juas.dev 1.0.2 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,52 +1,52 @@
1
- // ============================================================
2
- // commands/search.js
3
- // npx juas search "glass button"
4
- // ============================================================
5
- import ora from "ora";
6
- import pc from "picocolors";
7
-
8
- import { logger } from "../lib/logger.js";
9
- import { searchComponents } from "../lib/supabase.js";
10
-
11
- export async function cmdSearch(query, options) {
12
- logger.banner();
13
- logger.info(`Searching for: ${pc.bold(query)}`);
14
- logger.blank();
15
-
16
- const spinner = ora("Searching juas.dev…").start();
17
-
18
- let results;
19
- try {
20
- results = await searchComponents(query);
21
- spinner.succeed(`${results.length} result${results.length !== 1 ? "s" : ""}`);
22
- } catch (err) {
23
- spinner.fail("Search failed.");
24
- logger.error(err.message);
25
- process.exit(1);
26
- }
27
-
28
- if (!results.length) {
29
- logger.warn(`No components matched "${query}".`);
30
- logger.info(`Try browsing all: ${pc.bold("npx juas list")}`);
31
- return;
32
- }
33
-
34
- if (options.json) {
35
- console.log(JSON.stringify(results, null, 2));
36
- return;
37
- }
38
-
39
- logger.blank();
40
- for (const item of results) {
41
- const tags = item.tags?.slice(0, 4).map((t) => pc.dim(`#${t}`)).join(" ") ?? "";
42
- console.log(` ${pc.green(pc.bold(item.slug.padEnd(36)))} ${pc.dim(item.category ?? "")}`);
43
- if (item.description) {
44
- console.log(` ${pc.dim(item.description.slice(0, 72))}`);
45
- }
46
- if (tags) console.log(` ${tags}`);
47
- console.log();
48
- }
49
-
50
- logger.info(`Install: ${pc.bold("npx juas add <slug>")}`);
51
- logger.blank();
52
- }
1
+ // ============================================================
2
+ // commands/search.js
3
+ // npx juas.dev search "glass button"
4
+ // ============================================================
5
+ import ora from "ora";
6
+ import pc from "picocolors";
7
+
8
+ import { logger } from "../lib/logger.js";
9
+ import { searchComponents } from "../lib/supabase.js";
10
+
11
+ export async function cmdSearch(query, options) {
12
+ logger.banner();
13
+ logger.info(`Searching for: ${pc.bold(query)}`);
14
+ logger.blank();
15
+
16
+ const spinner = ora("Searching juas.dev…").start();
17
+
18
+ let results;
19
+ try {
20
+ results = await searchComponents(query);
21
+ spinner.succeed(`${results.length} result${results.length !== 1 ? "s" : ""}`);
22
+ } catch (err) {
23
+ spinner.fail("Search failed.");
24
+ logger.error(err.message);
25
+ process.exit(1);
26
+ }
27
+
28
+ if (!results.length) {
29
+ logger.warn(`No components matched "${query}".`);
30
+ logger.info(`Try browsing all: ${pc.bold("npx juas.dev list")}`);
31
+ return;
32
+ }
33
+
34
+ if (options.json) {
35
+ console.log(JSON.stringify(results, null, 2));
36
+ return;
37
+ }
38
+
39
+ logger.blank();
40
+ for (const item of results) {
41
+ const tags = item.tags?.slice(0, 4).map((t) => pc.dim(`#${t}`)).join(" ") ?? "";
42
+ console.log(` ${pc.green(pc.bold(item.slug.padEnd(36)))} ${pc.dim(item.category ?? "")}`);
43
+ if (item.description) {
44
+ console.log(` ${pc.dim(item.description.slice(0, 72))}`);
45
+ }
46
+ if (tags) console.log(` ${tags}`);
47
+ console.log();
48
+ }
49
+
50
+ logger.info(`Install: ${pc.bold("npx juas.dev add <slug>")}`);
51
+ logger.blank();
52
+ }
@@ -0,0 +1,119 @@
1
+ // ============================================================
2
+ // commands/whoami.js — `juas whoami [--check <slug>]`
3
+ // ============================================================
4
+ import ora from "ora";
5
+ import pc from "picocolors";
6
+ import { fetchWhoami } from "../lib/authApi.js";
7
+ import { getActiveToken, getCliBaseUrl } from "../lib/credentials.js";
8
+ import { logger } from "../lib/logger.js";
9
+
10
+ export async function cmdWhoami(options = {}) {
11
+ const isJson = Boolean(options.json);
12
+ const { token, source, baseUrl: savedBaseUrl } = getActiveToken(options.token);
13
+ const baseUrl = getCliBaseUrl(options.webUrl || savedBaseUrl);
14
+
15
+ if (!token) {
16
+ if (isJson) {
17
+ console.log(JSON.stringify({ authenticated: false, error: "Not logged in" }, null, 2));
18
+ } else {
19
+ logger.banner();
20
+ logger.warn("Not logged in to juas.dev.");
21
+ logger.info(`Authenticate now: ${pc.bold("npx juas.dev login")}`);
22
+ logger.blank();
23
+ }
24
+ process.exit(1);
25
+ }
26
+
27
+ const spinner = isJson ? null : ora("Checking access status with juas.dev…").start();
28
+
29
+ let res;
30
+ try {
31
+ res = await fetchWhoami(token, { slug: options.check, baseUrl });
32
+ } catch (err) {
33
+ if (spinner) spinner.fail("Network error.");
34
+ if (isJson) {
35
+ console.log(JSON.stringify({ authenticated: false, error: err.message }, null, 2));
36
+ } else {
37
+ logger.error(err.message);
38
+ }
39
+ process.exit(1);
40
+ }
41
+
42
+ if (!res.ok || !res.data?.authenticated) {
43
+ if (spinner) spinner.fail("Session is invalid or revoked.");
44
+ const errorMsg = res.data?.error || `HTTP ${res.status}: Unauthorized`;
45
+ if (isJson) {
46
+ console.log(JSON.stringify({ authenticated: false, error: errorMsg }, null, 2));
47
+ } else {
48
+ logger.error(errorMsg);
49
+ logger.info(`Run ${pc.bold("npx juas.dev login")} to re-authenticate.`);
50
+ logger.blank();
51
+ }
52
+ process.exit(1);
53
+ }
54
+
55
+ const data = res.data;
56
+
57
+ if (isJson) {
58
+ console.log(JSON.stringify(data, null, 2));
59
+ if (options.check && !data.componentAccess?.canViewFullCode) {
60
+ process.exit(1);
61
+ }
62
+ return;
63
+ }
64
+
65
+ spinner.stop();
66
+ logger.banner();
67
+ logger.success(pc.bold("Authenticated with juas.dev"));
68
+ logger.divider();
69
+
70
+ const handle = data.user?.username
71
+ ? `@${data.user.username}`
72
+ : data.user?.name || data.user?.id;
73
+ logger.label("Account", handle);
74
+ logger.label(
75
+ "Auth Source",
76
+ `${data.auth?.type === "api_key" ? `API Key (${data.auth.scope})` : "Session JWT"} via ${source}`
77
+ );
78
+ logger.label(
79
+ "Plan",
80
+ `${data.subscription?.tier || "free"} (${data.subscription?.status || "active"})`
81
+ );
82
+ logger.label(
83
+ "Pro CLI Access",
84
+ data.subscription?.hasUnlimitedProAccess
85
+ ? pc.green("Unlocked (Pro / Lifetime)")
86
+ : data.subscription?.hasYearlyAccess
87
+ ? pc.green("Yearly Window Active")
88
+ : pc.yellow("Free / Credit-Gated")
89
+ );
90
+ logger.label(
91
+ "Credits",
92
+ data.subscription?.hasUnlimitedProAccess
93
+ ? "Unlimited"
94
+ : String(data.creditsAvailable ?? 0)
95
+ );
96
+
97
+ if (data.componentAccess) {
98
+ logger.divider();
99
+ const access = data.componentAccess;
100
+ if (!access.found) {
101
+ logger.error(`Component "${access.slug}" not found.`);
102
+ logger.blank();
103
+ process.exit(1);
104
+ }
105
+ const badge = access.canViewFullCode
106
+ ? pc.green(`UNLOCKED (${access.accessType})`)
107
+ : pc.red("LOCKED");
108
+ logger.label(`Component (${access.slug})`, badge);
109
+ if (!access.canViewFullCode) {
110
+ logger.info(access.reason || "Requires Pro plan or 1 credit.");
111
+ logger.info(`Unlock on web: ${pc.underline("https://juas.dev/component/" + access.slug)}`);
112
+ logger.blank();
113
+ process.exit(1);
114
+ }
115
+ }
116
+
117
+ logger.divider();
118
+ logger.blank();
119
+ }
@@ -0,0 +1,67 @@
1
+ // ============================================================
2
+ // authApi.js — CLI HTTP client for /api/cli/whoami & /component
3
+ // ============================================================
4
+ import { getCliBaseUrl } from "./credentials.js";
5
+
6
+ /**
7
+ * Queries `/api/cli/whoami` to verify token validity, plan tier, credits,
8
+ * and optional component entitlement (`slug`).
9
+ */
10
+ export async function fetchWhoami(token, options = {}) {
11
+ const baseUrl = getCliBaseUrl(options.baseUrl);
12
+ const url = new URL("/api/cli/whoami", baseUrl);
13
+ if (options.slug) {
14
+ url.searchParams.set("slug", String(options.slug).trim());
15
+ }
16
+
17
+ const headers = {
18
+ Accept: "application/json",
19
+ };
20
+ if (token) {
21
+ headers.Authorization = `Bearer ${token}`;
22
+ }
23
+
24
+ const res = await fetch(url.toString(), { method: "GET", headers });
25
+ let data = null;
26
+ try {
27
+ data = await res.json();
28
+ } catch {
29
+ data = null;
30
+ }
31
+
32
+ return {
33
+ ok: res.ok,
34
+ status: res.status,
35
+ data,
36
+ };
37
+ }
38
+
39
+ /**
40
+ * Fetches component source files or lock metadata from `/api/cli/component`.
41
+ */
42
+ export async function fetchCliComponent(slug, options = {}) {
43
+ const baseUrl = getCliBaseUrl(options.baseUrl);
44
+ const url = new URL("/api/cli/component", baseUrl);
45
+ url.searchParams.set("slug", String(slug).trim());
46
+
47
+ const headers = {
48
+ Accept: "application/json",
49
+ };
50
+ if (options.token) {
51
+ headers.Authorization = `Bearer ${options.token}`;
52
+ }
53
+
54
+ const res = await fetch(url.toString(), { method: "GET", headers });
55
+ let data = null;
56
+ try {
57
+ data = await res.json();
58
+ } catch {
59
+ data = null;
60
+ }
61
+
62
+ return {
63
+ ok: res.ok,
64
+ status: res.status,
65
+ data,
66
+ };
67
+ }
package/src/lib/config.js CHANGED
@@ -1,48 +1,48 @@
1
- // ============================================================
2
- // config.js — read/write juas.config.json in the user's project
3
- // ============================================================
4
- import fs from "fs-extra";
5
- import path from "path";
6
-
7
- const CONFIG_FILE = "juas.config.json";
8
-
9
- /** Default config shape */
10
- const DEFAULT_CONFIG = {
11
- outputDir: "src/components/juas",
12
- typescript: true,
13
- framework: "react",
14
- };
15
-
16
- /**
17
- * Find the nearest juas.config.json walking up from cwd.
18
- * Returns the absolute path or null if not found.
19
- */
20
- export function findConfig(cwd = process.cwd()) {
21
- let dir = cwd;
22
- while (true) {
23
- const candidate = path.join(dir, CONFIG_FILE);
24
- if (fs.existsSync(candidate)) return candidate;
25
- const parent = path.dirname(dir);
26
- if (parent === dir) return null; // reached filesystem root
27
- dir = parent;
28
- }
29
- }
30
-
31
- /**
32
- * Load config. Falls back to defaults if no file found.
33
- */
34
- export function loadConfig(cwd = process.cwd()) {
35
- const cfgPath = findConfig(cwd);
36
- if (!cfgPath) return { ...DEFAULT_CONFIG, _path: null };
37
- const raw = fs.readJsonSync(cfgPath);
38
- return { ...DEFAULT_CONFIG, ...raw, _path: cfgPath };
39
- }
40
-
41
- /**
42
- * Write a new config file.
43
- */
44
- export async function writeConfig(dir, data) {
45
- const cfgPath = path.join(dir, CONFIG_FILE);
46
- await fs.outputJson(cfgPath, { ...DEFAULT_CONFIG, ...data }, { spaces: 2 });
47
- return cfgPath;
48
- }
1
+ // ============================================================
2
+ // config.js — read/write juas.config.json in the user's project
3
+ // ============================================================
4
+ import fs from "fs-extra";
5
+ import path from "path";
6
+
7
+ const CONFIG_FILE = "juas.config.json";
8
+
9
+ /** Default config shape */
10
+ const DEFAULT_CONFIG = {
11
+ outputDir: "src/components/juas",
12
+ typescript: true,
13
+ framework: "react",
14
+ };
15
+
16
+ /**
17
+ * Find the nearest juas.config.json walking up from cwd.
18
+ * Returns the absolute path or null if not found.
19
+ */
20
+ export function findConfig(cwd = process.cwd()) {
21
+ let dir = cwd;
22
+ while (true) {
23
+ const candidate = path.join(dir, CONFIG_FILE);
24
+ if (fs.existsSync(candidate)) return candidate;
25
+ const parent = path.dirname(dir);
26
+ if (parent === dir) return null; // reached filesystem root
27
+ dir = parent;
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Load config. Falls back to defaults if no file found.
33
+ */
34
+ export function loadConfig(cwd = process.cwd()) {
35
+ const cfgPath = findConfig(cwd);
36
+ if (!cfgPath) return { ...DEFAULT_CONFIG, _path: null };
37
+ const raw = fs.readJsonSync(cfgPath);
38
+ return { ...DEFAULT_CONFIG, ...raw, _path: cfgPath };
39
+ }
40
+
41
+ /**
42
+ * Write a new config file.
43
+ */
44
+ export async function writeConfig(dir, data) {
45
+ const cfgPath = path.join(dir, CONFIG_FILE);
46
+ await fs.outputJson(cfgPath, { ...DEFAULT_CONFIG, ...data }, { spaces: 2 });
47
+ return cfgPath;
48
+ }
@@ -0,0 +1,164 @@
1
+ // ============================================================
2
+ // credentials.js — Secure local credential storage (~/.juas)
3
+ // ============================================================
4
+ import fs from "fs";
5
+ import fsp from "fs/promises";
6
+ import os from "os";
7
+ import path from "path";
8
+
9
+ export const DEFAULT_CLI_BASE_URL = "https://juas.dev";
10
+
11
+ /**
12
+ * Resolves the directory where CLI credentials are persisted.
13
+ * Supports JUAS_HOME override for isolated environments and automated tests.
14
+ */
15
+ export function getCredentialsDir() {
16
+ const override = process.env.JUAS_HOME?.trim();
17
+ if (override) {
18
+ return path.resolve(override);
19
+ }
20
+ return path.join(os.homedir(), ".juas");
21
+ }
22
+
23
+ export function getCredentialsPath() {
24
+ return path.join(getCredentialsDir(), "credentials.json");
25
+ }
26
+
27
+ /**
28
+ * Validates and normalizes the Juas.dev base URL.
29
+ * Rejects unencrypted remote HTTP URLs to prevent credential leakage over plaintext networks.
30
+ */
31
+ export function validateCliBaseUrl(rawUrl) {
32
+ const candidate = (rawUrl || DEFAULT_CLI_BASE_URL).trim().replace(/\/+$/, "");
33
+ let parsed;
34
+ try {
35
+ parsed = new URL(candidate);
36
+ } catch {
37
+ throw new Error(`Invalid Juas CLI URL: "${candidate}"`);
38
+ }
39
+
40
+ const isLocalhost =
41
+ parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" || parsed.hostname === "::1";
42
+
43
+ if (parsed.protocol !== "https:" && !(parsed.protocol === "http:" && isLocalhost)) {
44
+ throw new Error(
45
+ `Insecure CLI endpoint "${candidate}". Use HTTPS or a local loopback URL.`
46
+ );
47
+ }
48
+
49
+ return parsed.origin;
50
+ }
51
+
52
+ export function getCliBaseUrl(explicitUrl) {
53
+ return validateCliBaseUrl(explicitUrl || process.env.JUAS_CLI_URL || DEFAULT_CLI_BASE_URL);
54
+ }
55
+
56
+ /**
57
+ * Reads saved CLI credentials from disk, returning null if absent or malformed.
58
+ */
59
+ export function readCredentials() {
60
+ const credPath = getCredentialsPath();
61
+ try {
62
+ if (!fs.existsSync(credPath)) return null;
63
+ const raw = JSON.parse(fs.readFileSync(credPath, "utf-8"));
64
+ if (!raw || typeof raw !== "object" || typeof raw.token !== "string" || !raw.token.trim()) {
65
+ return null;
66
+ }
67
+ return {
68
+ ...raw,
69
+ token: raw.token.trim(),
70
+ };
71
+ } catch {
72
+ return null;
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Persists CLI credentials with restrictive permissions (0700 dir / 0600 file on POSIX).
78
+ */
79
+ export async function writeCredentials(payload) {
80
+ if (!payload || typeof payload.token !== "string" || !payload.token.trim()) {
81
+ throw new Error("Cannot persist empty CLI credentials.");
82
+ }
83
+
84
+ const dir = getCredentialsDir();
85
+ const credPath = getCredentialsPath();
86
+
87
+ await fsp.mkdir(dir, { recursive: true, mode: 0o700 });
88
+ if (process.platform !== "win32") {
89
+ await fsp.chmod(dir, 0o700).catch(() => undefined);
90
+ }
91
+
92
+ const record = {
93
+ token: payload.token.trim(),
94
+ baseUrl: payload.baseUrl || DEFAULT_CLI_BASE_URL,
95
+ user: payload.user || null,
96
+ subscription: payload.subscription || null,
97
+ savedAt: payload.savedAt || new Date().toISOString(),
98
+ };
99
+
100
+ await fsp.writeFile(credPath, JSON.stringify(record, null, 2) + "\n", {
101
+ encoding: "utf-8",
102
+ mode: 0o600,
103
+ });
104
+ if (process.platform !== "win32") {
105
+ await fsp.chmod(credPath, 0o600).catch(() => undefined);
106
+ }
107
+
108
+ return credPath;
109
+ }
110
+
111
+ /**
112
+ * Removes saved local credentials if present. Returns true if a file was deleted.
113
+ */
114
+ export async function clearCredentials() {
115
+ const credPath = getCredentialsPath();
116
+ try {
117
+ await fsp.unlink(credPath);
118
+ return true;
119
+ } catch (err) {
120
+ if (err && typeof err === "object" && err.code === "ENOENT") {
121
+ return false;
122
+ }
123
+ throw err;
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Resolves the active CLI bearer token following standard precedence:
129
+ * 1. Explicit `--token` flag
130
+ * 2. `JUAS_API_TOKEN` environment variable
131
+ * 3. `~/.juas/credentials.json`
132
+ */
133
+ export function getActiveToken(explicitToken) {
134
+ const flagToken = typeof explicitToken === "string" ? explicitToken.trim() : "";
135
+ if (flagToken) {
136
+ return { token: flagToken, source: "flag", baseUrl: getCliBaseUrl() };
137
+ }
138
+
139
+ const envToken = process.env.JUAS_API_TOKEN?.trim() || "";
140
+ if (envToken) {
141
+ return { token: envToken, source: "env", baseUrl: getCliBaseUrl() };
142
+ }
143
+
144
+ const saved = readCredentials();
145
+ if (saved?.token) {
146
+ return {
147
+ token: saved.token,
148
+ source: "file",
149
+ baseUrl: saved.baseUrl ? validateCliBaseUrl(saved.baseUrl) : getCliBaseUrl(),
150
+ saved,
151
+ };
152
+ }
153
+
154
+ return { token: null, source: null, baseUrl: getCliBaseUrl() };
155
+ }
156
+
157
+ /**
158
+ * Returns a redacted preview of a CLI key suitable for terminal output.
159
+ */
160
+ export function maskToken(token) {
161
+ if (!token || typeof token !== "string") return "(none)";
162
+ if (token.length <= 16) return "••••••••";
163
+ return `${token.slice(0, 12)}••••••••${token.slice(-4)}`;
164
+ }
package/src/lib/deps.js CHANGED
@@ -1,55 +1,55 @@
1
- // ============================================================
2
- // deps.js — detect the user's package manager & install deps
3
- // ============================================================
4
- import { execSync, spawnSync } from "child_process";
5
- import fs from "fs-extra";
6
- import path from "path";
7
-
8
- /** Detect which package manager is in use. */
9
- export function detectPackageManager(cwd = process.cwd()) {
10
- if (fs.existsSync(path.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
11
- if (fs.existsSync(path.join(cwd, "yarn.lock"))) return "yarn";
12
- if (fs.existsSync(path.join(cwd, "bun.lockb"))) return "bun";
13
- return "npm";
14
- }
15
-
16
- /**
17
- * Install an array of npm packages using the detected package manager.
18
- * @param {string[]} packages - e.g. ["framer-motion", "clsx"]
19
- * @param {string} cwd - project root
20
- */
21
- export function installDependencies(packages, cwd = process.cwd()) {
22
- if (!packages.length) return;
23
- const pm = detectPackageManager(cwd);
24
-
25
- const installCmd = {
26
- npm: `npm install ${packages.join(" ")}`,
27
- pnpm: `pnpm add ${packages.join(" ")}`,
28
- yarn: `yarn add ${packages.join(" ")}`,
29
- bun: `bun add ${packages.join(" ")}`,
30
- }[pm];
31
-
32
- execSync(installCmd, { cwd, stdio: "inherit" });
33
- }
34
-
35
- /**
36
- * Check whether the user already has a package installed.
37
- */
38
- export function isPackageInstalled(pkg, cwd = process.cwd()) {
39
- const pkgJsonPath = path.join(cwd, "package.json");
40
- if (!fs.existsSync(pkgJsonPath)) return false;
41
- const pkgJson = fs.readJsonSync(pkgJsonPath);
42
- const allDeps = {
43
- ...(pkgJson.dependencies ?? {}),
44
- ...(pkgJson.devDependencies ?? {}),
45
- ...(pkgJson.peerDependencies ?? {}),
46
- };
47
- return pkg in allDeps;
48
- }
49
-
50
- /**
51
- * Filter out already-installed packages.
52
- */
53
- export function getMissingPackages(packages, cwd = process.cwd()) {
54
- return packages.filter((p) => !isPackageInstalled(p, cwd));
55
- }
1
+ // ============================================================
2
+ // deps.js — detect the user's package manager & install deps
3
+ // ============================================================
4
+ import { execSync, spawnSync } from "child_process";
5
+ import fs from "fs-extra";
6
+ import path from "path";
7
+
8
+ /** Detect which package manager is in use. */
9
+ export function detectPackageManager(cwd = process.cwd()) {
10
+ if (fs.existsSync(path.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
11
+ if (fs.existsSync(path.join(cwd, "yarn.lock"))) return "yarn";
12
+ if (fs.existsSync(path.join(cwd, "bun.lockb"))) return "bun";
13
+ return "npm";
14
+ }
15
+
16
+ /**
17
+ * Install an array of npm packages using the detected package manager.
18
+ * @param {string[]} packages - e.g. ["framer-motion", "clsx"]
19
+ * @param {string} cwd - project root
20
+ */
21
+ export function installDependencies(packages, cwd = process.cwd()) {
22
+ if (!packages.length) return;
23
+ const pm = detectPackageManager(cwd);
24
+
25
+ const installCmd = {
26
+ npm: `npm install ${packages.join(" ")}`,
27
+ pnpm: `pnpm add ${packages.join(" ")}`,
28
+ yarn: `yarn add ${packages.join(" ")}`,
29
+ bun: `bun add ${packages.join(" ")}`,
30
+ }[pm];
31
+
32
+ execSync(installCmd, { cwd, stdio: "inherit" });
33
+ }
34
+
35
+ /**
36
+ * Check whether the user already has a package installed.
37
+ */
38
+ export function isPackageInstalled(pkg, cwd = process.cwd()) {
39
+ const pkgJsonPath = path.join(cwd, "package.json");
40
+ if (!fs.existsSync(pkgJsonPath)) return false;
41
+ const pkgJson = fs.readJsonSync(pkgJsonPath);
42
+ const allDeps = {
43
+ ...(pkgJson.dependencies ?? {}),
44
+ ...(pkgJson.devDependencies ?? {}),
45
+ ...(pkgJson.peerDependencies ?? {}),
46
+ };
47
+ return pkg in allDeps;
48
+ }
49
+
50
+ /**
51
+ * Filter out already-installed packages.
52
+ */
53
+ export function getMissingPackages(packages, cwd = process.cwd()) {
54
+ return packages.filter((p) => !isPackageInstalled(p, cwd));
55
+ }