@xpack/xpm-lib 3.1.2 → 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.
Files changed (202) hide show
  1. package/README.md +16 -212
  2. package/dist/classes/actions.d.ts +58 -0
  3. package/dist/classes/actions.d.ts.map +1 -0
  4. package/dist/classes/actions.js +250 -0
  5. package/dist/classes/actions.js.map +1 -0
  6. package/dist/classes/build-configurations.d.ts +78 -0
  7. package/dist/classes/build-configurations.d.ts.map +1 -0
  8. package/dist/classes/build-configurations.js +489 -0
  9. package/dist/classes/build-configurations.js.map +1 -0
  10. package/dist/classes/combinations-generator.d.ts +19 -0
  11. package/dist/classes/combinations-generator.d.ts.map +1 -0
  12. package/dist/classes/combinations-generator.js +48 -0
  13. package/dist/classes/combinations-generator.js.map +1 -0
  14. package/dist/classes/data-model.d.ts +21 -0
  15. package/dist/classes/data-model.d.ts.map +1 -0
  16. package/dist/classes/data-model.js +47 -0
  17. package/dist/classes/data-model.js.map +1 -0
  18. package/dist/classes/errors.d.ts +13 -0
  19. package/dist/classes/errors.d.ts.map +1 -0
  20. package/dist/classes/errors.js +13 -0
  21. package/dist/classes/errors.js.map +1 -0
  22. package/dist/classes/init-template-base.d.ts +47 -0
  23. package/dist/classes/init-template-base.d.ts.map +1 -0
  24. package/dist/classes/init-template-base.js +358 -0
  25. package/dist/classes/init-template-base.js.map +1 -0
  26. package/dist/classes/liquid-drop.d.ts +28 -0
  27. package/dist/classes/liquid-drop.d.ts.map +1 -0
  28. package/dist/classes/liquid-drop.js +70 -0
  29. package/dist/classes/liquid-drop.js.map +1 -0
  30. package/dist/classes/liquid-engine.d.ts +7 -0
  31. package/dist/classes/liquid-engine.d.ts.map +1 -0
  32. package/dist/classes/liquid-engine.js +72 -0
  33. package/dist/classes/liquid-engine.js.map +1 -0
  34. package/dist/classes/package.d.ts +31 -0
  35. package/dist/classes/package.d.ts.map +1 -0
  36. package/dist/classes/package.js +268 -0
  37. package/dist/classes/package.js.map +1 -0
  38. package/dist/classes/platform-detector.d.ts +14 -0
  39. package/dist/classes/platform-detector.d.ts.map +1 -0
  40. package/dist/classes/platform-detector.js +26 -0
  41. package/dist/classes/platform-detector.js.map +1 -0
  42. package/dist/classes/policies.d.ts +14 -0
  43. package/dist/classes/policies.d.ts.map +1 -0
  44. package/dist/classes/policies.js +20 -0
  45. package/dist/classes/policies.js.map +1 -0
  46. package/dist/classes/template-expander.d.ts +29 -0
  47. package/dist/classes/template-expander.d.ts.map +1 -0
  48. package/dist/classes/template-expander.js +62 -0
  49. package/dist/classes/template-expander.js.map +1 -0
  50. package/dist/data/substitutions-variables.d.ts +43 -0
  51. package/dist/data/substitutions-variables.d.ts.map +1 -0
  52. package/dist/{lib → data}/substitutions-variables.js +1 -16
  53. package/dist/data/substitutions-variables.js.map +1 -0
  54. package/dist/functions/chmod-recursively.d.ts +9 -0
  55. package/dist/functions/chmod-recursively.d.ts.map +1 -0
  56. package/dist/functions/chmod-recursively.js +66 -0
  57. package/dist/functions/chmod-recursively.js.map +1 -0
  58. package/dist/functions/filter-paths.d.ts +5 -0
  59. package/dist/functions/filter-paths.d.ts.map +1 -0
  60. package/dist/functions/filter-paths.js +16 -0
  61. package/dist/functions/filter-paths.js.map +1 -0
  62. package/dist/functions/is-something.d.ts +9 -0
  63. package/dist/functions/is-something.d.ts.map +1 -0
  64. package/dist/functions/is-something.js +25 -0
  65. package/dist/functions/is-something.js.map +1 -0
  66. package/dist/functions/matrix-expander.d.ts +17 -0
  67. package/dist/functions/matrix-expander.d.ts.map +1 -0
  68. package/dist/functions/matrix-expander.js +52 -0
  69. package/dist/functions/matrix-expander.js.map +1 -0
  70. package/dist/functions/perform-substitutions.d.ts +12 -0
  71. package/dist/functions/perform-substitutions.d.ts.map +1 -0
  72. package/dist/functions/perform-substitutions.js +76 -0
  73. package/dist/functions/perform-substitutions.js.map +1 -0
  74. package/dist/functions/utils.d.ts +8 -0
  75. package/dist/functions/utils.d.ts.map +1 -0
  76. package/dist/functions/utils.js +16 -0
  77. package/dist/functions/utils.js.map +1 -0
  78. package/dist/index.d.ts +22 -15
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +22 -29
  81. package/dist/index.js.map +1 -1
  82. package/dist/{lib/types.d.ts → types/json.d.ts} +31 -22
  83. package/dist/types/json.d.ts.map +1 -0
  84. package/dist/types/json.js +2 -0
  85. package/dist/types/json.js.map +1 -0
  86. package/dist/types/xpm-init-template.d.ts +21 -0
  87. package/dist/types/xpm-init-template.d.ts.map +1 -0
  88. package/dist/types/xpm-init-template.js +2 -0
  89. package/dist/types/xpm-init-template.js.map +1 -0
  90. package/dist/types/xpm.d.ts +16 -0
  91. package/dist/types/xpm.d.ts.map +1 -0
  92. package/dist/types/xpm.js +2 -0
  93. package/dist/types/xpm.js.map +1 -0
  94. package/package.json +53 -44
  95. package/src/CODE-REVIEW.md +2167 -0
  96. package/src/README.md +393 -6
  97. package/src/classes/actions.ts +1157 -0
  98. package/src/classes/build-configurations.ts +2127 -0
  99. package/src/classes/combinations-generator.ts +331 -0
  100. package/src/classes/data-model.ts +337 -0
  101. package/src/classes/errors.ts +105 -0
  102. package/src/classes/init-template-base.ts +1028 -0
  103. package/src/classes/liquid-drop.ts +376 -0
  104. package/src/classes/liquid-engine.ts +249 -0
  105. package/src/classes/package.ts +765 -0
  106. package/src/classes/platform-detector.ts +237 -0
  107. package/src/classes/policies.ts +200 -0
  108. package/src/classes/template-expander.ts +330 -0
  109. package/src/data/substitutions-variables.ts +390 -0
  110. package/src/functions/chmod-recursively.ts +195 -0
  111. package/src/functions/filter-paths.ts +126 -0
  112. package/src/functions/is-something.ts +223 -0
  113. package/src/functions/matrix-expander.ts +172 -0
  114. package/src/functions/perform-substitutions.ts +253 -0
  115. package/src/functions/utils.ts +151 -0
  116. package/src/index.ts +72 -19
  117. package/src/types/json.ts +519 -0
  118. package/src/types/xpm-init-template.ts +282 -0
  119. package/src/types/xpm.ts +162 -0
  120. package/dist/lib/chmod-recursive.d.ts +0 -7
  121. package/dist/lib/chmod-recursive.d.ts.map +0 -1
  122. package/dist/lib/chmod-recursive.js +0 -81
  123. package/dist/lib/chmod-recursive.js.map +0 -1
  124. package/dist/lib/errors.d.ts +0 -11
  125. package/dist/lib/errors.d.ts.map +0 -1
  126. package/dist/lib/errors.js +0 -26
  127. package/dist/lib/errors.js.map +0 -1
  128. package/dist/lib/functions/chmod-recursive.d.ts +0 -7
  129. package/dist/lib/functions/chmod-recursive.d.ts.map +0 -1
  130. package/dist/lib/functions/chmod-recursive.js +0 -81
  131. package/dist/lib/functions/chmod-recursive.js.map +0 -1
  132. package/dist/lib/functions/perform-substitutions.d.ts +0 -20
  133. package/dist/lib/functions/perform-substitutions.d.ts.map +0 -1
  134. package/dist/lib/functions/perform-substitutions.js +0 -85
  135. package/dist/lib/functions/perform-substitutions.js.map +0 -1
  136. package/dist/lib/functions/utils.d.ts +0 -30
  137. package/dist/lib/functions/utils.d.ts.map +0 -1
  138. package/dist/lib/functions/utils.js +0 -70
  139. package/dist/lib/functions/utils.js.map +0 -1
  140. package/dist/lib/init-template-base.d.ts +0 -46
  141. package/dist/lib/init-template-base.d.ts.map +0 -1
  142. package/dist/lib/init-template-base.js +0 -281
  143. package/dist/lib/init-template-base.js.map +0 -1
  144. package/dist/lib/liquid-actions.d.ts +0 -37
  145. package/dist/lib/liquid-actions.d.ts.map +0 -1
  146. package/dist/lib/liquid-actions.js +0 -148
  147. package/dist/lib/liquid-actions.js.map +0 -1
  148. package/dist/lib/liquid-build-configurations.d.ts +0 -47
  149. package/dist/lib/liquid-build-configurations.d.ts.map +0 -1
  150. package/dist/lib/liquid-build-configurations.js +0 -282
  151. package/dist/lib/liquid-build-configurations.js.map +0 -1
  152. package/dist/lib/liquid-drop.d.ts +0 -13
  153. package/dist/lib/liquid-drop.d.ts.map +0 -1
  154. package/dist/lib/liquid-drop.js +0 -56
  155. package/dist/lib/liquid-drop.js.map +0 -1
  156. package/dist/lib/liquid-engine.d.ts +0 -5
  157. package/dist/lib/liquid-engine.d.ts.map +0 -1
  158. package/dist/lib/liquid-engine.js +0 -85
  159. package/dist/lib/liquid-engine.js.map +0 -1
  160. package/dist/lib/liquid-package.d.ts +0 -17
  161. package/dist/lib/liquid-package.d.ts.map +0 -1
  162. package/dist/lib/liquid-package.js +0 -70
  163. package/dist/lib/liquid-package.js.map +0 -1
  164. package/dist/lib/package.d.ts +0 -66
  165. package/dist/lib/package.d.ts.map +0 -1
  166. package/dist/lib/package.js +0 -700
  167. package/dist/lib/package.js.map +0 -1
  168. package/dist/lib/perform-substitutions.d.ts +0 -20
  169. package/dist/lib/perform-substitutions.d.ts.map +0 -1
  170. package/dist/lib/perform-substitutions.js +0 -85
  171. package/dist/lib/perform-substitutions.js.map +0 -1
  172. package/dist/lib/policies.d.ts +0 -14
  173. package/dist/lib/policies.d.ts.map +0 -1
  174. package/dist/lib/policies.js +0 -33
  175. package/dist/lib/policies.js.map +0 -1
  176. package/dist/lib/substitutions-variables.d.ts +0 -117
  177. package/dist/lib/substitutions-variables.d.ts.map +0 -1
  178. package/dist/lib/substitutions-variables.js.map +0 -1
  179. package/dist/lib/types.d.ts.map +0 -1
  180. package/dist/lib/types.js +0 -13
  181. package/dist/lib/types.js.map +0 -1
  182. package/dist/lib/utils.d.ts +0 -30
  183. package/dist/lib/utils.d.ts.map +0 -1
  184. package/dist/lib/utils.js +0 -70
  185. package/dist/lib/utils.js.map +0 -1
  186. package/dist/tsconfig.tsbuildinfo +0 -1
  187. package/src/lib/errors.ts +0 -29
  188. package/src/lib/functions/chmod-recursive.ts +0 -103
  189. package/src/lib/functions/perform-substitutions.ts +0 -116
  190. package/src/lib/functions/utils.ts +0 -88
  191. package/src/lib/init-template-base.ts +0 -408
  192. package/src/lib/liquid-actions.ts +0 -223
  193. package/src/lib/liquid-build-configurations.ts +0 -433
  194. package/src/lib/liquid-drop.ts +0 -99
  195. package/src/lib/liquid-engine.ts +0 -135
  196. package/src/lib/liquid-package.ts +0 -108
  197. package/src/lib/package.ts +0 -947
  198. package/src/lib/policies.ts +0 -51
  199. package/src/lib/substitutions-variables.ts +0 -177
  200. package/src/lib/types.ts +0 -109
  201. package/src/package.json +0 -3
  202. package/src/tsconfig.json +0 -10
@@ -0,0 +1,282 @@
1
+ /*
2
+ * This file is part of the xPack project (http://xpack.github.io).
3
+ * Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
4
+ *
5
+ * Permission to use, copy, modify, and/or distribute this software
6
+ * for any purpose is hereby granted, under the terms of the MIT license.
7
+ *
8
+ * If a copy of the license was not distributed with this file, it can
9
+ * be obtained from https://opensource.org/license/mit.
10
+ */
11
+
12
+ // ============================================================================
13
+
14
+ /**
15
+ * Represents a map of `xpm init` template property definitions.
16
+ *
17
+ * @remarks
18
+ * Template properties define the interactive configuration interface for
19
+ * `xpm init` command, allowing templates to collect user input before
20
+ * generating project files.
21
+ *
22
+ * Each property key becomes accessible in template files via Liquid syntax
23
+ * as `{{ properties.key }}`. Property definitions control the prompt type,
24
+ * validation, default values, and available options.
25
+ *
26
+ * Example usage in template metadata:
27
+ *
28
+ * ```js
29
+ * {
30
+ * language: {
31
+ * label: 'Programming language',
32
+ * description: 'Select the preferred programming language',
33
+ * type: 'select',
34
+ * items: {
35
+ * c: 'C for the application files',
36
+ * cpp: 'C++ for the application files'
37
+ * },
38
+ * default: 'cpp',
39
+ * isMandatory: true
40
+ * }
41
+ * }
42
+ * ```
43
+ */
44
+ export type InitTemplatePropertiesDefinitions = Record<
45
+ string,
46
+ InitTemplatePropertiesDefinition
47
+ >
48
+
49
+ /**
50
+ * Defines an `xpm init` single template property.
51
+ *
52
+ * @remarks
53
+ * Property definitions control how users are prompted for template
54
+ * configuration values during `xpm init` execution.
55
+ *
56
+ * Property types:
57
+ *
58
+ * <ul>
59
+ * <li><code>select</code>: Present a list of options for the user to
60
+ * choose from.
61
+ * Requires <code>items</code> to be populated with available choices.</li>
62
+ * <li><code>string</code>: Accept free-form text input from the user.</li>
63
+ * <li><code>number</code>: Accept numeric input with validation.</li>
64
+ * <li><code>boolean</code>: Accept yes/no input
65
+ * (<code>true</code>/<code>false</code>).</li>
66
+ * </ul>
67
+ *
68
+ * Platform filtering: For `select` types, items can specify platform
69
+ * constraints via `InitTemplateItemValue`, hiding options that
70
+ * don't match the current platform. This enables platform-specific
71
+ * configuration without manual filtering.
72
+ *
73
+ * Mandatory properties without defaults will block template initialization
74
+ * until the user provides a value. Optional properties with defaults use
75
+ * the default when the user skips the prompt.
76
+ */
77
+ export interface InitTemplatePropertiesDefinition {
78
+ /**
79
+ * The human-readable label used in prompts.
80
+ */
81
+ label: string
82
+ /**
83
+ * The description shown when the user requests help.
84
+ */
85
+ description: string
86
+ /**
87
+ * The property value type.
88
+ */
89
+ type: InitTemplateType
90
+ /**
91
+ * The selectable items for a `select` property.
92
+ */
93
+ items?: InitTemplateItems
94
+ /**
95
+ * Indicates whether the property is mandatory; defaults to `false`.
96
+ */
97
+ isMandatory?: boolean
98
+ /**
99
+ * The default value for the property. Must match the property type.
100
+ */
101
+ default?: string | number | boolean
102
+ }
103
+
104
+ /**
105
+ * Represents the supported property types for `xpm init` template
106
+ * properties.
107
+ *
108
+ * @remarks
109
+ * Property types control how the `xpm init` command prompts users for
110
+ * configuration values during template initialisation:
111
+ *
112
+ * <ul>
113
+ * <li><b><code>select</code>:</b> Presents a list of predefined options
114
+ * for the user to choose from. Requires the <code>items</code> field to
115
+ * be populated.</li>
116
+ * <li><b><code>string</code>:</b> Accepts free-form text input from the
117
+ * user.</li>
118
+ * <li><b><code>number</code>:</b> Accepts numeric input with
119
+ * validation.</li>
120
+ * <li><b><code>boolean</code>:</b> Accepts yes/no input, converted to
121
+ * <code>true</code> or <code>false</code>.</li>
122
+ * </ul>
123
+ */
124
+ export type InitTemplateType = 'select' | 'string' | 'number' | 'boolean'
125
+
126
+ /**
127
+ * Represents the available items for a `select` type property in `xpm init`
128
+ * templates.
129
+ *
130
+ * @remarks
131
+ * Items define the options users can choose from when a property uses the
132
+ * <code>select</code> type. Each key represents the value stored when that
133
+ * option is selected, whilst the value provides the description shown to
134
+ * the user.
135
+ *
136
+ * Item values can be either:
137
+ *
138
+ * <ul>
139
+ * <li><b>Simple string:</b> A description shown to all users regardless
140
+ * of platform.</li>
141
+ * <li><b><code>InitTemplateItemValue</code>:</b> A platform-specific
142
+ * item that only appears when the current platform matches the
143
+ * <code>platforms</code> constraint.</li>
144
+ * </ul>
145
+ *
146
+ * Example:
147
+ * ```js
148
+ * {
149
+ * gcc: 'The GCC compiler',
150
+ * clang: {
151
+ * platforms: ['darwin'],
152
+ * message: 'The Clang compiler (macOS only)'
153
+ * }
154
+ * }
155
+ * ```
156
+ */
157
+ export type InitTemplateItems = Record<string, string | InitTemplateItemValue>
158
+
159
+ /**
160
+ * Represents the supported platform identifiers for `xpm init` template items.
161
+ *
162
+ * @remarks
163
+ * Platform identifiers filter select items based on the current execution
164
+ * environment, allowing templates to show only relevant options.
165
+ *
166
+ * Platform matching strategy:
167
+ *
168
+ * <ul>
169
+ * <li><b>Generic platforms (linux, win32, darwin):</b> match any
170
+ * architecture on operating system.</li>
171
+ * <li><b>Specific platforms (linux-x64, darwin-arm64, etc.):</b> match
172
+ * only the exact OS and architecture combination.</li>
173
+ * </ul>
174
+ *
175
+ * Example: An item with `platforms: ["darwin-arm64"]` only appears when
176
+ * running on Apple Silicon Macs, while `platforms: ["darwin"]` appears on
177
+ * both Intel and ARM Macs.
178
+ *
179
+ * Common use case: Offering different toolchain options based on whether
180
+ * the user is on Windows, macOS Intel, macOS ARM, or Linux.
181
+ */
182
+ export type InitTemplatePlatform =
183
+ | 'linux'
184
+ | 'linux-x64'
185
+ | 'linux-arm64'
186
+ | 'win32'
187
+ | 'darwin'
188
+ | 'darwin-x64'
189
+ | 'darwin-arm64'
190
+
191
+ /**
192
+ * Defines an `xpm init` template platform-specific item value.
193
+ *
194
+ * @remarks
195
+ * Platform-specific items allow select properties to offer different
196
+ * options based on the user's operating system and architecture. Only items
197
+ * matching the current platform are shown to the user.
198
+ *
199
+ * Example usage in property definition:
200
+ * ```js
201
+ * {
202
+ * toolchain: {
203
+ * label: 'Toolchain',
204
+ * description: 'Select the toolchain to be used by the builds',
205
+ * type: 'select',
206
+ * items: {
207
+ * gcc: {
208
+ * // There is no gcc on macOS.
209
+ * platforms: ['linux', 'win32'],
210
+ * message: 'The xPack GNU Compiler Collection (GCC) toolchain'
211
+ * },
212
+ * clang: 'The xPack LLVM clang toolchain',
213
+ * system: {
214
+ * // There is no system toolchain on Windows.
215
+ * platforms: ['linux', 'darwin'],
216
+ * message: 'The system toolchain'
217
+ * }
218
+ * },
219
+ * default: 'clang'
220
+ * }
221
+ * }
222
+ * ```
223
+ *
224
+ * When running on Windows, only the "msvc" option appears. On Linux or
225
+ * macOS Intel, only "gcc-arm" appears.
226
+ */
227
+ export interface InitTemplateItemValue {
228
+ /**
229
+ * The list of supported platforms.
230
+ */
231
+ platforms: InitTemplatePlatform[]
232
+ /**
233
+ * The description message for this item.
234
+ */
235
+ message: string
236
+ }
237
+
238
+ /**
239
+ * Defines the substitution variables used by `xpm init` templates.
240
+ *
241
+ * @remarks
242
+ * Substitution variables provide the context for Liquid template processing
243
+ * during project initialization. All collected property values and
244
+ * additional template-specific variables are accessible in template files.
245
+ *
246
+ * Variable structure:
247
+ *
248
+ * <ul>
249
+ * <li><b><code>properties</code></b>: Contains all user-provided or
250
+ * default values from the
251
+ * template property definitions, accessible via
252
+ * <code>\{\{ properties.propertyName \}\}</code> in template files.</li>
253
+ * <li><b>Additional variables:</b> Templates can define custom variables
254
+ * for reuse across multiple files or for computed values based on
255
+ * properties.</li>
256
+ * </ul>
257
+ *
258
+ * Template files (with `.liquid` extension) are
259
+ * processed with this context, allowing conditional content, loops, and
260
+ * value substitution. Non-template files are copied as-is without
261
+ * processing.
262
+ *
263
+ * Example template usage:
264
+ * ```
265
+ * Project name: {{ properties.name }}
266
+ * {% if properties.language == "cpp" %}
267
+ * Language: C++
268
+ * {% endif %}
269
+ * ```
270
+ */
271
+ export interface InitTemplateSubstitutionsVariables {
272
+ /**
273
+ * The resolved template properties.
274
+ */
275
+ properties: Record<string, string | boolean | number>
276
+ /**
277
+ * Additional template variables.
278
+ */
279
+ [key: string]: unknown
280
+ }
281
+
282
+ // ----------------------------------------------------------------------------
@@ -0,0 +1,162 @@
1
+ /*
2
+ * This file is part of the xPack project (http://xpack.github.io).
3
+ * Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
4
+ *
5
+ * Permission to use, copy, modify, and/or distribute this software
6
+ * for any purpose is hereby granted, under the terms of the MIT license.
7
+ *
8
+ * If a copy of the license was not distributed with this file, it can
9
+ * be obtained from https://opensource.org/license/mit.
10
+ */
11
+
12
+ // ----------------------------------------------------------------------------
13
+
14
+ import { Logger } from '@xpack/logger'
15
+
16
+ // ============================================================================
17
+
18
+ /**
19
+ * Represents a list of action command strings.
20
+ *
21
+ * @remarks
22
+ * Action commands are always stored as an array of strings after Liquid
23
+ * template evaluation, even if the original definition in `package.json` was
24
+ * a single string.
25
+ *
26
+ * Each string represents a complete command to be executed in sequence.
27
+ * Commands are typically shell commands but can be any executable that can
28
+ * be invoked from the command line.
29
+ *
30
+ * The array structure enables:
31
+ *
32
+ * <ul>
33
+ * <li><b>Multi-step actions:</b> Execute multiple commands in order.</li>
34
+ * <li><b>Error handling:</b> Stop execution on first command failure (default
35
+ * behavior).</li>
36
+ * <li><b>Logging:</b> Report progress as each command completes.</li>
37
+ * </ul>
38
+ *
39
+ * Commands have access to the full shell environment and can reference
40
+ * environment variables, pipe outputs, or chain operations using standard
41
+ * shell syntax (`&&`, `||`, `|`, etc.).
42
+ */
43
+ export type ActionCommands = string[]
44
+
45
+ /**
46
+ * Defines the <b>xpm</b> configuration options.
47
+ *
48
+ * @remarks
49
+ * Configuration options control <b>xpm</b> operation behavior,
50
+ * providing flags for
51
+ * safe mode overrides, installation optimizations, testing scenarios, and
52
+ * property overrides.
53
+ *
54
+ * Configuration lifecycle:
55
+ *
56
+ * <ol>
57
+ * <li>Created from CLI arguments or programmatic API calls.</li>
58
+ * <li>Merged with defaults to form complete configuration.</li>
59
+ * <li>Passed through <code>Context</code> to all <b>xpm</b> operations.</li>
60
+ * <li>Consulted by operations to determine behavior (skip, force,
61
+ * dry-run).</li>
62
+ * </ol>
63
+ *
64
+ * Key configuration patterns:
65
+ *
66
+ * <ul>
67
+ * <li><b>Force mode (<code>doForce: true</code>):</b> Bypasses safety checks
68
+ * like "already
69
+ * installed" or "files exist". Use with caution as it can overwrite
70
+ * data.</li>
71
+ * <li><b>Dry run (<code>isDryRun: true</code>):</b> Simulates operations
72
+ * without making changes,
73
+ * useful for testing or previewing actions.</li>
74
+ * </ul>
75
+ *
76
+ * The extensible design (additional properties allowed) supports future
77
+ * configuration options without breaking changes.
78
+ */
79
+ export interface Config {
80
+ /**
81
+ * Whether to force operations even when safeguards would prevent them.
82
+ */
83
+ doForce?: boolean
84
+ /**
85
+ * Whether to skip operations if the target is already installed.
86
+ */
87
+ doSkipIfInstalled?: boolean
88
+ /**
89
+ * Whether to perform a dry run without making changes.
90
+ */
91
+ isDryRun?: boolean
92
+ /**
93
+ * The properties map used for substitutions.
94
+ */
95
+ properties?: Record<string, string | boolean | number>
96
+
97
+ /**
98
+ * The current working directory for operations that require a base path.
99
+ */
100
+ cwd: string
101
+
102
+ /**
103
+ * Allows additional configuration properties.
104
+ */
105
+ [key: string]: unknown // Allow any additional property
106
+ }
107
+
108
+ /**
109
+ * Provides the execution context for <b>xpm</b> operations.
110
+ *
111
+ * @remarks
112
+ * The context object serves as the central coordination point for all
113
+ * <b>xpm</b>
114
+ * operations, providing access to logging, configuration, and extensible
115
+ * state.
116
+ *
117
+ * Context flow:
118
+ *
119
+ * <ol>
120
+ * <li>Created at the start of each <b>xpm</b> command execution.</li>
121
+ * <li>Initialized with logger instance and configuration options.</li>
122
+ * <li>Passed to all library functions and classes that perform <b>xpm</b>
123
+ * operations.</li>
124
+ * <li>Extended with additional properties as needed by specific operations
125
+ * (e.g., package paths, temporary directories, cache state).</li>
126
+ * </ol>
127
+ *
128
+ * Core responsibilities:
129
+ *
130
+ * <ul>
131
+ * <li><b>Logging:</b> Provides consistent output and diagnostics
132
+ * through the logger
133
+ * instance, enabling verbosity control and structured output.</li>
134
+ * <li><b>Configuration:</b> Makes operational flags and user preferences
135
+ * accessible to all components.</li>
136
+ * <li><b>State sharing:</b> The extensible design allows operations to attach
137
+ * computed values or state that should be available to subsequent
138
+ * operations within the same execution.</li>
139
+ * </ul>
140
+ *
141
+ * The context pattern enables dependency injection, making the code more
142
+ * testable and allowing operations to access shared resources without
143
+ * global state.
144
+ */
145
+ export interface Context {
146
+ /**
147
+ * The logger instance for output and diagnostics.
148
+ */
149
+ log: Logger
150
+ /**
151
+ * The <b>xpm</b> configuration options.
152
+ */
153
+ config: Config
154
+
155
+ /**
156
+ * Allows additional context properties.
157
+ */
158
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
159
+ [key: string]: any // Allow any additional property
160
+ }
161
+
162
+ // ----------------------------------------------------------------------------
@@ -1,7 +0,0 @@
1
- import { Logger } from '@xpack/logger';
2
- export declare function chmodRecursive({ inputPath, readOnly, log, }: {
3
- inputPath: string;
4
- readOnly: boolean;
5
- log: Logger;
6
- }): Promise<void>;
7
- //# sourceMappingURL=chmod-recursive.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chmod-recursive.d.ts","sourceRoot":"","sources":["../../src/lib/chmod-recursive.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAItC,wBAAsB,cAAc,CAAC,EACnC,SAAS,EACT,QAAQ,EACR,GAAG,GACJ,EAAE;IACD,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,OAAO,CAAA;IACjB,GAAG,EAAE,MAAM,CAAA;CACZ,GAAG,OAAO,CAAC,IAAI,CAAC,CAoEhB"}
@@ -1,81 +0,0 @@
1
- /*
2
- * This file is part of the xPack project (http://xpack.github.io).
3
- * Copyright (c) 2017-2025 Liviu Ionescu. All rights reserved.
4
- *
5
- * Permission to use, copy, modify, and/or distribute this software
6
- * for any purpose is hereby granted, under the terms of the MIT license.
7
- *
8
- * If a copy of the license was not distributed with this file, it can
9
- * be obtained from https://opensource.org/license/mit.
10
- */
11
- /* eslint max-len: [ "error", 80, { "ignoreUrls": true } ] */
12
- // ----------------------------------------------------------------------------
13
- // https://nodejs.org/docs/latest/api/
14
- import assert from 'node:assert';
15
- import * as fs from 'node:fs/promises';
16
- import path from 'node:path';
17
- // ----------------------------------------------------------------------------
18
- export async function chmodRecursive({ inputPath, readOnly, log, }) {
19
- assert(inputPath, 'mandatory inputPath');
20
- assert(log, 'mandatory log');
21
- const stat = await fs.lstat(inputPath);
22
- // log.trace(util.inspect(stat))
23
- if (stat.isSymbolicLink()) {
24
- // Since it is not possible to change the modes of links (lchmod
25
- // was deprecated and worked on macOS anyway), don't bother
26
- // with them.
27
- return;
28
- }
29
- // The order is important, process the folder before
30
- // changing it to RO.
31
- if (readOnly && stat.isDirectory()) {
32
- log.trace(inputPath);
33
- const dirents = await fs.readdir(inputPath, {
34
- withFileTypes: true,
35
- });
36
- for (const dirent of dirents) {
37
- await chmodRecursive({
38
- inputPath: path.resolve(inputPath, dirent.name),
39
- readOnly,
40
- log,
41
- });
42
- }
43
- }
44
- const mode = stat.mode;
45
- // For RO, remove all W bits, for RW add only user.
46
- const newMode = readOnly
47
- ? mode &
48
- ~(fs.constants.S_IWUSR | fs.constants.S_IWGRP | fs.constants.S_IWOTH)
49
- : mode | fs.constants.S_IWUSR;
50
- // log.trace(
51
- // `set ${inputPath} from ${mode.toString(8)} to ${newMode.toString(8)}`)
52
- await fs.chmod(inputPath, newMode);
53
- const actualStat = await fs.stat(inputPath);
54
- // log.trace(`actual ${inputPath} is ${actualStat.mode.toString(8)}`)
55
- if (readOnly) {
56
- if ((actualStat.mode & fs.constants.S_IWUSR) !== 0) {
57
- log.warn(`${inputPath} not set to RO`);
58
- }
59
- }
60
- else {
61
- if ((actualStat.mode & fs.constants.S_IWUSR) === 0) {
62
- log.warn(`${inputPath} not set to RW`);
63
- }
64
- }
65
- // If RW, process the folder after changing it to RW.
66
- if (!readOnly && stat.isDirectory()) {
67
- log.trace(inputPath);
68
- const dirents = await fs.readdir(inputPath, {
69
- withFileTypes: true,
70
- });
71
- for (const dirent of dirents) {
72
- await chmodRecursive({
73
- inputPath: path.resolve(inputPath, dirent.name),
74
- readOnly,
75
- log,
76
- });
77
- }
78
- }
79
- }
80
- // ----------------------------------------------------------------------------
81
- //# sourceMappingURL=chmod-recursive.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chmod-recursive.js","sourceRoot":"","sources":["../../src/lib/chmod-recursive.ts"],"names":[],"mappings":"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"}
@@ -1,11 +0,0 @@
1
- export declare class XpmError extends Error {
2
- }
3
- export declare class XpmPrerequisitesError extends Error {
4
- }
5
- export declare class XpmInputError extends Error {
6
- }
7
- export declare class XpmSyntaxError extends Error {
8
- }
9
- export declare class XpmOutputError extends Error {
10
- }
11
- //# sourceMappingURL=errors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAgBA,qBAAa,QAAS,SAAQ,KAAK;CAAG;AAEtC,qBAAa,qBAAsB,SAAQ,KAAK;CAAG;AAEnD,qBAAa,aAAc,SAAQ,KAAK;CAAG;AAE3C,qBAAa,cAAe,SAAQ,KAAK;CAAG;AAE5C,qBAAa,cAAe,SAAQ,KAAK;CAAG"}
@@ -1,26 +0,0 @@
1
- /*
2
- * This file is part of the xPack project (http://xpack.github.io).
3
- * Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
4
- *
5
- * Permission to use, copy, modify, and/or distribute this software
6
- * for any purpose is hereby granted, under the terms of the MIT license.
7
- *
8
- * If a copy of the license was not distributed with this file, it can
9
- * be obtained from https://opensource.org/license/mit.
10
- */
11
- /* eslint max-len: [ "error", 80, { "ignoreUrls": true } ] */
12
- // ----------------------------------------------------------------------------
13
- // Application errors
14
- export class XpmError extends Error {
15
- }
16
- export class XpmPrerequisitesError extends Error {
17
- }
18
- export class XpmInputError extends Error {
19
- }
20
- export class XpmSyntaxError extends Error {
21
- }
22
- export class XpmOutputError extends Error {
23
- }
24
- // Other errors: Child.
25
- // ----------------------------------------------------------------------------
26
- //# sourceMappingURL=errors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,6DAA6D;AAE7D,+EAA+E;AAE/E,qBAAqB;AACrB,MAAM,OAAO,QAAS,SAAQ,KAAK;CAAG;AAEtC,MAAM,OAAO,qBAAsB,SAAQ,KAAK;CAAG;AAEnD,MAAM,OAAO,aAAc,SAAQ,KAAK;CAAG;AAE3C,MAAM,OAAO,cAAe,SAAQ,KAAK;CAAG;AAE5C,MAAM,OAAO,cAAe,SAAQ,KAAK;CAAG;AAE5C,wBAAwB;AAExB,+EAA+E"}
@@ -1,7 +0,0 @@
1
- import { Logger } from '@xpack/logger';
2
- export declare function chmodRecursive({ inputPath, readOnly, log, }: {
3
- inputPath: string;
4
- readOnly: boolean;
5
- log: Logger;
6
- }): Promise<void>;
7
- //# sourceMappingURL=chmod-recursive.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chmod-recursive.d.ts","sourceRoot":"","sources":["../../../src/lib/functions/chmod-recursive.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAItC,wBAAsB,cAAc,CAAC,EACnC,SAAS,EACT,QAAQ,EACR,GAAG,GACJ,EAAE;IACD,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,OAAO,CAAA;IACjB,GAAG,EAAE,MAAM,CAAA;CACZ,GAAG,OAAO,CAAC,IAAI,CAAC,CAoEhB"}
@@ -1,81 +0,0 @@
1
- /*
2
- * This file is part of the xPack project (http://xpack.github.io).
3
- * Copyright (c) 2017-2026 Liviu Ionescu. All rights reserved.
4
- *
5
- * Permission to use, copy, modify, and/or distribute this software
6
- * for any purpose is hereby granted, under the terms of the MIT license.
7
- *
8
- * If a copy of the license was not distributed with this file, it can
9
- * be obtained from https://opensource.org/license/mit.
10
- */
11
- /* eslint max-len: [ "error", 80, { "ignoreUrls": true } ] */
12
- // ----------------------------------------------------------------------------
13
- // https://nodejs.org/docs/latest/api/
14
- import assert from 'node:assert';
15
- import * as fs from 'node:fs/promises';
16
- import * as path from 'node:path';
17
- // ----------------------------------------------------------------------------
18
- export async function chmodRecursive({ inputPath, readOnly, log, }) {
19
- assert(inputPath, 'mandatory inputPath');
20
- assert(log, 'mandatory log');
21
- const stat = await fs.lstat(inputPath);
22
- // log.trace(util.inspect(stat))
23
- if (stat.isSymbolicLink()) {
24
- // Since it is not possible to change the modes of links (lchmod
25
- // was deprecated and worked on macOS anyway), don't bother
26
- // with them.
27
- return;
28
- }
29
- // The order is important, process the folder before
30
- // changing it to RO.
31
- if (readOnly && stat.isDirectory()) {
32
- log.trace(inputPath);
33
- const dirents = await fs.readdir(inputPath, {
34
- withFileTypes: true,
35
- });
36
- for (const dirent of dirents) {
37
- await chmodRecursive({
38
- inputPath: path.resolve(inputPath, dirent.name),
39
- readOnly,
40
- log,
41
- });
42
- }
43
- }
44
- const mode = stat.mode;
45
- // For RO, remove all W bits, for RW add only user.
46
- const newMode = readOnly
47
- ? mode &
48
- ~(fs.constants.S_IWUSR | fs.constants.S_IWGRP | fs.constants.S_IWOTH)
49
- : mode | fs.constants.S_IWUSR;
50
- // log.trace(
51
- // `set ${inputPath} from ${mode.toString(8)} to ${newMode.toString(8)}`)
52
- await fs.chmod(inputPath, newMode);
53
- const actualStat = await fs.stat(inputPath);
54
- // log.trace(`actual ${inputPath} is ${actualStat.mode.toString(8)}`)
55
- if (readOnly) {
56
- if ((actualStat.mode & fs.constants.S_IWUSR) !== 0) {
57
- log.warn(`${inputPath} not set to RO`);
58
- }
59
- }
60
- else {
61
- if ((actualStat.mode & fs.constants.S_IWUSR) === 0) {
62
- log.warn(`${inputPath} not set to RW`);
63
- }
64
- }
65
- // If RW, process the folder after changing it to RW.
66
- if (!readOnly && stat.isDirectory()) {
67
- log.trace(inputPath);
68
- const dirents = await fs.readdir(inputPath, {
69
- withFileTypes: true,
70
- });
71
- for (const dirent of dirents) {
72
- await chmodRecursive({
73
- inputPath: path.resolve(inputPath, dirent.name),
74
- readOnly,
75
- log,
76
- });
77
- }
78
- }
79
- }
80
- // ----------------------------------------------------------------------------
81
- //# sourceMappingURL=chmod-recursive.js.map