@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,151 +0,0 @@
|
|
|
1
|
-
import MagicString from "magic-string";
|
|
2
|
-
const MAX_ALIGNMENT_CELLS = 1e6;
|
|
3
|
-
function generateDiffSourceMap(original, transformed) {
|
|
4
|
-
if (original === transformed) {
|
|
5
|
-
return null;
|
|
6
|
-
}
|
|
7
|
-
const ms = new MagicString(original);
|
|
8
|
-
const origLines = original.split("\n");
|
|
9
|
-
const newLines = transformed.split("\n");
|
|
10
|
-
const lineOffsets = new Array(origLines.length);
|
|
11
|
-
let offset = 0;
|
|
12
|
-
for (let i = 0; i < origLines.length; i++) {
|
|
13
|
-
lineOffsets[i] = offset;
|
|
14
|
-
offset += origLines[i].length + 1;
|
|
15
|
-
}
|
|
16
|
-
let prefix = 0;
|
|
17
|
-
const maxPrefix = Math.min(origLines.length, newLines.length);
|
|
18
|
-
while (prefix < maxPrefix && origLines[prefix] === newLines[prefix]) {
|
|
19
|
-
prefix++;
|
|
20
|
-
}
|
|
21
|
-
let suffix = 0;
|
|
22
|
-
const maxSuffix = Math.min(origLines.length, newLines.length) - prefix;
|
|
23
|
-
while (suffix < maxSuffix && origLines[origLines.length - 1 - suffix] === newLines[newLines.length - 1 - suffix]) {
|
|
24
|
-
suffix++;
|
|
25
|
-
}
|
|
26
|
-
const hunks = alignLines(
|
|
27
|
-
origLines,
|
|
28
|
-
prefix,
|
|
29
|
-
origLines.length - suffix,
|
|
30
|
-
newLines,
|
|
31
|
-
prefix,
|
|
32
|
-
newLines.length - suffix
|
|
33
|
-
);
|
|
34
|
-
for (const hunk of hunks) {
|
|
35
|
-
applyHunk(ms, hunk, origLines, newLines, lineOffsets, original.length);
|
|
36
|
-
}
|
|
37
|
-
if (ms.toString() !== transformed) {
|
|
38
|
-
return new MagicString(original).generateMap({ hires: true });
|
|
39
|
-
}
|
|
40
|
-
return ms.generateMap({ hires: true });
|
|
41
|
-
}
|
|
42
|
-
function alignLines(origLines, oLo, oHi, newLines, nLo, nHi) {
|
|
43
|
-
const m = oHi - oLo;
|
|
44
|
-
const n = nHi - nLo;
|
|
45
|
-
if (m === 0 && n === 0) {
|
|
46
|
-
return [];
|
|
47
|
-
}
|
|
48
|
-
if (m === 0 || n === 0 || m * n > MAX_ALIGNMENT_CELLS) {
|
|
49
|
-
return [{ oStart: oLo, oEnd: oHi, nStart: nLo, nEnd: nHi }];
|
|
50
|
-
}
|
|
51
|
-
const width = n + 1;
|
|
52
|
-
const dp = new Int32Array((m + 1) * width);
|
|
53
|
-
for (let i2 = m - 1; i2 >= 0; i2--) {
|
|
54
|
-
for (let j2 = n - 1; j2 >= 0; j2--) {
|
|
55
|
-
dp[i2 * width + j2] = origLines[oLo + i2] === newLines[nLo + j2] ? dp[(i2 + 1) * width + j2 + 1] + 1 : Math.max(dp[(i2 + 1) * width + j2], dp[i2 * width + j2 + 1]);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const hunks = [];
|
|
59
|
-
let i = 0;
|
|
60
|
-
let j = 0;
|
|
61
|
-
let hunkO = 0;
|
|
62
|
-
let hunkN = 0;
|
|
63
|
-
const flushHunk = () => {
|
|
64
|
-
if (i > hunkO || j > hunkN) {
|
|
65
|
-
hunks.push({
|
|
66
|
-
oStart: oLo + hunkO,
|
|
67
|
-
oEnd: oLo + i,
|
|
68
|
-
nStart: nLo + hunkN,
|
|
69
|
-
nEnd: nLo + j
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
while (i < m && j < n) {
|
|
74
|
-
if (origLines[oLo + i] === newLines[nLo + j]) {
|
|
75
|
-
flushHunk();
|
|
76
|
-
i++;
|
|
77
|
-
j++;
|
|
78
|
-
hunkO = i;
|
|
79
|
-
hunkN = j;
|
|
80
|
-
} else if (dp[(i + 1) * width + j] >= dp[i * width + j + 1]) {
|
|
81
|
-
i++;
|
|
82
|
-
} else {
|
|
83
|
-
j++;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
i = m;
|
|
87
|
-
j = n;
|
|
88
|
-
flushHunk();
|
|
89
|
-
return hunks;
|
|
90
|
-
}
|
|
91
|
-
function applyHunk(ms, { oStart, oEnd, nStart, nEnd }, origLines, newLines, lineOffsets, originalLength) {
|
|
92
|
-
const oCount = oEnd - oStart;
|
|
93
|
-
const nCount = nEnd - nStart;
|
|
94
|
-
const newSlice = newLines.slice(nStart, nEnd);
|
|
95
|
-
if (oCount === nCount) {
|
|
96
|
-
for (let k = 0; k < oCount; k++) {
|
|
97
|
-
diffLinePair(
|
|
98
|
-
ms,
|
|
99
|
-
lineOffsets[oStart + k],
|
|
100
|
-
origLines[oStart + k],
|
|
101
|
-
newLines[nStart + k]
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
} else if (oCount === 0) {
|
|
105
|
-
const text = newSlice.join("\n");
|
|
106
|
-
if (oStart >= origLines.length) {
|
|
107
|
-
ms.appendLeft(originalLength, "\n" + text);
|
|
108
|
-
} else {
|
|
109
|
-
ms.appendLeft(lineOffsets[oStart], text + "\n");
|
|
110
|
-
}
|
|
111
|
-
} else if (nCount === 0) {
|
|
112
|
-
const start = lineOffsets[oStart];
|
|
113
|
-
if (oEnd >= origLines.length) {
|
|
114
|
-
ms.remove(oStart > 0 ? start - 1 : start, originalLength);
|
|
115
|
-
} else {
|
|
116
|
-
ms.remove(start, lineOffsets[oEnd]);
|
|
117
|
-
}
|
|
118
|
-
} else {
|
|
119
|
-
const start = lineOffsets[oStart];
|
|
120
|
-
const end = lineOffsets[oEnd - 1] + origLines[oEnd - 1].length;
|
|
121
|
-
ms.overwrite(start, end, newSlice.join("\n"));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
function diffLinePair(ms, lineStart, origLine, newLine) {
|
|
125
|
-
if (origLine === newLine) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
let charPrefix = 0;
|
|
129
|
-
const maxCharPrefix = Math.min(origLine.length, newLine.length);
|
|
130
|
-
while (charPrefix < maxCharPrefix && origLine[charPrefix] === newLine[charPrefix]) {
|
|
131
|
-
charPrefix++;
|
|
132
|
-
}
|
|
133
|
-
let charSuffix = 0;
|
|
134
|
-
const maxCharSuffix = Math.min(origLine.length, newLine.length) - charPrefix;
|
|
135
|
-
while (charSuffix < maxCharSuffix && origLine[origLine.length - 1 - charSuffix] === newLine[newLine.length - 1 - charSuffix]) {
|
|
136
|
-
charSuffix++;
|
|
137
|
-
}
|
|
138
|
-
const start = lineStart + charPrefix;
|
|
139
|
-
const end = lineStart + origLine.length - charSuffix;
|
|
140
|
-
const replacement = newLine.slice(charPrefix, newLine.length - charSuffix);
|
|
141
|
-
if (start === end) {
|
|
142
|
-
ms.appendLeft(start, replacement);
|
|
143
|
-
} else if (replacement === "") {
|
|
144
|
-
ms.remove(start, end);
|
|
145
|
-
} else {
|
|
146
|
-
ms.overwrite(start, end, replacement);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
export {
|
|
150
|
-
generateDiffSourceMap
|
|
151
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from 'vite';
|
|
2
|
-
/**
|
|
3
|
-
* `$api/` imports resolve to files on the api side. They're only supported in
|
|
4
|
-
* `*.routeHooks.{js,ts}` files and in scripts run with `yarn cedar exec` – both
|
|
5
|
-
* of which run on the server. This plugin makes a `$api/` import from code that
|
|
6
|
-
* ends up in the browser bundle fail with an explanatory error instead of
|
|
7
|
-
* silently bundling server-only code (like the Prisma client) into the browser.
|
|
8
|
-
*
|
|
9
|
-
* Has to run before `vite-tsconfig-paths`, which would otherwise resolve
|
|
10
|
-
* `$api/*` using the `paths` mapping in the project's `web/tsconfig.json`.
|
|
11
|
-
*/
|
|
12
|
-
export declare function cedarApiImportGuardPlugin(): Plugin;
|
|
13
|
-
//# sourceMappingURL=vite-plugin-cedar-api-import-guard.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-cedar-api-import-guard.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-api-import-guard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,IAAI,MAAM,CA0BlD"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
function cedarApiImportGuardPlugin() {
|
|
2
|
-
return {
|
|
3
|
-
name: "cedar-api-import-guard",
|
|
4
|
-
enforce: "pre",
|
|
5
|
-
resolveId(id, importer) {
|
|
6
|
-
if (this.environment?.name !== "client" || !id.startsWith("$api/")) {
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
|
-
throw new Error(
|
|
10
|
-
`Cannot import "${id}" from client-side code` + (importer ? ` (imported by "${importer}")` : "") + '.\n\n"$api/" imports resolve to your api side, which must never end up in the browser bundle. They\'re only supported in server-side code, like *.routeHooks.{js,ts} files and scripts run with `yarn cedar exec`.\n\nIf you need this data in the browser, fetch it through GraphQL instead.'
|
|
11
|
-
);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export {
|
|
16
|
-
cedarApiImportGuardPlugin
|
|
17
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-cedar-data-uri-shim.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-data-uri-shim.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAgClC,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,SAAS,CA4BrD"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { getConfig } from "@cedarjs/project-config";
|
|
2
|
-
function dataUriToBuffer(uri) {
|
|
3
|
-
const match = uri.match(/^data:(.*?)(;(.*?))?(,(.*))$/);
|
|
4
|
-
if (!match) {
|
|
5
|
-
throw new Error("Invalid data URI");
|
|
6
|
-
}
|
|
7
|
-
const mediaType = match[1] || "text/plain";
|
|
8
|
-
const params = match[3] || "";
|
|
9
|
-
const data = match[5];
|
|
10
|
-
const [type] = mediaType.split(";");
|
|
11
|
-
const typeFull = params ? mediaType + ";" + params : mediaType;
|
|
12
|
-
const lowerParams = params.toLowerCase();
|
|
13
|
-
const isBase64 = lowerParams.includes("base64");
|
|
14
|
-
const charset = lowerParams.startsWith("charset=") ? lowerParams.slice(8) : "";
|
|
15
|
-
const bytes = isBase64 ? Uint8Array.from(atob(data), (c) => c.charCodeAt(0)) : new TextEncoder().encode(decodeURIComponent(data));
|
|
16
|
-
const decoder = new TextDecoder();
|
|
17
|
-
bytes.toString = () => decoder.decode(bytes);
|
|
18
|
-
return Object.assign(bytes, { type, typeFull, charset });
|
|
19
|
-
}
|
|
20
|
-
function cedarDataUriShim() {
|
|
21
|
-
if (getConfig().experimental?.rsc?.enabled) {
|
|
22
|
-
return void 0;
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
name: "cedar-data-uri-shim",
|
|
26
|
-
apply: "serve",
|
|
27
|
-
resolveId(id) {
|
|
28
|
-
if (id === "data-uri-to-buffer") {
|
|
29
|
-
return "\0cedar-data-uri-to-buffer";
|
|
30
|
-
}
|
|
31
|
-
return void 0;
|
|
32
|
-
},
|
|
33
|
-
load(id) {
|
|
34
|
-
if (id === "\0cedar-data-uri-to-buffer") {
|
|
35
|
-
return "export default " + dataUriToBuffer.toString();
|
|
36
|
-
}
|
|
37
|
-
return void 0;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export {
|
|
42
|
-
cedarDataUriShim
|
|
43
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from 'vite';
|
|
2
|
-
/**
|
|
3
|
-
* Resolves bare directory imports to the index file or directory-named module.
|
|
4
|
-
*
|
|
5
|
-
* When you import `./Button`, this plugin checks:
|
|
6
|
-
* 1. `./Button/index.[js|ts|tsx|jsx|...]` — preferred if it exists
|
|
7
|
-
* 2. `./Button/Button.[js|ts|tsx|jsx|...]` — directory-named module fallback
|
|
8
|
-
*
|
|
9
|
-
* This mirrors the behaviour of babel-plugin-redwood-directory-named-import.
|
|
10
|
-
*/
|
|
11
|
-
export declare function cedarDirectoryNamedImportPlugin(): Plugin;
|
|
12
|
-
//# sourceMappingURL=vite-plugin-cedar-directory-named-import.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-cedar-directory-named-import.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-directory-named-import.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;;;;;;GAQG;AACH,wBAAgB,+BAA+B,IAAI,MAAM,CA0CxD"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { normalizePath } from "vite";
|
|
3
|
-
import { resolveFile } from "@cedarjs/project-config";
|
|
4
|
-
function cedarDirectoryNamedImportPlugin() {
|
|
5
|
-
return {
|
|
6
|
-
name: "vite-plugin-cedar-directory-named-import",
|
|
7
|
-
resolveId(id, importer) {
|
|
8
|
-
if (!id.startsWith(".") || !importer) {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
if (normalizePath(importer).includes("/node_modules/")) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
const absolutePath = path.resolve(path.dirname(importer), id);
|
|
15
|
-
if (resolveFile(absolutePath)) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
const basename = path.basename(absolutePath);
|
|
19
|
-
const indexPath = absolutePath + "/index";
|
|
20
|
-
const resolvedIndex = resolveFile(indexPath);
|
|
21
|
-
if (resolvedIndex) {
|
|
22
|
-
return normalizePath(resolvedIndex);
|
|
23
|
-
}
|
|
24
|
-
const dirnamedPath = absolutePath + "/" + basename;
|
|
25
|
-
const resolvedDirnamed = resolveFile(dirnamedPath);
|
|
26
|
-
if (resolvedDirnamed) {
|
|
27
|
-
return normalizePath(resolvedDirnamed);
|
|
28
|
-
}
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
export {
|
|
34
|
-
cedarDirectoryNamedImportPlugin
|
|
35
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from 'vite';
|
|
2
|
-
/**
|
|
3
|
-
* Vite plugin that injects the auto-generated gqlorm backend into
|
|
4
|
-
* `api/src/functions/graphql.ts` at build time.
|
|
5
|
-
*
|
|
6
|
-
* When `experimental.gqlorm.enabled = true` and `.cedar/gqlorm/backend.ts`
|
|
7
|
-
* exists, this plugin:
|
|
8
|
-
*
|
|
9
|
-
* 1. Adds imports at the top of graphql.ts:
|
|
10
|
-
* import * as __gqlorm_sdl__ from '../../../.cedar/gqlorm/backend'
|
|
11
|
-
* import { db as __gqlorm_db__ } from 'src/lib/db'
|
|
12
|
-
*
|
|
13
|
-
* 2. Inserts a statement immediately before the `createGraphQLHandler` call:
|
|
14
|
-
* Object.assign(sdls, {
|
|
15
|
-
* __gqlorm__: {
|
|
16
|
-
* schema: __gqlorm_sdl__.schema,
|
|
17
|
-
* resolvers: __gqlorm_sdl__.createGqlormResolvers(__gqlorm_db__),
|
|
18
|
-
* },
|
|
19
|
-
* })
|
|
20
|
-
*
|
|
21
|
-
* The `sdls` variable is already a `let` binding because
|
|
22
|
-
* `vite-plugin-cedar-import-dir` transforms the glob import
|
|
23
|
-
* `import sdls from 'src/graphql/**\/*.sdl.{js,ts}'` into `let sdls = {}`.
|
|
24
|
-
*
|
|
25
|
-
* This plugin is a no-op when gqlorm is disabled or the backend file does
|
|
26
|
-
* not exist.
|
|
27
|
-
*/
|
|
28
|
-
export declare function cedarGqlormInjectPlugin(): Plugin;
|
|
29
|
-
//# sourceMappingURL=vite-plugin-cedar-gqlorm-inject.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-cedar-gqlorm-inject.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-gqlorm-inject.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAQlC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAgHhD"}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
getConfig,
|
|
5
|
-
getPaths,
|
|
6
|
-
importStatementPath
|
|
7
|
-
} from "@cedarjs/project-config";
|
|
8
|
-
function cedarGqlormInjectPlugin() {
|
|
9
|
-
return {
|
|
10
|
-
name: "cedar-gqlorm-inject",
|
|
11
|
-
transform(code, id) {
|
|
12
|
-
if (!id.endsWith("/graphql.ts") && !id.endsWith("/graphql.js")) {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
if (code.includes("__gqlorm_sdl__")) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
if (!code.includes("createGraphQLHandler")) {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
let config;
|
|
22
|
-
try {
|
|
23
|
-
config = getConfig();
|
|
24
|
-
} catch {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
if (!config.experimental?.gqlorm?.enabled) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
let paths;
|
|
31
|
-
try {
|
|
32
|
-
paths = getPaths();
|
|
33
|
-
} catch {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
const backendPathWithoutExt = path.join(
|
|
37
|
-
paths.generated.base,
|
|
38
|
-
"gqlorm",
|
|
39
|
-
"backend"
|
|
40
|
-
);
|
|
41
|
-
if (!fs.existsSync(backendPathWithoutExt + ".ts")) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
const handlerPattern = /^export\s+const\s+(\w+)\s*=\s*createGraphQLHandler\s*\(/m;
|
|
45
|
-
const handlerMatch = handlerPattern.exec(code);
|
|
46
|
-
if (!handlerMatch) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
const handlerLineStart = code.lastIndexOf("\n", handlerMatch.index) + 1;
|
|
50
|
-
const relPath = importStatementPath(
|
|
51
|
-
path.relative(path.dirname(id), backendPathWithoutExt)
|
|
52
|
-
) + ".ts";
|
|
53
|
-
const dbSrcPath = path.join(paths.api.src, "lib", "db");
|
|
54
|
-
const relDbPath = importStatementPath(path.relative(path.dirname(id), dbSrcPath)) + ".ts";
|
|
55
|
-
const importDb = `import { db as __gqlorm_db__ } from '${relDbPath}'`;
|
|
56
|
-
const importSdl = `import * as __gqlorm_sdl__ from '${relPath}'`;
|
|
57
|
-
const importsToAdd = `${importDb}
|
|
58
|
-
${importSdl}
|
|
59
|
-
`;
|
|
60
|
-
const sdlsMutation = `Object.assign(sdls, {
|
|
61
|
-
__gqlorm__: {
|
|
62
|
-
schema: __gqlorm_sdl__.schema,
|
|
63
|
-
resolvers: __gqlorm_sdl__.createGqlormResolvers(__gqlorm_db__),
|
|
64
|
-
},
|
|
65
|
-
})
|
|
66
|
-
`;
|
|
67
|
-
const transformed = importsToAdd + code.slice(0, handlerLineStart) + sdlsMutation + code.slice(handlerLineStart);
|
|
68
|
-
return {
|
|
69
|
-
code: transformed
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
export {
|
|
75
|
-
cedarGqlormInjectPlugin
|
|
76
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { SourceMap } from 'magic-string';
|
|
2
|
-
import type { Plugin } from 'vite';
|
|
3
|
-
/**
|
|
4
|
-
* Vite plugin that extracts options passed to createGraphQLHandler into an
|
|
5
|
-
* exported variable.
|
|
6
|
-
*
|
|
7
|
-
* Transforms:
|
|
8
|
-
* export const handler = createGraphQLHandler({ options })
|
|
9
|
-
* into:
|
|
10
|
-
* export const __cedar_graphqlOptions = { options }
|
|
11
|
-
* export const handler = createGraphQLHandler(__cedar_graphqlOptions)
|
|
12
|
-
*
|
|
13
|
-
* This allows options to be imported elsewhere and enables the gqlorm-inject
|
|
14
|
-
* plugin to mutate the sdls object in-place before the call.
|
|
15
|
-
*
|
|
16
|
-
* The extraction uses an oxc-parser AST walk (see `applyGraphqlOptionsExtract`
|
|
17
|
-
* below) so the transform is robust against aliased imports, nested calls, and
|
|
18
|
-
* string escapes. The same logic is duplicated in
|
|
19
|
-
* `@cedarjs/internal` (`applyGraphqlOptionsExtract`) for the standalone esbuild
|
|
20
|
-
* API build
|
|
21
|
-
*/
|
|
22
|
-
export declare function cedarGraphqlOptionsExtractPlugin(): Plugin;
|
|
23
|
-
/**
|
|
24
|
-
* Extracts the options argument from createGraphQLHandler calls and stores
|
|
25
|
-
* them in an exported variable. Returns the transformed code with a sourcemap,
|
|
26
|
-
* or null if no transformation was needed.
|
|
27
|
-
*
|
|
28
|
-
* Transforms:
|
|
29
|
-
* export const handler = createGraphQLHandler({ options })
|
|
30
|
-
* into:
|
|
31
|
-
* export const __cedar_graphqlOptions = { options }
|
|
32
|
-
* export const handler = createGraphQLHandler(__cedar_graphqlOptions)
|
|
33
|
-
*
|
|
34
|
-
* Duplicate of `@cedarjs/internal`'s `applyGraphqlOptionsExtract` so this
|
|
35
|
-
* logic can run inside the Vite plugin pipeline without depending on internal's
|
|
36
|
-
* build output.
|
|
37
|
-
*/
|
|
38
|
-
export declare function applyGraphqlOptionsExtract(code: string): {
|
|
39
|
-
code: string;
|
|
40
|
-
map: SourceMap;
|
|
41
|
-
} | null;
|
|
42
|
-
//# sourceMappingURL=vite-plugin-cedar-graphql-options-extract.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-cedar-graphql-options-extract.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-graphql-options-extract.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAG7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gCAAgC,IAAI,MAAM,CA2BzD;AAQD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,MAAM,GACX;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,SAAS,CAAA;CAAE,GAAG,IAAI,CAiHzC"}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import MagicString from "magic-string";
|
|
2
|
-
import { parseSync, Visitor } from "oxc-parser";
|
|
3
|
-
function cedarGraphqlOptionsExtractPlugin() {
|
|
4
|
-
return {
|
|
5
|
-
name: "cedar-graphql-options-extract",
|
|
6
|
-
transform(code, id) {
|
|
7
|
-
if (!id.endsWith("/graphql.ts") && !id.endsWith("/graphql.js")) {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
if (!code.includes("createGraphQLHandler")) {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
const result = applyGraphqlOptionsExtract(code);
|
|
14
|
-
if (!result) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
return {
|
|
18
|
-
code: result.code,
|
|
19
|
-
map: result.map
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
const GRAPHQL_OPTIONS_ERROR_PREFIX = "Could not read the GraphQL options in api/src/functions/graphql. Cedar needs to statically extract them so the api server can serve /graphql and its health endpoint. ";
|
|
25
|
-
const GRAPHQL_OPTIONS_ERROR_SUFFIX = " Expected a single `createGraphQLHandler({ ... })` call with the options passed directly as an object, an identifier, a call, or a ternary.";
|
|
26
|
-
function applyGraphqlOptionsExtract(code) {
|
|
27
|
-
if (code.includes("__cedar_graphqlOptions")) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
const { program } = parseSync("graphql.ts", code, {
|
|
31
|
-
// lang is only a parse hint; 'ts' also parses JS (the graphql handler can
|
|
32
|
-
// be graphql.js in JS projects), so this is safe for both file types.
|
|
33
|
-
lang: "ts",
|
|
34
|
-
sourceType: "module"
|
|
35
|
-
});
|
|
36
|
-
const importNames = /* @__PURE__ */ new Set();
|
|
37
|
-
for (const node of program.body) {
|
|
38
|
-
if (node.type === "ImportDeclaration") {
|
|
39
|
-
if (node.source.value !== "@cedarjs/graphql-server") {
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
for (const specifier of node.specifiers) {
|
|
43
|
-
if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name === "createGraphQLHandler") {
|
|
44
|
-
importNames.add(specifier.local.name);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (importNames.size === 0) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
const callExpressionPaths = [];
|
|
53
|
-
new Visitor({
|
|
54
|
-
CallExpression(node) {
|
|
55
|
-
if (node.callee.type === "Identifier" && importNames.has(node.callee.name)) {
|
|
56
|
-
callExpressionPaths.push(node);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}).visit(program);
|
|
60
|
-
if (callExpressionPaths.length > 1) {
|
|
61
|
-
throw new Error(
|
|
62
|
-
GRAPHQL_OPTIONS_ERROR_PREFIX + "Found more than one call to createGraphQLHandler." + GRAPHQL_OPTIONS_ERROR_SUFFIX
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
const callExpression = callExpressionPaths[0];
|
|
66
|
-
if (!callExpression) {
|
|
67
|
-
throw new Error(
|
|
68
|
-
GRAPHQL_OPTIONS_ERROR_PREFIX + "createGraphQLHandler is imported but never called." + GRAPHQL_OPTIONS_ERROR_SUFFIX
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
const options = callExpression.arguments[0];
|
|
72
|
-
if (!options) {
|
|
73
|
-
throw new Error(
|
|
74
|
-
GRAPHQL_OPTIONS_ERROR_PREFIX + "createGraphQLHandler was called without any options." + GRAPHQL_OPTIONS_ERROR_SUFFIX
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
if (options.type !== "Identifier" && options.type !== "ObjectExpression" && options.type !== "CallExpression" && options.type !== "ConditionalExpression") {
|
|
78
|
-
throw new Error(
|
|
79
|
-
GRAPHQL_OPTIONS_ERROR_PREFIX + `The options argument is a ${options.type}, which can't be read statically.` + GRAPHQL_OPTIONS_ERROR_SUFFIX
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
const optionsStart = options.start;
|
|
83
|
-
const optionsEnd = options.end;
|
|
84
|
-
const lineStart = code.lastIndexOf("\n", callExpression.start) + 1;
|
|
85
|
-
const indentMatch = /^[ \t]*/.exec(code.slice(lineStart));
|
|
86
|
-
const indent = indentMatch ? indentMatch[0] : "";
|
|
87
|
-
const optionsConst = `${indent}export const __cedar_graphqlOptions = ${code.slice(
|
|
88
|
-
optionsStart,
|
|
89
|
-
optionsEnd
|
|
90
|
-
)}
|
|
91
|
-
`;
|
|
92
|
-
const s = new MagicString(code);
|
|
93
|
-
s.prependLeft(lineStart, optionsConst);
|
|
94
|
-
s.overwrite(optionsStart, optionsEnd, "__cedar_graphqlOptions");
|
|
95
|
-
return {
|
|
96
|
-
code: s.toString(),
|
|
97
|
-
map: s.generateMap({ hires: true })
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
export {
|
|
101
|
-
applyGraphqlOptionsExtract,
|
|
102
|
-
cedarGraphqlOptionsExtractPlugin
|
|
103
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from 'vite';
|
|
2
|
-
import type * as apiLogger from '@cedarjs/api/logger';
|
|
3
|
-
/**
|
|
4
|
-
* Dev-only Vite plugin that makes the api's pino logger pretty-print
|
|
5
|
-
* through the same formatter plain `yarn cedar dev` gets via its
|
|
6
|
-
* `... | cedar-log-formatter` shell pipe.
|
|
7
|
-
*
|
|
8
|
-
* `--ud` mode runs the api in-process as Vite SSR middleware, so there's no
|
|
9
|
-
* separate api process whose stdout a shell pipe could format externally,
|
|
10
|
-
* and pino's default destination writes straight to file descriptor 1
|
|
11
|
-
* (bypassing `process.stdout.write`), so patching stdout wouldn't see the
|
|
12
|
-
* log lines either. Instead, this intercepts resolution of
|
|
13
|
-
* `@cedarjs/api/logger` and swaps in a wrapped `createLogger` that injects
|
|
14
|
-
* a formatting `destination` whenever the caller (the app's own
|
|
15
|
-
* `api/src/lib/logger.ts`) doesn't already supply one.
|
|
16
|
-
*
|
|
17
|
-
* Only registered in `createApiViteServer()`'s dev-only Vite instance —
|
|
18
|
-
* never touched by any production build path — so this has no effect on
|
|
19
|
-
* (and no dependency footprint added to) a deployed api.
|
|
20
|
-
*/
|
|
21
|
-
export declare function cedarApiLogFormatterDevPlugin(): Plugin;
|
|
22
|
-
export declare function createFormattingDestination(): {
|
|
23
|
-
write(chunk: string): void;
|
|
24
|
-
};
|
|
25
|
-
type CreateLoggerParams = Parameters<typeof apiLogger.createLogger>[0];
|
|
26
|
-
export declare function createLogger(params?: CreateLoggerParams): apiLogger.Logger;
|
|
27
|
-
export {};
|
|
28
|
-
//# sourceMappingURL=vite-plugin-cedar-log-formatter-dev.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-cedar-log-formatter-dev.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-log-formatter-dev.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAMlC,OAAO,KAAK,KAAK,SAAS,MAAM,qBAAqB,CAAA;AAOrD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,6BAA6B,IAAI,MAAM,CAoCtD;AAED,wBAAgB,2BAA2B;iBAK1B,MAAM;EAYtB;AAED,KAAK,kBAAkB,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;AAUtE,wBAAgB,YAAY,CAAC,MAAM,GAAE,kBAAuB,oBAS3D"}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { LogFormatter } from "@cedarjs/api-server/logFormatter";
|
|
2
|
-
const INTERCEPTED_SPECIFIER = "@cedarjs/api/logger";
|
|
3
|
-
const VIRTUAL_MODULE_ID = "virtual:cedar-api-logger-dev";
|
|
4
|
-
const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
|
|
5
|
-
function cedarApiLogFormatterDevPlugin() {
|
|
6
|
-
return {
|
|
7
|
-
name: "cedar-api-log-formatter-dev",
|
|
8
|
-
enforce: "pre",
|
|
9
|
-
resolveId(id, importer) {
|
|
10
|
-
if (id === INTERCEPTED_SPECIFIER && importer !== RESOLVED_VIRTUAL_MODULE_ID) {
|
|
11
|
-
return RESOLVED_VIRTUAL_MODULE_ID;
|
|
12
|
-
}
|
|
13
|
-
return null;
|
|
14
|
-
},
|
|
15
|
-
load(id) {
|
|
16
|
-
if (id !== RESOLVED_VIRTUAL_MODULE_ID) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
return `
|
|
20
|
-
import * as realLogger from ${JSON.stringify(INTERCEPTED_SPECIFIER)}
|
|
21
|
-
import { LogFormatter } from '@cedarjs/api-server/logFormatter'
|
|
22
|
-
|
|
23
|
-
export * from ${JSON.stringify(INTERCEPTED_SPECIFIER)}
|
|
24
|
-
|
|
25
|
-
${createFormattingDestination.toString()}
|
|
26
|
-
|
|
27
|
-
// toString() doesn't include the 'export' keyword
|
|
28
|
-
export ${createLogger.toString()}
|
|
29
|
-
`;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function createFormattingDestination() {
|
|
34
|
-
const format = LogFormatter();
|
|
35
|
-
let buffered = "";
|
|
36
|
-
return {
|
|
37
|
-
write(chunk) {
|
|
38
|
-
buffered += chunk;
|
|
39
|
-
const lines = buffered.split("\n");
|
|
40
|
-
buffered = lines.pop() ?? "";
|
|
41
|
-
for (const line of lines) {
|
|
42
|
-
if (line.length > 0) {
|
|
43
|
-
process.stdout.write(format(line));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
const realLogger = {
|
|
50
|
-
createLogger: (_params) => {
|
|
51
|
-
return {};
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
function createLogger(params = {}) {
|
|
55
|
-
if (params.destination) {
|
|
56
|
-
return realLogger.createLogger(params);
|
|
57
|
-
}
|
|
58
|
-
return realLogger.createLogger({
|
|
59
|
-
...params,
|
|
60
|
-
destination: createFormattingDestination()
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
export {
|
|
64
|
-
cedarApiLogFormatterDevPlugin,
|
|
65
|
-
createFormattingDestination,
|
|
66
|
-
createLogger
|
|
67
|
-
};
|