diff --git a/build/amd/rollup-types.config.mjs b/build/amd/rollup-types.config.mjs index 0a591923..84fb946a 100644 --- a/build/amd/rollup-types.config.mjs +++ b/build/amd/rollup-types.config.mjs @@ -9,45 +9,22 @@ 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/' -}; +import { dtsDeprecationWarning, mapModuleId } from '../shared.mjs'; export default defineConfig({ input: { types: join(import.meta.dirname, './src/types.ts') }, output: { - dir: outDir, + dir: join(import.meta.dirname, './out'), 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'); - } + const m = mapModuleId(moduleId, '.d.ts'); + if (m !== undefined) { + return m; } } return '[name].d.ts'; @@ -61,6 +38,7 @@ export default defineConfig({ stripInternal: true }, includeExternal: ['monaco-editor-core', '@vscode/monaco-lsp-client'] - }) + }), + dtsDeprecationWarning(), ] }); diff --git a/build/amd/vite.config.js b/build/amd/vite.config.mjs similarity index 82% rename from build/amd/vite.config.js rename to build/amd/vite.config.mjs index b4f735f4..9be71e84 100644 --- a/build/amd/vite.config.js +++ b/build/amd/vite.config.mjs @@ -1,23 +1,13 @@ import { readFileSync } from 'node:fs'; -import { glob } from 'node:fs/promises'; -import { basename, dirname, join, resolve } from 'node:path'; +import { dirname, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { defineConfig } from 'vite'; import { urlToEsmPlugin } from './plugin'; +import { getNlsEntryPoints } from '../shared.mjs'; const __dirname = dirname(fileURLToPath(import.meta.url)); export default defineConfig(async (args) => { - const monacoEditorCoreDir = join( - dirname(require.resolve('monaco-editor-core/package.json')), - 'esm' - ); - const nlsEntries = {}; - for await (const path of glob(`${monacoEditorCoreDir}/nls.messages.*.js`)) { - const entryName = basename(path).replace('.js', ''); - nlsEntries[entryName] = path; - } - /** @type {import('vite').UserConfig} */ return { base: './', @@ -28,7 +18,7 @@ export default defineConfig(async (args) => { lib: { cssFileName: 'editor/editor.main', entry: { - ...nlsEntries, + ...getNlsEntryPoints(), 'nls.messages-loader': resolve(__dirname, 'src/nls.messages-loader.js'), 'editor/editor.main': resolve(__dirname, 'src/editor.main.ts'), 'basic-languages/monaco.contribution': resolve( diff --git a/build/build-monaco-editor.ts b/build/build-monaco-editor.ts index 2d718f28..71d9f671 100644 --- a/build/build-monaco-editor.ts +++ b/build/build-monaco-editor.ts @@ -8,11 +8,11 @@ import fs = require('fs'); import { REPO_ROOT, readFiles, writeFiles } from '../build/utils'; import { generateEsmMetadataJsAndDTs } from './releaseMetadata'; import { buildESM } from './esm/build.script'; -import { removeDir } from './fs'; import { buildAmdMinDev } from './amd/build.script'; +import { rm } from 'fs/promises'; async function run() { - removeDir(`out/monaco-editor`); + await rm(path.join(REPO_ROOT, './out/monaco-editor'), { recursive: true, force: true }); await buildESM(); await buildAmdMinDev(); diff --git a/build/esm/rollup-types.config.mjs b/build/esm/rollup-types.config.mjs index a622c2ca..c4610971 100644 --- a/build/esm/rollup-types.config.mjs +++ b/build/esm/rollup-types.config.mjs @@ -9,46 +9,24 @@ import nodeResolve from '@rollup/plugin-node-resolve'; import { join } from 'path'; import { defineConfig } from 'rollup'; import { dts } from "rollup-plugin-dts"; +import { dtsDeprecationWarning, mapModuleId } from '../shared.mjs'; const root = join(import.meta.dirname, '../../'); -const outDir = join(root, './out/monaco-editor/esm'); - -/** - * @param {string} filePath - * @param {string} newExt - * @returns {string} - */ -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: { entry: join(root, './src/editor/editor.main.ts'), }, output: { - dir: outDir, + dir: join(root, './out/monaco-editor/esm'), 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'); - } + const m = mapModuleId(moduleId, '.d.ts'); + if (m !== undefined) { + return m; } } return '[name].d.ts'; @@ -63,5 +41,6 @@ export default defineConfig({ }, includeExternal: ['monaco-editor-core', '@vscode/monaco-lsp-client'] }), + dtsDeprecationWarning(), ], }); diff --git a/build/esm/rollup.config.mjs b/build/esm/rollup.config.mjs index 4c6bf1bd..37b08bd5 100644 --- a/build/esm/rollup.config.mjs +++ b/build/esm/rollup.config.mjs @@ -13,48 +13,13 @@ import del from 'rollup-plugin-delete'; import keepCssImports from './rollup-plugin-keep-css-imports/dist/index.mjs'; import nodeResolve from '@rollup/plugin-node-resolve'; import { urlToEsmPlugin } from './rollup-url-to-module-plugin/index.mjs'; -import { copyFileSync, mkdirSync } from 'fs'; -import { dirname } from 'path'; -import { fileURLToPath } from 'url'; -import { readdirSync } from 'fs'; +import { getNlsEntryPoints, mapModuleId } from '../shared.mjs'; +import { readFileSync } from 'fs'; + const root = join(import.meta.dirname, '../../'); const outDir = join(root, './out/monaco-editor/esm'); -/** - * @param {string} filePath - * @param {string} newExt - * @returns {string} - */ -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, 'monaco-lsp-client/')]: 'external/monaco-lsp-client/', - [join(root, 'src/')]: 'vs/', -}; - -function getNlsEntryPoints() { - // Scan for nls.messages.*.js files dynamically - const nlsDir = dirname(fileURLToPath(import.meta.resolve('monaco-editor-core/esm/nls.messages.en.js'))); - const nlsFiles = readdirSync(nlsDir) - .filter(file => file.startsWith('nls.messages.') && file.endsWith('.js')) - .reduce((acc, file) => { - // @ts-ignore - acc[file] = join(nlsDir, file); - return acc; - }, {}); - return nlsFiles; -} - export default defineConfig({ input: { entry: join(root, './src/editor/editor.main.ts'), @@ -72,11 +37,9 @@ export default defineConfig({ 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), '.js'); - } + const r = mapModuleId(moduleId, '.js'); + if (r !== undefined) { + return r; } } return '[name].js'; @@ -90,11 +53,12 @@ export default defineConfig({ { name: 'copy-codicon-font', - buildEnd() { - const codiconSource = join(root, 'node_modules/monaco-editor-core/esm/vs/base/browser/ui/codicons/codicon/codicon.ttf'); - const codiconDest = join(outDir, 'vs/base/browser/ui/codicons/codicon/codicon.ttf'); - mkdirSync(dirname(codiconDest), { recursive: true }); - copyFileSync(codiconSource, codiconDest); + generateBundle() { + this.emitFile({ + type: 'asset', + fileName: 'vs/base/browser/ui/codicons/codicon/codicon.ttf', + source: readFileSync(join(root, 'node_modules/monaco-editor-core/esm/vs/base/browser/ui/codicons/codicon/codicon.ttf')) + }); } }, @@ -106,13 +70,10 @@ export default defineConfig({ * @param {string} assetId */ outputPath: (assetId) => { - for (const [key, val] of Object.entries(mappedPaths)) { - if (assetId.startsWith(key)) { - const relativePath = assetId.substring(key.length); - return changeExt(join(outDir, val, relativePath), '.css'); - } + const r = mapModuleId(assetId, '.css'); + if (r !== undefined) { + return join(outDir, r); } - const relativePath = join(outDir, relative(root, assetId)); return relativePath.replace(/(\.s[ca]ss)$/, ".min$1") }, diff --git a/build/fs.ts b/build/fs.ts index 1fc659a2..83189b8f 100644 --- a/build/fs.ts +++ b/build/fs.ts @@ -23,25 +23,12 @@ export function ensureDir(dirname: string) { if (!existingDirCache.has(dir)) { try { fs.mkdirSync(dir); - } catch (err) {} + } catch (err) { } existingDirCache.add(dir); } }); } -/** - * Copy a file. - */ -export function copyFile(_source: string, _destination: string) { - const source = path.join(REPO_ROOT, _source); - const destination = path.join(REPO_ROOT, _destination); - - ensureDir(path.dirname(destination)); - fs.writeFileSync(destination, fs.readFileSync(source)); - - console.log(`Copied ${_source} to ${_destination}`); -} - /** * Remove a directory and all its contents. */ diff --git a/build/shared.mjs b/build/shared.mjs new file mode 100644 index 00000000..900ea618 --- /dev/null +++ b/build/shared.mjs @@ -0,0 +1,90 @@ +/*--------------------------------------------------------------------------------------------- + * 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 { dirname, join } from 'path'; +import { fileURLToPath } from 'url'; +import { readdirSync } from 'fs'; + +/** + * @param {string} filePath + * @param {string} newExt + */ +export function changeExt(filePath, newExt) { + const idx = filePath.lastIndexOf('.'); + if (idx === -1) { + return filePath + newExt; + } else { + return filePath.substring(0, idx) + newExt; + } +} + +export function getNlsEntryPoints() { + const nlsDir = dirname(fileURLToPath(import.meta.resolve('monaco-editor-core/esm/nls.messages.en.js'))); + const nlsFiles = readdirSync(nlsDir) + .filter(file => file.startsWith('nls.messages.') && file.endsWith('.js')) + .reduce((acc, file) => { + // @ts-ignore + acc[file] = join(nlsDir, file); + return acc; + }, {}); + return nlsFiles; +} + +const root = join(import.meta.dirname, '../'); + +const mappedPaths = { + [join(root, 'node_modules/monaco-editor-core/esm/')]: '.', + [join(root, 'node_modules/')]: 'external/', + [join(root, 'monaco-lsp-client/')]: 'external/monaco-lsp-client/', + [join(root, 'src/')]: 'vs/', +}; + +/** + * @param {string} moduleId + * @param {string} newExt (with leading .) + * @returns {string | undefined} + */ +export function mapModuleId(moduleId, newExt) { + for (const [key, val] of Object.entries(mappedPaths)) { + if (moduleId.startsWith(key)) { + const relativePath = moduleId.substring(key.length); + return changeExt(join(val, relativePath), newExt); + } + } + return undefined; +} + +/** @return {import('rollup').Plugin} */ +export function dtsDeprecationWarning() { + return { + name: 'add-dts-deprecation-warning', + generateBundle(options, bundle) { + for (const fileName in bundle) { + const file = bundle[fileName]; + if (file.type === 'chunk' && fileName.endsWith('.d.ts')) { + let content = file.code.toString(); + content = content + ` +declare namespace languages { + /** @deprecated Use the new top level "css" namespace instead. */ + export const css: { deprecated: true }; + + /** @deprecated Use the new top level "html" namespace instead. */ + export const html: { deprecated: true }; + + /** @deprecated Use the new top level "json" namespace instead. */ + export const json: { deprecated: true }; + + /** @deprecated Use the new top level "typescript" namespace instead. */ + export const typescript: { deprecated: true }; +} +`; + file.code = content; + } + } + } + }; +} diff --git a/monaco-lsp-client/package-lock.json b/monaco-lsp-client/package-lock.json index 03240878..2f47ccae 100644 --- a/monaco-lsp-client/package-lock.json +++ b/monaco-lsp-client/package-lock.json @@ -21,22 +21,6 @@ "monaco-editor-core": "^0.54.0-dev-20250929" } }, - "../../../hediet/typed-json-rpc/json-rpc": { - "name": "@hediet/json-rpc", - "version": "0.5.0", - "license": "MIT", - "devDependencies": { - "typescript": "^5.8.3" - } - }, - "../../../hediet/typed-json-rpc/json-rpc-browser": { - "name": "@hediet/json-rpc-browser", - "version": "0.5.1", - "license": "MIT", - "dependencies": { - "@hediet/json-rpc": "^0.5.0" - } - }, "../../../hediet/typed-json-rpc/json-rpc-node": { "name": "@hediet/json-rpc-node", "version": "0.5.0", @@ -55,16 +39,6 @@ "source-map-support": "^0.5.12" } }, - "../../../hediet/typed-json-rpc/json-rpc-websocket": { - "name": "@hediet/json-rpc-websocket", - "version": "0.5.1", - "license": "MIT", - "dependencies": { - "@hediet/json-rpc": "^0.5.0", - "@types/ws": "^6.0.4", - "isomorphic-ws": "^5.0.0" - } - }, "../../hediet/typed-json-rpc/json-rpc-browser": { "extraneous": true }, @@ -170,16 +144,30 @@ } }, "node_modules/@hediet/json-rpc": { - "resolved": "../../../hediet/typed-json-rpc/json-rpc", - "link": true + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/@hediet/json-rpc/-/json-rpc-0.5.0.tgz", + "integrity": "sha512-SApO7NbKJztClcznEqg46ZGQzO2v3Q3gVIuRVC9QE/m75J/5AipJdclxEXgT++7j4x4LI2JjEpf2xhi67Ngu9A==", + "license": "MIT" }, "node_modules/@hediet/json-rpc-browser": { - "resolved": "../../../hediet/typed-json-rpc/json-rpc-browser", - "link": true + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/@hediet/json-rpc-browser/-/json-rpc-browser-0.5.1.tgz", + "integrity": "sha512-iR+WrTdM7WozRJ/MElfeT8CmH2f911Y8P6xfcj5RCfywp7kjnnqKPUV/VnNnzToxRZUO8WAfJtLvmhDBsSjMtA==", + "license": "MIT", + "dependencies": { + "@hediet/json-rpc": "^0.5.0" + } }, "node_modules/@hediet/json-rpc-websocket": { - "resolved": "../../../hediet/typed-json-rpc/json-rpc-websocket", - "link": true + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/@hediet/json-rpc-websocket/-/json-rpc-websocket-0.5.1.tgz", + "integrity": "sha512-1H9UjKyR00ZjwcReQdzTxyEoZKaEubeOvxBVrwHGo4n9HeQt6SvQgtef+1AJ9MT7/sV2Qfe0VWarYivx6BWgIA==", + "license": "MIT", + "dependencies": { + "@hediet/json-rpc": "^0.5.0", + "@types/ws": "^6.0.4", + "isomorphic-ws": "^5.0.0" + } }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.13", @@ -888,6 +876,24 @@ "license": "MIT", "peer": true }, + "node_modules/@types/node": { + "version": "24.10.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.0.tgz", + "integrity": "sha512-qzQZRBqkFsYyaSWXuEHc2WR9c0a0CXwiE5FWUvn7ZM+vdy1uZLfCunD38UzhuB7YN/J11ndbDBcTmOdxJo9Q7A==", + "license": "MIT", + "dependencies": { + "undici-types": "~7.16.0" + } + }, + "node_modules/@types/ws": { + "version": "6.0.4", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-6.0.4.tgz", + "integrity": "sha512-PpPrX7SZW9re6+Ha8ojZG4Se8AZXgf0GK6zmfqEuCsY49LFDNXO3SByp44X3dFEqtB73lkCDAdUazhAjVPiNwg==", + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/ansis": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/ansis/-/ansis-4.2.0.tgz", @@ -1176,6 +1182,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/isomorphic-ws": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/isomorphic-ws/-/isomorphic-ws-5.0.0.tgz", + "integrity": "sha512-muId7Zzn9ywDsyXgTIafTry2sV3nySZeUDe6YedVd1Hvuuep5AsIlqK+XefWpYTyJG5e503F2xIuT2lcU6rCSw==", + "license": "MIT", + "peerDependencies": { + "ws": "*" + } + }, "node_modules/jsesc": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz", @@ -1547,6 +1562,12 @@ "license": "0BSD", "optional": true }, + "node_modules/undici-types": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz", + "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==", + "license": "MIT" + }, "node_modules/unicorn-magic": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/unicorn-magic/-/unicorn-magic-0.3.0.tgz", @@ -1559,6 +1580,28 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/ws": { + "version": "8.18.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz", + "integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } } } }