@skathi-native/cli 0.1.0-beta.4 → 0.3.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/aot/host-globals.json +1 -1
- package/aot/pin.ts +1 -1
- package/aot/toolchain.lock.json +5 -5
- package/aot/transform.ts +9 -1
- package/aot-inputs.ts +21 -2
- package/build.ts +284 -64
- package/check/builtins.json +11 -11
- package/check/bundle.ts +265 -0
- package/check/codes.ts +46 -0
- package/check/css-catalog.json +451 -0
- package/check/css.ts +512 -0
- package/check/finding.ts +63 -1
- package/check/graph.ts +14 -1
- package/check/index.ts +30 -49
- package/check/program.ts +26 -6
- package/cli/aot-build.ts +2 -6
- package/cli/build-app.ts +19 -0
- package/cli/create.ts +70 -12
- package/cli/dev.ts +11 -6
- package/cli/effects.ts +39 -18
- package/cli/gallery.ts +106 -0
- package/cli/sk.ts +5 -2
- package/devtools/commands.ts +26 -1
- package/devtools/ctl.ts +4 -3
- package/effects/compile.ts +160 -31
- package/effects/sk.slang +359 -30
- package/gallery.json +1 -0
- package/package.json +9 -5
- package/prod.ts +78 -10
- package/svelte.ts +76 -0
- package/templates/icon.png +0 -0
- package/templates/showcase/assets/textures/golden.png +0 -0
- package/templates/showcase/assets/textures/hammered.png +0 -0
- package/templates/showcase/assets/textures/noir.png +0 -0
- package/templates/showcase/assets/textures/reeded.png +0 -0
- package/templates/showcase/assets/textures/teal-orange.png +0 -0
- package/templates/showcase/shaders/dissolve.slang +40 -0
- package/templates/showcase/shaders/fireflies.slang +58 -0
- package/templates/showcase/shaders/glass.slang +31 -0
- package/templates/showcase/shaders/grade.slang +34 -0
- package/templates/showcase/shaders/halftone.slang +42 -0
- package/templates/showcase/shaders/lens.slang +51 -0
- package/templates/showcase/shaders/nebula.slang +57 -0
- package/templates/showcase/shaders/orbit.slang +52 -0
- package/templates/showcase/shaders/pond.slang +76 -0
- package/templates/showcase/shaders/ripples.slang +71 -0
- package/templates/showcase/shaders/shatter.slang +116 -0
- package/templates/showcase/shaders/snow.slang +57 -0
- package/templates/showcase/shaders/spotlight.slang +52 -0
- package/templates/showcase/src/App.vue +11 -16
- package/templates/showcase/src/components/FullWindow.vue +77 -0
- package/templates/showcase/src/components/Page.vue +2 -0
- package/templates/showcase/src/fullwindow.ts +36 -0
- package/templates/showcase/src/icons.ts +2 -0
- package/templates/showcase/src/pages/GraphicsPage.vue +122 -0
- package/templates/showcase/src/pages/MotionPage.vue +71 -1
- package/templates/showcase/src/pages/ShadersPage.vue +443 -0
- package/templates/showcase/src/router.ts +32 -1
- package/templates/svelte/.vscode/settings.json +3 -0
- package/templates/svelte/assets/hello.txt +1 -0
- package/templates/svelte/src/App.svelte +142 -0
- package/templates/svelte/src/main.ts +4 -0
- package/vitecompat.ts +2 -0
package/build.ts
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
//
|
|
4
4
|
// dist/vendor.js IIFE: @vue/runtime-core + src/runtime.ts + src/loader.ts.
|
|
5
5
|
// dist/modules/<enc>.js one classic script per app module; <enc> is the id with "/" -> "__".
|
|
6
|
-
// dist/manifest.json { rev, vendorRev, entry, modules, deps }
|
|
6
|
+
// dist/manifest.json { rev, vendorRev, entry, appRoot, modules, deps }
|
|
7
7
|
// dist/changes.json { rev, vendorRev, changed: [{ id, kind }] }
|
|
8
8
|
//
|
|
9
9
|
// Module ids are workspace-relative POSIX paths. Change kind: script or <style> scoped/module/lang
|
|
10
10
|
// shape changed -> "reload"; template -> "rerender" (state survives); <style> text only ->
|
|
11
|
-
// "css-only"; non-.vue source -> "reload"
|
|
11
|
+
// "css-only"; non-.vue source -> "reload"; an npm module already loaded that now belongs to a
|
|
12
|
+
// rebuilt package group -> "restart".
|
|
12
13
|
// hoistStatic and inlineTemplate are forced off: the host has no insertStaticContent, and an inline
|
|
13
14
|
// render inside setup() could not be swapped without losing state.
|
|
14
15
|
// npm dependencies are one shared module per package entry (inlining per importer breaks
|
|
@@ -53,6 +54,10 @@ import {
|
|
|
53
54
|
viteShapesPlugin,
|
|
54
55
|
} from "./vitecompat";
|
|
55
56
|
import { colorEnabled, paint } from "./cli/term";
|
|
57
|
+
import { parseCheckConfig } from "./check/config";
|
|
58
|
+
import { CssWarnings } from "./check/css";
|
|
59
|
+
import { diagnosticLine } from "./check/finding";
|
|
60
|
+
import { SVELTE_SOURCE, compileSvelte } from "./svelte";
|
|
56
61
|
|
|
57
62
|
const C = paint(colorEnabled(process.stdout));
|
|
58
63
|
const styled = (rest: (text: string) => string) => (text: string) => {
|
|
@@ -75,7 +80,7 @@ const APP_SRC_DIR = dirname(ENTRY_ABS);
|
|
|
75
80
|
const DIST = resolve(positional[1] ?? join(PKG_DIR, "dist"));
|
|
76
81
|
const MODULES_DIR = join(DIST, "modules");
|
|
77
82
|
|
|
78
|
-
const SOURCE_EXT = /\.(vue|js|ts|mjs)$/;
|
|
83
|
+
const SOURCE_EXT = /\.(vue|svelte|js|ts|mjs)$/;
|
|
79
84
|
|
|
80
85
|
// The window block of sk.config.json is copied verbatim into the manifest: the host reads it
|
|
81
86
|
// before the window opens, the only time creation-time options can be set without a flash.
|
|
@@ -322,7 +327,8 @@ const DEFINES: Record<string, string> = {
|
|
|
322
327
|
// by Bun while parsing.
|
|
323
328
|
"import.meta.env.SK": "true",
|
|
324
329
|
"import.meta.env": JSON.stringify(VITE_ENV_DEV),
|
|
325
|
-
//
|
|
330
|
+
// Undefined in the vendor bundle and npm modules (library code guards on it); an app module gets its own
|
|
331
|
+
// (`MODULE_DEFINES`).
|
|
326
332
|
"import.meta.hot": "undefined",
|
|
327
333
|
"import.meta.url": '"sk://module"',
|
|
328
334
|
// Leftover import.meta.glob calls are defined to a findable name so buildModule can fail clearly.
|
|
@@ -331,6 +337,9 @@ const DEFINES: Record<string, string> = {
|
|
|
331
337
|
...APP_DEFINES.defines,
|
|
332
338
|
};
|
|
333
339
|
|
|
340
|
+
// An app module's `import.meta.hot` is the loader's per-module HMR context.
|
|
341
|
+
const MODULE_DEFINES: Record<string, string> = { ...DEFINES, "import.meta.hot": "module.hot" };
|
|
342
|
+
|
|
334
343
|
function writeAtomic(path: string, text: string) {
|
|
335
344
|
const tmp = path + ".tmp";
|
|
336
345
|
writeFileSync(tmp, text);
|
|
@@ -342,10 +351,6 @@ function ensureDirs() {
|
|
|
342
351
|
}
|
|
343
352
|
|
|
344
353
|
async function buildVendor() {
|
|
345
|
-
for (const [name, dep] of FRAMEWORK) {
|
|
346
|
-
if (dep.warning) devAdvise(dep.warning);
|
|
347
|
-
say(`${stamp()} ${name} ${dep.version ?? "unknown"}: the ${dep.from === "app" ? "app's" : "runtime's"} copy`);
|
|
348
|
-
}
|
|
349
354
|
const result = await Bun.build({
|
|
350
355
|
entrypoints: [LOADER_ENTRY],
|
|
351
356
|
format: "iife",
|
|
@@ -353,15 +358,10 @@ async function buildVendor() {
|
|
|
353
358
|
define: DEFINES,
|
|
354
359
|
plugins: [
|
|
355
360
|
{
|
|
356
|
-
//
|
|
357
|
-
// bun 1.4 crashes on catch-all onResolve filters.
|
|
361
|
+
// "vue" is our runtime. Exact-match filter only: bun 1.4 crashes on catch-all onResolve filters.
|
|
358
362
|
name: "vendor-vue-alias",
|
|
359
363
|
setup(b: Bun.PluginBuilder) {
|
|
360
364
|
b.onResolve({ filter: /^vue$/ }, () => ({ path: RUNTIME_ENTRY }));
|
|
361
|
-
// The app owns these packages in dev and prod; mixing majors breaks store/router identity.
|
|
362
|
-
b.onResolve({ filter: /^(vue-router|pinia)$/ }, (args: Bun.OnResolveArgs) => ({
|
|
363
|
-
path: FRAMEWORK.get(args.path)!.path,
|
|
364
|
-
}));
|
|
365
365
|
},
|
|
366
366
|
},
|
|
367
367
|
],
|
|
@@ -394,8 +394,18 @@ function devAdvise(m: string) {
|
|
|
394
394
|
warn(`${stamp()} advisory: ${m}`);
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
+
/** Every .css file the dev build has read, @imports too: what the CSS warnings watch. */
|
|
398
|
+
const styleSheets = new Set<string>();
|
|
399
|
+
|
|
400
|
+
function inlineImports(text: string, from: string): string {
|
|
401
|
+
const seen = new Set([resolve(from)]);
|
|
402
|
+
const css = inlineCssImports(text, from, SK_CONFIG_DIR, devAdvise, seen);
|
|
403
|
+
for (const file of seen) if (/\.css$/i.test(file)) styleSheets.add(file);
|
|
404
|
+
return css;
|
|
405
|
+
}
|
|
406
|
+
|
|
397
407
|
async function viteCss(text: string, from: string, label: string): Promise<string> {
|
|
398
|
-
const css =
|
|
408
|
+
const css = inlineImports(text, from);
|
|
399
409
|
if (!TW_CONFIG || !needsTailwindPass(css)) return css;
|
|
400
410
|
try {
|
|
401
411
|
return await generateTailwind(TW_CONFIG, { text: css, from });
|
|
@@ -504,6 +514,18 @@ const vuePlugin = {
|
|
|
504
514
|
const source = await Bun.file(args.path).text();
|
|
505
515
|
return compileVue(args.path, source);
|
|
506
516
|
});
|
|
517
|
+
// A package's Svelte components (the runtime's `<SkWindow>`, a component library), compiled as the app's are,
|
|
518
|
+
// without HMR: a package module is rebuilt whole.
|
|
519
|
+
build.onLoad({ filter: SVELTE_SOURCE }, async (args: Bun.OnLoadArgs) => {
|
|
520
|
+
const id = toId(args.path);
|
|
521
|
+
const out = await compileSvelte(APP_ROOT, args.path, await Bun.file(args.path).text(), {
|
|
522
|
+
dev: false,
|
|
523
|
+
filename: id,
|
|
524
|
+
});
|
|
525
|
+
for (const w of out.warnings) devAdvise(w);
|
|
526
|
+
if (out.css) devAdvise(`${id}: a package component's <style> is applied by sk build, not by sk dev`);
|
|
527
|
+
return { contents: out.js, loader: "js" as const };
|
|
528
|
+
});
|
|
507
529
|
},
|
|
508
530
|
};
|
|
509
531
|
|
|
@@ -543,6 +565,16 @@ const appModulePlugin = {
|
|
|
543
565
|
const code = transformSource(out.contents, args.path, DEV_SHAPES);
|
|
544
566
|
return code === null ? out : { ...out, contents: code };
|
|
545
567
|
});
|
|
568
|
+
build.onLoad({ filter: SVELTE_SOURCE }, async (args: Bun.OnLoadArgs) => {
|
|
569
|
+
const id = toId(args.path);
|
|
570
|
+
const out = await compileSvelte(APP_ROOT, args.path, await Bun.file(args.path).text(), {
|
|
571
|
+
dev: true,
|
|
572
|
+
filename: id,
|
|
573
|
+
});
|
|
574
|
+
for (const w of out.warnings) devAdvise(w);
|
|
575
|
+
capturedCss = out.css ? pruneVendorPrefixes(await viteCss(out.css, args.path, `${id} <style>`)) : null;
|
|
576
|
+
return { contents: transformSource(out.js, args.path, DEV_SHAPES) ?? out.js, loader: "js" as const };
|
|
577
|
+
});
|
|
546
578
|
},
|
|
547
579
|
};
|
|
548
580
|
|
|
@@ -552,7 +584,20 @@ const appModulePlugin = {
|
|
|
552
584
|
|
|
553
585
|
const REQUIRE_RE = /\brequire\(\s*("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')\s*\)/g;
|
|
554
586
|
|
|
555
|
-
const CANDIDATE_EXTS = [
|
|
587
|
+
const CANDIDATE_EXTS = [
|
|
588
|
+
"",
|
|
589
|
+
".js",
|
|
590
|
+
".ts",
|
|
591
|
+
".mjs",
|
|
592
|
+
".vue",
|
|
593
|
+
".svelte",
|
|
594
|
+
".svelte.ts",
|
|
595
|
+
".svelte.js",
|
|
596
|
+
"/index.js",
|
|
597
|
+
"/index.ts",
|
|
598
|
+
"/index.vue",
|
|
599
|
+
"/index.svelte",
|
|
600
|
+
];
|
|
556
601
|
|
|
557
602
|
function normalizeId(path: string): string {
|
|
558
603
|
const out: string[] = [];
|
|
@@ -588,7 +633,10 @@ function depsOf(id: string, body: string, ids: Set<string>, skip: Set<string>):
|
|
|
588
633
|
if (spec === null || spec.charCodeAt(0) !== 46 /* . */) continue; // bare -> vendor
|
|
589
634
|
if (skip.has(spec)) continue; // a stylesheet: its own synthetic module
|
|
590
635
|
const base = normalizeId((dir ? dir + "/" : "") + spec);
|
|
591
|
-
|
|
636
|
+
// TypeScript's ESM spelling: `./x.js` names `x.ts`.
|
|
637
|
+
const hit = CANDIDATE_EXTS.map((ext) => base + ext)
|
|
638
|
+
.concat(base.endsWith(".js") ? [base.slice(0, -3) + ".ts"] : [])
|
|
639
|
+
.find((cand) => ids.has(cand));
|
|
592
640
|
if (!hit) {
|
|
593
641
|
warn(`${stamp()} ${id}: import ${J(spec)} resolves to no built module — ` + `require() will throw at runtime`);
|
|
594
642
|
continue;
|
|
@@ -606,7 +654,7 @@ function bareOf(body: string, skip: Set<string>): string[] {
|
|
|
606
654
|
if (spec === null) continue;
|
|
607
655
|
const c = spec.charCodeAt(0);
|
|
608
656
|
if (c === 46 /* . */ || c === 47 /* / */) continue; // relative/absolute -> graph
|
|
609
|
-
if (isPreseeded(spec) || found.includes(spec) || skip.has(spec)) continue;
|
|
657
|
+
if ((isPreseeded(spec) && !FRAMEWORK.has(spec)) || found.includes(spec) || skip.has(spec)) continue;
|
|
610
658
|
found.push(spec);
|
|
611
659
|
}
|
|
612
660
|
return found;
|
|
@@ -661,7 +709,7 @@ const cssIds = () => Array.from(cssModules.keys());
|
|
|
661
709
|
*/
|
|
662
710
|
async function buildCssModule(id: string): Promise<boolean> {
|
|
663
711
|
const abs = cssModules.get(id)!;
|
|
664
|
-
let css =
|
|
712
|
+
let css = inlineImports(readFileSync(abs, "utf-8"), abs);
|
|
665
713
|
if (TW_CONFIG && needsTailwindPass(css)) {
|
|
666
714
|
const t0 = Date.now();
|
|
667
715
|
try {
|
|
@@ -733,7 +781,7 @@ async function buildModule(absPath: string, ids: Set<string>) {
|
|
|
733
781
|
target: "node",
|
|
734
782
|
external: ["*"],
|
|
735
783
|
plugins: [devShapesPlugin, devImports, appModulePlugin],
|
|
736
|
-
define:
|
|
784
|
+
define: MODULE_DEFINES,
|
|
737
785
|
});
|
|
738
786
|
} finally {
|
|
739
787
|
inlinedNow = null;
|
|
@@ -780,11 +828,18 @@ async function buildModule(absPath: string, ids: Set<string>) {
|
|
|
780
828
|
// npm modules: one per package ENTRY, keyed on the resolved directory (not the name), so every
|
|
781
829
|
// importer of a directory shares it and a nested copy at another version stays separate. The id
|
|
782
830
|
// is the specifier when the app resolves it to that directory, else `<spec>~<hash of the directory>`.
|
|
831
|
+
// Two or more entries of one package (`svelte`, `svelte/internal/client`) share module state through
|
|
832
|
+
// relative imports: they are bundled together into one group module, and each entry's module reads
|
|
833
|
+
// its namespace from it.
|
|
783
834
|
|
|
784
835
|
const npmBuilt = new Map<string, number>();
|
|
785
836
|
const npmFailed = new Set<string>();
|
|
786
|
-
const npmEntries = new Map<string, { spec: string; from: string }>();
|
|
837
|
+
const npmEntries = new Map<string, { spec: string; from: string; root: string | null }>();
|
|
787
838
|
const npmBare = new Map<string, string[]>();
|
|
839
|
+
/** Package root -> its group module's id and members. */
|
|
840
|
+
const npmGroups = new Map<string, { id: string; members: string[] }>();
|
|
841
|
+
/** npm id -> the group module it was last built as a member of, "" when built alone. */
|
|
842
|
+
const npmShape = new Map<string, string>();
|
|
788
843
|
|
|
789
844
|
function splitSpec(spec: string): [string, string] {
|
|
790
845
|
const parts = spec.split("/");
|
|
@@ -832,20 +887,34 @@ function npmIdOf(spec: string, abs: string, from: string): string {
|
|
|
832
887
|
appKeys.set(spec, appKey);
|
|
833
888
|
}
|
|
834
889
|
const id = key === appKey ? spec : `${spec}~${Bun.hash(key).toString(16).slice(0, 8)}`;
|
|
835
|
-
if (!npmEntries.has(id))
|
|
890
|
+
if (!npmEntries.has(id)) {
|
|
891
|
+
npmEntries.set(id, { spec, from: id === spec ? APP_ROOT : from, root: packageRootOf(abs, splitSpec(spec)[0]) });
|
|
892
|
+
}
|
|
836
893
|
return id;
|
|
837
894
|
}
|
|
838
895
|
|
|
839
|
-
|
|
896
|
+
/** A file of the package at `root` itself, not of one installed beneath it. */
|
|
897
|
+
function inPackage(abs: string, root: string): boolean {
|
|
898
|
+
const rel = relative(root, abs);
|
|
899
|
+
return !!rel && !rel.startsWith("..") && !isAbsolute(rel) && !rel.split(sep).includes("node_modules");
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
function npmSharePlugin(selfKey: string, selfRoot: string | null, found: Set<string>) {
|
|
840
903
|
return {
|
|
841
904
|
name: "sk-dev-npm-share",
|
|
842
905
|
setup(build: Bun.PluginBuilder) {
|
|
843
906
|
build.onResolve({ filter: /^(?!node:)[^./\\]/ }, (args: Bun.OnResolveArgs) => {
|
|
844
|
-
if (args.kind === "entry-point-build" || isAbsolute(args.path)
|
|
907
|
+
if (args.kind === "entry-point-build" || isAbsolute(args.path)) return undefined;
|
|
908
|
+
// Every importer lands on the one copy: the vendor bundle's, or the framework module built on demand.
|
|
909
|
+
if (isPreseeded(args.path)) {
|
|
910
|
+
if (FRAMEWORK.has(args.path)) found.add(args.path);
|
|
911
|
+
return { path: args.path, external: true };
|
|
912
|
+
}
|
|
845
913
|
const from = importerDir(args, APP_ROOT);
|
|
846
914
|
const abs = resolveImport(args.path, from);
|
|
847
915
|
if (abs === null || !isAbsolute(abs) || /\.css$/i.test(abs) || LEAF_IMPORT.test(abs)) return undefined;
|
|
848
|
-
|
|
916
|
+
// The package's own `#imports` and self-references are part of it, as its relative imports are.
|
|
917
|
+
if (npmKey(args.path, abs) === selfKey || (selfRoot && inPackage(abs, selfRoot))) return undefined;
|
|
849
918
|
const id = npmIdOf(args.path, abs, from);
|
|
850
919
|
found.add(id);
|
|
851
920
|
return { path: id, external: true };
|
|
@@ -854,25 +923,60 @@ function npmSharePlugin(selfKey: string, found: Set<string>) {
|
|
|
854
923
|
};
|
|
855
924
|
}
|
|
856
925
|
|
|
926
|
+
function noteUnresolved(id: string, spec: string, from: string): void {
|
|
927
|
+
if (npmFailed.has(id)) return;
|
|
928
|
+
npmFailed.add(id);
|
|
929
|
+
const alias = !/^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*(?:\/|$)/i.test(spec);
|
|
930
|
+
warn(
|
|
931
|
+
`${stamp()} cannot resolve ${J(spec)} from ${toId(from)} — ` +
|
|
932
|
+
`require(${J(id)}) will throw at runtime ` +
|
|
933
|
+
(alias
|
|
934
|
+
? "(an import alias resolves through tsconfig.json compilerOptions.paths, as in sk build; " +
|
|
935
|
+
"a vite.config resolve.alias is not read)"
|
|
936
|
+
: "(is it installed?)"),
|
|
937
|
+
);
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
const npmHash = new Map<string, string>();
|
|
941
|
+
|
|
942
|
+
/** Writes an npm module script; true when its body differs from the last one written under this id. */
|
|
943
|
+
function writeNpmModule(id: string, what: string, body: string): boolean {
|
|
944
|
+
moduleDeps.set(id, []);
|
|
945
|
+
// Constant unless the package changes, so a rebuild never invalidates module-scope singletons.
|
|
946
|
+
const hash = Bun.hash(body).toString(16);
|
|
947
|
+
writeAtomic(
|
|
948
|
+
join(MODULES_DIR, encId(id)),
|
|
949
|
+
[
|
|
950
|
+
`// Skathi module: ${id} (${what})`,
|
|
951
|
+
`__SK__.setDeps && __SK__.setDeps(${J(id)}, []);`,
|
|
952
|
+
`__SK__.define(${J(id)}, function (require, module, exports) {`,
|
|
953
|
+
body,
|
|
954
|
+
`}, ${J(hash)});`,
|
|
955
|
+
].join("\n"),
|
|
956
|
+
);
|
|
957
|
+
npmBuilt.set(id, body.length);
|
|
958
|
+
const changed = npmHash.get(id) !== hash;
|
|
959
|
+
npmHash.set(id, hash);
|
|
960
|
+
return changed;
|
|
961
|
+
}
|
|
962
|
+
|
|
857
963
|
async function buildNpmModule(id: string): Promise<boolean> {
|
|
858
964
|
const { spec, from } = npmEntries.get(id) ?? { spec: id, from: APP_ROOT };
|
|
859
|
-
|
|
965
|
+
// vue-router and pinia: the copy the app declares (else the runtime's), like the production bundle.
|
|
966
|
+
const framework = FRAMEWORK.get(id);
|
|
967
|
+
if (framework) {
|
|
968
|
+
if (framework.warning) devAdvise(framework.warning);
|
|
969
|
+
say(
|
|
970
|
+
`${stamp()} ${id} ${framework.version ?? "unknown"}: the ${framework.from === "app" ? "app's" : "runtime's"} copy`,
|
|
971
|
+
);
|
|
972
|
+
}
|
|
973
|
+
const candidates = framework ? [framework.path] : await entryCandidates(spec, from);
|
|
860
974
|
if (!candidates.length) {
|
|
861
|
-
|
|
862
|
-
npmFailed.add(id);
|
|
863
|
-
const alias = !/^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*(?:\/|$)/i.test(spec);
|
|
864
|
-
warn(
|
|
865
|
-
`${stamp()} cannot resolve ${J(spec)} from ${toId(from)} — ` +
|
|
866
|
-
`require(${J(id)}) will throw at runtime ` +
|
|
867
|
-
(alias
|
|
868
|
-
? "(an import alias resolves through tsconfig.json compilerOptions.paths, as in sk build; " +
|
|
869
|
-
"a vite.config resolve.alias is not read)"
|
|
870
|
-
: "(is it installed?)"),
|
|
871
|
-
);
|
|
872
|
-
}
|
|
975
|
+
noteUnresolved(id, spec, from);
|
|
873
976
|
return false;
|
|
874
977
|
}
|
|
875
978
|
const selfKey = npmKey(spec, candidates[0]!);
|
|
979
|
+
const selfRoot = packageRootOf(candidates[0]!, splitSpec(spec)[0]);
|
|
876
980
|
const requires = new Set<string>();
|
|
877
981
|
let result: Awaited<ReturnType<typeof Bun.build>> | null = null;
|
|
878
982
|
let entry = candidates[0]!;
|
|
@@ -886,7 +990,7 @@ async function buildNpmModule(id: string): Promise<boolean> {
|
|
|
886
990
|
// Pre-seeded ids plus every other package entry stay external. A dependency can ship raw .vue
|
|
887
991
|
// source: without the SFC plugin Bun treats it as an asset and the import silently renders
|
|
888
992
|
// nothing.
|
|
889
|
-
plugins: [npmShapesPlugin, npmSharePlugin(selfKey, requires), vuePlugin],
|
|
993
|
+
plugins: [npmShapesPlugin, npmSharePlugin(selfKey, selfRoot, requires), vuePlugin],
|
|
890
994
|
define: DEFINES,
|
|
891
995
|
}).catch(() => null);
|
|
892
996
|
if (result?.success) break;
|
|
@@ -898,24 +1002,87 @@ async function buildNpmModule(id: string): Promise<boolean> {
|
|
|
898
1002
|
for (const log of result?.logs ?? []) console.error(log);
|
|
899
1003
|
throw new Error(`npm module build failed: ${id}`);
|
|
900
1004
|
}
|
|
901
|
-
const body = tagModuleNamespaces(await result.outputs[0]!.text()).code;
|
|
902
|
-
moduleDeps.set(id, []);
|
|
903
1005
|
npmBare.set(id, Array.from(requires).sort());
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
`__SK__.define(${J(id)}, function (require, module, exports) {`,
|
|
910
|
-
body,
|
|
911
|
-
// Constant unless the package changes, so a rebuild never invalidates module-scope singletons.
|
|
912
|
-
`}, ${J(Bun.hash(body).toString(16))});`,
|
|
913
|
-
].join("\n"),
|
|
1006
|
+
npmShape.set(id, "");
|
|
1007
|
+
writeNpmModule(
|
|
1008
|
+
id,
|
|
1009
|
+
`npm dependency, bundled from ${toId(entry)}`,
|
|
1010
|
+
tagModuleNamespaces(await result.outputs[0]!.text()).code,
|
|
914
1011
|
);
|
|
915
|
-
npmBuilt.set(id, body.length);
|
|
916
1012
|
return true;
|
|
917
1013
|
}
|
|
918
1014
|
|
|
1015
|
+
const GROUP_ENTRY = "__sk_npm_group__.js";
|
|
1016
|
+
|
|
1017
|
+
/** Bundles the entries `members` of the package at `root` into one module: the members it built, and whether that module changed. */
|
|
1018
|
+
async function buildNpmGroup(root: string, members: string[]): Promise<{ built: string[]; changed: boolean }> {
|
|
1019
|
+
const lists: string[][] = [];
|
|
1020
|
+
const built: string[] = [];
|
|
1021
|
+
for (const id of members) {
|
|
1022
|
+
const { spec, from } = npmEntries.get(id)!;
|
|
1023
|
+
const candidates = await entryCandidates(spec, from);
|
|
1024
|
+
if (!candidates.length) {
|
|
1025
|
+
noteUnresolved(id, spec, from);
|
|
1026
|
+
continue;
|
|
1027
|
+
}
|
|
1028
|
+
lists.push(candidates);
|
|
1029
|
+
built.push(id);
|
|
1030
|
+
}
|
|
1031
|
+
if (!built.length) return { built, changed: false };
|
|
1032
|
+
const gid = `${pkgNameAt.get(root) ?? toId(root)}~pkg~${Bun.hash(toId(root)).toString(16).slice(0, 8)}`;
|
|
1033
|
+
const probe = join(root, GROUP_ENTRY); // never written: the plugin answers for it
|
|
1034
|
+
const requires = new Set<string>();
|
|
1035
|
+
let result: Awaited<ReturnType<typeof Bun.build>> | null = null;
|
|
1036
|
+
const attempts = Math.max(...lists.map((l) => l.length));
|
|
1037
|
+
for (let i = 0; i < attempts; i++) {
|
|
1038
|
+
const source = lists.map((l, k) => `export * as e${k} from ${J(l[Math.min(i, l.length - 1)])};`).join("\n");
|
|
1039
|
+
requires.clear();
|
|
1040
|
+
result = await Bun.build({
|
|
1041
|
+
entrypoints: [probe],
|
|
1042
|
+
format: "cjs",
|
|
1043
|
+
target: "browser",
|
|
1044
|
+
plugins: [
|
|
1045
|
+
{
|
|
1046
|
+
name: "sk-npm-group-entry",
|
|
1047
|
+
setup(b: Bun.PluginBuilder) {
|
|
1048
|
+
b.onResolve({ filter: /__sk_npm_group__\.js$/ }, () => ({ path: probe }));
|
|
1049
|
+
b.onLoad({ filter: /__sk_npm_group__\.js$/ }, () => ({ contents: source, loader: "js" }));
|
|
1050
|
+
},
|
|
1051
|
+
},
|
|
1052
|
+
npmShapesPlugin,
|
|
1053
|
+
npmSharePlugin("", root, requires),
|
|
1054
|
+
vuePlugin,
|
|
1055
|
+
],
|
|
1056
|
+
define: DEFINES,
|
|
1057
|
+
}).catch(() => null);
|
|
1058
|
+
if (result?.success) break;
|
|
1059
|
+
}
|
|
1060
|
+
if (!result?.success) {
|
|
1061
|
+
for (const log of result?.logs ?? []) console.error(log);
|
|
1062
|
+
throw new Error(`npm module build failed: ${built.join(", ")} (bundled together as ${gid})`);
|
|
1063
|
+
}
|
|
1064
|
+
npmBare.set(gid, Array.from(requires).sort());
|
|
1065
|
+
const changed = writeNpmModule(
|
|
1066
|
+
gid,
|
|
1067
|
+
`npm dependency, the entries ${built.join(", ")} of ${toId(root)}`,
|
|
1068
|
+
tagModuleNamespaces(await result.outputs[0]!.text()).code,
|
|
1069
|
+
);
|
|
1070
|
+
for (const [k, id] of built.entries()) {
|
|
1071
|
+
// An ES module's namespace is the module; a CommonJS entry's is its `module.exports`, as when built alone.
|
|
1072
|
+
writeNpmModule(
|
|
1073
|
+
id,
|
|
1074
|
+
`npm dependency, entry of ${gid}`,
|
|
1075
|
+
`var ns = require(${J(gid)}).e${k};\n` +
|
|
1076
|
+
'module.exports = ns && ns[Symbol.toStringTag] === "Module" ? ' +
|
|
1077
|
+
'Object.defineProperty(ns, "__esModule", { value: true }) : ns && ns.default;',
|
|
1078
|
+
);
|
|
1079
|
+
npmBare.set(id, [gid]);
|
|
1080
|
+
npmShape.set(id, gid);
|
|
1081
|
+
}
|
|
1082
|
+
npmGroups.set(root, { id: gid, members: built });
|
|
1083
|
+
return { built, changed };
|
|
1084
|
+
}
|
|
1085
|
+
|
|
919
1086
|
const npmIds = () => Array.from(npmBuilt.keys()).sort();
|
|
920
1087
|
|
|
921
1088
|
function wantedNpm(): Set<string> {
|
|
@@ -930,16 +1097,50 @@ function wantedNpm(): Set<string> {
|
|
|
930
1097
|
return wanted;
|
|
931
1098
|
}
|
|
932
1099
|
|
|
933
|
-
|
|
1100
|
+
/** `added`: npm modules new to the build; `regrouped`: ones already built that now belong to a new group module (a running app holds the old copy). */
|
|
1101
|
+
async function syncNpmModules(): Promise<{ added: string[]; regrouped: string[] }> {
|
|
934
1102
|
const added: string[] = [];
|
|
1103
|
+
const regrouped: string[] = [];
|
|
935
1104
|
const tried = new Set<string>();
|
|
936
|
-
for (
|
|
937
|
-
|
|
938
|
-
|
|
1105
|
+
for (let progress = true; progress;) {
|
|
1106
|
+
progress = false;
|
|
1107
|
+
const wanted = wantedNpm();
|
|
1108
|
+
const groupIds = new Set(Array.from(npmGroups.values(), (g) => g.id));
|
|
1109
|
+
const byRoot = new Map<string, string[]>();
|
|
1110
|
+
for (const id of wanted) {
|
|
1111
|
+
const root = groupIds.has(id) ? null : npmEntries.get(id)?.root;
|
|
1112
|
+
if (root) byRoot.set(root, [...(byRoot.get(root) ?? []), id]);
|
|
1113
|
+
}
|
|
1114
|
+
for (const [root, ids] of byRoot) {
|
|
1115
|
+
const known = npmGroups.get(root)?.members ?? [];
|
|
1116
|
+
// A member that went away leaves the group as it is; a new one rebuilds it.
|
|
1117
|
+
if (ids.length < 2 && !known.length) continue;
|
|
1118
|
+
if (ids.every((id) => known.includes(id) && npmBuilt.has(id))) continue;
|
|
1119
|
+
const members = Array.from(new Set([...known, ...ids])).sort();
|
|
1120
|
+
const key = members.join("\n");
|
|
1121
|
+
if (tried.has(key)) continue;
|
|
1122
|
+
tried.add(key);
|
|
1123
|
+
progress = true;
|
|
1124
|
+
const before = new Set(members.filter((id) => npmBuilt.has(id)));
|
|
1125
|
+
const shapeBefore = new Map(members.map((id) => [id, npmShape.get(id)]));
|
|
1126
|
+
const t0 = Date.now();
|
|
1127
|
+
const { built, changed } = await buildNpmGroup(root, members);
|
|
1128
|
+
for (const id of built) {
|
|
1129
|
+
if (!before.has(id)) added.push(id);
|
|
1130
|
+
else if (changed || shapeBefore.get(id) !== npmShape.get(id)) regrouped.push(id);
|
|
1131
|
+
}
|
|
1132
|
+
if (built.length) say(`${stamp()} npm ${built.join(", ")}: bundled together in ${Date.now() - t0} ms`);
|
|
1133
|
+
}
|
|
1134
|
+
const grouped = (id: string) => {
|
|
1135
|
+
const root = npmEntries.get(id)?.root;
|
|
1136
|
+
return !!root && npmGroups.has(root);
|
|
1137
|
+
};
|
|
1138
|
+
const todo = Array.from(wanted)
|
|
1139
|
+
.filter((id) => !npmBuilt.has(id) && !tried.has(id) && !groupIds.has(id) && !grouped(id))
|
|
939
1140
|
.sort();
|
|
940
|
-
if (!todo.length) break;
|
|
941
1141
|
for (const id of todo) {
|
|
942
1142
|
tried.add(id);
|
|
1143
|
+
progress = true;
|
|
943
1144
|
const t0 = Date.now();
|
|
944
1145
|
if (!(await buildNpmModule(id))) continue;
|
|
945
1146
|
added.push(id);
|
|
@@ -952,12 +1153,14 @@ async function syncNpmModules(): Promise<string[]> {
|
|
|
952
1153
|
if (wanted.has(id)) continue;
|
|
953
1154
|
npmBuilt.delete(id);
|
|
954
1155
|
npmBare.delete(id);
|
|
1156
|
+
npmShape.delete(id);
|
|
955
1157
|
moduleDeps.delete(id);
|
|
956
1158
|
try {
|
|
957
1159
|
rmSync(join(MODULES_DIR, encId(id)));
|
|
958
1160
|
} catch {}
|
|
959
1161
|
}
|
|
960
|
-
|
|
1162
|
+
for (const [root, group] of npmGroups) if (!npmBuilt.has(group.id)) npmGroups.delete(root);
|
|
1163
|
+
return { added: added.filter((id) => npmBuilt.has(id)), regrouped: regrouped.filter((id) => npmBuilt.has(id)) };
|
|
961
1164
|
}
|
|
962
1165
|
|
|
963
1166
|
const TW_CONFIG = findConfig(appRootArg ? APP_ROOT : APP_SRC_DIR, ID_ROOT);
|
|
@@ -987,7 +1190,7 @@ async function buildTailwind(): Promise<boolean> {
|
|
|
987
1190
|
}
|
|
988
1191
|
|
|
989
1192
|
type Blocks = { src: string; script: string; template: string; styleShape: string; styleText: string };
|
|
990
|
-
type Kind = "reload" | "rerender" | "css-only";
|
|
1193
|
+
type Kind = "reload" | "rerender" | "css-only" | "restart";
|
|
991
1194
|
|
|
992
1195
|
const prevBlocks = new Map<string, Blocks>(); // abs path -> blocks
|
|
993
1196
|
|
|
@@ -1055,6 +1258,7 @@ function writeManifest(files: string[]) {
|
|
|
1055
1258
|
rev,
|
|
1056
1259
|
vendorRev,
|
|
1057
1260
|
entry: toId(ENTRY_ABS),
|
|
1261
|
+
appRoot: appRootArg ? APP_ROOT : SK_CONFIG_DIR,
|
|
1058
1262
|
name: readAppName(),
|
|
1059
1263
|
modules: ids,
|
|
1060
1264
|
assetFiles: Object.fromEntries(
|
|
@@ -1094,6 +1298,9 @@ async function fullBuild(reason: string) {
|
|
|
1094
1298
|
npmBuilt.clear(); // force a rewrite: the module files may not exist yet
|
|
1095
1299
|
npmBare.clear();
|
|
1096
1300
|
npmEntries.clear();
|
|
1301
|
+
npmGroups.clear();
|
|
1302
|
+
npmShape.clear();
|
|
1303
|
+
npmHash.clear();
|
|
1097
1304
|
appKeys.clear();
|
|
1098
1305
|
pkgNameAt.clear();
|
|
1099
1306
|
cssModules.clear();
|
|
@@ -1162,10 +1369,10 @@ async function incrementalBuild() {
|
|
|
1162
1369
|
structural = true;
|
|
1163
1370
|
}
|
|
1164
1371
|
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1372
|
+
const npm = await syncNpmModules();
|
|
1373
|
+
for (const id of npm.added) changed.push({ id, kind: "reload" });
|
|
1374
|
+
for (const id of npm.regrouped) changed.push({ id, kind: "restart" });
|
|
1375
|
+
if (npm.added.length || npm.regrouped.length) structural = true;
|
|
1169
1376
|
|
|
1170
1377
|
// Always re-run Tailwind: any content file can add a utility, and a stylesheet that went
|
|
1171
1378
|
// through Tailwind is re-emitted on the same signal.
|
|
@@ -1181,7 +1388,19 @@ async function incrementalBuild() {
|
|
|
1181
1388
|
);
|
|
1182
1389
|
}
|
|
1183
1390
|
|
|
1184
|
-
|
|
1391
|
+
const cssWarnings = new CssWarnings({
|
|
1392
|
+
root: appRootArg ? APP_ROOT : SK_CONFIG_DIR,
|
|
1393
|
+
allow: parseCheckConfig(readSkConfig()?.check).allow,
|
|
1394
|
+
tailwind: TW_CONFIG !== null,
|
|
1395
|
+
});
|
|
1396
|
+
|
|
1397
|
+
/** CSS the engine does not apply, in the styles that changed; each warning once per session. */
|
|
1398
|
+
function reportCss() {
|
|
1399
|
+
const components = [...prevBlocks.keys()].filter((f) => /\.(vue|svelte)$/i.test(f));
|
|
1400
|
+
for (const d of cssWarnings.update([...components, ...styleSheets])) warn(`${stamp()} ${diagnosticLine(d)}`);
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
await fullBuild("startup").then(reportCss, (e) => {
|
|
1185
1404
|
console.error(e);
|
|
1186
1405
|
if (!WATCH) process.exit(1);
|
|
1187
1406
|
});
|
|
@@ -1201,6 +1420,7 @@ if (WATCH) {
|
|
|
1201
1420
|
try {
|
|
1202
1421
|
if (full) await fullBuild("runtime source changed");
|
|
1203
1422
|
else await incrementalBuild();
|
|
1423
|
+
reportCss();
|
|
1204
1424
|
} catch (e) {
|
|
1205
1425
|
fail(`${stamp()} ${String(e)}`);
|
|
1206
1426
|
}
|
package/check/builtins.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"table": "
|
|
3
|
-
"engine": "
|
|
2
|
+
"table": "a9db25bde548594d86b2439e8dfd11335a87004ee374a31e2d1a557c40543886",
|
|
3
|
+
"engine": "3bc94211496460feda299ef85eef710eb67fafb3",
|
|
4
4
|
"locked": [
|
|
5
5
|
"AggregateError.prototype",
|
|
6
6
|
"Array",
|
|
@@ -997,7 +997,8 @@
|
|
|
997
997
|
"WeakRef.prototype.deref",
|
|
998
998
|
"WebAssembly",
|
|
999
999
|
"WebAssembly.CompileError",
|
|
1000
|
-
"WebAssembly.CompileError.prototype.
|
|
1000
|
+
"WebAssembly.CompileError.prototype.message",
|
|
1001
|
+
"WebAssembly.CompileError.prototype.name",
|
|
1001
1002
|
"WebAssembly.Exception",
|
|
1002
1003
|
"WebAssembly.Exception.prototype.getArg",
|
|
1003
1004
|
"WebAssembly.Exception.prototype.is",
|
|
@@ -1009,7 +1010,8 @@
|
|
|
1009
1010
|
"WebAssembly.Instance.prototype.exports",
|
|
1010
1011
|
"WebAssembly.JSTag",
|
|
1011
1012
|
"WebAssembly.LinkError",
|
|
1012
|
-
"WebAssembly.LinkError.prototype.
|
|
1013
|
+
"WebAssembly.LinkError.prototype.message",
|
|
1014
|
+
"WebAssembly.LinkError.prototype.name",
|
|
1013
1015
|
"WebAssembly.Memory",
|
|
1014
1016
|
"WebAssembly.Memory.prototype.buffer",
|
|
1015
1017
|
"WebAssembly.Memory.prototype.grow",
|
|
@@ -1020,9 +1022,11 @@
|
|
|
1020
1022
|
"WebAssembly.Module.exports",
|
|
1021
1023
|
"WebAssembly.Module.imports",
|
|
1022
1024
|
"WebAssembly.RuntimeError",
|
|
1023
|
-
"WebAssembly.RuntimeError.prototype.
|
|
1025
|
+
"WebAssembly.RuntimeError.prototype.message",
|
|
1026
|
+
"WebAssembly.RuntimeError.prototype.name",
|
|
1024
1027
|
"WebAssembly.SuspendError",
|
|
1025
|
-
"WebAssembly.SuspendError.prototype.
|
|
1028
|
+
"WebAssembly.SuspendError.prototype.message",
|
|
1029
|
+
"WebAssembly.SuspendError.prototype.name",
|
|
1026
1030
|
"WebAssembly.Suspending",
|
|
1027
1031
|
"WebAssembly.Table",
|
|
1028
1032
|
"WebAssembly.Table.prototype.get",
|
|
@@ -1050,7 +1054,7 @@
|
|
|
1050
1054
|
"parseInt",
|
|
1051
1055
|
"unescape"
|
|
1052
1056
|
],
|
|
1053
|
-
"lockedObjects": ["Object.prototype"
|
|
1057
|
+
"lockedObjects": ["Object.prototype"],
|
|
1054
1058
|
"objects": [
|
|
1055
1059
|
"AggregateError",
|
|
1056
1060
|
"AggregateError.prototype",
|
|
@@ -1187,7 +1191,6 @@
|
|
|
1187
1191
|
"WebAssembly",
|
|
1188
1192
|
"WebAssembly.CompileError",
|
|
1189
1193
|
"WebAssembly.CompileError.prototype",
|
|
1190
|
-
"WebAssembly.CompileError.prototype.constructor",
|
|
1191
1194
|
"WebAssembly.Exception",
|
|
1192
1195
|
"WebAssembly.Exception.prototype",
|
|
1193
1196
|
"WebAssembly.Global",
|
|
@@ -1196,17 +1199,14 @@
|
|
|
1196
1199
|
"WebAssembly.Instance.prototype",
|
|
1197
1200
|
"WebAssembly.LinkError",
|
|
1198
1201
|
"WebAssembly.LinkError.prototype",
|
|
1199
|
-
"WebAssembly.LinkError.prototype.constructor",
|
|
1200
1202
|
"WebAssembly.Memory",
|
|
1201
1203
|
"WebAssembly.Memory.prototype",
|
|
1202
1204
|
"WebAssembly.Module",
|
|
1203
1205
|
"WebAssembly.Module.prototype",
|
|
1204
1206
|
"WebAssembly.RuntimeError",
|
|
1205
1207
|
"WebAssembly.RuntimeError.prototype",
|
|
1206
|
-
"WebAssembly.RuntimeError.prototype.constructor",
|
|
1207
1208
|
"WebAssembly.SuspendError",
|
|
1208
1209
|
"WebAssembly.SuspendError.prototype",
|
|
1209
|
-
"WebAssembly.SuspendError.prototype.constructor",
|
|
1210
1210
|
"WebAssembly.Suspending",
|
|
1211
1211
|
"WebAssembly.Suspending.prototype",
|
|
1212
1212
|
"WebAssembly.Table",
|