@shell-shock/plugin-upgrade 0.1.3 → 0.1.5

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.
@@ -19,18 +19,26 @@ declare function GetPackageManagerFunctionDeclaration(): _alloy_js_core0.Childre
19
19
  */
20
20
  declare function FetchNpmPackageFunctionDeclaration(): _alloy_js_core0.Children;
21
21
  /**
22
- * The `getLatest` handler function declaration code for the Shell Shock project.
22
+ * The `getLatestVersion` handler function declaration code for the Shell Shock project.
23
23
  */
24
- declare function GetLatestFunctionDeclaration(): _alloy_js_core0.Children;
24
+ declare function GetLatestVersionFunctionDeclaration(): _alloy_js_core0.Children;
25
25
  /**
26
- * The `install` handler function declaration code for the Shell Shock project.
26
+ * The `upgrade` handler function declaration code for the Shell Shock project.
27
27
  */
28
- declare function InstallFunctionDeclaration(): _alloy_js_core0.Children;
28
+ declare function GetUpgradeCommandFunctionDeclaration(): _alloy_js_core0.Children;
29
+ /**
30
+ * The `upgrade` handler function declaration code for the Shell Shock project.
31
+ */
32
+ declare function UpgradeFunctionDeclaration(): _alloy_js_core0.Children;
33
+ /**
34
+ * The `checkForUpdates` handler function declaration code for the Shell Shock project.
35
+ */
36
+ declare function CheckForUpdatesFunctionDeclaration(): _alloy_js_core0.Children;
29
37
  interface UpgradeBuiltinProps extends Omit<BuiltinFileProps, "id" | "description"> {}
30
38
  /**
31
39
  * A built-in upgrade module for Shell Shock.
32
40
  */
33
41
  declare function UpgradeBuiltin(props: UpgradeBuiltinProps): _alloy_js_core0.Children;
34
42
  //#endregion
35
- export { FetchNpmPackageFunctionDeclaration, GetLatestFunctionDeclaration, GetPackageManagerFunctionDeclaration, InstallFunctionDeclaration, LocateLockfileFunctionDeclaration, LocatePackageJsonFunctionDeclaration, UpgradeBuiltin, UpgradeBuiltinProps };
43
+ export { CheckForUpdatesFunctionDeclaration, FetchNpmPackageFunctionDeclaration, GetLatestVersionFunctionDeclaration, GetPackageManagerFunctionDeclaration, GetUpgradeCommandFunctionDeclaration, LocateLockfileFunctionDeclaration, LocatePackageJsonFunctionDeclaration, UpgradeBuiltin, UpgradeBuiltinProps, UpgradeFunctionDeclaration };
36
44
  //# sourceMappingURL=upgrade-builtin.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"upgrade-builtin.d.cts","names":[],"sources":["../../src/components/upgrade-builtin.tsx"],"sourcesContent":[],"mappings":";;;;;;;AA2CgB,iBAAA,oCAAA,CAAA,CAAoC,EAAA,eAAA,CAAA,QAAA;AAwEpD;AAwFA;AAyIA;AA6KgB,iBA9YA,iCAAA,CAAA,CA8Y4B,EA9YK,eAAA,CAAA,QA8YL;AAwC5C;AAmGA;AAQA;iBAzcgB,oCAAA,CAAA,GAAoC,eAAA,CAAA;;;;iBAyIpC,kCAAA,CAAA,GAAkC,eAAA,CAAA;;;;iBA6KlC,4BAAA,CAAA,GAA4B,eAAA,CAAA;;;;iBAwC5B,0BAAA,CAAA,GAA0B,eAAA,CAAA;UAmGzB,mBAAA,SAA4B,KAC3C;;;;iBAOc,cAAA,QAAsB,sBAAmB,eAAA,CAAA"}
1
+ {"version":3,"file":"upgrade-builtin.d.cts","names":[],"sources":["../../src/components/upgrade-builtin.tsx"],"sourcesContent":[],"mappings":";;;;;;;AA6CgB,iBAAA,oCAAA,CAAA,CAAoC,EAAA,eAAA,CAAA,QAAA;AAgGpD;AAuFA;AAkJA;AA6KgB,iBAtZA,iCAAA,CAAA,CAsZmC,EAtZF,eAAA,CAAA,QAsZE;AA2CnD;AAyEA;AAyFA;AAgIiB,iBA5oBD,oCAAA,CAAA,CA4oBiC,EA5oBG,eAAA,CAAA,QA4oBH;AAQjD;;;iBAlgBgB,kCAAA,CAAA,GAAkC,eAAA,CAAA;;;;iBA6KlC,mCAAA,CAAA,GAAmC,eAAA,CAAA;;;;iBA2CnC,oCAAA,CAAA,GAAoC,eAAA,CAAA;;;;iBAyEpC,0BAAA,CAAA,GAA0B,eAAA,CAAA;;;;iBAyF1B,kCAAA,CAAA,GAAkC,eAAA,CAAA;UAgIjC,mBAAA,SAA4B,KAC3C;;;;iBAOc,cAAA,QAAsB,sBAAmB,eAAA,CAAA"}
@@ -19,18 +19,26 @@ declare function GetPackageManagerFunctionDeclaration(): _alloy_js_core0.Childre
19
19
  */
20
20
  declare function FetchNpmPackageFunctionDeclaration(): _alloy_js_core0.Children;
21
21
  /**
22
- * The `getLatest` handler function declaration code for the Shell Shock project.
22
+ * The `getLatestVersion` handler function declaration code for the Shell Shock project.
23
23
  */
24
- declare function GetLatestFunctionDeclaration(): _alloy_js_core0.Children;
24
+ declare function GetLatestVersionFunctionDeclaration(): _alloy_js_core0.Children;
25
25
  /**
26
- * The `install` handler function declaration code for the Shell Shock project.
26
+ * The `upgrade` handler function declaration code for the Shell Shock project.
27
27
  */
28
- declare function InstallFunctionDeclaration(): _alloy_js_core0.Children;
28
+ declare function GetUpgradeCommandFunctionDeclaration(): _alloy_js_core0.Children;
29
+ /**
30
+ * The `upgrade` handler function declaration code for the Shell Shock project.
31
+ */
32
+ declare function UpgradeFunctionDeclaration(): _alloy_js_core0.Children;
33
+ /**
34
+ * The `checkForUpdates` handler function declaration code for the Shell Shock project.
35
+ */
36
+ declare function CheckForUpdatesFunctionDeclaration(): _alloy_js_core0.Children;
29
37
  interface UpgradeBuiltinProps extends Omit<BuiltinFileProps, "id" | "description"> {}
30
38
  /**
31
39
  * A built-in upgrade module for Shell Shock.
32
40
  */
33
41
  declare function UpgradeBuiltin(props: UpgradeBuiltinProps): _alloy_js_core0.Children;
34
42
  //#endregion
35
- export { FetchNpmPackageFunctionDeclaration, GetLatestFunctionDeclaration, GetPackageManagerFunctionDeclaration, InstallFunctionDeclaration, LocateLockfileFunctionDeclaration, LocatePackageJsonFunctionDeclaration, UpgradeBuiltin, UpgradeBuiltinProps };
43
+ export { CheckForUpdatesFunctionDeclaration, FetchNpmPackageFunctionDeclaration, GetLatestVersionFunctionDeclaration, GetPackageManagerFunctionDeclaration, GetUpgradeCommandFunctionDeclaration, LocateLockfileFunctionDeclaration, LocatePackageJsonFunctionDeclaration, UpgradeBuiltin, UpgradeBuiltinProps, UpgradeFunctionDeclaration };
36
44
  //# sourceMappingURL=upgrade-builtin.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"upgrade-builtin.d.mts","names":[],"sources":["../../src/components/upgrade-builtin.tsx"],"sourcesContent":[],"mappings":";;;;;;;AA2CgB,iBAAA,oCAAA,CAAA,CAAoC,EAAA,eAAA,CAAA,QAAA;AAwEpD;AAwFA;AAyIA;AA6KgB,iBA9YA,iCAAA,CAAA,CA8Y4B,EA9YK,eAAA,CAAA,QA8YL;AAwC5C;AAmGA;AAQA;iBAzcgB,oCAAA,CAAA,GAAoC,eAAA,CAAA;;;;iBAyIpC,kCAAA,CAAA,GAAkC,eAAA,CAAA;;;;iBA6KlC,4BAAA,CAAA,GAA4B,eAAA,CAAA;;;;iBAwC5B,0BAAA,CAAA,GAA0B,eAAA,CAAA;UAmGzB,mBAAA,SAA4B,KAC3C;;;;iBAOc,cAAA,QAAsB,sBAAmB,eAAA,CAAA"}
1
+ {"version":3,"file":"upgrade-builtin.d.mts","names":[],"sources":["../../src/components/upgrade-builtin.tsx"],"sourcesContent":[],"mappings":";;;;;;;AA6CgB,iBAAA,oCAAA,CAAA,CAAoC,EAAA,eAAA,CAAA,QAAA;AAgGpD;AAuFA;AAkJA;AA6KgB,iBAtZA,iCAAA,CAAA,CAsZmC,EAtZF,eAAA,CAAA,QAsZE;AA2CnD;AAyEA;AAyFA;AAgIiB,iBA5oBD,oCAAA,CAAA,CA4oBiC,EA5oBG,eAAA,CAAA,QA4oBH;AAQjD;;;iBAlgBgB,kCAAA,CAAA,GAAkC,eAAA,CAAA;;;;iBA6KlC,mCAAA,CAAA,GAAmC,eAAA,CAAA;;;;iBA2CnC,oCAAA,CAAA,GAAoC,eAAA,CAAA;;;;iBAyEpC,0BAAA,CAAA,GAA0B,eAAA,CAAA;;;;iBAyF1B,kCAAA,CAAA,GAAkC,eAAA,CAAA;UAgIjC,mBAAA,SAA4B,KAC3C;;;;iBAOc,cAAA,QAAsB,sBAAmB,eAAA,CAAA"}
@@ -1,28 +1,39 @@
1
- import { createComponent, createIntrinsic, mergeProps } from "@alloy-js/core/jsx-runtime";
1
+ import { createComponent, createIntrinsic, memo, mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import defu from "defu";
2
3
  import { Show, code, splitProps } from "@alloy-js/core";
3
4
  import { ElseClause, ElseIfClause, FunctionDeclaration, IfStatement, InterfaceDeclaration, VarDeclaration } from "@alloy-js/typescript";
4
5
  import { Spacing } from "@powerlines/plugin-alloy/core/components/spacing";
6
+ import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
5
7
  import { InterfaceMember, TSDoc, TSDocParam, TSDocRemarks, TSDocReturns, TypeDeclaration } from "@powerlines/plugin-alloy/typescript";
6
8
  import { BuiltinFile } from "@powerlines/plugin-alloy/typescript/components/builtin-file";
7
- import defu from "defu";
8
9
 
9
10
  //#region src/components/upgrade-builtin.tsx
10
11
  /**
11
12
  * The `locatePackageJson` handler function declaration code for the Shell Shock project.
12
13
  */
13
14
  function LocatePackageJsonFunctionDeclaration() {
15
+ const context = usePowerlines();
14
16
  return [
15
17
  createComponent(InterfaceDeclaration, {
16
18
  "export": true,
17
19
  name: "LocatePackageJsonOptions",
18
20
  doc: "Options for the `locatePackageJson` handler function.",
19
21
  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
- });
22
+ return [
23
+ createComponent(InterfaceMember, {
24
+ name: "cwd",
25
+ optional: true,
26
+ type: "string",
27
+ doc: "The current working directory to use. If not provided, the process's current working directory will be used."
28
+ }),
29
+ createComponent(Spacing, {}),
30
+ createComponent(InterfaceMember, {
31
+ name: "isDependencyRequired",
32
+ optional: true,
33
+ type: "boolean",
34
+ doc: "Whether to only locate a package.json file if it contains the application as a dependency. If set to `true`, the function will check if the located package.json file has the application listed as a dependency in its dependencies, devDependencies, peerDependencies, or optionalDependencies before returning its path. This can be useful in monorepo setups where multiple package.json files may exist, but only the one that includes the application as a dependency is relevant for upgrade purposes."
35
+ })
36
+ ];
26
37
  }
27
38
  }),
28
39
  createComponent(Spacing, {}),
@@ -66,11 +77,32 @@ function LocatePackageJsonFunctionDeclaration() {
66
77
  }),
67
78
  createComponent(Spacing, {}),
68
79
  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"); `
80
+ createComponent(VarDeclaration, {
81
+ "const": true,
82
+ name: "packageJsonPath",
83
+ initializer: code`join(currentPath, "package.json"); `
72
84
  }),
73
- createComponent(ElseClause, { children: code`currentPath = pathParent;
85
+ createComponent(IfStatement, {
86
+ condition: code`existsSync(packageJsonPath)`,
87
+ get children() {
88
+ return [createComponent(IfStatement, {
89
+ condition: code`options.isDependencyRequired`,
90
+ get children() {
91
+ return [createComponent(VarDeclaration, {
92
+ "const": true,
93
+ name: "packageJson",
94
+ initializer: code`JSON.parse(await readFile(packageJsonPath, "utf8")); `
95
+ }), createComponent(IfStatement, {
96
+ get condition() {
97
+ return code`Object.keys(packageJson.dependencies || {}).concat(Object.keys(packageJson.devDependencies || {})).concat(Object.keys(packageJson.peerDependencies || {})).concat(Object.keys(packageJson.optionalDependencies || {})).some(dep => dep === "${context.packageJson.name}" || dep.startsWith("${context.packageJson.name}@"))`;
98
+ },
99
+ children: code`return packageJsonPath; `
100
+ })];
101
+ }
102
+ }), createComponent(ElseClause, { children: code`return packageJsonPath; ` })];
103
+ }
104
+ }),
105
+ createComponent(ElseClause, { children: code`currentPath = parentPath;
74
106
  parentPath = resolve(currentPath, ".."); ` }),
75
107
  code` }
76
108
 
@@ -115,7 +147,6 @@ function LocateLockfileFunctionDeclaration() {
115
147
  }),
116
148
  createComponent(FunctionDeclaration, {
117
149
  "export": true,
118
- async: true,
119
150
  name: "locateLockfile",
120
151
  parameters: [{
121
152
  name: "options",
@@ -160,7 +191,7 @@ function LocateLockfileFunctionDeclaration() {
160
191
  condition: code`lockfile`,
161
192
  children: code`return lockfile; `
162
193
  }),
163
- createComponent(ElseClause, { children: code`currentPath = pathParent;
194
+ createComponent(ElseClause, { children: code`currentPath = parentPath;
164
195
  parentPath = resolve(currentPath, ".."); ` }),
165
196
  code` }
166
197
 
@@ -175,6 +206,15 @@ function LocateLockfileFunctionDeclaration() {
175
206
  */
176
207
  function GetPackageManagerFunctionDeclaration() {
177
208
  return [
209
+ code`declare global {
210
+ var Bun: any;
211
+ namespace NodeJS {
212
+ interface ProcessVersions {
213
+ bun?: string;
214
+ }
215
+ }
216
+ } `,
217
+ createComponent(Spacing, {}),
178
218
  createComponent(TypeDeclaration, {
179
219
  "export": true,
180
220
  name: "GetPackageManagerOptions",
@@ -263,7 +303,7 @@ function GetPackageManagerFunctionDeclaration() {
263
303
  createComponent(VarDeclaration, {
264
304
  "const": true,
265
305
  name: "packageJsonPath",
266
- initializer: code`locatePackageJson(options); `
306
+ initializer: code`await locatePackageJson(options); `
267
307
  }),
268
308
  createComponent(IfStatement, {
269
309
  condition: code`packageJsonPath && existsSync(packageJsonPath)`,
@@ -510,9 +550,10 @@ function FetchNpmPackageFunctionDeclaration() {
510
550
  ];
511
551
  }
512
552
  /**
513
- * The `getLatest` handler function declaration code for the Shell Shock project.
553
+ * The `getLatestVersion` handler function declaration code for the Shell Shock project.
514
554
  */
515
- function GetLatestFunctionDeclaration() {
555
+ function GetLatestVersionFunctionDeclaration() {
556
+ const context = usePowerlines();
516
557
  return [createComponent(TSDoc, {
517
558
  heading: "Get the latest version of the application from the npm registry.",
518
559
  get children() {
@@ -529,89 +570,172 @@ function GetLatestFunctionDeclaration() {
529
570
  }), createComponent(FunctionDeclaration, {
530
571
  "export": true,
531
572
  async: true,
532
- name: "getLatest",
573
+ name: "getLatestVersion",
574
+ get parameters() {
575
+ return [{
576
+ name: "packageName",
577
+ default: `"${context.packageJson.name}"`
578
+ }];
579
+ },
580
+ returnType: code`Promise<string | undefined>`,
581
+ get children() {
582
+ return [
583
+ createComponent(VarDeclaration, {
584
+ "const": true,
585
+ name: "result",
586
+ initializer: code`await fetchNpmPackage(packageName); `
587
+ }),
588
+ createComponent(Spacing, {}),
589
+ code`return result?.version; `
590
+ ];
591
+ }
592
+ })];
593
+ }
594
+ /**
595
+ * The `upgrade` handler function declaration code for the Shell Shock project.
596
+ */
597
+ function GetUpgradeCommandFunctionDeclaration() {
598
+ const context = usePowerlines();
599
+ return [createComponent(TSDoc, {
600
+ heading: "A function to get the upgrade command for a specific package manager.",
601
+ get children() {
602
+ return [
603
+ createComponent(TSDocRemarks, { children: `This function is used to get the appropriate upgrade command for a specific package manager. It can be used in the CLI upgrade command to determine which command to run based on the package manager being used by the application.` }),
604
+ createComponent(Spacing, {}),
605
+ createComponent(TSDocParam, {
606
+ name: "packageManager",
607
+ children: `The name of the package manager to get the upgrade command for. This should be one of "npm", "yarn", "pnpm", "deno", or "bun".`
608
+ }),
609
+ createComponent(TSDocParam, {
610
+ name: "cwd",
611
+ children: `The current working directory to use when determining the upgrade command. This can be used to locate the appropriate package.json and lockfile to determine how to run the upgrade command. If not provided, the process's current working directory will be used.`
612
+ }),
613
+ createComponent(TSDocReturns, { children: `An array of strings representing the command and its arguments to run in order to upgrade the application dependencies using the specified package manager.` })
614
+ ];
615
+ }
616
+ }), createComponent(FunctionDeclaration, {
617
+ "export": true,
618
+ async: true,
619
+ name: "getUpgradeCommand",
533
620
  parameters: [{
534
- name: "packageName",
621
+ name: "packageManager",
535
622
  type: "string"
623
+ }, {
624
+ name: "cwd",
625
+ type: "string",
626
+ default: "process.cwd()"
536
627
  }],
628
+ returnType: "Promise<string[]>",
537
629
  get children() {
538
630
  return [
539
631
  createComponent(VarDeclaration, {
540
632
  "const": true,
541
- name: "package",
542
- initializer: code`await fetchNpmPackage(packageName); `
633
+ name: "version",
634
+ get initializer() {
635
+ return code`(await getLatestVersion("${context.packageJson.name}")) || "latest"; `;
636
+ }
543
637
  }),
544
638
  createComponent(Spacing, {}),
545
- code`return package?.version; `
639
+ createComponent(IfStatement, {
640
+ condition: code`packageManager === "yarn"`,
641
+ get children() {
642
+ return code`return ["upgrade", \`${context.packageJson.name}@\${version}\`]; `;
643
+ }
644
+ }),
645
+ createComponent(ElseIfClause, {
646
+ condition: code`packageManager === "pnpm"`,
647
+ get children() {
648
+ return code`return ["update", \`${context.packageJson.name}@\${version}\`]; `;
649
+ }
650
+ }),
651
+ createComponent(ElseIfClause, {
652
+ condition: code`packageManager === "deno"`,
653
+ get children() {
654
+ return code`return ["outdated", "--update", \`${context.packageJson.name}@\${version}\`]; `;
655
+ }
656
+ }),
657
+ createComponent(ElseIfClause, {
658
+ condition: code`packageManager === "bun"`,
659
+ get children() {
660
+ return code`return ["update", "--save", \`${context.packageJson.name}@\${version}\`]; `;
661
+ }
662
+ }),
663
+ createComponent(ElseClause, { get children() {
664
+ return code`return ["update", "--save", "--bin-links", \`${context.packageJson.name}@\${version}\`]; `;
665
+ } })
546
666
  ];
547
667
  }
548
668
  })];
549
669
  }
550
670
  /**
551
- * The `install` handler function declaration code for the Shell Shock project.
671
+ * The `upgrade` handler function declaration code for the Shell Shock project.
552
672
  */
553
- function InstallFunctionDeclaration() {
673
+ function UpgradeFunctionDeclaration() {
554
674
  return [
555
675
  createComponent(InterfaceDeclaration, {
556
- "export": true,
557
- name: "InstallOptions",
558
- doc: "Options for the `install` handler function.",
676
+ name: "UpgradeBaseOptions",
677
+ doc: "Options for the `upgrade` handler function.",
559
678
  get children() {
560
679
  return [
561
680
  createComponent(InterfaceMember, {
562
681
  name: "stdout",
563
682
  optional: true,
564
- type: "(string) => void",
683
+ type: "(data: string) => void",
565
684
  doc: "A callback function that is called with the stdout output of the command."
566
685
  }),
567
686
  createIntrinsic("hbr", {}),
568
687
  createComponent(InterfaceMember, {
569
688
  name: "stderr",
570
689
  optional: true,
571
- type: "(string) => void",
690
+ type: "(err: string) => void",
572
691
  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
692
  })
581
693
  ];
582
694
  }
583
695
  }),
584
696
  createComponent(Spacing, {}),
697
+ createComponent(TypeDeclaration, {
698
+ "export": true,
699
+ name: "UpgradeOptions",
700
+ doc: "Options for the `upgrade` handler function.",
701
+ children: code`UpgradeBaseOptions & GetPackageManagerOptions & Parameters<typeof spawn>[2];`
702
+ }),
703
+ createComponent(Spacing, {}),
585
704
  createComponent(TSDoc, {
586
- heading: "Install the application dependencies.",
705
+ heading: "Upgrade the application dependencies.",
587
706
  get children() {
588
707
  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.` }),
708
+ createComponent(TSDocRemarks, { children: `This function is used to upgrade the application dependencies. It can be used in the CLI upgrade command to ensure that all necessary dependencies are up-to-date.` }),
590
709
  createComponent(Spacing, {}),
591
710
  createComponent(TSDocParam, {
592
711
  name: "options",
593
- children: `The options for the \`install\` function. Currently, there are no options available, but this parameter is included for future extensibility.`
712
+ children: `The options for the \`upgrade\` function. Currently, there are no options available, but this parameter is included for future extensibility.`
594
713
  }),
595
- createComponent(TSDocReturns, { children: `A promise that resolves when the installation of dependencies is complete.` })
714
+ createComponent(TSDocReturns, { children: `A promise that resolves when the upgrade of dependencies is complete.` })
596
715
  ];
597
716
  }
598
717
  }),
599
718
  createComponent(FunctionDeclaration, {
600
719
  "export": true,
601
720
  async: true,
602
- name: "install",
721
+ name: "upgrade",
603
722
  parameters: [{
604
723
  name: "options",
605
- type: "InstallOptions",
724
+ type: "UpgradeOptions",
606
725
  default: "{}"
607
726
  }],
608
- returnType: "Promise<string>",
609
727
  get children() {
610
728
  return [
611
729
  createComponent(VarDeclaration, {
612
730
  "const": true,
613
731
  name: "packageManager",
614
- initializer: code`getPackageManager(); `
732
+ initializer: code`await getPackageManager(options); `
733
+ }),
734
+ createComponent(Spacing, {}),
735
+ createComponent(VarDeclaration, {
736
+ "const": true,
737
+ name: "args",
738
+ initializer: code`await getUpgradeCommand(packageManager, options.cwd); `
615
739
  }),
616
740
  createIntrinsic("hbr", {}),
617
741
  createComponent(VarDeclaration, {
@@ -620,39 +744,165 @@ function InstallFunctionDeclaration() {
620
744
  initializer: code`""; `
621
745
  }),
622
746
  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
- `
747
+ code`await spawn(
748
+ \`\${packageManager}\${isWindows && packageManager !== "bun" ? ".cmd" : ""}\`,
749
+ [args.join(" ")],
750
+ {
751
+ ...options,
752
+ env: {
753
+ ...options.env,
754
+ ...(packageManager === "pnpm" ? { npm_config_strict_peer_dependencies: false } : null),
755
+ },
756
+ stdout: (data: string) => {
757
+ options.stdout?.(data);
758
+ output += data;
759
+ },
760
+ stderr: (data: string) => {
761
+ options.stderr?.(data);
762
+ },
763
+ },
764
+ ); `
765
+ ];
766
+ }
767
+ })
768
+ ];
769
+ }
770
+ /**
771
+ * The `checkForUpdates` handler function declaration code for the Shell Shock project.
772
+ */
773
+ function CheckForUpdatesFunctionDeclaration() {
774
+ const context = usePowerlines();
775
+ return [
776
+ createComponent(InterfaceDeclaration, {
777
+ "export": true,
778
+ name: "CheckForUpdatesOptions",
779
+ "extends": "GetPackageManagerOptions",
780
+ doc: "Options for the `checkForUpdates` handler function."
781
+ }),
782
+ createComponent(Spacing, {}),
783
+ createComponent(InterfaceDeclaration, {
784
+ "export": true,
785
+ name: "CheckForUpdatesResult",
786
+ doc: "The result for the `checkForUpdates` handler function.",
787
+ get children() {
788
+ return [
789
+ createComponent(InterfaceMember, {
790
+ name: "latestVersion",
791
+ type: "string",
792
+ doc: "The latest version of the application dependencies."
793
+ }),
794
+ createIntrinsic("hbr", {}),
795
+ createComponent(InterfaceMember, {
796
+ name: "currentVersion",
797
+ type: "string",
798
+ doc: "The current version of the application dependencies."
799
+ }),
800
+ createIntrinsic("hbr", {}),
801
+ createComponent(InterfaceMember, {
802
+ name: "isUpToDate",
803
+ type: "boolean",
804
+ doc: "Indicates whether the application dependencies are up-to-date."
805
+ }),
806
+ createIntrinsic("hbr", {}),
807
+ createComponent(InterfaceMember, {
808
+ name: "package",
809
+ type: "NpmPackage",
810
+ doc: "The npm package that was checked for updates."
811
+ }),
812
+ createIntrinsic("hbr", {}),
813
+ createComponent(InterfaceMember, {
814
+ name: "packageManager",
815
+ type: "'npm' | 'yarn' | 'pnpm' | 'deno' | 'bun'",
816
+ doc: "The package manager used to check for updates."
817
+ })
818
+ ];
819
+ }
820
+ }),
821
+ createComponent(Spacing, {}),
822
+ createComponent(TSDoc, {
823
+ heading: "Check for updates to the application dependencies.",
824
+ get children() {
825
+ return [
826
+ createComponent(TSDocRemarks, { children: `This function is used to check for updates to the application dependencies. It can be used in the CLI upgrade command to ensure that all necessary dependencies are up-to-date.` }),
827
+ createComponent(Spacing, {}),
828
+ createComponent(TSDocParam, {
829
+ name: "options",
830
+ children: `The options for the \`checkForUpdates\` function. Currently, there are no options available, but this parameter is included for future extensibility.`
831
+ }),
832
+ createComponent(TSDocReturns, { children: `A promise that resolves when the check for updates is complete or undefined if the check was not performed.` })
833
+ ];
834
+ }
835
+ }),
836
+ createComponent(FunctionDeclaration, {
837
+ "export": true,
838
+ async: true,
839
+ name: "checkForUpdates",
840
+ parameters: [{
841
+ name: "options",
842
+ type: "CheckForUpdatesOptions",
843
+ default: "{}"
844
+ }],
845
+ returnType: "Promise<CheckForUpdatesResult | undefined>",
846
+ get children() {
847
+ return [
848
+ createComponent(VarDeclaration, {
849
+ "const": true,
850
+ name: "filePath",
851
+ initializer: code`join(paths.data, "version-check.json"); `
852
+ }),
853
+ createComponent(IfStatement, {
854
+ condition: code`existsSync(filePath)`,
855
+ get children() {
856
+ return [
857
+ createComponent(VarDeclaration, {
858
+ "const": true,
859
+ name: "file",
860
+ type: "{ timestamp: number; }",
861
+ initializer: code` JSON.parse(await readFile(filePath, "utf8")); `
862
+ }),
863
+ createComponent(IfStatement, {
864
+ condition: code`!file.timestamp`,
865
+ children: code`await writeFile(filePath, JSON.stringify({ timestamp: new Date().getTime() }), "utf8");
866
+ return undefined; `
867
+ }),
868
+ createComponent(ElseIfClause, {
869
+ get condition() {
870
+ return code`new Date().getTime() - file.timestamp < ${context.config.upgrade.staleTime}`;
871
+ },
872
+ children: code`return undefined; `
873
+ })
874
+ ];
875
+ }
876
+ }),
877
+ createComponent(ElseClause, { children: code`await writeFile(filePath, JSON.stringify({ timestamp: new Date().getTime() }), "utf8");
878
+ return undefined; ` }),
879
+ createComponent(Spacing, {}),
880
+ createComponent(VarDeclaration, {
881
+ "const": true,
882
+ name: "packageManager",
883
+ initializer: code`await getPackageManager(options); `
884
+ }),
885
+ createComponent(Spacing, {}),
886
+ createComponent(VarDeclaration, {
887
+ "const": true,
888
+ name: "pkg",
889
+ initializer: code`await fetchNpmPackage(); `
890
+ }),
891
+ createComponent(Spacing, {}),
892
+ createComponent(IfStatement, {
893
+ condition: code`!pkg`,
894
+ children: code`return undefined; `
895
+ }),
896
+ createComponent(Spacing, {}),
897
+ memo(() => code`await writeFile(filePath, JSON.stringify({ timestamp: new Date().getTime() }), "utf8");
898
+
899
+ return {
900
+ latestVersion: pkg?.version ?? "0.0.0",
901
+ currentVersion: "${context.packageJson.version}",
902
+ isUpToDate: pkg ? "${context.packageJson.version}" === pkg.version : true,
903
+ package: pkg,
904
+ packageManager,
905
+ }; `)
656
906
  ];
657
907
  }
658
908
  })
@@ -683,7 +933,8 @@ function UpgradeBuiltin(props) {
683
933
  "verbose",
684
934
  "writeLine"
685
935
  ],
686
- env: ["paths", "isWindows"]
936
+ env: ["paths", "isWindows"],
937
+ utils: ["isColorSupported", "spawn"]
687
938
  });
688
939
  },
689
940
  get children() {
@@ -702,15 +953,21 @@ function UpgradeBuiltin(props) {
702
953
  initializer: code`os.tmpdir(); `
703
954
  }),
704
955
  createComponent(Spacing, {}),
956
+ createComponent(LocatePackageJsonFunctionDeclaration, {}),
957
+ createComponent(Spacing, {}),
705
958
  createComponent(LocateLockfileFunctionDeclaration, {}),
706
959
  createComponent(Spacing, {}),
707
960
  createComponent(GetPackageManagerFunctionDeclaration, {}),
708
961
  createComponent(Spacing, {}),
709
962
  createComponent(FetchNpmPackageFunctionDeclaration, {}),
710
963
  createComponent(Spacing, {}),
711
- createComponent(GetLatestFunctionDeclaration, {}),
964
+ createComponent(GetLatestVersionFunctionDeclaration, {}),
965
+ createComponent(Spacing, {}),
966
+ createComponent(GetUpgradeCommandFunctionDeclaration, {}),
967
+ createComponent(Spacing, {}),
968
+ createComponent(UpgradeFunctionDeclaration, {}),
712
969
  createComponent(Spacing, {}),
713
- createComponent(InstallFunctionDeclaration, {}),
970
+ createComponent(CheckForUpdatesFunctionDeclaration, {}),
714
971
  createComponent(Spacing, {}),
715
972
  createComponent(Show, {
716
973
  get when() {
@@ -724,5 +981,5 @@ function UpgradeBuiltin(props) {
724
981
  }
725
982
 
726
983
  //#endregion
727
- export { FetchNpmPackageFunctionDeclaration, GetLatestFunctionDeclaration, GetPackageManagerFunctionDeclaration, InstallFunctionDeclaration, LocateLockfileFunctionDeclaration, LocatePackageJsonFunctionDeclaration, UpgradeBuiltin };
984
+ export { CheckForUpdatesFunctionDeclaration, FetchNpmPackageFunctionDeclaration, GetLatestVersionFunctionDeclaration, GetPackageManagerFunctionDeclaration, GetUpgradeCommandFunctionDeclaration, LocateLockfileFunctionDeclaration, LocatePackageJsonFunctionDeclaration, UpgradeBuiltin, UpgradeFunctionDeclaration };
728
985
  //# sourceMappingURL=upgrade-builtin.mjs.map