Rename to webpack-plugin

This commit is contained in:
Alex Dima 2021-11-15 16:16:53 +01:00
parent db6aec351b
commit a21839d00d
No known key found for this signature in database
GPG key ID: 39563C1504FDD0C9
25 changed files with 5 additions and 5 deletions

View file

@ -0,0 +1,309 @@
//
// THIS IS A GENERATED FILE. PLEASE DO NOT EDIT DIRECTLY.
// GENERATED USING node scripts/import-editor.js
//
import { IFeatureDefinition } from './types';
export const featuresArr: IFeatureDefinition[] = [
{
label: 'accessibilityHelp',
entry: 'vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp'
},
{
label: 'anchorSelect',
entry: 'vs/editor/contrib/anchorSelect/anchorSelect'
},
{
label: 'bracketMatching',
entry: 'vs/editor/contrib/bracketMatching/bracketMatching'
},
{
label: 'caretOperations',
entry: 'vs/editor/contrib/caretOperations/caretOperations'
},
{
label: 'clipboard',
entry: 'vs/editor/contrib/clipboard/clipboard'
},
{
label: 'codeAction',
entry: 'vs/editor/contrib/codeAction/codeActionContributions'
},
{
label: 'codelens',
entry: 'vs/editor/contrib/codelens/codelensController'
},
{
label: 'colorPicker',
entry: 'vs/editor/contrib/colorPicker/colorContributions'
},
{
label: 'comment',
entry: 'vs/editor/contrib/comment/comment'
},
{
label: 'contextmenu',
entry: 'vs/editor/contrib/contextmenu/contextmenu'
},
{
label: 'coreCommands',
entry: 'vs/editor/browser/controller/coreCommands'
},
{
label: 'cursorUndo',
entry: 'vs/editor/contrib/cursorUndo/cursorUndo'
},
{
label: 'dnd',
entry: 'vs/editor/contrib/dnd/dnd'
},
{
label: 'documentSymbols',
entry: 'vs/editor/contrib/documentSymbols/documentSymbols'
},
{
label: 'find',
entry: 'vs/editor/contrib/find/findController'
},
{
label: 'folding',
entry: 'vs/editor/contrib/folding/folding'
},
{
label: 'fontZoom',
entry: 'vs/editor/contrib/fontZoom/fontZoom'
},
{
label: 'format',
entry: 'vs/editor/contrib/format/formatActions'
},
{
label: 'gotoError',
entry: 'vs/editor/contrib/gotoError/gotoError'
},
{
label: 'gotoLine',
entry: 'vs/editor/standalone/browser/quickAccess/standaloneGotoLineQuickAccess'
},
{
label: 'gotoSymbol',
entry: [
'vs/editor/contrib/gotoSymbol/goToCommands',
'vs/editor/contrib/gotoSymbol/link/goToDefinitionAtPosition'
]
},
{
label: 'hover',
entry: 'vs/editor/contrib/hover/hover'
},
{
label: 'iPadShowKeyboard',
entry: 'vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard'
},
{
label: 'inPlaceReplace',
entry: 'vs/editor/contrib/inPlaceReplace/inPlaceReplace'
},
{
label: 'indentation',
entry: 'vs/editor/contrib/indentation/indentation'
},
{
label: 'inlayHints',
entry: 'vs/editor/contrib/inlayHints/inlayHintsController'
},
{
label: 'inlineCompletions',
entry: 'vs/editor/contrib/inlineCompletions/ghostTextController'
},
{
label: 'inspectTokens',
entry: 'vs/editor/standalone/browser/inspectTokens/inspectTokens'
},
{
label: 'linesOperations',
entry: 'vs/editor/contrib/linesOperations/linesOperations'
},
{
label: 'linkedEditing',
entry: 'vs/editor/contrib/linkedEditing/linkedEditing'
},
{
label: 'links',
entry: 'vs/editor/contrib/links/links'
},
{
label: 'multicursor',
entry: 'vs/editor/contrib/multicursor/multicursor'
},
{
label: 'parameterHints',
entry: 'vs/editor/contrib/parameterHints/parameterHints'
},
{
label: 'quickCommand',
entry: 'vs/editor/standalone/browser/quickAccess/standaloneCommandsQuickAccess'
},
{
label: 'quickHelp',
entry: 'vs/editor/standalone/browser/quickAccess/standaloneHelpQuickAccess'
},
{
label: 'quickOutline',
entry: 'vs/editor/standalone/browser/quickAccess/standaloneGotoSymbolQuickAccess'
},
{
label: 'referenceSearch',
entry: 'vs/editor/standalone/browser/referenceSearch/standaloneReferenceSearch'
},
{
label: 'rename',
entry: 'vs/editor/contrib/rename/rename'
},
{
label: 'smartSelect',
entry: 'vs/editor/contrib/smartSelect/smartSelect'
},
{
label: 'snippets',
entry: 'vs/editor/contrib/snippet/snippetController2'
},
{
label: 'suggest',
entry: 'vs/editor/contrib/suggest/suggestController'
},
{
label: 'toggleHighContrast',
entry: 'vs/editor/standalone/browser/toggleHighContrast/toggleHighContrast'
},
{
label: 'toggleTabFocusMode',
entry: 'vs/editor/contrib/toggleTabFocusMode/toggleTabFocusMode'
},
{
label: 'transpose',
entry: 'vs/editor/contrib/caretOperations/transpose'
},
{
label: 'unusualLineTerminators',
entry: 'vs/editor/contrib/unusualLineTerminators/unusualLineTerminators'
},
{
label: 'viewportSemanticTokens',
entry: 'vs/editor/contrib/viewportSemanticTokens/viewportSemanticTokens'
},
{
label: 'wordHighlighter',
entry: 'vs/editor/contrib/wordHighlighter/wordHighlighter'
},
{
label: 'wordOperations',
entry: 'vs/editor/contrib/wordOperations/wordOperations'
},
{
label: 'wordPartOperations',
entry: 'vs/editor/contrib/wordPartOperations/wordPartOperations'
}
];
export type EditorFeature =
| 'accessibilityHelp'
| 'anchorSelect'
| 'bracketMatching'
| 'caretOperations'
| 'clipboard'
| 'codeAction'
| 'codelens'
| 'colorPicker'
| 'comment'
| 'contextmenu'
| 'coreCommands'
| 'cursorUndo'
| 'dnd'
| 'documentSymbols'
| 'find'
| 'folding'
| 'fontZoom'
| 'format'
| 'gotoError'
| 'gotoLine'
| 'gotoSymbol'
| 'hover'
| 'iPadShowKeyboard'
| 'inPlaceReplace'
| 'indentation'
| 'inlayHints'
| 'inlineCompletions'
| 'inspectTokens'
| 'linesOperations'
| 'linkedEditing'
| 'links'
| 'multicursor'
| 'parameterHints'
| 'quickCommand'
| 'quickHelp'
| 'quickOutline'
| 'referenceSearch'
| 'rename'
| 'smartSelect'
| 'snippets'
| 'suggest'
| 'toggleHighContrast'
| 'toggleTabFocusMode'
| 'transpose'
| 'unusualLineTerminators'
| 'viewportSemanticTokens'
| 'wordHighlighter'
| 'wordOperations'
| 'wordPartOperations';
export type NegatedEditorFeature =
| '!accessibilityHelp'
| '!anchorSelect'
| '!bracketMatching'
| '!caretOperations'
| '!clipboard'
| '!codeAction'
| '!codelens'
| '!colorPicker'
| '!comment'
| '!contextmenu'
| '!coreCommands'
| '!cursorUndo'
| '!dnd'
| '!documentSymbols'
| '!find'
| '!folding'
| '!fontZoom'
| '!format'
| '!gotoError'
| '!gotoLine'
| '!gotoSymbol'
| '!hover'
| '!iPadShowKeyboard'
| '!inPlaceReplace'
| '!indentation'
| '!inlayHints'
| '!inlineCompletions'
| '!inspectTokens'
| '!linesOperations'
| '!linkedEditing'
| '!links'
| '!multicursor'
| '!parameterHints'
| '!quickCommand'
| '!quickHelp'
| '!quickOutline'
| '!referenceSearch'
| '!rename'
| '!smartSelect'
| '!snippets'
| '!suggest'
| '!toggleHighContrast'
| '!toggleTabFocusMode'
| '!transpose'
| '!unusualLineTerminators'
| '!viewportSemanticTokens'
| '!wordHighlighter'
| '!wordOperations'
| '!wordPartOperations';

343
webpack-plugin/src/index.ts Normal file
View file

@ -0,0 +1,343 @@
import type * as webpack from 'webpack';
import * as path from 'path';
import * as loaderUtils from 'loader-utils';
import * as fs from 'fs';
import { AddWorkerEntryPointPlugin } from './plugins/AddWorkerEntryPointPlugin';
import { languagesArr, EditorLanguage } from './languages';
import { featuresArr, EditorFeature, NegatedEditorFeature } from './features';
import { IFeatureDefinition } from './types';
const INCLUDE_LOADER_PATH = require.resolve('./loaders/include');
const EDITOR_MODULE: IFeatureDefinition = {
label: 'editorWorkerService',
entry: undefined,
worker: {
id: 'vs/editor/editor',
entry: 'vs/editor/editor.worker'
}
};
const languagesById: { [language: string]: IFeatureDefinition } = {};
languagesArr.forEach((language) => (languagesById[language.label] = language));
const featuresById: { [feature: string]: IFeatureDefinition } = {};
featuresArr.forEach((feature) => (featuresById[feature.label] = feature));
/**
* Return a resolved path for a given Monaco file.
*/
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) {}
try {
return require.resolve(path.join(process.cwd(), 'node_modules/monaco-editor/esm', filePath));
} 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,
monacoEditorPath: string | undefined
): string {
return loaderUtils.interpolateName(<any>{ resourcePath: entry }, filename, {
content: fs.readFileSync(resolveMonacoPath(entry, monacoEditorPath))
});
}
function getFeaturesIds(userFeatures: string[]): string[] {
function notContainedIn(arr: string[]) {
return (element: string) => arr.indexOf(element) === -1;
}
let featuresIds: string[];
if (userFeatures.length) {
const excludedFeatures = userFeatures.filter((f) => f[0] === '!').map((f) => f.slice(1));
if (excludedFeatures.length) {
featuresIds = Object.keys(featuresById).filter(notContainedIn(excludedFeatures));
} else {
featuresIds = userFeatures;
}
} else {
featuresIds = Object.keys(featuresById);
}
return featuresIds;
}
interface IMonacoEditorWebpackPluginOpts {
/**
* Include only a subset of the languages supported.
*/
languages?: EditorLanguage[];
/**
* Custom languages (outside of the ones shipped with the `monaco-editor`).
*/
customLanguages?: IFeatureDefinition[];
/**
* Include only a subset of the editor features.
* Use e.g. '!contextmenu' to exclude a certain feature.
*/
features?: (EditorFeature | NegatedEditorFeature)[];
/**
* Specify a filename template to use for generated files.
* Use e.g. '[name].worker.[contenthash].js' to include content-based hashes.
*/
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-
* origin when using a CDN for other static resources.
* Use e.g. '/' if you want to load your resources from the current origin.
*/
publicPath?: string;
/**
* Specify whether the editor API should be exposed through a global `monaco` object or not. This
* option is applicable to `0.22.0` and newer version of `monaco-editor`. Since `0.22.0`, the ESM
* version of the monaco editor does no longer define a global `monaco` object unless
* `global.MonacoEnvironment = { globalAPI: true }` is set ([change
* log](https://github.com/microsoft/monaco-editor/blob/main/CHANGELOG.md#0220-29012021)).
*/
globalAPI?: boolean;
}
interface IInternalMonacoEditorWebpackPluginOpts {
languages: IFeatureDefinition[];
features: IFeatureDefinition[];
filename: string;
monacoEditorPath: string | undefined;
publicPath: string;
globalAPI: boolean;
}
class MonacoEditorWebpackPlugin implements webpack.WebpackPluginInstance {
private readonly options: IInternalMonacoEditorWebpackPluginOpts;
constructor(options: IMonacoEditorWebpackPluginOpts = {}) {
const languages = options.languages || Object.keys(languagesById);
const customLanguages = options.customLanguages || [];
const features = getFeaturesIds(options.features || []);
this.options = {
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, monacoEditorPath, publicPath, globalAPI } = this.options;
const compilationPublicPath = getCompilationPublicPath(compiler);
const modules = [EDITOR_MODULE].concat(languages).concat(features);
const workers: ILabeledWorkerDefinition[] = [];
modules.forEach((module) => {
if (module.worker) {
workers.push({
label: module.label,
id: module.worker.id,
entry: module.worker.entry
});
}
});
const rules = createLoaderRules(
languages,
features,
workers,
filename,
monacoEditorPath,
publicPath,
compilationPublicPath,
globalAPI
);
const plugins = createPlugins(compiler, workers, filename, monacoEditorPath);
addCompilerRules(compiler, rules);
addCompilerPlugins(compiler, plugins);
}
}
interface ILabeledWorkerDefinition {
label: string;
id: string;
entry: string;
}
function addCompilerRules(compiler: webpack.Compiler, rules: webpack.RuleSetRule[]): void {
const compilerOptions = compiler.options;
if (!compilerOptions.module) {
compilerOptions.module = <any>{ rules: rules };
} else {
const moduleOptions = compilerOptions.module;
moduleOptions.rules = (moduleOptions.rules || []).concat(rules);
}
}
function addCompilerPlugins(compiler: webpack.Compiler, plugins: webpack.WebpackPluginInstance[]) {
plugins.forEach((plugin) => plugin.apply(compiler));
}
function getCompilationPublicPath(compiler: webpack.Compiler): string {
if (compiler.options.output && compiler.options.output.publicPath) {
if (typeof compiler.options.output.publicPath === 'string') {
return compiler.options.output.publicPath;
} else {
console.warn(`Cannot handle options.publicPath (expected a string)`);
}
}
return '';
}
function createLoaderRules(
languages: IFeatureDefinition[],
features: IFeatureDefinition[],
workers: ILabeledWorkerDefinition[],
filename: string,
monacoEditorPath: string | undefined,
pluginPublicPath: string,
compilationPublicPath: string,
globalAPI: boolean
): webpack.RuleSetRule[] {
if (!languages.length && !features.length) {
return [];
}
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, monacoEditorPath)])
);
if (workerPaths['typescript']) {
// javascript shares the same worker
workerPaths['javascript'] = workerPaths['typescript'];
}
if (workerPaths['css']) {
// scss and less share the same worker
workerPaths['less'] = workerPaths['css'];
workerPaths['scss'] = workerPaths['css'];
}
if (workerPaths['html']) {
// handlebars, razor and html share the same worker
workerPaths['handlebars'] = workerPaths['html'];
workerPaths['razor'] = workerPaths['html'];
}
// Determine the public path from which to load worker JS files. In order of precedence:
// 1. Plugin-specific public path.
// 2. Dynamic runtime public path.
// 3. Compilation public path.
const pathPrefix = Boolean(pluginPublicPath)
? JSON.stringify(pluginPublicPath)
: `typeof __webpack_public_path__ === 'string' ` +
`? __webpack_public_path__ ` +
`: ${JSON.stringify(compilationPublicPath)}`;
const globals = {
MonacoEnvironment: `(function (paths) {
function stripTrailingSlash(str) {
return str.replace(/\\/$/, '');
}
return {
globalAPI: ${globalAPI},
getWorkerUrl: function (moduleId, label) {
var pathPrefix = ${pathPrefix};
var result = (pathPrefix ? stripTrailingSlash(pathPrefix) + '/' : '') + paths[label];
if (/^((http:)|(https:)|(file:)|(\\/\\/))/.test(result)) {
var currentUrl = String(window.location);
var currentOrigin = currentUrl.substr(0, currentUrl.length - window.location.hash.length - window.location.search.length - window.location.pathname.length);
if (result.substring(0, currentOrigin.length) !== currentOrigin) {
if(/^(\\/\\/)/.test(result)) {
result = window.location.protocol + result
}
var js = '/*' + label + '*/importScripts("' + result + '");';
var blob = new Blob([js], { type: 'application/javascript' });
return URL.createObjectURL(blob);
}
}
return result;
}
};
})(${JSON.stringify(workerPaths, null, 2)})`
};
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))
}
}
]
}
];
}
function createPlugins(
compiler: webpack.Compiler,
workers: ILabeledWorkerDefinition[],
filename: string,
monacoEditorPath: string | undefined
): AddWorkerEntryPointPlugin[] {
const webpack = compiler.webpack ?? require('webpack');
return (<AddWorkerEntryPointPlugin[]>[]).concat(
workers.map(
({ id, entry }) =>
new AddWorkerEntryPointPlugin({
id,
entry: resolveMonacoPath(entry, monacoEditorPath),
filename: getWorkerFilename(filename, entry, monacoEditorPath),
plugins: [new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 })]
})
)
);
}
function flatArr<T>(items: (T | T[])[]): T[] {
return items.reduce((acc: T[], item: T | T[]) => {
if (Array.isArray(item)) {
return (<T[]>[]).concat(acc).concat(item);
}
return (<T[]>[]).concat(acc).concat([item]);
}, <T[]>[]);
}
function fromPairs<T>(values: [string, T][]): { [key: string]: T } {
return values.reduce(
(acc, [key, value]) => Object.assign(acc, { [key]: value }),
<{ [key: string]: T }>{}
);
}
function coalesce<T>(array: ReadonlyArray<T | undefined | null>): T[] {
return <T[]>array.filter(Boolean);
}
export = MonacoEditorWebpackPlugin;

View file

@ -0,0 +1,414 @@
//
// THIS IS A GENERATED FILE. PLEASE DO NOT EDIT DIRECTLY.
// GENERATED USING node scripts/import-editor.js
//
import { IFeatureDefinition } from './types';
export const languagesArr: IFeatureDefinition[] = [
{
label: 'abap',
entry: 'vs/basic-languages/abap/abap.contribution'
},
{
label: 'apex',
entry: 'vs/basic-languages/apex/apex.contribution'
},
{
label: 'azcli',
entry: 'vs/basic-languages/azcli/azcli.contribution'
},
{
label: 'bat',
entry: 'vs/basic-languages/bat/bat.contribution'
},
{
label: 'bicep',
entry: 'vs/basic-languages/bicep/bicep.contribution'
},
{
label: 'cameligo',
entry: 'vs/basic-languages/cameligo/cameligo.contribution'
},
{
label: 'clojure',
entry: 'vs/basic-languages/clojure/clojure.contribution'
},
{
label: 'coffee',
entry: 'vs/basic-languages/coffee/coffee.contribution'
},
{
label: 'cpp',
entry: 'vs/basic-languages/cpp/cpp.contribution'
},
{
label: 'csharp',
entry: 'vs/basic-languages/csharp/csharp.contribution'
},
{
label: 'csp',
entry: 'vs/basic-languages/csp/csp.contribution'
},
{
label: 'css',
entry: ['vs/basic-languages/css/css.contribution', 'vs/language/css/monaco.contribution'],
worker: {
id: 'vs/language/css/cssWorker',
entry: 'vs/language/css/css.worker'
}
},
{
label: 'dart',
entry: 'vs/basic-languages/dart/dart.contribution'
},
{
label: 'dockerfile',
entry: 'vs/basic-languages/dockerfile/dockerfile.contribution'
},
{
label: 'ecl',
entry: 'vs/basic-languages/ecl/ecl.contribution'
},
{
label: 'elixir',
entry: 'vs/basic-languages/elixir/elixir.contribution'
},
{
label: 'flow9',
entry: 'vs/basic-languages/flow9/flow9.contribution'
},
{
label: 'fsharp',
entry: 'vs/basic-languages/fsharp/fsharp.contribution'
},
{
label: 'go',
entry: 'vs/basic-languages/go/go.contribution'
},
{
label: 'graphql',
entry: 'vs/basic-languages/graphql/graphql.contribution'
},
{
label: 'handlebars',
entry: 'vs/basic-languages/handlebars/handlebars.contribution'
},
{
label: 'hcl',
entry: 'vs/basic-languages/hcl/hcl.contribution'
},
{
label: 'html',
entry: ['vs/basic-languages/html/html.contribution', 'vs/language/html/monaco.contribution'],
worker: {
id: 'vs/language/html/htmlWorker',
entry: 'vs/language/html/html.worker'
}
},
{
label: 'ini',
entry: 'vs/basic-languages/ini/ini.contribution'
},
{
label: 'java',
entry: 'vs/basic-languages/java/java.contribution'
},
{
label: 'javascript',
entry: 'vs/basic-languages/javascript/javascript.contribution'
},
{
label: 'json',
entry: 'vs/language/json/monaco.contribution',
worker: {
id: 'vs/language/json/jsonWorker',
entry: 'vs/language/json/json.worker'
}
},
{
label: 'julia',
entry: 'vs/basic-languages/julia/julia.contribution'
},
{
label: 'kotlin',
entry: 'vs/basic-languages/kotlin/kotlin.contribution'
},
{
label: 'less',
entry: 'vs/basic-languages/less/less.contribution'
},
{
label: 'lexon',
entry: 'vs/basic-languages/lexon/lexon.contribution'
},
{
label: 'liquid',
entry: 'vs/basic-languages/liquid/liquid.contribution'
},
{
label: 'lua',
entry: 'vs/basic-languages/lua/lua.contribution'
},
{
label: 'm3',
entry: 'vs/basic-languages/m3/m3.contribution'
},
{
label: 'markdown',
entry: 'vs/basic-languages/markdown/markdown.contribution'
},
{
label: 'mips',
entry: 'vs/basic-languages/mips/mips.contribution'
},
{
label: 'msdax',
entry: 'vs/basic-languages/msdax/msdax.contribution'
},
{
label: 'mysql',
entry: 'vs/basic-languages/mysql/mysql.contribution'
},
{
label: 'objective-c',
entry: 'vs/basic-languages/objective-c/objective-c.contribution'
},
{
label: 'pascal',
entry: 'vs/basic-languages/pascal/pascal.contribution'
},
{
label: 'pascaligo',
entry: 'vs/basic-languages/pascaligo/pascaligo.contribution'
},
{
label: 'perl',
entry: 'vs/basic-languages/perl/perl.contribution'
},
{
label: 'pgsql',
entry: 'vs/basic-languages/pgsql/pgsql.contribution'
},
{
label: 'php',
entry: 'vs/basic-languages/php/php.contribution'
},
{
label: 'pla',
entry: 'vs/basic-languages/pla/pla.contribution'
},
{
label: 'postiats',
entry: 'vs/basic-languages/postiats/postiats.contribution'
},
{
label: 'powerquery',
entry: 'vs/basic-languages/powerquery/powerquery.contribution'
},
{
label: 'powershell',
entry: 'vs/basic-languages/powershell/powershell.contribution'
},
{
label: 'protobuf',
entry: 'vs/basic-languages/protobuf/protobuf.contribution'
},
{
label: 'pug',
entry: 'vs/basic-languages/pug/pug.contribution'
},
{
label: 'python',
entry: 'vs/basic-languages/python/python.contribution'
},
{
label: 'qsharp',
entry: 'vs/basic-languages/qsharp/qsharp.contribution'
},
{
label: 'r',
entry: 'vs/basic-languages/r/r.contribution'
},
{
label: 'razor',
entry: 'vs/basic-languages/razor/razor.contribution'
},
{
label: 'redis',
entry: 'vs/basic-languages/redis/redis.contribution'
},
{
label: 'redshift',
entry: 'vs/basic-languages/redshift/redshift.contribution'
},
{
label: 'restructuredtext',
entry: 'vs/basic-languages/restructuredtext/restructuredtext.contribution'
},
{
label: 'ruby',
entry: 'vs/basic-languages/ruby/ruby.contribution'
},
{
label: 'rust',
entry: 'vs/basic-languages/rust/rust.contribution'
},
{
label: 'sb',
entry: 'vs/basic-languages/sb/sb.contribution'
},
{
label: 'scala',
entry: 'vs/basic-languages/scala/scala.contribution'
},
{
label: 'scheme',
entry: 'vs/basic-languages/scheme/scheme.contribution'
},
{
label: 'scss',
entry: 'vs/basic-languages/scss/scss.contribution'
},
{
label: 'shell',
entry: 'vs/basic-languages/shell/shell.contribution'
},
{
label: 'solidity',
entry: 'vs/basic-languages/solidity/solidity.contribution'
},
{
label: 'sophia',
entry: 'vs/basic-languages/sophia/sophia.contribution'
},
{
label: 'sparql',
entry: 'vs/basic-languages/sparql/sparql.contribution'
},
{
label: 'sql',
entry: 'vs/basic-languages/sql/sql.contribution'
},
{
label: 'st',
entry: 'vs/basic-languages/st/st.contribution'
},
{
label: 'swift',
entry: 'vs/basic-languages/swift/swift.contribution'
},
{
label: 'systemverilog',
entry: 'vs/basic-languages/systemverilog/systemverilog.contribution'
},
{
label: 'tcl',
entry: 'vs/basic-languages/tcl/tcl.contribution'
},
{
label: 'twig',
entry: 'vs/basic-languages/twig/twig.contribution'
},
{
label: 'typescript',
entry: [
'vs/basic-languages/typescript/typescript.contribution',
'vs/language/typescript/monaco.contribution'
],
worker: {
id: 'vs/language/typescript/tsWorker',
entry: 'vs/language/typescript/ts.worker'
}
},
{
label: 'vb',
entry: 'vs/basic-languages/vb/vb.contribution'
},
{
label: 'xml',
entry: 'vs/basic-languages/xml/xml.contribution'
},
{
label: 'yaml',
entry: 'vs/basic-languages/yaml/yaml.contribution'
}
];
export type EditorLanguage =
| 'abap'
| 'apex'
| 'azcli'
| 'bat'
| 'bicep'
| 'cameligo'
| 'clojure'
| 'coffee'
| 'cpp'
| 'csharp'
| 'csp'
| 'css'
| 'dart'
| 'dockerfile'
| 'ecl'
| 'elixir'
| 'flow9'
| 'fsharp'
| 'go'
| 'graphql'
| 'handlebars'
| 'hcl'
| 'html'
| 'ini'
| 'java'
| 'javascript'
| 'json'
| 'julia'
| 'kotlin'
| 'less'
| 'lexon'
| 'liquid'
| 'lua'
| 'm3'
| 'markdown'
| 'mips'
| 'msdax'
| 'mysql'
| 'objective-c'
| 'pascal'
| 'pascaligo'
| 'perl'
| 'pgsql'
| 'php'
| 'pla'
| 'postiats'
| 'powerquery'
| 'powershell'
| 'protobuf'
| 'pug'
| 'python'
| 'qsharp'
| 'r'
| 'razor'
| 'redis'
| 'redshift'
| 'restructuredtext'
| 'ruby'
| 'rust'
| 'sb'
| 'scala'
| 'scheme'
| 'scss'
| 'shell'
| 'solidity'
| 'sophia'
| 'sparql'
| 'sql'
| 'st'
| 'swift'
| 'systemverilog'
| 'tcl'
| 'twig'
| 'typescript'
| 'vb'
| 'xml'
| 'yaml';

3
webpack-plugin/src/loader-utils.d.ts vendored Normal file
View file

@ -0,0 +1,3 @@
declare module 'loader-utils' {
export function interpolateName(loaderContext: any, name: string, options?: any): string;
}

View file

@ -0,0 +1,21 @@
const loaderUtils = require('loader-utils');
export function pitch(this: any, remainingRequest: any) {
const { globals = undefined, pre = [], post = [] } = loaderUtils.getOptions(this) || {};
// 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
// See https://github.com/webpack/webpack/issues/4613#issuecomment-325178346 for details
if (this._module && this._module.userRequest) {
this._module.userRequest = `include-loader!${this._module.userRequest}`;
}
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)});`)
].join('\n');
}

View file

@ -0,0 +1,63 @@
import type * as webpack from 'webpack';
export interface IAddWorkerEntryPointPluginOptions {
id: string;
entry: string;
filename: string;
chunkFilename?: string;
plugins: webpack.WebpackPluginInstance[];
}
function getCompilerHook(
compiler: webpack.Compiler,
{ id, entry, filename, chunkFilename, plugins }: IAddWorkerEntryPointPluginOptions
) {
const webpack = compiler.webpack ?? require('webpack');
return function (
compilation: webpack.Compilation,
callback: (error?: Error | null | false) => void
) {
const outputOptions = {
filename,
chunkFilename,
publicPath: compilation.outputOptions.publicPath,
// HACK: globalObject is necessary to fix https://github.com/webpack/webpack/issues/6642
globalObject: 'this'
};
const childCompiler = compilation.createChildCompiler(id, outputOptions, [
new webpack.webworker.WebWorkerTemplatePlugin(),
new webpack.LoaderTargetPlugin('webworker')
]);
const SingleEntryPlugin = webpack.EntryPlugin ?? webpack.SingleEntryPlugin;
new SingleEntryPlugin(compiler.context, entry, 'main').apply(childCompiler);
plugins.forEach((plugin) => plugin.apply(childCompiler));
childCompiler.runAsChild((err?: Error) => callback(err));
};
}
export class AddWorkerEntryPointPlugin implements webpack.WebpackPluginInstance {
private readonly options: IAddWorkerEntryPointPluginOptions;
constructor({
id,
entry,
filename,
chunkFilename = undefined,
plugins
}: IAddWorkerEntryPointPluginOptions) {
this.options = { id, entry, filename, chunkFilename, plugins };
}
apply(compiler: webpack.Compiler) {
const webpack = compiler.webpack ?? require('webpack');
const compilerHook = getCompilerHook(compiler, this.options);
const majorVersion = webpack.version.split('.')[0];
if (parseInt(majorVersion) < 4) {
(<any>compiler).plugin('make', compilerHook);
} else {
compiler.hooks.make.tapAsync('AddWorkerEntryPointPlugin', compilerHook);
}
}
}

View file

@ -0,0 +1,10 @@
export interface IWorkerDefinition {
id: string;
entry: string;
}
export interface IFeatureDefinition {
label: string;
entry: string | string[] | undefined;
worker?: IWorkerDefinition;
}