22 * Copyright (c) Microsoft Corporation. All rights reserved.
33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
5+ // @ts -check
56
67'use strict' ;
78
89const fs = require ( 'fs' ) ;
910const path = require ( 'path' ) ;
10- const toDelete = new Set ( [ 'tsc.js' , 'tsserverlibrary.js' , 'typescriptServices.js' ] ) ;
11+ const rimraf = require ( 'rimraf' ) ;
1112
12- const root = path . join ( __dirname , 'node_modules' , 'typescript' , 'lib' ) ;
13- for ( let name of fs . readdirSync ( root ) ) {
14- if ( name === 'lib.d.ts' || name . match ( / ^ l i b \. .* \. d \. t s $ / ) || name === 'protocol.d.ts' ) {
15- continue ;
16- }
17- if ( name === 'typescript.js' || name === 'typescript.d.ts' ) {
18- // used by html and extension editing
19- continue ;
13+ const root = path . join ( __dirname , 'node_modules' , 'typescript' ) ;
14+
15+ function processRoot ( ) {
16+ const toKeep = new Set ( [
17+ 'lib' ,
18+ 'package.json' ,
19+ ] ) ;
20+ for ( const name of fs . readdirSync ( root ) ) {
21+ if ( ! toKeep . has ( name ) ) {
22+ const filePath = path . join ( root , name ) ;
23+ console . log ( `Removed ${ filePath } ` ) ;
24+ rimraf . sync ( filePath ) ;
25+ }
2026 }
27+ }
28+
29+ function processLib ( ) {
30+ const toDelete = new Set ( [
31+ 'tsc.js' ,
32+ 'tsserverlibrary.js' ,
33+ 'typescriptServices.js' ,
34+ ] ) ;
35+
36+ const libRoot = path . join ( root , 'lib' ) ;
2137
22- if ( toDelete . has ( name ) || name . match ( / \. d \. t s $ / ) ) {
23- try {
24- fs . unlinkSync ( path . join ( root , name ) ) ;
25- console . log ( `removed '${ path . join ( root , name ) } '` ) ;
26- } catch ( e ) {
27- console . warn ( e ) ;
38+ for ( const name of fs . readdirSync ( libRoot ) ) {
39+ if ( name === 'lib.d.ts' || name . match ( / ^ l i b \. .* \. d \. t s $ / ) || name === 'protocol.d.ts' ) {
40+ continue ;
41+ }
42+ if ( name === 'typescript.js' || name === 'typescript.d.ts' ) {
43+ // used by html and extension editing
44+ continue ;
45+ }
46+
47+ if ( toDelete . has ( name ) || name . match ( / \. d \. t s $ / ) ) {
48+ try {
49+ fs . unlinkSync ( path . join ( libRoot , name ) ) ;
50+ console . log ( `removed '${ path . join ( libRoot , name ) } '` ) ;
51+ } catch ( e ) {
52+ console . warn ( e ) ;
53+ }
2854 }
2955 }
30- }
56+ }
57+
58+ processRoot ( ) ;
59+ processLib ( ) ;
0 commit comments