@cedarjs/cli 1.0.0-canary.12378 → 1.0.0-canary.12381

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.
@@ -18,11 +18,11 @@ const builder = (yargs) => {
18
18
  alias: "s",
19
19
  type: "boolean",
20
20
  default: false,
21
- description: "Silence Redwood's output, leaving only the script output"
21
+ description: "Silence CedarJS's output, leaving only the script output"
22
22
  }).strict(false).epilogue(
23
23
  `Also see the ${terminalLink(
24
- "Redwood CLI Reference",
25
- "https://redwoodjs.com/docs/cli-commands#up"
24
+ "CedarJS CLI Reference",
25
+ "https://cedarjs.com/docs/cli-commands#exec"
26
26
  )}`
27
27
  );
28
28
  };
@@ -6,7 +6,7 @@ import { Listr } from "listr2";
6
6
  import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
7
7
  import { findScripts } from "@cedarjs/internal/dist/files";
8
8
  import c from "../lib/colors.js";
9
- import { configureBabel, runScriptFunction } from "../lib/exec.js";
9
+ import { runScriptFunction } from "../lib/exec.js";
10
10
  import { generatePrismaClient } from "../lib/generatePrismaClient.js";
11
11
  import { getPaths } from "../lib/index.js";
12
12
  const printAvailableScriptsToConsole = () => {
@@ -56,7 +56,6 @@ No script called \`${name}\` in the ./scripts folder.
56
56
  printAvailableScriptsToConsole();
57
57
  process.exit(1);
58
58
  }
59
- configureBabel();
60
59
  const scriptTasks = [
61
60
  {
62
61
  title: "Generating Prisma client",
@@ -7,7 +7,8 @@ import { detectPrerenderRoutes } from "@cedarjs/prerender/detection";
7
7
  import { getConfig, getPaths } from "@cedarjs/project-config";
8
8
  import { errorTelemetry } from "@cedarjs/telemetry";
9
9
  import c from "../lib/colors.js";
10
- import { configureBabel, runScriptFunction } from "../lib/exec.js";
10
+ import { runScriptFunction } from "../lib/exec.js";
11
+ import { configureBabel } from "../lib/execBabel.js";
11
12
  class PathParamError extends Error {
12
13
  }
13
14
  const mapRouterPathToHtml = (routerPath) => {
package/dist/lib/exec.js CHANGED
@@ -1,85 +1,111 @@
1
- import { createRequire } from "node:module";
2
1
  import path from "node:path";
2
+ import { createServer, version as viteVersion } from "vite";
3
+ import { ViteNodeRunner } from "vite-node/client";
4
+ import { ViteNodeServer } from "vite-node/server";
5
+ import { installSourcemapsSupport } from "vite-node/source-map";
6
+ import { getConfig, getPaths } from "@cedarjs/project-config";
3
7
  import {
4
- getWebSideDefaultBabelConfig,
5
- registerApiSideBabelHook
6
- } from "@cedarjs/babel-config";
7
- import { getPaths } from "@cedarjs/project-config";
8
+ cedarCellTransform,
9
+ cedarjsDirectoryNamedImportPlugin,
10
+ cedarjsJobPathInjectorPlugin,
11
+ swapApolloProvider
12
+ } from "@cedarjs/vite/plugins";
8
13
  async function runScriptFunction({
9
14
  path: scriptPath,
10
15
  functionName,
11
16
  args
12
17
  }) {
13
- const createdRequire = createRequire(import.meta.url);
14
- const script = createdRequire(scriptPath);
15
- const returnValue = await script[functionName](args);
16
- try {
17
- const { db } = createdRequire(path.join(getPaths().api.lib, "db"));
18
- db.$disconnect();
19
- } catch (e) {
20
- }
21
- return returnValue;
22
- }
23
- function configureBabel() {
24
- const {
25
- overrides: _overrides,
26
- plugins: webPlugins,
27
- ...otherWebConfig
28
- } = getWebSideDefaultBabelConfig();
29
- registerApiSideBabelHook({
30
- plugins: [
31
- [
32
- "babel-plugin-module-resolver",
18
+ const rwConfig = getConfig();
19
+ const streamingEnabled = rwConfig?.experimental.streamingSsr.enabled;
20
+ const NODE_ENV = process.env.NODE_ENV;
21
+ process.env.NODE_ENV = "production";
22
+ const server = await createServer({
23
+ mode: "production",
24
+ optimizeDeps: {
25
+ // This is recommended in the vite-node readme
26
+ noDiscovery: true,
27
+ include: void 0
28
+ },
29
+ resolve: {
30
+ alias: [
31
+ {
32
+ find: /^\$api\//,
33
+ replacement: getPaths().api.base + "/"
34
+ },
35
+ {
36
+ find: /^\$web\//,
37
+ replacement: getPaths().web.base + "/"
38
+ },
39
+ {
40
+ find: /^api\//,
41
+ replacement: getPaths().api.base + "/"
42
+ },
33
43
  {
34
- alias: {
35
- $api: getPaths().api.base,
36
- $web: getPaths().web.base,
37
- api: getPaths().api.base,
38
- web: getPaths().web.base
39
- },
40
- loglevel: "silent"
41
- // to silence the unnecessary warnings
44
+ find: /^web\//,
45
+ replacement: getPaths().web.base + "/"
42
46
  },
43
- "exec-$side-module-resolver"
47
+ {
48
+ find: /^src\//,
49
+ replacement: "src/",
50
+ customResolver: (id, importer, _options) => {
51
+ if (importer.startsWith(getPaths().api.base)) {
52
+ return { id: id.replace("src", getPaths().api.src) };
53
+ } else if (importer.startsWith(getPaths().web.base)) {
54
+ return { id: id.replace("src", getPaths().web.src) };
55
+ }
56
+ return null;
57
+ }
58
+ }
44
59
  ]
45
- ],
46
- overrides: [
47
- {
48
- test: ["./api/"],
49
- plugins: [
50
- [
51
- "babel-plugin-module-resolver",
52
- {
53
- alias: {
54
- src: getPaths().api.src
55
- },
56
- loglevel: "silent"
57
- },
58
- "exec-api-src-module-resolver"
59
- ]
60
- ]
61
- },
62
- {
63
- test: ["./web/"],
64
- plugins: [
65
- ...webPlugins,
66
- [
67
- "babel-plugin-module-resolver",
68
- {
69
- alias: {
70
- src: getPaths().web.src
71
- },
72
- loglevel: "silent"
73
- },
74
- "exec-web-src-module-resolver"
75
- ]
76
- ],
77
- ...otherWebConfig
78
- }
60
+ },
61
+ plugins: [
62
+ cedarjsDirectoryNamedImportPlugin(),
63
+ cedarCellTransform(),
64
+ cedarjsJobPathInjectorPlugin(),
65
+ streamingEnabled && swapApolloProvider()
79
66
  ]
80
67
  });
68
+ if (Number(viteVersion.split(".")[0]) < 6) {
69
+ await server.pluginContainer.buildStart({});
70
+ }
71
+ const node = new ViteNodeServer(server, {
72
+ transformMode: {
73
+ ssr: [/.*/],
74
+ web: [/\/web\//]
75
+ },
76
+ deps: {
77
+ fallbackCJS: true
78
+ }
79
+ });
80
+ installSourcemapsSupport({
81
+ getSourceMap: (source) => node.getSourceMap(source)
82
+ });
83
+ const runner = new ViteNodeRunner({
84
+ root: server.config.root,
85
+ base: server.config.base,
86
+ fetchModule(id) {
87
+ return node.fetchModule(id);
88
+ },
89
+ resolveId(id, importer) {
90
+ return node.resolveId(id, importer);
91
+ }
92
+ });
93
+ let returnValue;
94
+ try {
95
+ const script = await runner.executeFile(scriptPath);
96
+ returnValue = script[functionName](args);
97
+ } catch (error) {
98
+ console.error(error);
99
+ }
100
+ try {
101
+ const { db } = await runner.executeFile(path.join(getPaths().api.lib, "db"));
102
+ db.$disconnect();
103
+ } catch (e) {
104
+ }
105
+ await server.close();
106
+ process.env.NODE_ENV = NODE_ENV;
107
+ return returnValue;
81
108
  }
82
109
  export {
83
- configureBabel,
84
110
  runScriptFunction
85
111
  };
@@ -0,0 +1,85 @@
1
+ import { createRequire } from "node:module";
2
+ import path from "node:path";
3
+ import {
4
+ getWebSideDefaultBabelConfig,
5
+ registerApiSideBabelHook
6
+ } from "@cedarjs/babel-config";
7
+ import { getPaths } from "@cedarjs/project-config";
8
+ async function runScriptFunction({
9
+ path: scriptPath,
10
+ functionName,
11
+ args
12
+ }) {
13
+ const createdRequire = createRequire(import.meta.url);
14
+ const script = createdRequire(scriptPath);
15
+ const returnValue = await script[functionName](args);
16
+ try {
17
+ const { db } = createdRequire(path.join(getPaths().api.lib, "db"));
18
+ db.$disconnect();
19
+ } catch (e) {
20
+ }
21
+ return returnValue;
22
+ }
23
+ function configureBabel() {
24
+ const {
25
+ overrides: _overrides,
26
+ plugins: webPlugins,
27
+ ...otherWebConfig
28
+ } = getWebSideDefaultBabelConfig();
29
+ registerApiSideBabelHook({
30
+ plugins: [
31
+ [
32
+ "babel-plugin-module-resolver",
33
+ {
34
+ alias: {
35
+ $api: getPaths().api.base,
36
+ $web: getPaths().web.base,
37
+ api: getPaths().api.base,
38
+ web: getPaths().web.base
39
+ },
40
+ loglevel: "silent"
41
+ // to silence the unnecessary warnings
42
+ },
43
+ "exec-$side-module-resolver"
44
+ ]
45
+ ],
46
+ overrides: [
47
+ {
48
+ test: ["./api/"],
49
+ plugins: [
50
+ [
51
+ "babel-plugin-module-resolver",
52
+ {
53
+ alias: {
54
+ src: getPaths().api.src
55
+ },
56
+ loglevel: "silent"
57
+ },
58
+ "exec-api-src-module-resolver"
59
+ ]
60
+ ]
61
+ },
62
+ {
63
+ test: ["./web/"],
64
+ plugins: [
65
+ ...webPlugins,
66
+ [
67
+ "babel-plugin-module-resolver",
68
+ {
69
+ alias: {
70
+ src: getPaths().web.src
71
+ },
72
+ loglevel: "silent"
73
+ },
74
+ "exec-web-src-module-resolver"
75
+ ]
76
+ ],
77
+ ...otherWebConfig
78
+ }
79
+ ]
80
+ });
81
+ }
82
+ export {
83
+ configureBabel,
84
+ runScriptFunction
85
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli",
3
- "version": "1.0.0-canary.12378+0c980b4f3",
3
+ "version": "1.0.0-canary.12381+f68e0d2f6",
4
4
  "description": "The Redwood Command Line",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,15 +29,15 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@babel/runtime-corejs3": "7.27.6",
32
- "@cedarjs/api-server": "1.0.0-canary.12378",
33
- "@cedarjs/cli-helpers": "1.0.0-canary.12378",
34
- "@cedarjs/fastify-web": "1.0.0-canary.12378",
35
- "@cedarjs/internal": "1.0.0-canary.12378",
36
- "@cedarjs/prerender": "1.0.0-canary.12378",
37
- "@cedarjs/project-config": "1.0.0-canary.12378",
38
- "@cedarjs/structure": "1.0.0-canary.12378",
39
- "@cedarjs/telemetry": "1.0.0-canary.12378",
40
- "@cedarjs/web-server": "1.0.0-canary.12378",
32
+ "@cedarjs/api-server": "1.0.0-canary.12381",
33
+ "@cedarjs/cli-helpers": "1.0.0-canary.12381",
34
+ "@cedarjs/fastify-web": "1.0.0-canary.12381",
35
+ "@cedarjs/internal": "1.0.0-canary.12381",
36
+ "@cedarjs/prerender": "1.0.0-canary.12381",
37
+ "@cedarjs/project-config": "1.0.0-canary.12381",
38
+ "@cedarjs/structure": "1.0.0-canary.12381",
39
+ "@cedarjs/telemetry": "1.0.0-canary.12381",
40
+ "@cedarjs/web-server": "1.0.0-canary.12381",
41
41
  "@listr2/prompt-adapter-enquirer": "2.0.12",
42
42
  "@opentelemetry/api": "1.8.0",
43
43
  "@opentelemetry/core": "1.22.0",
@@ -83,6 +83,7 @@
83
83
  "title-case": "3.0.3",
84
84
  "unionfs": "4.5.4",
85
85
  "uuid": "10.0.0",
86
+ "vite-node": "3.2.4",
86
87
  "yargs": "17.7.2"
87
88
  },
88
89
  "devDependencies": {
@@ -95,5 +96,5 @@
95
96
  "typescript": "5.6.2",
96
97
  "vitest": "3.2.4"
97
98
  },
98
- "gitHead": "0c980b4f364095c0bcfa2df4ce8c8d7f4c187d92"
99
+ "gitHead": "f68e0d2f6cc27c9b25edf9f3d6d7bb7b316e4247"
99
100
  }