@prisma/orm-sqlite 8.0.0-rc.20-dev.9 → 8.0.0-rc.20-dev.10

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.
Files changed (25) hide show
  1. package/dist/runtime.mjs +1 -1
  2. package/dist/runtime.mjs.map +1 -1
  3. package/dist/{sqlite-static-CnyBsQfq-BR59alOC.mjs → sqlite-static-mr8PBZYf-C8YT9m5s.mjs} +3 -3
  4. package/dist/sqlite-static-mr8PBZYf-C8YT9m5s.mjs.map +1 -0
  5. package/dist/static.mjs +1 -1
  6. package/package.json +8 -8
  7. package/skills/prisma-8/SKILL.md +1 -1
  8. package/skills/prisma-8/references/upgrade-app.md +2 -2
  9. package/skills/prisma-8/references/upgrade-extension.md +2 -2
  10. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md +130 -94
  11. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/client-takes-contract-value/contract-from-json.ts +245 -30
  12. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/data-type-values/data-type-values.ts +8 -5
  13. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/mongo-field-storage-names/mongo-field-storage-names.ts +77 -23
  14. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/remove-nocheck/remove-nocheck.ts +1668 -19
  15. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/instructions.md +23 -12
  16. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/scripts/expand-type-aliases/expand-type-aliases.ts +50 -15
  17. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md +273 -87
  18. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/client-takes-contract-value/contract-from-json.ts +245 -30
  19. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/data-type-values/data-type-values.ts +1120 -0
  20. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/default-generators-to-on-create/rewrite-default-generators.mjs +86 -0
  21. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/mongo-field-storage-names/mongo-field-storage-names.ts +304 -0
  22. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/remove-nocheck/remove-nocheck.ts +1668 -19
  23. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/instructions.md +8 -6
  24. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/scripts/expand-type-aliases/expand-type-aliases.ts +50 -15
  25. package/dist/sqlite-static-CnyBsQfq-BR59alOC.mjs.map +0 -1
@@ -4,7 +4,7 @@ to: "8.0.0-rc.20"
4
4
  changes:
5
5
  - id: stored-contracts-expand-type-aliases
6
6
  summary: |
7
- A stored SQL contract whose columns name a type alias in `typeRef` no longer loads. Run `scripts/expand-type-aliases/expand-type-aliases.ts` from the project root, then re-emit the contract, then run `prisma db sign` against every database. The script writes each alias's parameters into the columns typed by it, in every stored contract, migration snapshots and the emitted `contract.json` included, and refreshes every hash and reference that changes.
7
+ A stored SQL contract whose columns name a type alias in `typeRef` no longer loads. Run `scripts/expand-type-aliases/expand-type-aliases.ts` from the project root, then re-emit the contract, then run `prisma db sign` against every database. Sign a database that has not applied every migration with `prisma db sign --contract <the last migration it applied>`, then run `prisma db migrate`. The script writes each alias's parameters into the columns typed by it, in every stored contract, migration snapshots and the emitted `contract.json` included, and refreshes every hash and reference that changes.
8
8
  detection:
9
9
  glob: "**/contract.json"
10
10
  matches:
@@ -30,11 +30,11 @@ changes:
30
30
  - '"@prisma/orm-extension-supabase"'
31
31
  - id: engine-pin-moves-to-0-9-0
32
32
  summary: |
33
- The toolchain now requires `@prisma/cli-engine@0.9.0` (up from 0.7.0). A project that depends on `@prisma/cli-engine` itself must move to `0.9.0`.
33
+ The toolchain now requires `@prisma/cli-engine@0.9.0` (up from 0.7.0). A project whose Prisma config, tests or tooling load `@prisma/cli-engine` alongside the Prisma toolchain must move it to `0.9.0`, in `package.json` or in a `pnpm-workspace.yaml` catalog. A separate CLI that the project builds on the engine is not affected. The detection matches an engine version below 0.9 in either file.
34
34
  detection:
35
- glob: "**/package.json"
35
+ glob: "**/{package.json,pnpm-workspace.yaml}"
36
36
  matches:
37
- - '"@prisma/cli-engine":\s*"[^"]*(?<![\d.])0\.[0-8](?!\d)'
37
+ - '[\x27"]@prisma/cli-engine[\x27"]\s*:\s*[\x27"]?[^\x27"\n#]*(?<![\d.])0\.[0-8](?!\d)'
38
38
  - id: piped-output-needs-json
39
39
  summary: |
40
40
  A piped Prisma ORM command no longer prints JSON. Without `--json`, stdout receives the command's plain data lines, such as one tab-separated line per migration. A script that reads JSON from `prisma contract …`, `prisma db …`, `prisma migration …` or `prisma orm init` must pass `--json`.
@@ -75,14 +75,14 @@ changes:
75
75
  detection:
76
76
  glob: "**/*.prisma"
77
77
  matches:
78
- - 'enum\s+\w+\s*\{(?=[^}]*@@type\(\s*"mongo/(?:double|int64|int64Number|decimal128|date|binary)@1"\s*\))[^}]*\n\s*\w+\s*=\s*"'
78
+ - 'enum\s+\w+\s*\{(?=[^{}]*@@type\(\s*"mongo/(?:double|int64|int64Number|decimal128|date|binary)@1"\s*\))[^{}]*\n\s*\w+\s*=\s*"'
79
79
  - id: mongo-integer-enum-members-with-a-fraction
80
80
  summary: |
81
81
  A MongoDB PSL number with a fraction, such as `1.0`, is now a Decimal128 value, and no integer type casts from Decimal128, so an Int32 or Int64 member written with a fraction is refused with `PSL_VALUE_TYPE_INCOMPATIBLE` (`Expected a number that mongo/int32 can hold; got mongo/decimal128`). Write the whole number, `One = 1`. The detection matches an Int32 or Int64 enum with a member written with a fraction.
82
82
  detection:
83
83
  glob: "**/*.prisma"
84
84
  matches:
85
- - 'enum\s+\w+\s*\{(?=[^}]*@@type\(\s*"mongo/(?:int32|int64|int64Number)@1"\s*\))[^}]*\n\s*\w+\s*=\s*-?\d+\.\d'
85
+ - 'enum\s+\w+\s*\{(?=[^{}]*@@type\(\s*"mongo/(?:int32|int64|int64Number)@1"\s*\))[^{}]*\n\s*\w+\s*=\s*-?\d+\.\d'
86
86
  - id: discriminator-optional-or-list
87
87
  summary: |
88
88
  A `@@discriminator` field must be required and hold one value, in SQL and MongoDB schemas alike. An optional field is refused with `Discriminator field "<field>" on model "<Model>" must be required, but it is optional. Remove the "?"`, and a list with `... must hold one value, but it is a list. Remove the "[]"`, both `PSL_INVALID_ATTRIBUTE_ARGUMENT`. Make the field required and single: a document or row without the value has no variant. The detection matches a model whose `@@discriminator` names a field declared with `?` or `[]`.
@@ -105,14 +105,14 @@ changes:
105
105
  matches:
106
106
  - 'was rejected by codec \\?"mongo/'
107
107
  - 'must be of type String'
108
- - '(?=[\s\S]*@@base\()[\s\S]*PSL_INVALID_DEFAULT_LITERAL'
108
+ - '(?<![\s\S])(?=[\s\S]*@@base\()[\s\S]*PSL_INVALID_DEFAULT_LITERAL'
109
109
  - id: decimal128-spelling
110
110
  summary: |
111
111
  `mongo/decimal128` stores its values as MongoDB writes them: without leading zeros, keeping negative zero, and only a value a Decimal128 holds exactly. A `contract.json` that stores a Decimal128 value with leading zeros, such as `"007.5"`, is refused when it is loaded with `RUNTIME.DECODE_FAILED`, which names the value to store; emit the contract again. A TypeScript enum member such as `member('Half', '007.5')` is stored as `7.5`, so its contract gets a new hash on the next emit. A value with more than 34 significant digits, counting zeros after the decimal point, such as `1.000000000000000000000000000000000000`, is refused in PSL, TypeScript and `contract.json` instead of being rounded; write a value with at most 34 significant digits. The detection matches a Decimal128 value with leading zeros or more than 34 digits.
112
112
  detection:
113
113
  glob: "**/*.{json,ts,mts,cts,tsx,prisma}"
114
114
  matches:
115
- - 'mongo/decimal128@1[\s\S]*?(?:[=,(:]\s*["\x27`]?-?0\d|[=,(:]\s*["\x27`]?-?\d[\d.]{35,})'
115
+ - '(?<![\s\S])(?=([\s\S]*?mongo/decimal128@1))\1[\s\S]*?(?:[=,(:]\s*["\x27`]?-?0\d(?![0-9a-f]{62}["\x27`])|[=,(:]\s*["\x27`]?-?\d[\d.]{35,})'
116
116
  - id: sql-builder-insert-required-columns
117
117
  summary: |
118
118
  A SQL builder insert, `db.sql.<namespace>.<table>.insert(rows)`, must now include every column that is not nullable and has no default. Leaving one out is a type error that names the column, and so is a value typed `T | undefined` for such a column. Add a real value, narrowed to `T`.
@@ -169,11 +169,11 @@ changes:
169
169
 
170
170
  Two changes in this release change storage hashes: the type-alias change (`stored-contracts-expand-type-aliases`) and the re-emitted Supabase contract (`supabase-contract-expanded`). Do the steps in this order, and skip a step that does not apply to the project:
171
171
 
172
- 1. Commit your work, so the script's changes can be reviewed and undone with git. Then upgrade the Prisma packages. If the project depends on `@prisma/cli-engine` itself, move it to `0.9.0` (`engine-pin-moves-to-0-9-0`).
172
+ 1. Commit your work, so the script's changes can be reviewed and undone with git. Then upgrade the Prisma packages. If the project's Prisma config, tests or tooling load `@prisma/cli-engine` alongside the Prisma toolchain, move it to `0.9.0` (`engine-pin-moves-to-0-9-0`).
173
173
  2. Rewrite the stored contracts, from the project root, with `scripts/expand-type-aliases/expand-type-aliases.ts` (`stored-contracts-expand-type-aliases`). It leaves a project without type aliases unchanged and says so.
174
174
  3. Change the contract source as the entries below say: a TypeScript contract drops its `types` key (`ts-types-key-removed`), and a MongoDB schema rewrites the enum members and discriminators the MongoDB entries name.
175
175
  4. Run `prisma contract emit` (this also covers `contract-artifacts-restamp`).
176
- 5. Run `prisma db sign` against every database when step 2 changed a storage hash, or when the project uses the Supabase extension.
176
+ 5. Run `prisma db sign` against every database when step 2 changed a storage hash, or when the project uses the Supabase extension. A database that has not applied every migration needs `--contract`, as `stored-contracts-expand-type-aliases` describes.
177
177
  6. For each migration that is not applied yet and that `check-expectation` or `check-expectation-raw-sql` matches, run its `migration.ts` again. This is optional.
178
178
  7. Change the application code and scripts: add `--json` where a script parses a command's output (`piped-output-needs-json`), rename `accessWidening` (`access-changes-rename`), read `meta.schemaIssues` (`schema-verification-failed-schema-issues`), complete SQL builder inserts and ORM creates (`sql-builder-insert-required-columns`, `orm-create-on-update-only-field`), and move Supabase code to `forRole` (`supabase-for-role-replaces-with-role-methods` and the entries after it).
179
179
 
@@ -193,7 +193,7 @@ Migration snapshots, the emitted `contract.json` and any other stored contract w
193
193
  node <guide>/scripts/expand-type-aliases/expand-type-aliases.ts
194
194
  ```
195
195
 
196
- `<guide>` is the directory that holds this guide. Node 24 or later runs the TypeScript script directly; it needs no `tsx`. The script reads and writes files only and needs no database. It rewrites every SQL contract under the root, skipping `node_modules`, `.git`, `dist` and `build`. That includes a test fixture of an old contract: if you keep one on purpose, restore it with git afterwards.
196
+ `<guide>` is the directory that holds this guide. Node 24 or later runs the TypeScript script directly; it needs no `tsx`. The script reads and writes files only and needs no database. It rewrites every SQL contract under the root, skipping `node_modules`, `dist`, `build` and every directory whose name starts with `.`, such as `.git` and the worktrees under `.claude/worktrees/`. That includes a test fixture of an old contract: if you keep one on purpose, restore it with git afterwards.
197
197
 
198
198
  In each contract it replaces every column's `typeRef` with the parameters of the `storage.types` entry it names, and removes each entry a column named. In a contract of your app's own contract space it also removes every entry that no column names. Your app's contract never needs such an entry: it is an alias that the source declares but no field uses, which a re-emit drops as well, or, in a TypeScript source, a `codec-instance` entry that no field uses, which `ts-types-key-removed` tells you to delete. Only an extension's contract space registers a database type. So in a contract of an extension's contract space, such as the copy of pgvector's space in `migrations/snapshots/`, the script keeps an entry that no column names, such as `vector`, and lists it. It makes the same change in the `contract.d.ts` next to the contract. The script tells the spaces apart by the migrations directory: a snapshot that a migration or ref under `migrations/app/` names is your app's, and one that a migration or ref under any other `migrations/<space>/` names is an extension's. A snapshot that no migration or ref names may be either, so the script keeps its unused entries and lists them. The emitted `contract.json` is your app's.
199
199
 
@@ -219,6 +219,15 @@ Each database's marker still holds the old storage hash, so `prisma db verify` a
219
219
  prisma db sign --db "$DATABASE_URL"
220
220
  ```
221
221
 
222
+ A plain `prisma db sign` signs the database against the emitted contract, so it signs only a database that has applied every migration. A database that has not, such as production while the latest migrations wait for review, is refused: `db sign` says its schema does not satisfy the contract, and `prisma db migrate` stops with `MIGRATION.MARKER_MISMATCH`, because the marker holds an old hash that no migration names any more. Sign such a database with the contract of the last migration it applied, then migrate it:
223
+
224
+ ```sh
225
+ prisma db sign --contract <the last migration it applied> --db "$DATABASE_URL"
226
+ prisma db migrate --db "$DATABASE_URL"
227
+ ```
228
+
229
+ `--contract` takes the migration's directory name, such as `20260917T0818_add_post_expires_at`, or the new hash that migration goes to. To find it, run `prisma migration status` against the database. It prints the start of the old hash the marker holds: `Database marker <hash> is not in the on-disk migration graph`. The error of `prisma db migrate` prints the whole hash: `DB marker is <hash>`. Find the line of the script's `<old> -> <new>` list whose old hash is that one. The new hash on that line is the one to sign with, and the migration that goes to it is the last one the database applied.
230
+
222
231
  The script has already written the new hash into each ref, so when `db sign` advances a ref, such as `migrations/app/refs/db.json`, it prints the new hash twice: `Advanced ref "db" → <new hash> (was <new hash>)`. This is expected, and the database is signed.
223
232
 
224
233
  The script also gives each rewritten migration a new hash, and the database's migration history keeps the old ones. After the upgrade, `prisma migration status` therefore no longer marks the migrations applied before it as applied, although it still reports the database as up to date. `prisma db migrate` runs none of them again, and `prisma db verify` passes.
@@ -292,7 +301,9 @@ A contract that composes the Supabase space references it by id, so this change
292
301
 
293
302
  ### `engine-pin-moves-to-0-9-0`
294
303
 
295
- For every `package.json` matched by `detection`, change the `@prisma/cli-engine` version (`0.7.0`, `^0.7.0` or any other 0.x below 0.9) to `0.9.0` and reinstall. Projects assembled by the `prisma` CLI resolve the engine automatically.
304
+ This applies to a project whose Prisma config, tests or tooling load `@prisma/cli-engine` alongside the Prisma toolchain. A separate CLI that the project builds on the engine runs its own engine, so it does not have to move with this upgrade.
305
+
306
+ For every `package.json` or `pnpm-workspace.yaml` catalog matched by `detection`, change the `@prisma/cli-engine` version (`0.7.0`, `^0.7.0` or any other 0.x below 0.9) to `0.9.0` and reinstall. Projects assembled by the `prisma` CLI resolve the engine automatically.
296
307
 
297
308
  ### `piped-output-needs-json`
298
309
 
@@ -31,10 +31,11 @@ interface JsonRecord {
31
31
  [key: string]: Json;
32
32
  }
33
33
 
34
- const SKIPPED_DIRECTORIES = new Set(['node_modules', '.git', 'dist', 'build']);
34
+ const SKIPPED_DIRECTORIES = new Set(['node_modules', 'dist', 'build']);
35
35
  const APP_SPACE_ID = 'app';
36
36
  const HASH = /^[0-9a-f]{64}$/;
37
37
  const TEMPORARY_SUFFIX = '.expand-type-aliases-tmp';
38
+ const BYTE_ORDER_MARK = '\uFEFF';
38
39
 
39
40
  function isRecord(value: unknown): value is JsonRecord {
40
41
  if (typeof value !== 'object' || value === null || Array.isArray(value)) return false;
@@ -42,9 +43,13 @@ function isRecord(value: unknown): value is JsonRecord {
42
43
  return prototype === Object.prototype || prototype === null;
43
44
  }
44
45
 
46
+ function withoutByteOrderMark(text: string): string {
47
+ return text.startsWith(BYTE_ORDER_MARK) ? text.slice(BYTE_ORDER_MARK.length) : text;
48
+ }
49
+
45
50
  function parseJson(text: string): Json | undefined {
46
51
  try {
47
- const value: Json = JSON.parse(text);
52
+ const value: Json = JSON.parse(withoutByteOrderMark(text));
48
53
  return value;
49
54
  } catch {
50
55
  return undefined;
@@ -325,7 +330,7 @@ function listFiles(root: string): ProjectFiles {
325
330
  continue;
326
331
  }
327
332
  if (entry.isDirectory() || (entry.isSymbolicLink() && isDirectory(path))) {
328
- if (!SKIPPED_DIRECTORIES.has(entry.name)) visit(path);
333
+ if (!SKIPPED_DIRECTORIES.has(entry.name) && !entry.name.startsWith('.')) visit(path);
329
334
  continue;
330
335
  }
331
336
  if (!isFileEntry(dir, entry)) continue;
@@ -518,12 +523,20 @@ function withStorageHash(contract: JsonRecord, hash: string): JsonRecord {
518
523
  return { ...contract, storage: { ...storage, storageHash: hash } };
519
524
  }
520
525
 
521
- /** The contract written the way the file held it: a snapshot's canonical line, or indented JSON. */
526
+ function lineEndingOf(text: string): string {
527
+ return text.includes('\r\n') ? '\r\n' : '\n';
528
+ }
529
+
530
+ /** The contract written the way the file held it: a snapshot's canonical line, or indented JSON, with the file's byte order mark and line ending. */
522
531
  function writtenForm(contract: JsonRecord, original: JsonRecord, text: string): string {
523
- const newline = text.endsWith('\n') ? '\n' : '';
524
- if (text === `${canonicalizeJson(original)}${newline}`)
525
- return `${canonicalizeJson(contract)}${newline}`;
526
- return `${JSON.stringify(contract, null, 2)}${newline}`;
532
+ const mark = text.startsWith(BYTE_ORDER_MARK) ? BYTE_ORDER_MARK : '';
533
+ const body = withoutByteOrderMark(text);
534
+ const lineEnding = lineEndingOf(body);
535
+ const finalNewline = body.endsWith('\n') ? lineEnding : '';
536
+ if (body === `${canonicalizeJson(original)}${finalNewline}`)
537
+ return `${mark}${canonicalizeJson(contract)}${finalNewline}`;
538
+ const indented = JSON.stringify(contract, null, 2).replaceAll('\n', lineEnding);
539
+ return `${mark}${indented}${finalNewline}`;
527
540
  }
528
541
 
529
542
  interface Block {
@@ -621,7 +634,7 @@ function lineStart(text: string, position: number): number {
621
634
 
622
635
  /** The end of the member a block closes: past its `;` and the line break after it. */
623
636
  function memberEnd(text: string, block: Block): number {
624
- const rest = /^\s*;?[ \t]*\n?/.exec(text.slice(block.end + 1));
637
+ const rest = /^\s*;?[ \t]*(?:\r?\n)?/.exec(text.slice(block.end + 1));
625
638
  return block.end + 1 + (rest?.[0].length ?? 0);
626
639
  }
627
640
 
@@ -657,7 +670,7 @@ function topLevelMembers(literal: string): string[] {
657
670
  }
658
671
 
659
672
  /** The `readonly typeParams` member, laid out as the emitter's formatter lays it out at `indent`. */
660
- function typeParamsMember(literal: string, indent: string): string {
673
+ function typeParamsMember(literal: string, indent: string, lineEnding: string): string {
661
674
  const lines = literal.split('\n');
662
675
  const head = `${indent}readonly typeParams: `;
663
676
  if (lines.length > 1) {
@@ -670,7 +683,7 @@ function typeParamsMember(literal: string, indent: string): string {
670
683
  const single = `${head}${literal};`;
671
684
  if (single.length <= DTS_LINE_WIDTH) return single;
672
685
  const members = topLevelMembers(literal).map((member) => `${indent} ${member};`);
673
- return `${head}{\n${members.join('\n')}\n${indent}};`;
686
+ return `${head}{${lineEnding}${members.join(lineEnding)}${lineEnding}${indent}};`;
674
687
  }
675
688
 
676
689
  /** The text of `typeParams` in an entry block of `readonly types`, as the emitter wrote it. */
@@ -703,6 +716,7 @@ function rewriteDts(
703
716
  removedEntries: ReadonlySet<string>,
704
717
  hashes: ReadonlyMap<string, string>,
705
718
  ): string {
719
+ const lineEnding = lineEndingOf(text);
706
720
  const blocks = scanBlocks(text);
707
721
  const typesBlock = storageTypesBlock(blocks);
708
722
  const entryBlocks = typesBlock === undefined ? [] : childBlocks(blocks, typesBlock);
@@ -726,12 +740,13 @@ function rewriteDts(
726
740
  const literal = literals.get(alias);
727
741
  if (literal === undefined) {
728
742
  const end = match.index + match[0].length;
729
- edits.push({ start, end: text[end] === '\n' ? end + 1 : end, text: '' });
743
+ const lineBreak = /^\r?\n/.exec(text.slice(end))?.[0] ?? '';
744
+ edits.push({ start, end: end + lineBreak.length, text: '' });
730
745
  } else {
731
746
  edits.push({
732
747
  start,
733
748
  end: match.index + match[0].length,
734
- text: typeParamsMember(literal, indentOf(text, match.index)),
749
+ text: typeParamsMember(literal, indentOf(text, match.index), lineEnding),
735
750
  });
736
751
  }
737
752
  }
@@ -966,7 +981,27 @@ function mergedSnapshots(
966
981
 
967
982
  const JSON_FILES_THAT_MUST_PARSE = new Set(['contract.json', 'migration.json']);
968
983
 
969
- function main(root: string): number {
984
+ function parseRoot(args: readonly string[]): { readonly root: string; readonly errors: string[] } {
985
+ const errors = args.filter((arg) => arg.startsWith('-')).map((arg) => `${arg}: unknown option`);
986
+ const positional = args.filter((arg) => !arg.startsWith('-'));
987
+ if (positional.length > 1) errors.push(`expected one project root, got ${positional.length}`);
988
+ const root = resolve(positional[0] ?? process.cwd());
989
+ if (errors.length === 0 && !isDirectory(root)) errors.push(`${root}: not a directory`);
990
+ if (errors.length > 0) errors.push('Usage: node expand-type-aliases.ts [project-root]');
991
+ return { root, errors };
992
+ }
993
+
994
+ function main({
995
+ root,
996
+ errors,
997
+ }: {
998
+ readonly root: string;
999
+ readonly errors: readonly string[];
1000
+ }): number {
1001
+ if (errors.length > 0) {
1002
+ process.stderr.write(`${errors.join('\n')}\n`);
1003
+ return 1;
1004
+ }
970
1005
  const display = (path: string): string => relative(root, path).split(sep).join('/');
971
1006
  const files = listFiles(root);
972
1007
  const references = hashReferences(files);
@@ -1168,4 +1203,4 @@ function main(root: string): number {
1168
1203
  return 0;
1169
1204
  }
1170
1205
 
1171
- process.exitCode = main(resolve(process.argv[2] ?? '.'));
1206
+ process.exitCode = main(parseRoot(process.argv.slice(2)));