mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 20:52:56 +01:00
Have the webpack plugin tests use the /release/ folder
This commit is contained in:
parent
8af6bd5f8a
commit
8430c538b4
5 changed files with 54 additions and 28 deletions
6
monaco-editor-webpack-plugin/package-lock.json
generated
6
monaco-editor-webpack-plugin/package-lock.json
generated
|
|
@ -785,12 +785,6 @@
|
|||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
||||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
|
||||
},
|
||||
"monaco-editor": {
|
||||
"version": "0.30.0",
|
||||
"resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.30.0.tgz",
|
||||
"integrity": "sha512-/k++/ofRmwnwWTpOWYOMGVcqBrqrlt3MP0Mt/cRTQojW7A9fnekcvPQ2iIFA0YSZdPWPN9yYXrYq0xqiUuxT/A==",
|
||||
"dev": true
|
||||
},
|
||||
"neo-async": {
|
||||
"version": "2.6.2",
|
||||
"resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz",
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@
|
|||
"css-loader": "^5.1.1",
|
||||
"file-loader": "^6.2.0",
|
||||
"glob": "^7.1.6",
|
||||
"monaco-editor": "^0.30.0",
|
||||
"style-loader": "^2.0.0",
|
||||
"typescript": "^4.2.3",
|
||||
"webpack": "^5.24.3",
|
||||
|
|
|
|||
|
|
@ -27,24 +27,32 @@ featuresArr.forEach((feature) => (featuresById[feature.label] = feature));
|
|||
/**
|
||||
* Return a resolved path for a given Monaco file.
|
||||
*/
|
||||
function resolveMonacoPath(filePath: string): string {
|
||||
function resolveMonacoPath(filePath: string, monacoEditorPath: string | undefined): string {
|
||||
if (monacoEditorPath) {
|
||||
return require.resolve(path.join(monacoEditorPath, 'esm', filePath));
|
||||
}
|
||||
|
||||
try {
|
||||
return require.resolve(path.join('monaco-editor/esm', filePath));
|
||||
} catch (err) {
|
||||
} catch (err) {}
|
||||
|
||||
try {
|
||||
return require.resolve(path.join(process.cwd(), 'node_modules/monaco-editor/esm', filePath));
|
||||
} catch (err) {
|
||||
} catch (err) {}
|
||||
|
||||
return require.resolve(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the interpolated final filename for a worker, respecting the file name template.
|
||||
*/
|
||||
function getWorkerFilename(filename: string, entry: string): string {
|
||||
function getWorkerFilename(
|
||||
filename: string,
|
||||
entry: string,
|
||||
monacoEditorPath: string | undefined
|
||||
): string {
|
||||
return loaderUtils.interpolateName(<any>{ resourcePath: entry }, filename, {
|
||||
content: fs.readFileSync(resolveMonacoPath(entry))
|
||||
content: fs.readFileSync(resolveMonacoPath(entry, monacoEditorPath))
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -92,6 +100,12 @@ interface IMonacoEditorWebpackPluginOpts {
|
|||
*/
|
||||
filename?: string;
|
||||
|
||||
/**
|
||||
* The absolute file system path to the monaco-editor npm module.
|
||||
* Use e.g. `C:\projects\my-project\node-modules\monaco-editor`
|
||||
*/
|
||||
monacoEditorPath?: string;
|
||||
|
||||
/**
|
||||
* Override the public path from which files generated by this plugin will be served.
|
||||
* This wins out over Webpack's dynamic runtime path and can be useful to avoid attempting to load workers cross-
|
||||
|
|
@ -114,6 +128,7 @@ interface IInternalMonacoEditorWebpackPluginOpts {
|
|||
languages: IFeatureDefinition[];
|
||||
features: IFeatureDefinition[];
|
||||
filename: string;
|
||||
monacoEditorPath: string | undefined;
|
||||
publicPath: string;
|
||||
globalAPI: boolean;
|
||||
}
|
||||
|
|
@ -129,13 +144,14 @@ class MonacoEditorWebpackPlugin implements webpack.WebpackPluginInstance {
|
|||
languages: coalesce(languages.map((id) => languagesById[id])).concat(customLanguages),
|
||||
features: coalesce(features.map((id) => featuresById[id])),
|
||||
filename: options.filename || '[name].worker.js',
|
||||
monacoEditorPath: options.monacoEditorPath,
|
||||
publicPath: options.publicPath || '',
|
||||
globalAPI: options.globalAPI || false
|
||||
};
|
||||
}
|
||||
|
||||
apply(compiler: webpack.Compiler): void {
|
||||
const { languages, features, filename, publicPath, globalAPI } = this.options;
|
||||
const { languages, features, filename, monacoEditorPath, publicPath, globalAPI } = this.options;
|
||||
const compilationPublicPath = getCompilationPublicPath(compiler);
|
||||
const modules = [EDITOR_MODULE].concat(languages).concat(features);
|
||||
const workers: ILabeledWorkerDefinition[] = [];
|
||||
|
|
@ -153,11 +169,12 @@ class MonacoEditorWebpackPlugin implements webpack.WebpackPluginInstance {
|
|||
features,
|
||||
workers,
|
||||
filename,
|
||||
monacoEditorPath,
|
||||
publicPath,
|
||||
compilationPublicPath,
|
||||
globalAPI
|
||||
);
|
||||
const plugins = createPlugins(compiler, workers, filename);
|
||||
const plugins = createPlugins(compiler, workers, filename, monacoEditorPath);
|
||||
addCompilerRules(compiler, rules);
|
||||
addCompilerPlugins(compiler, plugins);
|
||||
}
|
||||
|
|
@ -199,6 +216,7 @@ function createLoaderRules(
|
|||
features: IFeatureDefinition[],
|
||||
workers: ILabeledWorkerDefinition[],
|
||||
filename: string,
|
||||
monacoEditorPath: string | undefined,
|
||||
pluginPublicPath: string,
|
||||
compilationPublicPath: string,
|
||||
globalAPI: boolean
|
||||
|
|
@ -209,7 +227,7 @@ function createLoaderRules(
|
|||
const languagePaths = flatArr(coalesce(languages.map((language) => language.entry)));
|
||||
const featurePaths = flatArr(coalesce(features.map((feature) => feature.entry)));
|
||||
const workerPaths = fromPairs(
|
||||
workers.map(({ label, entry }) => [label, getWorkerFilename(filename, entry)])
|
||||
workers.map(({ label, entry }) => [label, getWorkerFilename(filename, entry, monacoEditorPath)])
|
||||
);
|
||||
if (workerPaths['typescript']) {
|
||||
// javascript shares the same worker
|
||||
|
|
@ -266,14 +284,14 @@ function createLoaderRules(
|
|||
};
|
||||
return [
|
||||
{
|
||||
test: /monaco-editor[/\\]esm[/\\]vs[/\\]editor[/\\]editor.(api|main).js/,
|
||||
test: /esm[/\\]vs[/\\]editor[/\\]editor.(api|main).js/,
|
||||
use: [
|
||||
{
|
||||
loader: INCLUDE_LOADER_PATH,
|
||||
options: {
|
||||
globals,
|
||||
pre: featurePaths.map((importPath) => resolveMonacoPath(importPath)),
|
||||
post: languagePaths.map((importPath) => resolveMonacoPath(importPath))
|
||||
pre: featurePaths.map((importPath) => resolveMonacoPath(importPath, monacoEditorPath)),
|
||||
post: languagePaths.map((importPath) => resolveMonacoPath(importPath, monacoEditorPath))
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
@ -284,7 +302,8 @@ function createLoaderRules(
|
|||
function createPlugins(
|
||||
compiler: webpack.Compiler,
|
||||
workers: ILabeledWorkerDefinition[],
|
||||
filename: string
|
||||
filename: string,
|
||||
monacoEditorPath: string | undefined
|
||||
): AddWorkerEntryPointPlugin[] {
|
||||
const webpack = compiler.webpack ?? require('webpack');
|
||||
|
||||
|
|
@ -293,8 +312,8 @@ function createPlugins(
|
|||
({ id, entry }) =>
|
||||
new AddWorkerEntryPointPlugin({
|
||||
id,
|
||||
entry: resolveMonacoPath(entry),
|
||||
filename: getWorkerFilename(filename, entry),
|
||||
entry: resolveMonacoPath(entry, monacoEditorPath),
|
||||
filename: getWorkerFilename(filename, entry, monacoEditorPath),
|
||||
plugins: [new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 })]
|
||||
})
|
||||
)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,11 @@ module.exports = {
|
|||
filename: 'app.js',
|
||||
publicPath: ASSET_PATH
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'monaco-editor': path.resolve(__dirname, '../../release'),
|
||||
},
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
|
|
@ -24,5 +29,7 @@ module.exports = {
|
|||
}
|
||||
]
|
||||
},
|
||||
plugins: [new MonacoWebpackPlugin()]
|
||||
plugins: [new MonacoWebpackPlugin({
|
||||
monacoEditorPath: path.resolve(__dirname, '../../release')
|
||||
})]
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,6 +9,11 @@ module.exports = {
|
|||
path: path.resolve(__dirname, 'dist'),
|
||||
filename: 'app.js'
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'monaco-editor': path.resolve(__dirname, '../../release'),
|
||||
},
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
|
|
@ -21,5 +26,7 @@ module.exports = {
|
|||
}
|
||||
]
|
||||
},
|
||||
plugins: [new MonacoWebpackPlugin()]
|
||||
plugins: [new MonacoWebpackPlugin({
|
||||
monacoEditorPath: path.resolve(__dirname, '../../release')
|
||||
})]
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue