@cedarjs/cli 0.2.1-next.0 → 0.3.0

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
  };
@@ -3,10 +3,6 @@ import path from "node:path";
3
3
  import { context } from "@opentelemetry/api";
4
4
  import { suppressTracing } from "@opentelemetry/core";
5
5
  import { Listr } from "listr2";
6
- import {
7
- getWebSideDefaultBabelConfig,
8
- registerApiSideBabelHook
9
- } from "@cedarjs/babel-config";
10
6
  import { recordTelemetryAttributes } from "@cedarjs/cli-helpers";
11
7
  import { findScripts } from "@cedarjs/internal/dist/files";
12
8
  import c from "../lib/colors.js";
@@ -45,63 +41,6 @@ const handler = async (args) => {
45
41
  printAvailableScriptsToConsole();
46
42
  return;
47
43
  }
48
- const {
49
- overrides: _overrides,
50
- plugins: webPlugins,
51
- ...otherWebConfig
52
- } = getWebSideDefaultBabelConfig();
53
- registerApiSideBabelHook({
54
- plugins: [
55
- [
56
- "babel-plugin-module-resolver",
57
- {
58
- alias: {
59
- $api: getPaths().api.base,
60
- $web: getPaths().web.base,
61
- api: getPaths().api.base,
62
- web: getPaths().web.base
63
- },
64
- loglevel: "silent"
65
- // to silence the unnecessary warnings
66
- },
67
- "exec-$side-module-resolver"
68
- ]
69
- ],
70
- overrides: [
71
- {
72
- test: ["./api/"],
73
- plugins: [
74
- [
75
- "babel-plugin-module-resolver",
76
- {
77
- alias: {
78
- src: getPaths().api.src
79
- },
80
- loglevel: "silent"
81
- },
82
- "exec-api-src-module-resolver"
83
- ]
84
- ]
85
- },
86
- {
87
- test: ["./web/"],
88
- plugins: [
89
- ...webPlugins,
90
- [
91
- "babel-plugin-module-resolver",
92
- {
93
- alias: {
94
- src: getPaths().web.src
95
- },
96
- loglevel: "silent"
97
- },
98
- "exec-web-src-module-resolver"
99
- ]
100
- ],
101
- ...otherWebConfig
102
- }
103
- ]
104
- });
105
44
  const scriptPath = resolveScriptPath(name);
106
45
  if (!scriptPath) {
107
46
  console.error(
@@ -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) => {
@@ -14,6 +14,7 @@ model BackgroundJob {
14
14
  queue String
15
15
  priority Int
16
16
  runAt DateTime?
17
+ cron String?
17
18
  lockedAt DateTime?
18
19
  lockedBy String?
19
20
  lastError String?
package/dist/lib/exec.js CHANGED
@@ -1,85 +1,119 @@
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";
3
6
  import {
4
- getWebSideDefaultBabelConfig,
5
- registerApiSideBabelHook
6
- } from "@cedarjs/babel-config";
7
- import { getPaths } from "@cedarjs/project-config";
7
+ getConfig,
8
+ getPaths,
9
+ importStatementPath
10
+ } from "@cedarjs/project-config";
11
+ import {
12
+ cedarCellTransform,
13
+ cedarjsDirectoryNamedImportPlugin,
14
+ cedarjsJobPathInjectorPlugin,
15
+ swapApolloProvider
16
+ } from "@cedarjs/vite/plugins";
8
17
  async function runScriptFunction({
9
18
  path: scriptPath,
10
19
  functionName,
11
20
  args
12
21
  }) {
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
- async function configureBabel() {
24
- const {
25
- overrides: _overrides,
26
- plugins: webPlugins,
27
- ...otherWebConfig
28
- } = getWebSideDefaultBabelConfig();
29
- registerApiSideBabelHook({
30
- plugins: [
31
- [
32
- "babel-plugin-module-resolver",
22
+ const rwConfig = getConfig();
23
+ const streamingEnabled = rwConfig?.experimental.streamingSsr.enabled;
24
+ const NODE_ENV = process.env.NODE_ENV;
25
+ process.env.NODE_ENV = "production";
26
+ const server = await createServer({
27
+ mode: "production",
28
+ optimizeDeps: {
29
+ // This is recommended in the vite-node readme
30
+ noDiscovery: true,
31
+ include: void 0
32
+ },
33
+ resolve: {
34
+ alias: [
35
+ {
36
+ find: /^\$api\//,
37
+ replacement: getPaths().api.base + "/"
38
+ },
39
+ {
40
+ find: /^\$web\//,
41
+ replacement: getPaths().web.base + "/"
42
+ },
43
+ {
44
+ find: /^api\//,
45
+ replacement: getPaths().api.base + "/"
46
+ },
33
47
  {
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
48
+ find: /^web\//,
49
+ replacement: getPaths().web.base + "/"
42
50
  },
43
- "exec-$side-module-resolver"
51
+ {
52
+ find: /^src\//,
53
+ replacement: "src/",
54
+ customResolver: (id, importer, _options) => {
55
+ const apiImportBase = importStatementPath(getPaths().api.base);
56
+ const webImportBase = importStatementPath(getPaths().web.base);
57
+ if (importer.startsWith(apiImportBase)) {
58
+ const apiImportSrc = importStatementPath(getPaths().api.src);
59
+ return { id: id.replace("src", apiImportSrc) };
60
+ } else if (importer.startsWith(webImportBase)) {
61
+ const webImportSrc = importStatementPath(getPaths().web.src);
62
+ return { id: id.replace("src", webImportSrc) };
63
+ }
64
+ return null;
65
+ }
66
+ }
44
67
  ]
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
- }
68
+ },
69
+ plugins: [
70
+ cedarjsDirectoryNamedImportPlugin(),
71
+ cedarCellTransform(),
72
+ cedarjsJobPathInjectorPlugin(),
73
+ streamingEnabled && swapApolloProvider()
79
74
  ]
80
75
  });
76
+ if (Number(viteVersion.split(".")[0]) < 6) {
77
+ await server.pluginContainer.buildStart({});
78
+ }
79
+ const node = new ViteNodeServer(server, {
80
+ transformMode: {
81
+ ssr: [/.*/],
82
+ web: [/\/web\//]
83
+ },
84
+ deps: {
85
+ fallbackCJS: true
86
+ }
87
+ });
88
+ installSourcemapsSupport({
89
+ getSourceMap: (source) => node.getSourceMap(source)
90
+ });
91
+ const runner = new ViteNodeRunner({
92
+ root: server.config.root,
93
+ base: server.config.base,
94
+ fetchModule(id) {
95
+ return node.fetchModule(id);
96
+ },
97
+ resolveId(id, importer) {
98
+ return node.resolveId(id, importer);
99
+ }
100
+ });
101
+ let returnValue;
102
+ try {
103
+ const script = await runner.executeFile(scriptPath);
104
+ returnValue = script[functionName](args);
105
+ } catch (error) {
106
+ console.error(error);
107
+ }
108
+ try {
109
+ const { db } = await runner.executeFile(path.join(getPaths().api.lib, "db"));
110
+ db.$disconnect();
111
+ } catch (e) {
112
+ }
113
+ await server.close();
114
+ process.env.NODE_ENV = NODE_ENV;
115
+ return returnValue;
81
116
  }
82
117
  export {
83
- configureBabel,
84
118
  runScriptFunction
85
119
  };
@@ -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": "0.2.1-next.0+de39d1a12",
3
+ "version": "0.3.0",
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": "0.2.1-next.0+de39d1a12",
33
- "@cedarjs/cli-helpers": "0.2.1-next.0+de39d1a12",
34
- "@cedarjs/fastify-web": "0.2.1-next.0+de39d1a12",
35
- "@cedarjs/internal": "0.2.1-next.0+de39d1a12",
36
- "@cedarjs/prerender": "0.2.1-next.0+de39d1a12",
37
- "@cedarjs/project-config": "0.2.1-next.0+de39d1a12",
38
- "@cedarjs/structure": "0.2.1-next.0+de39d1a12",
39
- "@cedarjs/telemetry": "0.2.1-next.0+de39d1a12",
40
- "@cedarjs/web-server": "0.2.1-next.0+de39d1a12",
32
+ "@cedarjs/api-server": "0.3.0",
33
+ "@cedarjs/cli-helpers": "0.3.0",
34
+ "@cedarjs/fastify-web": "0.3.0",
35
+ "@cedarjs/internal": "0.3.0",
36
+ "@cedarjs/prerender": "0.3.0",
37
+ "@cedarjs/project-config": "0.3.0",
38
+ "@cedarjs/structure": "0.3.0",
39
+ "@cedarjs/telemetry": "0.3.0",
40
+ "@cedarjs/web-server": "0.3.0",
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": {
@@ -98,5 +99,5 @@
98
99
  "publishConfig": {
99
100
  "access": "public"
100
101
  },
101
- "gitHead": "de39d1a12de3a16f1cbb443dbcf84825ac5e4d93"
102
+ "gitHead": "ebf827bba666cc5a129823079056d0b0e8280aad"
102
103
  }