Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce size of parser-typescript.js #13431

Merged
merged 3 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 2 additions & 55 deletions scripts/build/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from "node:path";
import { createRequire } from "node:module";
import createEsmUtils from "esm-utils";
import { PROJECT_ROOT } from "../utils/index.mjs";
import modifyTypescriptModule from "./modify-typescript-module.mjs";

const { require } = createEsmUtils(import.meta);

Expand Down Expand Up @@ -101,62 +102,8 @@ const parsers = [
},
{
module: require.resolve("typescript"),
process(text) {
return text.replace(
/(?<=\n)(?<indentString>\s+)function tryGetNodePerformanceHooks\(\) {.*?\n\k<indentString>}(?=\n)/s,
"function tryGetNodePerformanceHooks() {}"
);
},
process: modifyTypescriptModule,
},

...Object.entries({
// `typescript/lib/typescript.js` expose extra global objects
// `TypeScript`, `toolsVersion`, `globalThis`
'typeof process === "undefined" || process.browser': "false",
'typeof globalThis === "object"': "true",

"_fs.realpathSync.native":
"_fs.realpathSync && _fs.realpathSync.native",
// Remove useless `ts.sys`
"ts.sys = ": "ts.sys = undefined && ",

// Remove useless language service
"ts.realizeDiagnostics = ": "ts.realizeDiagnostics = undefined && ",
"ts.TypeScriptServicesFactory = ":
"ts.TypeScriptServicesFactory = undefined && ",
"var ShimBase = ": "var ShimBase = undefined && ",
"var TypeScriptServicesFactory = ":
"var TypeScriptServicesFactory = undefined && ",
"var LanguageServiceShimObject = ":
"var LanguageServiceShimObject = undefined && ",
"var CoreServicesShimHostAdapter = ":
"var CoreServicesShimHostAdapter = undefined && ",
"var LanguageServiceShimHostAdapter = ":
"var LanguageServiceShimHostAdapter = undefined && ",
"var ScriptSnapshotShimAdapter = ":
"var ScriptSnapshotShimAdapter = undefined && ",
"var ClassifierShimObject = ":
"var ClassifierShimObject = undefined && ",
"var CoreServicesShimObject = ":
"var CoreServicesShimObject = undefined && ",
"function simpleForwardCall(": "0 && function simpleForwardCall(",
"function forwardJSONCall(": "0 && function forwardJSONCall(",
"function forwardCall(": "0 && function forwardCall(",
"function realizeDiagnostics(": "0 && function realizeDiagnostics(",
"function realizeDiagnostic(": "0 && function realizeDiagnostic(",
"function convertClassifications(":
"0 && function convertClassifications(",

// Dynamic `require()`s
"ts.sys && ts.sys.require": "false",
"require(etwModulePath)": "undefined",
'require("source-map-support").install()': "",
"require(modulePath)": "undefined",
}).map(([find, replacement]) => ({
module: require.resolve("typescript"),
find,
replacement,
})),
{
module: require.resolve("debug/src/browser.js"),
path: require.resolve("./shims/debug.cjs"),
Expand Down