@@ -13,48 +13,13 @@ import del from 'rollup-plugin-delete';
1313import keepCssImports from './rollup-plugin-keep-css-imports/dist/index.mjs' ;
1414import nodeResolve from '@rollup/plugin-node-resolve' ;
1515import { urlToEsmPlugin } from './rollup-url-to-module-plugin/index.mjs' ;
16- import { copyFileSync , mkdirSync } from 'fs' ;
17- import { dirname } from 'path' ;
18- import { fileURLToPath } from 'url' ;
19- import { readdirSync } from 'fs' ;
16+ import { getNlsEntryPoints , mapModuleId } from '../shared.mjs' ;
17+ import { readFileSync } from 'fs' ;
18+
2019
2120const root = join ( import . meta. dirname , '../../' ) ;
2221const outDir = join ( root , './out/monaco-editor/esm' ) ;
2322
24- /**
25- * @param {string } filePath
26- * @param {string } newExt
27- * @returns {string }
28- */
29- function changeExt ( filePath , newExt ) {
30- const idx = filePath . lastIndexOf ( '.' ) ;
31- if ( idx === - 1 ) {
32- return filePath + newExt ;
33- } else {
34- return filePath . substring ( 0 , idx ) + newExt ;
35- }
36- }
37-
38- const mappedPaths = {
39- [ join ( root , 'node_modules/monaco-editor-core/esm/' ) ] : '.' ,
40- [ join ( root , 'node_modules/' ) ] : 'external/' ,
41- [ join ( root , 'monaco-lsp-client/' ) ] : 'external/monaco-lsp-client/' ,
42- [ join ( root , 'src/' ) ] : 'vs/' ,
43- } ;
44-
45- function getNlsEntryPoints ( ) {
46- // Scan for nls.messages.*.js files dynamically
47- const nlsDir = dirname ( fileURLToPath ( import . meta. resolve ( 'monaco-editor-core/esm/nls.messages.en.js' ) ) ) ;
48- const nlsFiles = readdirSync ( nlsDir )
49- . filter ( file => file . startsWith ( 'nls.messages.' ) && file . endsWith ( '.js' ) )
50- . reduce ( ( acc , file ) => {
51- // @ts -ignore
52- acc [ file ] = join ( nlsDir , file ) ;
53- return acc ;
54- } , { } ) ;
55- return nlsFiles ;
56- }
57-
5823export default defineConfig ( {
5924 input : {
6025 entry : join ( root , './src/editor/editor.main.ts' ) ,
@@ -72,11 +37,9 @@ export default defineConfig({
7237 entryFileNames : function ( chunkInfo ) {
7338 const moduleId = chunkInfo . facadeModuleId ;
7439 if ( moduleId ) {
75- for ( const [ key , val ] of Object . entries ( mappedPaths ) ) {
76- if ( moduleId . startsWith ( key ) ) {
77- const relativePath = moduleId . substring ( key . length ) ;
78- return changeExt ( join ( val , relativePath ) , '.js' ) ;
79- }
40+ const r = mapModuleId ( moduleId , '.js' ) ;
41+ if ( r !== undefined ) {
42+ return r ;
8043 }
8144 }
8245 return '[name].js' ;
@@ -90,11 +53,12 @@ export default defineConfig({
9053
9154 {
9255 name : 'copy-codicon-font' ,
93- buildEnd ( ) {
94- const codiconSource = join ( root , 'node_modules/monaco-editor-core/esm/vs/base/browser/ui/codicons/codicon/codicon.ttf' ) ;
95- const codiconDest = join ( outDir , 'vs/base/browser/ui/codicons/codicon/codicon.ttf' ) ;
96- mkdirSync ( dirname ( codiconDest ) , { recursive : true } ) ;
97- copyFileSync ( codiconSource , codiconDest ) ;
56+ generateBundle ( ) {
57+ this . emitFile ( {
58+ type : 'asset' ,
59+ fileName : 'vs/base/browser/ui/codicons/codicon/codicon.ttf' ,
60+ source : readFileSync ( join ( root , 'node_modules/monaco-editor-core/esm/vs/base/browser/ui/codicons/codicon/codicon.ttf' ) )
61+ } ) ;
9862 }
9963 } ,
10064
@@ -106,13 +70,10 @@ export default defineConfig({
10670 * @param {string } assetId
10771 */
10872 outputPath : ( assetId ) => {
109- for ( const [ key , val ] of Object . entries ( mappedPaths ) ) {
110- if ( assetId . startsWith ( key ) ) {
111- const relativePath = assetId . substring ( key . length ) ;
112- return changeExt ( join ( outDir , val , relativePath ) , '.css' ) ;
113- }
73+ const r = mapModuleId ( assetId , '.css' ) ;
74+ if ( r !== undefined ) {
75+ return join ( outDir , r ) ;
11476 }
115-
11677 const relativePath = join ( outDir , relative ( root , assetId ) ) ;
11778 return relativePath . replace ( / ( \. s [ c a ] s s ) $ / , ".min$1" )
11879 } ,
0 commit comments