mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 05:50:11 +01:00
uses rollup to bundle monaco-editor's monaco.d.ts (#5033)
* uses rollup to bundle monaco-editor's monaco.d.ts * Adds missing await
This commit is contained in:
parent
298ad9e43d
commit
a59f6c8a72
7 changed files with 1428 additions and 422 deletions
|
|
@ -4,4 +4,5 @@ export async function buildAmdMinDev() {
|
||||||
const rootPath = __dirname;
|
const rootPath = __dirname;
|
||||||
await run('npx vite build --mode development', { cwd: rootPath });
|
await run('npx vite build --mode development', { cwd: rootPath });
|
||||||
await run('npx vite build', { cwd: rootPath });
|
await run('npx vite build', { cwd: rootPath });
|
||||||
|
await run('npx rollup -c rollup-types.config.mjs', { cwd: rootPath });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
66
build/amd/rollup-types.config.mjs
Normal file
66
build/amd/rollup-types.config.mjs
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// @ts-check
|
||||||
|
|
||||||
|
import nodeResolve from '@rollup/plugin-node-resolve';
|
||||||
|
import { join } from 'path';
|
||||||
|
import { defineConfig } from 'rollup';
|
||||||
|
import { dts } from 'rollup-plugin-dts';
|
||||||
|
|
||||||
|
const root = join(import.meta.dirname, '../../');
|
||||||
|
const outDir = join(import.meta.dirname, './out');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} filePath
|
||||||
|
* @param {string} newExt
|
||||||
|
*/
|
||||||
|
function changeExt(filePath, newExt) {
|
||||||
|
const idx = filePath.lastIndexOf('.');
|
||||||
|
if (idx === -1) {
|
||||||
|
return filePath + newExt;
|
||||||
|
} else {
|
||||||
|
return filePath.substring(0, idx) + newExt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const mappedPaths = {
|
||||||
|
[join(root, 'node_modules/monaco-editor-core/esm/')]: '.',
|
||||||
|
[join(root, 'node_modules/')]: 'external/',
|
||||||
|
[join(root, 'src/')]: 'vs/'
|
||||||
|
};
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
input: {
|
||||||
|
types: join(import.meta.dirname, './src/types.ts')
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
dir: outDir,
|
||||||
|
format: 'es',
|
||||||
|
preserveModules: false,
|
||||||
|
entryFileNames: function (chunkInfo) {
|
||||||
|
const moduleId = chunkInfo.facadeModuleId;
|
||||||
|
if (moduleId) {
|
||||||
|
for (const [key, val] of Object.entries(mappedPaths)) {
|
||||||
|
if (moduleId.startsWith(key)) {
|
||||||
|
const relativePath = moduleId.substring(key.length);
|
||||||
|
return changeExt(join(val, relativePath), '.d.ts');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return '[name].d.ts';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
external: [/.*\.css/],
|
||||||
|
plugins: [
|
||||||
|
nodeResolve(),
|
||||||
|
dts({
|
||||||
|
compilerOptions: {
|
||||||
|
stripInternal: true
|
||||||
|
},
|
||||||
|
includeExternal: ['monaco-editor-core']
|
||||||
|
})
|
||||||
|
]
|
||||||
|
});
|
||||||
3
build/amd/src/types.ts
Normal file
3
build/amd/src/types.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
import * as m from './editor.main';
|
||||||
|
|
||||||
|
export { m };
|
||||||
|
|
@ -19,48 +19,57 @@ import { generateMetadata } from './releaseMetadata';
|
||||||
import { buildAmdMinDev } from './amd/build.script';
|
import { buildAmdMinDev } from './amd/build.script';
|
||||||
import ts = require('typescript');
|
import ts = require('typescript');
|
||||||
|
|
||||||
removeDir(`out/monaco-editor`);
|
async function run() {
|
||||||
|
removeDir(`out/monaco-editor`);
|
||||||
|
|
||||||
buildAmdMinDev();
|
await buildAmdMinDev();
|
||||||
|
|
||||||
// esm folder
|
// esm folder
|
||||||
ESM_release();
|
ESM_release();
|
||||||
|
|
||||||
// monaco.d.ts, editor.api.d.ts
|
// monaco.d.ts, editor.api.d.ts
|
||||||
releaseDTS();
|
releaseDTS();
|
||||||
|
|
||||||
// ThirdPartyNotices.txt
|
// copy types.d.ts from build/amd/out/ to out/monaco-editor/monaco.d.ts (and append `declare global { export import monaco = editor_main; }`)
|
||||||
releaseThirdPartyNotices();
|
(() => {
|
||||||
|
let contents = fs.readFileSync('build/amd/out/types.d.ts', { encoding: 'utf8' });
|
||||||
|
contents += '\n\ndeclare global { export import monaco = editor_main; }\n';
|
||||||
|
fs.writeFileSync('out/monaco-editor/monaco.d.ts', contents);
|
||||||
|
})();
|
||||||
|
|
||||||
// esm/metadata.d.ts, esm/metadata.js
|
// ThirdPartyNotices.txt
|
||||||
generateMetadata();
|
releaseThirdPartyNotices();
|
||||||
|
|
||||||
// package.json
|
// esm/metadata.d.ts, esm/metadata.js
|
||||||
(() => {
|
generateMetadata();
|
||||||
const packageJSON = readFiles('package.json', { base: '' })[0];
|
|
||||||
const json = JSON.parse(packageJSON.contents.toString());
|
|
||||||
|
|
||||||
json.private = false;
|
// package.json
|
||||||
delete json.scripts['postinstall'];
|
(() => {
|
||||||
|
const packageJSON = readFiles('package.json', { base: '' })[0];
|
||||||
|
const json = JSON.parse(packageJSON.contents.toString());
|
||||||
|
|
||||||
packageJSON.contents = Buffer.from(JSON.stringify(json, null, ' '));
|
json.private = false;
|
||||||
writeFiles([packageJSON], `out/monaco-editor`);
|
delete json.scripts['postinstall'];
|
||||||
})();
|
|
||||||
|
|
||||||
(() => {
|
packageJSON.contents = Buffer.from(JSON.stringify(json, null, ' '));
|
||||||
/** @type {IFile[]} */
|
writeFiles([packageJSON], `out/monaco-editor`);
|
||||||
let otherFiles = [];
|
})();
|
||||||
|
|
||||||
otherFiles = otherFiles.concat(readFiles('README.md', { base: '' }));
|
(() => {
|
||||||
otherFiles = otherFiles.concat(readFiles('CHANGELOG.md', { base: '' }));
|
/** @type {IFile[]} */
|
||||||
otherFiles = otherFiles.concat(
|
let otherFiles = [];
|
||||||
readFiles('node_modules/monaco-editor-core/LICENSE', {
|
|
||||||
base: 'node_modules/monaco-editor-core/'
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
writeFiles(otherFiles, `out/monaco-editor`);
|
otherFiles = otherFiles.concat(readFiles('README.md', { base: '' }));
|
||||||
})();
|
otherFiles = otherFiles.concat(readFiles('CHANGELOG.md', { base: '' }));
|
||||||
|
otherFiles = otherFiles.concat(
|
||||||
|
readFiles('node_modules/monaco-editor-core/LICENSE', {
|
||||||
|
base: 'node_modules/monaco-editor-core/'
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
writeFiles(otherFiles, `out/monaco-editor`);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
function ESM_release() {
|
function ESM_release() {
|
||||||
const coreFiles = readFiles(`node_modules/monaco-editor-core/esm/**/*`, {
|
const coreFiles = readFiles(`node_modules/monaco-editor-core/esm/**/*`, {
|
||||||
|
|
@ -354,3 +363,5 @@ function releaseThirdPartyNotices() {
|
||||||
|
|
||||||
writeFiles([tpn], `out/monaco-editor`);
|
writeFiles([tpn], `out/monaco-editor`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run();
|
||||||
|
|
|
||||||
1687
package-lock.json
generated
1687
package-lock.json
generated
File diff suppressed because it is too large
Load diff
10
package.json
10
package.json
|
|
@ -40,6 +40,8 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@playwright/test": "^1.53.2",
|
"@playwright/test": "^1.53.2",
|
||||||
|
"@rollup/plugin-alias": "^5.1.1",
|
||||||
|
"@rollup/plugin-node-resolve": "^16.0.2",
|
||||||
"@types/mocha": "^10.0.10",
|
"@types/mocha": "^10.0.10",
|
||||||
"@types/shelljs": "^0.8.11",
|
"@types/shelljs": "^0.8.11",
|
||||||
"@types/trusted-types": "^1.0.6",
|
"@types/trusted-types": "^1.0.6",
|
||||||
|
|
@ -56,12 +58,18 @@
|
||||||
"jsdom": "^19.0.0",
|
"jsdom": "^19.0.0",
|
||||||
"jsonc-parser": "^3.0.0",
|
"jsonc-parser": "^3.0.0",
|
||||||
"mocha": "^11.7.4",
|
"mocha": "^11.7.4",
|
||||||
"monaco-editor-core": "^0.54.0-dev-20251002",
|
"monaco-editor-core": "^0.55.0-dev-20251008",
|
||||||
"parcel": "^2.7.0",
|
"parcel": "^2.7.0",
|
||||||
"pin-github-action": "^1.8.0",
|
"pin-github-action": "^1.8.0",
|
||||||
"prettier": "^2.5.1",
|
"prettier": "^2.5.1",
|
||||||
"pretty-quick": "^3.1.3",
|
"pretty-quick": "^3.1.3",
|
||||||
"requirejs": "^2.3.7",
|
"requirejs": "^2.3.7",
|
||||||
|
"rollup": "^4.52.4",
|
||||||
|
"rollup-plugin-delete": "^3.0.1",
|
||||||
|
"rollup-plugin-dts": "^6.2.3",
|
||||||
|
"rollup-plugin-esbuild": "^6.2.1",
|
||||||
|
"rollup-plugin-import-css": "^4.0.2",
|
||||||
|
"rollup-plugin-keep-css-imports": "^1.0.0",
|
||||||
"shelljs": "^0.8.5",
|
"shelljs": "^0.8.5",
|
||||||
"style-loader": "^3.3.1",
|
"style-loader": "^3.3.1",
|
||||||
"terser": "^5.14.2",
|
"terser": "^5.14.2",
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
import { createWebWorker } from '../common/workers.js';
|
import { createWebWorker } from '../common/workers.js';
|
||||||
import '../basic-languages/monaco.contribution.js';
|
import '../basic-languages/monaco.contribution.js';
|
||||||
import '../language/css/monaco.contribution.js';
|
import * as css from '../language/css/monaco.contribution.js';
|
||||||
import '../language/html/monaco.contribution.js';
|
import * as html from '../language/html/monaco.contribution.js';
|
||||||
import '../language/json/monaco.contribution.js';
|
import * as json from '../language/json/monaco.contribution.js';
|
||||||
import '../language/typescript/monaco.contribution.js';
|
import * as typescript from '../language/typescript/monaco.contribution.js';
|
||||||
import * as monaco from 'monaco-editor-core';
|
import * as monaco from 'monaco-editor-core';
|
||||||
export * from 'monaco-editor-core';
|
export * from 'monaco-editor-core';
|
||||||
|
|
||||||
|
export { css, html, json, typescript };
|
||||||
|
|
||||||
const existingCreateWebWorker = monaco.editor.createWebWorker;
|
const existingCreateWebWorker = monaco.editor.createWebWorker;
|
||||||
monaco.editor.createWebWorker = function (options: any) {
|
monaco.editor.createWebWorker = function (options: any) {
|
||||||
if (options.worker === undefined) {
|
if (options.worker === undefined) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue