@prisma/orm-mongo 8.0.1-dev.40 → 8.0.1-dev.42
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/{mongo-static-DjmABCwj-8F0oDGAV.mjs → mongo-static-DXv-zWOu-FTCkjjZe.mjs} +3 -3
- package/dist/{mongo-static-DjmABCwj-8F0oDGAV.mjs.map → mongo-static-DXv-zWOu-FTCkjjZe.mjs.map} +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/runtime.mjs.map +1 -1
- package/dist/static.mjs +1 -1
- package/package.json +12 -12
- package/skills/prisma-8/SKILL.md +1 -1
- package/skills/prisma-8/references/upgrade-app.md +1 -1
- package/skills/prisma-8/references/upgrade-extension.md +1 -1
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md +2385 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts +2048 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-signature-names/contract-signature-names.ts +667 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/facade-paths-an-application-uses/facade-paths-an-application-uses.ts +667 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts +1996 -0
- package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/stored-files-format-version/stored-files-format-version.ts +586 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/instructions.md +2043 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-hash-inputs/contract-hash-inputs.ts +2048 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/contract-signature-names/contract-signature-names.ts +667 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/facade-paths-an-application-uses/facade-paths-an-application-uses.ts +667 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/platform-paths-an-extension-uses/platform-paths-an-extension-uses.ts +1996 -0
- package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.25-to-8.0.0-rc.26/scripts/stored-files-format-version/stored-files-format-version.ts +586 -0
|
@@ -0,0 +1,667 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Renames what Prisma called the contract "marker" to its new name, the contract signature, in a project's code, scripts and CI files.
|
|
4
|
+
*
|
|
5
|
+
* Usage: node contract-signature-names.ts [project-root]
|
|
6
|
+
*
|
|
7
|
+
* The project root defaults to the working directory. The script walks it, skipping `node_modules`, `dist`, `build` and directories whose name starts with a dot other than the CI folders `.github`, `.circleci`, `.gitlab` and `.buildkite`, and changes:
|
|
8
|
+
*
|
|
9
|
+
* - the flag `--marker-only` of `db verify` to `--signature-only`, wherever it is written as a whole word;
|
|
10
|
+
* - each of the nine renamed error codes, wherever it is written, and the published path `@prisma/orm-target-mysql/target/marker-lock`;
|
|
11
|
+
* - in code, the values `'orphanMarker'`, `'markerChanged'` and `'marker-verification'`, written as strings, which only Prisma's errors and logs carry;
|
|
12
|
+
* - in a code file that imports a renamed name from an `@prisma/orm-*` package, that import and the file's uses of it; a name the file re-exports keeps the name the file exports, and an object written in shorthand keeps its key (`{ errorMarkerMissing: errorSignatureMissing }`);
|
|
13
|
+
* - in a code file that imports from an `@prisma/orm-*` package, a renamed member of a published interface where the file reads it (`.readMarker`), writes it as a key (`{ verifyMarker: false }`) or declares it in a class or interface (`readMarker(…) {`);
|
|
14
|
+
* - in a code file that runs `db verify`, `db init`, `db update` or `db migrate` with `--json`, the fields it reads from that output, `marker` and `markerHash`, as properties, as keys of an object, and in destructuring, where the project's own name is kept (`{ signature: marker }`); and the mode `'marker-only'`.
|
|
15
|
+
*
|
|
16
|
+
* A name of the project's own, declared, exported or passed as a parameter, is never renamed, nor a name inside a longer one. It works out every file's new text before it writes any, so a run that stops before writing changes no file. If a write fails, it stops, names the file it failed on, which may be partly written, and names the files it did not write. It prints each file it changed, and a second run changes nothing.
|
|
17
|
+
*
|
|
18
|
+
* To tell a local binding of a renamed name, or of a namespace an `@prisma/orm-*` package is imported as, such as a parameter, from the import, the script reads a file that uses a renamed name through an import with the TypeScript compiler of the project, so such a project needs its `typescript` package installed.
|
|
19
|
+
*/
|
|
20
|
+
import { readdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
|
|
21
|
+
import { createRequire } from 'node:module';
|
|
22
|
+
import { join, relative, resolve } from 'node:path';
|
|
23
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
24
|
+
import type * as TS from 'typescript';
|
|
25
|
+
|
|
26
|
+
type TypeScript = typeof TS;
|
|
27
|
+
|
|
28
|
+
/** Each renamed error code; two old codes for one condition share their new one. `CONTRACT.MARKER_REQUIRED` and `CONFIG.FAMILY_READ_MARKER_REQUIRED` are gone, with no replacement. */
|
|
29
|
+
export const CODES: Readonly<Record<string, string>> = {
|
|
30
|
+
'CONTRACT.MARKER_MISMATCH': 'CONTRACT.SIGNATURE_MISMATCH',
|
|
31
|
+
'CONTRACT.MARKER_MISSING': 'CONTRACT.SIGNATURE_MISSING',
|
|
32
|
+
'CONTRACT.MARKER_READ_FAILED': 'CONTRACT.SIGNATURE_READ_FAILED',
|
|
33
|
+
'CONTRACT.MARKER_ROW_CORRUPT': 'CONTRACT.SIGNATURE_ROW_CORRUPT',
|
|
34
|
+
'MIGRATION.MARKER_CAS_FAILURE': 'MIGRATION.CONCURRENT_CHANGE',
|
|
35
|
+
'MIGRATION.MARKER_LOCK_TIMEOUT': 'MIGRATION.SIGNATURE_LOCK_TIMEOUT',
|
|
36
|
+
'MIGRATION.MARKER_MISMATCH': 'MIGRATION.SIGNATURE_NOT_IN_GRAPH',
|
|
37
|
+
'MIGRATION.MARKER_NOT_IN_HISTORY': 'MIGRATION.SIGNATURE_NOT_IN_GRAPH',
|
|
38
|
+
'MIGRATION.MARKER_ORIGIN_MISMATCH': 'MIGRATION.SIGNATURE_ORIGIN_MISMATCH',
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** String values only Prisma's errors and logs carry: a violation's `kind`, a failure's `reason`, and the scope of the client's warnings. */
|
|
42
|
+
export const VALUES: Readonly<Record<string, string>> = {
|
|
43
|
+
orphanMarker: 'orphanSignature',
|
|
44
|
+
markerChanged: 'signatureChanged',
|
|
45
|
+
'marker-verification': 'contract-signature-verification',
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** Each published path that was renamed. */
|
|
49
|
+
export const PATHS: Readonly<Record<string, string>> = {
|
|
50
|
+
'@prisma/orm-target-mysql/target/marker-lock': '@prisma/orm-target-mysql/target/signature-lock',
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** Each name an `@prisma/orm-*` package exports that was renamed: renamed where a file imports it. */
|
|
54
|
+
export const EXPORTS: Readonly<Record<string, string>> = {
|
|
55
|
+
acquireMarkerLock: 'acquireSignatureLock',
|
|
56
|
+
buildSignMarkerBootstrapQueries: 'buildSignBootstrapQueries',
|
|
57
|
+
contractHashAtMarker: 'contractHashAtSignature',
|
|
58
|
+
ContractMarkerRecord: 'ContractSignatureRecord',
|
|
59
|
+
ContractMarkerRecordLike: 'ContractSignatureRecordLike',
|
|
60
|
+
ContractMarkerRow: 'ContractSignatureRow',
|
|
61
|
+
errorHashMismatch: 'errorSignatureMismatch',
|
|
62
|
+
errorMarkerMissing: 'errorSignatureMissing',
|
|
63
|
+
errorMarkerReadFailed: 'errorSignatureReadFailed',
|
|
64
|
+
errorMarkerRowCorrupt: 'errorSignatureRowCorrupt',
|
|
65
|
+
MARKER_LOCK_TIMEOUT_SECONDS: 'SIGNATURE_LOCK_TIMEOUT_SECONDS',
|
|
66
|
+
MarkerCheckResult: 'ContractSignatureCheckResult',
|
|
67
|
+
MarkerCheckSection: 'ContractSignatureCheckSection',
|
|
68
|
+
MarkerDestination: 'ContractSignatureDestination',
|
|
69
|
+
MarkerHashes: 'ContractSignatureHashes',
|
|
70
|
+
MarkerInsert: 'ContractSignatureInsert',
|
|
71
|
+
MarkerOperations: 'ContractSignatureOperations',
|
|
72
|
+
MarkerReader: 'ContractSignatureReader',
|
|
73
|
+
MarkerReadResult: 'ContractSignatureReadResult',
|
|
74
|
+
markerSwapFailure: 'signatureSwapFailure',
|
|
75
|
+
MarkerSwapFailure: 'ContractSignatureSwapFailure',
|
|
76
|
+
parseContractMarkerRow: 'parseContractSignatureRow',
|
|
77
|
+
parseMarkerRowSafely: 'parseSignatureRowSafely',
|
|
78
|
+
releaseMarkerLock: 'releaseSignatureLock',
|
|
79
|
+
rethrowMarkerReadError: 'rethrowSignatureReadError',
|
|
80
|
+
sameMarkerHashes: 'sameContractSignatureHashes',
|
|
81
|
+
SpaceMarkerConflict: 'SpaceSignConflict',
|
|
82
|
+
SpaceMarkerHashConflict: 'SpaceSignatureHashConflict',
|
|
83
|
+
SpaceMarkerRecord: 'SpaceSignatureRecord',
|
|
84
|
+
SpaceSignature: 'SpaceSignOutcome',
|
|
85
|
+
VERIFY_CODE_HASH_MISMATCH: 'VERIFY_CODE_SIGNATURE_MISMATCH',
|
|
86
|
+
VERIFY_CODE_MARKER_MISSING: 'VERIFY_CODE_SIGNATURE_MISSING',
|
|
87
|
+
VerifyMarkerOption: 'VerifyContractSignatureOption',
|
|
88
|
+
withMarkerLock: 'withSignatureLock',
|
|
89
|
+
withMarkerReadErrorHandling: 'withSignatureReadErrorHandling',
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/** Each member of a published interface or options object that was renamed: a method, a property or a client option. */
|
|
93
|
+
export const MEMBERS: Readonly<Record<string, string>> = {
|
|
94
|
+
bootstrapSignMarkerQueries: 'bootstrapSignQueries',
|
|
95
|
+
currentMarker: 'currentSignature',
|
|
96
|
+
currentMarkerHash: 'currentSignatureHash',
|
|
97
|
+
currentMarkerInvariants: 'currentSignatureInvariants',
|
|
98
|
+
currentMarkerStorageHash: 'currentSignatureStorageHash',
|
|
99
|
+
databaseMarkerHashBySpace: 'databaseSignatureHashBySpace',
|
|
100
|
+
holdMarkerLock: 'holdSignatureLock',
|
|
101
|
+
initMarker: 'initSignature',
|
|
102
|
+
insertMarker: 'insertSignature',
|
|
103
|
+
lockMarker: 'lockSignature',
|
|
104
|
+
markerCheck: 'signatureCheck',
|
|
105
|
+
markerDrift: 'signatureDrift',
|
|
106
|
+
markerHash: 'signatureHash',
|
|
107
|
+
markerInvariants: 'signatureInvariants',
|
|
108
|
+
markerLocation: 'signatureLocation',
|
|
109
|
+
markerOps: 'signatureOps',
|
|
110
|
+
markerReader: 'signatureReader',
|
|
111
|
+
markerRowsBySpace: 'signatureRowsBySpace',
|
|
112
|
+
markersBySpaceId: 'signaturesBySpaceId',
|
|
113
|
+
orphanMarkers: 'orphanSignatures',
|
|
114
|
+
readAllMarkers: 'readAllSignatures',
|
|
115
|
+
readMarker: 'readSignature',
|
|
116
|
+
readMarkerDiscriminated: 'readSignatureDiscriminated',
|
|
117
|
+
skipMarker: 'skipSignature',
|
|
118
|
+
updateMarker: 'updateSignature',
|
|
119
|
+
verifyMarker: 'verifyContractSignature',
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/** The fields of `--json` output that were renamed. */
|
|
123
|
+
export const JSON_FIELDS: Readonly<Record<string, string>> = {
|
|
124
|
+
marker: 'signature',
|
|
125
|
+
markerHash: 'signatureHash',
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const escapeRegExp = (text: string): string => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
129
|
+
const alternation = (names: readonly string[]): string =>
|
|
130
|
+
[...names]
|
|
131
|
+
.sort((a, b) => b.length - a.length)
|
|
132
|
+
.map(escapeRegExp)
|
|
133
|
+
.join('|');
|
|
134
|
+
const IDENTIFIER = '[A-Za-z_$][\\w$]*';
|
|
135
|
+
|
|
136
|
+
const CODE = new RegExp(`(?<![\\w.])(?:${alternation(Object.keys(CODES))})(?![\\w])`, 'g');
|
|
137
|
+
const QUOTED_VALUE = new RegExp(`(['"\`])(${alternation(Object.keys(VALUES))})\\1`, 'g');
|
|
138
|
+
const PATH = new RegExp(`${alternation(Object.keys(PATHS))}(?![\\w/-])`, 'g');
|
|
139
|
+
const FLAG = /(?<![\w-])--marker-only(?![\w-])/g;
|
|
140
|
+
const PRISMA_MODULE = /^@prisma\/orm-[a-z0-9-]+(?:\/[\w./-]*)?$/;
|
|
141
|
+
const IMPORTS_PRISMA =
|
|
142
|
+
/(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*)['"`]@prisma\/orm-[a-z0-9-]+/;
|
|
143
|
+
const RUNS_JSON =
|
|
144
|
+
/(?:\bdb\s+(?:verify|init|update|migrate)\b|['"`]db['"`]\s*,\s*['"`](?:verify|init|update|migrate)['"`])[\s\S]*--json|--json[\s\S]*(?:\bdb\s+(?:verify|init|update|migrate)\b|['"`]db['"`]\s*,\s*['"`](?:verify|init|update|migrate)['"`])/;
|
|
145
|
+
|
|
146
|
+
interface Edit {
|
|
147
|
+
readonly at: number;
|
|
148
|
+
readonly length: number;
|
|
149
|
+
readonly text: string;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function applyEdits(source: string, edits: readonly Edit[]): string {
|
|
153
|
+
const sorted = [...edits].sort((a, b) => b.at - a.at);
|
|
154
|
+
let text = source;
|
|
155
|
+
let limit = Number.POSITIVE_INFINITY;
|
|
156
|
+
for (const edit of sorted) {
|
|
157
|
+
if (edit.at + edit.length > limit) continue;
|
|
158
|
+
text = `${text.slice(0, edit.at)}${edit.text}${text.slice(edit.at + edit.length)}`;
|
|
159
|
+
limit = edit.at;
|
|
160
|
+
}
|
|
161
|
+
return text;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** The source with each comment and the inside of each string replaced by spaces, so positions stay the same and only code is searched. */
|
|
165
|
+
function codeOnly(source: string): string {
|
|
166
|
+
const out = source.split('');
|
|
167
|
+
let i = 0;
|
|
168
|
+
const blank = (from: number, to: number) => {
|
|
169
|
+
for (let j = from; j < to; j++) if (out[j] !== '\n') out[j] = ' ';
|
|
170
|
+
};
|
|
171
|
+
while (i < source.length) {
|
|
172
|
+
const char = source[i];
|
|
173
|
+
if (char === '/' && source[i + 1] === '/') {
|
|
174
|
+
const end = source.indexOf('\n', i);
|
|
175
|
+
const stop = end === -1 ? source.length : end;
|
|
176
|
+
blank(i, stop);
|
|
177
|
+
i = stop;
|
|
178
|
+
} else if (char === '/' && source[i + 1] === '*') {
|
|
179
|
+
const end = source.indexOf('*/', i + 2);
|
|
180
|
+
const stop = end === -1 ? source.length : end + 2;
|
|
181
|
+
blank(i, stop);
|
|
182
|
+
i = stop;
|
|
183
|
+
} else if (char === "'" || char === '"') {
|
|
184
|
+
let j = i + 1;
|
|
185
|
+
while (j < source.length && source[j] !== char) j += source[j] === '\\' ? 2 : 1;
|
|
186
|
+
blank(i + 1, j);
|
|
187
|
+
i = j + 1;
|
|
188
|
+
} else if (char === '`') {
|
|
189
|
+
// A template's text is blanked; each `${…}` in it is code.
|
|
190
|
+
let j = i + 1;
|
|
191
|
+
let from = j;
|
|
192
|
+
while (j < source.length && source[j] !== '`') {
|
|
193
|
+
if (source[j] === '\\') {
|
|
194
|
+
j += 2;
|
|
195
|
+
} else if (source[j] === '$' && source[j + 1] === '{') {
|
|
196
|
+
blank(from, j);
|
|
197
|
+
const end = interpolationEnd(source, j + 2);
|
|
198
|
+
const inner = codeOnly(source.slice(j + 2, end));
|
|
199
|
+
for (let k = 0; k < inner.length; k++) out[j + 2 + k] = inner[k] ?? ' ';
|
|
200
|
+
j = end + 1;
|
|
201
|
+
from = j;
|
|
202
|
+
} else {
|
|
203
|
+
j++;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
blank(from, j);
|
|
207
|
+
i = j + 1;
|
|
208
|
+
} else {
|
|
209
|
+
i++;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return out.join('');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** The position of the `}` that closes a template interpolation whose expression starts at `from`. */
|
|
216
|
+
function interpolationEnd(source: string, from: number): number {
|
|
217
|
+
let depth = 0;
|
|
218
|
+
for (let i = from; i < source.length; i++) {
|
|
219
|
+
const char = source[i];
|
|
220
|
+
if (char === "'" || char === '"' || char === '`') {
|
|
221
|
+
let j = i + 1;
|
|
222
|
+
while (j < source.length && source[j] !== char) j += source[j] === '\\' ? 2 : 1;
|
|
223
|
+
i = j;
|
|
224
|
+
} else if (char === '{') depth++;
|
|
225
|
+
else if (char === '}') {
|
|
226
|
+
if (depth === 0) return i;
|
|
227
|
+
depth--;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return source.length;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** The innermost bracket open at `at` in `code`, and its position. */
|
|
234
|
+
function enclosing(
|
|
235
|
+
code: string,
|
|
236
|
+
at: number,
|
|
237
|
+
): { readonly bracket: string; readonly at: number } | undefined {
|
|
238
|
+
let depth = 0;
|
|
239
|
+
for (let i = at - 1; i >= 0; i--) {
|
|
240
|
+
const char = code[i];
|
|
241
|
+
if (char === ')' || char === ']' || char === '}') depth++;
|
|
242
|
+
else if (char === '(' || char === '[' || char === '{') {
|
|
243
|
+
if (depth === 0) return { bracket: char, at: i };
|
|
244
|
+
depth--;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** The position just after the bracket that closes the one at `open`. */
|
|
251
|
+
function closing(code: string, open: number): number {
|
|
252
|
+
let depth = 0;
|
|
253
|
+
for (let i = open; i < code.length; i++) {
|
|
254
|
+
const char = code[i];
|
|
255
|
+
if (char === '(' || char === '[' || char === '{') depth++;
|
|
256
|
+
else if (char === ')' || char === ']' || char === '}') {
|
|
257
|
+
depth--;
|
|
258
|
+
if (depth === 0) return i + 1;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return code.length;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const before = (code: string, at: number): string => code.slice(0, at).replace(/\s+$/, '');
|
|
265
|
+
const MODIFIERS =
|
|
266
|
+
/(?:^|[\s;{},])(?:(?:public|private|protected|static|readonly|override|declare|abstract|async|get|set)\s+)+$/;
|
|
267
|
+
|
|
268
|
+
/** Whether the name at `at` is a key of an object written in braces: after `{` or `,`, inside braces. */
|
|
269
|
+
function isObjectKey(code: string, at: number): boolean {
|
|
270
|
+
return /[{,]$/.test(before(code, at)) && enclosing(code, at)?.bracket === '{';
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** Whether the brace at `open` opens the body of a class: the heading before it may hold brackets of its own, as in `class A extends Base<{ x: 1 }> {`. */
|
|
274
|
+
function opensClassBody(code: string, open: number): boolean {
|
|
275
|
+
const heading = /\bclass\b(?![\s\S]*\bclass\b)([\s\S]*)$/.exec(code.slice(0, open));
|
|
276
|
+
if (heading === null) return false;
|
|
277
|
+
const text = heading[1] ?? '';
|
|
278
|
+
let depth = 0;
|
|
279
|
+
let angles = 0;
|
|
280
|
+
for (let i = 0; i < text.length; i++) {
|
|
281
|
+
const char = text[i];
|
|
282
|
+
if (char === '<') angles++;
|
|
283
|
+
else if (char === '>' && text[i - 1] !== '=') angles--;
|
|
284
|
+
else if (char === '{' && depth === 0 && angles === 0) return false;
|
|
285
|
+
if (char === '(' || char === '[' || char === '{') depth++;
|
|
286
|
+
else if (char === ')' || char === ']' || char === '}') depth--;
|
|
287
|
+
else if (depth === 0 && char === ';') return false;
|
|
288
|
+
if (depth < 0 || angles < 0) return false;
|
|
289
|
+
}
|
|
290
|
+
return depth === 0 && angles === 0;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** Whether the name at `at` declares a member of a class, an interface or an object: a field, a property or a method. In a class body, `name = …` is a field; elsewhere it is an assignment, and only a modifier makes it a declaration. */
|
|
294
|
+
function isMemberDeclaration(code: string, at: number, length: number): boolean {
|
|
295
|
+
const body = enclosing(code, at);
|
|
296
|
+
if (body?.bracket !== '{') return false;
|
|
297
|
+
const prefix = before(code, at);
|
|
298
|
+
const startsMember =
|
|
299
|
+
/(?:^|[{;},])$/.test(prefix) ||
|
|
300
|
+
/\n$/.test(code.slice(0, at).replace(/[ \t]+$/, '')) ||
|
|
301
|
+
MODIFIERS.test(code.slice(0, at));
|
|
302
|
+
if (!startsMember) return false;
|
|
303
|
+
const rest = code.slice(at + length);
|
|
304
|
+
if (/^\s*\??\s*:/.test(rest)) return true;
|
|
305
|
+
if (/^\s*=(?![=>])/.test(rest))
|
|
306
|
+
return MODIFIERS.test(code.slice(0, at)) || opensClassBody(code, body.at);
|
|
307
|
+
const call = /^\s*(?:<[^>]*>)?\s*\(/.exec(rest);
|
|
308
|
+
if (call === null) return false;
|
|
309
|
+
const open = at + length + call[0].length - 1;
|
|
310
|
+
return /^\s*(?::|\{)/.test(code.slice(closing(code, open)));
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
interface ImportUses {
|
|
314
|
+
/** The start of each use that refers to a binding of the file's own, such as a parameter, and not to the import of that name. */
|
|
315
|
+
readonly shadowed: ReadonlySet<number>;
|
|
316
|
+
/** The start of each use of the import written as a shorthand property, `{ name }`, whose key must keep the old name. */
|
|
317
|
+
readonly shorthand: ReadonlySet<number>;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function importUses(
|
|
321
|
+
ts: TypeScript,
|
|
322
|
+
fileName: string,
|
|
323
|
+
source: string,
|
|
324
|
+
names: ReadonlySet<string>,
|
|
325
|
+
): ImportUses {
|
|
326
|
+
const kind = /\.(tsx|jsx)$/.test(fileName)
|
|
327
|
+
? ts.ScriptKind.TSX
|
|
328
|
+
: /\.(js|mjs|cjs)$/.test(fileName)
|
|
329
|
+
? ts.ScriptKind.JS
|
|
330
|
+
: ts.ScriptKind.TS;
|
|
331
|
+
const file = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true, kind);
|
|
332
|
+
const host = ts.createCompilerHost({});
|
|
333
|
+
host.getSourceFile = (name) => (name === file.fileName ? file : undefined);
|
|
334
|
+
host.fileExists = (name) => name === file.fileName;
|
|
335
|
+
const program = ts.createProgram({
|
|
336
|
+
rootNames: [file.fileName],
|
|
337
|
+
options: { noLib: true, noResolve: true, allowJs: true },
|
|
338
|
+
host,
|
|
339
|
+
});
|
|
340
|
+
if (program.getSourceFile(file.fileName) !== file)
|
|
341
|
+
throw new Error(
|
|
342
|
+
`TypeScript did not take in ${fileName}, so the script cannot tell a local binding from an import there.`,
|
|
343
|
+
);
|
|
344
|
+
const checker = program.getTypeChecker();
|
|
345
|
+
const imported = new Set<TS.Symbol | undefined>();
|
|
346
|
+
const uses: TS.Identifier[] = [];
|
|
347
|
+
const visit = (node: TS.Node): void => {
|
|
348
|
+
if (ts.isIdentifier(node) && names.has(node.text)) {
|
|
349
|
+
if (ts.isImportSpecifier(node.parent) || ts.isNamespaceImport(node.parent))
|
|
350
|
+
imported.add(checker.getSymbolAtLocation(node));
|
|
351
|
+
else uses.push(node);
|
|
352
|
+
}
|
|
353
|
+
ts.forEachChild(node, visit);
|
|
354
|
+
};
|
|
355
|
+
visit(file);
|
|
356
|
+
const shadowed = new Set<number>();
|
|
357
|
+
const shorthand = new Set<number>();
|
|
358
|
+
for (const node of uses) {
|
|
359
|
+
const parent = node.parent;
|
|
360
|
+
const isShorthand = ts.isShorthandPropertyAssignment(parent) && parent.name === node;
|
|
361
|
+
const symbol = isShorthand
|
|
362
|
+
? checker.getShorthandAssignmentValueSymbol(parent)
|
|
363
|
+
: ts.isExportSpecifier(parent)
|
|
364
|
+
? checker.getExportSpecifierLocalTargetSymbol(parent)
|
|
365
|
+
: checker.getSymbolAtLocation(node);
|
|
366
|
+
if (symbol !== undefined && !imported.has(symbol)) shadowed.add(node.getStart(file));
|
|
367
|
+
else if (isShorthand) shorthand.add(node.getStart(file));
|
|
368
|
+
}
|
|
369
|
+
return { shadowed, shorthand };
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function renamedImports(
|
|
373
|
+
source: string,
|
|
374
|
+
code: string,
|
|
375
|
+
usesOf: (names: ReadonlySet<string>) => ImportUses,
|
|
376
|
+
): Edit[] {
|
|
377
|
+
const edits: Edit[] = [];
|
|
378
|
+
const locals = new Map<string, string>();
|
|
379
|
+
const declarations: Array<readonly [number, number]> = [];
|
|
380
|
+
const statement =
|
|
381
|
+
/\b(import|export)(\s+type)?\s+(?:[\w$]+\s*,\s*)?\{([^}]*)\}\s*from\s*(['"])([^'"]+)\4/g;
|
|
382
|
+
for (const match of source.matchAll(statement)) {
|
|
383
|
+
if (!PRISMA_MODULE.test(match[5] ?? '')) continue;
|
|
384
|
+
const listAt = (match.index ?? 0) + match[0].indexOf('{') + 1;
|
|
385
|
+
declarations.push([match.index ?? 0, (match.index ?? 0) + match[0].length]);
|
|
386
|
+
const reexport = match[1] === 'export';
|
|
387
|
+
const specifier = new RegExp(
|
|
388
|
+
`(?<![\\w$])(?:type\\s+)?(${IDENTIFIER})(\\s+as\\s+${IDENTIFIER})?`,
|
|
389
|
+
'g',
|
|
390
|
+
);
|
|
391
|
+
for (const entry of (match[3] ?? '').matchAll(specifier)) {
|
|
392
|
+
const name = entry[1] ?? '';
|
|
393
|
+
const now = EXPORTS[name];
|
|
394
|
+
if (now === undefined) continue;
|
|
395
|
+
const at =
|
|
396
|
+
listAt +
|
|
397
|
+
(entry.index ?? 0) +
|
|
398
|
+
entry[0].lastIndexOf(name, entry[0].length - (entry[2]?.length ?? 0));
|
|
399
|
+
const aliased = entry[2] !== undefined;
|
|
400
|
+
edits.push({
|
|
401
|
+
at,
|
|
402
|
+
length: name.length,
|
|
403
|
+
text: reexport && !aliased ? `${now} as ${name}` : now,
|
|
404
|
+
});
|
|
405
|
+
if (!reexport && !aliased) locals.set(name, now);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
const namespaces = /\bimport\s+(?:type\s+)?\*\s+as\s+([\w$]+)\s+from\s*(['"])([^'"]+)\2/g;
|
|
409
|
+
const spaces = [...source.matchAll(namespaces)]
|
|
410
|
+
.filter((match) => PRISMA_MODULE.test(match[3] ?? ''))
|
|
411
|
+
.map((match) => match[1] ?? '');
|
|
412
|
+
if (spaces.length > 0) {
|
|
413
|
+
const qualified = new RegExp(
|
|
414
|
+
`(?<![\\w$.])(?:${spaces.map(escapeRegExp).join('|')})\\s*\\.\\s*(${alternation(Object.keys(EXPORTS))})(?![\\w$])`,
|
|
415
|
+
'g',
|
|
416
|
+
);
|
|
417
|
+
const matches = [...code.matchAll(qualified)];
|
|
418
|
+
const { shadowed } =
|
|
419
|
+
matches.length > 0 ? usesOf(new Set(spaces)) : { shadowed: new Set<number>() };
|
|
420
|
+
for (const match of matches) {
|
|
421
|
+
if (shadowed.has(match.index ?? 0)) continue;
|
|
422
|
+
const name = match[1] ?? '';
|
|
423
|
+
edits.push({
|
|
424
|
+
at: (match.index ?? 0) + match[0].length - name.length,
|
|
425
|
+
length: name.length,
|
|
426
|
+
text: EXPORTS[name] ?? name,
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (locals.size > 0) {
|
|
431
|
+
const localExports = [...code.matchAll(/\bexport(?:\s+type)?\s*\{[^}]*\}(?!\s*from\b)/g)].map(
|
|
432
|
+
(match) => [match.index ?? 0, (match.index ?? 0) + match[0].length] as const,
|
|
433
|
+
);
|
|
434
|
+
const uses = new RegExp(`(?<![\\w$.])(?:${alternation([...locals.keys()])})(?![\\w$])`, 'g');
|
|
435
|
+
const { shadowed, shorthand } = usesOf(new Set(locals.keys()));
|
|
436
|
+
for (const match of code.matchAll(uses)) {
|
|
437
|
+
const at = match.index ?? 0;
|
|
438
|
+
if (declarations.some(([from, to]) => at >= from && at < to)) continue;
|
|
439
|
+
if (shadowed.has(at)) continue;
|
|
440
|
+
const now = locals.get(match[0]) ?? match[0];
|
|
441
|
+
// `export { name }` keeps the name other files import; `export { name as other }` keeps its alias.
|
|
442
|
+
if (localExports.some(([from, to]) => at >= from && at < to)) {
|
|
443
|
+
// After `as` the name is the one the module exports, not a local.
|
|
444
|
+
if (/\bas\s+$/.test(code.slice(0, at))) continue;
|
|
445
|
+
const aliased = /^\s+as\s/.test(code.slice(at + match[0].length));
|
|
446
|
+
edits.push({ at, length: match[0].length, text: aliased ? now : `${now} as ${match[0]}` });
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
if (isObjectKey(code, at) && /^\s*:/.test(code.slice(at + match[0].length))) continue;
|
|
450
|
+
edits.push({
|
|
451
|
+
at,
|
|
452
|
+
length: match[0].length,
|
|
453
|
+
text: shorthand.has(at) ? `${match[0]}: ${now}` : now,
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return edits;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
const MEMBER_IN_TYPE = /(?:\b(?:Pick|Omit)\s*<[^;{}()]*|\[\s*)$/;
|
|
461
|
+
|
|
462
|
+
function renamedMembers(source: string, code: string): Edit[] {
|
|
463
|
+
const edits: Edit[] = [];
|
|
464
|
+
const quoted = new RegExp(`(['"])(${alternation(Object.keys(MEMBERS))})\\1`, 'g');
|
|
465
|
+
for (const match of source.matchAll(quoted)) {
|
|
466
|
+
const at = match.index ?? 0;
|
|
467
|
+
if (code[at] !== match[1] || !MEMBER_IN_TYPE.test(code.slice(0, at))) continue;
|
|
468
|
+
const name = match[2] ?? '';
|
|
469
|
+
edits.push({ at: at + 1, length: name.length, text: MEMBERS[name] ?? name });
|
|
470
|
+
}
|
|
471
|
+
const names = new RegExp(`(?<![\\w$])(${alternation(Object.keys(MEMBERS))})(?![\\w$])`, 'g');
|
|
472
|
+
for (const match of code.matchAll(names)) {
|
|
473
|
+
const at = match.index ?? 0;
|
|
474
|
+
const name = match[1] ?? '';
|
|
475
|
+
const read = /(?:\?\.|\.)\s*$/.test(code.slice(0, at)) && !/\.\.\.\s*$/.test(code.slice(0, at));
|
|
476
|
+
const key = isObjectKey(code, at) && /^\s*\??\s*:/.test(code.slice(at + name.length));
|
|
477
|
+
if (read || key || isMemberDeclaration(code, at, name.length))
|
|
478
|
+
edits.push({ at, length: name.length, text: MEMBERS[name] ?? name });
|
|
479
|
+
}
|
|
480
|
+
return edits;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/** Whether the name at `at`, followed by `rest`, is a key: of an object, a type literal or an interface (`{ marker: …`, `; markerHash?: string`, or a member on a line of its own). */
|
|
484
|
+
function isKey(code: string, at: number, rest: string): boolean {
|
|
485
|
+
if (enclosing(code, at)?.bracket !== '{') return false;
|
|
486
|
+
if (/[{,;]$/.test(before(code, at))) return /^\s*\??\s*:/.test(rest);
|
|
487
|
+
return (
|
|
488
|
+
/\n[ \t]*$/.test(code.slice(0, at)) &&
|
|
489
|
+
/[\w$)\]}>'"`]$/.test(before(code, at)) &&
|
|
490
|
+
/^[ \t]*\??[ \t]*:/.test(rest)
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/** Whether `text` is a type annotation, `: T`, followed by `=`: the type may hold brackets of its own. */
|
|
495
|
+
function assignedAfterType(text: string): boolean {
|
|
496
|
+
const colon = /^\s*:/.exec(text);
|
|
497
|
+
if (colon === null) return false;
|
|
498
|
+
let depth = 0;
|
|
499
|
+
for (let i = colon[0].length; i < text.length; i++) {
|
|
500
|
+
const char = text[i];
|
|
501
|
+
if (char === '(' || char === '[' || char === '{' || char === '<') depth++;
|
|
502
|
+
else if (
|
|
503
|
+
char === ')' ||
|
|
504
|
+
char === ']' ||
|
|
505
|
+
char === '}' ||
|
|
506
|
+
(char === '>' && text[i - 1] !== '=')
|
|
507
|
+
) {
|
|
508
|
+
if (depth === 0) return false;
|
|
509
|
+
depth--;
|
|
510
|
+
} else if (depth === 0 && (char === ';' || char === ',')) return false;
|
|
511
|
+
else if (depth === 0 && char === '=' && !/[=>]/.test(text[i + 1] ?? '')) return true;
|
|
512
|
+
}
|
|
513
|
+
return false;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** Whether the braces at `open` destructure: `{ … } = …`, `{ … }: T = …`, or a parameter of an arrow function, a function or a method, `({ … }) =>` or `({ … }: T) {`. */
|
|
517
|
+
function isDestructuring(code: string, open: number): boolean {
|
|
518
|
+
const after = code.slice(closing(code, open));
|
|
519
|
+
if (/^\s*=(?![=>])/.test(after) || assignedAfterType(after)) return true;
|
|
520
|
+
const parameters = enclosing(code, open);
|
|
521
|
+
if (parameters?.bracket !== '(' || /=$/.test(before(code, open))) return false;
|
|
522
|
+
const afterParameters = code.slice(closing(code, parameters.at));
|
|
523
|
+
return /^\s*(?::[^=;{}]*)?=>/.test(afterParameters) || /^\s*(?::[^;{]*)?\{/.test(afterParameters);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function renamedJsonFields(source: string, code: string): Edit[] {
|
|
527
|
+
const edits: Edit[] = [];
|
|
528
|
+
const fields = new RegExp(`(?<![\\w$])(${alternation(Object.keys(JSON_FIELDS))})(?![\\w$])`, 'g');
|
|
529
|
+
for (const match of code.matchAll(fields)) {
|
|
530
|
+
const at = match.index ?? 0;
|
|
531
|
+
const name = match[1] ?? '';
|
|
532
|
+
const now = JSON_FIELDS[name] ?? name;
|
|
533
|
+
const prefix = code.slice(0, at);
|
|
534
|
+
const rest = code.slice(at + name.length);
|
|
535
|
+
if (/(?:\?\.|\.)\s*$/.test(prefix) && !/\.\.\.\s*$/.test(prefix)) {
|
|
536
|
+
edits.push({ at, length: name.length, text: now });
|
|
537
|
+
} else if (isKey(code, at, rest)) {
|
|
538
|
+
edits.push({ at, length: name.length, text: now });
|
|
539
|
+
} else if (isObjectKey(code, at) && /^\s*(?:[,}]|=(?![=>]))/.test(rest)) {
|
|
540
|
+
if (isDestructuring(code, enclosing(code, at)?.at ?? 0))
|
|
541
|
+
edits.push({ at, length: name.length, text: `${now}: ${name}` });
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
const quoted = /(['"])(marker(?:Hash)?|marker-only)\1/g;
|
|
545
|
+
for (const match of source.matchAll(quoted)) {
|
|
546
|
+
const value = match[2] ?? '';
|
|
547
|
+
const now = value === 'marker-only' ? 'signature-only' : (JSON_FIELDS[value] ?? value);
|
|
548
|
+
edits.push({ at: (match.index ?? 0) + 1, length: value.length, text: now });
|
|
549
|
+
}
|
|
550
|
+
return edits;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
export function rewriteCode(ts: () => TypeScript, fileName: string, source: string): string {
|
|
554
|
+
const text = source
|
|
555
|
+
.replace(FLAG, '--signature-only')
|
|
556
|
+
.replace(CODE, (code) => CODES[code] ?? code)
|
|
557
|
+
.replace(PATH, (path) => PATHS[path] ?? path)
|
|
558
|
+
.replace(
|
|
559
|
+
QUOTED_VALUE,
|
|
560
|
+
(_, quote: string, value: string) => `${quote}${VALUES[value] ?? value}${quote}`,
|
|
561
|
+
);
|
|
562
|
+
const code = codeOnly(text);
|
|
563
|
+
const edits: Edit[] = [];
|
|
564
|
+
if (IMPORTS_PRISMA.test(text))
|
|
565
|
+
edits.push(
|
|
566
|
+
...renamedImports(text, code, (names) => importUses(ts(), fileName, text, names)),
|
|
567
|
+
...renamedMembers(text, code),
|
|
568
|
+
);
|
|
569
|
+
if (RUNS_JSON.test(text)) edits.push(...renamedJsonFields(text, code));
|
|
570
|
+
return applyEdits(text, edits);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/** Scripts and CI files: the flag, the codes, and on a line that runs a command with `--json`, the fields a `jq` filter reads. */
|
|
574
|
+
export function rewriteScript(source: string): string {
|
|
575
|
+
return source
|
|
576
|
+
.replace(FLAG, '--signature-only')
|
|
577
|
+
.replace(CODE, (code) => CODES[code] ?? code)
|
|
578
|
+
.split('\n')
|
|
579
|
+
.map((line) =>
|
|
580
|
+
/--json/.test(line) && /\bdb\s+(?:verify|init|update|migrate)\b/.test(line)
|
|
581
|
+
? line.replace(/\.marker(Hash)?(?![\w$])/g, (_, hash = '') => `.signature${hash}`)
|
|
582
|
+
: line,
|
|
583
|
+
)
|
|
584
|
+
.join('\n');
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
const SKIPPED_DIRECTORIES = new Set(['node_modules', 'dist', 'build']);
|
|
588
|
+
const CI_DIRECTORIES = new Set(['.github', '.circleci', '.gitlab', '.buildkite']);
|
|
589
|
+
const CODE_FILE = /\.(ts|mts|cts|tsx|js|mjs|cjs|jsx)$/;
|
|
590
|
+
const SCRIPT_FILE =
|
|
591
|
+
/(^package\.json$|^Makefile$|^Dockerfile$|^justfile$|\.(sh|bash|zsh|ya?ml|toml|md|mdx)$)/;
|
|
592
|
+
|
|
593
|
+
function* files(dir: string): Generator<string> {
|
|
594
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
595
|
+
if (entry.isDirectory()) {
|
|
596
|
+
if (SKIPPED_DIRECTORIES.has(entry.name)) continue;
|
|
597
|
+
if (entry.name.startsWith('.') && !CI_DIRECTORIES.has(entry.name)) continue;
|
|
598
|
+
yield* files(join(dir, entry.name));
|
|
599
|
+
} else if (entry.isFile() && (CODE_FILE.test(entry.name) || SCRIPT_FILE.test(entry.name))) {
|
|
600
|
+
yield join(dir, entry.name);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/** TypeScript's compiler, from the project the script works on, or else from beside the script. */
|
|
606
|
+
export function loadTypeScript(root: string): TypeScript {
|
|
607
|
+
for (const from of [join(root, 'package.json'), fileURLToPath(import.meta.url)]) {
|
|
608
|
+
try {
|
|
609
|
+
return createRequire(from)('typescript');
|
|
610
|
+
} catch {}
|
|
611
|
+
}
|
|
612
|
+
throw new Error(
|
|
613
|
+
'This script reads code that imports a renamed name with TypeScript, and found no `typescript` package in the project or beside the script. Prisma lists `typescript` as an optional peer dependency, so the project may not have it: install it in the project, for example as a development dependency, then run the script again.',
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
function main(): void {
|
|
618
|
+
const root = resolve(process.argv[2] ?? process.cwd());
|
|
619
|
+
let typescript: TypeScript | undefined;
|
|
620
|
+
const ts = () => {
|
|
621
|
+
typescript ??= loadTypeScript(root);
|
|
622
|
+
return typescript;
|
|
623
|
+
};
|
|
624
|
+
const changes: Array<readonly [string, string]> = [];
|
|
625
|
+
try {
|
|
626
|
+
for (const file of files(root)) {
|
|
627
|
+
const source = readFileSync(file, 'utf8');
|
|
628
|
+
const rewritten = CODE_FILE.test(file)
|
|
629
|
+
? rewriteCode(ts, file, source)
|
|
630
|
+
: rewriteScript(source);
|
|
631
|
+
if (rewritten !== source) changes.push([file, rewritten]);
|
|
632
|
+
}
|
|
633
|
+
} catch (error) {
|
|
634
|
+
console.error(
|
|
635
|
+
`${error instanceof Error ? error.message : String(error)}\nThe script changed no file.`,
|
|
636
|
+
);
|
|
637
|
+
process.exitCode = 1;
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
let written = 0;
|
|
641
|
+
try {
|
|
642
|
+
for (const [file, rewritten] of changes) {
|
|
643
|
+
writeFileSync(file, rewritten);
|
|
644
|
+
written++;
|
|
645
|
+
console.log(relative(root, file));
|
|
646
|
+
}
|
|
647
|
+
} catch (error) {
|
|
648
|
+
console.error(
|
|
649
|
+
[
|
|
650
|
+
error instanceof Error ? error.message : String(error),
|
|
651
|
+
`The write to ${relative(root, changes[written]?.[0] ?? root)} failed, so that file may be partly written.`,
|
|
652
|
+
'The script changed the files listed above, and none of these:',
|
|
653
|
+
...changes.slice(written + 1).map(([file]) => ` ${relative(root, file)}`),
|
|
654
|
+
'Fix the cause and run the script again, or restore the changed files from version control.',
|
|
655
|
+
].join('\n'),
|
|
656
|
+
);
|
|
657
|
+
process.exitCode = 1;
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// Node names the module by its real path, so a script reached through a symbolic link compares that.
|
|
663
|
+
if (
|
|
664
|
+
process.argv[1] !== undefined &&
|
|
665
|
+
import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href
|
|
666
|
+
)
|
|
667
|
+
main();
|