Repository navigation
feat(migrate): migrate tsx scripts to vpx #3179
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
Merged
+2,021
−15
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
04f2797
feat(migrate): migrate tsx scripts to vpx
fengmk2 2d74237
fix(migrate): keep tsx where vpx would fail or lose it
fengmk2 c7407e0
fix(migrate): follow cd and find more tsx uses before removing it
fengmk2 e3d65ff
fix(migrate): rewrite quoted tsx only for launchers, check more Commo…
fengmk2 0522e9a
fix(migrate): find tsx in tool settings, keep require('./a.js') entries
fengmk2 5d51c69
fix(migrate): rewrite only command arguments of launchers, keep tsx-o…
fengmk2 5946649
fix(migrate): keep tsx for watched tests and launched TSX_TSCONFIG_PATH
fengmk2 f799a45
fix(migrate): detect compact ES module syntax, follow TSX_TSCONFIG_PA…
fengmk2 8c8fcc4
fix(migrate): handle cd fallbacks, %VAR%, and Windows tsx bin paths
fengmk2 823675b
style(migrate): use Array#at for the last token
fengmk2 e95bb39
fix(migrate): detect shebang-only tsx projects, scan JSONC configs
fengmk2 fc3977f
fix(migrate): refine the tsx script checks and use scan
fengmk2 69138ca
fix(migrate): keep tsx for large globs, scan TOML and argv-array laun…
fengmk2 139f207
fix(migrate): keep tsx for unreadable entries and unresolvable requires
fengmk2 a7999c7
fix(migrate): count more module uses, skip concurrently option values
fengmk2 ecd57a6
fix(migrate): drop redundant tsx loader flags, find more loader refer…
fengmk2 3785723
fix(migrate): keep tsx for decorators vpx cannot compile and unmatche…
fengmk2 9a3451f
fix(migrate): check preloads, env files, and --tsconfig before rewrit…
fengmk2 0daf722
refactor(migrate): simplify the tsx checks, fix false retention
fengmk2 e6d9b40
fix(migrate): find annotated tsx imports, bare imports aliases, npx -…
fengmk2 464cc7f
fix(migrate): check tsx preloads given as absolute paths
fengmk2 f7b188d
test(migrate): keep the absolute preload test free of Windows temp paths
fengmk2 ecac02a
fix(migrate): keep tsx for bare lint-staged tasks and loader settings
fengmk2 227cc4c
Merge branch 'main' into feat/migrate-tsx-to-vpx
fengmk2 6c3f3f8
Merge branch 'main' into feat/migrate-tsx-to-vpx
fengmk2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_tsx/.fixture/tsx/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "name": "tsx", | ||
| "version": "4.20.0" | ||
| } |
14 changes: 14 additions & 0 deletions
14
crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_tsx/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "name": "migration-tsx", | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "tsx watch --clear-screen=false src/server.ts", | ||
| "seed": "cross-env NODE_ENV=development npx tsx scripts/seed.ts", | ||
| "bench": "node --import tsx ./scripts/bench.ts", | ||
| "start": "concurrently \"tsx watch src/server.ts\" \"vp dev\"" | ||
| }, | ||
| "devDependencies": { | ||
| "tsx": "file:.fixture/tsx", | ||
| "vite": "^7.0.0" | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_tsx/scripts/bench.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const runs: number = 100; |
3 changes: 3 additions & 0 deletions
3
crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_tsx/scripts/release.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #!/usr/bin/env tsx | ||
| const version: string = '1.0.0'; | ||
| console.log(version); |
1 change: 1 addition & 0 deletions
1
crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_tsx/scripts/seed.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const rows: number = 10; |
31 changes: 31 additions & 0 deletions
31
crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_tsx/snapshots.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| [[case]] | ||
| name = "migration_tsx_scripts" | ||
| vp = "local" | ||
| comment = "tsx comes from a local stub package so the install stays offline" | ||
| steps = [ | ||
| { argv = ["vp", "migrate", "--no-interactive", "--no-hooks", "--no-agent", "--no-editor"], comment = "tsx scripts should migrate to vpx automatically", continue-on-failure = true }, | ||
| { argv = ["vpt", "print-file", "package.json"], comment = "scripts run vpx, and the tsx devDependency is gone", continue-on-failure = true }, | ||
| { argv = ["vpt", "print-file", "scripts/release.ts"], comment = "the shebang runs vpx", continue-on-failure = true }, | ||
| ] | ||
|
|
||
| [[case]] | ||
| name = "migration_tsx_kept" | ||
| vp = "local" | ||
| comment = "tsx comes from a local stub package so the install stays offline" | ||
| steps = [ | ||
| { argv = ["vpt", "json-edit", "package.json", "scripts.repl", "tsx"], snapshot = false }, | ||
| { argv = ["vpt", "json-edit", "package.json", "scripts.calc", "tsx -e 'console.log(1 + 1)'"], snapshot = false }, | ||
| { argv = ["vp", "migrate", "--no-interactive", "--no-hooks", "--no-agent", "--no-editor"], comment = "scripts vpx cannot run keep tsx, with a warning for each", continue-on-failure = true }, | ||
| { argv = ["vpt", "print-file", "package.json"], comment = "the other scripts run vpx, and the tsx devDependency stays", continue-on-failure = true }, | ||
| ] | ||
|
|
||
| [[case]] | ||
| name = "migration_tsx_already_vite_plus" | ||
| vp = "local" | ||
| comment = "On a project already using Vite+, the tsx migration belongs to `vp migrate --full`." | ||
| steps = [ | ||
| { argv = ["vpt", "json-edit", "package.json", "devDependencies.vite-plus", "latest"], snapshot = false }, | ||
| { argv = ["vp", "migrate", "--no-interactive"], comment = "a plain upgrade leaves tsx scripts to --full", continue-on-failure = true }, | ||
| { argv = ["vp", "migrate", "--no-interactive", "--full", "--no-hooks", "--no-agent", "--no-editor"], comment = "--full migrates tsx scripts to vpx", continue-on-failure = true }, | ||
| { argv = ["vpt", "print-file", "package.json"], comment = "scripts run vpx, and the tsx devDependency is gone", continue-on-failure = true }, | ||
| ] |
59 changes: 59 additions & 0 deletions
59
...i_snapshots/fixtures/migration_tsx/snapshots/migration_tsx_already_vite_plus.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # migration_tsx_already_vite_plus | ||
|
|
||
| On a project already using Vite+, the tsx migration belongs to `vp migrate --full`. | ||
|
|
||
| ## `vpt json-edit package.json devDependencies.vite-plus latest` | ||
|
|
||
|
|
||
| ## `vp migrate --no-interactive` | ||
|
|
||
| a plain upgrade leaves tsx scripts to --full | ||
|
|
||
| ``` | ||
| VITE+ - The Unified Toolchain for the Web | ||
|
|
||
| ◇ Updated . to Vite+ <version> | ||
| • Node <version> pnpm <version> | ||
| • Dependencies: | ||
| vite-plus latest → <version> | ||
| vite → <version> | ||
| • Package manager settings configured | ||
| • Skipped editor, hooks, and lint setup. Run `vp migrate --full` to apply them. | ||
| ``` | ||
|
|
||
| ## `vp migrate --no-interactive --full --no-hooks --no-agent --no-editor` | ||
|
|
||
| --full migrates tsx scripts to vpx | ||
|
|
||
| ``` | ||
| VITE+ - The Unified Toolchain for the Web | ||
|
|
||
| ▲ No package manager is declared in package.json; using pnpm for this migration without adding a pin. Run `vp env pin` to declare it explicitly. | ||
| ● tsx scripts detected. Auto-migrating to vpx... | ||
| ◇ Updated . to Vite+ <version> | ||
| • Node <version> pnpm <version> | ||
| • Dependencies: | ||
| vite → <version> | ||
| • tsx scripts migrated to `vpx` | ||
| ``` | ||
|
|
||
| ## `vpt print-file package.json` | ||
|
|
||
| scripts run vpx, and the tsx devDependency is gone | ||
|
|
||
| ``` | ||
| { | ||
| "devDependencies": { | ||
| "vite": "catalog:", | ||
| "vite-plus": "catalog:" | ||
| }, | ||
| "name": "migration-tsx", | ||
| "scripts": { | ||
| "bench": "vpx ./scripts/bench.ts", | ||
| "dev": "vpx --watch --clear-screen=false src/server.ts", | ||
| "seed": "cross-env NODE_ENV=development vpx scripts/seed.ts", | ||
| "start": "concurrently \"vpx --watch src/server.ts\" \"vp dev\"" | ||
| }, | ||
| "type": "module" | ||
| } | ||
| ``` |
51 changes: 51 additions & 0 deletions
51
...hots/tests/cli_snapshots/fixtures/migration_tsx/snapshots/migration_tsx_kept.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # migration_tsx_kept | ||
|
|
||
| tsx comes from a local stub package so the install stays offline | ||
|
|
||
| ## `vpt json-edit package.json scripts.repl tsx` | ||
|
|
||
|
|
||
| ## `vpt json-edit package.json scripts.calc 'tsx -e '\''console.log(1 + 1)'\'''` | ||
|
|
||
|
|
||
| ## `vp migrate --no-interactive --no-hooks --no-agent --no-editor` | ||
|
|
||
| scripts vpx cannot run keep tsx, with a warning for each | ||
|
|
||
| ``` | ||
| VITE+ - The Unified Toolchain for the Web | ||
|
|
||
| ● tsx scripts detected. Auto-migrating to vpx... | ||
| ◇ Migrated . to Vite+ <version> | ||
| • Node <version> pnpm <version> | ||
| • 1 config update applied | ||
| • tsx scripts migrated to `vpx` | ||
| ! Warnings: | ||
| - Kept tsx in package.json scripts "calc": `vpx` does not run TypeScript passed to --eval or --print. | ||
| - Kept tsx in package.json scripts "repl": `vpx` does not start a TypeScript REPL. | ||
| - Kept the tsx devDependency in package.json: `scripts` in package.json still uses tsx. | ||
| ``` | ||
|
|
||
| ## `vpt print-file package.json` | ||
|
|
||
| the other scripts run vpx, and the tsx devDependency stays | ||
|
|
||
| ``` | ||
| { | ||
| "devDependencies": { | ||
| "tsx": "file:.fixture/tsx", | ||
| "vite": "catalog:", | ||
| "vite-plus": "catalog:" | ||
| }, | ||
| "name": "migration-tsx", | ||
| "scripts": { | ||
| "bench": "vpx ./scripts/bench.ts", | ||
| "calc": "tsx -e 'console.log(1 + 1)'", | ||
| "dev": "vpx --watch --clear-screen=false src/server.ts", | ||
| "repl": "tsx", | ||
| "seed": "cross-env NODE_ENV=development vpx scripts/seed.ts", | ||
| "start": "concurrently \"vpx --watch src/server.ts\" \"vp dev\"" | ||
| }, | ||
| "type": "module" | ||
| } | ||
| ``` |
48 changes: 48 additions & 0 deletions
48
...s/tests/cli_snapshots/fixtures/migration_tsx/snapshots/migration_tsx_scripts.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # migration_tsx_scripts | ||
|
|
||
| tsx comes from a local stub package so the install stays offline | ||
|
|
||
| ## `vp migrate --no-interactive --no-hooks --no-agent --no-editor` | ||
|
|
||
| tsx scripts should migrate to vpx automatically | ||
|
|
||
| ``` | ||
| VITE+ - The Unified Toolchain for the Web | ||
|
|
||
| ● tsx scripts detected. Auto-migrating to vpx... | ||
| ◇ Migrated . to Vite+ <version> | ||
| • Node <version> pnpm <version> | ||
| • 1 config update applied | ||
| • tsx scripts migrated to `vpx` | ||
| ``` | ||
|
|
||
| ## `vpt print-file package.json` | ||
|
|
||
| scripts run vpx, and the tsx devDependency is gone | ||
|
|
||
| ``` | ||
| { | ||
| "name": "migration-tsx", | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "vpx --watch --clear-screen=false src/server.ts", | ||
| "seed": "cross-env NODE_ENV=development vpx scripts/seed.ts", | ||
| "bench": "vpx ./scripts/bench.ts", | ||
| "start": "concurrently \"vpx --watch src/server.ts\" \"vp dev\"" | ||
| }, | ||
| "devDependencies": { | ||
| "vite": "catalog:", | ||
| "vite-plus": "catalog:" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## `vpt print-file scripts/release.ts` | ||
|
|
||
| the shebang runs vpx | ||
|
|
||
| ``` | ||
| #!/usr/bin/env vpx | ||
| const version: string = '1.0.0'; | ||
| console.log(version); | ||
| ``` |
1 change: 1 addition & 0 deletions
1
crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_tsx/src/server.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const port: number = 3000; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.