@cedarjs/vite 7.0.0-canary.3007 → 7.0.0-canary.3008
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,3 +1,20 @@
|
|
|
1
1
|
import type { Paths } from '@cedarjs/project-config';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the path, relative to `web/dist/ssr/routeHooks` and with a `.js`
|
|
4
|
+
* extension, that the built version of the given route hook source file is
|
|
5
|
+
* written to. The layout mirrors `web/src`, so
|
|
6
|
+
* `web/src/pages/HomePage/HomePage.routeHooks.ts` ends up at
|
|
7
|
+
* `pages/HomePage/HomePage.routeHooks.js` and `web/src/App.routeHooks.ts` at
|
|
8
|
+
* `App.routeHooks.js`.
|
|
9
|
+
*
|
|
10
|
+
* Used both by the build (to name the Rollup entries) and by the route
|
|
11
|
+
* manifest (so the streaming handler can find the file at request time).
|
|
12
|
+
*/
|
|
13
|
+
export declare function getRouteHookDistPath(routeHookSrcPath: string, webSrc?: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Bundles every `web/src/** /*.routeHooks.{js,ts,tsx,jsx}` file into
|
|
16
|
+
* `web/dist/ssr/routeHooks` as a node ESM module, one output file per route
|
|
17
|
+
* hook. The streaming SSR handler `import()`s them at request time.
|
|
18
|
+
*/
|
|
2
19
|
export declare function buildRouteHooks(verbose: boolean | undefined, rwPaths: Paths): Promise<void>;
|
|
3
20
|
//# sourceMappingURL=buildRouteHooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildRouteHooks.d.ts","sourceRoot":"","sources":["../src/buildRouteHooks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buildRouteHooks.d.ts","sourceRoot":"","sources":["../src/buildRouteHooks.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAiBpD;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,gBAAgB,EAAE,MAAM,EACxB,MAAM,SAAqB,UAG5B;AA6BD;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,OAAO,GAAG,SAAS,EAC5B,OAAO,EAAE,KAAK,iBAuEf"}
|
package/dist/buildRouteHooks.js
CHANGED
|
@@ -1,81 +1,100 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
1
|
import path from "node:path";
|
|
3
|
-
import { build as
|
|
4
|
-
import { gqlPlugin } from "vite-plugin-graphql-tag";
|
|
5
|
-
import
|
|
6
|
-
getRouteHookBabelPlugins,
|
|
7
|
-
transformWithBabel
|
|
8
|
-
} from "@cedarjs/babel-config";
|
|
2
|
+
import { build as viteBuild } from "vite";
|
|
3
|
+
import { gqlPlugin as gqlTagPlugin } from "vite-plugin-graphql-tag";
|
|
4
|
+
import tsPathsMod from "vite-tsconfig-paths";
|
|
9
5
|
import { findRouteHooksSrc } from "@cedarjs/internal/dist/files.js";
|
|
10
6
|
import { getPaths } from "@cedarjs/project-config";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
import { cedarApiImportGuardPlugin } from "./plugins/vite-plugin-cedar-api-import-guard.js";
|
|
8
|
+
import { cedarAutoImportsPlugin } from "./plugins/vite-plugin-cedar-auto-import.js";
|
|
9
|
+
import { cedarDirectoryNamedImportPlugin } from "./plugins/vite-plugin-cedar-directory-named-import.js";
|
|
10
|
+
import { cedarjsResolveCedarStyleImportsPlugin } from "./plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js";
|
|
11
|
+
const tsconfigPaths = (
|
|
12
|
+
// @ts-expect-error – .default only exists at runtime in CJS double-wrap
|
|
13
|
+
// interop
|
|
14
|
+
tsPathsMod.default?.default || tsPathsMod.default || tsPathsMod
|
|
15
|
+
);
|
|
16
|
+
function getRouteHookDistPath(routeHookSrcPath, webSrc = getPaths().web.src) {
|
|
17
|
+
return getRouteHookEntryName(routeHookSrcPath, webSrc) + ".js";
|
|
15
18
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
function getRouteHookEntryName(routeHookSrcPath, webSrc) {
|
|
20
|
+
return path.relative(webSrc, routeHookSrcPath).replace(/\.(js|ts|tsx|jsx)$/, "").split(path.sep).join("/");
|
|
21
|
+
}
|
|
22
|
+
function postGqlTagPlugin() {
|
|
23
|
+
const plugin = gqlTagPlugin();
|
|
24
|
+
if (!plugin || Array.isArray(plugin) || plugin instanceof Promise) {
|
|
25
|
+
throw new Error("vite-plugin-graphql-tag did not return a plugin object");
|
|
26
|
+
}
|
|
27
|
+
return { ...plugin, enforce: "post" };
|
|
19
28
|
}
|
|
20
|
-
const gqlTransform = transform.handler;
|
|
21
29
|
async function buildRouteHooks(verbose, rwPaths) {
|
|
22
30
|
const allRouteHooks = findRouteHooksSrc();
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
error(err) {
|
|
42
|
-
throw new Error(String(err));
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
const gqlResult = await gqlTransform.call(
|
|
46
|
-
mockCtx,
|
|
47
|
-
transformedCode.code,
|
|
48
|
-
args.path
|
|
49
|
-
);
|
|
50
|
-
const gqlCode = gqlResult && typeof gqlResult === "object" && "code" in gqlResult ? gqlResult.code : void 0;
|
|
51
|
-
return {
|
|
52
|
-
contents: gqlCode ?? transformedCode.code,
|
|
53
|
-
loader: "js"
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
throw new Error(`Could not transform file: ${args.path}`);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
await esbuildBuild({
|
|
61
|
-
absWorkingDir: getPaths().web.base,
|
|
62
|
-
entryPoints: allRouteHooks,
|
|
63
|
-
platform: "node",
|
|
64
|
-
target: "node16",
|
|
65
|
-
// @MARK Disable splitting and esm, because Redwood web modules don't support esm yet
|
|
66
|
-
// outExtension: { '.js': '.mjs' },
|
|
67
|
-
// format: 'esm',
|
|
68
|
-
// splitting: true,
|
|
69
|
-
bundle: true,
|
|
70
|
-
plugins: [runRwBabelTransformsPlugin],
|
|
71
|
-
packages: "external",
|
|
31
|
+
if (allRouteHooks.length === 0) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const input = {};
|
|
35
|
+
for (const routeHook of allRouteHooks) {
|
|
36
|
+
input[getRouteHookEntryName(routeHook, rwPaths.web.src)] = routeHook;
|
|
37
|
+
}
|
|
38
|
+
await viteBuild({
|
|
39
|
+
// Route hooks run in node, so the project's web/vite.config, which is set
|
|
40
|
+
// up for browser and SSR builds of React code, doesn't apply. Only the
|
|
41
|
+
// plugins listed below are used.
|
|
42
|
+
configFile: false,
|
|
43
|
+
root: rwPaths.web.base,
|
|
44
|
+
// Route hooks are node modules, so the static assets in web/public
|
|
45
|
+
// must not be copied next to them
|
|
46
|
+
publicDir: false,
|
|
47
|
+
envFile: false,
|
|
72
48
|
logLevel: verbose ? "info" : "error",
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
49
|
+
plugins: [
|
|
50
|
+
// Turns `$api/` imports into an error in the client environment. It's a
|
|
51
|
+
// no-op in this ssr-only build, but it has to sit in front of
|
|
52
|
+
// tsconfigPaths() wherever that plugin is used, so it's kept here for
|
|
53
|
+
// parity with the web build
|
|
54
|
+
cedarApiImportGuardPlugin(),
|
|
55
|
+
// Resolves the `paths` mapping in web/tsconfig.json, like `$api/*`
|
|
56
|
+
tsconfigPaths(),
|
|
57
|
+
// Resolves `src/` imports to the web side, `$api/` and `api/` imports to
|
|
58
|
+
// the api side, and directory-named modules for those
|
|
59
|
+
cedarjsResolveCedarStyleImportsPlugin(),
|
|
60
|
+
// Resolves relative `./Foo` imports to `./Foo/index` or `./Foo/Foo`
|
|
61
|
+
cedarDirectoryNamedImportPlugin(),
|
|
62
|
+
// Auto-imports `gql` and `React`
|
|
63
|
+
cedarAutoImportsPlugin(),
|
|
64
|
+
// Compiles `gql` template literals into DocumentNode objects. Placed
|
|
65
|
+
// after cedarAutoImportsPlugin(), see postGqlTagPlugin()
|
|
66
|
+
postGqlTagPlugin()
|
|
67
|
+
],
|
|
68
|
+
build: {
|
|
69
|
+
ssr: true,
|
|
70
|
+
target: "node24",
|
|
71
|
+
minify: false,
|
|
72
|
+
outDir: rwPaths.web.distRouteHooks,
|
|
73
|
+
// The directory only ever holds route hook output, so clearing it keeps
|
|
74
|
+
// chunks from earlier builds from piling up
|
|
75
|
+
emptyOutDir: true,
|
|
76
|
+
rollupOptions: {
|
|
77
|
+
input,
|
|
78
|
+
output: {
|
|
79
|
+
format: "es",
|
|
80
|
+
entryFileNames: "[name].js",
|
|
81
|
+
// Modules shared between route hooks, like the api side's db.js
|
|
82
|
+
chunkFileNames: "chunks/[name]-[hash].js",
|
|
83
|
+
exports: "named"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
// Node builtins and everything that resolves into node_modules stay as
|
|
88
|
+
// imports for node to resolve at runtime. Only project files (the route
|
|
89
|
+
// hook itself and whatever it imports from the web and api sides) are
|
|
90
|
+
// bundled. Bare specifiers like `$api/` and `src/` are resolved by the
|
|
91
|
+
// plugins above before Vite decides whether to externalize them
|
|
92
|
+
ssr: {
|
|
93
|
+
external: true
|
|
76
94
|
}
|
|
77
95
|
});
|
|
78
96
|
}
|
|
79
97
|
export {
|
|
80
|
-
buildRouteHooks
|
|
98
|
+
buildRouteHooks,
|
|
99
|
+
getRouteHookDistPath
|
|
81
100
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildRouteManifest.d.ts","sourceRoot":"","sources":["../src/buildRouteManifest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buildRouteManifest.d.ts","sourceRoot":"","sources":["../src/buildRouteManifest.ts"],"names":[],"mappings":"AAYA;;;GAGG;AACH,wBAAsB,kBAAkB,kBAkDvC"}
|
|
@@ -2,7 +2,8 @@ import fs from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import url from "node:url";
|
|
4
4
|
import { getProjectRoutes } from "@cedarjs/internal/dist/routes.js";
|
|
5
|
-
import {
|
|
5
|
+
import { getPaths } from "@cedarjs/project-config";
|
|
6
|
+
import { getRouteHookDistPath } from "./buildRouteHooks.js";
|
|
6
7
|
async function buildRouteManifest() {
|
|
7
8
|
const rwPaths = getPaths();
|
|
8
9
|
const buildManifestUrl = url.pathToFileURL(
|
|
@@ -24,7 +25,7 @@ async function buildRouteManifest() {
|
|
|
24
25
|
// E.g. /blog/post/{id:Int}
|
|
25
26
|
pathDefinition: route.pathDefinition,
|
|
26
27
|
hasParams: route.hasParams,
|
|
27
|
-
routeHooks:
|
|
28
|
+
routeHooks: route.routeHooks ? getRouteHookDistPath(route.routeHooks) : null,
|
|
28
29
|
redirect: route.redirect ? {
|
|
29
30
|
to: route.redirect?.to,
|
|
30
31
|
permanent: false
|
|
@@ -42,17 +43,6 @@ async function buildRouteManifest() {
|
|
|
42
43
|
await fs.mkdir(rwPaths.web.distSsr, { recursive: true });
|
|
43
44
|
return fs.writeFile(webRouteManifest, JSON.stringify(routeManifest, null, 2));
|
|
44
45
|
}
|
|
45
|
-
const FIXME_constructRouteHookPath = (routeHookSrcPath) => {
|
|
46
|
-
const rwPaths = getPaths();
|
|
47
|
-
if (!routeHookSrcPath) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
if (getAppRouteHook()) {
|
|
51
|
-
return path.relative(rwPaths.web.src, routeHookSrcPath).replace(".ts", ".js");
|
|
52
|
-
} else {
|
|
53
|
-
return path.relative(path.join(rwPaths.web.src, "pages"), routeHookSrcPath).replace(".ts", ".js");
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
46
|
export {
|
|
57
47
|
buildRouteManifest
|
|
58
48
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/vite",
|
|
3
|
-
"version": "7.0.0-canary.
|
|
3
|
+
"version": "7.0.0-canary.3008",
|
|
4
4
|
"description": "Vite configuration package for CedarJS",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -53,17 +53,17 @@
|
|
|
53
53
|
"@babel/preset-typescript": "7.29.7",
|
|
54
54
|
"@babel/traverse": "7.29.8",
|
|
55
55
|
"@babel/types": "7.29.8",
|
|
56
|
-
"@cedarjs/api": "7.0.0-canary.
|
|
57
|
-
"@cedarjs/api-server": "7.0.0-canary.
|
|
58
|
-
"@cedarjs/babel-config": "7.0.0-canary.
|
|
59
|
-
"@cedarjs/context": "7.0.0-canary.
|
|
60
|
-
"@cedarjs/graphql-server": "7.0.0-canary.
|
|
61
|
-
"@cedarjs/internal": "7.0.0-canary.
|
|
62
|
-
"@cedarjs/jobs": "7.0.0-canary.
|
|
63
|
-
"@cedarjs/project-config": "7.0.0-canary.
|
|
64
|
-
"@cedarjs/server-store": "7.0.0-canary.
|
|
65
|
-
"@cedarjs/structure": "7.0.0-canary.
|
|
66
|
-
"@cedarjs/testing": "7.0.0-canary.
|
|
56
|
+
"@cedarjs/api": "7.0.0-canary.3008",
|
|
57
|
+
"@cedarjs/api-server": "7.0.0-canary.3008",
|
|
58
|
+
"@cedarjs/babel-config": "7.0.0-canary.3008",
|
|
59
|
+
"@cedarjs/context": "7.0.0-canary.3008",
|
|
60
|
+
"@cedarjs/graphql-server": "7.0.0-canary.3008",
|
|
61
|
+
"@cedarjs/internal": "7.0.0-canary.3008",
|
|
62
|
+
"@cedarjs/jobs": "7.0.0-canary.3008",
|
|
63
|
+
"@cedarjs/project-config": "7.0.0-canary.3008",
|
|
64
|
+
"@cedarjs/server-store": "7.0.0-canary.3008",
|
|
65
|
+
"@cedarjs/structure": "7.0.0-canary.3008",
|
|
66
|
+
"@cedarjs/testing": "7.0.0-canary.3008",
|
|
67
67
|
"@swc/core": "1.16.1",
|
|
68
68
|
"@universal-deploy/store": "^0.2.1",
|
|
69
69
|
"@universal-deploy/vite": "^0.1.9",
|
|
@@ -93,10 +93,10 @@
|
|
|
93
93
|
"yargs-parser": "21.1.1"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
|
-
"@cedarjs/auth": "7.0.0-canary.
|
|
97
|
-
"@cedarjs/framework-tools": "7.0.0-canary.
|
|
98
|
-
"@cedarjs/router": "7.0.0-canary.
|
|
99
|
-
"@cedarjs/web": "7.0.0-canary.
|
|
96
|
+
"@cedarjs/auth": "7.0.0-canary.3008",
|
|
97
|
+
"@cedarjs/framework-tools": "7.0.0-canary.3008",
|
|
98
|
+
"@cedarjs/router": "7.0.0-canary.3008",
|
|
99
|
+
"@cedarjs/web": "7.0.0-canary.3008",
|
|
100
100
|
"@dr.pogodin/react-helmet": "2.0.4",
|
|
101
101
|
"@hyrious/esbuild-plugin-commonjs": "0.2.6",
|
|
102
102
|
"@jridgewell/trace-mapping": "0.3.31",
|
|
@@ -118,9 +118,9 @@
|
|
|
118
118
|
"vitest": "4.1.10"
|
|
119
119
|
},
|
|
120
120
|
"peerDependencies": {
|
|
121
|
-
"@cedarjs/auth": "7.0.0-canary.
|
|
122
|
-
"@cedarjs/router": "7.0.0-canary.
|
|
123
|
-
"@cedarjs/web": "7.0.0-canary.
|
|
121
|
+
"@cedarjs/auth": "7.0.0-canary.3008",
|
|
122
|
+
"@cedarjs/router": "7.0.0-canary.3008",
|
|
123
|
+
"@cedarjs/web": "7.0.0-canary.3008",
|
|
124
124
|
"react": "19.2.8",
|
|
125
125
|
"react-dom": "19.2.8"
|
|
126
126
|
},
|