@cedarjs/internal 6.0.0-canary.2696 → 6.0.0-canary.2698
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/build/api.d.ts.map +1 -1
- package/dist/build/api.js +85 -54
- package/dist/build/esbuild-plugin-api-graphql.d.ts.map +1 -1
- package/dist/build/esbuild-plugin-api-graphql.js +21 -13
- package/dist/build/job-path-injector.d.ts +15 -0
- package/dist/build/job-path-injector.d.ts.map +1 -0
- package/dist/build/job-path-injector.js +69 -0
- package/dist/cjs/build/api.d.ts.map +1 -1
- package/dist/cjs/build/api.js +83 -53
- package/dist/cjs/build/esbuild-plugin-api-graphql.d.ts.map +1 -1
- package/dist/cjs/build/esbuild-plugin-api-graphql.js +19 -12
- package/dist/cjs/build/job-path-injector.d.ts +15 -0
- package/dist/cjs/build/job-path-injector.d.ts.map +1 -0
- package/dist/cjs/build/job-path-injector.js +103 -0
- package/package.json +9 -9
package/dist/build/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/build/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,YAAY,EAAe,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/build/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,YAAY,EAAe,MAAM,SAAS,CAAA;AA6CtE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAIxD,eAAO,MAAM,QAAQ,4DAIpB,CAAA;AAED,eAAO,MAAM,UAAU,4DAStB,CAAA;AAED,eAAO,MAAM,aAAa,qBAGzB,CAAA;AA0VD,eAAO,MAAM,gBAAgB,iHAiE5B,CAAA;AAcD,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAoDf"}
|
package/dist/build/api.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { build, context } from "esbuild";
|
|
4
|
+
import MagicString from "magic-string";
|
|
4
5
|
import { build as viteBuild, normalizePath } from "vite";
|
|
5
6
|
import tsPathsMod from "vite-tsconfig-paths";
|
|
6
7
|
const tsconfigPaths = (
|
|
@@ -9,7 +10,8 @@ const tsconfigPaths = (
|
|
|
9
10
|
tsPathsMod.default?.default || tsPathsMod.default || tsPathsMod
|
|
10
11
|
);
|
|
11
12
|
import {
|
|
12
|
-
|
|
13
|
+
getApiSideBabelConfigPath,
|
|
14
|
+
getApiSideBabelPluginsForVite,
|
|
13
15
|
transformWithBabel
|
|
14
16
|
} from "@cedarjs/babel-config";
|
|
15
17
|
import {
|
|
@@ -30,6 +32,7 @@ import { applyOtelWrapping } from "./esbuild-plugin-cedar-otel-wrapping.js";
|
|
|
30
32
|
import { applyHandlerAlsWrapping } from "./esbuild-plugin-handler-als-wrapping.js";
|
|
31
33
|
import { applyEsmExtensions } from "./esm-extensions.js";
|
|
32
34
|
import { applyImportDir } from "./import-dir.js";
|
|
35
|
+
import { applyJobPathInjector } from "./job-path-injector.js";
|
|
33
36
|
import { applySrcAlias } from "./src-alias.js";
|
|
34
37
|
import { applyTsconfigPaths } from "./tsconfig-paths.js";
|
|
35
38
|
import { applySrcAlias as applySrcAlias2 } from "./src-alias.js";
|
|
@@ -73,40 +76,59 @@ const runCedarBabelTransformsPlugin = {
|
|
|
73
76
|
fileContents = applyDirectoryNamedImport(fileContents, args.path);
|
|
74
77
|
fileContents = applyAutoImports(fileContents);
|
|
75
78
|
fileContents = applyImportDir(fileContents, args.path)?.code ?? fileContents;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const functionsDir = normalizePath(cedarPaths.api.functions);
|
|
93
|
-
if (normalizedPath.startsWith(functionsDir + "/")) {
|
|
94
|
-
code = applyHandlerAlsWrapping(code, {
|
|
95
|
-
projectIsEsm: isEsm
|
|
96
|
-
}) ?? code;
|
|
97
|
-
}
|
|
98
|
-
if (normalizedPath.startsWith(normalizePath(cedarPaths.api.src) + "/")) {
|
|
99
|
-
code = applyOtelWrapping(code, args.path, cedarPaths.api.src) ?? code;
|
|
79
|
+
fileContents = applyJobPathInjector(fileContents, args.path, getPaths().api.jobs) ?? fileContents;
|
|
80
|
+
const normalizedPath = normalizePath(args.path);
|
|
81
|
+
const cedarPaths = getPaths();
|
|
82
|
+
const isEsm = projectSideIsEsm("api");
|
|
83
|
+
const apiBabelConfigPath = getApiSideBabelConfigPath();
|
|
84
|
+
let code = fileContents;
|
|
85
|
+
if (apiBabelConfigPath) {
|
|
86
|
+
const transformedCode = await transformWithBabel(
|
|
87
|
+
fileContents,
|
|
88
|
+
args.path,
|
|
89
|
+
getApiSideBabelPluginsForVite(),
|
|
90
|
+
"inline",
|
|
91
|
+
true
|
|
92
|
+
);
|
|
93
|
+
if (!transformedCode?.code) {
|
|
94
|
+
throw new Error(`Could not transform file: ${args.path}`);
|
|
100
95
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
96
|
+
code = transformedCode.code;
|
|
97
|
+
}
|
|
98
|
+
if (isEsm) {
|
|
99
|
+
code = applyEsmExtensions(code, args.path);
|
|
100
|
+
}
|
|
101
|
+
const functionsDir = normalizePath(cedarPaths.api.functions);
|
|
102
|
+
if (normalizedPath.startsWith(functionsDir + "/")) {
|
|
103
|
+
code = applyHandlerAlsWrapping(code, {
|
|
104
|
+
projectIsEsm: isEsm
|
|
105
|
+
}) ?? code;
|
|
105
106
|
}
|
|
106
|
-
|
|
107
|
+
if (normalizedPath.startsWith(normalizePath(cedarPaths.api.src) + "/")) {
|
|
108
|
+
code = applyOtelWrapping(code, args.path, cedarPaths.api.src) ?? code;
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
contents: code,
|
|
112
|
+
// Babel output is always plain JS. Without Babel the contents are
|
|
113
|
+
// still TypeScript/JSX, so pick the loader matching the file's
|
|
114
|
+
// extension and let esbuild do the stripping.
|
|
115
|
+
loader: apiBabelConfigPath ? "js" : getEsbuildLoader(args.path)
|
|
116
|
+
};
|
|
107
117
|
});
|
|
108
118
|
}
|
|
109
119
|
};
|
|
120
|
+
function getEsbuildLoader(filePath) {
|
|
121
|
+
switch (path.extname(filePath)) {
|
|
122
|
+
case ".ts":
|
|
123
|
+
return "ts";
|
|
124
|
+
case ".tsx":
|
|
125
|
+
return "tsx";
|
|
126
|
+
case ".jsx":
|
|
127
|
+
return "jsx";
|
|
128
|
+
default:
|
|
129
|
+
return "js";
|
|
130
|
+
}
|
|
131
|
+
}
|
|
110
132
|
function createImportDirVitePlugin() {
|
|
111
133
|
return {
|
|
112
134
|
name: "cedar-internal-import-dir",
|
|
@@ -180,39 +202,48 @@ function createCedarViteApiPlugin() {
|
|
|
180
202
|
path.dirname(path.relative(cedarPaths.api.src, id))
|
|
181
203
|
);
|
|
182
204
|
sourceCode = applyAutoImports(sourceCode);
|
|
205
|
+
sourceCode = applyJobPathInjector(sourceCode, id, cedarPaths.api.jobs) ?? sourceCode;
|
|
183
206
|
if (normalizedId.endsWith("/graphql.ts") || normalizedId.endsWith("/graphql.js")) {
|
|
184
207
|
sourceCode = applyGraphqlOptionsExtract(sourceCode) ?? sourceCode;
|
|
185
208
|
sourceCode = applyGqlormInject(sourceCode, id) ?? sourceCode;
|
|
186
209
|
}
|
|
187
|
-
const
|
|
210
|
+
const apiBabelConfigPath = getApiSideBabelConfigPath();
|
|
211
|
+
const transformedCode = apiBabelConfigPath ? await transformWithBabel(
|
|
188
212
|
sourceCode,
|
|
189
213
|
id,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
projectIsEsm: isEsm
|
|
193
|
-
}),
|
|
214
|
+
getApiSideBabelPluginsForVite(),
|
|
215
|
+
true,
|
|
194
216
|
true
|
|
195
|
-
);
|
|
196
|
-
if (transformedCode?.code) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
217
|
+
) : null;
|
|
218
|
+
if (apiBabelConfigPath && !transformedCode?.code) {
|
|
219
|
+
throw new Error(`Could not transform file: ${id}`);
|
|
220
|
+
}
|
|
221
|
+
let outputCode = transformedCode?.code ?? sourceCode;
|
|
222
|
+
if (cedarConfig.experimental?.opentelemetry?.enabled && cedarConfig.experimental?.opentelemetry?.wrapApi) {
|
|
223
|
+
outputCode = applyOtelWrapping(outputCode, id, cedarPaths.api.src) ?? outputCode;
|
|
224
|
+
}
|
|
225
|
+
if (isEsm) {
|
|
226
|
+
outputCode = applyEsmExtensions(outputCode, id);
|
|
227
|
+
}
|
|
228
|
+
const functionsDir = normalizePath(cedarPaths.api.functions);
|
|
229
|
+
if (normalizedId.startsWith(functionsDir + "/")) {
|
|
230
|
+
outputCode = applyHandlerAlsWrapping(outputCode, {
|
|
231
|
+
projectIsEsm: isEsm
|
|
232
|
+
}) ?? outputCode;
|
|
233
|
+
}
|
|
234
|
+
if (!transformedCode) {
|
|
235
|
+
if (outputCode === code) {
|
|
236
|
+
return null;
|
|
209
237
|
}
|
|
210
238
|
return {
|
|
211
|
-
code:
|
|
212
|
-
map:
|
|
239
|
+
code: outputCode,
|
|
240
|
+
map: new MagicString(code).generateMap({ hires: true })
|
|
213
241
|
};
|
|
214
242
|
}
|
|
215
|
-
|
|
243
|
+
return {
|
|
244
|
+
code: outputCode,
|
|
245
|
+
map: transformedCode.map ?? null
|
|
246
|
+
};
|
|
216
247
|
}
|
|
217
248
|
};
|
|
218
249
|
}
|
|
@@ -258,8 +289,8 @@ const buildApiWithVite = async () => {
|
|
|
258
289
|
},
|
|
259
290
|
// cedarImportDirPlugin must run before the Babel transform so glob imports
|
|
260
291
|
// are expanded before Babel sees the code. The Babel import-dir plugin is
|
|
261
|
-
//
|
|
262
|
-
// replacement for this code path (both CJS and ESM output via Rollup).
|
|
292
|
+
// not part of getApiSideBabelPluginsForVite(); this inline Vite plugin is
|
|
293
|
+
// its replacement for this code path (both CJS and ESM output via Rollup).
|
|
263
294
|
// tsconfigPaths resolves user-defined tsconfig.json `paths` aliases; it
|
|
264
295
|
// replaces the Babel module-resolver's tsconfig-paths handling for this
|
|
265
296
|
// code path.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esbuild-plugin-api-graphql.d.ts","sourceRoot":"","sources":["../../src/build/esbuild-plugin-api-graphql.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"esbuild-plugin-api-graphql.d.ts","sourceRoot":"","sources":["../../src/build/esbuild-plugin-api-graphql.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAsB1C,eAAO,MAAM,qBAAqB;;iBAEnB,WAAW;CAiHzB,CAAA"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
getApiSideBabelConfigPath,
|
|
5
|
+
getApiSideBabelPluginsForVite,
|
|
5
6
|
transformWithBabel
|
|
6
7
|
} from "@cedarjs/babel-config";
|
|
7
8
|
import { getConfig, getPaths, projectSideIsEsm } from "@cedarjs/project-config";
|
|
@@ -39,18 +40,21 @@ const cedarApiGraphqlPlugin = {
|
|
|
39
40
|
fileContents = applyGqlormInject(fileContents, args.path, ".js") ?? fileContents;
|
|
40
41
|
fileContents = applyAutoImports(fileContents);
|
|
41
42
|
fileContents = applyImportDir(fileContents, args.path)?.code ?? fileContents;
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
const apiBabelConfigPath = getApiSideBabelConfigPath();
|
|
44
|
+
let code = fileContents;
|
|
45
|
+
if (apiBabelConfigPath) {
|
|
46
|
+
const transformedCode = await transformWithBabel(
|
|
47
|
+
fileContents,
|
|
48
|
+
args.path,
|
|
49
|
+
getApiSideBabelPluginsForVite(),
|
|
50
|
+
"inline",
|
|
51
|
+
true
|
|
52
|
+
);
|
|
53
|
+
if (!transformedCode?.code) {
|
|
54
|
+
throw new Error(`Could not transform file: ${args.path}`);
|
|
55
|
+
}
|
|
56
|
+
code = transformedCode.code;
|
|
52
57
|
}
|
|
53
|
-
let code = transformedCode.code;
|
|
54
58
|
if (projectSideIsEsm("api")) {
|
|
55
59
|
code = applyEsmExtensions(code, args.path);
|
|
56
60
|
}
|
|
@@ -62,7 +66,11 @@ const cedarApiGraphqlPlugin = {
|
|
|
62
66
|
}) ?? code;
|
|
63
67
|
return {
|
|
64
68
|
contents: code,
|
|
65
|
-
|
|
69
|
+
// Babel output is always plain JS. Without Babel the contents are
|
|
70
|
+
// still TypeScript when the source file is graphql.ts, so pick the
|
|
71
|
+
// matching loader and let esbuild do the stripping. (The onLoad
|
|
72
|
+
// filter only matches .ts and .js files.)
|
|
73
|
+
loader: !apiBabelConfigPath && args.path.endsWith(".ts") ? "ts" : "js"
|
|
66
74
|
};
|
|
67
75
|
});
|
|
68
76
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Injects `path` and `name` properties into `createJob()` definitions so the
|
|
3
|
+
* jobs runner can locate and identify the job's module at runtime.
|
|
4
|
+
*
|
|
5
|
+
* Standalone equivalent of the Vite cedarjsJobPathInjectorPlugin (used by
|
|
6
|
+
* buildApp and apiDevMiddleware) and the Babel pluginRedwoodJobPathInjector
|
|
7
|
+
* override they replaced. Applied inline in the esbuild API build and the
|
|
8
|
+
* standalone-Vite API build so neither path depends on Babel for job path
|
|
9
|
+
* injection.
|
|
10
|
+
*
|
|
11
|
+
* Keep this in sync with
|
|
12
|
+
* packages/vite/src/plugins/vite-plugin-cedarjs-job-path-injector.ts.
|
|
13
|
+
*/
|
|
14
|
+
export declare function applyJobPathInjector(code: string, filePath: string, jobsDir: string): string | null;
|
|
15
|
+
//# sourceMappingURL=job-path-injector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job-path-injector.d.ts","sourceRoot":"","sources":["../../src/build/job-path-injector.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,IAAI,CA8Ff"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { parseSync } from "oxc-parser";
|
|
3
|
+
function applyJobPathInjector(code, filePath, jobsDir) {
|
|
4
|
+
if (!code.includes("createJob")) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
let program;
|
|
8
|
+
try {
|
|
9
|
+
program = parseSync(filePath, code, { sourceType: "module" }).program;
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.warn("Failed to parse file:", filePath);
|
|
12
|
+
console.warn(error);
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const importPath = path.relative(jobsDir, filePath);
|
|
16
|
+
const importPathWithoutExtension = importPath.replace(/\.[^/.]+$/, "");
|
|
17
|
+
const insertions = [];
|
|
18
|
+
for (const node of program.body) {
|
|
19
|
+
if (node.type !== "ExportNamedDeclaration") {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const decl = node.declaration;
|
|
23
|
+
if (decl?.type !== "VariableDeclaration") {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
for (const declarator of decl.declarations) {
|
|
27
|
+
if (declarator.id.type !== "Identifier") {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const init = declarator.init;
|
|
31
|
+
if (init?.type !== "CallExpression") {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const callee = init.callee;
|
|
35
|
+
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier" || callee.property.name !== "createJob") {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const configArg = init.arguments[0];
|
|
39
|
+
if (configArg?.type !== "ObjectExpression") {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const pathProperty = `path: ${JSON.stringify(importPathWithoutExtension)}`;
|
|
43
|
+
const nameProperty = `name: ${JSON.stringify(declarator.id.name)}`;
|
|
44
|
+
const lastProperty = configArg.properties.at(-1);
|
|
45
|
+
if (lastProperty) {
|
|
46
|
+
insertions.push({
|
|
47
|
+
pos: lastProperty.end,
|
|
48
|
+
text: `, ${pathProperty}, ${nameProperty}`
|
|
49
|
+
});
|
|
50
|
+
} else {
|
|
51
|
+
insertions.push({
|
|
52
|
+
pos: configArg.start + 1,
|
|
53
|
+
text: `${pathProperty}, ${nameProperty}`
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (insertions.length === 0) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
let result = code;
|
|
62
|
+
for (const { pos, text } of insertions.sort((a, b) => b.pos - a.pos)) {
|
|
63
|
+
result = result.slice(0, pos) + text + result.slice(pos);
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
applyJobPathInjector
|
|
69
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/build/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,YAAY,EAAe,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/build/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,YAAY,EAAe,MAAM,SAAS,CAAA;AA6CtE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAIxD,eAAO,MAAM,QAAQ,4DAIpB,CAAA;AAED,eAAO,MAAM,UAAU,4DAStB,CAAA;AAED,eAAO,MAAM,aAAa,qBAGzB,CAAA;AA0VD,eAAO,MAAM,gBAAgB,iHAiE5B,CAAA;AAcD,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAoDf"}
|
package/dist/cjs/build/api.js
CHANGED
|
@@ -40,6 +40,7 @@ module.exports = __toCommonJS(api_exports);
|
|
|
40
40
|
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
41
41
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
42
42
|
var import_esbuild = require("esbuild");
|
|
43
|
+
var import_magic_string = __toESM(require("magic-string"), 1);
|
|
43
44
|
var import_vite = require("vite");
|
|
44
45
|
var import_vite_tsconfig_paths = __toESM(require("vite-tsconfig-paths"), 1);
|
|
45
46
|
var import_babel_config = require("@cedarjs/babel-config");
|
|
@@ -53,6 +54,7 @@ var import_esbuild_plugin_cedar_otel_wrapping = require("./esbuild-plugin-cedar-
|
|
|
53
54
|
var import_esbuild_plugin_handler_als_wrapping = require("./esbuild-plugin-handler-als-wrapping.js");
|
|
54
55
|
var import_esm_extensions = require("./esm-extensions.js");
|
|
55
56
|
var import_import_dir = require("./import-dir.js");
|
|
57
|
+
var import_job_path_injector = require("./job-path-injector.js");
|
|
56
58
|
var import_src_alias = require("./src-alias.js");
|
|
57
59
|
var import_tsconfig_paths = require("./tsconfig-paths.js");
|
|
58
60
|
var import_src_alias2 = require("./src-alias.js");
|
|
@@ -101,40 +103,59 @@ const runCedarBabelTransformsPlugin = {
|
|
|
101
103
|
fileContents = (0, import_directory_named_import.applyDirectoryNamedImport)(fileContents, args.path);
|
|
102
104
|
fileContents = (0, import_auto_import.applyAutoImports)(fileContents);
|
|
103
105
|
fileContents = (0, import_import_dir.applyImportDir)(fileContents, args.path)?.code ?? fileContents;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const functionsDir = (0, import_vite.normalizePath)(cedarPaths.api.functions);
|
|
121
|
-
if (normalizedPath.startsWith(functionsDir + "/")) {
|
|
122
|
-
code = (0, import_esbuild_plugin_handler_als_wrapping.applyHandlerAlsWrapping)(code, {
|
|
123
|
-
projectIsEsm: isEsm
|
|
124
|
-
}) ?? code;
|
|
125
|
-
}
|
|
126
|
-
if (normalizedPath.startsWith((0, import_vite.normalizePath)(cedarPaths.api.src) + "/")) {
|
|
127
|
-
code = (0, import_esbuild_plugin_cedar_otel_wrapping.applyOtelWrapping)(code, args.path, cedarPaths.api.src) ?? code;
|
|
106
|
+
fileContents = (0, import_job_path_injector.applyJobPathInjector)(fileContents, args.path, (0, import_project_config.getPaths)().api.jobs) ?? fileContents;
|
|
107
|
+
const normalizedPath = (0, import_vite.normalizePath)(args.path);
|
|
108
|
+
const cedarPaths = (0, import_project_config.getPaths)();
|
|
109
|
+
const isEsm = (0, import_project_config.projectSideIsEsm)("api");
|
|
110
|
+
const apiBabelConfigPath = (0, import_babel_config.getApiSideBabelConfigPath)();
|
|
111
|
+
let code = fileContents;
|
|
112
|
+
if (apiBabelConfigPath) {
|
|
113
|
+
const transformedCode = await (0, import_babel_config.transformWithBabel)(
|
|
114
|
+
fileContents,
|
|
115
|
+
args.path,
|
|
116
|
+
(0, import_babel_config.getApiSideBabelPluginsForVite)(),
|
|
117
|
+
"inline",
|
|
118
|
+
true
|
|
119
|
+
);
|
|
120
|
+
if (!transformedCode?.code) {
|
|
121
|
+
throw new Error(`Could not transform file: ${args.path}`);
|
|
128
122
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
123
|
+
code = transformedCode.code;
|
|
124
|
+
}
|
|
125
|
+
if (isEsm) {
|
|
126
|
+
code = (0, import_esm_extensions.applyEsmExtensions)(code, args.path);
|
|
127
|
+
}
|
|
128
|
+
const functionsDir = (0, import_vite.normalizePath)(cedarPaths.api.functions);
|
|
129
|
+
if (normalizedPath.startsWith(functionsDir + "/")) {
|
|
130
|
+
code = (0, import_esbuild_plugin_handler_als_wrapping.applyHandlerAlsWrapping)(code, {
|
|
131
|
+
projectIsEsm: isEsm
|
|
132
|
+
}) ?? code;
|
|
133
133
|
}
|
|
134
|
-
|
|
134
|
+
if (normalizedPath.startsWith((0, import_vite.normalizePath)(cedarPaths.api.src) + "/")) {
|
|
135
|
+
code = (0, import_esbuild_plugin_cedar_otel_wrapping.applyOtelWrapping)(code, args.path, cedarPaths.api.src) ?? code;
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
contents: code,
|
|
139
|
+
// Babel output is always plain JS. Without Babel the contents are
|
|
140
|
+
// still TypeScript/JSX, so pick the loader matching the file's
|
|
141
|
+
// extension and let esbuild do the stripping.
|
|
142
|
+
loader: apiBabelConfigPath ? "js" : getEsbuildLoader(args.path)
|
|
143
|
+
};
|
|
135
144
|
});
|
|
136
145
|
}
|
|
137
146
|
};
|
|
147
|
+
function getEsbuildLoader(filePath) {
|
|
148
|
+
switch (import_node_path.default.extname(filePath)) {
|
|
149
|
+
case ".ts":
|
|
150
|
+
return "ts";
|
|
151
|
+
case ".tsx":
|
|
152
|
+
return "tsx";
|
|
153
|
+
case ".jsx":
|
|
154
|
+
return "jsx";
|
|
155
|
+
default:
|
|
156
|
+
return "js";
|
|
157
|
+
}
|
|
158
|
+
}
|
|
138
159
|
function createImportDirVitePlugin() {
|
|
139
160
|
return {
|
|
140
161
|
name: "cedar-internal-import-dir",
|
|
@@ -208,39 +229,48 @@ function createCedarViteApiPlugin() {
|
|
|
208
229
|
import_node_path.default.dirname(import_node_path.default.relative(cedarPaths.api.src, id))
|
|
209
230
|
);
|
|
210
231
|
sourceCode = (0, import_auto_import.applyAutoImports)(sourceCode);
|
|
232
|
+
sourceCode = (0, import_job_path_injector.applyJobPathInjector)(sourceCode, id, cedarPaths.api.jobs) ?? sourceCode;
|
|
211
233
|
if (normalizedId.endsWith("/graphql.ts") || normalizedId.endsWith("/graphql.js")) {
|
|
212
234
|
sourceCode = (0, import_api_graphql_transforms.applyGraphqlOptionsExtract)(sourceCode) ?? sourceCode;
|
|
213
235
|
sourceCode = (0, import_api_graphql_transforms.applyGqlormInject)(sourceCode, id) ?? sourceCode;
|
|
214
236
|
}
|
|
215
|
-
const
|
|
237
|
+
const apiBabelConfigPath = (0, import_babel_config.getApiSideBabelConfigPath)();
|
|
238
|
+
const transformedCode = apiBabelConfigPath ? await (0, import_babel_config.transformWithBabel)(
|
|
216
239
|
sourceCode,
|
|
217
240
|
id,
|
|
218
|
-
(0, import_babel_config.
|
|
219
|
-
|
|
220
|
-
projectIsEsm: isEsm
|
|
221
|
-
}),
|
|
241
|
+
(0, import_babel_config.getApiSideBabelPluginsForVite)(),
|
|
242
|
+
true,
|
|
222
243
|
true
|
|
223
|
-
);
|
|
224
|
-
if (transformedCode?.code) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
244
|
+
) : null;
|
|
245
|
+
if (apiBabelConfigPath && !transformedCode?.code) {
|
|
246
|
+
throw new Error(`Could not transform file: ${id}`);
|
|
247
|
+
}
|
|
248
|
+
let outputCode = transformedCode?.code ?? sourceCode;
|
|
249
|
+
if (cedarConfig.experimental?.opentelemetry?.enabled && cedarConfig.experimental?.opentelemetry?.wrapApi) {
|
|
250
|
+
outputCode = (0, import_esbuild_plugin_cedar_otel_wrapping.applyOtelWrapping)(outputCode, id, cedarPaths.api.src) ?? outputCode;
|
|
251
|
+
}
|
|
252
|
+
if (isEsm) {
|
|
253
|
+
outputCode = (0, import_esm_extensions.applyEsmExtensions)(outputCode, id);
|
|
254
|
+
}
|
|
255
|
+
const functionsDir = (0, import_vite.normalizePath)(cedarPaths.api.functions);
|
|
256
|
+
if (normalizedId.startsWith(functionsDir + "/")) {
|
|
257
|
+
outputCode = (0, import_esbuild_plugin_handler_als_wrapping.applyHandlerAlsWrapping)(outputCode, {
|
|
258
|
+
projectIsEsm: isEsm
|
|
259
|
+
}) ?? outputCode;
|
|
260
|
+
}
|
|
261
|
+
if (!transformedCode) {
|
|
262
|
+
if (outputCode === code) {
|
|
263
|
+
return null;
|
|
237
264
|
}
|
|
238
265
|
return {
|
|
239
|
-
code:
|
|
240
|
-
map:
|
|
266
|
+
code: outputCode,
|
|
267
|
+
map: new import_magic_string.default(code).generateMap({ hires: true })
|
|
241
268
|
};
|
|
242
269
|
}
|
|
243
|
-
|
|
270
|
+
return {
|
|
271
|
+
code: outputCode,
|
|
272
|
+
map: transformedCode.map ?? null
|
|
273
|
+
};
|
|
244
274
|
}
|
|
245
275
|
};
|
|
246
276
|
}
|
|
@@ -286,8 +316,8 @@ const buildApiWithVite = async () => {
|
|
|
286
316
|
},
|
|
287
317
|
// cedarImportDirPlugin must run before the Babel transform so glob imports
|
|
288
318
|
// are expanded before Babel sees the code. The Babel import-dir plugin is
|
|
289
|
-
//
|
|
290
|
-
// replacement for this code path (both CJS and ESM output via Rollup).
|
|
319
|
+
// not part of getApiSideBabelPluginsForVite(); this inline Vite plugin is
|
|
320
|
+
// its replacement for this code path (both CJS and ESM output via Rollup).
|
|
291
321
|
// tsconfigPaths resolves user-defined tsconfig.json `paths` aliases; it
|
|
292
322
|
// replaces the Babel module-resolver's tsconfig-paths handling for this
|
|
293
323
|
// code path.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esbuild-plugin-api-graphql.d.ts","sourceRoot":"","sources":["../../../src/build/esbuild-plugin-api-graphql.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"esbuild-plugin-api-graphql.d.ts","sourceRoot":"","sources":["../../../src/build/esbuild-plugin-api-graphql.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAsB1C,eAAO,MAAM,qBAAqB;;iBAEnB,WAAW;CAiHzB,CAAA"}
|
|
@@ -66,18 +66,21 @@ const cedarApiGraphqlPlugin = {
|
|
|
66
66
|
fileContents = (0, import_api_graphql_transforms.applyGqlormInject)(fileContents, args.path, ".js") ?? fileContents;
|
|
67
67
|
fileContents = (0, import_auto_import.applyAutoImports)(fileContents);
|
|
68
68
|
fileContents = (0, import_import_dir.applyImportDir)(fileContents, args.path)?.code ?? fileContents;
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
(0, import_babel_config.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
const apiBabelConfigPath = (0, import_babel_config.getApiSideBabelConfigPath)();
|
|
70
|
+
let code = fileContents;
|
|
71
|
+
if (apiBabelConfigPath) {
|
|
72
|
+
const transformedCode = await (0, import_babel_config.transformWithBabel)(
|
|
73
|
+
fileContents,
|
|
74
|
+
args.path,
|
|
75
|
+
(0, import_babel_config.getApiSideBabelPluginsForVite)(),
|
|
76
|
+
"inline",
|
|
77
|
+
true
|
|
78
|
+
);
|
|
79
|
+
if (!transformedCode?.code) {
|
|
80
|
+
throw new Error(`Could not transform file: ${args.path}`);
|
|
81
|
+
}
|
|
82
|
+
code = transformedCode.code;
|
|
79
83
|
}
|
|
80
|
-
let code = transformedCode.code;
|
|
81
84
|
if ((0, import_project_config.projectSideIsEsm)("api")) {
|
|
82
85
|
code = (0, import_esm_extensions.applyEsmExtensions)(code, args.path);
|
|
83
86
|
}
|
|
@@ -89,7 +92,11 @@ const cedarApiGraphqlPlugin = {
|
|
|
89
92
|
}) ?? code;
|
|
90
93
|
return {
|
|
91
94
|
contents: code,
|
|
92
|
-
|
|
95
|
+
// Babel output is always plain JS. Without Babel the contents are
|
|
96
|
+
// still TypeScript when the source file is graphql.ts, so pick the
|
|
97
|
+
// matching loader and let esbuild do the stripping. (The onLoad
|
|
98
|
+
// filter only matches .ts and .js files.)
|
|
99
|
+
loader: !apiBabelConfigPath && args.path.endsWith(".ts") ? "ts" : "js"
|
|
93
100
|
};
|
|
94
101
|
});
|
|
95
102
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Injects `path` and `name` properties into `createJob()` definitions so the
|
|
3
|
+
* jobs runner can locate and identify the job's module at runtime.
|
|
4
|
+
*
|
|
5
|
+
* Standalone equivalent of the Vite cedarjsJobPathInjectorPlugin (used by
|
|
6
|
+
* buildApp and apiDevMiddleware) and the Babel pluginRedwoodJobPathInjector
|
|
7
|
+
* override they replaced. Applied inline in the esbuild API build and the
|
|
8
|
+
* standalone-Vite API build so neither path depends on Babel for job path
|
|
9
|
+
* injection.
|
|
10
|
+
*
|
|
11
|
+
* Keep this in sync with
|
|
12
|
+
* packages/vite/src/plugins/vite-plugin-cedarjs-job-path-injector.ts.
|
|
13
|
+
*/
|
|
14
|
+
export declare function applyJobPathInjector(code: string, filePath: string, jobsDir: string): string | null;
|
|
15
|
+
//# sourceMappingURL=job-path-injector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job-path-injector.d.ts","sourceRoot":"","sources":["../../../src/build/job-path-injector.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,IAAI,CA8Ff"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var job_path_injector_exports = {};
|
|
30
|
+
__export(job_path_injector_exports, {
|
|
31
|
+
applyJobPathInjector: () => applyJobPathInjector
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(job_path_injector_exports);
|
|
34
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
35
|
+
var import_oxc_parser = require("oxc-parser");
|
|
36
|
+
function applyJobPathInjector(code, filePath, jobsDir) {
|
|
37
|
+
if (!code.includes("createJob")) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
let program;
|
|
41
|
+
try {
|
|
42
|
+
program = (0, import_oxc_parser.parseSync)(filePath, code, { sourceType: "module" }).program;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.warn("Failed to parse file:", filePath);
|
|
45
|
+
console.warn(error);
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const importPath = import_node_path.default.relative(jobsDir, filePath);
|
|
49
|
+
const importPathWithoutExtension = importPath.replace(/\.[^/.]+$/, "");
|
|
50
|
+
const insertions = [];
|
|
51
|
+
for (const node of program.body) {
|
|
52
|
+
if (node.type !== "ExportNamedDeclaration") {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const decl = node.declaration;
|
|
56
|
+
if (decl?.type !== "VariableDeclaration") {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
for (const declarator of decl.declarations) {
|
|
60
|
+
if (declarator.id.type !== "Identifier") {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const init = declarator.init;
|
|
64
|
+
if (init?.type !== "CallExpression") {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const callee = init.callee;
|
|
68
|
+
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier" || callee.property.name !== "createJob") {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const configArg = init.arguments[0];
|
|
72
|
+
if (configArg?.type !== "ObjectExpression") {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const pathProperty = `path: ${JSON.stringify(importPathWithoutExtension)}`;
|
|
76
|
+
const nameProperty = `name: ${JSON.stringify(declarator.id.name)}`;
|
|
77
|
+
const lastProperty = configArg.properties.at(-1);
|
|
78
|
+
if (lastProperty) {
|
|
79
|
+
insertions.push({
|
|
80
|
+
pos: lastProperty.end,
|
|
81
|
+
text: `, ${pathProperty}, ${nameProperty}`
|
|
82
|
+
});
|
|
83
|
+
} else {
|
|
84
|
+
insertions.push({
|
|
85
|
+
pos: configArg.start + 1,
|
|
86
|
+
text: `${pathProperty}, ${nameProperty}`
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (insertions.length === 0) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
let result = code;
|
|
95
|
+
for (const { pos, text } of insertions.sort((a, b) => b.pos - a.pos)) {
|
|
96
|
+
result = result.slice(0, pos) + text + result.slice(pos);
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
101
|
+
0 && (module.exports = {
|
|
102
|
+
applyJobPathInjector
|
|
103
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/internal",
|
|
3
|
-
"version": "6.0.0-canary.
|
|
3
|
+
"version": "6.0.0-canary.2698",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -179,13 +179,13 @@
|
|
|
179
179
|
"@babel/plugin-transform-react-jsx": "7.29.7",
|
|
180
180
|
"@babel/plugin-transform-typescript": "^7.26.8",
|
|
181
181
|
"@babel/traverse": "7.29.7",
|
|
182
|
-
"@cedarjs/babel-config": "6.0.0-canary.
|
|
183
|
-
"@cedarjs/cli-helpers": "6.0.0-canary.
|
|
184
|
-
"@cedarjs/graphql-server": "6.0.0-canary.
|
|
185
|
-
"@cedarjs/project-config": "6.0.0-canary.
|
|
186
|
-
"@cedarjs/router": "6.0.0-canary.
|
|
187
|
-
"@cedarjs/structure": "6.0.0-canary.
|
|
188
|
-
"@cedarjs/utils": "6.0.0-canary.
|
|
182
|
+
"@cedarjs/babel-config": "6.0.0-canary.2698",
|
|
183
|
+
"@cedarjs/cli-helpers": "6.0.0-canary.2698",
|
|
184
|
+
"@cedarjs/graphql-server": "6.0.0-canary.2698",
|
|
185
|
+
"@cedarjs/project-config": "6.0.0-canary.2698",
|
|
186
|
+
"@cedarjs/router": "6.0.0-canary.2698",
|
|
187
|
+
"@cedarjs/structure": "6.0.0-canary.2698",
|
|
188
|
+
"@cedarjs/utils": "6.0.0-canary.2698",
|
|
189
189
|
"@graphql-codegen/add": "6.0.1",
|
|
190
190
|
"@graphql-codegen/cli": "6.3.1",
|
|
191
191
|
"@graphql-codegen/client-preset": "5.3.0",
|
|
@@ -230,7 +230,7 @@
|
|
|
230
230
|
},
|
|
231
231
|
"devDependencies": {
|
|
232
232
|
"@arethetypeswrong/cli": "0.18.5",
|
|
233
|
-
"@cedarjs/framework-tools": "6.0.0-canary.
|
|
233
|
+
"@cedarjs/framework-tools": "6.0.0-canary.2698",
|
|
234
234
|
"concurrently": "9.2.1",
|
|
235
235
|
"graphql-tag": "2.12.6",
|
|
236
236
|
"publint": "0.3.21",
|