opkg 0.9.2 → 0.9.3

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 (140) hide show
  1. package/package.json +3 -1
  2. package/packages/cli/dist/add-U44SL3OR.js +624 -0
  3. package/packages/cli/dist/add-U44SL3OR.js.map +7 -0
  4. package/packages/cli/dist/chunk-4B5HJLP2.js +48 -0
  5. package/packages/cli/dist/chunk-4B5HJLP2.js.map +7 -0
  6. package/packages/cli/dist/chunk-BROJ6OUT.js +631 -0
  7. package/packages/cli/dist/chunk-BROJ6OUT.js.map +7 -0
  8. package/packages/cli/dist/chunk-CVA64SXK.js +1136 -0
  9. package/packages/cli/dist/chunk-CVA64SXK.js.map +7 -0
  10. package/packages/cli/dist/chunk-D6LEPODL.js +413 -0
  11. package/packages/cli/dist/chunk-D6LEPODL.js.map +7 -0
  12. package/packages/cli/dist/chunk-HTYHJA3B.js +61 -0
  13. package/packages/cli/dist/chunk-HTYHJA3B.js.map +7 -0
  14. package/packages/cli/dist/chunk-KI7FDU3H.js +99 -0
  15. package/packages/cli/dist/chunk-KI7FDU3H.js.map +7 -0
  16. package/packages/cli/dist/chunk-PSQXKAL4.js +371 -0
  17. package/packages/cli/dist/chunk-PSQXKAL4.js.map +7 -0
  18. package/packages/cli/dist/chunk-PUDRKDVZ.js +1419 -0
  19. package/packages/cli/dist/chunk-PUDRKDVZ.js.map +7 -0
  20. package/packages/cli/dist/chunk-U7FW7SXX.js +568 -0
  21. package/packages/cli/dist/chunk-U7FW7SXX.js.map +7 -0
  22. package/packages/cli/dist/configure-3AZUMDJZ.js +107 -0
  23. package/packages/cli/dist/configure-3AZUMDJZ.js.map +7 -0
  24. package/packages/cli/dist/index.js +15 -15
  25. package/packages/cli/dist/install-EZNWMLJR.js +7581 -0
  26. package/packages/cli/dist/install-EZNWMLJR.js.map +7 -0
  27. package/packages/cli/dist/list-XR7RSJFS.js +327 -0
  28. package/packages/cli/dist/list-XR7RSJFS.js.map +7 -0
  29. package/packages/cli/dist/login-NRKHXZKM.js +150 -0
  30. package/packages/cli/dist/login-NRKHXZKM.js.map +7 -0
  31. package/packages/cli/dist/logout-SYHXCVCQ.js +40 -0
  32. package/packages/cli/dist/logout-SYHXCVCQ.js.map +7 -0
  33. package/packages/cli/dist/new-F46OSD72.js +277 -0
  34. package/packages/cli/dist/new-F46OSD72.js.map +7 -0
  35. package/packages/cli/dist/publish-4H43PCSG.js +619 -0
  36. package/packages/cli/dist/publish-4H43PCSG.js.map +7 -0
  37. package/packages/cli/dist/remove-BD52BHR2.js +542 -0
  38. package/packages/cli/dist/remove-BD52BHR2.js.map +7 -0
  39. package/packages/cli/dist/save-N3QWF2WN.js +1728 -0
  40. package/packages/cli/dist/save-N3QWF2WN.js.map +7 -0
  41. package/packages/cli/dist/search-ABROK3UO.js +157 -0
  42. package/packages/cli/dist/search-ABROK3UO.js.map +7 -0
  43. package/packages/cli/dist/set-NGM2FIKF.js +251 -0
  44. package/packages/cli/dist/set-NGM2FIKF.js.map +7 -0
  45. package/packages/cli/dist/uninstall-Q3CP4UN5.js +539 -0
  46. package/packages/cli/dist/uninstall-Q3CP4UN5.js.map +7 -0
  47. package/packages/cli/dist/unpublish-VBTNTMS5.js +245 -0
  48. package/packages/cli/dist/unpublish-VBTNTMS5.js.map +7 -0
  49. package/packages/cli/dist/view-MXRBMXOG.js +488 -0
  50. package/packages/cli/dist/view-MXRBMXOG.js.map +7 -0
  51. package/packages/cli/package.json +2 -0
  52. package/packages/core/dist/core/install/conflicts/file-conflict-resolver.d.ts +5 -4
  53. package/packages/core/dist/core/install/conflicts/file-conflict-resolver.d.ts.map +1 -1
  54. package/packages/core/dist/core/install/conflicts/file-conflict-resolver.js +6 -5
  55. package/packages/core/dist/core/install/conflicts/file-conflict-resolver.js.map +1 -1
  56. package/packages/core/dist/core/install/install-reporting.js +1 -1
  57. package/packages/core/dist/core/install/install-reporting.js.map +1 -1
  58. package/packages/core/dist/core/install/list-handler.d.ts.map +1 -1
  59. package/packages/core/dist/core/install/list-handler.js +7 -0
  60. package/packages/core/dist/core/install/list-handler.js.map +1 -1
  61. package/packages/core/dist/core/install/marketplace-handler.d.ts.map +1 -1
  62. package/packages/core/dist/core/install/marketplace-handler.js.map +1 -1
  63. package/packages/core/dist/core/install/operations/conflict-handler.d.ts +2 -1
  64. package/packages/core/dist/core/install/operations/conflict-handler.d.ts.map +1 -1
  65. package/packages/core/dist/core/install/operations/conflict-handler.js +2 -2
  66. package/packages/core/dist/core/install/operations/conflict-handler.js.map +1 -1
  67. package/packages/core/dist/core/install/orchestrator/orchestrator.d.ts.map +1 -1
  68. package/packages/core/dist/core/install/orchestrator/orchestrator.js +22 -14
  69. package/packages/core/dist/core/install/orchestrator/orchestrator.js.map +1 -1
  70. package/packages/core/dist/core/install/orchestrator/strategies/git-strategy.d.ts +1 -0
  71. package/packages/core/dist/core/install/orchestrator/strategies/git-strategy.d.ts.map +1 -1
  72. package/packages/core/dist/core/install/orchestrator/strategies/git-strategy.js +11 -24
  73. package/packages/core/dist/core/install/orchestrator/strategies/git-strategy.js.map +1 -1
  74. package/packages/core/dist/core/install/orchestrator/strategies/path-strategy.d.ts +2 -0
  75. package/packages/core/dist/core/install/orchestrator/strategies/path-strategy.d.ts.map +1 -1
  76. package/packages/core/dist/core/install/orchestrator/strategies/path-strategy.js +14 -14
  77. package/packages/core/dist/core/install/orchestrator/strategies/path-strategy.js.map +1 -1
  78. package/packages/core/dist/core/install/orchestrator/strategies/registry-strategy.d.ts +7 -0
  79. package/packages/core/dist/core/install/orchestrator/strategies/registry-strategy.d.ts.map +1 -1
  80. package/packages/core/dist/core/install/orchestrator/strategies/registry-strategy.js +28 -0
  81. package/packages/core/dist/core/install/orchestrator/strategies/registry-strategy.js.map +1 -1
  82. package/packages/core/dist/core/install/platform-resolution.d.ts +3 -0
  83. package/packages/core/dist/core/install/platform-resolution.d.ts.map +1 -1
  84. package/packages/core/dist/core/install/platform-resolution.js +5 -2
  85. package/packages/core/dist/core/install/platform-resolution.js.map +1 -1
  86. package/packages/core/dist/core/install/preprocessing/context-population.d.ts +18 -0
  87. package/packages/core/dist/core/install/preprocessing/context-population.d.ts.map +1 -0
  88. package/packages/core/dist/core/install/preprocessing/context-population.js +36 -0
  89. package/packages/core/dist/core/install/preprocessing/context-population.js.map +1 -0
  90. package/packages/core/dist/core/install/preprocessing/convenience-preprocessor.d.ts +23 -0
  91. package/packages/core/dist/core/install/preprocessing/convenience-preprocessor.d.ts.map +1 -1
  92. package/packages/core/dist/core/install/preprocessing/convenience-preprocessor.js +44 -0
  93. package/packages/core/dist/core/install/preprocessing/convenience-preprocessor.js.map +1 -1
  94. package/packages/core/dist/core/install/sources/path-source.d.ts.map +1 -1
  95. package/packages/core/dist/core/install/sources/path-source.js +8 -0
  96. package/packages/core/dist/core/install/sources/path-source.js.map +1 -1
  97. package/packages/core/dist/core/install/unified/context-builders.d.ts +5 -0
  98. package/packages/core/dist/core/install/unified/context-builders.d.ts.map +1 -1
  99. package/packages/core/dist/core/install/unified/context-builders.js +13 -0
  100. package/packages/core/dist/core/install/unified/context-builders.js.map +1 -1
  101. package/packages/core/dist/core/install/unified/context-helpers.d.ts.map +1 -1
  102. package/packages/core/dist/core/install/unified/context-helpers.js +5 -0
  103. package/packages/core/dist/core/install/unified/context-helpers.js.map +1 -1
  104. package/packages/core/dist/core/install/unified/context.d.ts +6 -0
  105. package/packages/core/dist/core/install/unified/context.d.ts.map +1 -1
  106. package/packages/core/dist/core/install/unified/multi-context-pipeline.d.ts.map +1 -1
  107. package/packages/core/dist/core/install/unified/multi-context-pipeline.js +0 -2
  108. package/packages/core/dist/core/install/unified/multi-context-pipeline.js.map +1 -1
  109. package/packages/core/dist/core/install/unified/phases/conflicts.d.ts.map +1 -1
  110. package/packages/core/dist/core/install/unified/phases/conflicts.js +1 -1
  111. package/packages/core/dist/core/install/unified/phases/conflicts.js.map +1 -1
  112. package/packages/core/dist/core/install/unified/phases/execute.d.ts.map +1 -1
  113. package/packages/core/dist/core/install/unified/phases/execute.js +2 -1
  114. package/packages/core/dist/core/install/unified/phases/execute.js.map +1 -1
  115. package/packages/core/dist/core/install/unified/phases/report.js +1 -1
  116. package/packages/core/dist/core/install/unified/phases/report.js.map +1 -1
  117. package/packages/core/dist/core/install/unified/pipeline.d.ts.map +1 -1
  118. package/packages/core/dist/core/install/unified/pipeline.js +5 -2
  119. package/packages/core/dist/core/install/unified/pipeline.js.map +1 -1
  120. package/packages/core/dist/core/ports/resolve.d.ts +0 -13
  121. package/packages/core/dist/core/ports/resolve.d.ts.map +1 -1
  122. package/packages/core/dist/core/ports/resolve.js +0 -28
  123. package/packages/core/dist/core/ports/resolve.js.map +1 -1
  124. package/packages/core/dist/core/remove/removal-confirmation.d.ts +4 -1
  125. package/packages/core/dist/core/remove/removal-confirmation.d.ts.map +1 -1
  126. package/packages/core/dist/core/remove/removal-confirmation.js +5 -4
  127. package/packages/core/dist/core/remove/removal-confirmation.js.map +1 -1
  128. package/packages/core/dist/core/remove/remove-from-source-pipeline.d.ts.map +1 -1
  129. package/packages/core/dist/core/remove/remove-from-source-pipeline.js +1 -10
  130. package/packages/core/dist/core/remove/remove-from-source-pipeline.js.map +1 -1
  131. package/packages/core/dist/core/uninstall/uninstall-executor.js +1 -1
  132. package/packages/core/dist/core/uninstall/uninstall-executor.js.map +1 -1
  133. package/packages/core/dist/core/uninstall/uninstall-reporter.d.ts +2 -2
  134. package/packages/core/dist/core/uninstall/uninstall-reporter.d.ts.map +1 -1
  135. package/packages/core/dist/core/uninstall/uninstall-reporter.js +4 -4
  136. package/packages/core/dist/core/uninstall/uninstall-reporter.js.map +1 -1
  137. package/packages/core/dist/index.d.ts +1 -1
  138. package/packages/core/dist/index.d.ts.map +1 -1
  139. package/packages/core/dist/types/execution-context.d.ts +24 -10
  140. package/packages/core/dist/types/execution-context.d.ts.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opkg",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -56,6 +56,7 @@
56
56
  "junk": "^4.0.1",
57
57
  "minimatch": "^10.1.1",
58
58
  "nanoid": "^5.0.7",
59
+ "prompts": "^2.4.2",
59
60
  "semver": "^7.7.2",
60
61
  "smol-toml": "^1.6.0",
61
62
  "tar": "^7.5.9"
@@ -66,6 +67,7 @@
66
67
  "@types/jsonpath-plus": "^5.0.5",
67
68
  "@types/minimatch": "^5.1.2",
68
69
  "@types/node": "^24.3.1",
70
+ "@types/prompts": "^2.4.9",
69
71
  "@types/semver": "^7.7.1",
70
72
  "@types/tar": "^6.1.0",
71
73
  "esbuild": "^0.25.0",
@@ -0,0 +1,624 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ buildWorkspacePackageContext,
4
+ expandDirectorySelections,
5
+ hasDirectorySelections,
6
+ interactiveFileSelect,
7
+ resolveSourceOperationArguments
8
+ } from "./chunk-PSQXKAL4.js";
9
+ import {
10
+ resolveMutableSource
11
+ } from "./chunk-QQFDQPT3.js";
12
+ import {
13
+ assertMutableSourceOrThrow
14
+ } from "./chunk-IBIYIU3K.js";
15
+ import {
16
+ classifyInputBase,
17
+ isPlatformRootFile
18
+ } from "./chunk-GJWX5XPU.js";
19
+ import "./chunk-4TCVCEPB.js";
20
+ import {
21
+ createInteractionPolicy
22
+ } from "./chunk-SVEFLCC2.js";
23
+ import {
24
+ applyMapPipeline,
25
+ createMapContext,
26
+ defaultTransformRegistry,
27
+ parseMarkdownDocument,
28
+ serializeMarkdownDocument,
29
+ splitMapPipeline
30
+ } from "./chunk-IXOEIRDT.js";
31
+ import "./chunk-E2DVTD75.js";
32
+ import "./chunk-A6ISKBNM.js";
33
+ import {
34
+ addPackageToYml,
35
+ createWorkspacePackageYml,
36
+ ensureLocalOpenPackageStructure
37
+ } from "./chunk-CVA64SXK.js";
38
+ import {
39
+ detectPluginType
40
+ } from "./chunk-TFQ4JBVO.js";
41
+ import {
42
+ getLocalPackageYmlPath
43
+ } from "./chunk-BCYZDID6.js";
44
+ import {
45
+ isValidPackageDirectory
46
+ } from "./chunk-V5OW4YEB.js";
47
+ import "./chunk-Q2N6OZJC.js";
48
+ import {
49
+ formatPathForYaml
50
+ } from "./chunk-FRYA3JAQ.js";
51
+ import {
52
+ formatPathForDisplay,
53
+ getTreeConnector
54
+ } from "./chunk-4B5HJLP2.js";
55
+ import {
56
+ createCliExecutionContext,
57
+ resolveOutput,
58
+ resolvePrompt
59
+ } from "./chunk-BROJ6OUT.js";
60
+ import "./chunk-XEPVYZO3.js";
61
+ import {
62
+ parsePackageYml,
63
+ writePackageYml
64
+ } from "./chunk-QTQYI4L5.js";
65
+ import {
66
+ arePackageNamesEquivalent,
67
+ normalizePackageName
68
+ } from "./chunk-VN22A7NW.js";
69
+ import {
70
+ mapWorkspaceFileToUniversal
71
+ } from "./chunk-GKEHDSL4.js";
72
+ import {
73
+ normalizePathForProcessing
74
+ } from "./chunk-YMKK4XPN.js";
75
+ import {
76
+ FILE_PATTERNS
77
+ } from "./chunk-J4IFFBLP.js";
78
+ import {
79
+ ensureDir,
80
+ exists,
81
+ isDirectory,
82
+ isFile,
83
+ readTextFile,
84
+ walkFiles,
85
+ writeTextFile
86
+ } from "./chunk-S47F4OG4.js";
87
+ import {
88
+ UserCancellationError,
89
+ ValidationError
90
+ } from "./chunk-ID4SVDQZ.js";
91
+ import {
92
+ logger
93
+ } from "./chunk-5EFWGD33.js";
94
+
95
+ // src/commands/add.ts
96
+ import { join as join6, relative as relative2 } from "path";
97
+
98
+ // ../core/src/core/add/add-to-source-pipeline.ts
99
+ import { resolve as resolvePath, join as join2 } from "path";
100
+
101
+ // ../core/src/core/add/source-collector.ts
102
+ import { relative, basename } from "path";
103
+ import { realpathSync } from "fs";
104
+ async function collectSourceEntries(resolvedPath, cwd) {
105
+ let entries = [];
106
+ if (await isDirectory(resolvedPath)) {
107
+ for await (let filePath of walkFiles(resolvedPath)) {
108
+ let entry = deriveSourceEntry(filePath, cwd);
109
+ if (!entry)
110
+ throw new Error(`Unsupported file inside directory: ${relative(cwd, filePath)}`);
111
+ entries.push(entry);
112
+ }
113
+ return entries;
114
+ }
115
+ if (await isFile(resolvedPath)) {
116
+ let entry = deriveSourceEntry(resolvedPath, cwd);
117
+ if (!entry)
118
+ throw new Error(`Unsupported file: ${relative(cwd, resolvedPath)}`);
119
+ return entries.push(entry), entries;
120
+ }
121
+ throw new Error(`Unsupported path type: ${resolvedPath}`);
122
+ }
123
+ function deriveSourceEntry(absFilePath, cwd) {
124
+ let realFilePath = realpathSync(absFilePath), realCwd = realpathSync(cwd), relativePath = relative(realCwd, realFilePath), normalizedRelPath = normalizePathForProcessing(relativePath), mapping = mapWorkspaceFileToUniversal(absFilePath, cwd);
125
+ if (mapping) {
126
+ let registryPath = [mapping.subdir, mapping.relPath].filter(Boolean).join("/");
127
+ return {
128
+ sourcePath: absFilePath,
129
+ registryPath,
130
+ flow: mapping.flow
131
+ };
132
+ }
133
+ let fileName = basename(normalizedRelPath);
134
+ return fileName && isPlatformRootFile(fileName) && !normalizedRelPath.includes("/") ? {
135
+ sourcePath: absFilePath,
136
+ registryPath: fileName
137
+ } : {
138
+ sourcePath: absFilePath,
139
+ registryPath: `root/${normalizedRelPath}`
140
+ };
141
+ }
142
+
143
+ // ../core/src/core/add/add-conflict-handler.ts
144
+ import { basename as basename2, dirname, extname, join, relative as pathRelative } from "path";
145
+ function resolveTargetPath(packageContext, registryPath) {
146
+ return join(packageContext.packageRootDir, registryPath);
147
+ }
148
+ function transformMarkdownWithFlowMap(raw, entry, workspaceRoot) {
149
+ let flow = entry.flow;
150
+ if (!flow?.map || flow.map.length === 0)
151
+ return { transformed: !1, output: raw };
152
+ if (![".md", ".mdc"].includes(extname(entry.sourcePath).toLowerCase()))
153
+ return { transformed: !1, output: raw };
154
+ let parsed = parseMarkdownDocument(raw, { lenient: !0 });
155
+ if (!parsed.frontmatter)
156
+ return { transformed: !1, output: raw };
157
+ let mapContext = createMapContext({
158
+ filename: basename2(entry.sourcePath, extname(entry.sourcePath)),
159
+ dirname: basename2(dirname(entry.sourcePath)),
160
+ path: pathRelative(workspaceRoot, entry.sourcePath).replace(/\\/g, "/"),
161
+ ext: extname(entry.sourcePath)
162
+ }), { schemaOps, pipeOps } = splitMapPipeline(flow.map), nextFrontmatter = parsed.frontmatter;
163
+ return schemaOps.length > 0 && (nextFrontmatter = applyMapPipeline(nextFrontmatter, schemaOps, mapContext, defaultTransformRegistry)), pipeOps.length > 0 && (nextFrontmatter = applyMapPipeline(nextFrontmatter, pipeOps, mapContext, defaultTransformRegistry)), { transformed: !0, output: serializeMarkdownDocument({ frontmatter: nextFrontmatter, body: parsed.body }) };
164
+ }
165
+ async function copyFilesWithConflictResolution(packageContext, entries, options = {}) {
166
+ let changedFiles = [], { name } = packageContext, policy = options.execContext?.interactionPolicy, forceOverwrite = options.force ?? !1;
167
+ for (let entry of entries) {
168
+ let destination = resolveTargetPath(packageContext, entry.registryPath), sourceContent = await readTextFile(entry.sourcePath), contentToWrite = transformMarkdownWithFlowMap(sourceContent, entry, process.cwd()).output;
169
+ if (await exists(destination)) {
170
+ if (await readTextFile(destination).catch(() => "") === contentToWrite) {
171
+ logger.debug(`Skipping unchanged file: ${entry.registryPath}`);
172
+ continue;
173
+ }
174
+ let decision;
175
+ if (forceOverwrite)
176
+ decision = "overwrite";
177
+ else if (policy?.canPrompt(2 /* Confirmation */)) {
178
+ let effectivePrompt = options.prompt ?? options.execContext?.prompt;
179
+ decision = await promptConflictDecision(name, entry.registryPath, effectivePrompt);
180
+ } else {
181
+ resolveOutput().warn(`Skipping '${entry.registryPath}' (already exists). Use --force to overwrite.`);
182
+ continue;
183
+ }
184
+ if (decision === "keep-existing") {
185
+ logger.debug(`Kept existing file for ${entry.registryPath}`);
186
+ continue;
187
+ }
188
+ }
189
+ await ensureDir(dirname(destination)), await writeTextFile(destination, contentToWrite), changedFiles.push({
190
+ path: entry.registryPath,
191
+ content: contentToWrite,
192
+ encoding: "utf8"
193
+ });
194
+ }
195
+ return changedFiles;
196
+ }
197
+ async function promptConflictDecision(packageName, registryPath, prompt) {
198
+ let decision = await (prompt ?? resolvePrompt()).select(
199
+ `File '${registryPath}' already exists in package '${packageName}'. Choose how to proceed:`,
200
+ [
201
+ { title: "Keep existing file (skip)", value: "keep-existing" },
202
+ { title: "Replace with workspace file", value: "overwrite" },
203
+ { title: "Cancel operation", value: "cancel" }
204
+ ]
205
+ );
206
+ if (decision === "cancel")
207
+ throw new UserCancellationError();
208
+ return decision;
209
+ }
210
+
211
+ // ../core/src/core/add/add-to-source-pipeline.ts
212
+ async function runAddToSourcePipeline(packageName, pathArg, options = {}) {
213
+ let cwd = process.cwd(), { resolvedPackageName, resolvedPath } = await resolveSourceOperationArguments(
214
+ cwd,
215
+ packageName,
216
+ pathArg,
217
+ { command: "add", checkWorkspaceRoot: !1 }
218
+ ), absInputPath = resolvePath(cwd, resolvedPath);
219
+ if (!await exists(absInputPath))
220
+ return { success: !1, error: `Path not found: ${resolvedPath}` };
221
+ let packageContext, sourceType, isWorkspaceRoot = resolvedPackageName === null;
222
+ if (isWorkspaceRoot)
223
+ try {
224
+ packageContext = await buildWorkspacePackageContext(cwd), sourceType = "workspace", logger.info("Adding files to workspace package", {
225
+ sourcePath: packageContext.packageRootDir,
226
+ inputPath: resolvedPath
227
+ });
228
+ } catch (error) {
229
+ return {
230
+ success: !1,
231
+ error: error instanceof Error ? error.message : String(error)
232
+ };
233
+ }
234
+ else {
235
+ let source;
236
+ try {
237
+ source = await resolveMutableSource({ cwd, packageName: resolvedPackageName });
238
+ } catch (error) {
239
+ return { success: !1, error: error instanceof Error ? error.message : String(error) };
240
+ }
241
+ assertMutableSourceOrThrow(source.absolutePath, { packageName: source.packageName, command: "add" }), packageContext = await buildPackageContextFromSource(source), sourceType = source.absolutePath.includes(`${cwd}/.openpackage/packages/`) ? "workspace" : "global", logger.info("Adding files to package source", {
242
+ packageName: source.packageName,
243
+ sourcePath: source.absolutePath,
244
+ sourceType: source.sourceType,
245
+ inputPath: resolvedPath
246
+ });
247
+ }
248
+ let entries = await collectSourceEntries(absInputPath, cwd), changed = await copyFilesWithConflictResolution(packageContext, entries, options);
249
+ logger.info("Files copied to package source", {
250
+ packageName: packageContext.name,
251
+ filesAdded: changed.length
252
+ });
253
+ let addedFilePaths = changed.map((file) => join2(packageContext.packageRootDir, file.path));
254
+ return {
255
+ success: !0,
256
+ data: {
257
+ packageName: packageContext.name,
258
+ filesAdded: changed.length,
259
+ sourcePath: packageContext.packageRootDir,
260
+ sourceType,
261
+ isWorkspaceRoot,
262
+ addedFilePaths
263
+ }
264
+ };
265
+ }
266
+ async function runAddToSourcePipelineBatch(packageName, absPaths, cwd, options = {}) {
267
+ let packageContext, sourceType, isWorkspaceRoot = !packageName;
268
+ if (isWorkspaceRoot)
269
+ try {
270
+ packageContext = await buildWorkspacePackageContext(cwd), sourceType = "workspace";
271
+ } catch (error) {
272
+ return { success: !1, error: error instanceof Error ? error.message : String(error) };
273
+ }
274
+ else {
275
+ let source;
276
+ try {
277
+ source = await resolveMutableSource({ cwd, packageName }), assertMutableSourceOrThrow(source.absolutePath, { packageName: source.packageName, command: "add" }), packageContext = await buildPackageContextFromSource(source), sourceType = source.absolutePath.includes(`${cwd}/.openpackage/packages/`) ? "workspace" : "global";
278
+ } catch (error) {
279
+ return { success: !1, error: error instanceof Error ? error.message : String(error) };
280
+ }
281
+ }
282
+ let allEntries = [], seenRegistryPaths = /* @__PURE__ */ new Set();
283
+ for (let absPath of absPaths) {
284
+ if (!await exists(absPath))
285
+ return { success: !1, error: `Path not found: ${absPath}` };
286
+ try {
287
+ let entries = await collectSourceEntries(absPath, cwd);
288
+ for (let entry of entries)
289
+ seenRegistryPaths.has(entry.registryPath) || (seenRegistryPaths.add(entry.registryPath), allEntries.push(entry));
290
+ } catch (error) {
291
+ return { success: !1, error: error instanceof Error ? error.message : String(error) };
292
+ }
293
+ }
294
+ if (allEntries.length === 0)
295
+ return { success: !0, data: { packageName: packageContext.name, filesAdded: 0, sourcePath: packageContext.packageRootDir, sourceType, isWorkspaceRoot, addedFilePaths: [] } };
296
+ let changed = await copyFilesWithConflictResolution(packageContext, allEntries, options), addedFilePaths = changed.map((f) => join2(packageContext.packageRootDir, f.path));
297
+ return {
298
+ success: !0,
299
+ data: {
300
+ packageName: packageContext.name,
301
+ filesAdded: changed.length,
302
+ sourcePath: packageContext.packageRootDir,
303
+ sourceType,
304
+ isWorkspaceRoot,
305
+ addedFilePaths
306
+ }
307
+ };
308
+ }
309
+ async function buildPackageContextFromSource(source) {
310
+ let packageYmlPath = join2(source.absolutePath, FILE_PATTERNS.OPENPACKAGE_YML), config = await parsePackageYml(packageYmlPath);
311
+ return {
312
+ name: source.packageName,
313
+ version: config.version,
314
+ config,
315
+ packageYmlPath,
316
+ packageRootDir: source.absolutePath,
317
+ packageFilesDir: source.absolutePath
318
+ };
319
+ }
320
+
321
+ // ../core/src/core/add/add-orchestrator.ts
322
+ import { join as join5, resolve as resolve2 } from "path";
323
+
324
+ // ../core/src/core/add/add-input-classifier.ts
325
+ import { join as join3, basename as basename3, resolve } from "path";
326
+ async function classifyAddInput(input, cwd, options) {
327
+ if (options.copy)
328
+ return handleCopyMode(input, cwd);
329
+ if (input.endsWith("/")) {
330
+ let stripped = input.replace(/\/+$/, ""), resolvedPath = resolve(cwd, stripped);
331
+ if (await exists(resolvedPath)) {
332
+ if (await isDirectory(resolvedPath)) {
333
+ let localPathSpec = await buildLocalPathSpec(resolvedPath);
334
+ return enrichWithAddMode(localPathSpec);
335
+ }
336
+ throw new ValidationError(
337
+ `Path '${input}' is not a directory. Trailing slash indicates directory intent.`
338
+ );
339
+ }
340
+ throw new ValidationError(`Directory not found: ${input}`);
341
+ }
342
+ if (isBareNameWithExtension(input)) {
343
+ let resolvedPath = resolve(cwd, input);
344
+ if (await exists(resolvedPath))
345
+ return { mode: "copy", copySourcePath: resolvedPath };
346
+ throw new ValidationError(`File not found: ${input}`);
347
+ }
348
+ let base = await classifyInputBase(input, cwd);
349
+ return enrichWithAddMode(base);
350
+ }
351
+ function isBareNameWithExtension(input) {
352
+ if (input.startsWith("./") || input.startsWith("../") || input.startsWith("/") || input.startsWith("~") || input.includes("@") || input.includes("/") || input.endsWith(".tgz") || input.endsWith(".tar.gz"))
353
+ return !1;
354
+ let lastDot = input.lastIndexOf(".");
355
+ if (lastDot <= 0) return !1;
356
+ let ext = input.slice(lastDot + 1);
357
+ return ext.length >= 1 && ext.length <= 8 && /^[a-zA-Z0-9]+$/.test(ext);
358
+ }
359
+ async function buildLocalPathSpec(absolutePath) {
360
+ let isValid = await isValidPackageDirectory(absolutePath), pluginResult = await detectPluginType(absolutePath), packageName;
361
+ if (isValid || pluginResult.isPlugin)
362
+ try {
363
+ let manifestPath = join3(absolutePath, "openpackage.yml");
364
+ await exists(manifestPath) && (packageName = (await parsePackageYml(manifestPath)).name ?? basename3(absolutePath));
365
+ } catch {
366
+ packageName = basename3(absolutePath);
367
+ }
368
+ return {
369
+ type: "local-path",
370
+ absolutePath,
371
+ isDirectory: !0,
372
+ packageName,
373
+ isValidPackage: isValid || pluginResult.isPlugin
374
+ };
375
+ }
376
+ async function handleCopyMode(input, cwd) {
377
+ let resolvedAbsPath = resolve(cwd, input);
378
+ if (!await exists(resolvedAbsPath))
379
+ throw new ValidationError(
380
+ `Path not found: ${input}
381
+ --copy requires an existing local path.`
382
+ );
383
+ return { mode: "copy", copySourcePath: resolvedAbsPath };
384
+ }
385
+ function enrichWithAddMode(base) {
386
+ switch (base.type) {
387
+ case "bulk":
388
+ throw new ValidationError("Add command requires an input argument");
389
+ case "git":
390
+ return {
391
+ mode: "dependency",
392
+ packageName: base.derivedName,
393
+ gitUrl: base.gitUrl,
394
+ gitRef: base.gitRef,
395
+ gitPath: base.gitPath
396
+ };
397
+ case "local-path":
398
+ return base.absolutePath.endsWith(".tgz") || base.absolutePath.endsWith(".tar.gz") ? {
399
+ mode: "dependency",
400
+ packageName: base.packageName ?? basename3(base.absolutePath).replace(/\.(tgz|tar\.gz)$/, ""),
401
+ localPath: base.absolutePath
402
+ } : base.isValidPackage ? (logger.debug("Classified local directory as dependency", {
403
+ packageName: base.packageName,
404
+ absolutePath: base.absolutePath
405
+ }), {
406
+ mode: "dependency",
407
+ packageName: base.packageName,
408
+ localPath: base.absolutePath
409
+ }) : {
410
+ mode: "copy",
411
+ copySourcePath: base.absolutePath
412
+ };
413
+ case "registry":
414
+ return {
415
+ mode: "dependency",
416
+ packageName: base.packageName,
417
+ version: base.version,
418
+ resourcePath: base.registryPath
419
+ };
420
+ }
421
+ }
422
+
423
+ // ../core/src/core/add/add-dependency-flow.ts
424
+ import { join as join4 } from "path";
425
+ async function runAddDependencyFlow(classification, options) {
426
+ let cwd = process.cwd(), isDev = options.dev ?? !1, section = isDev ? "dev-dependencies" : "dependencies", packageName = classification.packageName, isLocalPath = !!classification.localPath, localPath = classification.localPath ? formatPathForYaml(classification.localPath, cwd) : void 0, gitUrl;
427
+ classification.gitUrl && (gitUrl = classification.gitRef ? `${classification.gitUrl}#${classification.gitRef}` : classification.gitUrl);
428
+ let gitPath = classification.gitPath || classification.resourcePath;
429
+ if (options.to) {
430
+ let source = await resolveMutableSource({ cwd, packageName: options.to }), manifestPath = join4(source.absolutePath, FILE_PATTERNS.OPENPACKAGE_YML);
431
+ return await addDependencyToManifest(manifestPath, packageName, {
432
+ version: classification.version,
433
+ path: localPath,
434
+ url: gitUrl,
435
+ gitPath,
436
+ isDev
437
+ }), logger.info(`Added ${packageName} to ${manifestPath} [${section}]`), {
438
+ packageName,
439
+ targetManifest: manifestPath,
440
+ section,
441
+ isLocalPath,
442
+ wasAutoDetected: isLocalPath
443
+ };
444
+ }
445
+ let packageYmlPath = getLocalPackageYmlPath(cwd);
446
+ return await exists(packageYmlPath) || (await ensureLocalOpenPackageStructure(cwd), await createWorkspacePackageYml(cwd)), await addPackageToYml(
447
+ cwd,
448
+ packageName,
449
+ classification.version,
450
+ isDev,
451
+ void 0,
452
+ !0,
453
+ // silent — CLI layer handles display
454
+ localPath,
455
+ classification.gitUrl,
456
+ classification.gitRef,
457
+ gitPath,
458
+ void 0
459
+ ), logger.info(`Added ${packageName} to workspace manifest [${section}]`), {
460
+ packageName,
461
+ targetManifest: packageYmlPath,
462
+ section,
463
+ isLocalPath,
464
+ wasAutoDetected: isLocalPath
465
+ };
466
+ }
467
+ async function addDependencyToManifest(manifestPath, packageName, options) {
468
+ let config = await parsePackageYml(manifestPath);
469
+ config.dependencies || (config.dependencies = []), config["dev-dependencies"] || (config["dev-dependencies"] = []);
470
+ let normalized = normalizePackageName(packageName), dependency = {
471
+ name: normalized,
472
+ ...options.url ? { url: options.url } : {},
473
+ ...options.path && !options.url ? { path: options.path } : {},
474
+ ...options.version && !options.url && !options.path ? { version: options.version } : {},
475
+ ...options.gitPath && options.url ? { path: options.gitPath } : {}
476
+ }, targetKey = options.isDev ? "dev-dependencies" : "dependencies", otherKey = options.isDev ? "dependencies" : "dev-dependencies", otherArr = config[otherKey], otherIdx = otherArr.findIndex((d) => arePackageNamesEquivalent(d.name, normalized));
477
+ otherIdx >= 0 && otherArr.splice(otherIdx, 1);
478
+ let targetArr = config[targetKey], existingIdx = targetArr.findIndex((d) => arePackageNamesEquivalent(d.name, normalized));
479
+ existingIdx >= 0 ? targetArr[existingIdx] = dependency : targetArr.push(dependency), await writePackageYml(manifestPath, config);
480
+ }
481
+
482
+ // ../core/src/core/add/add-orchestrator.ts
483
+ function isBareNameInput(input) {
484
+ return !input.startsWith("./") && !input.startsWith("../") && !input.startsWith("/") && !input.startsWith("~") && !input.endsWith("/");
485
+ }
486
+ async function processAddResource(resourceSpec, options, cwd, execContext) {
487
+ let classification = await classifyAddInput(resourceSpec, cwd, {
488
+ copy: options.copy,
489
+ dev: options.dev
490
+ });
491
+ if (classification.mode === "dependency") {
492
+ if (options.platformSpecific)
493
+ throw new Error("--platform-specific can only be used with --copy or when adding files");
494
+ try {
495
+ return { kind: "dependency", result: await runAddDependencyFlow(classification, {
496
+ dev: options.dev,
497
+ to: options.to
498
+ }), classification };
499
+ } catch (error) {
500
+ let msg = error instanceof Error ? error.message : String(error);
501
+ if (isBareNameInput(resourceSpec)) {
502
+ let localPath = resolve2(cwd, resourceSpec);
503
+ if (await exists(localPath))
504
+ throw new Error(
505
+ `${msg}
506
+
507
+ A local path './${resourceSpec}' exists \u2014 did you mean:
508
+ opkg add ./${resourceSpec}`
509
+ );
510
+ }
511
+ throw error;
512
+ }
513
+ }
514
+ if (classification.mode === "workspace-resource") {
515
+ if (options.dev)
516
+ throw new Error("--dev can only be used when adding a dependency, not when copying files");
517
+ let resource = classification.resolvedResource, absPath = resource.sourcePath || join5(execContext.targetDir, resource.targetFiles[0]), result2 = await runAddToSourcePipeline(options.to, absPath, { ...options, execContext });
518
+ if (!result2.success)
519
+ throw new Error(result2.error || "Add operation failed");
520
+ return { kind: "workspace-resource", result: result2 };
521
+ }
522
+ if (options.dev)
523
+ throw new Error("--dev can only be used when adding a dependency, not when copying files");
524
+ let result = await runAddToSourcePipeline(options.to, classification.copySourcePath, { ...options, execContext });
525
+ if (!result.success)
526
+ throw new Error(result.error || "Add operation failed");
527
+ return { kind: "copy", result };
528
+ }
529
+
530
+ // src/commands/add.ts
531
+ function displayAddResults(data, out, interactive, skipHeader = !1) {
532
+ let { filesAdded, packageName: resolvedName, addedFilePaths, isWorkspaceRoot, sourcePath } = data, target = isWorkspaceRoot ? "workspace package" : resolvedName;
533
+ if (interactive && !skipHeader) {
534
+ let pkgLabel = isWorkspaceRoot ? "workspace package" : resolvedName, displayPath = formatPathForDisplay(sourcePath, process.cwd());
535
+ out.info(`To: ${pkgLabel} (${displayPath})`);
536
+ }
537
+ if (filesAdded > 0) {
538
+ let count = filesAdded === 1 ? "1 file" : `${filesAdded} files`;
539
+ if (interactive)
540
+ out.success(`Added ${count} to ${target}`);
541
+ else {
542
+ let displayPath = formatPathForDisplay(sourcePath, process.cwd());
543
+ out.success(`Added ${count} to ${target} (${displayPath})`);
544
+ }
545
+ let relPaths = [...addedFilePaths || []].sort((a, b) => a.localeCompare(b)).map((f) => relative2(sourcePath, f).replace(/\\/g, "/"));
546
+ if (interactive) {
547
+ let displayPaths = relPaths.slice(0, 10), more = relPaths.length > 10 ? `
548
+ ... and ${relPaths.length - 10} more` : "";
549
+ out.note(displayPaths.join(`
550
+ `) + more, "Added files");
551
+ } else
552
+ for (let i = 0; i < relPaths.length; i++) {
553
+ let connector = getTreeConnector(i === relPaths.length - 1);
554
+ out.message(` ${connector}${relPaths[i]}`);
555
+ }
556
+ } else
557
+ out.success(`No new files added to ${target}`);
558
+ }
559
+ function displayDependencyResult(depResult, out, interactive) {
560
+ let { result: dep, classification } = depResult, displayPath = formatPathForDisplay(dep.targetManifest, process.cwd());
561
+ if (interactive) {
562
+ let header = `To: ${dep.packageName} (${displayPath})`;
563
+ out.info(header), dep.wasAutoDetected && (out.info(`Detected package at ${classification.localPath} \u2014 adding as dependency.`), out.message("To copy files instead, use --copy."));
564
+ let versionSuffix = classification.version ? `@${classification.version}` : "";
565
+ out.success(`Added ${dep.packageName}${versionSuffix} to ${dep.section}`);
566
+ } else {
567
+ out.success(`Added to ${dep.section} (${displayPath})`);
568
+ let versionSuffix = classification.version ? `@${classification.version}` : "", connector = getTreeConnector(!0);
569
+ out.message(` ${connector}${dep.packageName}${versionSuffix}`), dep.wasAutoDetected && out.message(" Detected local package \u2014 use --copy to copy files instead.");
570
+ }
571
+ }
572
+ function displayResult(result, out, interactive, resourceSpec) {
573
+ switch (result.kind) {
574
+ case "dependency":
575
+ displayDependencyResult(result, out, interactive);
576
+ break;
577
+ case "workspace-resource":
578
+ result.result.data && (out.info(`Resolved "${resourceSpec}" from installed workspace resources.`), displayAddResults(result.result.data, out, interactive));
579
+ break;
580
+ case "copy":
581
+ result.result.data && displayAddResults(result.result.data, out, interactive);
582
+ break;
583
+ }
584
+ }
585
+ async function setupAddCommand(args) {
586
+ let [resource, options, command] = args, cwd = process.cwd(), programOpts = command.parent?.opts() || {}, interactive = !resource, execContext = await createCliExecutionContext({
587
+ global: !1,
588
+ cwd: programOpts.cwd,
589
+ interactive,
590
+ outputMode: interactive ? "rich" : "plain"
591
+ }), policy = createInteractionPolicy({ interactive, force: options.force });
592
+ execContext.interactionPolicy = policy;
593
+ let out = resolveOutput(execContext);
594
+ if (!resource) {
595
+ if (!policy.canPrompt(4 /* OptionalMenu */))
596
+ throw new Error(
597
+ `<resource-spec> argument is required in non-interactive mode.
598
+ Usage: opkg add <resource-spec> [options]`
599
+ );
600
+ let pkgLabel, sourcePath;
601
+ if (options.to) {
602
+ let source = await resolveMutableSource({ cwd, packageName: options.to });
603
+ pkgLabel = source.packageName, sourcePath = source.absolutePath;
604
+ } else {
605
+ let context = await buildWorkspacePackageContext(cwd);
606
+ pkgLabel = "workspace package", sourcePath = context.packageRootDir;
607
+ }
608
+ out.step(`To: ${pkgLabel} (${formatPathForDisplay(sourcePath, cwd)})`), out.connector();
609
+ let selectedFiles = await interactiveFileSelect({ cwd, includeDirs: !0 });
610
+ if (!selectedFiles || selectedFiles.length === 0) return;
611
+ let filesToProcess;
612
+ hasDirectorySelections(selectedFiles) ? (filesToProcess = await expandDirectorySelections(selectedFiles, cwd), out.info(`Found ${filesToProcess.length} total file${filesToProcess.length === 1 ? "" : "s"} to add`)) : filesToProcess = selectedFiles;
613
+ let absPaths = filesToProcess.map((f) => join6(cwd, f)), result2 = await runAddToSourcePipelineBatch(options.to, absPaths, cwd, { ...options, execContext });
614
+ if (!result2.success) throw new Error(result2.error || "Add operation failed");
615
+ result2.data && displayAddResults(result2.data, out, interactive, !0);
616
+ return;
617
+ }
618
+ let result = await processAddResource(resource, options, cwd, execContext);
619
+ displayResult(result, out, interactive, resource);
620
+ }
621
+ export {
622
+ setupAddCommand
623
+ };
624
+ //# sourceMappingURL=add-U44SL3OR.js.map