@metreeca/rack 0.4.0 → 0.6.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 +3 -0
- package/dist/node/index.d.ts +3 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +38 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/symlinks.d.ts +54 -0
- package/dist/node/symlinks.d.ts.map +1 -0
- package/dist/node/symlinks.js +134 -0
- package/dist/node/symlinks.js.map +1 -0
- package/dist/symlinks.d.ts +49 -0
- package/dist/symlinks.d.ts.map +1 -0
- package/dist/symlinks.js +107 -0
- package/dist/symlinks.js.map +1 -0
- package/dist/tool/cp.d.ts +7 -3
- package/dist/tool/cp.d.ts.map +1 -1
- package/dist/tool/cp.js +9 -8
- package/dist/tool/cp.js.map +1 -1
- package/dist/tool/index.core.d.ts +8 -6
- package/dist/tool/index.core.d.ts.map +1 -1
- package/dist/tool/index.core.js +11 -7
- package/dist/tool/index.core.js.map +1 -1
- package/dist/tool/index.d.ts +5 -23
- package/dist/tool/index.d.ts.map +1 -1
- package/dist/tool/index.js +47 -13
- package/dist/tool/index.js.map +1 -1
- package/dist/tool/ln.d.ts +19 -10
- package/dist/tool/ln.d.ts.map +1 -1
- package/dist/tool/ln.js +26 -34
- package/dist/tool/ln.js.map +1 -1
- package/dist/tool/rm.d.ts +8 -4
- package/dist/tool/rm.d.ts.map +1 -1
- package/dist/tool/rm.js +10 -9
- package/dist/tool/rm.js.map +1 -1
- package/dist/vite/symlinks.d.ts +9 -5
- package/dist/vite/symlinks.d.ts.map +1 -1
- package/dist/vite/symlinks.js +19 -34
- package/dist/vite/symlinks.js.map +1 -1
- package/package.json +9 -8
package/dist/tool/index.d.ts
CHANGED
|
@@ -1,24 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* Every tool lists the paths it acts on to stdout, one per line, so that a script log shows what changed on disk. It
|
|
8
|
-
* prints its usage with `--help`, and exits with a non-zero status after printing an error message to stderr.
|
|
9
|
-
*
|
|
10
|
-
* | Command | Purpose |
|
|
11
|
-
* |---------------------------------------|--------------------------------------------------------------------------|
|
|
12
|
-
* | {@link cp `cp <target> <pattern>...`} | Copies files matching glob patterns to a directory, keeping their layout |
|
|
13
|
-
* | {@link rm `rm <pattern>...`} | Removes files and directories matching glob patterns, with their content |
|
|
14
|
-
* | {@link ln `ln [<deps>]...`} | Links dependencies to their local checkouts instead of registry releases |
|
|
15
|
-
*
|
|
16
|
-
* Build scripts can call the same tools as functions, passing the command operands as arguments: a function throws on
|
|
17
|
-
* failure instead of printing an error message to stderr and setting a non-zero exit status for the process.
|
|
18
|
-
*
|
|
19
|
-
* @module
|
|
20
|
-
*/
|
|
21
|
-
export { cp } from "./cp.js";
|
|
22
|
-
export { ln } from "./ln.js";
|
|
23
|
-
export { rm } from "./rm.js";
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { cp } from "./cp.js";
|
|
3
|
+
import { ln } from "./ln.js";
|
|
4
|
+
import { rm } from "./rm.js";
|
|
5
|
+
export { cp, ln, rm };
|
|
24
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/tool/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tool/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tool/index.ts"],"names":[],"mappings":";AAoCA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,OAAO,EACN,EAAE,EACF,EAAE,EACF,EAAE,EACF,CAAC"}
|
package/dist/tool/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
/*
|
|
2
3
|
* Copyright © 2026 Metreeca srl
|
|
3
4
|
*
|
|
@@ -16,24 +17,57 @@
|
|
|
16
17
|
/**
|
|
17
18
|
* Unix-like command line tools for npm package scripts.
|
|
18
19
|
*
|
|
19
|
-
* Each tool
|
|
20
|
-
*
|
|
20
|
+
* Each tool runs as a subcommand of the `ush` command installed with the package, as in `ush <tool> <operand>...`.
|
|
21
|
+
* Tools behave the same on every platform and shell, and leave system commands with the same name untouched.
|
|
22
|
+
* `ush --help` lists the available tools, and `ush <tool> --help` prints the usage of a single tool.
|
|
21
23
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* | Command | Purpose |
|
|
26
|
-
* |---------------------------------------|--------------------------------------------------------------------------|
|
|
27
|
-
* | {@link cp `cp <target> <pattern>...`} | Copies files matching glob patterns to a directory, keeping their layout |
|
|
28
|
-
* | {@link rm `rm <pattern>...`} | Removes files and directories matching glob patterns, with their content |
|
|
29
|
-
* | {@link ln `ln [<deps>]...`} | Links dependencies to their local checkouts instead of registry releases |
|
|
24
|
+
* Tools list the paths they act on to stdout, one per line prefixed with the tool name, so that a script log shows
|
|
25
|
+
* what changed on disk and which command changed it. A failing tool exits with a non-zero status after printing an
|
|
26
|
+
* error message to stderr, prefixed with its full command so that the log points to the command that failed.
|
|
30
27
|
*
|
|
31
28
|
* Build scripts can call the same tools as functions, passing the command operands as arguments: a function throws on
|
|
32
29
|
* failure instead of printing an error message to stderr and setting a non-zero exit status for the process.
|
|
33
30
|
*
|
|
34
31
|
* @module
|
|
35
32
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
import { parse } from "node:path";
|
|
34
|
+
import { cp } from "./cp.js";
|
|
35
|
+
import { cli } from "./index.core.js";
|
|
36
|
+
import { ln } from "./ln.js";
|
|
37
|
+
import { rm } from "./rm.js";
|
|
38
|
+
export { cp, ln, rm };
|
|
39
|
+
const commands = [
|
|
40
|
+
cp,
|
|
41
|
+
ln,
|
|
42
|
+
rm
|
|
43
|
+
];
|
|
44
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
45
|
+
if (import.meta.main) {
|
|
46
|
+
process.exitCode = ush();
|
|
47
|
+
}
|
|
48
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
49
|
+
/**
|
|
50
|
+
* Runs the tool named on a command line, as in `ush rm dist`, with GNU-style help and error messages.
|
|
51
|
+
*
|
|
52
|
+
* `ush --help` lists every tool with its operands, and `ush <tool> --help` prints the usage of a single tool. Messages
|
|
53
|
+
* are prefixed with the command as invoked, as in `ush cp: missing target operand`, and messages about a malformed
|
|
54
|
+
* command line also point to the help of the command that received it, either `ush --help` or `ush <tool> --help`.
|
|
55
|
+
*
|
|
56
|
+
* @param args The script path, followed by the tool name and its operands; defaults to the process command line
|
|
57
|
+
*
|
|
58
|
+
* @returns The process exit status: `0` on success, `1` on failure
|
|
59
|
+
*/
|
|
60
|
+
function ush([path, name, ...operands] = process.argv.slice(1)) {
|
|
61
|
+
const program = parse(path).name;
|
|
62
|
+
const command = commands.find(tool => tool.name === name);
|
|
63
|
+
return command
|
|
64
|
+
? cli(command, command.usage, `${program} ${name}`, operands)
|
|
65
|
+
: cli(reject, "<command> [<operand>]...", program, name === undefined ? [] : [name, ...operands], listing());
|
|
66
|
+
function listing() {
|
|
67
|
+
return ["Commands:", ...commands.map(tool => ` ${tool.name} ${tool.usage}`)].join("\n");
|
|
68
|
+
}
|
|
69
|
+
function reject(operand) {
|
|
70
|
+
throw new TypeError(operand === undefined ? "missing command operand" : `unknown command <${operand}>`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
39
73
|
//# sourceMappingURL=index.js.map
|
package/dist/tool/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tool/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":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,EAAE,GAAG,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IAG9G,SAAS,OAAO;QACf,OAAO,CAAC,WAAW,EAAE,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1F,CAAC;IAED,SAAS,MAAM,CAAC,OAAgB;QAC/B,MAAM,IAAI,SAAS,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,oBAAoB,OAAO,GAAG,CAAC,CAAC;IACzG,CAAC;AAEF,CAAC"}
|
package/dist/tool/ln.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
/**
|
|
3
2
|
* Links the local checkouts of the dependencies of the package in the current folder into its `node_modules`.
|
|
4
3
|
*
|
|
4
|
+
* Runs on the command line as `ush ln [<deps>]...`.
|
|
5
|
+
*
|
|
5
6
|
* The current package, and in a monorepo each of its workspace members, then builds and runs against the working
|
|
6
7
|
* trees of its dependencies instead of their registry releases. Dependencies are matched to checkouts by package name.
|
|
7
8
|
*
|
|
@@ -11,32 +12,37 @@
|
|
|
11
12
|
* `optionalDependencies` of the current package or its members. Each linked package then brings in the checkouts
|
|
12
13
|
* named in its own `dependencies`, `peerDependencies` or `optionalDependencies`. A package shared along the chain
|
|
13
14
|
* is thus loaded once from its working tree, never also as a registry copy with distinct classes and symbols
|
|
14
|
-
* - **Copies**: installed copies of a linked package
|
|
15
|
-
*
|
|
15
|
+
* - **Copies**: installed copies of a linked package nested at any depth in the current package, and in a monorepo
|
|
16
|
+
* in its workspace members, are replaced with links, so that no registry copy is loaded next to the working tree
|
|
16
17
|
* - **Commands**: the `bin` commands of each linked package are linked into the `.bin` folder next to it and made
|
|
17
18
|
* executable, so that npm scripts run the working tree version of a command rather than its registry release
|
|
18
19
|
* - **Precedence**: where a name is found in more than one folder, the folder listed first wins
|
|
19
20
|
* - **Versions**: version ranges are ignored, as a working tree may carry a version that is not released yet
|
|
20
21
|
*
|
|
21
|
-
* Links replace whatever the current package has installed under the same name
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* Links replace whatever the current package has installed under the same name, and nothing outside the current
|
|
23
|
+
* package is touched: a linked checkout keeps resolving its own dependencies and peers from its own `node_modules`,
|
|
24
|
+
* as settled by its own setup, so that an install in one checkout never changes what another project loads, and a
|
|
25
|
+
* checkout shared by several projects serves all of them alike. Projects load a single copy of the packages a linked
|
|
26
|
+
* checkout shares with them through the `symlinks` hooks of `@metreeca/rack/node` when running under Node, and
|
|
27
|
+
* through the `symlinks` plugin of `@metreeca/rack/vite` when running under Vite or Vitest.
|
|
28
|
+
* Missing folders are skipped, so the same command runs unchanged on every machine, including machines where some of
|
|
29
|
+
* the named folders hold no local checkouts at all and the package runs against its registry dependencies.
|
|
24
30
|
*
|
|
25
|
-
* Each package link is printed on stdout
|
|
26
|
-
* to `bin` commands are created silently, since they follow from the package links already listed.
|
|
31
|
+
* Each package link is printed on stdout relative to the current package, as in `ln node_modules/@scope/name`;
|
|
32
|
+
* links to `bin` commands are created silently, since they follow from the package links already listed above.
|
|
27
33
|
*
|
|
28
34
|
* @example
|
|
29
35
|
*
|
|
30
36
|
* Linking the sibling checkouts of a package after a clean install, from an npm script:
|
|
31
37
|
*
|
|
32
38
|
* ```shell
|
|
33
|
-
* npm ci && ln
|
|
39
|
+
* npm ci && ush ln
|
|
34
40
|
* ```
|
|
35
41
|
*
|
|
36
42
|
* Linking from a folder of local dependencies elsewhere:
|
|
37
43
|
*
|
|
38
44
|
* ```shell
|
|
39
|
-
* npm ci && ln ~/Metreeca/Packages
|
|
45
|
+
* npm ci && ush ln ~/Metreeca/Packages
|
|
40
46
|
* ```
|
|
41
47
|
*
|
|
42
48
|
* @param deps The folders searched for local dependencies, in order of precedence; defaults to the parent folder (`..`)
|
|
@@ -44,4 +50,7 @@
|
|
|
44
50
|
* @throws Error If the current folder holds no `package.json`
|
|
45
51
|
*/
|
|
46
52
|
export declare function ln(...deps: readonly string[]): void;
|
|
53
|
+
export declare namespace ln {
|
|
54
|
+
var usage: string;
|
|
55
|
+
}
|
|
47
56
|
//# sourceMappingURL=ln.d.ts.map
|
package/dist/tool/ln.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ln.d.ts","sourceRoot":"","sources":["../../src/tool/ln.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"ln.d.ts","sourceRoot":"","sources":["../../src/tool/ln.ts"],"names":[],"mappings":"AAwCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,EAAE,CAAC,GAAG,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CA0JnD;yBA1Je,EAAE"}
|
package/dist/tool/ln.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
/*
|
|
3
2
|
* Copyright © 2026 Metreeca srl
|
|
4
3
|
*
|
|
@@ -14,16 +13,19 @@
|
|
|
14
13
|
* See the License for the specific language governing permissions and
|
|
15
14
|
* limitations under the License.
|
|
16
15
|
*/
|
|
17
|
-
import { chmodSync, existsSync, globSync, lstatSync, mkdirSync, readdirSync,
|
|
18
|
-
import { dirname, join,
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
import { chmodSync, existsSync, globSync, lstatSync, mkdirSync, readdirSync, realpathSync, rmSync, statSync, symlinkSync } from "node:fs";
|
|
17
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
18
|
+
import { manifest } from "../symlinks.js";
|
|
19
|
+
/**
|
|
20
|
+
* The command line synopsis of {@link ln}, printed by `ush ln --help`.
|
|
21
|
+
*/
|
|
22
|
+
ln.usage = "[<deps>]...";
|
|
23
23
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
24
24
|
/**
|
|
25
25
|
* Links the local checkouts of the dependencies of the package in the current folder into its `node_modules`.
|
|
26
26
|
*
|
|
27
|
+
* Runs on the command line as `ush ln [<deps>]...`.
|
|
28
|
+
*
|
|
27
29
|
* The current package, and in a monorepo each of its workspace members, then builds and runs against the working
|
|
28
30
|
* trees of its dependencies instead of their registry releases. Dependencies are matched to checkouts by package name.
|
|
29
31
|
*
|
|
@@ -33,32 +35,37 @@ if (import.meta.main) {
|
|
|
33
35
|
* `optionalDependencies` of the current package or its members. Each linked package then brings in the checkouts
|
|
34
36
|
* named in its own `dependencies`, `peerDependencies` or `optionalDependencies`. A package shared along the chain
|
|
35
37
|
* is thus loaded once from its working tree, never also as a registry copy with distinct classes and symbols
|
|
36
|
-
* - **Copies**: installed copies of a linked package
|
|
37
|
-
*
|
|
38
|
+
* - **Copies**: installed copies of a linked package nested at any depth in the current package, and in a monorepo
|
|
39
|
+
* in its workspace members, are replaced with links, so that no registry copy is loaded next to the working tree
|
|
38
40
|
* - **Commands**: the `bin` commands of each linked package are linked into the `.bin` folder next to it and made
|
|
39
41
|
* executable, so that npm scripts run the working tree version of a command rather than its registry release
|
|
40
42
|
* - **Precedence**: where a name is found in more than one folder, the folder listed first wins
|
|
41
43
|
* - **Versions**: version ranges are ignored, as a working tree may carry a version that is not released yet
|
|
42
44
|
*
|
|
43
|
-
* Links replace whatever the current package has installed under the same name
|
|
44
|
-
*
|
|
45
|
-
*
|
|
45
|
+
* Links replace whatever the current package has installed under the same name, and nothing outside the current
|
|
46
|
+
* package is touched: a linked checkout keeps resolving its own dependencies and peers from its own `node_modules`,
|
|
47
|
+
* as settled by its own setup, so that an install in one checkout never changes what another project loads, and a
|
|
48
|
+
* checkout shared by several projects serves all of them alike. Projects load a single copy of the packages a linked
|
|
49
|
+
* checkout shares with them through the `symlinks` hooks of `@metreeca/rack/node` when running under Node, and
|
|
50
|
+
* through the `symlinks` plugin of `@metreeca/rack/vite` when running under Vite or Vitest.
|
|
51
|
+
* Missing folders are skipped, so the same command runs unchanged on every machine, including machines where some of
|
|
52
|
+
* the named folders hold no local checkouts at all and the package runs against its registry dependencies.
|
|
46
53
|
*
|
|
47
|
-
* Each package link is printed on stdout
|
|
48
|
-
* to `bin` commands are created silently, since they follow from the package links already listed.
|
|
54
|
+
* Each package link is printed on stdout relative to the current package, as in `ln node_modules/@scope/name`;
|
|
55
|
+
* links to `bin` commands are created silently, since they follow from the package links already listed above.
|
|
49
56
|
*
|
|
50
57
|
* @example
|
|
51
58
|
*
|
|
52
59
|
* Linking the sibling checkouts of a package after a clean install, from an npm script:
|
|
53
60
|
*
|
|
54
61
|
* ```shell
|
|
55
|
-
* npm ci && ln
|
|
62
|
+
* npm ci && ush ln
|
|
56
63
|
* ```
|
|
57
64
|
*
|
|
58
65
|
* Linking from a folder of local dependencies elsewhere:
|
|
59
66
|
*
|
|
60
67
|
* ```shell
|
|
61
|
-
* npm ci && ln ~/Metreeca/Packages
|
|
68
|
+
* npm ci && ush ln ~/Metreeca/Packages
|
|
62
69
|
* ```
|
|
63
70
|
*
|
|
64
71
|
* @param deps The folders searched for local dependencies, in order of precedence; defaults to the parent folder (`..`)
|
|
@@ -84,16 +91,14 @@ export function ln(...deps) {
|
|
|
84
91
|
.reverse() // later entries override earlier ones, so that the folder listed first wins
|
|
85
92
|
);
|
|
86
93
|
const linked = closure(own.flatMap(path => dependencies(path, true)));
|
|
87
|
-
const roots = new Set([home, ...[...linked.values()].map(path => checkout(path))]);
|
|
88
94
|
linked.forEach((path, name) => link({ modules: join(home, "node_modules"), name, path }));
|
|
89
|
-
|
|
90
|
-
.flatMap(packages)
|
|
95
|
+
own
|
|
91
96
|
.flatMap(path => copies(join(path, "node_modules")))
|
|
92
97
|
.forEach(link);
|
|
93
98
|
function link({ modules, name, path }) {
|
|
94
99
|
const target = join(modules, name);
|
|
95
100
|
replace(target, path);
|
|
96
|
-
console.log(relative(home, target));
|
|
101
|
+
console.log(`ln ${relative(home, target)}`);
|
|
97
102
|
commands(path, name).forEach(([command, script]) => {
|
|
98
103
|
replace(join(modules, ".bin", command), join(target, script));
|
|
99
104
|
if (existsSync(join(path, script))) {
|
|
@@ -129,7 +134,7 @@ export function ln(...deps) {
|
|
|
129
134
|
}];
|
|
130
135
|
}
|
|
131
136
|
else if (lstatSync(copy).isSymbolicLink()) {
|
|
132
|
-
return []; // a link into
|
|
137
|
+
return []; // a link into a checkout, whose own setup settles its copies
|
|
133
138
|
}
|
|
134
139
|
else {
|
|
135
140
|
return copies(join(copy, "node_modules"));
|
|
@@ -143,16 +148,6 @@ export function ln(...deps) {
|
|
|
143
148
|
.filter(member => existsSync(join(member, "package.json")))
|
|
144
149
|
] : [];
|
|
145
150
|
}
|
|
146
|
-
function checkout(path) {
|
|
147
|
-
const parent = ancestors(path).find(ancestor => existsSync(join(ancestor, "package.json")));
|
|
148
|
-
return parent !== undefined && packages(parent).includes(path) ? parent : path;
|
|
149
|
-
}
|
|
150
|
-
function ancestors(path) {
|
|
151
|
-
const { root } = parse(path);
|
|
152
|
-
return relative(root, dirname(path)).split(sep).filter(Boolean)
|
|
153
|
-
.map((_, index, segments) => join(root, ...segments.slice(0, index + 1)))
|
|
154
|
-
.reverse();
|
|
155
|
-
}
|
|
156
151
|
function children(path) {
|
|
157
152
|
return folder(path) ? readdirSync(path) : [];
|
|
158
153
|
}
|
|
@@ -177,8 +172,5 @@ export function ln(...deps) {
|
|
|
177
172
|
...optionalDependencies
|
|
178
173
|
});
|
|
179
174
|
}
|
|
180
|
-
function manifest(path) {
|
|
181
|
-
return JSON.parse(readFileSync(join(path, "package.json"), "utf8")); // trusted local file, not validated
|
|
182
|
-
}
|
|
183
175
|
}
|
|
184
176
|
//# sourceMappingURL=ln.js.map
|
package/dist/tool/ln.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ln.js","sourceRoot":"","sources":["../../src/tool/ln.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E,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAEtE,CAAC,CAAC,CAAC,CAAC;QAEJ,OAAO,KAAK,CAAC,IAAI;YAChB,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;YAClG,CAAC,CAAC,MAAM,CAAC;IAEX,CAAC;IAED,SAAS,YAAY,CAAC,IAAY,EAAE,MAAe,KAAK;QAEvD,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEjG,OAAO,MAAM,CAAC,IAAI,CAAC;YAElB,GAAG,YAAY;YACf,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;YAC/B,GAAG,gBAAgB;YACnB,GAAG,oBAAoB;SAEvB,CAAC,CAAC;IAEJ,CAAC;AAEF,CAAC"}
|
package/dist/tool/rm.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
/**
|
|
3
2
|
* Removes the files and directories matching a set of glob patterns, with their whole content.
|
|
4
3
|
*
|
|
4
|
+
* Runs on the command line as `ush rm <pattern>...`.
|
|
5
|
+
*
|
|
5
6
|
* Patterns matching nothing are ignored, so that the same command can run again on an already clean tree.
|
|
6
7
|
*
|
|
7
|
-
* Each removed file or directory is printed on stdout once
|
|
8
|
-
* directory are not listed, even where a pattern selects them explicitly
|
|
8
|
+
* Each removed file or directory is printed on stdout once as `rm <path>`, relative to the current folder. Matches
|
|
9
|
+
* inside a removed directory go along with it and are not listed, even where a pattern selects them explicitly.
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
11
12
|
*
|
|
12
13
|
* Removing build outputs, from an npm script:
|
|
13
14
|
*
|
|
14
15
|
* ```shell
|
|
15
|
-
* rm dist docs 'src/**\/*.tsbuildinfo'
|
|
16
|
+
* ush rm dist docs 'src/**\/*.tsbuildinfo'
|
|
16
17
|
* ```
|
|
17
18
|
*
|
|
18
19
|
* Patterns are quoted so that they reach the tool unexpanded, as shells differ in their glob support.
|
|
@@ -22,4 +23,7 @@
|
|
|
22
23
|
* @throws TypeError If no pattern is provided
|
|
23
24
|
*/
|
|
24
25
|
export declare function rm(...patterns: readonly string[]): void;
|
|
26
|
+
export declare namespace rm {
|
|
27
|
+
var usage: string;
|
|
28
|
+
}
|
|
25
29
|
//# sourceMappingURL=rm.d.ts.map
|
package/dist/tool/rm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rm.d.ts","sourceRoot":"","sources":["../../src/tool/rm.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"rm.d.ts","sourceRoot":"","sources":["../../src/tool/rm.ts"],"names":[],"mappings":"AA4BA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,EAAE,CAAC,GAAG,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAcvD;yBAde,EAAE"}
|
package/dist/tool/rm.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
/*
|
|
3
2
|
* Copyright © 2026 Metreeca srl
|
|
4
3
|
*
|
|
@@ -16,25 +15,27 @@
|
|
|
16
15
|
*/
|
|
17
16
|
import { globSync, rmSync } from "node:fs";
|
|
18
17
|
import { relative, resolve, sep } from "node:path";
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
/**
|
|
19
|
+
* The command line synopsis of {@link rm}, printed by `ush rm --help`.
|
|
20
|
+
*/
|
|
21
|
+
rm.usage = "<pattern>...";
|
|
23
22
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
24
23
|
/**
|
|
25
24
|
* Removes the files and directories matching a set of glob patterns, with their whole content.
|
|
26
25
|
*
|
|
26
|
+
* Runs on the command line as `ush rm <pattern>...`.
|
|
27
|
+
*
|
|
27
28
|
* Patterns matching nothing are ignored, so that the same command can run again on an already clean tree.
|
|
28
29
|
*
|
|
29
|
-
* Each removed file or directory is printed on stdout once
|
|
30
|
-
* directory are not listed, even where a pattern selects them explicitly
|
|
30
|
+
* Each removed file or directory is printed on stdout once as `rm <path>`, relative to the current folder. Matches
|
|
31
|
+
* inside a removed directory go along with it and are not listed, even where a pattern selects them explicitly.
|
|
31
32
|
*
|
|
32
33
|
* @example
|
|
33
34
|
*
|
|
34
35
|
* Removing build outputs, from an npm script:
|
|
35
36
|
*
|
|
36
37
|
* ```shell
|
|
37
|
-
* rm dist docs 'src/**\/*.tsbuildinfo'
|
|
38
|
+
* ush rm dist docs 'src/**\/*.tsbuildinfo'
|
|
38
39
|
* ```
|
|
39
40
|
*
|
|
40
41
|
* Patterns are quoted so that they reach the tool unexpanded, as shells differ in their glob support.
|
|
@@ -51,7 +52,7 @@ export function rm(...patterns) {
|
|
|
51
52
|
const paths = matches.filter(path => !matches.some(match => path.startsWith(match + sep))); // gone with ancestors
|
|
52
53
|
paths.forEach(path => {
|
|
53
54
|
rmSync(path, { recursive: true, force: true });
|
|
54
|
-
console.log(relative(".", path));
|
|
55
|
+
console.log(`rm ${relative(".", path)}`);
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
58
|
//# sourceMappingURL=rm.js.map
|
package/dist/tool/rm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rm.js","sourceRoot":"","sources":["../../src/tool/rm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rm.js","sourceRoot":"","sources":["../../src/tool/rm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAA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er up through its ancestors, so
|
|
9
9
|
* links hoisted to a workspace root are found from any member; imports with no importer start from the Vite root.
|
|
10
|
+
* A package the importer resolves to an installed copy is looked up again from the Vite root, so a linked checkout
|
|
11
|
+
* importing a package the project links as well loads the linked source rather than its own registry copy.
|
|
10
12
|
*
|
|
11
|
-
* The
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* The project and its linked packages load a single copy of every linked package and of each of their
|
|
14
|
+
* `peerDependencies`, as libraries holding module state such as Preact hooks require: the links found in the
|
|
15
|
+
* `node_modules` of the Vite root, of its ancestors and of its workspace members extend `resolve.dedupe`, so that
|
|
16
|
+
* those packages always resolve from the project, dependencies prebundled by the optimizer included, whatever copies
|
|
17
|
+
* a linked checkout installs. Other dependencies of a linked package resolve from its checkout, as Node does.
|
|
15
18
|
*
|
|
16
19
|
* The plugin replaces `resolve.conditions`, which breaks registry packages whose exports name a condition without
|
|
17
20
|
* publishing its target: Vite does not fall back to `default` when that target is missing from the installed files.
|
|
@@ -41,7 +44,8 @@ import type { Plugin } from "vite";
|
|
|
41
44
|
*
|
|
42
45
|
* @param options The resolution settings
|
|
43
46
|
*
|
|
44
|
-
* @returns A plugin resolving linked imports to source
|
|
47
|
+
* @returns A plugin resolving linked imports to source, deduplicating linked packages and their peers, and leaving all
|
|
48
|
+
* other imports to the default resolution
|
|
45
49
|
*/
|
|
46
50
|
export declare function symlinks({ conditions }: {
|
|
47
51
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"symlinks.d.ts","sourceRoot":"","sources":["../../src/vite/symlinks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"symlinks.d.ts","sourceRoot":"","sources":["../../src/vite/symlinks.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAInC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,QAAQ,CAAC,EAExB,UAAU,EAEV,EAAE;IAEF;;;OAGG;IACH,UAAU,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAA;CAEtC,GAAG,MAAM,CA6CT"}
|
package/dist/vite/symlinks.js
CHANGED
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import { dirname, isAbsolute, join, resolve, sep } from "node:path";
|
|
16
|
+
import { realpathSync } from "node:fs";
|
|
17
|
+
import { dirname, isAbsolute, resolve } from "node:path";
|
|
19
18
|
import { exports } from "resolve.exports";
|
|
19
|
+
import { bare, lookup, manifest, shared } from "../symlinks.js";
|
|
20
20
|
/**
|
|
21
21
|
* Creates a plugin running tests against the live source of locally linked packages, with no rebuild.
|
|
22
22
|
*
|
|
@@ -25,11 +25,14 @@ import { exports } from "resolve.exports";
|
|
|
25
25
|
*
|
|
26
26
|
* Packages are looked up as Node does, from the `node_modules` nearest to the importer up through its ancestors, so
|
|
27
27
|
* links hoisted to a workspace root are found from any member; imports with no importer start from the Vite root.
|
|
28
|
+
* A package the importer resolves to an installed copy is looked up again from the Vite root, so a linked checkout
|
|
29
|
+
* importing a package the project links as well loads the linked source rather than its own registry copy.
|
|
28
30
|
*
|
|
29
|
-
* The
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* The project and its linked packages load a single copy of every linked package and of each of their
|
|
32
|
+
* `peerDependencies`, as libraries holding module state such as Preact hooks require: the links found in the
|
|
33
|
+
* `node_modules` of the Vite root, of its ancestors and of its workspace members extend `resolve.dedupe`, so that
|
|
34
|
+
* those packages always resolve from the project, dependencies prebundled by the optimizer included, whatever copies
|
|
35
|
+
* a linked checkout installs. Other dependencies of a linked package resolve from its checkout, as Node does.
|
|
33
36
|
*
|
|
34
37
|
* The plugin replaces `resolve.conditions`, which breaks registry packages whose exports name a condition without
|
|
35
38
|
* publishing its target: Vite does not fall back to `default` when that target is missing from the installed files.
|
|
@@ -59,20 +62,22 @@ import { exports } from "resolve.exports";
|
|
|
59
62
|
*
|
|
60
63
|
* @param options The resolution settings
|
|
61
64
|
*
|
|
62
|
-
* @returns A plugin resolving linked imports to source
|
|
65
|
+
* @returns A plugin resolving linked imports to source, deduplicating linked packages and their peers, and leaving all
|
|
66
|
+
* other imports to the default resolution
|
|
63
67
|
*/
|
|
64
68
|
export function symlinks({ conditions }) {
|
|
65
69
|
const $conditions = typeof conditions === "string" ? [conditions] : conditions;
|
|
66
|
-
const manifests = new Map(); // memoised by link real path, also tracking the peers to share
|
|
67
70
|
return {
|
|
68
71
|
name: "symlinks",
|
|
69
72
|
enforce: "pre",
|
|
70
|
-
|
|
73
|
+
config({ root }) {
|
|
74
|
+
return { resolve: { dedupe: [...shared(resolve(root ?? ""))] } };
|
|
75
|
+
},
|
|
76
|
+
resolveId(id, importer) {
|
|
71
77
|
const root = this.environment.config.root;
|
|
72
|
-
const name = id
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
const link = name && lookup(name, base);
|
|
78
|
+
const name = bare(id);
|
|
79
|
+
const base = importer && isAbsolute(importer) ? dirname(importer) : root;
|
|
80
|
+
const link = name && (lookup(name, base) ?? lookup(name, root));
|
|
76
81
|
if (link) {
|
|
77
82
|
try {
|
|
78
83
|
const path = realpathSync(link);
|
|
@@ -83,30 +88,10 @@ export function symlinks({ conditions }) {
|
|
|
83
88
|
return null;
|
|
84
89
|
}
|
|
85
90
|
}
|
|
86
|
-
else if (peer) { // falls back to the default resolution if missing from the project
|
|
87
|
-
return this.resolve(id, join(root, "package.json"), { ...options, skipSelf: true });
|
|
88
|
-
}
|
|
89
91
|
else {
|
|
90
92
|
return null;
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
95
|
};
|
|
94
|
-
function lookup(name, directory) {
|
|
95
|
-
const path = (createRequire(join(directory, sep)).resolve.paths(name) ?? [])
|
|
96
|
-
.map(modules => join(modules, name))
|
|
97
|
-
.find(candidate => lstatSync(candidate, { throwIfNoEntry: false }));
|
|
98
|
-
return path !== undefined && lstatSync(path).isSymbolicLink() ? path : undefined;
|
|
99
|
-
}
|
|
100
|
-
function manifest(path) {
|
|
101
|
-
const cached = manifests.get(path);
|
|
102
|
-
if (cached === undefined) {
|
|
103
|
-
const loaded = JSON.parse(readFileSync(join(path, "package.json"), "utf8"));
|
|
104
|
-
manifests.set(path, loaded);
|
|
105
|
-
return loaded;
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
return cached;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
96
|
}
|
|
112
97
|
//# sourceMappingURL=symlinks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"symlinks.js","sourceRoot":"","sources":["../../src/vite/symlinks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"symlinks.js","sourceRoot":"","sources":["../../src/vite/symlinks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,UAAU,QAAQ,CAAC,EAExB,UAAU,EAUV;IAEA,MAAM,WAAW,GAAG,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IAE/E,OAAO;QAEN,IAAI,EAAE,UAAU;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