Repository navigation
feat(http-client-python): migrate eng scripts from tsx to native Node.js TypeScript #11425
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
Changes from all commits
ef99994
ab802ef
93e9e43
c839d08
a430f98
9c9118b
06a1c9d
42fa7cf
244309d
ecd9b2f
cf7a56f
64c162a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copilot could we change what file gets called with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked into it —
So the entry file has to be one that works in both contexts, which is why the If the runners feel too magic, the alternative I'd suggest is dropping TypeScript for the lifecycle chain entirely — convert |
| 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 | ||
| } | ||
| } | ||
|
timotheeguerin marked this conversation as resolved.
Resolved
|
||
| 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 | ||
| } | ||
| } | ||
|
timotheeguerin marked this conversation as resolved.
Resolved
|
||
| 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"] | ||
| } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iscai-msft / Libba Lawrence (@l0lawrence) for awareness