mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 23:13:02 +01:00
Ship ESM variant
This commit is contained in:
parent
13fb3f4b6c
commit
0ab1a24b8d
4 changed files with 277 additions and 79 deletions
231
gulpfile.js
231
gulpfile.js
|
|
@ -1,21 +1,23 @@
|
||||||
|
|
||||||
var gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
var metadata = require('./metadata');
|
const metadata = require('./metadata');
|
||||||
var es = require('event-stream');
|
const es = require('event-stream');
|
||||||
var path = require('path');
|
const path = require('path');
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
var rimraf = require('rimraf');
|
const rimraf = require('rimraf');
|
||||||
var cp = require('child_process');
|
const cp = require('child_process');
|
||||||
var httpServer = require('http-server');
|
const httpServer = require('http-server');
|
||||||
var typedoc = require("gulp-typedoc");
|
const typedoc = require("gulp-typedoc");
|
||||||
var CleanCSS = require('clean-css');
|
const CleanCSS = require('clean-css');
|
||||||
var uncss = require('uncss');
|
const uncss = require('uncss');
|
||||||
|
const File = require('vinyl');
|
||||||
|
const ts = require('typescript');
|
||||||
|
|
||||||
var WEBSITE_GENERATED_PATH = path.join(__dirname, 'website/playground/new-samples');
|
const WEBSITE_GENERATED_PATH = path.join(__dirname, 'website/playground/new-samples');
|
||||||
var MONACO_EDITOR_VERSION = (function() {
|
const MONACO_EDITOR_VERSION = (function() {
|
||||||
var packageJsonPath = path.join(__dirname, 'package.json');
|
const packageJsonPath = path.join(__dirname, 'package.json');
|
||||||
var packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString());
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString());
|
||||||
var version = packageJson.version;
|
const version = packageJson.version;
|
||||||
if (!/\d+\.\d+\.\d+/.test(version)) {
|
if (!/\d+\.\d+\.\d+/.test(version)) {
|
||||||
console.log('unrecognized package.json version: ' + version);
|
console.log('unrecognized package.json version: ' + version);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
|
|
@ -33,8 +35,8 @@ gulp.task('release', ['clean-release'], function() {
|
||||||
// min folder
|
// min folder
|
||||||
releaseOne('min'),
|
releaseOne('min'),
|
||||||
|
|
||||||
// // esm folder
|
// esm folder
|
||||||
// releaseESM(),
|
ESM_release(),
|
||||||
|
|
||||||
// package.json
|
// package.json
|
||||||
gulp.src('package.json')
|
gulp.src('package.json')
|
||||||
|
|
@ -65,6 +67,9 @@ gulp.task('release', ['clean-release'], function() {
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release to `dev` or `min`.
|
||||||
|
*/
|
||||||
function releaseOne(type) {
|
function releaseOne(type) {
|
||||||
return es.merge(
|
return es.merge(
|
||||||
gulp.src('node_modules/monaco-editor-core/' + type + '/**/*')
|
gulp.src('node_modules/monaco-editor-core/' + type + '/**/*')
|
||||||
|
|
@ -74,12 +79,9 @@ function releaseOne(type) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// function releaseESM() {
|
/**
|
||||||
// // return es.merge(
|
* Release plugins to `dev` or `min`.
|
||||||
// // gulp.src('node_modules/monaco-editor-core/esm/**/*')
|
*/
|
||||||
// // )
|
|
||||||
// }
|
|
||||||
|
|
||||||
function pluginStreams(type, destinationPath) {
|
function pluginStreams(type, destinationPath) {
|
||||||
return es.merge(
|
return es.merge(
|
||||||
metadata.METADATA.PLUGINS.map(function(plugin) {
|
metadata.METADATA.PLUGINS.map(function(plugin) {
|
||||||
|
|
@ -88,14 +90,16 @@ function pluginStreams(type, destinationPath) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release a plugin to `dev` or `min`.
|
||||||
|
*/
|
||||||
function pluginStream(plugin, type, destinationPath) {
|
function pluginStream(plugin, type, destinationPath) {
|
||||||
var pluginPath = plugin.paths[`npm/${type}`]; // npm/dev or npm/min
|
var pluginPath = plugin.paths[`npm/${type}`]; // npm/dev or npm/min
|
||||||
var contribPath = path.join(pluginPath, plugin.contrib.substr(plugin.modulePrefix.length)) + '.js';
|
var contribPath = path.join(pluginPath, plugin.contrib.substr(plugin.modulePrefix.length)) + '.js';
|
||||||
return (
|
return (
|
||||||
gulp.src([
|
gulp.src([
|
||||||
pluginPath + '/**/*',
|
pluginPath + '/**/*',
|
||||||
'!' + contribPath,
|
'!' + contribPath
|
||||||
'!' + pluginPath + '/**/monaco.d.ts'
|
|
||||||
])
|
])
|
||||||
.pipe(gulp.dest(destinationPath + plugin.modulePrefix))
|
.pipe(gulp.dest(destinationPath + plugin.modulePrefix))
|
||||||
);
|
);
|
||||||
|
|
@ -178,6 +182,181 @@ function addPluginContribs(type) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ESM_release() {
|
||||||
|
return es.merge(
|
||||||
|
gulp.src('node_modules/monaco-editor-core/esm/**/*')
|
||||||
|
.pipe(ESM_addImportSuffix())
|
||||||
|
.pipe(ESM_addPluginContribs('release/esm'))
|
||||||
|
.pipe(gulp.dest('release/esm')),
|
||||||
|
ESM_pluginStreams('release/esm/')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release plugins to `esm`.
|
||||||
|
*/
|
||||||
|
function ESM_pluginStreams(destinationPath) {
|
||||||
|
return es.merge(
|
||||||
|
metadata.METADATA.PLUGINS.map(function(plugin) {
|
||||||
|
return ESM_pluginStream(plugin, destinationPath);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release a plugin to `esm`.
|
||||||
|
* Adds a dependency to 'vs/editor/editor.api' in contrib files in order for `monaco` to be defined.
|
||||||
|
* Rewrites imports for 'monaco-editor-core/**'
|
||||||
|
*/
|
||||||
|
function ESM_pluginStream(plugin, destinationPath) {
|
||||||
|
const DESTINATION = path.join(__dirname, destinationPath);
|
||||||
|
let pluginPath = plugin.paths[`esm`];
|
||||||
|
return (
|
||||||
|
gulp.src([
|
||||||
|
pluginPath + '/**/*'
|
||||||
|
])
|
||||||
|
.pipe(es.through(function(data) {
|
||||||
|
if (!/\.js$/.test(data.path)) {
|
||||||
|
this.emit('data', data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let contents = data.contents.toString();
|
||||||
|
|
||||||
|
const info = ts.preProcessFile(contents);
|
||||||
|
for (let i = info.importedFiles.length - 1; i >= 0; i--) {
|
||||||
|
const importText = info.importedFiles[i].fileName;
|
||||||
|
const pos = info.importedFiles[i].pos;
|
||||||
|
const end = info.importedFiles[i].end;
|
||||||
|
|
||||||
|
if (!/(^\.\/)|(^\.\.\/)/.test(importText)) {
|
||||||
|
// non-relative import
|
||||||
|
if (!/^monaco-editor-core/.test(importText)) {
|
||||||
|
console.error(`Non-relative import for unknown module: ${importText}`);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const myFileDestPath = path.join(DESTINATION, plugin.modulePrefix, data.relative);
|
||||||
|
const importFilePath = path.join(DESTINATION, importText.substr('monaco-editor-core/esm/'.length));
|
||||||
|
let relativePath = path.relative(path.dirname(myFileDestPath), importFilePath);
|
||||||
|
if (!/(^\.\/)|(^\.\.\/)/.test(relativePath)) {
|
||||||
|
relativePath = './' + relativePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
contents = (
|
||||||
|
contents.substring(0, pos + 1)
|
||||||
|
+ relativePath
|
||||||
|
+ contents.substring(end + 1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data.contents = new Buffer(contents);
|
||||||
|
this.emit('data', data);
|
||||||
|
}))
|
||||||
|
.pipe(es.through(function(data) {
|
||||||
|
if (!/monaco\.contribution\.js$/.test(data.path)) {
|
||||||
|
this.emit('data', data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const myFileDestPath = path.join(DESTINATION, plugin.modulePrefix, data.relative);
|
||||||
|
const apiFilePath = path.join(DESTINATION, 'vs/editor/editor.api');
|
||||||
|
let relativePath = path.relative(path.dirname(myFileDestPath), apiFilePath);
|
||||||
|
if (!/(^\.\/)|(^\.\.\/)/.test(relativePath)) {
|
||||||
|
relativePath = './' + relativePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
let contents = data.contents.toString();
|
||||||
|
contents = (
|
||||||
|
`import '${relativePath}';\n` +
|
||||||
|
contents
|
||||||
|
);
|
||||||
|
|
||||||
|
data.contents = new Buffer(contents);
|
||||||
|
|
||||||
|
this.emit('data', data);
|
||||||
|
}))
|
||||||
|
.pipe(ESM_addImportSuffix())
|
||||||
|
.pipe(gulp.dest(destinationPath + plugin.modulePrefix))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ESM_addImportSuffix() {
|
||||||
|
return es.through(function(data) {
|
||||||
|
if (!/\.js$/.test(data.path)) {
|
||||||
|
this.emit('data', data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let contents = data.contents.toString();
|
||||||
|
|
||||||
|
const info = ts.preProcessFile(contents);
|
||||||
|
for (let i = info.importedFiles.length - 1; i >= 0; i--) {
|
||||||
|
const importText = info.importedFiles[i].fileName;
|
||||||
|
const pos = info.importedFiles[i].pos;
|
||||||
|
const end = info.importedFiles[i].end;
|
||||||
|
|
||||||
|
if (/\.css$/.test(importText)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
contents = (
|
||||||
|
contents.substring(0, pos + 1)
|
||||||
|
+ importText + '.js'
|
||||||
|
+ contents.substring(end + 1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
data.contents = new Buffer(contents);
|
||||||
|
this.emit('data', data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* - Rename esm/vs/editor/editor.main.js to esm/vs/editor/edcore.main.js
|
||||||
|
* - Create esm/vs/editor/editor.main.js that that stiches things together
|
||||||
|
*/
|
||||||
|
function ESM_addPluginContribs(dest) {
|
||||||
|
const DESTINATION = path.join(__dirname, dest);
|
||||||
|
return es.through(function(data) {
|
||||||
|
if (!/editor\.main\.js$/.test(data.path)) {
|
||||||
|
this.emit('data', data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.emit('data', new File({
|
||||||
|
path: data.path.replace(/editor\.main/, 'edcore.main'),
|
||||||
|
base: data.base,
|
||||||
|
contents: data.contents
|
||||||
|
}));
|
||||||
|
|
||||||
|
const mainFileDestPath = path.join(DESTINATION, 'vs/editor/editor.main.js');
|
||||||
|
let mainFileImports = [];
|
||||||
|
metadata.METADATA.PLUGINS.forEach(function(plugin) {
|
||||||
|
const contribDestPath = path.join(DESTINATION, plugin.contrib);
|
||||||
|
|
||||||
|
let relativePath = path.relative(path.dirname(mainFileDestPath), contribDestPath);
|
||||||
|
if (!/(^\.\/)|(^\.\.\/)/.test(relativePath)) {
|
||||||
|
relativePath = './' + relativePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
mainFileImports.push(relativePath);
|
||||||
|
});
|
||||||
|
|
||||||
|
let mainFileContents = (
|
||||||
|
mainFileImports.map((name) => `import '${name}';`).join('\n')
|
||||||
|
+ `\n\nexport * from './edcore.main';`
|
||||||
|
);
|
||||||
|
|
||||||
|
this.emit('data', new File({
|
||||||
|
path: data.path,
|
||||||
|
base: data.base,
|
||||||
|
contents: new Buffer(mainFileContents)
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit monaco.d.ts:
|
* Edit monaco.d.ts:
|
||||||
* - append monaco.d.ts from plugins
|
* - append monaco.d.ts from plugins
|
||||||
|
|
|
||||||
23
metadata.js
23
metadata.js
|
|
@ -11,7 +11,8 @@
|
||||||
releaseMin: 'release/min/vs',
|
releaseMin: 'release/min/vs',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PLUGINS: [{
|
PLUGINS: [
|
||||||
|
{
|
||||||
name: 'monaco-typescript',
|
name: 'monaco-typescript',
|
||||||
contrib: 'vs/language/typescript/monaco.contribution',
|
contrib: 'vs/language/typescript/monaco.contribution',
|
||||||
modulePrefix: 'vs/language/typescript',
|
modulePrefix: 'vs/language/typescript',
|
||||||
|
|
@ -20,8 +21,10 @@
|
||||||
src: '/monaco-typescript/release/dev',
|
src: '/monaco-typescript/release/dev',
|
||||||
'npm/dev': 'node_modules/monaco-typescript/release/dev',
|
'npm/dev': 'node_modules/monaco-typescript/release/dev',
|
||||||
'npm/min': 'node_modules/monaco-typescript/release/min',
|
'npm/min': 'node_modules/monaco-typescript/release/min',
|
||||||
|
esm: 'node_modules/monaco-typescript/release/esm',
|
||||||
}
|
}
|
||||||
},{
|
},
|
||||||
|
{
|
||||||
name: 'monaco-css',
|
name: 'monaco-css',
|
||||||
contrib: 'vs/language/css/monaco.contribution',
|
contrib: 'vs/language/css/monaco.contribution',
|
||||||
modulePrefix: 'vs/language/css',
|
modulePrefix: 'vs/language/css',
|
||||||
|
|
@ -29,8 +32,10 @@
|
||||||
src: '/monaco-css/release/dev',
|
src: '/monaco-css/release/dev',
|
||||||
'npm/dev': 'node_modules/monaco-css/release/dev',
|
'npm/dev': 'node_modules/monaco-css/release/dev',
|
||||||
'npm/min': 'node_modules/monaco-css/release/min',
|
'npm/min': 'node_modules/monaco-css/release/min',
|
||||||
|
esm: 'node_modules/monaco-css/release/esm',
|
||||||
}
|
}
|
||||||
},{
|
},
|
||||||
|
{
|
||||||
name: 'monaco-json',
|
name: 'monaco-json',
|
||||||
contrib: 'vs/language/json/monaco.contribution',
|
contrib: 'vs/language/json/monaco.contribution',
|
||||||
modulePrefix: 'vs/language/json',
|
modulePrefix: 'vs/language/json',
|
||||||
|
|
@ -38,8 +43,10 @@
|
||||||
src: '/monaco-json/release/dev',
|
src: '/monaco-json/release/dev',
|
||||||
'npm/dev': 'node_modules/monaco-json/release/dev',
|
'npm/dev': 'node_modules/monaco-json/release/dev',
|
||||||
'npm/min': 'node_modules/monaco-json/release/min',
|
'npm/min': 'node_modules/monaco-json/release/min',
|
||||||
|
esm: 'node_modules/monaco-json/release/esm',
|
||||||
}
|
}
|
||||||
},{
|
},
|
||||||
|
{
|
||||||
name: 'monaco-html',
|
name: 'monaco-html',
|
||||||
contrib: 'vs/language/html/monaco.contribution',
|
contrib: 'vs/language/html/monaco.contribution',
|
||||||
modulePrefix: 'vs/language/html',
|
modulePrefix: 'vs/language/html',
|
||||||
|
|
@ -48,8 +55,10 @@
|
||||||
src: '/monaco-html/release/dev',
|
src: '/monaco-html/release/dev',
|
||||||
'npm/dev': 'node_modules/monaco-html/release/dev',
|
'npm/dev': 'node_modules/monaco-html/release/dev',
|
||||||
'npm/min': 'node_modules/monaco-html/release/min',
|
'npm/min': 'node_modules/monaco-html/release/min',
|
||||||
|
esm: 'node_modules/monaco-html/release/esm',
|
||||||
}
|
}
|
||||||
},{
|
},
|
||||||
|
{
|
||||||
name: 'monaco-languages',
|
name: 'monaco-languages',
|
||||||
contrib: 'vs/basic-languages/monaco.contribution',
|
contrib: 'vs/basic-languages/monaco.contribution',
|
||||||
modulePrefix: 'vs/basic-languages',
|
modulePrefix: 'vs/basic-languages',
|
||||||
|
|
@ -58,8 +67,10 @@
|
||||||
src: '/monaco-languages/release/dev',
|
src: '/monaco-languages/release/dev',
|
||||||
'npm/dev': 'node_modules/monaco-languages/release/dev',
|
'npm/dev': 'node_modules/monaco-languages/release/dev',
|
||||||
'npm/min': 'node_modules/monaco-languages/release/min',
|
'npm/min': 'node_modules/monaco-languages/release/min',
|
||||||
|
esm: 'node_modules/monaco-languages/release/esm',
|
||||||
}
|
}
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof exports !== 'undefined') {
|
if (typeof exports !== 'undefined') {
|
||||||
|
|
|
||||||
12
package-lock.json
generated
12
package-lock.json
generated
|
|
@ -3891,6 +3891,12 @@
|
||||||
"requires": {
|
"requires": {
|
||||||
"brace-expansion": "1.1.11"
|
"brace-expansion": "1.1.11"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"typescript": {
|
||||||
|
"version": "2.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.4.1.tgz",
|
||||||
|
"integrity": "sha1-w8yxbdqgsjFN4DHn5v7onlujRrw=",
|
||||||
|
"dev": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -3901,9 +3907,9 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"typescript": {
|
"typescript": {
|
||||||
"version": "2.4.1",
|
"version": "2.7.2",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.7.2.tgz",
|
||||||
"integrity": "sha1-w8yxbdqgsjFN4DHn5v7onlujRrw=",
|
"integrity": "sha512-p5TCYZDAO0m4G344hD+wx/LATebLWZNkkh2asWUFqSsD2OrDNhbAHuSjobrmsUmdzjJjEeZVU9g1h3O6vpstnw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"uglify-js": {
|
"uglify-js": {
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@
|
||||||
"monaco-typescript": "3.0.0",
|
"monaco-typescript": "3.0.0",
|
||||||
"rimraf": "^2.5.2",
|
"rimraf": "^2.5.2",
|
||||||
"typedoc": "^0.8.0",
|
"typedoc": "^0.8.0",
|
||||||
"uncss": "^0.14.1"
|
"typescript": "^2.7.2",
|
||||||
|
"uncss": "^0.14.1",
|
||||||
|
"vinyl": "^0.5.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue