From 2075f1200564b4cd4f14a2c0d7cc861d5774bf11 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Wed, 6 Oct 2021 16:45:17 +0000 Subject: [PATCH 1/2] [dev-tool] Use host package's TypeScript in module loader. --- common/tools/dev-tool/register.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/common/tools/dev-tool/register.js b/common/tools/dev-tool/register.js index 30baa8ecbfc6..e9459ed77e6a 100644 --- a/common/tools/dev-tool/register.js +++ b/common/tools/dev-tool/register.js @@ -13,15 +13,17 @@ * old JavaScript, it is simple enough. */ +// This is the calling module, which will be the node repl context. +const main = require.main || module.parent; + const path = require("path"); -const ts = require("typescript"); +// 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 = main.require("./node_modules/typescript"); const cwd = process.cwd(); -// This is the calling module, which will be the node repl context. -const main = module.parent; - // We need to know which package name to monkey patch const { name: hostPackageName } = main.require("./package.json"); From b235b8e3e118aba46c5f3e5f0dceb14ebe2360eb Mon Sep 17 00:00:00 2001 From: Will Temple Date: Wed, 6 Oct 2021 17:23:06 +0000 Subject: [PATCH 2/2] Made it just a little bit smarter --- common/tools/dev-tool/register.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/common/tools/dev-tool/register.js b/common/tools/dev-tool/register.js index e9459ed77e6a..da82300ff81d 100644 --- a/common/tools/dev-tool/register.js +++ b/common/tools/dev-tool/register.js @@ -13,19 +13,20 @@ * old JavaScript, it is simple enough. */ +const path = require("path"); +const cwd = process.cwd(); + // This is the calling module, which will be the node repl context. const main = require.main || module.parent; -const path = require("path"); +// 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 = main.require("./node_modules/typescript"); - -const cwd = process.cwd(); - -// We need to know which package name to monkey patch -const { name: hostPackageName } = main.require("./package.json"); +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