@iwsdk/cli 1.1.0 → 1.2.0-rc.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 +79 -2
- package/dist/agent-adapters.d.ts +12 -1
- package/dist/agent-adapters.d.ts.map +1 -1
- package/dist/agent-guidance/files/.agents/skills/iwsdk-build-model/SKILL.md +312 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-build-model/agents/openai.yaml +4 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-build-model/assets/hardsurface.ts.template +599 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-compose-scene/SKILL.md +277 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-compose-scene/agents/openai.yaml +4 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-compose-scene/references/environment-recipes.md +234 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-compose-scene/references/extended-workflow.md +166 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-compose-scene/references/image-intake.md +190 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-compose-scene/references/scene-composition.md +80 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-compose-scene/references/scene-format.md +466 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-compose-scene/references/scene-review.md +66 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-compose-scene/references/text-intake.md +80 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-debug/SKILL.md +74 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-depth-occlusion/SKILL.md +88 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-dev/SKILL.md +46 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-dev/references/api-reference.md +1531 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-dev/references/headless-rendering.md +82 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-dev/references/iterate.md +263 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-dev/references/planner.md +307 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-glasses-test/SKILL.md +282 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-grab/SKILL.md +75 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-hosting/SKILL.md +178 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-hosting/references/existing-hosts.md +181 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-hosting/references/vercel.md +114 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-native-xr-test/SKILL.md +262 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-physics/SKILL.md +106 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-physics/references/component-reference.md +152 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-physics/references/tuning-and-config.md +101 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-physics/references/workflows.md +303 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-pwa-packaging/SKILL.md +219 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-pwa-packaging/references/app-modes.md +104 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-pwa-packaging/references/bubblewrap.md +219 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-pwa-packaging/references/manifest-and-icons.md +149 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-pwa-packaging/references/store-upload.md +104 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-pwa-packaging/references/troubleshooting.md +178 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-ray/SKILL.md +70 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-ui/SKILL.md +328 -0
- package/dist/agent-guidance/files/.agents/skills/iwsdk-upgrade/SKILL.md +74 -0
- package/dist/agent-guidance/files/.claude/agents/iwsdk-project-code-reviewer.md +521 -0
- package/dist/agent-guidance/files/.claude/rules/assets-and-manifest.md +60 -0
- package/dist/agent-guidance/files/.claude/rules/ecs-api.md +103 -0
- package/dist/agent-guidance/files/.claude/rules/scene-json.md +72 -0
- package/dist/agent-guidance/files/.claude/rules/uikitml.md +66 -0
- package/dist/agent-guidance/files/.claude/settings.json +29 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-build-model/SKILL.md +312 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-build-model/agents/openai.yaml +4 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-build-model/assets/hardsurface.ts.template +599 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-compose-scene/SKILL.md +277 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-compose-scene/agents/openai.yaml +4 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-compose-scene/references/environment-recipes.md +234 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-compose-scene/references/extended-workflow.md +166 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-compose-scene/references/image-intake.md +190 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-compose-scene/references/scene-composition.md +80 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-compose-scene/references/scene-format.md +466 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-compose-scene/references/scene-review.md +66 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-compose-scene/references/text-intake.md +80 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-debug/SKILL.md +74 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-depth-occlusion/SKILL.md +88 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-dev/SKILL.md +46 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-dev/references/api-reference.md +1531 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-dev/references/headless-rendering.md +82 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-dev/references/iterate.md +263 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-dev/references/planner.md +307 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-glasses-test/SKILL.md +282 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-grab/SKILL.md +75 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-hosting/SKILL.md +178 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-hosting/references/existing-hosts.md +181 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-hosting/references/vercel.md +114 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-native-xr-test/SKILL.md +262 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-physics/SKILL.md +106 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-physics/references/component-reference.md +152 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-physics/references/tuning-and-config.md +101 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-physics/references/workflows.md +303 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-pwa-packaging/SKILL.md +219 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-pwa-packaging/references/app-modes.md +104 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-pwa-packaging/references/bubblewrap.md +219 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-pwa-packaging/references/manifest-and-icons.md +149 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-pwa-packaging/references/store-upload.md +104 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-pwa-packaging/references/troubleshooting.md +178 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-ray/SKILL.md +70 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-ui/SKILL.md +328 -0
- package/dist/agent-guidance/files/.claude/skills/iwsdk-upgrade/SKILL.md +74 -0
- package/dist/agent-guidance/files/.cursor/rules/assets-and-manifest.mdc +62 -0
- package/dist/agent-guidance/files/.cursor/rules/ecs-api.mdc +105 -0
- package/dist/agent-guidance/files/.cursor/rules/scene-json.mdc +74 -0
- package/dist/agent-guidance/files/.cursor/rules/uikitml.mdc +68 -0
- package/dist/agent-guidance/files/.github/instructions/assets-and-manifest.instructions.md +55 -0
- package/dist/agent-guidance/files/.github/instructions/ecs-api.instructions.md +101 -0
- package/dist/agent-guidance/files/.github/instructions/scene-json.instructions.md +71 -0
- package/dist/agent-guidance/files/.github/instructions/uikitml.instructions.md +65 -0
- package/{guidance → dist/agent-guidance/files}/AGENTS.md +107 -27
- package/dist/agent-guidance/files/CLAUDE.md +3 -0
- package/dist/agent-guidance/files/public/scenes/AGENTS.md +72 -0
- package/dist/agent-guidance/files/public/ui/AGENTS.md +66 -0
- package/dist/agent-guidance/files/src/AGENTS.md +153 -0
- package/dist/agent-guidance/manifest.json +854 -0
- package/dist/agent-guidance.d.ts +113 -0
- package/dist/agent-guidance.d.ts.map +1 -0
- package/dist/agent-guidance.js +3403 -0
- package/dist/agent-guidance.js.map +1 -0
- package/dist/cli.js +2407 -144
- package/dist/cli.js.map +1 -1
- package/dist/commands/adapter.d.ts +1 -0
- package/dist/commands/adapter.d.ts.map +1 -1
- package/dist/commands/agents.d.ts +11 -0
- package/dist/commands/agents.d.ts.map +1 -0
- package/dist/commands/browser.d.ts +11 -0
- package/dist/commands/browser.d.ts.map +1 -1
- package/dist/commands/dev.d.ts +1 -0
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/reference.d.ts +15 -1
- package/dist/commands/reference.d.ts.map +1 -1
- package/dist/commands/runtime.d.ts.map +1 -1
- package/dist/commands/upgrade.d.ts +51 -0
- package/dist/commands/upgrade.d.ts.map +1 -0
- package/dist/contract.js +32 -0
- package/dist/contract.js.map +1 -1
- package/dist/guidance-refresh.d.ts +33 -0
- package/dist/guidance-refresh.d.ts.map +1 -0
- package/dist/help.d.ts +2 -0
- package/dist/help.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4744 -135
- package/dist/index.js.map +1 -1
- package/dist/mcp-stdio.d.ts.map +1 -1
- package/dist/migrations/iwsdk-migrate-0-5/SKILL.md +413 -0
- package/dist/migrations.d.ts +36 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/package-manager.d.ts +28 -0
- package/dist/package-manager.d.ts.map +1 -0
- package/dist/release-notes.d.ts +28 -0
- package/dist/release-notes.d.ts.map +1 -0
- package/dist/release-notes.json +1374 -0
- package/dist/runtime-contract.d.ts +8 -0
- package/dist/runtime-contract.d.ts.map +1 -1
- package/dist/runtime-telemetry.d.ts +8 -1
- package/dist/runtime-telemetry.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +9 -3
|
@@ -0,0 +1,3403 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import { existsSync, readFileSync, realpathSync } from 'fs';
|
|
3
|
+
import { readFile, lstat, readdir, rm, mkdir, writeFile, rename, realpath, rmdir } from 'fs/promises';
|
|
4
|
+
import { createRequire } from 'module';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
|
|
8
|
+
function getDefaultExportFromCjs (x) {
|
|
9
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
var re$2 = {exports: {}};
|
|
13
|
+
|
|
14
|
+
// Note: this is the semver.org version of the spec that it implements
|
|
15
|
+
// Not necessarily the package version of this code.
|
|
16
|
+
const SEMVER_SPEC_VERSION = '2.0.0';
|
|
17
|
+
|
|
18
|
+
const MAX_LENGTH$1 = 256;
|
|
19
|
+
const MAX_SAFE_INTEGER$1 = Number.MAX_SAFE_INTEGER ||
|
|
20
|
+
/* istanbul ignore next */ 9007199254740991;
|
|
21
|
+
|
|
22
|
+
// Max safe segment length for coercion.
|
|
23
|
+
const MAX_SAFE_COMPONENT_LENGTH = 16;
|
|
24
|
+
|
|
25
|
+
// Max safe length for a build identifier. The max length minus 6 characters for
|
|
26
|
+
// the shortest version with a build 0.0.0+BUILD.
|
|
27
|
+
const MAX_SAFE_BUILD_LENGTH = MAX_LENGTH$1 - 6;
|
|
28
|
+
|
|
29
|
+
const RELEASE_TYPES = [
|
|
30
|
+
'major',
|
|
31
|
+
'premajor',
|
|
32
|
+
'minor',
|
|
33
|
+
'preminor',
|
|
34
|
+
'patch',
|
|
35
|
+
'prepatch',
|
|
36
|
+
'prerelease',
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
var constants$1 = {
|
|
40
|
+
MAX_LENGTH: MAX_LENGTH$1,
|
|
41
|
+
MAX_SAFE_COMPONENT_LENGTH,
|
|
42
|
+
MAX_SAFE_BUILD_LENGTH,
|
|
43
|
+
MAX_SAFE_INTEGER: MAX_SAFE_INTEGER$1,
|
|
44
|
+
RELEASE_TYPES,
|
|
45
|
+
SEMVER_SPEC_VERSION,
|
|
46
|
+
FLAG_INCLUDE_PRERELEASE: 0b001,
|
|
47
|
+
FLAG_LOOSE: 0b010,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const debug$1 = (
|
|
51
|
+
typeof process === 'object' &&
|
|
52
|
+
process.env &&
|
|
53
|
+
process.env.NODE_DEBUG &&
|
|
54
|
+
/\bsemver\b/i.test(process.env.NODE_DEBUG)
|
|
55
|
+
) ? (...args) => console.error('SEMVER', ...args)
|
|
56
|
+
: () => {};
|
|
57
|
+
|
|
58
|
+
var debug_1 = debug$1;
|
|
59
|
+
|
|
60
|
+
(function (module, exports) {
|
|
61
|
+
|
|
62
|
+
const {
|
|
63
|
+
MAX_SAFE_COMPONENT_LENGTH,
|
|
64
|
+
MAX_SAFE_BUILD_LENGTH,
|
|
65
|
+
MAX_LENGTH,
|
|
66
|
+
} = constants$1;
|
|
67
|
+
const debug = debug_1;
|
|
68
|
+
exports = module.exports = {};
|
|
69
|
+
|
|
70
|
+
// The actual regexps go on exports.re
|
|
71
|
+
const re = exports.re = [];
|
|
72
|
+
const safeRe = exports.safeRe = [];
|
|
73
|
+
const src = exports.src = [];
|
|
74
|
+
const safeSrc = exports.safeSrc = [];
|
|
75
|
+
const t = exports.t = {};
|
|
76
|
+
let R = 0;
|
|
77
|
+
|
|
78
|
+
const LETTERDASHNUMBER = '[a-zA-Z0-9-]';
|
|
79
|
+
|
|
80
|
+
// Replace some greedy regex tokens to prevent regex dos issues. These regex are
|
|
81
|
+
// used internally via the safeRe object since all inputs in this library get
|
|
82
|
+
// normalized first to trim and collapse all extra whitespace. The original
|
|
83
|
+
// regexes are exported for userland consumption and lower level usage. A
|
|
84
|
+
// future breaking change could export the safer regex only with a note that
|
|
85
|
+
// all input should have extra whitespace removed.
|
|
86
|
+
const safeRegexReplacements = [
|
|
87
|
+
['\\s', 1],
|
|
88
|
+
['\\d', MAX_LENGTH],
|
|
89
|
+
[LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH],
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
const makeSafeRegex = (value) => {
|
|
93
|
+
for (const [token, max] of safeRegexReplacements) {
|
|
94
|
+
value = value
|
|
95
|
+
.split(`${token}*`).join(`${token}{0,${max}}`)
|
|
96
|
+
.split(`${token}+`).join(`${token}{1,${max}}`);
|
|
97
|
+
}
|
|
98
|
+
return value
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const createToken = (name, value, isGlobal) => {
|
|
102
|
+
const safe = makeSafeRegex(value);
|
|
103
|
+
const index = R++;
|
|
104
|
+
debug(name, index, value);
|
|
105
|
+
t[name] = index;
|
|
106
|
+
src[index] = value;
|
|
107
|
+
safeSrc[index] = safe;
|
|
108
|
+
re[index] = new RegExp(value, isGlobal ? 'g' : undefined);
|
|
109
|
+
safeRe[index] = new RegExp(safe, isGlobal ? 'g' : undefined);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// The following Regular Expressions can be used for tokenizing,
|
|
113
|
+
// validating, and parsing SemVer version strings.
|
|
114
|
+
|
|
115
|
+
// ## Numeric Identifier
|
|
116
|
+
// A single `0`, or a non-zero digit followed by zero or more digits.
|
|
117
|
+
|
|
118
|
+
createToken('NUMERICIDENTIFIER', '0|[1-9]\\d*');
|
|
119
|
+
createToken('NUMERICIDENTIFIERLOOSE', '\\d+');
|
|
120
|
+
|
|
121
|
+
// ## Non-numeric Identifier
|
|
122
|
+
// Zero or more digits, followed by a letter or hyphen, and then zero or
|
|
123
|
+
// more letters, digits, or hyphens.
|
|
124
|
+
|
|
125
|
+
createToken('NONNUMERICIDENTIFIER', `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`);
|
|
126
|
+
|
|
127
|
+
// ## Main Version
|
|
128
|
+
// Three dot-separated numeric identifiers.
|
|
129
|
+
|
|
130
|
+
createToken('MAINVERSION', `(${src[t.NUMERICIDENTIFIER]})\\.` +
|
|
131
|
+
`(${src[t.NUMERICIDENTIFIER]})\\.` +
|
|
132
|
+
`(${src[t.NUMERICIDENTIFIER]})`);
|
|
133
|
+
|
|
134
|
+
createToken('MAINVERSIONLOOSE', `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
|
|
135
|
+
`(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
|
|
136
|
+
`(${src[t.NUMERICIDENTIFIERLOOSE]})`);
|
|
137
|
+
|
|
138
|
+
// ## Pre-release Version Identifier
|
|
139
|
+
// A numeric identifier, or a non-numeric identifier.
|
|
140
|
+
// Non-numberic identifiers include numberic identifiers but can be longer.
|
|
141
|
+
// Therefore non-numberic identifiers must go first.
|
|
142
|
+
|
|
143
|
+
createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NONNUMERICIDENTIFIER]
|
|
144
|
+
}|${src[t.NUMERICIDENTIFIER]})`);
|
|
145
|
+
|
|
146
|
+
createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NONNUMERICIDENTIFIER]
|
|
147
|
+
}|${src[t.NUMERICIDENTIFIERLOOSE]})`);
|
|
148
|
+
|
|
149
|
+
// ## Pre-release Version
|
|
150
|
+
// Hyphen, followed by one or more dot-separated pre-release version
|
|
151
|
+
// identifiers.
|
|
152
|
+
|
|
153
|
+
createToken('PRERELEASE', `(?:-(${src[t.PRERELEASEIDENTIFIER]
|
|
154
|
+
}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
|
|
155
|
+
|
|
156
|
+
createToken('PRERELEASELOOSE', `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]
|
|
157
|
+
}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
|
|
158
|
+
|
|
159
|
+
// ## Build Metadata Identifier
|
|
160
|
+
// Any combination of digits, letters, or hyphens.
|
|
161
|
+
|
|
162
|
+
createToken('BUILDIDENTIFIER', `${LETTERDASHNUMBER}+`);
|
|
163
|
+
|
|
164
|
+
// ## Build Metadata
|
|
165
|
+
// Plus sign, followed by one or more period-separated build metadata
|
|
166
|
+
// identifiers.
|
|
167
|
+
|
|
168
|
+
createToken('BUILD', `(?:\\+(${src[t.BUILDIDENTIFIER]
|
|
169
|
+
}(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
|
|
170
|
+
|
|
171
|
+
// ## Full Version String
|
|
172
|
+
// A main version, followed optionally by a pre-release version and
|
|
173
|
+
// build metadata.
|
|
174
|
+
|
|
175
|
+
// Note that the only major, minor, patch, and pre-release sections of
|
|
176
|
+
// the version string are capturing groups. The build metadata is not a
|
|
177
|
+
// capturing group, because it should not ever be used in version
|
|
178
|
+
// comparison.
|
|
179
|
+
|
|
180
|
+
createToken('FULLPLAIN', `v?${src[t.MAINVERSION]
|
|
181
|
+
}${src[t.PRERELEASE]}?${
|
|
182
|
+
src[t.BUILD]}?`);
|
|
183
|
+
|
|
184
|
+
createToken('FULL', `^${src[t.FULLPLAIN]}$`);
|
|
185
|
+
|
|
186
|
+
// like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
|
|
187
|
+
// also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
|
|
188
|
+
// common in the npm registry.
|
|
189
|
+
createToken('LOOSEPLAIN', `[v=\\s]*${src[t.MAINVERSIONLOOSE]
|
|
190
|
+
}${src[t.PRERELEASELOOSE]}?${
|
|
191
|
+
src[t.BUILD]}?`);
|
|
192
|
+
|
|
193
|
+
createToken('LOOSE', `^${src[t.LOOSEPLAIN]}$`);
|
|
194
|
+
|
|
195
|
+
createToken('GTLT', '((?:<|>)?=?)');
|
|
196
|
+
|
|
197
|
+
// Something like "2.*" or "1.2.x".
|
|
198
|
+
// Note that "x.x" is a valid xRange identifer, meaning "any version"
|
|
199
|
+
// Only the first item is strictly required.
|
|
200
|
+
createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
|
|
201
|
+
createToken('XRANGEIDENTIFIER', `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
|
|
202
|
+
|
|
203
|
+
createToken('XRANGEPLAIN', `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})` +
|
|
204
|
+
`(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
|
|
205
|
+
`(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
|
|
206
|
+
`(?:${src[t.PRERELEASE]})?${
|
|
207
|
+
src[t.BUILD]}?` +
|
|
208
|
+
`)?)?`);
|
|
209
|
+
|
|
210
|
+
createToken('XRANGEPLAINLOOSE', `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})` +
|
|
211
|
+
`(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
|
|
212
|
+
`(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
|
|
213
|
+
`(?:${src[t.PRERELEASELOOSE]})?${
|
|
214
|
+
src[t.BUILD]}?` +
|
|
215
|
+
`)?)?`);
|
|
216
|
+
|
|
217
|
+
createToken('XRANGE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
|
|
218
|
+
createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
|
|
219
|
+
|
|
220
|
+
// Coercion.
|
|
221
|
+
// Extract anything that could conceivably be a part of a valid semver
|
|
222
|
+
createToken('COERCEPLAIN', `${'(^|[^\\d])' +
|
|
223
|
+
'(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` +
|
|
224
|
+
`(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
|
|
225
|
+
`(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`);
|
|
226
|
+
createToken('COERCE', `${src[t.COERCEPLAIN]}(?:$|[^\\d])`);
|
|
227
|
+
createToken('COERCEFULL', src[t.COERCEPLAIN] +
|
|
228
|
+
`(?:${src[t.PRERELEASE]})?` +
|
|
229
|
+
`(?:${src[t.BUILD]})?` +
|
|
230
|
+
`(?:$|[^\\d])`);
|
|
231
|
+
createToken('COERCERTL', src[t.COERCE], true);
|
|
232
|
+
createToken('COERCERTLFULL', src[t.COERCEFULL], true);
|
|
233
|
+
|
|
234
|
+
// Tilde ranges.
|
|
235
|
+
// Meaning is "reasonably at or greater than"
|
|
236
|
+
createToken('LONETILDE', '(?:~>?)');
|
|
237
|
+
|
|
238
|
+
createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true);
|
|
239
|
+
exports.tildeTrimReplace = '$1~';
|
|
240
|
+
|
|
241
|
+
createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
|
|
242
|
+
createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
|
|
243
|
+
|
|
244
|
+
// Caret ranges.
|
|
245
|
+
// Meaning is "at least and backwards compatible with"
|
|
246
|
+
createToken('LONECARET', '(?:\\^)');
|
|
247
|
+
|
|
248
|
+
createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true);
|
|
249
|
+
exports.caretTrimReplace = '$1^';
|
|
250
|
+
|
|
251
|
+
createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
|
|
252
|
+
createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
|
|
253
|
+
|
|
254
|
+
// A simple gt/lt/eq thing, or just "" to indicate "any version"
|
|
255
|
+
createToken('COMPARATORLOOSE', `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
|
|
256
|
+
createToken('COMPARATOR', `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
|
|
257
|
+
|
|
258
|
+
// An expression to strip any whitespace between the gtlt and the thing
|
|
259
|
+
// it modifies, so that `> 1.2.3` ==> `>1.2.3`
|
|
260
|
+
createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT]
|
|
261
|
+
}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
|
|
262
|
+
exports.comparatorTrimReplace = '$1$2$3';
|
|
263
|
+
|
|
264
|
+
// Something like `1.2.3 - 1.2.4`
|
|
265
|
+
// Note that these all use the loose form, because they'll be
|
|
266
|
+
// checked against either the strict or loose comparator form
|
|
267
|
+
// later.
|
|
268
|
+
createToken('HYPHENRANGE', `^\\s*(${src[t.XRANGEPLAIN]})` +
|
|
269
|
+
`\\s+-\\s+` +
|
|
270
|
+
`(${src[t.XRANGEPLAIN]})` +
|
|
271
|
+
`\\s*$`);
|
|
272
|
+
|
|
273
|
+
createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +
|
|
274
|
+
`\\s+-\\s+` +
|
|
275
|
+
`(${src[t.XRANGEPLAINLOOSE]})` +
|
|
276
|
+
`\\s*$`);
|
|
277
|
+
|
|
278
|
+
// Star ranges basically just allow anything at all.
|
|
279
|
+
createToken('STAR', '(<|>)?=?\\s*\\*');
|
|
280
|
+
// >=0.0.0 is like a star
|
|
281
|
+
createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$');
|
|
282
|
+
createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$');
|
|
283
|
+
} (re$2, re$2.exports));
|
|
284
|
+
|
|
285
|
+
var reExports = re$2.exports;
|
|
286
|
+
|
|
287
|
+
// parse out just the options we care about
|
|
288
|
+
const looseOption = Object.freeze({ loose: true });
|
|
289
|
+
const emptyOpts = Object.freeze({ });
|
|
290
|
+
const parseOptions$1 = options => {
|
|
291
|
+
if (!options) {
|
|
292
|
+
return emptyOpts
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (typeof options !== 'object') {
|
|
296
|
+
return looseOption
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return options
|
|
300
|
+
};
|
|
301
|
+
var parseOptions_1 = parseOptions$1;
|
|
302
|
+
|
|
303
|
+
const numeric = /^[0-9]+$/;
|
|
304
|
+
const compareIdentifiers$1 = (a, b) => {
|
|
305
|
+
if (typeof a === 'number' && typeof b === 'number') {
|
|
306
|
+
return a === b ? 0 : a < b ? -1 : 1
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const anum = numeric.test(a);
|
|
310
|
+
const bnum = numeric.test(b);
|
|
311
|
+
|
|
312
|
+
if (anum && bnum) {
|
|
313
|
+
a = +a;
|
|
314
|
+
b = +b;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return a === b ? 0
|
|
318
|
+
: (anum && !bnum) ? -1
|
|
319
|
+
: (bnum && !anum) ? 1
|
|
320
|
+
: a < b ? -1
|
|
321
|
+
: 1
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
const rcompareIdentifiers = (a, b) => compareIdentifiers$1(b, a);
|
|
325
|
+
|
|
326
|
+
var identifiers$1 = {
|
|
327
|
+
compareIdentifiers: compareIdentifiers$1,
|
|
328
|
+
rcompareIdentifiers,
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
const debug = debug_1;
|
|
332
|
+
const { MAX_LENGTH, MAX_SAFE_INTEGER } = constants$1;
|
|
333
|
+
const { safeRe: re$1, t: t$1 } = reExports;
|
|
334
|
+
|
|
335
|
+
const parseOptions = parseOptions_1;
|
|
336
|
+
const { compareIdentifiers } = identifiers$1;
|
|
337
|
+
let SemVer$d = class SemVer {
|
|
338
|
+
constructor (version, options) {
|
|
339
|
+
options = parseOptions(options);
|
|
340
|
+
|
|
341
|
+
if (version instanceof SemVer) {
|
|
342
|
+
if (version.loose === !!options.loose &&
|
|
343
|
+
version.includePrerelease === !!options.includePrerelease) {
|
|
344
|
+
return version
|
|
345
|
+
} else {
|
|
346
|
+
version = version.version;
|
|
347
|
+
}
|
|
348
|
+
} else if (typeof version !== 'string') {
|
|
349
|
+
throw new TypeError(`Invalid version. Must be a string. Got type "${typeof version}".`)
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (version.length > MAX_LENGTH) {
|
|
353
|
+
throw new TypeError(
|
|
354
|
+
`version is longer than ${MAX_LENGTH} characters`
|
|
355
|
+
)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
debug('SemVer', version, options);
|
|
359
|
+
this.options = options;
|
|
360
|
+
this.loose = !!options.loose;
|
|
361
|
+
// this isn't actually relevant for versions, but keep it so that we
|
|
362
|
+
// don't run into trouble passing this.options around.
|
|
363
|
+
this.includePrerelease = !!options.includePrerelease;
|
|
364
|
+
|
|
365
|
+
const m = version.trim().match(options.loose ? re$1[t$1.LOOSE] : re$1[t$1.FULL]);
|
|
366
|
+
|
|
367
|
+
if (!m) {
|
|
368
|
+
throw new TypeError(`Invalid Version: ${version}`)
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
this.raw = version;
|
|
372
|
+
|
|
373
|
+
// these are actually numbers
|
|
374
|
+
this.major = +m[1];
|
|
375
|
+
this.minor = +m[2];
|
|
376
|
+
this.patch = +m[3];
|
|
377
|
+
|
|
378
|
+
if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
|
|
379
|
+
throw new TypeError('Invalid major version')
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
|
|
383
|
+
throw new TypeError('Invalid minor version')
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
|
|
387
|
+
throw new TypeError('Invalid patch version')
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// numberify any prerelease numeric ids
|
|
391
|
+
if (!m[4]) {
|
|
392
|
+
this.prerelease = [];
|
|
393
|
+
} else {
|
|
394
|
+
this.prerelease = m[4].split('.').map((id) => {
|
|
395
|
+
if (/^[0-9]+$/.test(id)) {
|
|
396
|
+
const num = +id;
|
|
397
|
+
if (num >= 0 && num < MAX_SAFE_INTEGER) {
|
|
398
|
+
return num
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return id
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
this.build = m[5] ? m[5].split('.') : [];
|
|
406
|
+
this.format();
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
format () {
|
|
410
|
+
this.version = `${this.major}.${this.minor}.${this.patch}`;
|
|
411
|
+
if (this.prerelease.length) {
|
|
412
|
+
this.version += `-${this.prerelease.join('.')}`;
|
|
413
|
+
}
|
|
414
|
+
return this.version
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
toString () {
|
|
418
|
+
return this.version
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
compare (other) {
|
|
422
|
+
debug('SemVer.compare', this.version, this.options, other);
|
|
423
|
+
if (!(other instanceof SemVer)) {
|
|
424
|
+
if (typeof other === 'string' && other === this.version) {
|
|
425
|
+
return 0
|
|
426
|
+
}
|
|
427
|
+
other = new SemVer(other, this.options);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (other.version === this.version) {
|
|
431
|
+
return 0
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
return this.compareMain(other) || this.comparePre(other)
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
compareMain (other) {
|
|
438
|
+
if (!(other instanceof SemVer)) {
|
|
439
|
+
other = new SemVer(other, this.options);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (this.major < other.major) {
|
|
443
|
+
return -1
|
|
444
|
+
}
|
|
445
|
+
if (this.major > other.major) {
|
|
446
|
+
return 1
|
|
447
|
+
}
|
|
448
|
+
if (this.minor < other.minor) {
|
|
449
|
+
return -1
|
|
450
|
+
}
|
|
451
|
+
if (this.minor > other.minor) {
|
|
452
|
+
return 1
|
|
453
|
+
}
|
|
454
|
+
if (this.patch < other.patch) {
|
|
455
|
+
return -1
|
|
456
|
+
}
|
|
457
|
+
if (this.patch > other.patch) {
|
|
458
|
+
return 1
|
|
459
|
+
}
|
|
460
|
+
return 0
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
comparePre (other) {
|
|
464
|
+
if (!(other instanceof SemVer)) {
|
|
465
|
+
other = new SemVer(other, this.options);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// NOT having a prerelease is > having one
|
|
469
|
+
if (this.prerelease.length && !other.prerelease.length) {
|
|
470
|
+
return -1
|
|
471
|
+
} else if (!this.prerelease.length && other.prerelease.length) {
|
|
472
|
+
return 1
|
|
473
|
+
} else if (!this.prerelease.length && !other.prerelease.length) {
|
|
474
|
+
return 0
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
let i = 0;
|
|
478
|
+
do {
|
|
479
|
+
const a = this.prerelease[i];
|
|
480
|
+
const b = other.prerelease[i];
|
|
481
|
+
debug('prerelease compare', i, a, b);
|
|
482
|
+
if (a === undefined && b === undefined) {
|
|
483
|
+
return 0
|
|
484
|
+
} else if (b === undefined) {
|
|
485
|
+
return 1
|
|
486
|
+
} else if (a === undefined) {
|
|
487
|
+
return -1
|
|
488
|
+
} else if (a === b) {
|
|
489
|
+
continue
|
|
490
|
+
} else {
|
|
491
|
+
return compareIdentifiers(a, b)
|
|
492
|
+
}
|
|
493
|
+
} while (++i)
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
compareBuild (other) {
|
|
497
|
+
if (!(other instanceof SemVer)) {
|
|
498
|
+
other = new SemVer(other, this.options);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
let i = 0;
|
|
502
|
+
do {
|
|
503
|
+
const a = this.build[i];
|
|
504
|
+
const b = other.build[i];
|
|
505
|
+
debug('build compare', i, a, b);
|
|
506
|
+
if (a === undefined && b === undefined) {
|
|
507
|
+
return 0
|
|
508
|
+
} else if (b === undefined) {
|
|
509
|
+
return 1
|
|
510
|
+
} else if (a === undefined) {
|
|
511
|
+
return -1
|
|
512
|
+
} else if (a === b) {
|
|
513
|
+
continue
|
|
514
|
+
} else {
|
|
515
|
+
return compareIdentifiers(a, b)
|
|
516
|
+
}
|
|
517
|
+
} while (++i)
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// preminor will bump the version up to the next minor release, and immediately
|
|
521
|
+
// down to pre-release. premajor and prepatch work the same way.
|
|
522
|
+
inc (release, identifier, identifierBase) {
|
|
523
|
+
if (release.startsWith('pre')) {
|
|
524
|
+
if (!identifier && identifierBase === false) {
|
|
525
|
+
throw new Error('invalid increment argument: identifier is empty')
|
|
526
|
+
}
|
|
527
|
+
// Avoid an invalid semver results
|
|
528
|
+
if (identifier) {
|
|
529
|
+
const match = `-${identifier}`.match(this.options.loose ? re$1[t$1.PRERELEASELOOSE] : re$1[t$1.PRERELEASE]);
|
|
530
|
+
if (!match || match[1] !== identifier) {
|
|
531
|
+
throw new Error(`invalid identifier: ${identifier}`)
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
switch (release) {
|
|
537
|
+
case 'premajor':
|
|
538
|
+
this.prerelease.length = 0;
|
|
539
|
+
this.patch = 0;
|
|
540
|
+
this.minor = 0;
|
|
541
|
+
this.major++;
|
|
542
|
+
this.inc('pre', identifier, identifierBase);
|
|
543
|
+
break
|
|
544
|
+
case 'preminor':
|
|
545
|
+
this.prerelease.length = 0;
|
|
546
|
+
this.patch = 0;
|
|
547
|
+
this.minor++;
|
|
548
|
+
this.inc('pre', identifier, identifierBase);
|
|
549
|
+
break
|
|
550
|
+
case 'prepatch':
|
|
551
|
+
// If this is already a prerelease, it will bump to the next version
|
|
552
|
+
// drop any prereleases that might already exist, since they are not
|
|
553
|
+
// relevant at this point.
|
|
554
|
+
this.prerelease.length = 0;
|
|
555
|
+
this.inc('patch', identifier, identifierBase);
|
|
556
|
+
this.inc('pre', identifier, identifierBase);
|
|
557
|
+
break
|
|
558
|
+
// If the input is a non-prerelease version, this acts the same as
|
|
559
|
+
// prepatch.
|
|
560
|
+
case 'prerelease':
|
|
561
|
+
if (this.prerelease.length === 0) {
|
|
562
|
+
this.inc('patch', identifier, identifierBase);
|
|
563
|
+
}
|
|
564
|
+
this.inc('pre', identifier, identifierBase);
|
|
565
|
+
break
|
|
566
|
+
case 'release':
|
|
567
|
+
if (this.prerelease.length === 0) {
|
|
568
|
+
throw new Error(`version ${this.raw} is not a prerelease`)
|
|
569
|
+
}
|
|
570
|
+
this.prerelease.length = 0;
|
|
571
|
+
break
|
|
572
|
+
|
|
573
|
+
case 'major':
|
|
574
|
+
// If this is a pre-major version, bump up to the same major version.
|
|
575
|
+
// Otherwise increment major.
|
|
576
|
+
// 1.0.0-5 bumps to 1.0.0
|
|
577
|
+
// 1.1.0 bumps to 2.0.0
|
|
578
|
+
if (
|
|
579
|
+
this.minor !== 0 ||
|
|
580
|
+
this.patch !== 0 ||
|
|
581
|
+
this.prerelease.length === 0
|
|
582
|
+
) {
|
|
583
|
+
this.major++;
|
|
584
|
+
}
|
|
585
|
+
this.minor = 0;
|
|
586
|
+
this.patch = 0;
|
|
587
|
+
this.prerelease = [];
|
|
588
|
+
break
|
|
589
|
+
case 'minor':
|
|
590
|
+
// If this is a pre-minor version, bump up to the same minor version.
|
|
591
|
+
// Otherwise increment minor.
|
|
592
|
+
// 1.2.0-5 bumps to 1.2.0
|
|
593
|
+
// 1.2.1 bumps to 1.3.0
|
|
594
|
+
if (this.patch !== 0 || this.prerelease.length === 0) {
|
|
595
|
+
this.minor++;
|
|
596
|
+
}
|
|
597
|
+
this.patch = 0;
|
|
598
|
+
this.prerelease = [];
|
|
599
|
+
break
|
|
600
|
+
case 'patch':
|
|
601
|
+
// If this is not a pre-release version, it will increment the patch.
|
|
602
|
+
// If it is a pre-release it will bump up to the same patch version.
|
|
603
|
+
// 1.2.0-5 patches to 1.2.0
|
|
604
|
+
// 1.2.0 patches to 1.2.1
|
|
605
|
+
if (this.prerelease.length === 0) {
|
|
606
|
+
this.patch++;
|
|
607
|
+
}
|
|
608
|
+
this.prerelease = [];
|
|
609
|
+
break
|
|
610
|
+
// This probably shouldn't be used publicly.
|
|
611
|
+
// 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
|
|
612
|
+
case 'pre': {
|
|
613
|
+
const base = Number(identifierBase) ? 1 : 0;
|
|
614
|
+
|
|
615
|
+
if (this.prerelease.length === 0) {
|
|
616
|
+
this.prerelease = [base];
|
|
617
|
+
} else {
|
|
618
|
+
let i = this.prerelease.length;
|
|
619
|
+
while (--i >= 0) {
|
|
620
|
+
if (typeof this.prerelease[i] === 'number') {
|
|
621
|
+
this.prerelease[i]++;
|
|
622
|
+
i = -2;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
if (i === -1) {
|
|
626
|
+
// didn't increment anything
|
|
627
|
+
if (identifier === this.prerelease.join('.') && identifierBase === false) {
|
|
628
|
+
throw new Error('invalid increment argument: identifier already exists')
|
|
629
|
+
}
|
|
630
|
+
this.prerelease.push(base);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
if (identifier) {
|
|
634
|
+
// 1.2.0-beta.1 bumps to 1.2.0-beta.2,
|
|
635
|
+
// 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
|
|
636
|
+
let prerelease = [identifier, base];
|
|
637
|
+
if (identifierBase === false) {
|
|
638
|
+
prerelease = [identifier];
|
|
639
|
+
}
|
|
640
|
+
if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
|
|
641
|
+
if (isNaN(this.prerelease[1])) {
|
|
642
|
+
this.prerelease = prerelease;
|
|
643
|
+
}
|
|
644
|
+
} else {
|
|
645
|
+
this.prerelease = prerelease;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
break
|
|
649
|
+
}
|
|
650
|
+
default:
|
|
651
|
+
throw new Error(`invalid increment argument: ${release}`)
|
|
652
|
+
}
|
|
653
|
+
this.raw = this.format();
|
|
654
|
+
if (this.build.length) {
|
|
655
|
+
this.raw += `+${this.build.join('.')}`;
|
|
656
|
+
}
|
|
657
|
+
return this
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
var semver$2 = SemVer$d;
|
|
662
|
+
|
|
663
|
+
const SemVer$c = semver$2;
|
|
664
|
+
const parse$6 = (version, options, throwErrors = false) => {
|
|
665
|
+
if (version instanceof SemVer$c) {
|
|
666
|
+
return version
|
|
667
|
+
}
|
|
668
|
+
try {
|
|
669
|
+
return new SemVer$c(version, options)
|
|
670
|
+
} catch (er) {
|
|
671
|
+
if (!throwErrors) {
|
|
672
|
+
return null
|
|
673
|
+
}
|
|
674
|
+
throw er
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
|
|
678
|
+
var parse_1 = parse$6;
|
|
679
|
+
|
|
680
|
+
const parse$5 = parse_1;
|
|
681
|
+
const valid$2 = (version, options) => {
|
|
682
|
+
const v = parse$5(version, options);
|
|
683
|
+
return v ? v.version : null
|
|
684
|
+
};
|
|
685
|
+
var valid_1 = valid$2;
|
|
686
|
+
|
|
687
|
+
const parse$4 = parse_1;
|
|
688
|
+
const clean$1 = (version, options) => {
|
|
689
|
+
const s = parse$4(version.trim().replace(/^[=v]+/, ''), options);
|
|
690
|
+
return s ? s.version : null
|
|
691
|
+
};
|
|
692
|
+
var clean_1 = clean$1;
|
|
693
|
+
|
|
694
|
+
const SemVer$b = semver$2;
|
|
695
|
+
|
|
696
|
+
const inc$1 = (version, release, options, identifier, identifierBase) => {
|
|
697
|
+
if (typeof (options) === 'string') {
|
|
698
|
+
identifierBase = identifier;
|
|
699
|
+
identifier = options;
|
|
700
|
+
options = undefined;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
try {
|
|
704
|
+
return new SemVer$b(
|
|
705
|
+
version instanceof SemVer$b ? version.version : version,
|
|
706
|
+
options
|
|
707
|
+
).inc(release, identifier, identifierBase).version
|
|
708
|
+
} catch (er) {
|
|
709
|
+
return null
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
var inc_1 = inc$1;
|
|
713
|
+
|
|
714
|
+
const parse$3 = parse_1;
|
|
715
|
+
|
|
716
|
+
const diff$1 = (version1, version2) => {
|
|
717
|
+
const v1 = parse$3(version1, null, true);
|
|
718
|
+
const v2 = parse$3(version2, null, true);
|
|
719
|
+
const comparison = v1.compare(v2);
|
|
720
|
+
|
|
721
|
+
if (comparison === 0) {
|
|
722
|
+
return null
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
const v1Higher = comparison > 0;
|
|
726
|
+
const highVersion = v1Higher ? v1 : v2;
|
|
727
|
+
const lowVersion = v1Higher ? v2 : v1;
|
|
728
|
+
const highHasPre = !!highVersion.prerelease.length;
|
|
729
|
+
const lowHasPre = !!lowVersion.prerelease.length;
|
|
730
|
+
|
|
731
|
+
if (lowHasPre && !highHasPre) {
|
|
732
|
+
// Going from prerelease -> no prerelease requires some special casing
|
|
733
|
+
|
|
734
|
+
// If the low version has only a major, then it will always be a major
|
|
735
|
+
// Some examples:
|
|
736
|
+
// 1.0.0-1 -> 1.0.0
|
|
737
|
+
// 1.0.0-1 -> 1.1.1
|
|
738
|
+
// 1.0.0-1 -> 2.0.0
|
|
739
|
+
if (!lowVersion.patch && !lowVersion.minor) {
|
|
740
|
+
return 'major'
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// If the main part has no difference
|
|
744
|
+
if (lowVersion.compareMain(highVersion) === 0) {
|
|
745
|
+
if (lowVersion.minor && !lowVersion.patch) {
|
|
746
|
+
return 'minor'
|
|
747
|
+
}
|
|
748
|
+
return 'patch'
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// add the `pre` prefix if we are going to a prerelease version
|
|
753
|
+
const prefix = highHasPre ? 'pre' : '';
|
|
754
|
+
|
|
755
|
+
if (v1.major !== v2.major) {
|
|
756
|
+
return prefix + 'major'
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
if (v1.minor !== v2.minor) {
|
|
760
|
+
return prefix + 'minor'
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
if (v1.patch !== v2.patch) {
|
|
764
|
+
return prefix + 'patch'
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// high and low are preleases
|
|
768
|
+
return 'prerelease'
|
|
769
|
+
};
|
|
770
|
+
|
|
771
|
+
var diff_1 = diff$1;
|
|
772
|
+
|
|
773
|
+
const SemVer$a = semver$2;
|
|
774
|
+
const major$1 = (a, loose) => new SemVer$a(a, loose).major;
|
|
775
|
+
var major_1 = major$1;
|
|
776
|
+
|
|
777
|
+
const SemVer$9 = semver$2;
|
|
778
|
+
const minor$1 = (a, loose) => new SemVer$9(a, loose).minor;
|
|
779
|
+
var minor_1 = minor$1;
|
|
780
|
+
|
|
781
|
+
const SemVer$8 = semver$2;
|
|
782
|
+
const patch$1 = (a, loose) => new SemVer$8(a, loose).patch;
|
|
783
|
+
var patch_1 = patch$1;
|
|
784
|
+
|
|
785
|
+
const parse$2 = parse_1;
|
|
786
|
+
const prerelease$1 = (version, options) => {
|
|
787
|
+
const parsed = parse$2(version, options);
|
|
788
|
+
return (parsed && parsed.prerelease.length) ? parsed.prerelease : null
|
|
789
|
+
};
|
|
790
|
+
var prerelease_1 = prerelease$1;
|
|
791
|
+
|
|
792
|
+
const SemVer$7 = semver$2;
|
|
793
|
+
const compare$b = (a, b, loose) =>
|
|
794
|
+
new SemVer$7(a, loose).compare(new SemVer$7(b, loose));
|
|
795
|
+
|
|
796
|
+
var compare_1 = compare$b;
|
|
797
|
+
|
|
798
|
+
const compare$a = compare_1;
|
|
799
|
+
const rcompare$1 = (a, b, loose) => compare$a(b, a, loose);
|
|
800
|
+
var rcompare_1 = rcompare$1;
|
|
801
|
+
|
|
802
|
+
const compare$9 = compare_1;
|
|
803
|
+
const compareLoose$1 = (a, b) => compare$9(a, b, true);
|
|
804
|
+
var compareLoose_1 = compareLoose$1;
|
|
805
|
+
|
|
806
|
+
const SemVer$6 = semver$2;
|
|
807
|
+
const compareBuild$3 = (a, b, loose) => {
|
|
808
|
+
const versionA = new SemVer$6(a, loose);
|
|
809
|
+
const versionB = new SemVer$6(b, loose);
|
|
810
|
+
return versionA.compare(versionB) || versionA.compareBuild(versionB)
|
|
811
|
+
};
|
|
812
|
+
var compareBuild_1 = compareBuild$3;
|
|
813
|
+
|
|
814
|
+
const compareBuild$2 = compareBuild_1;
|
|
815
|
+
const sort$1 = (list, loose) => list.sort((a, b) => compareBuild$2(a, b, loose));
|
|
816
|
+
var sort_1 = sort$1;
|
|
817
|
+
|
|
818
|
+
const compareBuild$1 = compareBuild_1;
|
|
819
|
+
const rsort$1 = (list, loose) => list.sort((a, b) => compareBuild$1(b, a, loose));
|
|
820
|
+
var rsort_1 = rsort$1;
|
|
821
|
+
|
|
822
|
+
const compare$8 = compare_1;
|
|
823
|
+
const gt$4 = (a, b, loose) => compare$8(a, b, loose) > 0;
|
|
824
|
+
var gt_1 = gt$4;
|
|
825
|
+
|
|
826
|
+
const compare$7 = compare_1;
|
|
827
|
+
const lt$3 = (a, b, loose) => compare$7(a, b, loose) < 0;
|
|
828
|
+
var lt_1 = lt$3;
|
|
829
|
+
|
|
830
|
+
const compare$6 = compare_1;
|
|
831
|
+
const eq$2 = (a, b, loose) => compare$6(a, b, loose) === 0;
|
|
832
|
+
var eq_1 = eq$2;
|
|
833
|
+
|
|
834
|
+
const compare$5 = compare_1;
|
|
835
|
+
const neq$2 = (a, b, loose) => compare$5(a, b, loose) !== 0;
|
|
836
|
+
var neq_1 = neq$2;
|
|
837
|
+
|
|
838
|
+
const compare$4 = compare_1;
|
|
839
|
+
const gte$3 = (a, b, loose) => compare$4(a, b, loose) >= 0;
|
|
840
|
+
var gte_1 = gte$3;
|
|
841
|
+
|
|
842
|
+
const compare$3 = compare_1;
|
|
843
|
+
const lte$3 = (a, b, loose) => compare$3(a, b, loose) <= 0;
|
|
844
|
+
var lte_1 = lte$3;
|
|
845
|
+
|
|
846
|
+
const eq$1 = eq_1;
|
|
847
|
+
const neq$1 = neq_1;
|
|
848
|
+
const gt$3 = gt_1;
|
|
849
|
+
const gte$2 = gte_1;
|
|
850
|
+
const lt$2 = lt_1;
|
|
851
|
+
const lte$2 = lte_1;
|
|
852
|
+
|
|
853
|
+
const cmp$1 = (a, op, b, loose) => {
|
|
854
|
+
switch (op) {
|
|
855
|
+
case '===':
|
|
856
|
+
if (typeof a === 'object') {
|
|
857
|
+
a = a.version;
|
|
858
|
+
}
|
|
859
|
+
if (typeof b === 'object') {
|
|
860
|
+
b = b.version;
|
|
861
|
+
}
|
|
862
|
+
return a === b
|
|
863
|
+
|
|
864
|
+
case '!==':
|
|
865
|
+
if (typeof a === 'object') {
|
|
866
|
+
a = a.version;
|
|
867
|
+
}
|
|
868
|
+
if (typeof b === 'object') {
|
|
869
|
+
b = b.version;
|
|
870
|
+
}
|
|
871
|
+
return a !== b
|
|
872
|
+
|
|
873
|
+
case '':
|
|
874
|
+
case '=':
|
|
875
|
+
case '==':
|
|
876
|
+
return eq$1(a, b, loose)
|
|
877
|
+
|
|
878
|
+
case '!=':
|
|
879
|
+
return neq$1(a, b, loose)
|
|
880
|
+
|
|
881
|
+
case '>':
|
|
882
|
+
return gt$3(a, b, loose)
|
|
883
|
+
|
|
884
|
+
case '>=':
|
|
885
|
+
return gte$2(a, b, loose)
|
|
886
|
+
|
|
887
|
+
case '<':
|
|
888
|
+
return lt$2(a, b, loose)
|
|
889
|
+
|
|
890
|
+
case '<=':
|
|
891
|
+
return lte$2(a, b, loose)
|
|
892
|
+
|
|
893
|
+
default:
|
|
894
|
+
throw new TypeError(`Invalid operator: ${op}`)
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
var cmp_1 = cmp$1;
|
|
898
|
+
|
|
899
|
+
const SemVer$5 = semver$2;
|
|
900
|
+
const parse$1 = parse_1;
|
|
901
|
+
const { safeRe: re, t } = reExports;
|
|
902
|
+
|
|
903
|
+
const coerce$1 = (version, options) => {
|
|
904
|
+
if (version instanceof SemVer$5) {
|
|
905
|
+
return version
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
if (typeof version === 'number') {
|
|
909
|
+
version = String(version);
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
if (typeof version !== 'string') {
|
|
913
|
+
return null
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
options = options || {};
|
|
917
|
+
|
|
918
|
+
let match = null;
|
|
919
|
+
if (!options.rtl) {
|
|
920
|
+
match = version.match(options.includePrerelease ? re[t.COERCEFULL] : re[t.COERCE]);
|
|
921
|
+
} else {
|
|
922
|
+
// Find the right-most coercible string that does not share
|
|
923
|
+
// a terminus with a more left-ward coercible string.
|
|
924
|
+
// Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
|
|
925
|
+
// With includePrerelease option set, '1.2.3.4-rc' wants to coerce '2.3.4-rc', not '2.3.4'
|
|
926
|
+
//
|
|
927
|
+
// Walk through the string checking with a /g regexp
|
|
928
|
+
// Manually set the index so as to pick up overlapping matches.
|
|
929
|
+
// Stop when we get a match that ends at the string end, since no
|
|
930
|
+
// coercible string can be more right-ward without the same terminus.
|
|
931
|
+
const coerceRtlRegex = options.includePrerelease ? re[t.COERCERTLFULL] : re[t.COERCERTL];
|
|
932
|
+
let next;
|
|
933
|
+
while ((next = coerceRtlRegex.exec(version)) &&
|
|
934
|
+
(!match || match.index + match[0].length !== version.length)
|
|
935
|
+
) {
|
|
936
|
+
if (!match ||
|
|
937
|
+
next.index + next[0].length !== match.index + match[0].length) {
|
|
938
|
+
match = next;
|
|
939
|
+
}
|
|
940
|
+
coerceRtlRegex.lastIndex = next.index + next[1].length + next[2].length;
|
|
941
|
+
}
|
|
942
|
+
// leave it in a clean state
|
|
943
|
+
coerceRtlRegex.lastIndex = -1;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
if (match === null) {
|
|
947
|
+
return null
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
const major = match[2];
|
|
951
|
+
const minor = match[3] || '0';
|
|
952
|
+
const patch = match[4] || '0';
|
|
953
|
+
const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : '';
|
|
954
|
+
const build = options.includePrerelease && match[6] ? `+${match[6]}` : '';
|
|
955
|
+
|
|
956
|
+
return parse$1(`${major}.${minor}.${patch}${prerelease}${build}`, options)
|
|
957
|
+
};
|
|
958
|
+
var coerce_1 = coerce$1;
|
|
959
|
+
|
|
960
|
+
var lrucache;
|
|
961
|
+
var hasRequiredLrucache;
|
|
962
|
+
|
|
963
|
+
function requireLrucache () {
|
|
964
|
+
if (hasRequiredLrucache) return lrucache;
|
|
965
|
+
hasRequiredLrucache = 1;
|
|
966
|
+
|
|
967
|
+
class LRUCache {
|
|
968
|
+
constructor () {
|
|
969
|
+
this.max = 1000;
|
|
970
|
+
this.map = new Map();
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
get (key) {
|
|
974
|
+
const value = this.map.get(key);
|
|
975
|
+
if (value === undefined) {
|
|
976
|
+
return undefined
|
|
977
|
+
} else {
|
|
978
|
+
// Remove the key from the map and add it to the end
|
|
979
|
+
this.map.delete(key);
|
|
980
|
+
this.map.set(key, value);
|
|
981
|
+
return value
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
delete (key) {
|
|
986
|
+
return this.map.delete(key)
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
set (key, value) {
|
|
990
|
+
const deleted = this.delete(key);
|
|
991
|
+
|
|
992
|
+
if (!deleted && value !== undefined) {
|
|
993
|
+
// If cache is full, delete the least recently used item
|
|
994
|
+
if (this.map.size >= this.max) {
|
|
995
|
+
const firstKey = this.map.keys().next().value;
|
|
996
|
+
this.delete(firstKey);
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
this.map.set(key, value);
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
return this
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
lrucache = LRUCache;
|
|
1007
|
+
return lrucache;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
var range;
|
|
1011
|
+
var hasRequiredRange;
|
|
1012
|
+
|
|
1013
|
+
function requireRange () {
|
|
1014
|
+
if (hasRequiredRange) return range;
|
|
1015
|
+
hasRequiredRange = 1;
|
|
1016
|
+
|
|
1017
|
+
const SPACE_CHARACTERS = /\s+/g;
|
|
1018
|
+
|
|
1019
|
+
// hoisted class for cyclic dependency
|
|
1020
|
+
class Range {
|
|
1021
|
+
constructor (range, options) {
|
|
1022
|
+
options = parseOptions(options);
|
|
1023
|
+
|
|
1024
|
+
if (range instanceof Range) {
|
|
1025
|
+
if (
|
|
1026
|
+
range.loose === !!options.loose &&
|
|
1027
|
+
range.includePrerelease === !!options.includePrerelease
|
|
1028
|
+
) {
|
|
1029
|
+
return range
|
|
1030
|
+
} else {
|
|
1031
|
+
return new Range(range.raw, options)
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
if (range instanceof Comparator) {
|
|
1036
|
+
// just put it in the set and return
|
|
1037
|
+
this.raw = range.value;
|
|
1038
|
+
this.set = [[range]];
|
|
1039
|
+
this.formatted = undefined;
|
|
1040
|
+
return this
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
this.options = options;
|
|
1044
|
+
this.loose = !!options.loose;
|
|
1045
|
+
this.includePrerelease = !!options.includePrerelease;
|
|
1046
|
+
|
|
1047
|
+
// First reduce all whitespace as much as possible so we do not have to rely
|
|
1048
|
+
// on potentially slow regexes like \s*. This is then stored and used for
|
|
1049
|
+
// future error messages as well.
|
|
1050
|
+
this.raw = range.trim().replace(SPACE_CHARACTERS, ' ');
|
|
1051
|
+
|
|
1052
|
+
// First, split on ||
|
|
1053
|
+
this.set = this.raw
|
|
1054
|
+
.split('||')
|
|
1055
|
+
// map the range to a 2d array of comparators
|
|
1056
|
+
.map(r => this.parseRange(r.trim()))
|
|
1057
|
+
// throw out any comparator lists that are empty
|
|
1058
|
+
// this generally means that it was not a valid range, which is allowed
|
|
1059
|
+
// in loose mode, but will still throw if the WHOLE range is invalid.
|
|
1060
|
+
.filter(c => c.length);
|
|
1061
|
+
|
|
1062
|
+
if (!this.set.length) {
|
|
1063
|
+
throw new TypeError(`Invalid SemVer Range: ${this.raw}`)
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
// if we have any that are not the null set, throw out null sets.
|
|
1067
|
+
if (this.set.length > 1) {
|
|
1068
|
+
// keep the first one, in case they're all null sets
|
|
1069
|
+
const first = this.set[0];
|
|
1070
|
+
this.set = this.set.filter(c => !isNullSet(c[0]));
|
|
1071
|
+
if (this.set.length === 0) {
|
|
1072
|
+
this.set = [first];
|
|
1073
|
+
} else if (this.set.length > 1) {
|
|
1074
|
+
// if we have any that are *, then the range is just *
|
|
1075
|
+
for (const c of this.set) {
|
|
1076
|
+
if (c.length === 1 && isAny(c[0])) {
|
|
1077
|
+
this.set = [c];
|
|
1078
|
+
break
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
this.formatted = undefined;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
get range () {
|
|
1088
|
+
if (this.formatted === undefined) {
|
|
1089
|
+
this.formatted = '';
|
|
1090
|
+
for (let i = 0; i < this.set.length; i++) {
|
|
1091
|
+
if (i > 0) {
|
|
1092
|
+
this.formatted += '||';
|
|
1093
|
+
}
|
|
1094
|
+
const comps = this.set[i];
|
|
1095
|
+
for (let k = 0; k < comps.length; k++) {
|
|
1096
|
+
if (k > 0) {
|
|
1097
|
+
this.formatted += ' ';
|
|
1098
|
+
}
|
|
1099
|
+
this.formatted += comps[k].toString().trim();
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
return this.formatted
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
format () {
|
|
1107
|
+
return this.range
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
toString () {
|
|
1111
|
+
return this.range
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
parseRange (range) {
|
|
1115
|
+
// memoize range parsing for performance.
|
|
1116
|
+
// this is a very hot path, and fully deterministic.
|
|
1117
|
+
const memoOpts =
|
|
1118
|
+
(this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) |
|
|
1119
|
+
(this.options.loose && FLAG_LOOSE);
|
|
1120
|
+
const memoKey = memoOpts + ':' + range;
|
|
1121
|
+
const cached = cache.get(memoKey);
|
|
1122
|
+
if (cached) {
|
|
1123
|
+
return cached
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
const loose = this.options.loose;
|
|
1127
|
+
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
|
|
1128
|
+
const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE];
|
|
1129
|
+
range = range.replace(hr, hyphenReplace(this.options.includePrerelease));
|
|
1130
|
+
debug('hyphen replace', range);
|
|
1131
|
+
|
|
1132
|
+
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
|
|
1133
|
+
range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace);
|
|
1134
|
+
debug('comparator trim', range);
|
|
1135
|
+
|
|
1136
|
+
// `~ 1.2.3` => `~1.2.3`
|
|
1137
|
+
range = range.replace(re[t.TILDETRIM], tildeTrimReplace);
|
|
1138
|
+
debug('tilde trim', range);
|
|
1139
|
+
|
|
1140
|
+
// `^ 1.2.3` => `^1.2.3`
|
|
1141
|
+
range = range.replace(re[t.CARETTRIM], caretTrimReplace);
|
|
1142
|
+
debug('caret trim', range);
|
|
1143
|
+
|
|
1144
|
+
// At this point, the range is completely trimmed and
|
|
1145
|
+
// ready to be split into comparators.
|
|
1146
|
+
|
|
1147
|
+
let rangeList = range
|
|
1148
|
+
.split(' ')
|
|
1149
|
+
.map(comp => parseComparator(comp, this.options))
|
|
1150
|
+
.join(' ')
|
|
1151
|
+
.split(/\s+/)
|
|
1152
|
+
// >=0.0.0 is equivalent to *
|
|
1153
|
+
.map(comp => replaceGTE0(comp, this.options));
|
|
1154
|
+
|
|
1155
|
+
if (loose) {
|
|
1156
|
+
// in loose mode, throw out any that are not valid comparators
|
|
1157
|
+
rangeList = rangeList.filter(comp => {
|
|
1158
|
+
debug('loose invalid filter', comp, this.options);
|
|
1159
|
+
return !!comp.match(re[t.COMPARATORLOOSE])
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
debug('range list', rangeList);
|
|
1163
|
+
|
|
1164
|
+
// if any comparators are the null set, then replace with JUST null set
|
|
1165
|
+
// if more than one comparator, remove any * comparators
|
|
1166
|
+
// also, don't include the same comparator more than once
|
|
1167
|
+
const rangeMap = new Map();
|
|
1168
|
+
const comparators = rangeList.map(comp => new Comparator(comp, this.options));
|
|
1169
|
+
for (const comp of comparators) {
|
|
1170
|
+
if (isNullSet(comp)) {
|
|
1171
|
+
return [comp]
|
|
1172
|
+
}
|
|
1173
|
+
rangeMap.set(comp.value, comp);
|
|
1174
|
+
}
|
|
1175
|
+
if (rangeMap.size > 1 && rangeMap.has('')) {
|
|
1176
|
+
rangeMap.delete('');
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
const result = [...rangeMap.values()];
|
|
1180
|
+
cache.set(memoKey, result);
|
|
1181
|
+
return result
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
intersects (range, options) {
|
|
1185
|
+
if (!(range instanceof Range)) {
|
|
1186
|
+
throw new TypeError('a Range is required')
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
return this.set.some((thisComparators) => {
|
|
1190
|
+
return (
|
|
1191
|
+
isSatisfiable(thisComparators, options) &&
|
|
1192
|
+
range.set.some((rangeComparators) => {
|
|
1193
|
+
return (
|
|
1194
|
+
isSatisfiable(rangeComparators, options) &&
|
|
1195
|
+
thisComparators.every((thisComparator) => {
|
|
1196
|
+
return rangeComparators.every((rangeComparator) => {
|
|
1197
|
+
return thisComparator.intersects(rangeComparator, options)
|
|
1198
|
+
})
|
|
1199
|
+
})
|
|
1200
|
+
)
|
|
1201
|
+
})
|
|
1202
|
+
)
|
|
1203
|
+
})
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
// if ANY of the sets match ALL of its comparators, then pass
|
|
1207
|
+
test (version) {
|
|
1208
|
+
if (!version) {
|
|
1209
|
+
return false
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
if (typeof version === 'string') {
|
|
1213
|
+
try {
|
|
1214
|
+
version = new SemVer(version, this.options);
|
|
1215
|
+
} catch (er) {
|
|
1216
|
+
return false
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
for (let i = 0; i < this.set.length; i++) {
|
|
1221
|
+
if (testSet(this.set[i], version, this.options)) {
|
|
1222
|
+
return true
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
return false
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
range = Range;
|
|
1230
|
+
|
|
1231
|
+
const LRU = requireLrucache();
|
|
1232
|
+
const cache = new LRU();
|
|
1233
|
+
|
|
1234
|
+
const parseOptions = parseOptions_1;
|
|
1235
|
+
const Comparator = requireComparator();
|
|
1236
|
+
const debug = debug_1;
|
|
1237
|
+
const SemVer = semver$2;
|
|
1238
|
+
const {
|
|
1239
|
+
safeRe: re,
|
|
1240
|
+
t,
|
|
1241
|
+
comparatorTrimReplace,
|
|
1242
|
+
tildeTrimReplace,
|
|
1243
|
+
caretTrimReplace,
|
|
1244
|
+
} = reExports;
|
|
1245
|
+
const { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = constants$1;
|
|
1246
|
+
|
|
1247
|
+
const isNullSet = c => c.value === '<0.0.0-0';
|
|
1248
|
+
const isAny = c => c.value === '';
|
|
1249
|
+
|
|
1250
|
+
// take a set of comparators and determine whether there
|
|
1251
|
+
// exists a version which can satisfy it
|
|
1252
|
+
const isSatisfiable = (comparators, options) => {
|
|
1253
|
+
let result = true;
|
|
1254
|
+
const remainingComparators = comparators.slice();
|
|
1255
|
+
let testComparator = remainingComparators.pop();
|
|
1256
|
+
|
|
1257
|
+
while (result && remainingComparators.length) {
|
|
1258
|
+
result = remainingComparators.every((otherComparator) => {
|
|
1259
|
+
return testComparator.intersects(otherComparator, options)
|
|
1260
|
+
});
|
|
1261
|
+
|
|
1262
|
+
testComparator = remainingComparators.pop();
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
return result
|
|
1266
|
+
};
|
|
1267
|
+
|
|
1268
|
+
// comprised of xranges, tildes, stars, and gtlt's at this point.
|
|
1269
|
+
// already replaced the hyphen ranges
|
|
1270
|
+
// turn into a set of JUST comparators.
|
|
1271
|
+
const parseComparator = (comp, options) => {
|
|
1272
|
+
comp = comp.replace(re[t.BUILD], '');
|
|
1273
|
+
debug('comp', comp, options);
|
|
1274
|
+
comp = replaceCarets(comp, options);
|
|
1275
|
+
debug('caret', comp);
|
|
1276
|
+
comp = replaceTildes(comp, options);
|
|
1277
|
+
debug('tildes', comp);
|
|
1278
|
+
comp = replaceXRanges(comp, options);
|
|
1279
|
+
debug('xrange', comp);
|
|
1280
|
+
comp = replaceStars(comp, options);
|
|
1281
|
+
debug('stars', comp);
|
|
1282
|
+
return comp
|
|
1283
|
+
};
|
|
1284
|
+
|
|
1285
|
+
const isX = id => !id || id.toLowerCase() === 'x' || id === '*';
|
|
1286
|
+
|
|
1287
|
+
// ~, ~> --> * (any, kinda silly)
|
|
1288
|
+
// ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0
|
|
1289
|
+
// ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0
|
|
1290
|
+
// ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0-0
|
|
1291
|
+
// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
|
|
1292
|
+
// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
|
|
1293
|
+
// ~0.0.1 --> >=0.0.1 <0.1.0-0
|
|
1294
|
+
const replaceTildes = (comp, options) => {
|
|
1295
|
+
return comp
|
|
1296
|
+
.trim()
|
|
1297
|
+
.split(/\s+/)
|
|
1298
|
+
.map((c) => replaceTilde(c, options))
|
|
1299
|
+
.join(' ')
|
|
1300
|
+
};
|
|
1301
|
+
|
|
1302
|
+
const replaceTilde = (comp, options) => {
|
|
1303
|
+
const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
|
|
1304
|
+
return comp.replace(r, (_, M, m, p, pr) => {
|
|
1305
|
+
debug('tilde', comp, _, M, m, p, pr);
|
|
1306
|
+
let ret;
|
|
1307
|
+
|
|
1308
|
+
if (isX(M)) {
|
|
1309
|
+
ret = '';
|
|
1310
|
+
} else if (isX(m)) {
|
|
1311
|
+
ret = `>=${M}.0.0 <${+M + 1}.0.0-0`;
|
|
1312
|
+
} else if (isX(p)) {
|
|
1313
|
+
// ~1.2 == >=1.2.0 <1.3.0-0
|
|
1314
|
+
ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`;
|
|
1315
|
+
} else if (pr) {
|
|
1316
|
+
debug('replaceTilde pr', pr);
|
|
1317
|
+
ret = `>=${M}.${m}.${p}-${pr
|
|
1318
|
+
} <${M}.${+m + 1}.0-0`;
|
|
1319
|
+
} else {
|
|
1320
|
+
// ~1.2.3 == >=1.2.3 <1.3.0-0
|
|
1321
|
+
ret = `>=${M}.${m}.${p
|
|
1322
|
+
} <${M}.${+m + 1}.0-0`;
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
debug('tilde return', ret);
|
|
1326
|
+
return ret
|
|
1327
|
+
})
|
|
1328
|
+
};
|
|
1329
|
+
|
|
1330
|
+
// ^ --> * (any, kinda silly)
|
|
1331
|
+
// ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0-0
|
|
1332
|
+
// ^2.0, ^2.0.x --> >=2.0.0 <3.0.0-0
|
|
1333
|
+
// ^1.2, ^1.2.x --> >=1.2.0 <2.0.0-0
|
|
1334
|
+
// ^1.2.3 --> >=1.2.3 <2.0.0-0
|
|
1335
|
+
// ^1.2.0 --> >=1.2.0 <2.0.0-0
|
|
1336
|
+
// ^0.0.1 --> >=0.0.1 <0.0.2-0
|
|
1337
|
+
// ^0.1.0 --> >=0.1.0 <0.2.0-0
|
|
1338
|
+
const replaceCarets = (comp, options) => {
|
|
1339
|
+
return comp
|
|
1340
|
+
.trim()
|
|
1341
|
+
.split(/\s+/)
|
|
1342
|
+
.map((c) => replaceCaret(c, options))
|
|
1343
|
+
.join(' ')
|
|
1344
|
+
};
|
|
1345
|
+
|
|
1346
|
+
const replaceCaret = (comp, options) => {
|
|
1347
|
+
debug('caret', comp, options);
|
|
1348
|
+
const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
|
|
1349
|
+
const z = options.includePrerelease ? '-0' : '';
|
|
1350
|
+
return comp.replace(r, (_, M, m, p, pr) => {
|
|
1351
|
+
debug('caret', comp, _, M, m, p, pr);
|
|
1352
|
+
let ret;
|
|
1353
|
+
|
|
1354
|
+
if (isX(M)) {
|
|
1355
|
+
ret = '';
|
|
1356
|
+
} else if (isX(m)) {
|
|
1357
|
+
ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
|
|
1358
|
+
} else if (isX(p)) {
|
|
1359
|
+
if (M === '0') {
|
|
1360
|
+
ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
|
|
1361
|
+
} else {
|
|
1362
|
+
ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`;
|
|
1363
|
+
}
|
|
1364
|
+
} else if (pr) {
|
|
1365
|
+
debug('replaceCaret pr', pr);
|
|
1366
|
+
if (M === '0') {
|
|
1367
|
+
if (m === '0') {
|
|
1368
|
+
ret = `>=${M}.${m}.${p}-${pr
|
|
1369
|
+
} <${M}.${m}.${+p + 1}-0`;
|
|
1370
|
+
} else {
|
|
1371
|
+
ret = `>=${M}.${m}.${p}-${pr
|
|
1372
|
+
} <${M}.${+m + 1}.0-0`;
|
|
1373
|
+
}
|
|
1374
|
+
} else {
|
|
1375
|
+
ret = `>=${M}.${m}.${p}-${pr
|
|
1376
|
+
} <${+M + 1}.0.0-0`;
|
|
1377
|
+
}
|
|
1378
|
+
} else {
|
|
1379
|
+
debug('no pr');
|
|
1380
|
+
if (M === '0') {
|
|
1381
|
+
if (m === '0') {
|
|
1382
|
+
ret = `>=${M}.${m}.${p
|
|
1383
|
+
}${z} <${M}.${m}.${+p + 1}-0`;
|
|
1384
|
+
} else {
|
|
1385
|
+
ret = `>=${M}.${m}.${p
|
|
1386
|
+
}${z} <${M}.${+m + 1}.0-0`;
|
|
1387
|
+
}
|
|
1388
|
+
} else {
|
|
1389
|
+
ret = `>=${M}.${m}.${p
|
|
1390
|
+
} <${+M + 1}.0.0-0`;
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
debug('caret return', ret);
|
|
1395
|
+
return ret
|
|
1396
|
+
})
|
|
1397
|
+
};
|
|
1398
|
+
|
|
1399
|
+
const replaceXRanges = (comp, options) => {
|
|
1400
|
+
debug('replaceXRanges', comp, options);
|
|
1401
|
+
return comp
|
|
1402
|
+
.split(/\s+/)
|
|
1403
|
+
.map((c) => replaceXRange(c, options))
|
|
1404
|
+
.join(' ')
|
|
1405
|
+
};
|
|
1406
|
+
|
|
1407
|
+
const replaceXRange = (comp, options) => {
|
|
1408
|
+
comp = comp.trim();
|
|
1409
|
+
const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
|
|
1410
|
+
return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
|
|
1411
|
+
debug('xRange', comp, ret, gtlt, M, m, p, pr);
|
|
1412
|
+
const xM = isX(M);
|
|
1413
|
+
const xm = xM || isX(m);
|
|
1414
|
+
const xp = xm || isX(p);
|
|
1415
|
+
const anyX = xp;
|
|
1416
|
+
|
|
1417
|
+
if (gtlt === '=' && anyX) {
|
|
1418
|
+
gtlt = '';
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
// if we're including prereleases in the match, then we need
|
|
1422
|
+
// to fix this to -0, the lowest possible prerelease value
|
|
1423
|
+
pr = options.includePrerelease ? '-0' : '';
|
|
1424
|
+
|
|
1425
|
+
if (xM) {
|
|
1426
|
+
if (gtlt === '>' || gtlt === '<') {
|
|
1427
|
+
// nothing is allowed
|
|
1428
|
+
ret = '<0.0.0-0';
|
|
1429
|
+
} else {
|
|
1430
|
+
// nothing is forbidden
|
|
1431
|
+
ret = '*';
|
|
1432
|
+
}
|
|
1433
|
+
} else if (gtlt && anyX) {
|
|
1434
|
+
// we know patch is an x, because we have any x at all.
|
|
1435
|
+
// replace X with 0
|
|
1436
|
+
if (xm) {
|
|
1437
|
+
m = 0;
|
|
1438
|
+
}
|
|
1439
|
+
p = 0;
|
|
1440
|
+
|
|
1441
|
+
if (gtlt === '>') {
|
|
1442
|
+
// >1 => >=2.0.0
|
|
1443
|
+
// >1.2 => >=1.3.0
|
|
1444
|
+
gtlt = '>=';
|
|
1445
|
+
if (xm) {
|
|
1446
|
+
M = +M + 1;
|
|
1447
|
+
m = 0;
|
|
1448
|
+
p = 0;
|
|
1449
|
+
} else {
|
|
1450
|
+
m = +m + 1;
|
|
1451
|
+
p = 0;
|
|
1452
|
+
}
|
|
1453
|
+
} else if (gtlt === '<=') {
|
|
1454
|
+
// <=0.7.x is actually <0.8.0, since any 0.7.x should
|
|
1455
|
+
// pass. Similarly, <=7.x is actually <8.0.0, etc.
|
|
1456
|
+
gtlt = '<';
|
|
1457
|
+
if (xm) {
|
|
1458
|
+
M = +M + 1;
|
|
1459
|
+
} else {
|
|
1460
|
+
m = +m + 1;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
if (gtlt === '<') {
|
|
1465
|
+
pr = '-0';
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
ret = `${gtlt + M}.${m}.${p}${pr}`;
|
|
1469
|
+
} else if (xm) {
|
|
1470
|
+
ret = `>=${M}.0.0${pr} <${+M + 1}.0.0-0`;
|
|
1471
|
+
} else if (xp) {
|
|
1472
|
+
ret = `>=${M}.${m}.0${pr
|
|
1473
|
+
} <${M}.${+m + 1}.0-0`;
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
debug('xRange return', ret);
|
|
1477
|
+
|
|
1478
|
+
return ret
|
|
1479
|
+
})
|
|
1480
|
+
};
|
|
1481
|
+
|
|
1482
|
+
// Because * is AND-ed with everything else in the comparator,
|
|
1483
|
+
// and '' means "any version", just remove the *s entirely.
|
|
1484
|
+
const replaceStars = (comp, options) => {
|
|
1485
|
+
debug('replaceStars', comp, options);
|
|
1486
|
+
// Looseness is ignored here. star is always as loose as it gets!
|
|
1487
|
+
return comp
|
|
1488
|
+
.trim()
|
|
1489
|
+
.replace(re[t.STAR], '')
|
|
1490
|
+
};
|
|
1491
|
+
|
|
1492
|
+
const replaceGTE0 = (comp, options) => {
|
|
1493
|
+
debug('replaceGTE0', comp, options);
|
|
1494
|
+
return comp
|
|
1495
|
+
.trim()
|
|
1496
|
+
.replace(re[options.includePrerelease ? t.GTE0PRE : t.GTE0], '')
|
|
1497
|
+
};
|
|
1498
|
+
|
|
1499
|
+
// This function is passed to string.replace(re[t.HYPHENRANGE])
|
|
1500
|
+
// M, m, patch, prerelease, build
|
|
1501
|
+
// 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
|
|
1502
|
+
// 1.2.3 - 3.4 => >=1.2.0 <3.5.0-0 Any 3.4.x will do
|
|
1503
|
+
// 1.2 - 3.4 => >=1.2.0 <3.5.0-0
|
|
1504
|
+
// TODO build?
|
|
1505
|
+
const hyphenReplace = incPr => ($0,
|
|
1506
|
+
from, fM, fm, fp, fpr, fb,
|
|
1507
|
+
to, tM, tm, tp, tpr) => {
|
|
1508
|
+
if (isX(fM)) {
|
|
1509
|
+
from = '';
|
|
1510
|
+
} else if (isX(fm)) {
|
|
1511
|
+
from = `>=${fM}.0.0${incPr ? '-0' : ''}`;
|
|
1512
|
+
} else if (isX(fp)) {
|
|
1513
|
+
from = `>=${fM}.${fm}.0${incPr ? '-0' : ''}`;
|
|
1514
|
+
} else if (fpr) {
|
|
1515
|
+
from = `>=${from}`;
|
|
1516
|
+
} else {
|
|
1517
|
+
from = `>=${from}${incPr ? '-0' : ''}`;
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
if (isX(tM)) {
|
|
1521
|
+
to = '';
|
|
1522
|
+
} else if (isX(tm)) {
|
|
1523
|
+
to = `<${+tM + 1}.0.0-0`;
|
|
1524
|
+
} else if (isX(tp)) {
|
|
1525
|
+
to = `<${tM}.${+tm + 1}.0-0`;
|
|
1526
|
+
} else if (tpr) {
|
|
1527
|
+
to = `<=${tM}.${tm}.${tp}-${tpr}`;
|
|
1528
|
+
} else if (incPr) {
|
|
1529
|
+
to = `<${tM}.${tm}.${+tp + 1}-0`;
|
|
1530
|
+
} else {
|
|
1531
|
+
to = `<=${to}`;
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
return `${from} ${to}`.trim()
|
|
1535
|
+
};
|
|
1536
|
+
|
|
1537
|
+
const testSet = (set, version, options) => {
|
|
1538
|
+
for (let i = 0; i < set.length; i++) {
|
|
1539
|
+
if (!set[i].test(version)) {
|
|
1540
|
+
return false
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
if (version.prerelease.length && !options.includePrerelease) {
|
|
1545
|
+
// Find the set of versions that are allowed to have prereleases
|
|
1546
|
+
// For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
|
|
1547
|
+
// That should allow `1.2.3-pr.2` to pass.
|
|
1548
|
+
// However, `1.2.4-alpha.notready` should NOT be allowed,
|
|
1549
|
+
// even though it's within the range set by the comparators.
|
|
1550
|
+
for (let i = 0; i < set.length; i++) {
|
|
1551
|
+
debug(set[i].semver);
|
|
1552
|
+
if (set[i].semver === Comparator.ANY) {
|
|
1553
|
+
continue
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
if (set[i].semver.prerelease.length > 0) {
|
|
1557
|
+
const allowed = set[i].semver;
|
|
1558
|
+
if (allowed.major === version.major &&
|
|
1559
|
+
allowed.minor === version.minor &&
|
|
1560
|
+
allowed.patch === version.patch) {
|
|
1561
|
+
return true
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
// Version has a -pre, but it's not one of the ones we like.
|
|
1567
|
+
return false
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
return true
|
|
1571
|
+
};
|
|
1572
|
+
return range;
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
var comparator;
|
|
1576
|
+
var hasRequiredComparator;
|
|
1577
|
+
|
|
1578
|
+
function requireComparator () {
|
|
1579
|
+
if (hasRequiredComparator) return comparator;
|
|
1580
|
+
hasRequiredComparator = 1;
|
|
1581
|
+
|
|
1582
|
+
const ANY = Symbol('SemVer ANY');
|
|
1583
|
+
// hoisted class for cyclic dependency
|
|
1584
|
+
class Comparator {
|
|
1585
|
+
static get ANY () {
|
|
1586
|
+
return ANY
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
constructor (comp, options) {
|
|
1590
|
+
options = parseOptions(options);
|
|
1591
|
+
|
|
1592
|
+
if (comp instanceof Comparator) {
|
|
1593
|
+
if (comp.loose === !!options.loose) {
|
|
1594
|
+
return comp
|
|
1595
|
+
} else {
|
|
1596
|
+
comp = comp.value;
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
comp = comp.trim().split(/\s+/).join(' ');
|
|
1601
|
+
debug('comparator', comp, options);
|
|
1602
|
+
this.options = options;
|
|
1603
|
+
this.loose = !!options.loose;
|
|
1604
|
+
this.parse(comp);
|
|
1605
|
+
|
|
1606
|
+
if (this.semver === ANY) {
|
|
1607
|
+
this.value = '';
|
|
1608
|
+
} else {
|
|
1609
|
+
this.value = this.operator + this.semver.version;
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
debug('comp', this);
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
parse (comp) {
|
|
1616
|
+
const r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
|
|
1617
|
+
const m = comp.match(r);
|
|
1618
|
+
|
|
1619
|
+
if (!m) {
|
|
1620
|
+
throw new TypeError(`Invalid comparator: ${comp}`)
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
this.operator = m[1] !== undefined ? m[1] : '';
|
|
1624
|
+
if (this.operator === '=') {
|
|
1625
|
+
this.operator = '';
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
// if it literally is just '>' or '' then allow anything.
|
|
1629
|
+
if (!m[2]) {
|
|
1630
|
+
this.semver = ANY;
|
|
1631
|
+
} else {
|
|
1632
|
+
this.semver = new SemVer(m[2], this.options.loose);
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
toString () {
|
|
1637
|
+
return this.value
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
test (version) {
|
|
1641
|
+
debug('Comparator.test', version, this.options.loose);
|
|
1642
|
+
|
|
1643
|
+
if (this.semver === ANY || version === ANY) {
|
|
1644
|
+
return true
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
if (typeof version === 'string') {
|
|
1648
|
+
try {
|
|
1649
|
+
version = new SemVer(version, this.options);
|
|
1650
|
+
} catch (er) {
|
|
1651
|
+
return false
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
return cmp(version, this.operator, this.semver, this.options)
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
intersects (comp, options) {
|
|
1659
|
+
if (!(comp instanceof Comparator)) {
|
|
1660
|
+
throw new TypeError('a Comparator is required')
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
if (this.operator === '') {
|
|
1664
|
+
if (this.value === '') {
|
|
1665
|
+
return true
|
|
1666
|
+
}
|
|
1667
|
+
return new Range(comp.value, options).test(this.value)
|
|
1668
|
+
} else if (comp.operator === '') {
|
|
1669
|
+
if (comp.value === '') {
|
|
1670
|
+
return true
|
|
1671
|
+
}
|
|
1672
|
+
return new Range(this.value, options).test(comp.semver)
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
options = parseOptions(options);
|
|
1676
|
+
|
|
1677
|
+
// Special cases where nothing can possibly be lower
|
|
1678
|
+
if (options.includePrerelease &&
|
|
1679
|
+
(this.value === '<0.0.0-0' || comp.value === '<0.0.0-0')) {
|
|
1680
|
+
return false
|
|
1681
|
+
}
|
|
1682
|
+
if (!options.includePrerelease &&
|
|
1683
|
+
(this.value.startsWith('<0.0.0') || comp.value.startsWith('<0.0.0'))) {
|
|
1684
|
+
return false
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
// Same direction increasing (> or >=)
|
|
1688
|
+
if (this.operator.startsWith('>') && comp.operator.startsWith('>')) {
|
|
1689
|
+
return true
|
|
1690
|
+
}
|
|
1691
|
+
// Same direction decreasing (< or <=)
|
|
1692
|
+
if (this.operator.startsWith('<') && comp.operator.startsWith('<')) {
|
|
1693
|
+
return true
|
|
1694
|
+
}
|
|
1695
|
+
// same SemVer and both sides are inclusive (<= or >=)
|
|
1696
|
+
if (
|
|
1697
|
+
(this.semver.version === comp.semver.version) &&
|
|
1698
|
+
this.operator.includes('=') && comp.operator.includes('=')) {
|
|
1699
|
+
return true
|
|
1700
|
+
}
|
|
1701
|
+
// opposite directions less than
|
|
1702
|
+
if (cmp(this.semver, '<', comp.semver, options) &&
|
|
1703
|
+
this.operator.startsWith('>') && comp.operator.startsWith('<')) {
|
|
1704
|
+
return true
|
|
1705
|
+
}
|
|
1706
|
+
// opposite directions greater than
|
|
1707
|
+
if (cmp(this.semver, '>', comp.semver, options) &&
|
|
1708
|
+
this.operator.startsWith('<') && comp.operator.startsWith('>')) {
|
|
1709
|
+
return true
|
|
1710
|
+
}
|
|
1711
|
+
return false
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
comparator = Comparator;
|
|
1716
|
+
|
|
1717
|
+
const parseOptions = parseOptions_1;
|
|
1718
|
+
const { safeRe: re, t } = reExports;
|
|
1719
|
+
const cmp = cmp_1;
|
|
1720
|
+
const debug = debug_1;
|
|
1721
|
+
const SemVer = semver$2;
|
|
1722
|
+
const Range = requireRange();
|
|
1723
|
+
return comparator;
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
const Range$9 = requireRange();
|
|
1727
|
+
const satisfies$4 = (version, range, options) => {
|
|
1728
|
+
try {
|
|
1729
|
+
range = new Range$9(range, options);
|
|
1730
|
+
} catch (er) {
|
|
1731
|
+
return false
|
|
1732
|
+
}
|
|
1733
|
+
return range.test(version)
|
|
1734
|
+
};
|
|
1735
|
+
var satisfies_1 = satisfies$4;
|
|
1736
|
+
|
|
1737
|
+
const Range$8 = requireRange();
|
|
1738
|
+
|
|
1739
|
+
// Mostly just for testing and legacy API reasons
|
|
1740
|
+
const toComparators$1 = (range, options) =>
|
|
1741
|
+
new Range$8(range, options).set
|
|
1742
|
+
.map(comp => comp.map(c => c.value).join(' ').trim().split(' '));
|
|
1743
|
+
|
|
1744
|
+
var toComparators_1 = toComparators$1;
|
|
1745
|
+
|
|
1746
|
+
const SemVer$4 = semver$2;
|
|
1747
|
+
const Range$7 = requireRange();
|
|
1748
|
+
|
|
1749
|
+
const maxSatisfying$1 = (versions, range, options) => {
|
|
1750
|
+
let max = null;
|
|
1751
|
+
let maxSV = null;
|
|
1752
|
+
let rangeObj = null;
|
|
1753
|
+
try {
|
|
1754
|
+
rangeObj = new Range$7(range, options);
|
|
1755
|
+
} catch (er) {
|
|
1756
|
+
return null
|
|
1757
|
+
}
|
|
1758
|
+
versions.forEach((v) => {
|
|
1759
|
+
if (rangeObj.test(v)) {
|
|
1760
|
+
// satisfies(v, range, options)
|
|
1761
|
+
if (!max || maxSV.compare(v) === -1) {
|
|
1762
|
+
// compare(max, v, true)
|
|
1763
|
+
max = v;
|
|
1764
|
+
maxSV = new SemVer$4(max, options);
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
});
|
|
1768
|
+
return max
|
|
1769
|
+
};
|
|
1770
|
+
var maxSatisfying_1 = maxSatisfying$1;
|
|
1771
|
+
|
|
1772
|
+
const SemVer$3 = semver$2;
|
|
1773
|
+
const Range$6 = requireRange();
|
|
1774
|
+
const minSatisfying$1 = (versions, range, options) => {
|
|
1775
|
+
let min = null;
|
|
1776
|
+
let minSV = null;
|
|
1777
|
+
let rangeObj = null;
|
|
1778
|
+
try {
|
|
1779
|
+
rangeObj = new Range$6(range, options);
|
|
1780
|
+
} catch (er) {
|
|
1781
|
+
return null
|
|
1782
|
+
}
|
|
1783
|
+
versions.forEach((v) => {
|
|
1784
|
+
if (rangeObj.test(v)) {
|
|
1785
|
+
// satisfies(v, range, options)
|
|
1786
|
+
if (!min || minSV.compare(v) === 1) {
|
|
1787
|
+
// compare(min, v, true)
|
|
1788
|
+
min = v;
|
|
1789
|
+
minSV = new SemVer$3(min, options);
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
});
|
|
1793
|
+
return min
|
|
1794
|
+
};
|
|
1795
|
+
var minSatisfying_1 = minSatisfying$1;
|
|
1796
|
+
|
|
1797
|
+
const SemVer$2 = semver$2;
|
|
1798
|
+
const Range$5 = requireRange();
|
|
1799
|
+
const gt$2 = gt_1;
|
|
1800
|
+
|
|
1801
|
+
const minVersion$1 = (range, loose) => {
|
|
1802
|
+
range = new Range$5(range, loose);
|
|
1803
|
+
|
|
1804
|
+
let minver = new SemVer$2('0.0.0');
|
|
1805
|
+
if (range.test(minver)) {
|
|
1806
|
+
return minver
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
minver = new SemVer$2('0.0.0-0');
|
|
1810
|
+
if (range.test(minver)) {
|
|
1811
|
+
return minver
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1814
|
+
minver = null;
|
|
1815
|
+
for (let i = 0; i < range.set.length; ++i) {
|
|
1816
|
+
const comparators = range.set[i];
|
|
1817
|
+
|
|
1818
|
+
let setMin = null;
|
|
1819
|
+
comparators.forEach((comparator) => {
|
|
1820
|
+
// Clone to avoid manipulating the comparator's semver object.
|
|
1821
|
+
const compver = new SemVer$2(comparator.semver.version);
|
|
1822
|
+
switch (comparator.operator) {
|
|
1823
|
+
case '>':
|
|
1824
|
+
if (compver.prerelease.length === 0) {
|
|
1825
|
+
compver.patch++;
|
|
1826
|
+
} else {
|
|
1827
|
+
compver.prerelease.push(0);
|
|
1828
|
+
}
|
|
1829
|
+
compver.raw = compver.format();
|
|
1830
|
+
/* fallthrough */
|
|
1831
|
+
case '':
|
|
1832
|
+
case '>=':
|
|
1833
|
+
if (!setMin || gt$2(compver, setMin)) {
|
|
1834
|
+
setMin = compver;
|
|
1835
|
+
}
|
|
1836
|
+
break
|
|
1837
|
+
case '<':
|
|
1838
|
+
case '<=':
|
|
1839
|
+
/* Ignore maximum versions */
|
|
1840
|
+
break
|
|
1841
|
+
/* istanbul ignore next */
|
|
1842
|
+
default:
|
|
1843
|
+
throw new Error(`Unexpected operation: ${comparator.operator}`)
|
|
1844
|
+
}
|
|
1845
|
+
});
|
|
1846
|
+
if (setMin && (!minver || gt$2(minver, setMin))) {
|
|
1847
|
+
minver = setMin;
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
if (minver && range.test(minver)) {
|
|
1852
|
+
return minver
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
return null
|
|
1856
|
+
};
|
|
1857
|
+
var minVersion_1 = minVersion$1;
|
|
1858
|
+
|
|
1859
|
+
const Range$4 = requireRange();
|
|
1860
|
+
const validRange$1 = (range, options) => {
|
|
1861
|
+
try {
|
|
1862
|
+
// Return '*' instead of '' so that truthiness works.
|
|
1863
|
+
// This will throw if it's invalid anyway
|
|
1864
|
+
return new Range$4(range, options).range || '*'
|
|
1865
|
+
} catch (er) {
|
|
1866
|
+
return null
|
|
1867
|
+
}
|
|
1868
|
+
};
|
|
1869
|
+
var valid$1 = validRange$1;
|
|
1870
|
+
|
|
1871
|
+
const SemVer$1 = semver$2;
|
|
1872
|
+
const Comparator$2 = requireComparator();
|
|
1873
|
+
const { ANY: ANY$1 } = Comparator$2;
|
|
1874
|
+
const Range$3 = requireRange();
|
|
1875
|
+
const satisfies$3 = satisfies_1;
|
|
1876
|
+
const gt$1 = gt_1;
|
|
1877
|
+
const lt$1 = lt_1;
|
|
1878
|
+
const lte$1 = lte_1;
|
|
1879
|
+
const gte$1 = gte_1;
|
|
1880
|
+
|
|
1881
|
+
const outside$3 = (version, range, hilo, options) => {
|
|
1882
|
+
version = new SemVer$1(version, options);
|
|
1883
|
+
range = new Range$3(range, options);
|
|
1884
|
+
|
|
1885
|
+
let gtfn, ltefn, ltfn, comp, ecomp;
|
|
1886
|
+
switch (hilo) {
|
|
1887
|
+
case '>':
|
|
1888
|
+
gtfn = gt$1;
|
|
1889
|
+
ltefn = lte$1;
|
|
1890
|
+
ltfn = lt$1;
|
|
1891
|
+
comp = '>';
|
|
1892
|
+
ecomp = '>=';
|
|
1893
|
+
break
|
|
1894
|
+
case '<':
|
|
1895
|
+
gtfn = lt$1;
|
|
1896
|
+
ltefn = gte$1;
|
|
1897
|
+
ltfn = gt$1;
|
|
1898
|
+
comp = '<';
|
|
1899
|
+
ecomp = '<=';
|
|
1900
|
+
break
|
|
1901
|
+
default:
|
|
1902
|
+
throw new TypeError('Must provide a hilo val of "<" or ">"')
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
// If it satisfies the range it is not outside
|
|
1906
|
+
if (satisfies$3(version, range, options)) {
|
|
1907
|
+
return false
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
// From now on, variable terms are as if we're in "gtr" mode.
|
|
1911
|
+
// but note that everything is flipped for the "ltr" function.
|
|
1912
|
+
|
|
1913
|
+
for (let i = 0; i < range.set.length; ++i) {
|
|
1914
|
+
const comparators = range.set[i];
|
|
1915
|
+
|
|
1916
|
+
let high = null;
|
|
1917
|
+
let low = null;
|
|
1918
|
+
|
|
1919
|
+
comparators.forEach((comparator) => {
|
|
1920
|
+
if (comparator.semver === ANY$1) {
|
|
1921
|
+
comparator = new Comparator$2('>=0.0.0');
|
|
1922
|
+
}
|
|
1923
|
+
high = high || comparator;
|
|
1924
|
+
low = low || comparator;
|
|
1925
|
+
if (gtfn(comparator.semver, high.semver, options)) {
|
|
1926
|
+
high = comparator;
|
|
1927
|
+
} else if (ltfn(comparator.semver, low.semver, options)) {
|
|
1928
|
+
low = comparator;
|
|
1929
|
+
}
|
|
1930
|
+
});
|
|
1931
|
+
|
|
1932
|
+
// If the edge version comparator has a operator then our version
|
|
1933
|
+
// isn't outside it
|
|
1934
|
+
if (high.operator === comp || high.operator === ecomp) {
|
|
1935
|
+
return false
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
// If the lowest version comparator has an operator and our version
|
|
1939
|
+
// is less than it then it isn't higher than the range
|
|
1940
|
+
if ((!low.operator || low.operator === comp) &&
|
|
1941
|
+
ltefn(version, low.semver)) {
|
|
1942
|
+
return false
|
|
1943
|
+
} else if (low.operator === ecomp && ltfn(version, low.semver)) {
|
|
1944
|
+
return false
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
return true
|
|
1948
|
+
};
|
|
1949
|
+
|
|
1950
|
+
var outside_1 = outside$3;
|
|
1951
|
+
|
|
1952
|
+
// Determine if version is greater than all the versions possible in the range.
|
|
1953
|
+
const outside$2 = outside_1;
|
|
1954
|
+
const gtr$1 = (version, range, options) => outside$2(version, range, '>', options);
|
|
1955
|
+
var gtr_1 = gtr$1;
|
|
1956
|
+
|
|
1957
|
+
const outside$1 = outside_1;
|
|
1958
|
+
// Determine if version is less than all the versions possible in the range
|
|
1959
|
+
const ltr$1 = (version, range, options) => outside$1(version, range, '<', options);
|
|
1960
|
+
var ltr_1 = ltr$1;
|
|
1961
|
+
|
|
1962
|
+
const Range$2 = requireRange();
|
|
1963
|
+
const intersects$1 = (r1, r2, options) => {
|
|
1964
|
+
r1 = new Range$2(r1, options);
|
|
1965
|
+
r2 = new Range$2(r2, options);
|
|
1966
|
+
return r1.intersects(r2, options)
|
|
1967
|
+
};
|
|
1968
|
+
var intersects_1 = intersects$1;
|
|
1969
|
+
|
|
1970
|
+
// given a set of versions and a range, create a "simplified" range
|
|
1971
|
+
// that includes the same versions that the original range does
|
|
1972
|
+
// If the original range is shorter than the simplified one, return that.
|
|
1973
|
+
const satisfies$2 = satisfies_1;
|
|
1974
|
+
const compare$2 = compare_1;
|
|
1975
|
+
var simplify = (versions, range, options) => {
|
|
1976
|
+
const set = [];
|
|
1977
|
+
let first = null;
|
|
1978
|
+
let prev = null;
|
|
1979
|
+
const v = versions.sort((a, b) => compare$2(a, b, options));
|
|
1980
|
+
for (const version of v) {
|
|
1981
|
+
const included = satisfies$2(version, range, options);
|
|
1982
|
+
if (included) {
|
|
1983
|
+
prev = version;
|
|
1984
|
+
if (!first) {
|
|
1985
|
+
first = version;
|
|
1986
|
+
}
|
|
1987
|
+
} else {
|
|
1988
|
+
if (prev) {
|
|
1989
|
+
set.push([first, prev]);
|
|
1990
|
+
}
|
|
1991
|
+
prev = null;
|
|
1992
|
+
first = null;
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
if (first) {
|
|
1996
|
+
set.push([first, null]);
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
const ranges = [];
|
|
2000
|
+
for (const [min, max] of set) {
|
|
2001
|
+
if (min === max) {
|
|
2002
|
+
ranges.push(min);
|
|
2003
|
+
} else if (!max && min === v[0]) {
|
|
2004
|
+
ranges.push('*');
|
|
2005
|
+
} else if (!max) {
|
|
2006
|
+
ranges.push(`>=${min}`);
|
|
2007
|
+
} else if (min === v[0]) {
|
|
2008
|
+
ranges.push(`<=${max}`);
|
|
2009
|
+
} else {
|
|
2010
|
+
ranges.push(`${min} - ${max}`);
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
const simplified = ranges.join(' || ');
|
|
2014
|
+
const original = typeof range.raw === 'string' ? range.raw : String(range);
|
|
2015
|
+
return simplified.length < original.length ? simplified : range
|
|
2016
|
+
};
|
|
2017
|
+
|
|
2018
|
+
const Range$1 = requireRange();
|
|
2019
|
+
const Comparator$1 = requireComparator();
|
|
2020
|
+
const { ANY } = Comparator$1;
|
|
2021
|
+
const satisfies$1 = satisfies_1;
|
|
2022
|
+
const compare$1 = compare_1;
|
|
2023
|
+
|
|
2024
|
+
// Complex range `r1 || r2 || ...` is a subset of `R1 || R2 || ...` iff:
|
|
2025
|
+
// - Every simple range `r1, r2, ...` is a null set, OR
|
|
2026
|
+
// - Every simple range `r1, r2, ...` which is not a null set is a subset of
|
|
2027
|
+
// some `R1, R2, ...`
|
|
2028
|
+
//
|
|
2029
|
+
// Simple range `c1 c2 ...` is a subset of simple range `C1 C2 ...` iff:
|
|
2030
|
+
// - If c is only the ANY comparator
|
|
2031
|
+
// - If C is only the ANY comparator, return true
|
|
2032
|
+
// - Else if in prerelease mode, return false
|
|
2033
|
+
// - else replace c with `[>=0.0.0]`
|
|
2034
|
+
// - If C is only the ANY comparator
|
|
2035
|
+
// - if in prerelease mode, return true
|
|
2036
|
+
// - else replace C with `[>=0.0.0]`
|
|
2037
|
+
// - Let EQ be the set of = comparators in c
|
|
2038
|
+
// - If EQ is more than one, return true (null set)
|
|
2039
|
+
// - Let GT be the highest > or >= comparator in c
|
|
2040
|
+
// - Let LT be the lowest < or <= comparator in c
|
|
2041
|
+
// - If GT and LT, and GT.semver > LT.semver, return true (null set)
|
|
2042
|
+
// - If any C is a = range, and GT or LT are set, return false
|
|
2043
|
+
// - If EQ
|
|
2044
|
+
// - If GT, and EQ does not satisfy GT, return true (null set)
|
|
2045
|
+
// - If LT, and EQ does not satisfy LT, return true (null set)
|
|
2046
|
+
// - If EQ satisfies every C, return true
|
|
2047
|
+
// - Else return false
|
|
2048
|
+
// - If GT
|
|
2049
|
+
// - If GT.semver is lower than any > or >= comp in C, return false
|
|
2050
|
+
// - If GT is >=, and GT.semver does not satisfy every C, return false
|
|
2051
|
+
// - If GT.semver has a prerelease, and not in prerelease mode
|
|
2052
|
+
// - If no C has a prerelease and the GT.semver tuple, return false
|
|
2053
|
+
// - If LT
|
|
2054
|
+
// - If LT.semver is greater than any < or <= comp in C, return false
|
|
2055
|
+
// - If LT is <=, and LT.semver does not satisfy every C, return false
|
|
2056
|
+
// - If GT.semver has a prerelease, and not in prerelease mode
|
|
2057
|
+
// - If no C has a prerelease and the LT.semver tuple, return false
|
|
2058
|
+
// - Else return true
|
|
2059
|
+
|
|
2060
|
+
const subset$1 = (sub, dom, options = {}) => {
|
|
2061
|
+
if (sub === dom) {
|
|
2062
|
+
return true
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
sub = new Range$1(sub, options);
|
|
2066
|
+
dom = new Range$1(dom, options);
|
|
2067
|
+
let sawNonNull = false;
|
|
2068
|
+
|
|
2069
|
+
OUTER: for (const simpleSub of sub.set) {
|
|
2070
|
+
for (const simpleDom of dom.set) {
|
|
2071
|
+
const isSub = simpleSubset(simpleSub, simpleDom, options);
|
|
2072
|
+
sawNonNull = sawNonNull || isSub !== null;
|
|
2073
|
+
if (isSub) {
|
|
2074
|
+
continue OUTER
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
// the null set is a subset of everything, but null simple ranges in
|
|
2078
|
+
// a complex range should be ignored. so if we saw a non-null range,
|
|
2079
|
+
// then we know this isn't a subset, but if EVERY simple range was null,
|
|
2080
|
+
// then it is a subset.
|
|
2081
|
+
if (sawNonNull) {
|
|
2082
|
+
return false
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
return true
|
|
2086
|
+
};
|
|
2087
|
+
|
|
2088
|
+
const minimumVersionWithPreRelease = [new Comparator$1('>=0.0.0-0')];
|
|
2089
|
+
const minimumVersion = [new Comparator$1('>=0.0.0')];
|
|
2090
|
+
|
|
2091
|
+
const simpleSubset = (sub, dom, options) => {
|
|
2092
|
+
if (sub === dom) {
|
|
2093
|
+
return true
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
if (sub.length === 1 && sub[0].semver === ANY) {
|
|
2097
|
+
if (dom.length === 1 && dom[0].semver === ANY) {
|
|
2098
|
+
return true
|
|
2099
|
+
} else if (options.includePrerelease) {
|
|
2100
|
+
sub = minimumVersionWithPreRelease;
|
|
2101
|
+
} else {
|
|
2102
|
+
sub = minimumVersion;
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
|
|
2106
|
+
if (dom.length === 1 && dom[0].semver === ANY) {
|
|
2107
|
+
if (options.includePrerelease) {
|
|
2108
|
+
return true
|
|
2109
|
+
} else {
|
|
2110
|
+
dom = minimumVersion;
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2114
|
+
const eqSet = new Set();
|
|
2115
|
+
let gt, lt;
|
|
2116
|
+
for (const c of sub) {
|
|
2117
|
+
if (c.operator === '>' || c.operator === '>=') {
|
|
2118
|
+
gt = higherGT(gt, c, options);
|
|
2119
|
+
} else if (c.operator === '<' || c.operator === '<=') {
|
|
2120
|
+
lt = lowerLT(lt, c, options);
|
|
2121
|
+
} else {
|
|
2122
|
+
eqSet.add(c.semver);
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
|
|
2126
|
+
if (eqSet.size > 1) {
|
|
2127
|
+
return null
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2130
|
+
let gtltComp;
|
|
2131
|
+
if (gt && lt) {
|
|
2132
|
+
gtltComp = compare$1(gt.semver, lt.semver, options);
|
|
2133
|
+
if (gtltComp > 0) {
|
|
2134
|
+
return null
|
|
2135
|
+
} else if (gtltComp === 0 && (gt.operator !== '>=' || lt.operator !== '<=')) {
|
|
2136
|
+
return null
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
// will iterate one or zero times
|
|
2141
|
+
for (const eq of eqSet) {
|
|
2142
|
+
if (gt && !satisfies$1(eq, String(gt), options)) {
|
|
2143
|
+
return null
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
if (lt && !satisfies$1(eq, String(lt), options)) {
|
|
2147
|
+
return null
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
for (const c of dom) {
|
|
2151
|
+
if (!satisfies$1(eq, String(c), options)) {
|
|
2152
|
+
return false
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
|
|
2156
|
+
return true
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
let higher, lower;
|
|
2160
|
+
let hasDomLT, hasDomGT;
|
|
2161
|
+
// if the subset has a prerelease, we need a comparator in the superset
|
|
2162
|
+
// with the same tuple and a prerelease, or it's not a subset
|
|
2163
|
+
let needDomLTPre = lt &&
|
|
2164
|
+
!options.includePrerelease &&
|
|
2165
|
+
lt.semver.prerelease.length ? lt.semver : false;
|
|
2166
|
+
let needDomGTPre = gt &&
|
|
2167
|
+
!options.includePrerelease &&
|
|
2168
|
+
gt.semver.prerelease.length ? gt.semver : false;
|
|
2169
|
+
// exception: <1.2.3-0 is the same as <1.2.3
|
|
2170
|
+
if (needDomLTPre && needDomLTPre.prerelease.length === 1 &&
|
|
2171
|
+
lt.operator === '<' && needDomLTPre.prerelease[0] === 0) {
|
|
2172
|
+
needDomLTPre = false;
|
|
2173
|
+
}
|
|
2174
|
+
|
|
2175
|
+
for (const c of dom) {
|
|
2176
|
+
hasDomGT = hasDomGT || c.operator === '>' || c.operator === '>=';
|
|
2177
|
+
hasDomLT = hasDomLT || c.operator === '<' || c.operator === '<=';
|
|
2178
|
+
if (gt) {
|
|
2179
|
+
if (needDomGTPre) {
|
|
2180
|
+
if (c.semver.prerelease && c.semver.prerelease.length &&
|
|
2181
|
+
c.semver.major === needDomGTPre.major &&
|
|
2182
|
+
c.semver.minor === needDomGTPre.minor &&
|
|
2183
|
+
c.semver.patch === needDomGTPre.patch) {
|
|
2184
|
+
needDomGTPre = false;
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
if (c.operator === '>' || c.operator === '>=') {
|
|
2188
|
+
higher = higherGT(gt, c, options);
|
|
2189
|
+
if (higher === c && higher !== gt) {
|
|
2190
|
+
return false
|
|
2191
|
+
}
|
|
2192
|
+
} else if (gt.operator === '>=' && !satisfies$1(gt.semver, String(c), options)) {
|
|
2193
|
+
return false
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
if (lt) {
|
|
2197
|
+
if (needDomLTPre) {
|
|
2198
|
+
if (c.semver.prerelease && c.semver.prerelease.length &&
|
|
2199
|
+
c.semver.major === needDomLTPre.major &&
|
|
2200
|
+
c.semver.minor === needDomLTPre.minor &&
|
|
2201
|
+
c.semver.patch === needDomLTPre.patch) {
|
|
2202
|
+
needDomLTPre = false;
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
if (c.operator === '<' || c.operator === '<=') {
|
|
2206
|
+
lower = lowerLT(lt, c, options);
|
|
2207
|
+
if (lower === c && lower !== lt) {
|
|
2208
|
+
return false
|
|
2209
|
+
}
|
|
2210
|
+
} else if (lt.operator === '<=' && !satisfies$1(lt.semver, String(c), options)) {
|
|
2211
|
+
return false
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
if (!c.operator && (lt || gt) && gtltComp !== 0) {
|
|
2215
|
+
return false
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
// if there was a < or >, and nothing in the dom, then must be false
|
|
2220
|
+
// UNLESS it was limited by another range in the other direction.
|
|
2221
|
+
// Eg, >1.0.0 <1.0.1 is still a subset of <2.0.0
|
|
2222
|
+
if (gt && hasDomLT && !lt && gtltComp !== 0) {
|
|
2223
|
+
return false
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
if (lt && hasDomGT && !gt && gtltComp !== 0) {
|
|
2227
|
+
return false
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
// we needed a prerelease range in a specific tuple, but didn't get one
|
|
2231
|
+
// then this isn't a subset. eg >=1.2.3-pre is not a subset of >=1.0.0,
|
|
2232
|
+
// because it includes prereleases in the 1.2.3 tuple
|
|
2233
|
+
if (needDomGTPre || needDomLTPre) {
|
|
2234
|
+
return false
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
return true
|
|
2238
|
+
};
|
|
2239
|
+
|
|
2240
|
+
// >=1.2.3 is lower than >1.2.3
|
|
2241
|
+
const higherGT = (a, b, options) => {
|
|
2242
|
+
if (!a) {
|
|
2243
|
+
return b
|
|
2244
|
+
}
|
|
2245
|
+
const comp = compare$1(a.semver, b.semver, options);
|
|
2246
|
+
return comp > 0 ? a
|
|
2247
|
+
: comp < 0 ? b
|
|
2248
|
+
: b.operator === '>' && a.operator === '>=' ? b
|
|
2249
|
+
: a
|
|
2250
|
+
};
|
|
2251
|
+
|
|
2252
|
+
// <=1.2.3 is higher than <1.2.3
|
|
2253
|
+
const lowerLT = (a, b, options) => {
|
|
2254
|
+
if (!a) {
|
|
2255
|
+
return b
|
|
2256
|
+
}
|
|
2257
|
+
const comp = compare$1(a.semver, b.semver, options);
|
|
2258
|
+
return comp < 0 ? a
|
|
2259
|
+
: comp > 0 ? b
|
|
2260
|
+
: b.operator === '<' && a.operator === '<=' ? b
|
|
2261
|
+
: a
|
|
2262
|
+
};
|
|
2263
|
+
|
|
2264
|
+
var subset_1 = subset$1;
|
|
2265
|
+
|
|
2266
|
+
// just pre-load all the stuff that index.js lazily exports
|
|
2267
|
+
const internalRe = reExports;
|
|
2268
|
+
const constants = constants$1;
|
|
2269
|
+
const SemVer = semver$2;
|
|
2270
|
+
const identifiers = identifiers$1;
|
|
2271
|
+
const parse = parse_1;
|
|
2272
|
+
const valid = valid_1;
|
|
2273
|
+
const clean = clean_1;
|
|
2274
|
+
const inc = inc_1;
|
|
2275
|
+
const diff = diff_1;
|
|
2276
|
+
const major = major_1;
|
|
2277
|
+
const minor = minor_1;
|
|
2278
|
+
const patch = patch_1;
|
|
2279
|
+
const prerelease = prerelease_1;
|
|
2280
|
+
const compare = compare_1;
|
|
2281
|
+
const rcompare = rcompare_1;
|
|
2282
|
+
const compareLoose = compareLoose_1;
|
|
2283
|
+
const compareBuild = compareBuild_1;
|
|
2284
|
+
const sort = sort_1;
|
|
2285
|
+
const rsort = rsort_1;
|
|
2286
|
+
const gt = gt_1;
|
|
2287
|
+
const lt = lt_1;
|
|
2288
|
+
const eq = eq_1;
|
|
2289
|
+
const neq = neq_1;
|
|
2290
|
+
const gte = gte_1;
|
|
2291
|
+
const lte = lte_1;
|
|
2292
|
+
const cmp = cmp_1;
|
|
2293
|
+
const coerce = coerce_1;
|
|
2294
|
+
const Comparator = requireComparator();
|
|
2295
|
+
const Range = requireRange();
|
|
2296
|
+
const satisfies = satisfies_1;
|
|
2297
|
+
const toComparators = toComparators_1;
|
|
2298
|
+
const maxSatisfying = maxSatisfying_1;
|
|
2299
|
+
const minSatisfying = minSatisfying_1;
|
|
2300
|
+
const minVersion = minVersion_1;
|
|
2301
|
+
const validRange = valid$1;
|
|
2302
|
+
const outside = outside_1;
|
|
2303
|
+
const gtr = gtr_1;
|
|
2304
|
+
const ltr = ltr_1;
|
|
2305
|
+
const intersects = intersects_1;
|
|
2306
|
+
const simplifyRange = simplify;
|
|
2307
|
+
const subset = subset_1;
|
|
2308
|
+
var semver = {
|
|
2309
|
+
parse,
|
|
2310
|
+
valid,
|
|
2311
|
+
clean,
|
|
2312
|
+
inc,
|
|
2313
|
+
diff,
|
|
2314
|
+
major,
|
|
2315
|
+
minor,
|
|
2316
|
+
patch,
|
|
2317
|
+
prerelease,
|
|
2318
|
+
compare,
|
|
2319
|
+
rcompare,
|
|
2320
|
+
compareLoose,
|
|
2321
|
+
compareBuild,
|
|
2322
|
+
sort,
|
|
2323
|
+
rsort,
|
|
2324
|
+
gt,
|
|
2325
|
+
lt,
|
|
2326
|
+
eq,
|
|
2327
|
+
neq,
|
|
2328
|
+
gte,
|
|
2329
|
+
lte,
|
|
2330
|
+
cmp,
|
|
2331
|
+
coerce,
|
|
2332
|
+
Comparator,
|
|
2333
|
+
Range,
|
|
2334
|
+
satisfies,
|
|
2335
|
+
toComparators,
|
|
2336
|
+
maxSatisfying,
|
|
2337
|
+
minSatisfying,
|
|
2338
|
+
minVersion,
|
|
2339
|
+
validRange,
|
|
2340
|
+
outside,
|
|
2341
|
+
gtr,
|
|
2342
|
+
ltr,
|
|
2343
|
+
intersects,
|
|
2344
|
+
simplifyRange,
|
|
2345
|
+
subset,
|
|
2346
|
+
SemVer,
|
|
2347
|
+
re: internalRe.re,
|
|
2348
|
+
src: internalRe.src,
|
|
2349
|
+
tokens: internalRe.t,
|
|
2350
|
+
SEMVER_SPEC_VERSION: constants.SEMVER_SPEC_VERSION,
|
|
2351
|
+
RELEASE_TYPES: constants.RELEASE_TYPES,
|
|
2352
|
+
compareIdentifiers: identifiers.compareIdentifiers,
|
|
2353
|
+
rcompareIdentifiers: identifiers.rcompareIdentifiers,
|
|
2354
|
+
};
|
|
2355
|
+
|
|
2356
|
+
var semver$1 = /*@__PURE__*/getDefaultExportFromCjs(semver);
|
|
2357
|
+
|
|
2358
|
+
/**
|
|
2359
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2360
|
+
*
|
|
2361
|
+
* This source code is licensed under the MIT license found in the
|
|
2362
|
+
* LICENSE file in the root directory of this source tree.
|
|
2363
|
+
*/
|
|
2364
|
+
/** Same list as SUPPORTED_AI_TOOLS; test/agent-guidance.test.ts checks it. */
|
|
2365
|
+
const GUIDANCE_TOOLS = [
|
|
2366
|
+
'claude',
|
|
2367
|
+
'cursor',
|
|
2368
|
+
'copilot',
|
|
2369
|
+
'codex',
|
|
2370
|
+
'opencode',
|
|
2371
|
+
];
|
|
2372
|
+
// Hash and stamp format. Keep in sync with
|
|
2373
|
+
// packages/core/scripts/agent-guidance-format.mjs, which renders the files;
|
|
2374
|
+
// test/agent-guidance.test.ts checks both sides against a fresh render.
|
|
2375
|
+
const GUIDANCE_FORMAT = 1;
|
|
2376
|
+
const BLOCK_NAME = 'iwsdk-agent-guidance';
|
|
2377
|
+
const STAMP_LINE = /^<!-- iwsdk-agent-guidance version=(\S+) sha256=([0-9a-f]{64})(?: name=(\S+))? [^\n]*-->\r?\n?/mu;
|
|
2378
|
+
const BLOCK_PATTERN = new RegExp(`<!-- BEGIN ${BLOCK_NAME} version=(\\S+) sha256=([0-9a-f]{64}) -->\\n([\\s\\S]*?)<!-- END ${BLOCK_NAME} -->\\n?`, 'u');
|
|
2379
|
+
const BLOCK_BEGIN = new RegExp(`<!-- BEGIN ${BLOCK_NAME}\\b`, 'gu');
|
|
2380
|
+
const BLOCK_END = new RegExp(`<!-- END ${BLOCK_NAME} -->`, 'gu');
|
|
2381
|
+
// Releases before the managed block opened AGENTS.md and CLAUDE.md with this
|
|
2382
|
+
// heading ("# IWSDK Project" in 0.4, "# IWSDK project" later).
|
|
2383
|
+
const LEGACY_IWSDK_HEADING = /^# IWSDK (?:scoped )?project/iu;
|
|
2384
|
+
const SKILL_PERMISSION = /^Skill\((iwsdk-[^)]*)\)$/u;
|
|
2385
|
+
/** Files that operating systems and editors drop into folders; never hashed. */
|
|
2386
|
+
const JUNK_FILE = /^(?:\.DS_Store|Thumbs\.db|desktop\.ini)$|\.swp$|~$/u;
|
|
2387
|
+
// Same sentence as the top of agent-guidance/common/AGENTS.md in @iwsdk/core.
|
|
2388
|
+
const RETIRED_SURFACES_NOTICE = "IWSDK changes faster than model training data. GLXF scenes, the external 0.4 scene editor and its Vite plugin, and the UIKitML-compile and glTF-optimizer Vite plugins were removed in 0.5: scenes are native `*.iwsdk.scene.json` files edited in IWSDK's built-in editor, and `@iwsdk/vite-plugin-dev` is the only IWSDK Vite plugin.";
|
|
2389
|
+
class GuidanceSourceError extends Error {
|
|
2390
|
+
constructor(message, code) {
|
|
2391
|
+
super(message);
|
|
2392
|
+
this.code = code;
|
|
2393
|
+
this.name = 'GuidanceSourceError';
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
function sha256(text) {
|
|
2397
|
+
return createHash('sha256').update(text).digest('hex');
|
|
2398
|
+
}
|
|
2399
|
+
function normalizeText(text) {
|
|
2400
|
+
return text.replace(/\r\n/gu, '\n');
|
|
2401
|
+
}
|
|
2402
|
+
function withTrailingNewline(text) {
|
|
2403
|
+
return text.endsWith('\n') ? text : `${text}\n`;
|
|
2404
|
+
}
|
|
2405
|
+
function stripStamp(text) {
|
|
2406
|
+
return normalizeText(text).replace(STAMP_LINE, '');
|
|
2407
|
+
}
|
|
2408
|
+
function readStamp(text) {
|
|
2409
|
+
const match = normalizeText(text).match(STAMP_LINE);
|
|
2410
|
+
return match ? { version: match[1], sha256: match[2], name: match[3] } : null;
|
|
2411
|
+
}
|
|
2412
|
+
function fileUnitHash(text) {
|
|
2413
|
+
return sha256(stripStamp(text));
|
|
2414
|
+
}
|
|
2415
|
+
function directoryUnitHash(files) {
|
|
2416
|
+
const hash = createHash('sha256');
|
|
2417
|
+
for (const [relativePath, contents] of [...files].sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)) {
|
|
2418
|
+
const digest = typeof contents === 'string' ? fileUnitHash(contents) : sha256(contents);
|
|
2419
|
+
hash.update(`${relativePath}\0${digest}\n`);
|
|
2420
|
+
}
|
|
2421
|
+
return hash.digest('hex');
|
|
2422
|
+
}
|
|
2423
|
+
function blockUnitHash(body) {
|
|
2424
|
+
return sha256(withTrailingNewline(normalizeText(body)));
|
|
2425
|
+
}
|
|
2426
|
+
function isTextFile(name) {
|
|
2427
|
+
return !/\.(png|jpe?g|webp|gif|glb|mp3|ktx2)$/iu.test(name);
|
|
2428
|
+
}
|
|
2429
|
+
async function readTree(root, relative = '', files = new Map()) {
|
|
2430
|
+
for (const entry of await readdir(path.join(root, relative), {
|
|
2431
|
+
withFileTypes: true,
|
|
2432
|
+
})) {
|
|
2433
|
+
const childRelative = relative ? `${relative}/${entry.name}` : entry.name;
|
|
2434
|
+
if (JUNK_FILE.test(entry.name)) {
|
|
2435
|
+
continue;
|
|
2436
|
+
}
|
|
2437
|
+
if (entry.isDirectory()) {
|
|
2438
|
+
await readTree(root, childRelative, files);
|
|
2439
|
+
}
|
|
2440
|
+
else if (entry.isFile()) {
|
|
2441
|
+
const contents = await readFile(path.join(root, childRelative));
|
|
2442
|
+
files.set(childRelative, isTextFile(entry.name) ? contents.toString('utf8') : contents);
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
return files;
|
|
2446
|
+
}
|
|
2447
|
+
async function readTextIfExists(filePath) {
|
|
2448
|
+
try {
|
|
2449
|
+
return await readFile(filePath, 'utf8');
|
|
2450
|
+
}
|
|
2451
|
+
catch (error) {
|
|
2452
|
+
if (error.code === 'ENOENT') {
|
|
2453
|
+
return null;
|
|
2454
|
+
}
|
|
2455
|
+
throw error;
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
function assertRelativeUnitPath(unitPath) {
|
|
2459
|
+
if (path.isAbsolute(unitPath) ||
|
|
2460
|
+
unitPath
|
|
2461
|
+
.split(/[\\/]/u)
|
|
2462
|
+
.some((segment) => segment === '..' || segment === '')) {
|
|
2463
|
+
throw new GuidanceSourceError(`Guidance manifest contains an unsafe path: ${unitPath}`, 'guidance_unavailable');
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
async function loadGuidanceSource(root, origin = 'explicit') {
|
|
2467
|
+
const manifestPath = path.join(root, 'manifest.json');
|
|
2468
|
+
const raw = await readTextIfExists(manifestPath);
|
|
2469
|
+
if (raw == null) {
|
|
2470
|
+
throw new GuidanceSourceError(`No agent guidance manifest at ${manifestPath}`, 'guidance_unavailable');
|
|
2471
|
+
}
|
|
2472
|
+
let manifest;
|
|
2473
|
+
try {
|
|
2474
|
+
manifest = JSON.parse(raw);
|
|
2475
|
+
}
|
|
2476
|
+
catch {
|
|
2477
|
+
throw new GuidanceSourceError(`The agent guidance manifest at ${manifestPath} is not valid JSON. Reinstall IWSDK.`, 'guidance_unavailable');
|
|
2478
|
+
}
|
|
2479
|
+
if (manifest.format !== GUIDANCE_FORMAT) {
|
|
2480
|
+
throw new GuidanceSourceError(`Agent guidance format ${manifest.format} is not supported by this @iwsdk/cli (expects ${GUIDANCE_FORMAT}). Use the @iwsdk/cli release that matches @iwsdk/core.`, 'unsupported_guidance_format');
|
|
2481
|
+
}
|
|
2482
|
+
for (const unit of manifest.units) {
|
|
2483
|
+
assertRelativeUnitPath(unit.path);
|
|
2484
|
+
for (const file of unit.files ?? []) {
|
|
2485
|
+
assertRelativeUnitPath(file);
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
return { root, manifest, origin };
|
|
2489
|
+
}
|
|
2490
|
+
function bundledGuidanceRoot() {
|
|
2491
|
+
return fileURLToPath(new URL('./agent-guidance/', import.meta.url));
|
|
2492
|
+
}
|
|
2493
|
+
/** Version of `@iwsdk/core` installed for the project, or null. */
|
|
2494
|
+
function readInstalledCoreVersion(projectRoot) {
|
|
2495
|
+
const packageJsonPath = resolveInstalledCorePackageJson(projectRoot);
|
|
2496
|
+
if (packageJsonPath == null) {
|
|
2497
|
+
return null;
|
|
2498
|
+
}
|
|
2499
|
+
try {
|
|
2500
|
+
return (JSON.parse(readFileSync(packageJsonPath, 'utf8')).version ?? null);
|
|
2501
|
+
}
|
|
2502
|
+
catch {
|
|
2503
|
+
return null;
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
/**
|
|
2507
|
+
* The installed `@iwsdk/core/package.json`, looked up fresh each time. Node's
|
|
2508
|
+
* resolver caches paths per process, so after `pnpm install` re-points
|
|
2509
|
+
* node_modules/@iwsdk/core it would still return the old release.
|
|
2510
|
+
*/
|
|
2511
|
+
function resolveInstalledCorePackageJson(projectRoot) {
|
|
2512
|
+
let current = path.resolve(projectRoot);
|
|
2513
|
+
while (true) {
|
|
2514
|
+
const candidate = path.join(current, 'node_modules', '@iwsdk', 'core', 'package.json');
|
|
2515
|
+
if (existsSync(candidate)) {
|
|
2516
|
+
return realpathSync(candidate);
|
|
2517
|
+
}
|
|
2518
|
+
const parent = path.dirname(current);
|
|
2519
|
+
if (parent === current) {
|
|
2520
|
+
break;
|
|
2521
|
+
}
|
|
2522
|
+
current = parent;
|
|
2523
|
+
}
|
|
2524
|
+
// Layouts without node_modules folders (Yarn Plug'n'Play).
|
|
2525
|
+
try {
|
|
2526
|
+
return createRequire(path.join(projectRoot, 'package.json')).resolve('@iwsdk/core/package.json');
|
|
2527
|
+
}
|
|
2528
|
+
catch {
|
|
2529
|
+
return null;
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
/**
|
|
2533
|
+
* Guidance for a project: the copy shipped in its installed `@iwsdk/core`, so
|
|
2534
|
+
* it always matches the installed release. Before `@iwsdk/core` is installed,
|
|
2535
|
+
* the copy bundled with this CLI is used instead.
|
|
2536
|
+
*/
|
|
2537
|
+
async function resolveProjectGuidance(projectRoot) {
|
|
2538
|
+
const corePackageJson = resolveInstalledCorePackageJson(projectRoot);
|
|
2539
|
+
if (corePackageJson != null) {
|
|
2540
|
+
const root = path.join(path.dirname(corePackageJson), 'dist', 'agent-guidance');
|
|
2541
|
+
if (!existsSync(path.join(root, 'manifest.json'))) {
|
|
2542
|
+
const version = readInstalledCoreVersion(projectRoot) ?? 'unknown';
|
|
2543
|
+
throw new GuidanceSourceError(`The installed @iwsdk/core ${version} predates bundled agent guidance. Upgrade IWSDK with \`npx @iwsdk/cli@latest upgrade\`.`, 'core_without_guidance');
|
|
2544
|
+
}
|
|
2545
|
+
return loadGuidanceSource(root, 'installed-core');
|
|
2546
|
+
}
|
|
2547
|
+
if (declaresCore(projectRoot)) {
|
|
2548
|
+
// Guidance from this CLI could belong to a different release than the
|
|
2549
|
+
// one the project declares; wait for the real one.
|
|
2550
|
+
throw new GuidanceSourceError(`package.json lists @iwsdk/core, but it is not installed in ${projectRoot}. Install the project's dependencies first, then run this command again.`, 'core_not_installed');
|
|
2551
|
+
}
|
|
2552
|
+
return loadGuidanceSource(bundledGuidanceRoot(), 'bundled-cli');
|
|
2553
|
+
}
|
|
2554
|
+
function declaresCore(projectRoot) {
|
|
2555
|
+
try {
|
|
2556
|
+
const manifest = JSON.parse(readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
|
|
2557
|
+
return ['dependencies', 'devDependencies', 'peerDependencies'].some((field) => {
|
|
2558
|
+
const dependencies = manifest[field];
|
|
2559
|
+
return (typeof dependencies === 'object' &&
|
|
2560
|
+
dependencies !== null &&
|
|
2561
|
+
'@iwsdk/core' in dependencies);
|
|
2562
|
+
});
|
|
2563
|
+
}
|
|
2564
|
+
catch {
|
|
2565
|
+
return false;
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2568
|
+
function selectedUnits(manifest, tools) {
|
|
2569
|
+
return manifest.units.filter((unit) => unit.tools.some((tool) => tools.includes(tool)));
|
|
2570
|
+
}
|
|
2571
|
+
async function resolveLink(filePath) {
|
|
2572
|
+
try {
|
|
2573
|
+
return (await lstat(filePath)).isSymbolicLink()
|
|
2574
|
+
? await realpath(filePath)
|
|
2575
|
+
: filePath;
|
|
2576
|
+
}
|
|
2577
|
+
catch {
|
|
2578
|
+
return filePath;
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
/** Both paths name the same file once every link on the way is followed. */
|
|
2582
|
+
async function isSameFile(first, second) {
|
|
2583
|
+
try {
|
|
2584
|
+
return (await realpath(first)) === (await realpath(second));
|
|
2585
|
+
}
|
|
2586
|
+
catch {
|
|
2587
|
+
return false;
|
|
2588
|
+
}
|
|
2589
|
+
}
|
|
2590
|
+
/** Temporary siblings a sync left behind when it was killed mid-swap. */
|
|
2591
|
+
const TEMPORARY_SIBLING = /^\..+\.iwsdk-(?:new|old)-(\d+)-(\d+)$/u;
|
|
2592
|
+
/** A temporary sibling that a sync running right now may still need. */
|
|
2593
|
+
function isInUse(name) {
|
|
2594
|
+
const [, pid, createdAt] = TEMPORARY_SIBLING.exec(name) ?? [];
|
|
2595
|
+
if (Date.now() - Number(createdAt) < 10 * 60_000) {
|
|
2596
|
+
return true;
|
|
2597
|
+
}
|
|
2598
|
+
try {
|
|
2599
|
+
process.kill(Number(pid), 0);
|
|
2600
|
+
return true;
|
|
2601
|
+
}
|
|
2602
|
+
catch (error) {
|
|
2603
|
+
// EPERM: the process exists but belongs to someone else.
|
|
2604
|
+
return error.code !== 'ESRCH';
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
function temporarySibling(filePath, label) {
|
|
2608
|
+
return path.join(path.dirname(filePath), `.${path.basename(filePath)}.iwsdk-${label}-${process.pid}-${Date.now()}`);
|
|
2609
|
+
}
|
|
2610
|
+
function createWriter(projectRoot, dryRun) {
|
|
2611
|
+
return {
|
|
2612
|
+
dryRun,
|
|
2613
|
+
projectRoot,
|
|
2614
|
+
async write(relativePath, contents) {
|
|
2615
|
+
if (dryRun) {
|
|
2616
|
+
return;
|
|
2617
|
+
}
|
|
2618
|
+
// Write through a link (CLAUDE.md -> AGENTS.md is common), so the
|
|
2619
|
+
// rename replaces the file it points at, not the link itself.
|
|
2620
|
+
const filePath = await resolveLink(path.join(projectRoot, relativePath));
|
|
2621
|
+
await mkdir(path.dirname(filePath), { recursive: true });
|
|
2622
|
+
const staged = temporarySibling(filePath, 'new');
|
|
2623
|
+
try {
|
|
2624
|
+
await writeFile(staged, contents);
|
|
2625
|
+
await rename(staged, filePath);
|
|
2626
|
+
}
|
|
2627
|
+
finally {
|
|
2628
|
+
await rm(staged, { force: true });
|
|
2629
|
+
}
|
|
2630
|
+
},
|
|
2631
|
+
async replaceDirectory(relativePath, files) {
|
|
2632
|
+
if (dryRun) {
|
|
2633
|
+
return;
|
|
2634
|
+
}
|
|
2635
|
+
const target = path.join(projectRoot, relativePath);
|
|
2636
|
+
await mkdir(path.dirname(target), { recursive: true });
|
|
2637
|
+
const staged = temporarySibling(target, 'new');
|
|
2638
|
+
const previous = temporarySibling(target, 'old');
|
|
2639
|
+
try {
|
|
2640
|
+
for (const [file, contents] of files) {
|
|
2641
|
+
const filePath = path.join(staged, file);
|
|
2642
|
+
await mkdir(path.dirname(filePath), { recursive: true });
|
|
2643
|
+
await writeFile(filePath, contents);
|
|
2644
|
+
}
|
|
2645
|
+
const hadPrevious = existsSync(target);
|
|
2646
|
+
if (hadPrevious) {
|
|
2647
|
+
await rename(target, previous);
|
|
2648
|
+
}
|
|
2649
|
+
try {
|
|
2650
|
+
await rename(staged, target);
|
|
2651
|
+
}
|
|
2652
|
+
catch (error) {
|
|
2653
|
+
if (hadPrevious) {
|
|
2654
|
+
await rename(previous, target);
|
|
2655
|
+
}
|
|
2656
|
+
throw error;
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
finally {
|
|
2660
|
+
await rm(staged, { recursive: true, force: true });
|
|
2661
|
+
await rm(previous, { recursive: true, force: true });
|
|
2662
|
+
}
|
|
2663
|
+
},
|
|
2664
|
+
async remove(relativePath) {
|
|
2665
|
+
if (dryRun) {
|
|
2666
|
+
return;
|
|
2667
|
+
}
|
|
2668
|
+
await rm(path.join(projectRoot, relativePath), {
|
|
2669
|
+
recursive: true,
|
|
2670
|
+
force: true,
|
|
2671
|
+
});
|
|
2672
|
+
await removeEmptyParents(projectRoot, path.dirname(relativePath));
|
|
2673
|
+
},
|
|
2674
|
+
};
|
|
2675
|
+
}
|
|
2676
|
+
async function removeEmptyParents(projectRoot, relativeDirectory) {
|
|
2677
|
+
let current = relativeDirectory;
|
|
2678
|
+
while (current && current !== '.') {
|
|
2679
|
+
try {
|
|
2680
|
+
await rmdir(path.join(projectRoot, current));
|
|
2681
|
+
}
|
|
2682
|
+
catch {
|
|
2683
|
+
return;
|
|
2684
|
+
}
|
|
2685
|
+
current = path.dirname(current);
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2688
|
+
async function readSourceFile(source, relativePath) {
|
|
2689
|
+
return readFile(path.join(source.root, 'files', relativePath));
|
|
2690
|
+
}
|
|
2691
|
+
/** Text written back with the line endings the existing file used. */
|
|
2692
|
+
function withLineEndings(text, existing) {
|
|
2693
|
+
return existing.includes('\r\n') ? text.replace(/\r?\n/gu, '\r\n') : text;
|
|
2694
|
+
}
|
|
2695
|
+
function classify(localHash, targetHash, stamp, legacyHashes, manifestVersion) {
|
|
2696
|
+
if (targetHash !== undefined && localHash === targetHash) {
|
|
2697
|
+
return 'unchanged';
|
|
2698
|
+
}
|
|
2699
|
+
if (stamp) {
|
|
2700
|
+
if (stamp.sha256 !== localHash) {
|
|
2701
|
+
return 'modified';
|
|
2702
|
+
}
|
|
2703
|
+
// Written by a newer release than this guidance: an older CLI or core
|
|
2704
|
+
// must not roll it back.
|
|
2705
|
+
return semver$1.valid(stamp.version) &&
|
|
2706
|
+
semver$1.valid(manifestVersion) &&
|
|
2707
|
+
semver$1.gt(stamp.version, manifestVersion)
|
|
2708
|
+
? 'newer'
|
|
2709
|
+
: 'managed';
|
|
2710
|
+
}
|
|
2711
|
+
return legacyHashes?.includes(localHash) ? 'legacy' : 'unmanaged';
|
|
2712
|
+
}
|
|
2713
|
+
function replacementResult(unit, ownership, force) {
|
|
2714
|
+
if (ownership === 'managed') {
|
|
2715
|
+
return { path: unit.path, kind: unit.kind, action: 'updated' };
|
|
2716
|
+
}
|
|
2717
|
+
if (ownership === 'legacy') {
|
|
2718
|
+
return {
|
|
2719
|
+
path: unit.path,
|
|
2720
|
+
kind: unit.kind,
|
|
2721
|
+
action: 'updated',
|
|
2722
|
+
reason: 'legacy',
|
|
2723
|
+
};
|
|
2724
|
+
}
|
|
2725
|
+
if (ownership === 'newer') {
|
|
2726
|
+
return {
|
|
2727
|
+
path: unit.path,
|
|
2728
|
+
kind: unit.kind,
|
|
2729
|
+
action: 'skipped',
|
|
2730
|
+
reason: 'newer',
|
|
2731
|
+
detail: 'Written by a newer IWSDK release; upgrade @iwsdk/core.',
|
|
2732
|
+
};
|
|
2733
|
+
}
|
|
2734
|
+
if (ownership === 'modified' || ownership === 'unmanaged') {
|
|
2735
|
+
return force
|
|
2736
|
+
? {
|
|
2737
|
+
path: unit.path,
|
|
2738
|
+
kind: unit.kind,
|
|
2739
|
+
action: 'updated',
|
|
2740
|
+
reason: 'forced',
|
|
2741
|
+
}
|
|
2742
|
+
: {
|
|
2743
|
+
path: unit.path,
|
|
2744
|
+
kind: unit.kind,
|
|
2745
|
+
action: 'skipped',
|
|
2746
|
+
reason: ownership,
|
|
2747
|
+
};
|
|
2748
|
+
}
|
|
2749
|
+
return null;
|
|
2750
|
+
}
|
|
2751
|
+
async function pathKind(filePath) {
|
|
2752
|
+
try {
|
|
2753
|
+
const stat = await lstat(filePath);
|
|
2754
|
+
return stat.isDirectory() ? 'directory' : stat.isFile() ? 'file' : 'other';
|
|
2755
|
+
}
|
|
2756
|
+
catch (error) {
|
|
2757
|
+
if (error.code === 'ENOENT') {
|
|
2758
|
+
return 'missing';
|
|
2759
|
+
}
|
|
2760
|
+
throw error;
|
|
2761
|
+
}
|
|
2762
|
+
}
|
|
2763
|
+
async function syncDirectoryUnit(unit, source, writer, force) {
|
|
2764
|
+
const localRoot = path.join(writer.projectRoot, unit.path);
|
|
2765
|
+
const replace = async () => {
|
|
2766
|
+
const files = [];
|
|
2767
|
+
for (const file of unit.files ?? []) {
|
|
2768
|
+
files.push([file, await readSourceFile(source, `${unit.path}/${file}`)]);
|
|
2769
|
+
}
|
|
2770
|
+
await writer.replaceDirectory(unit.path, files);
|
|
2771
|
+
};
|
|
2772
|
+
const kind = await pathKind(localRoot);
|
|
2773
|
+
const localFiles = kind === 'directory' ? await readTree(localRoot) : null;
|
|
2774
|
+
if (kind === 'missing' || localFiles?.size === 0) {
|
|
2775
|
+
await replace();
|
|
2776
|
+
return { path: unit.path, kind: unit.kind, action: 'created' };
|
|
2777
|
+
}
|
|
2778
|
+
if (localFiles == null) {
|
|
2779
|
+
// A file or link where the skill folder belongs.
|
|
2780
|
+
if (!force) {
|
|
2781
|
+
return {
|
|
2782
|
+
path: unit.path,
|
|
2783
|
+
kind: unit.kind,
|
|
2784
|
+
action: 'skipped',
|
|
2785
|
+
reason: 'unmanaged',
|
|
2786
|
+
};
|
|
2787
|
+
}
|
|
2788
|
+
await writer.remove(unit.path);
|
|
2789
|
+
await replace();
|
|
2790
|
+
return {
|
|
2791
|
+
path: unit.path,
|
|
2792
|
+
kind: unit.kind,
|
|
2793
|
+
action: 'updated',
|
|
2794
|
+
reason: 'forced',
|
|
2795
|
+
};
|
|
2796
|
+
}
|
|
2797
|
+
const skill = localFiles.get('SKILL.md');
|
|
2798
|
+
const ownership = classify(directoryUnitHash(localFiles), unit.sha256, typeof skill === 'string' ? readStamp(skill) : null, source.manifest.legacy[unit.path], source.manifest.version);
|
|
2799
|
+
if (ownership === 'unchanged') {
|
|
2800
|
+
return { path: unit.path, kind: unit.kind, action: 'unchanged' };
|
|
2801
|
+
}
|
|
2802
|
+
const result = replacementResult(unit, ownership, force);
|
|
2803
|
+
if (result.action === 'updated') {
|
|
2804
|
+
await replace();
|
|
2805
|
+
}
|
|
2806
|
+
return result;
|
|
2807
|
+
}
|
|
2808
|
+
async function syncFileUnit(unit, source, writer, force) {
|
|
2809
|
+
const local = await readTextIfExists(path.join(writer.projectRoot, unit.path));
|
|
2810
|
+
const next = await readSourceFile(source, unit.path);
|
|
2811
|
+
if (local == null) {
|
|
2812
|
+
await writer.write(unit.path, next);
|
|
2813
|
+
return { path: unit.path, kind: unit.kind, action: 'created' };
|
|
2814
|
+
}
|
|
2815
|
+
const ownership = classify(fileUnitHash(local), unit.sha256, readStamp(local), source.manifest.legacy[unit.path], source.manifest.version);
|
|
2816
|
+
if (ownership === 'unchanged') {
|
|
2817
|
+
return { path: unit.path, kind: unit.kind, action: 'unchanged' };
|
|
2818
|
+
}
|
|
2819
|
+
const result = replacementResult(unit, ownership, force);
|
|
2820
|
+
if (result.action === 'updated') {
|
|
2821
|
+
await writer.write(unit.path, next);
|
|
2822
|
+
}
|
|
2823
|
+
return result;
|
|
2824
|
+
}
|
|
2825
|
+
async function syncBlockUnit(unit, source, writer, force) {
|
|
2826
|
+
const local = await readTextIfExists(path.join(writer.projectRoot, unit.path));
|
|
2827
|
+
const block = (await readSourceFile(source, unit.path)).toString('utf8');
|
|
2828
|
+
if (local == null) {
|
|
2829
|
+
await writer.write(unit.path, block);
|
|
2830
|
+
return { path: unit.path, kind: unit.kind, action: 'created' };
|
|
2831
|
+
}
|
|
2832
|
+
const normalized = normalizeText(local);
|
|
2833
|
+
const begins = normalized.match(BLOCK_BEGIN)?.length ?? 0;
|
|
2834
|
+
const ends = normalized.match(BLOCK_END)?.length ?? 0;
|
|
2835
|
+
const match = normalized.match(BLOCK_PATTERN);
|
|
2836
|
+
if (begins > 0 || ends > 0) {
|
|
2837
|
+
if (begins !== 1 || ends !== 1 || !match) {
|
|
2838
|
+
// A lost END line or a duplicated block: neither appending nor
|
|
2839
|
+
// replacing can tell IWSDK's text from the developer's.
|
|
2840
|
+
return {
|
|
2841
|
+
path: unit.path,
|
|
2842
|
+
kind: unit.kind,
|
|
2843
|
+
action: 'skipped',
|
|
2844
|
+
reason: 'malformed-block',
|
|
2845
|
+
detail: 'Its iwsdk-agent-guidance markers are broken. Keep exactly one BEGIN and one END line, or delete the block, then sync again.',
|
|
2846
|
+
};
|
|
2847
|
+
}
|
|
2848
|
+
const ownership = classify(blockUnitHash(match[3]), unit.sha256, { version: match[1], sha256: match[2] }, undefined, source.manifest.version);
|
|
2849
|
+
if (ownership === 'unchanged') {
|
|
2850
|
+
return { path: unit.path, kind: unit.kind, action: 'unchanged' };
|
|
2851
|
+
}
|
|
2852
|
+
const result = replacementResult(unit, ownership, force);
|
|
2853
|
+
if (result.action === 'updated') {
|
|
2854
|
+
await writer.write(unit.path, withLineEndings(normalized.replace(BLOCK_PATTERN, () => block), local));
|
|
2855
|
+
}
|
|
2856
|
+
return result;
|
|
2857
|
+
}
|
|
2858
|
+
if (source.manifest.legacy[unit.path]?.includes(fileUnitHash(local))) {
|
|
2859
|
+
await writer.write(unit.path, withLineEndings(block, local));
|
|
2860
|
+
return {
|
|
2861
|
+
path: unit.path,
|
|
2862
|
+
kind: unit.kind,
|
|
2863
|
+
action: 'updated',
|
|
2864
|
+
reason: 'legacy',
|
|
2865
|
+
};
|
|
2866
|
+
}
|
|
2867
|
+
if (LEGACY_IWSDK_HEADING.test(normalized.trimStart())) {
|
|
2868
|
+
// An edited copy of guidance from a release before the managed block.
|
|
2869
|
+
// Appending would leave two contradicting versions in one file.
|
|
2870
|
+
if (!force) {
|
|
2871
|
+
return {
|
|
2872
|
+
path: unit.path,
|
|
2873
|
+
kind: unit.kind,
|
|
2874
|
+
action: 'skipped',
|
|
2875
|
+
reason: 'legacy-modified',
|
|
2876
|
+
detail: 'It holds edited guidance from an IWSDK release before 1.2; --force replaces the whole file.',
|
|
2877
|
+
};
|
|
2878
|
+
}
|
|
2879
|
+
await writer.write(unit.path, withLineEndings(block, local));
|
|
2880
|
+
return {
|
|
2881
|
+
path: unit.path,
|
|
2882
|
+
kind: unit.kind,
|
|
2883
|
+
action: 'updated',
|
|
2884
|
+
reason: 'forced',
|
|
2885
|
+
};
|
|
2886
|
+
}
|
|
2887
|
+
await writer.write(unit.path, withLineEndings(`${withTrailingNewline(normalized)}${normalized.trim() ? '\n' : ''}${block}`, local));
|
|
2888
|
+
return {
|
|
2889
|
+
path: unit.path,
|
|
2890
|
+
kind: unit.kind,
|
|
2891
|
+
action: 'updated',
|
|
2892
|
+
reason: 'appended',
|
|
2893
|
+
};
|
|
2894
|
+
}
|
|
2895
|
+
async function syncClaudeImport(unit, source, writer, force) {
|
|
2896
|
+
const rootFile = await readTextIfExists(path.join(writer.projectRoot, unit.path));
|
|
2897
|
+
const nestedFile = await readTextIfExists(path.join(writer.projectRoot, '.claude', 'CLAUDE.md'));
|
|
2898
|
+
const next = await readSourceFile(source, unit.path);
|
|
2899
|
+
if (rootFile == null && nestedFile == null) {
|
|
2900
|
+
await writer.write(unit.path, next);
|
|
2901
|
+
return { path: unit.path, kind: unit.kind, action: 'created' };
|
|
2902
|
+
}
|
|
2903
|
+
if (rootFile != null &&
|
|
2904
|
+
(await isSameFile(path.join(writer.projectRoot, unit.path), path.join(writer.projectRoot, 'AGENTS.md')))) {
|
|
2905
|
+
// CLAUDE.md is a link to AGENTS.md: Claude already reads the guidance.
|
|
2906
|
+
return { path: unit.path, kind: unit.kind, action: 'unchanged' };
|
|
2907
|
+
}
|
|
2908
|
+
if (rootFile != null &&
|
|
2909
|
+
fileUnitHash(rootFile) !== fileUnitHash(next.toString('utf8')) &&
|
|
2910
|
+
source.manifest.legacy[unit.path]?.includes(fileUnitHash(rootFile))) {
|
|
2911
|
+
// Releases before 1.0 put the full guidance in CLAUDE.md.
|
|
2912
|
+
await writer.write(unit.path, withLineEndings(next.toString('utf8'), rootFile));
|
|
2913
|
+
return {
|
|
2914
|
+
path: unit.path,
|
|
2915
|
+
kind: unit.kind,
|
|
2916
|
+
action: 'updated',
|
|
2917
|
+
reason: 'legacy',
|
|
2918
|
+
};
|
|
2919
|
+
}
|
|
2920
|
+
if (rootFile != null &&
|
|
2921
|
+
!/^@AGENTS\.md\s*$/mu.test(rootFile) &&
|
|
2922
|
+
LEGACY_IWSDK_HEADING.test(normalizeText(rootFile).trimStart())) {
|
|
2923
|
+
if (!force) {
|
|
2924
|
+
return {
|
|
2925
|
+
path: unit.path,
|
|
2926
|
+
kind: unit.kind,
|
|
2927
|
+
action: 'skipped',
|
|
2928
|
+
reason: 'legacy-modified',
|
|
2929
|
+
detail: 'It holds edited guidance from an IWSDK release before 1.0; --force replaces the whole file with an @AGENTS.md import.',
|
|
2930
|
+
};
|
|
2931
|
+
}
|
|
2932
|
+
await writer.write(unit.path, withLineEndings(next.toString('utf8'), rootFile));
|
|
2933
|
+
return {
|
|
2934
|
+
path: unit.path,
|
|
2935
|
+
kind: unit.kind,
|
|
2936
|
+
action: 'updated',
|
|
2937
|
+
reason: 'forced',
|
|
2938
|
+
};
|
|
2939
|
+
}
|
|
2940
|
+
if ((rootFile != null && /^@AGENTS\.md\s*$/mu.test(rootFile)) ||
|
|
2941
|
+
(nestedFile != null && /^@\.\.\/AGENTS\.md\s*$/mu.test(nestedFile))) {
|
|
2942
|
+
return { path: unit.path, kind: unit.kind, action: 'unchanged' };
|
|
2943
|
+
}
|
|
2944
|
+
if (rootFile != null) {
|
|
2945
|
+
await writer.write(unit.path, withLineEndings(`${withTrailingNewline(rootFile)}\n@AGENTS.md\n`, rootFile));
|
|
2946
|
+
return {
|
|
2947
|
+
path: unit.path,
|
|
2948
|
+
kind: unit.kind,
|
|
2949
|
+
action: 'updated',
|
|
2950
|
+
reason: 'appended',
|
|
2951
|
+
};
|
|
2952
|
+
}
|
|
2953
|
+
await writer.write('.claude/CLAUDE.md', withLineEndings(`${withTrailingNewline(nestedFile)}\n@../AGENTS.md\n`, nestedFile));
|
|
2954
|
+
return {
|
|
2955
|
+
path: '.claude/CLAUDE.md',
|
|
2956
|
+
kind: unit.kind,
|
|
2957
|
+
action: 'updated',
|
|
2958
|
+
reason: 'appended',
|
|
2959
|
+
};
|
|
2960
|
+
}
|
|
2961
|
+
/** Skill names IWSDK has shipped: this release's and every earlier one's. */
|
|
2962
|
+
function ownedSkillNames(manifest) {
|
|
2963
|
+
const names = new Set();
|
|
2964
|
+
for (const unit of manifest.units) {
|
|
2965
|
+
for (const skill of unit.skills ?? []) {
|
|
2966
|
+
names.add(skill);
|
|
2967
|
+
}
|
|
2968
|
+
}
|
|
2969
|
+
for (const unitPath of Object.keys(manifest.legacy)) {
|
|
2970
|
+
const match = unitPath.match(/^\.(?:claude|agents)\/skills\/([^/]+)$/u);
|
|
2971
|
+
if (match) {
|
|
2972
|
+
names.add(match[1]);
|
|
2973
|
+
}
|
|
2974
|
+
}
|
|
2975
|
+
return names;
|
|
2976
|
+
}
|
|
2977
|
+
async function syncClaudeSettings(unit, source, writer, installedSkills, retiredSkills, force) {
|
|
2978
|
+
const filePath = path.join(writer.projectRoot, unit.path);
|
|
2979
|
+
const raw = await readTextIfExists(filePath);
|
|
2980
|
+
let settings = {};
|
|
2981
|
+
if (raw != null) {
|
|
2982
|
+
let parsed;
|
|
2983
|
+
try {
|
|
2984
|
+
parsed = JSON.parse(raw);
|
|
2985
|
+
}
|
|
2986
|
+
catch {
|
|
2987
|
+
parsed = undefined;
|
|
2988
|
+
}
|
|
2989
|
+
if (typeof parsed !== 'object' ||
|
|
2990
|
+
parsed === null ||
|
|
2991
|
+
Array.isArray(parsed)) {
|
|
2992
|
+
return {
|
|
2993
|
+
path: unit.path,
|
|
2994
|
+
kind: unit.kind,
|
|
2995
|
+
action: 'skipped',
|
|
2996
|
+
reason: 'invalid-json',
|
|
2997
|
+
detail: `${filePath} is not a JSON object (comments and trailing commas are not supported), so its IWSDK skill permissions were not updated.`,
|
|
2998
|
+
};
|
|
2999
|
+
}
|
|
3000
|
+
settings = parsed;
|
|
3001
|
+
}
|
|
3002
|
+
const permissions = typeof settings.permissions === 'object' &&
|
|
3003
|
+
settings.permissions !== null &&
|
|
3004
|
+
!Array.isArray(settings.permissions)
|
|
3005
|
+
? { ...settings.permissions }
|
|
3006
|
+
: {};
|
|
3007
|
+
const allow = Array.isArray(permissions.allow) ? permissions.allow : [];
|
|
3008
|
+
const shipped = new Set(unit.skills ?? []);
|
|
3009
|
+
const owned = new Set([
|
|
3010
|
+
...ownedSkillNames(source.manifest),
|
|
3011
|
+
...retiredSkills,
|
|
3012
|
+
]);
|
|
3013
|
+
// Grant skills this sync installed (all of them for a new settings file);
|
|
3014
|
+
// a permission the developer removed for an untouched skill stays removed.
|
|
3015
|
+
// Grant every shipped skill when the file is new, when --force is given, or
|
|
3016
|
+
// when no IWSDK skill permission is left (after `adapter prune`, say).
|
|
3017
|
+
const grantAll = raw == null ||
|
|
3018
|
+
force ||
|
|
3019
|
+
!allow.some((rule) => {
|
|
3020
|
+
const name = typeof rule === 'string'
|
|
3021
|
+
? rule.match(SKILL_PERMISSION)?.[1]
|
|
3022
|
+
: undefined;
|
|
3023
|
+
return name != null && owned.has(name);
|
|
3024
|
+
});
|
|
3025
|
+
const grant = [...shipped].filter((name) => grantAll || installedSkills.has(name));
|
|
3026
|
+
const isRetired = (rule) => {
|
|
3027
|
+
const name = typeof rule === 'string' ? rule.match(SKILL_PERMISSION)?.[1] : undefined;
|
|
3028
|
+
return name != null && owned.has(name) && !shipped.has(name);
|
|
3029
|
+
};
|
|
3030
|
+
const nextAllow = allow.filter((rule) => !isRetired(rule));
|
|
3031
|
+
for (const name of grant) {
|
|
3032
|
+
if (!nextAllow.includes(`Skill(${name})`)) {
|
|
3033
|
+
nextAllow.push(`Skill(${name})`);
|
|
3034
|
+
}
|
|
3035
|
+
}
|
|
3036
|
+
if (raw != null &&
|
|
3037
|
+
nextAllow.length === allow.length &&
|
|
3038
|
+
nextAllow.every((rule, index) => rule === allow[index])) {
|
|
3039
|
+
return { path: unit.path, kind: unit.kind, action: 'unchanged' };
|
|
3040
|
+
}
|
|
3041
|
+
permissions.allow = nextAllow;
|
|
3042
|
+
const next = {
|
|
3043
|
+
$schema: 'https://json.schemastore.org/claude-code-settings.json',
|
|
3044
|
+
...settings,
|
|
3045
|
+
permissions,
|
|
3046
|
+
};
|
|
3047
|
+
await writer.write(unit.path, `${JSON.stringify(next, null, 2)}\n`);
|
|
3048
|
+
return {
|
|
3049
|
+
path: unit.path,
|
|
3050
|
+
kind: unit.kind,
|
|
3051
|
+
action: raw == null ? 'created' : 'updated',
|
|
3052
|
+
};
|
|
3053
|
+
}
|
|
3054
|
+
/** Where retired units can be left behind, and the tools that use them. */
|
|
3055
|
+
const PRUNE_ROOTS = [
|
|
3056
|
+
{
|
|
3057
|
+
directory: '.claude/skills',
|
|
3058
|
+
kind: 'directory',
|
|
3059
|
+
match: /^iwsdk-/u,
|
|
3060
|
+
tools: ['claude'],
|
|
3061
|
+
},
|
|
3062
|
+
{
|
|
3063
|
+
directory: '.agents/skills',
|
|
3064
|
+
kind: 'directory',
|
|
3065
|
+
match: /^iwsdk-/u,
|
|
3066
|
+
tools: ['codex', 'cursor', 'copilot', 'opencode'],
|
|
3067
|
+
},
|
|
3068
|
+
{
|
|
3069
|
+
directory: '.claude/rules',
|
|
3070
|
+
kind: 'file',
|
|
3071
|
+
match: /\.md$/u,
|
|
3072
|
+
tools: ['claude'],
|
|
3073
|
+
},
|
|
3074
|
+
{
|
|
3075
|
+
directory: '.claude/agents',
|
|
3076
|
+
kind: 'file',
|
|
3077
|
+
match: /\.md$/u,
|
|
3078
|
+
tools: ['claude'],
|
|
3079
|
+
},
|
|
3080
|
+
{
|
|
3081
|
+
directory: '.cursor/rules',
|
|
3082
|
+
kind: 'file',
|
|
3083
|
+
match: /\.mdc$/u,
|
|
3084
|
+
tools: ['cursor'],
|
|
3085
|
+
},
|
|
3086
|
+
{
|
|
3087
|
+
directory: '.github/instructions',
|
|
3088
|
+
kind: 'file',
|
|
3089
|
+
match: /\.instructions\.md$/u,
|
|
3090
|
+
tools: ['copilot'],
|
|
3091
|
+
},
|
|
3092
|
+
];
|
|
3093
|
+
function toolsForPath(unitPath) {
|
|
3094
|
+
const root = PRUNE_ROOTS.find((candidate) => unitPath.startsWith(`${candidate.directory}/`));
|
|
3095
|
+
if (root) {
|
|
3096
|
+
return root.tools;
|
|
3097
|
+
}
|
|
3098
|
+
if (unitPath.startsWith('.cursor/')) {
|
|
3099
|
+
return ['cursor'];
|
|
3100
|
+
}
|
|
3101
|
+
if (unitPath.startsWith('.github/')) {
|
|
3102
|
+
return ['copilot'];
|
|
3103
|
+
}
|
|
3104
|
+
return GUIDANCE_TOOLS;
|
|
3105
|
+
}
|
|
3106
|
+
async function pruneRetiredUnits(source, tools, writer) {
|
|
3107
|
+
const shipped = new Set(source.manifest.units.map((unit) => unit.path));
|
|
3108
|
+
const blocks = new Set(source.manifest.units
|
|
3109
|
+
.filter((unit) => unit.kind === 'block' || unit.kind === 'claude-import')
|
|
3110
|
+
.map((unit) => unit.path));
|
|
3111
|
+
const candidates = new Map();
|
|
3112
|
+
for (const root of PRUNE_ROOTS) {
|
|
3113
|
+
if (!root.tools.some((tool) => tools.includes(tool))) {
|
|
3114
|
+
continue;
|
|
3115
|
+
}
|
|
3116
|
+
let entries;
|
|
3117
|
+
try {
|
|
3118
|
+
entries = await readdir(path.join(writer.projectRoot, root.directory), {
|
|
3119
|
+
withFileTypes: true,
|
|
3120
|
+
});
|
|
3121
|
+
}
|
|
3122
|
+
catch {
|
|
3123
|
+
continue;
|
|
3124
|
+
}
|
|
3125
|
+
for (const entry of entries) {
|
|
3126
|
+
if (root.match.test(entry.name) &&
|
|
3127
|
+
(root.kind === 'directory' ? entry.isDirectory() : entry.isFile())) {
|
|
3128
|
+
candidates.set(`${root.directory}/${entry.name}`, root.kind);
|
|
3129
|
+
}
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
// Files earlier releases wrote outside these folders, such as 0.4's
|
|
3133
|
+
// .github/copilot-instructions.md, are known by path from the legacy table.
|
|
3134
|
+
for (const unitPath of Object.keys(source.manifest.legacy)) {
|
|
3135
|
+
if (!candidates.has(unitPath) &&
|
|
3136
|
+
!blocks.has(unitPath) &&
|
|
3137
|
+
toolsForPath(unitPath).some((tool) => tools.includes(tool))) {
|
|
3138
|
+
const kind = await pathKind(path.join(writer.projectRoot, unitPath));
|
|
3139
|
+
if (kind === 'directory' || kind === 'file') {
|
|
3140
|
+
candidates.set(unitPath, kind);
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
}
|
|
3144
|
+
const results = [];
|
|
3145
|
+
const removedSkills = new Set();
|
|
3146
|
+
for (const directory of ['.', ...PRUNE_ROOTS.map((root) => root.directory)]) {
|
|
3147
|
+
let entries;
|
|
3148
|
+
try {
|
|
3149
|
+
entries = await readdir(path.join(writer.projectRoot, directory));
|
|
3150
|
+
}
|
|
3151
|
+
catch {
|
|
3152
|
+
continue;
|
|
3153
|
+
}
|
|
3154
|
+
for (const name of entries.filter((entry) => TEMPORARY_SIBLING.test(entry) && !isInUse(entry))) {
|
|
3155
|
+
await writer.remove(path.posix.join(directory, name));
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
for (const [unitPath, kind] of candidates) {
|
|
3159
|
+
if (shipped.has(unitPath)) {
|
|
3160
|
+
continue;
|
|
3161
|
+
}
|
|
3162
|
+
const name = path.posix.basename(unitPath);
|
|
3163
|
+
let localHash;
|
|
3164
|
+
let stamp;
|
|
3165
|
+
if (kind === 'directory') {
|
|
3166
|
+
const files = await readTree(path.join(writer.projectRoot, unitPath));
|
|
3167
|
+
const skill = files.get('SKILL.md');
|
|
3168
|
+
localHash = directoryUnitHash(files);
|
|
3169
|
+
stamp = typeof skill === 'string' ? readStamp(skill) : null;
|
|
3170
|
+
}
|
|
3171
|
+
else {
|
|
3172
|
+
const text = await readFile(path.join(writer.projectRoot, unitPath), 'utf8');
|
|
3173
|
+
localHash = fileUnitHash(text);
|
|
3174
|
+
stamp = readStamp(text);
|
|
3175
|
+
}
|
|
3176
|
+
if (stamp?.name != null && stamp.name !== name) {
|
|
3177
|
+
// A copy of an IWSDK unit the developer saved under another name.
|
|
3178
|
+
continue;
|
|
3179
|
+
}
|
|
3180
|
+
const ownership = classify(localHash, undefined, stamp, source.manifest.legacy[unitPath], source.manifest.version);
|
|
3181
|
+
if (ownership === 'managed' || ownership === 'legacy') {
|
|
3182
|
+
await writer.remove(unitPath);
|
|
3183
|
+
results.push({ path: unitPath, kind, action: 'removed' });
|
|
3184
|
+
if (kind === 'directory') {
|
|
3185
|
+
removedSkills.add(name);
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
else if (ownership === 'modified') {
|
|
3189
|
+
// A retired IWSDK unit the developer edited: keep it, but say so.
|
|
3190
|
+
results.push({
|
|
3191
|
+
path: unitPath,
|
|
3192
|
+
kind,
|
|
3193
|
+
action: 'skipped',
|
|
3194
|
+
reason: 'modified',
|
|
3195
|
+
});
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
return { results, removedSkills };
|
|
3199
|
+
}
|
|
3200
|
+
function readSkillDescription(text) {
|
|
3201
|
+
const frontmatter = normalizeText(text).match(/^---\n([\s\S]*?)\n---/u)?.[1];
|
|
3202
|
+
if (!frontmatter) {
|
|
3203
|
+
return '';
|
|
3204
|
+
}
|
|
3205
|
+
const lines = frontmatter.split('\n');
|
|
3206
|
+
const index = lines.findIndex((line) => line.startsWith('description:'));
|
|
3207
|
+
if (index === -1) {
|
|
3208
|
+
return '';
|
|
3209
|
+
}
|
|
3210
|
+
const inline = lines[index].slice('description:'.length).trim();
|
|
3211
|
+
if (inline && !/^[>|]-?$/u.test(inline)) {
|
|
3212
|
+
return inline.replace(/^['"]|['"]$/gu, '');
|
|
3213
|
+
}
|
|
3214
|
+
const folded = [];
|
|
3215
|
+
for (const line of lines.slice(index + 1)) {
|
|
3216
|
+
if (!/^\s+\S/u.test(line)) {
|
|
3217
|
+
break;
|
|
3218
|
+
}
|
|
3219
|
+
folded.push(line.trim());
|
|
3220
|
+
}
|
|
3221
|
+
return folded.join(' ');
|
|
3222
|
+
}
|
|
3223
|
+
async function summarizeSkills(source, tools) {
|
|
3224
|
+
const byName = new Map();
|
|
3225
|
+
for (const unit of selectedUnits(source.manifest, tools)) {
|
|
3226
|
+
if (unit.kind !== 'directory') {
|
|
3227
|
+
continue;
|
|
3228
|
+
}
|
|
3229
|
+
const name = unit.path.split('/').pop();
|
|
3230
|
+
const summary = byName.get(name) ?? {
|
|
3231
|
+
name,
|
|
3232
|
+
description: readSkillDescription((await readSourceFile(source, `${unit.path}/SKILL.md`)).toString('utf8')),
|
|
3233
|
+
paths: [],
|
|
3234
|
+
};
|
|
3235
|
+
summary.paths.push(`${unit.path}/SKILL.md`);
|
|
3236
|
+
byName.set(name, summary);
|
|
3237
|
+
}
|
|
3238
|
+
for (const summary of byName.values()) {
|
|
3239
|
+
// Claude Code's copy first; it is the path most sessions can load.
|
|
3240
|
+
summary.paths.sort((left, right) => left.startsWith('.claude/') === right.startsWith('.claude/')
|
|
3241
|
+
? left.localeCompare(right)
|
|
3242
|
+
: left.startsWith('.claude/')
|
|
3243
|
+
? -1
|
|
3244
|
+
: 1);
|
|
3245
|
+
}
|
|
3246
|
+
return [...byName.values()].sort((left, right) => left.name === 'iwsdk-dev'
|
|
3247
|
+
? -1
|
|
3248
|
+
: right.name === 'iwsdk-dev'
|
|
3249
|
+
? 1
|
|
3250
|
+
: left.name.localeCompare(right.name));
|
|
3251
|
+
}
|
|
3252
|
+
function buildAgentNotice(source, skills, dryRun, changedCount) {
|
|
3253
|
+
const version = source.manifest.version;
|
|
3254
|
+
const entry = skills.find((skill) => skill.name === 'iwsdk-dev');
|
|
3255
|
+
return [
|
|
3256
|
+
dryRun
|
|
3257
|
+
? `This project is checked against IWSDK ${version} agent guidance.`
|
|
3258
|
+
: changedCount > 0
|
|
3259
|
+
? `Installed IWSDK ${version} agent guidance in this project (${changedCount} file${changedCount === 1 ? '' : 's'} or folder${changedCount === 1 ? '' : 's'} written or removed).`
|
|
3260
|
+
: `This project's IWSDK ${version} agent guidance is already current; nothing was written.`,
|
|
3261
|
+
...(source.origin === 'bundled-cli'
|
|
3262
|
+
? [
|
|
3263
|
+
`This project does not list @iwsdk/core yet, so this is the guidance bundled with @iwsdk/cli (IWSDK ${version}). Run this command again after installing IWSDK.`,
|
|
3264
|
+
]
|
|
3265
|
+
: []),
|
|
3266
|
+
RETIRED_SURFACES_NOTICE,
|
|
3267
|
+
entry
|
|
3268
|
+
? `Before writing IWSDK code, read the iwsdk-agent-guidance block in AGENTS.md, then ${entry.paths.join(' or ')}.`
|
|
3269
|
+
: 'Before writing IWSDK code, read the iwsdk-agent-guidance block in AGENTS.md.',
|
|
3270
|
+
'Skills installed mid-session may not be listed until the next session; read their SKILL.md files directly when the task matches:',
|
|
3271
|
+
...skills.map((skill) => `- ${skill.name} (${skill.paths[0]}): ${skill.description.length > 220 ? `${skill.description.slice(0, 217)}...` : skill.description}`),
|
|
3272
|
+
].join('\n');
|
|
3273
|
+
}
|
|
3274
|
+
/**
|
|
3275
|
+
* Write a guidance release into a project. Files IWSDK wrote and nobody edited
|
|
3276
|
+
* are replaced; edited files and files IWSDK does not own are reported and left
|
|
3277
|
+
* alone unless `force` is set; retired IWSDK files are removed.
|
|
3278
|
+
*/
|
|
3279
|
+
async function syncAgentGuidance({ projectRoot, source, tools = [...GUIDANCE_TOOLS], force = false, dryRun = false, }) {
|
|
3280
|
+
const writer = createWriter(projectRoot, dryRun);
|
|
3281
|
+
const pruned = await pruneRetiredUnits(source, tools, writer);
|
|
3282
|
+
const results = [];
|
|
3283
|
+
const installedSkills = new Set();
|
|
3284
|
+
const units = selectedUnits(source.manifest, tools);
|
|
3285
|
+
// Settings last: they grant the skills this run installed.
|
|
3286
|
+
for (const unit of [
|
|
3287
|
+
...units.filter((candidate) => candidate.kind !== 'claude-settings'),
|
|
3288
|
+
...units.filter((candidate) => candidate.kind === 'claude-settings'),
|
|
3289
|
+
]) {
|
|
3290
|
+
switch (unit.kind) {
|
|
3291
|
+
case 'directory': {
|
|
3292
|
+
const result = await syncDirectoryUnit(unit, source, writer, force);
|
|
3293
|
+
if (unit.path.startsWith('.claude/') &&
|
|
3294
|
+
(result.action === 'created' || result.action === 'updated')) {
|
|
3295
|
+
installedSkills.add(path.posix.basename(unit.path));
|
|
3296
|
+
}
|
|
3297
|
+
results.push(result);
|
|
3298
|
+
break;
|
|
3299
|
+
}
|
|
3300
|
+
case 'file':
|
|
3301
|
+
results.push(await syncFileUnit(unit, source, writer, force));
|
|
3302
|
+
break;
|
|
3303
|
+
case 'block':
|
|
3304
|
+
results.push(await syncBlockUnit(unit, source, writer, force));
|
|
3305
|
+
break;
|
|
3306
|
+
case 'claude-import':
|
|
3307
|
+
results.push(await syncClaudeImport(unit, source, writer, force));
|
|
3308
|
+
break;
|
|
3309
|
+
case 'claude-settings':
|
|
3310
|
+
results.push(await syncClaudeSettings(unit, source, writer, installedSkills, pruned.removedSkills, force));
|
|
3311
|
+
break;
|
|
3312
|
+
}
|
|
3313
|
+
}
|
|
3314
|
+
results.push(...pruned.results);
|
|
3315
|
+
const skills = await summarizeSkills(source, tools);
|
|
3316
|
+
const changedCount = results.filter((result) => result.action !== 'unchanged' && result.action !== 'skipped').length;
|
|
3317
|
+
return {
|
|
3318
|
+
projectRoot,
|
|
3319
|
+
version: source.manifest.version,
|
|
3320
|
+
origin: source.origin,
|
|
3321
|
+
tools: [...tools],
|
|
3322
|
+
dryRun,
|
|
3323
|
+
changed: changedCount > 0,
|
|
3324
|
+
results,
|
|
3325
|
+
skipped: results.filter((result) => result.action === 'skipped'),
|
|
3326
|
+
skills,
|
|
3327
|
+
agentNotice: buildAgentNotice(source, skills, dryRun, changedCount),
|
|
3328
|
+
};
|
|
3329
|
+
}
|
|
3330
|
+
/**
|
|
3331
|
+
* The project that receives guidance: the nearest directory at or above
|
|
3332
|
+
* `startDirectory` with a package.json. In a monorepo, run from the app's
|
|
3333
|
+
* directory or pass --workspace.
|
|
3334
|
+
*/
|
|
3335
|
+
function findGuidanceProjectRoot(startDirectory) {
|
|
3336
|
+
let current = path.resolve(startDirectory);
|
|
3337
|
+
while (true) {
|
|
3338
|
+
if (existsSync(path.join(current, 'package.json'))) {
|
|
3339
|
+
return current;
|
|
3340
|
+
}
|
|
3341
|
+
const parent = path.dirname(current);
|
|
3342
|
+
if (parent === current) {
|
|
3343
|
+
return null;
|
|
3344
|
+
}
|
|
3345
|
+
current = parent;
|
|
3346
|
+
}
|
|
3347
|
+
}
|
|
3348
|
+
/**
|
|
3349
|
+
* The coding tools a project already has IWSDK guidance for, judged from
|
|
3350
|
+
* files only those tools read. Codex and OpenCode read the same files
|
|
3351
|
+
* (`.agents/skills` and nested `AGENTS.md`), so they count together.
|
|
3352
|
+
*/
|
|
3353
|
+
async function installedGuidanceTools(projectRoot, source) {
|
|
3354
|
+
const present = new Set();
|
|
3355
|
+
// Units several tools share (`.agents/skills`) are left for last: they
|
|
3356
|
+
// mean Codex/OpenCode only when no tool that shares them has its own files.
|
|
3357
|
+
const shared = [];
|
|
3358
|
+
const add = (tools) => {
|
|
3359
|
+
if (tools.length === 1) {
|
|
3360
|
+
present.add(tools[0]);
|
|
3361
|
+
}
|
|
3362
|
+
else {
|
|
3363
|
+
shared.push(tools);
|
|
3364
|
+
}
|
|
3365
|
+
};
|
|
3366
|
+
for (const unit of source.manifest.units) {
|
|
3367
|
+
// Settings and CLAUDE.md are written by MCP setup and by developers too.
|
|
3368
|
+
if (unit.tools.length < GUIDANCE_TOOLS.length &&
|
|
3369
|
+
(unit.kind === 'directory' ||
|
|
3370
|
+
unit.kind === 'file' ||
|
|
3371
|
+
(unit.kind === 'block' &&
|
|
3372
|
+
// A nested AGENTS.md counts only when it holds IWSDK's block.
|
|
3373
|
+
(await readTextIfExists(path.join(projectRoot, unit.path)))?.match(BLOCK_BEGIN) != null)) &&
|
|
3374
|
+
existsSync(path.join(projectRoot, unit.path))) {
|
|
3375
|
+
add(unit.tools);
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3378
|
+
// A file from an earlier release counts only when it is that release's file.
|
|
3379
|
+
for (const [unitPath, hashes] of Object.entries(source.manifest.legacy)) {
|
|
3380
|
+
const tools = toolsForPath(unitPath);
|
|
3381
|
+
const filePath = path.join(projectRoot, unitPath);
|
|
3382
|
+
if (tools.length === GUIDANCE_TOOLS.length || !existsSync(filePath)) {
|
|
3383
|
+
continue;
|
|
3384
|
+
}
|
|
3385
|
+
const hash = (await pathKind(filePath)) === 'directory'
|
|
3386
|
+
? directoryUnitHash(await readTree(filePath))
|
|
3387
|
+
: fileUnitHash(await readFile(filePath, 'utf8'));
|
|
3388
|
+
if (hashes.includes(hash)) {
|
|
3389
|
+
add(tools);
|
|
3390
|
+
}
|
|
3391
|
+
}
|
|
3392
|
+
for (const tools of shared) {
|
|
3393
|
+
if (tools.includes('codex') &&
|
|
3394
|
+
!tools.some((tool) => tool !== 'codex' && tool !== 'opencode' && present.has(tool))) {
|
|
3395
|
+
present.add('codex');
|
|
3396
|
+
present.add('opencode');
|
|
3397
|
+
}
|
|
3398
|
+
}
|
|
3399
|
+
return GUIDANCE_TOOLS.filter((tool) => present.has(tool));
|
|
3400
|
+
}
|
|
3401
|
+
|
|
3402
|
+
export { GUIDANCE_TOOLS, GuidanceSourceError, blockUnitHash, directoryUnitHash, fileUnitHash, findGuidanceProjectRoot, installedGuidanceTools, loadGuidanceSource, ownedSkillNames, readInstalledCoreVersion, resolveInstalledCorePackageJson, resolveProjectGuidance, syncAgentGuidance };
|
|
3403
|
+
//# sourceMappingURL=agent-guidance.js.map
|