kopular 0.21.0 → 0.21.1

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.
Files changed (3) hide show
  1. package/LLM.md +5 -2
  2. package/package.json +1 -1
  3. package/src/testing.js +20 -7
package/LLM.md CHANGED
@@ -636,7 +636,7 @@ import { runKopularApp } from "kopular/testing";
636
636
 
637
637
  const { window, cleanup } = await runKopularApp(srcDir, "app.ks", {
638
638
  includeKopularPackage: true, // app consumes Kopular via `extern`, not relative `using`
639
- extraFiles: ["http_runtime.js"], // non-.ks/.html siblings a `using` graph needs at runtime
639
+ extraFiles: ["config.json"], // any sibling with an extension besides .ks/.html/.js
640
640
  fetchMock: (...args) => Promise.resolve({ ok: true, status: 200, text: () => Promise.resolve("body") }),
641
641
  url: "http://localhost/",
642
642
  });
@@ -650,7 +650,10 @@ try {
650
650
  Compiles `entryFileName` (plus everything else in `srcDir` it `using`s) via kopscript's
651
651
  `compileGraph`, binds jsdom onto `globalThis` (`document`/`Element`/`Event`/`location`/
652
652
  `history`/`window`/`fetch`) for the compiled ambient `extern` declarations to find, and
653
- runs it. `runKopularFixture(source, options)` is the sibling export for an inline fixture
653
+ runs it. Every `.ks`/`.html`/`.js` file in `srcDir` is copied along with it `.js`
654
+ included specifically so a hand-written (not compiled) sibling like a `Router.AddLazyRoute`
655
+ loader shim just works with no extra setup; `extraFiles` is only for a real dependency with
656
+ some OTHER extension (e.g. a `.json` config file). `runKopularFixture(source, options)` is the sibling export for an inline fixture
654
657
  string instead of a real file (used by Kopular's own test suite; copies Kopular's *own*
655
658
  `.ks` sources alongside the fixture, so `using "./component"` resolves — only meaningful
656
659
  for testing Kopular itself, not an external consumer, which should use `runKopularApp`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kopular",
3
- "version": "0.21.0",
3
+ "version": "0.21.1",
4
4
  "description": "Kopular: a small component framework for KopScript — components, reactive state, constructor-injected services, routing, real compiled templates, and HTTP, with no DI container",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/testing.js CHANGED
@@ -39,13 +39,25 @@ const OWN_SRC_DIR = dirname(fileURLToPath(import.meta.url));
39
39
  // than anything wrong with the copied files themselves.
40
40
  const TEMP_ROOT = join(OWN_SRC_DIR, "..", ".kopular-testing-tmp");
41
41
 
42
- // Copies every .ks/.html file from `srcDir` into `dir`, plus any filename
43
- // listed in `extraFiles` (e.g. http_runtime.js a hand-written sibling a
44
- // compiled `using` graph needs at runtime, which the compiler wouldn't know
45
- // to copy on its own).
42
+ // Copies every .ks/.html/.js file from `srcDir` into `dir`, plus any
43
+ // filename listed in `extraFiles` for anything with a different extension.
44
+ // `.js` is included alongside `.ks`/`.html` (not just left to `extraFiles`)
45
+ // because a hand-written, not-compiled-from-`.ks` companion file is a
46
+ // real, documented pattern now, not a one-off — most commonly a dynamic-
47
+ // `import()` loader shim for `Router.AddLazyRoute` (see kopscript's own
48
+ // LLM.md/README.md "extern" section, and Kopular's own "Lazy routes"
49
+ // docs), reached via a RELATIVE `extern ... from "./whatever";` the test
50
+ // author can't always know the exact filename of in advance — unlike
51
+ // http_runtime.js (a fixed name Kopular itself ships and controls, still
52
+ // the right fit for `extraFiles`), an app's own loader shim can be named
53
+ // anything. Any pre-existing `.js` with the same name as a `.ks` file
54
+ // gets harmlessly overwritten moments later by that `.ks`'s own fresh
55
+ // compiled output — copying it first only matters for a `.js` with no
56
+ // `.ks` counterpart at all, which is exactly the hand-written case this
57
+ // exists for.
46
58
  function copySources(srcDir, dir, extraFiles) {
47
59
  for (const name of readdirSync(srcDir)) {
48
- if (name.endsWith(".ks") || name.endsWith(".html") || extraFiles.includes(name)) {
60
+ if (name.endsWith(".ks") || name.endsWith(".html") || name.endsWith(".js") || extraFiles.includes(name)) {
49
61
  cpSync(join(srcDir, name), join(dir, name));
50
62
  }
51
63
  }
@@ -155,8 +167,9 @@ async function compileAndRun(dir, entryFileName, options) {
155
167
  * installed `kopular` package into a temp node_modules/, for an entry
156
168
  * that consumes Kopular via `extern ... from "kopular/..."` rather than
157
169
  * relative `using`. Default false.
158
- * @param {string[]} [options.extraFiles] - extra filenames (not .ks/.html)
159
- * to copy from srcDir, e.g. ["http_runtime.js"].
170
+ * @param {string[]} [options.extraFiles] - extra filenames to copy from
171
+ * srcDir beyond .ks/.html/.js (which are always copied), for anything
172
+ * with a different extension.
160
173
  * @param {(...args: unknown[]) => unknown} [options.fetchMock] - replaces
161
174
  * the global `fetch` for the duration of the run, for testing `Http`.
162
175
  * @param {string} [options.url] - the jsdom document's URL. Default