create-kerf-component 5.0.0-beta.17 → 5.0.0-beta.18
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 +1 -1
- package/index.js +12 -2
- package/package.json +1 -1
- package/template/README.md +8 -8
- package/template/package.json +1 -1
- package/template/src/counter.tsx +4 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ directory's basename is used as the package name.
|
|
|
20
20
|
## What you get
|
|
21
21
|
|
|
22
22
|
A ready-to-publish component package that encodes the rules from the kerf docs
|
|
23
|
-
(
|
|
23
|
+
(_Building reusable component packages_):
|
|
24
24
|
|
|
25
25
|
- **`kerfjs` as a `peerDependency`, `external` in the tsup build** — never
|
|
26
26
|
bundled, so `isSafeHtml` brand checks and signal identity stay intact across
|
package/index.js
CHANGED
|
@@ -17,7 +17,15 @@
|
|
|
17
17
|
// kerf-component` alone just works. No third-party dependencies — the
|
|
18
18
|
// initializer is plain Node so `npm create` runs it with zero install latency.
|
|
19
19
|
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
cpSync,
|
|
22
|
+
existsSync,
|
|
23
|
+
mkdirSync,
|
|
24
|
+
readdirSync,
|
|
25
|
+
readFileSync,
|
|
26
|
+
renameSync,
|
|
27
|
+
writeFileSync,
|
|
28
|
+
} from 'node:fs';
|
|
21
29
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
22
30
|
import { createInterface } from 'node:readline/promises';
|
|
23
31
|
import { fileURLToPath } from 'node:url';
|
|
@@ -41,7 +49,9 @@ const USAGE =
|
|
|
41
49
|
async function promptForTarget() {
|
|
42
50
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
43
51
|
try {
|
|
44
|
-
const answer = await rl.question(
|
|
52
|
+
const answer = await rl.question(
|
|
53
|
+
`Directory (\`.\` for current) [${DEFAULT_NAME}]: `,
|
|
54
|
+
);
|
|
45
55
|
return answer.trim() || DEFAULT_NAME;
|
|
46
56
|
} finally {
|
|
47
57
|
rl.close();
|
package/package.json
CHANGED
package/template/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# **PKG_NAME**
|
|
2
2
|
|
|
3
3
|
A reusable [kerf](https://github.com/brianwestphal/kerf) component package,
|
|
4
4
|
scaffolded with `create-kerf-component`.
|
|
@@ -7,7 +7,7 @@ scaffolded with `create-kerf-component`.
|
|
|
7
7
|
|
|
8
8
|
```bash
|
|
9
9
|
npm install
|
|
10
|
-
npm run build
|
|
10
|
+
npm run build # tsup → dist/ (ESM + .d.ts); kerfjs stays external
|
|
11
11
|
npm run typecheck
|
|
12
12
|
```
|
|
13
13
|
|
|
@@ -17,11 +17,11 @@ A kerf app that already has `jsxImportSource: "kerfjs"` configured can import an
|
|
|
17
17
|
render the component like any local function — there's no extra toolchain:
|
|
18
18
|
|
|
19
19
|
```tsx
|
|
20
|
-
import { mount } from
|
|
21
|
-
import { Counter, createCounter, wireCounter } from
|
|
20
|
+
import { mount } from "kerfjs";
|
|
21
|
+
import { Counter, createCounter, wireCounter } from "__PKG_NAME__";
|
|
22
22
|
|
|
23
|
-
const counter = createCounter(0);
|
|
24
|
-
const root = document.getElementById(
|
|
23
|
+
const counter = createCounter(0); // per-instance state (a factory)
|
|
24
|
+
const root = document.getElementById("app")!;
|
|
25
25
|
|
|
26
26
|
mount(root, () => <Counter store={counter} label="Clicks" />);
|
|
27
27
|
|
|
@@ -31,7 +31,7 @@ const dispose = wireCounter(root, counter); // delegation disposer (call on tear
|
|
|
31
31
|
## The rules this package follows
|
|
32
32
|
|
|
33
33
|
These are kerf's hard packaging rules (see the kerf docs,
|
|
34
|
-
|
|
34
|
+
_Building reusable component packages_). The scaffold encodes them so you don't
|
|
35
35
|
have to:
|
|
36
36
|
|
|
37
37
|
- **`kerfjs` is a `peerDependency` and is `external` in the build — never
|
|
@@ -45,7 +45,7 @@ have to:
|
|
|
45
45
|
`delegate()` (see `wireCounter`), which returns a disposer.
|
|
46
46
|
- **Build emits ESM + `.d.ts`; `tsconfig` sets `jsxImportSource: "kerfjs"`.**
|
|
47
47
|
- **Never import `kerfjs/dev`.** kerf's dev diagnostics install global hooks, so
|
|
48
|
-
installing them is the consuming
|
|
48
|
+
installing them is the consuming _app's_ call, not a library's — the app
|
|
49
49
|
writes `if (import.meta.env.DEV) await import('kerfjs/dev')` in its own entry.
|
|
50
50
|
To get the diagnostics while developing this package, add that line to your own
|
|
51
51
|
test harness or demo page instead (it belongs to the harness, not to `src/`).
|
package/template/package.json
CHANGED
package/template/src/counter.tsx
CHANGED
|
@@ -61,7 +61,10 @@ export function Counter({ store, label = 'Count' }: CounterProps): SafeHtml {
|
|
|
61
61
|
* single listener survives every re-render. Returns the disposer `delegate()`
|
|
62
62
|
* hands back — call it when the host unmounts.
|
|
63
63
|
*/
|
|
64
|
-
export function wireCounter(
|
|
64
|
+
export function wireCounter(
|
|
65
|
+
root: HTMLElement,
|
|
66
|
+
store: CounterStore,
|
|
67
|
+
): () => void {
|
|
65
68
|
return delegate(root, 'click', '[data-action^="counter:"]', (_event, el) => {
|
|
66
69
|
const action = el.getAttribute('data-action');
|
|
67
70
|
if (action === 'counter:inc') store.actions.inc();
|