Skip to content
Closed
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yuchao Yan (@msyyc) I was not super sure about the way it was done in the packaged instance

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
2 changes: 1 addition & 1 deletion packages/http-client-python/emitter/src/run-python3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// 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";
Expand Down
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
14 changes: 7 additions & 7 deletions packages/http-client-python/eng/scripts/ci/regenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import pc from "picocolors";
import { fileURLToPath } from "url";
import { parseArgs } from "util";

import type { RegenerateContext, RegenerateFlags } from "./regenerate-common.js";
import type { RegenerateContext, RegenerateFlags } from "./regenerate-common.ts";
import {
buildTaskGroups,
cleanGeneratedCode,
getSubdirectories,
preprocess,
runParallel,
} from "./regenerate-common.js";
} from "./regenerate-common.ts";

// Parse arguments
const argv = parseArgs({
Expand All @@ -46,7 +46,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 @@ -74,16 +74,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
27 changes: 27 additions & 0 deletions packages/http-client-python/eng/scripts/setup/install-runner.js

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot could we change what file gets called with publishConfig overrides?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into it — publishConfig can't do this with npm.

  • npm's publishConfig only holds npm config values (registry/tag/access/provenance/etc.), not package.json field overrides: lib/commands/publish.js just does flatten(manifest.publishConfig, opts) into the npm config. Arbitrary field overrides (main, exports, scripts, …) are a pnpm/yarn feature, and even pnpm's allowlist doesn't include scripts.
  • I also confirmed empirically that npm pack does not rewrite package.json from publishConfig — the tarball's manifest keeps the original scripts. Since Build-Packages.ps1 packs with npm pack and then npm install <tgz>, the packed install/prepare scripts are exactly what's in the repo's package.json. This package is also excluded from the pnpm workspace, so pnpm's publish rewriting doesn't apply either.

So the entry file has to be one that works in both contexts, which is why the *-runner.js bootstraps exist (.ts can't be type-stripped under node_modules).

If the runners feel too magic, the alternative I'd suggest is dropping TypeScript for the lifecycle chain entirely — convert eng/scripts/setup/{install,prepare,run-python3,system-requirements}.ts to plain .js. That removes both runners plus the extra tsconfig.build.json/tsc build step, at the cost of losing types in those ~340 lines. Happy to do that if you prefer it — just let me know.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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 {
await import("./install.ts");
} catch (err) {
if (err?.code !== "ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING") {
throw err;
}
if (existsSync(compiledPath)) {
await import(pathToFileURL(compiledPath).href);
} else {
console.log("Python environment setup skipped: run 'npm run build' first."); // eslint-disable-line no-console
}
}
Comment thread
timotheeguerin marked this conversation as resolved.
Resolved
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
27 changes: 27 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,27 @@
// 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 {
await import("./prepare.ts");
} catch (err) {
if (err?.code !== "ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING") {
throw err;
}
if (existsSync(compiledPath)) {
await import(pathToFileURL(compiledPath).href);
} else {
console.log("Python environment prepare skipped: run 'npm run build' first."); // eslint-disable-line no-console
}
}
Comment thread
timotheeguerin marked this conversation as resolved.
Resolved
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
@@ -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