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:
Henning Dieterichs 2025-10-09 21:26:17 +02:00 committed by GitHub
parent 298ad9e43d
commit a59f6c8a72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 1428 additions and 422 deletions

View file

@ -4,4 +4,5 @@ export async function buildAmdMinDev() {
const rootPath = __dirname;
await run('npx vite build --mode development', { cwd: rootPath });
await run('npx vite build', { cwd: rootPath });
await run('npx rollup -c rollup-types.config.mjs', { cwd: rootPath });
}

View 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
View file

@ -0,0 +1,3 @@
import * as m from './editor.main';
export { m };

View file

@ -19,48 +19,57 @@ import { generateMetadata } from './releaseMetadata';
import { buildAmdMinDev } from './amd/build.script';
import ts = require('typescript');
removeDir(`out/monaco-editor`);
async function run() {
removeDir(`out/monaco-editor`);
buildAmdMinDev();
await buildAmdMinDev();
// esm folder
ESM_release();
// esm folder
ESM_release();
// monaco.d.ts, editor.api.d.ts
releaseDTS();
// monaco.d.ts, editor.api.d.ts
releaseDTS();
// ThirdPartyNotices.txt
releaseThirdPartyNotices();
// copy types.d.ts from build/amd/out/ to out/monaco-editor/monaco.d.ts (and append `declare global { export import monaco = editor_main; }`)
(() => {
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
generateMetadata();
// ThirdPartyNotices.txt
releaseThirdPartyNotices();
// package.json
(() => {
const packageJSON = readFiles('package.json', { base: '' })[0];
const json = JSON.parse(packageJSON.contents.toString());
// esm/metadata.d.ts, esm/metadata.js
generateMetadata();
json.private = false;
delete json.scripts['postinstall'];
// package.json
(() => {
const packageJSON = readFiles('package.json', { base: '' })[0];
const json = JSON.parse(packageJSON.contents.toString());
packageJSON.contents = Buffer.from(JSON.stringify(json, null, ' '));
writeFiles([packageJSON], `out/monaco-editor`);
})();
json.private = false;
delete json.scripts['postinstall'];
(() => {
/** @type {IFile[]} */
let otherFiles = [];
packageJSON.contents = Buffer.from(JSON.stringify(json, null, ' '));
writeFiles([packageJSON], `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/'
})
);
(() => {
/** @type {IFile[]} */
let otherFiles = [];
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() {
const coreFiles = readFiles(`node_modules/monaco-editor-core/esm/**/*`, {
@ -354,3 +363,5 @@ function releaseThirdPartyNotices() {
writeFiles([tpn], `out/monaco-editor`);
}
run();