rman 1.0.12 → 1.2.1
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 +90 -70
- package/cli.js +226 -14
- package/commands/build.command.js +1 -0
- package/commands/changed.command.js +2 -2
- package/commands/changelog.command.js +13 -15
- package/commands/config.command.js +61 -0
- package/commands/diff.command.js +9 -4
- package/commands/exec.command.js +2 -8
- package/commands/github-release.command.js +1 -0
- package/commands/info.command.d.ts +9 -0
- package/commands/info.command.js +12 -2
- package/commands/run.command.js +5 -8
- package/commands/test.command.js +1 -0
- package/commands/version.command.js +53 -14
- package/constants.js +1 -1
- package/core/config.d.ts +265 -17
- package/core/config.js +651 -76
- package/core/custom-command.d.ts +133 -0
- package/core/custom-command.js +99 -0
- package/core/extends-config.d.ts +27 -0
- package/core/extends-config.js +89 -0
- package/core/manifest.d.ts +222 -0
- package/core/manifest.js +150 -0
- package/core/merge-config.d.ts +70 -0
- package/core/merge-config.js +193 -0
- package/core/package.d.ts +73 -7
- package/core/package.js +86 -24
- package/core/plugin.d.ts +112 -0
- package/core/plugin.js +189 -0
- package/core/repository.d.ts +91 -1
- package/core/repository.js +277 -132
- package/core/resolve-target.d.ts +12 -0
- package/core/resolve-target.js +33 -0
- package/core/run-step.d.ts +75 -0
- package/core/run-step.js +1 -0
- package/core/version-scheme.d.ts +134 -0
- package/core/version-scheme.js +148 -0
- package/core/workspace.d.ts +68 -0
- package/core/workspace.js +83 -0
- package/index.d.ts +55 -8
- package/index.js +42 -7
- package/interfaces/rman-config.interface.d.ts +222 -46
- package/package.json +16 -7
- package/services/change-hash.service.d.ts +88 -0
- package/services/change-hash.service.js +112 -0
- package/services/changelog.service.d.ts +8 -13
- package/services/changelog.service.js +12 -11
- package/services/conventional-commits.service.d.ts +73 -0
- package/services/conventional-commits.service.js +116 -0
- package/services/docker-publish.service.js +1 -1
- package/services/exec.service.js +1 -1
- package/services/github-release.service.d.ts +2 -2
- package/services/github-release.service.js +10 -5
- package/services/list.service.js +5 -2
- package/services/run.service.d.ts +112 -6
- package/services/run.service.js +265 -89
- package/services/system-info.d.ts +22 -7
- package/services/system-info.js +8 -23
- package/services/version-plan.service.d.ts +244 -0
- package/services/version-plan.service.js +414 -0
- package/services/version.service.d.ts +102 -82
- package/services/version.service.js +226 -434
- package/services.d.ts +5 -3
- package/services.js +5 -3
- package/utils/bin-path.d.ts +59 -0
- package/utils/bin-path.js +82 -0
- package/utils/child-tracker.d.ts +16 -0
- package/utils/child-tracker.js +30 -0
- package/utils/exec.d.ts +13 -2
- package/utils/exec.js +17 -17
- package/utils/git.d.ts +9 -3
- package/utils/git.js +10 -2
- package/utils/package-filter.d.ts +33 -2
- package/utils/package-filter.js +47 -7
- package/utils/printable-config.d.ts +15 -0
- package/utils/printable-config.js +42 -0
- package/utils/release-version.js +3 -3
- package/utils/run-bin.d.ts +46 -0
- package/utils/run-bin.js +63 -0
- package/utils/version-stamp.d.ts +14 -6
- package/utils/version-stamp.js +25 -13
- package/commands/ci.command.js +0 -30
- package/commands/clean.command.d.ts +0 -3
- package/commands/clean.command.js +0 -36
- package/commands/publish.command.d.ts +0 -3
- package/commands/publish.command.js +0 -225
- package/rmanrc.schema.json +0 -392
- package/services/ci.service.d.ts +0 -40
- package/services/ci.service.js +0 -204
- package/services/clean.service.d.ts +0 -42
- package/services/clean.service.js +0 -226
- package/services/publish.service.d.ts +0 -79
- package/services/publish.service.js +0 -273
- package/utils/change-hash.d.ts +0 -68
- package/utils/change-hash.js +0 -98
- package/utils/conventional-commits.d.ts +0 -52
- package/utils/conventional-commits.js +0 -90
- package/utils/npm-run-path.d.ts +0 -67
- package/utils/npm-run-path.js +0 -63
- package/utils/workspace-range.d.ts +0 -17
- package/utils/workspace-range.js +0 -28
- /package/commands/{ci.command.d.ts → config.command.d.ts} +0 -0
package/core/manifest.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { semverScheme } from './version-scheme.js';
|
|
3
|
+
/**
|
|
4
|
+
* The registry, merged onto the `Manifest` interface so one name carries both the shape and the
|
|
5
|
+
* operations - `Manifest.read(dir)` returns a `Manifest`.
|
|
6
|
+
*
|
|
7
|
+
* A namespace rather than loose `addManifestProvider`/`readManifest` functions because a namespace
|
|
8
|
+
* is what a plugin can *augment*: `declare module 'rman' { namespace Manifest { ... } }` is how
|
|
9
|
+
* `rman-node` already adds to `SystemInfo`, and anything this seam grows later can arrive the
|
|
10
|
+
* same way instead of as another top-level export.
|
|
11
|
+
*/
|
|
12
|
+
export var Manifest;
|
|
13
|
+
(function (Manifest) {
|
|
14
|
+
/** Registers a provider. Called by `loadPlugins` for each plugin's `manifest`, in `plugins`
|
|
15
|
+
* declaration order - so which one answers is a function of the repository's own config. */
|
|
16
|
+
function addProvider(provider) {
|
|
17
|
+
if (providers.includes(provider))
|
|
18
|
+
return;
|
|
19
|
+
providers.push(provider);
|
|
20
|
+
}
|
|
21
|
+
Manifest.addProvider = addProvider;
|
|
22
|
+
/** For tests, which would otherwise leak a provider into every later case in the process. */
|
|
23
|
+
function clearProviders() {
|
|
24
|
+
providers.length = 0;
|
|
25
|
+
}
|
|
26
|
+
Manifest.clearProviders = clearProviders;
|
|
27
|
+
/**
|
|
28
|
+
* Reads `dir`'s manifest through the first provider that recognizes it, with the scheme that
|
|
29
|
+
* provider brings.
|
|
30
|
+
*
|
|
31
|
+
* **With no provider registered, or none recognizing the directory**, the fallback is a package
|
|
32
|
+
* named after its own directory at version `0.0.0`. That is deliberately the least it can claim:
|
|
33
|
+
* the directory name is a fact, and `0.0.0` is the version a thing has when nothing says
|
|
34
|
+
* otherwise. The alternative - refusing to construct a package at all - would make `rman info` and
|
|
35
|
+
* `rman list` fail in a repository whose `.rmanrc` simply names no plugin yet, which is exactly
|
|
36
|
+
* when someone needs to run them.
|
|
37
|
+
*/
|
|
38
|
+
function read(dir) {
|
|
39
|
+
for (const provider of providers) {
|
|
40
|
+
const manifest = provider.read(dir);
|
|
41
|
+
if (manifest) {
|
|
42
|
+
return {
|
|
43
|
+
manifest,
|
|
44
|
+
versionScheme: provider.versionScheme ?? semverScheme,
|
|
45
|
+
fileName: provider.fileName,
|
|
46
|
+
provider: provider.name,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
manifest: { name: path.basename(dir), version: '0.0.0', raw: {} },
|
|
52
|
+
versionScheme: semverScheme,
|
|
53
|
+
/** Nothing was read, so nothing can be named - a caller listing "the file I changed" has no
|
|
54
|
+
* file to list, which is correct rather than a placeholder that does not exist. */
|
|
55
|
+
fileName: '',
|
|
56
|
+
/** Same reasoning: no provider claimed this directory, so it belongs to no ecosystem. Empty
|
|
57
|
+
* rather than a sentinel like `'unknown'`, which would read as an ecosystem's name and could
|
|
58
|
+
* collide with a real provider's. */
|
|
59
|
+
provider: '',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
Manifest.read = read;
|
|
63
|
+
/** Writes through whichever provider recognizes `dir`. Throws when none does: a write that lands
|
|
64
|
+
* nowhere is worse than one that fails, since the caller has already decided the new version. */
|
|
65
|
+
function write(dir, manifest) {
|
|
66
|
+
for (const provider of providers) {
|
|
67
|
+
if (provider.read(dir)) {
|
|
68
|
+
provider.write(dir, manifest);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
throw new Error(`No manifest provider recognizes "${dir}", so there is nowhere to write its version.\n` +
|
|
73
|
+
` A repository's ".rmanrc" names its providers - see "plugins" (e.g. ['rman-node']).`);
|
|
74
|
+
}
|
|
75
|
+
Manifest.write = write;
|
|
76
|
+
/**
|
|
77
|
+
* The packages `pkg` declares a dependency on, via whichever provider recognizes it.
|
|
78
|
+
*
|
|
79
|
+
* No provider, or one with no opinion, means no declared dependencies - `.rmanrc "dependencies"`
|
|
80
|
+
* is then the only source, which is exactly right: a repository rman cannot read the manifests
|
|
81
|
+
* of can still describe its own graph by hand.
|
|
82
|
+
*/
|
|
83
|
+
function dependenciesOf(pkg, candidates) {
|
|
84
|
+
return providerOf(pkg)?.dependencies?.(pkg.manifest, candidates) ?? [];
|
|
85
|
+
}
|
|
86
|
+
Manifest.dependenciesOf = dependenciesOf;
|
|
87
|
+
/** `${{ pkg.scope }}`/`${{ pkg.unscopedName }}`, by whichever provider recognizes `dir` - and
|
|
88
|
+
* "no scope, the name is its own unscoped form" when none has an opinion. */
|
|
89
|
+
function splitName(dir, name) {
|
|
90
|
+
for (const provider of providers) {
|
|
91
|
+
if (!provider.read(dir))
|
|
92
|
+
continue;
|
|
93
|
+
return provider.splitName?.(name) ?? { unscopedName: name };
|
|
94
|
+
}
|
|
95
|
+
return { unscopedName: name };
|
|
96
|
+
}
|
|
97
|
+
Manifest.splitName = splitName;
|
|
98
|
+
/**
|
|
99
|
+
* Refreshes `pkg`'s references to the packages in `bumped`, via whichever provider recognizes it.
|
|
100
|
+
*
|
|
101
|
+
* No provider, or one without an opinion, means nothing to rewrite - a repository whose packages
|
|
102
|
+
* reference each other by path has nothing here to go stale.
|
|
103
|
+
*/
|
|
104
|
+
function updateDependencyVersions(pkg, bumped) {
|
|
105
|
+
providerOf(pkg)?.updateDependencyVersions?.(pkg.manifest, bumped);
|
|
106
|
+
}
|
|
107
|
+
Manifest.updateDependencyVersions = updateDependencyVersions;
|
|
108
|
+
/**
|
|
109
|
+
* Rewrites a hard-coded version in `content` through `pkg`'s own ecosystem - see
|
|
110
|
+
* `ManifestProvider.stampVersion`.
|
|
111
|
+
*
|
|
112
|
+
* `undefined` covers three cases the caller has to tell apart from each other, and cannot: no
|
|
113
|
+
* provider claimed the package, the provider has no opinion about stamping, or it looked and found
|
|
114
|
+
* nothing to change. All three mean "this file was not stamped", which is what `version` reports.
|
|
115
|
+
*/
|
|
116
|
+
function stampVersion(pkg, file, content, version, options) {
|
|
117
|
+
return providerOf(pkg)?.stampVersion?.(file, content, version, options);
|
|
118
|
+
}
|
|
119
|
+
Manifest.stampVersion = stampVersion;
|
|
120
|
+
/**
|
|
121
|
+
* What `pkg`'s own ecosystem's registry says its current version is - see
|
|
122
|
+
* `ManifestProvider.publishedVersion` for the one thing this is for and the one thing it must
|
|
123
|
+
* never be used for.
|
|
124
|
+
*
|
|
125
|
+
* `undefined` when the provider has no opinion, which includes every repository that names no
|
|
126
|
+
* plugin: git tags then answer the boundary question alone.
|
|
127
|
+
*/
|
|
128
|
+
async function publishedVersion(pkg) {
|
|
129
|
+
return providerOf(pkg)?.publishedVersion?.(pkg);
|
|
130
|
+
}
|
|
131
|
+
Manifest.publishedVersion = publishedVersion;
|
|
132
|
+
/** The file names providers look for, for an error message that can say what was expected. */
|
|
133
|
+
function fileNames() {
|
|
134
|
+
return providers.map(p => p.fileName);
|
|
135
|
+
}
|
|
136
|
+
Manifest.fileNames = fileNames;
|
|
137
|
+
const providers = [];
|
|
138
|
+
/**
|
|
139
|
+
* The provider that claimed `pkg`, found by the name it reported as `pkg.provider` - exact, and
|
|
140
|
+
* without re-reading the manifest off disk to work it out again.
|
|
141
|
+
*
|
|
142
|
+
* The probe is the fallback, not the rule: it covers a package constructed *before* its provider
|
|
143
|
+
* was registered, which `Repository.create` cannot produce (plugins load first) but a test
|
|
144
|
+
* arranging providers by hand can.
|
|
145
|
+
*/
|
|
146
|
+
function providerOf(pkg) {
|
|
147
|
+
const byName = pkg.provider ? providers.find(p => p.name === pkg.provider) : undefined;
|
|
148
|
+
return byName ?? providers.find(p => p.read(pkg.dirname));
|
|
149
|
+
}
|
|
150
|
+
})(Manifest || (Manifest = {}));
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** The prefix that turns a key into an append instead of a replacement: `+before` adds to whatever
|
|
2
|
+
* `before` already resolved to, rather than taking its place. */
|
|
3
|
+
export declare const APPEND_PREFIX = "+";
|
|
4
|
+
/**
|
|
5
|
+
* Keys that **append whether or not you ask** - `+plugins` is accepted and means nothing extra.
|
|
6
|
+
*
|
|
7
|
+
* `plugins` is the whole list because it is the one key where replacing is never what anyone meant:
|
|
8
|
+
* every other setting has a value a closer layer can sensibly overrule, while a plugin *adds
|
|
9
|
+
* commands and seams*, and a repository naming one has no wish to lose the ones its shared config
|
|
10
|
+
* brought. Replacing was the silent failure - `extends`-ing a toolchain config and then adding a
|
|
11
|
+
* plugin of your own dropped the toolchain's, and what you noticed was `Unknown argument: publish`.
|
|
12
|
+
*
|
|
13
|
+
* Do not extend this list casually: a key that always appends can never be *un*-said by a closer
|
|
14
|
+
* layer, which is only acceptable where the value is a set of contributions rather than a decision.
|
|
15
|
+
*/
|
|
16
|
+
export declare const ALWAYS_APPEND: readonly string[];
|
|
17
|
+
/**
|
|
18
|
+
* Where a value function keeps the value it is replacing, so it can be handed back as `value`.
|
|
19
|
+
*
|
|
20
|
+
* A **symbol on a forwarding wrapper**, rather than a class or a `{fn, prev}` object, for one
|
|
21
|
+
* concrete reason: every walker in this file and in `config.ts` decides what to do by asking
|
|
22
|
+
* `isPlainObject`, and a wrapper object would answer yes - `finalizeConfig` would rebuild it as a
|
|
23
|
+
* plain object and lose the function, and `mergeConfig` would try to merge into it key by key. A
|
|
24
|
+
* function is not a plain object, so it travels through all of them untouched.
|
|
25
|
+
*
|
|
26
|
+
* The user's own function is never mutated: two packages inheriting the same shared-config function
|
|
27
|
+
* would otherwise share - and overwrite - one `prev`.
|
|
28
|
+
*/
|
|
29
|
+
export declare const PREVIOUS_VALUE: unique symbol;
|
|
30
|
+
/** `"+before"` -> `"before"`, or `undefined` for a key that isn't an append. */
|
|
31
|
+
export declare function appendTarget(key: string): string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Merges `source` onto `target` in place, the way every layer of rman config is combined - a
|
|
34
|
+
* directory's own file forms, the directory chain, `"[selector]"` blocks, and an `extends` base.
|
|
35
|
+
* One implementation for all of them, so they cannot disagree about what an append means.
|
|
36
|
+
*
|
|
37
|
+
* Plain keys replace, and nested objects merge recursively, as a deep merge always has. What this
|
|
38
|
+
* adds is `+key`:
|
|
39
|
+
*
|
|
40
|
+
* ```yaml
|
|
41
|
+
* # the root says before: "rm ./build"
|
|
42
|
+
* # a package adds +before: "rm ./cache"
|
|
43
|
+
* # it resolves to before: ["rm ./build", "rm ./cache"]
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* Appending is the half a shared config can't live without: a base that declares
|
|
47
|
+
* `before: ["rm ./build"]` otherwise forces every repository wanting one more step to restate the
|
|
48
|
+
* whole list - which is a copy of the base, silently frozen at the version it was copied from.
|
|
49
|
+
*
|
|
50
|
+
* A scalar is promoted to a list on the way, so neither side has to be written as an array. With
|
|
51
|
+
* nothing inherited, `+key` simply produces a one-element list.
|
|
52
|
+
*
|
|
53
|
+
* On a value that isn't a list, the prefix is **ignored** rather than an error, because there the
|
|
54
|
+
* two spellings already mean the same thing: objects merge whether or not you asked them to, and a
|
|
55
|
+
* scalar has nothing to append to, so `+key` behaves exactly as `key` would. Nothing is silently
|
|
56
|
+
* dropped - the value still lands.
|
|
57
|
+
*
|
|
58
|
+
* `key` and `+key` in the same object are both honored, in that order: the replacement happens
|
|
59
|
+
* first, then the append lands on top of it.
|
|
60
|
+
*/
|
|
61
|
+
export declare function mergeConfig(target: Record<string, any>, source: Record<string, any>): Record<string, any>;
|
|
62
|
+
/**
|
|
63
|
+
* Turns any `+key` still outstanding into its plain key, as a list - the "nothing was inherited"
|
|
64
|
+
* case, where an append simply is the whole value.
|
|
65
|
+
*
|
|
66
|
+
* Called once on a fully resolved config, and only there: until then an outstanding append may
|
|
67
|
+
* still find the layer it belongs to, and a config handed to a command must carry no `+key` at all
|
|
68
|
+
* or every reader would have to know about them.
|
|
69
|
+
*/
|
|
70
|
+
export declare function finalizeConfig<T>(config: T): T;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/** The prefix that turns a key into an append instead of a replacement: `+before` adds to whatever
|
|
2
|
+
* `before` already resolved to, rather than taking its place. */
|
|
3
|
+
export const APPEND_PREFIX = '+';
|
|
4
|
+
/**
|
|
5
|
+
* Keys that **append whether or not you ask** - `+plugins` is accepted and means nothing extra.
|
|
6
|
+
*
|
|
7
|
+
* `plugins` is the whole list because it is the one key where replacing is never what anyone meant:
|
|
8
|
+
* every other setting has a value a closer layer can sensibly overrule, while a plugin *adds
|
|
9
|
+
* commands and seams*, and a repository naming one has no wish to lose the ones its shared config
|
|
10
|
+
* brought. Replacing was the silent failure - `extends`-ing a toolchain config and then adding a
|
|
11
|
+
* plugin of your own dropped the toolchain's, and what you noticed was `Unknown argument: publish`.
|
|
12
|
+
*
|
|
13
|
+
* Do not extend this list casually: a key that always appends can never be *un*-said by a closer
|
|
14
|
+
* layer, which is only acceptable where the value is a set of contributions rather than a decision.
|
|
15
|
+
*/
|
|
16
|
+
export const ALWAYS_APPEND = ['plugins'];
|
|
17
|
+
/**
|
|
18
|
+
* Where a value function keeps the value it is replacing, so it can be handed back as `value`.
|
|
19
|
+
*
|
|
20
|
+
* A **symbol on a forwarding wrapper**, rather than a class or a `{fn, prev}` object, for one
|
|
21
|
+
* concrete reason: every walker in this file and in `config.ts` decides what to do by asking
|
|
22
|
+
* `isPlainObject`, and a wrapper object would answer yes - `finalizeConfig` would rebuild it as a
|
|
23
|
+
* plain object and lose the function, and `mergeConfig` would try to merge into it key by key. A
|
|
24
|
+
* function is not a plain object, so it travels through all of them untouched.
|
|
25
|
+
*
|
|
26
|
+
* The user's own function is never mutated: two packages inheriting the same shared-config function
|
|
27
|
+
* would otherwise share - and overwrite - one `prev`.
|
|
28
|
+
*/
|
|
29
|
+
export const PREVIOUS_VALUE = Symbol('rman.previousValue');
|
|
30
|
+
/** `"+before"` -> `"before"`, or `undefined` for a key that isn't an append. */
|
|
31
|
+
export function appendTarget(key) {
|
|
32
|
+
return key.length > APPEND_PREFIX.length && key.startsWith(APPEND_PREFIX)
|
|
33
|
+
? key.slice(APPEND_PREFIX.length)
|
|
34
|
+
: undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Merges `source` onto `target` in place, the way every layer of rman config is combined - a
|
|
38
|
+
* directory's own file forms, the directory chain, `"[selector]"` blocks, and an `extends` base.
|
|
39
|
+
* One implementation for all of them, so they cannot disagree about what an append means.
|
|
40
|
+
*
|
|
41
|
+
* Plain keys replace, and nested objects merge recursively, as a deep merge always has. What this
|
|
42
|
+
* adds is `+key`:
|
|
43
|
+
*
|
|
44
|
+
* ```yaml
|
|
45
|
+
* # the root says before: "rm ./build"
|
|
46
|
+
* # a package adds +before: "rm ./cache"
|
|
47
|
+
* # it resolves to before: ["rm ./build", "rm ./cache"]
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* Appending is the half a shared config can't live without: a base that declares
|
|
51
|
+
* `before: ["rm ./build"]` otherwise forces every repository wanting one more step to restate the
|
|
52
|
+
* whole list - which is a copy of the base, silently frozen at the version it was copied from.
|
|
53
|
+
*
|
|
54
|
+
* A scalar is promoted to a list on the way, so neither side has to be written as an array. With
|
|
55
|
+
* nothing inherited, `+key` simply produces a one-element list.
|
|
56
|
+
*
|
|
57
|
+
* On a value that isn't a list, the prefix is **ignored** rather than an error, because there the
|
|
58
|
+
* two spellings already mean the same thing: objects merge whether or not you asked them to, and a
|
|
59
|
+
* scalar has nothing to append to, so `+key` behaves exactly as `key` would. Nothing is silently
|
|
60
|
+
* dropped - the value still lands.
|
|
61
|
+
*
|
|
62
|
+
* `key` and `+key` in the same object are both honored, in that order: the replacement happens
|
|
63
|
+
* first, then the append lands on top of it.
|
|
64
|
+
*/
|
|
65
|
+
export function mergeConfig(target, source) {
|
|
66
|
+
// Plain keys first, so a `+key` alongside its own `key` appends to that replacement rather than
|
|
67
|
+
// to whatever the previous layer had.
|
|
68
|
+
for (const [key, value] of Object.entries(source)) {
|
|
69
|
+
if (appendTarget(key))
|
|
70
|
+
continue;
|
|
71
|
+
/** `plugins`: additive at every layer, so the closer one adds rather than takes over. */
|
|
72
|
+
if (ALWAYS_APPEND.includes(key)) {
|
|
73
|
+
appendList(target, key, value);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
assignMerged(target, key, value);
|
|
77
|
+
}
|
|
78
|
+
for (const [key, value] of Object.entries(source)) {
|
|
79
|
+
const plain = appendTarget(key);
|
|
80
|
+
if (!plain)
|
|
81
|
+
continue;
|
|
82
|
+
// An object merges either way, so the prefix asks for nothing extra - resolve it now and let
|
|
83
|
+
// the two spellings coincide.
|
|
84
|
+
if (isPlainObject(value) || isPlainObject(target[plain])) {
|
|
85
|
+
assignMerged(target, plain, value);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (plain in target) {
|
|
89
|
+
appendList(target, plain, value);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
/** Nothing to append to *yet*. Kept as an append rather than collapsed into the plain key,
|
|
93
|
+
* because the layer that provides it may still be coming: a directory's own file forms are
|
|
94
|
+
* merged into an empty object long before the selector blocks and parent directories they
|
|
95
|
+
* append to are. Collapsing here lost both of those - measured. `finalizeConfig` turns
|
|
96
|
+
* whatever is still outstanding at the end into a plain list. */
|
|
97
|
+
target[key] = [...toList(target[key] ?? []), ...toList(value)];
|
|
98
|
+
}
|
|
99
|
+
return target;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Turns any `+key` still outstanding into its plain key, as a list - the "nothing was inherited"
|
|
103
|
+
* case, where an append simply is the whole value.
|
|
104
|
+
*
|
|
105
|
+
* Called once on a fully resolved config, and only there: until then an outstanding append may
|
|
106
|
+
* still find the layer it belongs to, and a config handed to a command must carry no `+key` at all
|
|
107
|
+
* or every reader would have to know about them.
|
|
108
|
+
*/
|
|
109
|
+
export function finalizeConfig(config) {
|
|
110
|
+
if (Array.isArray(config))
|
|
111
|
+
return config.map(finalizeConfig);
|
|
112
|
+
if (!isPlainObject(config))
|
|
113
|
+
return config;
|
|
114
|
+
const result = {};
|
|
115
|
+
for (const [key, value] of Object.entries(config)) {
|
|
116
|
+
const plain = appendTarget(key);
|
|
117
|
+
if (!plain) {
|
|
118
|
+
result[key] = finalizeConfig(value);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const pending = finalizeConfig(value);
|
|
122
|
+
result[plain] = plain in result ? [...toList(result[plain]), ...toList(pending)] : toList(pending);
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
function assignMerged(target, key, value) {
|
|
127
|
+
if (isPlainObject(value)) {
|
|
128
|
+
if (!isPlainObject(target[key]))
|
|
129
|
+
target[key] = {};
|
|
130
|
+
mergeConfig(target[key], value);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* A function **replaces** like any other value - and remembers what it replaced, so it can be
|
|
135
|
+
* given it back as `value` when the config resolves:
|
|
136
|
+
*
|
|
137
|
+
* ```js
|
|
138
|
+
* '[*]': { clean: { include: ({ vars }) => [vars.buildDir] } }
|
|
139
|
+
* '[ws:*]': { clean: { include: ({ value, pkg }) => [...value, pkg.basename + '.log'] } }
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* Chained here rather than at resolution time because only the merge knows the order of the
|
|
143
|
+
* layers - by the time `interpolateConfig` sees the config they have collapsed into one object,
|
|
144
|
+
* and whatever a closer layer said has already taken the place of what it was derived from.
|
|
145
|
+
*/
|
|
146
|
+
if (typeof value === 'function') {
|
|
147
|
+
target[key] = chainValueFn(value, target[key]);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
target[key] = Array.isArray(value) ? [...value] : value;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Wraps `fn` so it carries `previous`, leaving `fn` itself alone.
|
|
154
|
+
*
|
|
155
|
+
* The wrapper forwards every argument unchanged, which is what lets one rule cover both kinds of
|
|
156
|
+
* function a config can hold: a **value** function is called by `interpolateConfig` with the config
|
|
157
|
+
* scope, a **step** function by `RunService` with a `RunStepContext`, and neither needs to know it
|
|
158
|
+
* has been wrapped. `name` is copied over because a step's label is its function's name.
|
|
159
|
+
*/
|
|
160
|
+
function chainValueFn(fn, previous) {
|
|
161
|
+
const wrapper = (...args) => fn(...args);
|
|
162
|
+
Object.defineProperty(wrapper, 'name', { value: fn.name, configurable: true });
|
|
163
|
+
/** Only when there *is* one: an own property set to `undefined` is indistinguishable from an
|
|
164
|
+
* inherited value that genuinely resolved to nothing. */
|
|
165
|
+
if (previous !== undefined)
|
|
166
|
+
Object.defineProperty(wrapper, PREVIOUS_VALUE, { value: previous });
|
|
167
|
+
return wrapper;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Appends `value` to `target[key]`, de-duplicating **only** an `ALWAYS_APPEND` key.
|
|
171
|
+
*
|
|
172
|
+
* That asymmetry is the point. `plugins` appends without being asked, so a repository and the config
|
|
173
|
+
* it extends both naming `'rman-node'` is the ordinary case rather than a mistake, and the list is
|
|
174
|
+
* also what `rman config` prints. An explicit `+before`, by contrast, was *written* - repeating a
|
|
175
|
+
* step that is already there is a strange thing to ask for, but it is what was asked for, and
|
|
176
|
+
* silently collapsing it would make one layer's list depend on another's contents.
|
|
177
|
+
*
|
|
178
|
+
* By identity (`===`), which covers a string by value and a plugin object by reference; two
|
|
179
|
+
* *different* objects claiming one plugin name are caught where it counts, at registration - see
|
|
180
|
+
* `loadPlugins`.
|
|
181
|
+
*/
|
|
182
|
+
function appendList(target, key, value) {
|
|
183
|
+
const merged = [...toList(target[key] ?? []), ...toList(value)];
|
|
184
|
+
target[key] = ALWAYS_APPEND.includes(key) ? merged.filter((entry, at) => merged.indexOf(entry) === at) : merged;
|
|
185
|
+
}
|
|
186
|
+
function toList(value) {
|
|
187
|
+
return Array.isArray(value) ? value : [value];
|
|
188
|
+
}
|
|
189
|
+
/** A config object, as opposed to an array or anything with its own prototype - only the former
|
|
190
|
+
* merges key by key. */
|
|
191
|
+
function isPlainObject(value) {
|
|
192
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
193
|
+
}
|
package/core/package.d.ts
CHANGED
|
@@ -1,17 +1,83 @@
|
|
|
1
1
|
import type { RmanConfig } from '../interfaces/rman-config.interface.js';
|
|
2
|
+
import { Manifest } from './manifest.js';
|
|
3
|
+
import type { Repository } from './repository.js';
|
|
4
|
+
import { type VersionScheme } from './version-scheme.js';
|
|
2
5
|
export declare class Package {
|
|
3
6
|
readonly dirname: string;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
/**
|
|
8
|
+
* This package's identity, read through whichever `ManifestProvider` recognizes its directory.
|
|
9
|
+
*
|
|
10
|
+
* There is no `json` here any more, and that is the point: `package.json` is npm's answer to
|
|
11
|
+
* "where is a package's name and version written", not rman's. `manifest.raw` is still the whole
|
|
12
|
+
* document for a command that knows its own ecosystem - `rman-node` reads `scripts` and
|
|
13
|
+
* `publishConfig` off it - but the core only ever touches `name`, `version` and `private`.
|
|
14
|
+
*/
|
|
15
|
+
manifest: Manifest;
|
|
16
|
+
/**
|
|
17
|
+
* In-repo packages this one depends on - **the full transitive closure**, not just its direct
|
|
18
|
+
* dependencies (see `Repository._updateDependencies`).
|
|
19
|
+
*
|
|
20
|
+
* References, not names: a name is only an identifier if the ecosystem guarantees uniqueness,
|
|
21
|
+
* which npm does and others do not - Go identifies a module by import path, and nothing stops a
|
|
22
|
+
* repository from holding two packages whose short names collide. A `Package` is unambiguous
|
|
23
|
+
* whatever the ecosystem, and comparing by identity removes a lookup from every consumer.
|
|
24
|
+
*/
|
|
25
|
+
dependencies: Package[];
|
|
26
|
+
/** Effective rman config for this package, cascaded from the repository root, with every
|
|
27
|
+
* `${{ ... }}` expression already evaluated. */
|
|
7
28
|
config: RmanConfig;
|
|
29
|
+
/**
|
|
30
|
+
* The repository this package belongs to - so anything holding a package can reach the whole
|
|
31
|
+
* picture (its siblings, the root's config, git) without being handed it separately.
|
|
32
|
+
*
|
|
33
|
+
* Assigned by `Repository.create` rather than taken as a constructor argument, and it has to be:
|
|
34
|
+
* `Repository extends Package`, so a repository constructing itself runs this constructor before
|
|
35
|
+
* it exists to be passed in. A repository's own is itself.
|
|
36
|
+
*/
|
|
37
|
+
repository: Repository;
|
|
38
|
+
/**
|
|
39
|
+
* The package whose directory contains this one - the repository root for an ordinary member, and
|
|
40
|
+
* a genuine enclosing package for one nested inside another (which `Repository.currentPackage`
|
|
41
|
+
* already has to reason about). `undefined` for the root itself, which nothing contains.
|
|
42
|
+
*/
|
|
43
|
+
parent?: Package;
|
|
44
|
+
/**
|
|
45
|
+
* How this package's versions are numbered - `pkg.versionScheme.next(pkg.version, 'minor')`.
|
|
46
|
+
*
|
|
47
|
+
* Comes from the same provider that read the manifest, because the ecosystem that decides where
|
|
48
|
+
* a version is written is the one that decides how it is numbered - a `pyproject.toml` read with
|
|
49
|
+
* semver's arithmetic would be a pair that never occurs in reality.
|
|
50
|
+
*
|
|
51
|
+
* Defaults to semver, so this seam existing changes nothing. **A group must not mix schemes** -
|
|
52
|
+
* a group is one version line, and comparing across schemes is meaningless; `assertOneScheme`
|
|
53
|
+
* refuses it rather than acting on whatever falls out.
|
|
54
|
+
*/
|
|
55
|
+
versionScheme: VersionScheme;
|
|
56
|
+
/** The file the manifest was read from, absolute - for a command that has to say which file it
|
|
57
|
+
* changed (a commit's path list). Empty when no provider recognized this directory. */
|
|
58
|
+
manifestFileName: string;
|
|
59
|
+
/**
|
|
60
|
+
* **Which ecosystem this package belongs to** - `'node'` for one read by `rman-node`, from the
|
|
61
|
+
* `ManifestProvider.name` that claimed the directory. Empty when no provider did.
|
|
62
|
+
*
|
|
63
|
+
* The escape hatch for code that legitimately knows one technology: `if (pkg.provider === 'node')`
|
|
64
|
+
* before reaching into `manifest.raw` for something only npm has. Per *package*, not per
|
|
65
|
+
* repository, because `Manifest.read` asks per directory - a polyglot monorepo can hold a `node`
|
|
66
|
+
* package beside a `cargo` one, and a command sweeping over `getPackages()` has to be able to
|
|
67
|
+
* tell.
|
|
68
|
+
*
|
|
69
|
+
* Not a union type on purpose: the set of ecosystems is whatever the repository's `plugins`
|
|
70
|
+
* contribute, so narrowing it here would mean the core listing plugins it cannot know about.
|
|
71
|
+
*/
|
|
72
|
+
provider: string;
|
|
8
73
|
constructor(dirname: string);
|
|
9
74
|
get basename(): string;
|
|
10
75
|
get name(): string;
|
|
11
76
|
get version(): string;
|
|
12
|
-
get json(): any;
|
|
13
|
-
get jsonFileName(): string;
|
|
14
77
|
get isPrivate(): boolean;
|
|
15
|
-
|
|
16
|
-
|
|
78
|
+
/** Re-reads from disk - for a command that has just written the manifest itself and wants the
|
|
79
|
+
* package to agree with the file again. */
|
|
80
|
+
reloadManifest(): Manifest;
|
|
81
|
+
/** Writes the current manifest back through its provider. */
|
|
82
|
+
writeManifest(): void;
|
|
17
83
|
}
|
package/core/package.js
CHANGED
|
@@ -1,44 +1,106 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
1
|
import path from 'path';
|
|
2
|
+
import { Manifest } from './manifest.js';
|
|
3
|
+
import { semverScheme } from './version-scheme.js';
|
|
3
4
|
export class Package {
|
|
4
5
|
dirname;
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* This package's identity, read through whichever `ManifestProvider` recognizes its directory.
|
|
8
|
+
*
|
|
9
|
+
* There is no `json` here any more, and that is the point: `package.json` is npm's answer to
|
|
10
|
+
* "where is a package's name and version written", not rman's. `manifest.raw` is still the whole
|
|
11
|
+
* document for a command that knows its own ecosystem - `rman-node` reads `scripts` and
|
|
12
|
+
* `publishConfig` off it - but the core only ever touches `name`, `version` and `private`.
|
|
13
|
+
*/
|
|
14
|
+
manifest;
|
|
15
|
+
/**
|
|
16
|
+
* In-repo packages this one depends on - **the full transitive closure**, not just its direct
|
|
17
|
+
* dependencies (see `Repository._updateDependencies`).
|
|
18
|
+
*
|
|
19
|
+
* References, not names: a name is only an identifier if the ecosystem guarantees uniqueness,
|
|
20
|
+
* which npm does and others do not - Go identifies a module by import path, and nothing stops a
|
|
21
|
+
* repository from holding two packages whose short names collide. A `Package` is unambiguous
|
|
22
|
+
* whatever the ecosystem, and comparing by identity removes a lookup from every consumer.
|
|
23
|
+
*/
|
|
6
24
|
dependencies = [];
|
|
7
|
-
/** Effective rman config for this package, cascaded from the repository root
|
|
25
|
+
/** Effective rman config for this package, cascaded from the repository root, with every
|
|
26
|
+
* `${{ ... }}` expression already evaluated. */
|
|
8
27
|
config = {};
|
|
28
|
+
/**
|
|
29
|
+
* The repository this package belongs to - so anything holding a package can reach the whole
|
|
30
|
+
* picture (its siblings, the root's config, git) without being handed it separately.
|
|
31
|
+
*
|
|
32
|
+
* Assigned by `Repository.create` rather than taken as a constructor argument, and it has to be:
|
|
33
|
+
* `Repository extends Package`, so a repository constructing itself runs this constructor before
|
|
34
|
+
* it exists to be passed in. A repository's own is itself.
|
|
35
|
+
*/
|
|
36
|
+
repository;
|
|
37
|
+
/**
|
|
38
|
+
* The package whose directory contains this one - the repository root for an ordinary member, and
|
|
39
|
+
* a genuine enclosing package for one nested inside another (which `Repository.currentPackage`
|
|
40
|
+
* already has to reason about). `undefined` for the root itself, which nothing contains.
|
|
41
|
+
*/
|
|
42
|
+
parent;
|
|
43
|
+
/**
|
|
44
|
+
* How this package's versions are numbered - `pkg.versionScheme.next(pkg.version, 'minor')`.
|
|
45
|
+
*
|
|
46
|
+
* Comes from the same provider that read the manifest, because the ecosystem that decides where
|
|
47
|
+
* a version is written is the one that decides how it is numbered - a `pyproject.toml` read with
|
|
48
|
+
* semver's arithmetic would be a pair that never occurs in reality.
|
|
49
|
+
*
|
|
50
|
+
* Defaults to semver, so this seam existing changes nothing. **A group must not mix schemes** -
|
|
51
|
+
* a group is one version line, and comparing across schemes is meaningless; `assertOneScheme`
|
|
52
|
+
* refuses it rather than acting on whatever falls out.
|
|
53
|
+
*/
|
|
54
|
+
versionScheme = semverScheme;
|
|
55
|
+
/** The file the manifest was read from, absolute - for a command that has to say which file it
|
|
56
|
+
* changed (a commit's path list). Empty when no provider recognized this directory. */
|
|
57
|
+
manifestFileName;
|
|
58
|
+
/**
|
|
59
|
+
* **Which ecosystem this package belongs to** - `'node'` for one read by `rman-node`, from the
|
|
60
|
+
* `ManifestProvider.name` that claimed the directory. Empty when no provider did.
|
|
61
|
+
*
|
|
62
|
+
* The escape hatch for code that legitimately knows one technology: `if (pkg.provider === 'node')`
|
|
63
|
+
* before reaching into `manifest.raw` for something only npm has. Per *package*, not per
|
|
64
|
+
* repository, because `Manifest.read` asks per directory - a polyglot monorepo can hold a `node`
|
|
65
|
+
* package beside a `cargo` one, and a command sweeping over `getPackages()` has to be able to
|
|
66
|
+
* tell.
|
|
67
|
+
*
|
|
68
|
+
* Not a union type on purpose: the set of ecosystems is whatever the repository's `plugins`
|
|
69
|
+
* contribute, so narrowing it here would mean the core listing plugins it cannot know about.
|
|
70
|
+
*/
|
|
71
|
+
provider;
|
|
9
72
|
constructor(dirname) {
|
|
10
73
|
this.dirname = dirname;
|
|
11
|
-
|
|
74
|
+
const { manifest, versionScheme, fileName, provider } = Manifest.read(dirname);
|
|
75
|
+
this.manifest = manifest;
|
|
76
|
+
this.versionScheme = versionScheme;
|
|
77
|
+
this.manifestFileName = fileName ? path.join(dirname, fileName) : '';
|
|
78
|
+
this.provider = provider;
|
|
12
79
|
}
|
|
13
80
|
get basename() {
|
|
14
81
|
return path.basename(this.dirname);
|
|
15
82
|
}
|
|
16
83
|
get name() {
|
|
17
|
-
return this.
|
|
84
|
+
return this.manifest.name;
|
|
18
85
|
}
|
|
19
86
|
get version() {
|
|
20
|
-
return this.
|
|
21
|
-
}
|
|
22
|
-
get json() {
|
|
23
|
-
return this._json;
|
|
24
|
-
}
|
|
25
|
-
get jsonFileName() {
|
|
26
|
-
return path.join(this.dirname, 'package.json');
|
|
87
|
+
return this.manifest.version;
|
|
27
88
|
}
|
|
28
89
|
get isPrivate() {
|
|
29
|
-
return !!this.
|
|
90
|
+
return !!this.manifest.private;
|
|
30
91
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.
|
|
37
|
-
|
|
92
|
+
/** Re-reads from disk - for a command that has just written the manifest itself and wants the
|
|
93
|
+
* package to agree with the file again. */
|
|
94
|
+
reloadManifest() {
|
|
95
|
+
const { manifest, versionScheme, fileName, provider } = Manifest.read(this.dirname);
|
|
96
|
+
this.manifest = manifest;
|
|
97
|
+
this.versionScheme = versionScheme;
|
|
98
|
+
this.manifestFileName = fileName ? path.join(this.dirname, fileName) : '';
|
|
99
|
+
this.provider = provider;
|
|
100
|
+
return this.manifest;
|
|
38
101
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
fs.writeFileSync(f, data, 'utf-8');
|
|
102
|
+
/** Writes the current manifest back through its provider. */
|
|
103
|
+
writeManifest() {
|
|
104
|
+
Manifest.write(this.dirname, this.manifest);
|
|
43
105
|
}
|
|
44
106
|
}
|