@cedarjs/vite 7.0.1-next.466 → 7.1.0-rc.32

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.
Files changed (35) hide show
  1. package/dist/buildApp.d.ts.map +1 -1
  2. package/dist/buildApp.js +11 -32
  3. package/dist/buildRouteHooks.d.ts +13 -7
  4. package/dist/buildRouteHooks.d.ts.map +1 -1
  5. package/dist/buildRouteHooks.js +10 -5
  6. package/dist/bundled/react-server-dom-webpack.server.js +29125 -2264
  7. package/dist/devFeServer.js +3 -3
  8. package/dist/index.d.ts +0 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +0 -4
  11. package/dist/jobsDevMiddleware.d.ts.map +1 -1
  12. package/dist/jobsDevMiddleware.js +2 -29
  13. package/dist/plugins/vite-plugin-cedar-cell.d.ts +1 -2
  14. package/dist/plugins/vite-plugin-cedar-cell.d.ts.map +1 -1
  15. package/dist/plugins/vite-plugin-cedar-cell.js +11 -30
  16. package/dist/plugins/vite-plugin-handler-als-wrapping.d.ts +6 -2
  17. package/dist/plugins/vite-plugin-handler-als-wrapping.d.ts.map +1 -1
  18. package/dist/plugins/vite-plugin-handler-als-wrapping.js +7 -4
  19. package/dist/rsc/rscBuildClient.d.ts +1 -1
  20. package/dist/rsc/rscBuildForServer.d.ts +1 -1
  21. package/dist/rsc/rscBuildForSsr.d.ts +1 -1
  22. package/dist/runFeServer.js +3 -3
  23. package/dist/streaming/streamHelpers.d.ts +1 -6
  24. package/dist/streaming/streamHelpers.d.ts.map +1 -1
  25. package/dist/streaming/streamHelpers.js +1 -1
  26. package/package.json +44 -46
  27. package/dist/lib/sandboxChildren.d.ts +0 -58
  28. package/dist/lib/sandboxChildren.d.ts.map +0 -1
  29. package/dist/lib/sandboxChildren.js +0 -157
  30. package/dist/plugins/vite-plugin-cedar-parsed-scalars.d.ts +0 -20
  31. package/dist/plugins/vite-plugin-cedar-parsed-scalars.d.ts.map +0 -1
  32. package/dist/plugins/vite-plugin-cedar-parsed-scalars.js +0 -60
  33. package/dist/plugins/vite-plugin-cedar-sandbox-children.d.ts +0 -20
  34. package/dist/plugins/vite-plugin-cedar-sandbox-children.d.ts.map +0 -1
  35. package/dist/plugins/vite-plugin-cedar-sandbox-children.js +0 -58
@@ -1,157 +0,0 @@
1
- import fs from "node:fs";
2
- import { isBuiltin } from "node:module";
3
- import path from "node:path";
4
- import fg from "fast-glob";
5
- const SANDBOX_CHILDREN_DIR = "sandbox-children";
6
- function findSandboxChildScripts(apiSrc) {
7
- const files = fg.sync("**/*.child.{ts,js,mts,mjs}", {
8
- cwd: apiSrc,
9
- absolute: true,
10
- ignore: ["**/node_modules/**", "**/__tests__/**"]
11
- }).sort();
12
- const entries = {};
13
- for (const file of files) {
14
- const name = path.basename(file).replace(/\.(ts|js|mts|mjs)$/, "");
15
- const key = `${SANDBOX_CHILDREN_DIR}/${name}`;
16
- if (entries[key]) {
17
- throw new Error(
18
- `Two sandboxed child scripts are named ${name}: ${path.relative(apiSrc, entries[key])} and ${path.relative(apiSrc, file)}. A bundled build puts every child script in one folder, so their names must be unique.`
19
- );
20
- }
21
- entries[key] = path.normalize(file);
22
- }
23
- return entries;
24
- }
25
- const packageName = (specifier) => {
26
- const parts = specifier.split("/");
27
- return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
28
- };
29
- const readPackageJson = (dir) => {
30
- const parsed = JSON.parse(
31
- fs.readFileSync(path.join(dir, "package.json"), "utf8")
32
- );
33
- return parsed && typeof parsed === "object" ? parsed : {};
34
- };
35
- const findPackage = (name, dir) => {
36
- let current = dir;
37
- for (; ; ) {
38
- const candidate = path.join(current, "node_modules", name);
39
- if (fs.existsSync(path.join(candidate, "package.json"))) {
40
- return { realDir: fs.realpathSync(candidate), foundIn: current };
41
- }
42
- const parent = path.dirname(current);
43
- if (parent === current) {
44
- return null;
45
- }
46
- current = parent;
47
- }
48
- };
49
- function vendorSandboxChildPackages(childrenDir, children) {
50
- const copyOf = /* @__PURE__ */ new Map();
51
- const occupied = /* @__PURE__ */ new Map();
52
- const inNodeModules = (dir) => dir.split(path.sep).includes("node_modules");
53
- const reachableFrom = (copy, name) => {
54
- let dir = copy;
55
- for (; ; ) {
56
- const there = occupied.get(path.join(dir, "node_modules", name));
57
- if (there || dir === childrenDir) {
58
- return there?.realDir;
59
- }
60
- dir = path.dirname(dir);
61
- }
62
- };
63
- const visit = (name, fromDir, dependentCopy, required, dependent) => {
64
- const found = findPackage(name, fromDir);
65
- if (!found) {
66
- if (required) {
67
- throw new Error(
68
- `Can't find package "${name}", which ${dependent} imports, in a node_modules folder above ${fromDir}`
69
- );
70
- }
71
- return;
72
- }
73
- const { realDir, foundIn } = found;
74
- const reachable = reachableFrom(dependentCopy, name);
75
- if (reachable === realDir) {
76
- return;
77
- }
78
- const copiedFolder = copyOf.get(foundIn);
79
- const besideDependent = path.join(dependentCopy, "node_modules", name);
80
- const target = copiedFolder ? path.join(copiedFolder, "node_modules", name) : inNodeModules(foundIn) || reachable ? besideDependent : path.join(childrenDir, "node_modules", name);
81
- const there = occupied.get(target);
82
- if (there) {
83
- throw new Error(
84
- `Sandboxed child scripts need two versions of "${name}" in one place: ${there.realDir} (for ${there.neededBy}) and ${realDir} (for ${dependent}). Install a single version of it, or move the children so their imports resolve the same way.`
85
- );
86
- }
87
- occupied.set(target, { realDir, neededBy: dependent });
88
- if (!copyOf.has(realDir)) {
89
- copyOf.set(realDir, target);
90
- }
91
- fs.cpSync(realDir, target, {
92
- recursive: true,
93
- dereference: true,
94
- // Its own node_modules are copied as dependencies, when they're needed
95
- filter: (src) => src !== path.join(realDir, "node_modules")
96
- });
97
- const pkg = readPackageJson(realDir);
98
- const optional = /* @__PURE__ */ new Set([
99
- ...Object.keys(pkg.optionalDependencies ?? {}),
100
- ...Object.keys(pkg.peerDependencies ?? {})
101
- ]);
102
- for (const dep of Object.keys(pkg.dependencies ?? {})) {
103
- visit(dep, realDir, target, !optional.has(dep), name);
104
- }
105
- for (const dep of optional) {
106
- visit(dep, realDir, target, false, name);
107
- }
108
- };
109
- for (const { source, imports } of children) {
110
- for (const specifier of imports) {
111
- if (isBuiltin(specifier) || specifier.startsWith("#")) {
112
- continue;
113
- }
114
- visit(
115
- packageName(specifier),
116
- fs.realpathSync(path.dirname(source)),
117
- childrenDir,
118
- true,
119
- path.basename(source)
120
- );
121
- }
122
- }
123
- }
124
- const findVercelFunctionDirs = (dir) => fs.existsSync(dir) ? fs.readdirSync(dir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).flatMap((entry) => {
125
- const entryPath = path.join(dir, entry.name);
126
- return entry.name.endsWith(".func") ? [entryPath] : findVercelFunctionDirs(entryPath);
127
- }) : [];
128
- function copySandboxChildrenIntoVercelFunctions({
129
- appRoot,
130
- childrenDir,
131
- functionsDir
132
- }) {
133
- const childrenDirInApp = path.relative(appRoot, childrenDir);
134
- if (!fs.existsSync(childrenDir)) {
135
- return [];
136
- }
137
- const functionDirs = findVercelFunctionDirs(functionsDir).filter((dir) => {
138
- const config = path.join(dir, ".vc-config.json");
139
- if (!fs.existsSync(config)) {
140
- return false;
141
- }
142
- const parsed = JSON.parse(fs.readFileSync(config, "utf8"));
143
- return !!parsed && typeof parsed === "object" && "runtime" in parsed && typeof parsed.runtime === "string" && parsed.runtime.startsWith("nodejs");
144
- });
145
- for (const dir of functionDirs) {
146
- fs.cpSync(childrenDir, path.join(dir, childrenDirInApp), {
147
- recursive: true
148
- });
149
- }
150
- return functionDirs;
151
- }
152
- export {
153
- SANDBOX_CHILDREN_DIR,
154
- copySandboxChildrenIntoVercelFunctions,
155
- findSandboxChildScripts,
156
- vendorSandboxChildPackages
157
- };
@@ -1,20 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- /**
3
- * Gives `CedarApolloProvider` the cache config for the scalars in
4
- * `graphql.parsedScalars` in `cedar.toml`. Does nothing when no scalar is set
5
- * to be parsed.
6
- *
7
- * The config comes from the project's generated GraphQL schema, so it is built
8
- * into the virtual module `virtual:cedar-parsed-scalars` rather than into the
9
- * provider, which is a published package that Vite pre-bundles in dev. The
10
- * module puts the config on `globalThis.__CEDAR__PARSED_SCALARS`, where the
11
- * provider reads it when it creates the cache, and `App` and the web test
12
- * setup file import the module so that every entry point that renders the
13
- * provider has it. The module is a
14
- * dependency of the generated schema file, so a change to the schema reloads
15
- * the app. The generated schema is only read, and `graphql` and its schema
16
- * loader only imported, when the virtual module is actually resolved, so a
17
- * project that doesn't use this setting doesn't pay for loading them.
18
- */
19
- export declare function cedarParsedScalarsPlugin(): Plugin | undefined;
20
- //# sourceMappingURL=vite-plugin-cedar-parsed-scalars.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vite-plugin-cedar-parsed-scalars.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-parsed-scalars.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAclC;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,GAAG,SAAS,CA4E7D"}
@@ -1,60 +0,0 @@
1
- import { normalizePath } from "vite";
2
- import { getParsedScalars, getPaths } from "@cedarjs/project-config";
3
- const VIRTUAL_MODULE_ID = "virtual:cedar-parsed-scalars";
4
- const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
5
- const APP_FILE_REGEXP = /web[\\/]src[\\/]App\.(ts|tsx|js|jsx)$/;
6
- const VITEST_WEB_SETUP_FILE_REGEXP = /[\\/]vitest-web\.setup\.(ts|js)$/;
7
- function cedarParsedScalarsPlugin() {
8
- if (Object.keys(getParsedScalars()).length === 0) {
9
- return void 0;
10
- }
11
- return {
12
- name: "cedar-parsed-scalars",
13
- resolveId(id) {
14
- if (id === VIRTUAL_MODULE_ID) {
15
- return RESOLVED_VIRTUAL_MODULE_ID;
16
- }
17
- return null;
18
- },
19
- async load(id) {
20
- if (id !== RESOLVED_VIRTUAL_MODULE_ID) {
21
- return null;
22
- }
23
- this.addWatchFile(getPaths().generated.schema);
24
- const { loadParsedScalarsCacheConfig } = await import("@cedarjs/internal/dist/generate/parsedScalars.js");
25
- const config = loadParsedScalarsCacheConfig();
26
- return `globalThis.__CEDAR__PARSED_SCALARS = ${JSON.stringify(config)}`;
27
- },
28
- transform(code, id) {
29
- if (!APP_FILE_REGEXP.test(id) && !VITEST_WEB_SETUP_FILE_REGEXP.test(id)) {
30
- return null;
31
- }
32
- return `import '${VIRTUAL_MODULE_ID}'
33
- ${code}`;
34
- },
35
- // `this.addWatchFile` in `load` only reruns the virtual module for a
36
- // change to a file it has already watched. The schema doesn't exist yet
37
- // on a clean `cedar dev` (the web server and `cedar-gen-watch` start
38
- // concurrently), so its first appearance is a 'create' event on a path
39
- // nothing has watched yet, and reaches here without an `addWatchFile`
40
- // call ever having registered it. Reload the virtual module for exactly
41
- // that file, on every event type, so the app picks up the first schema
42
- // once `cedar-gen-watch` writes it, the same way it already does for a
43
- // later edit.
44
- hotUpdate(options) {
45
- if (options.file !== normalizePath(getPaths().generated.schema)) {
46
- return;
47
- }
48
- const moduleGraph = this.environment.moduleGraph;
49
- const module = moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);
50
- if (!module) {
51
- return;
52
- }
53
- moduleGraph.invalidateModule(module);
54
- return [module];
55
- }
56
- };
57
- }
58
- export {
59
- cedarParsedScalarsPlugin
60
- };
@@ -1,20 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- /**
3
- * For the bundled API build (`cedar build --ud`): the sandboxed child
4
- * scripts in api/src are extra entries of the build (see
5
- * `findSandboxChildScripts()`), so each comes out as
6
- * `sandbox-children/<name>.child.js`. This plugin checks that each child
7
- * stands alone, importing only packages and Node builtins (it can read
8
- * nothing of the app), and then copies the packages they import into
9
- * `sandbox-children/node_modules`.
10
- *
11
- * `findChildScript()` from `@cedarjs/api/sandbox` finds the children there
12
- * from code in the bundle.
13
- */
14
- export declare function cedarSandboxChildrenPlugin({ environment, children, }: {
15
- /** The bundled build's environment */
16
- environment: string;
17
- /** The child scripts' entries: `{ 'sandbox-children/x.child': file }` */
18
- children: Record<string, string>;
19
- }): Plugin;
20
- //# sourceMappingURL=vite-plugin-cedar-sandbox-children.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vite-plugin-cedar-sandbox-children.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-cedar-sandbox-children.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AASlC;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,WAAW,EACX,QAAQ,GACT,EAAE;IACD,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAA;IACnB,yEAAyE;IACzE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACjC,GAAG,MAAM,CAmDT"}
@@ -1,58 +0,0 @@
1
- import path from "node:path";
2
- import { normalizePath } from "vite";
3
- import {
4
- SANDBOX_CHILDREN_DIR,
5
- vendorSandboxChildPackages
6
- } from "../lib/sandboxChildren.js";
7
- function cedarSandboxChildrenPlugin({
8
- environment,
9
- children
10
- }) {
11
- const sources = new Set(
12
- Object.values(children).map((file) => normalizePath(file))
13
- );
14
- let imports = [];
15
- return {
16
- name: "cedar-sandbox-children",
17
- apply: "build",
18
- applyToEnvironment(env) {
19
- return env.name === environment;
20
- },
21
- generateBundle(_options, bundle) {
22
- imports = [];
23
- for (const chunk of Object.values(bundle)) {
24
- if (chunk.type !== "chunk" || !chunk.facadeModuleId) {
25
- continue;
26
- }
27
- const source = normalizePath(chunk.facadeModuleId);
28
- if (!sources.has(source)) {
29
- continue;
30
- }
31
- const bundled = [...chunk.imports, ...chunk.dynamicImports].filter(
32
- (id) => id in bundle
33
- );
34
- if (bundled.length > 0) {
35
- this.error(
36
- `${path.basename(source)} imports your app's own code (${bundled.join(", ")}). A sandboxed child script may import only packages and Node builtins: it runs in a process that can't read the rest of your app.`
37
- );
38
- }
39
- imports.push({
40
- source,
41
- imports: [...chunk.imports, ...chunk.dynamicImports]
42
- });
43
- }
44
- },
45
- writeBundle(options) {
46
- if (imports.length === 0 || !options.dir) {
47
- return;
48
- }
49
- vendorSandboxChildPackages(
50
- path.join(options.dir, SANDBOX_CHILDREN_DIR),
51
- imports
52
- );
53
- }
54
- };
55
- }
56
- export {
57
- cedarSandboxChildrenPlugin
58
- };