Adopt `loader-utils` breaking changes

pull/2773/head
Alex Dima 3 years ago
parent ed1ee25b7b
commit 009bc9b864
No known key found for this signature in database
GPG Key ID: 39563C1504FDD0C9

@ -6,6 +6,7 @@ import { AddWorkerEntryPointPlugin } from './plugins/AddWorkerEntryPointPlugin';
import { languagesArr, EditorLanguage } from './languages';
import { featuresArr, EditorFeature, NegatedEditorFeature } from './features';
import { IFeatureDefinition } from './types';
import { ILoaderOptions } from './loaders/include';
const INCLUDE_LOADER_PATH = require.resolve('./loaders/include');
@ -282,17 +283,18 @@ function createLoaderRules(
};
})(${JSON.stringify(workerPaths, null, 2)})`
};
const options: ILoaderOptions = {
globals,
pre: featurePaths.map((importPath) => resolveMonacoPath(importPath, monacoEditorPath)),
post: languagePaths.map((importPath) => resolveMonacoPath(importPath, monacoEditorPath))
};
return [
{
test: /esm[/\\]vs[/\\]editor[/\\]editor.(api|main).js/,
use: [
{
loader: INCLUDE_LOADER_PATH,
options: {
globals,
pre: featurePaths.map((importPath) => resolveMonacoPath(importPath, monacoEditorPath)),
post: languagePaths.map((importPath) => resolveMonacoPath(importPath, monacoEditorPath))
}
options
}
]
}

@ -1,7 +1,15 @@
const loaderUtils = require('loader-utils');
import type { PitchLoaderDefinitionFunction } from 'webpack';
export function pitch(this: any, remainingRequest: any) {
const { globals = undefined, pre = [], post = [] } = loaderUtils.getOptions(this) || {};
export interface ILoaderOptions {
globals?: { [key: string]: string };
pre?: string[];
post?: string[];
}
export const pitch: PitchLoaderDefinitionFunction<ILoaderOptions> = function pitch(
remainingRequest
) {
const { globals = undefined, pre = [], post = [] } = this.getOptions() || {};
// HACK: NamedModulesPlugin overwrites existing modules when requesting the same module via
// different loaders, so we need to circumvent this by appending a suffix to make the name unique
@ -10,12 +18,16 @@ export function pitch(this: any, remainingRequest: any) {
this._module.userRequest = `include-loader!${this._module.userRequest}`;
}
const stringifyRequest = (request: string) => {
return JSON.stringify(this.utils.contextify(this.context || this.rootContext, request));
};
return [
...(globals
? Object.keys(globals).map((key) => `self[${JSON.stringify(key)}] = ${globals[key]};`)
: []),
...pre.map((include: any) => `require(${loaderUtils.stringifyRequest(this, include)});`),
`module.exports = require(${loaderUtils.stringifyRequest(this, `!!${remainingRequest}`)});`,
...post.map((include: any) => `require(${loaderUtils.stringifyRequest(this, include)});`)
...pre.map((include: any) => `require(${stringifyRequest(include)});`),
`module.exports = require(${stringifyRequest(`!!${remainingRequest}`)});`,
...post.map((include: any) => `require(${stringifyRequest(include)});`)
].join('\n');
}
};

Loading…
Cancel
Save