@basaltkit/deploy 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -104,6 +104,7 @@ incident (RFC 0006 §5):
104
104
  - **C8** stay silent about a certificate that does not cover the apex or a tenant host;
105
105
  - **C9** run with a package manager major other than the one `packageManager` declares;
106
106
  - **C10** keep a forbidden key, or a fixed key with another value.
107
+ - **C11** build a commit whose `packageManager` (pnpm ≥ 12) the lockfile does not record — checked in preflight and again on the commit the fetch brings, before any install.
107
108
 
108
109
  Secrets never reach a command line, the compose file, or the terminal: the
109
110
  summary names keys, passwords travel in child-process environments only.
package/dist/checks.d.ts CHANGED
@@ -11,3 +11,17 @@ export declare function covers(name: string, host: string): boolean;
11
11
  export declare function tlsFindings(ctx: DeployContext): Promise<Finding[]>;
12
12
  /** C9 — the toolchain the pipeline will call, before it calls it. */
13
13
  export declare function toolingFindings(ctx: DeployContext): Promise<Finding[]>;
14
+ /** The pnpm version the lockfile records for `packageManager` (`packageManagerDependencies`), if any. */
15
+ export declare function lockedPnpm(lockfile: string): string | undefined;
16
+ /**
17
+ * C11 — a `packageManager` the lockfile does not record. pnpm 12 writes the
18
+ * pnpm it runs as into the lockfile (`packageManagerDependencies`) and its
19
+ * frozen install refuses a lockfile without it, or with another version:
20
+ * ERR_PNPM_FROZEN_LOCKFILE_WITH_OUTDATED_LOCKFILE, half-way through a deploy.
21
+ * It happened twice on the first day: `packageManager: pnpm@12.3.4` was
22
+ * committed with a lockfile written by pnpm 11.
23
+ *
24
+ * Checked when it can bite: pnpm declared at 12 or later, or a lockfile that
25
+ * already records a version (which must then be the declared one).
26
+ */
27
+ export declare function lockfileFindings(ctx: DeployContext): Promise<Finding[]>;
package/dist/checks.js CHANGED
@@ -97,3 +97,53 @@ export async function toolingFindings(ctx) {
97
97
  }
98
98
  return findings;
99
99
  }
100
+ /** The pnpm version the lockfile records for `packageManager` (`packageManagerDependencies`), if any. */
101
+ export function lockedPnpm(lockfile) {
102
+ const at = lockfile.indexOf('packageManagerDependencies:');
103
+ if (at === -1)
104
+ return undefined;
105
+ const match = /\n\s+pnpm:\s*\n\s+specifier:\s*['"]?([^\s'"]+)/.exec(lockfile.slice(at, at + 2000));
106
+ return match?.[1];
107
+ }
108
+ /**
109
+ * C11 — a `packageManager` the lockfile does not record. pnpm 12 writes the
110
+ * pnpm it runs as into the lockfile (`packageManagerDependencies`) and its
111
+ * frozen install refuses a lockfile without it, or with another version:
112
+ * ERR_PNPM_FROZEN_LOCKFILE_WITH_OUTDATED_LOCKFILE, half-way through a deploy.
113
+ * It happened twice on the first day: `packageManager: pnpm@12.3.4` was
114
+ * committed with a lockfile written by pnpm 11.
115
+ *
116
+ * Checked when it can bite: pnpm declared at 12 or later, or a lockfile that
117
+ * already records a version (which must then be the declared one).
118
+ */
119
+ export async function lockfileFindings(ctx) {
120
+ if (ctx.pm !== 'pnpm')
121
+ return [];
122
+ let declared;
123
+ try {
124
+ const pkg = JSON.parse((await ctx.host.readFile(join(ctx.dir, 'package.json'))) ?? '{}');
125
+ const match = /^pnpm@(\d+[^+\s]*)/.exec(pkg.packageManager ?? '');
126
+ declared = match?.[1];
127
+ }
128
+ catch {
129
+ return [];
130
+ }
131
+ if (!declared)
132
+ return [];
133
+ const lockfile = await ctx.host.readFile(join(ctx.dir, 'pnpm-lock.yaml'));
134
+ if (lockfile === undefined)
135
+ return [];
136
+ const locked = lockedPnpm(lockfile);
137
+ if (locked === undefined && Number(declared.split('.')[0]) < 12)
138
+ return [];
139
+ if (locked === declared)
140
+ return [];
141
+ return [{
142
+ id: 'C11',
143
+ level: 'error',
144
+ message: locked === undefined
145
+ ? `package.json declares pnpm@${declared}, but pnpm-lock.yaml does not record it (packageManagerDependencies): pnpm's frozen install will refuse the lockfile`
146
+ : `package.json declares pnpm@${declared}, but pnpm-lock.yaml records pnpm ${locked}: pnpm's frozen install will refuse the lockfile`,
147
+ fix: `run pnpm install --lockfile-only with pnpm ${declared} and commit pnpm-lock.yaml`,
148
+ }];
149
+ }
package/dist/pipeline.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { join } from 'node:path';
2
2
  import { apacheInstall, apachePreflight, vhostPaths } from './apache.js';
3
3
  import { backupDatabase, restoreCommand } from './backup.js';
4
- import { tlsFindings, toolingFindings } from './checks.js';
4
+ import { lockfileFindings, tlsFindings, toolingFindings } from './checks.js';
5
5
  import { processName } from './config.js';
6
6
  import { DeployError, errors, INSTALL_COMMAND, report } from './context.js';
7
7
  import { checkSchema, coercionFindings, policyFindings } from './env-check.js';
@@ -32,6 +32,7 @@ export async function preflight(ctx, options = {}) {
32
32
  const findings = [...syntaxFindings(document, ctx.config.env.file ?? '.env')];
33
33
  const port = await resolvePort(ctx, values);
34
34
  findings.push(...await toolingFindings(ctx));
35
+ findings.push(...await lockfileFindings(ctx));
35
36
  findings.push(...await pm2Preflight(ctx, port));
36
37
  if (ctx.config.proxy?.kind === 'apache')
37
38
  findings.push(...await apachePreflight(ctx, port));
@@ -274,6 +275,9 @@ export async function run(ctx, options = {}) {
274
275
  let values = checked.values;
275
276
  let infra = { services: [], env: [], findings: [], secrets: {} };
276
277
  try {
278
+ // Again on the code the fetch brought: preflight saw the commit before it.
279
+ if (sha !== previous)
280
+ stopOnErrors(ctx, await lockfileFindings(ctx), `the incoming commit ${sha.slice(0, 7)}`);
277
281
  const prepared = await step(ctx, 'env', () => prepareEnv(ctx, port));
278
282
  infra = prepared.infra;
279
283
  stopOnErrors(ctx, infra.findings, 'infra');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basaltkit/deploy",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "engines": {
5
5
  "node": ">=22.5.0"
6
6
  },