Skip to content

Commit 3c84063

Browse files
authored
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 #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
1 parent 0dddb4d commit 3c84063

98 files changed

Lines changed: 460 additions & 463 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
lts/iron
1+
lts/jod

common/tools/dev-tool/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ It provides a place to centralize scripts, resources, and processes for developm
66

77
## Installation
88

9-
`dev-tool` runs using [tsx](https://tsx.is/), so it does not need to be built. It is ready-to-go after a `pnpm install`. It additionally does not need to be installed to a user's machine in order to be used in `package.json` scripts, since it provides the `dev-tool` binary to any dependent packages through the `bin` entry in its `package.json`. Simply add `@azure/dev-tool` to the `devDependencies` of a package, and the `dev-tool` binary will become available. If you wish to use `dev-tool` from the CLI manually, you can run it from a service package using `npx dev-tool`, or you can install it globally on your system by running `npm install -g` from this directory.
9+
`dev-tool` runs TypeScript source directly using Node.js's built-in type stripping, so it does not need to be built. It is ready-to-go after a `pnpm install` (requires Node.js 22.18+). It additionally does not need to be installed to a user's machine in order to be used in `package.json` scripts, since it provides the `dev-tool` binary to any dependent packages through the `bin` entry in its `package.json`. Simply add `@azure/dev-tool` to the `devDependencies` of a package, and the `dev-tool` binary will become available. If you wish to use `dev-tool` from the CLI manually, you can run it from a service package using `npx dev-tool`, or you can install it globally on your system by running `npm install -g` from this directory.
1010

1111
## Usage
1212

common/tools/dev-tool/dtx.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

common/tools/dev-tool/dtx.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env node
2+
3+
// Copyright (c) Microsoft Corporation.
4+
// Licensed under the MIT License.
5+
6+
/**
7+
* This command is an alias for `dev-tool run vendored`
8+
*/
9+
10+
import { spawn } from "node:child_process";
11+
import { resolve } from "node:path";
12+
13+
const engine = process.argv0;
14+
15+
const args = [
16+
resolve(import.meta.dirname, "launch.ts"),
17+
"run",
18+
"vendored",
19+
...process.argv.slice(2),
20+
];
21+
22+
const subProcess = spawn(engine, args, { stdio: "inherit" });
23+
24+
subProcess.on("exit", (code, signal) => {
25+
console.error(`subprocess exited with ${code} and signal ${signal}`);
26+
process.exit(code ?? 0);
27+
});
28+
subProcess.on("error", (error) => {
29+
console.error(error);
30+
process.exit(1);
31+
});

common/tools/dev-tool/eslint.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import typescriptEsLint from "typescript-eslint";
33

44
export default typescriptEsLint.config(
55
{
6-
ignores: ["**/test/samples/files/expectations/**/*.*", "**/*.{js,cjs,mjs}"],
6+
ignores: ["**/test/samples/files/**/*.*", "**/*.{js,cjs,mjs}"],
77
},
88
{
99
languageOptions: {
@@ -20,7 +20,7 @@ export default typescriptEsLint.config(
2020
{
2121
rules: {
2222
"@typescript-eslint/no-unused-vars": "off",
23-
"@typescript-eslint/no-require-imports": "off",
23+
"@typescript-eslint/consistent-type-imports": "error",
2424
},
2525
},
2626
);
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
// Copyright (c) Microsoft Corporation.
44
// Licensed under the MIT License.
55

6-
const path = require("path");
6+
import "dotenv/config";
77

88
if (process.env.DEBUG) {
9-
console.info("Azure SDK for JS dev-tool: bootstrapping from", __dirname);
9+
console.info("Azure SDK for JS dev-tool: bootstrapping from", import.meta.dirname);
1010
}
1111

12-
require("./register");
13-
14-
require(path.join(__dirname, "src", "index.ts"));
12+
await import("./src/index.ts");

common/tools/dev-tool/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
{
22
"name": "@azure/dev-tool",
33
"version": "1.0.0",
4+
"type": "module",
45
"description": "A helpful command for azure-sdk-for-js developers",
56
"sdk-type": "utility",
67
"bin": {
7-
"dev-tool": "launch.js",
8-
"dtx": "dtx.js"
8+
"dev-tool": "launch.ts",
9+
"dtx": "dtx.ts"
10+
},
11+
"engines": {
12+
"node": ">=22.18.0"
913
},
1014
"files": [
1115
"src"
@@ -47,7 +51,7 @@
4751
"@pnpm/catalogs.resolver": "^1000.0.3",
4852
"@pnpm/catalogs.types": "^1000.0.0",
4953
"@pnpm/workspace.read-manifest": "^1000.1.5",
50-
"chalk": "^4.1.1",
54+
"chalk": "^5.4.1",
5155
"concurrently": "^9.2.1",
5256
"diff": "^8.0.2",
5357
"dotenv": "^16.0.0",
@@ -60,7 +64,6 @@
6064
"tar": "^7.4.3",
6165
"ts-morph": "^27.0.0",
6266
"tslib": "^2.8.1",
63-
"tsx": "catalog:",
6467
"typescript": "~6.0.2",
6568
"unzipper": "~0.12.3",
6669
"yaml": "^2.3.4"

common/tools/dev-tool/register.d.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

common/tools/dev-tool/register.js

Lines changed: 0 additions & 58 deletions
This file was deleted.

common/tools/dev-tool/src/checks/packageJson.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {
44
packageJsonCheck,
55
enableForEsmPackage,
66
enableForSdkType,
7-
} from "../framework/check";
8-
import { resolveRoot } from "../util/resolveProject";
7+
} from "../framework/check.ts";
8+
import { resolveRoot } from "../util/resolveProject.ts";
99

1010
/**
1111
* Expected value for engines field

0 commit comments

Comments
 (0)