@cedarjs/vite 5.0.0-canary.2595 → 5.0.0-canary.2597

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.
@@ -0,0 +1,92 @@
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 vite_plugin_cedar_context_wrapping_exports = {};
30
+ __export(vite_plugin_cedar_context_wrapping_exports, {
31
+ cedarContextWrappingPlugin: () => cedarContextWrappingPlugin
32
+ });
33
+ module.exports = __toCommonJS(vite_plugin_cedar_context_wrapping_exports);
34
+ var import_node_path = __toESM(require("node:path"), 1);
35
+ var import_vite = require("vite");
36
+ var import_project_config = require("@cedarjs/project-config");
37
+ function cedarContextWrappingPlugin({
38
+ projectIsEsm = false
39
+ } = {}) {
40
+ const handlerRe = /^export\s+(?:const|let|var)\s+handler(?:[^=]|=>)*?=(?![>=])/m;
41
+ return {
42
+ name: "cedar-context-wrapping",
43
+ transform(code, id) {
44
+ let paths;
45
+ try {
46
+ paths = (0, import_project_config.getPaths)();
47
+ } catch {
48
+ return null;
49
+ }
50
+ const functionsDir = (0, import_vite.normalizePath)(import_node_path.default.join(paths.api.src, "functions"));
51
+ if (!(0, import_vite.normalizePath)(id).startsWith(functionsDir + "/")) {
52
+ return null;
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}'
62
+ `;
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 = `
68
+ export const handler = ${isAsync ? "async " : ""}(__rw_event, __rw__context) => {
69
+ // The store will be undefined if no context isolation has been performed yet
70
+ const __rw_contextStore = __rw_getAsyncStoreInstance().getStore()
71
+ if (__rw_contextStore === undefined) {
72
+ return __rw_getAsyncStoreInstance().run(
73
+ new Map(),
74
+ __rw_handler,
75
+ __rw_event,
76
+ __rw__context
77
+ )
78
+ }
79
+ return __rw_handler(__rw_event, __rw__context)
80
+ }
81
+ `;
82
+ return {
83
+ code: before + importStatement + renamed + wrappedHandler,
84
+ map: null
85
+ };
86
+ }
87
+ };
88
+ }
89
+ // Annotate the CommonJS export names for ESM import in node:
90
+ 0 && (module.exports = {
91
+ cedarContextWrappingPlugin
92
+ });
@@ -0,0 +1,31 @@
1
+ import type { Plugin } from 'vite';
2
+ /**
3
+ * Vite plugin that wraps user API functions to ensure context isolation has
4
+ * been performed. This should already be done at the request level but in
5
+ * serverless environments like Netlify we need to do this at the function
6
+ * level as a safeguard.
7
+ *
8
+ * For each file in `api/src/functions/` that exports a `handler`, this plugin:
9
+ *
10
+ * 1. Adds an import at the top of the file:
11
+ * import { getAsyncStoreInstance as __rw_getAsyncStoreInstance } from '@cedarjs/context/dist/store'
12
+ *
13
+ * 2. Renames the original handler:
14
+ * const __rw_handler = <original handler value>
15
+ *
16
+ * 3. Replaces the handler export with a wrapper that checks context isolation:
17
+ * export const handler = (__rw_event, __rw__context) => {
18
+ * const __rw_contextStore = __rw_getAsyncStoreInstance().getStore()
19
+ * if (__rw_contextStore === undefined) {
20
+ * return __rw_getAsyncStoreInstance().run(new Map(), __rw_handler, __rw_event, __rw__context)
21
+ * }
22
+ * return __rw_handler(__rw_event, __rw__context)
23
+ * }
24
+ *
25
+ * This replaces `babel-plugin-redwood-context-wrapping` for Vite builds.
26
+ * The babel plugin is still used for Jest and prerender.
27
+ */
28
+ export declare function cedarContextWrappingPlugin({ projectIsEsm, }?: {
29
+ projectIsEsm?: boolean;
30
+ }): Plugin;
31
+ //# sourceMappingURL=vite-plugin-cedar-context-wrapping.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,58 @@
1
+ import path from "node:path";
2
+ import { normalizePath } from "vite";
3
+ import { getPaths } from "@cedarjs/project-config";
4
+ function cedarContextWrappingPlugin({
5
+ projectIsEsm = false
6
+ } = {}) {
7
+ const handlerRe = /^export\s+(?:const|let|var)\s+handler(?:[^=]|=>)*?=(?![>=])/m;
8
+ return {
9
+ name: "cedar-context-wrapping",
10
+ transform(code, id) {
11
+ let paths;
12
+ try {
13
+ paths = getPaths();
14
+ } catch {
15
+ return null;
16
+ }
17
+ const functionsDir = normalizePath(path.join(paths.api.src, "functions"));
18
+ if (!normalizePath(id).startsWith(functionsDir + "/")) {
19
+ return null;
20
+ }
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}'
29
+ `;
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 = `
35
+ export const handler = ${isAsync ? "async " : ""}(__rw_event, __rw__context) => {
36
+ // The store will be undefined if no context isolation has been performed yet
37
+ const __rw_contextStore = __rw_getAsyncStoreInstance().getStore()
38
+ if (__rw_contextStore === undefined) {
39
+ return __rw_getAsyncStoreInstance().run(
40
+ new Map(),
41
+ __rw_handler,
42
+ __rw_event,
43
+ __rw__context
44
+ )
45
+ }
46
+ return __rw_handler(__rw_event, __rw__context)
47
+ }
48
+ `;
49
+ return {
50
+ code: before + importStatement + renamed + wrappedHandler,
51
+ map: null
52
+ };
53
+ }
54
+ };
55
+ }
56
+ export {
57
+ cedarContextWrappingPlugin
58
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/vite",
3
- "version": "5.0.0-canary.2595",
3
+ "version": "5.0.0-canary.2597",
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.2595",
67
- "@cedarjs/babel-config": "5.0.0-canary.2595",
68
- "@cedarjs/context": "5.0.0-canary.2595",
69
- "@cedarjs/cookie-jar": "5.0.0-canary.2595",
70
- "@cedarjs/graphql-server": "5.0.0-canary.2595",
71
- "@cedarjs/internal": "5.0.0-canary.2595",
72
- "@cedarjs/project-config": "5.0.0-canary.2595",
73
- "@cedarjs/server-store": "5.0.0-canary.2595",
74
- "@cedarjs/testing": "5.0.0-canary.2595",
66
+ "@cedarjs/api": "5.0.0-canary.2597",
67
+ "@cedarjs/babel-config": "5.0.0-canary.2597",
68
+ "@cedarjs/context": "5.0.0-canary.2597",
69
+ "@cedarjs/cookie-jar": "5.0.0-canary.2597",
70
+ "@cedarjs/graphql-server": "5.0.0-canary.2597",
71
+ "@cedarjs/internal": "5.0.0-canary.2597",
72
+ "@cedarjs/project-config": "5.0.0-canary.2597",
73
+ "@cedarjs/server-store": "5.0.0-canary.2597",
74
+ "@cedarjs/testing": "5.0.0-canary.2597",
75
75
  "@fastify/url-data": "6.0.3",
76
76
  "@swc/core": "1.15.41",
77
77
  "@universal-deploy/store": "^0.2.1",
@@ -105,9 +105,9 @@
105
105
  },
106
106
  "devDependencies": {
107
107
  "@arethetypeswrong/cli": "0.18.4",
108
- "@cedarjs/auth": "5.0.0-canary.2595",
109
- "@cedarjs/router": "5.0.0-canary.2595",
110
- "@cedarjs/web": "5.0.0-canary.2595",
108
+ "@cedarjs/auth": "5.0.0-canary.2597",
109
+ "@cedarjs/router": "5.0.0-canary.2597",
110
+ "@cedarjs/web": "5.0.0-canary.2597",
111
111
  "@hyrious/esbuild-plugin-commonjs": "0.2.6",
112
112
  "@jridgewell/trace-mapping": "0.3.31",
113
113
  "@types/aws-lambda": "8.10.162",