@twobirds/microcomponents 0.13.1 → 0.13.3
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/dist/cli/dev.d.ts +2 -1
- package/dist/cli/dev.d.ts.map +1 -1
- package/dist/cli/dispatch.d.ts +27 -1
- package/dist/cli/dispatch.d.ts.map +1 -1
- package/dist/cli/index.js +48 -13
- package/dist/docs/cli.d.ts +4 -2
- package/dist/docs/cli.d.ts.map +1 -1
- package/dist/mcp/api.json +1 -1
- package/package.json +1 -1
package/dist/cli/dev.d.ts
CHANGED
|
@@ -79,7 +79,8 @@ export declare function createDevServer(projectRoot: string, options: {
|
|
|
79
79
|
}): Server;
|
|
80
80
|
/**
|
|
81
81
|
* CLI entry for `mc dev`: mirror companions, start the server, and run `tsc -w`
|
|
82
|
-
* for the lifetime of the process.
|
|
82
|
+
* for the lifetime of the process. The watch runs with `--preserveWatchOutput`, so
|
|
83
|
+
* the screen is not cleared on each rebuild and the printed server URL stays visible.
|
|
83
84
|
*
|
|
84
85
|
* @param projectRoot Project root (defaults to the current directory).
|
|
85
86
|
* @param minJs Path of `microcomponents.min.js` (defaults to this package's `dist/`).
|
package/dist/cli/dev.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/cli/dev.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAsC,KAAK,MAAM,EAAuB,MAAM,WAAW,CAAC;AASjG;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO5C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAO/F;AAkCD;;;;;;;;;;;;GAYG;AACH,wBAAsB,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18,12 +18,38 @@ export type Runner = (script: string, options?: {
|
|
|
18
18
|
/** Asks the user to confirm a namespace long enough to be worth a second look. */
|
|
19
19
|
export type Confirmer = (namespace: string) => Promise<boolean>;
|
|
20
20
|
/**
|
|
21
|
+
Whether `mc <command>` runs the project's package.json script or the CLI's own
|
|
22
|
+
implementation.
|
|
23
|
+
|
|
24
|
+
A script that is a thin wrapper around the same command must not be delegated:
|
|
25
|
+
`mc dev` would spawn `pnpm run dev`, which runs `mc dev`, which spawns
|
|
26
|
+
`pnpm run dev`, forever. The scaffold writes exactly that shape (`"dev": "mc dev"`,
|
|
27
|
+
`"preview": "mc preview"`), so this guard is what keeps `pnpm dev` in a scaffolded
|
|
28
|
+
project from looping.
|
|
29
|
+
|
|
30
|
+
@example
|
|
31
|
+
```ts
|
|
32
|
+
scriptTarget('mc dev', 'dev'); // 'self'
|
|
33
|
+
scriptTarget('mc dev --port 5173', 'dev'); // 'self'
|
|
34
|
+
scriptTarget('npx mc preview', 'preview'); // 'self'
|
|
35
|
+
scriptTarget('vite preview --outDir build', 'dev'); // 'delegate'
|
|
36
|
+
scriptTarget('tsc -p tsconfig.json && mc bundle', 'bundle'); // 'delegate'
|
|
37
|
+
scriptTarget(undefined, 'clean'); // 'self'
|
|
38
|
+
```
|
|
39
|
+
@param body - The script body, or `undefined` when the project declares no such script.
|
|
40
|
+
@param command - The `mc` command being run.
|
|
41
|
+
@returns `'delegate'` to run the project script, `'self'` to run the CLI's implementation.
|
|
42
|
+
*/
|
|
43
|
+
export declare function scriptTarget(body: string | undefined, command: string): 'delegate' | 'self';
|
|
44
|
+
/**
|
|
21
45
|
Runs a package.json script through pnpm and resolves with its exit code.
|
|
22
46
|
|
|
23
47
|
Thin wrappers like `clean` and `check` delegate here so the script — not the
|
|
24
48
|
CLI — remains the single source of truth for what each command does. If the
|
|
25
49
|
current project defines no such script, the CLI runs its own implementation
|
|
26
|
-
against the current project, so the command works in any consumer project.
|
|
50
|
+
against the current project, so the command works in any consumer project. A script
|
|
51
|
+
that is a thin wrapper around the command itself is not delegated, because
|
|
52
|
+
delegating makes the CLI run itself forever — see {@link scriptTarget}.
|
|
27
53
|
|
|
28
54
|
@example
|
|
29
55
|
```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../src/cli/dispatch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;EAYE;AAwEF,MAAM,MAAM,MAAM,GAAG,CACpB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KACtC,OAAO,CAAC,MAAM,CAAC,CAAC;AAErB,kFAAkF;AAClF,MAAM,MAAM,SAAS,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../src/cli/dispatch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;EAYE;AAwEF,MAAM,MAAM,MAAM,GAAG,CACpB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KACtC,OAAO,CAAC,MAAM,CAAC,CAAC;AAErB,kFAAkF;AAClF,MAAM,MAAM,SAAS,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAgFhE;;;;;;;;;;;;;;;;;;;;;;EAsBE;AACF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAQ3F;AAgED;;;;;;;;;;;;;;EAcE;AACF,wBAAsB,SAAS,CAC9B,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GACxC,OAAO,CAAC,MAAM,CAAC,CAajB;AAED;;;;;;;;;;;;;;;;;;;;EAoBE;AACF,wBAAsB,IAAI,CACzB,IAAI,EAAE,MAAM,EAAE,EACd,GAAG,GAAE,MAAkB,EACvB,OAAO,GAAE,SAA4B,GACnC,OAAO,CAAC,MAAM,CAAC,CA4IjB"}
|
package/dist/cli/index.js
CHANGED
|
@@ -267,7 +267,7 @@ function packageJson(namespace) {
|
|
|
267
267
|
typecheck: "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.test.json",
|
|
268
268
|
test: "vitest run"
|
|
269
269
|
},
|
|
270
|
-
dependencies: { "@twobirds/microcomponents": "^0.13.
|
|
270
|
+
dependencies: { "@twobirds/microcomponents": "^0.13.3" },
|
|
271
271
|
devDependencies: {
|
|
272
272
|
typescript: "^6.0.3",
|
|
273
273
|
vitest: "^4.1.10",
|
|
@@ -1462,7 +1462,8 @@ function createDevServer(projectRoot, options) {
|
|
|
1462
1462
|
}
|
|
1463
1463
|
/**
|
|
1464
1464
|
* CLI entry for `mc dev`: mirror companions, start the server, and run `tsc -w`
|
|
1465
|
-
* for the lifetime of the process.
|
|
1465
|
+
* for the lifetime of the process. The watch runs with `--preserveWatchOutput`, so
|
|
1466
|
+
* the screen is not cleared on each rebuild and the printed server URL stays visible.
|
|
1466
1467
|
*
|
|
1467
1468
|
* @param projectRoot Project root (defaults to the current directory).
|
|
1468
1469
|
* @param minJs Path of `microcomponents.min.js` (defaults to this package's `dist/`).
|
|
@@ -1471,7 +1472,6 @@ function createDevServer(projectRoot, options) {
|
|
|
1471
1472
|
* not reachable off the machine. Pass an interface address to serve the LAN.
|
|
1472
1473
|
* @returns The process exit code (the server keeps running until killed).
|
|
1473
1474
|
*/
|
|
1474
|
-
/* v8 ignore start — the long-running server + tsc watch is exercised by hand, not in the suite */
|
|
1475
1475
|
async function runDev(projectRoot = process.cwd(), minJs = path.join(import.meta.dirname, "..", "microcomponents.min.js"), port = 5173, host = "127.0.0.1") {
|
|
1476
1476
|
const sourceRoot = path.join(projectRoot, "src");
|
|
1477
1477
|
const buildRoot = path.join(projectRoot, "build");
|
|
@@ -1479,6 +1479,7 @@ async function runDev(projectRoot = process.cwd(), minJs = path.join(import.meta
|
|
|
1479
1479
|
const tsc = spawn("npx", [
|
|
1480
1480
|
"tsc",
|
|
1481
1481
|
"-w",
|
|
1482
|
+
"--preserveWatchOutput",
|
|
1482
1483
|
"-p",
|
|
1483
1484
|
"tsconfig.json"
|
|
1484
1485
|
], {
|
|
@@ -1506,7 +1507,6 @@ async function runDev(projectRoot = process.cwd(), minJs = path.join(import.meta
|
|
|
1506
1507
|
});
|
|
1507
1508
|
});
|
|
1508
1509
|
}
|
|
1509
|
-
/* v8 ignore end */
|
|
1510
1510
|
//#endregion
|
|
1511
1511
|
//#region src/cli/preview.ts
|
|
1512
1512
|
/**
|
|
@@ -1721,23 +1721,56 @@ function spawnProcess(command, args, cwd) {
|
|
|
1721
1721
|
});
|
|
1722
1722
|
}
|
|
1723
1723
|
/**
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
the CLI's own implementation when the project defines no such script.
|
|
1724
|
+
The body of a package.json script in the current directory, or `undefined` when the
|
|
1725
|
+
project declares no such script. Consumers get this check so `mc clean`/`mc check`
|
|
1726
|
+
can fall back to the CLI's own implementation when the project defines no such script.
|
|
1727
1727
|
|
|
1728
1728
|
@example
|
|
1729
1729
|
```ts
|
|
1730
|
-
|
|
1730
|
+
await scriptBody('clean'); // 'rm -rf dist'
|
|
1731
|
+
await scriptBody('nope'); // undefined
|
|
1731
1732
|
```
|
|
1732
1733
|
@param script - Script name to look up.
|
|
1733
1734
|
*/
|
|
1734
|
-
async function
|
|
1735
|
+
async function scriptBody(script) {
|
|
1735
1736
|
try {
|
|
1736
|
-
|
|
1737
|
+
const body = JSON.parse(await readFile(path.join(process.cwd(), "package.json"), "utf8"))?.scripts?.[script];
|
|
1738
|
+
return typeof body === "string" ? body : void 0;
|
|
1737
1739
|
} catch {
|
|
1738
|
-
return
|
|
1740
|
+
return;
|
|
1739
1741
|
}
|
|
1740
1742
|
}
|
|
1743
|
+
/** The CLI's own bin names, so a script that wraps this command is recognized. */
|
|
1744
|
+
var SELF_BINS = /* @__PURE__ */ new Set(["mc", "microcomponents"]);
|
|
1745
|
+
/**
|
|
1746
|
+
Whether `mc <command>` runs the project's package.json script or the CLI's own
|
|
1747
|
+
implementation.
|
|
1748
|
+
|
|
1749
|
+
A script that is a thin wrapper around the same command must not be delegated:
|
|
1750
|
+
`mc dev` would spawn `pnpm run dev`, which runs `mc dev`, which spawns
|
|
1751
|
+
`pnpm run dev`, forever. The scaffold writes exactly that shape (`"dev": "mc dev"`,
|
|
1752
|
+
`"preview": "mc preview"`), so this guard is what keeps `pnpm dev` in a scaffolded
|
|
1753
|
+
project from looping.
|
|
1754
|
+
|
|
1755
|
+
@example
|
|
1756
|
+
```ts
|
|
1757
|
+
scriptTarget('mc dev', 'dev'); // 'self'
|
|
1758
|
+
scriptTarget('mc dev --port 5173', 'dev'); // 'self'
|
|
1759
|
+
scriptTarget('npx mc preview', 'preview'); // 'self'
|
|
1760
|
+
scriptTarget('vite preview --outDir build', 'dev'); // 'delegate'
|
|
1761
|
+
scriptTarget('tsc -p tsconfig.json && mc bundle', 'bundle'); // 'delegate'
|
|
1762
|
+
scriptTarget(undefined, 'clean'); // 'self'
|
|
1763
|
+
```
|
|
1764
|
+
@param body - The script body, or `undefined` when the project declares no such script.
|
|
1765
|
+
@param command - The `mc` command being run.
|
|
1766
|
+
@returns `'delegate'` to run the project script, `'self'` to run the CLI's implementation.
|
|
1767
|
+
*/
|
|
1768
|
+
function scriptTarget(body, command) {
|
|
1769
|
+
if (!body) return "self";
|
|
1770
|
+
const tokens = body.trim().split(/\s+/);
|
|
1771
|
+
while (tokens[0] === "npx" || tokens[0] === "pnpm" && tokens[1] === "exec") tokens.splice(0, tokens[0] === "npx" ? 1 : 2);
|
|
1772
|
+
return SELF_BINS.has(tokens[0]) && tokens[1] === command ? "self" : "delegate";
|
|
1773
|
+
}
|
|
1741
1774
|
/** Build artifacts to remove, relative to the project root. */
|
|
1742
1775
|
var CLEAN_DIRS = [
|
|
1743
1776
|
"dist",
|
|
@@ -1811,7 +1844,9 @@ Runs a package.json script through pnpm and resolves with its exit code.
|
|
|
1811
1844
|
Thin wrappers like `clean` and `check` delegate here so the script — not the
|
|
1812
1845
|
CLI — remains the single source of truth for what each command does. If the
|
|
1813
1846
|
current project defines no such script, the CLI runs its own implementation
|
|
1814
|
-
against the current project, so the command works in any consumer project.
|
|
1847
|
+
against the current project, so the command works in any consumer project. A script
|
|
1848
|
+
that is a thin wrapper around the command itself is not delegated, because
|
|
1849
|
+
delegating makes the CLI run itself forever — see {@link scriptTarget}.
|
|
1815
1850
|
|
|
1816
1851
|
@example
|
|
1817
1852
|
```ts
|
|
@@ -1819,7 +1854,7 @@ const code = await runScript('check');
|
|
|
1819
1854
|
```
|
|
1820
1855
|
*/
|
|
1821
1856
|
async function runScript(script, options) {
|
|
1822
|
-
if (await
|
|
1857
|
+
if (scriptTarget(await scriptBody(script), script) === "delegate") return spawnProcess("pnpm", ["run", script]);
|
|
1823
1858
|
if (script === "clean") return cleanSelf();
|
|
1824
1859
|
if (script === "check") return checkSelf();
|
|
1825
1860
|
if (script === "dev") return runDev(process.cwd(), void 0, options?.port ?? 5173, options?.host ?? "127.0.0.1");
|
package/dist/docs/cli.d.ts
CHANGED
|
@@ -57,7 +57,9 @@ on demand through `autoload()` — nothing is bundled, and a new component is pi
|
|
|
57
57
|
without restarting. The server rewrites the `@twobirds/microcomponents` specifier in the
|
|
58
58
|
JS it serves to the `/microcomponents.min.js` it answers, so the page carries no import
|
|
59
59
|
map, and it mirrors the files `tsc` does not compile — companion assets and plain `.js`
|
|
60
|
-
components — into `build/` next to the compiled component.
|
|
60
|
+
components — into `build/` next to the compiled component. The watch runs with
|
|
61
|
+
`--preserveWatchOutput`, so `tsc` does not clear the screen on each rebuild and the
|
|
62
|
+
server URL the process prints stays visible.
|
|
61
63
|
|
|
62
64
|
```sh
|
|
63
65
|
mc dev # dev server on port 5173, bound to 127.0.0.1
|
|
@@ -110,7 +112,7 @@ mc check
|
|
|
110
112
|
Reports the version of the installed library, not the version of the project it runs in.
|
|
111
113
|
|
|
112
114
|
```sh
|
|
113
|
-
mc --version # 0.13.
|
|
115
|
+
mc --version # 0.13.3
|
|
114
116
|
```
|
|
115
117
|
|
|
116
118
|
## mc --help
|
package/dist/docs/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/docs/cli.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/docs/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4HE"}
|
package/dist/mcp/api.json
CHANGED