If defined, use the runtime configured baseUrl (#176573)

This commit is contained in:
Alexandru Dima 2023-03-09 15:20:15 +01:00 committed by GitHub
parent 579d3ede22
commit 0255bb0b03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 11 deletions

File diff suppressed because one or more lines are too long

View File

@ -54,7 +54,7 @@ function loaderPlugin(src: string, base: string, amdModuleId: string | undefined
);
}
function loader(src: string, bundledFileHeader: string, bundleLoader: boolean, externalLoaderInfo?: any): NodeJS.ReadWriteStream {
function loader(src: string, bundledFileHeader: string, bundleLoader: boolean, externalLoaderInfo?: util.IExternalLoaderInfo): NodeJS.ReadWriteStream {
let loaderStream = gulp.src(`${src}/vs/loader.js`, { base: `${src}` });
if (bundleLoader) {
loaderStream = es.merge(
@ -95,7 +95,7 @@ function loader(src: string, bundledFileHeader: string, bundleLoader: boolean, e
files.push(new VinylFile({
path: 'fake2',
base: '.',
contents: Buffer.from(`require.config(${JSON.stringify(externalLoaderInfo, undefined, 2)});`)
contents: Buffer.from(emitExternalLoaderInfo(externalLoaderInfo))
}));
}
for (const file of files) {
@ -107,6 +107,19 @@ function loader(src: string, bundledFileHeader: string, bundleLoader: boolean, e
);
}
function emitExternalLoaderInfo(externalLoaderInfo: util.IExternalLoaderInfo): string {
const externalBaseUrl = externalLoaderInfo.baseUrl;
externalLoaderInfo.baseUrl = '$BASE_URL';
// If defined, use the runtime configured baseUrl.
const code = `
(function() {
const baseUrl = require.getConfig().baseUrl || ${JSON.stringify(externalBaseUrl)};
require.config(${JSON.stringify(externalLoaderInfo, undefined, 2)});
})();`;
return code.replace('"$BASE_URL"', 'baseUrl');
}
function toConcatStream(src: string, bundledFileHeader: string, sources: bundle.IFile[], dest: string, fileContentMapper: (contents: string, path: string) => string): NodeJS.ReadWriteStream {
const useSourcemaps = /\.js$/.test(dest) && !/\.nls\.js$/.test(dest);
@ -170,7 +183,7 @@ export interface IOptimizeAMDTaskOpts {
/**
* Additional info we append to the end of the loader
*/
externalLoaderInfo?: any;
externalLoaderInfo?: util.IExternalLoaderInfo;
/**
* (true by default - append css and nls to loader)
*/
@ -324,7 +337,7 @@ function optimizeManualTask(options: IOptimizeManualTaskOpts[]): NodeJS.ReadWrit
return es.merge(...concatenations);
}
export function optimizeLoaderTask(src: string, out: string, bundleLoader: boolean, bundledFileHeader = '', externalLoaderInfo?: any): () => NodeJS.ReadWriteStream {
export function optimizeLoaderTask(src: string, out: string, bundleLoader: boolean, bundledFileHeader = '', externalLoaderInfo?: util.IExternalLoaderInfo): () => NodeJS.ReadWriteStream {
return () => loader(src, bundledFileHeader, bundleLoader, externalLoaderInfo).pipe(gulp.dest(out));
}

File diff suppressed because one or more lines are too long

View File

@ -440,16 +440,22 @@ export function acquireWebNodePaths() {
return nodePaths;
}
export function createExternalLoaderConfig(webEndpoint?: string, commit?: string, quality?: string) {
export interface IExternalLoaderInfo {
baseUrl: string;
paths: { [moduleId: string]: string };
[key: string]: any;
}
export function createExternalLoaderConfig(webEndpoint?: string, commit?: string, quality?: string): IExternalLoaderInfo | undefined {
if (!webEndpoint || !commit || !quality) {
return undefined;
}
webEndpoint = webEndpoint + `/${quality}/${commit}`;
const nodePaths = acquireWebNodePaths();
Object.keys(nodePaths).map(function (key, _) {
nodePaths[key] = `${webEndpoint}/node_modules/${key}/${nodePaths[key]}`;
nodePaths[key] = `../node_modules/${key}/${nodePaths[key]}`;
});
const externalLoaderConfig = {
const externalLoaderConfig: IExternalLoaderInfo = {
baseUrl: `${webEndpoint}/out`,
recordStats: true,
paths: nodePaths