@@ -47,9 +47,12 @@ const Paths = {
4747 builtLocalRun : "built/local/run.js" ,
4848 locLcg : "built/local/enu/diagnosticMessages.generated.json.lcg" ,
4949 typesMapOutput : "built/local/typesMap.json" ,
50+
5051 servicesFile : "built/local/typescriptServices.js" ,
5152 servicesDefinitionFile : "built/local/typescriptServices.d.ts" ,
5253
54+ tsserverGlobalLibraryFile : "built/local/tsserverGlobalLibrary.js" ,
55+ tsserverGlobalLibraryDefinitionFile : "built/local/tsserverGlobalLibrary.d.ts" ,
5356 tsserverLibraryFile : "built/local/tsserverlibrary.js" ,
5457 tsserverLibraryDefinitionFile : "built/local/tsserverlibrary.d.ts" ,
5558
@@ -161,7 +164,7 @@ task(TaskNames.lkg, [
161164 const sizeBefore = getDirSize ( Paths . lkg ) ;
162165 const localizationTargets = locales . map ( f => path . join ( Paths . builtLocal , f ) ) . concat ( path . dirname ( Paths . locLcg ) ) ;
163166
164- const copyrightContent = fs . readFileSync ( Paths . copyright , { encoding : 'utf-8' } ) ;
167+ const copyrightContent = readFileSync ( Paths . copyright ) ;
165168
166169 const expectedFiles = [ ...libraryTargets , ...ExpectedLKGFiles , ...localizationTargets ] ;
167170 const missingFiles = expectedFiles . filter ( f => ! fs . existsSync ( f ) ) ;
@@ -172,7 +175,7 @@ task(TaskNames.lkg, [
172175 // Copy all the targets into the LKG directory
173176 jake . mkdirP ( Paths . lkg ) ;
174177 expectedFiles . forEach ( f => {
175- let content = fs . readFileSync ( f , { encoding : 'utf-8' } ) ;
178+ let content = readFileSync ( f ) ;
176179
177180 // If this is a .d.ts file, run remove-internal on it
178181 if ( f . endsWith ( ".d.ts" ) ) {
@@ -282,7 +285,7 @@ file(Paths.diagnosticInformationMap, [Paths.diagnosticMessagesJson], function (c
282285} , { async : true } ) ;
283286
284287file ( Paths . typesMapOutput , /** @type {* } */ ( function ( ) {
285- var content = fs . readFileSync ( path . join ( Paths . srcServer , 'typesMap.json' ) ) ;
288+ var content = readFileSync ( path . join ( Paths . srcServer , 'typesMap.json' ) ) ;
286289 // Validate that it's valid JSON
287290 try {
288291 JSON . parse ( content . toString ( ) ) ;
@@ -293,18 +296,21 @@ file(Paths.typesMapOutput, /** @type {*} */(function () {
293296} ) ) ;
294297
295298file ( Paths . tsserverLibraryFile , [ TaskNames . coreBuild , Paths . copyright , ...libraryTargets ] , function ( ) {
296- // fs.writeFileSync(Paths.tsserverLibraryFile, fs.readFileSync(path.join(Paths.builtLocal, "server.js"), { encoding: 'utf-8'}));
297- fs . writeFileSync ( Paths . tsserverLibraryFile , "wat" ) ;
299+ const originalContent = readFileSync ( Paths . tsserverGlobalLibraryFile ) ;
300+ const newContent =
301+ readFileSync ( Paths . copyright ) +
302+ originalContent ;
303+ writeFileSync ( Paths . tsserverLibraryFile , newContent ) ;
298304} ) ;
299305
300306file ( Paths . tsserverLibraryDefinitionFile , [ TaskNames . coreBuild , Paths . copyright , ...libraryTargets ] , function ( ) {
301- const content = fs . readFileSync ( Paths . servicesFile , { encoding : 'utf-8' } ) ;
307+ const content = readFileSync ( Paths . tsserverGlobalLibraryDefinitionFile ) ;
302308 const newContent =
303309 removeConstModifierFromEnumDeclarations ( content ) +
304310 `\nexport = ts` +
305311 `\nexport as namespace ts;` ;
306312
307- fs . writeFileSync ( Paths . tsserverLibraryDefinitionFile , newContent , { encoding : 'utf-8' } ) ;
313+ writeFileSync ( Paths . tsserverLibraryDefinitionFile , newContent ) ;
308314} ) ;
309315
310316function getLibraryTargets ( ) {
@@ -657,3 +663,18 @@ function getDiffTool() {
657663function removeConstModifierFromEnumDeclarations ( text ) {
658664 return text . replace ( / ^ ( \s * ) ( e x p o r t ) ? c o n s t e n u m ( \S + ) { ( \s * ) $ / gm, '$1$2enum $3 {$4' ) ;
659665}
666+
667+ /**
668+ * @param {string } path
669+ */
670+ function readFileSync ( path ) {
671+ return fs . readFileSync ( path , { encoding : "utf-8" } ) ;
672+ }
673+
674+ /**
675+ * @param {string } path
676+ * @param {string } contents
677+ */
678+ function writeFileSync ( path , contents ) {
679+ fs . writeFileSync ( path , contents , { encoding : "utf-8" } ) ;
680+ }
0 commit comments