@cedarjs/cli 9.0.0-canary.1784 → 9.0.0-canary.3124
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/README.md +7 -10
- package/dist/cfw.js +10 -6
- package/dist/commands/build/buildHandler.js +220 -45
- package/dist/commands/build/buildPackagesTask.js +21 -20
- package/dist/commands/build.js +13 -2
- package/dist/commands/check.js +4 -6
- package/dist/commands/console.js +6 -4
- package/dist/commands/deploy/baremetal/SshExecutor.js +13 -4
- package/dist/commands/deploy/baremetal/baremetalHandler.js +116 -50
- package/dist/commands/deploy/baremetal.js +11 -4
- package/dist/commands/deploy/flightcontrolHandler.js +28 -15
- package/dist/commands/deploy/helpers/deployHandler.js +11 -6
- package/dist/commands/deploy/netlify.js +1 -1
- package/dist/commands/deploy/packing/nft.js +1 -2
- package/dist/commands/deploy/render.js +1 -1
- package/dist/commands/deploy/renderHandler.js +24 -13
- package/dist/commands/deploy/serverlessHandler.js +69 -27
- package/dist/commands/deploy/vercel.js +1 -1
- package/dist/commands/destroy/component/component.js +2 -3
- package/dist/commands/destroy/directive/directive.js +1 -3
- package/dist/commands/destroy/directive/directiveHandler.js +2 -4
- package/dist/commands/destroy/function/function.js +1 -3
- package/dist/commands/destroy/handlerHelpers.js +17 -17
- package/dist/commands/destroy/helpers.js +8 -2
- package/dist/commands/destroy/layout/layout.js +1 -2
- package/dist/commands/destroy/page/pageHandler.js +3 -3
- package/dist/commands/destroy/scaffold/scaffoldHandler.js +31 -12
- package/dist/commands/destroy/sdl/sdlHandler.js +3 -3
- package/dist/commands/dev/apiDebugFlag.js +5 -4
- package/dist/commands/dev/devHandler.js +219 -68
- package/dist/commands/dev/packageWatchCommands.js +8 -3
- package/dist/commands/dev.js +16 -6
- package/dist/commands/execHandler.js +49 -29
- package/dist/commands/experimental/live-queries/liveQueries.js +32 -0
- package/dist/commands/experimental/live-queries/liveQueriesHandler.js +448 -0
- package/dist/commands/experimental/live-queries/templates/liveQueriesListener.ts.template +153 -0
- package/dist/commands/experimental/live-queries/templates/migration.sql.template +100 -0
- package/dist/commands/experimental/setupInngest.js +2 -2
- package/dist/commands/experimental/setupInngestHandler.js +13 -12
- package/dist/commands/experimental/setupOpentelemetry.js +2 -2
- package/dist/commands/experimental/setupOpentelemetryHandler.js +14 -10
- package/dist/commands/experimental/setupReactCompiler.js +2 -2
- package/dist/commands/experimental/setupReactCompilerHandler.js +48 -33
- package/dist/commands/experimental/setupRsc.js +1 -1
- package/dist/commands/experimental/setupRscHandler.js +20 -16
- package/dist/commands/experimental/setupStreamingSsr.js +2 -2
- package/dist/commands/experimental/setupStreamingSsrHandler.js +49 -34
- package/dist/commands/experimental/templates/opentelemetry.ts.template +2 -1
- package/dist/commands/experimental/templates/rsc/Document.tsx.template +1 -1
- package/dist/commands/experimental/templates/rsc/entry.client.tsx.template +8 -8
- package/dist/commands/experimental/templates/streamingSsr/Document.tsx.template +1 -1
- package/dist/commands/experimental/templates/streamingSsr/entry.client.tsx.template +6 -6
- package/dist/commands/experimental/templates/streamingSsr/tsconfig.json.template +6 -6
- package/dist/commands/experimental/util.js +27 -25
- package/dist/commands/experimental.js +3 -2
- package/dist/commands/generate/cell/cell.js +20 -0
- package/dist/commands/generate/cell/cellHandler.js +89 -40
- package/dist/commands/generate/cell/templates/cell.tsx.template +21 -2
- package/dist/commands/generate/cell/templates/cellFragment.tsx.template +43 -0
- package/dist/commands/generate/cell/templates/cellList.tsx.template +21 -2
- package/dist/commands/generate/cell/templates/storiesFragment.tsx.template +23 -0
- package/dist/commands/generate/cell/templates/test.js.template +1 -1
- package/dist/commands/generate/cell/templates/testFragment.js.template +30 -0
- package/dist/commands/generate/component/componentHandler.js +14 -16
- package/dist/commands/generate/dataMigration/dataMigration.js +36 -18
- package/dist/commands/generate/dataMigration/templates/dataMigration.js.template +1 -1
- package/dist/commands/generate/dataMigration/templates/dataMigration.ts.template +1 -1
- package/dist/commands/generate/dbAuth/dbAuth.js +1 -0
- package/dist/commands/generate/dbAuth/dbAuthHandler.js +63 -34
- package/dist/commands/generate/dbAuth/templates/login.oauth.tsx.template +164 -0
- package/dist/commands/generate/dbAuth/templates/signup.oauth.tsx.template +147 -0
- package/dist/commands/generate/directive/directiveHandler.js +14 -16
- package/dist/commands/generate/function/function.js +1 -0
- package/dist/commands/generate/function/functionHandler.js +14 -19
- package/dist/commands/generate/helpers.js +34 -18
- package/dist/commands/generate/job/job.js +1 -0
- package/dist/commands/generate/job/jobHandler.js +20 -24
- package/dist/commands/generate/layout/layoutHandler.js +13 -16
- package/dist/commands/generate/model/model.js +1 -0
- package/dist/commands/generate/model/modelHandler.js +11 -5
- package/dist/commands/generate/ogImage/ogImage.js +1 -0
- package/dist/commands/generate/ogImage/ogImageHandler.js +18 -11
- package/dist/commands/generate/package/filesTask.js +9 -0
- package/dist/commands/generate/package/packageHandler.js +50 -61
- package/dist/commands/generate/package/templates/test.ts.template +2 -2
- package/dist/commands/generate/package/templates/vitest.config.ts.template +9 -0
- package/dist/commands/generate/page/pageHandler.js +27 -24
- package/dist/commands/generate/realtime/realtime.js +2 -2
- package/dist/commands/generate/realtime/realtimeHandler.js +51 -32
- package/dist/commands/generate/realtime/templates/subscriptions/blank/blank.ts.template +1 -1
- package/dist/commands/generate/scaffold/scaffold.js +1 -0
- package/dist/commands/generate/scaffold/scaffoldHandler.js +176 -49
- package/dist/commands/generate/scaffold/templates/lib/formatters.tsx.template +1 -1
- package/dist/commands/generate/script/script.js +1 -0
- package/dist/commands/generate/script/scriptHandler.js +10 -6
- package/dist/commands/generate/script/templates/script.ts.template +9 -4
- package/dist/commands/generate/script/templates/tsconfig.json.template +16 -2
- package/dist/commands/generate/sdl/sdl.js +4 -3
- package/dist/commands/generate/sdl/sdlHandler.js +135 -46
- package/dist/commands/generate/sdl/stubFiles.js +132 -0
- package/dist/commands/generate/sdl/templates/sdl.js.template +2 -1
- package/dist/commands/generate/sdl/templates/sdl.ts.template +2 -1
- package/dist/commands/generate/secret/secret.js +20 -20
- package/dist/commands/generate/service/service.js +5 -5
- package/dist/commands/generate/service/serviceHandler.js +126 -61
- package/dist/commands/generate/service/templates/scenarios.ts.template +4 -2
- package/dist/commands/generate/service/templates/service.ts.template +22 -8
- package/dist/commands/generate/service/templates/test.ts.template +2 -2
- package/dist/commands/generate/yargsCommandHelpers.js +7 -2
- package/dist/commands/generate/yargsHandlerHelpers.js +20 -18
- package/dist/commands/generate.js +4 -4
- package/dist/commands/info.js +2 -2
- package/dist/commands/jobsHandler.js +7 -4
- package/dist/commands/lint.js +26 -69
- package/dist/commands/prerenderHandler.js +95 -58
- package/dist/commands/prismaHandler.js +51 -26
- package/dist/commands/record/init.js +2 -2
- package/dist/commands/record.js +4 -3
- package/dist/commands/serve.js +245 -31
- package/dist/commands/serveApiHandler.js +7 -6
- package/dist/commands/serveBothHandler.js +22 -13
- package/dist/commands/serveWebHandler.js +3 -2
- package/dist/commands/setup/auth/auth.js +15 -11
- package/dist/commands/setup/cache/cache.js +1 -1
- package/dist/commands/setup/cache/cacheHandler.js +15 -9
- package/dist/commands/setup/database/database.js +15 -0
- package/dist/commands/setup/database/postgres.js +19 -0
- package/dist/commands/setup/database/postgresHandler.js +196 -0
- package/dist/commands/setup/database/templates/db.ts.template +32 -0
- package/dist/commands/setup/deploy/deploy.js +4 -3
- package/dist/commands/setup/deploy/helpers/helpers.js +5 -1
- package/dist/commands/setup/deploy/helpers/index.js +132 -6
- package/dist/commands/setup/deploy/providers/baremetalHandler.js +28 -6
- package/dist/commands/setup/deploy/providers/coherence.js +1 -1
- package/dist/commands/setup/deploy/providers/coherenceHandler.js +60 -31
- package/dist/commands/setup/deploy/providers/flightcontrolHandler.js +69 -51
- package/dist/commands/setup/deploy/providers/netlify.js +6 -0
- package/dist/commands/setup/deploy/providers/netlifyHandler.js +114 -13
- package/dist/commands/setup/deploy/providers/renderHandler.js +44 -41
- package/dist/commands/setup/deploy/providers/serverlessHandler.js +7 -5
- package/dist/commands/setup/deploy/providers/universal-deploy.js +11 -0
- package/dist/commands/setup/deploy/providers/universalDeployHandler.js +186 -0
- package/dist/commands/setup/deploy/providers/vercel.js +6 -0
- package/dist/commands/setup/deploy/providers/vercelHandler.js +115 -14
- package/dist/commands/setup/deploy/templates/baremetal.js +3 -2
- package/dist/commands/setup/deploy/templates/flightcontrol.js +60 -49
- package/dist/commands/setup/deploy/templates/netlify.js +2 -1
- package/dist/commands/setup/deploy/templates/netlifyUD.js +31 -0
- package/dist/commands/setup/deploy/templates/render.js +32 -17
- package/dist/commands/setup/docker/docker.js +2 -2
- package/dist/commands/setup/docker/dockerHandler.js +74 -39
- package/dist/commands/setup/docker/templates/Dockerfile.npm +119 -0
- package/dist/commands/setup/docker/templates/Dockerfile.pnpm +112 -0
- package/dist/commands/setup/docker/templates/{Dockerfile → Dockerfile.yarn} +4 -7
- package/dist/commands/setup/docker/templates/docker-compose.dev.yml +3 -3
- package/dist/commands/setup/docker/templates/docker-compose.prod.yml +2 -5
- package/dist/commands/setup/docker/templates/dockerignore +1 -0
- package/dist/commands/setup/generator/generator.js +1 -1
- package/dist/commands/setup/generator/generatorHandler.js +5 -4
- package/dist/commands/setup/graphql/features/fragments/appGqlConfigTransform.js +6 -3
- package/dist/commands/setup/graphql/features/fragments/fragments.js +1 -1
- package/dist/commands/setup/graphql/features/fragments/fragmentsHandler.js +5 -7
- package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocuments.js +1 -1
- package/dist/commands/setup/graphql/features/trustedDocuments/trustedDocumentsHandler.js +4 -3
- package/dist/commands/setup/i18n/i18n.js +1 -1
- package/dist/commands/setup/i18n/i18nHandler.js +21 -17
- package/dist/commands/setup/jobs/jobs.js +1 -1
- package/dist/commands/setup/jobs/jobsHandler.js +17 -12
- package/dist/commands/setup/mailer/mailer.js +1 -1
- package/dist/commands/setup/mailer/mailerHandler.js +13 -11
- package/dist/commands/setup/middleware/ogImage/ogImage.js +1 -1
- package/dist/commands/setup/middleware/ogImage/ogImageHandler.js +2 -1
- package/dist/commands/setup/monitoring/sentry/sentry.js +1 -1
- package/dist/commands/setup/monitoring/sentry/sentryHandler.js +18 -12
- package/dist/commands/setup/neon/neon.js +35 -0
- package/dist/commands/setup/neon/neonHandler.js +264 -0
- package/dist/commands/setup/package/package.js +1 -1
- package/dist/commands/setup/package/packageHandler.js +18 -14
- package/dist/commands/setup/realtime/addRealtimeToGraphql.js +1 -1
- package/dist/commands/setup/realtime/realtime.js +1 -1
- package/dist/commands/setup/realtime/realtimeHandler.js +26 -37
- package/dist/commands/setup/realtime/templates/realtime.ts.template +1 -1
- package/dist/commands/setup/realtime/templates/subscriptions/countdown/countdown.ts.template +1 -1
- package/dist/commands/setup/realtime/templates/subscriptions/newMessage/newMessage.ts.template +1 -1
- package/dist/commands/setup/server-file/serverFile.js +1 -1
- package/dist/commands/setup/server-file/serverFileHandler.js +18 -10
- package/dist/commands/setup/tenancy/authCodemod.js +66 -0
- package/dist/commands/setup/tenancy/dbCodemod.js +64 -0
- package/dist/commands/setup/tenancy/graphqlCodemod.js +88 -0
- package/dist/commands/setup/tenancy/preflight.js +49 -0
- package/dist/commands/setup/tenancy/schemaPrisma.js +81 -0
- package/dist/commands/setup/tenancy/signupCodemod.js +153 -0
- package/dist/commands/setup/tenancy/templates/InvitePage.tsx.template +63 -0
- package/dist/commands/setup/tenancy/templates/OrgScope.tsx.template +40 -0
- package/dist/commands/setup/tenancy/templates/ensureDefaultOrganizations.dataMigration.ts.template +39 -0
- package/dist/commands/setup/tenancy/templates/organizations.scenarios.ts.template +59 -0
- package/dist/commands/setup/tenancy/templates/organizations.sdl.ts.template +89 -0
- package/dist/commands/setup/tenancy/templates/organizations.test.ts.template +389 -0
- package/dist/commands/setup/tenancy/templates/organizations.ts.template +394 -0
- package/dist/commands/setup/tenancy/templates/requireMembership.test.ts.template +35 -0
- package/dist/commands/setup/tenancy/templates/requireMembership.ts.template +25 -0
- package/dist/commands/setup/tenancy/tenancy.js +30 -0
- package/dist/commands/setup/tenancy/tenancyHandler.js +425 -0
- package/dist/commands/setup/ui/helpers/helpers.js +5 -1
- package/dist/commands/setup/ui/libraries/chakra-uiHandler.js +16 -8
- package/dist/commands/setup/ui/libraries/mantineHandler.js +26 -16
- package/dist/commands/setup/ui/libraries/tailwindcssHandler.js +40 -29
- package/dist/commands/setup/uploads/schemaPrisma.js +41 -0
- package/dist/commands/setup/uploads/serverFile.js +151 -0
- package/dist/commands/setup/uploads/templates/requireUploadToken.ts.template +15 -0
- package/dist/commands/setup/uploads/templates/srcLibUploads.ts.template +23 -24
- package/dist/commands/setup/uploads/templates/uploads.sdl.ts.template +79 -0
- package/dist/commands/setup/uploads/templates/uploads.ts.template +89 -0
- package/dist/commands/setup/uploads/templates/withDataUri.ts.template +14 -0
- package/dist/commands/setup/uploads/templates/withSignedUrl.ts.template +16 -0
- package/dist/commands/setup/uploads/uploads.js +49 -7
- package/dist/commands/setup/uploads/uploadsHandler.js +266 -72
- package/dist/commands/setup.js +5 -4
- package/dist/commands/studio.js +1 -1
- package/dist/commands/studioHandler.js +2 -2
- package/dist/commands/test/datasourceWarning.js +42 -0
- package/dist/commands/test/testHandler.js +104 -0
- package/dist/commands/test/viteVersionCheck.js +75 -0
- package/dist/commands/test.js +16 -19
- package/dist/commands/type-check.js +2 -1
- package/dist/commands/type-checkHandler.js +25 -18
- package/dist/commands/upgrade/preUpgradeScripts.js +11 -11
- package/dist/commands/upgrade/upgrade.js +4 -2
- package/dist/commands/upgrade/upgradeHandler.js +97 -73
- package/dist/index.js +15 -11
- package/dist/lib/background.js +22 -1
- package/dist/lib/configureStorybook.js +2 -2
- package/dist/lib/exec.js +68 -63
- package/dist/lib/exit.js +20 -5
- package/dist/lib/extendFile.js +23 -13
- package/dist/lib/generatePrismaClient.js +48 -12
- package/dist/lib/index.js +137 -106
- package/dist/lib/loadEnvFiles.js +1 -1
- package/dist/lib/locking.js +8 -4
- package/dist/lib/merge/algorithms.js +4 -1
- package/dist/lib/merge/index.js +78 -41
- package/dist/lib/merge/semanticIdentity.js +18 -6
- package/dist/lib/merge/strategy.js +86 -36
- package/dist/lib/packages.js +23 -13
- package/dist/lib/plugin.js +13 -7
- package/dist/lib/pluralHelpers.js +6 -2
- package/dist/lib/project.js +3 -1
- package/dist/lib/rollback.js +7 -7
- package/dist/lib/schemaHelpers.js +16 -19
- package/dist/lib/test.js +20 -5
- package/dist/lib/updateCheck.js +47 -18
- package/dist/middleware/checkNodeVersion.js +9 -4
- package/dist/middleware/{detectProjectRxVersion.js → detectProjectCedarVersion.js} +2 -2
- package/dist/plugin.js +18 -12
- package/dist/telemetry/exporter.js +12 -5
- package/dist/telemetry/index.js +4 -3
- package/dist/telemetry/resource.js +9 -12
- package/dist/telemetry/send.js +14 -10
- package/dist/testLib/cells.js +5 -3
- package/package.json +44 -41
- package/LICENSE +0 -21
- package/dist/commands/consoleHandler.js +0 -68
- package/dist/commands/setup/tsconfig/tsconfig.js +0 -25
- package/dist/commands/setup/tsconfig/tsconfigHandler.js +0 -59
- package/dist/commands/setup/uploads/dbCodemod.js +0 -28
- package/dist/commands/setup/uploads/templates/signedUrl.ts.template +0 -21
- package/dist/commands/setup/vite/templates/vite.config.ts.template +0 -19
- package/dist/commands/setup/vite/vite.js +0 -38
- package/dist/commands/setup/vite/viteHandler.js +0 -83
- package/dist/commands/testEsm.js +0 -36
- package/dist/commands/testHandler.js +0 -137
- package/dist/commands/testHandlerEsm.js +0 -85
- package/dist/commands/ts-to-js.js +0 -20
- package/dist/lib/cedarPluralize.js +0 -56
- package/dist/lib/colors.js +0 -18
- package/dist/testLib/getFilesWithPattern.js +0 -21
- /package/dist/{index.d.js → global.d.js} +0 -0
|
@@ -5,33 +5,36 @@ import execa from "execa";
|
|
|
5
5
|
import latestVersion from "latest-version";
|
|
6
6
|
import { Listr } from "listr2";
|
|
7
7
|
import { terminalLink } from "termi-link";
|
|
8
|
-
import {
|
|
8
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
9
|
+
import {
|
|
10
|
+
dedupe,
|
|
11
|
+
dedupeIsSupported,
|
|
12
|
+
install,
|
|
13
|
+
installationErrorMessage,
|
|
14
|
+
prettyPrintCedarCommand
|
|
15
|
+
} from "@cedarjs/cli-helpers/packageManager";
|
|
16
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
9
17
|
import { getConfig } from "@cedarjs/project-config";
|
|
10
|
-
import
|
|
18
|
+
import { getPackageManager } from "@cedarjs/project-config/packageManager";
|
|
11
19
|
import { generatePrismaClient } from "../../lib/generatePrismaClient.js";
|
|
12
20
|
import { getPaths } from "../../lib/index.js";
|
|
13
21
|
import { PLUGIN_CACHE_FILENAME } from "../../lib/plugin.js";
|
|
14
22
|
import { runPreUpgradeScripts } from "./preUpgradeScripts.js";
|
|
15
23
|
import { isValidCedarJSTag } from "./tags.js";
|
|
16
|
-
const handler = async ({
|
|
17
|
-
dryRun,
|
|
18
|
-
tag,
|
|
19
|
-
verbose,
|
|
20
|
-
dedupe,
|
|
21
|
-
yes,
|
|
22
|
-
force
|
|
23
|
-
}) => {
|
|
24
|
+
const handler = async (upgradeOptions) => {
|
|
25
|
+
const { dryRun, tag, verbose, dedupe: dedupe2, yes, force } = upgradeOptions;
|
|
24
26
|
recordTelemetryAttributes({
|
|
25
27
|
command: "upgrade",
|
|
26
28
|
dryRun: !!dryRun,
|
|
27
29
|
tag: tag ?? "latest",
|
|
28
30
|
verbose: !!verbose,
|
|
29
|
-
dedupe: !!
|
|
31
|
+
dedupe: !!dedupe2,
|
|
30
32
|
yes: !!yes,
|
|
31
33
|
force: !!force
|
|
32
34
|
});
|
|
33
35
|
let preUpgradeMessage = "";
|
|
34
36
|
let preUpgradeError = "";
|
|
37
|
+
const notBlockedByPreUpgradeChecks = (ctx) => force || !ctx.preUpgradeError;
|
|
35
38
|
const tasks = new Listr(
|
|
36
39
|
[
|
|
37
40
|
{
|
|
@@ -86,51 +89,57 @@ const handler = async ({
|
|
|
86
89
|
{
|
|
87
90
|
title: "Updating your CedarJS version",
|
|
88
91
|
task: (ctx) => updateCedarJSDepsForAllSides(ctx, { dryRun, verbose }),
|
|
89
|
-
enabled: (ctx) => !!ctx.versionToUpgradeTo &&
|
|
92
|
+
enabled: (ctx) => !!ctx.versionToUpgradeTo && notBlockedByPreUpgradeChecks(ctx)
|
|
90
93
|
},
|
|
91
94
|
{
|
|
92
95
|
title: "Updating other packages in your package.json(s)",
|
|
93
96
|
task: (ctx) => updatePackageVersionsFromTemplate(ctx, { dryRun, verbose }),
|
|
94
|
-
|
|
97
|
+
// Canary only. This forces the template's dependency versions onto the
|
|
98
|
+
// project and adds back any the project is missing, which resurrects
|
|
99
|
+
// packages people have deliberately removed — a project that moved off
|
|
100
|
+
// SQLite gets better-sqlite3 back, for example. That's too blunt for
|
|
101
|
+
// regular upgrades, but people running canary are already signed up
|
|
102
|
+
// for rougher edges.
|
|
103
|
+
// https://github.com/redwoodjs/redwood/pull/8855
|
|
104
|
+
enabled: (ctx) => String(ctx.versionToUpgradeTo).includes("canary") && notBlockedByPreUpgradeChecks(ctx)
|
|
95
105
|
},
|
|
96
106
|
{
|
|
97
107
|
title: "Downloading yarn patches",
|
|
98
108
|
task: (ctx) => downloadYarnPatches(ctx, { dryRun, verbose }),
|
|
99
|
-
enabled: (ctx) => String(ctx.versionToUpgradeTo).includes("canary") &&
|
|
109
|
+
enabled: (ctx) => String(ctx.versionToUpgradeTo).includes("canary") && notBlockedByPreUpgradeChecks(ctx)
|
|
100
110
|
},
|
|
101
111
|
{
|
|
102
112
|
title: "Removing CLI cache",
|
|
103
113
|
task: () => removeCliCache({ dryRun, verbose }),
|
|
104
|
-
enabled: (ctx) =>
|
|
114
|
+
enabled: (ctx) => notBlockedByPreUpgradeChecks(ctx)
|
|
105
115
|
},
|
|
106
116
|
{
|
|
107
|
-
title:
|
|
108
|
-
task: () =>
|
|
109
|
-
enabled: (ctx) =>
|
|
117
|
+
title: `Running ${getPackageManager()} ${install()}`,
|
|
118
|
+
task: () => packageManagerInstall({ verbose }),
|
|
119
|
+
enabled: (ctx) => notBlockedByPreUpgradeChecks(ctx),
|
|
110
120
|
skip: () => !!dryRun
|
|
111
121
|
},
|
|
112
122
|
{
|
|
113
123
|
title: "Refreshing the Prisma client",
|
|
114
124
|
task: (_ctx, task) => refreshPrismaClient(task, { verbose }),
|
|
115
|
-
enabled: (ctx) =>
|
|
125
|
+
enabled: (ctx) => notBlockedByPreUpgradeChecks(ctx),
|
|
116
126
|
skip: () => !!dryRun
|
|
117
127
|
},
|
|
118
128
|
{
|
|
119
129
|
title: "De-duplicating dependencies",
|
|
120
|
-
skip: () => !!dryRun || !
|
|
121
|
-
enabled: (ctx) =>
|
|
130
|
+
skip: () => !!dryRun || !dedupe2,
|
|
131
|
+
enabled: (ctx) => dedupeIsSupported() && notBlockedByPreUpgradeChecks(ctx),
|
|
122
132
|
task: (_ctx, task) => dedupeDeps(task, { verbose })
|
|
123
133
|
},
|
|
124
134
|
{
|
|
125
135
|
title: "One more thing..",
|
|
126
136
|
task: (ctx, task) => {
|
|
127
137
|
const version = ctx.versionToUpgradeTo;
|
|
138
|
+
const upgradeMessage = dryRun ? `\u{1F3C3} Dry run complete. Your project would be upgraded to CedarJS ${version}.` : `\u{1F389} Your project has been upgraded to CedarJS ${version}!`;
|
|
128
139
|
const messageSections = [
|
|
129
140
|
`One more thing...
|
|
130
141
|
|
|
131
|
-
${c.warning(
|
|
132
|
-
`\u{1F389} Your project has been upgraded to CedarJS ${version}!`
|
|
133
|
-
)}
|
|
142
|
+
${c.warning(upgradeMessage)}
|
|
134
143
|
|
|
135
144
|
`
|
|
136
145
|
];
|
|
@@ -188,21 +197,18 @@ const handler = async ({
|
|
|
188
197
|
}
|
|
189
198
|
if (preUpgradeMessage) {
|
|
190
199
|
console.log("");
|
|
191
|
-
console.log(` \u{1F4E3} ${c.info("Pre-upgrade
|
|
200
|
+
console.log(` \u{1F4E3} ${c.info("Pre-upgrade Script Messages:")}`);
|
|
192
201
|
console.log(" " + preUpgradeMessage.replace(/\n/g, "\n "));
|
|
193
202
|
}
|
|
194
203
|
};
|
|
195
|
-
async function
|
|
204
|
+
async function packageManagerInstall({ verbose }) {
|
|
196
205
|
try {
|
|
197
|
-
await execa(
|
|
198
|
-
shell: true,
|
|
206
|
+
await execa(getPackageManager(), [install()], {
|
|
199
207
|
stdio: verbose ? "inherit" : "pipe",
|
|
200
208
|
cwd: getPaths().base
|
|
201
209
|
});
|
|
202
210
|
} catch {
|
|
203
|
-
throw new Error(
|
|
204
|
-
"Could not finish installation. Please run `yarn install` and then `yarn dedupe`, before continuing"
|
|
205
|
-
);
|
|
211
|
+
throw new Error(installationErrorMessage());
|
|
206
212
|
}
|
|
207
213
|
}
|
|
208
214
|
async function removeCliCache({
|
|
@@ -306,6 +312,22 @@ function updateCedarJSDepsForAllSides(ctx, options) {
|
|
|
306
312
|
})
|
|
307
313
|
);
|
|
308
314
|
}
|
|
315
|
+
function mergeTemplateDependencies(field, templatePackageJson, localPackageJson, messages, { dryRun, verbose } = {}) {
|
|
316
|
+
const templateDeps = templatePackageJson[field];
|
|
317
|
+
if (!templateDeps) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
for (const [depName, depVersion] of Object.entries(templateDeps)) {
|
|
321
|
+
if (depName.startsWith("@cedarjs/")) {
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
const localDeps = localPackageJson[field] ??= {};
|
|
325
|
+
if (verbose || dryRun) {
|
|
326
|
+
messages.push(` - ${depName}: ${localDeps[depName]} => ${depVersion}`);
|
|
327
|
+
}
|
|
328
|
+
localDeps[depName] = depVersion;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
309
331
|
async function updatePackageVersionsFromTemplate(ctx, { dryRun, verbose }) {
|
|
310
332
|
if (!ctx.versionToUpgradeTo) {
|
|
311
333
|
throw new Error("Failed to upgrade");
|
|
@@ -331,35 +353,25 @@ async function updatePackageVersionsFromTemplate(ctx, { dryRun, verbose }) {
|
|
|
331
353
|
title: `Updating ${pkgJsonPath}`,
|
|
332
354
|
task: async (_ctx, task) => {
|
|
333
355
|
const res = await fetch(url);
|
|
356
|
+
if (!res.ok) {
|
|
357
|
+
throw new Error(
|
|
358
|
+
`Failed to fetch template package.json from ${url}: ` + res.statusText
|
|
359
|
+
);
|
|
360
|
+
}
|
|
334
361
|
const text = await res.text();
|
|
335
362
|
const templatePackageJson = JSON.parse(text);
|
|
336
363
|
const localPackageJsonText = fs.readFileSync(pkgJsonPath, "utf-8");
|
|
337
364
|
const localPackageJson = JSON.parse(localPackageJsonText);
|
|
338
365
|
const messages = [];
|
|
339
|
-
|
|
340
|
-
(
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
);
|
|
351
|
-
Object.entries(templatePackageJson.devDependencies || {}).forEach(
|
|
352
|
-
([depName, depVersion]) => {
|
|
353
|
-
if (!depName.startsWith("@cedarjs/")) {
|
|
354
|
-
if (verbose || dryRun) {
|
|
355
|
-
messages.push(
|
|
356
|
-
` - ${depName}: ${localPackageJson.devDependencies[depName]} => ${depVersion}`
|
|
357
|
-
);
|
|
358
|
-
}
|
|
359
|
-
localPackageJson.devDependencies[depName] = depVersion;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
);
|
|
366
|
+
for (const field of ["dependencies", "devDependencies"]) {
|
|
367
|
+
mergeTemplateDependencies(
|
|
368
|
+
field,
|
|
369
|
+
templatePackageJson,
|
|
370
|
+
localPackageJson,
|
|
371
|
+
messages,
|
|
372
|
+
{ dryRun, verbose }
|
|
373
|
+
);
|
|
374
|
+
}
|
|
363
375
|
if (messages.length > 0) {
|
|
364
376
|
task.title = task.title + "\n" + messages.join("\n");
|
|
365
377
|
}
|
|
@@ -380,16 +392,19 @@ async function downloadYarnPatches(ctx, { dryRun, verbose }) {
|
|
|
380
392
|
throw new Error("Failed to upgrade");
|
|
381
393
|
}
|
|
382
394
|
const githubToken = process.env.GH_TOKEN || process.env.GITHUB_TOKEN || process.env.REDWOOD_GITHUB_TOKEN;
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
{
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
Accept: "application/vnd.github+json"
|
|
390
|
-
}
|
|
395
|
+
const url = "https://api.github.com/repos/cedarjs/cedar/git/trees/main?recursive=1";
|
|
396
|
+
const res = await fetch(url, {
|
|
397
|
+
headers: {
|
|
398
|
+
...githubToken && { Authorization: `Bearer ${githubToken}` },
|
|
399
|
+
["X-GitHub-Api-Version"]: "2022-11-28",
|
|
400
|
+
Accept: "application/vnd.github+json"
|
|
391
401
|
}
|
|
392
|
-
);
|
|
402
|
+
});
|
|
403
|
+
if (!res.ok) {
|
|
404
|
+
throw new Error(
|
|
405
|
+
`Failed to fetch list of yarn patches from ${url}: ` + res.statusText
|
|
406
|
+
);
|
|
407
|
+
}
|
|
393
408
|
const json = await res.json();
|
|
394
409
|
const patches = json.tree?.filter(
|
|
395
410
|
(patchInfo) => patchInfo.path.startsWith(
|
|
@@ -409,6 +424,11 @@ async function downloadYarnPatches(ctx, { dryRun, verbose }) {
|
|
|
409
424
|
title: `Downloading ${patch.path}`,
|
|
410
425
|
task: async () => {
|
|
411
426
|
const res2 = await fetch(patch.url);
|
|
427
|
+
if (!res2.ok) {
|
|
428
|
+
throw new Error(
|
|
429
|
+
`Failed to fetch patch metadata from ${patch.url}: ` + res2.statusText
|
|
430
|
+
);
|
|
431
|
+
}
|
|
412
432
|
const patchMeta = await res2.json();
|
|
413
433
|
const patchPath = path.join(
|
|
414
434
|
getPaths().base,
|
|
@@ -429,20 +449,23 @@ async function downloadYarnPatches(ctx, { dryRun, verbose }) {
|
|
|
429
449
|
}
|
|
430
450
|
async function refreshPrismaClient(task, { verbose }) {
|
|
431
451
|
try {
|
|
432
|
-
await generatePrismaClient({ verbose, force:
|
|
452
|
+
await generatePrismaClient({ verbose, force: true });
|
|
433
453
|
} catch (e) {
|
|
434
454
|
const message = e instanceof Error ? e.message : String(e);
|
|
435
455
|
task.skip("Refreshing the Prisma client caused an Error.");
|
|
436
456
|
console.log(
|
|
437
|
-
"You may need to update your prisma client manually: $
|
|
457
|
+
"You may need to update your prisma client manually: $ " + prettyPrintCedarCommand(["prisma", "generate"])
|
|
438
458
|
);
|
|
439
459
|
console.log(c.error(message));
|
|
440
460
|
}
|
|
441
461
|
}
|
|
442
|
-
|
|
462
|
+
async function dedupeDeps(_task, { verbose }) {
|
|
463
|
+
const dedupeCmd = dedupe();
|
|
464
|
+
if (!dedupeCmd) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
443
467
|
try {
|
|
444
|
-
await execa(
|
|
445
|
-
shell: true,
|
|
468
|
+
await execa(getPackageManager(), [dedupeCmd], {
|
|
446
469
|
stdio: verbose ? "inherit" : "pipe",
|
|
447
470
|
cwd: getPaths().base
|
|
448
471
|
});
|
|
@@ -450,11 +473,12 @@ const dedupeDeps = async (_task, { verbose }) => {
|
|
|
450
473
|
const message = e instanceof Error ? e.message : String(e);
|
|
451
474
|
console.log(c.error(message));
|
|
452
475
|
throw new Error(
|
|
453
|
-
|
|
476
|
+
`Could not finish de-duplication. Please run \`${getPackageManager()} ${dedupeCmd}\` before continuing`
|
|
454
477
|
);
|
|
455
478
|
}
|
|
456
|
-
await
|
|
457
|
-
}
|
|
479
|
+
await packageManagerInstall({ verbose });
|
|
480
|
+
}
|
|
458
481
|
export {
|
|
459
|
-
handler
|
|
482
|
+
handler,
|
|
483
|
+
mergeTemplateDependencies
|
|
460
484
|
};
|
package/dist/index.js
CHANGED
|
@@ -4,8 +4,10 @@ import path from "path";
|
|
|
4
4
|
import { trace, SpanStatusCode } from "@opentelemetry/api";
|
|
5
5
|
import { hideBin, Parser } from "yargs/helpers";
|
|
6
6
|
import yargs from "yargs/yargs";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { colors as c } from "@cedarjs/cli-helpers/colors";
|
|
8
|
+
import { loadEnvFiles } from "@cedarjs/cli-helpers/loadEnvFiles";
|
|
9
|
+
import { recordTelemetryAttributes } from "@cedarjs/cli-helpers/telemetry";
|
|
10
|
+
import { findUp, getConfigPath } from "@cedarjs/project-config";
|
|
9
11
|
import { telemetryMiddleware } from "@cedarjs/telemetry";
|
|
10
12
|
import * as buildCommand from "./commands/build.js";
|
|
11
13
|
import * as checkCommand from "./commands/check.js";
|
|
@@ -26,29 +28,31 @@ import * as serveCommand from "./commands/serve.js";
|
|
|
26
28
|
import * as setupCommand from "./commands/setup.js";
|
|
27
29
|
import * as studioCommand from "./commands/studio.js";
|
|
28
30
|
import * as testCommand from "./commands/test.js";
|
|
29
|
-
import * as testCommandEsm from "./commands/testEsm.js";
|
|
30
|
-
import * as tstojsCommand from "./commands/ts-to-js.js";
|
|
31
31
|
import * as typeCheckCommand from "./commands/type-check.js";
|
|
32
32
|
import * as upgradeCommand from "./commands/upgrade/upgrade.js";
|
|
33
|
-
import c from "./lib/colors.js";
|
|
34
33
|
import { exitWithError } from "./lib/exit.js";
|
|
35
34
|
import * as updateCheck from "./lib/updateCheck.js";
|
|
36
35
|
import { loadPlugins } from "./plugin.js";
|
|
37
36
|
import { startTelemetry, shutdownTelemetry } from "./telemetry/index.js";
|
|
38
|
-
|
|
37
|
+
const {
|
|
38
|
+
telemetry,
|
|
39
|
+
help,
|
|
40
|
+
version,
|
|
41
|
+
cwd: parsedCwd
|
|
42
|
+
} = Parser(hideBin(process.argv), {
|
|
39
43
|
// Telemetry is enabled by default, but can be disabled in two ways
|
|
40
44
|
// - by passing a `--telemetry false` option
|
|
41
|
-
// - by setting a `
|
|
45
|
+
// - by setting a `CEDAR_DISABLE_TELEMETRY` env var
|
|
42
46
|
boolean: ["telemetry"],
|
|
43
47
|
default: {
|
|
44
|
-
telemetry: process.env.REDWOOD_DISABLE_TELEMETRY === void 0 || process.env.REDWOOD_DISABLE_TELEMETRY === ""
|
|
48
|
+
telemetry: (process.env.CEDAR_DISABLE_TELEMETRY === void 0 || process.env.CEDAR_DISABLE_TELEMETRY === "") && (process.env.REDWOOD_DISABLE_TELEMETRY === void 0 || process.env.REDWOOD_DISABLE_TELEMETRY === "")
|
|
45
49
|
}
|
|
46
50
|
});
|
|
51
|
+
let cwd = parsedCwd;
|
|
47
52
|
cwd ??= process.env.CEDAR_CWD;
|
|
48
53
|
cwd ??= process.env.RWJS_CWD;
|
|
49
54
|
cwd = getTomlDir(cwd);
|
|
50
55
|
process.env.CEDAR_CWD = cwd;
|
|
51
|
-
process.env.RWJS_CWD = cwd;
|
|
52
56
|
if (process.argv[1]?.endsWith("redwood.js")) {
|
|
53
57
|
const tomlPath = getConfigPath(cwd);
|
|
54
58
|
const toml = fs.readFileSync(tomlPath, "utf8");
|
|
@@ -127,7 +131,7 @@ async function runYargs() {
|
|
|
127
131
|
}).example(
|
|
128
132
|
"yarn cedar g page home /",
|
|
129
133
|
"Create a page component named 'Home' at path '/'"
|
|
130
|
-
).demandCommand().strict().exitProcess(false).alias("h", "help").command(buildCommand).command(checkCommand).command(consoleCommand).command(deployCommand).command(destroyCommand).command(devCommand).command(execCommand).command(experimentalCommand).command(generateCommand).command(infoCommand).command(jobsCommand).command(lintCommand).command(prerenderCommand).command(prismaCommand).command(recordCommand).command(serveCommand).command(setupCommand).command(studioCommand).command(
|
|
134
|
+
).demandCommand().strict().exitProcess(false).alias("h", "help").command(buildCommand).command(checkCommand).command(consoleCommand).command(deployCommand).command(destroyCommand).command(devCommand).command(execCommand).command(experimentalCommand).command(generateCommand).command(infoCommand).command(jobsCommand).command(lintCommand).command(prerenderCommand).command(prismaCommand).command(recordCommand).command(serveCommand).command(setupCommand).command(studioCommand).command(testCommand).command(typeCheckCommand).command(upgradeCommand);
|
|
131
135
|
await loadPlugins(yarg);
|
|
132
136
|
const pkgJson = await import("../package.json", { with: { type: "json" } });
|
|
133
137
|
yarg.version(pkgJson.default["version"]);
|
|
@@ -166,7 +170,7 @@ function getTomlDir(cwd2) {
|
|
|
166
170
|
tomlDir = path.dirname(configTomlPath);
|
|
167
171
|
}
|
|
168
172
|
} catch (error) {
|
|
169
|
-
console.error(error.message);
|
|
173
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
170
174
|
process.exit(1);
|
|
171
175
|
}
|
|
172
176
|
return tomlDir;
|
package/dist/lib/background.js
CHANGED
|
@@ -3,6 +3,23 @@ import fs from "node:fs";
|
|
|
3
3
|
import os from "os";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { getPaths } from "@cedarjs/project-config";
|
|
6
|
+
function quoteForWindowsShell(arg) {
|
|
7
|
+
let quoted = '"';
|
|
8
|
+
let backslashes = 0;
|
|
9
|
+
for (const char of arg) {
|
|
10
|
+
if (char === "\\") {
|
|
11
|
+
backslashes += 1;
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (char === '"') {
|
|
15
|
+
quoted += "\\".repeat(backslashes * 2 + 1) + '"';
|
|
16
|
+
} else {
|
|
17
|
+
quoted += "\\".repeat(backslashes) + char;
|
|
18
|
+
}
|
|
19
|
+
backslashes = 0;
|
|
20
|
+
}
|
|
21
|
+
return quoted + "\\".repeat(backslashes * 2) + '"';
|
|
22
|
+
}
|
|
6
23
|
function spawnBackgroundProcess(name, cmd, args) {
|
|
7
24
|
const logDirectory = path.join(getPaths().generated.base, "logs");
|
|
8
25
|
fs.mkdirSync(logDirectory, { recursive: true });
|
|
@@ -37,7 +54,8 @@ function spawnBackgroundProcess(name, cmd, args) {
|
|
|
37
54
|
shell: true,
|
|
38
55
|
stdio: ["ignore", stdout, stderr]
|
|
39
56
|
};
|
|
40
|
-
const
|
|
57
|
+
const command = [cmd, ...args].map(quoteForWindowsShell).join(" ");
|
|
58
|
+
const child = spawn(command, spawnOptions);
|
|
41
59
|
child.unref();
|
|
42
60
|
} else {
|
|
43
61
|
const spawnOptions = {
|
|
@@ -47,7 +65,10 @@ function spawnBackgroundProcess(name, cmd, args) {
|
|
|
47
65
|
const child = spawn(cmd, args, spawnOptions);
|
|
48
66
|
child.unref();
|
|
49
67
|
}
|
|
68
|
+
fs.closeSync(stdout);
|
|
69
|
+
fs.closeSync(stderr);
|
|
50
70
|
}
|
|
51
71
|
export {
|
|
72
|
+
quoteForWindowsShell,
|
|
52
73
|
spawnBackgroundProcess
|
|
53
74
|
};
|
|
@@ -10,11 +10,11 @@ import {
|
|
|
10
10
|
} from "./merge/strategy.js";
|
|
11
11
|
import { isTypeScriptProject } from "./project.js";
|
|
12
12
|
import { getPaths, transformTSToJS, writeFile } from "./index.js";
|
|
13
|
-
async function extendStorybookConfiguration(newConfigPath
|
|
13
|
+
async function extendStorybookConfiguration(newConfigPath) {
|
|
14
14
|
const webPaths = getPaths().web;
|
|
15
15
|
const ts = isTypeScriptProject();
|
|
16
16
|
const sbPreviewConfigPath = webPaths.storybookPreviewConfig ?? `${webPaths.storybook}/preview.${ts ? "tsx" : "js"}`;
|
|
17
|
-
const read = (
|
|
17
|
+
const read = (filePath) => fse.readFileSync(filePath, { encoding: "utf-8" });
|
|
18
18
|
if (!fse.existsSync(sbPreviewConfigPath)) {
|
|
19
19
|
const templateContent = read(
|
|
20
20
|
path.resolve(
|
package/dist/lib/exec.js
CHANGED
|
@@ -1,17 +1,38 @@
|
|
|
1
|
+
import { existsSync, statSync } from "node:fs";
|
|
1
2
|
import path from "node:path";
|
|
2
|
-
import { createServer,
|
|
3
|
-
import { ViteNodeRunner } from "vite-node/client";
|
|
4
|
-
import { ViteNodeServer } from "vite-node/server";
|
|
5
|
-
import { installSourcemapsSupport } from "vite-node/source-map";
|
|
3
|
+
import { createServer, isRunnableDevEnvironment } from "vite";
|
|
6
4
|
import { getPaths, importStatementPath } from "@cedarjs/project-config";
|
|
7
5
|
import {
|
|
8
6
|
cedarCellTransform,
|
|
9
|
-
|
|
7
|
+
cedarjsResolveCedarStyleImportsPlugin,
|
|
10
8
|
cedarjsJobPathInjectorPlugin,
|
|
11
9
|
cedarSwapApolloProvider,
|
|
12
10
|
cedarImportDirPlugin,
|
|
13
|
-
cedarAutoImportsPlugin
|
|
11
|
+
cedarAutoImportsPlugin,
|
|
12
|
+
cedarCjsCompatPlugin
|
|
14
13
|
} from "@cedarjs/vite";
|
|
14
|
+
function resolveId(id) {
|
|
15
|
+
if (existsSync(id) && statSync(id).isFile()) {
|
|
16
|
+
return id;
|
|
17
|
+
}
|
|
18
|
+
const withoutExt = /\.jsx?$/.test(id) ? id.replace(/\.jsx?$/, "") : id;
|
|
19
|
+
for (const ext of [".ts", ".tsx", ".js", ".jsx"]) {
|
|
20
|
+
if (existsSync(withoutExt + ext)) {
|
|
21
|
+
return withoutExt + ext;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (existsSync(id) && statSync(id).isDirectory()) {
|
|
25
|
+
for (const base of ["index", path.basename(id)]) {
|
|
26
|
+
for (const ext of [".ts", ".tsx", ".js", ".jsx"]) {
|
|
27
|
+
const candidate = path.join(id, base + ext);
|
|
28
|
+
if (existsSync(candidate)) {
|
|
29
|
+
return candidate;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return id;
|
|
35
|
+
}
|
|
15
36
|
async function runScriptFunction({
|
|
16
37
|
path: scriptPath,
|
|
17
38
|
functionName,
|
|
@@ -22,24 +43,27 @@ async function runScriptFunction({
|
|
|
22
43
|
const server = await createServer({
|
|
23
44
|
mode: "production",
|
|
24
45
|
optimizeDeps: {
|
|
25
|
-
// This is recommended in the vite-node readme
|
|
26
46
|
noDiscovery: true,
|
|
27
47
|
include: void 0
|
|
28
48
|
},
|
|
49
|
+
server: {
|
|
50
|
+
hmr: false,
|
|
51
|
+
watch: null
|
|
52
|
+
},
|
|
53
|
+
environments: {
|
|
54
|
+
nodeRunnerEnv: {}
|
|
55
|
+
},
|
|
29
56
|
resolve: {
|
|
57
|
+
// `$api/` and `api/` imports are handled by
|
|
58
|
+
// cedarjsResolveCedarStyleImportsPlugin below, which also resolves
|
|
59
|
+
// Cedar's directory named modules (`$api/src/services/posts` ->
|
|
60
|
+
// posts/posts.ts) and leaves an actual `api` npm package alone. The web
|
|
61
|
+
// side equivalents have no plugin support, so they stay aliases
|
|
30
62
|
alias: [
|
|
31
|
-
{
|
|
32
|
-
find: /^\$api\//,
|
|
33
|
-
replacement: getPaths().api.base + "/"
|
|
34
|
-
},
|
|
35
63
|
{
|
|
36
64
|
find: /^\$web\//,
|
|
37
65
|
replacement: getPaths().web.base + "/"
|
|
38
66
|
},
|
|
39
|
-
{
|
|
40
|
-
find: /^api\//,
|
|
41
|
-
replacement: getPaths().api.base + "/"
|
|
42
|
-
},
|
|
43
67
|
{
|
|
44
68
|
find: /^web\//,
|
|
45
69
|
replacement: getPaths().web.base + "/"
|
|
@@ -50,20 +74,14 @@ async function runScriptFunction({
|
|
|
50
74
|
customResolver: (id, importer, _options) => {
|
|
51
75
|
const apiImportBase = importStatementPath(getPaths().api.base);
|
|
52
76
|
const webImportBase = importStatementPath(getPaths().web.base);
|
|
53
|
-
if (importer
|
|
77
|
+
if (importer?.startsWith(apiImportBase)) {
|
|
54
78
|
const apiImportSrc = importStatementPath(getPaths().api.src);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
return { id: resolvedId };
|
|
60
|
-
} else if (importer.startsWith(webImportBase)) {
|
|
79
|
+
const apiId = id.replace("src", apiImportSrc);
|
|
80
|
+
return { id: resolveId(apiId) };
|
|
81
|
+
} else if (importer?.startsWith(webImportBase)) {
|
|
61
82
|
const webImportSrc = importStatementPath(getPaths().web.src);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
resolvedId = resolvedId.replace(/\.jsx?$/, "");
|
|
65
|
-
}
|
|
66
|
-
return { id: resolvedId };
|
|
83
|
+
const webId = id.replace("src", webImportSrc);
|
|
84
|
+
return { id: resolveId(webId) };
|
|
67
85
|
}
|
|
68
86
|
return null;
|
|
69
87
|
}
|
|
@@ -71,7 +89,8 @@ async function runScriptFunction({
|
|
|
71
89
|
]
|
|
72
90
|
},
|
|
73
91
|
plugins: [
|
|
74
|
-
|
|
92
|
+
cedarCjsCompatPlugin(),
|
|
93
|
+
cedarjsResolveCedarStyleImportsPlugin(),
|
|
75
94
|
cedarCellTransform(),
|
|
76
95
|
cedarjsJobPathInjectorPlugin(),
|
|
77
96
|
cedarSwapApolloProvider(),
|
|
@@ -79,47 +98,33 @@ async function runScriptFunction({
|
|
|
79
98
|
cedarAutoImportsPlugin()
|
|
80
99
|
]
|
|
81
100
|
});
|
|
82
|
-
|
|
83
|
-
|
|
101
|
+
const env = server.environments.nodeRunnerEnv;
|
|
102
|
+
if (!env || !isRunnableDevEnvironment(env)) {
|
|
103
|
+
await server.close();
|
|
104
|
+
throw new Error("Vite environment is not runnable.");
|
|
84
105
|
}
|
|
85
|
-
const node = new ViteNodeServer(server, {
|
|
86
|
-
transformMode: {
|
|
87
|
-
ssr: [/.*/],
|
|
88
|
-
web: [/\/web\//]
|
|
89
|
-
},
|
|
90
|
-
deps: {
|
|
91
|
-
fallbackCJS: true
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
installSourcemapsSupport({
|
|
95
|
-
getSourceMap: (source) => node.getSourceMap(source)
|
|
96
|
-
});
|
|
97
|
-
const runner = new ViteNodeRunner({
|
|
98
|
-
root: server.config.root,
|
|
99
|
-
base: server.config.base,
|
|
100
|
-
fetchModule(id) {
|
|
101
|
-
return node.fetchModule(id);
|
|
102
|
-
},
|
|
103
|
-
resolveId(id, importer) {
|
|
104
|
-
return node.resolveId(id, importer);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
106
|
let returnValue;
|
|
108
107
|
try {
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
108
|
+
const module = await env.runner.import(scriptPath);
|
|
109
|
+
const fn = module[functionName];
|
|
110
|
+
if (typeof fn !== "function") {
|
|
111
|
+
throw new Error(`Function '${functionName}' not found in script`);
|
|
112
|
+
}
|
|
113
|
+
returnValue = await fn(args);
|
|
114
|
+
} finally {
|
|
115
|
+
try {
|
|
116
|
+
const dbModule = await env.runner.import(
|
|
117
|
+
path.join(getPaths().api.lib, "db")
|
|
118
|
+
);
|
|
119
|
+
dbModule.db?.$disconnect?.();
|
|
120
|
+
} catch {
|
|
121
|
+
}
|
|
122
|
+
await server.close();
|
|
123
|
+
process.env.NODE_ENV = NODE_ENV;
|
|
118
124
|
}
|
|
119
|
-
await server.close();
|
|
120
|
-
process.env.NODE_ENV = NODE_ENV;
|
|
121
125
|
return returnValue;
|
|
122
126
|
}
|
|
123
127
|
export {
|
|
128
|
+
resolveId,
|
|
124
129
|
runScriptFunction
|
|
125
130
|
};
|
package/dist/lib/exit.js
CHANGED
|
@@ -4,7 +4,7 @@ import { v4 as uuidv4 } from "uuid";
|
|
|
4
4
|
import {
|
|
5
5
|
recordTelemetryAttributes,
|
|
6
6
|
recordTelemetryError
|
|
7
|
-
} from "@cedarjs/cli-helpers";
|
|
7
|
+
} from "@cedarjs/cli-helpers/telemetry";
|
|
8
8
|
const discordLink = terminalLink("Discord", "https://cedarjs.com/discord");
|
|
9
9
|
const githubLink = terminalLink("GitHub", "https://github.com/cedarjs/cedar");
|
|
10
10
|
const DEFAULT_ERROR_EPILOGUE = [
|
|
@@ -12,12 +12,27 @@ const DEFAULT_ERROR_EPILOGUE = [
|
|
|
12
12
|
` - Not sure about something or need advice? Reach out on our ${discordLink}`,
|
|
13
13
|
` - Think you've found a bug? Open an issue on our ${githubLink}`
|
|
14
14
|
].join("\n");
|
|
15
|
-
function exitWithError(error, {
|
|
16
|
-
exitCode
|
|
15
|
+
function exitWithError(error, {
|
|
16
|
+
exitCode,
|
|
17
|
+
message,
|
|
18
|
+
epilogue,
|
|
19
|
+
includeEpilogue,
|
|
20
|
+
includeReferenceCode
|
|
21
|
+
} = {}) {
|
|
22
|
+
if (error && typeof error === "object" && "exitCode" in error) {
|
|
23
|
+
exitCode ??= typeof error.exitCode === "number" ? error.exitCode : 1;
|
|
24
|
+
}
|
|
25
|
+
exitCode ??= 1;
|
|
17
26
|
epilogue ??= DEFAULT_ERROR_EPILOGUE;
|
|
18
27
|
includeEpilogue ??= true;
|
|
19
28
|
includeReferenceCode ??= true;
|
|
20
|
-
message
|
|
29
|
+
if (message === void 0) {
|
|
30
|
+
if (error instanceof Error && error.stack) {
|
|
31
|
+
message = error.stack;
|
|
32
|
+
} else {
|
|
33
|
+
message = String(error) || "Unknown error";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
21
36
|
const errorReferenceCode = uuidv4();
|
|
22
37
|
const line = ansis.red("-".repeat(process.stderr.columns - 4));
|
|
23
38
|
const content = !includeEpilogue ? message : [
|
|
@@ -31,7 +46,7 @@ ${line}`,
|
|
|
31
46
|
line
|
|
32
47
|
].filter(Boolean).join("\n");
|
|
33
48
|
console.error(content);
|
|
34
|
-
recordTelemetryError(error ?? new Error(message));
|
|
49
|
+
recordTelemetryError(error ?? new Error(message ?? ""));
|
|
35
50
|
recordTelemetryAttributes({ errorReferenceCode });
|
|
36
51
|
process.exit(exitCode);
|
|
37
52
|
}
|