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.1.2 to 0.2.0

dist/plugin/out/0.29._x_/features.d.ts

2

dist/plugin/versionMapping.d.ts

@@ -5,2 +5,4 @@ /**

export const versionMapping: {
'0.30.*': string[];
'0.29.*': string[];
'0.27.*': string[];

@@ -7,0 +9,0 @@ '0.26.*': string[];

@@ -973,6 +973,2 @@ 'use strict';

var builders = recast.types.builders;
var _require = /*#__PURE__*/require('../plugin/versionMapping'),
versionMapping = _require.versionMapping;
var featuresArr = [];

@@ -988,5 +984,40 @@ var languagesArr = [];

try {
initMonacoByMetadata({
monacoEditorPackageJsonPath: monacoEditorPackageJsonPath
});
} catch (_unused) {
initMonacoLegacy({
monacoEditorPackageJsonPath: monacoEditorPackageJsonPath
});
}
}
function initMonacoByMetadata(_ref) {
var monacoEditorPackageJsonPath = _ref.monacoEditorPackageJsonPath;
var metadataFilepath = path.join(path.dirname(monacoEditorPackageJsonPath), 'esm/metadata.js');
var metadata = require(metadataFilepath);
if (!metadata.features || !metadata.languages) {
throw new Error('features or languages not found in metadata');
}
featuresArr = metadata.features;
languagesArr = metadata.languages;
}
/**
* initialize monaco-editor < 0.31.0
*/
function initMonacoLegacy(_ref2) {
var monacoEditorPackageJsonPath = _ref2.monacoEditorPackageJsonPath;
var _JSON$parse = JSON.parse(fs__default.readFileSync(monacoEditorPackageJsonPath, 'utf-8')),
monacoEditorVersion = _JSON$parse.version;
var _require = require('../plugin/versionMapping'),
versionMapping = _require.versionMapping;
var monacoEditorVersionMappingEntries = Object.entries(versionMapping);

@@ -1355,3 +1386,3 @@ var resolvedMonacoEditorVersion = null;

return Promise.all(languageImportIds.map( /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(importId) {
var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(importId) {
var c;

@@ -1372,4 +1403,7 @@ return runtime_1.wrap(function _callee2$(_context2) {

// 2. fillers/monaco-editor-core is same with editor.api, remove it
c = c.replace(/import\s+.*from ['"]\.\/fillers\/monaco-editor-core\.js['"];?/, ''); // 3. rename getMode to getXXXMode
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

@@ -1383,3 +1417,3 @@ c = c.replace(/getMode\(\)/g, function () {

// 4. dedup import { registerLanguage } from '../_.contribution.js';
c = c.replace("import { registerLanguage } from '../_.contribution.js';", function () {
c = c.replace(/import\s+{\s+registerLanguage\s+}\s+from\s+['"]\.\.\/_\.contribution\.js['"];?/, function () {
hasImportRegisterLanguage = true;

@@ -1389,3 +1423,3 @@ return '';

_context2.next = 9;
_context2.next = 10;
return transformImports(c, function (spec) {

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

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

@@ -1415,3 +1449,3 @@ return _context2.stop();

return function (_x) {
return _ref.apply(this, arguments);
return _ref3.apply(this, arguments);
};

@@ -1418,0 +1452,0 @@ }()));

2

dist/rollup-plugin-monaco-editor.cjs.production.min.js

@@ -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 O(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,y=v&&v(v(E([])));y&&y!==t&&e.call(y,o)&&(d=y);var m=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 O(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:k}}function k(){return{value:void 0,done:!0}}return p.prototype=h,u(m,"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(m),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(m),u(m,a,"Generator"),u(m,o,(function(){return this})),u(m,"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,O.prototype={constructor:O,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: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)}}(p={exports:{}}),p.exports),d=function(r,t){return r.endsWith(t)},v=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,"/")},m=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,O=require("../plugin/versionMapping").versionMapping,E=[],k=[];!function(){for(var r=require.resolve("monaco-editor/package.json"),t=JSON.parse(n.readFileSync(r,"utf-8")).version,e=null,o=0,a=Object.entries(O);o<a.length;o++){var u=a[o],c=u[0];if(u[1].some((function(r){return i.satisfies(t,r)}))){e=c;break}}if(!e)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 s="../plugin/out/"+e.replace(/\*/g,"_x_"),l=require(s+"/features.js");E=l.featuresArr;var f=require(s+"/languages.js");k=f.languagesArr}();var S=E.reduce((function(r,t){return r[t.label]=t,r}),{}),L=k.reduce((function(r,t){return r[t.label]=t,r}),{}),_=/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 N(r){return require.resolve(I(r))}function I(r){return t.join("monaco-editor/esm",r+".js")}function P(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(L),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(S).filter((t=n,function(r){return-1===t.indexOf(r)})):r}else e=Object.keys(S);return e}(r.features||[]),u=!1;"esm"in r&&(u=!!r.esm);var l=P(n.map((function(r){return L[r]}))),f=P(i.map((function(r){return S[r]}))),p=[A].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=U(P(l.map((function(r){return r.entry})))),O=U(P(f.map((function(r){return r.entry})))),E={},k=0,F=b;k<F.length;k++){var R=F[k];E[R.label]=I(R.entry)}var M=!1;function q(r){if(!M){M=!0;for(var t=0,e=Object.entries(E);t<e.length;t++){var n=e[t][1];r({type:"chunk",id:require.resolve(n),fileName:n})}}}var T=!1;return{name:"monaco",options:function(r){var t=s({},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 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(!T)return null;var o=null,i=Array.from(this.getModuleIds()).some((function(r){return _.test(r)})),c=Object.values(E).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(E,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")?""+O.map((function(r){return N(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 T=!0,q(o.emitFile),a=["import "+JSON.stringify(v(n,"?monaco-features"))+";",r],u=x.map((function(r){return N(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=r.sent.toString()).replace(/import\s['"]\.\.\/\.\.\/editor\/editor\.api\.js['"];?/,"")).replace(/import\s+.*from ['"]\.\/fillers\/monaco-editor-core\.js['"];?/,"")).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(g,"_"))||m.has(r))&&(r="_"+r),(r||"_")+"Mode()")}))).replace("import { registerLanguage } from '../_.contribution.js';",(function(){return s=!0,""})),r.next=9,w(i,(function(r){return"."===r[0]?y(t.relative(t.dirname(n),t.resolve(t.dirname(o),r))):r}));case 9:return r.abrupt("return",i=r.sent);case 11: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=N("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");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)})))()}}};
//# sourceMappingURL=rollup-plugin-monaco-editor.cjs.production.min.js.map

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

var builders = types.builders;
var _require = /*#__PURE__*/require('../plugin/versionMapping'),
versionMapping = _require.versionMapping;
var featuresArr = [];

@@ -981,5 +977,40 @@ var languagesArr = [];

try {
initMonacoByMetadata({
monacoEditorPackageJsonPath: monacoEditorPackageJsonPath
});
} catch (_unused) {
initMonacoLegacy({
monacoEditorPackageJsonPath: monacoEditorPackageJsonPath
});
}
}
function initMonacoByMetadata(_ref) {
var monacoEditorPackageJsonPath = _ref.monacoEditorPackageJsonPath;
var metadataFilepath = path.join(path.dirname(monacoEditorPackageJsonPath), 'esm/metadata.js');
var metadata = require(metadataFilepath);
if (!metadata.features || !metadata.languages) {
throw new Error('features or languages not found in metadata');
}
featuresArr = metadata.features;
languagesArr = metadata.languages;
}
/**
* initialize monaco-editor < 0.31.0
*/
function initMonacoLegacy(_ref2) {
var monacoEditorPackageJsonPath = _ref2.monacoEditorPackageJsonPath;
var _JSON$parse = JSON.parse(fs.readFileSync(monacoEditorPackageJsonPath, 'utf-8')),
monacoEditorVersion = _JSON$parse.version;
var _require = require('../plugin/versionMapping'),
versionMapping = _require.versionMapping;
var monacoEditorVersionMappingEntries = Object.entries(versionMapping);

@@ -1348,3 +1379,3 @@ var resolvedMonacoEditorVersion = null;

return Promise.all(languageImportIds.map( /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(importId) {
var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(importId) {
var c;

@@ -1365,4 +1396,7 @@ return runtime_1.wrap(function _callee2$(_context2) {

// 2. fillers/monaco-editor-core is same with editor.api, remove it
c = c.replace(/import\s+.*from ['"]\.\/fillers\/monaco-editor-core\.js['"];?/, ''); // 3. rename getMode to getXXXMode
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

@@ -1376,3 +1410,3 @@ c = c.replace(/getMode\(\)/g, function () {

// 4. dedup import { registerLanguage } from '../_.contribution.js';
c = c.replace("import { registerLanguage } from '../_.contribution.js';", function () {
c = c.replace(/import\s+{\s+registerLanguage\s+}\s+from\s+['"]\.\.\/_\.contribution\.js['"];?/, function () {
hasImportRegisterLanguage = true;

@@ -1382,3 +1416,3 @@ return '';

_context2.next = 9;
_context2.next = 10;
return transformImports(c, function (spec) {

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

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

@@ -1408,3 +1442,3 @@ return _context2.stop();

return function (_x) {
return _ref.apply(this, arguments);
return _ref3.apply(this, arguments);
};

@@ -1411,0 +1445,0 @@ }()));

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

@@ -23,14 +23,2 @@ "main": "dist/index.js",

},
"scripts": {
"start": "tsdx watch",
"start:example": "http-server -c-1 example",
"generate": "(cd build && ts-node ./generate_plugin.ts)",
"build": "tsdx build && node ./build/fix_dist_index.js",
"build:example": "(cd example && rm -rf dist && rollup -c rollup.config.js)",
"test": "tsdx test --runInBand",
"lint": "tsdx lint",
"prepare": "npm run build",
"size": "size-limit",
"analyze": "size-limit --why"
},
"husky": {

@@ -69,2 +57,4 @@ "hooks": {

"devDependencies": {
"@changesets/changelog-github": "^0.4.1",
"@changesets/cli": "^2.17.0",
"@rollup/plugin-commonjs": "^16.0.0",

@@ -83,3 +73,4 @@ "@rollup/plugin-node-resolve": "^10.0.0",

"husky": "^4.3.0",
"monaco-editor": "0.27.0",
"monaco-editor": "0.31.1",
"rimraf": "^3.0.2",
"rollup": "^2.33.1",

@@ -100,3 +91,16 @@ "rollup-plugin-postcss": "^3.1.8",

"semver": "^7.3.5"
}
}
},
"scripts": {
"start": "tsdx watch",
"start:example": "http-server -c-1 example",
"generate": "(cd build && ts-node ./generate_plugin.ts)",
"build": "tsdx build && node ./build/fix_dist_index.js",
"build:example": "(cd example && rimraf dist && rollup -c rollup.config.js)",
"test": "tsdx test --runInBand",
"lint": "tsdx lint",
"pub": "changeset publish",
"size": "size-limit",
"analyze": "size-limit --why"
},
"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"
}

@@ -5,3 +5,5 @@ /**

const versionMapping = {
'0.27.*': ['0.27.*'],
'0.30.*': ['0.30.*'],
'0.29.*': ['0.29.*'],
'0.27.*': ['0.27.*', '0.28.*'],
'0.26.*': ['0.26.*'],

@@ -8,0 +10,0 @@ '0.25.*': ['0.25.*'],

@@ -7,5 +7,5 @@ # rollup-plugin-monaco-editor

For now, this plugin supports `monaco-editor@0.21.*` ~ `0.27.*`.
For now, this plugin supports `monaco-editor@0.21.*` ~ `0.31.*`.
The following versions have been tested locally:
The following versions have been tested:

@@ -18,2 +18,5 @@ - `0.21.2`

- `0.27.0`
- `0.29.1`
- `0.30.1`
- `0.31.1`

@@ -54,2 +57,48 @@ # Usage

# Plugin Options
Plugin 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:
## `languages`
Type: `string[]`
Default: All available languages depends on the version of `monaco-editor` installed.
Example:
```js
monaco({
languages: ['json'],
})
monaco({
languages: ['html', 'css', 'javascript'],
})
```
## `features`
Type: `string`
Default: All available features depends on the version of `monaco-editor` installed.
Example:
```js
monaco({
features: ['contextmenu'],
})
monaco({
features: ['rename'],
})
```
## `esm`
Type: `boolean`
Default: `true` if `rollup.outputOptions.format` is `esm` or `es`, otherwise `false`.
## `pathPrefix`
Type: `string`
Default: `rollup.outputOptions.dir` with leading slash.
# Example

@@ -56,0 +105,0 @@

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

@@ -14,8 +14,2 @@ import path from 'path';

const {
versionMapping,
}: {
versionMapping: Record<string, string[]>;
} = require('../plugin/versionMapping');
/**

@@ -50,5 +44,51 @@ * Features

);
try {
initMonacoByMetadata({
monacoEditorPackageJsonPath,
});
} catch {
initMonacoLegacy({
monacoEditorPackageJsonPath,
});
}
}
interface InitMonacoByMetadataParams {
monacoEditorPackageJsonPath: string;
}
function initMonacoByMetadata({
monacoEditorPackageJsonPath,
}: InitMonacoByMetadataParams) {
const metadataFilepath = path.join(
path.dirname(monacoEditorPackageJsonPath),
'esm/metadata.js'
);
const metadata = require(metadataFilepath);
if (!metadata.features || !metadata.languages) {
throw new Error('features or languages not found in metadata');
}
featuresArr = metadata.features;
languagesArr = metadata.languages;
}
interface InitMonacoLegacyParams {
monacoEditorPackageJsonPath: string;
}
/**
* initialize monaco-editor < 0.31.0
*/
function initMonacoLegacy({
monacoEditorPackageJsonPath,
}: InitMonacoLegacyParams) {
const { version: monacoEditorVersion } = JSON.parse(
fs.readFileSync(monacoEditorPackageJsonPath, 'utf-8')
);
const {
versionMapping,
}: {
versionMapping: Record<string, string[]>;
} = require('../plugin/versionMapping');

@@ -450,2 +490,7 @@ const monacoEditorVersionMappingEntries = Object.entries(versionMapping);

);
// 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

@@ -462,3 +507,3 @@ c = c.replace(/getMode\(\)/g, () => {

c = c.replace(
`import { registerLanguage } from '../_.contribution.js';`,
/import\s+{\s+registerLanguage\s+}\s+from\s+['"]\.\.\/_\.contribution\.js['"];?/,
() => {

@@ -465,0 +510,0 @@ hasImportRegisterLanguage = true;

@@ -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