Socket
Socket
Sign inDemoInstall

rollup-plugin-monaco-editor

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-monaco-editor - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

6

dist/index.d.ts

@@ -48,3 +48,9 @@ import { Plugin } from 'rollup';

pathPrefix?: string;
/**
* Normally, sourcemap is generated by default. You can set
* sourcemap to false to disable generate it, which makes build faster.
* @default true;
*/
sourcemap?: boolean;
}
declare function monaco(options?: MonacoPluginOptions): Plugin;

94

dist/rollup-plugin-monaco-editor.cjs.development.js

@@ -13,2 +13,3 @@ 'use strict';

var recast = require('recast');
var MagicString = _interopDefault(require('magic-string'));

@@ -1190,2 +1191,14 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {

var hasMonacoEntry = false;
var shouldGenerateSourcemap = options.sourcemap !== false;
function getMapFromCode(code) {
if (shouldGenerateSourcemap) {
return new MagicString(code).generateMap({
hires: true
});
}
return null;
}
return {

@@ -1318,3 +1331,7 @@ name: 'monaco',

if (modifiedCode) {
return modifiedCode;
var map = getMapFromCode(modifiedCode);
return {
code: modifiedCode,
map: map
};
}

@@ -1350,3 +1367,3 @@

return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
var arr, languageImportIds, hasImportRegisterLanguage, languageCodes, basicContribPath, basicContribCode;
var arr, languageImportIds, hasImportRegisterLanguage, languageCodes, basicContribPath, basicContribCode, transformedCode, map;
return runtime_1.wrap(function _callee3$(_context3) {

@@ -1373,3 +1390,3 @@ while (1) {

if (!MONACO_ENTRY_RE.test(id)) {
_context3.next = 22;
_context3.next = 30;
break;

@@ -1400,13 +1417,3 @@ }

c = _context2.sent.toString();
// FIXME: use this.parse to handle this
// 1. fix circular dependency
c = c.replace(/import\s['"]\.\.\/\.\.\/editor\/editor\.api\.js['"];?/, ''); // 2. fillers/monaco-editor-core is same with editor.api, remove it
// 2. fillers/monaco-editor-core is same with editor.api, remove it
c = c.replace(/import\s+.*from ['"]\.\/fillers\/monaco-editor-core\.js['"];?/, ''); // 2.2 dedup import * as monaco_editor_core_star from "../../editor/editor.api.js";
// 2.2 dedup import * as monaco_editor_core_star from "../../editor/editor.api.js";
c = c.replace(/import\s+\*\s+as\s+monaco_editor_core_star\s+from\s+["']\.\.\/\.\.\/editor\/editor\.api\.js["'];?/, ''); // 3. rename getMode to getXXXMode
// 3. rename getMode to getXXXMode
// 1. rename getMode to getXXXMode
c = c.replace(/getMode\(\)/g, function () {

@@ -1416,11 +1423,11 @@ var languageFilename = slash(importId).split('/').slice(-3, -1).join('_');

return "get" + langName + "Mode()";
}); // 4. dedup import { registerLanguage } from '../_.contribution.js';
}); // 2. dedup import { registerLanguage } from '../_.contribution.js';
// 4. dedup import { registerLanguage } from '../_.contribution.js';
// 2. dedup import { registerLanguage } from '../_.contribution.js';
c = c.replace(/import\s+{\s+registerLanguage\s+}\s+from\s+['"]\.\.\/_\.contribution\.js['"];?/, function () {
hasImportRegisterLanguage = true;
return '';
}); // 5. import('./foo') -> import('$relative/foo');
}); // 3. import('./foo') -> import('$relative/foo');
_context2.next = 10;
_context2.next = 7;
return transformImports(c, function (spec) {

@@ -1436,7 +1443,7 @@ if (spec[0] === '.') {

case 10:
case 7:
c = _context2.sent;
return _context2.abrupt("return", c);
case 12:
case 9:
case "end":

@@ -1456,2 +1463,4 @@ return _context2.stop();

languageCodes = _context3.sent;
// mock the dist code src/fillers/monaco-editor-core.ts
arr.push('var monaco_editor_core_exports = api;');

@@ -1464,9 +1473,7 @@ if (!hasImportRegisterLanguage) {

basicContribPath = resolveMonacoPath('vs/basic-languages/_.contribution');
_context3.next = 17;
_context3.next = 18;
return fs.promises.readFile(basicContribPath, 'utf-8');
case 17:
case 18:
basicContribCode = _context3.sent;
// fillers/monaco-editor-core is same with editor.api, remove it
basicContribCode = basicContribCode.replace(/import\s+.*from ['"]\.\/fillers\/monaco-editor-core\.js['"];?/, '');
arr = arr.concat(basicContribCode);

@@ -1476,11 +1483,42 @@

arr = arr.concat(languageCodes);
transformedCode = arr.join('\n');
/**
* Fix circular dependencies to transformed code
* FIXME: use this.parse to handle this
*/
// 1. dedup editor.api.js
// import "../../editor/editor.api.js";
// import "../editor/editor.api.js";
// import "editor/editor.api.js";
transformedCode = transformedCode.replace(/import\s['"](?:(?:\.\.\/)+editor\/)?editor\.api\.js['"];?/g, ''); // 2. fillers/monaco-editor-core is same with editor.api, remove it
// import { Emitter, languages } from '../language/json/fillers/monaco-editor-core.js';
// import from './fillers/monaco-editor.core.js'
transformedCode = transformedCode.replace(/import\s+.*from ['"](?:.*)\/fillers\/monaco-editor-core\.js['"];?/g, '');
/**
* // 2.2 monaco_editor_core_star
* // src/fillers/monaco-editor-core.ts
* var monaco_editor_core_exports = {};
* __markAsModule(monaco_editor_core_exports);
* __reExport(monaco_editor_core_exports, monaco_editor_core_star);
* import * as monaco_editor_core_star from "../editor/editor.api.js";
* import * as monaco_editor_core_star from "../../editor/editor.api.js";
* import * as monaco_editor_core_star from "editor.api.js";
*/
transformedCode = transformedCode.replace(/var monaco_editor_core_exports = {};/g, '');
transformedCode = transformedCode.replace(/__markAsModule\(monaco_editor_core_exports\);/g, '');
transformedCode = transformedCode.replace(/__reExport\(monaco_editor_core_exports, monaco_editor_core_star\);/g, '');
transformedCode = transformedCode.replace(/import\s+\*\s+as\s+monaco_editor_core_star\s+from\s+["'](?:(?:\.\.\/)+editor\/)?editor\.api\.js["'];?/g, '');
map = getMapFromCode(transformedCode);
return _context3.abrupt("return", {
code: arr.join('\n'),
map: null
code: transformedCode,
map: map
});
case 22:
case 30:
return _context3.abrupt("return", null);
case 23:
case 31:
case "end":

@@ -1487,0 +1525,0 @@ return _context3.stop();

@@ -1,2 +0,2 @@

"use strict";function r(r){return r&&"object"==typeof r&&"default"in r?r.default:r}Object.defineProperty(exports,"__esModule",{value:!0});var t=r(require("path")),e=require("fs"),n=r(e),o=require("es-module-lexer"),i=r(require("semver")),a=require("recast");function u(r,t,e,n,o,i,a){try{var u=r[i](a),c=u.value}catch(r){return void e(r)}u.done?t(c):Promise.resolve(c).then(n,o)}function c(r){return function(){var t=this,e=arguments;return new Promise((function(n,o){var i=r.apply(t,e);function a(r){u(i,n,o,a,c,"next",r)}function c(r){u(i,n,o,a,c,"throw",r)}a(void 0)}))}}function s(){return(s=Object.assign||function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r}).apply(this,arguments)}function l(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=new Array(t);e<t;e++)n[e]=r[e];return n}function f(r,t){var e="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(e)return(e=e.call(r)).next.bind(e);if(Array.isArray(r)||(e=function(r,t){if(r){if("string"==typeof r)return l(r,void 0);var e=Object.prototype.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?l(r,void 0):void 0}}(r))||t&&r&&"number"==typeof r.length){e&&(r=e);var n=0;return function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var p,h=(function(r){var t=function(r){var t=Object.prototype,e=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(r,t,e){return Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}),r[t]}try{u({},"")}catch(r){u=function(r,t,e){return r[t]=e}}function c(r,t,e,n){var o=Object.create((t&&t.prototype instanceof f?t:f).prototype),i=new E(n||[]);return o._invoke=function(r,t,e){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var u=w(a,e);if(u){if(u===l)continue;return u}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if("suspendedStart"===n)throw n="completed",e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n="executing";var c=s(r,t,e);if("normal"===c.type){if(n=e.done?"completed":"suspendedYield",c.arg===l)continue;return{value:c.arg,done:e.done}}"throw"===c.type&&(n="completed",e.method="throw",e.arg=c.arg)}}}(r,e,i),o}function s(r,t,e){try{return{type:"normal",arg:r.call(t,e)}}catch(r){return{type:"throw",arg:r}}}r.wrap=c;var l={};function f(){}function p(){}function h(){}var d={};u(d,o,(function(){return this}));var v=Object.getPrototypeOf,m=v&&v(v(O([])));m&&m!==t&&e.call(m,o)&&(d=m);var y=h.prototype=f.prototype=Object.create(d);function g(r){["next","throw","return"].forEach((function(t){u(r,t,(function(r){return this._invoke(t,r)}))}))}function b(r,t){var n;this._invoke=function(o,i){function a(){return new t((function(n,a){!function n(o,i,a,u){var c=s(r[o],r,i);if("throw"!==c.type){var l=c.arg,f=l.value;return f&&"object"==typeof f&&e.call(f,"__await")?t.resolve(f.__await).then((function(r){n("next",r,a,u)}),(function(r){n("throw",r,a,u)})):t.resolve(f).then((function(r){l.value=r,a(l)}),(function(r){return n("throw",r,a,u)}))}u(c.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function w(r,t){var e=r.iterator[t.method];if(void 0===e){if(t.delegate=null,"throw"===t.method){if(r.iterator.return&&(t.method="return",t.arg=void 0,w(r,t),"throw"===t.method))return l;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=s(e,r.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,l;var o=n.arg;return o?o.done?(t[r.resultName]=o.value,t.next=r.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,l):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,l)}function x(r){var t={tryLoc:r[0]};1 in r&&(t.catchLoc=r[1]),2 in r&&(t.finallyLoc=r[2],t.afterLoc=r[3]),this.tryEntries.push(t)}function j(r){var t=r.completion||{};t.type="normal",delete t.arg,r.completion=t}function E(r){this.tryEntries=[{tryLoc:"root"}],r.forEach(x,this),this.reset(!0)}function O(r){if(r){var t=r[o];if(t)return t.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function t(){for(;++n<r.length;)if(e.call(r,n))return t.value=r[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:k}}function k(){return{value:void 0,done:!0}}return p.prototype=h,u(y,"constructor",h),u(h,"constructor",p),p.displayName=u(h,a,"GeneratorFunction"),r.isGeneratorFunction=function(r){var t="function"==typeof r&&r.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},r.mark=function(r){return Object.setPrototypeOf?Object.setPrototypeOf(r,h):(r.__proto__=h,u(r,a,"GeneratorFunction")),r.prototype=Object.create(y),r},r.awrap=function(r){return{__await:r}},g(b.prototype),u(b.prototype,i,(function(){return this})),r.AsyncIterator=b,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new b(c(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(r){return r.done?r.value:a.next()}))},g(y),u(y,a,"Generator"),u(y,o,(function(){return this})),u(y,"toString",(function(){return"[object Generator]"})),r.keys=function(r){var t=[];for(var e in r)t.push(e);return t.reverse(),function e(){for(;t.length;){var n=t.pop();if(n in r)return e.value=n,e.done=!1,e}return e.done=!0,e}},r.values=O,E.prototype={constructor:E,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(j),!r)for(var t in this)"t"===t.charAt(0)&&e.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var r=this.tryEntries[0].completion;if("throw"===r.type)throw r.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var t=this;function n(e,n){return a.type="throw",a.arg=r,t.next=e,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=e.call(i,"catchLoc"),c=e.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(r,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&e.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===r||"continue"===r)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=r,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,l):this.complete(a)},complete:function(r,t){if("throw"===r.type)throw r.arg;return"break"===r.type||"continue"===r.type?this.next=r.arg:"return"===r.type?(this.rval=this.arg=r.arg,this.method="return",this.next="end"):"normal"===r.type&&t&&(this.next=t),l},finish:function(r){for(var t=this.tryEntries.length-1;t>=0;--t){var e=this.tryEntries[t];if(e.finallyLoc===r)return this.complete(e.completion,e.afterLoc),j(e),l}},catch:function(r){for(var t=this.tryEntries.length-1;t>=0;--t){var e=this.tryEntries[t];if(e.tryLoc===r){var n=e.completion;if("throw"===n.type){var o=n.arg;j(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,t,e){return this.delegate={iterator:O(r),resultName:t,nextLoc:e},"next"===this.method&&(this.arg=void 0),l}},r}(r.exports);try{regeneratorRuntime=t}catch(r){"object"==typeof globalThis?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}}(p={exports:{}}),p.exports),d=function(r,t){return r.endsWith(t)},v=function(r,t){return"\0"+r+t},m=function(r){var t=/^\\\\\?\\/.test(r),e=/[^\u0000-\u0080]+/.test(r);return t||e?r:r.replace(/\\/g,"/")},y=new Set("break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public".split(" ").concat("Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl".split(" "))),g=/[^$_a-zA-Z0-9]/g,b=/\s*(['"])(.*)\1\s*$/m;function w(r,t){return x.apply(this,arguments)}function x(){return(x=c(h.mark((function r(t,e){var n,i,a,u,c,s,l,p;return h.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:n=[];try{i=o.parse(t),n=i[0]}catch(r){}for(n=n.filter((function(r){return!(-2===r.d||r.d>-1&&!t.substring(r.s,r.e).match(b))})).reverse(),a=f(n);!(u=a()).done;)s=t.substring((c=u.value).s,c.e),c.d>-1&&(l=s.match(b),s=l[2]),(p=e(s))!==s&&(c.d>-1&&(p=JSON.stringify(p)),t=t.slice(0,c.s)+p+t.slice(c.e));return r.abrupt("return",t);case 5:case"end":return r.stop()}}),r)})))).apply(this,arguments)}var j=a.types.builders,E=[],O=[];!function(){var r=require.resolve("monaco-editor/package.json");try{!function(r){var e=t.join(t.dirname(r.monacoEditorPackageJsonPath),"esm/metadata.js"),n=require(e);if(!n.features||!n.languages)throw new Error("features or languages not found in metadata");E=n.features,O=n.languages}({monacoEditorPackageJsonPath:r})}catch(t){!function(r){for(var t=JSON.parse(n.readFileSync(r.monacoEditorPackageJsonPath,"utf-8")).version,e=require("../plugin/versionMapping"),o=null,a=0,u=Object.entries(e.versionMapping);a<u.length;a++){var c=u[a],s=c[0];if(c[1].some((function(r){return i.satisfies(t,r)}))){o=s;break}}if(!o)throw new Error("[rollup-plugin-monaco-editor] current monaco-editor version("+t+") are not supported, please file a issue at\nhttps://github.com/chengcyber/rollup-plugin-monaco-editor/issues");var l="../plugin/out/"+o.replace(/\*/g,"_x_"),f=require(l+"/features.js");E=f.featuresArr;var p=require(l+"/languages.js");O=p.languagesArr}({monacoEditorPackageJsonPath:r})}}();var k=E.reduce((function(r,t){return r[t.label]=t,r}),{}),S=O.reduce((function(r,t){return r[t.label]=t,r}),{}),_=/monaco-editor[/\\]esm[/\\]vs[/\\]editor[/\\]editor.(api|main)/,L={label:"editorWorkerService",entry:void 0,worker:{id:"vs/editor/editor",entry:"vs/editor/editor.worker"}};function A(r){return require.resolve(P(r))}function P(r){return t.join("monaco-editor/esm",r+".js")}function N(r){return r.filter(Boolean)}function I(r){return r.reduce((function(r,t){return Array.isArray(t)?[].concat(r).concat(t):[].concat(r).concat([t])}),[])}exports.default=function(r){void 0===r&&(r={});var n=r.languages||Object.keys(S),i=function(r){var t,e=[];if(r.length){var n=r.filter((function(r){return"!"===r[0]})).map((function(r){return r.slice(1)}));e=n.length?Object.keys(k).filter((t=n,function(r){return-1===t.indexOf(r)})):r}else e=Object.keys(k);return e}(r.features||[]),u=!1;"esm"in r&&(u=!!r.esm);var l=N(n.map((function(r){return S[r]}))),f=N(i.map((function(r){return k[r]}))),p=[L].concat(l).concat(f),b=[];p.forEach((function(r){"worker"in r&&r.worker&&b.push({label:r.label,id:r.worker.id,entry:r.worker.entry})}));for(var x=I(N(l.map((function(r){return r.entry})))),E=I(N(f.map((function(r){return r.entry})))),O={},U=0,F=b;U<F.length;U++){var R=F[U];O[R.label]=P(R.entry)}var q=!1;function J(r){if(!q){q=!0;for(var t=0,e=Object.entries(O);t<e.length;t++){var n=e[t][1];r({type:"chunk",id:require.resolve(n),fileName:n})}}}var M=!1;return{name:"monaco",options:function(r){var t=s({},r),e=r.moduleContext;return t.moduleContext="function"==typeof e?function(r){return m(r).indexOf("node_modules/monaco-editor")>=0?"self":e(r)}:e&&"object"==typeof e?function(r){return m(r).indexOf("node_modules/monaco-editor")>=0?"self":e[r]}:function(r){if(m(r).indexOf("node_modules/monaco-editor")>=0)return"self"},t},buildStart:function(){return c(h.mark((function r(){return h.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,o.init;case 2:case"end":return r.stop()}}),r)})))()},renderChunk:function(t,e,n){if(!M)return null;var o=null,i=Array.from(this.getModuleIds()).some((function(r){return _.test(r)})),c=Object.values(O).includes(e.fileName);if(i&&!c&&(("es"===n.format||u)&&(o=t.replace(/(?<!\/\/.*)new Worker\((.*)\);/g,(function(r,t){var e=a.parse(r),n=e.program.body[0].expression.arguments;if(1===n.length)n.push(j.objectExpression([j.property("init",j.identifier("type"),j.literal("module"))]));else if(2===n.length){var o=n[1];"ObjectExpression"===o.type&&o.properties.push(j.property("init",j.identifier("type"),j.literal("module")))}return a.print(e).code}))),e.isEntry)){var s=r.pathPrefix;if(!s){var l=n.dir;l?(s=l).startsWith("/")||(s="/"+s):this.warn("rollup outputOptions.dir is missing")}s||(s="");var f={MonacoEnvironment:"(function (paths) {\n function stripTrailingSlash(str) {\n return str.replace(/\\/$/, '');\n }\n return {\n getWorkerUrl: function (moduleId, label) {\n var pathPrefix = "+JSON.stringify(s)+";\n var result = (pathPrefix ? stripTrailingSlash(pathPrefix) + '/' : '') + paths[label];\n if (/^((http:)|(https:)|(file:)|(\\/\\/))/.test(result)) {\n var currentUrl = String(window.location);\n var currentOrigin = currentUrl.substr(0, currentUrl.length - window.location.hash.length - window.location.search.length - window.location.pathname.length);\n if (result.substring(0, currentOrigin.length) !== currentOrigin) {\n var js = '/*' + label + '*/importScripts(\"' + result + '\");';\n var blob = new Blob([js], { type: 'application/javascript' });\n return URL.createObjectURL(blob);\n }\n }\n return result;\n }\n };\n })("+JSON.stringify(O,null,2)+")"};o=[].concat(f?Object.keys(f).map((function(r){return"self["+JSON.stringify(r)+"] = "+f[r]+";"})):[],[o||t]).join("\n")}return o||null},resolveId:function(r,t){return d(r,"?monaco-features")?r:null},load:function(r){return d(r,"?monaco-features")?""+E.map((function(r){return A(r)})).map((function(r){return"import "+JSON.stringify(r)+";"})).join("\n"):null},transform:function(r,n){var o=this;return c(h.mark((function i(){var a,u,s,l,f,p;return h.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:if(!n.startsWith("\0")){i.next=2;break}return i.abrupt("return",null);case 2:if(t.isAbsolute(n)){i.next=4;break}return i.abrupt("return",null);case 4:if(!_.test(n)){i.next=22;break}return M=!0,J(o.emitFile),a=["import "+JSON.stringify(v(n,"?monaco-features"))+";",r],u=x.map((function(r){return A(r)})),s=!1,i.next=12,Promise.all(u.map(function(){var r=c(h.mark((function r(o){var i;return h.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,e.promises.readFile(o);case 2:return i=(i=(i=(i=(i=(i=r.sent.toString()).replace(/import\s['"]\.\.\/\.\.\/editor\/editor\.api\.js['"];?/,"")).replace(/import\s+.*from ['"]\.\/fillers\/monaco-editor-core\.js['"];?/,"")).replace(/import\s+\*\s+as\s+monaco_editor_core_star\s+from\s+["']\.\.\/\.\.\/editor\/editor\.api\.js["'];?/,"")).replace(/getMode\(\)/g,(function(){var r;return"get"+((function(r){return/\d/.test(r[0])}(r=(r=m(o).split("/").slice(-3,-1).join("_")).replace(/-(\w)/g,(function(r,t){return t.toUpperCase()})).replace(g,"_"))||y.has(r))&&(r="_"+r),(r||"_")+"Mode()")}))).replace(/import\s+{\s+registerLanguage\s+}\s+from\s+['"]\.\.\/_\.contribution\.js['"];?/,(function(){return s=!0,""})),r.next=10,w(i,(function(r){return"."===r[0]?m(t.relative(t.dirname(n),t.resolve(t.dirname(o),r))):r}));case 10:return r.abrupt("return",i=r.sent);case 12:case"end":return r.stop()}}),r)})));return function(t){return r.apply(this,arguments)}}()));case 12:if(l=i.sent,!s){i.next=20;break}return f=A("vs/basic-languages/_.contribution"),i.next=17,e.promises.readFile(f,"utf-8");case 17:p=(p=i.sent).replace(/import\s+.*from ['"]\.\/fillers\/monaco-editor-core\.js['"];?/,""),a=a.concat(p);case 20:return a=a.concat(l),i.abrupt("return",{code:a.join("\n"),map:null});case 22:return i.abrupt("return",null);case 23:case"end":return i.stop()}}),i)})))()}}};
"use strict";function r(r){return r&&"object"==typeof r&&"default"in r?r.default:r}Object.defineProperty(exports,"__esModule",{value:!0});var t=r(require("path")),e=require("fs"),n=r(e),o=require("es-module-lexer"),i=r(require("semver")),a=require("recast"),u=r(require("magic-string"));function c(r,t,e,n,o,i,a){try{var u=r[i](a),c=u.value}catch(r){return void e(r)}u.done?t(c):Promise.resolve(c).then(n,o)}function s(r){return function(){var t=this,e=arguments;return new Promise((function(n,o){var i=r.apply(t,e);function a(r){c(i,n,o,a,u,"next",r)}function u(r){c(i,n,o,a,u,"throw",r)}a(void 0)}))}}function l(){return(l=Object.assign||function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r}).apply(this,arguments)}function f(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=new Array(t);e<t;e++)n[e]=r[e];return n}function p(r,t){var e="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(e)return(e=e.call(r)).next.bind(e);if(Array.isArray(r)||(e=function(r,t){if(r){if("string"==typeof r)return f(r,void 0);var e=Object.prototype.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?f(r,void 0):void 0}}(r))||t&&r&&"number"==typeof r.length){e&&(r=e);var n=0;return function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var h,d=(function(r){var t=function(r){var t=Object.prototype,e=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(r,t,e){return Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}),r[t]}try{u({},"")}catch(r){u=function(r,t,e){return r[t]=e}}function c(r,t,e,n){var o=Object.create((t&&t.prototype instanceof f?t:f).prototype),i=new j(n||[]);return o._invoke=function(r,t,e){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var u=w(a,e);if(u){if(u===l)continue;return u}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if("suspendedStart"===n)throw n="completed",e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n="executing";var c=s(r,t,e);if("normal"===c.type){if(n=e.done?"completed":"suspendedYield",c.arg===l)continue;return{value:c.arg,done:e.done}}"throw"===c.type&&(n="completed",e.method="throw",e.arg=c.arg)}}}(r,e,i),o}function s(r,t,e){try{return{type:"normal",arg:r.call(t,e)}}catch(r){return{type:"throw",arg:r}}}r.wrap=c;var l={};function f(){}function p(){}function h(){}var d={};u(d,o,(function(){return this}));var v=Object.getPrototypeOf,m=v&&v(v(E([])));m&&m!==t&&e.call(m,o)&&(d=m);var y=h.prototype=f.prototype=Object.create(d);function g(r){["next","throw","return"].forEach((function(t){u(r,t,(function(r){return this._invoke(t,r)}))}))}function b(r,t){var n;this._invoke=function(o,i){function a(){return new t((function(n,a){!function n(o,i,a,u){var c=s(r[o],r,i);if("throw"!==c.type){var l=c.arg,f=l.value;return f&&"object"==typeof f&&e.call(f,"__await")?t.resolve(f.__await).then((function(r){n("next",r,a,u)}),(function(r){n("throw",r,a,u)})):t.resolve(f).then((function(r){l.value=r,a(l)}),(function(r){return n("throw",r,a,u)}))}u(c.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function w(r,t){var e=r.iterator[t.method];if(void 0===e){if(t.delegate=null,"throw"===t.method){if(r.iterator.return&&(t.method="return",t.arg=void 0,w(r,t),"throw"===t.method))return l;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=s(e,r.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,l;var o=n.arg;return o?o.done?(t[r.resultName]=o.value,t.next=r.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,l):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,l)}function x(r){var t={tryLoc:r[0]};1 in r&&(t.catchLoc=r[1]),2 in r&&(t.finallyLoc=r[2],t.afterLoc=r[3]),this.tryEntries.push(t)}function _(r){var t=r.completion||{};t.type="normal",delete t.arg,r.completion=t}function j(r){this.tryEntries=[{tryLoc:"root"}],r.forEach(x,this),this.reset(!0)}function E(r){if(r){var t=r[o];if(t)return t.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function t(){for(;++n<r.length;)if(e.call(r,n))return t.value=r[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:O}}function O(){return{value:void 0,done:!0}}return p.prototype=h,u(y,"constructor",h),u(h,"constructor",p),p.displayName=u(h,a,"GeneratorFunction"),r.isGeneratorFunction=function(r){var t="function"==typeof r&&r.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},r.mark=function(r){return Object.setPrototypeOf?Object.setPrototypeOf(r,h):(r.__proto__=h,u(r,a,"GeneratorFunction")),r.prototype=Object.create(y),r},r.awrap=function(r){return{__await:r}},g(b.prototype),u(b.prototype,i,(function(){return this})),r.AsyncIterator=b,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new b(c(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(r){return r.done?r.value:a.next()}))},g(y),u(y,a,"Generator"),u(y,o,(function(){return this})),u(y,"toString",(function(){return"[object Generator]"})),r.keys=function(r){var t=[];for(var e in r)t.push(e);return t.reverse(),function e(){for(;t.length;){var n=t.pop();if(n in r)return e.value=n,e.done=!1,e}return e.done=!0,e}},r.values=E,j.prototype={constructor:j,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(_),!r)for(var t in this)"t"===t.charAt(0)&&e.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var r=this.tryEntries[0].completion;if("throw"===r.type)throw r.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var t=this;function n(e,n){return a.type="throw",a.arg=r,t.next=e,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=e.call(i,"catchLoc"),c=e.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(r,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&e.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===r||"continue"===r)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=r,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,l):this.complete(a)},complete:function(r,t){if("throw"===r.type)throw r.arg;return"break"===r.type||"continue"===r.type?this.next=r.arg:"return"===r.type?(this.rval=this.arg=r.arg,this.method="return",this.next="end"):"normal"===r.type&&t&&(this.next=t),l},finish:function(r){for(var t=this.tryEntries.length-1;t>=0;--t){var e=this.tryEntries[t];if(e.finallyLoc===r)return this.complete(e.completion,e.afterLoc),_(e),l}},catch:function(r){for(var t=this.tryEntries.length-1;t>=0;--t){var e=this.tryEntries[t];if(e.tryLoc===r){var n=e.completion;if("throw"===n.type){var o=n.arg;_(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,t,e){return this.delegate={iterator:E(r),resultName:t,nextLoc:e},"next"===this.method&&(this.arg=void 0),l}},r}(r.exports);try{regeneratorRuntime=t}catch(r){"object"==typeof globalThis?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}}(h={exports:{}}),h.exports),v=function(r,t){return r.endsWith(t)},m=function(r,t){return"\0"+r+t},y=function(r){var t=/^\\\\\?\\/.test(r),e=/[^\u0000-\u0080]+/.test(r);return t||e?r:r.replace(/\\/g,"/")},g=new Set("break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public".split(" ").concat("Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl".split(" "))),b=/[^$_a-zA-Z0-9]/g,w=/\s*(['"])(.*)\1\s*$/m;function x(r,t){return _.apply(this,arguments)}function _(){return(_=s(d.mark((function r(t,e){var n,i,a,u,c,s,l,f;return d.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:n=[];try{i=o.parse(t),n=i[0]}catch(r){}for(n=n.filter((function(r){return!(-2===r.d||r.d>-1&&!t.substring(r.s,r.e).match(w))})).reverse(),a=p(n);!(u=a()).done;)s=t.substring((c=u.value).s,c.e),c.d>-1&&(l=s.match(w),s=l[2]),(f=e(s))!==s&&(c.d>-1&&(f=JSON.stringify(f)),t=t.slice(0,c.s)+f+t.slice(c.e));return r.abrupt("return",t);case 5:case"end":return r.stop()}}),r)})))).apply(this,arguments)}var j=a.types.builders,E=[],O=[];!function(){var r=require.resolve("monaco-editor/package.json");try{!function(r){var e=t.join(t.dirname(r.monacoEditorPackageJsonPath),"esm/metadata.js"),n=require(e);if(!n.features||!n.languages)throw new Error("features or languages not found in metadata");E=n.features,O=n.languages}({monacoEditorPackageJsonPath:r})}catch(t){!function(r){for(var t=JSON.parse(n.readFileSync(r.monacoEditorPackageJsonPath,"utf-8")).version,e=require("../plugin/versionMapping"),o=null,a=0,u=Object.entries(e.versionMapping);a<u.length;a++){var c=u[a],s=c[0];if(c[1].some((function(r){return i.satisfies(t,r)}))){o=s;break}}if(!o)throw new Error("[rollup-plugin-monaco-editor] current monaco-editor version("+t+") are not supported, please file a issue at\nhttps://github.com/chengcyber/rollup-plugin-monaco-editor/issues");var l="../plugin/out/"+o.replace(/\*/g,"_x_"),f=require(l+"/features.js");E=f.featuresArr;var p=require(l+"/languages.js");O=p.languagesArr}({monacoEditorPackageJsonPath:r})}}();var k=E.reduce((function(r,t){return r[t.label]=t,r}),{}),S=O.reduce((function(r,t){return r[t.label]=t,r}),{}),L=/monaco-editor[/\\]esm[/\\]vs[/\\]editor[/\\]editor.(api|main)/,A={label:"editorWorkerService",entry:void 0,worker:{id:"vs/editor/editor",entry:"vs/editor/editor.worker"}};function P(r){return require.resolve(N(r))}function N(r){return t.join("monaco-editor/esm",r+".js")}function I(r){return r.filter(Boolean)}function U(r){return r.reduce((function(r,t){return Array.isArray(t)?[].concat(r).concat(t):[].concat(r).concat([t])}),[])}exports.default=function(r){void 0===r&&(r={});var n=r.languages||Object.keys(S),i=function(r){var t,e=[];if(r.length){var n=r.filter((function(r){return"!"===r[0]})).map((function(r){return r.slice(1)}));e=n.length?Object.keys(k).filter((t=n,function(r){return-1===t.indexOf(r)})):r}else e=Object.keys(k);return e}(r.features||[]),c=!1;"esm"in r&&(c=!!r.esm);var f=I(n.map((function(r){return S[r]}))),p=I(i.map((function(r){return k[r]}))),h=[A].concat(f).concat(p),w=[];h.forEach((function(r){"worker"in r&&r.worker&&w.push({label:r.label,id:r.worker.id,entry:r.worker.entry})}));for(var _=U(I(f.map((function(r){return r.entry})))),E=U(I(p.map((function(r){return r.entry})))),O={},F=0,M=w;F<M.length;F++){var R=M[F];O[R.label]=N(R.entry)}var q=!1;function J(r){if(!q){q=!0;for(var t=0,e=Object.entries(O);t<e.length;t++){var n=e[t][1];r({type:"chunk",id:require.resolve(n),fileName:n})}}}var T=!1,G=!1!==r.sourcemap;function C(r){return G?new u(r).generateMap({hires:!0}):null}return{name:"monaco",options:function(r){var t=l({},r),e=r.moduleContext;return t.moduleContext="function"==typeof e?function(r){return y(r).indexOf("node_modules/monaco-editor")>=0?"self":e(r)}:e&&"object"==typeof e?function(r){return y(r).indexOf("node_modules/monaco-editor")>=0?"self":e[r]}:function(r){if(y(r).indexOf("node_modules/monaco-editor")>=0)return"self"},t},buildStart:function(){return s(d.mark((function r(){return d.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,o.init;case 2:case"end":return r.stop()}}),r)})))()},renderChunk:function(t,e,n){if(!T)return null;var o=null,i=Array.from(this.getModuleIds()).some((function(r){return L.test(r)})),u=Object.values(O).includes(e.fileName);if(i&&!u&&(("es"===n.format||c)&&(o=t.replace(/(?<!\/\/.*)new Worker\((.*)\);/g,(function(r,t){var e=a.parse(r),n=e.program.body[0].expression.arguments;if(1===n.length)n.push(j.objectExpression([j.property("init",j.identifier("type"),j.literal("module"))]));else if(2===n.length){var o=n[1];"ObjectExpression"===o.type&&o.properties.push(j.property("init",j.identifier("type"),j.literal("module")))}return a.print(e).code}))),e.isEntry)){var s=r.pathPrefix;if(!s){var l=n.dir;l?(s=l).startsWith("/")||(s="/"+s):this.warn("rollup outputOptions.dir is missing")}s||(s="");var f={MonacoEnvironment:"(function (paths) {\n function stripTrailingSlash(str) {\n return str.replace(/\\/$/, '');\n }\n return {\n getWorkerUrl: function (moduleId, label) {\n var pathPrefix = "+JSON.stringify(s)+";\n var result = (pathPrefix ? stripTrailingSlash(pathPrefix) + '/' : '') + paths[label];\n if (/^((http:)|(https:)|(file:)|(\\/\\/))/.test(result)) {\n var currentUrl = String(window.location);\n var currentOrigin = currentUrl.substr(0, currentUrl.length - window.location.hash.length - window.location.search.length - window.location.pathname.length);\n if (result.substring(0, currentOrigin.length) !== currentOrigin) {\n var js = '/*' + label + '*/importScripts(\"' + result + '\");';\n var blob = new Blob([js], { type: 'application/javascript' });\n return URL.createObjectURL(blob);\n }\n }\n return result;\n }\n };\n })("+JSON.stringify(O,null,2)+")"};o=[].concat(f?Object.keys(f).map((function(r){return"self["+JSON.stringify(r)+"] = "+f[r]+";"})):[],[o||t]).join("\n")}return o?{code:o,map:C(o)}:null},resolveId:function(r,t){return v(r,"?monaco-features")?r:null},load:function(r){return v(r,"?monaco-features")?""+E.map((function(r){return P(r)})).map((function(r){return"import "+JSON.stringify(r)+";"})).join("\n"):null},transform:function(r,n){var o=this;return s(d.mark((function i(){var a,u,c,l,f,p,h;return d.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:if(!n.startsWith("\0")){i.next=2;break}return i.abrupt("return",null);case 2:if(t.isAbsolute(n)){i.next=4;break}return i.abrupt("return",null);case 4:if(!L.test(n)){i.next=30;break}return T=!0,J(o.emitFile),a=["import "+JSON.stringify(m(n,"?monaco-features"))+";",r],u=_.map((function(r){return P(r)})),c=!1,i.next=12,Promise.all(u.map(function(){var r=s(d.mark((function r(o){var i;return d.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,e.promises.readFile(o);case 2:return i=(i=(i=r.sent.toString()).replace(/getMode\(\)/g,(function(){var r;return"get"+((function(r){return/\d/.test(r[0])}(r=(r=y(o).split("/").slice(-3,-1).join("_")).replace(/-(\w)/g,(function(r,t){return t.toUpperCase()})).replace(b,"_"))||g.has(r))&&(r="_"+r),(r||"_")+"Mode()")}))).replace(/import\s+{\s+registerLanguage\s+}\s+from\s+['"]\.\.\/_\.contribution\.js['"];?/,(function(){return c=!0,""})),r.next=7,x(i,(function(r){return"."===r[0]?y(t.relative(t.dirname(n),t.resolve(t.dirname(o),r))):r}));case 7:return r.abrupt("return",i=r.sent);case 9:case"end":return r.stop()}}),r)})));return function(t){return r.apply(this,arguments)}}()));case 12:if(l=i.sent,a.push("var monaco_editor_core_exports = api;"),!c){i.next=20;break}return f=P("vs/basic-languages/_.contribution"),i.next=18,e.promises.readFile(f,"utf-8");case 18:a=a.concat(i.sent);case 20:return a=a.concat(l),p=(p=(p=(p=(p=(p=(p=a.join("\n")).replace(/import\s['"](?:(?:\.\.\/)+editor\/)?editor\.api\.js['"];?/g,"")).replace(/import\s+.*from ['"](?:.*)\/fillers\/monaco-editor-core\.js['"];?/g,"")).replace(/var monaco_editor_core_exports = {};/g,"")).replace(/__markAsModule\(monaco_editor_core_exports\);/g,"")).replace(/__reExport\(monaco_editor_core_exports, monaco_editor_core_star\);/g,"")).replace(/import\s+\*\s+as\s+monaco_editor_core_star\s+from\s+["'](?:(?:\.\.\/)+editor\/)?editor\.api\.js["'];?/g,""),h=C(p),i.abrupt("return",{code:p,map:h});case 30:return i.abrupt("return",null);case 31:case"end":return i.stop()}}),i)})))()}}};
//# sourceMappingURL=rollup-plugin-monaco-editor.cjs.production.min.js.map

@@ -6,2 +6,3 @@ import path from 'path';

import { parse as parse$1, print, types } from 'recast';
import MagicString from 'magic-string';

@@ -1183,2 +1184,14 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {

var hasMonacoEntry = false;
var shouldGenerateSourcemap = options.sourcemap !== false;
function getMapFromCode(code) {
if (shouldGenerateSourcemap) {
return new MagicString(code).generateMap({
hires: true
});
}
return null;
}
return {

@@ -1311,3 +1324,7 @@ name: 'monaco',

if (modifiedCode) {
return modifiedCode;
var map = getMapFromCode(modifiedCode);
return {
code: modifiedCode,
map: map
};
}

@@ -1343,3 +1360,3 @@

return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
var arr, languageImportIds, hasImportRegisterLanguage, languageCodes, basicContribPath, basicContribCode;
var arr, languageImportIds, hasImportRegisterLanguage, languageCodes, basicContribPath, basicContribCode, transformedCode, map;
return runtime_1.wrap(function _callee3$(_context3) {

@@ -1366,3 +1383,3 @@ while (1) {

if (!MONACO_ENTRY_RE.test(id)) {
_context3.next = 22;
_context3.next = 30;
break;

@@ -1393,13 +1410,3 @@ }

c = _context2.sent.toString();
// FIXME: use this.parse to handle this
// 1. fix circular dependency
c = c.replace(/import\s['"]\.\.\/\.\.\/editor\/editor\.api\.js['"];?/, ''); // 2. fillers/monaco-editor-core is same with editor.api, remove it
// 2. fillers/monaco-editor-core is same with editor.api, remove it
c = c.replace(/import\s+.*from ['"]\.\/fillers\/monaco-editor-core\.js['"];?/, ''); // 2.2 dedup import * as monaco_editor_core_star from "../../editor/editor.api.js";
// 2.2 dedup import * as monaco_editor_core_star from "../../editor/editor.api.js";
c = c.replace(/import\s+\*\s+as\s+monaco_editor_core_star\s+from\s+["']\.\.\/\.\.\/editor\/editor\.api\.js["'];?/, ''); // 3. rename getMode to getXXXMode
// 3. rename getMode to getXXXMode
// 1. rename getMode to getXXXMode
c = c.replace(/getMode\(\)/g, function () {

@@ -1409,11 +1416,11 @@ var languageFilename = slash(importId).split('/').slice(-3, -1).join('_');

return "get" + langName + "Mode()";
}); // 4. dedup import { registerLanguage } from '../_.contribution.js';
}); // 2. dedup import { registerLanguage } from '../_.contribution.js';
// 4. dedup import { registerLanguage } from '../_.contribution.js';
// 2. dedup import { registerLanguage } from '../_.contribution.js';
c = c.replace(/import\s+{\s+registerLanguage\s+}\s+from\s+['"]\.\.\/_\.contribution\.js['"];?/, function () {
hasImportRegisterLanguage = true;
return '';
}); // 5. import('./foo') -> import('$relative/foo');
}); // 3. import('./foo') -> import('$relative/foo');
_context2.next = 10;
_context2.next = 7;
return transformImports(c, function (spec) {

@@ -1429,7 +1436,7 @@ if (spec[0] === '.') {

case 10:
case 7:
c = _context2.sent;
return _context2.abrupt("return", c);
case 12:
case 9:
case "end":

@@ -1449,2 +1456,4 @@ return _context2.stop();

languageCodes = _context3.sent;
// mock the dist code src/fillers/monaco-editor-core.ts
arr.push('var monaco_editor_core_exports = api;');

@@ -1457,9 +1466,7 @@ if (!hasImportRegisterLanguage) {

basicContribPath = resolveMonacoPath('vs/basic-languages/_.contribution');
_context3.next = 17;
_context3.next = 18;
return promises.readFile(basicContribPath, 'utf-8');
case 17:
case 18:
basicContribCode = _context3.sent;
// fillers/monaco-editor-core is same with editor.api, remove it
basicContribCode = basicContribCode.replace(/import\s+.*from ['"]\.\/fillers\/monaco-editor-core\.js['"];?/, '');
arr = arr.concat(basicContribCode);

@@ -1469,11 +1476,42 @@

arr = arr.concat(languageCodes);
transformedCode = arr.join('\n');
/**
* Fix circular dependencies to transformed code
* FIXME: use this.parse to handle this
*/
// 1. dedup editor.api.js
// import "../../editor/editor.api.js";
// import "../editor/editor.api.js";
// import "editor/editor.api.js";
transformedCode = transformedCode.replace(/import\s['"](?:(?:\.\.\/)+editor\/)?editor\.api\.js['"];?/g, ''); // 2. fillers/monaco-editor-core is same with editor.api, remove it
// import { Emitter, languages } from '../language/json/fillers/monaco-editor-core.js';
// import from './fillers/monaco-editor.core.js'
transformedCode = transformedCode.replace(/import\s+.*from ['"](?:.*)\/fillers\/monaco-editor-core\.js['"];?/g, '');
/**
* // 2.2 monaco_editor_core_star
* // src/fillers/monaco-editor-core.ts
* var monaco_editor_core_exports = {};
* __markAsModule(monaco_editor_core_exports);
* __reExport(monaco_editor_core_exports, monaco_editor_core_star);
* import * as monaco_editor_core_star from "../editor/editor.api.js";
* import * as monaco_editor_core_star from "../../editor/editor.api.js";
* import * as monaco_editor_core_star from "editor.api.js";
*/
transformedCode = transformedCode.replace(/var monaco_editor_core_exports = {};/g, '');
transformedCode = transformedCode.replace(/__markAsModule\(monaco_editor_core_exports\);/g, '');
transformedCode = transformedCode.replace(/__reExport\(monaco_editor_core_exports, monaco_editor_core_star\);/g, '');
transformedCode = transformedCode.replace(/import\s+\*\s+as\s+monaco_editor_core_star\s+from\s+["'](?:(?:\.\.\/)+editor\/)?editor\.api\.js["'];?/g, '');
map = getMapFromCode(transformedCode);
return _context3.abrupt("return", {
code: arr.join('\n'),
map: null
code: transformedCode,
map: map
});
case 22:
case 30:
return _context3.abrupt("return", null);
case 23:
case 31:
case "end":

@@ -1480,0 +1518,0 @@ return _context3.stop();

{
"version": "0.2.0",
"version": "0.2.1",
"license": "MIT",

@@ -85,2 +85,3 @@ "main": "dist/index.js",

"es-module-lexer": "^0.3.26",
"magic-string": "^0.25.7",
"recast": "^0.20.4",

@@ -96,3 +97,3 @@ "regenerator-runtime": "^0.13.9",

"build:example": "(cd example && rimraf dist && rollup -c rollup.config.js)",
"test": "tsdx test --runInBand",
"test": "tsdx test",
"lint": "tsdx lint",

@@ -103,3 +104,3 @@ "pub": "changeset publish",

},
"readme": "# rollup-plugin-monaco-editor\r\n\r\n> A rollup plugin to import monaco editor\r\n\r\n# Monaco Editor Version\r\n\r\nFor now, this plugin supports `monaco-editor@0.21.*` ~ `0.31.*`.\r\n\r\nThe following versions have been tested:\r\n\r\n- `0.21.2`\r\n- `0.22.3`\r\n- `0.24.0`\r\n- `0.25.0`\r\n- `0.26.1`\r\n- `0.27.0`\r\n- `0.29.1`\r\n- `0.30.1`\r\n- `0.31.1`\r\n\r\n# Usage\r\n\r\nThis plugin should be used with other plugins. including\r\n\r\n- `@rollup/plugin-node-resolve`\r\n- `rollup-plugin-postcss` (or other plugin can handle `.css` files)\r\n- `@rollup/plugin-commonjs`\r\n\r\n```javascript\r\n// rollup.config.js\r\nimport { nodeResolve } from '@rollup/plugin-node-resolve';\r\nimport postcss from 'rollup-plugin-postcss';\r\nimport commonjs from '@rollup/plugin-commonjs';\r\nimport monaco from 'rollup-plugin-monaco-editor';\r\n\r\nexport default {\r\n output: {\r\n format: 'es',\r\n dir: 'dist',\r\n },\r\n // ...other config\r\n plugins: [\r\n // ...other plugins\r\n // handle .css files\r\n postcss(),\r\n monaco({\r\n languages: ['json'],\r\n }),\r\n nodeResolve(),\r\n commonjs(),\r\n ],\r\n};\r\n```\r\n\r\n# Plugin Options\r\n\r\nPlugin options can be passed in to `rollup-plugin-monaco-editor`. They can be used to generate a smaller editor bundle by selecting only certain languages or only certain editor features:\r\n\r\n## `languages`\r\n\r\nType: `string[]` \r\nDefault: All available languages depends on the version of `monaco-editor` installed.\r\n\r\nExample:\r\n\r\n```js\r\nmonaco({\r\n languages: ['json'],\r\n})\r\nmonaco({\r\n languages: ['html', 'css', 'javascript'],\r\n})\r\n```\r\n\r\n## `features`\r\n\r\nType: `string` \r\nDefault: All available features depends on the version of `monaco-editor` installed.\r\n\r\nExample:\r\n\r\n```js\r\nmonaco({\r\n features: ['contextmenu'],\r\n})\r\nmonaco({\r\n features: ['rename'],\r\n})\r\n```\r\n\r\n## `esm`\r\n\r\nType: `boolean` \r\nDefault: `true` if `rollup.outputOptions.format` is `esm` or `es`, otherwise `false`.\r\n\r\n## `pathPrefix`\r\n\r\nType: `string` \r\nDefault: `rollup.outputOptions.dir` with leading slash.\r\n\r\n# Example\r\n\r\n> NOTE: pnpm@6 is used to manage this package\r\n\r\n```\r\npnpm install\r\npnpm build\r\npnpm build:example\r\npnpm start:example\r\n```\r\n\r\nvisit `http://localhost:8080` to see the simple demo.\r\n\r\n# Development\r\n\r\n```\r\npnpm start\r\n```\r\n\r\n# LICENSE\r\n\r\nMIT\r\n"
"readme": "# rollup-plugin-monaco-editor\n\n> A rollup plugin to import monaco editor\n\n# Monaco Editor Version\n\nFor now, this plugin supports `monaco-editor@0.21.*` ~ `0.31.*`.\n\nThe following versions have been tested:\n\n- `0.21.2`\n- `0.22.3`\n- `0.24.0`\n- `0.25.0`\n- `0.26.1`\n- `0.27.0`\n- `0.29.1`\n- `0.30.1`\n- `0.31.1`\n\n# Usage\n\nThis plugin should be used with other plugins. including\n\n- `@rollup/plugin-node-resolve`\n- `rollup-plugin-postcss` (or other plugin can handle `.css` files)\n- `@rollup/plugin-commonjs`\n\n```javascript\n// rollup.config.js\nimport { nodeResolve } from '@rollup/plugin-node-resolve';\nimport postcss from 'rollup-plugin-postcss';\nimport commonjs from '@rollup/plugin-commonjs';\nimport monaco from 'rollup-plugin-monaco-editor';\n\nexport default {\n output: {\n format: 'es',\n dir: 'dist',\n },\n // ...other config\n plugins: [\n // ...other plugins\n // handle .css files\n postcss(),\n monaco({\n languages: ['json'],\n }),\n nodeResolve(),\n commonjs(),\n ],\n};\n```\n\n# Plugin Options\n\nPlugin options can be passed in to `rollup-plugin-monaco-editor`. They can be used to generate a smaller editor bundle by selecting only certain languages or only certain editor features:\n\n## `languages`\n\nType: `string[]`\nDefault: All available languages depends on the version of `monaco-editor` installed.\n\nExample:\n\n```js\nmonaco({\n languages: ['json'],\n});\nmonaco({\n languages: ['html', 'css', 'javascript'],\n});\n```\n\n## `features`\n\nType: `string`\nDefault: All available features depends on the version of `monaco-editor` installed.\n\nExample:\n\n```js\nmonaco({\n features: ['contextmenu'],\n});\nmonaco({\n features: ['rename'],\n});\n```\n\n## `esm`\n\nType: `boolean`\nDefault: `true` if `rollup.outputOptions.format` is `esm` or `es`, otherwise `false`.\n\n## `pathPrefix`\n\nType: `string`\nDefault: `rollup.outputOptions.dir` with leading slash.\n\n## `sourcemap`\n\nType: `boolean`\nDefault: true\n\nYou can set `sourcemap` to `false` to disable generate sourcemap. It makes build faster.\n\n# Example\n\n> NOTE: pnpm@6 is used to manage this package\n\n```\npnpm install\npnpm build\npnpm build:example\npnpm start:example\n```\n\nvisit `http://localhost:8080` to see the simple demo.\n\n# Development\n\n```\npnpm start\n```\n\n# LICENSE\n\nMIT @[chengcyber](https://github.com/chengcyber)\n"
}

@@ -0,0 +0,0 @@ /**

@@ -61,3 +61,3 @@ # rollup-plugin-monaco-editor

Type: `string[]`
Type: `string[]`
Default: All available languages depends on the version of `monaco-editor` installed.

@@ -70,6 +70,6 @@

languages: ['json'],
})
});
monaco({
languages: ['html', 'css', 'javascript'],
})
});
```

@@ -79,3 +79,3 @@

Type: `string`
Type: `string`
Default: All available features depends on the version of `monaco-editor` installed.

@@ -88,6 +88,6 @@

features: ['contextmenu'],
})
});
monaco({
features: ['rename'],
})
});
```

@@ -97,3 +97,3 @@

Type: `boolean`
Type: `boolean`
Default: `true` if `rollup.outputOptions.format` is `esm` or `es`, otherwise `false`.

@@ -103,5 +103,12 @@

Type: `string`
Type: `string`
Default: `rollup.outputOptions.dir` with leading slash.
## `sourcemap`
Type: `boolean`
Default: true
You can set `sourcemap` to `false` to disable generate sourcemap. It makes build faster.
# Example

@@ -128,2 +135,2 @@

MIT
MIT @[chengcyber](https://github.com/chengcyber)

@@ -0,0 +0,0 @@ export const FEAT_SUFFIX = '?monaco-features';

import path from 'path';
import fs, { promises as fsp } from 'fs';
import { EmitFile, Plugin } from 'rollup';
import { EmitFile, Plugin, SourceMapInput } from 'rollup';
import { init } from 'es-module-lexer';

@@ -11,2 +11,3 @@ import { isWrappedId, FEAT_SUFFIX, wrapId } from './helpers';

import * as recast from 'recast';
import MagicString from 'magic-string';

@@ -231,2 +232,8 @@ const builders = recast.types.builders;

pathPrefix?: string;
/**
* Normally, sourcemap is generated by default. You can set
* sourcemap to false to disable generate it, which makes build faster.
* @default true;
*/
sourcemap?: boolean;
}

@@ -294,2 +301,11 @@

let hasMonacoEntry = false;
let shouldGenerateSourcemap = options.sourcemap !== false;
function getMapFromCode(code: string): SourceMapInput {
if (shouldGenerateSourcemap) {
return new MagicString(code).generateMap({
hires: true,
});
}
return null;
}

@@ -434,3 +450,7 @@ return {

if (modifiedCode) {
return modifiedCode;
const map = getMapFromCode(modifiedCode);
return {
code: modifiedCode,
map,
};
}

@@ -471,3 +491,6 @@ return null;

let arr = [`import ${JSON.stringify(wrapId(id, FEAT_SUFFIX))};`, code];
let arr: string[] = [
`import ${JSON.stringify(wrapId(id, FEAT_SUFFIX))};`,
code,
];

@@ -482,19 +505,3 @@ // append languages code to editor.api

let c = (await fsp.readFile(importId)).toString();
// FIXME: use this.parse to handle this
// 1. fix circular dependency
c = c.replace(
/import\s['"]\.\.\/\.\.\/editor\/editor\.api\.js['"];?/,
''
);
// 2. fillers/monaco-editor-core is same with editor.api, remove it
c = c.replace(
/import\s+.*from ['"]\.\/fillers\/monaco-editor-core\.js['"];?/,
''
);
// 2.2 dedup import * as monaco_editor_core_star from "../../editor/editor.api.js";
c = c.replace(
/import\s+\*\s+as\s+monaco_editor_core_star\s+from\s+["']\.\.\/\.\.\/editor\/editor\.api\.js["'];?/,
''
);
// 3. rename getMode to getXXXMode
// 1. rename getMode to getXXXMode
c = c.replace(/getMode\(\)/g, () => {

@@ -508,3 +515,3 @@ const languageFilename = slash(importId)

});
// 4. dedup import { registerLanguage } from '../_.contribution.js';
// 2. dedup import { registerLanguage } from '../_.contribution.js';
c = c.replace(

@@ -517,3 +524,3 @@ /import\s+{\s+registerLanguage\s+}\s+from\s+['"]\.\.\/_\.contribution\.js['"];?/,

);
// 5. import('./foo') -> import('$relative/foo');
// 3. import('./foo') -> import('$relative/foo');
c = await transformImports(c, spec => {

@@ -536,11 +543,12 @@ if (spec[0] === '.') {

// mock the dist code src/fillers/monaco-editor-core.ts
arr.push('var monaco_editor_core_exports = api;');
if (hasImportRegisterLanguage) {
const basicContribPath = resolveMonacoPath(
const basicContribPath: string = resolveMonacoPath(
'vs/basic-languages/_.contribution'
);
let basicContribCode = await fsp.readFile(basicContribPath, 'utf-8');
// fillers/monaco-editor-core is same with editor.api, remove it
basicContribCode = basicContribCode.replace(
/import\s+.*from ['"]\.\/fillers\/monaco-editor-core\.js['"];?/,
''
const basicContribCode: string = await fsp.readFile(
basicContribPath,
'utf-8'
);

@@ -552,5 +560,56 @@ arr = arr.concat(basicContribCode);

let transformedCode: string = arr.join('\n');
/**
* Fix circular dependencies to transformed code
* FIXME: use this.parse to handle this
*/
// 1. dedup editor.api.js
// import "../../editor/editor.api.js";
// import "../editor/editor.api.js";
// import "editor/editor.api.js";
transformedCode = transformedCode.replace(
/import\s['"](?:(?:\.\.\/)+editor\/)?editor\.api\.js['"];?/g,
''
);
// 2. fillers/monaco-editor-core is same with editor.api, remove it
// import { Emitter, languages } from '../language/json/fillers/monaco-editor-core.js';
// import from './fillers/monaco-editor.core.js'
transformedCode = transformedCode.replace(
/import\s+.*from ['"](?:.*)\/fillers\/monaco-editor-core\.js['"];?/g,
''
);
/**
* // 2.2 monaco_editor_core_star
* // src/fillers/monaco-editor-core.ts
* var monaco_editor_core_exports = {};
* __markAsModule(monaco_editor_core_exports);
* __reExport(monaco_editor_core_exports, monaco_editor_core_star);
* import * as monaco_editor_core_star from "../editor/editor.api.js";
* import * as monaco_editor_core_star from "../../editor/editor.api.js";
* import * as monaco_editor_core_star from "editor.api.js";
*/
transformedCode = transformedCode.replace(
/var monaco_editor_core_exports = {};/g,
''
);
transformedCode = transformedCode.replace(
/__markAsModule\(monaco_editor_core_exports\);/g,
''
);
transformedCode = transformedCode.replace(
/__reExport\(monaco_editor_core_exports, monaco_editor_core_star\);/g,
''
);
transformedCode = transformedCode.replace(
/import\s+\*\s+as\s+monaco_editor_core_star\s+from\s+["'](?:(?:\.\.\/)+editor\/)?editor\.api\.js["'];?/g,
''
);
const map = getMapFromCode(transformedCode);
return {
code: arr.join('\n'),
map: null,
code: transformedCode,
map,
};

@@ -557,0 +616,0 @@ }

@@ -0,0 +0,0 @@ const reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public'.split(

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ import { parse, ImportSpecifier } from 'es-module-lexer';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc