@g3nomaly/ui 0.3.4 → 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 +7 -6
- package/dist/cli/adapter.d.ts +11 -2
- package/dist/cli/adapter.d.ts.map +1 -1
- package/dist/cli/adapter.js +14 -5
- package/dist/cli/adapter.js.map +1 -1
- package/dist/cli/commands/add.js +1 -1
- package/dist/cli/commands/add.js.map +1 -1
- package/dist/cli/commands/ls.js +1 -1
- package/dist/cli/commands/ls.js.map +1 -1
- package/dist/cli/commands/source.d.ts +2 -0
- package/dist/cli/commands/source.d.ts.map +1 -1
- package/dist/cli/commands/source.js +1 -1
- package/dist/cli/commands/source.js.map +1 -1
- package/dist/cli/commands/sourceInit.d.ts.map +1 -1
- package/dist/cli/commands/sourceInit.js +3 -2
- package/dist/cli/commands/sourceInit.js.map +1 -1
- package/dist/cli/commands/update.js +1 -1
- package/dist/cli/commands/update.js.map +1 -1
- package/dist/cli/index.js +2 -1
- 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 +1 -1
- package/dist/cli/npmDependencies.d.ts.map +1 -1
- package/dist/cli/npmDependencies.js +12 -6
- package/dist/cli/npmDependencies.js.map +1 -1
- package/dist/cli/themeTokens.d.ts +1 -1
- package/dist/cli/themeTokens.d.ts.map +1 -1
- package/dist/cli/themeTokens.js +23 -15
- package/dist/cli/themeTokens.js.map +1 -1
- package/dist/packages/dependencies.d.ts +6 -2
- package/dist/packages/dependencies.d.ts.map +1 -1
- package/dist/packages/dependencies.js +8 -2
- package/dist/packages/dependencies.js.map +1 -1
- package/dist/packages/install.d.ts +20 -0
- package/dist/packages/install.d.ts.map +1 -1
- package/dist/packages/install.js +40 -7
- package/dist/packages/install.js.map +1 -1
- 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/componentsJson.d.ts +5 -2
- package/dist/registry/componentsJson.d.ts.map +1 -1
- package/dist/registry/componentsJson.js +21 -2
- package/dist/registry/componentsJson.js.map +1 -1
- 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.js +1 -1
- package/dist/registry/readSource.js.map +1 -1
- package/dist/theme/cssVars.d.ts +18 -5
- package/dist/theme/cssVars.d.ts.map +1 -1
- package/dist/theme/cssVars.js +37 -22
- package/dist/theme/cssVars.js.map +1 -1
- package/package.json +2 -2
- package/template/build.ts +12 -5
- package/template/package.json +5 -1
- package/template/src/components/example/example.meta.ts +8 -0
|
@@ -12,17 +12,20 @@ export interface NpmDependency {
|
|
|
12
12
|
range?: string;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* @brief An npm package the app lacks,
|
|
15
|
+
* @brief An npm package the app lacks, declares only for build time although a component imports it
|
|
16
|
+
* at runtime, or holds at a version outside the range a component asks for.
|
|
16
17
|
*
|
|
17
18
|
* @property dependency - The package as the first component listing it asks for it.
|
|
18
19
|
* @property dev - Whether every component listing it needs it at build time only.
|
|
19
20
|
* @property neededBy - Keys of the components that list it, e.g. `["@shadcn/dialog"]`.
|
|
21
|
+
* @property devOnly - The app declares it in `devDependencies` only, though a component needs it at runtime.
|
|
20
22
|
* @property installed - Installed version when it is outside the range; absent when the package is missing.
|
|
21
23
|
*/
|
|
22
24
|
export interface DependencyProblem {
|
|
23
25
|
dependency: NpmDependency;
|
|
24
26
|
dev: boolean;
|
|
25
27
|
neededBy: string[];
|
|
28
|
+
devOnly?: true;
|
|
26
29
|
installed?: string;
|
|
27
30
|
}
|
|
28
31
|
/**
|
|
@@ -34,7 +37,8 @@ export interface DependencyProblem {
|
|
|
34
37
|
export declare function parseNpmDependency(spec: string): NpmDependency;
|
|
35
38
|
/**
|
|
36
39
|
* @brief Checks the npm packages of components against the app: a package its `package.json`
|
|
37
|
-
* does not declare is missing,
|
|
40
|
+
* does not declare is missing, a runtime package it declares in `devDependencies` only is misplaced,
|
|
41
|
+
* and an installed package outside the requested range is out of range.
|
|
38
42
|
*
|
|
39
43
|
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
40
44
|
* @param components - Components by key whose packages to check.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencies.d.ts","sourceRoot":"","sources":["../../src/packages/dependencies.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAI,MAAM,CAAC;IACf,IAAI,EAAI,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED
|
|
1
|
+
{"version":3,"file":"dependencies.d.ts","sourceRoot":"","sources":["../../src/packages/dependencies.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAI,MAAM,CAAC;IACf,IAAI,EAAI,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,aAAa,CAAC;IAC1B,GAAG,EAAS,OAAO,CAAC;IACpB,QAAQ,EAAI,MAAM,EAAE,CAAC;IACrB,OAAO,CAAC,EAAI,IAAI,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAG9D;AAYD;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,iBAAiB,EAAE,CAiC1H"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// packages/ui/src/packages/dependencies.ts
|
|
2
|
-
import { findInstalledPackage, readDeclaredDependencies } from "@g3nomaly/core/sources";
|
|
2
|
+
import { findInstalledPackage, readDeclaredDependencies, RUNTIME_SECTIONS } from "@g3nomaly/core/sources";
|
|
3
3
|
/**
|
|
4
4
|
* @brief Splits an npm spec into name and version range. The range follows the last `@` that is not a scope's.
|
|
5
5
|
*
|
|
@@ -21,7 +21,8 @@ function isSemverRange(range) {
|
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* @brief Checks the npm packages of components against the app: a package its `package.json`
|
|
24
|
-
* does not declare is missing,
|
|
24
|
+
* does not declare is missing, a runtime package it declares in `devDependencies` only is misplaced,
|
|
25
|
+
* and an installed package outside the requested range is out of range.
|
|
25
26
|
*
|
|
26
27
|
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
27
28
|
* @param components - Components by key whose packages to check.
|
|
@@ -29,6 +30,7 @@ function isSemverRange(range) {
|
|
|
29
30
|
*/
|
|
30
31
|
export function findDependencyProblems(projectRoot, components) {
|
|
31
32
|
const declared = readDeclaredDependencies(projectRoot);
|
|
33
|
+
const runtime = readDeclaredDependencies(projectRoot, RUNTIME_SECTIONS);
|
|
32
34
|
const problems = new Map();
|
|
33
35
|
const check = (key, spec, dev) => {
|
|
34
36
|
const dependency = parseNpmDependency(spec);
|
|
@@ -42,6 +44,10 @@ export function findDependencyProblems(projectRoot, components) {
|
|
|
42
44
|
problems.set(dependency.name, { dependency, dev, neededBy: [key] });
|
|
43
45
|
return;
|
|
44
46
|
}
|
|
47
|
+
if (!dev && runtime[dependency.name] === undefined) {
|
|
48
|
+
problems.set(dependency.name, { dependency, dev, neededBy: [key], devOnly: true });
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
45
51
|
if (dependency.range === undefined || !isSemverRange(dependency.range))
|
|
46
52
|
return;
|
|
47
53
|
const installed = findInstalledPackage(projectRoot, dependency.name)?.version;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../../src/packages/dependencies.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../../src/packages/dependencies.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAkC1G;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACjC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACtG,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,WAAmB,EAAE,UAAyC;IACnG,MAAM,QAAQ,GAAG,wBAAwB,CAAC,WAAW,CAAC,CAAC;IACvD,MAAM,OAAO,GAAI,wBAAwB,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC;IACzE,MAAM,QAAQ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,CAAC;YAClF,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;QACjF,CAAC;IACH,CAAC,CAAC;IAEF,KAAK,MAAM,CAAC,GAAG,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1D,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,YAAY,IAAI,EAAE;YAAK,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC5E,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,eAAe,IAAI,EAAE;YAAE,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -7,4 +7,24 @@
|
|
|
7
7
|
* @returns `undefined` on success, else the error `bun add` printed.
|
|
8
8
|
*/
|
|
9
9
|
export declare function bunAdd(projectRoot: string, specs: readonly string[], dev: boolean): Promise<string | undefined>;
|
|
10
|
+
/**
|
|
11
|
+
* @brief Runs `bun remove` in the project for one package.
|
|
12
|
+
*
|
|
13
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
14
|
+
* @param pkg - Package to remove, e.g. `my-ui`.
|
|
15
|
+
* @returns `undefined` on success, else the error `bun remove` printed.
|
|
16
|
+
*/
|
|
17
|
+
export declare function bunRemove(projectRoot: string, pkg: string): Promise<string | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* @brief Packs a package folder with `bun pm pack`, which runs its `prepack` script first and keeps
|
|
20
|
+
* only what its `files` field lists, so the tarball holds no `node_modules`.
|
|
21
|
+
*
|
|
22
|
+
* @param folder - Absolute folder holding the package's `package.json`.
|
|
23
|
+
* @returns The tarball's file name inside `folder`, e.g. `my-ui-0.3.0.tgz`, or the error `bun pm pack` printed.
|
|
24
|
+
*/
|
|
25
|
+
export declare function bunPack(folder: string): Promise<{
|
|
26
|
+
tarball: string;
|
|
27
|
+
} | {
|
|
28
|
+
error: string;
|
|
29
|
+
}>;
|
|
10
30
|
//# sourceMappingURL=install.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/packages/install.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/packages/install.ts"],"names":[],"mappings":"AA2BA;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAGrH;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAE7F;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAM9F"}
|
package/dist/packages/install.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
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
|
+
}
|
|
2
16
|
/**
|
|
3
17
|
* @brief Runs `bun add` in the project for the given specs, with `-d` for build-time packages.
|
|
4
18
|
*
|
|
@@ -10,12 +24,31 @@
|
|
|
10
24
|
export async function bunAdd(projectRoot, specs, dev) {
|
|
11
25
|
if (specs.length === 0)
|
|
12
26
|
return undefined;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 };
|
|
20
53
|
}
|
|
21
54
|
//# sourceMappingURL=install.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.js","sourceRoot":"","sources":["../../src/packages/install.ts"],"names":[],"mappings":"AAAA,sCAAsC;
|
|
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,IAAuB;IACxD,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7F,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACxI,IAAI,QAAQ,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;IACrD,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI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,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,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAEhE,2EAA2E;AAC3E,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAe1C;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,WAAmB,EAAE,GAAW;IAC3D,MAAM,QAAQ,GAAG,wBAAwB,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAK,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACrF,IAAI,QAAQ,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAEhE,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACnD,MAAM,MAAM,GAAK,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrD,MAAM,MAAM,GAAK,MAAM,CAAC,CAAC,CAAC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,cAAc,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,eAAe,KAAK,CAAC,QAAQ,gBAAgB,QAAQ,EAAE,EAAE,EAAE,CAAC;AACnL,CAAC"}
|
|
@@ -6,13 +6,16 @@ export declare const COMPONENTS_JSON: string;
|
|
|
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
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
|
|
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.
|
|
10
12
|
*
|
|
11
13
|
* @param componentsDir - Absolute built components folder, e.g. `<package>/dist/components`
|
|
12
14
|
* @param outFile - Absolute path to write, e.g. `<package>/dist/components.json`
|
|
13
15
|
* @param version - Package version stamped on every component and file
|
|
14
16
|
* @returns how many components were written
|
|
15
|
-
* @throws {Error} naming each file marked `install: "package"` that the package's `exports` does not reach
|
|
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
|
|
16
19
|
*/
|
|
17
20
|
export declare function writeComponentsJson(componentsDir: string, outFile: string, version: string): Promise<number>;
|
|
18
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"}
|
|
@@ -8,6 +8,7 @@ import { hashFile } from "@g3nomaly/core/hash";
|
|
|
8
8
|
import { getSafeObject } from "@g3nomaly/core/security";
|
|
9
9
|
import { findPackageRoot } from "@g3nomaly/core/utils";
|
|
10
10
|
import { unexportedFiles } from "./packageExports";
|
|
11
|
+
import { undeclaredImports } from "./packageImports";
|
|
11
12
|
import { PackagedComponentSchema } from "./types";
|
|
12
13
|
/** Where a package keeps its built components and their registry, relative to the package root. */
|
|
13
14
|
export const COMPONENTS_DIR = path.join("dist", "components");
|
|
@@ -17,19 +18,28 @@ const ComponentsJsonSchema = z.record(z.string(), PackagedComponentSchema);
|
|
|
17
18
|
* @brief Builds `components.json` from every `*.meta.ts` under the built components
|
|
18
19
|
* folder: each component with its files hashed and stamped with the package
|
|
19
20
|
* version, the meta file itself included. Files marked `install: "package"` must
|
|
20
|
-
* be reachable through the package's `exports`, since apps import them from it
|
|
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.
|
|
21
24
|
*
|
|
22
25
|
* @param componentsDir - Absolute built components folder, e.g. `<package>/dist/components`
|
|
23
26
|
* @param outFile - Absolute path to write, e.g. `<package>/dist/components.json`
|
|
24
27
|
* @param version - Package version stamped on every component and file
|
|
25
28
|
* @returns how many components were written
|
|
26
|
-
* @throws {Error} naming each file marked `install: "package"` that the package's `exports` does not reach
|
|
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
|
|
27
31
|
*/
|
|
28
32
|
export async function writeComponentsJson(componentsDir, outFile, version) {
|
|
29
33
|
const store = createRegistryStore();
|
|
30
34
|
const metaFiles = await glob("**/*.meta.ts", { cwd: componentsDir, absolute: true });
|
|
31
35
|
for (const metaFile of metaFiles.sort()) {
|
|
32
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
|
+
}
|
|
33
43
|
const files = [...meta.files, { path: path.relative(componentsDir, metaFile), type: "meta" }];
|
|
34
44
|
const hashed = await Promise.all(files.map(async (file) => ({
|
|
35
45
|
...file,
|
|
@@ -48,6 +58,15 @@ export async function writeComponentsJson(componentsDir, outFile, version) {
|
|
|
48
58
|
`add an export that reaches them, e.g. "exports": { "./*": "./${path.relative(packageRoot, componentsDir).split(path.sep).join("/")}/*.ts" }`,
|
|
49
59
|
].join("\n"));
|
|
50
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
|
+
}
|
|
51
70
|
writeTo(store, outFile, jsonHandler);
|
|
52
71
|
return Object.keys(store.store.state).length;
|
|
53
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,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,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,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE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AAG,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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brief A package a file imports that its package does not declare as a peer.
|
|
3
|
+
*
|
|
4
|
+
* @property file - Path of the importing file from the package root, e.g. `dist/components/dock/layout.ts`.
|
|
5
|
+
* @property pkg - Name of the imported package, e.g. `react` or `@tanstack/store`.
|
|
6
|
+
*/
|
|
7
|
+
export interface UndeclaredImport {
|
|
8
|
+
file: string;
|
|
9
|
+
pkg: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @brief Packages the files import at runtime that the package's `peerDependencies` lack.
|
|
13
|
+
*
|
|
14
|
+
* Files marked `install: "package"` run inside the app, so every package they import must come from the
|
|
15
|
+
* app's own install: a package installed beside them would load a second copy, such as a second React.
|
|
16
|
+
* Type-only imports are left out, since they are gone at runtime, and so are imports of the package itself.
|
|
17
|
+
*
|
|
18
|
+
* @param packageRoot - Absolute folder holding the package's `package.json`.
|
|
19
|
+
* @param files - Files to scan, relative to the package root.
|
|
20
|
+
* @returns One entry per file and package that is not a peer, in file order.
|
|
21
|
+
*/
|
|
22
|
+
export declare function undeclaredImports(packageRoot: string, files: readonly string[]): UndeclaredImport[];
|
|
23
|
+
//# sourceMappingURL=packageImports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageImports.d.ts","sourceRoot":"","sources":["../../src/registry/packageImports.ts"],"names":[],"mappings":"AAcA;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAG,MAAM,CAAC;CACd;AAiBD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAYnG"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// packages/ui/src/registry/packageImports.ts
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { builtinModules } from "node:module";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
const PackagePeersSchema = z.object({
|
|
7
|
+
name: z.string().min(1),
|
|
8
|
+
peerDependencies: z.record(z.string(), z.string()).optional(),
|
|
9
|
+
});
|
|
10
|
+
/** Node and Bun built-ins, which need no install. */
|
|
11
|
+
const BUILTINS = new Set(builtinModules);
|
|
12
|
+
/**
|
|
13
|
+
* @brief The package an import path names, or `null` for a path that needs no package: a relative
|
|
14
|
+
* path, a built-in such as `node:fs` or `bun:test`.
|
|
15
|
+
*
|
|
16
|
+
* @param specifier - The import path as written, e.g. `@tanstack/store/vanilla`.
|
|
17
|
+
* @returns The package name, e.g. `@tanstack/store`.
|
|
18
|
+
*/
|
|
19
|
+
function packageOf(specifier) {
|
|
20
|
+
if (specifier.startsWith(".") || specifier.startsWith("/"))
|
|
21
|
+
return null;
|
|
22
|
+
if (specifier.startsWith("node:") || specifier.startsWith("bun:") || specifier === "bun")
|
|
23
|
+
return null;
|
|
24
|
+
const [first = "", second] = specifier.split("/");
|
|
25
|
+
const name = first.startsWith("@") && second !== undefined ? `${first}/${second}` : first;
|
|
26
|
+
return BUILTINS.has(name) ? null : name;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @brief Packages the files import at runtime that the package's `peerDependencies` lack.
|
|
30
|
+
*
|
|
31
|
+
* Files marked `install: "package"` run inside the app, so every package they import must come from the
|
|
32
|
+
* app's own install: a package installed beside them would load a second copy, such as a second React.
|
|
33
|
+
* Type-only imports are left out, since they are gone at runtime, and so are imports of the package itself.
|
|
34
|
+
*
|
|
35
|
+
* @param packageRoot - Absolute folder holding the package's `package.json`.
|
|
36
|
+
* @param files - Files to scan, relative to the package root.
|
|
37
|
+
* @returns One entry per file and package that is not a peer, in file order.
|
|
38
|
+
*/
|
|
39
|
+
export function undeclaredImports(packageRoot, files) {
|
|
40
|
+
const manifest = PackagePeersSchema.parse(JSON.parse(fs.readFileSync(path.join(packageRoot, "package.json"), "utf8")));
|
|
41
|
+
const peers = manifest.peerDependencies ?? {};
|
|
42
|
+
const transpiler = new Bun.Transpiler({ loader: "tsx" });
|
|
43
|
+
return files.flatMap((file) => {
|
|
44
|
+
const imports = transpiler.scanImports(fs.readFileSync(path.join(packageRoot, file), "utf8"));
|
|
45
|
+
const packages = new Set(imports.map((entry) => packageOf(entry.path)));
|
|
46
|
+
return [...packages]
|
|
47
|
+
.filter((pkg) => pkg !== null && pkg !== manifest.name && peers[pkg] === undefined)
|
|
48
|
+
.map((pkg) => ({ file, pkg }));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=packageImports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageImports.js","sourceRoot":"","sources":["../../src/registry/packageImports.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAA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CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IACzH,MAAM,KAAK,GAAQ,QAAQ,CAAC,gBAAgB,IAAI,EAAE,CAAC;IACnD,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IAEzD,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC5B,MAAM,OAAO,GAAI,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;QAC/F,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACxE,OAAO,CAAC,GAAG,QAAQ,CAAC;aACjB,MAAM,CAAC,CAAC,GAAG,EAAiB,EAAE,CAAC,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,QAAQ,CAAC,IAAI,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC;aACjG,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -74,7 +74,7 @@ export function readComponentSource(flags) {
|
|
|
74
74
|
}]);
|
|
75
75
|
}
|
|
76
76
|
if (unreachable.length > 0) {
|
|
77
|
-
warnings.push(`${unreachable.join(", ")} import files that stay in the package, which only resolve when the source is installed with \`bun add
|
|
77
|
+
warnings.push(`${unreachable.join(", ")} import files that stay in the package, which only resolve when the source is installed with \`bun add\`, from npm, git, a workspace or a folder, and registered as \`npm:<package>\``);
|
|
78
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G,CAAC,EAAE,CAAC;YAC3B,QAAQ,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,uLAAuL,CAAC,CAAC;QAClO,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;IAC/B,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/theme/cssVars.d.ts
CHANGED
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
import type { CssVars } from "../registry/types";
|
|
2
|
+
/**
|
|
3
|
+
* @brief One token added to a stylesheet.
|
|
4
|
+
*
|
|
5
|
+
* @property block - Selector of the block it went into, e.g. `:root`.
|
|
6
|
+
* @property name - Its name with the leading `--`, e.g. `--sidebar`.
|
|
7
|
+
* @property value - Its value, e.g. `oklch(0.98 0 0)`.
|
|
8
|
+
*/
|
|
9
|
+
export interface AddedToken {
|
|
10
|
+
block: string;
|
|
11
|
+
name: string;
|
|
12
|
+
value: string;
|
|
13
|
+
}
|
|
2
14
|
/**
|
|
3
15
|
* @brief The result of adding tokens to a stylesheet.
|
|
4
16
|
*
|
|
5
17
|
* @property css - The stylesheet with the missing tokens added.
|
|
6
|
-
* @property added - Each token added,
|
|
18
|
+
* @property added - Each token added, in block order.
|
|
7
19
|
*/
|
|
8
20
|
export interface CssVarsMerge {
|
|
9
21
|
css: string;
|
|
10
|
-
added:
|
|
22
|
+
added: AddedToken[];
|
|
11
23
|
}
|
|
12
24
|
/**
|
|
13
25
|
* @brief Adds the theme tokens a stylesheet lacks: `light` to `:root`, `dark` to `.dark`, `theme` to
|
|
14
|
-
* `@theme inline`. When the stylesheet has a `@theme` block (Tailwind v4), each
|
|
15
|
-
* its `--color-<name>: var(--<name>)` mapping there, the way shadcn adds them, so
|
|
16
|
-
* as `bg-sidebar` work. Tokens the stylesheet defines
|
|
26
|
+
* `@theme inline`. When the stylesheet has a `@theme` block (Tailwind v4), each token whose value is a
|
|
27
|
+
* colour also gets its `--color-<name>: var(--<name>)` mapping there, the way shadcn adds them, so
|
|
28
|
+
* Tailwind classes such as `bg-sidebar` work. Tokens the stylesheet defines, in any block of the same
|
|
29
|
+
* kind, keep their value: the app's theme wins.
|
|
17
30
|
*
|
|
18
31
|
* @param css - The stylesheet, e.g. the contents of `src/index.css`.
|
|
19
32
|
* @param vars - Tokens to add.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cssVars.d.ts","sourceRoot":"","sources":["../../src/theme/cssVars.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"cssVars.d.ts","sourceRoot":"","sources":["../../src/theme/cssVars.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAqBjD;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAG,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAI,MAAM,CAAC;IACd,KAAK,EAAE,UAAU,EAAE,CAAC;CACrB;AAkED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,YAAY,CAanE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAM7D"}
|