Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5022248

Browse files
[dev-tool] Use host package's TypeScript in module loader. (#18064)
* [dev-tool] Use host package's TypeScript in module loader. * Made it just a little bit smarter
1 parent a3d8612 commit 5022248

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

common/tools/dev-tool/register.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@
1414
*/
1515

1616
const path = require("path");
17-
18-
const ts = require("typescript");
19-
2017
const cwd = process.cwd();
2118

2219
// This is the calling module, which will be the node repl context.
23-
const main = module.parent;
20+
const main = require.main || module.parent;
2421

2522
// We need to know which package name to monkey patch
2623
const { name: hostPackageName } = main.require("./package.json");
2724

25+
// We need to use whatever version of TypeScript the calling package uses to inspect syntax nodes, because
26+
// that is what the ts-node invocation will use, and we need to agree with it on syntax brands.
27+
const ts = hostPackageName === "@azure/dev-tool"
28+
? require(path.join(cwd, "node_modules", "typescript"))
29+
: main.require("typescript");
30+
2831
// If we're bootstrapping a dev-tool command, we need to patch the package from
2932
// CWD instead. This will still end up being dev-tool if we end up in a
3033
// self-hosting situation where dev-tool calls itself from its own scripts.

0 commit comments

Comments
 (0)