mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 07:00:11 +01:00
Cleans up build scripts (#5097)
* Cleans up build scripts * Adds back removeDir
This commit is contained in:
parent
abae948dc3
commit
d84acb4d8f
8 changed files with 199 additions and 171 deletions
90
build/shared.mjs
Normal file
90
build/shared.mjs
Normal file
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue