@cedarjs/vite 5.0.7-next.338 → 5.0.7
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/bins/cedar-vite-dev.mjs +1 -14
- package/dist/api/vite-plugin-cedar-vitest-api-preset.d.ts.map +1 -1
- package/dist/api/vite-plugin-cedar-vitest-api-preset.js +0 -4
- package/dist/apiDevMiddleware.d.ts.map +1 -1
- package/dist/apiDevMiddleware.js +15 -117
- package/dist/buildApp.d.ts.map +1 -1
- package/dist/buildApp.js +18 -77
- package/dist/buildRouteHooks.d.ts.map +1 -1
- package/dist/buildRouteHooks.js +4 -36
- package/dist/bundled/react-server-dom-webpack.server.js +99 -192
- package/dist/cedar-unified-dev.d.ts +0 -19
- package/dist/cedar-unified-dev.d.ts.map +1 -1
- package/dist/cedar-unified-dev.js +9 -74
- package/dist/cjs/ClientRouter.d.ts +1 -0
- package/dist/cjs/api/vite-plugin-cedar-vitest-api-preset.js +37 -0
- package/dist/cjs/apiDevMiddleware.js +371 -0
- package/dist/cjs/build/build.d.ts +1 -0
- package/dist/cjs/build/build.js +58 -0
- package/dist/cjs/buildApp.js +306 -0
- package/dist/cjs/buildFeServer.d.ts +1 -0
- package/dist/cjs/buildFeServer.js +63 -0
- package/dist/cjs/buildRouteHooks.js +80 -0
- package/dist/cjs/buildRouteManifest.js +92 -0
- package/dist/cjs/buildRscClientAndServer.js +54 -0
- package/dist/cjs/cedar-unified-dev.js +310 -0
- package/dist/cjs/client.d.ts +1 -0
- package/dist/cjs/clientSsr.d.ts +1 -0
- package/dist/cjs/devFeServer.js +157 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +141 -0
- package/dist/cjs/lib/StatusError.js +37 -0
- package/dist/cjs/lib/entries.js +52 -0
- package/dist/cjs/lib/getMergedConfig.js +185 -0
- package/dist/cjs/lib/onWarn.js +36 -0
- package/dist/cjs/lib/registerFwGlobalsAndShims.js +102 -0
- package/dist/cjs/lib/workspacePackageAliases.js +107 -0
- package/dist/cjs/middleware/index.js +22 -0
- package/dist/cjs/middleware/invokeMiddleware.js +52 -0
- package/dist/cjs/middleware/register.js +105 -0
- package/dist/cjs/middleware/types.js +16 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/plugins/vite-plugin-cedar-auto-import.js +107 -0
- package/dist/cjs/plugins/vite-plugin-cedar-cell.js +183 -0
- package/dist/cjs/plugins/vite-plugin-cedar-cjs-compat.js +341 -0
- package/dist/cjs/plugins/vite-plugin-cedar-context-wrapping.js +95 -0
- package/dist/cjs/plugins/vite-plugin-cedar-entry-injection.js +107 -0
- package/dist/cjs/plugins/vite-plugin-cedar-html-env.js +67 -0
- package/dist/cjs/plugins/vite-plugin-cedar-import-dir.js +118 -0
- package/dist/cjs/plugins/vite-plugin-cedar-node-polyfills.js +43 -0
- package/dist/cjs/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js +61 -0
- package/dist/cjs/plugins/vite-plugin-cedar-remove-from-bundle.js +76 -0
- package/dist/cjs/plugins/vite-plugin-cedar-routes-auto-loader.js +126 -0
- package/dist/cjs/plugins/vite-plugin-cedar-universal-deploy.js +346 -0
- package/dist/cjs/plugins/vite-plugin-cedar-wait-for-api-server.js +134 -0
- package/dist/cjs/plugins/vite-plugin-cedarjs-job-path-injector.js +134 -0
- package/dist/cjs/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js +106 -0
- package/dist/cjs/plugins/vite-plugin-jsx-loader.js +42 -0
- package/dist/cjs/plugins/vite-plugin-merged-config.js +39 -0
- package/dist/cjs/plugins/vite-plugin-rsc-analyze.js +104 -0
- package/dist/cjs/plugins/vite-plugin-rsc-reload.js +75 -0
- package/dist/cjs/plugins/vite-plugin-rsc-routes-auto-loader.js +159 -0
- package/dist/cjs/plugins/vite-plugin-rsc-routes-imports.js +125 -0
- package/dist/cjs/plugins/vite-plugin-rsc-ssr-router-import.js +75 -0
- package/dist/cjs/plugins/vite-plugin-rsc-transform-client.js +228 -0
- package/dist/cjs/plugins/vite-plugin-rsc-transform-server.js +398 -0
- package/dist/cjs/plugins/vite-plugin-swap-apollo-provider.js +46 -0
- package/dist/cjs/rsc/rscBuildAnalyze.js +126 -0
- package/dist/cjs/rsc/rscBuildClient.js +91 -0
- package/dist/cjs/rsc/rscBuildCopyCssAssets.js +56 -0
- package/dist/cjs/rsc/rscBuildEntriesFile.js +115 -0
- package/dist/cjs/rsc/rscBuildForServer.js +168 -0
- package/dist/cjs/rsc/rscBuildForSsr.js +173 -0
- package/dist/cjs/rsc/rscBuildRwEnvVars.js +56 -0
- package/dist/cjs/rsc/rscRenderer.js +165 -0
- package/dist/cjs/rsc/rscRequestHandler.js +162 -0
- package/dist/cjs/rsc/rscStudioHandlers.js +156 -0
- package/dist/cjs/runFeServer.js +165 -0
- package/dist/cjs/streaming/buildForStreamingServer.js +65 -0
- package/dist/cjs/streaming/collectCss.js +52 -0
- package/dist/cjs/streaming/createReactStreamingHandler.js +173 -0
- package/dist/cjs/streaming/streamHelpers.js +230 -0
- package/dist/cjs/streaming/transforms/bufferedTransform.js +61 -0
- package/dist/cjs/streaming/transforms/cancelTimeoutTransform.js +34 -0
- package/dist/cjs/streaming/transforms/encode-decode.js +36 -0
- package/dist/cjs/streaming/transforms/serverInjectionTransform.js +84 -0
- package/dist/cjs/streaming/triggerRouteHooks.js +96 -0
- package/dist/cjs/types.js +16 -0
- package/dist/cjs/utils.js +92 -0
- package/dist/devFeServer.js +8 -3
- package/dist/index.d.ts +4 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -51
- package/dist/lib/getMergedConfig.d.ts.map +1 -1
- package/dist/lib/getMergedConfig.js +6 -16
- package/dist/lib/registerFwGlobalsAndShims.d.ts.map +1 -1
- package/dist/lib/registerFwGlobalsAndShims.js +4 -14
- package/dist/package.json +1 -0
- package/dist/plugins/vite-plugin-cedar-auto-import.d.ts +1 -1
- package/dist/plugins/vite-plugin-cedar-auto-import.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-cedar-auto-import.js +1 -8
- package/dist/plugins/vite-plugin-cedar-cell.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-cedar-cell.js +1 -2
- package/dist/plugins/{vite-plugin-handler-als-wrapping.d.ts → vite-plugin-cedar-context-wrapping.d.ts} +12 -12
- package/dist/plugins/vite-plugin-cedar-context-wrapping.d.ts.map +1 -0
- package/dist/plugins/{vite-plugin-handler-als-wrapping.js → vite-plugin-cedar-context-wrapping.js} +16 -16
- package/dist/plugins/vite-plugin-cedar-import-dir.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-cedar-import-dir.js +31 -44
- package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts +3 -0
- package/dist/plugins/vite-plugin-cedar-node-polyfills.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedar-node-polyfills.js +19 -0
- package/dist/plugins/vite-plugin-cedar-universal-deploy.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-cedar-universal-deploy.js +90 -92
- package/dist/plugins/vite-plugin-cedarjs-job-path-injector.d.ts +0 -29
- package/dist/plugins/vite-plugin-cedarjs-job-path-injector.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-cedarjs-job-path-injector.js +81 -63
- package/dist/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js +0 -14
- package/dist/plugins/vite-plugin-rsc-analyze.js +1 -2
- package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts +0 -3
- package/dist/plugins/vite-plugin-swap-apollo-provider.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-swap-apollo-provider.js +2 -2
- package/dist/rsc/rscBuildForSsr.d.ts.map +1 -1
- package/dist/rsc/rscBuildForSsr.js +5 -3
- package/dist/streaming/buildForStreamingServer.d.ts.map +1 -1
- package/dist/streaming/buildForStreamingServer.js +5 -3
- package/package.json +57 -47
- package/dist/jobsDevMiddleware.d.ts +0 -17
- package/dist/jobsDevMiddleware.d.ts.map +0 -1
- package/dist/jobsDevMiddleware.js +0 -106
- package/dist/lib/generateDiffSourceMap.d.ts +0 -18
- package/dist/lib/generateDiffSourceMap.d.ts.map +0 -1
- package/dist/lib/generateDiffSourceMap.js +0 -151
- package/dist/plugins/vite-plugin-cedar-api-import-guard.d.ts +0 -13
- package/dist/plugins/vite-plugin-cedar-api-import-guard.d.ts.map +0 -1
- package/dist/plugins/vite-plugin-cedar-api-import-guard.js +0 -17
- package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts +0 -3
- package/dist/plugins/vite-plugin-cedar-data-uri-shim.d.ts.map +0 -1
- package/dist/plugins/vite-plugin-cedar-data-uri-shim.js +0 -43
- package/dist/plugins/vite-plugin-cedar-directory-named-import.d.ts +0 -12
- package/dist/plugins/vite-plugin-cedar-directory-named-import.d.ts.map +0 -1
- package/dist/plugins/vite-plugin-cedar-directory-named-import.js +0 -35
- package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts +0 -29
- package/dist/plugins/vite-plugin-cedar-gqlorm-inject.d.ts.map +0 -1
- package/dist/plugins/vite-plugin-cedar-gqlorm-inject.js +0 -76
- package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts +0 -42
- package/dist/plugins/vite-plugin-cedar-graphql-options-extract.d.ts.map +0 -1
- package/dist/plugins/vite-plugin-cedar-graphql-options-extract.js +0 -103
- package/dist/plugins/vite-plugin-cedar-log-formatter-dev.d.ts +0 -28
- package/dist/plugins/vite-plugin-cedar-log-formatter-dev.d.ts.map +0 -1
- package/dist/plugins/vite-plugin-cedar-log-formatter-dev.js +0 -67
- package/dist/plugins/vite-plugin-cedar-mock-cell-data.d.ts +0 -28
- package/dist/plugins/vite-plugin-cedar-mock-cell-data.d.ts.map +0 -1
- package/dist/plugins/vite-plugin-cedar-mock-cell-data.js +0 -247
- package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts +0 -39
- package/dist/plugins/vite-plugin-cedar-otel-wrapping.d.ts.map +0 -1
- package/dist/plugins/vite-plugin-cedar-otel-wrapping.js +0 -200
- package/dist/plugins/vite-plugin-handler-als-wrapping.d.ts.map +0 -1
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from 'vite';
|
|
2
|
-
/**
|
|
3
|
-
* Vite plugin that automatically wraps the `standard` export in Cell mock files
|
|
4
|
-
* with `mockGraphQLQuery`.
|
|
5
|
-
*
|
|
6
|
-
* Only active in non-production environments (for Storybook and Jest).
|
|
7
|
-
*
|
|
8
|
-
* Transforms `*.Cell.mock.[js,ts]` files by:
|
|
9
|
-
* 1. Determining the query operation name from the adjacent Cell's QUERY export
|
|
10
|
-
* 2. Wrapping the `standard` function export in `mockGraphQLQuery(operationName, fn)`
|
|
11
|
-
* 3. If the Cell has an `afterQuery` export, also wraps with `afterQuery(fn())`
|
|
12
|
-
*
|
|
13
|
-
* This is a 1:1 port of `babel-plugin-redwood-mock-cell-data`.
|
|
14
|
-
*/
|
|
15
|
-
export declare function cedarMockCellDataPlugin(): Plugin;
|
|
16
|
-
export declare const getCellMetadata: (p: string) => {
|
|
17
|
-
hasDefaultExport: boolean;
|
|
18
|
-
namedExports: NamedExports[];
|
|
19
|
-
hasQueryExport: NamedExports | undefined;
|
|
20
|
-
hasAfterQueryExport: NamedExports | undefined;
|
|
21
|
-
operationName: string;
|
|
22
|
-
};
|
|
23
|
-
interface NamedExports {
|
|
24
|
-
name: string;
|
|
25
|
-
type: 're-export' | 'variable' | 'function' | 'class';
|
|
26
|
-
}
|
|
27
|
-
export {};
|
|
28
|
-
//# sourceMappingURL=vite-plugin-cedar-mock-cell-data.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-cedar-mock-cell-data.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-mock-cell-data.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAMlC;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CA2KhD;AAcD,eAAO,MAAM,eAAe,GAAI,GAAG,MAAM;;;;;;CAoFxC,CAAA;AAgCD,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAA;CACtD"}
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import babelGenerator from "@babel/generator";
|
|
4
|
-
import { parse as babelParse } from "@babel/parser";
|
|
5
|
-
import babelTraverse from "@babel/traverse";
|
|
6
|
-
import * as t from "@babel/types";
|
|
7
|
-
import fg from "fast-glob";
|
|
8
|
-
import { parse as graphqlParse, Kind } from "graphql";
|
|
9
|
-
const traverse = babelTraverse.default ?? babelTraverse;
|
|
10
|
-
const generate = babelGenerator.default ?? babelGenerator;
|
|
11
|
-
function cedarMockCellDataPlugin() {
|
|
12
|
-
return {
|
|
13
|
-
name: "cedar-mock-cell-data",
|
|
14
|
-
transform(code, id) {
|
|
15
|
-
if (!id.endsWith("Cell.mock.js") && !id.endsWith("Cell.mock.ts")) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
if (process.env.NODE_ENV === "production") {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
const ast = parse(id, code);
|
|
22
|
-
if (!ast) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
let pathsToRemove = [];
|
|
26
|
-
const nodesToInsert = [];
|
|
27
|
-
const createVisitors = (addWatchFile) => ({
|
|
28
|
-
ExportNamedDeclaration(p) {
|
|
29
|
-
const d = p.node.declaration;
|
|
30
|
-
let mockFunction = null;
|
|
31
|
-
switch (d?.type) {
|
|
32
|
-
case "VariableDeclaration": {
|
|
33
|
-
const standardMockExport = d.declarations[0];
|
|
34
|
-
const exportId = standardMockExport.id;
|
|
35
|
-
const exportName = exportId?.name;
|
|
36
|
-
if (exportName !== "standard") {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const mockFunctionMaybe = standardMockExport?.init;
|
|
40
|
-
if (!mockFunctionMaybe) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
if (mockFunctionMaybe.type !== "ArrowFunctionExpression" && mockFunctionMaybe.type !== "FunctionExpression") {
|
|
44
|
-
throw new Error(
|
|
45
|
-
`
|
|
46
|
-
|
|
47
|
-
Mock Error: You must export your standard mock as a function
|
|
48
|
-
|
|
49
|
-
`
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
mockFunction = mockFunctionMaybe;
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
case "FunctionDeclaration": {
|
|
56
|
-
const exportName = d.id?.name;
|
|
57
|
-
if (exportName !== "standard") {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
mockFunction = t.arrowFunctionExpression(d.params, d.body);
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
default:
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const dirname = path.dirname(id);
|
|
67
|
-
const cellName = path.basename(dirname);
|
|
68
|
-
const [cellPath] = fg.sync(`${cellName}.{js,jsx,ts,tsx}`, {
|
|
69
|
-
cwd: dirname,
|
|
70
|
-
absolute: true,
|
|
71
|
-
ignore: ["node_modules"]
|
|
72
|
-
});
|
|
73
|
-
if (!cellPath) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
addWatchFile?.(cellPath);
|
|
77
|
-
const cellMetadata = getCellMetadata(cellPath);
|
|
78
|
-
if (cellMetadata.hasDefaultExport || !cellMetadata.hasQueryExport) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (!cellMetadata.operationName) {
|
|
82
|
-
console.warn(
|
|
83
|
-
`[cedar-mock-cell-data] Cell ${cellPath} has an unnamed GraphQL operation. The mock for ${id} will not work. Ensure the QUERY is named, e.g., "query GetUser { ... }"`
|
|
84
|
-
);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const mockGraphQLCall = t.callExpression(
|
|
88
|
-
t.identifier("mockGraphQLQuery"),
|
|
89
|
-
[
|
|
90
|
-
t.stringLiteral(cellMetadata.operationName),
|
|
91
|
-
mockFunction
|
|
92
|
-
]
|
|
93
|
-
);
|
|
94
|
-
pathsToRemove = [...pathsToRemove, p];
|
|
95
|
-
if (cellMetadata.hasAfterQueryExport) {
|
|
96
|
-
const importAfterQuery = t.importDeclaration(
|
|
97
|
-
[
|
|
98
|
-
t.importSpecifier(
|
|
99
|
-
t.identifier("afterQuery"),
|
|
100
|
-
t.identifier("afterQuery")
|
|
101
|
-
)
|
|
102
|
-
],
|
|
103
|
-
t.stringLiteral(`./${path.basename(cellPath)}`)
|
|
104
|
-
);
|
|
105
|
-
nodesToInsert.push(
|
|
106
|
-
importAfterQuery,
|
|
107
|
-
createExportStandard(
|
|
108
|
-
t,
|
|
109
|
-
t.arrowFunctionExpression(
|
|
110
|
-
[],
|
|
111
|
-
t.callExpression(t.identifier("afterQuery"), [
|
|
112
|
-
t.callExpression(mockGraphQLCall, [])
|
|
113
|
-
])
|
|
114
|
-
)
|
|
115
|
-
)
|
|
116
|
-
);
|
|
117
|
-
} else {
|
|
118
|
-
nodesToInsert.push(createExportStandard(t, mockGraphQLCall));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
traverse(ast, createVisitors(this.addWatchFile?.bind(this)));
|
|
123
|
-
if (nodesToInsert.length === 0) {
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
for (const p of pathsToRemove) {
|
|
127
|
-
p.remove();
|
|
128
|
-
}
|
|
129
|
-
;
|
|
130
|
-
ast.program.body.unshift(...nodesToInsert);
|
|
131
|
-
const result = generate(ast, { retainLines: false }, code);
|
|
132
|
-
return {
|
|
133
|
-
code: result.code,
|
|
134
|
-
map: result.map
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
function createExportStandard(babelTypes, ex) {
|
|
140
|
-
return babelTypes.exportNamedDeclaration(
|
|
141
|
-
babelTypes.variableDeclaration("const", [
|
|
142
|
-
babelTypes.variableDeclarator(babelTypes.identifier("standard"), ex)
|
|
143
|
-
])
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
const getCellMetadata = (p) => {
|
|
147
|
-
const ast = getCellAst(p);
|
|
148
|
-
let hasDefaultExport = false;
|
|
149
|
-
const namedExports = [];
|
|
150
|
-
let operation;
|
|
151
|
-
traverse(ast, {
|
|
152
|
-
ExportDefaultDeclaration() {
|
|
153
|
-
hasDefaultExport = true;
|
|
154
|
-
},
|
|
155
|
-
ExportNamedDeclaration(path2) {
|
|
156
|
-
const specifiers = path2.node?.specifiers;
|
|
157
|
-
if (specifiers.length) {
|
|
158
|
-
for (const s of specifiers) {
|
|
159
|
-
const id = s.exported;
|
|
160
|
-
namedExports.push({
|
|
161
|
-
name: id.name,
|
|
162
|
-
type: "re-export"
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
const declaration = path2.node.declaration;
|
|
168
|
-
if (!declaration) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
if (declaration.type === "VariableDeclaration") {
|
|
172
|
-
const id = declaration.declarations[0].id;
|
|
173
|
-
namedExports.push({
|
|
174
|
-
name: id.name,
|
|
175
|
-
type: "variable"
|
|
176
|
-
});
|
|
177
|
-
} else if (declaration.type === "FunctionDeclaration") {
|
|
178
|
-
namedExports.push({
|
|
179
|
-
name: declaration?.id?.name,
|
|
180
|
-
type: "function"
|
|
181
|
-
});
|
|
182
|
-
} else if (declaration.type === "ClassDeclaration") {
|
|
183
|
-
namedExports.push({
|
|
184
|
-
name: declaration?.id?.name,
|
|
185
|
-
type: "class"
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
},
|
|
189
|
-
TaggedTemplateExpression(path2) {
|
|
190
|
-
if (path2.parent?.id?.name !== "QUERY") {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
operation = path2.node.quasi.quasis[0].value.raw;
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
const hasQueryExport = namedExports.find(({ name }) => name === "QUERY");
|
|
197
|
-
const hasAfterQueryExport = namedExports.find(
|
|
198
|
-
({ name }) => name === "afterQuery"
|
|
199
|
-
);
|
|
200
|
-
let operationName = "";
|
|
201
|
-
if (operation) {
|
|
202
|
-
const document = graphqlParse(operation);
|
|
203
|
-
for (const definition of document.definitions) {
|
|
204
|
-
if (definition.kind === Kind.OPERATION_DEFINITION && definition.name?.value) {
|
|
205
|
-
operationName = definition.name.value;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return {
|
|
210
|
-
hasDefaultExport,
|
|
211
|
-
namedExports,
|
|
212
|
-
hasQueryExport,
|
|
213
|
-
hasAfterQueryExport,
|
|
214
|
-
operationName
|
|
215
|
-
};
|
|
216
|
-
};
|
|
217
|
-
function getCellAst(filePath) {
|
|
218
|
-
const code = fs.readFileSync(filePath, "utf-8");
|
|
219
|
-
const plugins = ["typescript", "jsx"].filter(Boolean);
|
|
220
|
-
try {
|
|
221
|
-
return babelParse(code, {
|
|
222
|
-
sourceType: "module",
|
|
223
|
-
plugins
|
|
224
|
-
});
|
|
225
|
-
} catch (e) {
|
|
226
|
-
console.error(`Error parsing: ${filePath}`);
|
|
227
|
-
console.error(e);
|
|
228
|
-
throw new Error(e?.message);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
function parse(filePath, code) {
|
|
232
|
-
const plugins = ["typescript", "jsx"].filter(Boolean);
|
|
233
|
-
try {
|
|
234
|
-
return babelParse(code, {
|
|
235
|
-
sourceType: "module",
|
|
236
|
-
plugins
|
|
237
|
-
});
|
|
238
|
-
} catch (e) {
|
|
239
|
-
console.error(`Error parsing: ${filePath}`);
|
|
240
|
-
console.error(e);
|
|
241
|
-
return null;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
export {
|
|
245
|
-
cedarMockCellDataPlugin,
|
|
246
|
-
getCellMetadata
|
|
247
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from 'vite';
|
|
2
|
-
/**
|
|
3
|
-
* Vite plugin that wraps exported API functions with OpenTelemetry spans to
|
|
4
|
-
* provide automatic tracing in your Cedar API.
|
|
5
|
-
*
|
|
6
|
-
* For each `export const fn = (async?) (...) => {...}` declaration in an API
|
|
7
|
-
* file this plugin:
|
|
8
|
-
*
|
|
9
|
-
* 1. Adds an import at the top of the file:
|
|
10
|
-
* import { trace as OTEL_TRACE } from '@opentelemetry/api'
|
|
11
|
-
*
|
|
12
|
-
* 2. Wraps the original export with an OTel span:
|
|
13
|
-
* export const fn = (async?) (...params) => {
|
|
14
|
-
* const __fn = (async?) (...params) => { ...original body... }
|
|
15
|
-
* const OTEL_TRACER = OTEL_TRACE.getTracer('redwoodjs')
|
|
16
|
-
* const OTEL_RESULT = (await?) OTEL_TRACER.startActiveSpan(
|
|
17
|
-
* 'redwoodjs:api:<folder>:<fnName>',
|
|
18
|
-
* (async?) (span) => { ... }
|
|
19
|
-
* )
|
|
20
|
-
* return OTEL_RESULT
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* This replaces `babel-plugin-redwood-otel-wrapping` for all Vite and esbuild
|
|
24
|
-
* builds. The previous Babel plugin has been removed entirely; Jest transforms
|
|
25
|
-
* through the Vite SSR pipeline.
|
|
26
|
-
*
|
|
27
|
-
* NOTE: Known limitation. Spans will close before a Promise settles if a
|
|
28
|
-
* synchronous function returns a Promise. To trace async work correctly, mark
|
|
29
|
-
* the function as `async` if it returns or awaits Promises.
|
|
30
|
-
*/
|
|
31
|
-
export declare function cedarOtelWrappingPlugin(): Plugin;
|
|
32
|
-
/**
|
|
33
|
-
* Applies OpenTelemetry span wrapping to API source files.
|
|
34
|
-
*
|
|
35
|
-
* Exported as a standalone function so it can be tested without a Vite context.
|
|
36
|
-
* Returns the transformed code string, or `null` if nothing was changed.
|
|
37
|
-
*/
|
|
38
|
-
export declare function applyOtelWrapping(code: string, filename: string, apiFolder: string): string | null;
|
|
39
|
-
//# sourceMappingURL=vite-plugin-cedar-otel-wrapping.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-cedar-otel-wrapping.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-otel-wrapping.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAwBhD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,MAAM,GAAG,IAAI,CA+Ef"}
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { parseSync } from "oxc-parser";
|
|
2
|
-
import { normalizePath } from "vite";
|
|
3
|
-
import { getPaths } from "@cedarjs/project-config";
|
|
4
|
-
function cedarOtelWrappingPlugin() {
|
|
5
|
-
return {
|
|
6
|
-
name: "cedar-otel-wrapping",
|
|
7
|
-
transform(code, id) {
|
|
8
|
-
let apiSrc;
|
|
9
|
-
try {
|
|
10
|
-
apiSrc = normalizePath(getPaths().api.src);
|
|
11
|
-
} catch {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
if (!normalizePath(id).startsWith(apiSrc + "/")) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
const relativePath = normalizePath(id).slice(apiSrc.length + 1);
|
|
18
|
-
const apiFolder = relativePath.split("/")[0] ?? "?";
|
|
19
|
-
const result = applyOtelWrapping(code, id, apiFolder);
|
|
20
|
-
return result ? { code: result, map: null } : null;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function applyOtelWrapping(code, filename, apiFolder) {
|
|
25
|
-
const parseResult = parseSync(filename, code, { sourceType: "module" });
|
|
26
|
-
const replacements = [];
|
|
27
|
-
for (const node of parseResult.program.body) {
|
|
28
|
-
if (node.type !== "ExportNamedDeclaration") {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
const decl = node.declaration;
|
|
32
|
-
if (decl?.type !== "VariableDeclaration") {
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
const declarator = decl.declarations[0];
|
|
36
|
-
if (!declarator) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
const fn = declarator.init;
|
|
40
|
-
if (fn?.type !== "ArrowFunctionExpression") {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (declarator.id.type !== "Identifier") {
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
const fnName = declarator.id.name;
|
|
47
|
-
const innerArgs = buildInnerArgs(fn.params);
|
|
48
|
-
if (innerArgs === null) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
const fnHeader = code.slice(fn.start, fn.body.start);
|
|
52
|
-
const originalFnSrc = code.slice(fn.start, fn.end);
|
|
53
|
-
const isAsync = fn.async;
|
|
54
|
-
const awaitKw = isAsync ? "await " : "";
|
|
55
|
-
const asyncKw = isAsync ? "async " : "";
|
|
56
|
-
replacements.push({
|
|
57
|
-
start: node.start,
|
|
58
|
-
end: node.end,
|
|
59
|
-
src: buildWrappedExport(
|
|
60
|
-
fnName,
|
|
61
|
-
fnHeader,
|
|
62
|
-
originalFnSrc,
|
|
63
|
-
innerArgs,
|
|
64
|
-
awaitKw,
|
|
65
|
-
asyncKw,
|
|
66
|
-
apiFolder,
|
|
67
|
-
filename
|
|
68
|
-
)
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
if (replacements.length === 0) {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
let output = code;
|
|
75
|
-
for (let i = replacements.length - 1; i >= 0; i--) {
|
|
76
|
-
const r = replacements[i];
|
|
77
|
-
output = output.slice(0, r.start) + r.src + output.slice(r.end);
|
|
78
|
-
}
|
|
79
|
-
return `import { trace as OTEL_TRACE } from '@opentelemetry/api'
|
|
80
|
-
` + output;
|
|
81
|
-
}
|
|
82
|
-
function buildInnerArgs(params) {
|
|
83
|
-
const args = [];
|
|
84
|
-
for (const param of params) {
|
|
85
|
-
if (param.type === "RestElement" || param.type === "ArrayPattern" || param.type === "TSParameterProperty") {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
if (param.type === "Identifier") {
|
|
89
|
-
args.push(param.name);
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
if (param.type === "ObjectPattern") {
|
|
93
|
-
for (const prop of param.properties) {
|
|
94
|
-
if (prop.type === "RestElement") {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
if (prop.key.type !== "Identifier") {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
const value = prop.value;
|
|
101
|
-
if (value.type !== "Identifier" && value.type !== "AssignmentPattern" && value.type !== "ObjectPattern") {
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
if (value.type === "AssignmentPattern") {
|
|
105
|
-
if (value.left.type !== "Identifier" && value.left.type !== "ObjectPattern") {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const obj = buildObjectCallArg(param);
|
|
111
|
-
if (obj === null) {
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
args.push(obj);
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
if (param.type === "AssignmentPattern") {
|
|
118
|
-
const ap = param;
|
|
119
|
-
if (ap.left.type === "Identifier") {
|
|
120
|
-
args.push(ap.left.name);
|
|
121
|
-
} else if (ap.left.type === "ObjectPattern") {
|
|
122
|
-
const obj = buildObjectCallArg(ap.left);
|
|
123
|
-
if (obj === null) {
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
args.push(obj);
|
|
127
|
-
} else {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
return args.join(", ");
|
|
135
|
-
}
|
|
136
|
-
function buildObjectCallArg(pattern) {
|
|
137
|
-
const keys = [];
|
|
138
|
-
for (const prop of pattern.properties) {
|
|
139
|
-
if (prop.type === "RestElement") {
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
142
|
-
if (prop.key.type !== "Identifier") {
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
const keyName = prop.key.name;
|
|
146
|
-
let valueName = null;
|
|
147
|
-
if (prop.value.type === "Identifier") {
|
|
148
|
-
valueName = prop.value.name;
|
|
149
|
-
} else if (prop.value.type === "AssignmentPattern") {
|
|
150
|
-
if (prop.value.left.type === "Identifier") {
|
|
151
|
-
valueName = prop.value.left.name;
|
|
152
|
-
} else {
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
} else {
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
if (valueName !== keyName) {
|
|
159
|
-
keys.push(`${keyName}: ${valueName}`);
|
|
160
|
-
} else {
|
|
161
|
-
keys.push(keyName);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return `{ ${keys.join(", ")} }`;
|
|
165
|
-
}
|
|
166
|
-
function buildWrappedExport(fnName, fnHeader, originalFnSrc, innerArgs, awaitKw, asyncKw, apiFolder, filename) {
|
|
167
|
-
const privateName = `__${fnName}`;
|
|
168
|
-
const spanName = `redwoodjs:api:${apiFolder}:${fnName}`;
|
|
169
|
-
return `export const ${fnName} = ${fnHeader}{
|
|
170
|
-
const ${privateName} = ${originalFnSrc}
|
|
171
|
-
const OTEL_TRACER = OTEL_TRACE.getTracer('redwoodjs')
|
|
172
|
-
const OTEL_RESULT = ${awaitKw}OTEL_TRACER.startActiveSpan(
|
|
173
|
-
'${spanName}',
|
|
174
|
-
${asyncKw}(span) => {
|
|
175
|
-
span.setAttribute('code.function', '${fnName}')
|
|
176
|
-
span.setAttribute('code.filepath', ${JSON.stringify(filename)})
|
|
177
|
-
try {
|
|
178
|
-
const OTEL_INNER_RESULT = ${awaitKw}${privateName}(${innerArgs})
|
|
179
|
-
span.end()
|
|
180
|
-
return OTEL_INNER_RESULT
|
|
181
|
-
} catch (error) {
|
|
182
|
-
span.recordException(error)
|
|
183
|
-
span.setStatus({
|
|
184
|
-
code: 2,
|
|
185
|
-
message:
|
|
186
|
-
error?.message?.split('\\n')[0] ??
|
|
187
|
-
error?.toString()?.split('\\n')[0],
|
|
188
|
-
})
|
|
189
|
-
span.end()
|
|
190
|
-
throw error
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
)
|
|
194
|
-
return OTEL_RESULT
|
|
195
|
-
}`;
|
|
196
|
-
}
|
|
197
|
-
export {
|
|
198
|
-
applyOtelWrapping,
|
|
199
|
-
cedarOtelWrappingPlugin
|
|
200
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-handler-als-wrapping.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-handler-als-wrapping.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,wBAAwB,CAAC,EACvC,YAAoB,GACrB,GAAE;IACD,YAAY,CAAC,EAAE,OAAO,CAAA;CAClB,GAAG,MAAM,CAuBd;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,EAAE,YAAoB,EAAE,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO,GACxD,MAAM,GAAG,IAAI,CAsDf"}
|