@cedarjs/vite 5.0.0-canary.2602 → 5.0.0-canary.2604

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.
@@ -1 +1 @@
1
- {"version":3,"file":"buildApp.d.ts","sourceRoot":"","sources":["../src/buildApp.ts"],"names":[],"mappings":"AA8BA,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,EAAE,CAAC,EAAE,OAAO,CAAA;CACb;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,EAClC,OAAe,EACf,SAA0B,EAC1B,EAAU,GACX,GAAE,oBAAyB,iBA0U3B"}
1
+ {"version":3,"file":"buildApp.d.ts","sourceRoot":"","sources":["../src/buildApp.ts"],"names":[],"mappings":"AA+BA,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,EAAE,CAAC,EAAE,OAAO,CAAA;CACb;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,EAClC,OAAe,EACf,SAA0B,EAC1B,EAAU,GACX,GAAE,oBAAyB,iBA8U3B"}
package/dist/buildApp.js CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  import { findApiFiles } from "@cedarjs/internal/dist/files.js";
11
11
  import { getConfig, getPaths, projectSideIsEsm } from "@cedarjs/project-config";
12
12
  import { getWorkspacePackageAliases } from "./lib/workspacePackageAliases.js";
13
+ import { cedarContextWrappingPlugin } from "./plugins/vite-plugin-cedar-context-wrapping.js";
13
14
  function resolveWithExtensions(id) {
14
15
  if (fs.existsSync(id)) {
15
16
  return id;
@@ -221,36 +222,41 @@ async function buildCedarApp({
221
222
  return null;
222
223
  }
223
224
  });
224
- if (babelPlugins) {
225
- plugins.push({
226
- name: "cedar-vite-api-babel-transform",
227
- enforce: "pre",
228
- async transform(code, id) {
229
- if (!/\.(js|ts|tsx|jsx)$/.test(id)) {
230
- return null;
231
- }
232
- if (id.includes("node_modules")) {
233
- return null;
234
- }
235
- if (!normalizePath(id).startsWith(normalizePath(cedarPaths.api.base))) {
236
- return null;
237
- }
238
- const transformedCode = await transformWithBabel(
239
- code,
240
- id,
241
- babelPlugins,
242
- true
243
- );
244
- if (transformedCode?.code) {
245
- return {
246
- code: transformedCode.code,
247
- map: transformedCode.map ?? null
248
- };
249
- }
225
+ }
226
+ if (workspace.includes("api")) {
227
+ plugins.push(
228
+ cedarContextWrappingPlugin({ projectIsEsm: projectSideIsEsm("api") })
229
+ );
230
+ }
231
+ if (babelPlugins) {
232
+ plugins.push({
233
+ name: "cedar-vite-api-babel-transform",
234
+ enforce: "pre",
235
+ async transform(code, id) {
236
+ if (!/\.(js|ts|tsx|jsx)$/.test(id)) {
250
237
  return null;
251
238
  }
252
- });
253
- }
239
+ if (id.includes("node_modules")) {
240
+ return null;
241
+ }
242
+ if (!normalizePath(id).startsWith(normalizePath(cedarPaths.api.base))) {
243
+ return null;
244
+ }
245
+ const transformedCode = await transformWithBabel(
246
+ code,
247
+ id,
248
+ babelPlugins,
249
+ true
250
+ );
251
+ if (transformedCode?.code) {
252
+ return {
253
+ code: transformedCode.code,
254
+ map: transformedCode.map ?? null
255
+ };
256
+ }
257
+ return null;
258
+ }
259
+ });
254
260
  }
255
261
  const builder = await createBuilder({
256
262
  configFile: cedarPaths.web.viteConfig,
@@ -40,6 +40,7 @@ var import_babel_config = require("@cedarjs/babel-config");
40
40
  var import_files = require("@cedarjs/internal/dist/files.js");
41
41
  var import_project_config = require("@cedarjs/project-config");
42
42
  var import_workspacePackageAliases = require("./lib/workspacePackageAliases.js");
43
+ var import_vite_plugin_cedar_context_wrapping = require("./plugins/vite-plugin-cedar-context-wrapping.js");
43
44
  function resolveWithExtensions(id) {
44
45
  if (import_node_fs.default.existsSync(id)) {
45
46
  return id;
@@ -251,36 +252,41 @@ async function buildCedarApp({
251
252
  return null;
252
253
  }
253
254
  });
254
- if (babelPlugins) {
255
- plugins.push({
256
- name: "cedar-vite-api-babel-transform",
257
- enforce: "pre",
258
- async transform(code, id) {
259
- if (!/\.(js|ts|tsx|jsx)$/.test(id)) {
260
- return null;
261
- }
262
- if (id.includes("node_modules")) {
263
- return null;
264
- }
265
- if (!(0, import_vite2.normalizePath)(id).startsWith((0, import_vite2.normalizePath)(cedarPaths.api.base))) {
266
- return null;
267
- }
268
- const transformedCode = await (0, import_babel_config.transformWithBabel)(
269
- code,
270
- id,
271
- babelPlugins,
272
- true
273
- );
274
- if (transformedCode?.code) {
275
- return {
276
- code: transformedCode.code,
277
- map: transformedCode.map ?? null
278
- };
279
- }
255
+ }
256
+ if (workspace.includes("api")) {
257
+ plugins.push(
258
+ (0, import_vite_plugin_cedar_context_wrapping.cedarContextWrappingPlugin)({ projectIsEsm: (0, import_project_config.projectSideIsEsm)("api") })
259
+ );
260
+ }
261
+ if (babelPlugins) {
262
+ plugins.push({
263
+ name: "cedar-vite-api-babel-transform",
264
+ enforce: "pre",
265
+ async transform(code, id) {
266
+ if (!/\.(js|ts|tsx|jsx)$/.test(id)) {
280
267
  return null;
281
268
  }
282
- });
283
- }
269
+ if (id.includes("node_modules")) {
270
+ return null;
271
+ }
272
+ if (!(0, import_vite2.normalizePath)(id).startsWith((0, import_vite2.normalizePath)(cedarPaths.api.base))) {
273
+ return null;
274
+ }
275
+ const transformedCode = await (0, import_babel_config.transformWithBabel)(
276
+ code,
277
+ id,
278
+ babelPlugins,
279
+ true
280
+ );
281
+ if (transformedCode?.code) {
282
+ return {
283
+ code: transformedCode.code,
284
+ map: transformedCode.map ?? null
285
+ };
286
+ }
287
+ return null;
288
+ }
289
+ });
284
290
  }
285
291
  const builder = await (0, import_vite2.createBuilder)({
286
292
  configFile: cedarPaths.web.viteConfig,
package/dist/cjs/index.js CHANGED
@@ -28,10 +28,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var index_exports = {};
30
30
  __export(index_exports, {
31
+ applyContextWrapping: () => import_vite_plugin_cedar_context_wrapping2.applyContextWrapping,
31
32
  cedar: () => cedar,
32
33
  cedarAutoImportsPlugin: () => import_vite_plugin_cedar_auto_import.cedarAutoImportsPlugin,
33
34
  cedarCellTransform: () => import_vite_plugin_cedar_cell2.cedarCellTransform,
34
35
  cedarCjsCompatPlugin: () => import_vite_plugin_cedar_cjs_compat.cedarCjsCompatPlugin,
36
+ cedarContextWrappingPlugin: () => import_vite_plugin_cedar_context_wrapping.cedarContextWrappingPlugin,
35
37
  cedarDataUriShim: () => import_vite_plugin_cedar_data_uri_shim2.cedarDataUriShim,
36
38
  cedarEntryInjectionPlugin: () => import_vite_plugin_cedar_entry_injection2.cedarEntryInjectionPlugin,
37
39
  cedarHtmlEnvPlugin: () => import_vite_plugin_cedar_html_env2.cedarHtmlEnvPlugin,
@@ -68,6 +70,8 @@ var import_vite_plugin_swap_apollo_provider = require("./plugins/vite-plugin-swa
68
70
  var import_vite_plugin_cedar_auto_import = require("./plugins/vite-plugin-cedar-auto-import.js");
69
71
  var import_vite_plugin_cedar_cjs_compat = require("./plugins/vite-plugin-cedar-cjs-compat.js");
70
72
  var import_vite_plugin_cedar_cell2 = require("./plugins/vite-plugin-cedar-cell.js");
73
+ var import_vite_plugin_cedar_context_wrapping = require("./plugins/vite-plugin-cedar-context-wrapping.js");
74
+ var import_vite_plugin_cedar_context_wrapping2 = require("./plugins/vite-plugin-cedar-context-wrapping.js");
71
75
  var import_vite_plugin_cedar_entry_injection2 = require("./plugins/vite-plugin-cedar-entry-injection.js");
72
76
  var import_vite_plugin_cedar_html_env2 = require("./plugins/vite-plugin-cedar-html-env.js");
73
77
  var import_vite_plugin_cedar_import_dir = require("./plugins/vite-plugin-cedar-import-dir.js");
@@ -114,10 +118,12 @@ function cedar({ mode } = {}) {
114
118
  var index_default = cedar;
115
119
  // Annotate the CommonJS export names for ESM import in node:
116
120
  0 && (module.exports = {
121
+ applyContextWrapping,
117
122
  cedar,
118
123
  cedarAutoImportsPlugin,
119
124
  cedarCellTransform,
120
125
  cedarCjsCompatPlugin,
126
+ cedarContextWrappingPlugin,
121
127
  cedarDataUriShim,
122
128
  cedarEntryInjectionPlugin,
123
129
  cedarHtmlEnvPlugin,
@@ -28,6 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var vite_plugin_cedar_context_wrapping_exports = {};
30
30
  __export(vite_plugin_cedar_context_wrapping_exports, {
31
+ applyContextWrapping: () => applyContextWrapping,
31
32
  cedarContextWrappingPlugin: () => cedarContextWrappingPlugin
32
33
  });
33
34
  module.exports = __toCommonJS(vite_plugin_cedar_context_wrapping_exports);
@@ -37,7 +38,6 @@ var import_project_config = require("@cedarjs/project-config");
37
38
  function cedarContextWrappingPlugin({
38
39
  projectIsEsm = false
39
40
  } = {}) {
40
- const handlerRe = /^export\s+(?:const|let|var)\s+handler(?:[^=]|=>)*?=(?![>=])/m;
41
41
  return {
42
42
  name: "cedar-context-wrapping",
43
43
  transform(code, id) {
@@ -51,20 +51,27 @@ function cedarContextWrappingPlugin({
51
51
  if (!(0, import_vite.normalizePath)(id).startsWith(functionsDir + "/")) {
52
52
  return null;
53
53
  }
54
- const handlerMatch = handlerRe.exec(code);
55
- if (!handlerMatch) {
56
- return null;
57
- }
58
- const afterEquals = code.slice(handlerMatch.index + handlerMatch[0].length).trimStart();
59
- const isAsync = /^async(?:\s*[\(\*]|\s+function)/.test(afterEquals);
60
- const storePath = projectIsEsm ? "@cedarjs/context/dist/store.js" : "@cedarjs/context/dist/store";
61
- const importStatement = `import { getAsyncStoreInstance as __rw_getAsyncStoreInstance } from '${storePath}'
54
+ const wrapped = applyContextWrapping(code, { projectIsEsm });
55
+ return wrapped ? { code: wrapped, map: null } : null;
56
+ }
57
+ };
58
+ }
59
+ function applyContextWrapping(code, { projectIsEsm = false } = {}) {
60
+ const handlerRe = /^export\s+(?:const|let|var)\s+handler(?:[^=]|=>)*?=(?![>=])/m;
61
+ const handlerMatch = handlerRe.exec(code);
62
+ if (!handlerMatch) {
63
+ return null;
64
+ }
65
+ const afterEquals = code.slice(handlerMatch.index + handlerMatch[0].length).trimStart();
66
+ const isAsync = /^async(?:\s*[\(\*]|\s+function)/.test(afterEquals);
67
+ const storePath = projectIsEsm ? "@cedarjs/context/dist/store.js" : "@cedarjs/context/dist/store";
68
+ const importStatement = `import { getAsyncStoreInstance as __rw_getAsyncStoreInstance } from '${storePath}'
62
69
  `;
63
- const handlerStart = handlerMatch.index;
64
- const before = code.slice(0, handlerStart);
65
- const after = code.slice(handlerStart);
66
- const renamed = after.replace(handlerRe, "const __rw_handler =");
67
- const wrappedHandler = `
70
+ const handlerStart = handlerMatch.index;
71
+ const before = code.slice(0, handlerStart);
72
+ const after = code.slice(handlerStart);
73
+ const renamed = after.replace(handlerRe, "const __rw_handler =");
74
+ const wrappedHandler = `
68
75
  export const handler = ${isAsync ? "async " : ""}(__rw_event, __rw__context) => {
69
76
  // The store will be undefined if no context isolation has been performed yet
70
77
  const __rw_contextStore = __rw_getAsyncStoreInstance().getStore()
@@ -79,14 +86,10 @@ export const handler = ${isAsync ? "async " : ""}(__rw_event, __rw__context) =>
79
86
  return __rw_handler(__rw_event, __rw__context)
80
87
  }
81
88
  `;
82
- return {
83
- code: before + importStatement + renamed + wrappedHandler,
84
- map: null
85
- };
86
- }
87
- };
89
+ return before + importStatement + renamed + wrappedHandler;
88
90
  }
89
91
  // Annotate the CommonJS export names for ESM import in node:
90
92
  0 && (module.exports = {
93
+ applyContextWrapping,
91
94
  cedarContextWrappingPlugin
92
95
  });
package/dist/index.d.ts CHANGED
@@ -2,6 +2,8 @@ import type { PluginOption } from 'vite';
2
2
  export { cedarAutoImportsPlugin } from './plugins/vite-plugin-cedar-auto-import.js';
3
3
  export { cedarCjsCompatPlugin } from './plugins/vite-plugin-cedar-cjs-compat.js';
4
4
  export { cedarCellTransform } from './plugins/vite-plugin-cedar-cell.js';
5
+ export { cedarContextWrappingPlugin } from './plugins/vite-plugin-cedar-context-wrapping.js';
6
+ export { applyContextWrapping } from './plugins/vite-plugin-cedar-context-wrapping.js';
5
7
  export { cedarEntryInjectionPlugin } from './plugins/vite-plugin-cedar-entry-injection.js';
6
8
  export { cedarHtmlEnvPlugin } from './plugins/vite-plugin-cedar-html-env.js';
7
9
  export { cedarImportDirPlugin } from './plugins/vite-plugin-cedar-import-dir.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAuBxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAA;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAA;AAC/E,OAAO,EAAE,4BAA4B,EAAE,MAAM,4DAA4D,CAAA;AACzG,OAAO,EAAE,2BAA2B,EAAE,MAAM,mDAAmD,CAAA;AAC/F,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AACzF,OAAO,EAAE,qCAAqC,EAAE,MAAM,8DAA8D,CAAA;AACpH,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAA;AACjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAA;AACvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAA;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,oDAAoD,CAAA;AAE1F,KAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1B,CAAA;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,GAAE,aAAkB,GAAG,YAAY,EAAE,CAgClE;AAED,8DAA8D;AAC9D,eAAe,KAAK,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAuBxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAA;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAA;AAC5F,OAAO,EAAE,oBAAoB,EAAE,MAAM,iDAAiD,CAAA;AACtF,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAA;AAC/E,OAAO,EAAE,4BAA4B,EAAE,MAAM,4DAA4D,CAAA;AACzG,OAAO,EAAE,2BAA2B,EAAE,MAAM,mDAAmD,CAAA;AAC/F,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAA;AACzF,OAAO,EAAE,qCAAqC,EAAE,MAAM,8DAA8D,CAAA;AACpH,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAA;AACjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAA;AACvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAA;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,oDAAoD,CAAA;AAE1F,KAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1B,CAAA;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,GAAE,aAAkB,GAAG,YAAY,EAAE,CAgClE;AAED,8DAA8D;AAC9D,eAAe,KAAK,CAAA"}
package/dist/index.js CHANGED
@@ -21,6 +21,8 @@ import { cedarSwapApolloProvider } from "./plugins/vite-plugin-swap-apollo-provi
21
21
  import { cedarAutoImportsPlugin } from "./plugins/vite-plugin-cedar-auto-import.js";
22
22
  import { cedarCjsCompatPlugin } from "./plugins/vite-plugin-cedar-cjs-compat.js";
23
23
  import { cedarCellTransform as cedarCellTransform2 } from "./plugins/vite-plugin-cedar-cell.js";
24
+ import { cedarContextWrappingPlugin } from "./plugins/vite-plugin-cedar-context-wrapping.js";
25
+ import { applyContextWrapping } from "./plugins/vite-plugin-cedar-context-wrapping.js";
24
26
  import { cedarEntryInjectionPlugin as cedarEntryInjectionPlugin2 } from "./plugins/vite-plugin-cedar-entry-injection.js";
25
27
  import { cedarHtmlEnvPlugin as cedarHtmlEnvPlugin2 } from "./plugins/vite-plugin-cedar-html-env.js";
26
28
  import { cedarImportDirPlugin } from "./plugins/vite-plugin-cedar-import-dir.js";
@@ -66,10 +68,12 @@ function cedar({ mode } = {}) {
66
68
  }
67
69
  var index_default = cedar;
68
70
  export {
71
+ applyContextWrapping,
69
72
  cedar,
70
73
  cedarAutoImportsPlugin,
71
74
  cedarCellTransform2 as cedarCellTransform,
72
75
  cedarCjsCompatPlugin,
76
+ cedarContextWrappingPlugin,
73
77
  cedarDataUriShim2 as cedarDataUriShim,
74
78
  cedarEntryInjectionPlugin2 as cedarEntryInjectionPlugin,
75
79
  cedarHtmlEnvPlugin2 as cedarHtmlEnvPlugin,
@@ -28,4 +28,17 @@ import type { Plugin } from 'vite';
28
28
  export declare function cedarContextWrappingPlugin({ projectIsEsm, }?: {
29
29
  projectIsEsm?: boolean;
30
30
  }): Plugin;
31
+ /**
32
+ * Wraps the `handler` export of an API function file with an async context
33
+ * store guard. Returns the transformed code, or `null` if the file does not
34
+ * export a `handler`.
35
+ *
36
+ * This is the context-isolation safeguard that used to be performed by
37
+ * `babel-plugin-redwood-context-wrapping`. It is exported as a standalone
38
+ * function so it can be applied from build pipelines that don't go through
39
+ * Vite's plugin pipeline (e.g. the legacy esbuild API build).
40
+ */
41
+ export declare function applyContextWrapping(code: string, { projectIsEsm }?: {
42
+ projectIsEsm?: boolean;
43
+ }): string | null;
31
44
  //# sourceMappingURL=vite-plugin-cedar-context-wrapping.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin-cedar-context-wrapping.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-context-wrapping.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,YAAoB,GACrB,GAAE;IACD,YAAY,CAAC,EAAE,OAAO,CAAA;CAClB,GAAG,MAAM,CA6Ed"}
1
+ {"version":3,"file":"vite-plugin-cedar-context-wrapping.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-context-wrapping.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,YAAoB,GACrB,GAAE;IACD,YAAY,CAAC,EAAE,OAAO,CAAA;CAClB,GAAG,MAAM,CAuBd;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,EAAE,YAAoB,EAAE,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO,GACxD,MAAM,GAAG,IAAI,CAsDf"}
@@ -4,7 +4,6 @@ import { getPaths } from "@cedarjs/project-config";
4
4
  function cedarContextWrappingPlugin({
5
5
  projectIsEsm = false
6
6
  } = {}) {
7
- const handlerRe = /^export\s+(?:const|let|var)\s+handler(?:[^=]|=>)*?=(?![>=])/m;
8
7
  return {
9
8
  name: "cedar-context-wrapping",
10
9
  transform(code, id) {
@@ -18,20 +17,27 @@ function cedarContextWrappingPlugin({
18
17
  if (!normalizePath(id).startsWith(functionsDir + "/")) {
19
18
  return null;
20
19
  }
21
- const handlerMatch = handlerRe.exec(code);
22
- if (!handlerMatch) {
23
- return null;
24
- }
25
- const afterEquals = code.slice(handlerMatch.index + handlerMatch[0].length).trimStart();
26
- const isAsync = /^async(?:\s*[\(\*]|\s+function)/.test(afterEquals);
27
- const storePath = projectIsEsm ? "@cedarjs/context/dist/store.js" : "@cedarjs/context/dist/store";
28
- const importStatement = `import { getAsyncStoreInstance as __rw_getAsyncStoreInstance } from '${storePath}'
20
+ const wrapped = applyContextWrapping(code, { projectIsEsm });
21
+ return wrapped ? { code: wrapped, map: null } : null;
22
+ }
23
+ };
24
+ }
25
+ function applyContextWrapping(code, { projectIsEsm = false } = {}) {
26
+ const handlerRe = /^export\s+(?:const|let|var)\s+handler(?:[^=]|=>)*?=(?![>=])/m;
27
+ const handlerMatch = handlerRe.exec(code);
28
+ if (!handlerMatch) {
29
+ return null;
30
+ }
31
+ const afterEquals = code.slice(handlerMatch.index + handlerMatch[0].length).trimStart();
32
+ const isAsync = /^async(?:\s*[\(\*]|\s+function)/.test(afterEquals);
33
+ const storePath = projectIsEsm ? "@cedarjs/context/dist/store.js" : "@cedarjs/context/dist/store";
34
+ const importStatement = `import { getAsyncStoreInstance as __rw_getAsyncStoreInstance } from '${storePath}'
29
35
  `;
30
- const handlerStart = handlerMatch.index;
31
- const before = code.slice(0, handlerStart);
32
- const after = code.slice(handlerStart);
33
- const renamed = after.replace(handlerRe, "const __rw_handler =");
34
- const wrappedHandler = `
36
+ const handlerStart = handlerMatch.index;
37
+ const before = code.slice(0, handlerStart);
38
+ const after = code.slice(handlerStart);
39
+ const renamed = after.replace(handlerRe, "const __rw_handler =");
40
+ const wrappedHandler = `
35
41
  export const handler = ${isAsync ? "async " : ""}(__rw_event, __rw__context) => {
36
42
  // The store will be undefined if no context isolation has been performed yet
37
43
  const __rw_contextStore = __rw_getAsyncStoreInstance().getStore()
@@ -46,13 +52,9 @@ export const handler = ${isAsync ? "async " : ""}(__rw_event, __rw__context) =>
46
52
  return __rw_handler(__rw_event, __rw__context)
47
53
  }
48
54
  `;
49
- return {
50
- code: before + importStatement + renamed + wrappedHandler,
51
- map: null
52
- };
53
- }
54
- };
55
+ return before + importStatement + renamed + wrappedHandler;
55
56
  }
56
57
  export {
58
+ applyContextWrapping,
57
59
  cedarContextWrappingPlugin
58
60
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/vite",
3
- "version": "5.0.0-canary.2602",
3
+ "version": "5.0.0-canary.2604",
4
4
  "description": "Vite configuration package for CedarJS",
5
5
  "repository": {
6
6
  "type": "git",
@@ -63,15 +63,15 @@
63
63
  "@babel/parser": "7.29.7",
64
64
  "@babel/traverse": "7.29.7",
65
65
  "@babel/types": "7.29.7",
66
- "@cedarjs/api": "5.0.0-canary.2602",
67
- "@cedarjs/babel-config": "5.0.0-canary.2602",
68
- "@cedarjs/context": "5.0.0-canary.2602",
69
- "@cedarjs/cookie-jar": "5.0.0-canary.2602",
70
- "@cedarjs/graphql-server": "5.0.0-canary.2602",
71
- "@cedarjs/internal": "5.0.0-canary.2602",
72
- "@cedarjs/project-config": "5.0.0-canary.2602",
73
- "@cedarjs/server-store": "5.0.0-canary.2602",
74
- "@cedarjs/testing": "5.0.0-canary.2602",
66
+ "@cedarjs/api": "5.0.0-canary.2604",
67
+ "@cedarjs/babel-config": "5.0.0-canary.2604",
68
+ "@cedarjs/context": "5.0.0-canary.2604",
69
+ "@cedarjs/cookie-jar": "5.0.0-canary.2604",
70
+ "@cedarjs/graphql-server": "5.0.0-canary.2604",
71
+ "@cedarjs/internal": "5.0.0-canary.2604",
72
+ "@cedarjs/project-config": "5.0.0-canary.2604",
73
+ "@cedarjs/server-store": "5.0.0-canary.2604",
74
+ "@cedarjs/testing": "5.0.0-canary.2604",
75
75
  "@fastify/url-data": "6.0.3",
76
76
  "@swc/core": "1.15.41",
77
77
  "@universal-deploy/store": "^0.2.1",
@@ -103,9 +103,9 @@
103
103
  },
104
104
  "devDependencies": {
105
105
  "@arethetypeswrong/cli": "0.18.4",
106
- "@cedarjs/auth": "5.0.0-canary.2602",
107
- "@cedarjs/router": "5.0.0-canary.2602",
108
- "@cedarjs/web": "5.0.0-canary.2602",
106
+ "@cedarjs/auth": "5.0.0-canary.2604",
107
+ "@cedarjs/router": "5.0.0-canary.2604",
108
+ "@cedarjs/web": "5.0.0-canary.2604",
109
109
  "@hyrious/esbuild-plugin-commonjs": "0.2.6",
110
110
  "@jridgewell/trace-mapping": "0.3.31",
111
111
  "@types/aws-lambda": "8.10.162",