Skip to content

Commit

Permalink
[dev-tool] Use host package's TypeScript in module loader. (#18064)
Browse files Browse the repository at this point in the history
* [dev-tool] Use host package's TypeScript in module loader.

* Made it just a little bit smarter
  • Loading branch information
witemple-msft authored Oct 6, 2021
1 parent a3d8612 commit 5022248
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions common/tools/dev-tool/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@
*/

const path = require("path");

const ts = require("typescript");

const cwd = process.cwd();

// This is the calling module, which will be the node repl context.
const main = module.parent;
const main = require.main || module.parent;

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

// We need to use whatever version of TypeScript the calling package uses to inspect syntax nodes, because
// that is what the ts-node invocation will use, and we need to agree with it on syntax brands.
const ts = hostPackageName === "@azure/dev-tool"
? require(path.join(cwd, "node_modules", "typescript"))
: main.require("typescript");

// If we're bootstrapping a dev-tool command, we need to patch the package from
// CWD instead. This will still end up being dev-tool if we end up in a
// self-hosting situation where dev-tool calls itself from its own scripts.
Expand Down

0 comments on commit 5022248

Please sign in to comment.