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

[dev-tool] Use host package's TypeScript in module loader. #18064

Merged
merged 2 commits into from
Oct 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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