@g3nomaly/ui 0.3.3 → 0.3.5
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 +49 -26
- package/dist/cli/adapter.d.ts +25 -8
- package/dist/cli/adapter.d.ts.map +1 -1
- package/dist/cli/adapter.js +34 -20
- package/dist/cli/adapter.js.map +1 -1
- package/dist/cli/afterInstall.d.ts +26 -0
- package/dist/cli/afterInstall.d.ts.map +1 -0
- package/dist/cli/afterInstall.js +54 -0
- package/dist/cli/afterInstall.js.map +1 -0
- package/dist/cli/commands/add.d.ts +8 -2
- package/dist/cli/commands/add.d.ts.map +1 -1
- package/dist/cli/commands/add.js +10 -5
- package/dist/cli/commands/add.js.map +1 -1
- package/dist/cli/commands/index.d.ts +1 -0
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +1 -0
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/init.d.ts +16 -5
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +59 -13
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/ls.d.ts +1 -1
- package/dist/cli/commands/ls.js +1 -1
- package/dist/cli/commands/ls.js.map +1 -1
- package/dist/cli/commands/manifest.js +1 -1
- package/dist/cli/commands/manifest.js.map +1 -1
- package/dist/cli/commands/source.d.ts +4 -1
- package/dist/cli/commands/source.d.ts.map +1 -1
- package/dist/cli/commands/source.js +29 -2
- package/dist/cli/commands/source.js.map +1 -1
- package/dist/cli/commands/sourceInit.d.ts +9 -0
- package/dist/cli/commands/sourceInit.d.ts.map +1 -0
- package/dist/cli/commands/sourceInit.js +78 -0
- package/dist/cli/commands/sourceInit.js.map +1 -0
- package/dist/cli/commands/update.d.ts +10 -3
- package/dist/cli/commands/update.d.ts.map +1 -1
- package/dist/cli/commands/update.js +9 -4
- package/dist/cli/commands/update.js.map +1 -1
- package/dist/cli/index.js +17 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/localSources.d.ts +12 -0
- package/dist/cli/localSources.d.ts.map +1 -0
- package/dist/cli/localSources.js +49 -0
- package/dist/cli/localSources.js.map +1 -0
- package/dist/cli/npmDependencies.d.ts +11 -0
- package/dist/cli/npmDependencies.d.ts.map +1 -0
- package/dist/cli/npmDependencies.js +73 -0
- package/dist/cli/npmDependencies.js.map +1 -0
- package/dist/cli/packageFiles.d.ts +15 -0
- package/dist/cli/packageFiles.d.ts.map +1 -0
- package/dist/cli/packageFiles.js +54 -0
- package/dist/cli/packageFiles.js.map +1 -0
- package/dist/cli/themeTokens.d.ts +12 -0
- package/dist/cli/themeTokens.d.ts.map +1 -0
- package/dist/cli/themeTokens.js +60 -0
- package/dist/cli/themeTokens.js.map +1 -0
- package/dist/packages/dependencies.d.ts +48 -0
- package/dist/packages/dependencies.d.ts.map +1 -0
- package/dist/packages/dependencies.js +66 -0
- package/dist/packages/dependencies.js.map +1 -0
- package/dist/packages/install.d.ts +30 -0
- package/dist/packages/install.d.ts.map +1 -0
- package/dist/packages/install.js +54 -0
- package/dist/packages/install.js.map +1 -0
- package/dist/packages/localPack.d.ts +48 -0
- package/dist/packages/localPack.d.ts.map +1 -0
- package/dist/packages/localPack.js +72 -0
- package/dist/packages/localPack.js.map +1 -0
- package/dist/registry/adapters/shadcn.adapter.d.ts +32 -7
- package/dist/registry/adapters/shadcn.adapter.d.ts.map +1 -1
- package/dist/registry/adapters/shadcn.adapter.js +75 -20
- package/dist/registry/adapters/shadcn.adapter.js.map +1 -1
- package/dist/registry/adapters/shadcnImports.d.ts +10 -0
- package/dist/registry/adapters/shadcnImports.d.ts.map +1 -0
- package/dist/registry/adapters/shadcnImports.js +18 -0
- package/dist/registry/adapters/shadcnImports.js.map +1 -0
- package/dist/registry/componentsJson.d.ts +6 -1
- package/dist/registry/componentsJson.d.ts.map +1 -1
- package/dist/registry/componentsJson.js +34 -1
- package/dist/registry/componentsJson.js.map +1 -1
- package/dist/registry/index.d.ts +1 -1
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js +1 -1
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/manifest.d.ts +2 -13
- package/dist/registry/manifest.d.ts.map +1 -1
- package/dist/registry/manifest.js +4 -76
- package/dist/registry/manifest.js.map +1 -1
- package/dist/registry/packageExports.d.ts +9 -0
- package/dist/registry/packageExports.d.ts.map +1 -0
- package/dist/registry/packageExports.js +50 -0
- package/dist/registry/packageExports.js.map +1 -0
- package/dist/registry/packageImports.d.ts +23 -0
- package/dist/registry/packageImports.d.ts.map +1 -0
- package/dist/registry/packageImports.js +51 -0
- package/dist/registry/packageImports.js.map +1 -0
- package/dist/registry/readSource.d.ts +4 -2
- package/dist/registry/readSource.d.ts.map +1 -1
- package/dist/registry/readSource.js +27 -3
- package/dist/registry/readSource.js.map +1 -1
- package/dist/registry/types.d.ts +86 -3
- package/dist/registry/types.d.ts.map +1 -1
- package/dist/registry/types.js +46 -3
- package/dist/registry/types.js.map +1 -1
- package/dist/sources/builtins.d.ts +1 -5
- package/dist/sources/builtins.d.ts.map +1 -1
- package/dist/sources/builtins.js +2 -7
- package/dist/sources/builtins.js.map +1 -1
- package/dist/theme/cssVars.d.ts +43 -0
- package/dist/theme/cssVars.d.ts.map +1 -0
- package/dist/theme/cssVars.js +107 -0
- package/dist/theme/cssVars.js.map +1 -0
- package/dist/theme/detectCssFile.d.ts +9 -0
- package/dist/theme/detectCssFile.d.ts.map +1 -0
- package/dist/theme/detectCssFile.js +41 -0
- package/dist/theme/detectCssFile.js.map +1 -0
- package/package.json +8 -21
- package/template/build.ts +32 -0
- package/template/package.json +22 -0
- package/template/src/components/example/Example.css +20 -0
- package/template/src/components/example/Example.tsx +26 -0
- package/template/src/components/example/example.meta.ts +69 -0
- package/dist/components/basic/Card.css +0 -32
- package/dist/components/basic/Card.debug.ts +0 -5
- package/dist/components/basic/Card.tsx +0 -31
- package/dist/components/basic/CardFooter.css +0 -16
- package/dist/components/basic/CardFooter.debug.ts +0 -5
- package/dist/components/basic/CardFooter.tsx +0 -29
- package/dist/components/basic/CardHeader.css +0 -14
- package/dist/components/basic/CardHeader.debug.ts +0 -5
- package/dist/components/basic/CardHeader.tsx +0 -29
- package/dist/components/basic/card.meta.ts +0 -14
- package/dist/components/basic/cardfooter.meta.ts +0 -14
- package/dist/components/basic/cardheader.meta.ts +0 -14
- package/dist/components/input/Button.css +0 -34
- package/dist/components/input/Button.debug.ts +0 -5
- package/dist/components/input/Button.tsx +0 -28
- package/dist/components/input/button.meta.ts +0 -14
- package/dist/components.json +0 -138
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// packages/ui/src/packages/install.ts
|
|
2
|
+
/**
|
|
3
|
+
* @brief Runs `bun` with the given arguments in a folder.
|
|
4
|
+
*
|
|
5
|
+
* @param cwd - Absolute folder to run in.
|
|
6
|
+
* @param args - Arguments after `bun`, e.g. `["add", "radix-ui"]`.
|
|
7
|
+
* @returns Its stdout, and the error it printed when it failed.
|
|
8
|
+
*/
|
|
9
|
+
async function runBun(cwd, args) {
|
|
10
|
+
const proc = Bun.spawn([process.execPath, ...args], { cwd, stdout: "pipe", stderr: "pipe" });
|
|
11
|
+
const [stdout, stderr, exitCode] = await Promise.all([new Response(proc.stdout).text(), new Response(proc.stderr).text(), proc.exited]);
|
|
12
|
+
if (exitCode === 0)
|
|
13
|
+
return { stdout: stdout.trim() };
|
|
14
|
+
return { stdout: stdout.trim(), error: stderr.trim() || `bun ${args[0] ?? ""} exited with ${exitCode}` };
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @brief Runs `bun add` in the project for the given specs, with `-d` for build-time packages.
|
|
18
|
+
*
|
|
19
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
20
|
+
* @param specs - Specs to add, e.g. `["radix-ui", "recharts@3.8.0"]`.
|
|
21
|
+
* @param dev - Add them as `devDependencies`.
|
|
22
|
+
* @returns `undefined` on success, else the error `bun add` printed.
|
|
23
|
+
*/
|
|
24
|
+
export async function bunAdd(projectRoot, specs, dev) {
|
|
25
|
+
if (specs.length === 0)
|
|
26
|
+
return undefined;
|
|
27
|
+
return (await runBun(projectRoot, ["add", ...(dev ? ["-d"] : []), ...specs])).error;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @brief Runs `bun remove` in the project for one package.
|
|
31
|
+
*
|
|
32
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
33
|
+
* @param pkg - Package to remove, e.g. `my-ui`.
|
|
34
|
+
* @returns `undefined` on success, else the error `bun remove` printed.
|
|
35
|
+
*/
|
|
36
|
+
export async function bunRemove(projectRoot, pkg) {
|
|
37
|
+
return (await runBun(projectRoot, ["remove", pkg])).error;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @brief Packs a package folder with `bun pm pack`, which runs its `prepack` script first and keeps
|
|
41
|
+
* only what its `files` field lists, so the tarball holds no `node_modules`.
|
|
42
|
+
*
|
|
43
|
+
* @param folder - Absolute folder holding the package's `package.json`.
|
|
44
|
+
* @returns The tarball's file name inside `folder`, e.g. `my-ui-0.3.0.tgz`, or the error `bun pm pack` printed.
|
|
45
|
+
*/
|
|
46
|
+
export async function bunPack(folder) {
|
|
47
|
+
const result = await runBun(folder, ["pm", "pack", "--quiet"]);
|
|
48
|
+
if (result.error !== undefined)
|
|
49
|
+
return { error: result.error };
|
|
50
|
+
// `--quiet` prints only the file name, but the output of a `prepack` script comes before it.
|
|
51
|
+
const tarball = result.stdout.split("\n").map((line) => line.trim()).filter(Boolean).at(-1);
|
|
52
|
+
return tarball === undefined ? { error: "bun pm pack printed no tarball name" } : { tarball };
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=install.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.js","sourceRoot":"","sources":["../../src/packages/install.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAatC;;;;;;GAMG;AACH,KAAK,UAAU,MAAM,CAAC,GAAW,EAAE,IAAu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AAW,EAAE,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC5D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,MAAc;IAC1C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IAC/D,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;IAC/D,6FAA6F;IAC7F,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5F,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,qCAAqC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC;AAChG,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brief A package the app installs from a folder on disk.
|
|
3
|
+
*
|
|
4
|
+
* @property folder - Absolute folder holding the package's `package.json`.
|
|
5
|
+
* @property declared - The range the app's `package.json` gives it, e.g. `file:../my-ui`.
|
|
6
|
+
* @property tarball - Absolute path of the tarball the app installs, when it installs a packed copy rather than a link to the folder.
|
|
7
|
+
*/
|
|
8
|
+
export interface LocalPackage {
|
|
9
|
+
folder: string;
|
|
10
|
+
declared: string;
|
|
11
|
+
tarball?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @brief Where the app installs a package from, when that is a folder on disk: a `file:` or `link:`
|
|
15
|
+
* range naming the folder itself, or a tarball packed inside it.
|
|
16
|
+
*
|
|
17
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
18
|
+
* @param pkg - Package name, e.g. `my-ui`.
|
|
19
|
+
* @returns The folder, or `null` when the app installs the package from a registry, git or a workspace,
|
|
20
|
+
* or the folder holds a different package.
|
|
21
|
+
*/
|
|
22
|
+
export declare function localPackage(projectRoot: string, pkg: string): LocalPackage | null;
|
|
23
|
+
/**
|
|
24
|
+
* @brief The outcome of `installPackedCopy`.
|
|
25
|
+
*
|
|
26
|
+
* @property installed - The range now in `package.json`, e.g. `file:../my-ui/my-ui-0.3.0.tgz`; absent when nothing changed.
|
|
27
|
+
* @property error - What failed; the app keeps what it had.
|
|
28
|
+
*/
|
|
29
|
+
export interface PackResult {
|
|
30
|
+
installed?: string;
|
|
31
|
+
error?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @brief Installs a packed copy of a local package in place of a link to its folder, or refreshes the
|
|
35
|
+
* copy. A linked folder brings its own `node_modules`, so files the app imports from it load the folder's
|
|
36
|
+
* packages, such as a second React; a packed copy holds only what the package's `files` field lists.
|
|
37
|
+
*
|
|
38
|
+
* Packs the folder with `bun pm pack` (which runs its `prepack` script), then removes the package and
|
|
39
|
+
* adds the tarball: Bun keeps an old copy when a tarball is replaced under the same name. A tarball
|
|
40
|
+
* identical to the one already installed is left as is.
|
|
41
|
+
*
|
|
42
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
43
|
+
* @param pkg - Package name, e.g. `my-ui`.
|
|
44
|
+
* @param local - Where the app installs it from now.
|
|
45
|
+
* @returns The new range, nothing when the installed copy is current, or the error.
|
|
46
|
+
*/
|
|
47
|
+
export declare function installPackedCopy(projectRoot: string, pkg: string, local: LocalPackage): Promise<PackResult>;
|
|
48
|
+
//# sourceMappingURL=localPack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localPack.d.ts","sourceRoot":"","sources":["../../src/packages/localPack.ts"],"names":[],"mappings":"AAYA;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAI,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAalF;AAOD;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAM,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAiBlH"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// packages/ui/src/packages/localPack.ts
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { readDeclaredDependencies } from "@g3nomaly/core/sources";
|
|
6
|
+
import { bunAdd, bunPack, bunRemove } from "./install";
|
|
7
|
+
const PackageNameSchema = z.object({ name: z.string().min(1) });
|
|
8
|
+
/** `file:../my-ui`, `link:../my-ui` or `file:../my-ui/my-ui-0.3.0.tgz`. */
|
|
9
|
+
const LOCAL_SPEC = /^(?:file|link):(.+)$/;
|
|
10
|
+
/**
|
|
11
|
+
* @brief Where the app installs a package from, when that is a folder on disk: a `file:` or `link:`
|
|
12
|
+
* range naming the folder itself, or a tarball packed inside it.
|
|
13
|
+
*
|
|
14
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
15
|
+
* @param pkg - Package name, e.g. `my-ui`.
|
|
16
|
+
* @returns The folder, or `null` when the app installs the package from a registry, git or a workspace,
|
|
17
|
+
* or the folder holds a different package.
|
|
18
|
+
*/
|
|
19
|
+
export function localPackage(projectRoot, pkg) {
|
|
20
|
+
const declared = readDeclaredDependencies(projectRoot)[pkg];
|
|
21
|
+
const target = declared === undefined ? undefined : LOCAL_SPEC.exec(declared)?.[1];
|
|
22
|
+
if (declared === undefined || target === undefined)
|
|
23
|
+
return null;
|
|
24
|
+
const resolved = path.resolve(projectRoot, target);
|
|
25
|
+
const packed = /\.(?:tgz|tar\.gz)$/.test(resolved);
|
|
26
|
+
const folder = packed ? path.dirname(resolved) : resolved;
|
|
27
|
+
const manifest = path.join(folder, "package.json");
|
|
28
|
+
if (!fs.existsSync(manifest))
|
|
29
|
+
return null;
|
|
30
|
+
const parsed = PackageNameSchema.safeParse(JSON.parse(fs.readFileSync(manifest, "utf8")));
|
|
31
|
+
if (!parsed.success || parsed.data.name !== pkg)
|
|
32
|
+
return null;
|
|
33
|
+
return { folder, declared, ...(packed ? { tarball: resolved } : {}) };
|
|
34
|
+
}
|
|
35
|
+
/** Bytes of a file, or `null` when it does not exist. */
|
|
36
|
+
function readIfExists(file) {
|
|
37
|
+
return fs.existsSync(file) ? fs.readFileSync(file) : null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @brief Installs a packed copy of a local package in place of a link to its folder, or refreshes the
|
|
41
|
+
* copy. A linked folder brings its own `node_modules`, so files the app imports from it load the folder's
|
|
42
|
+
* packages, such as a second React; a packed copy holds only what the package's `files` field lists.
|
|
43
|
+
*
|
|
44
|
+
* Packs the folder with `bun pm pack` (which runs its `prepack` script), then removes the package and
|
|
45
|
+
* adds the tarball: Bun keeps an old copy when a tarball is replaced under the same name. A tarball
|
|
46
|
+
* identical to the one already installed is left as is.
|
|
47
|
+
*
|
|
48
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
49
|
+
* @param pkg - Package name, e.g. `my-ui`.
|
|
50
|
+
* @param local - Where the app installs it from now.
|
|
51
|
+
* @returns The new range, nothing when the installed copy is current, or the error.
|
|
52
|
+
*/
|
|
53
|
+
export async function installPackedCopy(projectRoot, pkg, local) {
|
|
54
|
+
const previous = local.tarball === undefined ? null : readIfExists(local.tarball);
|
|
55
|
+
const packed = await bunPack(local.folder);
|
|
56
|
+
if ("error" in packed)
|
|
57
|
+
return { error: `bun pm pack failed in ${local.folder}: ${packed.error}` };
|
|
58
|
+
const tarball = path.join(local.folder, packed.tarball);
|
|
59
|
+
const relative = path.relative(projectRoot, tarball).split(path.sep).join("/");
|
|
60
|
+
const range = `file:${relative.startsWith(".") ? relative : `./${relative}`}`;
|
|
61
|
+
if (tarball === local.tarball && previous !== null && previous.equals(fs.readFileSync(tarball)))
|
|
62
|
+
return {};
|
|
63
|
+
const removed = await bunRemove(projectRoot, pkg);
|
|
64
|
+
if (removed !== undefined)
|
|
65
|
+
return { error: `bun remove ${pkg} failed: ${removed}` };
|
|
66
|
+
const added = await bunAdd(projectRoot, [`${pkg}@${range}`], false);
|
|
67
|
+
if (added === undefined)
|
|
68
|
+
return { installed: range };
|
|
69
|
+
const restored = await bunAdd(projectRoot, [`${pkg}@${local.declared}`], false);
|
|
70
|
+
return { error: `bun add ${pkg}@${range} failed: ${added}${restored === undefined ? `; restored ${local.declared}` : `; restoring ${local.declared} failed too: ${restored}`}` };
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=localPack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localPack.js","sourceRoot":"","sources":["../../src/packages/localPack.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEvD,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM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AAC,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAAE,OAAO,EAAE,CAAC;IAE3G,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;IAClD,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,EAAE,KAAK,EAAE,cAAc,GAAG,YAAY,OAAO,EAAE,EAAE,CAAC;IACpF,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,WAAW,EAAE,CAAC,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IACpE,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAErD,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,WAAW,EAAE,CAAC,GAAG,GAAG,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IAChF,OAAO,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,KAAK,YAAY,KAAK,GAAG,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,eAAe,KAAK,CAAC,QAAQ,gBAAgB,QAAQ,EAAE,EAAE,EAAE,CAAC;AACnL,CAAC"}
|
|
@@ -4,16 +4,39 @@ import type { ComponentFileType, ComponentMeta } from "../types";
|
|
|
4
4
|
* @brief A single file returned by fetchShadcnComponentFiles().
|
|
5
5
|
*
|
|
6
6
|
* @property path - File path relative to the user's installDir, e.g. "shadcn/button.tsx".
|
|
7
|
-
* @property type -
|
|
7
|
+
* @property type - ui `ComponentFileType` the shadcn file type maps to.
|
|
8
8
|
*/
|
|
9
9
|
export interface ShadcnFileContent {
|
|
10
10
|
path: string;
|
|
11
11
|
content: string;
|
|
12
12
|
type: ComponentFileType;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* @brief What only a fetched shadcn component tells, since the index lacks it: its npm packages and theme tokens.
|
|
16
|
+
*/
|
|
17
|
+
export type FetchedComponentFields = Pick<ComponentMeta, "dependencies" | "devDependencies" | "cssVars">;
|
|
18
|
+
/**
|
|
19
|
+
* @brief The files of one shadcn component, with what it needs beside them.
|
|
20
|
+
*
|
|
21
|
+
* @property files - Files with their contents, imports already rewritten.
|
|
22
|
+
* @property fields - npm packages and theme tokens the component lists.
|
|
23
|
+
*/
|
|
24
|
+
export interface ShadcnComponent {
|
|
25
|
+
files: ShadcnFileContent[];
|
|
26
|
+
fields: FetchedComponentFields;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @brief Key a shadcn component is offered under.
|
|
30
|
+
*
|
|
31
|
+
* @param name - shadcn component name, e.g. `alert-dialog`.
|
|
32
|
+
* @returns The key, e.g. `@shadcn/alert-dialog`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function shadcnKey(name: string): string;
|
|
14
35
|
/**
|
|
15
36
|
* @brief Fetches the shadcn component index as entries keyed `@shadcn/<name>`,
|
|
16
|
-
* recorded under the `shadcn` source
|
|
37
|
+
* recorded under the `shadcn` source with the installed shadcn version as
|
|
38
|
+
* their version, so `update` shows the change after shadcn is upgraded.
|
|
39
|
+
* Hashes are absent until install.
|
|
17
40
|
*
|
|
18
41
|
* @returns no entries and a warning when shadcn is not installed or the index cannot be fetched
|
|
19
42
|
*/
|
|
@@ -22,20 +45,22 @@ export declare function readShadcnEntries(): Promise<{
|
|
|
22
45
|
warnings: string[];
|
|
23
46
|
}>;
|
|
24
47
|
/**
|
|
25
|
-
* @brief Fetches
|
|
26
|
-
*
|
|
48
|
+
* @brief Fetches one shadcn component through the installed shadcn package: its file contents,
|
|
49
|
+
* with registry imports rewritten to the installed siblings, and the npm packages and theme tokens
|
|
50
|
+
* it lists. The index lacks the theme tokens, so they are only known here.
|
|
27
51
|
*
|
|
28
52
|
* @param name - Component name without the `@shadcn/` prefix, e.g. `button`.
|
|
29
|
-
* @returns Files
|
|
53
|
+
* @returns Files and fields; no files when the component is unknown or lists none.
|
|
30
54
|
*/
|
|
31
|
-
export declare function
|
|
55
|
+
export declare function fetchShadcnComponent(name: string): Promise<ShadcnComponent>;
|
|
32
56
|
/**
|
|
33
57
|
* @brief Entry source that fetches shadcn components, one request per component,
|
|
34
58
|
* and writes each file from its content; entries of any other source go to
|
|
35
59
|
* `fallback`.
|
|
36
60
|
*
|
|
37
61
|
* @param fallback - Entry source for every entry of another source.
|
|
62
|
+
* @param fetchedByKey - Filled with the npm packages and theme tokens of each shadcn component fetched, by component key.
|
|
38
63
|
* @returns Entry source that serves shadcn entries and delegates the rest to `fallback`.
|
|
39
64
|
*/
|
|
40
|
-
export declare function shadcnFileSource(fallback: EntrySource): EntrySource;
|
|
65
|
+
export declare function shadcnFileSource(fallback: EntrySource, fetchedByKey: Map<string, FetchedComponentFields>): EntrySource;
|
|
41
66
|
//# sourceMappingURL=shadcn.adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadcn.adapter.d.ts","sourceRoot":"","sources":["../../../src/registry/adapters/shadcn.adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shadcn.adapter.d.ts","sourceRoot":"","sources":["../../../src/registry/adapters/shadcn.adapter.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAWjE;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAK,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAK,iBAAiB,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,aAAa,EAAE,cAAc,GAAG,iBAAiB,GAAG,SAAS,CAAC,CAAC;AAEzG;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAG,iBAAiB,EAAE,CAAC;IAC5B,MAAM,EAAE,sBAAsB,CAAC;CAChC;AAiED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC;IAAE,OAAO,EAAE,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAiC7G;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAiBjF;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,GAAG,WAAW,CActH"}
|
|
@@ -1,10 +1,31 @@
|
|
|
1
1
|
// packages/ui/src/registry/adapters/shadcn.adapter.ts
|
|
2
|
+
import fs from "node:fs";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { createRequire } from "node:module";
|
|
5
|
+
import { z } from "zod";
|
|
4
6
|
import { OriginEntrySchema } from "@g3nomaly/core/installer";
|
|
5
7
|
import { SHADCN_SOURCE } from "../manifest";
|
|
8
|
+
import { rewriteRegistryImports } from "./shadcnImports";
|
|
6
9
|
const require = createRequire(import.meta.url);
|
|
7
|
-
|
|
10
|
+
/** Every item of the `new-york-v4` style, the style the shadcn package fetches files in. */
|
|
11
|
+
const SHADCN_INDEX_URL = "https://ui.shadcn.com/r/styles/new-york-v4/registry.json";
|
|
12
|
+
/** Item types offered for install. Blocks, examples and themes are left out. */
|
|
13
|
+
const INSTALLABLE_TYPES = new Set(["registry:ui", "registry:hook", "registry:lib"]);
|
|
14
|
+
/**
|
|
15
|
+
* @brief The shadcn registry listing of one style: every item, each with its files as paths and types,
|
|
16
|
+
* the names of the shadcn items it needs (without the `@shadcn/` prefix) and its npm packages.
|
|
17
|
+
*/
|
|
18
|
+
const ShadcnIndexSchema = z.object({
|
|
19
|
+
items: z.array(z.object({
|
|
20
|
+
name: z.string().min(1),
|
|
21
|
+
type: z.string(),
|
|
22
|
+
description: z.string().optional(),
|
|
23
|
+
files: z.array(z.object({ path: z.string().min(1), type: z.string() })).optional(),
|
|
24
|
+
registryDependencies: z.array(z.string()).optional(),
|
|
25
|
+
dependencies: z.array(z.string()).optional(),
|
|
26
|
+
devDependencies: z.array(z.string()).optional(),
|
|
27
|
+
})),
|
|
28
|
+
});
|
|
8
29
|
/**
|
|
9
30
|
* @brief Root of the installed shadcn package.
|
|
10
31
|
*
|
|
@@ -15,10 +36,20 @@ function resolveShadcnRoot() {
|
|
|
15
36
|
return path.dirname(require.resolve("shadcn/package.json"));
|
|
16
37
|
}
|
|
17
38
|
/**
|
|
18
|
-
* @brief
|
|
39
|
+
* @brief Version of the installed shadcn package, which the app's `package.json` decides.
|
|
40
|
+
*
|
|
41
|
+
* @param root - Root of the installed shadcn package.
|
|
42
|
+
* @returns The version, e.g. `4.22.1`.
|
|
43
|
+
*/
|
|
44
|
+
function readShadcnVersion(root) {
|
|
45
|
+
const manifest = z.object({ version: z.string().min(1) }).parse(JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8")));
|
|
46
|
+
return manifest.version;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @brief The ui file type for a shadcn registry file type.
|
|
19
50
|
*
|
|
20
51
|
* @param shadcnType - shadcn registry file type, e.g. `registry:ui`.
|
|
21
|
-
* @returns The
|
|
52
|
+
* @returns The ui `ComponentFileType`; `component` for any type not listed.
|
|
22
53
|
*/
|
|
23
54
|
function mapShadcnType(shadcnType) {
|
|
24
55
|
if (shadcnType === "registry:ui")
|
|
@@ -42,15 +73,27 @@ function normalizeFilePath(fullPath) {
|
|
|
42
73
|
const parts = fullPath.split("/");
|
|
43
74
|
return `shadcn/${parts[parts.length - 1]}`;
|
|
44
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* @brief Key a shadcn component is offered under.
|
|
78
|
+
*
|
|
79
|
+
* @param name - shadcn component name, e.g. `alert-dialog`.
|
|
80
|
+
* @returns The key, e.g. `@shadcn/alert-dialog`.
|
|
81
|
+
*/
|
|
82
|
+
export function shadcnKey(name) {
|
|
83
|
+
return `@shadcn/${name.toLowerCase()}`;
|
|
84
|
+
}
|
|
45
85
|
/**
|
|
46
86
|
* @brief Fetches the shadcn component index as entries keyed `@shadcn/<name>`,
|
|
47
|
-
* recorded under the `shadcn` source
|
|
87
|
+
* recorded under the `shadcn` source with the installed shadcn version as
|
|
88
|
+
* their version, so `update` shows the change after shadcn is upgraded.
|
|
89
|
+
* Hashes are absent until install.
|
|
48
90
|
*
|
|
49
91
|
* @returns no entries and a warning when shadcn is not installed or the index cannot be fetched
|
|
50
92
|
*/
|
|
51
93
|
export async function readShadcnEntries() {
|
|
94
|
+
let version;
|
|
52
95
|
try {
|
|
53
|
-
resolveShadcnRoot();
|
|
96
|
+
version = readShadcnVersion(resolveShadcnRoot());
|
|
54
97
|
}
|
|
55
98
|
catch {
|
|
56
99
|
return { entries: [], warnings: ["shadcn is not installed: run `bun add shadcn@latest`"] };
|
|
@@ -60,43 +103,53 @@ export async function readShadcnEntries() {
|
|
|
60
103
|
const res = await fetch(SHADCN_INDEX_URL);
|
|
61
104
|
if (!res.ok)
|
|
62
105
|
throw new Error(`HTTP ${res.status}`);
|
|
63
|
-
items = (await res.json());
|
|
106
|
+
items = ShadcnIndexSchema.parse(await res.json()).items;
|
|
64
107
|
}
|
|
65
108
|
catch (err) {
|
|
66
109
|
return { entries: [], warnings: [`the shadcn index could not be fetched: ${String(err)}`] };
|
|
67
110
|
}
|
|
68
111
|
const entries = [];
|
|
69
112
|
for (const item of items) {
|
|
70
|
-
if (!item.
|
|
113
|
+
if (!INSTALLABLE_TYPES.has(item.type) || !item.files?.length)
|
|
71
114
|
continue;
|
|
72
|
-
entries.push([
|
|
115
|
+
entries.push([shadcnKey(item.name), {
|
|
73
116
|
name: item.name,
|
|
74
117
|
description: item.description,
|
|
118
|
+
version,
|
|
75
119
|
group: SHADCN_SOURCE,
|
|
76
|
-
origin: { source: SHADCN_SOURCE, dir: "" },
|
|
77
|
-
registryDependencies: (item.registryDependencies ?? []).map(
|
|
120
|
+
origin: { source: SHADCN_SOURCE, dir: "", version },
|
|
121
|
+
registryDependencies: (item.registryDependencies ?? []).map(shadcnKey),
|
|
122
|
+
dependencies: item.dependencies,
|
|
123
|
+
devDependencies: item.devDependencies,
|
|
78
124
|
files: item.files.map((f) => ({ path: normalizeFilePath(f.path), type: mapShadcnType(f.type) })),
|
|
79
125
|
}]);
|
|
80
126
|
}
|
|
81
127
|
return { entries, warnings: [] };
|
|
82
128
|
}
|
|
83
129
|
/**
|
|
84
|
-
* @brief Fetches
|
|
85
|
-
*
|
|
130
|
+
* @brief Fetches one shadcn component through the installed shadcn package: its file contents,
|
|
131
|
+
* with registry imports rewritten to the installed siblings, and the npm packages and theme tokens
|
|
132
|
+
* it lists. The index lacks the theme tokens, so they are only known here.
|
|
86
133
|
*
|
|
87
134
|
* @param name - Component name without the `@shadcn/` prefix, e.g. `button`.
|
|
88
|
-
* @returns Files
|
|
135
|
+
* @returns Files and fields; no files when the component is unknown or lists none.
|
|
89
136
|
*/
|
|
90
|
-
export async function
|
|
137
|
+
export async function fetchShadcnComponent(name) {
|
|
91
138
|
// Imported on use, so only commands that install shadcn components need the package.
|
|
92
139
|
const { getRegistryItems } = await import("shadcn/registry");
|
|
93
140
|
const items = await getRegistryItems([name]);
|
|
94
141
|
const item = items[0];
|
|
142
|
+
const fields = {
|
|
143
|
+
dependencies: item?.dependencies ?? [],
|
|
144
|
+
devDependencies: item?.devDependencies ?? [],
|
|
145
|
+
...(item?.cssVars === undefined ? {} : { cssVars: item.cssVars }),
|
|
146
|
+
};
|
|
95
147
|
if (!item?.files?.length)
|
|
96
|
-
return [];
|
|
97
|
-
|
|
148
|
+
return { files: [], fields };
|
|
149
|
+
const files = item.files
|
|
98
150
|
.filter((f) => typeof f.content === "string")
|
|
99
|
-
.map((f) => ({ path: normalizeFilePath(f.path), content: f.content, type: mapShadcnType(f.type) }));
|
|
151
|
+
.map((f) => ({ path: normalizeFilePath(f.path), content: rewriteRegistryImports(f.content), type: mapShadcnType(f.type) }));
|
|
152
|
+
return { files, fields };
|
|
100
153
|
}
|
|
101
154
|
/**
|
|
102
155
|
* @brief Entry source that fetches shadcn components, one request per component,
|
|
@@ -104,15 +157,17 @@ export async function fetchShadcnComponentFiles(name) {
|
|
|
104
157
|
* `fallback`.
|
|
105
158
|
*
|
|
106
159
|
* @param fallback - Entry source for every entry of another source.
|
|
160
|
+
* @param fetchedByKey - Filled with the npm packages and theme tokens of each shadcn component fetched, by component key.
|
|
107
161
|
* @returns Entry source that serves shadcn entries and delegates the rest to `fallback`.
|
|
108
162
|
*/
|
|
109
|
-
export function shadcnFileSource(fallback) {
|
|
163
|
+
export function shadcnFileSource(fallback, fetchedByKey) {
|
|
110
164
|
return async (entry) => {
|
|
111
165
|
const { origin } = OriginEntrySchema.pick({ origin: true }).parse(entry);
|
|
112
166
|
if (origin.source !== SHADCN_SOURCE)
|
|
113
167
|
return fallback(entry);
|
|
114
|
-
const fetched = await
|
|
115
|
-
|
|
168
|
+
const fetched = await fetchShadcnComponent(entry.name.toLowerCase());
|
|
169
|
+
fetchedByKey.set(shadcnKey(entry.name), fetched.fields);
|
|
170
|
+
const contents = new Map(fetched.files.map((f) => [f.path, f.content]));
|
|
116
171
|
const source = (file) => {
|
|
117
172
|
const content = contents.get(file.path);
|
|
118
173
|
return content === undefined ? null : { kind: "write", content };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadcn.adapter.js","sourceRoot":"","sources":["../../../src/registry/adapters/shadcn.adapter.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,a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CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACxD,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACxE,MAAM,MAAM,GAAe,CAAC,IAAI,EAAE,EAAE;YAClC,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACxC,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;QACnE,CAAC,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brief Points imports into the shadcn registry at the installed sibling file. The registry serves
|
|
3
|
+
* files with imports such as `@/registry/new-york-v4/ui/button`, which only resolve inside the shadcn
|
|
4
|
+
* repository. Every shadcn file is installed into the same `shadcn/` folder, so each becomes `./button`.
|
|
5
|
+
*
|
|
6
|
+
* @param content - File content as the shadcn registry serves it.
|
|
7
|
+
* @returns The content with every registry specifier replaced by a relative one.
|
|
8
|
+
*/
|
|
9
|
+
export declare function rewriteRegistryImports(content: string): string;
|
|
10
|
+
//# sourceMappingURL=shadcnImports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shadcnImports.d.ts","sourceRoot":"","sources":["../../../src/registry/adapters/shadcnImports.ts"],"names":[],"mappings":"AAQA;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE9D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// packages/ui/src/registry/adapters/shadcnImports.ts
|
|
2
|
+
/**
|
|
3
|
+
* A module specifier into the shadcn registry, quoted, e.g. `"@/registry/new-york-v4/ui/button"`.
|
|
4
|
+
* Group 1 is the quote, group 2 the last path segment.
|
|
5
|
+
*/
|
|
6
|
+
const REGISTRY_SPECIFIER = /(["'])@\/registry\/[^"'/]+\/(?:[^"']*\/)?([^"'/]+)\1/g;
|
|
7
|
+
/**
|
|
8
|
+
* @brief Points imports into the shadcn registry at the installed sibling file. The registry serves
|
|
9
|
+
* files with imports such as `@/registry/new-york-v4/ui/button`, which only resolve inside the shadcn
|
|
10
|
+
* repository. Every shadcn file is installed into the same `shadcn/` folder, so each becomes `./button`.
|
|
11
|
+
*
|
|
12
|
+
* @param content - File content as the shadcn registry serves it.
|
|
13
|
+
* @returns The content with every registry specifier replaced by a relative one.
|
|
14
|
+
*/
|
|
15
|
+
export function rewriteRegistryImports(content) {
|
|
16
|
+
return content.replace(REGISTRY_SPECIFIER, (_match, quote, name) => `${quote}./${name}${quote}`);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=shadcnImports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shadcnImports.js","sourceRoot":"","sources":["../../../src/registry/adapters/shadcnImports.ts"],"names":[],"mappings":"AAAA,qDAAqD;AAErD;;;GAGG;AACH,MAAM,kBAAkB,GAAG,uDAAuD,CAAC;AAEnF;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAe;IACpD,OAAO,OAAO,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,MAAM,EAAE,KAAa,EAAE,IAAY,EAAE,EAAE,CAAC,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,EAAE,CAAC,CAAC;AACnH,CAAC"}
|
|
@@ -5,12 +5,17 @@ export declare const COMPONENTS_JSON: string;
|
|
|
5
5
|
/**
|
|
6
6
|
* @brief Builds `components.json` from every `*.meta.ts` under the built components
|
|
7
7
|
* folder: each component with its files hashed and stamped with the package
|
|
8
|
-
* version, the meta file itself included.
|
|
8
|
+
* version, the meta file itself included. Files marked `install: "package"` must
|
|
9
|
+
* be reachable through the package's `exports`, since apps import them from it,
|
|
10
|
+
* and may only import packages the package declares in `peerDependencies`, so
|
|
11
|
+
* they use the app's copy. A component needs at least one file the app gets copied.
|
|
9
12
|
*
|
|
10
13
|
* @param componentsDir - Absolute built components folder, e.g. `<package>/dist/components`
|
|
11
14
|
* @param outFile - Absolute path to write, e.g. `<package>/dist/components.json`
|
|
12
15
|
* @param version - Package version stamped on every component and file
|
|
13
16
|
* @returns how many components were written
|
|
17
|
+
* @throws {Error} naming each file marked `install: "package"` that the package's `exports` does not reach,
|
|
18
|
+
* each package such a file imports that is not a peer, and each component with no copied file
|
|
14
19
|
*/
|
|
15
20
|
export declare function writeComponentsJson(componentsDir: string, outFile: string, version: string): Promise<number>;
|
|
16
21
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"componentsJson.d.ts","sourceRoot":"","sources":["../../src/registry/componentsJson.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"componentsJson.d.ts","sourceRoot":"","sources":["../../src/registry/componentsJson.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,mGAAmG;AACnG,eAAO,MAAM,cAAc,QAAmC,CAAC;AAC/D,eAAO,MAAM,eAAe,QAAuC,CAAC;AAIpE;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,mBAAmB,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA6ClH;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAMzF"}
|
|
@@ -6,6 +6,9 @@ import { z } from "zod";
|
|
|
6
6
|
import { createRegistryStore, jsonHandler, register, writeTo } from "@g3nomaly/core/registry";
|
|
7
7
|
import { hashFile } from "@g3nomaly/core/hash";
|
|
8
8
|
import { getSafeObject } from "@g3nomaly/core/security";
|
|
9
|
+
import { findPackageRoot } from "@g3nomaly/core/utils";
|
|
10
|
+
import { unexportedFiles } from "./packageExports";
|
|
11
|
+
import { undeclaredImports } from "./packageImports";
|
|
9
12
|
import { PackagedComponentSchema } from "./types";
|
|
10
13
|
/** Where a package keeps its built components and their registry, relative to the package root. */
|
|
11
14
|
export const COMPONENTS_DIR = path.join("dist", "components");
|
|
@@ -14,18 +17,29 @@ const ComponentsJsonSchema = z.record(z.string(), PackagedComponentSchema);
|
|
|
14
17
|
/**
|
|
15
18
|
* @brief Builds `components.json` from every `*.meta.ts` under the built components
|
|
16
19
|
* folder: each component with its files hashed and stamped with the package
|
|
17
|
-
* version, the meta file itself included.
|
|
20
|
+
* version, the meta file itself included. Files marked `install: "package"` must
|
|
21
|
+
* be reachable through the package's `exports`, since apps import them from it,
|
|
22
|
+
* and may only import packages the package declares in `peerDependencies`, so
|
|
23
|
+
* they use the app's copy. A component needs at least one file the app gets copied.
|
|
18
24
|
*
|
|
19
25
|
* @param componentsDir - Absolute built components folder, e.g. `<package>/dist/components`
|
|
20
26
|
* @param outFile - Absolute path to write, e.g. `<package>/dist/components.json`
|
|
21
27
|
* @param version - Package version stamped on every component and file
|
|
22
28
|
* @returns how many components were written
|
|
29
|
+
* @throws {Error} naming each file marked `install: "package"` that the package's `exports` does not reach,
|
|
30
|
+
* each package such a file imports that is not a peer, and each component with no copied file
|
|
23
31
|
*/
|
|
24
32
|
export async function writeComponentsJson(componentsDir, outFile, version) {
|
|
25
33
|
const store = createRegistryStore();
|
|
26
34
|
const metaFiles = await glob("**/*.meta.ts", { cwd: componentsDir, absolute: true });
|
|
27
35
|
for (const metaFile of metaFiles.sort()) {
|
|
28
36
|
const meta = await getSafeObject(metaFile, PackagedComponentSchema);
|
|
37
|
+
if (meta.files.every((file) => file.install === "package")) {
|
|
38
|
+
throw new Error([
|
|
39
|
+
`${path.relative(componentsDir, metaFile)} lists no file for the app to copy, so apps could never install ${meta.name}.`,
|
|
40
|
+
"A file that stays in the package needs no meta file of its own: delete this one, and import the file by package path where it is used.",
|
|
41
|
+
].join("\n"));
|
|
42
|
+
}
|
|
29
43
|
const files = [...meta.files, { path: path.relative(componentsDir, metaFile), type: "meta" }];
|
|
30
44
|
const hashed = await Promise.all(files.map(async (file) => ({
|
|
31
45
|
...file,
|
|
@@ -34,6 +48,25 @@ export async function writeComponentsJson(componentsDir, outFile, version) {
|
|
|
34
48
|
})));
|
|
35
49
|
register(store, meta.name.toLowerCase(), { ...meta, version, files: hashed });
|
|
36
50
|
}
|
|
51
|
+
const packageRoot = findPackageRoot(componentsDir);
|
|
52
|
+
const packageFiles = Object.values(store.store.state).flatMap((meta) => meta.files.filter((file) => file.install === "package").map((file) => path.relative(packageRoot, path.join(componentsDir, file.path))));
|
|
53
|
+
const unexported = unexportedFiles(packageRoot, packageFiles);
|
|
54
|
+
if (unexported.length > 0) {
|
|
55
|
+
throw new Error([
|
|
56
|
+
"files marked install: \"package\" are not in the exports of package.json, so apps cannot import them:",
|
|
57
|
+
...unexported.map((file) => ` ${file}`),
|
|
58
|
+
`add an export that reaches them, e.g. "exports": { "./*": "./${path.relative(packageRoot, componentsDir).split(path.sep).join("/")}/*.ts" }`,
|
|
59
|
+
].join("\n"));
|
|
60
|
+
}
|
|
61
|
+
const undeclared = undeclaredImports(packageRoot, packageFiles);
|
|
62
|
+
if (undeclared.length > 0) {
|
|
63
|
+
throw new Error([
|
|
64
|
+
"files marked install: \"package\" import packages that are not in the peerDependencies of package.json:",
|
|
65
|
+
...undeclared.map(({ file, pkg }) => ` ${file}: ${pkg}`),
|
|
66
|
+
"these files run in the app, so they must use the app's copy, or the app loads a second one, such as a second React.",
|
|
67
|
+
"add each package to \"peerDependencies\", and to \"devDependencies\" to build and typecheck here.",
|
|
68
|
+
].join("\n"));
|
|
69
|
+
}
|
|
37
70
|
writeTo(store, outFile, jsonHandler);
|
|
38
71
|
return Object.keys(store.store.state).length;
|
|
39
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"componentsJson.js","sourceRoot":"","sources":["../../src/registry/componentsJson.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC9F,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAGlD,mGAAmG;AACnG,MAAM,CAAC,MAAM,cAAc,GAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAC/D,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AAEpE,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,uBAAuB,CAAC,CAAC;AAE3E
|
|
1
|
+
{"version":3,"file":"componentsJson.js","sourceRoot":"","sources":["../../src/registry/componentsJson.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,O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AAC;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,gEAAgE,CAAC,CAAC;IACnH,MAAM,MAAM,GAAG,oBAAoB,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IACzF,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,qCAAqC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAClH,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACzG,CAAC"}
|
package/dist/registry/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export * from "./types";
|
|
|
2
2
|
export { COMPONENTS_DIR, COMPONENTS_JSON, readComponentsJson, writeComponentsJson } from "./componentsJson";
|
|
3
3
|
export { readComponentSource, filterFiles, groupOf } from "./readSource";
|
|
4
4
|
export type { ComponentFileFlags } from "./readSource";
|
|
5
|
-
export { uiManifestPath,
|
|
5
|
+
export { uiManifestPath, SHADCN_SOURCE } from "./manifest";
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|