@prisma/orm-sqlite 8.0.0-rc.20-dev.8 → 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.
- package/dist/runtime.mjs +1 -1
- package/dist/runtime.mjs.map +1 -1
- package/dist/{sqlite-static-DORjKoZ5-ChzQDdU5.mjs → sqlite-static-mr8PBZYf-C8YT9m5s.mjs} +3 -3
- package/dist/sqlite-static-mr8PBZYf-C8YT9m5s.mjs.map +1 -0
- package/dist/static.mjs +1 -1
- package/package.json +8 -8
- package/skills/prisma-8/SKILL.md +1 -1
- package/skills/prisma-8/references/migrations.md +2 -1
- package/skills/prisma-8/references/upgrade-app.md +2 -2
- package/skills/prisma-8/references/upgrade-extension.md +2 -2
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md +130 -94
- 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
- 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
- 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
- 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
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/instructions.md +23 -12
- 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
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md +273 -87
- 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
- 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
- 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
- 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
- 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
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/instructions.md +8 -6
- 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
- package/dist/sqlite-static-DORjKoZ5-ChzQDdU5.mjs.map +0 -1
|
@@ -4,17 +4,19 @@
|
|
|
4
4
|
// export const contract = contractFromJson<Contract>(contractJson);
|
|
5
5
|
// postgres({ contract, url })
|
|
6
6
|
//
|
|
7
|
-
// Usage: node contract-from-json.ts [project
|
|
7
|
+
// Usage: node contract-from-json.ts [project-root] [--typescript <path to the typescript package>]
|
|
8
8
|
//
|
|
9
9
|
// The script reads source files with the TypeScript compiler, which it loads from the project.
|
|
10
10
|
// It rewrites each source file it can move, and prints it. In a module with a default export, such
|
|
11
11
|
// as a Worker entry, it declares `contract` without `export` and says so. It prints to stderr, with the reason,
|
|
12
12
|
// each file that passes `contractJson` to a client but that it did not move: a test file, a file
|
|
13
|
-
// that already has
|
|
14
|
-
// a
|
|
15
|
-
//
|
|
13
|
+
// that already has another binding named `contract`, a file whose clients use different contracts,
|
|
14
|
+
// a file whose `contractJson` value is not readable at the top of the file, or a call it cannot
|
|
15
|
+
// read. A `contract` destructured from the moved call is dropped from the destructuring. It exits 1 when it printed such a file, and changes nothing and exits 1
|
|
16
|
+
// when TypeScript is not installed or an argument is wrong. It skips node_modules, dist, build and every directory whose
|
|
17
|
+
// name starts with a dot, such as .git, .agents or .claude, and links that lead nowhere.
|
|
16
18
|
|
|
17
|
-
import { readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
19
|
+
import { readdirSync, readFileSync, realpathSync, statSync, writeFileSync } from 'node:fs';
|
|
18
20
|
import { createRequire } from 'node:module';
|
|
19
21
|
import { join, relative, resolve } from 'node:path';
|
|
20
22
|
import type * as TS from 'typescript';
|
|
@@ -22,13 +24,13 @@ import type * as TS from 'typescript';
|
|
|
22
24
|
const SOURCE_FILE = /\.(?:ts|tsx|mts|cts)$/;
|
|
23
25
|
const TEST_FILE = /\.(?:test|spec)(?:-d)?\.[cm]?tsx?$/;
|
|
24
26
|
const TEST_DIRECTORIES = new Set(['test', 'tests', '__tests__']);
|
|
25
|
-
const SKIPPED_DIRECTORIES = new Set(['node_modules', 'dist', 'build'
|
|
27
|
+
const SKIPPED_DIRECTORIES = new Set(['node_modules', 'dist', 'build']);
|
|
26
28
|
const FACADE_ENTRY =
|
|
27
29
|
/^@prisma\/orm-(postgres|sqlite|mongo)\/(?:runtime|serverless|static|query-builder)$/;
|
|
28
30
|
const SUPABASE_ENTRY = '@prisma/orm-extension-supabase/runtime';
|
|
29
31
|
const FACTORY_EXPORTS = new Set(['default', 'supabase', 'mongoQuery']);
|
|
30
32
|
const DETECTION =
|
|
31
|
-
/(?<![\w$.])(?:postgres|postgresServerless|sqlite|supabase|mongo|postgresStatic|sqliteStatic|mongoStatic|mongoQuery)(?:<[
|
|
33
|
+
/(?<![\w$.])(?:postgres|postgresServerless|sqlite|supabase|mongo|postgresStatic|sqliteStatic|mongoStatic|mongoQuery)(?:<[^<>()]*(?:<[^<>()]*>[^<>()]*)*>)?\(\s*\{(?:(?:[^{}]|\{[^{}]*\})*?,)?\s*contractJson\s*[,}:]/;
|
|
32
34
|
|
|
33
35
|
interface Edit {
|
|
34
36
|
readonly start: number;
|
|
@@ -37,6 +39,7 @@ interface Edit {
|
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
interface MovedCall {
|
|
42
|
+
readonly node: TS.CallExpression;
|
|
40
43
|
readonly edits: readonly Edit[];
|
|
41
44
|
readonly typeArguments: string;
|
|
42
45
|
readonly json: string;
|
|
@@ -97,7 +100,7 @@ function topLevelNames(ts: typeof TS, sourceFile: TS.SourceFile) {
|
|
|
97
100
|
else for (const element of bindings?.elements ?? []) imported.add(element.name.text);
|
|
98
101
|
} else if (ts.isVariableStatement(statement)) {
|
|
99
102
|
for (const declaration of statement.declarationList.declarations) {
|
|
100
|
-
|
|
103
|
+
for (const name of bindingNames(ts, declaration.name)) declared.add(name);
|
|
101
104
|
}
|
|
102
105
|
} else if (
|
|
103
106
|
(ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) &&
|
|
@@ -109,10 +112,141 @@ function topLevelNames(ts: typeof TS, sourceFile: TS.SourceFile) {
|
|
|
109
112
|
return { imported, declared };
|
|
110
113
|
}
|
|
111
114
|
|
|
115
|
+
function bindingIdentifiers(ts: typeof TS, name: TS.BindingName): TS.Identifier[] {
|
|
116
|
+
if (ts.isIdentifier(name)) return [name];
|
|
117
|
+
return name.elements.flatMap((element) =>
|
|
118
|
+
ts.isOmittedExpression(element) ? [] : bindingIdentifiers(ts, element.name),
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function bindingNames(ts: typeof TS, name: TS.BindingName): string[] {
|
|
123
|
+
return bindingIdentifiers(ts, name).map((identifier) => identifier.text);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function bindingsOf(ts: typeof TS, root: TS.Node, wanted: string): TS.Node[] {
|
|
127
|
+
const found: TS.Node[] = [];
|
|
128
|
+
const visit = (node: TS.Node): void => {
|
|
129
|
+
const binding = ownBindingOf(ts, node, wanted);
|
|
130
|
+
if (binding !== undefined) found.push(binding);
|
|
131
|
+
ts.forEachChild(node, visit);
|
|
132
|
+
};
|
|
133
|
+
visit(root);
|
|
134
|
+
return found;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function ownBindingOf(ts: typeof TS, node: TS.Node, wanted: string): TS.Node | undefined {
|
|
138
|
+
if (ts.isVariableDeclaration(node) || ts.isParameter(node)) {
|
|
139
|
+
return bindingIdentifiers(ts, node.name).find((name) => name.text === wanted);
|
|
140
|
+
}
|
|
141
|
+
if (
|
|
142
|
+
(ts.isFunctionDeclaration(node) ||
|
|
143
|
+
ts.isFunctionExpression(node) ||
|
|
144
|
+
ts.isClassDeclaration(node) ||
|
|
145
|
+
ts.isClassExpression(node) ||
|
|
146
|
+
ts.isEnumDeclaration(node) ||
|
|
147
|
+
ts.isModuleDeclaration(node) ||
|
|
148
|
+
ts.isImportEqualsDeclaration(node) ||
|
|
149
|
+
ts.isExportSpecifier(node) ||
|
|
150
|
+
ts.isNamespaceExport(node) ||
|
|
151
|
+
ts.isImportSpecifier(node) ||
|
|
152
|
+
ts.isNamespaceImport(node) ||
|
|
153
|
+
ts.isImportClause(node)) &&
|
|
154
|
+
node.name !== undefined &&
|
|
155
|
+
ts.isIdentifier(node.name) &&
|
|
156
|
+
node.name.text === wanted
|
|
157
|
+
) {
|
|
158
|
+
return node.name;
|
|
159
|
+
}
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Whether `identifier` names a variable the file declares at its top level. */
|
|
164
|
+
function isTopLevelVariable(ts: typeof TS, identifier: TS.Node): boolean {
|
|
165
|
+
let node = identifier.parent;
|
|
166
|
+
while (
|
|
167
|
+
ts.isBindingElement(node) ||
|
|
168
|
+
ts.isObjectBindingPattern(node) ||
|
|
169
|
+
ts.isArrayBindingPattern(node)
|
|
170
|
+
)
|
|
171
|
+
node = node.parent;
|
|
172
|
+
return (
|
|
173
|
+
ts.isVariableDeclaration(node) &&
|
|
174
|
+
ts.isVariableDeclarationList(node.parent) &&
|
|
175
|
+
ts.isVariableStatement(node.parent.parent) &&
|
|
176
|
+
ts.isSourceFile(node.parent.parent.parent)
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function topLevelStatementOf(ts: typeof TS, node: TS.Node): TS.Node | undefined {
|
|
181
|
+
let current = node;
|
|
182
|
+
while (current.parent !== undefined && !ts.isSourceFile(current.parent)) current = current.parent;
|
|
183
|
+
return current.parent === undefined ? undefined : current;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** The edit that drops `contract` from `const { ..., contract } = client(...)`, whose value the moved declaration now holds. */
|
|
187
|
+
function destructuredContractEdit(
|
|
188
|
+
ts: typeof TS,
|
|
189
|
+
sourceFile: TS.SourceFile,
|
|
190
|
+
call: TS.CallExpression,
|
|
191
|
+
exported: boolean,
|
|
192
|
+
): { readonly binding: TS.Node; readonly edit: Edit } | undefined {
|
|
193
|
+
const declaration = call.parent;
|
|
194
|
+
if (!ts.isVariableDeclaration(declaration) || declaration.initializer !== call) return undefined;
|
|
195
|
+
const pattern = declaration.name;
|
|
196
|
+
if (!ts.isObjectBindingPattern(pattern)) return undefined;
|
|
197
|
+
if (pattern.elements.some((element) => element.dotDotDotToken !== undefined)) return undefined;
|
|
198
|
+
const index = pattern.elements.findIndex(
|
|
199
|
+
(element) =>
|
|
200
|
+
element.propertyName === undefined &&
|
|
201
|
+
element.initializer === undefined &&
|
|
202
|
+
ts.isIdentifier(element.name) &&
|
|
203
|
+
element.name.text === 'contract',
|
|
204
|
+
);
|
|
205
|
+
const element = pattern.elements[index];
|
|
206
|
+
if (element === undefined) return undefined;
|
|
207
|
+
const statement = declaration.parent.parent;
|
|
208
|
+
const isExported =
|
|
209
|
+
ts.isVariableStatement(statement) &&
|
|
210
|
+
(ts.getModifiers(statement)?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) ?? false);
|
|
211
|
+
if (isExported && !exported) return undefined;
|
|
212
|
+
if (pattern.elements.length === 1) {
|
|
213
|
+
if (
|
|
214
|
+
!ts.isVariableStatement(statement) ||
|
|
215
|
+
isExported ||
|
|
216
|
+
statement.declarationList.declarations.length !== 1
|
|
217
|
+
)
|
|
218
|
+
return undefined;
|
|
219
|
+
return {
|
|
220
|
+
binding: element.name,
|
|
221
|
+
edit: { start: statement.getStart(sourceFile), end: call.getStart(sourceFile), text: '' },
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
const next = pattern.elements[index + 1];
|
|
225
|
+
const previous = pattern.elements[index - 1];
|
|
226
|
+
const edit =
|
|
227
|
+
next !== undefined
|
|
228
|
+
? { start: element.getStart(sourceFile), end: next.getStart(sourceFile), text: '' }
|
|
229
|
+
: { start: previous?.end ?? element.getStart(sourceFile), end: element.end, text: '' };
|
|
230
|
+
return { binding: element.name, edit };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function isReference(ts: typeof TS, identifier: TS.Identifier): boolean {
|
|
234
|
+
const parent = identifier.parent;
|
|
235
|
+
return !(
|
|
236
|
+
(ts.isPropertyAccessExpression(parent) && parent.name === identifier) ||
|
|
237
|
+
(ts.isQualifiedName(parent) && parent.right === identifier) ||
|
|
238
|
+
((ts.isPropertyAssignment(parent) ||
|
|
239
|
+
ts.isMethodDeclaration(parent) ||
|
|
240
|
+
ts.isGetAccessorDeclaration(parent) ||
|
|
241
|
+
ts.isSetAccessorDeclaration(parent)) &&
|
|
242
|
+
parent.name === identifier)
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
112
246
|
function identifiersIn(ts: typeof TS, node: TS.Node): string[] {
|
|
113
247
|
const names: string[] = [];
|
|
114
248
|
const visit = (child: TS.Node): void => {
|
|
115
|
-
if (ts.isIdentifier(child)) names.push(child.text);
|
|
249
|
+
if (ts.isIdentifier(child) && isReference(ts, child)) names.push(child.text);
|
|
116
250
|
ts.forEachChild(child, visit);
|
|
117
251
|
};
|
|
118
252
|
visit(node);
|
|
@@ -156,6 +290,7 @@ function movedCalls(
|
|
|
156
290
|
});
|
|
157
291
|
}
|
|
158
292
|
calls.push({
|
|
293
|
+
node,
|
|
159
294
|
edits,
|
|
160
295
|
typeArguments:
|
|
161
296
|
typeArguments === undefined
|
|
@@ -249,11 +384,32 @@ export function moveFile(ts: typeof TS, fileName: string, source: string): Outco
|
|
|
249
384
|
};
|
|
250
385
|
}
|
|
251
386
|
const names = topLevelNames(ts, sourceFile);
|
|
252
|
-
|
|
387
|
+
const topLevelStatement = topLevelStatementOf(ts, first.node);
|
|
388
|
+
const inner = first.jsonNames.find(
|
|
389
|
+
(name) =>
|
|
390
|
+
topLevelStatement !== undefined &&
|
|
391
|
+
bindingsOf(ts, topLevelStatement, name).some((found) => !isTopLevelVariable(ts, found)),
|
|
392
|
+
);
|
|
393
|
+
if (inner !== undefined) {
|
|
394
|
+
return {
|
|
395
|
+
kind: 'refused',
|
|
396
|
+
reason: `its contractJson value uses ${inner}, which is a parameter or local binding where the client is created, not a value the top of the file can read; pass contract: contractFromJson${first.typeArguments}(${first.json}) to the call instead of contractJson, and import contractFromJson from ${first.staticEntry}`,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
const exported = !hasDefaultExport(ts, sourceFile);
|
|
400
|
+
const destructured = calls
|
|
401
|
+
.map((call) => destructuredContractEdit(ts, sourceFile, call.node, exported))
|
|
402
|
+
.filter((found) => found !== undefined);
|
|
403
|
+
const binding = bindingsOf(ts, sourceFile, 'contract').find(
|
|
404
|
+
(found) => !destructured.some((entry) => entry.binding === found),
|
|
405
|
+
);
|
|
406
|
+
if (binding !== undefined) {
|
|
407
|
+
const line = sourceFile.getLineAndCharacterOfPosition(binding.getStart(sourceFile)).line + 1;
|
|
253
408
|
return {
|
|
254
409
|
kind: 'refused',
|
|
255
|
-
reason:
|
|
256
|
-
|
|
410
|
+
reason: ts.isExportSpecifier(binding.parent)
|
|
411
|
+
? `it exports contract in an export statement (line ${line}); remove contract from that statement and run the script again`
|
|
412
|
+
: `it already has a binding named contract (line ${line}); rename that binding and run the script again`,
|
|
257
413
|
};
|
|
258
414
|
}
|
|
259
415
|
const local = first.jsonNames.find((name) => names.declared.has(name));
|
|
@@ -275,14 +431,16 @@ export function moveFile(ts: typeof TS, fileName: string, source: string): Outco
|
|
|
275
431
|
semicolon: firstImportText.endsWith(';') ? ';' : '',
|
|
276
432
|
eol: source.includes('\r\n') ? '\r\n' : '\n',
|
|
277
433
|
};
|
|
278
|
-
const edits: Edit[] =
|
|
434
|
+
const edits: Edit[] = [
|
|
435
|
+
...calls.flatMap((call) => call.edits),
|
|
436
|
+
...destructured.map((entry) => entry.edit),
|
|
437
|
+
];
|
|
279
438
|
const staticImport = importEdit(ts, sourceFile, imports, first.staticEntry, style);
|
|
280
439
|
const importedAfter = 'after' in staticImport ? staticImport.after : '';
|
|
281
440
|
if ('start' in staticImport) edits.push(staticImport);
|
|
282
441
|
|
|
283
442
|
let afterImports = lastImport.end;
|
|
284
443
|
while (source[afterImports] === '\r' || source[afterImports] === '\n') afterImports++;
|
|
285
|
-
const exported = !hasDefaultExport(ts, sourceFile);
|
|
286
444
|
const declaration = `${exported ? 'export ' : ''}const contract = contractFromJson${first.typeArguments}(${first.json})${style.semicolon}`;
|
|
287
445
|
edits.push({
|
|
288
446
|
start: lastImport.end,
|
|
@@ -315,15 +473,46 @@ function isTestPath(path: string): boolean {
|
|
|
315
473
|
return TEST_FILE.test(path) || path.split(/[\\/]/).some((part) => TEST_DIRECTORIES.has(part));
|
|
316
474
|
}
|
|
317
475
|
|
|
318
|
-
function
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
if (statSync(path).isDirectory()) files.push(...sourceFiles(path));
|
|
324
|
-
else if (SOURCE_FILE.test(entry) && !entry.endsWith('.d.ts')) files.push(path);
|
|
476
|
+
function isDirectory(path: string): boolean {
|
|
477
|
+
try {
|
|
478
|
+
return statSync(path).isDirectory();
|
|
479
|
+
} catch {
|
|
480
|
+
return false;
|
|
325
481
|
}
|
|
326
|
-
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function isFile(path: string): boolean {
|
|
485
|
+
try {
|
|
486
|
+
return statSync(path).isFile();
|
|
487
|
+
} catch {
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/** Each source file under `root`, once, by the first path that reaches it; a link to a directory already visited is not followed again. */
|
|
493
|
+
function sourceFiles(root: string): string[] {
|
|
494
|
+
const visited = new Set<string>();
|
|
495
|
+
const found = new Map<string, string>();
|
|
496
|
+
const visit = (directory: string): void => {
|
|
497
|
+
const realDirectory = realpathSync(directory);
|
|
498
|
+
if (visited.has(realDirectory)) return;
|
|
499
|
+
visited.add(realDirectory);
|
|
500
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
501
|
+
const path = join(directory, entry.name);
|
|
502
|
+
if (entry.isDirectory() || (entry.isSymbolicLink() && isDirectory(path))) {
|
|
503
|
+
if (!SKIPPED_DIRECTORIES.has(entry.name) && !entry.name.startsWith('.')) visit(path);
|
|
504
|
+
} else if (
|
|
505
|
+
(entry.isFile() || (entry.isSymbolicLink() && isFile(path))) &&
|
|
506
|
+
SOURCE_FILE.test(entry.name) &&
|
|
507
|
+
!entry.name.endsWith('.d.ts')
|
|
508
|
+
) {
|
|
509
|
+
const realFile = realpathSync(path);
|
|
510
|
+
if (!found.has(realFile)) found.set(realFile, path);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
visit(root);
|
|
515
|
+
return [...found.values()];
|
|
327
516
|
}
|
|
328
517
|
|
|
329
518
|
function loadTypeScript(root: string, explicit: string | undefined): typeof TS | undefined {
|
|
@@ -335,15 +524,41 @@ function loadTypeScript(root: string, explicit: string | undefined): typeof TS |
|
|
|
335
524
|
}
|
|
336
525
|
}
|
|
337
526
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
527
|
+
const USAGE =
|
|
528
|
+
'Usage: node contract-from-json.ts [project-root] [--typescript <path to the typescript package>]';
|
|
529
|
+
|
|
530
|
+
function parseArgs(args: readonly string[]): {
|
|
531
|
+
readonly root: string;
|
|
532
|
+
readonly typescript: string | undefined;
|
|
533
|
+
readonly errors: string[];
|
|
534
|
+
} {
|
|
535
|
+
const errors: string[] = [];
|
|
536
|
+
const positional: string[] = [];
|
|
537
|
+
let typescript: string | undefined;
|
|
538
|
+
for (let index = 0; index < args.length; index++) {
|
|
539
|
+
const arg = args[index] ?? '';
|
|
540
|
+
if (arg === '--typescript') {
|
|
541
|
+
const path = args[++index];
|
|
542
|
+
if (path === undefined || path.startsWith('-'))
|
|
543
|
+
errors.push('--typescript: needs the path to the typescript package');
|
|
544
|
+
else typescript = resolve(path);
|
|
545
|
+
} else if (arg.startsWith('-')) errors.push(`${arg}: unknown option`);
|
|
546
|
+
else positional.push(arg);
|
|
547
|
+
}
|
|
548
|
+
if (positional.length > 1) errors.push(`expected one project root, got ${positional.length}`);
|
|
345
549
|
const root = resolve(positional[0] ?? process.cwd());
|
|
346
|
-
|
|
550
|
+
if (errors.length === 0 && !isDirectory(root)) errors.push(`${root}: not a directory`);
|
|
551
|
+
if (errors.length > 0) errors.push(USAGE);
|
|
552
|
+
return { root, typescript, errors };
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
function main(): number {
|
|
556
|
+
const { root, typescript, errors } = parseArgs(process.argv.slice(2));
|
|
557
|
+
if (errors.length > 0) {
|
|
558
|
+
process.stderr.write(`${errors.join('\n')}\n`);
|
|
559
|
+
return 1;
|
|
560
|
+
}
|
|
561
|
+
const ts = loadTypeScript(root, typescript);
|
|
347
562
|
if (ts === undefined) {
|
|
348
563
|
process.stderr.write(
|
|
349
564
|
`TypeScript is not installed in ${root}. Install it (for example pnpm add -D typescript) and run the script again, or move each client by hand as the guide describes. No file was changed.\n`,
|