@vite-hub/codemods 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {}
package/dist/cli.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import { t as runCli } from "./cli-main-CmPQbswC.js";
3
+ //#region src/cli.ts
4
+ process.exitCode = await runCli(process.argv.slice(2));
5
+ //#endregion
6
+ export {};
@@ -0,0 +1,150 @@
1
+ import "nostics";
2
+ //#region src/types.d.ts
3
+ /** A manual step that the codemod could not do safely. */
4
+ interface FollowUp {
5
+ /** Path relative to the project directory. */
6
+ file?: string;
7
+ /** 1-based line in `file`. */
8
+ line?: number;
9
+ message: string;
10
+ }
11
+ /** The planned content of one file. `before` is `undefined` for a new file, and `after` is `null` for a deleted file. */
12
+ interface FileEdit {
13
+ /** Path relative to the project directory. */
14
+ path: string;
15
+ before: string | undefined;
16
+ after: string | null;
17
+ }
18
+ interface CodemodResult {
19
+ /** One line that tells what the codemod did. */
20
+ summary: string;
21
+ edits: FileEdit[];
22
+ followUps: FollowUp[];
23
+ /** Facts about the migration that need no action in a specific file. */
24
+ notes: string[];
25
+ /** Commands to run after the codemod, such as an install. */
26
+ nextSteps: string[];
27
+ }
28
+ interface CodemodContext {
29
+ /** Absolute path of the project directory. */
30
+ cwd: string;
31
+ /** Original project directory for read-only installed dependency inspection when cwd is a scratch copy. */
32
+ dependencyRoot?: string;
33
+ }
34
+ /** Why a codemod applies to a project, such as "nuxt.config.ts lists nuxt-safe-runtime-config". */
35
+ interface Detection {
36
+ reason: string;
37
+ }
38
+ interface Codemod {
39
+ name: string;
40
+ /** One line for the codemod list. */
41
+ description: string;
42
+ /** Positional arguments after the codemod name, for help output. */
43
+ usage: string;
44
+ /** Tells whether the project uses what this codemod migrates. It must be cheap and must not throw for a project that does not use it. */
45
+ detect: (context: CodemodContext) => Promise<Detection | undefined>;
46
+ /** Plans the edits. It must not write files; the runner writes them. */
47
+ run: (context: CodemodContext) => Promise<CodemodResult>;
48
+ }
49
+ //#endregion
50
+ //#region src/registry.d.ts
51
+ /**
52
+ * Every available codemod. Add a new codemod here to make the CLI list and run it. NuxtHub runs first: it renames
53
+ * hub to vitehub in place and picks the host from the Wrangler config, and the others add to that vitehub key.
54
+ */
55
+ export declare const codemods: readonly Codemod[];
56
+ /**
57
+ * Codemods that move an app between ViteHub releases. `vitehub migrate` runs each one that applies, in this order, and
58
+ * each one sees the edits of the ones before it. Config codemods run first: `vitehub-options` moves top-level feature
59
+ * keys into `vitehub()`, where `agent-surface` then renames the Agent driver keys. `define-forms` moves the Database
60
+ * files before the import codemods rewrite them. `root-accessors` moves `#vitehub/env/server` to `vite-hub/env` before
61
+ * `one-entry-imports` joins the `vite-hub/env/*` imports with it. The codemods that move an app from another module, such
62
+ * as NuxtHub, are not upgrades, so only `npx @vite-hub/codemods` runs them.
63
+ */
64
+ export declare const upgradeCodemods: readonly Codemod[];
65
+ //#endregion
66
+ //#region src/runner.d.ts
67
+ interface RunCodemodOptions {
68
+ /** Project directory. Defaults to `process.cwd()`. */
69
+ cwd?: string;
70
+ /** Plan the edits and write nothing. */
71
+ dryRun?: boolean;
72
+ }
73
+ interface CodemodRun {
74
+ codemod: Codemod;
75
+ cwd: string;
76
+ dryRun: boolean;
77
+ result: CodemodResult;
78
+ }
79
+ export declare function findCodemod(name: string): Codemod | undefined;
80
+ /**
81
+ * Runs one codemod. Writes its edits unless `dryRun` is set. Throws `CODEMODS_BLOCKED` when it cannot migrate, also when an
82
+ * edit is a symbolic link or is inside one.
83
+ */
84
+ export declare function runCodemod(name: string, options?: RunCodemodOptions): Promise<CodemodRun>;
85
+ /** Formats the planned edits as unified diffs. */
86
+ export declare function formatDiff(result: Pick<CodemodResult, "edits">): string;
87
+ /** Formats the report that ends every codemod run. */
88
+ export declare function formatReport(run: CodemodRun): string;
89
+ //#endregion
90
+ //#region src/cli-main.d.ts
91
+ interface CliOutput {
92
+ stdout: (text: string) => void;
93
+ stderr: (text: string) => void;
94
+ }
95
+ /** Runs the CLI with arguments after the binary name. Returns the exit code. */
96
+ export declare function runCli(argv: readonly string[], output?: CliOutput): Promise<number>;
97
+ //#endregion
98
+ //#region src/migrate.d.ts
99
+ interface RunMigrationOptions {
100
+ /** Project directory. Defaults to `process.cwd()`. */
101
+ cwd?: string;
102
+ /** Plan the edits and write nothing. */
103
+ dryRun?: boolean;
104
+ /** The codemods to detect and run, in order. Defaults to every codemod. `vitehub migrate` passes `upgradeCodemods`. */
105
+ codemods?: readonly Codemod[];
106
+ }
107
+ /** One codemod that the migration ran. It has a `result` or an `error`. */
108
+ interface MigrationStep {
109
+ codemod: Codemod;
110
+ detection: Detection;
111
+ result?: CodemodResult;
112
+ /** Why the codemod could not migrate. Its edits are not applied. */
113
+ error?: string;
114
+ }
115
+ interface Migration {
116
+ cwd: string;
117
+ dryRun: boolean;
118
+ steps: MigrationStep[];
119
+ /** The combined edits of every step that succeeded, against the files as they were before the migration. */
120
+ edits: FileEdit[];
121
+ /** Problems with the project that no codemod owns, such as a Nuxt version that ViteHub does not support. */
122
+ warnings: string[];
123
+ /** Names of the codemods that the migration checked. */
124
+ supported: string[];
125
+ }
126
+ /** Lists every codemod of `candidates` that applies to the project, in their order. */
127
+ export declare function detectCodemods(cwd: string, candidates?: readonly Codemod[]): Promise<Array<{
128
+ codemod: Codemod;
129
+ detection: Detection;
130
+ }>>;
131
+ /**
132
+ * Detects every supported module in the project and runs its codemod. The codemods run one after another on a
133
+ * scratch copy, so each one sees the edits of the ones before it. A codemod that fails adds an error and changes
134
+ * nothing; the others still run. Writes the combined edits unless `dryRun` is set.
135
+ */
136
+ export declare function runMigration(options?: RunMigrationOptions): Promise<Migration>;
137
+ /**
138
+ * Formats the report that ends a migration: what each codemod did, what it could not do, and what to run next.
139
+ * `nextSteps` adds steps of the caller after those of the codemods, when the migration changed files.
140
+ */
141
+ export declare function formatMigrationReport(migration: Migration, nextSteps?: readonly string[]): string;
142
+ //#endregion
143
+ //#region src/error-diagnostics.d.ts
144
+ /** Whether a codemod refused to migrate the project, so the caller reports the message and the fix. */
145
+ export declare function isCodemodError(error: unknown): error is Error & {
146
+ code: string;
147
+ fix?: string;
148
+ };
149
+ //#endregion
150
+ export type { Codemod, CodemodContext, CodemodResult, CodemodRun, Detection, FileEdit, FollowUp, Migration, MigrationStep, RunCodemodOptions, RunMigrationOptions };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import { a as findCodemod, c as runCodemod, d as isCodemodError, i as runMigration, l as codemods, n as detectCodemods, o as formatDiff, r as formatMigrationReport, s as formatReport, t as runCli, u as upgradeCodemods } from "./cli-main-CmPQbswC.js";
2
+ export { codemods, detectCodemods, findCodemod, formatDiff, formatMigrationReport, formatReport, isCodemodError, runCli, runCodemod, runMigration, upgradeCodemods };
package/package.json CHANGED
@@ -1,6 +1,74 @@
1
1
  {
2
2
  "name": "@vite-hub/codemods",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.3.0",
4
+ "description": "Codemods that move applications to ViteHub.",
5
+ "keywords": [
6
+ "codemod",
7
+ "migration",
8
+ "nuxt",
9
+ "typescript",
10
+ "vitehub"
11
+ ],
12
+ "homepage": "https://vitehub.dev",
13
+ "bugs": "https://github.com/vite-hub/vitehub/issues",
14
+ "license": "Apache-2.0",
15
+ "author": "onmax <maximogarciamtnez@gmail.com>",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/vite-hub/vitehub.git",
19
+ "directory": "packages/codemods"
20
+ },
21
+ "bin": {
22
+ "vitehub-codemods": "./dist/cli.js"
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "package.json"
27
+ ],
28
+ "type": "module",
29
+ "sideEffects": false,
30
+ "types": "./dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/index.js",
35
+ "default": "./dist/index.js"
36
+ },
37
+ "./package.json": "./package.json"
38
+ },
39
+ "dependencies": {
40
+ "@babel/parser": "^7.29.9",
41
+ "@valibot/to-json-schema": "^1.8.0",
42
+ "@vue/compiler-sfc": "^3.5.44",
43
+ "diff": "^9.0.0",
44
+ "jiti": "^2.7.0",
45
+ "magic-string": "^0.30.21",
46
+ "nostics": "1.4.0",
47
+ "scule": "^1.3.0",
48
+ "semver": "^7.8.5",
49
+ "tinyglobby": "^0.2.17",
50
+ "valibot": "^1.5.0"
51
+ },
52
+ "devDependencies": {
53
+ "@babel/types": "^7.29.8",
54
+ "@types/node": "^24.19.1",
55
+ "@types/semver": "^7.8.0",
56
+ "@vite-hub/env": "0.3.0",
57
+ "@vite-hub/internal": "0.0.1",
58
+ "publint": "^0.3.25",
59
+ "typescript": "^6.0.3",
60
+ "vite": "^8.2.2",
61
+ "vite-plus": "^0.3.3",
62
+ "vitest": "^4.1.11",
63
+ "zod": "^4.6.7"
64
+ },
65
+ "engines": {
66
+ "node": ">=22.18.0"
67
+ },
68
+ "scripts": {
69
+ "build": "vp pack",
70
+ "dev": "vp pack --watch",
71
+ "typecheck": "vp run --cache -t @vite-hub/codemods#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
72
+ "test": "vp run --cache -t @vite-hub/codemods#build && vp test"
73
+ }
6
74
  }