Skip to content
Draft
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- "@typespec/http-client-python"
---

Migrate eng scripts from tsx to native Node.js TypeScript support
12 changes: 6 additions & 6 deletions packages/http-client-python/eng/scripts/ci/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const argv = parseArgs({

if (argv.values.help) {
console.log(`
${pc.bold("Usage:")} tsx format.ts [options]
${pc.bold("Usage:")} node format.ts [options]

${pc.bold("Description:")}
Format code using Prettier (TypeScript) and Black (Python).
Expand All @@ -56,19 +56,19 @@ ${pc.bold("Options:")}

${pc.bold("Examples:")}
${pc.dim("# Format emitter + pygen source (default)")}
tsx format.ts
node format.ts

${pc.dim("# Format only TypeScript emitter")}
tsx format.ts --emitter
node format.ts --emitter

${pc.dim("# Format only pygen source code")}
tsx format.ts --generator
node format.ts --generator

${pc.dim("# Check formatting without making changes")}
tsx format.ts --check
node format.ts --check

${pc.dim("# Format generated SDK packages")}
tsx format.ts --generated
node format.ts --generated
`);
process.exit(0);
}
Expand Down
12 changes: 6 additions & 6 deletions packages/http-client-python/eng/scripts/ci/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const argv = parseArgs({

if (argv.values.help) {
console.log(`
${pc.bold("Usage:")} tsx lint.ts [options]
${pc.bold("Usage:")} node lint.ts [options]

${pc.bold("Description:")}
Run linting checks on the codebase.
Expand All @@ -59,19 +59,19 @@ ${pc.bold("Options:")}

${pc.bold("Examples:")}
${pc.dim("# Lint emitter + pygen source (default)")}
tsx lint.ts
node lint.ts

${pc.dim("# Lint only TypeScript emitter")}
tsx lint.ts --emitter
node lint.ts --emitter

${pc.dim("# Lint only pygen source code")}
tsx lint.ts --generator
node lint.ts --generator

${pc.dim("# Lint generated SDK packages")}
tsx lint.ts --generated
node lint.ts --generated

${pc.dim("# Lint generated SDK packages for azure only")}
tsx lint.ts --generated --flavor=azure
node lint.ts --generated --flavor=azure
`);
process.exit(0);
}
Expand Down
16 changes: 8 additions & 8 deletions packages/http-client-python/eng/scripts/ci/regenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import {
cleanGeneratedCode,
getSubdirectories,
preprocess,
RegenerateContext,
RegenerateFlags,
type RegenerateContext,
type RegenerateFlags,
runParallel,
} from "./regenerate-common.js";
} from "./regenerate-common.ts";

// Parse arguments
const argv = parseArgs({
Expand All @@ -47,7 +47,7 @@ const argv = parseArgs({

if (argv.values.help) {
console.log(`
${pc.bold("Usage:")} tsx regenerate.ts [options]
${pc.bold("Usage:")} node regenerate.ts [options]

${pc.bold("Description:")}
Regenerates Python SDK code from TypeSpec definitions using in-process compilation.
Expand Down Expand Up @@ -75,16 +75,16 @@ ${pc.bold("Options:")}

${pc.bold("Examples:")}
${pc.dim("# Regenerate all packages for both flavors")}
tsx regenerate.ts
node regenerate.ts

${pc.dim("# Regenerate only Azure packages")}
tsx regenerate.ts --flavor azure
node regenerate.ts --flavor azure

${pc.dim("# Regenerate a specific package by name")}
tsx regenerate.ts --flavor azure --name authentication-api-key
node regenerate.ts --flavor azure --name authentication-api-key

${pc.dim("# Regenerate with more parallelism")}
tsx regenerate.ts --jobs 50
node regenerate.ts --jobs 50
`);
process.exit(0);
}
Expand Down
12 changes: 6 additions & 6 deletions packages/http-client-python/eng/scripts/ci/typecheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const argv = parseArgs({

if (argv.values.help) {
console.log(`
${pc.bold("Usage:")} tsx typecheck.ts [options]
${pc.bold("Usage:")} node typecheck.ts [options]

${pc.bold("Description:")}
Run type checking (mypy + pyright) on Python code.
Expand All @@ -58,19 +58,19 @@ ${pc.bold("Options:")}

${pc.bold("Examples:")}
${pc.dim("# Type check pygen source (default - runs both mypy and pyright)")}
tsx typecheck.ts
node typecheck.ts

${pc.dim("# Run only mypy on pygen source")}
tsx typecheck.ts --mypy
node typecheck.ts --mypy

${pc.dim("# Run only pyright on pygen source")}
tsx typecheck.ts --pyright
node typecheck.ts --pyright

${pc.dim("# Type check generated SDK packages")}
tsx typecheck.ts --generated
node typecheck.ts --generated

${pc.dim("# Type check generated SDK packages for azure only")}
tsx typecheck.ts --generated --flavor=azure
node typecheck.ts --generated --flavor=azure
`);
process.exit(0);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/http-client-python/eng/scripts/setup/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { exec } from "child_process";
import { runPython3 } from "./run-python3.js";
import { runPython3 } from "./run-python3.ts";

async function main() {
await runPython3("./eng/scripts/setup/build_pygen_wheel.py");
Expand Down
34 changes: 34 additions & 0 deletions packages/http-client-python/eng/scripts/setup/install-runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Plain JavaScript bootstrap for the npm `install` lifecycle script.
// This file must stay as plain JavaScript because it may run from within
// node_modules (when the package is installed as a dependency), where
// Node.js refuses to strip TypeScript types.
//
// When installed from npm/tgz the compiled dist/scripts/setup/install.js is
// used. When running in the repository itself (dev context) the TypeScript
// source is loaded directly via Node.js native type stripping.
import { existsSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const compiledPath = join(__dirname, "../../../dist/scripts/setup/install.js");

try {
if (existsSync(compiledPath)) {
// Installed from npm package: use pre-compiled JavaScript.
// Use pathToFileURL so Windows absolute paths (D:\...) are valid ESM URLs.
await import(pathToFileURL(compiledPath).href);
} else {
// Development context: TypeScript source works via native type stripping.
await import("./install.ts");
}
} catch (err) {
if (err?.code === "ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING") {
// Running from node_modules without pre-compiled JS — this shouldn't
// happen for a properly built package, but fail gracefully rather than
// blocking the install.
console.log("Python environment setup skipped: run 'npm run build' first."); // eslint-disable-line no-console
} else {
throw err;
}
}
2 changes: 1 addition & 1 deletion packages/http-client-python/eng/scripts/setup/install.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cp from "child_process";
import { patchPythonPath } from "./system-requirements.js";
import { patchPythonPath } from "./system-requirements.ts";

async function main() {
let pythonCommand: string[];
Expand Down
34 changes: 34 additions & 0 deletions packages/http-client-python/eng/scripts/setup/prepare-runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Plain JavaScript bootstrap for the npm `prepare` lifecycle script.
// This file must stay as plain JavaScript because it may run from within
// node_modules (when the package is installed as a dependency), where
// Node.js refuses to strip TypeScript types.
//
// When installed from npm/tgz the compiled dist/scripts/setup/prepare.js is
// used. When running in the repository itself (dev context) the TypeScript
// source is loaded directly via Node.js native type stripping.
import { existsSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const compiledPath = join(__dirname, "../../../dist/scripts/setup/prepare.js");

try {
if (existsSync(compiledPath)) {
// Installed from npm package: use pre-compiled JavaScript.
// Use pathToFileURL so Windows absolute paths (D:\...) are valid ESM URLs.
await import(pathToFileURL(compiledPath).href);
} else {
// Development context: TypeScript source works via native type stripping.
await import("./prepare.ts");
}
} catch (err) {
if (err?.code === "ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING") {
// Running from node_modules without pre-compiled JS — this shouldn't
// happen for a properly built package, but fail gracefully rather than
// blocking the install.
console.log("Python environment prepare skipped: run 'npm run build' first."); // eslint-disable-line no-console
} else {
throw err;
}
}
2 changes: 1 addition & 1 deletion packages/http-client-python/eng/scripts/setup/prepare.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { runPython3 } from "./run-python3.js";
import { runPython3 } from "./run-python3.ts";

async function main() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
// path resolution algorithm as AutoRest so that the behavior
// is fully consistent (and also supports AUTOREST_PYTHON_EXE).
//
// Invoke it like so: "tsx run-python3.ts script.py"
// Invoke it like so: "node run-python3.ts script.py"

import cp from "child_process";
import { patchPythonPath } from "./system-requirements.js";
import { patchPythonPath } from "./system-requirements.ts";

export async function runPython3(...args: string[]) {
const command = await patchPythonPath(["python", ...args], {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChildProcess, spawn, SpawnOptions } from "child_process";
import { ChildProcess, spawn, type SpawnOptions } from "child_process";

/*
* Copied from @autorest/system-requirements
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noEmit": false,
"rootDir": ".",
"outDir": "../../../dist/scripts/setup",
"allowImportingTsExtensions": true,
"rewriteRelativeImportExtensions": true,
"declaration": false,
"declarationMap": false,
"sourceMap": false,
"strict": true,
"skipLibCheck": true,
"types": ["node"]
},
"include": ["./**/*.ts"]
}
Loading
Loading