@effected/workspaces 0.47.1 → 0.48.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/ConfigDependencyHooks.js +14 -26
- package/PackageManagerName.js +75 -19
- package/PackedInstall.js +7 -9
- package/PeerCheck.js +9 -10
- package/README.md +13 -43
- package/WorkspaceCatalogs.js +9 -7
- package/WorkspacePackage.js +7 -1
- package/WorkspaceStateSnapshot.js +3 -1
- package/Workspaces.js +5 -2
- package/WorkspacesSync.js +7 -5
- package/index.d.ts +91 -409
- package/index.js +3 -4
- package/internal/catalogs.js +55 -32
- package/internal/importerVersions.js +1 -1
- package/internal/limits.js +1 -1
- package/internal/membership.js +2 -1
- package/internal/packageManagerDecision.js +14 -3
- package/internal/packedInstallPlan.js +10 -33
- package/internal/workspaceYaml.js +4 -4
- package/package.json +8 -10
- package/testing.d.ts +30 -22
- package/PnpmSettings.js +0 -535
- package/internal/peerPatterns.js +0 -34
package/PnpmSettings.js
DELETED
|
@@ -1,535 +0,0 @@
|
|
|
1
|
-
import { stringsOf } from "./internal/patterns.js";
|
|
2
|
-
import { Effect, FileSystem, Option, Path, Result, Schema } from "effect";
|
|
3
|
-
import { GlobSet } from "@effected/glob";
|
|
4
|
-
import { Yaml } from "@effected/yaml";
|
|
5
|
-
import { Walker } from "@effected/walker";
|
|
6
|
-
|
|
7
|
-
// src/PnpmSettings.ts
|
|
8
|
-
/**
|
|
9
|
-
* A pnpm settings file could not be used.
|
|
10
|
-
*
|
|
11
|
-
* @remarks
|
|
12
|
-
* `reason` routes: `"read"` — the file exists but could not be read (the
|
|
13
|
-
* platform failure is the `cause`); `"parse"` — the file is not valid YAML (the
|
|
14
|
-
* `YamlParseError` is the `cause`); `"shape"` — the file is valid YAML but its
|
|
15
|
-
* document is not a mapping (a list or a scalar), which pnpm refuses too;
|
|
16
|
-
* `"membership"` — the workspace's `packages:` patterns each compile alone but
|
|
17
|
-
* fail as a set (they share one compile budget; the `GlobError` is the
|
|
18
|
-
* `cause`), so whether the directory is a member cannot be decided and the
|
|
19
|
-
* load fails rather than reading the workspace file as not applying. A
|
|
20
|
-
* file that does not exist is not an error: pnpm skips it, and so does
|
|
21
|
-
* {@link PnpmSettings.load}. An empty file is an empty mapping.
|
|
22
|
-
*
|
|
23
|
-
* @public
|
|
24
|
-
*/
|
|
25
|
-
var PnpmSettingsError = class extends Schema.TaggedError()("PnpmSettingsError", {
|
|
26
|
-
/** Why the file could not be used. */
|
|
27
|
-
reason: Schema.Literals([
|
|
28
|
-
"read",
|
|
29
|
-
"parse",
|
|
30
|
-
"shape",
|
|
31
|
-
"membership"
|
|
32
|
-
]),
|
|
33
|
-
/** The file involved, when the source named one. */
|
|
34
|
-
path: Schema.optionalKey(Schema.String),
|
|
35
|
-
/** The underlying failure, for `"read"`, `"parse"` and `"membership"`. */
|
|
36
|
-
cause: Schema.optionalKey(Schema.Defect())
|
|
37
|
-
}) {
|
|
38
|
-
get message() {
|
|
39
|
-
const where = this.path === void 0 ? "pnpm settings file" : `pnpm settings file ${this.path}`;
|
|
40
|
-
return this.reason === "read" ? `Could not read ${where}` : this.reason === "membership" ? `The \`packages:\` patterns in ${where} compile one by one but not as a set, so workspace membership cannot be decided` : this.reason === "parse" ? `Could not parse ${where} as YAML` : `The document in ${where} is not a mapping of settings`;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
/** A setting name as pnpm spells it in YAML: camelCase, from an npmrc-style kebab-case key. */
|
|
44
|
-
const settingName = (key) => key.startsWith("@") || key.startsWith("/") ? key : key.replace(/-([a-z0-9])/g, (_, char) => char.toUpperCase());
|
|
45
|
-
/** A lower snake-case env suffix as the camelCase setting it names (`minimum_release_age` → `minimumReleaseAge`). */
|
|
46
|
-
const camelFromSnake = (snake) => snake.replace(/_([a-z0-9])/g, (_, char) => char.toUpperCase());
|
|
47
|
-
/** pnpm's two accepted spellings: all-lowercase or all-uppercase prefix and suffix, no empty segment. */
|
|
48
|
-
const LOWER_ENV = /^pnpm_config_([a-z0-9]+(?:_[a-z0-9]+)*)$/;
|
|
49
|
-
const UPPER_ENV = /^PNPM_CONFIG_([A-Z0-9]+(?:_[A-Z0-9]+)*)$/;
|
|
50
|
-
/** Defines an own, enumerable data property, so a `__proto__` key never reaches a prototype. */
|
|
51
|
-
const define = (target, key, value) => {
|
|
52
|
-
Object.defineProperty(target, key, {
|
|
53
|
-
value,
|
|
54
|
-
writable: true,
|
|
55
|
-
enumerable: true,
|
|
56
|
-
configurable: true
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* The environment's pnpm settings, keyed by camelCase setting name. An empty
|
|
61
|
-
* value is unset, and the uppercase spelling wins over the lowercase one when
|
|
62
|
-
* both are present, as pnpm 12 resolves them.
|
|
63
|
-
*/
|
|
64
|
-
const environmentSettings = (env) => {
|
|
65
|
-
const lower = {};
|
|
66
|
-
const upper = {};
|
|
67
|
-
for (const [name, value] of Object.entries(env)) {
|
|
68
|
-
if (value === void 0 || value === "") continue;
|
|
69
|
-
const lowerMatch = LOWER_ENV.exec(name);
|
|
70
|
-
if (lowerMatch !== null) define(lower, camelFromSnake(lowerMatch[1]), value);
|
|
71
|
-
const upperMatch = UPPER_ENV.exec(name);
|
|
72
|
-
if (upperMatch !== null) define(upper, camelFromSnake(upperMatch[1].toLowerCase()), value);
|
|
73
|
-
}
|
|
74
|
-
const merged = {};
|
|
75
|
-
for (const [key, value] of Object.entries(lower)) define(merged, key, value);
|
|
76
|
-
for (const [key, value] of Object.entries(upper)) define(merged, key, value);
|
|
77
|
-
return merged;
|
|
78
|
-
};
|
|
79
|
-
/** One YAML settings file as its top-level mapping: an empty document is `{}`, a non-mapping fails `"shape"`. */
|
|
80
|
-
const mappingOf = (source) => {
|
|
81
|
-
if (source === void 0) return Result.succeed({});
|
|
82
|
-
const at = source.path === void 0 ? {} : { path: source.path };
|
|
83
|
-
const parsed = Yaml.parseResult(source.text);
|
|
84
|
-
if (Result.isFailure(parsed)) return Result.fail(new PnpmSettingsError({
|
|
85
|
-
reason: "parse",
|
|
86
|
-
...at,
|
|
87
|
-
cause: parsed.failure
|
|
88
|
-
}));
|
|
89
|
-
const document = parsed.success;
|
|
90
|
-
if (document === null || document === void 0) return Result.succeed({});
|
|
91
|
-
if (typeof document !== "object" || Array.isArray(document)) return Result.fail(new PnpmSettingsError({
|
|
92
|
-
reason: "shape",
|
|
93
|
-
...at
|
|
94
|
-
}));
|
|
95
|
-
const mapping = {};
|
|
96
|
-
for (const [key, value] of Object.entries(document)) define(mapping, key, value);
|
|
97
|
-
return Result.succeed(mapping);
|
|
98
|
-
};
|
|
99
|
-
/** A canonical decimal: optional `-`, no leading zero, no `+`, hex, exponent or digit separator. */
|
|
100
|
-
const DECIMAL = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$/;
|
|
101
|
-
/** A canonical unsigned integer, the only form pnpm 12 reads for an integer setting. */
|
|
102
|
-
const UNSIGNED = /^(?:0|[1-9][0-9]*)$/;
|
|
103
|
-
/** A trimmed canonical decimal string as a finite number, or `undefined`. */
|
|
104
|
-
const numberFromText = (text) => {
|
|
105
|
-
const trimmed = text.trim();
|
|
106
|
-
if (!DECIMAL.test(trimmed)) return void 0;
|
|
107
|
-
const value = Number(trimmed);
|
|
108
|
-
return Number.isFinite(value) ? value : void 0;
|
|
109
|
-
};
|
|
110
|
-
/** A trimmed canonical unsigned integer string, within the safe-integer range, or `undefined`. */
|
|
111
|
-
const unsignedFromText = (text) => {
|
|
112
|
-
const trimmed = text.trim();
|
|
113
|
-
if (!UNSIGNED.test(trimmed)) return void 0;
|
|
114
|
-
const value = Number(trimmed);
|
|
115
|
-
return Number.isSafeInteger(value) ? value : void 0;
|
|
116
|
-
};
|
|
117
|
-
/** A file value as a non-negative safe integer: a number (never `-0`) or a canonical unsigned string. */
|
|
118
|
-
const unsignedFromValue = (value) => typeof value === "number" ? Number.isSafeInteger(value) && value >= 0 && !Object.is(value, -0) ? value : void 0 : typeof value === "string" ? unsignedFromText(value) : void 0;
|
|
119
|
-
const numberFromValue = (value) => typeof value === "number" ? Number.isFinite(value) ? value : void 0 : typeof value === "string" ? numberFromText(value) : void 0;
|
|
120
|
-
const stringsFromValue = (value) => Array.isArray(value) && value.every((item) => typeof item === "string") ? value : void 0;
|
|
121
|
-
/** An environment value as a list: a JSON array of strings, the one form pnpm 11 and 12 both read as a list. */
|
|
122
|
-
const stringsFromText = (text) => {
|
|
123
|
-
let parsed;
|
|
124
|
-
try {
|
|
125
|
-
parsed = JSON.parse(text);
|
|
126
|
-
} catch {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
return stringsFromValue(parsed);
|
|
130
|
-
};
|
|
131
|
-
/** An environment value as a boolean: exactly `true` or `false` once trimmed, as pnpm 12 reads it. */
|
|
132
|
-
const booleanFromText = (text) => {
|
|
133
|
-
const trimmed = text.trim();
|
|
134
|
-
return trimmed === "true" ? true : trimmed === "false" ? false : void 0;
|
|
135
|
-
};
|
|
136
|
-
/** The strings pnpm 12 coerces to a boolean in a settings file, compared trimmed and case-insensitively. */
|
|
137
|
-
const TRUTHY = /* @__PURE__ */ new Set([
|
|
138
|
-
"true",
|
|
139
|
-
"yes",
|
|
140
|
-
"y",
|
|
141
|
-
"on"
|
|
142
|
-
]);
|
|
143
|
-
const FALSY = /* @__PURE__ */ new Set([
|
|
144
|
-
"false",
|
|
145
|
-
"no",
|
|
146
|
-
"n",
|
|
147
|
-
"off"
|
|
148
|
-
]);
|
|
149
|
-
/** A file value as a boolean: a YAML boolean, or one of the strings pnpm 12 coerces. */
|
|
150
|
-
const booleanFromValue = (value) => {
|
|
151
|
-
if (typeof value === "boolean") return value;
|
|
152
|
-
if (typeof value !== "string") return void 0;
|
|
153
|
-
const word = value.trim().toLowerCase();
|
|
154
|
-
return TRUTHY.has(word) ? true : FALSY.has(word) ? false : void 0;
|
|
155
|
-
};
|
|
156
|
-
/** The one name pnpm accepts for a workspace manifest. */
|
|
157
|
-
const WORKSPACE_MANIFEST = "pnpm-workspace.yaml";
|
|
158
|
-
/** The files that make a directory a project for pnpm's membership check. */
|
|
159
|
-
const PROJECT_MANIFESTS = [
|
|
160
|
-
"package.json",
|
|
161
|
-
"package.json5",
|
|
162
|
-
"package.yaml"
|
|
163
|
-
];
|
|
164
|
-
/** Directory names that keep a directory out of every workspace, as pnpm 11 rules. */
|
|
165
|
-
const IGNORED_SEGMENTS = /* @__PURE__ */ new Set(["node_modules", "bower_components"]);
|
|
166
|
-
/** A POSIX pattern body with empty and `.` segments dropped and `..` folded, as `path.posix.normalize` would. */
|
|
167
|
-
const normalizeBody = (body) => {
|
|
168
|
-
const out = [];
|
|
169
|
-
for (const segment of body.split("/")) {
|
|
170
|
-
if (segment === "" || segment === ".") continue;
|
|
171
|
-
if (segment === ".." && out.length > 0 && out[out.length - 1] !== "..") out.pop();
|
|
172
|
-
else out.push(segment);
|
|
173
|
-
}
|
|
174
|
-
return out.join("/");
|
|
175
|
-
};
|
|
176
|
-
/**
|
|
177
|
-
* Whether a project directory at `relative` (a non-empty POSIX path below the
|
|
178
|
-
* workspace root) is a member under the manifest's `packages:` value, by
|
|
179
|
-
* pnpm's rule: each pattern names a directory whose `package.json` must match,
|
|
180
|
-
* a `!` pattern excludes, a pattern starting with `/` is skipped, and an absent
|
|
181
|
-
* list is `["."]`, the root alone. A single pattern that does not compile
|
|
182
|
-
* matches nothing; a set that compiles pattern by pattern but fails as a whole
|
|
183
|
-
* (the members share one compile budget) is neither member nor non-member, so
|
|
184
|
-
* it fails `"membership"` rather than answering `false`.
|
|
185
|
-
*/
|
|
186
|
-
const isWorkspaceMember = (relative, packages) => {
|
|
187
|
-
if (relative.split("/").some((segment) => IGNORED_SEGMENTS.has(segment))) return Result.succeed(false);
|
|
188
|
-
const patterns = stringsOf(packages) ?? ["."];
|
|
189
|
-
const globs = [];
|
|
190
|
-
for (const pattern of patterns) {
|
|
191
|
-
const negated = pattern.startsWith("!");
|
|
192
|
-
const body = negated ? pattern.slice(1) : pattern;
|
|
193
|
-
if (body.startsWith("/")) continue;
|
|
194
|
-
const normalized = normalizeBody(body);
|
|
195
|
-
const glob = `${negated ? "!" : ""}${normalized === "" ? "" : `${normalized}/`}package.json`;
|
|
196
|
-
if (Result.isSuccess(GlobSet.compileResult([glob]))) globs.push(glob);
|
|
197
|
-
}
|
|
198
|
-
const set = GlobSet.compileResult(globs);
|
|
199
|
-
return Result.isSuccess(set) ? Result.succeed(set.success.matches(`${relative}/package.json`)) : Result.fail(new PnpmSettingsError({
|
|
200
|
-
reason: "membership",
|
|
201
|
-
cause: set.failure
|
|
202
|
-
}));
|
|
203
|
-
};
|
|
204
|
-
/** The first non-empty value of the named variables, read as own properties. */
|
|
205
|
-
const firstEnv = (env, names) => {
|
|
206
|
-
for (const name of names) {
|
|
207
|
-
const value = Object.hasOwn(env, name) ? env[name] : void 0;
|
|
208
|
-
if (value !== void 0 && value !== "") return value;
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
/**
|
|
212
|
-
* pnpm's effective settings: the values `pnpm config get <key>` reports for a
|
|
213
|
-
* pnpm setting, merged from the sources pnpm reads with pnpm's precedence.
|
|
214
|
-
*
|
|
215
|
-
* @remarks
|
|
216
|
-
* Build one with {@link PnpmSettings.load} (finds and reads the files through
|
|
217
|
-
* `FileSystem`) or {@link PnpmSettings.fromSourcesResult} (from text you
|
|
218
|
-
* already hold), then read a setting by name:
|
|
219
|
-
*
|
|
220
|
-
* ```ts
|
|
221
|
-
* settings.minimumReleaseAge; // Option<number>
|
|
222
|
-
* settings.minimumReleaseAgeExclude; // ReadonlyArray<string>
|
|
223
|
-
* settings.getBoolean("minimumReleaseAgeStrict");
|
|
224
|
-
* ```
|
|
225
|
-
*
|
|
226
|
-
* **Precedence, highest first**: a `pnpm_config_<name>` or
|
|
227
|
-
* `PNPM_CONFIG_<NAME>` environment variable, the workspace root's
|
|
228
|
-
* `pnpm-workspace.yaml`, then pnpm's global `config.yaml`. A higher source
|
|
229
|
-
* replaces a lower one's value whole; lists are not merged. This is the order
|
|
230
|
-
* pnpm 11 and pnpm 12 apply to settings such as `minimumReleaseAge` and
|
|
231
|
-
* `minimumReleaseAgeExclude`.
|
|
232
|
-
*
|
|
233
|
-
* **What pnpm does not read for a pnpm setting, this does not read either.**
|
|
234
|
-
* `.npmrc` files (project, user and global), `npm_config_*` variables and
|
|
235
|
-
* the old global `rc` file carry no pnpm setting for pnpm 11 and 12: pnpm
|
|
236
|
-
* takes only registry and auth keys from `.npmrc`. A registry or a credential
|
|
237
|
-
* is `@effected/npm`'s `NpmConfig`, not this. Command-line `--config.*`
|
|
238
|
-
* flags, pnpm's built-in defaults (`minimumReleaseAge` reads as unset here,
|
|
239
|
-
* as `pnpm config get` reports it, though pnpm applies a default when it
|
|
240
|
-
* installs), and the per-setting source restrictions pnpm applies to a few
|
|
241
|
-
* machine-level settings (a `pnpm-workspace.yaml` cannot set `globalDir`, for
|
|
242
|
-
* example) are not modelled.
|
|
243
|
-
*
|
|
244
|
-
* **Keys.** Every accessor takes the camelCase name pnpm writes in YAML
|
|
245
|
-
* (`minimumReleaseAge`) or the kebab-case one an npmrc would use
|
|
246
|
-
* (`minimum-release-age`); both name the same setting. An environment
|
|
247
|
-
* variable names a setting in snake case: `pnpm_config_minimum_release_age`
|
|
248
|
-
* all lowercase, or `PNPM_CONFIG_MINIMUM_RELEASE_AGE` all uppercase. A mixed
|
|
249
|
-
* spelling is not a pnpm setting and is ignored, and an empty value is unset.
|
|
250
|
-
* When both spellings are set, the uppercase one wins, as in pnpm 12.
|
|
251
|
-
*
|
|
252
|
-
* **Typed reads.** An environment value is text, read as the type the
|
|
253
|
-
* accessor asks for: a number as a canonical decimal, a boolean as `true` or
|
|
254
|
-
* `false`, a list as a JSON array of strings. An environment value that does
|
|
255
|
-
* not read as that type is skipped, and the next source answers, as pnpm 12
|
|
256
|
-
* skips it. In a file, pnpm 12 coerces boolean words (`yes`, `on`, `"true"`)
|
|
257
|
-
* and digit strings (`"15"`), and so does this. A file value that still does
|
|
258
|
-
* not read as the type answers `None` instead of falling through, because
|
|
259
|
-
* pnpm 12 refuses to load a file with a mistyped setting; {@link
|
|
260
|
-
* PnpmSettings.get} shows the raw value. A `null` in a file is unset.
|
|
261
|
-
*
|
|
262
|
-
* @example
|
|
263
|
-
* ```ts
|
|
264
|
-
* import { PnpmSettings } from "@effected/workspaces";
|
|
265
|
-
* import { Effect, Option } from "effect";
|
|
266
|
-
*
|
|
267
|
-
* const cutoffMinutes = Effect.gen(function* () {
|
|
268
|
-
* const settings = yield* PnpmSettings.load({
|
|
269
|
-
* cwd: process.cwd(),
|
|
270
|
-
* env: process.env,
|
|
271
|
-
* platform: process.platform,
|
|
272
|
-
* });
|
|
273
|
-
* // Unset means pnpm's own default, 1440 minutes, not an open gate.
|
|
274
|
-
* return Option.getOrElse(settings.minimumReleaseAge, () => 1440);
|
|
275
|
-
* });
|
|
276
|
-
* ```
|
|
277
|
-
*
|
|
278
|
-
* @public
|
|
279
|
-
*/
|
|
280
|
-
var PnpmSettings = class PnpmSettings extends Schema.Class("PnpmSettings")({
|
|
281
|
-
/** The environment's pnpm settings, keyed by camelCase name, as written. */
|
|
282
|
-
environment: Schema.Record(Schema.String, Schema.String),
|
|
283
|
-
/** The top-level settings of the workspace's `pnpm-workspace.yaml`. */
|
|
284
|
-
workspace: Schema.Record(Schema.String, Schema.Unknown),
|
|
285
|
-
/** The top-level settings of pnpm's global `config.yaml`. */
|
|
286
|
-
global: Schema.Record(Schema.String, Schema.Unknown),
|
|
287
|
-
/** The settings files that were read, lowest precedence first. */
|
|
288
|
-
files: Schema.Array(Schema.String)
|
|
289
|
-
}) {
|
|
290
|
-
/**
|
|
291
|
-
* A setting's raw value from the highest source that sets it, or `None`.
|
|
292
|
-
*
|
|
293
|
-
* @remarks
|
|
294
|
-
* An environment value is the string as written; a file value is the
|
|
295
|
-
* decoded YAML (a number, a list, a mapping). Use the typed accessors to
|
|
296
|
-
* read it as a type.
|
|
297
|
-
*
|
|
298
|
-
* @param key - The setting, camelCase or kebab-case.
|
|
299
|
-
*/
|
|
300
|
-
get(key) {
|
|
301
|
-
const name = settingName(key);
|
|
302
|
-
if (Object.hasOwn(this.environment, name)) return Option.some(this.environment[name]);
|
|
303
|
-
for (const layer of [this.workspace, this.global]) {
|
|
304
|
-
const value = Object.hasOwn(layer, name) ? layer[name] : void 0;
|
|
305
|
-
if (value !== void 0 && value !== null) return Option.some(value);
|
|
306
|
-
}
|
|
307
|
-
return Option.none();
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Which source {@link PnpmSettings.get} answers a setting from, or `None`
|
|
311
|
-
* when no source sets it.
|
|
312
|
-
*
|
|
313
|
-
* @param key - The setting, camelCase or kebab-case.
|
|
314
|
-
*/
|
|
315
|
-
origin(key) {
|
|
316
|
-
const name = settingName(key);
|
|
317
|
-
if (Object.hasOwn(this.environment, name)) return Option.some("environment");
|
|
318
|
-
if (Object.hasOwn(this.workspace, name) && this.workspace[name] != null) return Option.some("workspace");
|
|
319
|
-
if (Object.hasOwn(this.global, name) && this.global[name] != null) return Option.some("global");
|
|
320
|
-
return Option.none();
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* A string setting: an environment value as written, or a string in a file.
|
|
324
|
-
*
|
|
325
|
-
* @param key - The setting, camelCase or kebab-case.
|
|
326
|
-
*/
|
|
327
|
-
getString(key) {
|
|
328
|
-
return this.read(key, (text) => text, (value) => typeof value === "string" ? value : void 0);
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* A numeric setting: a finite number, or a canonical decimal string, in any
|
|
332
|
-
* source.
|
|
333
|
-
*
|
|
334
|
-
* @remarks
|
|
335
|
-
* A canonical decimal is an optional `-`, digits with no leading zero, and
|
|
336
|
-
* an optional fraction: `05`, `+5`, `0x10`, `1e2` and `1_000` are not
|
|
337
|
-
* numbers here, as pnpm 12 does not read them from the environment. An
|
|
338
|
-
* integer setting such as {@link PnpmSettings.minimumReleaseAge} is
|
|
339
|
-
* stricter still.
|
|
340
|
-
*
|
|
341
|
-
* @param key - The setting, camelCase or kebab-case.
|
|
342
|
-
*/
|
|
343
|
-
getNumber(key) {
|
|
344
|
-
return this.read(key, numberFromText, numberFromValue);
|
|
345
|
-
}
|
|
346
|
-
/**
|
|
347
|
-
* A boolean setting: `true` or `false` in the environment, a YAML boolean
|
|
348
|
-
* or a boolean word in a file.
|
|
349
|
-
*
|
|
350
|
-
* @remarks
|
|
351
|
-
* In a file, the strings `true`, `yes`, `y` and `on` read as `true` and
|
|
352
|
-
* `false`, `no`, `n` and `off` as `false`, trimmed and in any case, as
|
|
353
|
-
* pnpm 12 coerces them. A number (`1`, `0`) or any other string answers
|
|
354
|
-
* `None`; pnpm 12 refuses it as an invalid boolean. The environment is
|
|
355
|
-
* stricter: only `true` or `false`, trimmed and lowercase.
|
|
356
|
-
*
|
|
357
|
-
* @param key - The setting, camelCase or kebab-case.
|
|
358
|
-
*/
|
|
359
|
-
getBoolean(key) {
|
|
360
|
-
return this.read(key, booleanFromText, booleanFromValue);
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* A list setting: a JSON array of strings in the environment, a YAML list
|
|
364
|
-
* of strings in a file.
|
|
365
|
-
*
|
|
366
|
-
* @remarks
|
|
367
|
-
* A comma-separated environment value is not a list: pnpm 12 ignores it,
|
|
368
|
-
* and this skips it to the next source.
|
|
369
|
-
*
|
|
370
|
-
* @param key - The setting, camelCase or kebab-case.
|
|
371
|
-
*/
|
|
372
|
-
getStringArray(key) {
|
|
373
|
-
return this.read(key, stringsFromText, stringsFromValue);
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* `minimumReleaseAge`: the minutes a version must have been published before
|
|
377
|
-
* pnpm installs it, or `None` when no source sets it. `None` is not an
|
|
378
|
-
* open gate: pnpm then applies its built-in default of 1440 minutes.
|
|
379
|
-
*
|
|
380
|
-
* @remarks
|
|
381
|
-
* Only a non-negative safe integer counts, as pnpm 12 reads the setting
|
|
382
|
-
* (an unsigned 64-bit integer, here bounded by `Number.MAX_SAFE_INTEGER`).
|
|
383
|
-
* Text, in the environment or a quoted file value, must be canonical digits
|
|
384
|
-
* once trimmed: `" 30 "` reads as 30, while `05`, `+5`, `-0`, `5.0`, `0x10`
|
|
385
|
-
* and `1e2` do not read at all. Such an environment value is skipped to the
|
|
386
|
-
* next source; such a file value answers `None`. A YAML number is read as
|
|
387
|
-
* decoded, so an unquoted `5.0` or `1e2` in a file reads as 5 or 100 where
|
|
388
|
-
* pnpm 12 refuses the file.
|
|
389
|
-
*/
|
|
390
|
-
get minimumReleaseAge() {
|
|
391
|
-
return this.read("minimumReleaseAge", unsignedFromText, unsignedFromValue);
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* `minimumReleaseAgeExclude`: the package patterns exempt from
|
|
395
|
-
* {@link PnpmSettings.minimumReleaseAge}, empty when no source sets them.
|
|
396
|
-
*
|
|
397
|
-
* @remarks
|
|
398
|
-
* An explicitly empty list in a higher source shadows a lower source's
|
|
399
|
-
* entries, as in pnpm.
|
|
400
|
-
*/
|
|
401
|
-
get minimumReleaseAgeExclude() {
|
|
402
|
-
return Option.getOrElse(this.getStringArray("minimumReleaseAgeExclude"), () => []);
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* The typed read every accessor shares: an environment value that does not
|
|
406
|
-
* parse falls through; the first file that sets the key decides.
|
|
407
|
-
*/
|
|
408
|
-
read(key, fromText, fromValue) {
|
|
409
|
-
const name = settingName(key);
|
|
410
|
-
if (Object.hasOwn(this.environment, name)) {
|
|
411
|
-
const parsed = fromText(this.environment[name]);
|
|
412
|
-
if (parsed !== void 0) return Option.some(parsed);
|
|
413
|
-
}
|
|
414
|
-
for (const layer of [this.workspace, this.global]) {
|
|
415
|
-
const value = Object.hasOwn(layer, name) ? layer[name] : void 0;
|
|
416
|
-
if (value === void 0 || value === null) continue;
|
|
417
|
-
return Option.fromUndefinedOr(fromValue(value));
|
|
418
|
-
}
|
|
419
|
-
return Option.none();
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* Merges pnpm's settings sources, with no IO.
|
|
423
|
-
*
|
|
424
|
-
* @remarks
|
|
425
|
-
* Parses each YAML file, keeps the environment's `pnpm_config_*` and
|
|
426
|
-
* `PNPM_CONFIG_*` variables, and records the named files in
|
|
427
|
-
* `PnpmSettings.files`. Fails `"parse"` for a file that is not YAML
|
|
428
|
-
* and `"shape"` for one whose document is not a mapping.
|
|
429
|
-
*
|
|
430
|
-
* @param sources - The workspace file, the global file and the environment.
|
|
431
|
-
*/
|
|
432
|
-
static fromSourcesResult(sources) {
|
|
433
|
-
const global = mappingOf(sources.global);
|
|
434
|
-
if (Result.isFailure(global)) return Result.fail(global.failure);
|
|
435
|
-
const workspace = mappingOf(sources.workspace);
|
|
436
|
-
if (Result.isFailure(workspace)) return Result.fail(workspace.failure);
|
|
437
|
-
const files = [];
|
|
438
|
-
for (const source of [sources.global, sources.workspace]) if (source?.path !== void 0) files.push(source.path);
|
|
439
|
-
return Result.succeed(PnpmSettings.make({
|
|
440
|
-
environment: environmentSettings(sources.env ?? {}),
|
|
441
|
-
workspace: workspace.success,
|
|
442
|
-
global: global.success,
|
|
443
|
-
files
|
|
444
|
-
}));
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Loads the settings pnpm would use when run in `options.cwd`.
|
|
448
|
-
*
|
|
449
|
-
* @remarks
|
|
450
|
-
* The workspace file is found as pnpm finds it. When a
|
|
451
|
-
* `PNPM_CONFIG_WORKSPACE_DIR` / `NPM_CONFIG_WORKSPACE_DIR` variable names a
|
|
452
|
-
* directory (resolved against `cwd`), its `pnpm-workspace.yaml` is the
|
|
453
|
-
* file, unconditionally. Otherwise `cwd` is resolved through
|
|
454
|
-
* `FileSystem.realPath` (the lexical path when that fails, as in pnpm), and
|
|
455
|
-
* the nearest `pnpm-workspace.yaml` at or above it is taken. A misnamed
|
|
456
|
-
* manifest (`pnpm-workspace.yml`, `.pnpm-workspace.yaml`) is not a
|
|
457
|
-
* workspace manifest and the ascent passes it, as pnpm 12 does; pnpm 11
|
|
458
|
-
* refuses to run below one. That workspace applies only when `cwd` belongs
|
|
459
|
-
* to it: `cwd`
|
|
460
|
-
* is its root, `cwd` holds no project manifest (`package.json`,
|
|
461
|
-
* `package.json5` or `package.yaml`), or `cwd` matches the manifest's
|
|
462
|
-
* `packages:` patterns. A manifest with no `packages:` key has the root as
|
|
463
|
-
* its only member, so a nested project with its own `package.json` (an
|
|
464
|
-
* example app, a fixture) reads no workspace file, exactly as pnpm skips
|
|
465
|
-
* it. A directory under `node_modules` or `bower_components` is never a
|
|
466
|
-
* member.
|
|
467
|
-
*
|
|
468
|
-
* The global file is `config.yaml` in pnpm's global config directory:
|
|
469
|
-
* {@link PnpmSettingsLoadOptions.globalConfigDir}, else
|
|
470
|
-
* `$XDG_CONFIG_HOME/pnpm`, else the platform default (see
|
|
471
|
-
* {@link PnpmSettingsLoadOptions.platform}). A file that does not exist is
|
|
472
|
-
* skipped; one that cannot be read fails `"read"` (so does a project
|
|
473
|
-
* manifest probe that fails other than not-found), and one that does not
|
|
474
|
-
* parse fails as {@link PnpmSettings.fromSourcesResult} does.
|
|
475
|
-
*
|
|
476
|
-
* @param options - See {@link PnpmSettingsLoadOptions}.
|
|
477
|
-
*/
|
|
478
|
-
static load = Effect.fn("PnpmSettings.load")(function* (options) {
|
|
479
|
-
const fs = yield* FileSystem.FileSystem;
|
|
480
|
-
const path = yield* Path.Path;
|
|
481
|
-
const env = options.env;
|
|
482
|
-
const cwd = path.resolve(options.cwd);
|
|
483
|
-
const realCwd = yield* fs.realPath(cwd).pipe(Effect.orElseSucceed(() => cwd));
|
|
484
|
-
const home = options.home ?? firstEnv(env, ["HOME", "USERPROFILE"]);
|
|
485
|
-
const read = (file) => fs.readFileString(file).pipe(Effect.map((text) => ({
|
|
486
|
-
text,
|
|
487
|
-
path: file
|
|
488
|
-
})), Effect.catchTag("PlatformError", (error) => error.reason._tag === "NotFound" ? Effect.succeed(void 0) : Effect.fail(new PnpmSettingsError({
|
|
489
|
-
reason: "read",
|
|
490
|
-
path: file,
|
|
491
|
-
cause: error
|
|
492
|
-
}))));
|
|
493
|
-
const workspaceDir = firstEnv(env, [
|
|
494
|
-
"PNPM_CONFIG_WORKSPACE_DIR",
|
|
495
|
-
"pnpm_config_workspace_dir",
|
|
496
|
-
"NPM_CONFIG_WORKSPACE_DIR",
|
|
497
|
-
"npm_config_workspace_dir"
|
|
498
|
-
]);
|
|
499
|
-
const hasProjectManifest = (dir) => Effect.forEach(PROJECT_MANIFESTS, (name) => {
|
|
500
|
-
const file = path.join(dir, name);
|
|
501
|
-
return fs.exists(file).pipe(Effect.mapError((cause) => new PnpmSettingsError({
|
|
502
|
-
reason: "read",
|
|
503
|
-
path: file,
|
|
504
|
-
cause
|
|
505
|
-
})));
|
|
506
|
-
}).pipe(Effect.map((found) => found.some(Boolean)));
|
|
507
|
-
const ascendToWorkspace = Effect.gen(function* () {
|
|
508
|
-
const chain = yield* Walker.ascend(realCwd);
|
|
509
|
-
const found = yield* Walker.findUpward(chain, (dir) => [path.join(dir, WORKSPACE_MANIFEST)]);
|
|
510
|
-
if (Option.isNone(found)) return void 0;
|
|
511
|
-
const file = found.value;
|
|
512
|
-
const source = yield* read(file);
|
|
513
|
-
if (source === void 0) return void 0;
|
|
514
|
-
const relative = path.relative(path.dirname(file), realCwd).split(path.sep).join("/");
|
|
515
|
-
if (relative === "" || !(yield* hasProjectManifest(realCwd))) return source;
|
|
516
|
-
const mapping = yield* Effect.fromResult(mappingOf(source));
|
|
517
|
-
const packages = Object.hasOwn(mapping, "packages") ? mapping.packages : void 0;
|
|
518
|
-
return (yield* Effect.fromResult(isWorkspaceMember(relative, packages))) ? source : void 0;
|
|
519
|
-
});
|
|
520
|
-
const workspaceFile = workspaceDir !== void 0 ? path.join(path.resolve(cwd, workspaceDir), WORKSPACE_MANIFEST) : void 0;
|
|
521
|
-
const workspace = workspaceFile === void 0 ? yield* ascendToWorkspace : yield* read(workspaceFile);
|
|
522
|
-
const xdg = firstEnv(env, ["XDG_CONFIG_HOME"]);
|
|
523
|
-
const localAppData = firstEnv(env, ["LOCALAPPDATA"]);
|
|
524
|
-
const configDir = options.globalConfigDir ?? (xdg !== void 0 ? path.join(xdg, "pnpm") : options.platform === "win32" && localAppData !== void 0 ? path.join(localAppData, "pnpm", "config") : home === void 0 ? void 0 : options.platform === "darwin" ? path.join(home, "Library", "Preferences", "pnpm") : path.join(home, ".config", "pnpm"));
|
|
525
|
-
const globalFile = configDir === void 0 ? void 0 : path.join(configDir, "config.yaml");
|
|
526
|
-
const global = globalFile === void 0 || globalFile === workspace?.path ? void 0 : yield* read(globalFile);
|
|
527
|
-
return yield* Effect.fromResult(PnpmSettings.fromSourcesResult({
|
|
528
|
-
workspace,
|
|
529
|
-
global,
|
|
530
|
-
env
|
|
531
|
-
}));
|
|
532
|
-
});
|
|
533
|
-
};
|
|
534
|
-
|
|
535
|
-
export { PnpmSettings, PnpmSettingsError };
|
package/internal/peerPatterns.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { ReleaseAgeGate } from "@effected/npm";
|
|
2
|
-
|
|
3
|
-
// src/internal/peerPatterns.ts
|
|
4
|
-
/** One pattern (negation stripped) as a predicate, on the shared single-pattern grammar. */
|
|
5
|
-
const matcherFromPattern = (pattern) => (name) => ReleaseAgeGate.matchesExclude(name, [pattern]);
|
|
6
|
-
const isNegation = (pattern) => pattern.startsWith("!");
|
|
7
|
-
/**
|
|
8
|
-
* Compile one `ignoreMissing` / `allowAny` list into a predicate over peer
|
|
9
|
-
* names, with `@pnpm/matcher`'s composition rules (see the module header).
|
|
10
|
-
*
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
const peerNameMatcher = (patterns) => {
|
|
14
|
-
if (patterns.length === 0) return () => false;
|
|
15
|
-
const compiled = patterns.map((pattern) => isNegation(pattern) ? {
|
|
16
|
-
negation: true,
|
|
17
|
-
match: matcherFromPattern(pattern.slice(1))
|
|
18
|
-
} : {
|
|
19
|
-
negation: false,
|
|
20
|
-
match: matcherFromPattern(pattern)
|
|
21
|
-
});
|
|
22
|
-
const negations = compiled.filter((entry) => entry.negation);
|
|
23
|
-
if (negations.length === 0) return (name) => compiled.some((entry) => entry.match(name));
|
|
24
|
-
if (negations.length === compiled.length) return (name) => !negations.some((entry) => entry.match(name));
|
|
25
|
-
return (name) => {
|
|
26
|
-
let matched = false;
|
|
27
|
-
for (const entry of compiled) if (entry.negation) {
|
|
28
|
-
if (entry.match(name)) matched = false;
|
|
29
|
-
} else if (!matched && entry.match(name)) matched = true;
|
|
30
|
-
return matched;
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export { peerNameMatcher };
|