@prisma/orm-toolchain 8.0.0-rc.23-dev.12 → 8.0.0-rc.23-dev.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +101 -44
- package/dist/cli.mjs.map +1 -1
- package/package.json +12 -12
package/dist/cli.mjs
CHANGED
|
@@ -43,8 +43,8 @@ import stringWidth from "string-width";
|
|
|
43
43
|
import { bold, createColors, cyan, cyanBright, dim, green, yellow } from "colorette";
|
|
44
44
|
import { isCI } from "ci-info";
|
|
45
45
|
import { build } from "esbuild";
|
|
46
|
-
//#region ../../../1-framework/3-tooling/cli/dist/cli-
|
|
47
|
-
var version = "8.0.0-rc.23-dev.
|
|
46
|
+
//#region ../../../1-framework/3-tooling/cli/dist/cli-CFId1dwB.mjs
|
|
47
|
+
var version = "8.0.0-rc.23-dev.13";
|
|
48
48
|
const ESCAPES = {
|
|
49
49
|
"\\": "\\\\",
|
|
50
50
|
" ": "\\t",
|
|
@@ -4426,7 +4426,7 @@ function dbFile(target, resolveImportSpecifier = keepInternalSpecifiers) {
|
|
|
4426
4426
|
return `import 'dotenv/config';
|
|
4427
4427
|
import ${factory} from '${runtime}';
|
|
4428
4428
|
import { contractFromJson } from '${staticEntry}';
|
|
4429
|
-
import type { Contract } from './contract.d';
|
|
4429
|
+
import type { Contract } from './contract.d.js';
|
|
4430
4430
|
import contractJson from './contract.json' with { type: 'json' };
|
|
4431
4431
|
|
|
4432
4432
|
export const contract = contractFromJson<Contract>(contractJson);
|
|
@@ -5922,6 +5922,38 @@ const REQUIRED_COMPILER_OPTIONS = {
|
|
|
5922
5922
|
* explicitly is the documented escape hatch (FR2.2).
|
|
5923
5923
|
*/
|
|
5924
5924
|
const REQUIRED_COMPILER_OPTIONS_TYPES = ["node"];
|
|
5925
|
+
const MODULE_COMPILER_OPTIONS = ["module", "moduleResolution"];
|
|
5926
|
+
/**
|
|
5927
|
+
* The `module` values that go with each resolution mode the scaffold
|
|
5928
|
+
* already typechecks under, so a project that has picked one keeps its
|
|
5929
|
+
* own pair. `db.ts` spells its type import `./contract.d.js`, which
|
|
5930
|
+
* resolves to the emitted `contract.d.ts` under each.
|
|
5931
|
+
*
|
|
5932
|
+
* Only whole pairs count: TypeScript rejects a mismatched one (TS5110,
|
|
5933
|
+
* TS5095), so a project carrying half of one still gets the required
|
|
5934
|
+
* defaults. So does one on `module: 'node16'`, which predates import
|
|
5935
|
+
* attributes — `db.ts` imports `contract.json with { type: 'json' }`,
|
|
5936
|
+
* which is TS2823 there.
|
|
5937
|
+
*/
|
|
5938
|
+
const BUNDLER_MODULE_PAIRS = { bundler: ["preserve", "esnext"] };
|
|
5939
|
+
/**
|
|
5940
|
+
* Node 18 and Node 20 projects resolve under `moduleResolution:
|
|
5941
|
+
* 'node16'` — TypeScript has no `node18` or `node20` resolution mode —
|
|
5942
|
+
* and under `'nodenext'` as well.
|
|
5943
|
+
*
|
|
5944
|
+
* These modes compile a `.ts` file as CommonJS unless `package.json`
|
|
5945
|
+
* declares `"type": "module"`, and TypeScript rejects the import
|
|
5946
|
+
* attribute in a file compiled as CommonJS (TS2856). So they are kept
|
|
5947
|
+
* only in an ES module package.
|
|
5948
|
+
*/
|
|
5949
|
+
const NODE_MODULE_PAIRS = {
|
|
5950
|
+
node16: ["node18", "node20"],
|
|
5951
|
+
nodenext: [
|
|
5952
|
+
"nodenext",
|
|
5953
|
+
"node18",
|
|
5954
|
+
"node20"
|
|
5955
|
+
]
|
|
5956
|
+
};
|
|
5925
5957
|
function defaultTsConfig() {
|
|
5926
5958
|
return JSON.stringify({
|
|
5927
5959
|
compilerOptions: {
|
|
@@ -5971,21 +6003,27 @@ function formatTsConfigParseErrors(errors) {
|
|
|
5971
6003
|
* Throws `TsConfigParseError` when the input is not parseable as JSONC.
|
|
5972
6004
|
* The caller must catch this and surface a structured error before
|
|
5973
6005
|
* writing any scaffold files (FR6.2 atomicity).
|
|
6006
|
+
*
|
|
6007
|
+
* A project already on a pair the scaffold typechecks under keeps its
|
|
6008
|
+
* own `module` / `moduleResolution`; the options it never set are still
|
|
6009
|
+
* added. `packageType` is the `package.json` `"type"` after init.
|
|
5974
6010
|
*/
|
|
5975
|
-
function mergeTsConfig(existing) {
|
|
6011
|
+
function mergeTsConfig(existing, packageType) {
|
|
5976
6012
|
const { config } = parseTsConfigText(existing);
|
|
5977
6013
|
const formattingOptions = {
|
|
5978
6014
|
tabSize: detectIndent(existing),
|
|
5979
6015
|
insertSpaces: true,
|
|
5980
6016
|
eol: existing.includes("\r\n") ? "\r\n" : "\n"
|
|
5981
6017
|
};
|
|
6018
|
+
const compilerOptions = config["compilerOptions"];
|
|
6019
|
+
const keepModuleOptions = resolvesScaffoldImports(compilerOptions, packageType);
|
|
5982
6020
|
let result = existing;
|
|
5983
6021
|
for (const [key, value] of Object.entries(REQUIRED_COMPILER_OPTIONS)) {
|
|
6022
|
+
if (keepModuleOptions && MODULE_COMPILER_OPTIONS.includes(key)) continue;
|
|
5984
6023
|
const edits = modify(result, ["compilerOptions", key], value, { formattingOptions });
|
|
5985
6024
|
result = applyEdits(result, edits);
|
|
5986
6025
|
}
|
|
5987
|
-
const
|
|
5988
|
-
const mergedTypes = mergeTypesArray(existingTypes);
|
|
6026
|
+
const mergedTypes = mergeTypesArray(compilerOptions?.["types"]);
|
|
5989
6027
|
const typesEdits = modify(result, ["compilerOptions", "types"], mergedTypes, { formattingOptions });
|
|
5990
6028
|
result = applyEdits(result, typesEdits);
|
|
5991
6029
|
return result;
|
|
@@ -6011,6 +6049,17 @@ function parseTsConfigText(text) {
|
|
|
6011
6049
|
if (errors.length > 0) throw new TsConfigParseError(errors);
|
|
6012
6050
|
return { config: value };
|
|
6013
6051
|
}
|
|
6052
|
+
function resolvesScaffoldImports(compilerOptions, packageType) {
|
|
6053
|
+
return isModulePairIn(BUNDLER_MODULE_PAIRS, compilerOptions) || packageType === "module" && isModulePairIn(NODE_MODULE_PAIRS, compilerOptions);
|
|
6054
|
+
}
|
|
6055
|
+
function isModulePairIn(pairs, compilerOptions) {
|
|
6056
|
+
const moduleResolution = compilerOptions?.["moduleResolution"];
|
|
6057
|
+
const moduleOption = compilerOptions?.["module"];
|
|
6058
|
+
if (typeof moduleResolution !== "string" || typeof moduleOption !== "string") return false;
|
|
6059
|
+
const resolution = moduleResolution.toLowerCase();
|
|
6060
|
+
if (!Object.hasOwn(pairs, resolution)) return false;
|
|
6061
|
+
return pairs[resolution]?.includes(moduleOption.toLowerCase()) ?? false;
|
|
6062
|
+
}
|
|
6014
6063
|
function detectIndent(text) {
|
|
6015
6064
|
const match = text.match(/^([ \t]+)\S/m);
|
|
6016
6065
|
if (match === null) return 2;
|
|
@@ -6100,6 +6149,10 @@ function declaresRuntimeDependencies(parsed) {
|
|
|
6100
6149
|
const value = parsed?.["dependencies"];
|
|
6101
6150
|
return value !== null && typeof value === "object" && Object.keys(value).length > 0;
|
|
6102
6151
|
}
|
|
6152
|
+
function declaredPackageType(parsed) {
|
|
6153
|
+
const value = parsed?.["type"];
|
|
6154
|
+
return typeof value === "string" ? value : void 0;
|
|
6155
|
+
}
|
|
6103
6156
|
function hasDirectDep(parsed, name) {
|
|
6104
6157
|
for (const field of ["dependencies", "devDependencies"]) {
|
|
6105
6158
|
const value = parsed[field];
|
|
@@ -6187,45 +6240,13 @@ function planScaffold(ctx) {
|
|
|
6187
6240
|
path: ".env",
|
|
6188
6241
|
content: envFileContent(inputs.target)
|
|
6189
6242
|
});
|
|
6190
|
-
const tsconfigPath = join(cwd, "tsconfig.json");
|
|
6191
|
-
if (existsSync(tsconfigPath)) {
|
|
6192
|
-
const existing = readFileSync(tsconfigPath, "utf-8");
|
|
6193
|
-
let merged;
|
|
6194
|
-
try {
|
|
6195
|
-
merged = mergeTsConfig(existing);
|
|
6196
|
-
} catch (error) {
|
|
6197
|
-
if (error instanceof TsConfigParseError) throw errorInitInvalidTsconfig({
|
|
6198
|
-
path: "tsconfig.json",
|
|
6199
|
-
cause: error.message
|
|
6200
|
-
});
|
|
6201
|
-
throw error;
|
|
6202
|
-
}
|
|
6203
|
-
files.push({
|
|
6204
|
-
path: "tsconfig.json",
|
|
6205
|
-
content: merged,
|
|
6206
|
-
note: "Updated tsconfig.json with required compiler options."
|
|
6207
|
-
});
|
|
6208
|
-
} else files.push({
|
|
6209
|
-
path: "tsconfig.json",
|
|
6210
|
-
content: defaultTsConfig()
|
|
6211
|
-
});
|
|
6212
|
-
const gitignorePath = join(cwd, ".gitignore");
|
|
6213
|
-
const nextGitignore = mergeGitignore(existsSync(gitignorePath) ? readFileSync(gitignorePath, "utf-8") : void 0);
|
|
6214
|
-
if (nextGitignore !== null) files.push({
|
|
6215
|
-
path: ".gitignore",
|
|
6216
|
-
content: nextGitignore
|
|
6217
|
-
});
|
|
6218
|
-
const gitattributesPath = join(cwd, ".gitattributes");
|
|
6219
|
-
const nextGitattributes = mergeGitattributes(existsSync(gitattributesPath) ? readFileSync(gitattributesPath, "utf-8") : void 0, requiredGitattributesLines(outputDir, inputs.target));
|
|
6220
|
-
if (nextGitattributes !== null) files.push({
|
|
6221
|
-
path: ".gitattributes",
|
|
6222
|
-
content: nextGitattributes
|
|
6223
|
-
});
|
|
6224
6243
|
const manifestPath = join(cwd, "package.json");
|
|
6225
6244
|
const manifestExisted = existsSync(manifestPath);
|
|
6226
6245
|
const synthesiseManifest = !manifestExisted && !hasProjectManifest(cwd);
|
|
6227
6246
|
let parsedManifest = null;
|
|
6228
6247
|
let scriptsRewritten = [];
|
|
6248
|
+
let manifestContent = null;
|
|
6249
|
+
let packageType;
|
|
6229
6250
|
if (manifestExisted || synthesiseManifest) {
|
|
6230
6251
|
const raw = manifestExisted ? readFileSync(manifestPath, "utf-8") : defaultPackageJsonContent(basename(cwd));
|
|
6231
6252
|
try {
|
|
@@ -6264,14 +6285,50 @@ function planScaffold(ctx) {
|
|
|
6264
6285
|
working = withType;
|
|
6265
6286
|
changed = true;
|
|
6266
6287
|
}
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
content: working
|
|
6270
|
-
});
|
|
6288
|
+
packageType = withType !== null ? "module" : declaredPackageType(parsedManifest);
|
|
6289
|
+
if (changed) manifestContent = working;
|
|
6271
6290
|
warnings.push(...scriptWarnings);
|
|
6272
6291
|
if (typeWarning !== null) warnings.push(typeWarning);
|
|
6273
6292
|
if (synthesiseManifest) warnings.push("No package.json found in the target directory; created a minimal one. Edit `name` / `version` to taste.");
|
|
6274
6293
|
}
|
|
6294
|
+
const tsconfigPath = join(cwd, "tsconfig.json");
|
|
6295
|
+
if (existsSync(tsconfigPath)) {
|
|
6296
|
+
const existing = readFileSync(tsconfigPath, "utf-8");
|
|
6297
|
+
let merged;
|
|
6298
|
+
try {
|
|
6299
|
+
merged = mergeTsConfig(existing, packageType);
|
|
6300
|
+
} catch (error) {
|
|
6301
|
+
if (error instanceof TsConfigParseError) throw errorInitInvalidTsconfig({
|
|
6302
|
+
path: "tsconfig.json",
|
|
6303
|
+
cause: error.message
|
|
6304
|
+
});
|
|
6305
|
+
throw error;
|
|
6306
|
+
}
|
|
6307
|
+
files.push({
|
|
6308
|
+
path: "tsconfig.json",
|
|
6309
|
+
content: merged,
|
|
6310
|
+
note: "Updated tsconfig.json with required compiler options."
|
|
6311
|
+
});
|
|
6312
|
+
} else files.push({
|
|
6313
|
+
path: "tsconfig.json",
|
|
6314
|
+
content: defaultTsConfig()
|
|
6315
|
+
});
|
|
6316
|
+
const gitignorePath = join(cwd, ".gitignore");
|
|
6317
|
+
const nextGitignore = mergeGitignore(existsSync(gitignorePath) ? readFileSync(gitignorePath, "utf-8") : void 0);
|
|
6318
|
+
if (nextGitignore !== null) files.push({
|
|
6319
|
+
path: ".gitignore",
|
|
6320
|
+
content: nextGitignore
|
|
6321
|
+
});
|
|
6322
|
+
const gitattributesPath = join(cwd, ".gitattributes");
|
|
6323
|
+
const nextGitattributes = mergeGitattributes(existsSync(gitattributesPath) ? readFileSync(gitattributesPath, "utf-8") : void 0, requiredGitattributesLines(outputDir, inputs.target));
|
|
6324
|
+
if (nextGitattributes !== null) files.push({
|
|
6325
|
+
path: ".gitattributes",
|
|
6326
|
+
content: nextGitattributes
|
|
6327
|
+
});
|
|
6328
|
+
if (manifestContent !== null) files.push({
|
|
6329
|
+
path: "package.json",
|
|
6330
|
+
content: manifestContent
|
|
6331
|
+
});
|
|
6275
6332
|
if (source.kind === "starter" && existsSync(join(cwd, "src/index.ts"))) if (existsSync(join(cwd, "README.md"))) warnings.push("README.md already exists; leaving it untouched.");
|
|
6276
6333
|
else {
|
|
6277
6334
|
const declaredName = parsedManifest !== null && typeof parsedManifest["name"] === "string" ? parsedManifest["name"] : basename(cwd);
|