gencow 0.1.267 → 0.1.268

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.
@@ -7,6 +7,7 @@ import { fetchAppDiagnosticLogsViaRest, normalizeDiagnosticLogLines } from "./ap
7
7
  import { createCloudAppIfNeeded as createCloudAppIfNeededImpl } from "./deploy-app-creation.mjs";
8
8
  import { rejectExplicitAppNotFound } from "./deploy-app-target.mjs";
9
9
  import { loadProjectConfigForDeploy } from "./deploy-project-config-load.mjs";
10
+ import { loadPackageJson } from "./deploy-project-package-json.mjs";
10
11
  import { resolveConfiguredAuditorImplementation } from "./auditor-mode.mjs";
11
12
  import {
12
13
  loadDeployMigrationGenerationContext,
@@ -398,12 +399,13 @@ export function createDeployPackageRuntime({
398
399
  warnRuntimePathsOutsideBackendRoot({ entryPoint, projectRoot: cwd, backendRoot, warnImpl });
399
400
  let dependencyAuditManifest = null;
400
401
  let dependencyVersionMessage = "";
401
- let projectPkg;
402
+ const packageJson = loadPackageJson({ cwd, readFileSyncImpl, resolvePathImpl, errorImpl, exitImpl });
403
+ if (!packageJson) return null;
404
+ const projectPkg = packageJson.pkg;
402
405
  try {
403
406
  const { auditDependencyVersions, formatDependencyVersionAuditError } = await (
404
407
  loadDeployAuditorImpl ?? loadDeployAuditorDefault
405
408
  )();
406
- projectPkg = JSON.parse(readFileSyncImpl(resolvePathImpl(cwd, "package.json"), "utf8"));
407
409
  const auditOptions = { cwd, existsSyncImpl, readFileSyncImpl };
408
410
  const dependencyVersionResult = auditDependencyVersions(projectPkg, auditOptions);
409
411
  dependencyVersionMessage = formatDependencyVersionAuditError(dependencyVersionResult);
@@ -447,9 +449,6 @@ export function createDeployPackageRuntime({
447
449
  }
448
450
  }
449
451
 
450
- // Keep the manifest byte-compatible with the canonical pnpm lock importer.
451
- const stagedPackageJson = readFileSyncImpl(resolvePathImpl(cwd, "package.json"), "utf8");
452
-
453
452
  let bundleBackendRoot;
454
453
  let bundleFileRows = [];
455
454
  try {
@@ -472,7 +471,7 @@ export function createDeployPackageRuntime({
472
471
  readFileSyncImpl,
473
472
  resolvePathImpl,
474
473
  rmSyncImpl,
475
- stagedPackageJson,
474
+ stagedPackageJson: packageJson.text,
476
475
  tarCreateImpl,
477
476
  tmpBundle,
478
477
  writeCronManifestForProjectImpl,
@@ -0,0 +1,79 @@
1
+ // Reads the project package.json for deploy packaging. A missing, unreadable or non-JSON file is reported
2
+ // as a typed, secret-free diagnosis (no raw fs/parser text, no absolute workspace path) and returns null.
3
+
4
+ export const DEPLOY_PACKAGE_JSON_CODES = Object.freeze({
5
+ MISSING: "DEPLOY_PACKAGE_JSON_MISSING",
6
+ UNREADABLE: "DEPLOY_PACKAGE_JSON_UNREADABLE",
7
+ INVALID: "DEPLOY_PACKAGE_JSON_INVALID",
8
+ });
9
+
10
+ const NEXT_ACTION_FOR_MISSING =
11
+ "Next action: for a static-only site, run `gencow static --prod <build-output-dir>` (for example `gencow static --prod dist/`); for a backend app, run `npx gencow@latest init` to create a project with a package.json, then rerun deploy.";
12
+
13
+ const DIAGNOSES = Object.freeze({
14
+ [DEPLOY_PACKAGE_JSON_CODES.MISSING]: {
15
+ message: "DEPLOY BLOCKED — package.json was not found in the project root.",
16
+ retryable:
17
+ "Retryable: yes, after package.json exists in the project root — run `ls package.json` to confirm, then rerun the same deploy command.",
18
+ nextAction: NEXT_ACTION_FOR_MISSING,
19
+ },
20
+ [DEPLOY_PACKAGE_JSON_CODES.UNREADABLE]: {
21
+ message: "DEPLOY BLOCKED — package.json exists but could not be read.",
22
+ retryable:
23
+ "Retryable: yes, after package.json is readable by the current user — check its file permissions, then rerun the same deploy command.",
24
+ nextAction:
25
+ "Next action: make package.json a readable regular file in the project root, then rerun deploy.",
26
+ },
27
+ [DEPLOY_PACKAGE_JSON_CODES.INVALID]: {
28
+ message: "DEPLOY BLOCKED — package.json is not a valid JSON object.",
29
+ retryable:
30
+ "Retryable: yes, after package.json is fixed — run `node -p \"require('./package.json').name\"` to see the syntax error, correct the file, then rerun the same deploy command.",
31
+ nextAction:
32
+ "Next action: correct the JSON syntax of package.json in the project root, then rerun deploy.",
33
+ },
34
+ });
35
+
36
+ export function formatDeployPackageJsonDiagnostic(code) {
37
+ const diagnosis = DIAGNOSES[code];
38
+ return [
39
+ diagnosis.message,
40
+ `Code: ${code}`,
41
+ "Stage: packaging",
42
+ "Database mutation: NONE",
43
+ "Incumbent serving: PRESERVED",
44
+ diagnosis.retryable,
45
+ diagnosis.nextAction,
46
+ ].join("\n");
47
+ }
48
+
49
+ function isPlainObject(value) {
50
+ return value !== null && typeof value === "object" && !Array.isArray(value);
51
+ }
52
+
53
+ // Returns { pkg, text } (text is the exact file content, so the staged manifest stays byte-identical to what
54
+ // was validated), or null after printing the typed diagnosis and exiting with code 1.
55
+ export function loadPackageJson({ cwd, readFileSyncImpl, resolvePathImpl, errorImpl, exitImpl }) {
56
+ let text;
57
+ let code = null;
58
+ try {
59
+ text = readFileSyncImpl(resolvePathImpl(cwd, "package.json"), "utf8");
60
+ } catch (caught) {
61
+ code =
62
+ caught?.code === "ENOENT" ? DEPLOY_PACKAGE_JSON_CODES.MISSING : DEPLOY_PACKAGE_JSON_CODES.UNREADABLE;
63
+ }
64
+ let pkg;
65
+ if (code === null) {
66
+ try {
67
+ pkg = JSON.parse(text);
68
+ } catch {
69
+ pkg = undefined;
70
+ }
71
+ if (!isPlainObject(pkg)) code = DEPLOY_PACKAGE_JSON_CODES.INVALID;
72
+ }
73
+ if (code !== null) {
74
+ errorImpl(formatDeployPackageJsonDiagnostic(code));
75
+ exitImpl(1);
76
+ return null;
77
+ }
78
+ return { pkg, text };
79
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gencow",
3
- "version": "0.1.267",
3
+ "version": "0.1.268",
4
4
  "description": "Gencow — AI Backend Engine",
5
5
  "type": "module",
6
6
  "bin": {