frakment 3.0.0 → 4.0.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/README.md +3 -1
- package/dist/package.json +4 -3
- package/dist/src/commands/add.js +91 -42
- package/dist/src/commands/init.js +14 -11
- package/dist/src/commands/list.js +44 -8
- package/dist/src/utils/detect.js +3 -0
- package/dist/src/utils/safe-path.js +93 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Frakment-authored CLI code is licensed under MIT, which permits commercial use,
|
|
|
9
9
|
|
|
10
10
|
## Requirements
|
|
11
11
|
|
|
12
|
-
- Node.js >= 22.
|
|
12
|
+
- Node.js >= 22.22.2
|
|
13
13
|
- Tailwind CSS v4 (`@import "tailwindcss";` in your `globals.css`)
|
|
14
14
|
|
|
15
15
|
## Package managers
|
|
@@ -84,6 +84,8 @@ The default registry URL is written to `components.json` during `init`. If the p
|
|
|
84
84
|
npx frakment@latest add badge --registry http://localhost:8765
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
+
The CLI verifies official registry payloads against a Sigstore-signed manifest published by the Frakment GitHub repository. Custom registry URLs are outside that signature policy and should only be used when trusted.
|
|
88
|
+
|
|
87
89
|
## Troubleshooting
|
|
88
90
|
|
|
89
91
|
### "Frakment requires Tailwind v4"
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frakment",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "MIT-licensed CLI and design system for the Frakment component registry",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"components",
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"commander": "^15.1.0",
|
|
35
35
|
"execa": "^10.2.1",
|
|
36
36
|
"ora": "^10.0.0",
|
|
37
|
-
"prompts": "^2.4.2"
|
|
37
|
+
"prompts": "^2.4.2",
|
|
38
|
+
"sigstore": "^5.0.1"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@types/prompts": "^2.4.9",
|
|
@@ -44,6 +45,6 @@
|
|
|
44
45
|
"tailwind-merge": "^3.7.1"
|
|
45
46
|
},
|
|
46
47
|
"engines": {
|
|
47
|
-
"node": ">=22.
|
|
48
|
+
"node": ">=22.22.2"
|
|
48
49
|
}
|
|
49
50
|
}
|
package/dist/src/commands/add.js
CHANGED
|
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { createHash } from "node:crypto";
|
|
13
13
|
import { existsSync } from "node:fs";
|
|
14
|
-
import {
|
|
14
|
+
import { readFile } from "node:fs/promises";
|
|
15
15
|
import path from "node:path";
|
|
16
16
|
import chalk from "chalk";
|
|
17
17
|
import { execa } from "execa";
|
|
@@ -19,10 +19,17 @@ import ora from "ora";
|
|
|
19
19
|
import prompts from "prompts";
|
|
20
20
|
import { detectPackageManager, findProjectRoot } from "../utils/detect.js";
|
|
21
21
|
import { logger } from "../utils/logger.js";
|
|
22
|
+
import { resolveSafePath as assertSafePath, writeFileWithinProject, } from "../utils/safe-path.js";
|
|
23
|
+
export { assertSafePath };
|
|
22
24
|
const componentNamePattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
|
|
23
25
|
const dependencyPattern = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*(?:@[0-9A-Za-z*~^<>=|.+_-]+)?$/u;
|
|
24
26
|
const maxRegistryPayloadBytes = 10 * 1024 * 1024;
|
|
27
|
+
const maxRegistryManifestBytes = 1024 * 1024;
|
|
25
28
|
const defaultWebRegistry = "https://www.arrafi.dev/frakment/r";
|
|
29
|
+
const registryManifestUrl = "https://github.com/frakment/ui/releases/download/registry/manifest.json";
|
|
30
|
+
const registrySignatureUrl = "https://github.com/frakment/ui/releases/download/registry/manifest.sigstore.json";
|
|
31
|
+
const registrySignerIdentity = "^https://github\\.com/frakment/ui/\\.github/workflows/registry-sign\\.yml@refs/heads/main$";
|
|
32
|
+
const sigstoreIssuer = "https://token.actions.githubusercontent.com";
|
|
26
33
|
const defaultAliases = {
|
|
27
34
|
components: "@/components",
|
|
28
35
|
ui: "@/components/ui",
|
|
@@ -64,6 +71,59 @@ const canonicalize = (value) => {
|
|
|
64
71
|
const createIntegrity = (payload) => `sha256:${createHash("sha256")
|
|
65
72
|
.update(canonicalize(payload), "utf8")
|
|
66
73
|
.digest("hex")}`;
|
|
74
|
+
async function fetchRegistryText(url, maxBytes) {
|
|
75
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(10000) });
|
|
76
|
+
if (!response.ok) {
|
|
77
|
+
throw new Error(`HTTP ${response.status} from ${url}`);
|
|
78
|
+
}
|
|
79
|
+
const contentLength = Number(response.headers.get("content-length"));
|
|
80
|
+
if (Number.isFinite(contentLength) && contentLength > maxBytes) {
|
|
81
|
+
throw new Error(`Response from ${url} is too large`);
|
|
82
|
+
}
|
|
83
|
+
const raw = await response.text();
|
|
84
|
+
if (Buffer.byteLength(raw, "utf8") > maxBytes) {
|
|
85
|
+
throw new Error(`Response from ${url} is too large`);
|
|
86
|
+
}
|
|
87
|
+
return raw;
|
|
88
|
+
}
|
|
89
|
+
export async function fetchSignedRegistryManifest() {
|
|
90
|
+
const [manifestRaw, signatureRaw] = await Promise.all([
|
|
91
|
+
fetchRegistryText(registryManifestUrl, maxRegistryManifestBytes),
|
|
92
|
+
fetchRegistryText(registrySignatureUrl, maxRegistryManifestBytes),
|
|
93
|
+
]);
|
|
94
|
+
const manifest = JSON.parse(manifestRaw);
|
|
95
|
+
const signature = JSON.parse(signatureRaw);
|
|
96
|
+
const sigstore = await import("sigstore");
|
|
97
|
+
await sigstore.verify(signature, Buffer.from(manifestRaw, "utf8"), {
|
|
98
|
+
certificateIdentityURI: registrySignerIdentity,
|
|
99
|
+
certificateIssuer: sigstoreIssuer,
|
|
100
|
+
});
|
|
101
|
+
if (!isRecord(manifest) ||
|
|
102
|
+
manifest.version !== 1 ||
|
|
103
|
+
!isRecord(manifest.files)) {
|
|
104
|
+
throw new Error("Signed registry manifest has an invalid format");
|
|
105
|
+
}
|
|
106
|
+
const files = {};
|
|
107
|
+
for (const [name, digest] of Object.entries(manifest.files)) {
|
|
108
|
+
if (!/^(?:index|[a-z0-9]+(?:-[a-z0-9]+)*)\.json$/u.test(name) ||
|
|
109
|
+
typeof digest !== "string" ||
|
|
110
|
+
!/^sha256:[a-f0-9]{64}$/u.test(digest)) {
|
|
111
|
+
throw new Error("Signed registry manifest has an invalid file entry");
|
|
112
|
+
}
|
|
113
|
+
files[name] = digest;
|
|
114
|
+
}
|
|
115
|
+
return { files, version: 1 };
|
|
116
|
+
}
|
|
117
|
+
export function verifySignedRegistryFile(name, raw, manifest) {
|
|
118
|
+
const expectedDigest = manifest.files[name];
|
|
119
|
+
const actualDigest = `sha256:${createHash("sha256")
|
|
120
|
+
.update(raw, "utf8")
|
|
121
|
+
.digest("hex")}`;
|
|
122
|
+
if (!expectedDigest || expectedDigest !== actualDigest) {
|
|
123
|
+
throw new Error(`Registry file ${name} does not match the signed manifest`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export const isOfficialRegistryUrl = (url) => url === defaultWebRegistry;
|
|
67
127
|
function assertComponentName(name) {
|
|
68
128
|
if (typeof name !== "string" || !componentNamePattern.test(name)) {
|
|
69
129
|
throw new Error(`Invalid component name: ${String(name)}`);
|
|
@@ -74,9 +134,12 @@ function assertDependency(dependency) {
|
|
|
74
134
|
throw new Error(`Invalid dependency in registry payload: ${String(dependency)}`);
|
|
75
135
|
}
|
|
76
136
|
}
|
|
77
|
-
const getDependencyName = (dependency) => {
|
|
137
|
+
export const getDependencyName = (dependency) => {
|
|
78
138
|
if (dependency.startsWith("@")) {
|
|
79
|
-
|
|
139
|
+
const versionSeparator = dependency.indexOf("@", 1);
|
|
140
|
+
return versionSeparator === -1
|
|
141
|
+
? dependency
|
|
142
|
+
: dependency.slice(0, versionSeparator);
|
|
80
143
|
}
|
|
81
144
|
return dependency.split("@")[0];
|
|
82
145
|
};
|
|
@@ -156,7 +219,7 @@ export function resolveRegistryUrl(config, options = {}) {
|
|
|
156
219
|
const configured = (_a = registry !== null && registry !== void 0 ? registry : web) !== null && _a !== void 0 ? _a : defaultWebRegistry;
|
|
157
220
|
return getRegistryUrl((_b = options.registry) !== null && _b !== void 0 ? _b : configured);
|
|
158
221
|
}
|
|
159
|
-
async function fetchComponent(name, registryUrl, spinner) {
|
|
222
|
+
async function fetchComponent(name, registryUrl, spinner, manifest) {
|
|
160
223
|
try {
|
|
161
224
|
const res = await fetch(`${registryUrl}/${name}.json`, {
|
|
162
225
|
signal: AbortSignal.timeout(30000),
|
|
@@ -172,6 +235,9 @@ async function fetchComponent(name, registryUrl, spinner) {
|
|
|
172
235
|
if (Buffer.byteLength(raw, "utf8") > maxRegistryPayloadBytes) {
|
|
173
236
|
throw new Error("Registry response is too large");
|
|
174
237
|
}
|
|
238
|
+
if (manifest) {
|
|
239
|
+
verifySignedRegistryFile(`${name}.json`, raw, manifest);
|
|
240
|
+
}
|
|
175
241
|
const payload = validateRegistryPayload(JSON.parse(raw), name);
|
|
176
242
|
spinner.text = `Fetching ${name}...`;
|
|
177
243
|
return payload;
|
|
@@ -181,57 +247,26 @@ async function fetchComponent(name, registryUrl, spinner) {
|
|
|
181
247
|
process.exit(1);
|
|
182
248
|
}
|
|
183
249
|
}
|
|
184
|
-
export async function assertSafePath(cwd, relativePath) {
|
|
185
|
-
if (typeof relativePath !== "string" || relativePath.length === 0) {
|
|
186
|
-
throw new Error("Invalid file path in registry payload");
|
|
187
|
-
}
|
|
188
|
-
if (relativePath.includes("\0")) {
|
|
189
|
-
throw new Error(`Null byte in path: ${relativePath}`);
|
|
190
|
-
}
|
|
191
|
-
if (path.isAbsolute(relativePath) || /^[a-zA-Z]:/.test(relativePath)) {
|
|
192
|
-
throw new Error(`Absolute path rejected: ${relativePath}`);
|
|
193
|
-
}
|
|
194
|
-
if (relativePath.split(/[\\/]/).some((seg) => seg === "..")) {
|
|
195
|
-
throw new Error(`Parent traversal rejected: ${relativePath}`);
|
|
196
|
-
}
|
|
197
|
-
const root = path.resolve(cwd);
|
|
198
|
-
const target = path.resolve(root, relativePath);
|
|
199
|
-
if (target !== root && !target.startsWith(root + path.sep)) {
|
|
200
|
-
throw new Error(`Path escapes project root: ${relativePath}`);
|
|
201
|
-
}
|
|
202
|
-
const realRoot = await realpath(root).catch(() => root);
|
|
203
|
-
let existingParent = path.dirname(target);
|
|
204
|
-
while (!existsSync(existingParent)) {
|
|
205
|
-
existingParent = path.dirname(existingParent);
|
|
206
|
-
}
|
|
207
|
-
const realParent = await realpath(existingParent).catch(() => existingParent);
|
|
208
|
-
if (realParent !== realRoot && !realParent.startsWith(realRoot + path.sep)) {
|
|
209
|
-
throw new Error(`Symlink escape rejected: ${relativePath}`);
|
|
210
|
-
}
|
|
211
|
-
if (existsSync(target) && (await lstat(target)).isSymbolicLink()) {
|
|
212
|
-
throw new Error(`Symlink target rejected: ${relativePath}`);
|
|
213
|
-
}
|
|
214
|
-
return target;
|
|
215
|
-
}
|
|
216
250
|
async function writeFileSafely(file, cwd, options, aliases) {
|
|
217
251
|
const targetPath = await assertSafePath(cwd, file.path);
|
|
218
|
-
|
|
219
|
-
|
|
252
|
+
let overwrite = options.overwrite === true;
|
|
253
|
+
if (existsSync(targetPath) && !overwrite) {
|
|
254
|
+
const { overwrite: shouldOverwrite } = await prompts({
|
|
220
255
|
initial: false,
|
|
221
256
|
message: `${file.path} already exists. Overwrite?`,
|
|
222
257
|
name: "overwrite",
|
|
223
258
|
type: "confirm",
|
|
224
259
|
});
|
|
225
|
-
if (
|
|
260
|
+
if (shouldOverwrite === undefined || !shouldOverwrite) {
|
|
226
261
|
logger.info(`Skipped ${file.path}.`);
|
|
227
262
|
return null;
|
|
228
263
|
}
|
|
264
|
+
overwrite = true;
|
|
229
265
|
}
|
|
230
|
-
await mkdir(path.dirname(targetPath), { recursive: true });
|
|
231
266
|
const output = file.encoding === "base64"
|
|
232
267
|
? Buffer.from(file.content, "base64")
|
|
233
268
|
: rewriteImports(file.content, aliases).replaceAll("\r\n", "\n");
|
|
234
|
-
await
|
|
269
|
+
await writeFileWithinProject(cwd, file.path, output, overwrite);
|
|
235
270
|
return file.path;
|
|
236
271
|
}
|
|
237
272
|
export async function add(componentNamesInput, options = {}) {
|
|
@@ -274,6 +309,19 @@ export async function add(componentNamesInput, options = {}) {
|
|
|
274
309
|
process.exit(1);
|
|
275
310
|
}
|
|
276
311
|
const registrySpinner = ora("Checking registry").start();
|
|
312
|
+
let signedManifest;
|
|
313
|
+
if (registryUrl === defaultWebRegistry) {
|
|
314
|
+
try {
|
|
315
|
+
signedManifest = await fetchSignedRegistryManifest();
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
registrySpinner.fail(`Registry signature verification failed: ${error instanceof Error ? error.message : "unknown error"}`);
|
|
319
|
+
process.exit(1);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
logger.warn("Custom registry is not covered by Frakment's Sigstore signature.");
|
|
324
|
+
}
|
|
277
325
|
const roots = new Set(componentNames);
|
|
278
326
|
const queue = [...roots];
|
|
279
327
|
const fetched = new Map();
|
|
@@ -286,7 +334,7 @@ export async function add(componentNamesInput, options = {}) {
|
|
|
286
334
|
if (fetched.has(name)) {
|
|
287
335
|
continue;
|
|
288
336
|
}
|
|
289
|
-
const payload = await fetchComponent(name, registryUrl, registrySpinner);
|
|
337
|
+
const payload = await fetchComponent(name, registryUrl, registrySpinner, signedManifest);
|
|
290
338
|
fetched.set(name, payload);
|
|
291
339
|
for (const d of (_a = payload.dependencies) !== null && _a !== void 0 ? _a : []) {
|
|
292
340
|
const packageName = getDependencyName(d);
|
|
@@ -374,6 +422,7 @@ export async function add(componentNamesInput, options = {}) {
|
|
|
374
422
|
catch (error) {
|
|
375
423
|
s.fail("Failed to install dependencies.");
|
|
376
424
|
logger.warn(error instanceof Error ? error.message : "Unknown error");
|
|
425
|
+
process.exitCode = 1;
|
|
377
426
|
}
|
|
378
427
|
}
|
|
379
428
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import { execa } from "execa";
|
|
@@ -7,6 +7,7 @@ import ora from "ora";
|
|
|
7
7
|
import prompts from "prompts";
|
|
8
8
|
import { detectGlobalsCss, detectPackageManager, findProjectRoot, } from "../utils/detect.js";
|
|
9
9
|
import { logger } from "../utils/logger.js";
|
|
10
|
+
import { resolveSafePath, writeFileWithinProject } from "../utils/safe-path.js";
|
|
10
11
|
const __dirname = import.meta.dirname;
|
|
11
12
|
const templatesDir = path.resolve(__dirname, "../../templates");
|
|
12
13
|
const defaultRegistry = "https://www.arrafi.dev/frakment/r";
|
|
@@ -28,7 +29,7 @@ export async function init() {
|
|
|
28
29
|
process.exit(1);
|
|
29
30
|
}
|
|
30
31
|
const cssPath = detectGlobalsCss(cwd);
|
|
31
|
-
const cssFullPath =
|
|
32
|
+
const cssFullPath = await resolveSafePath(cwd, cssPath);
|
|
32
33
|
const cssCheck = ora("Verifying Tailwind CSS config").start();
|
|
33
34
|
if (!existsSync(cssFullPath)) {
|
|
34
35
|
cssCheck.fail(`CSS file not found: ${cssPath}`);
|
|
@@ -43,7 +44,7 @@ export async function init() {
|
|
|
43
44
|
process.exit(1);
|
|
44
45
|
}
|
|
45
46
|
cssCheck.succeed(`Verifying Tailwind CSS config. Found ${chalk.cyan("v4")} in ${chalk.cyan(cssPath)}.`);
|
|
46
|
-
const configPath =
|
|
47
|
+
const configPath = await resolveSafePath(cwd, configFile);
|
|
47
48
|
const configExists = existsSync(configPath);
|
|
48
49
|
let shouldWriteConfig = !configExists;
|
|
49
50
|
if (configExists) {
|
|
@@ -68,7 +69,7 @@ export async function init() {
|
|
|
68
69
|
const s = ora("Writing components.json").start();
|
|
69
70
|
const template = JSON.parse(await readFile(path.join(templatesDir, "components.json"), "utf-8"));
|
|
70
71
|
const config = Object.assign(Object.assign({}, template), { registry: defaultRegistry, tailwind: Object.assign(Object.assign({}, template.tailwind), { css: cssPath }) });
|
|
71
|
-
await
|
|
72
|
+
await writeFileWithinProject(cwd, configFile, `${JSON.stringify(config, null, 2)}\n`);
|
|
72
73
|
s.succeed("Writing components.json.");
|
|
73
74
|
}
|
|
74
75
|
const themeSpinner = ora("Updating CSS variables").start();
|
|
@@ -91,12 +92,12 @@ export async function init() {
|
|
|
91
92
|
else {
|
|
92
93
|
css = `${css.trimEnd()}\n\n${wrapped}\n`;
|
|
93
94
|
}
|
|
94
|
-
await
|
|
95
|
+
await writeFileWithinProject(cwd, cssPath, css);
|
|
95
96
|
themeSpinner.succeed(`Updating CSS variables in ${cssPath}`);
|
|
96
|
-
|
|
97
|
+
const utilsPath = await resolveSafePath(cwd, "lib/utils.ts");
|
|
98
|
+
if (!existsSync(utilsPath)) {
|
|
97
99
|
const s = ora("Creating lib/utils.ts").start();
|
|
98
|
-
await
|
|
99
|
-
await writeFile(path.join(cwd, "lib/utils.ts"), `import { clsx, type ClassValue } from "clsx";
|
|
100
|
+
await writeFileWithinProject(cwd, "lib/utils.ts", `import { clsx, type ClassValue } from "clsx";
|
|
100
101
|
import { twMerge } from "tailwind-merge";
|
|
101
102
|
|
|
102
103
|
export function cn(...inputs: ClassValue[]) {
|
|
@@ -106,13 +107,13 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
106
107
|
s.succeed("Created 1 file:");
|
|
107
108
|
logger.log(" - lib/utils.ts");
|
|
108
109
|
}
|
|
109
|
-
|
|
110
|
+
const motionPath = await resolveSafePath(cwd, "lib/motion.ts");
|
|
111
|
+
if (existsSync(motionPath)) {
|
|
110
112
|
}
|
|
111
113
|
else {
|
|
112
114
|
const s = ora("Creating lib/motion.ts").start();
|
|
113
|
-
await mkdir(path.join(cwd, "lib"), { recursive: true });
|
|
114
115
|
const motion = await readFile(path.join(templatesDir, "lib/motion.ts"), "utf-8");
|
|
115
|
-
await
|
|
116
|
+
await writeFileWithinProject(cwd, "lib/motion.ts", motion);
|
|
116
117
|
s.succeed("Created 1 file:");
|
|
117
118
|
logger.log(" - lib/motion.ts");
|
|
118
119
|
}
|
|
@@ -137,6 +138,8 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
137
138
|
catch (error) {
|
|
138
139
|
s.fail("Failed to install dependencies.");
|
|
139
140
|
logger.warn(error instanceof Error ? error.message : "Unknown error");
|
|
141
|
+
process.exitCode = 1;
|
|
142
|
+
return;
|
|
140
143
|
}
|
|
141
144
|
}
|
|
142
145
|
logger.break();
|
|
@@ -5,8 +5,17 @@ import chalk from "chalk";
|
|
|
5
5
|
import ora from "ora";
|
|
6
6
|
import { findProjectRoot } from "../utils/detect.js";
|
|
7
7
|
import { logger } from "../utils/logger.js";
|
|
8
|
+
import { fetchSignedRegistryManifest, isOfficialRegistryUrl, resolveRegistryUrl, verifySignedRegistryFile, } from "./add.js";
|
|
9
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10
|
+
export const isRegistryIndex = (value) => isRecord(value) &&
|
|
11
|
+
Array.isArray(value.components) &&
|
|
12
|
+
value.components.every((component) => isRecord(component) &&
|
|
13
|
+
typeof component.name === "string" &&
|
|
14
|
+
/^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(component.name) &&
|
|
15
|
+
(component.description === undefined ||
|
|
16
|
+
typeof component.description === "string"));
|
|
8
17
|
export async function list(options) {
|
|
9
|
-
var _a
|
|
18
|
+
var _a;
|
|
10
19
|
let cwd;
|
|
11
20
|
const preflight = ora("Preflight checks").start();
|
|
12
21
|
try {
|
|
@@ -23,19 +32,46 @@ export async function list(options) {
|
|
|
23
32
|
logger.info("Run `frakment init` first.");
|
|
24
33
|
process.exit(1);
|
|
25
34
|
}
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
let registryUrl;
|
|
36
|
+
try {
|
|
37
|
+
const configRaw = await readFile(configPath, "utf-8");
|
|
38
|
+
const config = JSON.parse(configRaw.replace(/^\uFEFF/u, ""));
|
|
39
|
+
registryUrl = resolveRegistryUrl(config, options);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
logger.error(error instanceof Error ? error.message : "Invalid components.json.");
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
28
45
|
const s = ora("Fetching components").start();
|
|
29
46
|
let index;
|
|
30
47
|
try {
|
|
31
|
-
const
|
|
48
|
+
const manifest = isOfficialRegistryUrl(registryUrl)
|
|
49
|
+
? await fetchSignedRegistryManifest()
|
|
50
|
+
: undefined;
|
|
51
|
+
if (!manifest) {
|
|
52
|
+
logger.warn("Custom registry is not covered by Frakment's Sigstore signature.");
|
|
53
|
+
}
|
|
54
|
+
const res = await fetch(`${registryUrl}/index.json`, {
|
|
55
|
+
signal: AbortSignal.timeout(30000),
|
|
56
|
+
});
|
|
32
57
|
if (!res.ok) {
|
|
33
58
|
throw new Error(`HTTP ${res.status}`);
|
|
34
59
|
}
|
|
35
|
-
|
|
60
|
+
const raw = await res.text();
|
|
61
|
+
if (Buffer.byteLength(raw, "utf8") > 10 * 1024 * 1024) {
|
|
62
|
+
throw new Error("Registry index response is too large");
|
|
63
|
+
}
|
|
64
|
+
if (manifest) {
|
|
65
|
+
verifySignedRegistryFile("index.json", raw, manifest);
|
|
66
|
+
}
|
|
67
|
+
const response = JSON.parse(raw);
|
|
68
|
+
if (!isRegistryIndex(response)) {
|
|
69
|
+
throw new Error("Registry index has an invalid shape");
|
|
70
|
+
}
|
|
71
|
+
index = response;
|
|
36
72
|
}
|
|
37
|
-
catch (
|
|
38
|
-
s.fail(
|
|
73
|
+
catch (error) {
|
|
74
|
+
s.fail(`Failed to fetch component list: ${error instanceof Error ? error.message : "unknown error"}`);
|
|
39
75
|
process.exit(1);
|
|
40
76
|
}
|
|
41
77
|
s.succeed(`Found ${index.components.length} component(s).`);
|
|
@@ -47,7 +83,7 @@ export async function list(options) {
|
|
|
47
83
|
const nameWidth = Math.max(...index.components.map((c) => c.name.length));
|
|
48
84
|
logger.break();
|
|
49
85
|
for (const c of index.components) {
|
|
50
|
-
logger.log(` ${chalk.cyan(c.name.padEnd(nameWidth))} ${chalk.dim((
|
|
86
|
+
logger.log(` ${chalk.cyan(c.name.padEnd(nameWidth))} ${chalk.dim((_a = c.description) !== null && _a !== void 0 ? _a : "")}`);
|
|
51
87
|
}
|
|
52
88
|
logger.break();
|
|
53
89
|
logger.log(`Add one with ${chalk.cyan("frakment add <name>")}`);
|
package/dist/src/utils/detect.js
CHANGED
|
@@ -17,6 +17,9 @@ export function detectPackageManager(cwd) {
|
|
|
17
17
|
if (existsSync(path.join(cwd, "yarn.lock"))) {
|
|
18
18
|
return "yarn";
|
|
19
19
|
}
|
|
20
|
+
if (existsSync(path.join(cwd, "bun.lock"))) {
|
|
21
|
+
return "bun";
|
|
22
|
+
}
|
|
20
23
|
if (existsSync(path.join(cwd, "bun.lockb"))) {
|
|
21
24
|
return "bun";
|
|
22
25
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { link, lstat, mkdir, realpath, rename, rm, writeFile, } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
const isWithin = (root, target) => {
|
|
5
|
+
const relative = path.relative(root, target);
|
|
6
|
+
return (relative === "" ||
|
|
7
|
+
(relative !== ".." &&
|
|
8
|
+
!relative.startsWith(`..${path.sep}`) &&
|
|
9
|
+
!path.isAbsolute(relative)));
|
|
10
|
+
};
|
|
11
|
+
const isPathMissing = (error) => error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
12
|
+
export async function resolveSafePath(cwd, relativePath) {
|
|
13
|
+
if (typeof relativePath !== "string" || relativePath.length === 0) {
|
|
14
|
+
throw new Error("Invalid file path in registry payload");
|
|
15
|
+
}
|
|
16
|
+
if (relativePath.includes("\0")) {
|
|
17
|
+
throw new Error(`Null byte in path: ${relativePath}`);
|
|
18
|
+
}
|
|
19
|
+
if (path.isAbsolute(relativePath) ||
|
|
20
|
+
path.win32.isAbsolute(relativePath) ||
|
|
21
|
+
/^[a-zA-Z]:/u.test(relativePath)) {
|
|
22
|
+
throw new Error(`Absolute path rejected: ${relativePath}`);
|
|
23
|
+
}
|
|
24
|
+
if (relativePath.split(/[\\/]/u).some((segment) => segment === "..")) {
|
|
25
|
+
throw new Error(`Parent traversal rejected: ${relativePath}`);
|
|
26
|
+
}
|
|
27
|
+
const root = await realpath(path.resolve(cwd));
|
|
28
|
+
const target = path.resolve(root, relativePath);
|
|
29
|
+
if (!isWithin(root, target)) {
|
|
30
|
+
throw new Error(`Path escapes project root: ${relativePath}`);
|
|
31
|
+
}
|
|
32
|
+
let existingAncestor = path.dirname(target);
|
|
33
|
+
let realAncestor;
|
|
34
|
+
while (true) {
|
|
35
|
+
try {
|
|
36
|
+
realAncestor = await realpath(existingAncestor);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (!isPathMissing(error)) {
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
const parent = path.dirname(existingAncestor);
|
|
44
|
+
if (parent === existingAncestor) {
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
existingAncestor = parent;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (!isWithin(root, realAncestor)) {
|
|
51
|
+
throw new Error(`Symlink escape rejected: ${relativePath}`);
|
|
52
|
+
}
|
|
53
|
+
const canonicalTarget = path.resolve(realAncestor, path.relative(existingAncestor, target));
|
|
54
|
+
if (!isWithin(root, canonicalTarget)) {
|
|
55
|
+
throw new Error(`Path escapes project root: ${relativePath}`);
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
if ((await lstat(target)).isSymbolicLink()) {
|
|
59
|
+
throw new Error(`Symlink target rejected: ${relativePath}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (!isPathMissing(error)) {
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return canonicalTarget;
|
|
68
|
+
}
|
|
69
|
+
export async function writeFileWithinProject(cwd, relativePath, contents, overwrite = true) {
|
|
70
|
+
const initialTarget = await resolveSafePath(cwd, relativePath);
|
|
71
|
+
await mkdir(path.dirname(initialTarget), { recursive: true });
|
|
72
|
+
const target = await resolveSafePath(cwd, relativePath);
|
|
73
|
+
const parent = await realpath(path.dirname(target));
|
|
74
|
+
const root = await realpath(path.resolve(cwd));
|
|
75
|
+
if (!isWithin(root, parent)) {
|
|
76
|
+
throw new Error(`Symlink escape rejected: ${relativePath}`);
|
|
77
|
+
}
|
|
78
|
+
const canonicalTarget = path.join(parent, path.basename(target));
|
|
79
|
+
const temporary = path.join(parent, `.frakment-${randomUUID()}.tmp`);
|
|
80
|
+
await writeFile(temporary, contents, { flag: "wx" });
|
|
81
|
+
try {
|
|
82
|
+
if (overwrite) {
|
|
83
|
+
await rename(temporary, canonicalTarget);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
await link(temporary, canonicalTarget);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
await rm(temporary, { force: true });
|
|
91
|
+
}
|
|
92
|
+
return canonicalTarget;
|
|
93
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frakment",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "MIT-licensed CLI and design system for the Frakment component registry",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"components",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"commander": "^15.1.0",
|
|
30
30
|
"execa": "^10.2.1",
|
|
31
31
|
"ora": "^10.0.0",
|
|
32
|
-
"prompts": "^2.4.2"
|
|
32
|
+
"prompts": "^2.4.2",
|
|
33
|
+
"sigstore": "^5.0.1"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@types/prompts": "^2.4.9",
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
"tailwind-merge": "^3.7.1"
|
|
40
41
|
},
|
|
41
42
|
"engines": {
|
|
42
|
-
"node": ">=22.
|
|
43
|
+
"node": ">=22.22.2"
|
|
43
44
|
},
|
|
44
45
|
"scripts": {
|
|
45
46
|
"build": "tsc -p tsconfig.build.json && node ../../scripts/copy-runtime-package.ts",
|