@shell-shock/plugin-upgrade 0.1.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 (46) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +264 -0
  3. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  4. package/dist/components/index.cjs +11 -0
  5. package/dist/components/index.d.cts +3 -0
  6. package/dist/components/index.d.mts +3 -0
  7. package/dist/components/index.mjs +4 -0
  8. package/dist/components/upgrade-builtin.cjs +735 -0
  9. package/dist/components/upgrade-builtin.d.cts +36 -0
  10. package/dist/components/upgrade-builtin.d.cts.map +1 -0
  11. package/dist/components/upgrade-builtin.d.mts +36 -0
  12. package/dist/components/upgrade-builtin.d.mts.map +1 -0
  13. package/dist/components/upgrade-builtin.mjs +728 -0
  14. package/dist/components/upgrade-builtin.mjs.map +1 -0
  15. package/dist/components/upgrade-command.cjs +96 -0
  16. package/dist/components/upgrade-command.d.cts +10 -0
  17. package/dist/components/upgrade-command.d.cts.map +1 -0
  18. package/dist/components/upgrade-command.d.mts +10 -0
  19. package/dist/components/upgrade-command.d.mts.map +1 -0
  20. package/dist/components/upgrade-command.mjs +96 -0
  21. package/dist/components/upgrade-command.mjs.map +1 -0
  22. package/dist/index.cjs +51 -0
  23. package/dist/index.d.cts +12 -0
  24. package/dist/index.d.cts.map +1 -0
  25. package/dist/index.d.mts +12 -0
  26. package/dist/index.d.mts.map +1 -0
  27. package/dist/index.mjs +49 -0
  28. package/dist/index.mjs.map +1 -0
  29. package/dist/types/index.cjs +4 -0
  30. package/dist/types/index.d.cts +3 -0
  31. package/dist/types/index.d.mts +3 -0
  32. package/dist/types/index.mjs +3 -0
  33. package/dist/types/package-manager.cjs +20 -0
  34. package/dist/types/package-manager.d.cts +7 -0
  35. package/dist/types/package-manager.d.cts.map +1 -0
  36. package/dist/types/package-manager.d.mts +7 -0
  37. package/dist/types/package-manager.d.mts.map +1 -0
  38. package/dist/types/package-manager.mjs +19 -0
  39. package/dist/types/package-manager.mjs.map +1 -0
  40. package/dist/types/plugin.cjs +0 -0
  41. package/dist/types/plugin.d.cts +29 -0
  42. package/dist/types/plugin.d.cts.map +1 -0
  43. package/dist/types/plugin.d.mts +29 -0
  44. package/dist/types/plugin.d.mts.map +1 -0
  45. package/dist/types/plugin.mjs +1 -0
  46. package/package.json +185 -0
@@ -0,0 +1,728 @@
1
+ import { createComponent, createIntrinsic, mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { Show, code, splitProps } from "@alloy-js/core";
3
+ import { ElseClause, ElseIfClause, FunctionDeclaration, IfStatement, InterfaceDeclaration, VarDeclaration } from "@alloy-js/typescript";
4
+ import { Spacing } from "@powerlines/plugin-alloy/core/components/spacing";
5
+ import { InterfaceMember, TSDoc, TSDocParam, TSDocRemarks, TSDocReturns, TypeDeclaration } from "@powerlines/plugin-alloy/typescript";
6
+ import { BuiltinFile } from "@powerlines/plugin-alloy/typescript/components/builtin-file";
7
+ import defu from "defu";
8
+
9
+ //#region src/components/upgrade-builtin.tsx
10
+ /**
11
+ * The `locatePackageJson` handler function declaration code for the Shell Shock project.
12
+ */
13
+ function LocatePackageJsonFunctionDeclaration() {
14
+ return [
15
+ createComponent(InterfaceDeclaration, {
16
+ "export": true,
17
+ name: "LocatePackageJsonOptions",
18
+ doc: "Options for the `locatePackageJson` handler function.",
19
+ get children() {
20
+ return createComponent(InterfaceMember, {
21
+ name: "cwd",
22
+ optional: true,
23
+ type: "string",
24
+ doc: "The current working directory to use. If not provided, the process's current working directory will be used."
25
+ });
26
+ }
27
+ }),
28
+ createComponent(Spacing, {}),
29
+ createComponent(TSDoc, {
30
+ heading: "Locate the package.json file currently being used by the command-line/workspace.",
31
+ get children() {
32
+ return [
33
+ createComponent(TSDocRemarks, { children: `This function is used to determine the package.json file currently being used by the command-line/workspace. It can be used in the CLI upgrade command to check if the application is using npm, yarn, or another package manager.` }),
34
+ createComponent(Spacing, {}),
35
+ createComponent(TSDocParam, {
36
+ name: "options",
37
+ children: `The options for the \`locatePackageJson\` function. Currently, there are no options available, but this parameter is included for future extensibility.`
38
+ }),
39
+ createComponent(TSDocReturns, { children: `A promise that resolves to the package.json file currently being used by the command-line/workspace as a string.` })
40
+ ];
41
+ }
42
+ }),
43
+ createComponent(FunctionDeclaration, {
44
+ "export": true,
45
+ async: true,
46
+ name: "locatePackageJson",
47
+ parameters: [{
48
+ name: "options",
49
+ type: "LocatePackageJsonOptions",
50
+ default: "{}"
51
+ }],
52
+ returnType: "string | undefined",
53
+ get children() {
54
+ return [
55
+ createComponent(VarDeclaration, {
56
+ "let": true,
57
+ name: "currentPath",
58
+ type: "string",
59
+ initializer: code`options.cwd ?? process.cwd(); `
60
+ }),
61
+ createIntrinsic("hbr", {}),
62
+ createComponent(VarDeclaration, {
63
+ "let": true,
64
+ name: "parentPath",
65
+ initializer: code`resolve(currentPath, ".."); `
66
+ }),
67
+ createComponent(Spacing, {}),
68
+ code`while (parentPath !== currentPath && currentPath !== homePath && currentPath !== tempPath) { `,
69
+ createComponent(IfStatement, {
70
+ condition: code`existsSync(join(currentPath, "package.json"))`,
71
+ children: code`return join(currentPath, "package.json"); `
72
+ }),
73
+ createComponent(ElseClause, { children: code`currentPath = pathParent;
74
+ parentPath = resolve(currentPath, ".."); ` }),
75
+ code` }
76
+
77
+ return undefined; `
78
+ ];
79
+ }
80
+ })
81
+ ];
82
+ }
83
+ /**
84
+ * The `locateLockfile` handler function declaration code for the Shell Shock project.
85
+ */
86
+ function LocateLockfileFunctionDeclaration() {
87
+ return [
88
+ createComponent(InterfaceDeclaration, {
89
+ "export": true,
90
+ name: "LocateLockfileOptions",
91
+ doc: "Options for the `locateLockfile` handler function.",
92
+ get children() {
93
+ return createComponent(InterfaceMember, {
94
+ name: "cwd",
95
+ optional: true,
96
+ type: "string",
97
+ doc: "The current working directory to use. If not provided, the process's current working directory will be used."
98
+ });
99
+ }
100
+ }),
101
+ createComponent(Spacing, {}),
102
+ createComponent(TSDoc, {
103
+ heading: "Locate the lockfile currently being used by the command-line/workspace.",
104
+ get children() {
105
+ return [
106
+ createComponent(TSDocRemarks, { children: `This function is used to determine the lockfile currently being used by the command-line/workspace. It can be used in the CLI upgrade command to check if the application is using npm, yarn, or another package manager.` }),
107
+ createComponent(Spacing, {}),
108
+ createComponent(TSDocParam, {
109
+ name: "options",
110
+ children: `The options for the \`locateLockfile\` function. Currently, there are no options available, but this parameter is included for future extensibility.`
111
+ }),
112
+ createComponent(TSDocReturns, { children: `A promise that resolves to the lockfile currently being used by the command-line/workspace as a string.` })
113
+ ];
114
+ }
115
+ }),
116
+ createComponent(FunctionDeclaration, {
117
+ "export": true,
118
+ async: true,
119
+ name: "locateLockfile",
120
+ parameters: [{
121
+ name: "options",
122
+ type: "LocateLockfileOptions",
123
+ default: "{}"
124
+ }],
125
+ returnType: "string | undefined",
126
+ get children() {
127
+ return [
128
+ createComponent(VarDeclaration, {
129
+ "let": true,
130
+ name: "currentPath",
131
+ type: "string",
132
+ initializer: code`options.cwd ?? process.cwd(); `
133
+ }),
134
+ createIntrinsic("hbr", {}),
135
+ createComponent(VarDeclaration, {
136
+ "let": true,
137
+ name: "parentPath",
138
+ initializer: code`resolve(currentPath, ".."); `
139
+ }),
140
+ createComponent(Spacing, {}),
141
+ code`while (parentPath !== currentPath && currentPath !== homePath && currentPath !== tempPath) { `,
142
+ createComponent(VarDeclaration, {
143
+ "const": true,
144
+ name: "lockfile",
145
+ initializer: code`[
146
+ "package-lock.json",
147
+ "npm-shrinkwrap.json",
148
+ "yarn.lock",
149
+ "pnpm-lock.yaml",
150
+ "pnpm-workspace.yaml",
151
+ "deno.lock",
152
+ "deno.json",
153
+ "deno.jsonc",
154
+ "bun.lock",
155
+ "bun.lockb"
156
+ ].find(lf => existsSync(join(currentPath, lf))); `
157
+ }),
158
+ createIntrinsic("hbr", {}),
159
+ createComponent(IfStatement, {
160
+ condition: code`lockfile`,
161
+ children: code`return lockfile; `
162
+ }),
163
+ createComponent(ElseClause, { children: code`currentPath = pathParent;
164
+ parentPath = resolve(currentPath, ".."); ` }),
165
+ code` }
166
+
167
+ return undefined; `
168
+ ];
169
+ }
170
+ })
171
+ ];
172
+ }
173
+ /**
174
+ * The `getPackageManager` handler function declaration code for the Shell Shock project.
175
+ */
176
+ function GetPackageManagerFunctionDeclaration() {
177
+ return [
178
+ createComponent(TypeDeclaration, {
179
+ "export": true,
180
+ name: "GetPackageManagerOptions",
181
+ doc: "Options for the `getPackageManager` handler function.",
182
+ children: code`LocateLockfileOptions;`
183
+ }),
184
+ createComponent(Spacing, {}),
185
+ createComponent(TSDoc, {
186
+ heading: "Get the package manager currently being used by the command-line/workspace.",
187
+ get children() {
188
+ return [
189
+ createComponent(TSDocRemarks, { children: `This function is used to determine the package manager currently being used by the command-line/workspace. It can be used in the CLI upgrade command to check if the application is using npm, yarn, or another package manager.` }),
190
+ createComponent(Spacing, {}),
191
+ createComponent(TSDocParam, {
192
+ name: "options",
193
+ children: `The options for the \`getPackageManager\` function. Currently, there are no options available, but this parameter is included for future extensibility.`
194
+ }),
195
+ createComponent(TSDocReturns, { children: `A promise that resolves to the package manager currently being used by the command-line/workspace as a string.` })
196
+ ];
197
+ }
198
+ }),
199
+ createComponent(FunctionDeclaration, {
200
+ "export": true,
201
+ async: true,
202
+ name: "getPackageManager",
203
+ parameters: [{
204
+ name: "options",
205
+ type: "GetPackageManagerOptions",
206
+ default: "{}"
207
+ }],
208
+ returnType: code`Promise<"npm" | "yarn" | "deno" | "pnpm" | "bun">`,
209
+ get children() {
210
+ return [
211
+ createComponent(VarDeclaration, {
212
+ "const": true,
213
+ name: "userAgent",
214
+ type: "string",
215
+ initializer: code`process.env.npm_config_user_agent ?? ""; `
216
+ }),
217
+ createIntrinsic("hbr", {}),
218
+ createComponent(VarDeclaration, {
219
+ "const": true,
220
+ name: "execPath",
221
+ type: "string",
222
+ initializer: code`process.env.npm_execpath ?? ""; `
223
+ }),
224
+ createComponent(Spacing, {}),
225
+ createComponent(IfStatement, {
226
+ condition: code`userAgent.startsWith("yarn") || execPath.includes("yarn")`,
227
+ children: code`return "yarn"; `
228
+ }),
229
+ createComponent(ElseIfClause, {
230
+ condition: code`userAgent.startsWith("pnpm") || execPath.includes("pnpm")`,
231
+ children: code`return "pnpm"; `
232
+ }),
233
+ createComponent(ElseIfClause, {
234
+ condition: code`userAgent.startsWith("bun") || execPath.includes("bun") || typeof Bun !== "undefined" || process.versions.bun`,
235
+ children: code`return "bun"; `
236
+ }),
237
+ createComponent(ElseClause, { get children() {
238
+ return [
239
+ createComponent(VarDeclaration, {
240
+ "const": true,
241
+ name: "lockfilePath",
242
+ initializer: code`locateLockfile(options); `
243
+ }),
244
+ createComponent(Spacing, {}),
245
+ createComponent(IfStatement, {
246
+ condition: code`lockfilePath === "yarn.lock"`,
247
+ children: code`return "yarn"; `
248
+ }),
249
+ createComponent(ElseIfClause, {
250
+ condition: code`lockfilePath === "deno.lock" || lockfilePath === "deno.json" || lockfilePath === "deno.jsonc"`,
251
+ children: code`return "deno"; `
252
+ }),
253
+ createComponent(ElseIfClause, {
254
+ condition: code`lockfilePath === "pnpm-lock.yaml" || lockfilePath === "pnpm-workspace.yaml"`,
255
+ children: code`return "pnpm"; `
256
+ }),
257
+ createComponent(ElseIfClause, {
258
+ condition: code`lockfilePath === "bun.lock" || lockfilePath === "bun.lockb"`,
259
+ children: code`return "bun"; `
260
+ }),
261
+ createComponent(ElseClause, { get children() {
262
+ return [
263
+ createComponent(VarDeclaration, {
264
+ "const": true,
265
+ name: "packageJsonPath",
266
+ initializer: code`locatePackageJson(options); `
267
+ }),
268
+ createComponent(IfStatement, {
269
+ condition: code`packageJsonPath && existsSync(packageJsonPath)`,
270
+ get children() {
271
+ return [
272
+ createComponent(VarDeclaration, {
273
+ "const": true,
274
+ name: "packageJson",
275
+ initializer: code`JSON.parse(await readFile(packageJsonPath, "utf8")); `
276
+ }),
277
+ createComponent(IfStatement, {
278
+ condition: code`packageJson.devEngines?.packageManager?.name && typeof packageJson.devEngines.packageManager.name === "string" && ["npm", "yarn", "pnpm", "deno", "bun"].includes(packageJson.devEngines.packageManager.name)`,
279
+ children: code`return packageJson.devEngines.packageManager.name; `
280
+ }),
281
+ createComponent(Spacing, {}),
282
+ createComponent(VarDeclaration, {
283
+ "const": true,
284
+ name: "dependencies",
285
+ initializer: code`{
286
+ ...packageJson.dependencies,
287
+ ...packageJson.devDependencies,
288
+ ...packageJson.peerDependencies,
289
+ ...packageJson.optionalDependencies,
290
+ }; `
291
+ }),
292
+ createComponent(IfStatement, {
293
+ condition: code`Object.keys(dependencies).some(dep => dep === "yarn" || dep.startsWith("yarn@") || dep === "yarnpkg" || dep.startsWith("yarnpkg@"))`,
294
+ children: code`return "yarn"; `
295
+ }),
296
+ createComponent(ElseIfClause, {
297
+ condition: code`Object.keys(dependencies).some(dep => dep === "bun" || dep.startsWith("bun@"))`,
298
+ children: code`return "bun"; `
299
+ }),
300
+ createComponent(ElseIfClause, {
301
+ condition: code`Object.keys(dependencies).some(dep => dep === "pnpm" || dep.startsWith("pnpm@"))`,
302
+ children: code`return "pnpm"; `
303
+ }),
304
+ createComponent(ElseIfClause, {
305
+ condition: code`Object.keys(dependencies).some(dep => dep === "deno" || dep.startsWith("deno@"))`,
306
+ children: code`return "deno"; `
307
+ })
308
+ ];
309
+ }
310
+ }),
311
+ createComponent(Spacing, {}),
312
+ code`return "npm"; `
313
+ ];
314
+ } })
315
+ ];
316
+ } })
317
+ ];
318
+ }
319
+ })
320
+ ];
321
+ }
322
+ /**
323
+ * The `fetchNpmPackage` handler function declaration code for the Shell Shock project.
324
+ */
325
+ function FetchNpmPackageFunctionDeclaration() {
326
+ return [
327
+ createComponent(InterfaceDeclaration, {
328
+ "export": true,
329
+ name: "NpmPackageMaintainer",
330
+ doc: "Represents a maintainer of an npm package.",
331
+ get children() {
332
+ return [
333
+ createComponent(InterfaceMember, {
334
+ name: "email",
335
+ type: "string",
336
+ doc: "The email of the npm package maintainer."
337
+ }),
338
+ createIntrinsic("hbr", {}),
339
+ createComponent(InterfaceMember, {
340
+ name: "username",
341
+ type: "string",
342
+ doc: "The username of the npm package maintainer."
343
+ })
344
+ ];
345
+ }
346
+ }),
347
+ createComponent(Spacing, {}),
348
+ createComponent(InterfaceDeclaration, {
349
+ "export": true,
350
+ name: "NpmPackageLinks",
351
+ doc: "Represents the links of an npm package.",
352
+ get children() {
353
+ return [
354
+ createComponent(InterfaceMember, {
355
+ name: "homepage",
356
+ type: "string",
357
+ optional: true,
358
+ doc: "The homepage of the npm package."
359
+ }),
360
+ createIntrinsic("hbr", {}),
361
+ createComponent(InterfaceMember, {
362
+ name: "repository",
363
+ type: "string",
364
+ optional: true,
365
+ doc: "The repository of the npm package."
366
+ }),
367
+ createIntrinsic("hbr", {}),
368
+ createComponent(InterfaceMember, {
369
+ name: "bugs",
370
+ type: "string",
371
+ optional: true,
372
+ doc: "The bugs page of the npm package."
373
+ }),
374
+ createIntrinsic("hbr", {}),
375
+ createComponent(InterfaceMember, {
376
+ name: "npm",
377
+ type: "string",
378
+ optional: true,
379
+ doc: "The npm page of the npm package."
380
+ })
381
+ ];
382
+ }
383
+ }),
384
+ createComponent(Spacing, {}),
385
+ createComponent(InterfaceDeclaration, {
386
+ "export": true,
387
+ name: "NpmPackage",
388
+ doc: "Represents an npm package.",
389
+ get children() {
390
+ return [
391
+ createComponent(InterfaceMember, {
392
+ name: "name",
393
+ type: "string",
394
+ doc: "The name of the npm package."
395
+ }),
396
+ createIntrinsic("hbr", {}),
397
+ createComponent(InterfaceMember, {
398
+ name: "date",
399
+ type: "Date",
400
+ doc: "The date when the npm package was last updated."
401
+ }),
402
+ createIntrinsic("hbr", {}),
403
+ createComponent(InterfaceMember, {
404
+ name: "version",
405
+ type: "string",
406
+ doc: "The version of the npm package."
407
+ }),
408
+ createIntrinsic("hbr", {}),
409
+ createComponent(InterfaceMember, {
410
+ name: "description",
411
+ type: "string",
412
+ optional: true,
413
+ doc: "The description of the npm package."
414
+ }),
415
+ createIntrinsic("hbr", {}),
416
+ createComponent(InterfaceMember, {
417
+ name: "keywords",
418
+ type: "string[]",
419
+ doc: "A list of keywords associated with the npm package."
420
+ }),
421
+ createIntrinsic("hbr", {}),
422
+ createComponent(InterfaceMember, {
423
+ name: "license",
424
+ type: "string",
425
+ optional: true,
426
+ doc: "The license of the npm package."
427
+ }),
428
+ createIntrinsic("hbr", {}),
429
+ createComponent(InterfaceMember, {
430
+ name: "maintainers",
431
+ type: "NpmPackageMaintainer[]",
432
+ doc: "The maintainers of the npm package."
433
+ }),
434
+ createIntrinsic("hbr", {}),
435
+ createComponent(InterfaceMember, {
436
+ name: "links",
437
+ type: "NpmPackageLinks",
438
+ doc: "The links of the npm package."
439
+ }),
440
+ createIntrinsic("hbr", {})
441
+ ];
442
+ }
443
+ }),
444
+ createComponent(Spacing, {}),
445
+ createComponent(InterfaceDeclaration, {
446
+ "export": true,
447
+ name: "NpmPackageSearchResultItem",
448
+ doc: "Represents an npm package search result item.",
449
+ get children() {
450
+ return createComponent(InterfaceMember, {
451
+ name: "package",
452
+ type: "NpmPackage",
453
+ doc: "The npm package details."
454
+ });
455
+ }
456
+ }),
457
+ createComponent(Spacing, {}),
458
+ createComponent(InterfaceDeclaration, {
459
+ "export": true,
460
+ name: "NpmPackageSearchResult",
461
+ doc: "Represents an npm package search result.",
462
+ get children() {
463
+ return createComponent(InterfaceMember, {
464
+ name: "objects",
465
+ type: "NpmPackageSearchResultItem[]",
466
+ doc: "The list of npm package search result items."
467
+ });
468
+ }
469
+ }),
470
+ createComponent(Spacing, {}),
471
+ createComponent(TSDoc, {
472
+ heading: "Fetch details of an npm package.",
473
+ get children() {
474
+ return [
475
+ createComponent(TSDocRemarks, { children: `This function is used to fetch an npm package. It can be used in the CLI upgrade command to check if the application is using npm, yarn, or another package manager.` }),
476
+ createComponent(Spacing, {}),
477
+ createComponent(TSDocParam, {
478
+ name: "packageName",
479
+ children: `The name of the npm package to fetch.`
480
+ }),
481
+ createComponent(TSDocReturns, { children: `A promise that resolves to the npm package details or undefined if the package is not found.` })
482
+ ];
483
+ }
484
+ }),
485
+ createComponent(FunctionDeclaration, {
486
+ "export": true,
487
+ async: true,
488
+ name: "fetchNpmPackage",
489
+ parameters: [{
490
+ name: "packageName",
491
+ type: "string"
492
+ }],
493
+ returnType: code`Promise<NpmPackage | undefined>`,
494
+ get children() {
495
+ return [
496
+ createComponent(VarDeclaration, {
497
+ "const": true,
498
+ name: "result",
499
+ initializer: code` await fetch(\`https://registry.npmjs.com/-/v1/search?text=\${packageName}&size=1\`).then(res => res.json()) as NpmPackageSearchResult; `
500
+ }),
501
+ createIntrinsic("hbr", {}),
502
+ createComponent(IfStatement, {
503
+ condition: code`result.objects && result.objects.length > 0 && result.objects[0].package && result.objects[0].package.name === packageName`,
504
+ children: code`return result.objects[0].package; `
505
+ }),
506
+ createComponent(ElseClause, { children: code`return undefined; ` })
507
+ ];
508
+ }
509
+ })
510
+ ];
511
+ }
512
+ /**
513
+ * The `getLatest` handler function declaration code for the Shell Shock project.
514
+ */
515
+ function GetLatestFunctionDeclaration() {
516
+ return [createComponent(TSDoc, {
517
+ heading: "Get the latest version of the application from the npm registry.",
518
+ get children() {
519
+ return [
520
+ createComponent(TSDocRemarks, { children: `This function is used to retrieve the latest version of the application from the npm registry. It can be used in the CLI upgrade command to check if there is a newer version of the application available.` }),
521
+ createComponent(Spacing, {}),
522
+ createComponent(TSDocParam, {
523
+ name: "packageName",
524
+ children: `The name of the npm package to fetch.`
525
+ }),
526
+ createComponent(TSDocReturns, { children: `A promise that resolves to the latest version of the specified npm package as a string.` })
527
+ ];
528
+ }
529
+ }), createComponent(FunctionDeclaration, {
530
+ "export": true,
531
+ async: true,
532
+ name: "getLatest",
533
+ parameters: [{
534
+ name: "packageName",
535
+ type: "string"
536
+ }],
537
+ get children() {
538
+ return [
539
+ createComponent(VarDeclaration, {
540
+ "const": true,
541
+ name: "package",
542
+ initializer: code`await fetchNpmPackage(packageName); `
543
+ }),
544
+ createComponent(Spacing, {}),
545
+ code`return package?.version; `
546
+ ];
547
+ }
548
+ })];
549
+ }
550
+ /**
551
+ * The `install` handler function declaration code for the Shell Shock project.
552
+ */
553
+ function InstallFunctionDeclaration() {
554
+ return [
555
+ createComponent(InterfaceDeclaration, {
556
+ "export": true,
557
+ name: "InstallOptions",
558
+ doc: "Options for the `install` handler function.",
559
+ get children() {
560
+ return [
561
+ createComponent(InterfaceMember, {
562
+ name: "stdout",
563
+ optional: true,
564
+ type: "(string) => void",
565
+ doc: "A callback function that is called with the stdout output of the command."
566
+ }),
567
+ createIntrinsic("hbr", {}),
568
+ createComponent(InterfaceMember, {
569
+ name: "stderr",
570
+ optional: true,
571
+ type: "(string) => void",
572
+ doc: "A callback function that is called with the stderr output of the command."
573
+ }),
574
+ createIntrinsic("hbr", {}),
575
+ createComponent(InterfaceMember, {
576
+ name: "color",
577
+ optional: true,
578
+ type: "boolean",
579
+ doc: "Whether to enable color output in the command. If not provided, color output will be enabled by default."
580
+ })
581
+ ];
582
+ }
583
+ }),
584
+ createComponent(Spacing, {}),
585
+ createComponent(TSDoc, {
586
+ heading: "Install the application dependencies.",
587
+ get children() {
588
+ return [
589
+ createComponent(TSDocRemarks, { children: `This function is used to install the application dependencies. It can be used in the CLI upgrade command to ensure that all necessary dependencies are installed.` }),
590
+ createComponent(Spacing, {}),
591
+ createComponent(TSDocParam, {
592
+ name: "options",
593
+ children: `The options for the \`install\` function. Currently, there are no options available, but this parameter is included for future extensibility.`
594
+ }),
595
+ createComponent(TSDocReturns, { children: `A promise that resolves when the installation of dependencies is complete.` })
596
+ ];
597
+ }
598
+ }),
599
+ createComponent(FunctionDeclaration, {
600
+ "export": true,
601
+ async: true,
602
+ name: "install",
603
+ parameters: [{
604
+ name: "options",
605
+ type: "InstallOptions",
606
+ default: "{}"
607
+ }],
608
+ returnType: "Promise<string>",
609
+ get children() {
610
+ return [
611
+ createComponent(VarDeclaration, {
612
+ "const": true,
613
+ name: "packageManager",
614
+ initializer: code`getPackageManager(); `
615
+ }),
616
+ createIntrinsic("hbr", {}),
617
+ createComponent(VarDeclaration, {
618
+ "let": true,
619
+ name: "output",
620
+ initializer: code`""; `
621
+ }),
622
+ createIntrinsic("hbr", {}),
623
+ code`try {
624
+ // await spawn(
625
+ // \`\${packageManager}\${isWindows && packageManager !== "bun" ? ".cmd" : ""}\`,
626
+ // ["install"],
627
+ // {
628
+ // stdout: (data: string) => {
629
+ // options.stdout?.(data);
630
+ // output += data;
631
+ // },
632
+ // stderr: (data: string) => {
633
+ // options.stderr?.(data);
634
+ // },
635
+ // },
636
+ // {
637
+ // cwd: options.cwd ?? process.cwd(),
638
+ // env: {
639
+ // ...process.env,
640
+ // ...(options.color !== false ? { FORCE_COLOR: true } : null),
641
+ // // With spawn, pnpm install will fail with ERR_PNPM_PEER_DEP_ISSUES Unmet peer dependencies.
642
+ // // When pnpm install is run directly from the terminal, this error does not occur.
643
+ // // When pnpm install is run from a simple spawn script, this error does not occur.
644
+ // // The issue only seems to be when pnpm install is executed from npm-check-updates, but it's not clear what configuration or environmental factors are causing this.
645
+ // // For now, turn off strict-peer-dependencies on pnpm auto-install.
646
+ // // See: https://github.com/raineorshine/npm-check-updates/issues/1191
647
+ // ...(packageManager === 'pnpm' ? { npm_config_strict_peer_dependencies: false } : null),
648
+ // },
649
+ // },
650
+ // );
651
+ } catch (err) {
652
+ console.error("Error executing install command:", err);
653
+ throw err;
654
+ }
655
+ `
656
+ ];
657
+ }
658
+ })
659
+ ];
660
+ }
661
+ /**
662
+ * A built-in upgrade module for Shell Shock.
663
+ */
664
+ function UpgradeBuiltin(props) {
665
+ const [{ children }, rest] = splitProps(props, ["children"]);
666
+ return createComponent(BuiltinFile, mergeProps({
667
+ id: "upgrade",
668
+ description: "A collection of application upgrade utility functions for Shell Shock."
669
+ }, rest, {
670
+ get imports() {
671
+ return defu(rest.imports ?? {}, {
672
+ "node:os": "os",
673
+ "node:path": ["join", "resolve"],
674
+ "node:fs": ["existsSync"],
675
+ "node:fs/promises": ["readFile", "writeFile"],
676
+ "node:process": "process"
677
+ });
678
+ },
679
+ get builtinImports() {
680
+ return defu(rest.builtinImports ?? {}, {
681
+ console: [
682
+ "error",
683
+ "verbose",
684
+ "writeLine"
685
+ ],
686
+ env: ["paths", "isWindows"]
687
+ });
688
+ },
689
+ get children() {
690
+ return [
691
+ createComponent(VarDeclaration, {
692
+ "const": true,
693
+ name: "homePath",
694
+ type: "string",
695
+ initializer: code`os.homedir(); `
696
+ }),
697
+ createComponent(Spacing, {}),
698
+ createComponent(VarDeclaration, {
699
+ "const": true,
700
+ name: "tempPath",
701
+ type: "string",
702
+ initializer: code`os.tmpdir(); `
703
+ }),
704
+ createComponent(Spacing, {}),
705
+ createComponent(LocateLockfileFunctionDeclaration, {}),
706
+ createComponent(Spacing, {}),
707
+ createComponent(GetPackageManagerFunctionDeclaration, {}),
708
+ createComponent(Spacing, {}),
709
+ createComponent(FetchNpmPackageFunctionDeclaration, {}),
710
+ createComponent(Spacing, {}),
711
+ createComponent(GetLatestFunctionDeclaration, {}),
712
+ createComponent(Spacing, {}),
713
+ createComponent(InstallFunctionDeclaration, {}),
714
+ createComponent(Spacing, {}),
715
+ createComponent(Show, {
716
+ get when() {
717
+ return Boolean(children);
718
+ },
719
+ children
720
+ })
721
+ ];
722
+ }
723
+ }));
724
+ }
725
+
726
+ //#endregion
727
+ export { FetchNpmPackageFunctionDeclaration, GetLatestFunctionDeclaration, GetPackageManagerFunctionDeclaration, InstallFunctionDeclaration, LocateLockfileFunctionDeclaration, LocatePackageJsonFunctionDeclaration, UpgradeBuiltin };
728
+ //# sourceMappingURL=upgrade-builtin.mjs.map