From 8079e0b721a203eeb47ff6ef13115deb5e6792e9 Mon Sep 17 00:00:00 2001 From: Logan Ramos Date: Tue, 10 Aug 2021 16:56:18 -0400 Subject: [PATCH] Move webNodePaths to run on compile since we rimraf out --- build/gulpfile.js | 4 ++-- build/lib/util.js | 44 +++++++++++++++++++++++++++++++++++++++- build/lib/util.ts | 42 ++++++++++++++++++++++++++++++++++++++ build/npm/postinstall.js | 37 --------------------------------- 4 files changed, 87 insertions(+), 40 deletions(-) diff --git a/build/gulpfile.js b/build/gulpfile.js index 8b991e27a16..ca00206281e 100644 --- a/build/gulpfile.js +++ b/build/gulpfile.js @@ -16,10 +16,10 @@ const { monacoTypecheckTask/* , monacoTypecheckWatchTask */ } = require('./gulpf const { compileExtensionsTask, watchExtensionsTask, compileExtensionMediaTask } = require('./gulpfile.extensions'); // Fast compile for development time -const compileClientTask = task.define('compile-client', task.series(util.rimraf('out'), compilation.compileTask('src', 'out', false))); +const compileClientTask = task.define('compile-client', task.series(util.rimraf('out'), util.buildWebNodePaths(), compilation.compileTask('src', 'out', false))); gulp.task(compileClientTask); -const watchClientTask = task.define('watch-client', task.series(util.rimraf('out'), compilation.watchTask('out', false))); +const watchClientTask = task.define('watch-client', task.series(util.rimraf('out'), util.buildWebNodePaths(), compilation.watchTask('out', false))); gulp.task(watchClientTask); // All diff --git a/build/lib/util.js b/build/lib/util.js index 8d0294e4ceb..acc96f901f3 100644 --- a/build/lib/util.js +++ b/build/lib/util.js @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); -exports.getElectronVersion = exports.streamToPromise = exports.versionStringToNumber = exports.filter = exports.rebase = exports.getVersion = exports.ensureDir = exports.rreddir = exports.rimraf = exports.rewriteSourceMappingURL = exports.stripSourceMappingURL = exports.loadSourcemaps = exports.cleanNodeModules = exports.skipDirectories = exports.toFileUri = exports.setExecutableBit = exports.fixWin32DirectoryPermissions = exports.incremental = void 0; +exports.buildWebNodePaths = exports.getElectronVersion = exports.streamToPromise = exports.versionStringToNumber = exports.filter = exports.rebase = exports.getVersion = exports.ensureDir = exports.rreddir = exports.rimraf = exports.rewriteSourceMappingURL = exports.stripSourceMappingURL = exports.loadSourcemaps = exports.cleanNodeModules = exports.skipDirectories = exports.toFileUri = exports.setExecutableBit = exports.fixWin32DirectoryPermissions = exports.incremental = void 0; const es = require("event-stream"); const debounce = require("debounce"); const _filter = require("gulp-filter"); @@ -274,3 +274,45 @@ function getElectronVersion() { return target; } exports.getElectronVersion = getElectronVersion; +function buildWebNodePaths() { + const result = () => new Promise((resolve, _) => { + var _a; + const root = path.join(__dirname, '..', '..'); + const webPackageJSON = path.join(root, '/remote/web', 'package.json'); + const webPackages = JSON.parse(fs.readFileSync(webPackageJSON, 'utf8')).dependencies; + const nodePaths = {}; + for (const key of Object.keys(webPackages)) { + const packageJSON = path.join(root, 'node_modules', key, 'package.json'); + const packageData = JSON.parse(fs.readFileSync(packageJSON, 'utf8')); + let entryPoint = (_a = packageData.browser) !== null && _a !== void 0 ? _a : packageData.main; + // On rare cases a package doesn't have an entrypoint so we assume it has a dist folder with a min.js + if (!entryPoint) { + console.warn(`No entry point for ${key} assuming dist/${key}.min.js`); + entryPoint = `dist/${key}.min.js`; + } + // Remove any starting path information so it's all relative info + if (entryPoint.startsWith('./')) { + entryPoint = entryPoint.substr(2); + } + else if (entryPoint.startsWith('/')) { + entryPoint = entryPoint.substr(1); + } + nodePaths[key] = entryPoint; + } + // Now we write the node paths to out/vs + const outDirectory = path.join(root, 'out', 'vs'); + fs.mkdirSync(outDirectory, { recursive: true }); + const headerWithGeneratedFileWarning = `/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + + // This file is generated by build/npm/postinstall.js. Do not edit.`; + const fileContents = `${headerWithGeneratedFileWarning}\nself.webPackagePaths = ${JSON.stringify(nodePaths, null, 2)};`; + fs.writeFileSync(path.join(outDirectory, 'webPackagePaths.js'), fileContents, 'utf8'); + resolve(); + }); + result.taskName = 'build-web-node-paths'; + return result; +} +exports.buildWebNodePaths = buildWebNodePaths; diff --git a/build/lib/util.ts b/build/lib/util.ts index c0a0d9619d7..940dd22865d 100644 --- a/build/lib/util.ts +++ b/build/lib/util.ts @@ -340,3 +340,45 @@ export function getElectronVersion(): string { const target = /^target "(.*)"$/m.exec(yarnrc)![1]; return target; } + +export function buildWebNodePaths() { + const result = () => new Promise((resolve, _) => { + const root = path.join(__dirname, '..', '..'); + const webPackageJSON = path.join(root, '/remote/web', 'package.json'); + const webPackages = JSON.parse(fs.readFileSync(webPackageJSON, 'utf8')).dependencies; + const nodePaths: { [key: string]: string } = {}; + for (const key of Object.keys(webPackages)) { + const packageJSON = path.join(root, 'node_modules', key, 'package.json'); + const packageData = JSON.parse(fs.readFileSync(packageJSON, 'utf8')); + let entryPoint = packageData.browser ?? packageData.main; + // On rare cases a package doesn't have an entrypoint so we assume it has a dist folder with a min.js + if (!entryPoint) { + console.warn(`No entry point for ${key} assuming dist/${key}.min.js`); + entryPoint = `dist/${key}.min.js`; + } + // Remove any starting path information so it's all relative info + if (entryPoint.startsWith('./')) { + entryPoint = entryPoint.substr(2); + } else if (entryPoint.startsWith('/')) { + entryPoint = entryPoint.substr(1); + } + nodePaths[key] = entryPoint; + } + + // Now we write the node paths to out/vs + const outDirectory = path.join(root, 'out', 'vs'); + fs.mkdirSync(outDirectory, { recursive: true }); + const headerWithGeneratedFileWarning = `/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + + // This file is generated by build/npm/postinstall.js. Do not edit.`; + const fileContents = `${headerWithGeneratedFileWarning}\nself.webPackagePaths = ${JSON.stringify(nodePaths, null, 2)};`; + fs.writeFileSync(path.join(outDirectory, 'webPackagePaths.js'), fileContents, 'utf8'); + resolve(); + }); + result.taskName = 'build-web-node-paths'; + return result; +} + diff --git a/build/npm/postinstall.js b/build/npm/postinstall.js index c503104eb37..2433da29e86 100644 --- a/build/npm/postinstall.js +++ b/build/npm/postinstall.js @@ -71,7 +71,6 @@ for (let dir of dirs) { yarnInstall(dir, opts); } -buildWebNodePaths(); function yarnInstallBuildDependencies() { // make sure we install the deps of build/lib/watch for the system installed @@ -91,41 +90,5 @@ runtime "${runtime}"`; yarnInstall(watchPath); } -function buildWebNodePaths() { - const root = path.join(__dirname, '..', '..'); - const webPackageJSON = path.join(root, '/remote/web', 'package.json'); - const webPackages = JSON.parse(fs.readFileSync(webPackageJSON, 'utf8')).dependencies; - const nodePaths = new Object(null); - for (const key of Object.keys(webPackages)) { - const packageJSON = path.join(root, 'node_modules', key, 'package.json'); - const packageData = JSON.parse(fs.readFileSync(packageJSON, 'utf8')); - let entryPoint = packageData.browser ?? packageData.main; - // On rare cases a package doesn't have an entrypoint so we assume it has a dist folder with a min.js - if (!entryPoint) { - console.warn(`No entry point for ${key} assuming dist/${key}.min.js`); - entryPoint = `dist/${key}.min.js`; - } - // Remove any starting path information so it's all relative info - if (entryPoint.startsWith('./')) { - entryPoint = entryPoint.substr(2); - } else if (entryPoint.startsWith('/')) { - entryPoint = entryPoint.substr(1); - } - nodePaths[key] = entryPoint; - } - - // Now we write the node paths to out/vs - const outDirectory = path.join(root, 'out', 'vs'); - fs.mkdirSync(outDirectory, { recursive: true }); - const headerWithGeneratedFileWarning = `/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -// This file is generated by build/npm/postinstall.js. Do not edit.`; - const fileContents = `${headerWithGeneratedFileWarning}\nself.webPackagePaths = ${JSON.stringify(nodePaths, null, 2)};`; - fs.writeFileSync(path.join(outDirectory, 'webPackagePaths.js'), fileContents, 'utf8'); -} - cp.execSync('git config pull.rebase merges'); cp.execSync('git config blame.ignoreRevsFile .git-blame-ignore');