@@ -16,15 +16,14 @@ const pkg = JSON.parse(
1616const EXTENSIONS = [ '' , '.ts' , '.js' ]
1717
1818const MONACO_EDITOR_DIR = path . resolve ( BASE_DIR , 'monaco-editor' )
19- const BASIC_LANGUAGE_DIR = path . resolve ( MONACO_EDITOR_DIR , 'basic-languages' )
20- const LANGUAGE_FEATURE_DIR = path . resolve ( MONACO_EDITOR_DIR , 'language' )
19+ const LANGUAGES_FEATURE_DIR = path . resolve ( MONACO_EDITOR_DIR , 'languages' )
2120
22- const monacoContributions = (
23- await glob ( '**/monaco.contribution .js' , {
24- cwd : LANGUAGE_FEATURE_DIR ,
21+ const monacoLanguageFeatures = (
22+ await glob ( 'features/*/register .js' , {
23+ cwd : LANGUAGES_FEATURE_DIR ,
2524 onlyFiles : true
2625 } )
27- ) . map ( ( fileName ) => path . resolve ( LANGUAGE_FEATURE_DIR , fileName ) )
26+ ) . map ( ( fileName ) => path . resolve ( LANGUAGES_FEATURE_DIR , fileName ) )
2827
2928function getInstalledVersion ( libName : string ) {
3029 const output = execSync ( `npm ls ${ libName } --json --depth 1 --long` ) . toString ( )
@@ -76,7 +75,11 @@ const resolver: rollup.Plugin = {
7675 }
7776 }
7877
79- if ( source . endsWith ( 'editor.api.js' ) || source . endsWith ( 'editor.api2.js' ) ) {
78+ if (
79+ source . endsWith ( 'editor.api.js' ) ||
80+ source . endsWith ( 'editor.api2.js' ) ||
81+ source . endsWith ( 'editor.api.d.ts' )
82+ ) {
8083 return {
8184 id : 'monaco-editor' ,
8285 external : true
@@ -103,7 +106,7 @@ const resolver: rollup.Plugin = {
103106
104107export default rollup . defineConfig ( [
105108 ...( await Promise . all (
106- monacoContributions . map ( async ( contributionFile ) => {
109+ monacoLanguageFeatures . map ( async ( contributionFile ) => {
107110 const dirname = path . dirname ( contributionFile )
108111 const language = path . basename ( dirname )
109112 return < rollup . RollupOptions > {
@@ -130,6 +133,7 @@ export default rollup.defineConfig([
130133 output : {
131134 minifyInternalExports : false ,
132135 preserveModules : true ,
136+ preserveModulesRoot : MONACO_EDITOR_DIR ,
133137 sanitizeFileName,
134138 assetFileNames : '[name][extname]' ,
135139 format : 'esm' ,
@@ -154,7 +158,7 @@ export default rollup.defineConfig([
154158 return output . type === 'chunk' && output . isEntry
155159 } )
156160
157- const main = entryChunkIds . find ( ( m ) => m . includes ( 'monaco.contribution ' ) ) !
161+ const main = entryChunkIds . find ( ( m ) => m . includes ( 'register ' ) ) !
158162 const worker = entryChunkIds . find ( ( m ) => m . includes ( 'worker' ) ) !
159163
160164 const dependencies = Object . fromEntries (
@@ -186,13 +190,15 @@ export default rollup.defineConfig([
186190 description : `monaco-editor ${ language } language features bundled to work with ${ pkg . name } ` ,
187191 exports : {
188192 '.' : {
189- default : './' + main
193+ default : './' + main ,
194+ types : './' + main . replace ( '.js' , '.d.ts' )
190195 } ,
191196 './worker' : {
192197 default : './' + worker
193198 }
194199 } ,
195200 main : './' + main ,
201+ types : './' + main . replace ( '.js' , '.d.ts' ) ,
196202 module : './' + main ,
197203 dependencies : {
198204 'monaco-editor' : `npm:${ EDITOR_API_PACKAGE_NAME } @^${ pkg . version } ` ,
@@ -215,12 +221,11 @@ export default rollup.defineConfig([
215221 } )
216222 ) ) ,
217223 {
218- input : {
219- index : path . resolve ( BASIC_LANGUAGE_DIR , 'monaco.contribution.js' )
220- } ,
224+ input : [ path . resolve ( MONACO_EDITOR_DIR , 'languages/definitions/register.all.js' ) ] ,
221225 output : {
222226 minifyInternalExports : false ,
223227 preserveModules : true ,
228+ preserveModulesRoot : MONACO_EDITOR_DIR ,
224229 sanitizeFileName,
225230 assetFileNames : '[name][extname]' ,
226231 format : 'esm' ,
@@ -234,9 +239,18 @@ export default rollup.defineConfig([
234239 preventAssignment : true
235240 } ) ,
236241 resolver ,
242+ carryDtsPlugin ( ) ,
237243 {
238244 name : 'loader' ,
239- generateBundle ( ) {
245+ generateBundle ( options , bundle ) {
246+ const allChunkIds = Object . keys ( bundle )
247+
248+ const entryChunkIds : string [ ] = allChunkIds . filter ( ( chunkId ) => {
249+ const output = bundle [ chunkId ] !
250+ return output . type === 'chunk' && output . isEntry
251+ } )
252+ const main = entryChunkIds . find ( ( m ) => m . includes ( 'register' ) ) !
253+
240254 const dependencies = Object . fromEntries (
241255 Array . from ( this . getModuleIds ( ) )
242256 . map ( ( id ) => this . getModuleInfo ( id ) ! )
@@ -264,9 +278,17 @@ export default rollup.defineConfig([
264278 ) ,
265279 private : false ,
266280 description : `monaco-editor default language bundled to work with ${ pkg . name } ` ,
267- main : 'index.js' ,
268- module : 'index.js' ,
269- types : 'index.d.ts' ,
281+ exports : {
282+ '.' : {
283+ default : './' + main ,
284+ types : './' + main . replace ( '.js' , '.d.ts' )
285+ } ,
286+ './*.js' : './*.js' ,
287+ './*' : './*.js'
288+ } ,
289+ main : './' + main ,
290+ types : './' + main . replace ( '.js' , '.d.ts' ) ,
291+ module : './' + main ,
270292 dependencies : {
271293 'monaco-editor' : `npm:${ EDITOR_API_PACKAGE_NAME } @^${ pkg . version } ` ,
272294 ...dependencies
0 commit comments