2015-11-23 19:28:42 +00:00
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Copyright ( c ) Microsoft Corporation . All rights reserved .
* Licensed under the MIT License . See License . txt in the project root for license information .
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- * /
2018-03-07 08:38:59 +00:00
const gulp = require ( 'gulp' ) ;
const path = require ( 'path' ) ;
const util = require ( './lib/util' ) ;
2022-10-05 17:05:40 +00:00
const { getVersion } = require ( './lib/getVersion' ) ;
2019-02-12 14:13:43 +00:00
const task = require ( './lib/task' ) ;
2022-09-21 07:38:44 +00:00
const optimize = require ( './lib/optimize' ) ;
2018-03-07 08:38:59 +00:00
const es = require ( 'event-stream' ) ;
const File = require ( 'vinyl' ) ;
const i18n = require ( './lib/i18n' ) ;
const standalone = require ( './lib/standalone' ) ;
const cp = require ( 'child_process' ) ;
2018-07-19 19:05:38 +00:00
const compilation = require ( './lib/compilation' ) ;
2020-09-24 15:39:48 +00:00
const monacoapi = require ( './lib/monaco-api' ) ;
2018-07-20 09:25:46 +00:00
const fs = require ( 'fs' ) ;
2015-11-23 19:28:42 +00:00
2022-06-08 15:49:21 +00:00
const root = path . dirname ( _ _dirname ) ;
2022-10-05 17:05:40 +00:00
const sha1 = getVersion ( root ) ;
2022-06-08 15:49:21 +00:00
const semver = require ( './monaco/package.json' ) . version ;
const headerVersion = semver + '(' + sha1 + ')' ;
2015-11-23 19:28:42 +00:00
// Build
2022-06-08 15:49:21 +00:00
const editorEntryPoints = [
2016-09-18 08:50:11 +00:00
{
name : 'vs/editor/editor.main' ,
include : [ ] ,
2018-02-12 11:40:53 +00:00
exclude : [ 'vs/css' , 'vs/nls' ] ,
2022-06-16 20:01:19 +00:00
prepend : [
2022-06-17 15:12:27 +00:00
{ path : 'out-editor-build/vs/css.js' , amdModuleId : 'vs/css' } ,
2022-06-16 20:01:19 +00:00
{ path : 'out-editor-build/vs/nls.js' , amdModuleId : 'vs/nls' }
] ,
2016-09-18 08:50:11 +00:00
} ,
{
name : 'vs/base/common/worker/simpleWorker' ,
2018-02-12 11:40:53 +00:00
include : [ 'vs/editor/common/services/editorSimpleWorker' ] ,
2022-06-15 12:51:27 +00:00
exclude : [ 'vs/nls' ] ,
2022-06-22 19:30:09 +00:00
prepend : [
{ path : 'vs/loader.js' } ,
{ path : 'vs/nls.js' , amdModuleId : 'vs/nls' } ,
{ path : 'vs/base/worker/workerMain.js' }
] ,
2016-09-18 20:05:42 +00:00
dest : 'vs/base/worker/workerMain.js'
2016-10-07 15:55:12 +00:00
}
2016-09-21 08:14:37 +00:00
] ;
2015-11-23 19:28:42 +00:00
2022-06-08 15:49:21 +00:00
const editorResources = [
2020-04-17 11:39:54 +00:00
'out-editor-build/vs/base/browser/ui/codicons/**/*.ttf'
2015-11-23 19:28:42 +00:00
] ;
2022-06-08 15:49:21 +00:00
const BUNDLED _FILE _HEADER = [
2015-11-23 19:28:42 +00:00
'/*!-----------------------------------------------------------' ,
2016-02-24 13:27:53 +00:00
' * Copyright (c) Microsoft Corporation. All rights reserved.' ,
2016-03-06 11:37:24 +00:00
' * Version: ' + headerVersion ,
2015-11-23 19:28:42 +00:00
' * Released under the MIT license' ,
2021-02-14 19:10:24 +00:00
' * https://github.com/microsoft/vscode/blob/main/LICENSE.txt' ,
2015-11-23 19:28:42 +00:00
' *-----------------------------------------------------------*/' ,
''
] . join ( '\n' ) ;
2018-03-07 08:38:59 +00:00
const languages = i18n . defaultLanguages . concat ( [ ] ) ; // i18n.defaultLanguages.concat(process.env.VSCODE_QUALITY !== 'stable' ? i18n.extraLanguages : []);
2019-02-12 19:43:28 +00:00
const extractEditorSrcTask = task . define ( 'extract-editor-src' , ( ) => {
2018-07-20 09:25:46 +00:00
const apiusages = monacoapi . execute ( ) . usageContent ;
const extrausages = fs . readFileSync ( path . join ( root , 'build' , 'monaco' , 'monaco.usage.recipe' ) ) . toString ( ) ;
2018-07-19 15:43:17 +00:00
standalone . extractEditor ( {
sourcesRoot : path . join ( root , 'src' ) ,
entryPoints : [
'vs/editor/editor.main' ,
'vs/editor/editor.worker' ,
2018-07-20 08:38:56 +00:00
'vs/base/worker/workerMain' ,
2018-07-20 09:25:46 +00:00
] ,
inlineEntryPoints : [
apiusages ,
extrausages
2018-07-19 15:43:17 +00:00
] ,
2018-07-20 09:25:46 +00:00
shakeLevel : 2 , // 0-Files, 1-InnerFile, 2-ClassMembers
2020-03-02 14:30:43 +00:00
importIgnorePattern : /(^vs\/css!)/ ,
2019-11-04 23:00:55 +00:00
destRoot : path . join ( root , 'out-editor-src' ) ,
redirects : [ ]
2018-07-19 15:43:17 +00:00
} ) ;
2019-02-12 19:43:28 +00:00
} ) ;
2018-07-19 15:43:17 +00:00
2023-03-15 13:46:23 +00:00
// Disable mangling for the editor, as it complicates debugging & quite a few users rely on private/protected fields.
const compileEditorAMDTask = task . define ( 'compile-editor-amd' , compilation . compileTask ( 'out-editor-src' , 'out-editor-build' , true , { disableMangle : true } ) ) ;
2018-07-19 19:05:38 +00:00
2022-09-21 07:38:44 +00:00
const optimizeEditorAMDTask = task . define ( 'optimize-editor-amd' , optimize . optimizeTask (
{
out : 'out-editor' ,
amd : {
src : 'out-editor-build' ,
entryPoints : editorEntryPoints ,
resources : editorResources ,
loaderConfig : {
paths : {
'vs' : 'out-editor-build/vs' ,
'vs/css' : 'out-editor-build/vs/css.build' ,
'vs/nls' : 'out-editor-build/vs/nls.build' ,
'vscode' : 'empty:'
}
} ,
header : BUNDLED _FILE _HEADER ,
bundleInfo : true ,
languages
2018-07-20 08:38:56 +00:00
}
2022-09-21 07:38:44 +00:00
}
) ) ;
2018-07-20 08:38:56 +00:00
2022-09-21 07:38:44 +00:00
const minifyEditorAMDTask = task . define ( 'minify-editor-amd' , optimize . minifyTask ( 'out-editor' ) ) ;
2016-05-31 14:29:52 +00:00
2019-02-12 19:43:28 +00:00
const createESMSourcesAndResourcesTask = task . define ( 'extract-editor-esm' , ( ) => {
2018-08-10 07:27:06 +00:00
standalone . createESMSourcesAndResources2 ( {
srcFolder : './out-editor-src' ,
2018-10-10 09:02:10 +00:00
outFolder : './out-editor-esm' ,
2018-03-07 08:38:59 +00:00
outResourcesFolder : './out-monaco-editor-core/esm' ,
2018-08-10 07:27:06 +00:00
ignores : [
'inlineEntryPoint:0.ts' ,
'inlineEntryPoint:1.ts' ,
2018-08-10 11:57:35 +00:00
'vs/loader.js' ,
2018-08-10 07:27:06 +00:00
'vs/base/worker/workerMain.ts' ,
] ,
renames : {
'vs/nls.mock.ts' : 'vs/nls.ts'
2018-03-07 08:38:59 +00:00
}
} ) ;
2019-02-12 19:43:28 +00:00
} ) ;
2019-02-05 18:23:51 +00:00
2019-02-12 19:43:28 +00:00
const compileEditorESMTask = task . define ( 'compile-editor-esm' , ( ) => {
2020-03-05 09:21:54 +00:00
const KEEP _PREV _ANALYSIS = false ;
2020-05-08 12:40:50 +00:00
const FAIL _ON _PURPOSE = false ;
2019-11-13 10:14:45 +00:00
console . log ( ` Launching the TS compiler at ${ path . join ( _ _dirname , '../out-editor-esm' ) } ... ` ) ;
let result ;
2018-11-12 15:20:32 +00:00
if ( process . platform === 'win32' ) {
2019-11-13 10:14:45 +00:00
result = cp . spawnSync ( ` .. \\ node_modules \\ .bin \\ tsc.cmd ` , {
2018-11-12 15:20:32 +00:00
cwd : path . join ( _ _dirname , '../out-editor-esm' )
} ) ;
} else {
2019-11-13 10:14:45 +00:00
result = cp . spawnSync ( ` node ` , [ ` ../node_modules/.bin/tsc ` ] , {
2018-11-12 15:20:32 +00:00
cwd : path . join ( _ _dirname , '../out-editor-esm' )
} ) ;
2019-11-13 10:14:45 +00:00
}
console . log ( result . stdout . toString ( ) ) ;
console . log ( result . stderr . toString ( ) ) ;
2020-05-08 12:40:50 +00:00
if ( FAIL _ON _PURPOSE || result . status !== 0 ) {
2019-11-13 10:14:45 +00:00
console . log ( ` The TS Compilation failed, preparing analysis folder... ` ) ;
const destPath = path . join ( _ _dirname , '../../vscode-monaco-editor-esm-analysis' ) ;
2020-03-05 09:21:54 +00:00
const keepPrevAnalysis = ( KEEP _PREV _ANALYSIS && fs . existsSync ( destPath ) ) ;
const cleanDestPath = ( keepPrevAnalysis ? Promise . resolve ( ) : util . rimraf ( destPath ) ( ) ) ;
return cleanDestPath . then ( ( ) => {
2019-11-13 10:14:45 +00:00
// build a list of files to copy
const files = util . rreddir ( path . join ( _ _dirname , '../out-editor-esm' ) ) ;
2020-03-05 09:21:54 +00:00
if ( ! keepPrevAnalysis ) {
fs . mkdirSync ( destPath ) ;
// initialize a new repository
cp . spawnSync ( ` git ` , [ ` init ` ] , {
cwd : destPath
} ) ;
// copy files from src
for ( const file of files ) {
const srcFilePath = path . join ( _ _dirname , '../src' , file ) ;
const dstFilePath = path . join ( destPath , file ) ;
if ( fs . existsSync ( srcFilePath ) ) {
util . ensureDir ( path . dirname ( dstFilePath ) ) ;
const contents = fs . readFileSync ( srcFilePath ) . toString ( ) . replace ( /\r\n|\r|\n/g , '\n' ) ;
fs . writeFileSync ( dstFilePath , contents ) ;
}
2019-11-13 10:14:45 +00:00
}
2020-03-05 09:21:54 +00:00
// create an initial commit to diff against
cp . spawnSync ( ` git ` , [ ` add ` , ` . ` ] , {
cwd : destPath
} ) ;
2019-11-13 10:14:45 +00:00
2020-03-05 09:21:54 +00:00
// create the commit
cp . spawnSync ( ` git ` , [ ` commit ` , ` -m ` , ` "original sources" ` , ` --no-gpg-sign ` ] , {
cwd : destPath
} ) ;
}
2019-11-13 10:14:45 +00:00
2020-03-05 09:24:43 +00:00
// copy files from tree shaken src
2019-11-13 10:14:45 +00:00
for ( const file of files ) {
2020-03-05 09:24:43 +00:00
const srcFilePath = path . join ( _ _dirname , '../out-editor-src' , file ) ;
2019-11-13 10:14:45 +00:00
const dstFilePath = path . join ( destPath , file ) ;
if ( fs . existsSync ( srcFilePath ) ) {
util . ensureDir ( path . dirname ( dstFilePath ) ) ;
const contents = fs . readFileSync ( srcFilePath ) . toString ( ) . replace ( /\r\n|\r|\n/g , '\n' ) ;
fs . writeFileSync ( dstFilePath , contents ) ;
}
}
2021-09-28 12:13:56 +00:00
console . log ( ` Open in VS Code the folder at ' ${ destPath } ' and you can analyze the compilation error ` ) ;
2019-11-13 10:14:45 +00:00
throw new Error ( 'Standalone Editor compilation failed. If this is the build machine, simply launch `yarn run gulp editor-distro` on your machine to further analyze the compilation problem.' ) ;
} ) ;
2018-11-12 15:20:32 +00:00
}
2019-02-12 19:43:28 +00:00
} ) ;
2018-03-07 08:38:59 +00:00
2022-01-25 14:19:30 +00:00
/ * *
* Go over all . js files in ` /out-monaco-editor-core/esm/ ` and make sure that all imports
* use ` .js ` at the end in order to be ESM compliant .
* /
const appendJSToESMImportsTask = task . define ( 'append-js-to-esm-imports' , ( ) => {
const SRC _DIR = path . join ( _ _dirname , '../out-monaco-editor-core/esm' ) ;
const files = util . rreddir ( SRC _DIR ) ;
for ( const file of files ) {
const filePath = path . join ( SRC _DIR , file ) ;
if ( ! /\.js$/ . test ( filePath ) ) {
continue ;
}
const contents = fs . readFileSync ( filePath ) . toString ( ) ;
const lines = contents . split ( /\r\n|\r|\n/g ) ;
const /** @type {string[]} */ result = [ ] ;
for ( const line of lines ) {
if ( ! /^import/ . test ( line ) && ! /^export \* from/ . test ( line ) ) {
// not an import
result . push ( line ) ;
continue ;
}
if ( /^import '[^']+\.css';/ . test ( line ) ) {
// CSS import
result . push ( line ) ;
continue ;
}
2022-06-08 15:49:21 +00:00
const modifiedLine = (
2022-01-25 14:19:30 +00:00
line
. replace ( /^import(.*)\'([^']+)\'/ , ` import $ 1' $ 2.js' ` )
. replace ( /^export \* from \'([^']+)\'/ , ` export * from ' $ 1.js' ` )
) ;
result . push ( modifiedLine ) ;
}
fs . writeFileSync ( filePath , result . join ( '\n' ) ) ;
}
} ) ;
2022-02-28 22:32:12 +00:00
/ * *
* @ param { string } contents
* /
2018-05-15 09:10:05 +00:00
function toExternalDTS ( contents ) {
2022-06-08 15:49:21 +00:00
const lines = contents . split ( /\r\n|\r|\n/ ) ;
2021-10-08 14:58:02 +00:00
let killNextCloseCurlyBrace = false ;
for ( let i = 0 ; i < lines . length ; i ++ ) {
2022-06-08 15:49:21 +00:00
const line = lines [ i ] ;
2018-05-15 09:10:05 +00:00
2021-10-08 14:58:02 +00:00
if ( killNextCloseCurlyBrace ) {
if ( '}' === line ) {
lines [ i ] = '' ;
killNextCloseCurlyBrace = false ;
continue ;
}
if ( line . indexOf ( ' ' ) === 0 ) {
lines [ i ] = line . substr ( 4 ) ;
} else if ( line . charAt ( 0 ) === '\t' ) {
lines [ i ] = line . substr ( 1 ) ;
}
continue ;
}
if ( 'declare namespace monaco {' === line ) {
lines [ i ] = '' ;
killNextCloseCurlyBrace = true ;
continue ;
}
if ( line . indexOf ( 'declare namespace monaco.' ) === 0 ) {
lines [ i ] = line . replace ( 'declare namespace monaco.' , 'export namespace ' ) ;
}
2020-02-03 22:14:21 +00:00
2021-10-08 14:58:02 +00:00
if ( line . indexOf ( 'declare let MonacoEnvironment' ) === 0 ) {
lines [ i ] = ` declare global { \n let MonacoEnvironment: Environment | undefined; \n } ` ;
}
2021-09-21 15:19:45 +00:00
2021-10-08 14:58:02 +00:00
if ( line . indexOf ( '\tMonacoEnvironment?' ) === 0 ) {
lines [ i ] = ` MonacoEnvironment?: Environment | undefined; ` ;
}
}
return lines . join ( '\n' ) . replace ( /\n\n\n+/g , '\n\n' ) ;
2018-05-15 09:10:05 +00:00
}
2022-02-28 22:32:12 +00:00
/ * *
* @ param { { ( path : string ) : boolean } } testFunc
* /
2019-02-05 18:23:51 +00:00
function filterStream ( testFunc ) {
return es . through ( function ( data ) {
if ( ! testFunc ( data . relative ) ) {
return ;
}
this . emit ( 'data' , data ) ;
} ) ;
}
2019-02-12 19:43:28 +00:00
const finalEditorResourcesTask = task . define ( 'final-editor-resources' , ( ) => {
2016-05-31 14:29:52 +00:00
return es . merge (
// other assets
es . merge (
gulp . src ( 'build/monaco/LICENSE' ) ,
gulp . src ( 'build/monaco/ThirdPartyNotices.txt' ) ,
gulp . src ( 'src/vs/monaco.d.ts' )
) . pipe ( gulp . dest ( 'out-monaco-editor-core' ) ) ,
2018-04-25 09:46:17 +00:00
// place the .d.ts in the esm folder
gulp . src ( 'src/vs/monaco.d.ts' )
. pipe ( es . through ( function ( data ) {
this . emit ( 'data' , new File ( {
path : data . path . replace ( /monaco\.d\.ts/ , 'editor.api.d.ts' ) ,
base : data . base ,
2018-08-22 08:42:36 +00:00
contents : Buffer . from ( toExternalDTS ( data . contents . toString ( ) ) )
2018-04-25 09:46:17 +00:00
} ) ) ;
} ) )
. pipe ( gulp . dest ( 'out-monaco-editor-core/esm/vs/editor' ) ) ,
2016-06-06 14:44:28 +00:00
// package.json
gulp . src ( 'build/monaco/package.json' )
2018-02-12 11:40:53 +00:00
. pipe ( es . through ( function ( data ) {
2022-06-08 15:49:21 +00:00
const json = JSON . parse ( data . contents . toString ( ) ) ;
2016-06-06 14:44:28 +00:00
json . private = false ;
2018-02-26 12:09:47 +00:00
data . contents = Buffer . from ( JSON . stringify ( json , null , ' ' ) ) ;
2016-06-06 14:44:28 +00:00
this . emit ( 'data' , data ) ;
} ) )
. pipe ( gulp . dest ( 'out-monaco-editor-core' ) ) ,
2019-03-02 01:25:49 +00:00
// version.txt
gulp . src ( 'build/monaco/version.txt' )
. pipe ( es . through ( function ( data ) {
2020-09-15 23:13:49 +00:00
data . contents = Buffer . from ( ` monaco-editor-core: https://github.com/microsoft/vscode/tree/ ${ sha1 } ` ) ;
2019-03-02 01:25:49 +00:00
this . emit ( 'data' , data ) ;
} ) )
. pipe ( gulp . dest ( 'out-monaco-editor-core' ) ) ,
2016-06-09 09:20:03 +00:00
// README.md
gulp . src ( 'build/monaco/README-npm.md' )
2018-02-12 11:40:53 +00:00
. pipe ( es . through ( function ( data ) {
2016-06-09 09:20:03 +00:00
this . emit ( 'data' , new File ( {
path : data . path . replace ( /README-npm\.md/ , 'README.md' ) ,
base : data . base ,
contents : data . contents
} ) ) ;
} ) )
. pipe ( gulp . dest ( 'out-monaco-editor-core' ) ) ,
2016-05-31 14:29:52 +00:00
// dev folder
es . merge (
gulp . src ( 'out-editor/**/*' )
) . pipe ( gulp . dest ( 'out-monaco-editor-core/dev' ) ) ,
// min folder
es . merge (
gulp . src ( 'out-editor-min/**/*' )
2018-02-12 11:40:53 +00:00
) . pipe ( filterStream ( function ( path ) {
2016-05-31 14:29:52 +00:00
// no map files
2016-06-09 08:50:11 +00:00
return ! /(\.js\.map$)|(nls\.metadata\.json$)|(bundleInfo\.json$)/ . test ( path ) ;
2018-02-12 11:40:53 +00:00
} ) ) . pipe ( es . through ( function ( data ) {
2016-05-31 14:29:52 +00:00
// tweak the sourceMappingURL
if ( ! /\.js$/ . test ( data . path ) ) {
this . emit ( 'data' , data ) ;
return ;
}
2022-06-08 15:49:21 +00:00
const relativePathToMap = path . relative ( path . join ( data . relative ) , path . join ( 'min-maps' , data . relative + '.map' ) ) ;
2016-05-31 14:29:52 +00:00
2020-01-02 19:35:07 +00:00
let strContents = data . contents . toString ( ) ;
2022-06-08 15:49:21 +00:00
const newStr = '//# sourceMappingURL=' + relativePathToMap . replace ( /\\/g , '/' ) ;
2019-02-05 22:39:23 +00:00
strContents = strContents . replace ( /\/\/# sourceMappingURL=[^ ]+$/ , newStr ) ;
2016-05-31 14:29:52 +00:00
2018-02-26 12:09:47 +00:00
data . contents = Buffer . from ( strContents ) ;
2016-05-31 14:29:52 +00:00
this . emit ( 'data' , data ) ;
} ) ) . pipe ( gulp . dest ( 'out-monaco-editor-core/min' ) ) ,
// min-maps folder
es . merge (
gulp . src ( 'out-editor-min/**/*' )
2018-02-12 11:40:53 +00:00
) . pipe ( filterStream ( function ( path ) {
2016-05-31 14:29:52 +00:00
// no map files
2016-05-31 14:37:47 +00:00
return /\.js\.map$/ . test ( path ) ;
2016-05-31 14:29:52 +00:00
} ) ) . pipe ( gulp . dest ( 'out-monaco-editor-core/min-maps' ) )
) ;
2019-02-12 19:43:28 +00:00
} ) ;
2019-02-05 18:23:51 +00:00
2020-03-05 09:21:54 +00:00
gulp . task ( 'extract-editor-src' ,
task . series (
util . rimraf ( 'out-editor-src' ) ,
extractEditorSrcTask
)
) ;
2019-02-05 18:23:51 +00:00
gulp . task ( 'editor-distro' ,
2019-02-12 14:13:43 +00:00
task . series (
task . parallel (
2019-02-05 18:23:51 +00:00
util . rimraf ( 'out-editor-src' ) ,
util . rimraf ( 'out-editor-build' ) ,
util . rimraf ( 'out-editor-esm' ) ,
util . rimraf ( 'out-monaco-editor-core' ) ,
util . rimraf ( 'out-editor' ) ,
util . rimraf ( 'out-editor-min' )
) ,
extractEditorSrcTask ,
2019-02-12 14:13:43 +00:00
task . parallel (
task . series (
2019-02-05 18:23:51 +00:00
compileEditorAMDTask ,
optimizeEditorAMDTask ,
minifyEditorAMDTask
) ,
2019-02-12 14:13:43 +00:00
task . series (
2019-02-05 18:23:51 +00:00
createESMSourcesAndResourcesTask ,
2022-01-25 14:19:30 +00:00
compileEditorESMTask ,
appendJSToESMImportsTask
2019-02-05 18:23:51 +00:00
)
) ,
finalEditorResourcesTask
)
) ;
2018-04-05 08:00:50 +00:00
2023-11-15 17:42:55 +00:00
gulp . task ( 'editor-esm' ,
2019-11-12 23:55:21 +00:00
task . series (
task . parallel (
util . rimraf ( 'out-editor-src' ) ,
util . rimraf ( 'out-editor-esm' ) ,
util . rimraf ( 'out-monaco-editor-core' ) ,
) ,
extractEditorSrcTask ,
createESMSourcesAndResourcesTask ,
compileEditorESMTask ,
2022-01-25 14:19:30 +00:00
appendJSToESMImportsTask ,
2019-11-12 23:55:21 +00:00
)
) ;
2020-01-14 14:09:39 +00:00
gulp . task ( 'monacodts' , task . define ( 'monacodts' , ( ) => {
const result = monacoapi . execute ( ) ;
fs . writeFileSync ( result . filePath , result . content ) ;
fs . writeFileSync ( path . join ( root , 'src/vs/editor/common/standalone/standaloneEnums.ts' ) , result . enums ) ;
return Promise . resolve ( true ) ;
} ) ) ;
2018-04-05 08:00:50 +00:00
//#region monaco type checking
function createTscCompileTask ( watch ) {
return ( ) => {
const createReporter = require ( './lib/reporter' ) . createReporter ;
return new Promise ( ( resolve , reject ) => {
2018-04-05 12:36:21 +00:00
const args = [ './node_modules/.bin/tsc' , '-p' , './src/tsconfig.monaco.json' , '--noEmit' ] ;
2018-04-05 08:00:50 +00:00
if ( watch ) {
args . push ( '-w' ) ;
}
2018-04-05 12:36:21 +00:00
const child = cp . spawn ( ` node ` , args , {
2018-04-05 08:00:50 +00:00
cwd : path . join ( _ _dirname , '..' ) ,
2018-04-05 12:36:21 +00:00
// stdio: [null, 'pipe', 'inherit']
2018-04-05 08:00:50 +00:00
} ) ;
2022-06-08 15:49:21 +00:00
const errors = [ ] ;
const reporter = createReporter ( 'monaco' ) ;
2022-02-28 22:32:12 +00:00
/** @type {NodeJS.ReadWriteStream | undefined} */
2018-04-05 08:00:50 +00:00
let report ;
2019-02-05 22:39:23 +00:00
// eslint-disable-next-line no-control-regex
2022-06-08 15:49:21 +00:00
const magic = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g ; // https://stackoverflow.com/questions/25245716/remove-all-ansi-colors-styles-from-strings
2018-04-05 08:00:50 +00:00
child . stdout . on ( 'data' , data => {
let str = String ( data ) ;
str = str . replace ( magic , '' ) . trim ( ) ;
if ( str . indexOf ( 'Starting compilation' ) >= 0 || str . indexOf ( 'File change detected' ) >= 0 ) {
errors . length = 0 ;
report = reporter . end ( false ) ;
} else if ( str . indexOf ( 'Compilation complete' ) >= 0 ) {
report . end ( ) ;
} else if ( str ) {
2022-06-08 15:49:21 +00:00
const match = /(.*\(\d+,\d+\): )(.*: )(.*)/ . exec ( str ) ;
2018-04-05 08:00:50 +00:00
if ( match ) {
// trying to massage the message so that it matches the gulp-tsb error messages
// e.g. src/vs/base/common/strings.ts(663,5): error TS2322: Type '1234' is not assignable to type 'string'.
2022-06-08 15:49:21 +00:00
const fullpath = path . join ( root , match [ 1 ] ) ;
const message = match [ 3 ] ;
2018-04-05 08:00:50 +00:00
reporter ( fullpath + message ) ;
} else {
reporter ( str ) ;
}
}
} ) ;
child . on ( 'exit' , resolve ) ;
child . on ( 'error' , reject ) ;
} ) ;
} ;
}
2019-02-12 19:43:28 +00:00
const monacoTypecheckWatchTask = task . define ( 'monaco-typecheck-watch' , createTscCompileTask ( true ) ) ;
2019-02-05 20:23:25 +00:00
exports . monacoTypecheckWatchTask = monacoTypecheckWatchTask ;
2019-02-12 19:43:28 +00:00
const monacoTypecheckTask = task . define ( 'monaco-typecheck' , createTscCompileTask ( false ) ) ;
2019-02-05 20:23:25 +00:00
exports . monacoTypecheckTask = monacoTypecheckTask ;
2018-04-05 08:00:50 +00:00
//#endregion