dsh-plugin-toolkit 0.20.37 → 0.20.39
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/CHANGELOG.md +59 -0
- package/README.md +1 -1
- package/lib/cli.mjs +5 -0
- package/lib/compat.mjs +43 -8
- package/lib/doctor.mjs +156 -13
- package/lib/release.mjs +68 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,62 @@
|
|
|
1
|
+
## 0.20.39
|
|
2
|
+
|
|
3
|
+
- **`doctor`'s files-list check honors a `.npmignore` in a subdirectory.** npm
|
|
4
|
+
disables the root `.npmignore` when `files` exists, but a `lib/.npmignore`
|
|
5
|
+
(or the `lib/.gitignore` fallback) still removes files from the tarball. A
|
|
6
|
+
package whose `files: ["lib"]` shipped the folder while `lib/.npmignore`
|
|
7
|
+
dropped the `lib/client.js` named by `exports["./client"]` used to pass
|
|
8
|
+
`doctor` and fail after install. The check walks each declared path through
|
|
9
|
+
the subdirectory ignore files and keeps npm's two exceptions: an explicit
|
|
10
|
+
file entry in `files` re-includes that file, and a later `!` rule in the
|
|
11
|
+
subdirectory ignore file puts it back. `test/doctor-files-npmignore.test.mjs`
|
|
12
|
+
pins the reported case, the `.gitignore` fallback, a nested
|
|
13
|
+
`lib/nested/.npmignore`, and the unrelated-file and negation controls against
|
|
14
|
+
`npm pack --dry-run --json`.
|
|
15
|
+
|
|
16
|
+
- **`release --dry-run` no longer plans a tag git will reject when the version
|
|
17
|
+
is valid.** A pre-release or build identifier ending in `.lock`
|
|
18
|
+
(`1.2.3-rc.lock`) is legal SemVer and packs with npm, but
|
|
19
|
+
`git tag plugin-v1.2.3-rc.lock` fails; an invalid `--tag-prefix` (a space or
|
|
20
|
+
`..`) had the same effect. `plan()` and the real release now apply git's
|
|
21
|
+
ref-name rules before printing or creating the tag, and report a `tag`
|
|
22
|
+
failure instead. `test/release.test.mjs` covers the valid controls, the
|
|
23
|
+
`.lock` version, an invalid prefix, and that the real release makes no git
|
|
24
|
+
calls for a name it refuses.
|
|
25
|
+
|
|
26
|
+
- **`doctor` validates `version` with the same strict SemVer parser the rest of
|
|
27
|
+
the toolkit uses, and `release --dry-run` no longer prints a tag for a version
|
|
28
|
+
the preflight rejects.** The package version check had its own regex while
|
|
29
|
+
the compatibility code had another parser, so the two could disagree about
|
|
30
|
+
forms such as `01.2.3`, `1.2.3-01` and `1.2.3-..`. The shared parser now also
|
|
31
|
+
rejects malformed build identifiers (`1.2.3+build..1`), which the older
|
|
32
|
+
compatibility parser let through. `plan()` refuses to build a `plugin-v...`
|
|
33
|
+
tag when the version is invalid, and the CLI reports the version failure
|
|
34
|
+
instead of printing a command the real release would never run.
|
|
35
|
+
`test/doctor-version-semver.test.mjs` checks the parser agreement, the
|
|
36
|
+
accepted `1.2.3` / `1.2.3-rc.1` controls, and that the invalid forms exit `1`
|
|
37
|
+
without a tag in the dry-run plan.
|
|
38
|
+
|
|
39
|
+
## 0.20.38
|
|
40
|
+
|
|
41
|
+
- **`doctor` accepts SemVer 2.0 build metadata in `version`, and rejects
|
|
42
|
+
malformed pre-release and build identifiers.** The hand-written check only
|
|
43
|
+
allowed an optional pre-release and no `+build`, so valid package versions
|
|
44
|
+
(`1.0.0+build.5`, `2.3.4+sha.abc`, `0.1.0+20261103`) failed as `not semver`
|
|
45
|
+
and `release --dry-run` stopped at preflight even though npm accepts them.
|
|
46
|
+
The same loose pre-release pattern let `1.0.0-..` and `1.0.0-.` through. The
|
|
47
|
+
check now follows SemVer 2.0's core, pre-release and build grammar, so empty
|
|
48
|
+
identifiers and leading zeros in numeric identifiers fail. The acceptance
|
|
49
|
+
covers `checkVersion`, `doctor` at the process boundary, the
|
|
50
|
+
`release --dry-run` plan and the invalid forms in
|
|
51
|
+
`test/doctor-version-semver.test.mjs`; `docs/repair.md` states the same rule.
|
|
52
|
+
|
|
53
|
+
- **The build-metadata acceptance is checked against npm itself.** The CLI
|
|
54
|
+
regression test now runs `doctor`, `release --dry-run` and
|
|
55
|
+
`npm pack --dry-run` on the same three fixtures and requires
|
|
56
|
+
`doctor_ok=3 release_ok=3 pack_ok=3`, so a future version check cannot drift
|
|
57
|
+
away from what npm will actually pack even if the two toolkit paths still
|
|
58
|
+
agree with each other.
|
|
59
|
+
|
|
1
60
|
## 0.20.37
|
|
2
61
|
|
|
3
62
|
- **The README tarball gate reads every relative `node <path>` command, not
|
package/README.md
CHANGED
|
@@ -746,7 +746,7 @@ the diff in the terminal.
|
|
|
746
746
|
| `dsh field` | `dsh.bundle.patch` must exist for the host to load the plugin |
|
|
747
747
|
| `patch file` | The path declared above must be a real file |
|
|
748
748
|
| `client entry` | If `dsh.client` is declared, the bundle has to be there |
|
|
749
|
-
| `files list` | Every path `package.json` points at (`exports`, patch, client) must be covered by `files
|
|
749
|
+
| `files list` | Every path `package.json` points at (`exports`, patch, client) must be covered by `files` and not removed by a `.npmignore`/`.gitignore` in a subdirectory it passes through; a leading `!` excludes what the positive entries would ship |
|
|
750
750
|
| `root export` | The loader imports the bare package name; if that module is missing, is a directory, is the CLI, exports no `apply`, or the `exports` map has no `.` entry, the row mounts nothing while the install reports success |
|
|
751
751
|
|
|
752
752
|
The `root export` check is a source check, not an install. `doctor` resolves the module the loader imports — `exports["."]` when it is a string or a conditions object (`default`, `import`, `require`, `node`, `module-sync`), otherwise `main` — then checks that the path is a readable regular file, removes comments and the contents of string, template and regex literals, and looks for a real export. A missing file, a directory and an unreadable file are reported as `root export` failures naming the target instead of being skipped or raising a raw `EISDIR`; on a directory the install would have failed at import too. It accepts `export function apply`, `export async function apply`, `export const apply = ...` (also `let` and `var`), `export { apply }` (including `export { helper as apply }`), `exports.apply = ...`, and an `apply` property in `module.exports = { ... }`. A comment such as `// TODO: export function apply() {}` is not an export, and `doctor` never imports or runs the plugin to decide.
|
package/lib/cli.mjs
CHANGED
|
@@ -863,6 +863,11 @@ export async function run(argv, io = console, deps = {}) {
|
|
|
863
863
|
tagPrefix: options.tagPrefix,
|
|
864
864
|
indexFile: options.index === undefined ? undefined : expandHome(options.index),
|
|
865
865
|
});
|
|
866
|
+
if (planned.tag === null) {
|
|
867
|
+
io.error(' cannot plan a release tag:');
|
|
868
|
+
printFailures(planned.failures, io);
|
|
869
|
+
return 1;
|
|
870
|
+
}
|
|
866
871
|
for (const step of planned.steps) {
|
|
867
872
|
io.log(` ${step.runs === false ? '·' : '→'} ${step.title}`);
|
|
868
873
|
io.log(` ${step.command}`);
|
package/lib/compat.mjs
CHANGED
|
@@ -13,9 +13,22 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
const CORE = '(0|[1-9]\\d*)';
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
// One grammar for every version this module accepts. Numeric identifiers may
|
|
17
|
+
// not carry leading zeros, while non-numeric ones may; prerelease and build
|
|
18
|
+
// identifiers are never empty and never joined by a bare dot. The same rule is
|
|
19
|
+
// used for the package `version` a release tags and for the host version a
|
|
20
|
+
// range is compared against, so the two probes cannot drift apart.
|
|
21
|
+
const NUMERIC_ID = '0|[1-9]\\d*';
|
|
22
|
+
const PRERELEASE_ID = `(?:${NUMERIC_ID}|\\d*[A-Za-z-][0-9A-Za-z-]*)`;
|
|
23
|
+
const BUILD_ID = '[0-9A-Za-z-]+';
|
|
24
|
+
const PRERELEASE = `(?:-(${PRERELEASE_ID}(?:\\.${PRERELEASE_ID})*))?`;
|
|
25
|
+
const BUILD = `(?:\\+(${BUILD_ID}(?:\\.${BUILD_ID})*))?`;
|
|
26
|
+
const VERSION_BODY = `${CORE}\\.${CORE}\\.${CORE}${PRERELEASE}${BUILD}`;
|
|
27
|
+
const FULL_VERSION = new RegExp(`^[v=]?${VERSION_BODY}$`, 'u');
|
|
28
|
+
// A package `version` is written by the author, not typed at a CLI: npm does
|
|
29
|
+
// not normalise a leading `v`/`=` or surrounding whitespace in the manifest
|
|
30
|
+
// field, and a release must not tag a version npm will rewrite.
|
|
31
|
+
const STRICT_VERSION = new RegExp(`^${VERSION_BODY}$`, 'u');
|
|
19
32
|
const PARTIAL_VERSION = new RegExp(
|
|
20
33
|
`^[v=]?(0|[1-9]\\d*|[xX*])(?:\\.(0|[1-9]\\d*|[xX*]))?(?:\\.(0|[1-9]\\d*|[xX*]))?${PRERELEASE}${BUILD}$`,
|
|
21
34
|
'u',
|
|
@@ -31,11 +44,7 @@ function prereleaseOf(text) {
|
|
|
31
44
|
return identifiers;
|
|
32
45
|
}
|
|
33
46
|
|
|
34
|
-
|
|
35
|
-
export function parseVersion(value) {
|
|
36
|
-
if (typeof value !== 'string') return null;
|
|
37
|
-
const match = FULL_VERSION.exec(value.trim());
|
|
38
|
-
if (match === null) return null;
|
|
47
|
+
function versionFromMatch(match) {
|
|
39
48
|
const prerelease = prereleaseOf(match[4]);
|
|
40
49
|
if (prerelease === null) return null;
|
|
41
50
|
return {
|
|
@@ -46,6 +55,32 @@ export function parseVersion(value) {
|
|
|
46
55
|
};
|
|
47
56
|
}
|
|
48
57
|
|
|
58
|
+
/**
|
|
59
|
+
* A complete `major.minor.patch[-prerelease][+build]` version, or null when
|
|
60
|
+
* malformed. This is the strict form a `package.json` `version` must have: no
|
|
61
|
+
* `v`/`=` prefix, no surrounding whitespace, and valid prerelease and build
|
|
62
|
+
* identifiers. Build metadata is accepted and does not affect precedence.
|
|
63
|
+
*/
|
|
64
|
+
export function parseStrictVersion(value) {
|
|
65
|
+
if (typeof value !== 'string') return null;
|
|
66
|
+
const match = STRICT_VERSION.exec(value);
|
|
67
|
+
if (match === null) return null;
|
|
68
|
+
return versionFromMatch(match);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A complete version for a host or range comparison, or null when malformed.
|
|
73
|
+
* npm's parser tolerates the leading `v`/`=` and surrounding whitespace users
|
|
74
|
+
* type on a command line, so the host form keeps that tolerance; the package
|
|
75
|
+
* `version` check uses `parseStrictVersion` instead.
|
|
76
|
+
*/
|
|
77
|
+
export function parseVersion(value) {
|
|
78
|
+
if (typeof value !== 'string') return null;
|
|
79
|
+
const match = FULL_VERSION.exec(value.trim());
|
|
80
|
+
if (match === null) return null;
|
|
81
|
+
return versionFromMatch(match);
|
|
82
|
+
}
|
|
83
|
+
|
|
49
84
|
/**
|
|
50
85
|
* The audit's `--host` contract, in one place: a complete version to compare
|
|
51
86
|
* against, never a range, a partial version or a label. Returns null when the
|
package/lib/doctor.mjs
CHANGED
|
@@ -9,13 +9,11 @@
|
|
|
9
9
|
import fs from 'node:fs';
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
|
|
12
|
-
import { hostCompatibility, parsePartialVersion, parseRange } from './compat.mjs';
|
|
12
|
+
import { hostCompatibility, parsePartialVersion, parseRange, parseStrictVersion } from './compat.mjs';
|
|
13
13
|
import { resolvePath } from './paths.mjs';
|
|
14
14
|
|
|
15
15
|
export { hostCompatibility } from './compat.mjs';
|
|
16
16
|
|
|
17
|
-
const SEMVER = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
|
|
18
|
-
|
|
19
17
|
/**
|
|
20
18
|
* npm publishes and installs by `name`; a missing, empty or malformed one fails
|
|
21
19
|
* at the publish/pack boundary, after every other check has already passed.
|
|
@@ -147,7 +145,9 @@ export function checkName(manifest) {
|
|
|
147
145
|
export function checkVersion(manifest) {
|
|
148
146
|
const value = version(manifest);
|
|
149
147
|
if (value === null) return 'package.json has no version';
|
|
150
|
-
|
|
148
|
+
// The same strict parser the compatibility code uses for a package version,
|
|
149
|
+
// so `doctor` and `release --dry-run` cannot accept different forms.
|
|
150
|
+
if (parseStrictVersion(value) === null) return `version "${value}" is not semver`;
|
|
151
151
|
return null;
|
|
152
152
|
}
|
|
153
153
|
|
|
@@ -496,10 +496,137 @@ export function isShipped(target, files) {
|
|
|
496
496
|
return shipped;
|
|
497
497
|
}
|
|
498
498
|
|
|
499
|
+
/**
|
|
500
|
+
* Read the ignore file npm would use for a subdirectory. A `.npmignore` file
|
|
501
|
+
* wins over `.gitignore` in the same directory, and a missing one falls through
|
|
502
|
+
* to the next candidate. The root `.npmignore` is not consulted here: when a
|
|
503
|
+
* `files` list exists npm disables the root ignore files, but a subdirectory
|
|
504
|
+
* `.npmignore` (or the `.gitignore` fallback) still subtracts from it.
|
|
505
|
+
*/
|
|
506
|
+
function subdirectoryIgnoreFile(directory) {
|
|
507
|
+
for (const name of ['.npmignore', '.gitignore']) {
|
|
508
|
+
let text;
|
|
509
|
+
try {
|
|
510
|
+
text = fs.readFileSync(path.join(directory, name), 'utf8');
|
|
511
|
+
} catch (error) {
|
|
512
|
+
if (error?.code === 'ENOENT' || error?.code === 'ENOTDIR') continue;
|
|
513
|
+
// npm would stop packing on an unreadable ignore file. The files-list
|
|
514
|
+
// check has no way to report that, so it keeps looking rather than
|
|
515
|
+
// calling the package clean because of a filesystem error.
|
|
516
|
+
return null;
|
|
517
|
+
}
|
|
518
|
+
return {
|
|
519
|
+
file: path.join(directory, name),
|
|
520
|
+
rules: text
|
|
521
|
+
.split(/\r?\n/u)
|
|
522
|
+
.map((line) => line.trim())
|
|
523
|
+
.filter((line) => line !== '' && line.startsWith('#') === false)
|
|
524
|
+
.map((line) => {
|
|
525
|
+
const negate = line.startsWith('!');
|
|
526
|
+
return { negate, pattern: negate ? line.slice(1) : line };
|
|
527
|
+
})
|
|
528
|
+
.filter((rule) => rule.pattern !== ''),
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
return null;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Whether one ignore-file rule names `relative`, a path below the directory
|
|
536
|
+
* that owns the ignore file. A rule also removes a file when it names one of
|
|
537
|
+
* its parent directories, which is how `nested/` drops `nested/client.js`.
|
|
538
|
+
*/
|
|
539
|
+
function ignoreRuleMatches(relative, pattern) {
|
|
540
|
+
// Anchoring is decided before `packagePath` strips the leading slash that
|
|
541
|
+
// spells it; `/client.js` names a direct child of the ignore file's folder,
|
|
542
|
+
// not a basename at any depth.
|
|
543
|
+
const anchored = String(pattern).startsWith('/');
|
|
544
|
+
let clean = packagePath(pattern);
|
|
545
|
+
const directoryOnly = clean.endsWith('/');
|
|
546
|
+
if (directoryOnly === true) clean = clean.replace(/\/+$/u, '');
|
|
547
|
+
if (clean === '' || clean === '.') return false;
|
|
548
|
+
|
|
549
|
+
const segments = relative.split('/');
|
|
550
|
+
for (let depth = 1; depth <= segments.length; depth += 1) {
|
|
551
|
+
// A trailing slash names a directory. It removes the files below that
|
|
552
|
+
// directory, not a file that happens to have the directory's name.
|
|
553
|
+
if (directoryOnly === true && depth === segments.length) continue;
|
|
554
|
+
const candidate = segments.slice(0, depth).join('/');
|
|
555
|
+
if (anchored === true || clean.includes('/') === true) {
|
|
556
|
+
if (globMatches(candidate, clean) === true) return true;
|
|
557
|
+
} else {
|
|
558
|
+
// npm compiles ignore rules with minimatch's matchBase: a pattern with
|
|
559
|
+
// no slash matches a basename at any depth (`*.test.js`).
|
|
560
|
+
const basename = candidate.slice(candidate.lastIndexOf('/') + 1);
|
|
561
|
+
if (globMatches(basename, clean) === true) return true;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
return false;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/** Whether the last matching rule in one ignore file excludes `relative`. */
|
|
568
|
+
function ignoredByRules(relative, rules) {
|
|
569
|
+
let ignored = false;
|
|
570
|
+
for (const rule of rules) {
|
|
571
|
+
if (ignoreRuleMatches(relative, rule.pattern) === true) ignored = rule.negate === false;
|
|
572
|
+
}
|
|
573
|
+
return ignored;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* The subdirectory ignore file that makes `npm pack` drop `target`, or null.
|
|
578
|
+
*
|
|
579
|
+
* npm walks the tree and applies each directory's own ignore file to the paths
|
|
580
|
+
* below it. The shallowest directory that excludes the path stops the walk, so
|
|
581
|
+
* a deeper ignore file cannot re-include what a parent removed. An explicit
|
|
582
|
+
* file entry in `files` is the one exception: npm marks it as required and
|
|
583
|
+
* packs it even when a subdirectory `.npmignore` names it.
|
|
584
|
+
*/
|
|
585
|
+
function subdirectoryIgnoreFor(dir, target) {
|
|
586
|
+
const root = path.resolve(dir);
|
|
587
|
+
const wanted = packagePath(target);
|
|
588
|
+
// A wildcard export names a set of files, not one path. npm decides that set
|
|
589
|
+
// while packing, so a single ignore rule cannot say the whole export is gone.
|
|
590
|
+
if (GLOB_MAGIC.test(wanted) === true) return null;
|
|
591
|
+
const segments = wanted.split('/').filter((segment) => segment !== '' && segment !== '.');
|
|
592
|
+
if (segments.length < 2 || segments.includes('..') === true) return null;
|
|
593
|
+
|
|
594
|
+
for (let depth = 1; depth < segments.length; depth += 1) {
|
|
595
|
+
const directory = path.join(root, ...segments.slice(0, depth));
|
|
596
|
+
if (directory.startsWith(`${root}${path.sep}`) === false) return null;
|
|
597
|
+
const ignore = subdirectoryIgnoreFile(directory);
|
|
598
|
+
if (ignore === null) continue;
|
|
599
|
+
const relative = segments.slice(depth).join('/');
|
|
600
|
+
if (ignoredByRules(relative, ignore.rules) === true) return ignore.file;
|
|
601
|
+
}
|
|
602
|
+
return null;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/** True when `files` names `target` as a file, which npm marks as required. */
|
|
606
|
+
function explicitlyListedFile(dir, target, files) {
|
|
607
|
+
const wanted = packagePath(target);
|
|
608
|
+
for (const entry of files) {
|
|
609
|
+
if (typeof entry !== 'string' || entry.startsWith('!')) continue;
|
|
610
|
+
const clean = packagePath(entry).replace(/\/+$/u, '');
|
|
611
|
+
if (clean !== wanted || clean === '') continue;
|
|
612
|
+
try {
|
|
613
|
+
if (fs.statSync(path.join(dir, clean)).isFile() === true) return true;
|
|
614
|
+
} catch {
|
|
615
|
+
// npm treats a path that is not there as a pattern, so nothing is
|
|
616
|
+
// required and a subdirectory ignore file still applies.
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
return false;
|
|
620
|
+
}
|
|
621
|
+
|
|
499
622
|
/**
|
|
500
623
|
* npm always puts these in the tarball whatever `files` says, so a `files` list
|
|
501
624
|
* that omits them is not a packaging bug. `main` is on the same list: npm adds
|
|
502
625
|
* the file the `main` field names even when `files` does not mention it.
|
|
626
|
+
*
|
|
627
|
+
* A subdirectory `.npmignore` can still drop these files, so the caller has to
|
|
628
|
+
* ask the ignore question separately; this predicate only covers the `files`
|
|
629
|
+
* list part of npm's rules.
|
|
503
630
|
*/
|
|
504
631
|
const ALWAYS_SHIPPED = (entry, manifest) => {
|
|
505
632
|
if (entry === 'package.json') return true;
|
|
@@ -510,19 +637,35 @@ const ALWAYS_SHIPPED = (entry, manifest) => {
|
|
|
510
637
|
return main !== null && entry === main;
|
|
511
638
|
};
|
|
512
639
|
|
|
513
|
-
/**
|
|
514
|
-
|
|
640
|
+
/**
|
|
641
|
+
* The paths `package.json` points at that its own `files` list (or the
|
|
642
|
+
* subdirectory ignore files npm applies on top of it) would omit.
|
|
643
|
+
*
|
|
644
|
+
* `dir` is optional because `doctor --remote` and `audit --remote` only have
|
|
645
|
+
* the manifest GitHub serves. Without a tree there is nothing to read, so the
|
|
646
|
+
* remote check keeps its manifest-only answer instead of guessing.
|
|
647
|
+
*/
|
|
648
|
+
export function missingDeclaredPaths(manifest, dir = undefined) {
|
|
515
649
|
const files = manifest.files;
|
|
516
650
|
if (Array.isArray(files) === false) return [];
|
|
517
|
-
const declared = declaredPaths(manifest)
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
651
|
+
const declared = declaredPaths(manifest);
|
|
652
|
+
const root = dir === undefined ? null : path.resolve(dir);
|
|
653
|
+
return declared.filter((entry) => {
|
|
654
|
+
const alwaysShipped = ALWAYS_SHIPPED(entry, manifest);
|
|
655
|
+
if (alwaysShipped === false && isShipped(entry, files) === false) return true;
|
|
656
|
+
if (root === null) return false;
|
|
657
|
+
// npm's synthetic rule for an explicit file in `files` re-includes that
|
|
658
|
+
// file, so a subdirectory `.npmignore` cannot drop it.
|
|
659
|
+
if (explicitlyListedFile(root, entry, files) === true) return false;
|
|
660
|
+
return subdirectoryIgnoreFor(root, entry) !== null;
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
export function checkFilesList(manifest, dir = undefined) {
|
|
522
665
|
if (Array.isArray(manifest.files) === false) {
|
|
523
666
|
return 'package.json has no "files" list, so the tarball ships whatever happens to be in the folder';
|
|
524
667
|
}
|
|
525
|
-
const missing = missingDeclaredPaths(manifest);
|
|
668
|
+
const missing = missingDeclaredPaths(manifest, dir);
|
|
526
669
|
if (missing.length > 0) {
|
|
527
670
|
return `files does not ship ${missing.join(', ')}, which package.json points at, so the installed plugin would be missing its own code`;
|
|
528
671
|
}
|
|
@@ -756,7 +899,7 @@ export function doctor(dir, { installed = false } = {}) {
|
|
|
756
899
|
['client declaration', checkClientDeclaration(target, manifest)],
|
|
757
900
|
// After install the tarball is already unpacked, so `files` cannot be used to
|
|
758
901
|
// decide what shipped: npm always ships package.json and the README.
|
|
759
|
-
['files list', installed === true ? null : checkFilesList(manifest)],
|
|
902
|
+
['files list', installed === true ? null : checkFilesList(manifest, target)],
|
|
760
903
|
['root export', checkRootExport(target, manifest)],
|
|
761
904
|
];
|
|
762
905
|
const failures = checks.filter(([, result]) => result !== null && typeof result === 'string');
|
package/lib/release.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { commandFailureDetail, run as runCommand } from './exec.mjs';
|
|
|
9
9
|
import fs from 'node:fs';
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
|
|
12
|
-
import { doctor } from './doctor.mjs';
|
|
12
|
+
import { checkVersion, doctor } from './doctor.mjs';
|
|
13
13
|
import { expandHome, resolvePath } from './paths.mjs';
|
|
14
14
|
import { addVersion, buildEntry, readIndex, writeIndex } from './index-file.mjs';
|
|
15
15
|
import { publishedAt, waitForVersion } from './registry.mjs';
|
|
@@ -59,6 +59,43 @@ export function tagName(version, prefix = 'plugin-v') {
|
|
|
59
59
|
return `${prefix}${version}`;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
/**
|
|
63
|
+
* True when `git tag` would accept this name; `refs/tags/` is implicit.
|
|
64
|
+
*
|
|
65
|
+
* The version check alone is not enough: a valid SemVer pre-release or build
|
|
66
|
+
* identifier can end in `.lock` (`1.2.3-rc.lock`), and `--tag-prefix` can carry
|
|
67
|
+
* a space or `..`. A dry run that printed one of those tags would tell the
|
|
68
|
+
* author to run a `git tag` command that fails. These are the
|
|
69
|
+
* `git check-ref-format` rules a derived name can violate, without asking a git
|
|
70
|
+
* binary during a read-only plan.
|
|
71
|
+
*/
|
|
72
|
+
export function isValidTagName(tag) {
|
|
73
|
+
if (typeof tag !== 'string' || tag.length === 0) return false;
|
|
74
|
+
if (/[\u0000-\u0020\u007f~^:?*\[\\]/u.test(tag)) return false;
|
|
75
|
+
if (
|
|
76
|
+
tag.includes('..') ||
|
|
77
|
+
tag.includes('@{') ||
|
|
78
|
+
tag.startsWith('/') ||
|
|
79
|
+
tag.endsWith('/') ||
|
|
80
|
+
tag.endsWith('.')
|
|
81
|
+
) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
return tag.split('/').every((component) => {
|
|
85
|
+
return (
|
|
86
|
+
component !== '' &&
|
|
87
|
+
component.startsWith('.') === false &&
|
|
88
|
+
component.endsWith('.lock') === false
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The sentence both the plan and the real release report for an unusable tag. */
|
|
94
|
+
function tagNameIssue(tag) {
|
|
95
|
+
if (isValidTagName(tag) === true) return null;
|
|
96
|
+
return `tag ${JSON.stringify(tag)} is not a valid git tag name; use a version and --tag-prefix without spaces, "..", a leading dot or a ".lock" component`;
|
|
97
|
+
}
|
|
98
|
+
|
|
62
99
|
export function tagExists(dir, tag, run) {
|
|
63
100
|
try {
|
|
64
101
|
(run ?? ((args) => git(dir, args)))(['rev-parse', `refs/tags/${tag}`]);
|
|
@@ -155,8 +192,33 @@ export function dirtyPaths(dir, limit = 3, run) {
|
|
|
155
192
|
export function plan({ dir = process.cwd(), version, name, tagPrefix = 'plugin-v', indexFile = 'market/index.json', marketDir }) {
|
|
156
193
|
const report = doctor(resolvePath(dir));
|
|
157
194
|
const resolvedName = name ?? report.manifest.name ?? 'this-plugin';
|
|
158
|
-
const resolvedVersion = version ?? report.manifest.version
|
|
195
|
+
const resolvedVersion = version ?? report.manifest.version;
|
|
196
|
+
// Do not build a tag for a version the preflight rejects. A dry run that
|
|
197
|
+
// printed `plugin-v01.2.3` was telling the author to run a command that npm
|
|
198
|
+
// would normalise away once the real release began.
|
|
199
|
+
const versionFailure = checkVersion({ version: resolvedVersion });
|
|
200
|
+
if (versionFailure !== null) {
|
|
201
|
+
return {
|
|
202
|
+
tag: null,
|
|
203
|
+
name: resolvedName,
|
|
204
|
+
version: resolvedVersion ?? '(no version)',
|
|
205
|
+
indexFile,
|
|
206
|
+
steps: [],
|
|
207
|
+
failures: [{ check: 'version', message: versionFailure }],
|
|
208
|
+
};
|
|
209
|
+
}
|
|
159
210
|
const tag = tagName(resolvedVersion, tagPrefix);
|
|
211
|
+
const tagFailure = tagNameIssue(tag);
|
|
212
|
+
if (tagFailure !== null) {
|
|
213
|
+
return {
|
|
214
|
+
tag: null,
|
|
215
|
+
name: resolvedName,
|
|
216
|
+
version: resolvedVersion,
|
|
217
|
+
indexFile,
|
|
218
|
+
steps: [],
|
|
219
|
+
failures: [{ check: 'tag', message: tagFailure }],
|
|
220
|
+
};
|
|
221
|
+
}
|
|
160
222
|
const steps = [
|
|
161
223
|
{ title: 'Read the manifest and check it can be loaded', command: 'dsh-plugin doctor', runs: true },
|
|
162
224
|
{ title: `Create the tag ${tag}`, command: `git tag ${tag}`, runs: true },
|
|
@@ -208,6 +270,10 @@ export async function release(options) {
|
|
|
208
270
|
const name = report.manifest.name;
|
|
209
271
|
const version = report.manifest.version;
|
|
210
272
|
const tag = tagName(version, tagPrefix);
|
|
273
|
+
const tagFailure = tagNameIssue(tag);
|
|
274
|
+
if (tagFailure !== null) {
|
|
275
|
+
return { ok: false, stage: 'tag', failures: [{ check: 'tag', message: tagFailure }] };
|
|
276
|
+
}
|
|
211
277
|
|
|
212
278
|
const resuming = tagExists(root, tag, gitRun) === true;
|
|
213
279
|
if (resuming === true && tagPointsAtHead(root, tag, gitRun) === false) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-toolkit",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.39",
|
|
4
4
|
"description": "Preflight, release and test DeepSeek Harness plugins: check a folder or any GitHub repository, wait for npm to actually serve the version, and keep the market index honest.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|