@n6k.io/build 0.0.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.
- package/README.md +71 -0
- package/package.json +102 -0
- package/src/cli.ts +29 -0
- package/src/index.ts +1 -0
- package/src/pipeline/build.ts +301 -0
- package/src/pipeline/html.test.ts +173 -0
- package/src/pipeline/imports.test.ts +95 -0
- package/src/pipeline/imports.ts +129 -0
- package/src/pipeline/layouts.ts +39 -0
- package/src/pipeline/preprocess.test.ts +137 -0
- package/src/pipeline/preprocess.ts +212 -0
- package/src/storybook/decorators.tsx +93 -0
- package/src/storybook/index.ts +13 -0
- package/src/storybook/preview.ts +17 -0
- package/src/storybook/seed-demo-data.ts +206 -0
- package/src/storybook/story-shell.tsx +21 -0
- package/src/templates/contents-mdx.hbs +9 -0
- package/src/templates/entry.hbs +4 -0
- package/src/templates/page.hbs +18 -0
- package/src/util/logger.ts +42 -0
- package/src/vite/cross-origin.ts +19 -0
- package/src/vite/index.ts +6 -0
- package/src/vite/wasm.ts +67 -0
- package/src/vite/workers.ts +91 -0
- package/src/wasm/extensions.ts +32 -0
- package/src/workers/manifest.ts +53 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { build as esbuild } from "esbuild";
|
|
5
|
+
|
|
6
|
+
// The worker SET itself is owned by the driver (@n6k.io/db/workers) — it defines
|
|
7
|
+
// which workers exist, their sources, output filenames, and canonical URLs. We
|
|
8
|
+
// re-export it so build's consumers keep importing from @n6k.io/build, and add
|
|
9
|
+
// the build-time helpers (dev URL map, virtual-module ids, source resolution,
|
|
10
|
+
// esbuild bundling) that are specific to this pipeline.
|
|
11
|
+
export {
|
|
12
|
+
N6K_WORKER_ENTRIES,
|
|
13
|
+
N6K_WORKERS_URL_PREFIX,
|
|
14
|
+
n6kWorkerUrl,
|
|
15
|
+
type N6kWorkerEntry,
|
|
16
|
+
} from "@n6k.io/db/workers";
|
|
17
|
+
import { N6K_WORKER_ENTRIES, n6kWorkerUrl } from "@n6k.io/db/workers";
|
|
18
|
+
|
|
19
|
+
// Stable dev URLs → driver source, used by dev middleware to re-bundle on demand.
|
|
20
|
+
export const N6K_WORKER_DEV_URLS: Record<string, string> = Object.fromEntries(
|
|
21
|
+
N6K_WORKER_ENTRIES.map((e) => [n6kWorkerUrl(e.file), e.src]),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export const N6K_WORKERS_VIRTUAL_ID = "virtual:n6k-workers";
|
|
25
|
+
export const N6K_WORKERS_RESOLVED_ID = "\0virtual:n6k-workers";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Resolve a path inside the linked `@n6k.io/db` package from a path relative to
|
|
29
|
+
* its package root. `@n6k.io/db/package.json` isn't in the package's exports
|
|
30
|
+
* map, so walk up from a subpath that IS exported until we find the root.
|
|
31
|
+
*/
|
|
32
|
+
export function resolveN6kWorkerSource(relativePath: string): string {
|
|
33
|
+
const require = createRequire(import.meta.url);
|
|
34
|
+
const wasmDirEntry = require.resolve("@n6k.io/db/wasm-dir");
|
|
35
|
+
let pkgRoot = path.dirname(wasmDirEntry);
|
|
36
|
+
while (pkgRoot !== path.dirname(pkgRoot)) {
|
|
37
|
+
if (fs.existsSync(path.join(pkgRoot, "package.json"))) break;
|
|
38
|
+
pkgRoot = path.dirname(pkgRoot);
|
|
39
|
+
}
|
|
40
|
+
return path.join(pkgRoot, relativePath);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Bundle one worker entry to a self-contained IIFE string via esbuild. */
|
|
44
|
+
export async function bundleN6kWorker(src: string): Promise<string> {
|
|
45
|
+
const result = await esbuild({
|
|
46
|
+
entryPoints: [src],
|
|
47
|
+
bundle: true,
|
|
48
|
+
format: "iife",
|
|
49
|
+
target: "esnext",
|
|
50
|
+
write: false,
|
|
51
|
+
});
|
|
52
|
+
return result.outputFiles[0].text;
|
|
53
|
+
}
|