Skip to content

Commit

Permalink
Use the new loader format for web selfhost (microsoft#130592)
Browse files Browse the repository at this point in the history
* Update workbench html and bump distro

* Bump distro

* Add web node paths to the build task too

* Split task for reuse

* Bump distro
  • Loading branch information
lramos15 authored Aug 11, 2021
1 parent 2ee9010 commit 279c4d8
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 54 deletions.
1 change: 1 addition & 0 deletions build/gulpfile.compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const compilation = require('./lib/compilation');
const compileBuildTask = task.define('compile-build',
task.series(
util.rimraf('out-build'),
util.buildWebNodePaths('out-build'),
compilation.compileTask('src', 'out-build', true)
)
);
Expand Down
4 changes: 2 additions & 2 deletions build/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'), util.buildWebNodePaths(), compilation.compileTask('src', 'out', false)));
const compileClientTask = task.define('compile-client', task.series(util.rimraf('out'), util.buildWebNodePaths('out'), compilation.compileTask('src', 'out', false)));
gulp.task(compileClientTask);

const watchClientTask = task.define('watch-client', task.series(util.rimraf('out'), util.buildWebNodePaths(), compilation.watchTask('out', false)));
const watchClientTask = task.define('watch-client', task.series(util.rimraf('out'), util.buildWebNodePaths('out'), compilation.watchTask('out', false)));
gulp.task(watchClientTask);

// All
Expand Down
4 changes: 2 additions & 2 deletions build/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ function getElectronVersion() {
return target;
}
exports.getElectronVersion = getElectronVersion;
function buildWebNodePaths() {
function buildWebNodePaths(outDir) {
const result = () => new Promise((resolve, _) => {
var _a;
const root = path.join(__dirname, '..', '..');
Expand All @@ -300,7 +300,7 @@ function buildWebNodePaths() {
nodePaths[key] = entryPoint;
}
// Now we write the node paths to out/vs
const outDirectory = path.join(root, 'out', 'vs');
const outDirectory = path.join(root, outDir, 'vs');
fs.mkdirSync(outDirectory, { recursive: true });
const headerWithGeneratedFileWarning = `/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
Expand Down
51 changes: 28 additions & 23 deletions build/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,32 +341,37 @@ export function getElectronVersion(): string {
return target;
}

export function buildWebNodePaths() {
const result = () => new Promise<void>((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;
export function acquireWebNodePaths() {
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;
}
return nodePaths;
}

export function buildWebNodePaths(outDir: string) {
const result = () => new Promise<void>((resolve, _) => {
const root = path.join(__dirname, '..', '..');
const nodePaths = acquireWebNodePaths();
// Now we write the node paths to out/vs
const outDirectory = path.join(root, 'out', 'vs');
const outDirectory = path.join(root, outDir, 'vs');
fs.mkdirSync(outDirectory, { recursive: true });
const headerWithGeneratedFileWarning = `/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "code-oss-dev",
"version": "1.60.0",
"distro": "1a48bc9e1d4b74944a0721212e078bf24b2cbf79",
"distro": "0daa48b9b8ac455e8d47a401b305cbd093b8c375",
"author": {
"name": "Microsoft Corporation"
},
Expand Down
18 changes: 5 additions & 13 deletions src/vs/code/browser/workbench/workbench-dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
</body>

<!-- Startup (do not modify order of script tags!) -->
<script src="./static/out/vs/webPackagePaths.js"></script>
<script>
Object.keys(self.webPackagePaths).map(function (key, index) {
self.webPackagePaths[key] = `${window.location.origin}/static/remote/web/node_modules/${key}/${self.webPackagePaths[key]}`;
});
self.require = {
baseUrl: `${window.location.origin}/static/out`,
recordStats: true,
Expand All @@ -40,19 +44,7 @@
throw new Error(`Invalid script url: ${value}`)
}
}),
paths: {
'@microsoft/applicationinsights-web': `${window.location.origin}/static/remote/web/node_modules/@microsoft/applicationinsights-web/dist/applicationinsights-web.js`,
'@vscode/vscode-languagedetection': `${window.location.origin}/static/remote/web/node_modules/@vscode/vscode-languagedetection/dist/lib/index.js`,
'vscode-textmate': `${window.location.origin}/static/remote/web/node_modules/vscode-textmate/release/main`,
'vscode-oniguruma': `${window.location.origin}/static/remote/web/node_modules/vscode-oniguruma/release/main`,
'xterm': `${window.location.origin}/static/remote/web/node_modules/xterm/lib/xterm.js`,
'xterm-addon-search': `${window.location.origin}/static/remote/web/node_modules/xterm-addon-search/lib/xterm-addon-search.js`,
'xterm-addon-unicode11': `${window.location.origin}/static/remote/web/node_modules/xterm-addon-unicode11/lib/xterm-addon-unicode11.js`,
'xterm-addon-webgl': `${window.location.origin}/static/remote/web/node_modules/xterm-addon-webgl/lib/xterm-addon-webgl.js`,
'tas-client-umd': `${window.location.origin}/static/remote/web/node_modules/tas-client-umd/lib/tas-client-umd.js`,
'iconv-lite-umd': `${window.location.origin}/static/remote/web/node_modules/iconv-lite-umd/lib/iconv-lite-umd.js`,
'jschardet': `${window.location.origin}/static/remote/web/node_modules/jschardet/dist/jschardet.min.js`,
}
paths: self.webPackagePaths
};
</script>
<script src="./static/out/vs/loader.js"></script>
Expand Down
18 changes: 5 additions & 13 deletions src/vs/code/browser/workbench/workbench.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
</body>

<!-- Startup (do not modify order of script tags!) -->
<script src="./static/out/vs/webPackagePaths.js"></script>
<script>
Object.keys(self.webPackagePaths).map(function (key, index) {
self.webPackagePaths[key] = `${window.location.origin}/static/remote/web/node_modules/${key}/${self.webPackagePaths[key]}`;
});
self.require = {
baseUrl: `${window.location.origin}/static/out`,
recordStats: true,
Expand All @@ -39,19 +43,7 @@
throw new Error(`Invalid script url: ${value}`)
}
}),
paths: {
'@microsoft/applicationinsights-web': `${window.location.origin}/static/node_modules/@microsoft/applicationinsights-web/dist/applicationinsights-web.js`,
'@vscode/vscode-languagedetection': `${window.location.origin}/static/node_modules/@vscode/vscode-languagedetection/dist/lib/index.js`,
'vscode-textmate': `${window.location.origin}/static/node_modules/vscode-textmate/release/main`,
'vscode-oniguruma': `${window.location.origin}/static/node_modules/vscode-oniguruma/release/main`,
'xterm': `${window.location.origin}/static/node_modules/xterm/lib/xterm.js`,
'xterm-addon-search': `${window.location.origin}/static/node_modules/xterm-addon-search/lib/xterm-addon-search.js`,
'xterm-addon-unicode11': `${window.location.origin}/static/node_modules/xterm-addon-unicode11/lib/xterm-addon-unicode11.js`,
'xterm-addon-webgl': `${window.location.origin}/static/node_modules/xterm-addon-webgl/lib/xterm-addon-webgl.js`,
'tas-client-umd': `${window.location.origin}/static/node_modules/tas-client-umd/lib/tas-client-umd.js`,
'iconv-lite-umd': `${window.location.origin}/static/node_modules/iconv-lite-umd/lib/iconv-lite-umd.js`,
'jschardet': `${window.location.origin}/static/node_modules/jschardet/dist/jschardet.min.js`,
}
paths: self.webPackagePaths
};
</script>
<script src="./static/out/vs/loader.js"></script>
Expand Down

0 comments on commit 279c4d8

Please sign in to comment.