@cedarjs/cli 2.2.2-next.0 → 2.3.0-rc.34
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/commands/consoleHandler.js +1 -1
- package/dist/commands/generate/package/filesTask.js +73 -0
- package/dist/commands/generate/package/package.js +14 -0
- package/dist/commands/generate/package/packageHandler.js +158 -0
- package/dist/commands/generate/package/templates/README.md.template +15 -0
- package/dist/commands/generate/package/templates/index.ts.template +3 -0
- package/dist/commands/generate/package/templates/package.json.template +15 -0
- package/dist/commands/generate/package/templates/scenarios.ts.template +8 -0
- package/dist/commands/generate/package/templates/test.ts.template +7 -0
- package/dist/commands/generate/package/templates/tsconfig.json.template +16 -0
- package/dist/commands/generate/script/scriptHandler.js +15 -14
- package/dist/commands/generate/yargsHandlerHelpers.js +12 -4
- package/dist/commands/generate.js +2 -1
- package/dist/commands/setup/generator/generator.js +1 -7
- package/dist/commands/setup/generator/generatorHandler.js +8 -3
- package/dist/commands/upgrade/preUpgradeScripts.js +235 -0
- package/dist/commands/upgrade/tags.js +6 -0
- package/dist/commands/upgrade/upgrade.js +75 -0
- package/dist/commands/{upgrade.js → upgrade/upgradeHandler.js} +56 -325
- package/dist/index.js +1 -1
- package/dist/lib/merge/index.js +0 -2
- package/dist/lib/test.js +6 -4
- package/dist/telemetry/resource.js +0 -2
- package/package.json +14 -13
|
@@ -1,92 +1,34 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import { builtinModules } from "node:module";
|
|
3
|
-
import os from "node:os";
|
|
4
2
|
import path from "node:path";
|
|
5
3
|
import { ListrEnquirerPromptAdapter } from "@listr2/prompt-adapter-enquirer";
|
|
6
4
|
import execa from "execa";
|
|
7
5
|
import latestVersion from "latest-version";
|
|
8
6
|
import { Listr } from "listr2";
|
|
9
|
-
import semver from "semver";
|
|
10
7
|
import { terminalLink } from "termi-link";
|
|
11
8
|
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
|
|
12
9
|
import { getConfig } from "@cedarjs/project-config";
|
|
13
|
-
import c from "
|
|
14
|
-
import { generatePrismaClient } from "
|
|
15
|
-
import { getPaths } from "
|
|
16
|
-
import { PLUGIN_CACHE_FILENAME } from "
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}).option("tag", {
|
|
28
|
-
alias: "t",
|
|
29
|
-
description: '[choices: "latest", "rc", "next", "canary", "experimental", or a specific-version (see example below)] WARNING: "canary", "rc" and "experimental" are unstable releases! And "canary" releases include breaking changes often requiring changes to your codebase when upgrading a project.',
|
|
30
|
-
requiresArg: true,
|
|
31
|
-
type: "string",
|
|
32
|
-
coerce: validateTag
|
|
33
|
-
}).option("verbose", {
|
|
34
|
-
alias: "v",
|
|
35
|
-
description: "Print verbose logs",
|
|
36
|
-
type: "boolean",
|
|
37
|
-
default: false
|
|
38
|
-
}).option("dedupe", {
|
|
39
|
-
description: "Skip dedupe check with --no-dedupe",
|
|
40
|
-
type: "boolean",
|
|
41
|
-
default: true
|
|
42
|
-
}).option("yes", {
|
|
43
|
-
alias: "y",
|
|
44
|
-
describe: "Skip prompts and use defaults",
|
|
45
|
-
default: false,
|
|
46
|
-
type: "boolean"
|
|
47
|
-
}).option("force", {
|
|
48
|
-
alias: "f",
|
|
49
|
-
describe: "Force upgrade even if pre-upgrade checks fail",
|
|
50
|
-
default: false,
|
|
51
|
-
type: "boolean"
|
|
52
|
-
}).epilogue(
|
|
53
|
-
`Also see the ${terminalLink(
|
|
54
|
-
"CedarJS CLI Reference for the upgrade command",
|
|
55
|
-
"https://cedarjs.com/docs/cli-commands#upgrade"
|
|
56
|
-
)}.
|
|
57
|
-
And the ${terminalLink(
|
|
58
|
-
"GitHub releases page",
|
|
59
|
-
"https://github.com/cedarjs/cedar/releases"
|
|
60
|
-
)} for more information on the current release.`
|
|
61
|
-
);
|
|
62
|
-
};
|
|
63
|
-
const SEMVER_REGEX = /(?<=^v?|\sv?)(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*)(?:\.(?:0|[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*))*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?(?=$|\s)/i;
|
|
64
|
-
const isValidSemver = (string) => {
|
|
65
|
-
return SEMVER_REGEX.test(string);
|
|
66
|
-
};
|
|
67
|
-
const isValidCedarJSTag = (tag) => {
|
|
68
|
-
return ["rc", "canary", "latest", "next", "experimental"].includes(tag);
|
|
69
|
-
};
|
|
70
|
-
const validateTag = (tag) => {
|
|
71
|
-
const isTagValid = isValidSemver(tag) || isValidCedarJSTag(tag);
|
|
72
|
-
if (!isTagValid) {
|
|
73
|
-
throw new Error(
|
|
74
|
-
c.error(
|
|
75
|
-
"Invalid tag supplied. Supported values: 'rc', 'canary', 'latest', 'next', 'experimental', or a valid semver version\n"
|
|
76
|
-
)
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
return tag;
|
|
80
|
-
};
|
|
81
|
-
const handler = async ({ dryRun, tag, verbose, dedupe, yes, force }) => {
|
|
10
|
+
import c from "../../lib/colors.js";
|
|
11
|
+
import { generatePrismaClient } from "../../lib/generatePrismaClient.js";
|
|
12
|
+
import { getPaths } from "../../lib/index.js";
|
|
13
|
+
import { PLUGIN_CACHE_FILENAME } from "../../lib/plugin.js";
|
|
14
|
+
import { runPreUpgradeScripts } from "./preUpgradeScripts.js";
|
|
15
|
+
import { isValidCedarJSTag } from "./tags.js";
|
|
16
|
+
const handler = async ({
|
|
17
|
+
dryRun,
|
|
18
|
+
tag,
|
|
19
|
+
verbose,
|
|
20
|
+
dedupe,
|
|
21
|
+
yes,
|
|
22
|
+
force
|
|
23
|
+
}) => {
|
|
82
24
|
recordTelemetryAttributes({
|
|
83
25
|
command: "upgrade",
|
|
84
|
-
dryRun,
|
|
85
|
-
tag,
|
|
86
|
-
verbose,
|
|
87
|
-
dedupe,
|
|
88
|
-
yes,
|
|
89
|
-
force
|
|
26
|
+
dryRun: !!dryRun,
|
|
27
|
+
tag: tag ?? "latest",
|
|
28
|
+
verbose: !!verbose,
|
|
29
|
+
dedupe: !!dedupe,
|
|
30
|
+
yes: !!yes,
|
|
31
|
+
force: !!force
|
|
90
32
|
});
|
|
91
33
|
let preUpgradeMessage = "";
|
|
92
34
|
let preUpgradeError = "";
|
|
@@ -126,17 +68,17 @@ const handler = async ({ dryRun, tag, verbose, dedupe, yes, force }) => {
|
|
|
126
68
|
},
|
|
127
69
|
{
|
|
128
70
|
title: "Checking latest version",
|
|
129
|
-
task: async (ctx) => setLatestVersionToContext(ctx, tag)
|
|
71
|
+
task: async (ctx) => setLatestVersionToContext(ctx, tag, verbose)
|
|
130
72
|
},
|
|
131
73
|
{
|
|
132
74
|
title: "Running pre-upgrade scripts",
|
|
133
75
|
task: async (ctx, task) => {
|
|
134
76
|
await runPreUpgradeScripts(ctx, task, { verbose, force });
|
|
135
77
|
if (ctx.preUpgradeMessage) {
|
|
136
|
-
preUpgradeMessage = ctx.preUpgradeMessage;
|
|
78
|
+
preUpgradeMessage = String(ctx.preUpgradeMessage);
|
|
137
79
|
}
|
|
138
80
|
if (ctx.preUpgradeError) {
|
|
139
|
-
preUpgradeError = ctx.preUpgradeError;
|
|
81
|
+
preUpgradeError = String(ctx.preUpgradeError);
|
|
140
82
|
}
|
|
141
83
|
},
|
|
142
84
|
enabled: (ctx) => !!ctx.versionToUpgradeTo
|
|
@@ -149,33 +91,33 @@ const handler = async ({ dryRun, tag, verbose, dedupe, yes, force }) => {
|
|
|
149
91
|
{
|
|
150
92
|
title: "Updating other packages in your package.json(s)",
|
|
151
93
|
task: (ctx) => updatePackageVersionsFromTemplate(ctx, { dryRun, verbose }),
|
|
152
|
-
enabled: (ctx) => ctx.versionToUpgradeTo
|
|
94
|
+
enabled: (ctx) => String(ctx.versionToUpgradeTo).includes("canary") && !ctx.preUpgradeError
|
|
153
95
|
},
|
|
154
96
|
{
|
|
155
97
|
title: "Downloading yarn patches",
|
|
156
98
|
task: (ctx) => downloadYarnPatches(ctx, { dryRun, verbose }),
|
|
157
|
-
enabled: (ctx) => ctx.versionToUpgradeTo
|
|
99
|
+
enabled: (ctx) => String(ctx.versionToUpgradeTo).includes("canary") && !ctx.preUpgradeError
|
|
158
100
|
},
|
|
159
101
|
{
|
|
160
102
|
title: "Removing CLI cache",
|
|
161
|
-
task: (
|
|
103
|
+
task: () => removeCliCache({ dryRun, verbose }),
|
|
162
104
|
enabled: (ctx) => !ctx.preUpgradeError
|
|
163
105
|
},
|
|
164
106
|
{
|
|
165
107
|
title: "Running yarn install",
|
|
166
|
-
task: (
|
|
108
|
+
task: () => yarnInstall({ verbose }),
|
|
167
109
|
enabled: (ctx) => !ctx.preUpgradeError,
|
|
168
|
-
skip: () => dryRun
|
|
110
|
+
skip: () => !!dryRun
|
|
169
111
|
},
|
|
170
112
|
{
|
|
171
113
|
title: "Refreshing the Prisma client",
|
|
172
114
|
task: (_ctx, task) => refreshPrismaClient(task, { verbose }),
|
|
173
115
|
enabled: (ctx) => !ctx.preUpgradeError,
|
|
174
|
-
skip: () => dryRun
|
|
116
|
+
skip: () => !!dryRun
|
|
175
117
|
},
|
|
176
118
|
{
|
|
177
119
|
title: "De-duplicating dependencies",
|
|
178
|
-
skip: () => dryRun || !dedupe,
|
|
120
|
+
skip: () => !!dryRun || !dedupe,
|
|
179
121
|
enabled: (ctx) => !ctx.preUpgradeError,
|
|
180
122
|
task: (_ctx, task) => dedupeDeps(task, { verbose })
|
|
181
123
|
},
|
|
@@ -195,8 +137,8 @@ const handler = async ({ dryRun, tag, verbose, dedupe, yes, force }) => {
|
|
|
195
137
|
if ([void 0, "latest", "rc"].includes(tag)) {
|
|
196
138
|
const ghReleasesLink = terminalLink(
|
|
197
139
|
`GitHub Release notes`,
|
|
198
|
-
`https://github.com/cedarjs/cedar/releases`
|
|
199
140
|
// intentionally not linking to specific version
|
|
141
|
+
`https://github.com/cedarjs/cedar/releases`
|
|
200
142
|
);
|
|
201
143
|
const discordLink = terminalLink(
|
|
202
144
|
`Discord`,
|
|
@@ -257,13 +199,16 @@ async function yarnInstall({ verbose }) {
|
|
|
257
199
|
stdio: verbose ? "inherit" : "pipe",
|
|
258
200
|
cwd: getPaths().base
|
|
259
201
|
});
|
|
260
|
-
} catch
|
|
202
|
+
} catch {
|
|
261
203
|
throw new Error(
|
|
262
204
|
"Could not finish installation. Please run `yarn install` and then `yarn dedupe`, before continuing"
|
|
263
205
|
);
|
|
264
206
|
}
|
|
265
207
|
}
|
|
266
|
-
async function removeCliCache(
|
|
208
|
+
async function removeCliCache({
|
|
209
|
+
dryRun,
|
|
210
|
+
verbose
|
|
211
|
+
}) {
|
|
267
212
|
const cliCacheDir = path.join(
|
|
268
213
|
getPaths().generated.base,
|
|
269
214
|
PLUGIN_CACHE_FILENAME
|
|
@@ -275,7 +220,10 @@ async function removeCliCache(ctx, { dryRun, verbose }) {
|
|
|
275
220
|
fs.rmSync(cliCacheDir, { recursive: true, force: true });
|
|
276
221
|
}
|
|
277
222
|
}
|
|
278
|
-
|
|
223
|
+
function isErrorWithNestedCode(error, code) {
|
|
224
|
+
return error instanceof Object && ("code" in error && error.code === code || "cause" in error && isErrorWithNestedCode(error.cause, code));
|
|
225
|
+
}
|
|
226
|
+
async function setLatestVersionToContext(ctx, tag, verbose) {
|
|
279
227
|
try {
|
|
280
228
|
const foundVersion = await latestVersion(
|
|
281
229
|
"@cedarjs/core",
|
|
@@ -283,11 +231,15 @@ async function setLatestVersionToContext(ctx, tag) {
|
|
|
283
231
|
);
|
|
284
232
|
ctx.versionToUpgradeTo = foundVersion;
|
|
285
233
|
return foundVersion;
|
|
286
|
-
} catch (
|
|
234
|
+
} catch (error) {
|
|
235
|
+
if (verbose) {
|
|
236
|
+
console.error(error);
|
|
237
|
+
}
|
|
238
|
+
const proxyError = isErrorWithNestedCode(error, "ENOTFOUND") ? "\n\nIf you are behind a proxy, please set the relevant proxy environment variables.\nSee here for more information: https://nodejs.org/api/http.html#built-in-proxy-support\n" : "";
|
|
287
239
|
if (tag) {
|
|
288
|
-
throw new Error(
|
|
240
|
+
throw new Error(`Could not find the latest '${tag}' version${proxyError}`);
|
|
289
241
|
}
|
|
290
|
-
throw new Error(
|
|
242
|
+
throw new Error(`Could not find the latest version${proxyError}`);
|
|
291
243
|
}
|
|
292
244
|
}
|
|
293
245
|
function updatePackageJsonVersion(pkgPath, version, task, { dryRun, verbose }) {
|
|
@@ -345,7 +297,7 @@ function updateCedarJSDepsForAllSides(ctx, options) {
|
|
|
345
297
|
title: `Updating ${pkgJsonPath}`,
|
|
346
298
|
task: (_ctx, task) => updatePackageJsonVersion(
|
|
347
299
|
basePath,
|
|
348
|
-
ctx.versionToUpgradeTo,
|
|
300
|
+
String(ctx.versionToUpgradeTo),
|
|
349
301
|
task,
|
|
350
302
|
options
|
|
351
303
|
),
|
|
@@ -432,7 +384,7 @@ async function downloadYarnPatches(ctx, { dryRun, verbose }) {
|
|
|
432
384
|
"https://api.github.com/repos/cedarjs/cedar/git/trees/main?recursive=1",
|
|
433
385
|
{
|
|
434
386
|
headers: {
|
|
435
|
-
Authorization:
|
|
387
|
+
...githubToken && { Authorization: `Bearer ${githubToken}` },
|
|
436
388
|
["X-GitHub-Api-Version"]: "2022-11-28",
|
|
437
389
|
Accept: "application/vnd.github+json"
|
|
438
390
|
}
|
|
@@ -477,16 +429,14 @@ async function downloadYarnPatches(ctx, { dryRun, verbose }) {
|
|
|
477
429
|
}
|
|
478
430
|
async function refreshPrismaClient(task, { verbose }) {
|
|
479
431
|
try {
|
|
480
|
-
await generatePrismaClient({
|
|
481
|
-
verbose,
|
|
482
|
-
force: false
|
|
483
|
-
});
|
|
432
|
+
await generatePrismaClient({ verbose, force: false });
|
|
484
433
|
} catch (e) {
|
|
434
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
485
435
|
task.skip("Refreshing the Prisma client caused an Error.");
|
|
486
436
|
console.log(
|
|
487
437
|
"You may need to update your prisma client manually: $ yarn cedar prisma generate"
|
|
488
438
|
);
|
|
489
|
-
console.log(c.error(
|
|
439
|
+
console.log(c.error(message));
|
|
490
440
|
}
|
|
491
441
|
}
|
|
492
442
|
const dedupeDeps = async (_task, { verbose }) => {
|
|
@@ -497,233 +447,14 @@ const dedupeDeps = async (_task, { verbose }) => {
|
|
|
497
447
|
cwd: getPaths().base
|
|
498
448
|
});
|
|
499
449
|
} catch (e) {
|
|
500
|
-
|
|
450
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
451
|
+
console.log(c.error(message));
|
|
501
452
|
throw new Error(
|
|
502
|
-
"Could not finish de-duplication.
|
|
453
|
+
"Could not finish de-duplication. Please run `yarn dedupe` before continuing"
|
|
503
454
|
);
|
|
504
455
|
}
|
|
505
456
|
await yarnInstall({ verbose });
|
|
506
457
|
};
|
|
507
|
-
async function runPreUpgradeScripts(ctx, task, { verbose, force }) {
|
|
508
|
-
if (!ctx.versionToUpgradeTo) {
|
|
509
|
-
return;
|
|
510
|
-
}
|
|
511
|
-
const version = ctx.versionToUpgradeTo;
|
|
512
|
-
const parsed = semver.parse(version);
|
|
513
|
-
const baseUrl = "https://raw.githubusercontent.com/cedarjs/cedar/main/upgrade-scripts/";
|
|
514
|
-
const manifestUrl = `${baseUrl}manifest.json`;
|
|
515
|
-
let manifest = [];
|
|
516
|
-
try {
|
|
517
|
-
const res = await fetch(manifestUrl);
|
|
518
|
-
if (res.status === 200) {
|
|
519
|
-
manifest = await res.json();
|
|
520
|
-
} else {
|
|
521
|
-
if (verbose) {
|
|
522
|
-
console.log("No upgrade script manifest found.");
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
} catch (e) {
|
|
526
|
-
if (verbose) {
|
|
527
|
-
console.log("Failed to fetch upgrade script manifest", e);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
if (!Array.isArray(manifest) || manifest.length === 0) {
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
533
|
-
const checkLevels = [];
|
|
534
|
-
if (parsed && !parsed.prerelease.length) {
|
|
535
|
-
checkLevels.push({
|
|
536
|
-
id: "exact",
|
|
537
|
-
candidates: [`${version}.ts`, `${version}/index.ts`]
|
|
538
|
-
});
|
|
539
|
-
checkLevels.push({
|
|
540
|
-
id: "patch",
|
|
541
|
-
candidates: [
|
|
542
|
-
`${parsed.major}.${parsed.minor}.x.ts`,
|
|
543
|
-
`${parsed.major}.${parsed.minor}.x/index.ts`
|
|
544
|
-
]
|
|
545
|
-
});
|
|
546
|
-
checkLevels.push({
|
|
547
|
-
id: "minor",
|
|
548
|
-
candidates: [`${parsed.major}.x.ts`, `${parsed.major}.x/index.ts`]
|
|
549
|
-
});
|
|
550
|
-
} else if (parsed && parsed.prerelease.length > 0) {
|
|
551
|
-
checkLevels.push({
|
|
552
|
-
id: "tag",
|
|
553
|
-
candidates: [
|
|
554
|
-
`${parsed.prerelease[0]}.ts`,
|
|
555
|
-
`${parsed.prerelease[0]}/index.ts`
|
|
556
|
-
]
|
|
557
|
-
});
|
|
558
|
-
}
|
|
559
|
-
const scriptsToRun = [];
|
|
560
|
-
for (const level of checkLevels) {
|
|
561
|
-
for (const candidate of level.candidates) {
|
|
562
|
-
if (manifest.includes(candidate)) {
|
|
563
|
-
scriptsToRun.push(candidate);
|
|
564
|
-
break;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
if (scriptsToRun.length === 0) {
|
|
569
|
-
if (verbose) {
|
|
570
|
-
console.log(`No upgrade scripts found for ${version}`);
|
|
571
|
-
}
|
|
572
|
-
return;
|
|
573
|
-
}
|
|
574
|
-
ctx.preUpgradeMessage = "";
|
|
575
|
-
ctx.preUpgradeError = "";
|
|
576
|
-
for (const scriptName of scriptsToRun) {
|
|
577
|
-
task.output = `Found upgrade check script: ${scriptName}. Downloading...`;
|
|
578
|
-
const tempDir = await fs.promises.mkdtemp(
|
|
579
|
-
// realpath: https://github.com/e18e/ecosystem-issues/issues/168
|
|
580
|
-
path.join(fs.realpathSync(os.tmpdir()), "cedar-upgrade-")
|
|
581
|
-
);
|
|
582
|
-
const scriptPath = path.join(tempDir, "script.mts");
|
|
583
|
-
const isDirectoryScript = scriptName.includes("/");
|
|
584
|
-
if (isDirectoryScript) {
|
|
585
|
-
const dirName = scriptName.split("/")[0];
|
|
586
|
-
const githubApiUrl = `https://api.github.com/repos/cedarjs/cedar/contents/upgrade-scripts/${dirName}`;
|
|
587
|
-
try {
|
|
588
|
-
const dirRes = await fetch(githubApiUrl, {
|
|
589
|
-
headers: {
|
|
590
|
-
Accept: "application/vnd.github.v3+json"
|
|
591
|
-
}
|
|
592
|
-
});
|
|
593
|
-
if (dirRes.status !== 200) {
|
|
594
|
-
throw new Error(
|
|
595
|
-
`Failed to fetch directory contents: ${dirRes.statusText}`
|
|
596
|
-
);
|
|
597
|
-
}
|
|
598
|
-
const files = await dirRes.json();
|
|
599
|
-
for (const file of files) {
|
|
600
|
-
if (file.type === "file") {
|
|
601
|
-
task.output = `Downloading ${file.name}...`;
|
|
602
|
-
const fileRes = await fetch(file.download_url);
|
|
603
|
-
if (fileRes.status !== 200) {
|
|
604
|
-
throw new Error(`Failed to download ${file.name}`);
|
|
605
|
-
}
|
|
606
|
-
const fileContent = await fileRes.text();
|
|
607
|
-
const filePath = path.join(tempDir, file.name);
|
|
608
|
-
await fs.promises.writeFile(filePath, fileContent);
|
|
609
|
-
if (file.name === "index.ts") {
|
|
610
|
-
await fs.promises.rename(filePath, scriptPath);
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
} catch (e) {
|
|
615
|
-
if (verbose) {
|
|
616
|
-
console.error(e);
|
|
617
|
-
}
|
|
618
|
-
throw new Error(
|
|
619
|
-
`Failed to download upgrade script directory from ${githubApiUrl}`
|
|
620
|
-
);
|
|
621
|
-
}
|
|
622
|
-
} else {
|
|
623
|
-
const scriptUrl = `${baseUrl}${scriptName}`;
|
|
624
|
-
try {
|
|
625
|
-
const res = await fetch(scriptUrl);
|
|
626
|
-
if (res.status !== 200) {
|
|
627
|
-
throw new Error(`Failed to download script: ${res.statusText}`);
|
|
628
|
-
}
|
|
629
|
-
const scriptContent2 = await res.text();
|
|
630
|
-
await fs.promises.writeFile(scriptPath, scriptContent2);
|
|
631
|
-
} catch (e) {
|
|
632
|
-
if (verbose) {
|
|
633
|
-
console.error(e);
|
|
634
|
-
}
|
|
635
|
-
throw new Error(`Failed to download upgrade script from ${scriptUrl}`);
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
const scriptContent = await fs.promises.readFile(scriptPath, "utf8");
|
|
639
|
-
const deps = extractDependencies(scriptContent);
|
|
640
|
-
if (deps.length > 0) {
|
|
641
|
-
const depList = deps.join(", ");
|
|
642
|
-
task.output = `Installing dependencies for ${scriptName}: ${depList}...`;
|
|
643
|
-
await fs.promises.writeFile(
|
|
644
|
-
path.join(tempDir, "package.json"),
|
|
645
|
-
JSON.stringify({
|
|
646
|
-
name: "pre-upgrade-script",
|
|
647
|
-
version: "0.0.0",
|
|
648
|
-
dependencies: {}
|
|
649
|
-
})
|
|
650
|
-
);
|
|
651
|
-
await execa("npm", ["install", ...deps], { cwd: tempDir });
|
|
652
|
-
}
|
|
653
|
-
task.output = `Running pre-upgrade script: ${scriptName}...`;
|
|
654
|
-
let shouldCleanup = true;
|
|
655
|
-
try {
|
|
656
|
-
const { stdout } = await execa(
|
|
657
|
-
"node",
|
|
658
|
-
["script.mts", "--verbose", verbose, "--force", force],
|
|
659
|
-
{ cwd: tempDir }
|
|
660
|
-
);
|
|
661
|
-
if (stdout) {
|
|
662
|
-
if (ctx.preUpgradeMessage) {
|
|
663
|
-
ctx.preUpgradeMessage += "\n";
|
|
664
|
-
}
|
|
665
|
-
ctx.preUpgradeMessage += `
|
|
666
|
-
${stdout}`;
|
|
667
|
-
}
|
|
668
|
-
} catch (e) {
|
|
669
|
-
const errorOutput = e.stdout || e.stderr || e.message || "";
|
|
670
|
-
const verboseErrorMessage = verbose ? `Pre-upgrade check ${scriptName} failed with exit code ${e.exitCode}:
|
|
671
|
-
${e.stderr ? e.stderr + "\n" : ""}` : "";
|
|
672
|
-
if (ctx.preUpgradeError) {
|
|
673
|
-
ctx.preUpgradeError += "\n";
|
|
674
|
-
}
|
|
675
|
-
if (verbose) {
|
|
676
|
-
ctx.preUpgradeError += `
|
|
677
|
-
${verboseErrorMessage}`;
|
|
678
|
-
}
|
|
679
|
-
ctx.preUpgradeError += `
|
|
680
|
-
${errorOutput}`;
|
|
681
|
-
if (!force) {
|
|
682
|
-
await fs.promises.rm(tempDir, { recursive: true });
|
|
683
|
-
shouldCleanup = false;
|
|
684
|
-
return;
|
|
685
|
-
}
|
|
686
|
-
} finally {
|
|
687
|
-
if (shouldCleanup) {
|
|
688
|
-
await fs.promises.rm(tempDir, { recursive: true });
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
const extractDependencies = (content) => {
|
|
694
|
-
const deps = /* @__PURE__ */ new Map();
|
|
695
|
-
const commentRegex = /\/\/\s*@dependency:\s*(\S+)/g;
|
|
696
|
-
let match;
|
|
697
|
-
while ((match = commentRegex.exec(content)) !== null) {
|
|
698
|
-
const spec = match[1];
|
|
699
|
-
const nameMatch = spec.match(/^(@?[^@\s]+)(?:@.+)?$/);
|
|
700
|
-
if (nameMatch) {
|
|
701
|
-
deps.set(nameMatch[1], spec);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
const importRegex = /(?:import|from)\s*\(?['"]([^'"]+)['"]\)?/g;
|
|
705
|
-
while ((match = importRegex.exec(content)) !== null) {
|
|
706
|
-
let name = match[1];
|
|
707
|
-
if (name.startsWith(".") || name.startsWith("/") || name.startsWith("node:") || builtinModules.includes(name)) {
|
|
708
|
-
continue;
|
|
709
|
-
}
|
|
710
|
-
const parts = name.split("/");
|
|
711
|
-
if (name.startsWith("@") && parts.length >= 2) {
|
|
712
|
-
name = parts.slice(0, 2).join("/");
|
|
713
|
-
} else if (parts.length >= 1) {
|
|
714
|
-
name = parts[0];
|
|
715
|
-
}
|
|
716
|
-
if (!deps.has(name)) {
|
|
717
|
-
deps.set(name, name);
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
return Array.from(deps.values());
|
|
721
|
-
};
|
|
722
458
|
export {
|
|
723
|
-
|
|
724
|
-
command,
|
|
725
|
-
description,
|
|
726
|
-
handler,
|
|
727
|
-
runPreUpgradeScripts,
|
|
728
|
-
validateTag
|
|
459
|
+
handler
|
|
729
460
|
};
|
package/dist/index.js
CHANGED
|
@@ -29,7 +29,7 @@ import * as testCommand from "./commands/test.js";
|
|
|
29
29
|
import * as testCommandEsm from "./commands/testEsm.js";
|
|
30
30
|
import * as tstojsCommand from "./commands/ts-to-js.js";
|
|
31
31
|
import * as typeCheckCommand from "./commands/type-check.js";
|
|
32
|
-
import * as upgradeCommand from "./commands/upgrade.js";
|
|
32
|
+
import * as upgradeCommand from "./commands/upgrade/upgrade.js";
|
|
33
33
|
import { exitWithError } from "./lib/exit.js";
|
|
34
34
|
import { findUp } from "./lib/index.js";
|
|
35
35
|
import * as updateCheck from "./lib/updateCheck.js";
|
package/dist/lib/merge/index.js
CHANGED
|
@@ -79,13 +79,11 @@ function insertAfterLastImport(expression, program) {
|
|
|
79
79
|
}
|
|
80
80
|
function prune(path) {
|
|
81
81
|
switch (path.parentPath.type) {
|
|
82
|
-
// If pruning 'path' would yield an ill-formed parent (e.g, '{foo:}' or 'const x;'), prune it.
|
|
83
82
|
case "ObjectProperty":
|
|
84
83
|
case "VariableDeclarator":
|
|
85
84
|
return path.parentPath.remove();
|
|
86
85
|
default:
|
|
87
86
|
console.log(`Warning: default prune strategy for ${path.parentPath.type}`);
|
|
88
|
-
// eslint-disable-next-line no-fallthrough
|
|
89
87
|
case "Program":
|
|
90
88
|
case "ArrayExpression":
|
|
91
89
|
return path.remove();
|
package/dist/lib/test.js
CHANGED
|
@@ -25,26 +25,28 @@ vi.mock("@cedarjs/project-config", async (importOriginal) => {
|
|
|
25
25
|
"prisma.config.cjs"
|
|
26
26
|
),
|
|
27
27
|
dataMigrations: path.join(BASE_PATH, "./api/dataMigrations"),
|
|
28
|
-
generators: path.join(BASE_PATH, "./api/generators"),
|
|
29
28
|
src: path.join(BASE_PATH, "./api/src"),
|
|
30
29
|
jobs: path.join(BASE_PATH, "./api/src/jobs"),
|
|
31
30
|
services: path.join(BASE_PATH, "./api/src/services"),
|
|
32
31
|
directives: path.join(BASE_PATH, "./api/src/directives"),
|
|
33
32
|
graphql: path.join(BASE_PATH, "./api/src/graphql"),
|
|
34
|
-
functions: path.join(BASE_PATH, "./api/src/functions")
|
|
33
|
+
functions: path.join(BASE_PATH, "./api/src/functions"),
|
|
34
|
+
generators: path.join(BASE_PATH, "./api/generators")
|
|
35
35
|
},
|
|
36
36
|
web: {
|
|
37
37
|
base: path.join(BASE_PATH, "./web"),
|
|
38
38
|
config: path.join(BASE_PATH, "./web/config"),
|
|
39
39
|
src: path.join(BASE_PATH, "./web/src"),
|
|
40
|
-
generators: path.join(BASE_PATH, "./web/generators"),
|
|
41
40
|
routes: path.join(BASE_PATH, "web/src/Routes.js"),
|
|
42
41
|
components: path.join(BASE_PATH, "/web/src/components"),
|
|
43
42
|
layouts: path.join(BASE_PATH, "/web/src/layouts"),
|
|
44
43
|
pages: path.join(BASE_PATH, "/web/src/pages"),
|
|
45
|
-
app: path.join(BASE_PATH, "/web/src/App.js")
|
|
44
|
+
app: path.join(BASE_PATH, "/web/src/App.js"),
|
|
45
|
+
generators: path.join(BASE_PATH, "./web/generators")
|
|
46
46
|
},
|
|
47
47
|
scripts: path.join(BASE_PATH, "scripts"),
|
|
48
|
+
packages: path.join(BASE_PATH, "packages"),
|
|
49
|
+
generatorTemplates: path.join(BASE_PATH, "generatorTemplates"),
|
|
48
50
|
generated: {
|
|
49
51
|
base: path.join(BASE_PATH, ".redwood"),
|
|
50
52
|
schema: path.join(BASE_PATH, ".redwood/schema.graphql"),
|
|
@@ -6,7 +6,6 @@ import envinfo from "envinfo";
|
|
|
6
6
|
import system from "systeminformation";
|
|
7
7
|
import { v4 as uuidv4, validate as validateUUID } from "uuid";
|
|
8
8
|
import { getPaths, getRawConfig } from "@cedarjs/project-config";
|
|
9
|
-
import { DefaultHost } from "@cedarjs/structure/dist/hosts";
|
|
10
9
|
import { RWProject } from "@cedarjs/structure/dist/model/RWProject";
|
|
11
10
|
import {
|
|
12
11
|
name as packageName,
|
|
@@ -57,7 +56,6 @@ async function getResources() {
|
|
|
57
56
|
}
|
|
58
57
|
const experiments = Object.keys(getRawConfig()["experimental"] || {});
|
|
59
58
|
const project = new RWProject({
|
|
60
|
-
host: new DefaultHost(),
|
|
61
59
|
projectRoot: getPaths().base
|
|
62
60
|
});
|
|
63
61
|
const routes = project.getRouter().routes;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0-rc.34",
|
|
4
4
|
"description": "The CedarJS Command Line",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "tsx ./build.mts",
|
|
23
23
|
"build:pack": "yarn pack -o cedarjs-cli.tgz",
|
|
24
|
+
"build:types": "tsc --build --verbose ./tsconfig.build.json",
|
|
24
25
|
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build && yarn fix:permissions\"",
|
|
25
26
|
"dev": "RWJS_CWD=../../__fixtures__/example-todo-main node dist/index.js",
|
|
26
27
|
"fix:permissions": "chmod +x dist/index.js dist/cfw.js",
|
|
@@ -31,15 +32,15 @@
|
|
|
31
32
|
"dependencies": {
|
|
32
33
|
"@babel/preset-typescript": "7.28.5",
|
|
33
34
|
"@babel/runtime-corejs3": "7.28.4",
|
|
34
|
-
"@cedarjs/api-server": "2.
|
|
35
|
-
"@cedarjs/cli-helpers": "2.
|
|
36
|
-
"@cedarjs/fastify-web": "2.
|
|
37
|
-
"@cedarjs/internal": "2.
|
|
38
|
-
"@cedarjs/prerender": "2.
|
|
39
|
-
"@cedarjs/project-config": "2.
|
|
40
|
-
"@cedarjs/structure": "2.
|
|
41
|
-
"@cedarjs/telemetry": "2.
|
|
42
|
-
"@cedarjs/web-server": "2.
|
|
35
|
+
"@cedarjs/api-server": "2.3.0-rc.34",
|
|
36
|
+
"@cedarjs/cli-helpers": "2.3.0-rc.34",
|
|
37
|
+
"@cedarjs/fastify-web": "2.3.0-rc.34",
|
|
38
|
+
"@cedarjs/internal": "2.3.0-rc.34",
|
|
39
|
+
"@cedarjs/prerender": "2.3.0-rc.34",
|
|
40
|
+
"@cedarjs/project-config": "2.3.0-rc.34",
|
|
41
|
+
"@cedarjs/structure": "2.3.0-rc.34",
|
|
42
|
+
"@cedarjs/telemetry": "2.3.0-rc.34",
|
|
43
|
+
"@cedarjs/web-server": "2.3.0-rc.34",
|
|
43
44
|
"@listr2/prompt-adapter-enquirer": "2.0.16",
|
|
44
45
|
"@opentelemetry/api": "1.8.0",
|
|
45
46
|
"@opentelemetry/core": "1.22.0",
|
|
@@ -79,7 +80,7 @@
|
|
|
79
80
|
"semver": "7.7.3",
|
|
80
81
|
"smol-toml": "1.6.0",
|
|
81
82
|
"string-env-interpolation": "1.0.1",
|
|
82
|
-
"systeminformation": "5.28.
|
|
83
|
+
"systeminformation": "5.28.3",
|
|
83
84
|
"termi-link": "1.1.0",
|
|
84
85
|
"title-case": "3.0.3",
|
|
85
86
|
"unionfs": "4.6.0",
|
|
@@ -90,7 +91,7 @@
|
|
|
90
91
|
"devDependencies": {
|
|
91
92
|
"@babel/cli": "7.28.3",
|
|
92
93
|
"@babel/core": "^7.26.10",
|
|
93
|
-
"@types/archiver": "^
|
|
94
|
+
"@types/archiver": "^7.0.0",
|
|
94
95
|
"memfs": "4.51.1",
|
|
95
96
|
"node-ssh": "13.2.1",
|
|
96
97
|
"ts-dedent": "2.2.0",
|
|
@@ -101,5 +102,5 @@
|
|
|
101
102
|
"publishConfig": {
|
|
102
103
|
"access": "public"
|
|
103
104
|
},
|
|
104
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "5e54987a7f0b11f713a37ab49ca5abd7339f9411"
|
|
105
106
|
}
|