@olegkuibar/plunk 0.2.0-canary.04ff96f

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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +95 -0
  3. package/dist/add-5ZRFUL6Z.mjs +258 -0
  4. package/dist/chokidar-XGAEDN45.mjs +1746 -0
  5. package/dist/chunk-34UXZ622.mjs +98 -0
  6. package/dist/chunk-4O2QOKVO.mjs +1958 -0
  7. package/dist/chunk-CSMZ6DZA.mjs +367 -0
  8. package/dist/chunk-CZM4TNAI.mjs +292 -0
  9. package/dist/chunk-EDUXIQ5W.mjs +1729 -0
  10. package/dist/chunk-GAAB2TLH.mjs +160 -0
  11. package/dist/chunk-HKNM3UWU.mjs +496 -0
  12. package/dist/chunk-I6SN7BBN.mjs +1131 -0
  13. package/dist/chunk-KYDBD2KQ.mjs +39 -0
  14. package/dist/chunk-LKQINKH4.mjs +130 -0
  15. package/dist/chunk-PUSXMPOF.mjs +82 -0
  16. package/dist/chunk-S4HJSJ32.mjs +69 -0
  17. package/dist/chunk-W3C72UKC.mjs +113 -0
  18. package/dist/chunk-WSECI6M7.mjs +85 -0
  19. package/dist/chunk-XMIZ7OUZ.mjs +26 -0
  20. package/dist/chunk-XZK5T4GK.mjs +23 -0
  21. package/dist/chunk-ZOYNYK5Y.mjs +23 -0
  22. package/dist/chunk-ZQCGJUBJ.mjs +92 -0
  23. package/dist/clean-LTR5MZTY.mjs +84 -0
  24. package/dist/cli.mjs +57 -0
  25. package/dist/dev-LFXQP6SA.mjs +194 -0
  26. package/dist/dist-DUFCZSIL.mjs +813 -0
  27. package/dist/doctor-R7ZVR7PY.mjs +230 -0
  28. package/dist/hash-worker.mjs +65 -0
  29. package/dist/index.d.ts +194 -0
  30. package/dist/index.mjs +9486 -0
  31. package/dist/init-SWCNRISY.mjs +310 -0
  32. package/dist/list-B77L2F34.mjs +119 -0
  33. package/dist/migrate-X5TIC5SS.mjs +124 -0
  34. package/dist/prompt-HTPH6HQ7.mjs +756 -0
  35. package/dist/publish-UXCLPNM6.mjs +63 -0
  36. package/dist/push-JI6HGCFG.mjs +197 -0
  37. package/dist/remove-DCR7KKD5.mjs +149 -0
  38. package/dist/restore-SUN3WGSW.mjs +124 -0
  39. package/dist/status-MESRBH54.mjs +103 -0
  40. package/dist/tailwind-source-JBBEIXIJ.mjs +89 -0
  41. package/dist/update-SKDSA673.mjs +100 -0
  42. package/dist/vite-config-BAK67JHB.mjs +128 -0
  43. package/dist/vite-plugin.d.ts +5 -0
  44. package/dist/vite-plugin.mjs +42 -0
  45. package/dist/workspace-76HJPAK2.mjs +97 -0
  46. package/package.json +96 -0
@@ -0,0 +1,367 @@
1
+ #!/usr/bin/env node
2
+ import{createRequire as __cr}from"node:module";globalThis.require=__cr(import.meta.url);
3
+
4
+ // node_modules/.pnpm/citty@0.2.1/node_modules/citty/dist/_chunks/libs/scule.mjs
5
+ var NUMBER_CHAR_RE = /\d/;
6
+ var STR_SPLITTERS = [
7
+ "-",
8
+ "_",
9
+ "/",
10
+ "."
11
+ ];
12
+ function isUppercase(char = "") {
13
+ if (NUMBER_CHAR_RE.test(char)) return;
14
+ return char !== char.toLowerCase();
15
+ }
16
+ function splitByCase(str, separators) {
17
+ const splitters = separators ?? STR_SPLITTERS;
18
+ const parts = [];
19
+ if (!str || typeof str !== "string") return parts;
20
+ let buff = "";
21
+ let previousUpper;
22
+ let previousSplitter;
23
+ for (const char of str) {
24
+ const isSplitter = splitters.includes(char);
25
+ if (isSplitter === true) {
26
+ parts.push(buff);
27
+ buff = "";
28
+ previousUpper = void 0;
29
+ continue;
30
+ }
31
+ const isUpper = isUppercase(char);
32
+ if (previousSplitter === false) {
33
+ if (previousUpper === false && isUpper === true) {
34
+ parts.push(buff);
35
+ buff = char;
36
+ previousUpper = isUpper;
37
+ continue;
38
+ }
39
+ if (previousUpper === true && isUpper === false && buff.length > 1) {
40
+ const lastChar = buff.at(-1);
41
+ parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
42
+ buff = lastChar + char;
43
+ previousUpper = isUpper;
44
+ continue;
45
+ }
46
+ }
47
+ buff += char;
48
+ previousUpper = isUpper;
49
+ previousSplitter = isSplitter;
50
+ }
51
+ parts.push(buff);
52
+ return parts;
53
+ }
54
+ function upperFirst(str) {
55
+ return str ? str[0].toUpperCase() + str.slice(1) : "";
56
+ }
57
+ function lowerFirst(str) {
58
+ return str ? str[0].toLowerCase() + str.slice(1) : "";
59
+ }
60
+ function pascalCase(str, opts) {
61
+ return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
62
+ }
63
+ function camelCase(str, opts) {
64
+ return lowerFirst(pascalCase(str || "", opts));
65
+ }
66
+ function kebabCase(str, joiner) {
67
+ return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
68
+ }
69
+
70
+ // node_modules/.pnpm/citty@0.2.1/node_modules/citty/dist/index.mjs
71
+ import { parseArgs as parseArgs$1 } from "util";
72
+ function toArray(val) {
73
+ if (Array.isArray(val)) return val;
74
+ return val === void 0 ? [] : [val];
75
+ }
76
+ function formatLineColumns(lines, linePrefix = "") {
77
+ const maxLength = [];
78
+ for (const line of lines) for (const [i, element] of line.entries()) maxLength[i] = Math.max(maxLength[i] || 0, element.length);
79
+ return lines.map((l) => l.map((c, i) => linePrefix + c[i === 0 ? "padStart" : "padEnd"](maxLength[i])).join(" ")).join("\n");
80
+ }
81
+ function resolveValue(input) {
82
+ return typeof input === "function" ? input() : input;
83
+ }
84
+ var CLIError = class extends Error {
85
+ code;
86
+ constructor(message, code) {
87
+ super(message);
88
+ this.name = "CLIError";
89
+ this.code = code;
90
+ }
91
+ };
92
+ function parseRawArgs(args = [], opts = {}) {
93
+ const booleans = new Set(opts.boolean || []);
94
+ const strings = new Set(opts.string || []);
95
+ const aliasMap = opts.alias || {};
96
+ const defaults = opts.default || {};
97
+ const aliasToMain = /* @__PURE__ */ new Map();
98
+ const mainToAliases = /* @__PURE__ */ new Map();
99
+ for (const [key, value] of Object.entries(aliasMap)) {
100
+ const targets = value;
101
+ for (const target of targets) {
102
+ aliasToMain.set(key, target);
103
+ if (!mainToAliases.has(target)) mainToAliases.set(target, []);
104
+ mainToAliases.get(target).push(key);
105
+ aliasToMain.set(target, key);
106
+ if (!mainToAliases.has(key)) mainToAliases.set(key, []);
107
+ mainToAliases.get(key).push(target);
108
+ }
109
+ }
110
+ const options = {};
111
+ function getType(name) {
112
+ if (booleans.has(name)) return "boolean";
113
+ const aliases = mainToAliases.get(name) || [];
114
+ for (const alias of aliases) if (booleans.has(alias)) return "boolean";
115
+ return "string";
116
+ }
117
+ const allOptions = /* @__PURE__ */ new Set([
118
+ ...booleans,
119
+ ...strings,
120
+ ...Object.keys(aliasMap),
121
+ ...Object.values(aliasMap).flat(),
122
+ ...Object.keys(defaults)
123
+ ]);
124
+ for (const name of allOptions) if (!options[name]) options[name] = {
125
+ type: getType(name),
126
+ default: defaults[name]
127
+ };
128
+ for (const [alias, main] of aliasToMain.entries()) if (alias.length === 1 && options[main] && !options[main].short) options[main].short = alias;
129
+ const processedArgs = [];
130
+ const negatedFlags = {};
131
+ for (let i = 0; i < args.length; i++) {
132
+ const arg = args[i];
133
+ if (arg === "--") {
134
+ processedArgs.push(...args.slice(i));
135
+ break;
136
+ }
137
+ if (arg.startsWith("--no-")) {
138
+ const flagName = arg.slice(5);
139
+ negatedFlags[flagName] = true;
140
+ continue;
141
+ }
142
+ processedArgs.push(arg);
143
+ }
144
+ let parsed;
145
+ try {
146
+ parsed = parseArgs$1({
147
+ args: processedArgs,
148
+ options: Object.keys(options).length > 0 ? options : void 0,
149
+ allowPositionals: true,
150
+ strict: false
151
+ });
152
+ } catch {
153
+ parsed = {
154
+ values: {},
155
+ positionals: processedArgs
156
+ };
157
+ }
158
+ const out = { _: [] };
159
+ out._ = parsed.positionals;
160
+ for (const [key, value] of Object.entries(parsed.values)) out[key] = value;
161
+ for (const [name] of Object.entries(negatedFlags)) {
162
+ out[name] = false;
163
+ const mainName = aliasToMain.get(name);
164
+ if (mainName) out[mainName] = false;
165
+ const aliases = mainToAliases.get(name);
166
+ if (aliases) for (const alias of aliases) out[alias] = false;
167
+ }
168
+ for (const [alias, main] of aliasToMain.entries()) {
169
+ if (out[alias] !== void 0 && out[main] === void 0) out[main] = out[alias];
170
+ if (out[main] !== void 0 && out[alias] === void 0) out[alias] = out[main];
171
+ }
172
+ return out;
173
+ }
174
+ var noColor = /* @__PURE__ */ (() => {
175
+ const env = globalThis.process?.env ?? {};
176
+ return env.NO_COLOR === "1" || env.TERM === "dumb" || env.TEST || env.CI;
177
+ })();
178
+ var _c = (c, r = 39) => (t) => noColor ? t : `\x1B[${c}m${t}\x1B[${r}m`;
179
+ var bold = /* @__PURE__ */ _c(1, 22);
180
+ var cyan = /* @__PURE__ */ _c(36);
181
+ var gray = /* @__PURE__ */ _c(90);
182
+ var underline = /* @__PURE__ */ _c(4, 24);
183
+ function parseArgs(rawArgs, argsDef) {
184
+ const parseOptions = {
185
+ boolean: [],
186
+ string: [],
187
+ alias: {},
188
+ default: {}
189
+ };
190
+ const args = resolveArgs(argsDef);
191
+ for (const arg of args) {
192
+ if (arg.type === "positional") continue;
193
+ if (arg.type === "string" || arg.type === "enum") parseOptions.string.push(arg.name);
194
+ else if (arg.type === "boolean") parseOptions.boolean.push(arg.name);
195
+ if (arg.default !== void 0) parseOptions.default[arg.name] = arg.default;
196
+ if (arg.alias) parseOptions.alias[arg.name] = arg.alias;
197
+ const camelName = camelCase(arg.name);
198
+ const kebabName = kebabCase(arg.name);
199
+ if (camelName !== arg.name || kebabName !== arg.name) {
200
+ const existingAliases = toArray(parseOptions.alias[arg.name] || []);
201
+ if (camelName !== arg.name && !existingAliases.includes(camelName)) existingAliases.push(camelName);
202
+ if (kebabName !== arg.name && !existingAliases.includes(kebabName)) existingAliases.push(kebabName);
203
+ if (existingAliases.length > 0) parseOptions.alias[arg.name] = existingAliases;
204
+ }
205
+ }
206
+ const parsed = parseRawArgs(rawArgs, parseOptions);
207
+ const [...positionalArguments] = parsed._;
208
+ const parsedArgsProxy = new Proxy(parsed, { get(target, prop) {
209
+ return target[prop] ?? target[camelCase(prop)] ?? target[kebabCase(prop)];
210
+ } });
211
+ for (const [, arg] of args.entries()) if (arg.type === "positional") {
212
+ const nextPositionalArgument = positionalArguments.shift();
213
+ if (nextPositionalArgument !== void 0) parsedArgsProxy[arg.name] = nextPositionalArgument;
214
+ else if (arg.default === void 0 && arg.required !== false) throw new CLIError(`Missing required positional argument: ${arg.name.toUpperCase()}`, "EARG");
215
+ else parsedArgsProxy[arg.name] = arg.default;
216
+ } else if (arg.type === "enum") {
217
+ const argument = parsedArgsProxy[arg.name];
218
+ const options = arg.options || [];
219
+ if (argument !== void 0 && options.length > 0 && !options.includes(argument)) throw new CLIError(`Invalid value for argument: ${cyan(`--${arg.name}`)} (${cyan(argument)}). Expected one of: ${options.map((o) => cyan(o)).join(", ")}.`, "EARG");
220
+ } else if (arg.required && parsedArgsProxy[arg.name] === void 0) throw new CLIError(`Missing required argument: --${arg.name}`, "EARG");
221
+ return parsedArgsProxy;
222
+ }
223
+ function resolveArgs(argsDef) {
224
+ const args = [];
225
+ for (const [name, argDef] of Object.entries(argsDef || {})) args.push({
226
+ ...argDef,
227
+ name,
228
+ alias: toArray(argDef.alias)
229
+ });
230
+ return args;
231
+ }
232
+ function defineCommand(def) {
233
+ return def;
234
+ }
235
+ async function runCommand(cmd, opts) {
236
+ const cmdArgs = await resolveValue(cmd.args || {});
237
+ const parsedArgs = parseArgs(opts.rawArgs, cmdArgs);
238
+ const context = {
239
+ rawArgs: opts.rawArgs,
240
+ args: parsedArgs,
241
+ data: opts.data,
242
+ cmd
243
+ };
244
+ if (typeof cmd.setup === "function") await cmd.setup(context);
245
+ let result;
246
+ try {
247
+ const subCommands = await resolveValue(cmd.subCommands);
248
+ if (subCommands && Object.keys(subCommands).length > 0) {
249
+ const subCommandArgIndex = opts.rawArgs.findIndex((arg) => !arg.startsWith("-"));
250
+ const subCommandName = opts.rawArgs[subCommandArgIndex];
251
+ if (subCommandName) {
252
+ if (!subCommands[subCommandName]) throw new CLIError(`Unknown command ${cyan(subCommandName)}`, "E_UNKNOWN_COMMAND");
253
+ const subCommand = await resolveValue(subCommands[subCommandName]);
254
+ if (subCommand) await runCommand(subCommand, { rawArgs: opts.rawArgs.slice(subCommandArgIndex + 1) });
255
+ } else if (!cmd.run) throw new CLIError(`No command specified.`, "E_NO_COMMAND");
256
+ }
257
+ if (typeof cmd.run === "function") result = await cmd.run(context);
258
+ } finally {
259
+ if (typeof cmd.cleanup === "function") await cmd.cleanup(context);
260
+ }
261
+ return { result };
262
+ }
263
+ async function resolveSubCommand(cmd, rawArgs, parent) {
264
+ const subCommands = await resolveValue(cmd.subCommands);
265
+ if (subCommands && Object.keys(subCommands).length > 0) {
266
+ const subCommandArgIndex = rawArgs.findIndex((arg) => !arg.startsWith("-"));
267
+ const subCommandName = rawArgs[subCommandArgIndex];
268
+ const subCommand = await resolveValue(subCommands[subCommandName]);
269
+ if (subCommand) return resolveSubCommand(subCommand, rawArgs.slice(subCommandArgIndex + 1), cmd);
270
+ }
271
+ return [cmd, parent];
272
+ }
273
+ async function showUsage(cmd, parent) {
274
+ try {
275
+ console.log(await renderUsage(cmd, parent) + "\n");
276
+ } catch (error) {
277
+ console.error(error);
278
+ }
279
+ }
280
+ var negativePrefixRe = /^no[-A-Z]/;
281
+ async function renderUsage(cmd, parent) {
282
+ const cmdMeta = await resolveValue(cmd.meta || {});
283
+ const cmdArgs = resolveArgs(await resolveValue(cmd.args || {}));
284
+ const parentMeta = await resolveValue(parent?.meta || {});
285
+ const commandName = `${parentMeta.name ? `${parentMeta.name} ` : ""}` + (cmdMeta.name || process.argv[1]);
286
+ const argLines = [];
287
+ const posLines = [];
288
+ const commandsLines = [];
289
+ const usageLine = [];
290
+ for (const arg of cmdArgs) if (arg.type === "positional") {
291
+ const name = arg.name.toUpperCase();
292
+ const isRequired = arg.required !== false && arg.default === void 0;
293
+ const defaultHint = arg.default ? `="${arg.default}"` : "";
294
+ posLines.push([
295
+ cyan(name + defaultHint),
296
+ arg.description || "",
297
+ arg.valueHint ? `<${arg.valueHint}>` : ""
298
+ ]);
299
+ usageLine.push(isRequired ? `<${name}>` : `[${name}]`);
300
+ } else {
301
+ const isRequired = arg.required === true && arg.default === void 0;
302
+ const argStr = [...(arg.alias || []).map((a) => `-${a}`), `--${arg.name}`].join(", ") + (arg.type === "string" && (arg.valueHint || arg.default) ? `=${arg.valueHint ? `<${arg.valueHint}>` : `"${arg.default || ""}"`}` : "") + (arg.type === "enum" && arg.options ? `=<${arg.options.join("|")}>` : "");
303
+ argLines.push([cyan(argStr + (isRequired ? " (required)" : "")), arg.description || ""]);
304
+ if (arg.type === "boolean" && (arg.default === true || arg.negativeDescription) && !negativePrefixRe.test(arg.name)) {
305
+ const negativeArgStr = [...(arg.alias || []).map((a) => `--no-${a}`), `--no-${arg.name}`].join(", ");
306
+ argLines.push([cyan(negativeArgStr + (isRequired ? " (required)" : "")), arg.negativeDescription || ""]);
307
+ }
308
+ if (isRequired) usageLine.push(argStr);
309
+ }
310
+ if (cmd.subCommands) {
311
+ const commandNames = [];
312
+ const subCommands = await resolveValue(cmd.subCommands);
313
+ for (const [name, sub] of Object.entries(subCommands)) {
314
+ const meta = await resolveValue((await resolveValue(sub))?.meta);
315
+ if (meta?.hidden) continue;
316
+ commandsLines.push([cyan(name), meta?.description || ""]);
317
+ commandNames.push(name);
318
+ }
319
+ usageLine.push(commandNames.join("|"));
320
+ }
321
+ const usageLines = [];
322
+ const version = cmdMeta.version || parentMeta.version;
323
+ usageLines.push(gray(`${cmdMeta.description} (${commandName + (version ? ` v${version}` : "")})`), "");
324
+ const hasOptions = argLines.length > 0 || posLines.length > 0;
325
+ usageLines.push(`${underline(bold("USAGE"))} ${cyan(`${commandName}${hasOptions ? " [OPTIONS]" : ""} ${usageLine.join(" ")}`)}`, "");
326
+ if (posLines.length > 0) {
327
+ usageLines.push(underline(bold("ARGUMENTS")), "");
328
+ usageLines.push(formatLineColumns(posLines, " "));
329
+ usageLines.push("");
330
+ }
331
+ if (argLines.length > 0) {
332
+ usageLines.push(underline(bold("OPTIONS")), "");
333
+ usageLines.push(formatLineColumns(argLines, " "));
334
+ usageLines.push("");
335
+ }
336
+ if (commandsLines.length > 0) {
337
+ usageLines.push(underline(bold("COMMANDS")), "");
338
+ usageLines.push(formatLineColumns(commandsLines, " "));
339
+ usageLines.push("", `Use ${cyan(`${commandName} <command> --help`)} for more information about a command.`);
340
+ }
341
+ return usageLines.filter((l) => typeof l === "string").join("\n");
342
+ }
343
+ async function runMain(cmd, opts = {}) {
344
+ const rawArgs = opts.rawArgs || process.argv.slice(2);
345
+ const showUsage$1 = opts.showUsage || showUsage;
346
+ try {
347
+ if (rawArgs.includes("--help") || rawArgs.includes("-h")) {
348
+ await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
349
+ process.exit(0);
350
+ } else if (rawArgs.length === 1 && rawArgs[0] === "--version") {
351
+ const meta = typeof cmd.meta === "function" ? await cmd.meta() : await cmd.meta;
352
+ if (!meta?.version) throw new CLIError("No version specified", "E_NO_VERSION");
353
+ console.log(meta.version);
354
+ } else await runCommand(cmd, { rawArgs });
355
+ } catch (error) {
356
+ if (error instanceof CLIError) {
357
+ await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
358
+ console.error(error.message);
359
+ } else console.error(error, "\n");
360
+ process.exit(1);
361
+ }
362
+ }
363
+
364
+ export {
365
+ defineCommand,
366
+ runMain
367
+ };
@@ -0,0 +1,292 @@
1
+ #!/usr/bin/env node
2
+ import{createRequire as __cr}from"node:module";globalThis.require=__cr(import.meta.url);
3
+ import {
4
+ detectAllBundlers,
5
+ detectYarnNodeLinker
6
+ } from "./chunk-34UXZ622.mjs";
7
+ import {
8
+ getConsumerBackupPath,
9
+ getNodeModulesPackagePath
10
+ } from "./chunk-EDUXIQ5W.mjs";
11
+ import {
12
+ copyDir,
13
+ ensureDir,
14
+ exists,
15
+ incrementalCopy,
16
+ isNodeError,
17
+ removeDir
18
+ } from "./chunk-HKNM3UWU.mjs";
19
+ import {
20
+ consola,
21
+ verbose
22
+ } from "./chunk-I6SN7BBN.mjs";
23
+
24
+ // src/core/injector.ts
25
+ import { readFile, readdir, realpath, stat } from "fs/promises";
26
+ import { join as join3, resolve as resolve2 } from "path";
27
+
28
+ // src/utils/bin-linker.ts
29
+ import { mkdir, symlink, writeFile, chmod, rm } from "fs/promises";
30
+ import { join, relative, resolve, sep } from "path";
31
+ import { platform } from "os";
32
+ function resolveBinEntries(pkg) {
33
+ if (!pkg.bin) return {};
34
+ if (typeof pkg.bin === "string") {
35
+ const binName = pkg.name.startsWith("@") ? pkg.name.split("/")[1] : pkg.name;
36
+ return { [binName]: pkg.bin };
37
+ }
38
+ return pkg.bin;
39
+ }
40
+ async function createBinLinks(consumerPath, packageName, pkg) {
41
+ const entries = resolveBinEntries(pkg);
42
+ if (Object.keys(entries).length === 0) return 0;
43
+ const binDir = join(consumerPath, "node_modules", ".bin");
44
+ await mkdir(binDir, { recursive: true });
45
+ const isWindows = platform() === "win32";
46
+ let count = 0;
47
+ for (const [binName, binPath] of Object.entries(entries)) {
48
+ const packageRoot = join(consumerPath, "node_modules", packageName);
49
+ const targetAbsolute = join(packageRoot, binPath);
50
+ const resolvedTarget = resolve(targetAbsolute);
51
+ if (!resolvedTarget.startsWith(resolve(packageRoot) + sep) && resolvedTarget !== resolve(packageRoot)) {
52
+ consola.warn(`bin "${binName}" points outside package directory, skipping`);
53
+ continue;
54
+ }
55
+ const targetRelative = relative(binDir, targetAbsolute).replace(
56
+ /\\/g,
57
+ "/"
58
+ );
59
+ if (isWindows) {
60
+ const cmdPath = join(binDir, `${binName}.cmd`);
61
+ const cmdContent = `@ECHO off\r
62
+ GOTO start\r
63
+ :find_dp0\r
64
+ SET dp0=%~dp0\r
65
+ EXIT /b\r
66
+ :start\r
67
+ CALL :find_dp0\r
68
+ "%dp0%\\${targetRelative}" %*\r
69
+ `;
70
+ await writeFile(cmdPath, cmdContent);
71
+ const shPath = join(binDir, binName);
72
+ const shContent = `#!/bin/sh
73
+ exec node "${targetRelative}" "$@"
74
+ `;
75
+ await writeFile(shPath, shContent);
76
+ } else {
77
+ const linkPath = join(binDir, binName);
78
+ try {
79
+ await rm(linkPath, { force: true });
80
+ } catch {
81
+ }
82
+ try {
83
+ await symlink(targetRelative, linkPath);
84
+ await chmod(targetAbsolute, 493);
85
+ } catch (err) {
86
+ if (isNodeError(err) && (err.code === "EPERM" || err.code === "EACCES")) {
87
+ verbose(`[bin-linker] Symlink failed (${err.code}), using shell wrapper for ${binName}`);
88
+ const shContent = `#!/bin/sh
89
+ exec node "${targetRelative}" "$@"
90
+ `;
91
+ await writeFile(linkPath, shContent);
92
+ await chmod(linkPath, 493);
93
+ } else {
94
+ throw err;
95
+ }
96
+ }
97
+ }
98
+ count++;
99
+ }
100
+ return count;
101
+ }
102
+ async function removeBinLinks(consumerPath, pkg) {
103
+ const entries = resolveBinEntries(pkg);
104
+ const binDir = join(consumerPath, "node_modules", ".bin");
105
+ const isWindows = platform() === "win32";
106
+ for (const binName of Object.keys(entries)) {
107
+ try {
108
+ await rm(join(binDir, binName), { force: true });
109
+ if (isWindows) {
110
+ await rm(join(binDir, `${binName}.cmd`), { force: true });
111
+ }
112
+ } catch {
113
+ }
114
+ }
115
+ }
116
+
117
+ // src/utils/bundler-cache.ts
118
+ import { join as join2 } from "path";
119
+ var CACHE_DIRS = {
120
+ vite: ["node_modules/.vite"],
121
+ next: [".next/cache"],
122
+ webpack: ["node_modules/.cache"]
123
+ };
124
+ async function invalidateBundlerCache(consumerPath) {
125
+ const bundlers = await detectAllBundlers(consumerPath);
126
+ for (const bundler of bundlers) {
127
+ if (!bundler.type) continue;
128
+ const dirs = CACHE_DIRS[bundler.type];
129
+ if (!dirs) continue;
130
+ for (const dir of dirs) {
131
+ const cacheDir = join2(consumerPath, dir);
132
+ if (await exists(cacheDir)) {
133
+ try {
134
+ await removeDir(cacheDir);
135
+ verbose(`[inject] Invalidated ${bundler.type} cache: ${dir}`);
136
+ } catch {
137
+ verbose(`[inject] Could not clear ${bundler.type} cache: ${dir} (locked?)`);
138
+ }
139
+ }
140
+ }
141
+ }
142
+ }
143
+
144
+ // src/core/injector.ts
145
+ async function inject(storeEntry, consumerPath, pm) {
146
+ const targetDir = await resolveTargetDir(
147
+ consumerPath,
148
+ storeEntry.name,
149
+ pm,
150
+ storeEntry.version
151
+ );
152
+ verbose(`[inject] ${storeEntry.name}@${storeEntry.version} \u2192 ${targetDir}`);
153
+ await ensureDir(targetDir);
154
+ const { copied, removed, skipped } = await incrementalCopy(
155
+ storeEntry.packageDir,
156
+ targetDir
157
+ );
158
+ verbose(`[inject] ${copied} copied, ${removed} removed, ${skipped} skipped`);
159
+ if (copied > 0 || removed > 0) {
160
+ await invalidateBundlerCache(consumerPath);
161
+ }
162
+ const pkg = await readPackageJson(storeEntry.packageDir);
163
+ const binLinks = pkg ? await createBinLinks(consumerPath, storeEntry.name, pkg) : 0;
164
+ if (binLinks > 0) {
165
+ verbose(`[inject] Created ${binLinks} bin link(s)`);
166
+ }
167
+ return { copied, removed, skipped, binLinks };
168
+ }
169
+ async function backupExisting(consumerPath, packageName, pm) {
170
+ const installedDir = await resolveTargetDir(consumerPath, packageName, pm);
171
+ if (!await exists(installedDir)) return false;
172
+ const backupDir = getConsumerBackupPath(consumerPath, packageName);
173
+ await removeDir(backupDir);
174
+ await copyDir(installedDir, backupDir);
175
+ return true;
176
+ }
177
+ async function restoreBackup(consumerPath, packageName, pm) {
178
+ const backupDir = getConsumerBackupPath(consumerPath, packageName);
179
+ if (!await exists(backupDir)) return false;
180
+ const targetDir = await resolveTargetDir(consumerPath, packageName, pm);
181
+ await removeDir(targetDir);
182
+ await copyDir(backupDir, targetDir);
183
+ await removeDir(backupDir);
184
+ return true;
185
+ }
186
+ async function removeInjected(consumerPath, packageName, pm) {
187
+ const targetDir = await resolveTargetDir(consumerPath, packageName, pm);
188
+ const pkg = await readPackageJson(targetDir);
189
+ if (pkg) {
190
+ await removeBinLinks(consumerPath, pkg);
191
+ }
192
+ await removeDir(targetDir);
193
+ }
194
+ async function checkMissingDeps(storeEntry, consumerPath) {
195
+ const pkg = await readPackageJson(storeEntry.packageDir);
196
+ if (!pkg) return [];
197
+ const allDeps = {
198
+ ...pkg.dependencies,
199
+ ...Object.fromEntries(
200
+ Object.entries(pkg.peerDependencies ?? {}).filter(
201
+ ([name]) => !pkg.peerDependenciesMeta?.[name]?.optional
202
+ )
203
+ )
204
+ };
205
+ if (Object.keys(allDeps).length === 0) return [];
206
+ const missing = [];
207
+ for (const dep of Object.keys(allDeps)) {
208
+ const depPath = join3(consumerPath, "node_modules", dep);
209
+ if (!await exists(depPath)) {
210
+ missing.push(dep);
211
+ }
212
+ }
213
+ return missing;
214
+ }
215
+ async function resolveTargetDir(consumerPath, packageName, pm, version) {
216
+ const directPath = getNodeModulesPackagePath(consumerPath, packageName);
217
+ const needsSymlinkResolution = pm === "pnpm" || pm === "yarn" && await detectYarnNodeLinker(consumerPath) === "pnpm";
218
+ if (!needsSymlinkResolution) {
219
+ return directPath;
220
+ }
221
+ try {
222
+ const realPath = await resolveRealPath(directPath);
223
+ if (realPath !== resolve2(directPath)) {
224
+ verbose(`[inject] pnpm: resolved symlink \u2192 ${realPath}`);
225
+ return realPath;
226
+ }
227
+ } catch (err) {
228
+ if (isNodeError(err) && err.code !== "ENOENT") {
229
+ consola.debug(`pnpm symlink resolution error: ${err}`);
230
+ }
231
+ }
232
+ const pnpmDir = join3(consumerPath, "node_modules", ".pnpm");
233
+ if (await exists(pnpmDir)) {
234
+ verbose(`[inject] pnpm: scanning .pnpm/ for ${packageName}`);
235
+ const encodedName = packageName.replace("/", "+");
236
+ if (version) {
237
+ const exactEntry = `${encodedName}@${version}`;
238
+ const candidate = join3(pnpmDir, exactEntry, "node_modules", packageName);
239
+ if (await exists(candidate)) {
240
+ verbose(`[inject] pnpm: exact version match in .pnpm/ \u2192 ${candidate}`);
241
+ return candidate;
242
+ }
243
+ }
244
+ const entries = await readdir(pnpmDir);
245
+ for (const entry of entries) {
246
+ if (entry.startsWith(encodedName + "@")) {
247
+ const candidate = join3(
248
+ pnpmDir,
249
+ entry,
250
+ "node_modules",
251
+ packageName
252
+ );
253
+ if (await exists(candidate)) {
254
+ verbose(`[inject] pnpm: found in .pnpm/ \u2192 ${candidate}`);
255
+ return candidate;
256
+ }
257
+ }
258
+ }
259
+ }
260
+ consola.warn(`pnpm: falling back to direct node_modules path for ${packageName}`);
261
+ return directPath;
262
+ }
263
+ async function resolveRealPath(linkPath) {
264
+ try {
265
+ await stat(linkPath);
266
+ return await realpath(linkPath);
267
+ } catch (err) {
268
+ if (isNodeError(err) && err.code === "ENOENT") {
269
+ return resolve2(linkPath);
270
+ }
271
+ throw err;
272
+ }
273
+ }
274
+ async function readPackageJson(dir) {
275
+ try {
276
+ const content = await readFile(join3(dir, "package.json"), "utf-8");
277
+ return JSON.parse(content);
278
+ } catch (err) {
279
+ if (isNodeError(err) && err.code !== "ENOENT") {
280
+ consola.warn(`Failed to read package.json in ${dir}: ${err}`);
281
+ }
282
+ return null;
283
+ }
284
+ }
285
+
286
+ export {
287
+ inject,
288
+ backupExisting,
289
+ restoreBackup,
290
+ removeInjected,
291
+ checkMissingDeps
292
+ };