@cedarjs/cli 5.0.0-canary.2377 → 5.0.0-canary.2382
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/setup/deploy/helpers/index.js +89 -0
- package/dist/commands/setup/deploy/providers/netlifyHandler.js +12 -12
- package/dist/commands/setup/deploy/providers/universalDeployHandler.js +1 -1
- package/dist/commands/setup/deploy/providers/vercelHandler.js +26 -20
- package/dist/commands/setup/deploy/templates/netlifyUD.js +1 -1
- package/package.json +12 -12
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import * as parser from "@babel/parser";
|
|
4
|
+
import * as t from "@babel/types";
|
|
3
5
|
import execa from "execa";
|
|
4
6
|
import { Listr } from "listr2";
|
|
7
|
+
import * as recast from "recast";
|
|
5
8
|
import { getConfigPath, getConfig } from "@cedarjs/project-config";
|
|
6
9
|
import { getPaths, writeFilesTask } from "../../../../lib/index.js";
|
|
7
10
|
const updateApiURLTask = (apiUrl) => {
|
|
@@ -84,6 +87,91 @@ const verifyUDSetupTask = () => {
|
|
|
84
87
|
}
|
|
85
88
|
};
|
|
86
89
|
};
|
|
90
|
+
function posToIndex(str, line, column) {
|
|
91
|
+
const lines = str.split("\n");
|
|
92
|
+
let index = 0;
|
|
93
|
+
for (let i = 0; i < line - 1; i++) {
|
|
94
|
+
index += lines[i].length + 1;
|
|
95
|
+
}
|
|
96
|
+
return index + column;
|
|
97
|
+
}
|
|
98
|
+
function insertPluginsBeforeCedar({ content, pluginCodes }) {
|
|
99
|
+
const ast = recast.parse(content, {
|
|
100
|
+
parser: {
|
|
101
|
+
parse(source) {
|
|
102
|
+
return parser.parse(source, {
|
|
103
|
+
sourceType: "module",
|
|
104
|
+
plugins: ["typescript", "jsx"]
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
const defaultExport = ast.program.body.find(
|
|
110
|
+
(node) => t.isExportDefaultDeclaration(node) && t.isCallExpression(node.declaration) && t.isIdentifier(node.declaration.callee) && node.declaration.callee.name === "defineConfig"
|
|
111
|
+
);
|
|
112
|
+
if (!defaultExport) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
const configArg = defaultExport.declaration.arguments[0];
|
|
116
|
+
if (!t.isObjectExpression(configArg)) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
const pluginsProp = configArg.properties.find(
|
|
120
|
+
(prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "plugins" && t.isArrayExpression(prop.value)
|
|
121
|
+
);
|
|
122
|
+
if (!pluginsProp) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
const elements = pluginsProp.value.elements;
|
|
126
|
+
const cedarIndex = elements.findIndex(
|
|
127
|
+
(el) => t.isCallExpression(el) && t.isIdentifier(el.callee) && el.callee.name === "cedar"
|
|
128
|
+
);
|
|
129
|
+
if (cedarIndex === -1) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
const cedarNode = elements[cedarIndex];
|
|
133
|
+
const arrayNode = pluginsProp.value;
|
|
134
|
+
const isInline = cedarNode.loc.start.line === arrayNode.loc.start.line;
|
|
135
|
+
if (isInline) {
|
|
136
|
+
const startPos = posToIndex(
|
|
137
|
+
content,
|
|
138
|
+
arrayNode.loc.start.line,
|
|
139
|
+
arrayNode.loc.start.column
|
|
140
|
+
);
|
|
141
|
+
const endPos = posToIndex(
|
|
142
|
+
content,
|
|
143
|
+
arrayNode.loc.end.line,
|
|
144
|
+
arrayNode.loc.end.column
|
|
145
|
+
);
|
|
146
|
+
const precedingText = content.slice(0, startPos);
|
|
147
|
+
const followingText = content.slice(endPos);
|
|
148
|
+
const existingCodes = elements.map(
|
|
149
|
+
(el) => content.slice(
|
|
150
|
+
posToIndex(content, el.loc.start.line, el.loc.start.column),
|
|
151
|
+
posToIndex(content, el.loc.end.line, el.loc.end.column)
|
|
152
|
+
)
|
|
153
|
+
);
|
|
154
|
+
const lines2 = content.split("\n");
|
|
155
|
+
const pluginsLine = pluginsProp.loc.start.line;
|
|
156
|
+
const pluginsIndent = lines2[pluginsLine - 1].match(/^\s*/)[0];
|
|
157
|
+
const elemIndent = pluginsIndent + " ";
|
|
158
|
+
const allCodes = [...existingCodes];
|
|
159
|
+
allCodes.splice(cedarIndex, 0, ...pluginCodes);
|
|
160
|
+
const multiline = [
|
|
161
|
+
"[",
|
|
162
|
+
...allCodes.map((code) => `${elemIndent}${code},`),
|
|
163
|
+
`${pluginsIndent}]`
|
|
164
|
+
].join("\n");
|
|
165
|
+
return precedingText + multiline + followingText;
|
|
166
|
+
}
|
|
167
|
+
const cedarLine = cedarNode.loc.start.line;
|
|
168
|
+
const insertPos = posToIndex(content, cedarLine, 0);
|
|
169
|
+
const lines = content.split("\n");
|
|
170
|
+
const indent = lines[cedarLine - 1].match(/^\s*/)[0];
|
|
171
|
+
const insertion = pluginCodes.map((code) => `${indent}${code},
|
|
172
|
+
`).join("");
|
|
173
|
+
return content.slice(0, insertPos) + insertion + content.slice(insertPos);
|
|
174
|
+
}
|
|
87
175
|
const addToGitIgnoreTask = ({ paths }) => {
|
|
88
176
|
return {
|
|
89
177
|
title: "Updating .gitignore...",
|
|
@@ -125,6 +213,7 @@ export {
|
|
|
125
213
|
addToDotEnvTask,
|
|
126
214
|
addToGitIgnoreTask,
|
|
127
215
|
getUserApiUrl,
|
|
216
|
+
insertPluginsBeforeCedar,
|
|
128
217
|
preRequisiteCheckTask,
|
|
129
218
|
updateApiURLTask,
|
|
130
219
|
verifyUDSetupTask
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from "../../../../lib/index.js";
|
|
11
11
|
import {
|
|
12
12
|
addFilesTask,
|
|
13
|
+
insertPluginsBeforeCedar,
|
|
13
14
|
updateApiURLTask,
|
|
14
15
|
verifyUDSetupTask
|
|
15
16
|
} from "../helpers/index.js";
|
|
@@ -87,17 +88,16 @@ ${result}`;
|
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
if (!content.includes("netlifyCompat(")) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
);
|
|
91
|
+
const result = insertPluginsBeforeCedar({
|
|
92
|
+
content,
|
|
93
|
+
pluginCodes: [
|
|
94
|
+
"netlify({ build: { enabled: true } })",
|
|
95
|
+
"netlifyCompat()"
|
|
96
|
+
]
|
|
97
|
+
});
|
|
98
|
+
if (result) {
|
|
99
|
+
content = result;
|
|
100
|
+
}
|
|
101
101
|
}
|
|
102
102
|
fs.writeFileSync(viteConfigPath, content);
|
|
103
103
|
}
|
|
@@ -118,7 +118,7 @@ const handler = async ({ force, ud }) => {
|
|
|
118
118
|
const tasks = new Listr(
|
|
119
119
|
[
|
|
120
120
|
ud && verifyUDSetupTask(),
|
|
121
|
-
ud && installNetlifyPackagesTask(),
|
|
121
|
+
ud && await installNetlifyPackagesTask(),
|
|
122
122
|
ud && addNetlifyPluginsToViteConfigTask(),
|
|
123
123
|
!ud && updateApiURLTask("/.netlify/functions"),
|
|
124
124
|
addFilesTask({ files: ud ? filesUd : files, force }),
|
|
@@ -20,7 +20,7 @@ const notes = [
|
|
|
20
20
|
` ${c.highlight("yarn cedar setup deploy netlify --ud")}`,
|
|
21
21
|
` ${c.highlight("yarn cedar setup deploy vercel --ud")}`,
|
|
22
22
|
"",
|
|
23
|
-
"See: https://cedarjs.com/docs/deploy
|
|
23
|
+
"See: https://cedarjs.com/docs/deploy/universal-deploy"
|
|
24
24
|
];
|
|
25
25
|
async function handler() {
|
|
26
26
|
recordTelemetryAttributes({
|
|
@@ -9,7 +9,11 @@ import {
|
|
|
9
9
|
printSetupNotes,
|
|
10
10
|
writeFile
|
|
11
11
|
} from "../../../../lib/index.js";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
insertPluginsBeforeCedar,
|
|
14
|
+
updateApiURLTask,
|
|
15
|
+
verifyUDSetupTask
|
|
16
|
+
} from "../helpers/index.js";
|
|
13
17
|
async function handler({ force, ud }) {
|
|
14
18
|
recordTelemetryAttributes({
|
|
15
19
|
command: "setup deploy vercel",
|
|
@@ -19,7 +23,7 @@ async function handler({ force, ud }) {
|
|
|
19
23
|
const tasks = new Listr(
|
|
20
24
|
[
|
|
21
25
|
ud && verifyUDSetupTask(),
|
|
22
|
-
ud && installVercelPackagesTask(),
|
|
26
|
+
ud && await installVercelPackagesTask(),
|
|
23
27
|
ud && addVercelPluginToViteConfigTask(),
|
|
24
28
|
!ud && updateApiURLTask("/api"),
|
|
25
29
|
ud ? writeVercelUDConfigTask({ overwriteExisting: force }) : writeVercelConfigTask({ overwriteExisting: force }),
|
|
@@ -50,29 +54,31 @@ function addVercelPluginToViteConfigTask() {
|
|
|
50
54
|
return;
|
|
51
55
|
}
|
|
52
56
|
let content = fs.readFileSync(viteConfigPath, "utf-8");
|
|
53
|
-
|
|
57
|
+
const hasVercelPlugin = content.includes("vite-plugin-vercel");
|
|
58
|
+
if (hasVercelPlugin && content.includes("vercel(")) {
|
|
54
59
|
task.skip("Vercel plugin is already configured.");
|
|
55
60
|
return;
|
|
56
61
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
if (!hasVercelPlugin) {
|
|
63
|
+
const newContent = content.replace(
|
|
64
|
+
/(import\s+\{[^}]*\}\s+from\s+['"]vite['"];?)/,
|
|
65
|
+
"import { vercel } from 'vite-plugin-vercel/vite'\n$1"
|
|
66
|
+
);
|
|
67
|
+
if (newContent === content) {
|
|
68
|
+
content = "import { vercel } from 'vite-plugin-vercel/vite'\n" + content;
|
|
69
|
+
} else {
|
|
70
|
+
content = newContent;
|
|
71
|
+
}
|
|
65
72
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
${indent}${cedarCall}`;
|
|
73
|
+
if (!content.includes("vercel(")) {
|
|
74
|
+
const result = insertPluginsBeforeCedar({
|
|
75
|
+
content,
|
|
76
|
+
pluginCodes: ["vercel()"]
|
|
77
|
+
});
|
|
78
|
+
if (result) {
|
|
79
|
+
content = result;
|
|
74
80
|
}
|
|
75
|
-
|
|
81
|
+
}
|
|
76
82
|
fs.writeFileSync(viteConfigPath, content);
|
|
77
83
|
}
|
|
78
84
|
};
|
|
@@ -8,7 +8,7 @@ publish = "web/dist"
|
|
|
8
8
|
NODE_VERSION = "24"
|
|
9
9
|
|
|
10
10
|
[functions]
|
|
11
|
-
directory = "api/dist/
|
|
11
|
+
directory = "api/dist/ud"
|
|
12
12
|
|
|
13
13
|
# To use Netlify Dev, install Netlify's CLI (\`netlify-cli\`) from NPM and use
|
|
14
14
|
# \`netlify link\` to connect your local project to a site on Netlify. Then run
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/cli",
|
|
3
|
-
"version": "5.0.0-canary.
|
|
3
|
+
"version": "5.0.0-canary.2382",
|
|
4
4
|
"description": "The CedarJS Command Line",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,17 +33,17 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/parser": "7.29.3",
|
|
35
35
|
"@babel/preset-typescript": "7.28.5",
|
|
36
|
-
"@cedarjs/api-server": "5.0.0-canary.
|
|
37
|
-
"@cedarjs/cli-helpers": "5.0.0-canary.
|
|
38
|
-
"@cedarjs/fastify-web": "5.0.0-canary.
|
|
39
|
-
"@cedarjs/internal": "5.0.0-canary.
|
|
40
|
-
"@cedarjs/prerender": "5.0.0-canary.
|
|
41
|
-
"@cedarjs/project-config": "5.0.0-canary.
|
|
42
|
-
"@cedarjs/structure": "5.0.0-canary.
|
|
43
|
-
"@cedarjs/telemetry": "5.0.0-canary.
|
|
44
|
-
"@cedarjs/utils": "5.0.0-canary.
|
|
45
|
-
"@cedarjs/vite": "5.0.0-canary.
|
|
46
|
-
"@cedarjs/web-server": "5.0.0-canary.
|
|
36
|
+
"@cedarjs/api-server": "5.0.0-canary.2382",
|
|
37
|
+
"@cedarjs/cli-helpers": "5.0.0-canary.2382",
|
|
38
|
+
"@cedarjs/fastify-web": "5.0.0-canary.2382",
|
|
39
|
+
"@cedarjs/internal": "5.0.0-canary.2382",
|
|
40
|
+
"@cedarjs/prerender": "5.0.0-canary.2382",
|
|
41
|
+
"@cedarjs/project-config": "5.0.0-canary.2382",
|
|
42
|
+
"@cedarjs/structure": "5.0.0-canary.2382",
|
|
43
|
+
"@cedarjs/telemetry": "5.0.0-canary.2382",
|
|
44
|
+
"@cedarjs/utils": "5.0.0-canary.2382",
|
|
45
|
+
"@cedarjs/vite": "5.0.0-canary.2382",
|
|
46
|
+
"@cedarjs/web-server": "5.0.0-canary.2382",
|
|
47
47
|
"@listr2/prompt-adapter-enquirer": "4.2.1",
|
|
48
48
|
"@opentelemetry/api": "1.9.0",
|
|
49
49
|
"@opentelemetry/core": "1.30.1",
|