@shell-shock/plugin-upgrade 0.1.4 → 0.1.6
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.
- package/dist/components/index.cjs +7 -3
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.mts +2 -2
- package/dist/components/index.mjs +2 -2
- package/dist/components/upgrade-builtin.cjs +436 -49
- package/dist/components/upgrade-builtin.d.cts +21 -5
- package/dist/components/upgrade-builtin.d.cts.map +1 -1
- package/dist/components/upgrade-builtin.d.mts +21 -5
- package/dist/components/upgrade-builtin.d.mts.map +1 -1
- package/dist/components/upgrade-builtin.mjs +430 -47
- package/dist/components/upgrade-builtin.mjs.map +1 -1
- package/dist/components/upgrade-command.cjs +1 -1
- package/dist/components/upgrade-command.d.cts +2 -2
- package/dist/components/upgrade-command.mjs +1 -1
- package/dist/index.cjs +12 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +11 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types/env.cjs +0 -0
- package/dist/types/env.d.cts +14 -0
- package/dist/types/env.d.cts.map +1 -0
- package/dist/types/env.d.mts +14 -0
- package/dist/types/env.d.mts.map +1 -0
- package/dist/types/env.mjs +1 -0
- package/dist/types/package-manager.d.cts.map +1 -1
- package/dist/types/plugin.d.cts +6 -4
- package/dist/types/plugin.d.cts.map +1 -1
- package/dist/types/plugin.d.mts +6 -4
- package/dist/types/plugin.d.mts.map +1 -1
- package/package.json +22 -8
|
@@ -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
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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) { `,
|
|
80
|
+
createComponent(VarDeclaration, {
|
|
81
|
+
"const": true,
|
|
82
|
+
name: "packageJsonPath",
|
|
83
|
+
initializer: code`join(currentPath, "package.json"); `
|
|
84
|
+
}),
|
|
69
85
|
createComponent(IfStatement, {
|
|
70
|
-
condition: code`existsSync(
|
|
71
|
-
children
|
|
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
|
+
}
|
|
72
104
|
}),
|
|
73
|
-
createComponent(ElseClause, { children: code`currentPath =
|
|
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 =
|
|
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",
|
|
@@ -205,7 +245,7 @@ function GetPackageManagerFunctionDeclaration() {
|
|
|
205
245
|
type: "GetPackageManagerOptions",
|
|
206
246
|
default: "{}"
|
|
207
247
|
}],
|
|
208
|
-
returnType: code`
|
|
248
|
+
returnType: code`"npm" | "yarn" | "deno" | "pnpm" | "bun"`,
|
|
209
249
|
get children() {
|
|
210
250
|
return [
|
|
211
251
|
createComponent(VarDeclaration, {
|
|
@@ -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)`,
|
|
@@ -490,7 +530,7 @@ function FetchNpmPackageFunctionDeclaration() {
|
|
|
490
530
|
name: "packageName",
|
|
491
531
|
type: "string"
|
|
492
532
|
}],
|
|
493
|
-
returnType: code`
|
|
533
|
+
returnType: code`NpmPackage | undefined`,
|
|
494
534
|
get children() {
|
|
495
535
|
return [
|
|
496
536
|
createComponent(VarDeclaration, {
|
|
@@ -510,9 +550,10 @@ function FetchNpmPackageFunctionDeclaration() {
|
|
|
510
550
|
];
|
|
511
551
|
}
|
|
512
552
|
/**
|
|
513
|
-
* The `
|
|
553
|
+
* The `getLatestVersion` handler function declaration code for the Shell Shock project.
|
|
514
554
|
*/
|
|
515
|
-
function
|
|
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,45 +570,124 @@ function GetLatestFunctionDeclaration() {
|
|
|
529
570
|
}), createComponent(FunctionDeclaration, {
|
|
530
571
|
"export": true,
|
|
531
572
|
async: true,
|
|
532
|
-
name: "
|
|
573
|
+
name: "getLatestVersion",
|
|
574
|
+
get parameters() {
|
|
575
|
+
return [{
|
|
576
|
+
name: "packageName",
|
|
577
|
+
default: `"${context.packageJson.name}"`
|
|
578
|
+
}];
|
|
579
|
+
},
|
|
580
|
+
returnType: code`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: "
|
|
621
|
+
name: "packageManager",
|
|
535
622
|
type: "string"
|
|
623
|
+
}, {
|
|
624
|
+
name: "cwd",
|
|
625
|
+
type: "string",
|
|
626
|
+
default: "process.cwd()"
|
|
536
627
|
}],
|
|
628
|
+
returnType: "string[]",
|
|
537
629
|
get children() {
|
|
538
630
|
return [
|
|
539
631
|
createComponent(VarDeclaration, {
|
|
540
632
|
"const": true,
|
|
541
|
-
name: "
|
|
542
|
-
initializer
|
|
633
|
+
name: "version",
|
|
634
|
+
get initializer() {
|
|
635
|
+
return code`(await getLatestVersion("${context.packageJson.name}")) || "latest"; `;
|
|
636
|
+
}
|
|
543
637
|
}),
|
|
544
638
|
createComponent(Spacing, {}),
|
|
545
|
-
|
|
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 `
|
|
671
|
+
* The `upgrade` handler function declaration code for the Shell Shock project.
|
|
552
672
|
*/
|
|
553
|
-
function
|
|
673
|
+
function UpgradeFunctionDeclaration() {
|
|
554
674
|
return [
|
|
555
675
|
createComponent(InterfaceDeclaration, {
|
|
556
|
-
name: "
|
|
557
|
-
doc: "Options for the `
|
|
676
|
+
name: "UpgradeBaseOptions",
|
|
677
|
+
doc: "Options for the `upgrade` handler function.",
|
|
558
678
|
get children() {
|
|
559
679
|
return [
|
|
560
680
|
createComponent(InterfaceMember, {
|
|
561
681
|
name: "stdout",
|
|
562
682
|
optional: true,
|
|
563
|
-
type: "(string) => void",
|
|
683
|
+
type: "(data: string) => void",
|
|
564
684
|
doc: "A callback function that is called with the stdout output of the command."
|
|
565
685
|
}),
|
|
566
686
|
createIntrinsic("hbr", {}),
|
|
567
687
|
createComponent(InterfaceMember, {
|
|
568
688
|
name: "stderr",
|
|
569
689
|
optional: true,
|
|
570
|
-
type: "(string) => void",
|
|
690
|
+
type: "(err: string) => void",
|
|
571
691
|
doc: "A callback function that is called with the stderr output of the command."
|
|
572
692
|
})
|
|
573
693
|
];
|
|
@@ -576,32 +696,32 @@ function InstallFunctionDeclaration() {
|
|
|
576
696
|
createComponent(Spacing, {}),
|
|
577
697
|
createComponent(TypeDeclaration, {
|
|
578
698
|
"export": true,
|
|
579
|
-
name: "
|
|
580
|
-
doc: "Options for the `
|
|
581
|
-
children: code`
|
|
699
|
+
name: "UpgradeOptions",
|
|
700
|
+
doc: "Options for the `upgrade` handler function.",
|
|
701
|
+
children: code`UpgradeBaseOptions & GetPackageManagerOptions & Parameters<typeof spawn>[2];`
|
|
582
702
|
}),
|
|
583
703
|
createComponent(Spacing, {}),
|
|
584
704
|
createComponent(TSDoc, {
|
|
585
|
-
heading: "
|
|
705
|
+
heading: "Upgrade the application dependencies.",
|
|
586
706
|
get children() {
|
|
587
707
|
return [
|
|
588
|
-
createComponent(TSDocRemarks, { children: `This function is used to
|
|
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.` }),
|
|
589
709
|
createComponent(Spacing, {}),
|
|
590
710
|
createComponent(TSDocParam, {
|
|
591
711
|
name: "options",
|
|
592
|
-
children: `The options for the \`
|
|
712
|
+
children: `The options for the \`upgrade\` function. Currently, there are no options available, but this parameter is included for future extensibility.`
|
|
593
713
|
}),
|
|
594
|
-
createComponent(TSDocReturns, { children: `A promise that resolves when the
|
|
714
|
+
createComponent(TSDocReturns, { children: `A promise that resolves when the upgrade of dependencies is complete.` })
|
|
595
715
|
];
|
|
596
716
|
}
|
|
597
717
|
}),
|
|
598
718
|
createComponent(FunctionDeclaration, {
|
|
599
719
|
"export": true,
|
|
600
720
|
async: true,
|
|
601
|
-
name: "
|
|
721
|
+
name: "upgrade",
|
|
602
722
|
parameters: [{
|
|
603
723
|
name: "options",
|
|
604
|
-
type: "
|
|
724
|
+
type: "UpgradeOptions",
|
|
605
725
|
default: "{}"
|
|
606
726
|
}],
|
|
607
727
|
get children() {
|
|
@@ -609,9 +729,15 @@ function InstallFunctionDeclaration() {
|
|
|
609
729
|
createComponent(VarDeclaration, {
|
|
610
730
|
"const": true,
|
|
611
731
|
name: "packageManager",
|
|
612
|
-
initializer: code`getPackageManager(); `
|
|
732
|
+
initializer: code`await getPackageManager(options); `
|
|
613
733
|
}),
|
|
614
734
|
createComponent(Spacing, {}),
|
|
735
|
+
createComponent(VarDeclaration, {
|
|
736
|
+
"const": true,
|
|
737
|
+
name: "args",
|
|
738
|
+
initializer: code`await getUpgradeCommand(packageManager, options.cwd); `
|
|
739
|
+
}),
|
|
740
|
+
createIntrinsic("hbr", {}),
|
|
615
741
|
createComponent(VarDeclaration, {
|
|
616
742
|
"let": true,
|
|
617
743
|
name: "output",
|
|
@@ -620,9 +746,9 @@ function InstallFunctionDeclaration() {
|
|
|
620
746
|
createIntrinsic("hbr", {}),
|
|
621
747
|
code`await spawn(
|
|
622
748
|
\`\${packageManager}\${isWindows && packageManager !== "bun" ? ".cmd" : ""}\`,
|
|
623
|
-
["
|
|
749
|
+
[args.join(" ")],
|
|
624
750
|
{
|
|
625
|
-
...options
|
|
751
|
+
...options,
|
|
626
752
|
env: {
|
|
627
753
|
...options.env,
|
|
628
754
|
...(packageManager === "pnpm" ? { npm_config_strict_peer_dependencies: false } : null),
|
|
@@ -642,6 +768,240 @@ function InstallFunctionDeclaration() {
|
|
|
642
768
|
];
|
|
643
769
|
}
|
|
644
770
|
/**
|
|
771
|
+
* The `updateVersionCheckFile` handler function declaration code for the Shell Shock project.
|
|
772
|
+
*/
|
|
773
|
+
function UpdateVersionCheckFileFunctionDeclaration() {
|
|
774
|
+
return [createComponent(TSDoc, {
|
|
775
|
+
heading: "A helper function that updates the version check file.",
|
|
776
|
+
get children() {
|
|
777
|
+
return [
|
|
778
|
+
createComponent(TSDocRemarks, { children: `This function is used to update the version check file with the current timestamp. It can be used in the CLI upgrade command to record the last time a check for updates was performed. The function writes a "version-check.json" file in the data directory, which contains a timestamp of the last check for updates.` }),
|
|
779
|
+
createComponent(Spacing, {}),
|
|
780
|
+
createComponent(TSDocReturns, { children: `A promise that resolves to a boolean indicating whether a check for updates is required.` })
|
|
781
|
+
];
|
|
782
|
+
}
|
|
783
|
+
}), createComponent(FunctionDeclaration, {
|
|
784
|
+
"export": true,
|
|
785
|
+
async: true,
|
|
786
|
+
name: "updateVersionCheckFile",
|
|
787
|
+
returnType: "void",
|
|
788
|
+
get children() {
|
|
789
|
+
return [createComponent(IfStatement, {
|
|
790
|
+
condition: code`!existsSync(paths.data)`,
|
|
791
|
+
children: code`await mkdir(paths.data, { recursive: true }); `
|
|
792
|
+
}), code`await writeFile(join(paths.data, "version-check.json"), JSON.stringify({ timestamp: new Date().getTime() }), "utf8"); `];
|
|
793
|
+
}
|
|
794
|
+
})];
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* The `isCheckForUpdatesRequired` handler function declaration code for the Shell Shock project.
|
|
798
|
+
*/
|
|
799
|
+
function IsCheckForUpdatesRequiredFunctionDeclaration() {
|
|
800
|
+
const context = usePowerlines();
|
|
801
|
+
return [createComponent(TSDoc, {
|
|
802
|
+
heading: "A helper function that verifies if a check for updates is required.",
|
|
803
|
+
get children() {
|
|
804
|
+
return [
|
|
805
|
+
createComponent(TSDocRemarks, { children: `This function is used to determine if a check for updates is required based on the last time a check was performed. It can be used in the CLI upgrade command to avoid unnecessary checks for updates if one was recently performed. The function checks for the existence of a "version-check.json" file in the data directory, which contains a timestamp of the last check for updates. If the file does not exist or if the timestamp is older than a specified stale time, the function will return true, indicating that a check for updates is required. Otherwise, it will return false.` }),
|
|
806
|
+
createComponent(Spacing, {}),
|
|
807
|
+
createComponent(TSDocReturns, { children: `A promise that resolves to a boolean indicating whether a check for updates is required.` })
|
|
808
|
+
];
|
|
809
|
+
}
|
|
810
|
+
}), createComponent(FunctionDeclaration, {
|
|
811
|
+
"export": true,
|
|
812
|
+
async: true,
|
|
813
|
+
name: "isCheckForUpdatesRequired",
|
|
814
|
+
get children() {
|
|
815
|
+
return [
|
|
816
|
+
createComponent(IfStatement, {
|
|
817
|
+
condition: code`!isInteractive || isCI || env.SKIP_VERSION_CHECK`,
|
|
818
|
+
children: code`return false; `
|
|
819
|
+
}),
|
|
820
|
+
createComponent(Spacing, {}),
|
|
821
|
+
createComponent(VarDeclaration, {
|
|
822
|
+
"const": true,
|
|
823
|
+
name: "filePath",
|
|
824
|
+
initializer: code`join(paths.data, "version-check.json"); `
|
|
825
|
+
}),
|
|
826
|
+
createComponent(IfStatement, {
|
|
827
|
+
condition: code`existsSync(filePath)`,
|
|
828
|
+
get children() {
|
|
829
|
+
return [
|
|
830
|
+
createComponent(VarDeclaration, {
|
|
831
|
+
"const": true,
|
|
832
|
+
name: "file",
|
|
833
|
+
type: "{ timestamp: number; }",
|
|
834
|
+
initializer: code` JSON.parse(await readFile(filePath, "utf8")); `
|
|
835
|
+
}),
|
|
836
|
+
createComponent(IfStatement, {
|
|
837
|
+
condition: code`!file.timestamp`,
|
|
838
|
+
children: code`await updateVersionCheckFile();
|
|
839
|
+
return true; `
|
|
840
|
+
}),
|
|
841
|
+
createComponent(ElseIfClause, {
|
|
842
|
+
get condition() {
|
|
843
|
+
return code`new Date().getTime() - file.timestamp < ${context.config.upgrade.staleTime}`;
|
|
844
|
+
},
|
|
845
|
+
children: code`return false; `
|
|
846
|
+
})
|
|
847
|
+
];
|
|
848
|
+
}
|
|
849
|
+
}),
|
|
850
|
+
createComponent(ElseClause, { children: code`await updateVersionCheckFile();
|
|
851
|
+
return true; ` })
|
|
852
|
+
];
|
|
853
|
+
}
|
|
854
|
+
})];
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* The `checkForUpdates` handler function declaration code for the Shell Shock project.
|
|
858
|
+
*/
|
|
859
|
+
function CheckForUpdatesFunctionDeclaration() {
|
|
860
|
+
const context = usePowerlines();
|
|
861
|
+
return [
|
|
862
|
+
createComponent(InterfaceDeclaration, {
|
|
863
|
+
"export": true,
|
|
864
|
+
name: "CheckForUpdatesOptions",
|
|
865
|
+
"extends": "GetPackageManagerOptions",
|
|
866
|
+
doc: "Options for the `checkForUpdates` handler function.",
|
|
867
|
+
get children() {
|
|
868
|
+
return createComponent(InterfaceMember, {
|
|
869
|
+
name: "force",
|
|
870
|
+
optional: true,
|
|
871
|
+
type: "boolean",
|
|
872
|
+
doc: "Whether to force a check for updates regardless of the last check timestamp. If set to `true`, the function will bypass the timestamp check and perform a check for updates, updating the timestamp in the process. This can be useful if you want to ensure that a check for updates is performed even if one was recently done, such as when the user explicitly requests it or when certain conditions are met that warrant an immediate check."
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
}),
|
|
876
|
+
createComponent(Spacing, {}),
|
|
877
|
+
createComponent(InterfaceDeclaration, {
|
|
878
|
+
name: "CheckForUpdatesBaseResult",
|
|
879
|
+
get children() {
|
|
880
|
+
return createComponent(InterfaceMember, {
|
|
881
|
+
name: "isError",
|
|
882
|
+
type: "boolean",
|
|
883
|
+
optional: true,
|
|
884
|
+
doc: "Indicates whether an error occurred while checking for updates."
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
}),
|
|
888
|
+
createComponent(Spacing, {}),
|
|
889
|
+
createComponent(InterfaceDeclaration, {
|
|
890
|
+
name: "CheckForUpdatesSuccessResult",
|
|
891
|
+
"extends": "CheckForUpdatesBaseResult",
|
|
892
|
+
get children() {
|
|
893
|
+
return [
|
|
894
|
+
createComponent(InterfaceMember, {
|
|
895
|
+
name: "latestVersion",
|
|
896
|
+
type: "string",
|
|
897
|
+
doc: "The latest version of the application dependencies."
|
|
898
|
+
}),
|
|
899
|
+
createIntrinsic("hbr", {}),
|
|
900
|
+
createComponent(InterfaceMember, {
|
|
901
|
+
name: "currentVersion",
|
|
902
|
+
type: "string",
|
|
903
|
+
doc: "The current version of the application dependencies."
|
|
904
|
+
}),
|
|
905
|
+
createIntrinsic("hbr", {}),
|
|
906
|
+
createComponent(InterfaceMember, {
|
|
907
|
+
name: "isUpToDate",
|
|
908
|
+
type: "boolean",
|
|
909
|
+
doc: "Indicates whether the application dependencies are up-to-date."
|
|
910
|
+
}),
|
|
911
|
+
createIntrinsic("hbr", {}),
|
|
912
|
+
createComponent(InterfaceMember, {
|
|
913
|
+
name: "package",
|
|
914
|
+
type: "NpmPackage",
|
|
915
|
+
optional: true,
|
|
916
|
+
doc: "The npm package that was checked for updates."
|
|
917
|
+
})
|
|
918
|
+
];
|
|
919
|
+
}
|
|
920
|
+
}),
|
|
921
|
+
createComponent(Spacing, {}),
|
|
922
|
+
createComponent(InterfaceDeclaration, {
|
|
923
|
+
name: "CheckForUpdatesErrorResult",
|
|
924
|
+
"extends": "CheckForUpdatesBaseResult",
|
|
925
|
+
get children() {
|
|
926
|
+
return createComponent(InterfaceMember, {
|
|
927
|
+
name: "error",
|
|
928
|
+
type: "Error",
|
|
929
|
+
doc: "The error that occurred while checking for updates."
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
}),
|
|
933
|
+
createComponent(Spacing, {}),
|
|
934
|
+
createComponent(TypeDeclaration, {
|
|
935
|
+
"export": true,
|
|
936
|
+
name: "CheckForUpdatesResult",
|
|
937
|
+
doc: "The result for the `checkForUpdates` handler function.",
|
|
938
|
+
children: code`CheckForUpdatesSuccessResult | CheckForUpdatesErrorResult;`
|
|
939
|
+
}),
|
|
940
|
+
createComponent(Spacing, {}),
|
|
941
|
+
createComponent(TSDoc, {
|
|
942
|
+
heading: "Check for updates to the application dependencies.",
|
|
943
|
+
get children() {
|
|
944
|
+
return [
|
|
945
|
+
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.` }),
|
|
946
|
+
createComponent(Spacing, {}),
|
|
947
|
+
createComponent(TSDocParam, {
|
|
948
|
+
name: "options",
|
|
949
|
+
children: `The options for the \`checkForUpdates\` function. Currently, there are no options available, but this parameter is included for future extensibility.`
|
|
950
|
+
}),
|
|
951
|
+
createComponent(TSDocReturns, { children: `A promise that resolves when the check for updates is complete or undefined if the check was not performed.` })
|
|
952
|
+
];
|
|
953
|
+
}
|
|
954
|
+
}),
|
|
955
|
+
createComponent(FunctionDeclaration, {
|
|
956
|
+
"export": true,
|
|
957
|
+
async: true,
|
|
958
|
+
name: "checkForUpdates",
|
|
959
|
+
parameters: [{
|
|
960
|
+
name: "options",
|
|
961
|
+
type: "CheckForUpdatesOptions",
|
|
962
|
+
default: "{}"
|
|
963
|
+
}],
|
|
964
|
+
returnType: "CheckForUpdatesResult",
|
|
965
|
+
get children() {
|
|
966
|
+
return [
|
|
967
|
+
createComponent(IfStatement, {
|
|
968
|
+
condition: code`!options.force && !(await isCheckForUpdatesRequired())`,
|
|
969
|
+
get children() {
|
|
970
|
+
return code`return {
|
|
971
|
+
latestVersion: "${context.packageJson.version}",
|
|
972
|
+
currentVersion: "${context.packageJson.version}",
|
|
973
|
+
isUpToDate: true,
|
|
974
|
+
isError: false,
|
|
975
|
+
}; `;
|
|
976
|
+
}
|
|
977
|
+
}),
|
|
978
|
+
createComponent(Spacing, {}),
|
|
979
|
+
code`try { `,
|
|
980
|
+
createComponent(VarDeclaration, {
|
|
981
|
+
"const": true,
|
|
982
|
+
name: "pkg",
|
|
983
|
+
get initializer() {
|
|
984
|
+
return code`await fetchNpmPackage("${context.packageJson.name}"); `;
|
|
985
|
+
}
|
|
986
|
+
}),
|
|
987
|
+
createComponent(Spacing, {}),
|
|
988
|
+
memo(() => code`
|
|
989
|
+
return {
|
|
990
|
+
latestVersion: pkg?.version || "${context.packageJson.version}",
|
|
991
|
+
currentVersion: "${context.packageJson.version}",
|
|
992
|
+
isUpToDate: pkg ? "${context.packageJson.version}" === pkg.version : true,
|
|
993
|
+
package: pkg,
|
|
994
|
+
isError: false,
|
|
995
|
+
};
|
|
996
|
+
} catch (err) {
|
|
997
|
+
return { isError: true, error: err instanceof Error ? err : new Error(String(err)) };
|
|
998
|
+
} `)
|
|
999
|
+
];
|
|
1000
|
+
}
|
|
1001
|
+
})
|
|
1002
|
+
];
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
645
1005
|
* A built-in upgrade module for Shell Shock.
|
|
646
1006
|
*/
|
|
647
1007
|
function UpgradeBuiltin(props) {
|
|
@@ -655,7 +1015,11 @@ function UpgradeBuiltin(props) {
|
|
|
655
1015
|
"node:os": "os",
|
|
656
1016
|
"node:path": ["join", "resolve"],
|
|
657
1017
|
"node:fs": ["existsSync"],
|
|
658
|
-
"node:fs/promises": [
|
|
1018
|
+
"node:fs/promises": [
|
|
1019
|
+
"readFile",
|
|
1020
|
+
"writeFile",
|
|
1021
|
+
"mkdir"
|
|
1022
|
+
],
|
|
659
1023
|
"node:process": "process"
|
|
660
1024
|
});
|
|
661
1025
|
},
|
|
@@ -666,8 +1030,17 @@ function UpgradeBuiltin(props) {
|
|
|
666
1030
|
"verbose",
|
|
667
1031
|
"writeLine"
|
|
668
1032
|
],
|
|
669
|
-
env: [
|
|
670
|
-
|
|
1033
|
+
env: [
|
|
1034
|
+
"paths",
|
|
1035
|
+
"isWindows",
|
|
1036
|
+
"isCI",
|
|
1037
|
+
"env"
|
|
1038
|
+
],
|
|
1039
|
+
utils: [
|
|
1040
|
+
"isColorSupported",
|
|
1041
|
+
"isInteractive",
|
|
1042
|
+
"spawn"
|
|
1043
|
+
]
|
|
671
1044
|
});
|
|
672
1045
|
},
|
|
673
1046
|
get children() {
|
|
@@ -686,15 +1059,25 @@ function UpgradeBuiltin(props) {
|
|
|
686
1059
|
initializer: code`os.tmpdir(); `
|
|
687
1060
|
}),
|
|
688
1061
|
createComponent(Spacing, {}),
|
|
1062
|
+
createComponent(LocatePackageJsonFunctionDeclaration, {}),
|
|
1063
|
+
createComponent(Spacing, {}),
|
|
689
1064
|
createComponent(LocateLockfileFunctionDeclaration, {}),
|
|
690
1065
|
createComponent(Spacing, {}),
|
|
691
1066
|
createComponent(GetPackageManagerFunctionDeclaration, {}),
|
|
692
1067
|
createComponent(Spacing, {}),
|
|
693
1068
|
createComponent(FetchNpmPackageFunctionDeclaration, {}),
|
|
694
1069
|
createComponent(Spacing, {}),
|
|
695
|
-
createComponent(
|
|
1070
|
+
createComponent(GetLatestVersionFunctionDeclaration, {}),
|
|
1071
|
+
createComponent(Spacing, {}),
|
|
1072
|
+
createComponent(GetUpgradeCommandFunctionDeclaration, {}),
|
|
1073
|
+
createComponent(Spacing, {}),
|
|
1074
|
+
createComponent(UpgradeFunctionDeclaration, {}),
|
|
1075
|
+
createComponent(Spacing, {}),
|
|
1076
|
+
createComponent(CheckForUpdatesFunctionDeclaration, {}),
|
|
1077
|
+
createComponent(Spacing, {}),
|
|
1078
|
+
createComponent(IsCheckForUpdatesRequiredFunctionDeclaration, {}),
|
|
696
1079
|
createComponent(Spacing, {}),
|
|
697
|
-
createComponent(
|
|
1080
|
+
createComponent(UpdateVersionCheckFileFunctionDeclaration, {}),
|
|
698
1081
|
createComponent(Spacing, {}),
|
|
699
1082
|
createComponent(Show, {
|
|
700
1083
|
get when() {
|
|
@@ -708,5 +1091,5 @@ function UpgradeBuiltin(props) {
|
|
|
708
1091
|
}
|
|
709
1092
|
|
|
710
1093
|
//#endregion
|
|
711
|
-
export { FetchNpmPackageFunctionDeclaration,
|
|
1094
|
+
export { CheckForUpdatesFunctionDeclaration, FetchNpmPackageFunctionDeclaration, GetLatestVersionFunctionDeclaration, GetPackageManagerFunctionDeclaration, GetUpgradeCommandFunctionDeclaration, IsCheckForUpdatesRequiredFunctionDeclaration, LocateLockfileFunctionDeclaration, LocatePackageJsonFunctionDeclaration, UpdateVersionCheckFileFunctionDeclaration, UpgradeBuiltin, UpgradeFunctionDeclaration };
|
|
712
1095
|
//# sourceMappingURL=upgrade-builtin.mjs.map
|