openapi-typesafe-migrate 1.0.0-rc.2 → 1.0.0-rc.4

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/CHANGELOG.md ADDED
@@ -0,0 +1,34 @@
1
+ # openapi-typesafe-migrate
2
+
3
+ ## 1.0.0-rc.4
4
+
5
+ No changes in this release.
6
+
7
+ ## 1.0.0-rc.3
8
+
9
+ No changes in this release.
10
+
11
+ ## 1.0.0-rc.2
12
+
13
+ No changes in this release.
14
+
15
+ ## 1.0.0-rc.1
16
+
17
+ No changes in this release.
18
+
19
+ ## 1.0.0-rc.0
20
+
21
+ ### Minor Changes
22
+
23
+ - [`730de95`](https://github.com/openapi-typesafe/openapi-typesafe/commit/730de95d814cf9b1ec70d2b8fac6b84b17106a29) Thanks [@fedorello](https://github.com/fedorello)! - New package `openapi-typesafe-migrate`: run `npx openapi-typesafe-migrate` in a project to move it from openapi-typescript, openapi-fetch, openapi-react-query and openapi-typescript-helpers. It renames the packages in `package.json` files and pnpm catalogs, module specifiers in sources, and the generator command and its renamed flags in scripts, CI files and Makefiles. A legacy `transform` callback that returns plain `ts.factory` types is rewritten to return type text with `irCallbacks: true`. Everything it cannot change safely is listed as a manual step. It only reports until you add `--write`, and logs every finding to a JSON Lines file.
24
+
25
+ ### Patch Changes
26
+
27
+ - [`e57d12b`](https://github.com/openapi-typesafe/openapi-typesafe/commit/e57d12b11b023258100cbabc5cac1d276ba5ae1f) Thanks [@fedorello](https://github.com/fedorello)! - `--help` lists the exit codes: `0` done, `1` the migration failed, `2` unknown option or argument.
28
+
29
+ - [`f0a93e4`](https://github.com/openapi-typesafe/openapi-typesafe/commit/f0a93e4094b3c69dfa8aeb229339f7d622f5cb06) Thanks [@fedorello](https://github.com/fedorello)! - The report now names only the package an override key targets: `openapi-typescript-helpers` no
30
+ longer also reports `openapi-typescript`, and `app>openapi-fetch`, `**/openapi-fetch` and
31
+ `openapi-fetch@0.13` keys are read as `openapi-fetch`. `overrides:` and `patchedDependencies:` in
32
+ `pnpm-workspace.yaml` that name an old package are reported like those of `package.json`; before,
33
+ they were neither rewritten nor reported. The output folders `.next`, `.nuxt`, `.output`,
34
+ `.svelte-kit`, `.turbo` and `coverage` are skipped like `dist`.
package/README.md CHANGED
@@ -18,16 +18,53 @@ Run it with `npx` (or `pnpm dlx`, `yarn dlx`, `bunx`), not as a dependency: it u
18
18
 
19
19
  ## What it changes
20
20
 
21
- | Where | Change |
22
- | -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
23
- | Every `package.json` | `dependencies`, `devDependencies`, `peerDependencies` and `optionalDependencies` get the new names, with the version of this tool; `^`, `~` and exact ranges keep their style. `catalog:` and `workspace:` stay. |
24
- | `pnpm-workspace.yaml` | Entries of `catalog:` and `catalogs:`. Comments, formatting and line endings stay. |
25
- | `package.json` scripts, shell scripts, YAML (CI), `Makefile`, `justfile`, `Dockerfile` | The `openapi-typescript` command, and the flags it renamed: `--immutable-types` / `-it` → `--immutable`, `--support-array-length` → `--array-length`, `--redoc` → `--redocly`, `-ap` → `--additional-properties`. |
26
- | Sources (`.ts`, `.tsx`, `.js`, `.mjs`, `.cjs`, `.vue`, `.svelte`, `.astro`, …) | Module specifiers only: `import` / `export … from`, `import()`, `require()`, `require.resolve()`, `import("…")` types and `@import` tags in JSDoc (every block), `declare module`, `/// <reference types>`, and module mocks: `vi.mock()` and the other `vi` / `jest` module methods (`jest.setMock()`, `jest.requireActual()`, …), bun's `mock.module()`. Components: their `<script>` blocks and Astro's frontmatter. |
27
- | `openapiTS(source, { transform })` calls | When `transform` is the only callback and returns plain `ts.factory` types (or the helper constants), the returns become type text and `irCallbacks: true` is added. |
28
-
29
- `Makefile`, `justfile` and `Dockerfile` are read only under exactly these names, so
30
- `Dockerfile.dev` is not changed.
21
+ | Where | Change |
22
+ | ------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
23
+ | Every `package.json` and pnpm's `package.yaml` | `dependencies`, `devDependencies`, `peerDependencies` and `optionalDependencies` get the new names, with the version of this tool, in the style of the old range (see below). `catalog:` and `workspace:` stay. An `npm:` alias of an original package (`"my-fetch": "npm:openapi-fetch@^0.13"`) points at the new package. The keys of `peerDependenciesMeta` and `dependenciesMeta` and the names in `bundleDependencies` get the new names too, and so do bun's `catalog` and `catalogs`. |
24
+ | `pnpm-workspace.yaml`, `.yarnrc.yml` | Entries of `catalog:` and `catalogs:` (pnpm, Yarn 4.10 and newer), ranges with spaces included. |
25
+ | `deno.json`, `deno.jsonc`, `import_map.json` | Keys of `imports` and `scopes` that name an original package (`openapi-fetch`, `openapi-fetch/`), and their `npm:` values. |
26
+ | Commands (the files are listed below the table) | The `openapi-typescript` command (also as `npx`, `pnpm exec`, `node_modules/.bin/…` or `npm:openapi-typescript`), and the flags it renamed, in that command only: `--immutable-types` / `-it` → `--immutable`, `--support-array-length` → `--array-length`, `--redoc` → `--redocly`, `-ap` → `--additional-properties`. The old package names in install commands (`npm i`, `pnpm add`, `npx -p`, …). |
27
+ | `.github/dependabot.yml` | Every old package name in `dependency-name` and `patterns`. |
28
+ | Sources (`.ts`, `.tsx`, `.js`, `.mjs`, `.cjs`, `.vue`, `.svelte`, `.astro`, …) | Module specifiers only: `import` / `export … from`, `import()`, `require()`, `require.resolve()`, `import("…")` types and `@import` tags in JSDoc (every block), `declare module`, `/// <reference types>`, and module mocks: `vi.mock()` and the other `vi` / `jest` module methods (`jest.setMock()`, `jest.requireActual()`, …), bun's `mock.module()`. Components: their `<script>` blocks and Astro's frontmatter. |
29
+ | `openapiTS(source, { transform })` calls | When `transform` is the only callback and returns plain `ts.factory` types (or the helper constants), the returns become type text and `irCallbacks: true` is added. The options may also be a `const` of the same file that only this call uses. Module constants and imports that only the old returns used are removed. Names are resolved by scope, so a local constant is never taken for a module one. |
30
+
31
+ Commands are read in `package.json` scripts, shell scripts (`.sh`, `.bash`, `.zsh`), husky hooks,
32
+ `Makefile`, `justfile`, `Dockerfile`, CI and other YAML files, Nx `project.json` targets,
33
+ `deno.json` tasks and pnpm `package.yaml` scripts. They are read word by word, the way the shell
34
+ splits them (quotes, `\` line continuations, comments, `&&`, `|`, `sh -c "…"`, and the commands
35
+ inside `if`, `while`, `for` and `{ … }`), so only the generator's own flags are renamed, and a
36
+ script name (`npm run openapi-typescript`) is never changed. A Dockerfile's exec form (`RUN ["npx",
37
+ "openapi-typescript", …]`, also after `RUN --mount=…`) is read word by word, and the command line of
38
+ `["sh", "-c", "…"]` as shell text. A Makefile variable that holds the generator (`OAT :=
39
+ openapi-typescript`, also for some targets only, and `GEN := $(OAT)`) is renamed where it is set,
40
+ and the flags after `$(OAT)` (or `$G` for a one-letter name) where it runs; so is an `env` variable
41
+ of a workflow and the flags after `$GEN` or `${{ env.GEN }}`, and a Dockerfile `ARG` or `ENV`
42
+ variable and the flags after `$GEN`. The flags change only when every definition of the variable
43
+ in the file sets it to the generator: a variable that another Dockerfile stage, a step `env` or a
44
+ later Makefile line sets to another program is reported with its old flags. A variable of old
45
+ flags that the generator gets (`$(FLAGS)` with `FLAGS := -it`) may serve other commands too, so it
46
+ is reported, not changed. YAML files are changed only in command
47
+ keys (`run`, `script`, `command`, `entrypoint`, …) and in the values of `env`, in block and flow
48
+ style, never in other values such as an OpenAPI `description`; a YAML file that names no old package
49
+ is not even parsed. A config that cannot be parsed and names an old package is reported with the
50
+ line and column, not changed. `Makefile`, `justfile` and `Dockerfile` are read only under the names
51
+ make, just and docker look for (also `makefile`, `GNUmakefile`, `Justfile`, `.justfile`,
52
+ `Containerfile` and `*.mk`), so `Dockerfile.dev` is not changed.
53
+
54
+ A range keeps its style: `^` and `>=` give `^1.0.0`, `~` gives `~1.0.0`, an exact version stays
55
+ exact, and a partial version keeps what it fixes (`7`, `7.x` and `0.x` give `^1.0.0`; `0.13` and
56
+ `0.13.x` give `~1.0.0`). A range of several comparators (`>=0.13 <0.18`, `^0.13 || ^0.17`) takes
57
+ the style of its first one. Anything else (`*`, `latest`, an upper bound only, a URL or a file) is
58
+ kept and reported.
59
+
60
+ Manifests, catalogs and import maps are edited in place: only the renamed keys and the new values
61
+ change, and comments, formatting, key order and line endings stay. A byte order mark is kept. An
62
+ entry whose new name is already in the same map is left and reported, and so is an entry the tool
63
+ does not edit (a YAML alias, anchor or block value). A catalog entry and the `catalog:` dependencies
64
+ on it keep one name: an entry stays while a dependency that was left or an override
65
+ (`"openapi-fetch": "catalog:"` under `overrides`, which are reported, not changed) still uses it,
66
+ and a dependency stays while its entry does, so the install never misses a catalog entry; both are
67
+ reported. Sources also get `npm:` specifiers renamed (`import x from "npm:openapi-fetch@^0.13"`).
31
68
 
32
69
  In a git repository the tool reads the files git lists: tracked files, and untracked files that
33
70
  `.gitignore` does not ignore, so ignored build output (`cjs/`, `esm/`, `types/`, …) stays out. A
@@ -38,12 +75,25 @@ repository around it ignores, it reads the whole tree of that folder. Either way
38
75
  `coverage` are skipped, and links are not followed. The log names the folders and how each one
39
76
  was read.
40
77
 
41
- The tool does not trust the folder it migrates. Git runs with `core.fsmonitor` turned off, so a
42
- nested repository's `.git/config` cannot make it run a command, and it does not open a bare
43
- repository that is not named explicitly. A path that git lists but that leads outside the folder
44
- (`../`, an absolute path, or a linked parent folder) is not read or written; the report lists it
45
- under "Skipped". A file is written as a new file that replaces the old one (same mode), so a hard
46
- link to a file elsewhere keeps its old text; the log notes it.
78
+ The tool does not trust the folder it migrates. Git is the `git` of an absolute folder on `PATH`
79
+ outside the project and outside every `node_modules` (as written and after links, in any case,
80
+ since macOS and Windows ignore case in folder names), so neither a `git` at the project root nor
81
+ one in a `node_modules/.bin` that `npx` puts on `PATH` runs (npx adds those of the project and of
82
+ every folder above it, such as a workspace root), and it runs with `core.fsmonitor` turned off and every transport refused
83
+ (`GIT_ALLOW_PROTOCOL` set to an empty list, which no `protocol.*` key of a repository's config can
84
+ undo), so a nested repository's `.git/config` cannot make it run a command, not even through a
85
+ partial clone that fetches a missing object. It does not open a bare repository that is not named
86
+ explicitly, and the folder whose `.git` git takes as the repository is the work tree, so a
87
+ `core.worktree` in the config cannot point the listing at another folder; `GIT_DIR` and the other
88
+ variables that name a repository are not passed on. A path that git lists but that leads outside the
89
+ folder (`../`, an absolute path, a linked parent folder or a link to a file elsewhere) is not read
90
+ or written; the report lists it under "Skipped". A file is written as a new file that replaces the
91
+ old one (same mode), so a hard link to a file elsewhere keeps its old text; the log notes it.
92
+ A file whose bytes are not UTF-8 (a Latin-1 source, for example) is not changed, because its
93
+ text cannot be written back without changing other characters; neither is a file that cannot be
94
+ read. The report lists both under "Skipped". Every file is read and migrated before the first one
95
+ is written. If a write fails, the writing stops, the command exits with `1`, and the report names
96
+ the files written before it and the ones that were not.
47
97
  The report and the log show a spec with credentials (`git+https://<token>@…`) as
48
98
  `git+https://***@…`; the file keeps it as written.
49
99
 
@@ -55,8 +105,23 @@ The report lists each of these with the file and line:
55
105
  `resolutions` / `pnpm` settings (in `package.json` or `pnpm-workspace.yaml`, patches included)
56
106
  that name an old package;
57
107
  - a renamed peer dependency: users of your package must switch too;
58
- - `npx openapi-typescript@<version>`: the old package is pinned, change it by hand;
108
+ - a pnpm `package.json5` that names an old package: the tool does not read JSON5, so rename the
109
+ packages and the command there by hand, or write it as `package.json` and run the tool again;
110
+ - `npx openapi-typescript@<version>`, and pinned old packages in install commands
111
+ (`npm i openapi-fetch@0.13`): change them by hand;
112
+ - a command that runs a file inside the old package
113
+ (`node node_modules/openapi-typescript/bin/cli.js`): run `openapi-typesafe` instead;
114
+ - strings in sources that run `openapi-typescript` (`execSync("npx openapi-typescript …")`, also
115
+ a template such as `` `npx openapi-typescript ${spec}` ``),
116
+ with the command they should become;
59
117
  - deep imports such as `openapi-fetch/dist/...`: check that the file exists in the new package;
118
+ - a module name built at run time right after an old package name
119
+ (``import(`openapi-fetch${suffix}`)``): the rest may go on with the name, so only you know what
120
+ to write;
121
+ - imports of `openapi-typesafe-helpers` that no `package.json` or Deno import map at or above the
122
+ file lists, also imports that an earlier run renamed: openapi-fetch and openapi-react-query
123
+ installed `openapi-typescript-helpers` with them, the openapi-typesafe packages do not. Add it to the dependencies, or import the types from
124
+ `openapi-typesafe-fetch/helpers`;
60
125
  - strings that equal an old package name outside a module specifier (an object key, a label, a
61
126
  bundler option such as `external: ["openapi-fetch"]`): they are kept, because only you know
62
127
  whether they mean the package. Comments are not changed or reported;
@@ -64,8 +129,9 @@ The report lists each of these with the file and line:
64
129
  dependency), so alias `openapi-fetch` to `openapi-typesafe-fetch` with `overrides` or
65
130
  `resolutions` (see
66
131
  [Libraries built on openapi-fetch](https://github.com/openapi-typesafe/openapi-typesafe/blob/main/docs/fetch/index.md#libraries-built-on-openapi-fetch));
67
- - `transform` callbacks it cannot rewrite, and `postTransform` / `transformProperty`: they keep
68
- working with a deprecation warning; see
132
+ - `transform` callbacks it cannot rewrite, and `postTransform` / `transformProperty`, also in
133
+ options that other code shares, and `openapiTS()` calls whose options it cannot see (a
134
+ parameter, a function call): they keep working with a deprecation warning; see
69
135
  [IR callbacks](https://github.com/openapi-typesafe/openapi-typesafe/blob/main/docs/node.md#ir-callbacks).
70
136
 
71
137
  Then install, regenerate your types and commit them once (the file header names openapi-typesafe
@@ -84,8 +150,9 @@ now, so `--check` fails until you do), and run your type check and tests.
84
150
  The default log folder is new for each run and only you can open it (mode 0700). A `--log` file
85
151
  that exists gets the new lines appended, and missing parent folders are created.
86
152
 
87
- Exit codes: `0` done, `1` the migration failed (the message and the log say why) or the log could
88
- not be created (nothing is changed then), `2` unknown option or argument.
153
+ Exit codes: `0` done, `1` the migration failed (the message and the log say why), a file could not
154
+ be written (the report names what was written), the project folder does not exist or is a file,
155
+ or the log could not be created (nothing is changed then), `2` unknown option or argument.
89
156
 
90
157
  ## Versioning
91
158