mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 12:45:39 +01:00
Exported modules reorganization
This commit is contained in:
parent
ec78a33c7b
commit
f534b2234e
434 changed files with 798 additions and 482 deletions
|
|
@ -8,12 +8,16 @@
|
|||
import { dirname, join } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { readdirSync } from 'fs';
|
||||
import glob from 'glob';
|
||||
|
||||
/**
|
||||
* @param {string} filePath
|
||||
* @param {string} newExt
|
||||
*/
|
||||
export function changeExt(filePath, newExt) {
|
||||
if (filePath.endsWith(newExt)) {
|
||||
return filePath;
|
||||
}
|
||||
const idx = filePath.lastIndexOf('.');
|
||||
if (idx === -1) {
|
||||
return filePath + newExt;
|
||||
|
|
@ -22,20 +26,49 @@ export function changeExt(filePath, newExt) {
|
|||
}
|
||||
}
|
||||
|
||||
export function getNlsEntryPoints() {
|
||||
/**
|
||||
* @returns {{ pathFromRoot: string, source: { value: string } | { absolutePath: string } }[]}
|
||||
*/
|
||||
export function getAdditionalFiles() {
|
||||
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;
|
||||
return readdirSync(nlsDir)
|
||||
.flatMap(file => {
|
||||
const match = /nls\.messages\.(?<lang>.+)\.js/.exec(file);
|
||||
if (!match) {
|
||||
return [];
|
||||
}
|
||||
const lang = match.groups?.lang;
|
||||
return [
|
||||
{
|
||||
pathFromRoot: join('vs', 'nls', 'lang', lang + '.js'),
|
||||
source: { absolutePath: join(nlsDir, file) }
|
||||
},
|
||||
{
|
||||
pathFromRoot: join('vs', 'nls', 'lang', lang + '.d.ts'),
|
||||
source: { value: 'export {};' }
|
||||
}
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
const root = join(import.meta.dirname, '../');
|
||||
|
||||
/**
|
||||
* @param {string} pattern
|
||||
* @returns
|
||||
*/
|
||||
function findFiles(pattern) {
|
||||
return glob.sync(pattern, { cwd: root });
|
||||
}
|
||||
|
||||
export function getAdditionalEntryPoints() {
|
||||
const features = Object.fromEntries(findFiles('./src/**/register.*').filter(p => !p.includes('.d.ts')).map(v => [v, join(root, v)]));
|
||||
return {
|
||||
...features,
|
||||
'editor': join(root, 'src/editor.ts')
|
||||
};
|
||||
}
|
||||
|
||||
const mappedPaths = {
|
||||
[join(root, 'node_modules/monaco-editor-core/esm/')]: '.',
|
||||
[join(root, 'node_modules/')]: 'external/',
|
||||
|
|
@ -87,7 +120,7 @@ declare namespace languages {
|
|||
/** @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