Fix bundling (#152389)

* Ensure stable order in bundled loader.js

* Avoid packaging build version of loader plugins
This commit is contained in:
Alexandru Dima 2022-06-16 23:05:10 +02:00 committed by GitHub
parent c462359652
commit 0d160ac237
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 33 deletions

View File

@ -48,10 +48,13 @@ function bundle(entryPoints, config, callback) {
loader.config(config);
loader(['require'], (localRequire) => {
const resolvePath = (entry) => {
const r = localRequire.toUrl(entry.path);
if (!/\.js/.test(r)) {
return { path: r + '.js', amdModuleId: entry.amdModuleId };
let r = localRequire.toUrl(entry.path);
if (!r.endsWith('.js')) {
r += '.js';
}
// avoid packaging the build version of plugins:
r = r.replace('vs/nls.build.js', 'vs/nls.js');
r = r.replace('vs/css.build.js', 'vs/css.js');
return { path: r, amdModuleId: entry.amdModuleId };
};
for (const moduleId in entryPointsMap) {

View File

@ -151,10 +151,13 @@ export function bundle(entryPoints: IEntryPoint[], config: ILoaderConfig, callba
loader(['require'], (localRequire: any) => {
const resolvePath = (entry: IExtraFile) => {
const r = localRequire.toUrl(entry.path);
if (!/\.js/.test(r)) {
return { path: r + '.js', amdModuleId: entry.amdModuleId };
let r = localRequire.toUrl(entry.path);
if (!r.endsWith('.js')) {
r += '.js';
}
// avoid packaging the build version of plugins:
r = r.replace('vs/nls.build.js', 'vs/nls.js');
r = r.replace('vs/css.build.js', 'vs/css.js');
return { path: r, amdModuleId: entry.amdModuleId };
};
for (const moduleId in entryPointsMap) {

View File

@ -52,29 +52,41 @@ function loader(src, bundledFileHeader, bundleLoader, externalLoaderInfo) {
if (bundleLoader) {
loaderStream = es.merge(loaderStream, loaderPlugin(`${src}/vs/css.js`, `${src}`, 'vs/css'), loaderPlugin(`${src}/vs/nls.js`, `${src}`, 'vs/nls'));
}
let isFirst = true;
const files = [];
const order = (f) => {
if (f.path.endsWith('loader.js')) {
return 0;
}
if (f.path.endsWith('css.js')) {
return 1;
}
if (f.path.endsWith('nls.js')) {
return 2;
}
return 3;
};
return (loaderStream
.pipe(es.through(function (data) {
if (isFirst) {
isFirst = false;
this.emit('data', new VinylFile({
path: 'fake',
base: '.',
contents: Buffer.from(bundledFileHeader)
}));
this.emit('data', data);
}
else {
this.emit('data', data);
}
files.push(data);
}, function () {
files.sort((a, b) => {
return order(a) - order(b);
});
files.unshift(new VinylFile({
path: 'fake',
base: '.',
contents: Buffer.from(bundledFileHeader)
}));
if (externalLoaderInfo !== undefined) {
this.emit('data', new VinylFile({
files.push(new VinylFile({
path: 'fake2',
base: '.',
contents: Buffer.from(`require.config(${JSON.stringify(externalLoaderInfo, undefined, 2)});`)
}));
}
for (const file of files) {
this.emit('data', file);
}
this.emit('end');
}))
.pipe(concat('vs/loader.js')));

View File

@ -66,29 +66,43 @@ function loader(src: string, bundledFileHeader: string, bundleLoader: boolean, e
);
}
let isFirst = true;
const files: VinylFile[] = [];
const order = (f: VinylFile) => {
if (f.path.endsWith('loader.js')) {
return 0;
}
if (f.path.endsWith('css.js')) {
return 1;
}
if (f.path.endsWith('nls.js')) {
return 2;
}
return 3;
};
return (
loaderStream
.pipe(es.through(function (data) {
if (isFirst) {
isFirst = false;
this.emit('data', new VinylFile({
path: 'fake',
base: '.',
contents: Buffer.from(bundledFileHeader)
}));
this.emit('data', data);
} else {
this.emit('data', data);
}
files.push(data);
}, function () {
files.sort((a, b) => {
return order(a) - order(b);
});
files.unshift(new VinylFile({
path: 'fake',
base: '.',
contents: Buffer.from(bundledFileHeader)
}));
if (externalLoaderInfo !== undefined) {
this.emit('data', new VinylFile({
files.push(new VinylFile({
path: 'fake2',
base: '.',
contents: Buffer.from(`require.config(${JSON.stringify(externalLoaderInfo, undefined, 2)});`)
}));
}
for (const file of files) {
this.emit('data', file);
}
this.emit('end');
}))
.pipe(concat('vs/loader.js'))