@panomc/plugin-kit 0.0.0-stage → 1.0.0-dev.62
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/assets/pano-bootstrap.css +17903 -0
- package/bin/__tests__/new/e2e.test.js +111 -0
- package/bin/__tests__/new/helpers.js +76 -0
- package/bin/__tests__/new/new.test.js +472 -0
- package/bin/new.js +530 -0
- package/bin/pano-plugin.js +162 -0
- package/bin/templates/plugin/README.md +30 -0
- package/bin/templates/plugin/_gitignore +15 -0
- package/bin/templates/plugin/build.gradle.kts +389 -0
- package/bin/templates/plugin/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/bin/templates/plugin/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/bin/templates/plugin/gradle.properties +55 -0
- package/bin/templates/plugin/gradlew +249 -0
- package/bin/templates/plugin/gradlew.bat +92 -0
- package/bin/templates/plugin/package.json.tpl +14 -0
- package/bin/templates/plugin/rollup.config.js +2 -0
- package/bin/templates/plugin/settings.gradle.kts +5 -0
- package/bin/templates/plugin/src/main/kotlin/__PKGPATH__/__CLASS__Plugin.kt +50 -0
- package/bin/templates/plugin/src/main/kotlin/__PKGPATH__/frontend/ExampleFallbackPage.kt +28 -0
- package/bin/templates/plugin/src/main/kotlin/__PKGPATH__/routes/GetHelloAPI.kt +19 -0
- package/bin/templates/plugin/src/main/kotlin/com/panomc/plugins/license/LicenseGuard.kt +30 -0
- package/bin/templates/plugin/src/main/kotlin/com/panomc/plugins/license/PluginLicenseClient.kt +144 -0
- package/bin/templates/plugin/src/main/resources/config.conf +1 -0
- package/bin/templates/plugin/src/main/resources/frontend-targets.json +1 -0
- package/bin/templates/plugin/src/main/resources/locales/en-US.json +3 -0
- package/bin/templates/plugin/src/main/resources/logo.png +0 -0
- package/bin/templates/plugin/src/theme/views/HelloPage.svelte +26 -0
- package/bin/ui.js +96 -0
- package/package.json +48 -4
- package/src/config.js +191 -0
- package/src/controller/__tests__/controller.test.js +647 -0
- package/src/controller/index.js +604 -0
- package/src/dev.js +208 -0
- package/src/index.js +22 -0
- package/src/rollup/__tests__/controllers/controllers.test.js +418 -0
- package/src/rollup/__tests__/controllers/fixture.js +143 -0
- package/src/rollup/__tests__/controllers/golden/controllers.json +34 -0
- package/src/rollup/__tests__/controllers/golden/controllers.types.js +69 -0
- package/src/rollup/__tests__/controllers/golden/pano-plugin.json +16 -0
- package/src/rollup/__tests__/controllers/golden/pano-plugin.lock.json +27 -0
- package/src/rollup/__tests__/controllers/golden/pano-plugin.with-views.json +54 -0
- package/src/rollup/__tests__/preset/preset.test.js +418 -0
- package/src/rollup/__tests__/rules/_build.js +39 -0
- package/src/rollup/__tests__/rules/_fixture.js +83 -0
- package/src/rollup/__tests__/rules/helpers.test.js +148 -0
- package/src/rollup/__tests__/rules/rules.test.js +259 -0
- package/src/rollup/__tests__/rules/stamp.test.js +113 -0
- package/src/rollup/__tests__/samples/samples.test.js +481 -0
- package/src/rollup/__tests__/seams/config.test.js +78 -0
- package/src/rollup/__tests__/seams/lock.test.js +124 -0
- package/src/rollup/__tests__/seams/sdk-seams.test.js +93 -0
- package/src/rollup/__tests__/seams/stubs.test.js +52 -0
- package/src/rollup/__tests__/views/helpers.js +82 -0
- package/src/rollup/__tests__/views/views.test.js +522 -0
- package/src/rollup/__tests__/widgets/helpers.js +117 -0
- package/src/rollup/__tests__/widgets/widgets.test.js +422 -0
- package/src/rollup/cli-build.js +90 -0
- package/src/rollup/cli-check.js +280 -0
- package/src/rollup/cli-classes.js +75 -0
- package/src/rollup/client-gen.js +67 -0
- package/src/rollup/controllers.js +434 -0
- package/src/rollup/entry.js +250 -0
- package/src/rollup/helpers.js +193 -0
- package/src/rollup/index.js +601 -0
- package/src/rollup/integrate.js +205 -0
- package/src/rollup/lock.js +230 -0
- package/src/rollup/meta.js +479 -0
- package/src/rollup/rules.js +950 -0
- package/src/rollup/samples.js +667 -0
- package/src/rollup/stamp.js +410 -0
- package/src/rollup/types.js +248 -0
- package/src/rollup/views.js +1205 -0
- package/src/rollup/widgets.js +1000 -0
- package/src/styles/__tests__/fallback/__snapshots__/build-fallback-css.test.js.snap +173 -0
- package/src/styles/__tests__/fallback/build-fallback-css.test.js +526 -0
- package/src/styles/__tests__/fallback/fixtures/base.css +247 -0
- package/src/styles/__tests__/fallback/plugins.test.js +301 -0
- package/src/styles/__tests__/lint/check-styles.test.js +423 -0
- package/src/styles/__tests__/lint/fixtures/ProductCard.golden.svelte +13 -0
- package/src/styles/__tests__/lint/fixtures/ProductCard.in.svelte +13 -0
- package/src/styles/__tests__/lint/semantic-classes.test.js +364 -0
- package/src/styles/bootstrap-classes.js +155 -0
- package/src/styles/check-styles.js +626 -0
- package/src/styles/fallback-css.js +1182 -0
- package/src/styles/plugin-css.js +237 -0
- package/src/styles/scan.js +206 -0
- package/src/styles/semantic-classes.js +436 -0
- package/src/styles/tokens.map.js +53 -0
- package/README.md +0 -3
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { rollup } from "rollup";
|
|
7
|
+
import { createSampleController, defineController } from "../../../controller/index.js";
|
|
8
|
+
import { main } from "../../../../bin/pano-plugin.js";
|
|
9
|
+
import { getBuildContext } from "../../meta.js";
|
|
10
|
+
import {
|
|
11
|
+
STANDARD_STATES,
|
|
12
|
+
checkSamples,
|
|
13
|
+
compileSamples,
|
|
14
|
+
panoSamples,
|
|
15
|
+
runCheckWithSamples,
|
|
16
|
+
runSamples,
|
|
17
|
+
samplesStub,
|
|
18
|
+
} from "../../samples.js";
|
|
19
|
+
|
|
20
|
+
/** @type {string[]} */
|
|
21
|
+
const made = [];
|
|
22
|
+
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
while (made.length) fs.rmSync(/** @type {string} */ (made.pop()), { recursive: true, force: true });
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const PAGE = `<script module>
|
|
28
|
+
export const view = { path: "/cart" };
|
|
29
|
+
</script>
|
|
30
|
+
<script>
|
|
31
|
+
/** @type {{ lines: { id: number }[], title: string, count?: number }} */
|
|
32
|
+
let { lines, title, count = 0 } = $props();
|
|
33
|
+
</script>
|
|
34
|
+
<h1>{title}</h1>
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
const PLAIN = `<script>
|
|
38
|
+
/** @type {{ label: string }} */
|
|
39
|
+
let { label } = $props();
|
|
40
|
+
</script>
|
|
41
|
+
<span>{label}</span>
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
const BLOCK = `<script module>
|
|
45
|
+
export const view = { block: true };
|
|
46
|
+
</script>
|
|
47
|
+
<p>block</p>
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
const FIXTURES = `export const lines = [{ id: 1 }, { id: 2 }];
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
const CART_SAMPLES = `import { lines } from '../../fixtures.js';
|
|
54
|
+
export const notApplicable = ['loading', 'error'];
|
|
55
|
+
export default {
|
|
56
|
+
filled: { props: { lines, title: 'Cart' }, controllers: { 'demo/cart': { count: 2 } } },
|
|
57
|
+
empty: { props: { lines: [], title: 'Cart' }, session: 'guest' },
|
|
58
|
+
gifted: () => ({ props: { lines: [lines[0]], title: 'Gift' }, label: 'Gift' }),
|
|
59
|
+
};
|
|
60
|
+
`;
|
|
61
|
+
|
|
62
|
+
const FULL = (title) => `export default {
|
|
63
|
+
filled: { props: { label: '${title}' } },
|
|
64
|
+
empty: { props: { label: '' } },
|
|
65
|
+
error: { props: { label: '!' } },
|
|
66
|
+
loading: { props: { label: '...' } },
|
|
67
|
+
};
|
|
68
|
+
`;
|
|
69
|
+
|
|
70
|
+
/** @param {Record<string, string>} files */
|
|
71
|
+
function plugin(files) {
|
|
72
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "kit-samples-"));
|
|
73
|
+
|
|
74
|
+
made.push(root);
|
|
75
|
+
|
|
76
|
+
const all = { "gradle.properties": "pluginId=pano-plugin-demo\nversion=1.0.0\n", ...files };
|
|
77
|
+
|
|
78
|
+
for (const [file, content] of Object.entries(all)) {
|
|
79
|
+
fs.mkdirSync(path.dirname(path.join(root, file)), { recursive: true });
|
|
80
|
+
fs.writeFileSync(path.join(root, file), content);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return root;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const BASE = {
|
|
87
|
+
"src/theme/fixtures.js": FIXTURES,
|
|
88
|
+
"src/theme/views/pages/Cart.svelte": PAGE,
|
|
89
|
+
"src/theme/views/Chip.svelte": PLAIN,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/** Runs a rollup build of a throw-away entry with only panoSamples, as the client build would. */
|
|
93
|
+
async function buildWith(root, options = {}) {
|
|
94
|
+
const outDir = path.join(root, "out");
|
|
95
|
+
const logs = [];
|
|
96
|
+
const bundle = await rollup({
|
|
97
|
+
input: "\0entry",
|
|
98
|
+
onwarn: (warning) => logs.push(warning.message),
|
|
99
|
+
plugins: [
|
|
100
|
+
{ name: "entry", resolveId: (id) => (id === "\0entry" ? id : null), load: (id) => (id === "\0entry" ? "export default 1;" : null) },
|
|
101
|
+
panoSamples({ root, outDir, side: "client", ...options }),
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
await bundle.write({ dir: path.join(outDir, "client"), format: "es" });
|
|
107
|
+
} finally {
|
|
108
|
+
await bundle.close();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return { outDir, logs };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Imports the written module the way the catalogue does. */
|
|
115
|
+
async function loadWritten(outDir) {
|
|
116
|
+
const file = path.join(outDir, "samples", "samples.mjs");
|
|
117
|
+
const copy = path.join(os.tmpdir(), `kit-samples-load-${process.pid}-${Math.random().toString(36).slice(2)}.mjs`);
|
|
118
|
+
|
|
119
|
+
fs.copyFileSync(file, copy);
|
|
120
|
+
made.push(copy);
|
|
121
|
+
|
|
122
|
+
return import(pathToFileURL(copy).href);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
describe("samples.mjs", () => {
|
|
126
|
+
test("has the shape of doc 02 section 7 and is self-contained", async () => {
|
|
127
|
+
const root = plugin({
|
|
128
|
+
...BASE,
|
|
129
|
+
"src/theme/views/pages/Cart.samples.js": CART_SAMPLES,
|
|
130
|
+
"src/theme/views/Chip.samples.js": FULL("Chip"),
|
|
131
|
+
});
|
|
132
|
+
const { outDir } = await buildWith(root);
|
|
133
|
+
const text = fs.readFileSync(path.join(outDir, "samples/samples.mjs"), "utf8");
|
|
134
|
+
|
|
135
|
+
expect(text).not.toMatch(/^\s*import\b/m);
|
|
136
|
+
|
|
137
|
+
const mod = await loadWritten(outDir);
|
|
138
|
+
|
|
139
|
+
expect(Object.keys(mod.default)).toEqual(["Cart", "Chip"]);
|
|
140
|
+
expect(Object.keys(mod.default.Cart)).toEqual(["filled", "empty", "gifted"]);
|
|
141
|
+
expect(mod.default.Cart.filled).toEqual({
|
|
142
|
+
props: { lines: [{ id: 1 }, { id: 2 }], title: "Cart" },
|
|
143
|
+
controllers: { "demo/cart": { count: 2 } },
|
|
144
|
+
});
|
|
145
|
+
expect(mod.default.Cart.empty.session).toBe("guest");
|
|
146
|
+
expect(typeof mod.default.Cart.gifted).toBe("function");
|
|
147
|
+
expect(mod.default.Cart.gifted().props.title).toBe("Gift");
|
|
148
|
+
expect(Object.keys(mod.default.Chip)).toEqual(["filled", "empty", "error", "loading"]);
|
|
149
|
+
expect([...STANDARD_STATES].sort()).toEqual(["empty", "error", "filled", "loading"]);
|
|
150
|
+
expect(mod.notApplicable).toEqual({ Cart: ["loading", "error"], Chip: [] });
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("is never written next to, or imported by, the client or server bundles", async () => {
|
|
154
|
+
const root = plugin({ ...BASE, "src/theme/views/pages/Cart.samples.js": CART_SAMPLES });
|
|
155
|
+
const { outDir } = await buildWith(root);
|
|
156
|
+
const emitted = fs.readdirSync(path.join(outDir, "client"));
|
|
157
|
+
|
|
158
|
+
expect(emitted).toHaveLength(1);
|
|
159
|
+
expect(fs.readFileSync(path.join(outDir, "client", emitted[0]), "utf8")).not.toContain("Cart");
|
|
160
|
+
expect(fs.existsSync(path.join(outDir, "samples", "samples.mjs"))).toBe(true);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test("records the state names and the badge in the build context", async () => {
|
|
164
|
+
const root = plugin({
|
|
165
|
+
...BASE,
|
|
166
|
+
"src/theme/views/pages/Cart.samples.js": CART_SAMPLES,
|
|
167
|
+
"src/theme/views/Chip.svelte": PLAIN,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
await buildWith(root);
|
|
171
|
+
|
|
172
|
+
const context = getBuildContext(root);
|
|
173
|
+
|
|
174
|
+
expect(context.views.Cart.samples).toEqual(["filled", "empty", "gifted"]);
|
|
175
|
+
expect(context.views.Chip.samples).toEqual([]);
|
|
176
|
+
expect(context.badges.samples).toBe(true); // the only page has `filled`; Chip is a component
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test("the badge needs filled on every page and block", async () => {
|
|
180
|
+
const root = plugin({
|
|
181
|
+
...BASE,
|
|
182
|
+
"src/theme/views/Banner.svelte": BLOCK,
|
|
183
|
+
"src/theme/views/pages/Cart.samples.js": CART_SAMPLES,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
await buildWith(root);
|
|
187
|
+
expect(getBuildContext(root).badges.samples).toBe(false); // Banner is a block without samples
|
|
188
|
+
|
|
189
|
+
fs.writeFileSync(path.join(root, "src/theme/views/Banner.samples.js"), "export default { empty: {} };\n");
|
|
190
|
+
await buildWith(root);
|
|
191
|
+
expect(getBuildContext(root).badges.samples).toBe(false); // no `filled`
|
|
192
|
+
|
|
193
|
+
fs.writeFileSync(path.join(root, "src/theme/views/Banner.samples.js"), "export default { filled: {} };\n");
|
|
194
|
+
await buildWith(root);
|
|
195
|
+
expect(getBuildContext(root).badges.samples).toBe(true);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test("a plugin without samples gets no file and no badge, and a stale file is removed", async () => {
|
|
199
|
+
const root = plugin({ ...BASE, "src/theme/views/pages/Cart.samples.js": CART_SAMPLES });
|
|
200
|
+
const { outDir } = await buildWith(root);
|
|
201
|
+
|
|
202
|
+
expect(fs.existsSync(path.join(outDir, "samples", "samples.mjs"))).toBe(true);
|
|
203
|
+
|
|
204
|
+
fs.rmSync(path.join(root, "src/theme/views/pages/Cart.samples.js"));
|
|
205
|
+
await buildWith(root);
|
|
206
|
+
|
|
207
|
+
expect(fs.existsSync(path.join(outDir, "samples"))).toBe(false);
|
|
208
|
+
expect(getBuildContext(root).badges.samples).toBe(false);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test("only the client side writes the package", async () => {
|
|
212
|
+
const root = plugin({ ...BASE, "src/theme/views/pages/Cart.samples.js": CART_SAMPLES });
|
|
213
|
+
const { outDir } = await buildWith(root, { side: "server" });
|
|
214
|
+
|
|
215
|
+
expect(fs.existsSync(path.join(outDir, "samples"))).toBe(false);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test("a samples file that imports a package fails with the V3 text", async () => {
|
|
219
|
+
const root = plugin({
|
|
220
|
+
...BASE,
|
|
221
|
+
"src/theme/views/pages/Cart.samples.js": `import dayjs from 'dayjs';\nexport default { filled: { props: { at: dayjs() } } };\n`,
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
await expect(buildWith(root)).rejects.toThrow(/Cart\.samples\.js imports 'dayjs' — sample files are pure data/);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test("a samples file without a default export fails", async () => {
|
|
228
|
+
const root = plugin({ ...BASE, "src/theme/views/pages/Cart.samples.js": `export const notApplicable = [];\n` });
|
|
229
|
+
|
|
230
|
+
await expect(buildWith(root)).rejects.toThrow(/Cart\.samples\.js has no default export/);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test("a state that is neither an object nor a function fails", async () => {
|
|
234
|
+
const root = plugin({ ...BASE, "src/theme/views/pages/Cart.samples.js": `export default { filled: 3 };\n` });
|
|
235
|
+
|
|
236
|
+
await expect(buildWith(root)).rejects.toThrow(/state 'filled' must be an object/);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test("a samples file with no view only warns", async () => {
|
|
240
|
+
const root = plugin({ ...BASE, "src/theme/views/Ghost.samples.js": FULL("Ghost") });
|
|
241
|
+
const { logs } = await buildWith(root);
|
|
242
|
+
|
|
243
|
+
expect(logs.join("\n")).toMatch(/Ghost\.samples\.js belongs to no view/);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test("compileSamples reports a duplicate name through buildSamples", async () => {
|
|
247
|
+
const root = plugin({
|
|
248
|
+
...BASE,
|
|
249
|
+
"src/theme/views/pages/Cart.samples.js": CART_SAMPLES,
|
|
250
|
+
"src/theme/views/other/Cart.samples.js": CART_SAMPLES,
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
await expect(buildWith(root)).rejects.toThrow(/both hold the samples of Cart/);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test("compileSamples bundles fixtures into one module", async () => {
|
|
257
|
+
const root = plugin({ ...BASE, "src/theme/views/pages/Cart.samples.js": CART_SAMPLES });
|
|
258
|
+
const { code } = await compileSamples([{ name: "Cart", file: path.join(root, "src/theme/views/pages/Cart.samples.js") }], root);
|
|
259
|
+
|
|
260
|
+
expect(code).toContain("export { ");
|
|
261
|
+
expect(code).not.toMatch(/\bfrom\s+['"]/);
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
describe("createSampleController with a sample's controllers patch", () => {
|
|
266
|
+
test("starts from the patched state and records the action calls", async () => {
|
|
267
|
+
const root = plugin({ ...BASE, "src/theme/views/pages/Cart.samples.js": CART_SAMPLES });
|
|
268
|
+
const { outDir } = await buildWith(root);
|
|
269
|
+
const sample = (await loadWritten(outDir)).default.Cart.filled;
|
|
270
|
+
const def = defineController({
|
|
271
|
+
name: "cart",
|
|
272
|
+
version: 1,
|
|
273
|
+
state: () => ({ count: 0, lines: [] }),
|
|
274
|
+
actions: ({ update }) => ({
|
|
275
|
+
add: (line) => (update((s) => ({ ...s, lines: [...s.lines, line] })), Promise.resolve({ ok: true })),
|
|
276
|
+
clear: () => Promise.resolve({ ok: true }),
|
|
277
|
+
}),
|
|
278
|
+
});
|
|
279
|
+
const calls = [];
|
|
280
|
+
const controller = createSampleController(def, sample.controllers["demo/cart"], {
|
|
281
|
+
namespace: "demo",
|
|
282
|
+
onCall: (call) => calls.push(call),
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
expect(controller.name).toBe("demo/cart");
|
|
286
|
+
expect(controller.get()).toEqual({ count: 2, lines: [] });
|
|
287
|
+
|
|
288
|
+
await controller.actions.add({ id: 9 });
|
|
289
|
+
await controller.actions.clear();
|
|
290
|
+
|
|
291
|
+
expect(calls).toEqual([
|
|
292
|
+
{ name: "add", args: [{ id: 9 }] },
|
|
293
|
+
{ name: "clear", args: [] },
|
|
294
|
+
]);
|
|
295
|
+
expect(controller.calls).toEqual(calls);
|
|
296
|
+
expect(controller.get()).toEqual({ count: 2, lines: [] }); // fixed state: actions only record
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
describe("pano-plugin samples", () => {
|
|
301
|
+
test("samplesStub has the four standard keys and one line per required prop", () => {
|
|
302
|
+
const stub = samplesStub("Cart", {
|
|
303
|
+
lines: { type: "{ id: number }[]", required: true },
|
|
304
|
+
title: { type: "string", required: true },
|
|
305
|
+
count: { type: "number", required: false },
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
for (const key of ["filled", "empty", "error", "loading"]) expect(stub).toContain(` ${key}: {`);
|
|
309
|
+
|
|
310
|
+
expect(stub.match(/^ {6}lines: \[\],/gm)?.length).toBe(4);
|
|
311
|
+
expect(stub.match(/^ {6}title: '',/gm)?.length).toBe(4);
|
|
312
|
+
expect(stub).not.toContain("count:");
|
|
313
|
+
expect(stub).toContain("export const notApplicable = [];");
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
test("writes the stub next to the view, which then passes --strict", async () => {
|
|
317
|
+
const root = plugin({ ...BASE });
|
|
318
|
+
const lines = [];
|
|
319
|
+
const code = await runSamples({ root, view: "demo:Cart", out: (l) => lines.push(l), err: (l) => lines.push(l) });
|
|
320
|
+
const file = path.join(root, "src/theme/views/pages/Cart.samples.js");
|
|
321
|
+
|
|
322
|
+
expect(code).toBe(0);
|
|
323
|
+
expect(lines).toEqual(["wrote src/theme/views/pages/Cart.samples.js"]);
|
|
324
|
+
expect(fs.readFileSync(file, "utf8")).toContain("lines: [], // { id: number }[], required");
|
|
325
|
+
|
|
326
|
+
// the stub compiles to the four states
|
|
327
|
+
const { outDir } = await buildWith(root);
|
|
328
|
+
|
|
329
|
+
expect((await loadWritten(outDir)).default.Cart).toHaveProperty("loading");
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
test("refuses to overwrite and names unknown views", async () => {
|
|
333
|
+
const root = plugin({ ...BASE, "src/theme/views/pages/Cart.samples.js": CART_SAMPLES });
|
|
334
|
+
const err = [];
|
|
335
|
+
|
|
336
|
+
expect(await runSamples({ root, view: "Cart", err: (l) => err.push(l), out: () => {} })).toBe(1);
|
|
337
|
+
expect(err[0]).toMatch(/Cart\.samples\.js exists already/);
|
|
338
|
+
expect(fs.readFileSync(path.join(root, "src/theme/views/pages/Cart.samples.js"), "utf8")).toBe(CART_SAMPLES);
|
|
339
|
+
|
|
340
|
+
err.length = 0;
|
|
341
|
+
expect(await runSamples({ root, view: "Nope", err: (l) => err.push(l), out: () => {} })).toBe(1);
|
|
342
|
+
expect(err[0]).toMatch(/no view named Nope — the views are Cart, Chip/);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
test("without a name it lists the views with the command as the hint", async () => {
|
|
346
|
+
const root = plugin({ ...BASE, "src/theme/views/pages/Cart.samples.js": CART_SAMPLES });
|
|
347
|
+
const lines = [];
|
|
348
|
+
|
|
349
|
+
expect(await runSamples({ root, out: (l) => lines.push(l), err: () => {} })).toBe(0);
|
|
350
|
+
expect(lines).toEqual(["Cart src/theme/views/pages/Cart.samples.js", "Chip no samples — pano-plugin samples Chip"]);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
test("the pano-plugin binary routes the command", async () => {
|
|
354
|
+
const root = plugin({ ...BASE });
|
|
355
|
+
const previous = process.cwd();
|
|
356
|
+
|
|
357
|
+
process.chdir(root);
|
|
358
|
+
|
|
359
|
+
try {
|
|
360
|
+
const write = process.stdout.write.bind(process.stdout);
|
|
361
|
+
let printed = "";
|
|
362
|
+
|
|
363
|
+
process.stdout.write = (chunk) => ((printed += chunk), true);
|
|
364
|
+
|
|
365
|
+
try {
|
|
366
|
+
expect(await main(["samples", "Chip"])).toBe(0);
|
|
367
|
+
} finally {
|
|
368
|
+
process.stdout.write = write;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
expect(printed).toContain("wrote src/theme/views/Chip.samples.js");
|
|
372
|
+
expect(fs.existsSync(path.join(root, "src/theme/views/Chip.samples.js"))).toBe(true);
|
|
373
|
+
} finally {
|
|
374
|
+
process.chdir(previous);
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
describe("pano-plugin check --strict", () => {
|
|
380
|
+
const complete = {
|
|
381
|
+
...BASE,
|
|
382
|
+
"src/theme/views/pages/Cart.samples.js": CART_SAMPLES,
|
|
383
|
+
"src/theme/views/Chip.samples.js": FULL("Chip"),
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
test("passes when every view has filled and each standard state or a notApplicable entry", async () => {
|
|
387
|
+
const result = await checkSamples({ root: plugin(complete) });
|
|
388
|
+
|
|
389
|
+
expect(result).toEqual({ errors: [], problems: [], notes: [] });
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
test("fails on a view without a samples file, with the command as the hint", async () => {
|
|
393
|
+
const root = plugin({ ...BASE, "src/theme/views/Chip.samples.js": FULL("Chip") });
|
|
394
|
+
const result = await checkSamples({ root });
|
|
395
|
+
|
|
396
|
+
expect(result.problems).toEqual([
|
|
397
|
+
"src/theme/views/pages/Cart.svelte: Cart has no samples file — run: pano-plugin samples Cart",
|
|
398
|
+
]);
|
|
399
|
+
expect(result.notes).toEqual(["Cart has no samples — pano-plugin samples Cart"]);
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
test("fails on a view without filled", async () => {
|
|
403
|
+
const root = plugin({
|
|
404
|
+
...complete,
|
|
405
|
+
"src/theme/views/Chip.samples.js": `export const notApplicable = ['loading', 'error'];\nexport default { empty: { props: { label: '' } } };\n`,
|
|
406
|
+
});
|
|
407
|
+
const result = await checkSamples({ root });
|
|
408
|
+
|
|
409
|
+
expect(result.problems).toEqual([`src/theme/views/Chip.samples.js: Chip has no 'filled' sample — add filled: { props: { ... } }`]);
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
test("fails on a standard state that is neither present nor not applicable", async () => {
|
|
413
|
+
const root = plugin({
|
|
414
|
+
...complete,
|
|
415
|
+
"src/theme/views/Chip.samples.js": `export default { filled: {}, empty: {}, loading: {} };\n`,
|
|
416
|
+
});
|
|
417
|
+
const result = await checkSamples({ root });
|
|
418
|
+
|
|
419
|
+
expect(result.problems).toEqual([
|
|
420
|
+
`src/theme/views/Chip.samples.js: Chip has no 'error' sample — add it, or list 'error' in notApplicable`,
|
|
421
|
+
]);
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
test("rejects a notApplicable that lists filled, an unknown name or a state that exists", async () => {
|
|
425
|
+
const root = plugin({
|
|
426
|
+
...complete,
|
|
427
|
+
"src/theme/views/Chip.samples.js": `export const notApplicable = ['filled', 'nope', 'empty'];\nexport default { filled: {}, empty: {}, error: {}, loading: {} };\n`,
|
|
428
|
+
});
|
|
429
|
+
const result = await checkSamples({ root });
|
|
430
|
+
|
|
431
|
+
expect(result.problems.map((p) => p.replace(/^[^:]+: /, ""))).toEqual([
|
|
432
|
+
"'filled' cannot be listed in notApplicable — every view needs a filled sample",
|
|
433
|
+
"notApplicable names 'nope', which is not a standard state (empty, filled, error, loading)",
|
|
434
|
+
"'empty' is both a sample and in notApplicable — keep one",
|
|
435
|
+
]);
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
test("a samples file with no view is a problem", async () => {
|
|
439
|
+
const root = plugin({ ...complete, "src/theme/views/Ghost.samples.js": FULL("Ghost") });
|
|
440
|
+
|
|
441
|
+
expect((await checkSamples({ root })).problems).toEqual([
|
|
442
|
+
"src/theme/views/Ghost.samples.js belongs to no view — there is no Ghost.svelte; rename the file or remove it",
|
|
443
|
+
]);
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
test("the command: strict fails on a view without filled, plain check only lists the view", async () => {
|
|
447
|
+
const root = plugin({
|
|
448
|
+
...BASE,
|
|
449
|
+
"src/theme/views/Chip.samples.js": `export const notApplicable = ['loading', 'error'];\nexport default { empty: {} };\n`,
|
|
450
|
+
});
|
|
451
|
+
const strict = [];
|
|
452
|
+
const plain = [];
|
|
453
|
+
const run = (strictFlag, sink) =>
|
|
454
|
+
runCheckWithSamples({ root, strict: strictFlag, out: (l) => sink.push(["out", l]), err: (l) => sink.push(["err", l]) });
|
|
455
|
+
|
|
456
|
+
expect(await run(true, strict)).toBe(1);
|
|
457
|
+
expect(strict.some(([, l]) => /Chip has no 'filled' sample/.test(l))).toBe(true);
|
|
458
|
+
expect(strict.some(([, l]) => /Cart has no samples file/.test(l))).toBe(true);
|
|
459
|
+
expect(strict.some(([, l]) => /^check failed: \d+ problems?$/.test(l))).toBe(true);
|
|
460
|
+
|
|
461
|
+
// plain check: the samples are not what fails it, and the view without samples is a note with the hint
|
|
462
|
+
await run(false, plain);
|
|
463
|
+
|
|
464
|
+
const lines = plain.map(([, l]) => l);
|
|
465
|
+
|
|
466
|
+
expect(lines).toContain("note: Cart has no samples — pano-plugin samples Cart");
|
|
467
|
+
expect(lines.join("\n")).not.toMatch(/'filled'/);
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
test("the command passes --strict for a complete plugin", async () => {
|
|
471
|
+
const root = plugin(complete);
|
|
472
|
+
const lines = [];
|
|
473
|
+
const code = await runCheckWithSamples({ root, strict: true, out: (l) => lines.push(l), err: (l) => lines.push(l) });
|
|
474
|
+
const own = lines.filter((l) => /samples|filled/.test(l) && !/^note: pano-api/.test(l));
|
|
475
|
+
|
|
476
|
+
expect(own).toEqual([]);
|
|
477
|
+
expect(lines.some((l) => /^public \(readable\): 2 views/.test(l))).toBe(true);
|
|
478
|
+
// a complete plugin may still fail on something else (the sdk pin of this machine); samples add nothing
|
|
479
|
+
expect([0, 1]).toContain(code);
|
|
480
|
+
});
|
|
481
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { loadConfig, namespaceOf } from "../../../config.js";
|
|
6
|
+
|
|
7
|
+
const dirs = [];
|
|
8
|
+
|
|
9
|
+
function plugin(files) {
|
|
10
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "kit-config-"));
|
|
11
|
+
dirs.push(dir);
|
|
12
|
+
for (const [name, content] of Object.entries(files)) {
|
|
13
|
+
fs.writeFileSync(path.join(dir, name), content);
|
|
14
|
+
}
|
|
15
|
+
return dir;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
delete process.env.PANO_SDK_DIR;
|
|
20
|
+
while (dirs.length) fs.rmSync(dirs.pop(), { recursive: true, force: true });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("namespaceOf", () => {
|
|
24
|
+
test("strips a leading pano-plugin- and nothing else", () => {
|
|
25
|
+
expect(namespaceOf("pano-plugin-market")).toBe("market");
|
|
26
|
+
expect(namespaceOf("pano-plugin-market-payments")).toBe("market-payments");
|
|
27
|
+
expect(namespaceOf("acme-shop")).toBe("acme-shop");
|
|
28
|
+
expect(namespaceOf("my-pano-plugin-x")).toBe("my-pano-plugin-x");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("config.namespace wins", () => {
|
|
32
|
+
expect(namespaceOf("pano-plugin-market", { namespace: "shop" })).toBe("shop");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("reserved and malformed namespaces are refused with the fix", () => {
|
|
36
|
+
expect(() => namespaceOf("pano-plugin-core")).toThrow(/reserved.*pano\.plugin\.js/);
|
|
37
|
+
expect(() => namespaceOf("pano-plugin-x", { namespace: "Bad:Name" })).toThrow(/invalid/);
|
|
38
|
+
expect(() => namespaceOf("")).toThrow(/pluginId is required/);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("loadConfig", () => {
|
|
43
|
+
test("defaults: id from gradle.properties, one view dir, no styles", async () => {
|
|
44
|
+
const dir = plugin({
|
|
45
|
+
"gradle.properties": "# comment\npluginName=Shop\npluginId=pano-plugin-shop\n",
|
|
46
|
+
});
|
|
47
|
+
expect(await loadConfig(dir)).toEqual({
|
|
48
|
+
pluginId: "pano-plugin-shop",
|
|
49
|
+
namespace: "shop",
|
|
50
|
+
viewDirs: ["src/theme/views"],
|
|
51
|
+
styles: {},
|
|
52
|
+
sdkDir: null,
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("pano.plugin.js overrides namespace, viewDirs and styles; PANO_SDK_DIR resolves", async () => {
|
|
57
|
+
const dir = plugin({
|
|
58
|
+
"gradle.properties": "pluginId = pano-plugin-market\n",
|
|
59
|
+
"pano.plugin.js":
|
|
60
|
+
'export default { namespace: "store", viewDirs: ["src/theme/pages/", "src/theme/components"], styles: { safelist: ["fa-x"] } };\n',
|
|
61
|
+
});
|
|
62
|
+
process.env.PANO_SDK_DIR = "../sdk";
|
|
63
|
+
const config = await loadConfig(dir);
|
|
64
|
+
expect(config.namespace).toBe("store");
|
|
65
|
+
expect(config.viewDirs).toEqual(["src/theme/pages", "src/theme/components"]);
|
|
66
|
+
expect(config.styles).toEqual({ safelist: ["fa-x"] });
|
|
67
|
+
expect(config.sdkDir).toBe(path.resolve(dir, "../sdk"));
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("missing pluginId and bad viewDirs name the fix", async () => {
|
|
71
|
+
await expect(loadConfig(plugin({}))).rejects.toThrow(/pluginId=pano-plugin-/);
|
|
72
|
+
const dir = plugin({
|
|
73
|
+
"gradle.properties": "pluginId=pano-plugin-a\n",
|
|
74
|
+
"pano.plugin.js": "export default { viewDirs: [] };\n",
|
|
75
|
+
});
|
|
76
|
+
await expect(loadConfig(dir)).rejects.toThrow(/viewDirs/);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { diffSection, readLock, writeLockSection } from "../../lock.js";
|
|
6
|
+
|
|
7
|
+
const dirs = [];
|
|
8
|
+
const root = () => {
|
|
9
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "kit-lock-"));
|
|
10
|
+
dirs.push(dir);
|
|
11
|
+
return dir;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
while (dirs.length) fs.rmSync(dirs.pop(), { recursive: true, force: true });
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const card = (extra = {}) => ({
|
|
19
|
+
contract: 2,
|
|
20
|
+
props: { product: { required: true }, settings: { required: false } },
|
|
21
|
+
slots: [],
|
|
22
|
+
hooks: [],
|
|
23
|
+
...extra,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe("lock file", () => {
|
|
27
|
+
test("a missing file reads as an empty lock", () => {
|
|
28
|
+
expect(readLock(root())).toEqual({ format: 1 });
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("sections are written sorted, kept apart, and unchanged content is not rewritten", () => {
|
|
32
|
+
const dir = root();
|
|
33
|
+
expect(writeLockSection(dir, "views", { "b:B": { contract: 1 }, "a:A": { contract: 1 } })).toBe(true);
|
|
34
|
+
expect(writeLockSection(dir, "controllers", { "a/x": { version: 1, state: [], actions: [] } })).toBe(true);
|
|
35
|
+
expect(writeLockSection(dir, "views", { "a:A": { contract: 1 }, "b:B": { contract: 1 } })).toBe(false);
|
|
36
|
+
|
|
37
|
+
const text = fs.readFileSync(path.join(dir, "pano-plugin.lock.json"), "utf8");
|
|
38
|
+
expect(text.endsWith("}\n")).toBe(true);
|
|
39
|
+
expect(Object.keys(JSON.parse(text))).toEqual(["controllers", "format", "views"]);
|
|
40
|
+
expect(Object.keys(readLock(dir).views)).toEqual(["a:A", "b:B"]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("malformed JSON names the file and the fix", () => {
|
|
44
|
+
const dir = root();
|
|
45
|
+
fs.writeFileSync(path.join(dir, "pano-plugin.lock.json"), "{ nope");
|
|
46
|
+
expect(() => readLock(dir)).toThrow(/pano-plugin\.lock\.json is not valid JSON.*delete it/);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("diffSection views", () => {
|
|
51
|
+
test("no previous section: changed, nothing breaking", () => {
|
|
52
|
+
expect(diffSection("views", null, { "market:ProductCard": card() })).toEqual({ changed: true, breaking: [] });
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("identical section is unchanged", () => {
|
|
56
|
+
expect(diffSection("views", { "market:ProductCard": card() }, { "market:ProductCard": card() })).toEqual({
|
|
57
|
+
changed: false,
|
|
58
|
+
breaking: [],
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("a removed prop without a raised contract is breaking, with the doc 01 message", () => {
|
|
63
|
+
const next = card({ props: { product: { required: true } } });
|
|
64
|
+
expect(diffSection("views", { "market:ProductCard": card() }, { "market:ProductCard": next }).breaking).toEqual([
|
|
65
|
+
'market:ProductCard: prop "settings" removed — set contract: 3 in ProductCard.svelte (never published? delete pano-plugin.lock.json)',
|
|
66
|
+
]);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("raising the contract makes the same change legal", () => {
|
|
70
|
+
const next = card({ contract: 3, props: { product: { required: true } } });
|
|
71
|
+
const diff = diffSection("views", { "market:ProductCard": card() }, { "market:ProductCard": next });
|
|
72
|
+
expect(diff).toEqual({ changed: true, breaking: [] });
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("a required prop added, slots changed and a removed class are breaking; an optional prop is not", () => {
|
|
76
|
+
const next = card({
|
|
77
|
+
props: { product: { required: true }, settings: { required: false }, extra: { required: true }, nice: { required: false } },
|
|
78
|
+
slots: ["market:card:footer"],
|
|
79
|
+
});
|
|
80
|
+
const messages = diffSection("views", { "market:ProductCard": card() }, { "market:ProductCard": next }).breaking;
|
|
81
|
+
expect(messages.length).toBe(2);
|
|
82
|
+
expect(messages[0]).toContain('required prop "extra" added');
|
|
83
|
+
expect(messages[1]).toContain("slots changed");
|
|
84
|
+
|
|
85
|
+
const withClass = diffSection(
|
|
86
|
+
"views",
|
|
87
|
+
{ "market:ProductCard": card({ classes: ["market-product-card", "market-product-card__title"] }) },
|
|
88
|
+
{ "market:ProductCard": card({ classes: ["market-product-card"] }) },
|
|
89
|
+
);
|
|
90
|
+
expect(withClass.breaking).toEqual([expect.stringContaining("class market-product-card__title removed")]);
|
|
91
|
+
|
|
92
|
+
const optional = card({ props: { product: { required: true }, settings: { required: false }, nice: { required: false } } });
|
|
93
|
+
expect(diffSection("views", { "market:ProductCard": card() }, { "market:ProductCard": optional })).toEqual({
|
|
94
|
+
changed: true,
|
|
95
|
+
breaking: [],
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("a deleted or a new view is never breaking", () => {
|
|
100
|
+
expect(diffSection("views", { "a:Old": card() }, { "a:New": card() })).toEqual({ changed: true, breaking: [] });
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe("diffSection controllers", () => {
|
|
105
|
+
const cart = (extra = {}) => ({ version: 1, state: ["lines", "count"], actions: ["add", "retry"], ...extra });
|
|
106
|
+
|
|
107
|
+
test("a removed action without a raised version is breaking", () => {
|
|
108
|
+
const diff = diffSection("controllers", { "market/cart": cart() }, { "market/cart": cart({ actions: ["add"] }) });
|
|
109
|
+
expect(diff.breaking).toEqual(["market/cart: action 'retry' removed — set version: 2 in src/theme/controllers/cart.js"]);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("a removed state key is breaking; added keys only update the lock", () => {
|
|
113
|
+
const removed = diffSection("controllers", { "market/cart": cart() }, { "market/cart": cart({ state: ["lines"] }) });
|
|
114
|
+
expect(removed.breaking).toEqual([expect.stringContaining("state 'count' removed")]);
|
|
115
|
+
|
|
116
|
+
const added = diffSection("controllers", { "market/cart": cart() }, { "market/cart": cart({ actions: ["add", "retry", "clear"] }) });
|
|
117
|
+
expect(added).toEqual({ changed: true, breaking: [] });
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("a raised version allows the removal", () => {
|
|
121
|
+
const diff = diffSection("controllers", { "market/cart": cart() }, { "market/cart": cart({ version: 2, actions: ["add"] }) });
|
|
122
|
+
expect(diff.breaking).toEqual([]);
|
|
123
|
+
});
|
|
124
|
+
});
|