Explorar o código

Merge remote-tracking branch 'origin/master' into pr/jimmydief/83

Alexandru Dima %!s(int64=5) %!d(string=hai) anos
pai
achega
d71d21ec6f
Modificáronse 7 ficheiros con 305 adicións e 369 borrados
  1. 2 0
      README.md
  2. 0 41
      features.js
  3. 8 0
      index.d.ts
  4. 20 22
      index.js
  5. 4 50
      languages.js
  6. 268 253
      package-lock.json
  7. 3 3
      package.json

+ 2 - 0
README.md

@@ -48,6 +48,8 @@ Options can be passed in to `MonacoWebpackPlugin`. They can be used to generate
 
 * `filename` (`string`) - custom filename template for worker scripts, respects the same options as [loader-utils' interpolateName](https://github.com/webpack/loader-utils#interpolatename). Useful for adding content-based hashes so that files can be served with long-lived caching headers.
   * default value: `'[name].worker.js'`.
+* `publicPath` (`string`) - custom public path for worker scripts, overrides 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..
+  * default value: `''`.
 * `languages` (`string[]`) - include only a subset of the languages supported.
   * default value: `['apex', 'azcli', 'bat', 'clojure', 'coffee', 'cpp', 'csharp', 'csp', 'css', 'dockerfile', 'fsharp', 'go', 'handlebars', 'html', 'ini', 'java', 'javascript', 'json', 'less', 'lua', 'markdown', 'msdax', 'mysql', 'objective', 'perl', 'pgsql', 'php', 'postiats', 'powerquery', 'powershell', 'pug', 'python', 'r', 'razor', 'redis', 'redshift', 'ruby', 'rust', 'sb', 'scheme', 'scss', 'shell', 'solidity', 'sql', 'st', 'swift', 'typescript', 'vb', 'xml', 'yaml']`.
 

+ 0 - 41
features.js

@@ -1,169 +1,128 @@
 module.exports = {
   accessibilityHelp: {
     entry: 'vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp',
-    worker: undefined,
   },
   bracketMatching: {
     entry: 'vs/editor/contrib/bracketMatching/bracketMatching',
-    worker: undefined,
   },
   caretOperations: {
     entry: 'vs/editor/contrib/caretOperations/caretOperations',
-    worker: undefined,
   },
   clipboard: {
     entry: 'vs/editor/contrib/clipboard/clipboard',
-    worker: undefined,
   },
   codeAction: {
     entry: 'vs/editor/contrib/codeAction/codeActionContributions',
-    worker: undefined,
   },
   codelens: {
     entry: 'vs/editor/contrib/codelens/codelensController',
-    worker: undefined,
   },
   colorDetector: {
     entry: 'vs/editor/contrib/colorPicker/colorDetector',
-    worker: undefined,
   },
   comment: {
     entry: 'vs/editor/contrib/comment/comment',
-    worker: undefined,
   },
   contextmenu: {
     entry: 'vs/editor/contrib/contextmenu/contextmenu',
-    worker: undefined,
   },
   coreCommands: {
     entry: 'vs/editor/browser/controller/coreCommands',
-    worker: undefined,
   },
   cursorUndo: {
     entry: 'vs/editor/contrib/cursorUndo/cursorUndo',
-    worker: undefined,
   },
   dnd: {
     entry: 'vs/editor/contrib/dnd/dnd',
-    worker: undefined,
   },
   find: {
     entry: 'vs/editor/contrib/find/findController',
-    worker: undefined,
   },
   folding: {
     entry: 'vs/editor/contrib/folding/folding',
-    worker: undefined,
   },
   fontZoom: {
     entry: 'vs/editor/contrib/fontZoom/fontZoom',
-    worker: undefined,
   },
   format: {
     entry: 'vs/editor/contrib/format/formatActions',
-    worker: undefined,
   },
   goToDefinitionCommands: {
     entry: 'vs/editor/contrib/goToDefinition/goToDefinitionCommands',
-    worker: undefined,
   },
   goToDefinitionMouse: {
     entry: 'vs/editor/contrib/goToDefinition/goToDefinitionMouse',
-    worker: undefined,
   },
   gotoError: {
     entry: 'vs/editor/contrib/gotoError/gotoError',
-    worker: undefined,
   },
   gotoLine: {
     entry: 'vs/editor/standalone/browser/quickOpen/gotoLine',
-    worker: undefined,
   },
   hover: {
     entry: 'vs/editor/contrib/hover/hover',
-    worker: undefined,
   },
   inPlaceReplace: {
     entry: 'vs/editor/contrib/inPlaceReplace/inPlaceReplace',
-    worker: undefined,
   },
   inspectTokens: {
     entry: 'vs/editor/standalone/browser/inspectTokens/inspectTokens',
-    worker: undefined,
   },
   iPadShowKeyboard: {
     entry: 'vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard',
-    worker: undefined,
   },
   linesOperations: {
     entry: 'vs/editor/contrib/linesOperations/linesOperations',
-    worker: undefined,
   },
   links: {
     entry: 'vs/editor/contrib/links/links',
-    worker: undefined,
   },
   multicursor: {
     entry: 'vs/editor/contrib/multicursor/multicursor',
-    worker: undefined,
   },
   parameterHints: {
     entry: 'vs/editor/contrib/parameterHints/parameterHints',
-    worker: undefined,
   },
   quickCommand: {
     entry: 'vs/editor/standalone/browser/quickOpen/quickCommand',
-    worker: undefined,
   },
   quickOutline: {
     entry: 'vs/editor/standalone/browser/quickOpen/quickOutline',
-    worker: undefined,
   },
   referenceSearch: {
     entry: [
       'vs/editor/contrib/referenceSearch/referenceSearch',
       'vs/editor/standalone/browser/referenceSearch/standaloneReferenceSearch',
     ],
-    worker: undefined,
   },
   rename: {
     entry: 'vs/editor/contrib/rename/rename',
-    worker: undefined,
   },
   smartSelect: {
     entry: 'vs/editor/contrib/smartSelect/smartSelect',
-    worker: undefined,
   },
   snippets: {
     entry: 'vs/editor/contrib/snippet/snippetController2',
-    worker: undefined,
   },
   suggest: {
     entry: 'vs/editor/contrib/suggest/suggestController',
-    worker: undefined,
   },
   toggleHighContrast: {
     entry: 'vs/editor/standalone/browser/toggleHighContrast/toggleHighContrast',
-    worker: undefined,
   },
   toggleTabFocusMode: {
     entry: 'vs/editor/contrib/toggleTabFocusMode/toggleTabFocusMode',
-    worker: undefined,
   },
   transpose: {
     entry: 'vs/editor/contrib/caretOperations/transpose',
-    worker: undefined,
   },
   wordHighlighter: {
     entry: 'vs/editor/contrib/wordHighlighter/wordHighlighter',
-    worker: undefined,
   },
   wordOperations: {
     entry: 'vs/editor/contrib/wordOperations/wordOperations',
-    worker: undefined,
   },
   wordPartOperations: {
     entry: 'vs/editor/contrib/wordPartOperations/wordPartOperations',
-    worker: undefined,
   },
 };

+ 8 - 0
index.d.ts

@@ -17,6 +17,14 @@ interface IMonacoEditorWebpackPluginOpts {
      * Use e.g. '[name].worker.[contenthash].js' to include content-based hashes.
      */
     filename?: 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;
 }
 
 declare class MonacoEditorWebpackPlugin extends Plugin {

+ 20 - 22
index.js

@@ -14,7 +14,6 @@ const EDITOR_MODULE = {
     entry: 'vs/editor/editor.worker',
     fallback: undefined
   },
-  alias: undefined,
 };
 const LANGUAGES = require('./languages');
 const FEATURES = require('./features');
@@ -35,11 +34,7 @@ function getWorkerFilename(filename, entry) {
   });
 }
 
-const languagesById = fromPairs(
-  flatMap(toPairs(LANGUAGES), ([id, language]) =>
-    [id].concat(language.alias || []).map((label) => [label, mixin({ label }, language)])
-  )
-);
+const languagesById = mapValues(LANGUAGES, (language, id) => mixin({ label: id }, language));
 const featuresById = mapValues(FEATURES, (feature, key) => mixin({ label: key }, feature))
 
 function getFeaturesIds(userFeatures, predefinedFeaturesById) {
@@ -70,18 +65,19 @@ class MonacoWebpackPlugin {
     this.options = {
       languages: languages.map((id) => languagesById[id]).filter(Boolean),
       features: features.map(id => featuresById[id]).filter(Boolean),
-      filename: options.filename || "[name].worker.js"
+      filename: options.filename || "[name].worker.js",
+      publicPath: options.publicPath || '',
     };
   }
 
   apply(compiler) {
-    const { languages, features, filename } = this.options;
-    const publicPath = getPublicPath(compiler);
+    const { languages, features, filename, publicPath } = this.options;
+    const compilationPublicPath = getCompilationPublicPath(compiler);
     const modules = [EDITOR_MODULE].concat(languages).concat(features);
     const workers = modules.map(
-      ({ label, alias, worker }) => worker && (mixin({ label, alias }, worker))
+      ({ label, worker }) => worker && (mixin({ label }, worker))
     ).filter(Boolean);
-    const rules = createLoaderRules(languages, features, workers, publicPath, filename);
+    const rules = createLoaderRules(languages, features, workers, filename, publicPath, compilationPublicPath);
     const plugins = createPlugins(workers, filename);
     addCompilerRules(compiler, rules);
     addCompilerPlugins(compiler, plugins);
@@ -98,11 +94,11 @@ function addCompilerPlugins(compiler, plugins) {
   plugins.forEach((plugin) => plugin.apply(compiler));
 }
 
-function getPublicPath(compiler) {
+function getCompilationPublicPath(compiler) {
   return compiler.options.output && compiler.options.output.publicPath || '';
 }
 
-function createLoaderRules(languages, features, workers, publicPath, filename) {
+function createLoaderRules(languages, features, workers, filename, pluginPublicPath, compilationPublicPath) {
   if (!languages.length && !features.length) { return []; }
   const languagePaths = flatArr(languages.map(({ entry }) => entry).filter(Boolean));
   const featurePaths = flatArr(features.map(({ entry }) => entry).filter(Boolean));
@@ -123,6 +119,16 @@ function createLoaderRules(languages, features, workers, publicPath, filename) {
     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) {
@@ -130,7 +136,7 @@ function createLoaderRules(languages, features, workers, publicPath, filename) {
       }
       return {
         getWorkerUrl: function (moduleId, label) {
-          var pathPrefix = (typeof window.__webpack_public_path__ === 'string' ? window.__webpack_public_path__ : ${JSON.stringify(publicPath)});
+          var pathPrefix = ${pathPrefix};
           return (pathPrefix ? stripTrailingSlash(pathPrefix) + '/' : '') + paths[label];
         }
       };
@@ -169,10 +175,6 @@ function createPlugins(workers, filename) {
   );
 }
 
-function flatMap(items, iteratee) {
-  return items.map(iteratee).reduce((acc, item) => [].concat(acc).concat(item), []);
-}
-
 function flatArr(items) {
   return items.reduce((acc, item) => {
     if (Array.isArray(item)) {
@@ -182,10 +184,6 @@ function flatArr(items) {
   }, []);
 }
 
-function toPairs(object) {
-  return Object.keys(object).map((key) => [key, object[key]]);
-}
-
 function fromPairs(values) {
   return values.reduce((acc, [key, value]) => Object.assign(acc, { [key]: value }), {});
 }

+ 4 - 50
languages.js

@@ -2,42 +2,34 @@ module.exports = {
   apex: {
     entry: 'vs/basic-languages/apex/apex.contribution',
     worker: undefined,
-    alias: undefined,
   },
   azcli: {
     entry: 'vs/basic-languages/azcli/azcli.contribution',
     worker: undefined,
-    alias: undefined,
   },
   bat: {
     entry: 'vs/basic-languages/bat/bat.contribution',
     worker: undefined,
-    alias: undefined,
   },
   clojure: {
     entry: 'vs/basic-languages/clojure/clojure.contribution',
     worker: undefined,
-    alias: undefined,
   },
   coffee: {
     entry: 'vs/basic-languages/coffee/coffee.contribution',
     worker: undefined,
-    alias: undefined,
   },
   cpp: {
     entry: 'vs/basic-languages/cpp/cpp.contribution',
     worker: undefined,
-    alias: undefined,
   },
   csharp: {
     entry: 'vs/basic-languages/csharp/csharp.contribution',
     worker: undefined,
-    alias: undefined,
   },
   csp: {
     entry: 'vs/basic-languages/csp/csp.contribution',
     worker: undefined,
-    alias: undefined,
   },
   css: {
     entry: [
@@ -49,27 +41,26 @@ module.exports = {
       entry: 'vs/language/css/css.worker',
       fallback: 'vs/language/css/cssWorker',
     },
-    alias: undefined,
   },
   dockerfile: {
     entry: 'vs/basic-languages/dockerfile/dockerfile.contribution',
     worker: undefined,
-    alias: undefined,
   },
   fsharp: {
     entry: 'vs/basic-languages/fsharp/fsharp.contribution',
     worker: undefined,
-    alias: undefined,
   },
   go: {
     entry: 'vs/basic-languages/go/go.contribution',
     worker: undefined,
-    alias: undefined,
+  },
+  graphql: {
+    entry: 'vs/basic-languages/graphql/graphql.contribution',
+    worker: undefined,
   },
   handlebars: {
     entry: 'vs/basic-languages/handlebars/handlebars.contribution',
     worker: undefined,
-    alias: undefined,
   },
   html: {
     entry: [
@@ -81,22 +72,18 @@ module.exports = {
       entry: 'vs/language/html/html.worker',
       fallback: 'vs/language/html/htmlWorker',
     },
-    alias: undefined,
   },
   ini: {
     entry: 'vs/basic-languages/ini/ini.contribution',
     worker: undefined,
-    alias: undefined,
   },
   java: {
     entry: 'vs/basic-languages/java/java.contribution',
     worker: undefined,
-    alias: undefined,
   },
   javascript: {
     entry: 'vs/basic-languages/javascript/javascript.contribution',
     worker: undefined,
-    alias: undefined,
   },
   json: {
     entry: 'vs/language/json/monaco.contribution',
@@ -105,147 +92,118 @@ module.exports = {
       entry: 'vs/language/json/json.worker',
       fallback: 'vs/language/json/jsonWorker',
     },
-    alias: undefined,
   },
   less: {
     entry: 'vs/basic-languages/less/less.contribution',
     worker: undefined,
-    alias: undefined,
   },
   lua: {
     entry: 'vs/basic-languages/lua/lua.contribution',
     worker: undefined,
-    alias: undefined,
   },
   markdown: {
     entry: 'vs/basic-languages/markdown/markdown.contribution',
     worker: undefined,
-    alias: undefined,
   },
   msdax: {
     entry: 'vs/basic-languages/msdax/msdax.contribution',
     worker: undefined,
-    alias: undefined,
   },
   mysql: {
     entry: 'vs/basic-languages/mysql/mysql.contribution',
     worker: undefined,
-    alias: undefined,
   },
   objective: {
     entry: 'vs/basic-languages/objective-c/objective-c.contribution',
     worker: undefined,
-    alias: undefined,
   },
   perl: {
     entry: 'vs/basic-languages/perl/perl.contribution',
     worker: undefined,
-    alias: undefined,
   },
   pgsql: {
     entry: 'vs/basic-languages/pgsql/pgsql.contribution',
     worker: undefined,
-    alias: undefined,
   },
   php: {
     entry: 'vs/basic-languages/php/php.contribution',
     worker: undefined,
-    alias: undefined,
   },
   postiats: {
     entry: 'vs/basic-languages/postiats/postiats.contribution',
     worker: undefined,
-    alias: undefined,
   },
   powerquery: {
     entry: 'vs/basic-languages/powerquery/powerquery.contribution',
     worker: undefined,
-    alias: undefined,
   },
   powershell: {
     entry: 'vs/basic-languages/powershell/powershell.contribution',
     worker: undefined,
-    alias: undefined,
   },
   pug: {
     entry: 'vs/basic-languages/pug/pug.contribution',
     worker: undefined,
-    alias: undefined,
   },
   python: {
     entry: 'vs/basic-languages/python/python.contribution',
     worker: undefined,
-    alias: undefined,
   },
   r: {
     entry: 'vs/basic-languages/r/r.contribution',
     worker: undefined,
-    alias: undefined,
   },
   razor: {
     entry: 'vs/basic-languages/razor/razor.contribution',
     worker: undefined,
-    alias: undefined,
   },
   redis: {
     entry: 'vs/basic-languages/redis/redis.contribution',
     worker: undefined,
-    alias: undefined,
   },
   redshift: {
     entry: 'vs/basic-languages/redshift/redshift.contribution',
     worker: undefined,
-    alias: undefined,
   },
   ruby: {
     entry: 'vs/basic-languages/ruby/ruby.contribution',
     worker: undefined,
-    alias: undefined,
   },
   rust: {
     entry: 'vs/basic-languages/rust/rust.contribution',
     worker: undefined,
-    alias: undefined,
   },
   sb: {
     entry: 'vs/basic-languages/sb/sb.contribution',
     worker: undefined,
-    alias: undefined,
   },
   scheme: {
     entry: 'vs/basic-languages/scheme/scheme.contribution',
     worker: undefined,
-    alias: undefined,
   },
   scss: {
     entry: 'vs/basic-languages/scss/scss.contribution',
     worker: undefined,
-    alias: undefined,
   },
   shell: {
     entry: 'vs/basic-languages/shell/shell.contribution',
     worker: undefined,
-    alias: undefined,
   },
   solidity: {
     entry: 'vs/basic-languages/solidity/solidity.contribution',
     worker: undefined,
-    alias: undefined,
   },
   sql: {
     entry: 'vs/basic-languages/sql/sql.contribution',
     worker: undefined,
-    alias: undefined,
   },
   st: {
     entry: 'vs/basic-languages/st/st.contribution',
     worker: undefined,
-    alias: undefined,
   },
   swift: {
     entry: 'vs/basic-languages/swift/swift.contribution',
     worker: undefined,
-    alias: undefined,
   },
   typescript: {
     entry: [
@@ -257,21 +215,17 @@ module.exports = {
       entry: 'vs/language/typescript/ts.worker',
       fallback: 'vs/language/typescript/tsWorker',
     },
-    alias: undefined,
   },
   vb: {
     entry: 'vs/basic-languages/vb/vb.contribution',
     worker: undefined,
-    alias: undefined,
   },
   xml: {
     entry: 'vs/basic-languages/xml/xml.contribution',
     worker: undefined,
-    alias: undefined,
   },
   yaml: {
     entry: 'vs/basic-languages/yaml/yaml.contribution',
     worker: undefined,
-    alias: undefined,
   },
 };

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 268 - 253
package-lock.json


+ 3 - 3
package.json

@@ -25,17 +25,17 @@
   "homepage": "https://github.com/Microsoft/monaco-editor-webpack-plugin#readme",
   "peerDependencies": {
     "webpack": "^4.5.0",
-    "monaco-editor": "^0.15.1"
+    "monaco-editor": "^0.17.0"
   },
   "devDependencies": {
+    "@types/webpack": "^4.4.19",
     "css-loader": "^1.0.1",
-    "monaco-editor": "^0.15.6",
+    "monaco-editor": "^0.17.0",
     "style-loader": "^0.23.1",
     "webpack": "^4.25.1",
     "webpack-cli": "^3.1.2"
   },
   "dependencies": {
-    "@types/webpack": "^4.4.19",
     "loader-utils": "^1.2.3"
   }
 }

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio