From e2b754bad627b8e8ff617534b34926774df8af0b Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Mon, 23 Jul 2018 11:24:38 -0500 Subject: [PATCH] Remove `$1` in `CodeMirror$1` for development --- tools/update-libraries.js | 13 ++++++-- tools/zip.js | 11 +++++-- vendor/codemirror/lib/codemirror.js | 48 ++++++++++++++--------------- 3 files changed, 43 insertions(+), 29 deletions(-) diff --git a/tools/update-libraries.js b/tools/update-libraries.js index 4e6f4d3d..b67c576f 100644 --- a/tools/update-libraries.js +++ b/tools/update-libraries.js @@ -43,6 +43,12 @@ function isFolder(fileOrFolder) { return stat.isDirectory(); } +// Rename CodeMirror$1 -> CodeMirror for development purposes +function renameCodeMirrorVariable(filePath) { + const file = fs.readFileSync(filePath, 'utf8'); + fs.writeFileSync(filePath, file.replace(/CodeMirror\$1/g, 'CodeMirror')); +} + function updateExisting(lib) { const libRoot = `${root}/node_modules/`; const vendorRoot = `${root}/vendor/`; @@ -54,8 +60,11 @@ function updateExisting(lib) { const folderRoot = `${vendorRoot}${folder}`; const entries = fs.readdirSync(folderRoot); entries.forEach(entry => { - // Ignore README.md & LICENSE files - if (entry !== 'README.md' && entry !== 'LICENSE') { + // Remove $1 from "CodeMirror$1" in codemirror.js + if (entry === 'codemirror.js') { + renameCodeMirrorVariable(`${folderRoot}/${entry}`); + } else if (entry !== 'README.md' && entry !== 'LICENSE') { + // Ignore README.md & LICENSE files const entryPath = `${folderRoot}/${entry}`; try { if (fs.existsSync(entryPath)) { diff --git a/tools/zip.js b/tools/zip.js index b78818e3..ac51e543 100644 --- a/tools/zip.js +++ b/tools/zip.js @@ -8,9 +8,12 @@ function createZip() { const fileName = 'stylus.zip'; const exclude = [ '.*', // dot files/folders (glob, not regexp) - 'node_modules', - 'tools', + 'vendor/codemirror/lib/**', // get unmodified copy from node_modules + 'node_modules/**', + 'tools/**', 'package.json', + 'package-lock.json', + 'yarn.lock', '*.zip' ]; @@ -34,7 +37,9 @@ function createZip() { }); archive.pipe(file); - archive.glob(`!(${exclude.join('|')})`); + archive.glob('**', {ignore: exclude}); + // Don't use modified codemirror.js (see "update-libraries.js") + archive.directory('node_modules/codemirror/lib', 'vendor/codemirror/lib'); archive.finalize(); }); } diff --git a/vendor/codemirror/lib/codemirror.js b/vendor/codemirror/lib/codemirror.js index 85d16f1c..c36613fb 100644 --- a/vendor/codemirror/lib/codemirror.js +++ b/vendor/codemirror/lib/codemirror.js @@ -6408,7 +6408,7 @@ Doc.prototype = createObj(BranchChunk.prototype, { unlinkDoc: function(other) { var this$1 = this; - if (other instanceof CodeMirror$1) { other = other.doc; } + if (other instanceof CodeMirror) { other = other.doc; } if (this.linked) { for (var i = 0; i < this.linked.length; ++i) { var link = this$1.linked[i]; if (link.doc != other) { continue } @@ -7773,10 +7773,10 @@ function wrappingChanged(cm) { // A CodeMirror instance represents an editor. This is the object // that user code is usually dealing with. -function CodeMirror$1(place, options) { +function CodeMirror(place, options) { var this$1 = this; - if (!(this instanceof CodeMirror$1)) { return new CodeMirror$1(place, options) } + if (!(this instanceof CodeMirror)) { return new CodeMirror(place, options) } this.options = options = options ? copyObj(options) : {}; // Determine effective options based on given values and defaults. @@ -7788,7 +7788,7 @@ function CodeMirror$1(place, options) { else if (options.mode) { doc.modeOption = options.mode; } this.doc = doc; - var input = new CodeMirror$1.inputStyles[options.inputStyle](this); + var input = new CodeMirror.inputStyles[options.inputStyle](this); var display = this.display = new Display(place, doc, input); display.wrapper.CodeMirror = this; updateGutters(this); @@ -7845,9 +7845,9 @@ function CodeMirror$1(place, options) { } // The default configuration options. -CodeMirror$1.defaults = defaults; +CodeMirror.defaults = defaults; // Functions to run when options are changed. -CodeMirror$1.optionHandlers = optionHandlers; +CodeMirror.optionHandlers = optionHandlers; // Attach the necessary event handlers when initializing the editor function registerEventHandlers(cm) { @@ -7958,7 +7958,7 @@ function registerEventHandlers(cm) { } var initHooks = []; -CodeMirror$1.defineInitHook = function (f) { return initHooks.push(f); }; +CodeMirror.defineInitHook = function (f) { return initHooks.push(f); }; // Indent the given line. The how parameter can be "smart", // "add"/null, "subtract", or "prev". When aggressive is false @@ -9592,7 +9592,7 @@ function fromTextArea(textarea, options) { }; textarea.style.display = "none"; - var cm = CodeMirror$1(function (node) { return textarea.parentNode.insertBefore(node, textarea.nextSibling); }, + var cm = CodeMirror(function (node) { return textarea.parentNode.insertBefore(node, textarea.nextSibling); }, options); return cm } @@ -9643,14 +9643,14 @@ function addLegacyProps(CodeMirror) { // EDITOR CONSTRUCTOR -defineOptions(CodeMirror$1); +defineOptions(CodeMirror); -addEditorMethods(CodeMirror$1); +addEditorMethods(CodeMirror); // Set up methods on CodeMirror's prototype to redirect to the editor's document. var dontDelegate = "iter insert remove copy getEditor constructor".split(" "); for (var prop in Doc.prototype) { if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0) - { CodeMirror$1.prototype[prop] = (function(method) { + { CodeMirror.prototype[prop] = (function(method) { return function() {return method.apply(this.doc, arguments)} })(Doc.prototype[prop]); } } @@ -9658,39 +9658,39 @@ eventMixin(Doc); // INPUT HANDLING -CodeMirror$1.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput}; +CodeMirror.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput}; // MODE DEFINITION AND QUERYING // Extra arguments are stored as the mode's dependencies, which is // used by (legacy) mechanisms like loadmode.js to automatically // load a mode. (Preferred mechanism is the require/define calls.) -CodeMirror$1.defineMode = function(name/*, mode, …*/) { - if (!CodeMirror$1.defaults.mode && name != "null") { CodeMirror$1.defaults.mode = name; } +CodeMirror.defineMode = function(name/*, mode, …*/) { + if (!CodeMirror.defaults.mode && name != "null") { CodeMirror.defaults.mode = name; } defineMode.apply(this, arguments); }; -CodeMirror$1.defineMIME = defineMIME; +CodeMirror.defineMIME = defineMIME; // Minimal default mode. -CodeMirror$1.defineMode("null", function () { return ({token: function (stream) { return stream.skipToEnd(); }}); }); -CodeMirror$1.defineMIME("text/plain", "null"); +CodeMirror.defineMode("null", function () { return ({token: function (stream) { return stream.skipToEnd(); }}); }); +CodeMirror.defineMIME("text/plain", "null"); // EXTENSIONS -CodeMirror$1.defineExtension = function (name, func) { - CodeMirror$1.prototype[name] = func; +CodeMirror.defineExtension = function (name, func) { + CodeMirror.prototype[name] = func; }; -CodeMirror$1.defineDocExtension = function (name, func) { +CodeMirror.defineDocExtension = function (name, func) { Doc.prototype[name] = func; }; -CodeMirror$1.fromTextArea = fromTextArea; +CodeMirror.fromTextArea = fromTextArea; -addLegacyProps(CodeMirror$1); +addLegacyProps(CodeMirror); -CodeMirror$1.version = "5.39.2"; +CodeMirror.version = "5.39.2"; -return CodeMirror$1; +return CodeMirror; })));