Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If defined, use the runtime configured baseUrl #176573

Merged
merged 1 commit into from Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions build/lib/optimize.js

Large diffs are not rendered by default.

21 changes: 17 additions & 4 deletions build/lib/optimize.ts
Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand All @@ -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);

Expand Down Expand Up @@ -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)
*/
Expand Down Expand Up @@ -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));
}

Expand Down