@pellux/goodvibes-toolchain 1.11.1 → 1.11.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.
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
import { loadToolchainConfig } from '../lib/load-config.js';
|
|
5
5
|
import { consoleLogger } from '../lib/effects.js';
|
|
6
6
|
import { runPublishPackage, pollPropagation } from '../lib/publish-package.js';
|
|
7
|
+
/** Read the value that follows a `--flag <value>` argument, or undefined when absent. */
|
|
8
|
+
function flagValue(flag) {
|
|
9
|
+
const index = process.argv.indexOf(flag);
|
|
10
|
+
if (index < 0)
|
|
11
|
+
return undefined;
|
|
12
|
+
return process.argv[index + 1];
|
|
13
|
+
}
|
|
7
14
|
const root = process.cwd();
|
|
8
15
|
const config = loadToolchainConfig(root);
|
|
9
16
|
if (!config.publish) {
|
|
@@ -13,7 +20,28 @@ if (!config.publish) {
|
|
|
13
20
|
const version = JSON.parse(readFileSync(resolve(root, 'package.json'), 'utf8')).version;
|
|
14
21
|
const dryRun = process.argv.includes('--dry-run');
|
|
15
22
|
const registry = process.env.GOODVIBES_PUBLISH_REGISTRY ?? config.publish.defaultRegistry;
|
|
16
|
-
|
|
23
|
+
// --tarball <path>: publish a prebuilt .tgz instead of packing cwd. Validate the
|
|
24
|
+
// flag value up front — a missing/empty path is a caller error (exit 2), kept
|
|
25
|
+
// distinct from a publish failure (exit 1) so a broken pack→publish handoff is
|
|
26
|
+
// unambiguous in CI logs.
|
|
27
|
+
const tarballPath = flagValue('--tarball');
|
|
28
|
+
if (process.argv.includes('--tarball') && (tarballPath === undefined || tarballPath.length === 0)) {
|
|
29
|
+
consoleLogger.error('publish-package: --tarball requires a file path');
|
|
30
|
+
process.exit(2);
|
|
31
|
+
}
|
|
32
|
+
if (tarballPath !== undefined && !existsSync(resolve(root, tarballPath))) {
|
|
33
|
+
consoleLogger.error(`publish-package: --tarball path does not exist: ${tarballPath}`);
|
|
34
|
+
process.exit(2);
|
|
35
|
+
}
|
|
36
|
+
const result = runPublishPackage({
|
|
37
|
+
cwd: root,
|
|
38
|
+
name: config.publish.packageName,
|
|
39
|
+
version,
|
|
40
|
+
registry,
|
|
41
|
+
dryRun,
|
|
42
|
+
...(tarballPath !== undefined ? { tarballPath } : {}),
|
|
43
|
+
logger: consoleLogger,
|
|
44
|
+
});
|
|
17
45
|
consoleLogger.info(`publish-package: ${result.detail}`);
|
|
18
46
|
if (!result.ok)
|
|
19
47
|
process.exit(1);
|
|
@@ -15,7 +15,17 @@ export interface PublishOptions {
|
|
|
15
15
|
readonly version: string;
|
|
16
16
|
readonly registry?: string;
|
|
17
17
|
readonly dryRun?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* When set, publish this prebuilt tarball (`npm publish <tarballPath>`)
|
|
20
|
+
* instead of packing and publishing `cwd`. Used by repos whose npm bytes are
|
|
21
|
+
* produced by a separate pack job (e.g. the agent bundles a runtime before
|
|
22
|
+
* `bun pm pack`), so the publish must ship the staged .tgz rather than a bare
|
|
23
|
+
* checkout. The path must exist and be a readable `.tgz`.
|
|
24
|
+
*/
|
|
25
|
+
readonly tarballPath?: string;
|
|
18
26
|
readonly exec?: Exec;
|
|
27
|
+
/** File-existence seam (defaults to node `existsSync`) so tarball validation is testable. */
|
|
28
|
+
readonly fileExists?: (path: string) => boolean;
|
|
19
29
|
readonly logger?: Logger;
|
|
20
30
|
}
|
|
21
31
|
export interface PublishResult {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish-package.d.ts","sourceRoot":"","sources":["../../src/lib/publish-package.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"publish-package.d.ts","sourceRoot":"","sources":["../../src/lib/publish-package.ts"],"names":[],"mappings":"A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MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC;IACrB,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,gFAAgF;AAChF,wBAAsB,eAAe,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAiB7F"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* (re-runs are safe). Propagation poll: after publish, wait until the registry
|
|
7
7
|
* actually serves the new version before downstream jobs depend on it.
|
|
8
8
|
*/
|
|
9
|
+
import { existsSync } from 'node:fs';
|
|
9
10
|
import { realExec, consoleLogger, realSleep } from './effects.js';
|
|
10
11
|
import { DEFAULT_REGISTRY } from '../config.js';
|
|
11
12
|
/** Query the published version of name@version; null when absent (or on error). */
|
|
@@ -21,6 +22,31 @@ export function runPublishPackage(options) {
|
|
|
21
22
|
const exec = options.exec ?? realExec;
|
|
22
23
|
const logger = options.logger ?? consoleLogger;
|
|
23
24
|
const registry = options.registry ?? DEFAULT_REGISTRY;
|
|
25
|
+
const fileExists = options.fileExists ?? existsSync;
|
|
26
|
+
const tarball = options.tarballPath;
|
|
27
|
+
if (tarball !== undefined) {
|
|
28
|
+
// Tarball mode: publish a prebuilt .tgz. Validate the flag value — the file
|
|
29
|
+
// must exist and be a `.tgz` — before doing anything with it. `npm pack
|
|
30
|
+
// --dry-run` is meaningless here (there is nothing to pack), so a dry run
|
|
31
|
+
// just confirms the staged tarball is present and readable.
|
|
32
|
+
if (!tarball.endsWith('.tgz') || !fileExists(tarball)) {
|
|
33
|
+
return { ok: false, skipped: false, detail: `tarball not found or not a .tgz: ${tarball}` };
|
|
34
|
+
}
|
|
35
|
+
if (options.dryRun) {
|
|
36
|
+
return { ok: true, skipped: false, detail: `dry-run: tarball present (${tarball})` };
|
|
37
|
+
}
|
|
38
|
+
const alreadyTarball = getPublishedVersion(exec, options.name, options.version, registry);
|
|
39
|
+
if (alreadyTarball === options.version) {
|
|
40
|
+
logger.info(`[publish-package] ${options.name}@${options.version} already published — skipping`);
|
|
41
|
+
return { ok: true, skipped: true, detail: 'already published' };
|
|
42
|
+
}
|
|
43
|
+
const res = exec('npm', ['publish', tarball, '--access', 'public', '--registry', registry], { cwd: options.cwd });
|
|
44
|
+
if (res.status !== 0) {
|
|
45
|
+
return { ok: false, skipped: false, detail: `npm publish failed: ${res.stderr.trim().slice(0, 400)}` };
|
|
46
|
+
}
|
|
47
|
+
logger.info(`[publish-package] published ${options.name}@${options.version} from ${tarball}`);
|
|
48
|
+
return { ok: true, skipped: false, detail: 'published' };
|
|
49
|
+
}
|
|
24
50
|
if (options.dryRun) {
|
|
25
51
|
const res = exec('npm', ['pack', '--json'], { cwd: options.cwd });
|
|
26
52
|
return { ok: res.status === 0, skipped: false, detail: res.status === 0 ? 'dry-run pack ok' : `dry-run pack failed: ${res.stderr.trim()}` };
|