@anizoptera/publish-clean 0.5.0 → 0.6.0
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 +28 -16
- package/dist/cli.js +143 -52
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ dependencies. No deps, one JS file.
|
|
|
7
7
|
[](https://www.npmjs.com/package/@anizoptera/publish-clean)
|
|
8
8
|
[](https://www.npmjs.com/package/@anizoptera/publish-clean#provenance)
|
|
9
9
|
[](https://github.com/Anizoptera/publish-clean/actions/workflows/check.yml)
|
|
10
|
-
[](package.json)
|
|
11
11
|
[](package.json)
|
|
12
12
|
[](LICENSE)
|
|
13
13
|
|
|
@@ -47,11 +47,14 @@ choices are argued, with measurements, in
|
|
|
47
47
|
**Whatever you start it with, `pnpm` prepares the package and `npm` uploads it, so both
|
|
48
48
|
must be on `PATH`.** A Bun, npm or Yarn project needs pnpm installed too, including in CI.
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
Node.js 22+ runs it. npm provenance additionally needs 22.14+, because below that npm
|
|
51
|
+
cannot mint it.
|
|
51
52
|
|
|
52
53
|
That installs one package and nothing else. `publish-clean` has zero runtime
|
|
53
|
-
dependencies: it is a single file that talks to `pnpm
|
|
54
|
-
|
|
54
|
+
dependencies: it is a single file that talks to `pnpm` and `npm`, and reads and rewrites
|
|
55
|
+
the tarball itself, so there is nothing else to have on the machine.
|
|
56
|
+
|
|
57
|
+
For something that sits on your publish path and handles your
|
|
55
58
|
registry credentials, that matters. A publishing tool with a dependency tree is a
|
|
56
59
|
supply-chain risk of its own, and this one has no transitive code to audit.
|
|
57
60
|
|
|
@@ -256,6 +259,9 @@ nothing can alter the artifact after it was checked.
|
|
|
256
259
|
- the package is marked `private: true`
|
|
257
260
|
- the working tree has uncommitted changes (`--no-git-checks` to allow it)
|
|
258
261
|
- the package has no non-empty `files` array (`--skip-file-check` to allow it)
|
|
262
|
+
- the tarball holds tests, CI config, a lockfile or a `tsconfig` (`--allow-suspicious` to
|
|
263
|
+
allow it — a separate switch from the one above, so waiving a manifest convention never
|
|
264
|
+
silently disarms the artifact scan)
|
|
259
265
|
- the tarball holds something that should never ship: a `.env`, an `.npmrc`, `.git`,
|
|
260
266
|
`node_modules`, or a private key. This one has no off switch, by any flag or config key
|
|
261
267
|
- a dependency is still written as `catalog:`, `workspace:`, `link:` or `portal:`, which
|
|
@@ -319,6 +325,7 @@ choices like dist-tags on the command line and stable project policy in the mani
|
|
|
319
325
|
"publish-clean": {
|
|
320
326
|
"registry": "https://registry.npmjs.org",
|
|
321
327
|
"skipFileCheck": false,
|
|
328
|
+
"allowSuspicious": false,
|
|
322
329
|
"noGitChecks": false,
|
|
323
330
|
"devFields": ["customBuildOnlyField"],
|
|
324
331
|
"keepFields": ["contributes"]
|
|
@@ -326,17 +333,19 @@ choices like dist-tags on the command line and stable project policy in the mani
|
|
|
326
333
|
}
|
|
327
334
|
```
|
|
328
335
|
|
|
329
|
-
| Flag
|
|
330
|
-
|
|
|
331
|
-
| `--dry-run`
|
|
332
|
-
| `--guard-only`
|
|
333
|
-
| `--tarball-out DIR`
|
|
334
|
-
| `--registry URL`
|
|
335
|
-
| `--skip-file-check`
|
|
336
|
-
| `--
|
|
337
|
-
| -
|
|
338
|
-
| -
|
|
339
|
-
|
|
|
336
|
+
| Flag | `package.json` | What it does |
|
|
337
|
+
| -------------------- | ----------------- | ------------------------------------------------------------------------------------------ |
|
|
338
|
+
| `--dry-run` | - | Run everything up to the publish, then print the file list and the cleaned `package.json`. |
|
|
339
|
+
| `--guard-only` | - | Run everything up to the publish and exit, printing nothing. |
|
|
340
|
+
| `--tarball-out DIR` | - | Copy the final tarball into `DIR` before publishing. |
|
|
341
|
+
| `--registry URL` | `registry` | Set `publishConfig.registry` on the cleaned manifest, and publish to it. |
|
|
342
|
+
| `--skip-file-check` | `skipFileCheck` | Allow a manifest with no `files` array. |
|
|
343
|
+
| `--allow-suspicious` | `allowSuspicious` | Allow tests, CI config, lockfiles or `tsconfig` in the artifact. |
|
|
344
|
+
| `--no-git-checks` | `noGitChecks` | Allow publishing from a dirty working tree. |
|
|
345
|
+
| - | `devFields` | Extra manifest fields to strip. |
|
|
346
|
+
| - | `keepFields` | Fields that belong in the published package, so stop reporting them. |
|
|
347
|
+
| `-h`, `--help` | - | Print usage, every flag, and the config keys. |
|
|
348
|
+
| `-v`, `--version` | - | Print the installed version. |
|
|
340
349
|
|
|
341
350
|
Arguments after `--` go to `npm publish`. Pass the dist-tag explicitly: `--tag latest` for
|
|
342
351
|
a normal public release.
|
|
@@ -350,7 +359,10 @@ every mode, before the publish, so you get the validated artifact even if the up
|
|
|
350
359
|
`registry` pins where the package goes, so it cannot end up on whatever registry the
|
|
351
360
|
machine happens to be pointed at.
|
|
352
361
|
|
|
353
|
-
`skipFileCheck`
|
|
362
|
+
`skipFileCheck` and `allowSuspicious` are deliberately two switches. A missing `files`
|
|
363
|
+
array is a manifest convention some packages do not follow; tests or a lockfile in the
|
|
364
|
+
tarball is content nobody meant to ship. Neither touches the leak checks, which have no
|
|
365
|
+
off switch at all.
|
|
354
366
|
|
|
355
367
|
`noGitChecks` is what you need when you publish from a build directory, or from a checkout
|
|
356
368
|
that is not a git repository at all.
|
package/dist/cli.js
CHANGED
|
@@ -4,6 +4,7 @@ import { readFileSync } from "node:fs";
|
|
|
4
4
|
import { copyFile, mkdir, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
6
6
|
import path from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
7
8
|
import { parseArgs } from "node:util";
|
|
8
9
|
import { gunzipSync, gzipSync } from "node:zlib";
|
|
9
10
|
//#region src/error.ts
|
|
@@ -342,13 +343,41 @@ function assertPublicPackage(pkg) {
|
|
|
342
343
|
function assertFilesField(pkg, skip) {
|
|
343
344
|
if (!skip && (!Array.isArray(pkg.files) || pkg.files.length === 0)) throw new PublishCleanError("Package manifest must define a non-empty \"files\" array.");
|
|
344
345
|
}
|
|
346
|
+
/**
|
|
347
|
+
* Every key this tool reads out of the manifest's `publish-clean` block. Naming them is what
|
|
348
|
+
* makes a typo an error instead of a silent no-op — and a silent no-op here is not cosmetic:
|
|
349
|
+
* `devFeilds` publishes the field the author meant to strip, and nothing in the output says so.
|
|
350
|
+
*/
|
|
351
|
+
const CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
352
|
+
"allowSuspicious",
|
|
353
|
+
"devFields",
|
|
354
|
+
"keepFields",
|
|
355
|
+
"noGitChecks",
|
|
356
|
+
"registry",
|
|
357
|
+
"skipFileCheck"
|
|
358
|
+
]);
|
|
345
359
|
function packageConfig(pkg) {
|
|
346
360
|
let config = pkg["publish-clean"];
|
|
347
|
-
|
|
361
|
+
if (!isObject(config)) return {};
|
|
362
|
+
let unknown = Object.keys(config).filter((key) => !CONFIG_KEYS.has(key));
|
|
363
|
+
if (unknown.length > 0) throw new PublishCleanError(`Unknown "publish-clean" manifest options:\n${unknown.join("\n")}\nValid options: ${[...CONFIG_KEYS].join(", ")}`);
|
|
364
|
+
return config;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Reads a string-list option, refusing anything else outright rather than filtering it out.
|
|
368
|
+
* A number or a nested object in this list is a mistake in the manifest, and skipping it
|
|
369
|
+
* silently means the author's intent is lost with no signal anywhere.
|
|
370
|
+
*/
|
|
371
|
+
function stringList(config, key) {
|
|
372
|
+
let value = config[key];
|
|
373
|
+
if (value === void 0) return [];
|
|
374
|
+
if (!Array.isArray(value) || value.some((entry) => typeof entry != "string")) throw new PublishCleanError(`publish-clean.${key} must be an array of strings.`);
|
|
375
|
+
return value;
|
|
348
376
|
}
|
|
349
377
|
function customDevFields(config) {
|
|
350
|
-
|
|
351
|
-
|
|
378
|
+
let fields = stringList(config, "devFields"), kept = new Set(stringList(config, "keepFields")), contradictory = fields.filter((field) => kept.has(field));
|
|
379
|
+
if (contradictory.length > 0) throw new PublishCleanError(`These fields are listed as both devFields and keepFields, which asks to strip and to publish the same key:\n${contradictory.join("\n")}`);
|
|
380
|
+
let unsafe = fields.filter((field) => RUNTIME_MANIFEST_FIELDS.has(field));
|
|
352
381
|
if (unsafe.length > 0) throw new PublishCleanError(`publish-clean.devFields cannot remove runtime/public manifest fields:\n${unsafe.join("\n")}`);
|
|
353
382
|
return fields;
|
|
354
383
|
}
|
|
@@ -364,12 +393,13 @@ function customDevFields(config) {
|
|
|
364
393
|
* next one, including a real leak.
|
|
365
394
|
*/
|
|
366
395
|
function keptFields(config) {
|
|
367
|
-
return
|
|
396
|
+
return stringList(config, "keepFields");
|
|
368
397
|
}
|
|
369
398
|
//#endregion
|
|
370
399
|
//#region src/tarball.ts
|
|
371
400
|
/**
|
|
372
|
-
*
|
|
401
|
+
* Reads and rewrites a packed npm tarball. The only place this tool decodes or authors
|
|
402
|
+
* archive bytes, and the only reader every guard consults.
|
|
373
403
|
*
|
|
374
404
|
* The pipeline packs once, with pnpm, because that packer decides the file set. Cleaning the
|
|
375
405
|
* manifest by unpacking and packing again hands that decision to a second packer, which
|
|
@@ -379,9 +409,15 @@ function keptFields(config) {
|
|
|
379
409
|
* into.
|
|
380
410
|
*
|
|
381
411
|
* Every entry other than the manifest is copied as opaque bytes and never decoded, so entry
|
|
382
|
-
* shapes this code does not model — pax extended headers, ustar prefix splitting
|
|
383
|
-
*
|
|
384
|
-
*
|
|
412
|
+
* shapes this code does not model — pax extended headers, ustar prefix splitting — survive
|
|
413
|
+
* untouched. Only walking is universal: an entry's length is always its header block plus its
|
|
414
|
+
* size rounded up to a block, whatever the type.
|
|
415
|
+
*
|
|
416
|
+
* Reading here rather than through the `tar` binary is what makes the whole tool depend on
|
|
417
|
+
* nothing but Node: one archive is decompressed once and answers every question about it
|
|
418
|
+
* (file list, manifest bytes, rewrite), instead of one spawn and one decompression per
|
|
419
|
+
* question. It is also the stricter reader — `tar tzf` prints one name per line, so a path
|
|
420
|
+
* containing a newline arrives as two entries there and as itself here.
|
|
385
421
|
*/
|
|
386
422
|
const MANIFEST_PATH = "package/package.json", PAX_TYPES = /* @__PURE__ */ new Set(["x", "g"]);
|
|
387
423
|
function field(block, offset, length) {
|
|
@@ -413,32 +449,71 @@ function reheader(original, size) {
|
|
|
413
449
|
return header.write(sum.toString(8).padStart(6, "0") + "\0 ", 148, 8, "ascii"), header;
|
|
414
450
|
}
|
|
415
451
|
/**
|
|
416
|
-
*
|
|
452
|
+
* Decodes a gzipped tarball into its entries, refusing every shape whose meaning this tool
|
|
453
|
+
* cannot state unambiguously.
|
|
417
454
|
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
*
|
|
455
|
+
* A duplicate manifest is a refusal rather than a last-one-wins guess, because extractors
|
|
456
|
+
* disagree about which survives and the published manifest would then depend on the extractor
|
|
457
|
+
* rather than on this tool. A short final block is a truncation: an archive that ends
|
|
458
|
+
* mid-entry would otherwise read as a valid one that simply stops, which is exactly how a
|
|
459
|
+
* partial write becomes a published package.
|
|
421
460
|
*/
|
|
422
|
-
function
|
|
423
|
-
let tar = gunzipSync(
|
|
461
|
+
function readArchive(gzipped) {
|
|
462
|
+
let tar = gunzipSync(gzipped), entries = [], tail = tar.subarray(tar.length);
|
|
424
463
|
for (let offset = 0; offset < tar.length;) {
|
|
425
|
-
let header = tar.subarray(offset, offset + 512)
|
|
464
|
+
let header = tar.subarray(offset, offset + 512);
|
|
465
|
+
if (header.length < 512) throw new PublishCleanError("Tarball ends mid-header; the archive is truncated.");
|
|
466
|
+
let name = field(header, 0, 100);
|
|
426
467
|
if (name === "") {
|
|
427
|
-
|
|
468
|
+
tail = tar.subarray(offset);
|
|
428
469
|
break;
|
|
429
470
|
}
|
|
430
|
-
let size = entrySize(header), end = offset + 512 + 512 * Math.ceil(size / 512)
|
|
471
|
+
let size = entrySize(header), end = offset + 512 + 512 * Math.ceil(size / 512);
|
|
472
|
+
if (end > tar.length) throw new PublishCleanError(`Tarball entry ${name} runs past the end of the archive.`);
|
|
473
|
+
let type = field(header, 156, 1), body = tar.subarray(offset + 512, offset + 512 + size);
|
|
431
474
|
if (type === "L") throw new PublishCleanError("Tarball uses GNU long-name entries, which this tool refuses.");
|
|
432
|
-
if (PAX_TYPES.has(type) && assertNoManifestOverride(
|
|
433
|
-
if (replaced) throw new PublishCleanError(`Tarball contains ${MANIFEST_PATH} more than once.`);
|
|
475
|
+
if (PAX_TYPES.has(type) && assertNoManifestOverride(body), name === MANIFEST_PATH) {
|
|
434
476
|
if (type !== "0" && type !== "") throw new PublishCleanError(`${MANIFEST_PATH} is not a regular file in the tarball.`);
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
477
|
+
if (entries.some((entry) => entry.name === MANIFEST_PATH)) throw new PublishCleanError(`Tarball contains ${MANIFEST_PATH} more than once.`);
|
|
478
|
+
}
|
|
479
|
+
entries.push({
|
|
480
|
+
name,
|
|
481
|
+
type,
|
|
482
|
+
header,
|
|
483
|
+
body,
|
|
484
|
+
raw: tar.subarray(offset, end)
|
|
485
|
+
}), offset = end;
|
|
439
486
|
}
|
|
440
|
-
|
|
441
|
-
|
|
487
|
+
return {
|
|
488
|
+
entries,
|
|
489
|
+
tail
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* The paths a consumer's installer writes, with the `package/` prefix stripped — the list every
|
|
494
|
+
* content guard judges. Directories and pax headers are dropped: neither is a file anyone
|
|
495
|
+
* imports, and a pax header's own name (`PaxHeader`) names no file at all.
|
|
496
|
+
*/
|
|
497
|
+
function packageFiles(archive) {
|
|
498
|
+
return archive.entries.filter((entry) => entry.type !== "5" && !PAX_TYPES.has(entry.type)).map((entry) => entry.name.startsWith("package/") ? entry.name.slice(8) : entry.name).filter((name) => name.length > 0 && !name.endsWith("/")).sort();
|
|
499
|
+
}
|
|
500
|
+
function manifestEntry(archive) {
|
|
501
|
+
let entry = archive.entries.find((candidate) => candidate.name === MANIFEST_PATH);
|
|
502
|
+
if (!entry) throw new PublishCleanError(`Tarball does not contain ${MANIFEST_PATH}.`);
|
|
503
|
+
return entry;
|
|
504
|
+
}
|
|
505
|
+
/** The manifest exactly as the archive carries it, for parsing by the caller. */
|
|
506
|
+
function manifestText(archive) {
|
|
507
|
+
return manifestEntry(archive).body.toString("utf8");
|
|
508
|
+
}
|
|
509
|
+
/** Returns the gzipped tarball with `package/package.json` replaced by `manifest`. */
|
|
510
|
+
function replaceManifest(archive, manifest) {
|
|
511
|
+
let target = manifestEntry(archive), body = Buffer.from(manifest, "utf8"), parts = archive.entries.map((entry) => entry === target ? Buffer.concat([
|
|
512
|
+
reheader(entry.header, body.length),
|
|
513
|
+
body,
|
|
514
|
+
Buffer.alloc(512 * Math.ceil(body.length / 512) - body.length)
|
|
515
|
+
]) : entry.raw);
|
|
516
|
+
return parts.push(archive.tail), gzipSync(Buffer.concat(parts), { level: 9 });
|
|
442
517
|
}
|
|
443
518
|
//#endregion
|
|
444
519
|
//#region src/trusted-publish.ts
|
|
@@ -505,6 +580,15 @@ function assertRepositoryForTrustedPublish(pkg, publishArgs, env) {
|
|
|
505
580
|
//#endregion
|
|
506
581
|
//#region src/cli.ts
|
|
507
582
|
const TOOL_PROBE_TIMEOUT_MS = 1e4;
|
|
583
|
+
/**
|
|
584
|
+
* Read from the installed manifest rather than baked in at build time, so the number cannot
|
|
585
|
+
* drift from the package a user actually has — which is the only reason anyone asks a tool
|
|
586
|
+
* for its version.
|
|
587
|
+
*/
|
|
588
|
+
function ownVersion() {
|
|
589
|
+
let manifest = readJson(fileURLToPath(new URL("../package.json", import.meta.url)));
|
|
590
|
+
return typeof manifest.version == "string" ? manifest.version : "unknown";
|
|
591
|
+
}
|
|
508
592
|
function readJson(file) {
|
|
509
593
|
let parsed;
|
|
510
594
|
try {
|
|
@@ -633,34 +717,27 @@ function assertCleanGit(packageDir, skip) {
|
|
|
633
717
|
], packageDir).trim();
|
|
634
718
|
if (output) throw new PublishCleanError(`Source package has uncommitted changes:\n${output}`);
|
|
635
719
|
} catch (error) {
|
|
636
|
-
|
|
720
|
+
if (error instanceof PublishCleanError) throw error;
|
|
721
|
+
let stderr = outputFromError(error, "stderr");
|
|
722
|
+
throw new PublishCleanError(`Unable to verify source git status${stderr ? `: ${stderr}` : ""}.\nPass --no-git-checks to publish without this check.`, { cause: error });
|
|
637
723
|
}
|
|
638
724
|
}
|
|
639
725
|
/**
|
|
640
|
-
*
|
|
641
|
-
*
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
* `tar tzf` prints one name per line, so a filename containing a newline would arrive as two
|
|
645
|
-
* entries. That is safe in the only direction that matters, because every guard here fails
|
|
646
|
-
* closed: splitting a name can only add entries to a leak scan that refuses on any match, and a
|
|
647
|
-
* declared path whose name was split is then absent and refused as missing.
|
|
726
|
+
* Reads an archive from disk, so every judgement is made about bytes that exist as a file
|
|
727
|
+
* rather than about a buffer this process is holding. The final artifact is read back this
|
|
728
|
+
* way after it is written, which also proves the write itself landed whole.
|
|
648
729
|
*/
|
|
649
|
-
function
|
|
650
|
-
return
|
|
730
|
+
async function readTarball(tarball) {
|
|
731
|
+
return readArchive(await readFile(tarball));
|
|
651
732
|
}
|
|
652
|
-
function
|
|
733
|
+
function manifestOf(archive, label) {
|
|
653
734
|
let parsed;
|
|
654
735
|
try {
|
|
655
|
-
parsed = JSON.parse(
|
|
656
|
-
"xOzf",
|
|
657
|
-
tarball,
|
|
658
|
-
`package/${file}`
|
|
659
|
-
], cwd));
|
|
736
|
+
parsed = JSON.parse(manifestText(archive));
|
|
660
737
|
} catch (cause) {
|
|
661
|
-
throw new PublishCleanError(`Unable to
|
|
738
|
+
throw new PublishCleanError(`Unable to parse package.json inside ${label}.`, { cause });
|
|
662
739
|
}
|
|
663
|
-
if (!isObject(parsed)) throw new PublishCleanError(
|
|
740
|
+
if (!isObject(parsed)) throw new PublishCleanError(`package.json inside ${label} must contain a JSON object.`);
|
|
664
741
|
return parsed;
|
|
665
742
|
}
|
|
666
743
|
/**
|
|
@@ -682,10 +759,10 @@ async function soleTarball(packRoot) {
|
|
|
682
759
|
return path.join(packRoot, tarball);
|
|
683
760
|
}
|
|
684
761
|
async function packAndClean(packageDir, opts) {
|
|
685
|
-
requireTool("pnpm"), requireTool("npm"),
|
|
762
|
+
requireTool("pnpm"), requireTool("npm"), warnIfNonPnpmLifecycle();
|
|
686
763
|
let sourcePkg = readJson(path.join(packageDir, "package.json"));
|
|
687
764
|
!opts.guardOnly && !opts.dryRun && assertTrustedPublishingRuntime(sourcePkg, opts.publishArgs);
|
|
688
|
-
let config = packageConfig(sourcePkg), skipFileCheck = opts.skipFileCheck || config.skipFileCheck === !0, noGitChecks = opts.noGitChecks || config.noGitChecks === !0, registry = opts.registry ?? (typeof config.registry == "string" ? config.registry : null), extraDevFields = customDevFields(config), keepFields = keptFields(config);
|
|
765
|
+
let config = packageConfig(sourcePkg), skipFileCheck = opts.skipFileCheck || config.skipFileCheck === !0, allowSuspicious = opts.allowSuspicious || config.allowSuspicious === !0, noGitChecks = opts.noGitChecks || config.noGitChecks === !0, registry = opts.registry ?? (typeof config.registry == "string" ? config.registry : null), extraDevFields = customDevFields(config), keepFields = keptFields(config);
|
|
689
766
|
assertPublicPackage(sourcePkg), assertCleanGit(packageDir, noGitChecks), assertFilesField(sourcePkg, skipFileCheck);
|
|
690
767
|
let root = await mkdtemp(path.join(tmpdir(), "publish-clean-"));
|
|
691
768
|
try {
|
|
@@ -694,15 +771,15 @@ async function packAndClean(packageDir, opts) {
|
|
|
694
771
|
"--pack-destination",
|
|
695
772
|
root
|
|
696
773
|
], packageDir);
|
|
697
|
-
let tarball = await soleTarball(root), cleanedPkg = withRegistry(stripManifest(
|
|
774
|
+
let tarball = await soleTarball(root), packed = await readTarball(tarball), cleanedPkg = withRegistry(stripManifest(manifestOf(packed, "the packed tarball"), extraDevFields), registry), unrecognized = unrecognizedFieldsReport(cleanedPkg, keepFields);
|
|
698
775
|
unrecognized && console.warn(unrecognized);
|
|
699
776
|
let publishRoot = path.join(root, "publish");
|
|
700
777
|
await mkdir(publishRoot);
|
|
701
778
|
let finalTarball = path.join(publishRoot, path.basename(tarball));
|
|
702
|
-
await writeFile(finalTarball,
|
|
703
|
-
let
|
|
704
|
-
assertSameEntries(
|
|
705
|
-
let shippedPkg =
|
|
779
|
+
await writeFile(finalTarball, replaceManifest(packed, stringifyJson(cleanedPkg)));
|
|
780
|
+
let published = await readTarball(finalTarball), finalFiles = packageFiles(published);
|
|
781
|
+
assertSameEntries(packageFiles(packed), finalFiles), validatePackedFiles(finalFiles, allowSuspicious), assertDeclaredFiles(cleanedPkg, finalFiles);
|
|
782
|
+
let shippedPkg = manifestOf(published, "the published tarball");
|
|
706
783
|
if (assertNoMonorepoProtocols(shippedPkg), assertNoLostConsumerFields(sourcePkg, shippedPkg, extraDevFields), stableJson(shippedPkg) !== stableJson(cleanedPkg)) throw new PublishCleanError("Rewritten tarball manifest differs from the cleaned manifest.");
|
|
707
784
|
if (opts.tarballOut !== null) {
|
|
708
785
|
await mkdir(opts.tarballOut, { recursive: !0 });
|
|
@@ -739,6 +816,10 @@ async function main() {
|
|
|
739
816
|
args: cliArgs,
|
|
740
817
|
allowPositionals: !0,
|
|
741
818
|
options: {
|
|
819
|
+
"allow-suspicious": {
|
|
820
|
+
type: "boolean",
|
|
821
|
+
default: !1
|
|
822
|
+
},
|
|
742
823
|
"dry-run": {
|
|
743
824
|
type: "boolean",
|
|
744
825
|
default: !1
|
|
@@ -767,16 +848,26 @@ async function main() {
|
|
|
767
848
|
"tarball-out": {
|
|
768
849
|
type: "string",
|
|
769
850
|
default: void 0
|
|
851
|
+
},
|
|
852
|
+
version: {
|
|
853
|
+
type: "boolean",
|
|
854
|
+
short: "v",
|
|
855
|
+
default: !1
|
|
770
856
|
}
|
|
771
857
|
},
|
|
772
858
|
strict: !0
|
|
773
859
|
});
|
|
860
|
+
if (parsed.values.version) {
|
|
861
|
+
console.log(ownVersion());
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
774
864
|
if (parsed.values.help) {
|
|
775
|
-
console.log("publish-clean [--dry-run
|
|
865
|
+
console.log("publish-clean [options] [package-dir] [-- npm publish args]\n\nPacks with pnpm, strips developer-only fields from the packed manifest, validates the\nartifact, and publishes that exact tarball with npm. Arguments after `--` go to\n`npm publish` untouched (e.g. --access public --tag next --provenance).\n\nOptions:\n --dry-run Pack, clean and validate; print the file list and manifest, publish nothing.\n --guard-only Same checks, no output and no publish. For a pre-publish gate.\n --tarball-out DIR Also write the validated tarball into DIR, for attestation or release upload.\n --registry URL Publish to URL, and record it in the artifact's publishConfig.\n --no-git-checks Publish from a working tree with uncommitted changes.\n --skip-file-check Allow a manifest with no \"files\" array.\n --allow-suspicious Allow tests, CI config, lockfiles or tsconfig in the published artifact.\n -h, --help Show this help.\n -v, --version Show the publish-clean version.\n\nManifest configuration, under a \"publish-clean\" key in package.json:\n devFields string[] Extra fields to strip. Refused for fields consumers resolve.\n keepFields string[] Fields to acknowledge, so they stop being reported as unrecognised.\n registry string Default for --registry.\n noGitChecks boolean Default for --no-git-checks.\n skipFileCheck boolean Default for --skip-file-check.\n allowSuspicious boolean Default for --allow-suspicious.\n\nRequires pnpm and npm on PATH. npm provenance additionally requires Node.js 22.14+ and\nnpm 11.5.1+, and only a cloud CI runner can produce it.");
|
|
776
866
|
return;
|
|
777
867
|
}
|
|
778
868
|
if (parsed.positionals.length > 1) throw new PublishCleanError(`Unexpected positional arguments before --:\n${parsed.positionals.slice(1).join("\n")}`);
|
|
779
869
|
await packAndClean(path.resolve(String(parsed.positionals[0] ?? ".")), {
|
|
870
|
+
allowSuspicious: parsed.values["allow-suspicious"] === !0,
|
|
780
871
|
dryRun: parsed.values["dry-run"] === !0,
|
|
781
872
|
guardOnly: parsed.values["guard-only"] === !0,
|
|
782
873
|
noGitChecks: parsed.values["no-git-checks"] === !0,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anizoptera/publish-clean",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Pre-publish npm package cleaner that strips common useless noise and crap from package.json; prevents accidental publication of unwanted things and unresolved dependencies. No deps, one JS file.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -42,6 +42,6 @@
|
|
|
42
42
|
"provenance": true
|
|
43
43
|
},
|
|
44
44
|
"engines": {
|
|
45
|
-
"node": ">=22.
|
|
45
|
+
"node": ">=22.0.0"
|
|
46
46
|
}
|
|
47
47
|
}
|