@cedarjs/internal 6.0.0-canary.2697 → 6.0.0-canary.2699
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 +11 -13
- package/dist/build/esbuild-plugin-api-graphql.d.ts.map +1 -1
- package/dist/build/esbuild-plugin-api-graphql.js +3 -1
- 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 +11 -13
- package/dist/cjs/build/esbuild-plugin-api-graphql.d.ts.map +1 -1
- package/dist/cjs/build/esbuild-plugin-api-graphql.js +3 -1
- 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
|
@@ -32,6 +32,7 @@ import { applyOtelWrapping } from "./esbuild-plugin-cedar-otel-wrapping.js";
|
|
|
32
32
|
import { applyHandlerAlsWrapping } from "./esbuild-plugin-handler-als-wrapping.js";
|
|
33
33
|
import { applyEsmExtensions } from "./esm-extensions.js";
|
|
34
34
|
import { applyImportDir } from "./import-dir.js";
|
|
35
|
+
import { applyJobPathInjector } from "./job-path-injector.js";
|
|
35
36
|
import { applySrcAlias } from "./src-alias.js";
|
|
36
37
|
import { applyTsconfigPaths } from "./tsconfig-paths.js";
|
|
37
38
|
import { applySrcAlias as applySrcAlias2 } from "./src-alias.js";
|
|
@@ -75,20 +76,19 @@ const runCedarBabelTransformsPlugin = {
|
|
|
75
76
|
fileContents = applyDirectoryNamedImport(fileContents, args.path);
|
|
76
77
|
fileContents = applyAutoImports(fileContents);
|
|
77
78
|
fileContents = applyImportDir(fileContents, args.path)?.code ?? fileContents;
|
|
79
|
+
fileContents = applyJobPathInjector(fileContents, args.path, getPaths().api.jobs) ?? fileContents;
|
|
78
80
|
const normalizedPath = normalizePath(args.path);
|
|
79
81
|
const cedarPaths = getPaths();
|
|
80
82
|
const isEsm = projectSideIsEsm("api");
|
|
81
83
|
const apiBabelConfigPath = getApiSideBabelConfigPath();
|
|
82
|
-
const isJobsFile = normalizedPath.startsWith(
|
|
83
|
-
normalizePath(cedarPaths.api.jobs) + "/"
|
|
84
|
-
);
|
|
85
|
-
const useBabel = Boolean(apiBabelConfigPath) || isJobsFile;
|
|
86
84
|
let code = fileContents;
|
|
87
|
-
if (
|
|
85
|
+
if (apiBabelConfigPath) {
|
|
88
86
|
const transformedCode = await transformWithBabel(
|
|
89
87
|
fileContents,
|
|
90
88
|
args.path,
|
|
91
|
-
getApiSideBabelPluginsForVite()
|
|
89
|
+
getApiSideBabelPluginsForVite(),
|
|
90
|
+
"inline",
|
|
91
|
+
true
|
|
92
92
|
);
|
|
93
93
|
if (!transformedCode?.code) {
|
|
94
94
|
throw new Error(`Could not transform file: ${args.path}`);
|
|
@@ -112,7 +112,7 @@ const runCedarBabelTransformsPlugin = {
|
|
|
112
112
|
// Babel output is always plain JS. Without Babel the contents are
|
|
113
113
|
// still TypeScript/JSX, so pick the loader matching the file's
|
|
114
114
|
// extension and let esbuild do the stripping.
|
|
115
|
-
loader:
|
|
115
|
+
loader: apiBabelConfigPath ? "js" : getEsbuildLoader(args.path)
|
|
116
116
|
};
|
|
117
117
|
});
|
|
118
118
|
}
|
|
@@ -202,22 +202,20 @@ function createCedarViteApiPlugin() {
|
|
|
202
202
|
path.dirname(path.relative(cedarPaths.api.src, id))
|
|
203
203
|
);
|
|
204
204
|
sourceCode = applyAutoImports(sourceCode);
|
|
205
|
+
sourceCode = applyJobPathInjector(sourceCode, id, cedarPaths.api.jobs) ?? sourceCode;
|
|
205
206
|
if (normalizedId.endsWith("/graphql.ts") || normalizedId.endsWith("/graphql.js")) {
|
|
206
207
|
sourceCode = applyGraphqlOptionsExtract(sourceCode) ?? sourceCode;
|
|
207
208
|
sourceCode = applyGqlormInject(sourceCode, id) ?? sourceCode;
|
|
208
209
|
}
|
|
209
210
|
const apiBabelConfigPath = getApiSideBabelConfigPath();
|
|
210
|
-
const
|
|
211
|
-
normalizePath(cedarPaths.api.jobs) + "/"
|
|
212
|
-
);
|
|
213
|
-
const useBabel = Boolean(apiBabelConfigPath) || isJobsFile;
|
|
214
|
-
const transformedCode = useBabel ? await transformWithBabel(
|
|
211
|
+
const transformedCode = apiBabelConfigPath ? await transformWithBabel(
|
|
215
212
|
sourceCode,
|
|
216
213
|
id,
|
|
217
214
|
getApiSideBabelPluginsForVite(),
|
|
215
|
+
true,
|
|
218
216
|
true
|
|
219
217
|
) : null;
|
|
220
|
-
if (
|
|
218
|
+
if (apiBabelConfigPath && !transformedCode?.code) {
|
|
221
219
|
throw new Error(`Could not transform file: ${id}`);
|
|
222
220
|
}
|
|
223
221
|
let outputCode = transformedCode?.code ?? sourceCode;
|
|
@@ -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;AAsB1C,eAAO,MAAM,qBAAqB;;iBAEnB,WAAW;
|
|
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"}
|
|
@@ -46,7 +46,9 @@ const cedarApiGraphqlPlugin = {
|
|
|
46
46
|
const transformedCode = await transformWithBabel(
|
|
47
47
|
fileContents,
|
|
48
48
|
args.path,
|
|
49
|
-
getApiSideBabelPluginsForVite()
|
|
49
|
+
getApiSideBabelPluginsForVite(),
|
|
50
|
+
"inline",
|
|
51
|
+
true
|
|
50
52
|
);
|
|
51
53
|
if (!transformedCode?.code) {
|
|
52
54
|
throw new Error(`Could not transform file: ${args.path}`);
|
|
@@ -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
|
@@ -54,6 +54,7 @@ var import_esbuild_plugin_cedar_otel_wrapping = require("./esbuild-plugin-cedar-
|
|
|
54
54
|
var import_esbuild_plugin_handler_als_wrapping = require("./esbuild-plugin-handler-als-wrapping.js");
|
|
55
55
|
var import_esm_extensions = require("./esm-extensions.js");
|
|
56
56
|
var import_import_dir = require("./import-dir.js");
|
|
57
|
+
var import_job_path_injector = require("./job-path-injector.js");
|
|
57
58
|
var import_src_alias = require("./src-alias.js");
|
|
58
59
|
var import_tsconfig_paths = require("./tsconfig-paths.js");
|
|
59
60
|
var import_src_alias2 = require("./src-alias.js");
|
|
@@ -102,20 +103,19 @@ const runCedarBabelTransformsPlugin = {
|
|
|
102
103
|
fileContents = (0, import_directory_named_import.applyDirectoryNamedImport)(fileContents, args.path);
|
|
103
104
|
fileContents = (0, import_auto_import.applyAutoImports)(fileContents);
|
|
104
105
|
fileContents = (0, import_import_dir.applyImportDir)(fileContents, args.path)?.code ?? fileContents;
|
|
106
|
+
fileContents = (0, import_job_path_injector.applyJobPathInjector)(fileContents, args.path, (0, import_project_config.getPaths)().api.jobs) ?? fileContents;
|
|
105
107
|
const normalizedPath = (0, import_vite.normalizePath)(args.path);
|
|
106
108
|
const cedarPaths = (0, import_project_config.getPaths)();
|
|
107
109
|
const isEsm = (0, import_project_config.projectSideIsEsm)("api");
|
|
108
110
|
const apiBabelConfigPath = (0, import_babel_config.getApiSideBabelConfigPath)();
|
|
109
|
-
const isJobsFile = normalizedPath.startsWith(
|
|
110
|
-
(0, import_vite.normalizePath)(cedarPaths.api.jobs) + "/"
|
|
111
|
-
);
|
|
112
|
-
const useBabel = Boolean(apiBabelConfigPath) || isJobsFile;
|
|
113
111
|
let code = fileContents;
|
|
114
|
-
if (
|
|
112
|
+
if (apiBabelConfigPath) {
|
|
115
113
|
const transformedCode = await (0, import_babel_config.transformWithBabel)(
|
|
116
114
|
fileContents,
|
|
117
115
|
args.path,
|
|
118
|
-
(0, import_babel_config.getApiSideBabelPluginsForVite)()
|
|
116
|
+
(0, import_babel_config.getApiSideBabelPluginsForVite)(),
|
|
117
|
+
"inline",
|
|
118
|
+
true
|
|
119
119
|
);
|
|
120
120
|
if (!transformedCode?.code) {
|
|
121
121
|
throw new Error(`Could not transform file: ${args.path}`);
|
|
@@ -139,7 +139,7 @@ const runCedarBabelTransformsPlugin = {
|
|
|
139
139
|
// Babel output is always plain JS. Without Babel the contents are
|
|
140
140
|
// still TypeScript/JSX, so pick the loader matching the file's
|
|
141
141
|
// extension and let esbuild do the stripping.
|
|
142
|
-
loader:
|
|
142
|
+
loader: apiBabelConfigPath ? "js" : getEsbuildLoader(args.path)
|
|
143
143
|
};
|
|
144
144
|
});
|
|
145
145
|
}
|
|
@@ -229,22 +229,20 @@ function createCedarViteApiPlugin() {
|
|
|
229
229
|
import_node_path.default.dirname(import_node_path.default.relative(cedarPaths.api.src, id))
|
|
230
230
|
);
|
|
231
231
|
sourceCode = (0, import_auto_import.applyAutoImports)(sourceCode);
|
|
232
|
+
sourceCode = (0, import_job_path_injector.applyJobPathInjector)(sourceCode, id, cedarPaths.api.jobs) ?? sourceCode;
|
|
232
233
|
if (normalizedId.endsWith("/graphql.ts") || normalizedId.endsWith("/graphql.js")) {
|
|
233
234
|
sourceCode = (0, import_api_graphql_transforms.applyGraphqlOptionsExtract)(sourceCode) ?? sourceCode;
|
|
234
235
|
sourceCode = (0, import_api_graphql_transforms.applyGqlormInject)(sourceCode, id) ?? sourceCode;
|
|
235
236
|
}
|
|
236
237
|
const apiBabelConfigPath = (0, import_babel_config.getApiSideBabelConfigPath)();
|
|
237
|
-
const
|
|
238
|
-
(0, import_vite.normalizePath)(cedarPaths.api.jobs) + "/"
|
|
239
|
-
);
|
|
240
|
-
const useBabel = Boolean(apiBabelConfigPath) || isJobsFile;
|
|
241
|
-
const transformedCode = useBabel ? await (0, import_babel_config.transformWithBabel)(
|
|
238
|
+
const transformedCode = apiBabelConfigPath ? await (0, import_babel_config.transformWithBabel)(
|
|
242
239
|
sourceCode,
|
|
243
240
|
id,
|
|
244
241
|
(0, import_babel_config.getApiSideBabelPluginsForVite)(),
|
|
242
|
+
true,
|
|
245
243
|
true
|
|
246
244
|
) : null;
|
|
247
|
-
if (
|
|
245
|
+
if (apiBabelConfigPath && !transformedCode?.code) {
|
|
248
246
|
throw new Error(`Could not transform file: ${id}`);
|
|
249
247
|
}
|
|
250
248
|
let outputCode = transformedCode?.code ?? sourceCode;
|
|
@@ -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;AAsB1C,eAAO,MAAM,qBAAqB;;iBAEnB,WAAW;
|
|
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"}
|
|
@@ -72,7 +72,9 @@ const cedarApiGraphqlPlugin = {
|
|
|
72
72
|
const transformedCode = await (0, import_babel_config.transformWithBabel)(
|
|
73
73
|
fileContents,
|
|
74
74
|
args.path,
|
|
75
|
-
(0, import_babel_config.getApiSideBabelPluginsForVite)()
|
|
75
|
+
(0, import_babel_config.getApiSideBabelPluginsForVite)(),
|
|
76
|
+
"inline",
|
|
77
|
+
true
|
|
76
78
|
);
|
|
77
79
|
if (!transformedCode?.code) {
|
|
78
80
|
throw new Error(`Could not transform file: ${args.path}`);
|
|
@@ -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.2699",
|
|
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.2699",
|
|
183
|
+
"@cedarjs/cli-helpers": "6.0.0-canary.2699",
|
|
184
|
+
"@cedarjs/graphql-server": "6.0.0-canary.2699",
|
|
185
|
+
"@cedarjs/project-config": "6.0.0-canary.2699",
|
|
186
|
+
"@cedarjs/router": "6.0.0-canary.2699",
|
|
187
|
+
"@cedarjs/structure": "6.0.0-canary.2699",
|
|
188
|
+
"@cedarjs/utils": "6.0.0-canary.2699",
|
|
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.2699",
|
|
234
234
|
"concurrently": "9.2.1",
|
|
235
235
|
"graphql-tag": "2.12.6",
|
|
236
236
|
"publint": "0.3.21",
|