diff --git a/common/tools/dev-tool/register.js b/common/tools/dev-tool/register.js index 30baa8ecbfc6..da82300ff81d 100644 --- a/common/tools/dev-tool/register.js +++ b/common/tools/dev-tool/register.js @@ -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.