@@ -2,6 +2,7 @@ import path from "node:path";
22import { createRequire } from "node:module" ;
33import createEsmUtils from "esm-utils" ;
44import { PROJECT_ROOT } from "../utils/index.mjs" ;
5+ import modifyTypescriptModule from "./modify-typescript-module.mjs" ;
56
67const { require } = createEsmUtils ( import . meta) ;
78
@@ -101,62 +102,8 @@ const parsers = [
101102 } ,
102103 {
103104 module : require . resolve ( "typescript" ) ,
104- process ( text ) {
105- return text . replace (
106- / (?< = \n ) (?< indentString > \s + ) f u n c t i o n t r y G e t N o d e P e r f o r m a n c e H o o k s \( \) { .* ?\n \k<indentString > } (? = \n ) / s,
107- "function tryGetNodePerformanceHooks() {}"
108- ) ;
109- } ,
105+ process : modifyTypescriptModule ,
110106 } ,
111-
112- ...Object . entries ( {
113- // `typescript/lib/typescript.js` expose extra global objects
114- // `TypeScript`, `toolsVersion`, `globalThis`
115- 'typeof process === "undefined" || process.browser' : "false" ,
116- 'typeof globalThis === "object"' : "true" ,
117-
118- "_fs.realpathSync.native" :
119- "_fs.realpathSync && _fs.realpathSync.native" ,
120- // Remove useless `ts.sys`
121- "ts.sys = " : "ts.sys = undefined && " ,
122-
123- // Remove useless language service
124- "ts.realizeDiagnostics = " : "ts.realizeDiagnostics = undefined && " ,
125- "ts.TypeScriptServicesFactory = " :
126- "ts.TypeScriptServicesFactory = undefined && " ,
127- "var ShimBase = " : "var ShimBase = undefined && " ,
128- "var TypeScriptServicesFactory = " :
129- "var TypeScriptServicesFactory = undefined && " ,
130- "var LanguageServiceShimObject = " :
131- "var LanguageServiceShimObject = undefined && " ,
132- "var CoreServicesShimHostAdapter = " :
133- "var CoreServicesShimHostAdapter = undefined && " ,
134- "var LanguageServiceShimHostAdapter = " :
135- "var LanguageServiceShimHostAdapter = undefined && " ,
136- "var ScriptSnapshotShimAdapter = " :
137- "var ScriptSnapshotShimAdapter = undefined && " ,
138- "var ClassifierShimObject = " :
139- "var ClassifierShimObject = undefined && " ,
140- "var CoreServicesShimObject = " :
141- "var CoreServicesShimObject = undefined && " ,
142- "function simpleForwardCall(" : "0 && function simpleForwardCall(" ,
143- "function forwardJSONCall(" : "0 && function forwardJSONCall(" ,
144- "function forwardCall(" : "0 && function forwardCall(" ,
145- "function realizeDiagnostics(" : "0 && function realizeDiagnostics(" ,
146- "function realizeDiagnostic(" : "0 && function realizeDiagnostic(" ,
147- "function convertClassifications(" :
148- "0 && function convertClassifications(" ,
149-
150- // Dynamic `require()`s
151- "ts.sys && ts.sys.require" : "false" ,
152- "require(etwModulePath)" : "undefined" ,
153- 'require("source-map-support").install()' : "" ,
154- "require(modulePath)" : "undefined" ,
155- } ) . map ( ( [ find , replacement ] ) => ( {
156- module : require . resolve ( "typescript" ) ,
157- find,
158- replacement,
159- } ) ) ,
160107 {
161108 module : require . resolve ( "debug/src/browser.js" ) ,
162109 path : require . resolve ( "./shims/debug.cjs" ) ,
0 commit comments