@canonical/summon-component 0.30.0 → 0.32.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/dist/esm/lit/generator.js +37 -22
- package/dist/esm/lit/generator.js.map +1 -1
- package/dist/esm/react/generator.js +41 -25
- package/dist/esm/react/generator.js.map +1 -1
- package/dist/esm/shared/loadTemplate.js +90 -39
- package/dist/esm/shared/loadTemplate.js.map +1 -1
- package/dist/esm/shared/validateComponentPath.js +12 -1
- package/dist/esm/shared/validateComponentPath.js.map +1 -1
- package/dist/esm/svelte/generator.js +43 -28
- package/dist/esm/svelte/generator.js.map +1 -1
- package/dist/types/lit/generator.d.ts.map +1 -1
- package/dist/types/react/generator.d.ts.map +1 -1
- package/dist/types/shared/loadTemplate.d.ts +50 -4
- package/dist/types/shared/loadTemplate.d.ts.map +1 -1
- package/dist/types/shared/validateComponentPath.d.ts +5 -1
- package/dist/types/shared/validateComponentPath.d.ts.map +1 -1
- package/dist/types/svelte/generator.d.ts.map +1 -1
- package/package.json +12 -8
|
@@ -21,20 +21,34 @@ import { fileURLToPath } from "node:url";
|
|
|
21
21
|
import { template } from "@canonical/summon-core";
|
|
22
22
|
import { debug, info, mkdir, sequence_, when } from "@canonical/task";
|
|
23
23
|
import { appendExportToParentIndex, createComponentPathPrompt, createTemplateContext, getComponentName, getParentDir, PACKAGE_NAME, } from "../shared/index.js";
|
|
24
|
-
import
|
|
24
|
+
import { loadTemplateSync } from "../shared/loadTemplate.js";
|
|
25
25
|
// =============================================================================
|
|
26
|
-
// Template Paths & Content (loaded
|
|
26
|
+
// Template Paths & Content (loaded LAZILY on first generate())
|
|
27
27
|
// =============================================================================
|
|
28
28
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
29
29
|
const templatesDir = path.join(__dirname, "..", "templates");
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
/** Read every Lit template from disk (or the embedded manifest). */
|
|
31
|
+
function loadLitTemplates() {
|
|
32
|
+
return {
|
|
33
|
+
component: loadTemplateSync(path.join(templatesDir, "lit", "component.ts.ejs")),
|
|
34
|
+
index: loadTemplateSync(path.join(templatesDir, "lit", "index.ts.ejs")),
|
|
35
|
+
types: loadTemplateSync(path.join(templatesDir, "lit", "types.ts.ejs")),
|
|
36
|
+
tests: loadTemplateSync(path.join(templatesDir, "lit", "tests.ts.ejs")),
|
|
37
|
+
stories: loadTemplateSync(path.join(templatesDir, "lit", "stories.ts.ejs")),
|
|
38
|
+
styles: loadTemplateSync(path.join(templatesDir, "lit", "styles.css.ejs")),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Memoized template bundle. Loaded on the FIRST `generate()` call, never at
|
|
43
|
+
* module-eval — so importing this generator never reads a template, and a READ
|
|
44
|
+
* command (which never calls `generate()`) never touches the `.ejs` a compiled
|
|
45
|
+
* binary lacks. See the react generator for the full rationale.
|
|
46
|
+
*/
|
|
47
|
+
let litTemplatesCache;
|
|
48
|
+
function litTemplates() {
|
|
49
|
+
litTemplatesCache ??= loadLitTemplates();
|
|
50
|
+
return litTemplatesCache;
|
|
51
|
+
}
|
|
38
52
|
// =============================================================================
|
|
39
53
|
// Custom Prompts (without SSR tests)
|
|
40
54
|
// =============================================================================
|
|
@@ -96,49 +110,50 @@ with the custom element tag 'button'.`,
|
|
|
96
110
|
const componentDir = answers.componentPath;
|
|
97
111
|
const parentDir = getParentDir(answers.componentPath);
|
|
98
112
|
const ctx = createTemplateContext(answers, "lit");
|
|
113
|
+
const t = litTemplates();
|
|
99
114
|
return sequence_([
|
|
100
115
|
info(`Generating Lit web component: ${componentName}`),
|
|
101
116
|
debug("Creating component directory"),
|
|
102
117
|
mkdir(componentDir),
|
|
103
118
|
debug("Creating main component file"),
|
|
104
119
|
template({
|
|
105
|
-
source:
|
|
106
|
-
content:
|
|
120
|
+
source: t.component.source,
|
|
121
|
+
content: t.component.content,
|
|
107
122
|
dest: path.join(componentDir, `${componentName}.ts`),
|
|
108
123
|
vars: ctx,
|
|
109
124
|
}),
|
|
110
125
|
debug("Creating index barrel file"),
|
|
111
126
|
template({
|
|
112
|
-
source:
|
|
113
|
-
content:
|
|
127
|
+
source: t.index.source,
|
|
128
|
+
content: t.index.content,
|
|
114
129
|
dest: path.join(componentDir, "index.ts"),
|
|
115
130
|
vars: ctx,
|
|
116
131
|
}),
|
|
117
132
|
debug("Creating types file"),
|
|
118
133
|
template({
|
|
119
|
-
source:
|
|
120
|
-
content:
|
|
134
|
+
source: t.types.source,
|
|
135
|
+
content: t.types.content,
|
|
121
136
|
dest: path.join(componentDir, "types.ts"),
|
|
122
137
|
vars: ctx,
|
|
123
138
|
}),
|
|
124
139
|
debug("Creating test file"),
|
|
125
140
|
template({
|
|
126
|
-
source:
|
|
127
|
-
content:
|
|
141
|
+
source: t.tests.source,
|
|
142
|
+
content: t.tests.content,
|
|
128
143
|
dest: path.join(componentDir, `${componentName}.tests.ts`),
|
|
129
144
|
vars: ctx,
|
|
130
145
|
}),
|
|
131
146
|
when(answers.withStories, debug("Creating stories file")),
|
|
132
147
|
when(answers.withStories, template({
|
|
133
|
-
source:
|
|
134
|
-
content:
|
|
148
|
+
source: t.stories.source,
|
|
149
|
+
content: t.stories.content,
|
|
135
150
|
dest: path.join(componentDir, `${componentName}.stories.ts`),
|
|
136
151
|
vars: ctx,
|
|
137
152
|
})),
|
|
138
153
|
when(answers.withStyles, debug("Creating styles file")),
|
|
139
154
|
when(answers.withStyles, template({
|
|
140
|
-
source:
|
|
141
|
-
content:
|
|
155
|
+
source: t.styles.source,
|
|
156
|
+
content: t.styles.content,
|
|
142
157
|
dest: path.join(componentDir, "styles.css"),
|
|
143
158
|
vars: ctx,
|
|
144
159
|
})),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../src/lit/generator.ts"],"names":[],"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AE,GAAG;aACV,CAAC,CACH;YAED,KAAK,CAAC,sCAAsC,CAAC;YAC7C,yBAAyB,CAAC,SAAS,EAAE,aAAa,CAAC;YAEnD,IAAI,CAAC,WAAW,aAAa,iBAAiB,YAAY,EAAE,CAAC;SAC9D,CAAC,CAAC;IACL,CAAC;CACiD,CAAC;AAErD,eAAe,SAAS,CAAC"}
|
|
@@ -17,21 +17,36 @@ import { fileURLToPath } from "node:url";
|
|
|
17
17
|
import { template } from "@canonical/summon-core";
|
|
18
18
|
import { debug, info, mkdir, sequence_, when } from "@canonical/task";
|
|
19
19
|
import { appendExportToParentIndex, createComponentPathPrompt, createTemplateContext, getComponentName, getParentDir, PACKAGE_NAME, sharedPrompts, } from "../shared/index.js";
|
|
20
|
-
import
|
|
20
|
+
import { loadTemplateSync } from "../shared/loadTemplate.js";
|
|
21
21
|
// =============================================================================
|
|
22
|
-
// Template Paths & Content (loaded
|
|
22
|
+
// Template Paths & Content (loaded LAZILY on first generate())
|
|
23
23
|
// =============================================================================
|
|
24
24
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
25
25
|
const templatesDir = path.join(__dirname, "..", "templates");
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
/** Read every React template from disk (or the embedded manifest). */
|
|
27
|
+
function loadReactTemplates() {
|
|
28
|
+
return {
|
|
29
|
+
component: loadTemplateSync(path.join(templatesDir, "react", "component.tsx.ejs")),
|
|
30
|
+
types: loadTemplateSync(path.join(templatesDir, "react", "types.ts.ejs")),
|
|
31
|
+
index: loadTemplateSync(path.join(templatesDir, "react", "index.ts.ejs")),
|
|
32
|
+
test: loadTemplateSync(path.join(templatesDir, "react", "test.tsx.ejs")),
|
|
33
|
+
ssrTest: loadTemplateSync(path.join(templatesDir, "react", "ssr.test.tsx.ejs")),
|
|
34
|
+
stories: loadTemplateSync(path.join(templatesDir, "react", "stories.tsx.ejs")),
|
|
35
|
+
styles: loadTemplateSync(path.join(templatesDir, "shared", "styles.css.ejs")),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Memoized template bundle. Loaded on the FIRST `generate()` call, never at
|
|
40
|
+
* module-eval — so importing this generator (which the CLI does behind a lazy
|
|
41
|
+
* boundary, and which a compiled-binary READ may still eval) never reads a
|
|
42
|
+
* template. A READ never calls `generate()`, so it never touches the disk/`.ejs`
|
|
43
|
+
* that a standalone binary lacks — closing the bun-code-splitting-fragility hole.
|
|
44
|
+
*/
|
|
45
|
+
let reactTemplatesCache;
|
|
46
|
+
function reactTemplates() {
|
|
47
|
+
reactTemplatesCache ??= loadReactTemplates();
|
|
48
|
+
return reactTemplatesCache;
|
|
49
|
+
}
|
|
35
50
|
// =============================================================================
|
|
36
51
|
// Generator Definition
|
|
37
52
|
// =============================================================================
|
|
@@ -66,56 +81,57 @@ For example, 'src/components/Button' creates a 'Button' component.`,
|
|
|
66
81
|
const componentDir = answers.componentPath;
|
|
67
82
|
const parentDir = getParentDir(answers.componentPath);
|
|
68
83
|
const ctx = createTemplateContext(answers, "react");
|
|
84
|
+
const t = reactTemplates();
|
|
69
85
|
return sequence_([
|
|
70
86
|
info(`Generating React component: ${componentName}`),
|
|
71
87
|
debug("Creating component directory"),
|
|
72
88
|
mkdir(componentDir),
|
|
73
89
|
debug("Creating main component file"),
|
|
74
90
|
template({
|
|
75
|
-
source:
|
|
76
|
-
content:
|
|
91
|
+
source: t.component.source,
|
|
92
|
+
content: t.component.content,
|
|
77
93
|
dest: path.join(componentDir, `${componentName}.tsx`),
|
|
78
94
|
vars: ctx,
|
|
79
95
|
}),
|
|
80
96
|
debug("Creating types file"),
|
|
81
97
|
template({
|
|
82
|
-
source:
|
|
83
|
-
content:
|
|
98
|
+
source: t.types.source,
|
|
99
|
+
content: t.types.content,
|
|
84
100
|
dest: path.join(componentDir, "types.ts"),
|
|
85
101
|
vars: ctx,
|
|
86
102
|
}),
|
|
87
103
|
debug("Creating index barrel file"),
|
|
88
104
|
template({
|
|
89
|
-
source:
|
|
90
|
-
content:
|
|
105
|
+
source: t.index.source,
|
|
106
|
+
content: t.index.content,
|
|
91
107
|
dest: path.join(componentDir, "index.ts"),
|
|
92
108
|
vars: ctx,
|
|
93
109
|
}),
|
|
94
110
|
debug("Creating test file"),
|
|
95
111
|
template({
|
|
96
|
-
source:
|
|
97
|
-
content:
|
|
112
|
+
source: t.test.source,
|
|
113
|
+
content: t.test.content,
|
|
98
114
|
dest: path.join(componentDir, `${componentName}.tests.tsx`),
|
|
99
115
|
vars: ctx,
|
|
100
116
|
}),
|
|
101
117
|
when(answers.withSsrTests, debug("Creating SSR test file")),
|
|
102
118
|
when(answers.withSsrTests, template({
|
|
103
|
-
source:
|
|
104
|
-
content:
|
|
119
|
+
source: t.ssrTest.source,
|
|
120
|
+
content: t.ssrTest.content,
|
|
105
121
|
dest: path.join(componentDir, `${componentName}.ssr.tests.tsx`),
|
|
106
122
|
vars: ctx,
|
|
107
123
|
})),
|
|
108
124
|
when(answers.withStories, debug("Creating stories file")),
|
|
109
125
|
when(answers.withStories, template({
|
|
110
|
-
source:
|
|
111
|
-
content:
|
|
126
|
+
source: t.stories.source,
|
|
127
|
+
content: t.stories.content,
|
|
112
128
|
dest: path.join(componentDir, `${componentName}.stories.tsx`),
|
|
113
129
|
vars: ctx,
|
|
114
130
|
})),
|
|
115
131
|
when(answers.withStyles, debug("Creating styles file")),
|
|
116
132
|
when(answers.withStyles, template({
|
|
117
|
-
source:
|
|
118
|
-
content:
|
|
133
|
+
source: t.styles.source,
|
|
134
|
+
content: t.styles.content,
|
|
119
135
|
dest: path.join(componentDir, "styles.css"),
|
|
120
136
|
vars: ctx,
|
|
121
137
|
})),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../src/react/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AA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I,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC;gBAC3C,IAAI,EAAE,GAAG;aACV,CAAC,CACH;YAED,KAAK,CAAC,sCAAsC,CAAC;YAC7C,yBAAyB,CAAC,SAAS,EAAE,aAAa,CAAC;YAEnD,IAAI,CAAC,WAAW,aAAa,iBAAiB,YAAY,EAAE,CAAC;SAC9D,CAAC,CAAC;IACL,CAAC;CAC4D,CAAC;AAEhE,eAAe,SAAS,CAAC"}
|
|
@@ -1,56 +1,107 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Load a template file eagerly, with compiled
|
|
2
|
+
* Load a template file eagerly, with compiled-binary support.
|
|
3
3
|
*
|
|
4
|
-
* In
|
|
5
|
-
*
|
|
4
|
+
* In a source run (or tests) the template is read from disk. In the standalone
|
|
5
|
+
* `bun build --compile` binary the `.ejs` files are not on disk, so the loader
|
|
6
|
+
* falls back to an EMBEDDED MANIFEST injected by the host via
|
|
7
|
+
* {@link setEmbeddedTemplates} — a map keyed by DIRECTORY-QUALIFIED path
|
|
8
|
+
* (`component/<framework>/<file>`), compiled into the binary as inline strings.
|
|
9
|
+
*
|
|
10
|
+
* The directory-qualified key is what fixes the historic basename collision:
|
|
11
|
+
* several component templates share a basename across frameworks
|
|
12
|
+
* (`types.ts.ejs`, `index.ts.ejs`, `styles.css.ejs`, `stories.ts.ejs` exist in
|
|
13
|
+
* `react/`, `svelte/` and `lit/`). The previous fallback matched embedded blobs
|
|
14
|
+
* by BARE BASENAME, so a compiled binary could silently emit the WRONG
|
|
15
|
+
* framework's template (whichever blob was encountered first). Matching on the
|
|
16
|
+
* framework-qualified suffix instead guarantees the right framework's file.
|
|
6
17
|
*/
|
|
7
18
|
import { readFileSync } from "node:fs";
|
|
8
19
|
/**
|
|
9
|
-
*
|
|
20
|
+
* The injected embedded-template manifest: directory-qualified path
|
|
21
|
+
* (`component/react/types.ts.ejs`) → template content. Empty in a source run
|
|
22
|
+
* (templates load from disk); populated by the compiled-binary host BEFORE the
|
|
23
|
+
* component generators evaluate their top-level `await loadTemplate`.
|
|
24
|
+
*/
|
|
25
|
+
let embeddedTemplates = {};
|
|
26
|
+
/**
|
|
27
|
+
* Inject the embedded-template manifest — the compiled-binary fallback. Called
|
|
28
|
+
* once by the host (the `pragma` `create` runtime) before the component
|
|
29
|
+
* generators are imported, so their eager `loadTemplate` calls can resolve from
|
|
30
|
+
* it when the disk read fails. Passing an empty map (the default) restores pure
|
|
31
|
+
* disk loading.
|
|
32
|
+
*
|
|
33
|
+
* @param manifest - Directory-qualified path → template content.
|
|
34
|
+
*/
|
|
35
|
+
export function setEmbeddedTemplates(manifest) {
|
|
36
|
+
embeddedTemplates = manifest;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The directory-qualified manifest key for a template source path: the portion
|
|
40
|
+
* after the last `/templates/` segment (e.g. `react/types.ts.ejs`), prefixed
|
|
41
|
+
* with the generator id (`component/`). Returns `undefined` when the path has no
|
|
42
|
+
* `templates/` segment (never expected for a real template).
|
|
43
|
+
*
|
|
44
|
+
* The `component/` prefix is correct because this loader is used ONLY by the
|
|
45
|
+
* component generators; the shared manifest additionally carries `package/…` and
|
|
46
|
+
* `application/…` entries (embedded for a future compiled-binary rollout of
|
|
47
|
+
* those nouns), which this loader never queries.
|
|
48
|
+
*/
|
|
49
|
+
function qualifiedKey(source) {
|
|
50
|
+
const marker = "/templates/";
|
|
51
|
+
const at = source.lastIndexOf(marker);
|
|
52
|
+
if (at === -1)
|
|
53
|
+
return undefined;
|
|
54
|
+
return `component/${source.slice(at + marker.length)}`;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Load a template from disk, or — when the disk read fails (a compiled binary) —
|
|
58
|
+
* from the injected embedded manifest. SYNCHRONOUS.
|
|
59
|
+
*
|
|
60
|
+
* Disk is consulted FIRST: a source run reads the real file, and the compiled
|
|
61
|
+
* binary's absolute `/$bunfs/…` source paths never exist on a user's disk, so it
|
|
62
|
+
* always falls through to the manifest. A source run and a compiled run are
|
|
63
|
+
* therefore byte-identical (the manifest is generated from the same files).
|
|
64
|
+
*
|
|
65
|
+
* This is synchronous (both branches — `readFileSync` and the in-memory manifest
|
|
66
|
+
* lookup — are), so a generator can load its templates LAZILY inside its
|
|
67
|
+
* synchronous `generate(answers): Task` call rather than via a module-eval
|
|
68
|
+
* top-level `await`. That is the whole point of the sync form: a READ command
|
|
69
|
+
* (which never calls `generate()`) then never touches a template, regardless of
|
|
70
|
+
* whether bun's `--compile` code-splitting kept the generator module lazy — the
|
|
71
|
+
* exact fragility that crashed `pragma block list` on some bun versions.
|
|
10
72
|
*
|
|
11
73
|
* @param source - Absolute path to the template file.
|
|
12
74
|
* @returns Loaded template with path and content.
|
|
75
|
+
* @throws If the template is neither on disk nor in the embedded manifest — fail
|
|
76
|
+
* loud rather than return `""`, which callers do not guard against and would
|
|
77
|
+
* silently write as empty files (notably in a compiled binary).
|
|
13
78
|
*/
|
|
14
|
-
export
|
|
15
|
-
//
|
|
79
|
+
export function loadTemplateSync(source) {
|
|
80
|
+
// Filesystem first (source runs / tests).
|
|
16
81
|
try {
|
|
17
82
|
return { source, content: readFileSync(source, "utf-8") };
|
|
18
83
|
}
|
|
19
84
|
catch {
|
|
20
|
-
//
|
|
85
|
+
// Not on disk — fall through to the embedded manifest (compiled binary).
|
|
21
86
|
}
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// filename (the source directory is not preserved). Several templates
|
|
30
|
-
// share a basename across frameworks — types.ts.ejs, index.ts.ejs,
|
|
31
|
-
// styles.css.ejs and stories.ts.ejs each exist in lit/, react/ and/or
|
|
32
|
-
// svelte/. In a compiled binary this can resolve to the WRONG
|
|
33
|
-
// framework's template (whichever blob is encountered first), producing
|
|
34
|
-
// a silently incorrect generated file. The proper fix is build-side:
|
|
35
|
-
// embed templates under directory-qualified unique names and match on
|
|
36
|
-
// those. Deferred — needs verification against a real compiled binary
|
|
37
|
-
// (see pragma-adrs/session/J.CLI_MCP_FINISH.md). Interpreted mode (the
|
|
38
|
-
// common path) reads from disk above and is unaffected.
|
|
39
|
-
const basename = source.slice(source.lastIndexOf("/") + 1);
|
|
40
|
-
for (const blob of blobs) {
|
|
41
|
-
const dehashed = blob.name.replace(/-[a-z0-9]+\./, ".");
|
|
42
|
-
if (dehashed === basename) {
|
|
43
|
-
const content = await blob.text();
|
|
44
|
-
return { source, content };
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
87
|
+
// Directory-qualified embedded lookup: `react/types.ts.ejs` and
|
|
88
|
+
// `svelte/types.ts.ejs` map to distinct keys, so the collision is impossible.
|
|
89
|
+
const key = qualifiedKey(source);
|
|
90
|
+
if (key !== undefined) {
|
|
91
|
+
const content = embeddedTemplates[key];
|
|
92
|
+
if (content !== undefined)
|
|
93
|
+
return { source, content };
|
|
48
94
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
95
|
+
throw new Error(`Template not found: ${source} (not on disk, and no embedded template for ${key === undefined ? "this path" : `'${key}'`}).`);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Async wrapper over {@link loadTemplateSync}, kept for callers that await a
|
|
99
|
+
* template load. The body is fully synchronous.
|
|
100
|
+
*
|
|
101
|
+
* @param source - Absolute path to the template file.
|
|
102
|
+
* @returns Loaded template with path and content.
|
|
103
|
+
*/
|
|
104
|
+
export default async function loadTemplate(source) {
|
|
105
|
+
return loadTemplateSync(source);
|
|
55
106
|
}
|
|
56
107
|
//# sourceMappingURL=loadTemplate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadTemplate.js","sourceRoot":"","sources":["../../../src/shared/loadTemplate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"loadTemplate.js","sourceRoot":"","sources":["../../../src/shared/loadTemplate.ts"],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AAI,CACL,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,YAAY,CACxC,MAAc;IAEd,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
2
|
import { isPascalCase } from "./string-helpers/index.js";
|
|
3
3
|
/**
|
|
4
|
-
* Validate component path
|
|
4
|
+
* Validate component path.
|
|
5
|
+
*
|
|
6
|
+
* Rejects an empty path, an absolute path, or one that escapes the project via
|
|
7
|
+
* `..` segments (all of which would write outside the working tree), and
|
|
8
|
+
* requires the final path segment to be a PascalCase component name.
|
|
5
9
|
*/
|
|
6
10
|
export default function validateComponentPath(value) {
|
|
7
11
|
if (!value || typeof value !== "string") {
|
|
8
12
|
return "Component path is required";
|
|
9
13
|
}
|
|
14
|
+
if (path.isAbsolute(value)) {
|
|
15
|
+
return "Component path must be relative to the project, not absolute";
|
|
16
|
+
}
|
|
17
|
+
const segments = value.split(/[/\\]/);
|
|
18
|
+
if (segments.includes("..")) {
|
|
19
|
+
return "Component path must stay within the project (no '..' segments)";
|
|
20
|
+
}
|
|
10
21
|
const name = path.basename(value);
|
|
11
22
|
if (!isPascalCase(name)) {
|
|
12
23
|
return "Component name must be in PascalCase (e.g., MyComponent)";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateComponentPath.js","sourceRoot":"","sources":["../../../src/shared/validateComponentPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD
|
|
1
|
+
{"version":3,"file":"validateComponentPath.js","sourceRoot":"","sources":["../../../src/shared/validateComponentPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,KAAc;IAC1D,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,4BAA4B,CAAC;IACtC,CAAC;IACD,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,8DAA8D,CAAC;IACxE,CAAC;IACD,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACtC,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,OAAO,gEAAgE,CAAC;IAC1E,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,OAAO,0DAA0D,CAAC;IACpE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -25,22 +25,36 @@ import { fileURLToPath } from "node:url";
|
|
|
25
25
|
import { template } from "@canonical/summon-core";
|
|
26
26
|
import { debug, info, mkdir, sequence_, when } from "@canonical/task";
|
|
27
27
|
import { appendExportToParentIndex, createComponentPathPrompt, createTemplateContext, getComponentName, getParentDir, PACKAGE_NAME, sharedPrompts, } from "../shared/index.js";
|
|
28
|
-
import
|
|
28
|
+
import { loadTemplateSync } from "../shared/loadTemplate.js";
|
|
29
29
|
// =============================================================================
|
|
30
|
-
// Template Paths & Content (loaded
|
|
30
|
+
// Template Paths & Content (loaded LAZILY on first generate())
|
|
31
31
|
// =============================================================================
|
|
32
32
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
33
33
|
const templatesDir = path.join(__dirname, "..", "templates");
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
/** Read every Svelte template from disk (or the embedded manifest). */
|
|
35
|
+
function loadSvelteTemplates() {
|
|
36
|
+
return {
|
|
37
|
+
component: loadTemplateSync(path.join(templatesDir, "svelte", "component.svelte.ejs")),
|
|
38
|
+
types: loadTemplateSync(path.join(templatesDir, "svelte", "types.ts.ejs")),
|
|
39
|
+
index: loadTemplateSync(path.join(templatesDir, "svelte", "index.ts.ejs")),
|
|
40
|
+
test: loadTemplateSync(path.join(templatesDir, "svelte", "test.ts.ejs")),
|
|
41
|
+
ssrTest: loadTemplateSync(path.join(templatesDir, "svelte", "ssr.test.ts.ejs")),
|
|
42
|
+
storiesSvelte: loadTemplateSync(path.join(templatesDir, "svelte", "stories.svelte.ejs")),
|
|
43
|
+
storiesTs: loadTemplateSync(path.join(templatesDir, "svelte", "stories.ts.ejs")),
|
|
44
|
+
styles: loadTemplateSync(path.join(templatesDir, "shared", "styles.css.ejs")),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Memoized template bundle. Loaded on the FIRST `generate()` call, never at
|
|
49
|
+
* module-eval — so importing this generator never reads a template, and a READ
|
|
50
|
+
* command (which never calls `generate()`) never touches the `.ejs` a compiled
|
|
51
|
+
* binary lacks. See the react generator for the full rationale.
|
|
52
|
+
*/
|
|
53
|
+
let svelteTemplatesCache;
|
|
54
|
+
function svelteTemplates() {
|
|
55
|
+
svelteTemplatesCache ??= loadSvelteTemplates();
|
|
56
|
+
return svelteTemplatesCache;
|
|
57
|
+
}
|
|
44
58
|
// =============================================================================
|
|
45
59
|
// Generator Definition
|
|
46
60
|
// =============================================================================
|
|
@@ -95,63 +109,64 @@ For example, 'src/lib/components/Button' creates a 'Button' component.`,
|
|
|
95
109
|
const componentDir = answers.componentPath;
|
|
96
110
|
const parentDir = getParentDir(answers.componentPath);
|
|
97
111
|
const ctx = createTemplateContext(answers, "svelte");
|
|
112
|
+
const t = svelteTemplates();
|
|
98
113
|
return sequence_([
|
|
99
114
|
info(`Generating Svelte component: ${componentName}`),
|
|
100
115
|
debug("Creating component directory"),
|
|
101
116
|
mkdir(componentDir),
|
|
102
117
|
debug("Creating main component file"),
|
|
103
118
|
template({
|
|
104
|
-
source:
|
|
105
|
-
content:
|
|
119
|
+
source: t.component.source,
|
|
120
|
+
content: t.component.content,
|
|
106
121
|
dest: path.join(componentDir, `${componentName}.svelte`),
|
|
107
122
|
vars: ctx,
|
|
108
123
|
}),
|
|
109
124
|
debug("Creating types file"),
|
|
110
125
|
template({
|
|
111
|
-
source:
|
|
112
|
-
content:
|
|
126
|
+
source: t.types.source,
|
|
127
|
+
content: t.types.content,
|
|
113
128
|
dest: path.join(componentDir, "types.ts"),
|
|
114
129
|
vars: ctx,
|
|
115
130
|
}),
|
|
116
131
|
debug("Creating index barrel file"),
|
|
117
132
|
template({
|
|
118
|
-
source:
|
|
119
|
-
content:
|
|
133
|
+
source: t.index.source,
|
|
134
|
+
content: t.index.content,
|
|
120
135
|
dest: path.join(componentDir, "index.ts"),
|
|
121
136
|
vars: ctx,
|
|
122
137
|
}),
|
|
123
138
|
debug("Creating test file"),
|
|
124
139
|
template({
|
|
125
|
-
source:
|
|
126
|
-
content:
|
|
140
|
+
source: t.test.source,
|
|
141
|
+
content: t.test.content,
|
|
127
142
|
dest: path.join(componentDir, `${componentName}.svelte.test.ts`),
|
|
128
143
|
vars: ctx,
|
|
129
144
|
}),
|
|
130
145
|
when(answers.withSsrTests, debug("Creating SSR test file")),
|
|
131
146
|
when(answers.withSsrTests, template({
|
|
132
|
-
source:
|
|
133
|
-
content:
|
|
147
|
+
source: t.ssrTest.source,
|
|
148
|
+
content: t.ssrTest.content,
|
|
134
149
|
dest: path.join(componentDir, `${componentName}.ssr.test.ts`),
|
|
135
150
|
vars: ctx,
|
|
136
151
|
})),
|
|
137
152
|
when(answers.withStories && !answers.useTsStories, debug("Creating Svelte CSF stories file")),
|
|
138
153
|
when(answers.withStories && !answers.useTsStories, template({
|
|
139
|
-
source:
|
|
140
|
-
content:
|
|
154
|
+
source: t.storiesSvelte.source,
|
|
155
|
+
content: t.storiesSvelte.content,
|
|
141
156
|
dest: path.join(componentDir, `${componentName}.stories.svelte`),
|
|
142
157
|
vars: ctx,
|
|
143
158
|
})),
|
|
144
159
|
when(answers.withStories && answers.useTsStories, debug("Creating TypeScript stories file")),
|
|
145
160
|
when(answers.withStories && answers.useTsStories, template({
|
|
146
|
-
source:
|
|
147
|
-
content:
|
|
161
|
+
source: t.storiesTs.source,
|
|
162
|
+
content: t.storiesTs.content,
|
|
148
163
|
dest: path.join(componentDir, `${componentName}.stories.ts`),
|
|
149
164
|
vars: ctx,
|
|
150
165
|
})),
|
|
151
166
|
when(answers.withStyles, debug("Creating styles file")),
|
|
152
167
|
when(answers.withStyles, template({
|
|
153
|
-
source:
|
|
154
|
-
content:
|
|
168
|
+
source: t.styles.source,
|
|
169
|
+
content: t.styles.content,
|
|
155
170
|
dest: path.join(componentDir, "styles.css"),
|
|
156
171
|
vars: ctx,
|
|
157
172
|
})),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../src/svelte/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAA4B,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEtE,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,qBAAqB,EACrB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,aAAa,GACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../src/svelte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C,OAAO;gBAC5B,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,aAAa,aAAa,CAAC;gBAC5D,IAAI,EAAE,GAAG;aACV,CAAC,CACH;YAED,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,sBAAsB,CAAC,CAAC;YACvD,IAAI,CACF,OAAO,CAAC,UAAU,EAClB,QAAQ,CAAC;gBACP,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM;gBACvB,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO;gBACzB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC;gBAC3C,IAAI,EAAE,GAAG;aACV,CAAC,CACH;YAED,KAAK,CAAC,sCAAsC,CAAC;YAC7C,yBAAyB,CAAC,SAAS,EAAE,aAAa,CAAC;YAEnD,IAAI,CAAC,WAAW,aAAa,iBAAiB,YAAY,EAAE,CAAC;SAC9D,CAAC,CAAC;IACL,CAAC;CAC6D,CAAC;AAEjE,eAAe,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/lit/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/lit/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AA4EH;;;;;;;GAOG;AACH,QAAA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;CAsGqC,CAAC;AAErD,eAAe,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/react/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/react/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAgEH,QAAA,MAAM,SAAS;;;;;;;;;;;CAiHgD,CAAC;AAEhE,eAAe,SAAS,CAAC"}
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Load a template file eagerly, with compiled
|
|
2
|
+
* Load a template file eagerly, with compiled-binary support.
|
|
3
3
|
*
|
|
4
|
-
* In
|
|
5
|
-
*
|
|
4
|
+
* In a source run (or tests) the template is read from disk. In the standalone
|
|
5
|
+
* `bun build --compile` binary the `.ejs` files are not on disk, so the loader
|
|
6
|
+
* falls back to an EMBEDDED MANIFEST injected by the host via
|
|
7
|
+
* {@link setEmbeddedTemplates} — a map keyed by DIRECTORY-QUALIFIED path
|
|
8
|
+
* (`component/<framework>/<file>`), compiled into the binary as inline strings.
|
|
9
|
+
*
|
|
10
|
+
* The directory-qualified key is what fixes the historic basename collision:
|
|
11
|
+
* several component templates share a basename across frameworks
|
|
12
|
+
* (`types.ts.ejs`, `index.ts.ejs`, `styles.css.ejs`, `stories.ts.ejs` exist in
|
|
13
|
+
* `react/`, `svelte/` and `lit/`). The previous fallback matched embedded blobs
|
|
14
|
+
* by BARE BASENAME, so a compiled binary could silently emit the WRONG
|
|
15
|
+
* framework's template (whichever blob was encountered first). Matching on the
|
|
16
|
+
* framework-qualified suffix instead guarantees the right framework's file.
|
|
6
17
|
*/
|
|
7
18
|
export interface LoadedTemplate {
|
|
8
19
|
/** Original source path (for diagnostics and dry-run display). */
|
|
@@ -11,7 +22,42 @@ export interface LoadedTemplate {
|
|
|
11
22
|
readonly content: string;
|
|
12
23
|
}
|
|
13
24
|
/**
|
|
14
|
-
*
|
|
25
|
+
* Inject the embedded-template manifest — the compiled-binary fallback. Called
|
|
26
|
+
* once by the host (the `pragma` `create` runtime) before the component
|
|
27
|
+
* generators are imported, so their eager `loadTemplate` calls can resolve from
|
|
28
|
+
* it when the disk read fails. Passing an empty map (the default) restores pure
|
|
29
|
+
* disk loading.
|
|
30
|
+
*
|
|
31
|
+
* @param manifest - Directory-qualified path → template content.
|
|
32
|
+
*/
|
|
33
|
+
export declare function setEmbeddedTemplates(manifest: Readonly<Record<string, string>>): void;
|
|
34
|
+
/**
|
|
35
|
+
* Load a template from disk, or — when the disk read fails (a compiled binary) —
|
|
36
|
+
* from the injected embedded manifest. SYNCHRONOUS.
|
|
37
|
+
*
|
|
38
|
+
* Disk is consulted FIRST: a source run reads the real file, and the compiled
|
|
39
|
+
* binary's absolute `/$bunfs/…` source paths never exist on a user's disk, so it
|
|
40
|
+
* always falls through to the manifest. A source run and a compiled run are
|
|
41
|
+
* therefore byte-identical (the manifest is generated from the same files).
|
|
42
|
+
*
|
|
43
|
+
* This is synchronous (both branches — `readFileSync` and the in-memory manifest
|
|
44
|
+
* lookup — are), so a generator can load its templates LAZILY inside its
|
|
45
|
+
* synchronous `generate(answers): Task` call rather than via a module-eval
|
|
46
|
+
* top-level `await`. That is the whole point of the sync form: a READ command
|
|
47
|
+
* (which never calls `generate()`) then never touches a template, regardless of
|
|
48
|
+
* whether bun's `--compile` code-splitting kept the generator module lazy — the
|
|
49
|
+
* exact fragility that crashed `pragma block list` on some bun versions.
|
|
50
|
+
*
|
|
51
|
+
* @param source - Absolute path to the template file.
|
|
52
|
+
* @returns Loaded template with path and content.
|
|
53
|
+
* @throws If the template is neither on disk nor in the embedded manifest — fail
|
|
54
|
+
* loud rather than return `""`, which callers do not guard against and would
|
|
55
|
+
* silently write as empty files (notably in a compiled binary).
|
|
56
|
+
*/
|
|
57
|
+
export declare function loadTemplateSync(source: string): LoadedTemplate;
|
|
58
|
+
/**
|
|
59
|
+
* Async wrapper over {@link loadTemplateSync}, kept for callers that await a
|
|
60
|
+
* template load. The body is fully synchronous.
|
|
15
61
|
*
|
|
16
62
|
* @param source - Absolute path to the template file.
|
|
17
63
|
* @returns Loaded template with path and content.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadTemplate.d.ts","sourceRoot":"","sources":["../../../src/shared/loadTemplate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"loadTemplate.d.ts","sourceRoot":"","sources":["../../../src/shared/loadTemplate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,MAAM,WAAW,cAAc;IAC7B,kEAAkE;IAClE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,+BAA+B;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAUD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACzC,IAAI,CAEN;AAoBD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,CAqB/D;AAED;;;;;;GAMG;AACH,wBAA8B,YAAY,CACxC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,cAAc,CAAC,CAEzB"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Validate component path
|
|
2
|
+
* Validate component path.
|
|
3
|
+
*
|
|
4
|
+
* Rejects an empty path, an absolute path, or one that escapes the project via
|
|
5
|
+
* `..` segments (all of which would write outside the working tree), and
|
|
6
|
+
* requires the final path segment to be a PascalCase component name.
|
|
3
7
|
*/
|
|
4
8
|
export default function validateComponentPath(value: unknown): true | string;
|
|
5
9
|
//# sourceMappingURL=validateComponentPath.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateComponentPath.d.ts","sourceRoot":"","sources":["../../../src/shared/validateComponentPath.ts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"validateComponentPath.d.ts","sourceRoot":"","sources":["../../../src/shared/validateComponentPath.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,MAAM,CAgB3E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/svelte/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAiBH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/svelte/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAiBH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAiDzD;;;;;;;GAOG;AACH,QAAA,MAAM,SAAS;;;;;;;;;;;;;;;;;;CA8IiD,CAAC;AAEjE,eAAe,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canonical/summon-component",
|
|
3
3
|
"description": "Component generators for Summon - React, Svelte and Lit component scaffolding",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.32.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/esm/index.js",
|
|
7
7
|
"module": "dist/esm/index.js",
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/types/index.d.ts",
|
|
12
12
|
"import": "./dist/esm/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./embedded": {
|
|
15
|
+
"types": "./dist/types/shared/loadTemplate.d.ts",
|
|
16
|
+
"import": "./dist/esm/shared/loadTemplate.js"
|
|
13
17
|
}
|
|
14
18
|
},
|
|
15
19
|
"files": [
|
|
@@ -46,20 +50,20 @@
|
|
|
46
50
|
},
|
|
47
51
|
"devDependencies": {
|
|
48
52
|
"@biomejs/biome": "2.4.9",
|
|
49
|
-
"@canonical/biome-config": "^0.
|
|
50
|
-
"@canonical/typescript-config": "^0.
|
|
51
|
-
"@canonical/webarchitect": "^0.
|
|
53
|
+
"@canonical/biome-config": "^0.32.0",
|
|
54
|
+
"@canonical/typescript-config": "^0.32.0",
|
|
55
|
+
"@canonical/webarchitect": "^0.32.0",
|
|
52
56
|
"@types/bun": "^1.3.10",
|
|
53
57
|
"@types/node": "^24.12.0",
|
|
54
58
|
"typescript": "^5.9.3",
|
|
55
59
|
"vitest": "^4.0.18"
|
|
56
60
|
},
|
|
57
61
|
"dependencies": {
|
|
58
|
-
"@canonical/utils": "^0.
|
|
62
|
+
"@canonical/utils": "^0.32.0"
|
|
59
63
|
},
|
|
60
64
|
"peerDependencies": {
|
|
61
|
-
"@canonical/summon-core": "^0.
|
|
62
|
-
"@canonical/task": "^0.
|
|
65
|
+
"@canonical/summon-core": "^0.30.0",
|
|
66
|
+
"@canonical/task": "^0.30.0"
|
|
63
67
|
},
|
|
64
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "5b279d8150e3988c68c6c2a741046bcd425624ca"
|
|
65
69
|
}
|