rolldown-pnpm-config 0.1.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/LICENSE +21 -0
- package/README.md +127 -0
- package/bin/rolldown-pnpm-config.js +21 -0
- package/catalogs.js +27 -0
- package/cli/commands/export.js +118 -0
- package/cli/commands/preview.js +73 -0
- package/cli/commands/upgrade.js +437 -0
- package/cli/diff/build.js +122 -0
- package/cli/diff/render.js +103 -0
- package/cli/discover.js +128 -0
- package/cli/drift.js +22 -0
- package/cli/edits.js +41 -0
- package/cli/effective.js +42 -0
- package/cli/evaluate.js +91 -0
- package/cli/interop.js +285 -0
- package/cli/local-merge.js +75 -0
- package/cli/peer-range.js +34 -0
- package/cli/plan.js +66 -0
- package/cli/preview-views.js +34 -0
- package/cli/release-age.js +74 -0
- package/cli/resolve.js +109 -0
- package/cli/rewrite.js +22 -0
- package/cli/select-file.js +64 -0
- package/cli/summary.js +137 -0
- package/cli/ui/Preview.js +60 -0
- package/cli/ui/Walk.js +55 -0
- package/cli/ui/ansi.js +20 -0
- package/cli/ui/env.js +20 -0
- package/cli/ui/run-preview.js +23 -0
- package/cli/ui/run-walk.js +29 -0
- package/cli/ui/styled.js +27 -0
- package/cli/walk-plan.js +35 -0
- package/cli/walk-reducer.js +61 -0
- package/cli/workspace-file.js +58 -0
- package/cli/workspace-overlay.js +21 -0
- package/descriptors/build.js +248 -0
- package/descriptors/hoisting.js +175 -0
- package/descriptors/index.js +38 -0
- package/descriptors/lockfile.js +117 -0
- package/descriptors/misc.js +144 -0
- package/descriptors/network.js +108 -0
- package/descriptors/resolution.js +250 -0
- package/descriptors/runtime-cfg.js +90 -0
- package/descriptors/schemas.js +26 -0
- package/descriptors/workspace.js +116 -0
- package/index.d.ts +363 -0
- package/index.js +3 -0
- package/package.json +60 -0
- package/plugin/freeze.js +79 -0
- package/plugin/index.js +48 -0
- package/plugin/serialize.js +26 -0
- package/registry.js +8 -0
- package/runtime/ctx.js +39 -0
- package/runtime/enforcement.js +36 -0
- package/runtime/strategies/arrays.js +37 -0
- package/runtime/strategies/catalogs.js +36 -0
- package/runtime/strategies/maps.js +46 -0
- package/runtime/strategies/overrides.js +57 -0
- package/runtime/strategies/scalar.js +57 -0
- package/runtime/strategies/table.js +27 -0
- package/runtime/warnings.js +61 -0
- package/runtime.d.ts +111 -0
- package/runtime.js +54 -0
- package/tsdoc-metadata.json +11 -0
- package/virtual.d.ts +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 C. Spencer Beggs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# rolldown-pnpm-config
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/rolldown-pnpm-config)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://nodejs.org/)
|
|
6
|
+
|
|
7
|
+
A rolldown plugin whose output is a pnpm config-dependency `pnpmfile`. You author your catalogs and pnpm settings as one declarative config. Run a build and you get a self-contained `pnpmfile.mjs`. pnpm 11 loads it and calls its `updateConfig` hook to merge your settings into a consuming repo.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -D rolldown-pnpm-config rolldown
|
|
13
|
+
# or
|
|
14
|
+
pnpm add -D rolldown-pnpm-config rolldown
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The build runs on Node.js. The emitted `pnpmfile.mjs` targets pnpm 11 in the consuming repo — the pnpm version that loads `.mjs` pnpmfiles.
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
A vanilla rolldown setup is three files: the config you author, a build entry that re-exports the runtime hooks and a rolldown config that runs the plugin.
|
|
22
|
+
|
|
23
|
+
Author your catalogs and pnpm settings as a plain `PluginConfig` object. The `name` field is required — use the npm name of the config package itself; it tags runtime warnings as `[<name>]` so consuming repos know which config dependency is speaking:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import type { PluginConfig } from "rolldown-pnpm-config";
|
|
27
|
+
|
|
28
|
+
export const plugin = {
|
|
29
|
+
name: "@acme/pnpm-config",
|
|
30
|
+
catalogs: {
|
|
31
|
+
default: { packages: { typescript: "^5.9.0", vitest: "^4.0.0" } },
|
|
32
|
+
},
|
|
33
|
+
overrides: { "tar@<6.2.1": ">=6.2.1" },
|
|
34
|
+
publicHoistPattern: ["@types/*"],
|
|
35
|
+
allowBuilds: { esbuild: true },
|
|
36
|
+
strictDepBuilds: true,
|
|
37
|
+
minimumReleaseAge: { value: 1440, enforcement: "warn" },
|
|
38
|
+
confirmModulesPurge: false,
|
|
39
|
+
} satisfies PluginConfig;
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Add a build entry that re-exports the runtime `hooks` from the plugin's virtual pnpmfile module. The reference directive pulls in the package's shipped virtual-module types, so the import type-checks with no hand-written declaration. Save it as `src/pnpmfile.ts`:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
/// <reference types="rolldown-pnpm-config/virtual" />
|
|
46
|
+
export { hooks } from "rolldown-pnpm-config/virtual/pnpmfile";
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Run `PnpmConfigPlugin` over your authored config and point rolldown at the build entry:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { defineConfig } from "rolldown";
|
|
53
|
+
import { PnpmConfigPlugin } from "rolldown-pnpm-config";
|
|
54
|
+
import { plugin } from "./pnpm-config.js"; // the config above, saved as pnpm-config.ts
|
|
55
|
+
|
|
56
|
+
export default defineConfig({
|
|
57
|
+
input: "src/pnpmfile.ts",
|
|
58
|
+
// the emitted pnpmfile runs under Node, so target node — externalizes node: builtins
|
|
59
|
+
platform: "node",
|
|
60
|
+
output: { file: "pnpmfile.mjs", format: "esm" },
|
|
61
|
+
plugins: [PnpmConfigPlugin(plugin)],
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Build it:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npx rolldown -c
|
|
69
|
+
# writes a self-contained pnpmfile.mjs to the project root
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The output pulls in only Node's own builtins, so pnpm can load it without any `node_modules` present. Ship it as a pnpm config dependency and pnpm 11 calls its `updateConfig` hook to merge your settings into the consuming repo.
|
|
73
|
+
|
|
74
|
+
## Keeping catalogs current
|
|
75
|
+
|
|
76
|
+
The bundled `rolldown-pnpm-config upgrade` command rewrites the version ranges in your config file in place. Run it with no arguments and it autodetects the config — the single top-level `.ts` file in the current directory that calls `PnpmConfigPlugin(...)`:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npx rolldown-pnpm-config upgrade
|
|
80
|
+
# walks each catalog package, then:
|
|
81
|
+
# Applied <n> change(s).
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The walk is interactive by default. `--yes` takes the latest in-range version without prompting, `--dry-run` prints the planned changes without writing and `--catalog <name>` restricts the walk to one catalog. Pass `--preview` for a non-interactive projection of what the walk would do, with `--full` to show the full tree without context collapsing. The output is colorized in a supporting terminal. For packages that declare a `strategy`, the command also resyncs their materialized peer range. See [upgrading catalogs](https://github.com/spencerbeggs/rolldown-pnpm-config/blob/main/docs/05-upgrading-catalogs.md) for the full surface.
|
|
85
|
+
|
|
86
|
+
## Exporting to pnpm-workspace.yaml
|
|
87
|
+
|
|
88
|
+
For repos that develop the plugin itself and cannot consume it as a config dependency, `rolldown-pnpm-config export` materializes the managed config directly into `pnpm-workspace.yaml`. Pass `--dry-run` to print a colored canonical diff without writing; add `--full` to emit the entire tree rather than changed lines with context. `file:`, `link:`, `workspace:` and `portal:` overrides already present in the file are preserved by default on every run.
|
|
89
|
+
|
|
90
|
+
The `rolldown-pnpm-config preview` command opens an interactive tabbed view — Changes, Full and Simulated — without writing anything. In a non-interactive terminal it falls back to printing the Changes diff, so it is safe to run in CI.
|
|
91
|
+
|
|
92
|
+
The optional `local` field on `PluginConfig` adjusts managed settings for this repo's export only — the built pnpmfile and its runtime behavior are unaffected. A bare value overwrites the managed value; the directive form merges it:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
local: {
|
|
96
|
+
// union: add local patterns on top of the managed list
|
|
97
|
+
publicHoistPattern: { strategy: "union", value: ["@acme/*"] },
|
|
98
|
+
// difference: drop one managed override entry
|
|
99
|
+
overrides: { strategy: "difference", value: { "lodash@<4.17.21": ">=4.17.21" } },
|
|
100
|
+
// bare value: overwrite the managed field entirely
|
|
101
|
+
strictDepBuilds: false,
|
|
102
|
+
},
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`publicHoistPattern` also accepts `excludeByRepo` — a map keyed by consuming repo name — to drop specific patterns when the config runs in a named repo:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
publicHoistPattern: {
|
|
109
|
+
value: ["@types/*", "@acme/cli"],
|
|
110
|
+
excludeByRepo: { "consumer-a": ["@acme/cli"] },
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
See [exporting to pnpm-workspace.yaml](https://github.com/spencerbeggs/rolldown-pnpm-config/blob/main/docs/06-exporting.md) for the full surface.
|
|
115
|
+
|
|
116
|
+
## Documentation
|
|
117
|
+
|
|
118
|
+
- [Getting started](https://github.com/spencerbeggs/rolldown-pnpm-config/blob/main/docs/01-getting-started.md) — Wire the plugin into a vanilla rolldown build and emit a pnpmfile.
|
|
119
|
+
- [Using @savvy-web/bundler](https://github.com/spencerbeggs/rolldown-pnpm-config/blob/main/docs/02-savvy-bundler.md) — The same plugin with the build wiring done for you, emitting both `.mjs` and `.cjs`.
|
|
120
|
+
- [Concepts](https://github.com/spencerbeggs/rolldown-pnpm-config/blob/main/docs/03-concepts.md) — What the emitted pnpmfile does: config dependencies, catalogs and the enforcement model.
|
|
121
|
+
- [pnpm settings coverage](https://github.com/spencerbeggs/rolldown-pnpm-config/blob/main/docs/04-pnpm-settings-coverage.md) — Every pnpm-workspace.yaml setting the plugin manages and the ones it leaves to each consumer.
|
|
122
|
+
- [Upgrading catalogs](https://github.com/spencerbeggs/rolldown-pnpm-config/blob/main/docs/05-upgrading-catalogs.md) — The `upgrade` CLI that rewrites catalog version ranges in place.
|
|
123
|
+
- [Exporting to pnpm-workspace.yaml](https://github.com/spencerbeggs/rolldown-pnpm-config/blob/main/docs/06-exporting.md) — The `export` and `preview` CLI, the `local` merge directive and per-repo `excludeByRepo` filtering.
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { exportCommand } from "../cli/commands/export.js";
|
|
3
|
+
import { previewCommand } from "../cli/commands/preview.js";
|
|
4
|
+
import { upgradeCommand } from "../cli/commands/upgrade.js";
|
|
5
|
+
import { Effect } from "effect";
|
|
6
|
+
import { Command } from "@effect/cli";
|
|
7
|
+
import { NodeContext, NodeRuntime } from "@effect/platform-node";
|
|
8
|
+
|
|
9
|
+
//#region src/cli/bin.ts
|
|
10
|
+
const root = Command.make("rolldown-pnpm-config").pipe(Command.withSubcommands([
|
|
11
|
+
upgradeCommand,
|
|
12
|
+
exportCommand,
|
|
13
|
+
previewCommand
|
|
14
|
+
]));
|
|
15
|
+
Command.run(root, {
|
|
16
|
+
name: "rolldown-pnpm-config",
|
|
17
|
+
version: "0.1.0"
|
|
18
|
+
})(process.argv).pipe(Effect.provide(NodeContext.layer), NodeRuntime.runMain);
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { };
|
package/catalogs.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/catalogs.ts
|
|
2
|
+
/**
|
|
3
|
+
* Normalize declarative catalog input into the resolved `{ catalog → pkg → range }`
|
|
4
|
+
* map consumed by the runtime. Pure: the base catalog uses each package's
|
|
5
|
+
* `range` (or bare string); a `<name>Peers` catalog is emitted only for packages
|
|
6
|
+
* carrying a materialized `peer`, using that value verbatim. `strategy` is
|
|
7
|
+
* CLI-only and ignored here.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
function normalizeCatalogs(input) {
|
|
12
|
+
const out = {};
|
|
13
|
+
for (const [name, decl] of Object.entries(input)) {
|
|
14
|
+
const base = {};
|
|
15
|
+
const peers = {};
|
|
16
|
+
for (const [pkg, spec] of Object.entries(decl.packages)) {
|
|
17
|
+
base[pkg] = typeof spec === "string" ? spec : spec.range;
|
|
18
|
+
if (typeof spec === "object" && spec.peer !== void 0) peers[pkg] = spec.peer;
|
|
19
|
+
}
|
|
20
|
+
out[name] = base;
|
|
21
|
+
if (Object.keys(peers).length > 0) out[`${name}Peers`] = peers;
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { normalizeCatalogs };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { DESCRIPTORS } from "../../descriptors/index.js";
|
|
2
|
+
import { freeze } from "../../plugin/freeze.js";
|
|
3
|
+
import { resolveRootName } from "../../runtime/ctx.js";
|
|
4
|
+
import { buildDiff } from "../diff/build.js";
|
|
5
|
+
import { renderExportDiff } from "../diff/render.js";
|
|
6
|
+
import { effectiveManaged } from "../effective.js";
|
|
7
|
+
import { evaluatePluginConfig } from "../evaluate.js";
|
|
8
|
+
import { findConfigFiles, pickConfigCandidate } from "../select-file.js";
|
|
9
|
+
import { toAnsi } from "../ui/ansi.js";
|
|
10
|
+
import { detectCapabilities } from "../ui/env.js";
|
|
11
|
+
import { canonicalize, findWorkspaceFile, parseWorkspace, renderWorkspace } from "../workspace-file.js";
|
|
12
|
+
import { overlayWorkspace } from "../workspace-overlay.js";
|
|
13
|
+
import { Data, Effect, Option } from "effect";
|
|
14
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { dirname, join } from "node:path";
|
|
16
|
+
import { Args, Command, Options } from "@effect/cli";
|
|
17
|
+
|
|
18
|
+
//#region src/cli/commands/export.ts
|
|
19
|
+
/**
|
|
20
|
+
* Typed failure raised when the export run cannot complete.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
var ExportError = class extends Data.TaggedError("ExportError") {};
|
|
25
|
+
/**
|
|
26
|
+
* The set of pnpm config keys that belong in pnpm-workspace.yaml
|
|
27
|
+
* (i.e. descriptors with `workspaceYaml: true`).
|
|
28
|
+
*
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
const WORKSPACE_FIELDS = new Set(Object.entries(DESCRIPTORS).filter(([, d]) => d.workspaceYaml).map(([k]) => k));
|
|
32
|
+
/**
|
|
33
|
+
* Export core: freeze the plugin config first, then apply excludeByRepo and
|
|
34
|
+
* local directives via the effective pipeline, overlay onto the existing
|
|
35
|
+
* pnpm-workspace.yaml (or create fresh), and write the result. In preview
|
|
36
|
+
* mode nothing is written.
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
function runExport(opts) {
|
|
41
|
+
return Effect.gen(function* () {
|
|
42
|
+
const { config, errors } = evaluatePluginConfig(yield* Effect.try({
|
|
43
|
+
try: () => readFileSync(opts.configFile, "utf8"),
|
|
44
|
+
catch: () => new ExportError({ message: `Cannot read ${opts.configFile}` })
|
|
45
|
+
}), opts.configFile);
|
|
46
|
+
if (config === null) return yield* Effect.fail(new ExportError({ message: `No PnpmConfigPlugin call found in ${opts.configFile}` }));
|
|
47
|
+
if (errors.length > 0) return yield* Effect.fail(new ExportError({ message: `Non-literal config values: ${errors.join("; ")}` }));
|
|
48
|
+
const { base, manifest } = yield* freeze(config).pipe(Effect.mapError((e) => new ExportError({ message: e.message })));
|
|
49
|
+
const managed = {};
|
|
50
|
+
for (const [k, v] of Object.entries(base)) if (WORKSPACE_FIELDS.has(k)) managed[k] = v;
|
|
51
|
+
const path = opts.workspacePath ?? findWorkspaceFile(process.cwd()) ?? join(process.cwd(), "pnpm-workspace.yaml");
|
|
52
|
+
const parsed = existsSync(path) ? yield* Effect.try({
|
|
53
|
+
try: () => parseWorkspace(readFileSync(path, "utf8")),
|
|
54
|
+
catch: (e) => new ExportError({ message: `Cannot read or parse ${path}: ${String(e)}` })
|
|
55
|
+
}) : {};
|
|
56
|
+
const rootName = resolveRootName({ dir: dirname(path) });
|
|
57
|
+
const merged = overlayWorkspace(effectiveManaged(managed, config.local && typeof config.local === "object" ? config.local : void 0, parsed, manifest, rootName), parsed);
|
|
58
|
+
const rendered = renderWorkspace(merged);
|
|
59
|
+
const localKeys = new Set(config.local && typeof config.local === "object" ? Object.keys(config.local) : []);
|
|
60
|
+
const diff = renderExportDiff(buildDiff(canonicalize(parsed), canonicalize(merged), {
|
|
61
|
+
localKeys,
|
|
62
|
+
managedKeys: WORKSPACE_FIELDS
|
|
63
|
+
}), { full: opts.full ?? false });
|
|
64
|
+
if (opts.preview) return {
|
|
65
|
+
path,
|
|
66
|
+
rendered,
|
|
67
|
+
written: false,
|
|
68
|
+
diff
|
|
69
|
+
};
|
|
70
|
+
yield* Effect.try({
|
|
71
|
+
try: () => writeFileSync(path, rendered, "utf8"),
|
|
72
|
+
catch: () => new ExportError({ message: `Cannot write ${path}` })
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
path,
|
|
76
|
+
rendered,
|
|
77
|
+
written: true,
|
|
78
|
+
diff
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const pathArg = Args.file({ name: "path" }).pipe(Args.optional);
|
|
83
|
+
const dryRunFlag = Options.boolean("dry-run").pipe(Options.withDefault(false));
|
|
84
|
+
const fullFlag = Options.boolean("full").pipe(Options.withDefault(false));
|
|
85
|
+
/**
|
|
86
|
+
* The "export" command. Materializes the plugin config into pnpm-workspace.yaml.
|
|
87
|
+
* An optional path argument overrides the auto-detected workspace file. --dry-run
|
|
88
|
+
* prints the colored diff to stdout without writing. --full disables context
|
|
89
|
+
* collapsing in the diff output.
|
|
90
|
+
*
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
const exportCommand = Command.make("export", {
|
|
94
|
+
path: pathArg,
|
|
95
|
+
dryRun: dryRunFlag,
|
|
96
|
+
full: fullFlag
|
|
97
|
+
}, ({ path, dryRun, full }) => Effect.gen(function* () {
|
|
98
|
+
const picked = pickConfigCandidate(yield* findConfigFiles(process.cwd()));
|
|
99
|
+
if (!picked.ok) return yield* Effect.fail(new ExportError({ message: picked.message }));
|
|
100
|
+
const workspacePath = Option.getOrUndefined(path);
|
|
101
|
+
const result = yield* runExport({
|
|
102
|
+
configFile: picked.file,
|
|
103
|
+
...workspacePath !== void 0 ? { workspacePath } : {},
|
|
104
|
+
preview: dryRun,
|
|
105
|
+
full
|
|
106
|
+
});
|
|
107
|
+
yield* Effect.sync(() => {
|
|
108
|
+
if (dryRun) {
|
|
109
|
+
const caps = detectCapabilities();
|
|
110
|
+
process.stdout.write(`${result.path} (dry run — not written)\n\n`);
|
|
111
|
+
process.stdout.write(`${toAnsi(result.diff, { color: caps.color })}\n`);
|
|
112
|
+
process.stdout.write("\n+ added ~ changed - removed (local) local override (unmanaged) not managed\n");
|
|
113
|
+
} else process.stdout.write(`Exported to ${result.path}\n`);
|
|
114
|
+
});
|
|
115
|
+
})).pipe(Command.withDescription("Materialize the plugin config into pnpm-workspace.yaml (--dry-run to preview)"));
|
|
116
|
+
|
|
117
|
+
//#endregion
|
|
118
|
+
export { ExportError, WORKSPACE_FIELDS, exportCommand, runExport };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { freeze } from "../../plugin/freeze.js";
|
|
2
|
+
import { resolveRootName } from "../../runtime/ctx.js";
|
|
3
|
+
import { evaluatePluginConfig } from "../evaluate.js";
|
|
4
|
+
import { findConfigFiles, pickConfigCandidate } from "../select-file.js";
|
|
5
|
+
import { toAnsi } from "../ui/ansi.js";
|
|
6
|
+
import { detectCapabilities } from "../ui/env.js";
|
|
7
|
+
import { findWorkspaceFile, parseWorkspace } from "../workspace-file.js";
|
|
8
|
+
import { WORKSPACE_FIELDS } from "./export.js";
|
|
9
|
+
import { buildPreviewViews } from "../preview-views.js";
|
|
10
|
+
import { runPreview } from "../ui/run-preview.js";
|
|
11
|
+
import { Data, Effect, Option } from "effect";
|
|
12
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
13
|
+
import { dirname, join } from "node:path";
|
|
14
|
+
import { Args, Command } from "@effect/cli";
|
|
15
|
+
|
|
16
|
+
//#region src/cli/commands/preview.ts
|
|
17
|
+
/** Typed failure for the preview run. @internal */
|
|
18
|
+
var PreviewError = class extends Data.TaggedError("PreviewError") {};
|
|
19
|
+
/**
|
|
20
|
+
* Build the three preview views from a config + workspace file. Pure of any
|
|
21
|
+
* terminal interaction; the command wraps this with interactive/non-TTY output.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
function runPreviewViews(opts) {
|
|
26
|
+
return Effect.gen(function* () {
|
|
27
|
+
const { config, errors } = evaluatePluginConfig(yield* Effect.try({
|
|
28
|
+
try: () => readFileSync(opts.configFile, "utf8"),
|
|
29
|
+
catch: () => new PreviewError({ message: `Cannot read ${opts.configFile}` })
|
|
30
|
+
}), opts.configFile);
|
|
31
|
+
if (config === null) return yield* Effect.fail(new PreviewError({ message: `No PnpmConfigPlugin call found in ${opts.configFile}` }));
|
|
32
|
+
if (errors.length > 0) return yield* Effect.fail(new PreviewError({ message: `Non-literal config values: ${errors.join("; ")}` }));
|
|
33
|
+
const { base, manifest } = yield* freeze(config).pipe(Effect.mapError((e) => new PreviewError({ message: e.message })));
|
|
34
|
+
const managed = {};
|
|
35
|
+
for (const [k, v] of Object.entries(base)) if (WORKSPACE_FIELDS.has(k)) managed[k] = v;
|
|
36
|
+
const path = opts.workspacePath ?? findWorkspaceFile(process.cwd()) ?? join(process.cwd(), "pnpm-workspace.yaml");
|
|
37
|
+
const parsed = existsSync(path) ? yield* Effect.try({
|
|
38
|
+
try: () => parseWorkspace(readFileSync(path, "utf8")),
|
|
39
|
+
catch: (e) => new PreviewError({ message: `Cannot read or parse ${path}: ${String(e)}` })
|
|
40
|
+
}) : {};
|
|
41
|
+
const localCfg = config.local && typeof config.local === "object" ? config.local : void 0;
|
|
42
|
+
return buildPreviewViews({
|
|
43
|
+
managed,
|
|
44
|
+
...localCfg ? { local: localCfg } : {},
|
|
45
|
+
parsed,
|
|
46
|
+
manifest,
|
|
47
|
+
rootName: resolveRootName({ dir: dirname(path) })
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const pathArg = Args.file({ name: "path" }).pipe(Args.optional);
|
|
52
|
+
/**
|
|
53
|
+
* The "preview" command: interactive ink-tab explorer of the export diff
|
|
54
|
+
* (Changes / Full / Simulated). Falls back to printing the Changes view when
|
|
55
|
+
* the terminal is non-interactive.
|
|
56
|
+
*
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
const previewCommand = Command.make("preview", { path: pathArg }, ({ path }) => Effect.gen(function* () {
|
|
60
|
+
const picked = pickConfigCandidate(yield* findConfigFiles(process.cwd()));
|
|
61
|
+
if (!picked.ok) return yield* Effect.fail(new PreviewError({ message: picked.message }));
|
|
62
|
+
const workspacePath = Option.getOrUndefined(path);
|
|
63
|
+
const views = yield* runPreviewViews({
|
|
64
|
+
configFile: picked.file,
|
|
65
|
+
...workspacePath !== void 0 ? { workspacePath } : {}
|
|
66
|
+
});
|
|
67
|
+
const caps = detectCapabilities();
|
|
68
|
+
if (caps.interactive) yield* runPreview(views);
|
|
69
|
+
else yield* Effect.sync(() => process.stdout.write(`${toAnsi(views.changes, { color: caps.color })}\n`));
|
|
70
|
+
})).pipe(Command.withDescription("Interactively preview how pnpm-workspace.yaml would change"));
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
export { PreviewError, previewCommand, runPreviewViews };
|