Files
Jeff FisherandGitHub 3c84063ae8 Migrate dev-tool from CommonJS to ESM with native TypeScript support (#37255)
### Packages impacted by this PR

`@azure/dev-tool`

### Issues associated with this PR

https://github.com/Azure/azure-sdk-for-js/issues/36819

### Describe the problem that is addressed by this PR

Replace tsx runtime with Node's native TypeScript execution. This
simplifies the bootstrap chain and removes the tsx dependency.

Key changes:
- Add "type": "module" to package.json and set engines >= 22.6.0
- Convert launch.js, dtx.js to TypeScript with strip-types shebangs
- Delete register.js/register.d.ts (tsx loader no longer needed)
- Update tsconfig: module/moduleResolution to NodeNext, add
allowImportingTsExtensions and noEmit
- Replace all __dirname usage with import.meta.dirname
- Replace dynamic require() in resolveProject.ts with createRequire()
- Add .ts extensions to all relative imports (~82 files)
- Add JSON import assertions (with { type: "json" })
- Upgrade chalk from v4 to v5 (ESM-only)
- Remove tsx from dependencies
2026-05-05 15:33:34 -05:00

34 lines
1.2 KiB
TypeScript

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License
import { describe, it, assert, expect } from "vitest";
import path from "node:path";
import { resolveProject } from "../src/util/resolveProject.ts";
describe("Project Resolution", () => {
it("resolution halts at monorepo root", async () => {
await expect(resolveProject(path.join(import.meta.dirname, "..", ".."))).rejects.toThrow(
/monorepo root/,
);
});
it("resolution halts at filesystem root", async () => {
const p = path.join(import.meta.dirname, "..", "..", "..", "..", "..");
await expect(resolveProject(p)).rejects.toThrow(/filesystem root/);
});
it("resolution finds dev-tool package", async () => {
const packageInfo = await resolveProject(import.meta.dirname);
assert.equal(packageInfo.name, "@azure/dev-tool");
assert.match(
packageInfo.path,
// Replacement below is required because of escaping. A single backslash is
// interpreted as an escape character in the RegExp compiler, but we need
// it to be interpreted _literally_ in windows file paths, so we double-escape them.
new RegExp(
`.*${(path.sep + path.join("common", "tools", "dev-tool")).replace(/\\/g, "\\\\")}`,
),
);
});
});