@cedarjs/prerender 0.9.1-next.21 → 0.10.0-rc.24
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/dist/babelPlugins/babel-plugin-redwood-cell.d.ts +5 -0
- package/dist/babelPlugins/babel-plugin-redwood-cell.d.ts.map +1 -0
- package/dist/babelPlugins/babel-plugin-redwood-cell.js +97 -0
- package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts +5 -0
- package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts.map +1 -0
- package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.js +76 -0
- package/dist/babelPlugins/utils.d.ts +2 -0
- package/dist/babelPlugins/utils.d.ts.map +1 -0
- package/dist/babelPlugins/utils.js +15 -0
- package/dist/cjs/babelPlugins/babel-plugin-redwood-cell.d.ts +5 -0
- package/dist/cjs/babelPlugins/babel-plugin-redwood-cell.d.ts.map +1 -0
- package/dist/cjs/babelPlugins/babel-plugin-redwood-cell.js +121 -0
- package/dist/cjs/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts +5 -0
- package/dist/cjs/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts.map +1 -0
- package/dist/cjs/babelPlugins/babel-plugin-redwood-prerender-media-imports.js +100 -0
- package/dist/cjs/babelPlugins/utils.d.ts +2 -0
- package/dist/cjs/babelPlugins/utils.d.ts.map +1 -0
- package/dist/cjs/babelPlugins/utils.js +49 -0
- package/dist/cjs/browserUtils/index.d.ts +8 -0
- package/dist/cjs/browserUtils/index.d.ts.map +1 -0
- package/dist/cjs/browserUtils/index.js +47 -0
- package/dist/cjs/build-and-import/buildAndImport.js +173 -0
- package/dist/cjs/build-and-import/load-tsconfig.d.js +1 -0
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.js +183 -0
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-directory-named-imports.js +83 -0
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-external.js +125 -0
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.js +48 -0
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-inject-file-globals.js +66 -0
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-prerender-media-imports.js +118 -0
- package/dist/cjs/build-and-import/rollupPlugins/rollup-plugin-cedarjs-routes-auto-loader.js +146 -0
- package/dist/cjs/build-and-import/rollupPlugins/utils.js +78 -0
- package/dist/cjs/build-and-import/utils.js +68 -0
- package/dist/cjs/detection/detection.d.ts +11 -0
- package/dist/cjs/detection/detection.d.ts.map +1 -0
- package/dist/cjs/detection/detection.js +48 -0
- package/dist/cjs/errors.d.ts +19 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +52 -0
- package/dist/cjs/graphql/graphql.d.ts +19 -0
- package/dist/cjs/graphql/graphql.d.ts.map +1 -0
- package/dist/cjs/graphql/graphql.js +152 -0
- package/dist/cjs/graphql/node-runner.js +109 -0
- package/dist/cjs/graphql/vite-plugin-cedar-auto-import.js +107 -0
- package/dist/cjs/graphql/vite-plugin-cedar-import-dir.js +118 -0
- package/dist/{index.d.ts.map → cjs/index.d.ts.map} +1 -1
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/internal.d.ts +28 -0
- package/dist/cjs/internal.d.ts.map +1 -0
- package/dist/cjs/internal.js +135 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/runPrerender.d.ts.map +1 -0
- package/dist/cjs/runPrerender.js +307 -0
- package/dist/cjs/runPrerenderEsm.js +304 -0
- package/dist/graphql/graphql.d.ts +3 -3
- package/dist/graphql/graphql.d.ts.map +1 -1
- package/dist/graphql/graphql.js +4 -4
- package/dist/runPrerenderEsm.d.ts +9 -0
- package/dist/runPrerenderEsm.d.ts.map +1 -0
- package/dist/{runPrerender.js → runPrerenderEsm.js} +5 -5
- package/package.json +44 -17
- package/dist/index.js +0 -1
- package/dist/runPrerender.d.ts.map +0 -1
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{runPrerender.d.ts → cjs/runPrerender.d.ts} +0 -0
|
@@ -0,0 +1,152 @@
|
|
|
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 graphql_exports = {};
|
|
30
|
+
__export(graphql_exports, {
|
|
31
|
+
executeQuery: () => executeQuery,
|
|
32
|
+
getGqlHandler: () => getGqlHandler
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(graphql_exports);
|
|
35
|
+
var import_path = __toESM(require("path"), 1);
|
|
36
|
+
var import_graphql = require("graphql");
|
|
37
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
38
|
+
var import_graphql2 = require("@cedarjs/web/dist/graphql.js");
|
|
39
|
+
var import_errors = require("../errors.js");
|
|
40
|
+
async function executeQuery(fileImporter, gqlHandler, query, variables) {
|
|
41
|
+
const config = (0, import_project_config.getConfig)();
|
|
42
|
+
const operationName = (0, import_graphql2.getOperationName)(query);
|
|
43
|
+
const operation = {
|
|
44
|
+
operationName,
|
|
45
|
+
query: (0, import_graphql.print)(query),
|
|
46
|
+
variables
|
|
47
|
+
};
|
|
48
|
+
if (config.graphql.trustedDocuments) {
|
|
49
|
+
const documentsPath = import_path.default.join((0, import_project_config.getPaths)().web.graphql, "graphql");
|
|
50
|
+
const documents = await fileImporter(documentsPath);
|
|
51
|
+
const documentName = operationName[0].toUpperCase() + operationName.slice(1) + "Document";
|
|
52
|
+
const queryHash = documents?.[documentName]?.__meta__?.hash;
|
|
53
|
+
operation.query = void 0;
|
|
54
|
+
operation.extensions = {
|
|
55
|
+
persistedQuery: {
|
|
56
|
+
version: 1,
|
|
57
|
+
sha256Hash: queryHash
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const handlerResult = await gqlHandler(operation);
|
|
62
|
+
return handlerResult?.body;
|
|
63
|
+
}
|
|
64
|
+
async function getGqlHandler(fileImporter) {
|
|
65
|
+
const gqlPath = import_path.default.join((0, import_project_config.getPaths)().api.functions, "graphql");
|
|
66
|
+
try {
|
|
67
|
+
const { handler } = await fileImporter(gqlPath);
|
|
68
|
+
return async (operation) => {
|
|
69
|
+
return await handler(buildApiEvent(operation), buildContext());
|
|
70
|
+
};
|
|
71
|
+
} catch {
|
|
72
|
+
return () => {
|
|
73
|
+
throw new import_errors.GqlHandlerImportError(
|
|
74
|
+
`Unable to import GraphQL handler at ${gqlPath}`
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function buildApiEvent(body) {
|
|
80
|
+
return {
|
|
81
|
+
body: JSON.stringify(body),
|
|
82
|
+
headers: {
|
|
83
|
+
origin: "http://localhost:8910",
|
|
84
|
+
"content-type": "application/json",
|
|
85
|
+
accept: "*/*",
|
|
86
|
+
host: "localhost:8910"
|
|
87
|
+
},
|
|
88
|
+
multiValueHeaders: {},
|
|
89
|
+
httpMethod: "POST",
|
|
90
|
+
isBase64Encoded: false,
|
|
91
|
+
path: "/graphql",
|
|
92
|
+
pathParameters: null,
|
|
93
|
+
queryStringParameters: {},
|
|
94
|
+
multiValueQueryStringParameters: null,
|
|
95
|
+
stageVariables: null,
|
|
96
|
+
resource: "",
|
|
97
|
+
requestContext: {
|
|
98
|
+
requestId: "req-3",
|
|
99
|
+
identity: {
|
|
100
|
+
sourceIp: "::1",
|
|
101
|
+
accessKey: null,
|
|
102
|
+
accountId: null,
|
|
103
|
+
apiKey: null,
|
|
104
|
+
apiKeyId: null,
|
|
105
|
+
caller: null,
|
|
106
|
+
clientCert: null,
|
|
107
|
+
cognitoAuthenticationProvider: null,
|
|
108
|
+
cognitoAuthenticationType: null,
|
|
109
|
+
cognitoIdentityId: null,
|
|
110
|
+
cognitoIdentityPoolId: null,
|
|
111
|
+
principalOrgId: null,
|
|
112
|
+
user: null,
|
|
113
|
+
userAgent: null,
|
|
114
|
+
userArn: null
|
|
115
|
+
},
|
|
116
|
+
authorizer: {},
|
|
117
|
+
protocol: "http",
|
|
118
|
+
httpMethod: "POST",
|
|
119
|
+
path: "/graphql",
|
|
120
|
+
stage: "",
|
|
121
|
+
requestTimeEpoch: 0,
|
|
122
|
+
resourceId: "",
|
|
123
|
+
resourcePath: "",
|
|
124
|
+
accountId: "",
|
|
125
|
+
apiId: ""
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function buildContext() {
|
|
130
|
+
return {
|
|
131
|
+
callbackWaitsForEmptyEventLoop: false,
|
|
132
|
+
functionName: "",
|
|
133
|
+
functionVersion: "",
|
|
134
|
+
invokedFunctionArn: "",
|
|
135
|
+
memoryLimitInMB: "",
|
|
136
|
+
awsRequestId: "",
|
|
137
|
+
logGroupName: "",
|
|
138
|
+
logStreamName: "",
|
|
139
|
+
getRemainingTimeInMillis: () => 100,
|
|
140
|
+
done: () => {
|
|
141
|
+
},
|
|
142
|
+
fail: () => {
|
|
143
|
+
},
|
|
144
|
+
succeed: () => {
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
149
|
+
0 && (module.exports = {
|
|
150
|
+
executeQuery,
|
|
151
|
+
getGqlHandler
|
|
152
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var node_runner_exports = {};
|
|
20
|
+
__export(node_runner_exports, {
|
|
21
|
+
NodeRunner: () => NodeRunner
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(node_runner_exports);
|
|
24
|
+
var import_vite = require("vite");
|
|
25
|
+
var import_client = require("vite-node/client");
|
|
26
|
+
var import_server = require("vite-node/server");
|
|
27
|
+
var import_source_map = require("vite-node/source-map");
|
|
28
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
29
|
+
var import_vite2 = require("@cedarjs/vite");
|
|
30
|
+
var import_vite_plugin_cedar_auto_import = require("./vite-plugin-cedar-auto-import.js");
|
|
31
|
+
var import_vite_plugin_cedar_import_dir = require("./vite-plugin-cedar-import-dir.js");
|
|
32
|
+
async function createViteServer(customConfig = {}) {
|
|
33
|
+
const defaultConfig = {
|
|
34
|
+
mode: "production",
|
|
35
|
+
optimizeDeps: {
|
|
36
|
+
// This is recommended in the vite-node readme
|
|
37
|
+
noDiscovery: true,
|
|
38
|
+
include: void 0
|
|
39
|
+
},
|
|
40
|
+
resolve: {
|
|
41
|
+
alias: [
|
|
42
|
+
{
|
|
43
|
+
find: /^src\/(.*?)(\.([jt]sx?))?$/,
|
|
44
|
+
replacement: (0, import_project_config.getPaths)().api.src + "/$1"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
plugins: [
|
|
49
|
+
(0, import_vite_plugin_cedar_import_dir.cedarImportDirPlugin)(),
|
|
50
|
+
(0, import_vite_plugin_cedar_auto_import.cedarAutoImportsPlugin)(),
|
|
51
|
+
(0, import_vite2.cedarjsDirectoryNamedImportPlugin)(),
|
|
52
|
+
(0, import_vite2.cedarCellTransform)(),
|
|
53
|
+
(0, import_vite2.cedarjsJobPathInjectorPlugin)(),
|
|
54
|
+
(0, import_vite2.cedarSwapApolloProvider)()
|
|
55
|
+
]
|
|
56
|
+
};
|
|
57
|
+
const mergedConfig = (0, import_vite.mergeConfig)(defaultConfig, customConfig);
|
|
58
|
+
const server = await (0, import_vite.createServer)(mergedConfig);
|
|
59
|
+
if (Number(import_vite.version.split(".")[0]) < 6) {
|
|
60
|
+
await server.pluginContainer.buildStart({});
|
|
61
|
+
}
|
|
62
|
+
return server;
|
|
63
|
+
}
|
|
64
|
+
class NodeRunner {
|
|
65
|
+
viteServer = void 0;
|
|
66
|
+
runner = void 0;
|
|
67
|
+
customViteConfig;
|
|
68
|
+
constructor(customViteConfig = {}) {
|
|
69
|
+
this.customViteConfig = customViteConfig;
|
|
70
|
+
}
|
|
71
|
+
async init() {
|
|
72
|
+
this.viteServer = await createViteServer(this.customViteConfig);
|
|
73
|
+
const nodeServer = new import_server.ViteNodeServer(this.viteServer, {
|
|
74
|
+
transformMode: {
|
|
75
|
+
ssr: [/.*/],
|
|
76
|
+
web: [/\/web\//]
|
|
77
|
+
},
|
|
78
|
+
deps: {
|
|
79
|
+
fallbackCJS: true
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
(0, import_source_map.installSourcemapsSupport)({
|
|
83
|
+
getSourceMap: (source) => nodeServer?.getSourceMap(source)
|
|
84
|
+
});
|
|
85
|
+
this.runner = new import_client.ViteNodeRunner({
|
|
86
|
+
root: this.viteServer.config.root,
|
|
87
|
+
base: this.viteServer.config.base,
|
|
88
|
+
fetchModule(id) {
|
|
89
|
+
return nodeServer.fetchModule(id);
|
|
90
|
+
},
|
|
91
|
+
resolveId(id, importer) {
|
|
92
|
+
return nodeServer.resolveId(id, importer);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
async importFile(filePath) {
|
|
97
|
+
if (!this.runner) {
|
|
98
|
+
await this.init();
|
|
99
|
+
}
|
|
100
|
+
return this.runner?.executeFile(filePath);
|
|
101
|
+
}
|
|
102
|
+
async close() {
|
|
103
|
+
await this.viteServer?.close();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {
|
|
108
|
+
NodeRunner
|
|
109
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
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_auto_import_exports = {};
|
|
30
|
+
__export(vite_plugin_cedar_auto_import_exports, {
|
|
31
|
+
cedarAutoImportsPlugin: () => cedarAutoImportsPlugin
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(vite_plugin_cedar_auto_import_exports);
|
|
34
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
35
|
+
var import_unplugin = __toESM(require("unimport/unplugin"), 1);
|
|
36
|
+
var import_vite = __toESM(require("unplugin-auto-import/vite"), 1);
|
|
37
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
38
|
+
function cedarAutoImportsPlugin() {
|
|
39
|
+
const config = (0, import_project_config.getConfig)();
|
|
40
|
+
const cedarPaths = (0, import_project_config.getPaths)();
|
|
41
|
+
const useTrustedDocumentsGqlTag = config?.graphql?.trustedDocuments;
|
|
42
|
+
return [
|
|
43
|
+
(0, import_vite.default)({
|
|
44
|
+
// targets to transform
|
|
45
|
+
include: [
|
|
46
|
+
/web\/.*\.[tj]sx?$/,
|
|
47
|
+
// Assume we want the trusted documents gql tag import in all .jsx and
|
|
48
|
+
// .tsx files
|
|
49
|
+
/\.[tj]sx$/
|
|
50
|
+
],
|
|
51
|
+
// global imports to register
|
|
52
|
+
imports: [
|
|
53
|
+
// import gql from 'graphql-tag'
|
|
54
|
+
!useTrustedDocumentsGqlTag && {
|
|
55
|
+
"graphql-tag": ["gql"]
|
|
56
|
+
},
|
|
57
|
+
// import { gql } from 'src/graphql/gql'
|
|
58
|
+
useTrustedDocumentsGqlTag && {
|
|
59
|
+
[(0, import_project_config.importStatementPath)(
|
|
60
|
+
import_node_path.default.join(cedarPaths.web.base, "src", "graphql", "gql")
|
|
61
|
+
)]: ["gql"]
|
|
62
|
+
}
|
|
63
|
+
].filter((v) => Boolean(v)),
|
|
64
|
+
// Types aren't important since the output is ephemeral
|
|
65
|
+
dts: false
|
|
66
|
+
}),
|
|
67
|
+
(0, import_vite.default)({
|
|
68
|
+
// targets to transform
|
|
69
|
+
include: [/\.[tj]sx?$/],
|
|
70
|
+
// global imports to register
|
|
71
|
+
imports: [
|
|
72
|
+
{
|
|
73
|
+
"@cedarjs/context": ["context"]
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
// Types aren't important since the output is ephemeral
|
|
77
|
+
dts: false
|
|
78
|
+
}),
|
|
79
|
+
(0, import_vite.default)({
|
|
80
|
+
// targets to transform
|
|
81
|
+
include: [/api\/.*\.[tj]sx?$/],
|
|
82
|
+
// global imports to register
|
|
83
|
+
imports: [
|
|
84
|
+
// import gql from 'graphql-tag'
|
|
85
|
+
{
|
|
86
|
+
"graphql-tag": ["gql"]
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
// Types aren't important since the output is ephemeral
|
|
90
|
+
dts: false
|
|
91
|
+
}),
|
|
92
|
+
import_unplugin.default.vite({
|
|
93
|
+
imports: [
|
|
94
|
+
// import React from 'react'
|
|
95
|
+
{
|
|
96
|
+
name: "default",
|
|
97
|
+
as: "React",
|
|
98
|
+
from: "react"
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
})
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
cedarAutoImportsPlugin
|
|
107
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
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_import_dir_exports = {};
|
|
30
|
+
__export(vite_plugin_cedar_import_dir_exports, {
|
|
31
|
+
cedarImportDirPlugin: () => cedarImportDirPlugin
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(vite_plugin_cedar_import_dir_exports);
|
|
34
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
35
|
+
var import_napi = require("@ast-grep/napi");
|
|
36
|
+
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
37
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
38
|
+
function cedarImportDirPlugin() {
|
|
39
|
+
return {
|
|
40
|
+
name: "vite-plugin-cedar-import-dir",
|
|
41
|
+
enforce: "pre",
|
|
42
|
+
async transform(code, id) {
|
|
43
|
+
if (!code.includes("/**/")) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const ext = import_node_path.default.extname(id);
|
|
47
|
+
const language = ext === ".ts" || ext === ".tsx" ? import_napi.Lang.TypeScript : import_napi.Lang.JavaScript;
|
|
48
|
+
let ast;
|
|
49
|
+
try {
|
|
50
|
+
ast = (0, import_napi.parse)(language, code);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.warn("Failed to parse file:", id);
|
|
53
|
+
console.warn(error);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const root = ast.root();
|
|
57
|
+
let hasTransformations = false;
|
|
58
|
+
const edits = [];
|
|
59
|
+
const globImports = root.findAll({
|
|
60
|
+
rule: {
|
|
61
|
+
pattern: "import $DEFAULT_IMPORT from $SOURCE"
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
for (const importNode of globImports) {
|
|
65
|
+
const sourceNode = importNode.getMatch("SOURCE");
|
|
66
|
+
const defaultImportNode = importNode.getMatch("DEFAULT_IMPORT");
|
|
67
|
+
if (!sourceNode || !defaultImportNode) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const sourceValue = sourceNode.text().slice(1, -1);
|
|
71
|
+
if (!sourceValue.includes("/**/")) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
hasTransformations = true;
|
|
75
|
+
const importName = defaultImportNode.text();
|
|
76
|
+
const importGlob = (0, import_project_config.importStatementPath)(sourceValue);
|
|
77
|
+
const cwd = importGlob.startsWith("src/") ? (0, import_project_config.getPaths)().api.base : import_node_path.default.dirname(id);
|
|
78
|
+
try {
|
|
79
|
+
const dirFiles = import_fast_glob.default.sync(importGlob, { cwd }).filter(
|
|
80
|
+
(n) => !n.includes(".test.") && !n.includes(".scenarios.") && !n.includes(".d.ts")
|
|
81
|
+
);
|
|
82
|
+
const staticGlob = importGlob.split("*")[0];
|
|
83
|
+
const filePathToVarName = (filePath) => {
|
|
84
|
+
return filePath.replace(staticGlob, "").replace(/\.(js|ts)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
|
|
85
|
+
};
|
|
86
|
+
let replacement = `let ${importName} = {};
|
|
87
|
+
`;
|
|
88
|
+
for (const filePath of dirFiles) {
|
|
89
|
+
const { dir: fileDir, name: fileName } = import_node_path.default.parse(filePath);
|
|
90
|
+
const fileImportPath = fileDir + "/" + fileName;
|
|
91
|
+
const filePathVarName = filePathToVarName(filePath);
|
|
92
|
+
const namespaceImportName = `${importName}_${filePathVarName}`;
|
|
93
|
+
replacement += `import * as ${namespaceImportName} from '${fileImportPath}';
|
|
94
|
+
`;
|
|
95
|
+
replacement += `${importName}.${filePathVarName} = ${namespaceImportName};
|
|
96
|
+
`;
|
|
97
|
+
}
|
|
98
|
+
edits.push(importNode.replace(replacement.trim()));
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.warn(`Failed to process glob import: ${sourceValue}`, error);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (hasTransformations && edits.length > 0) {
|
|
104
|
+
const transformedCode = root.commitEdits(edits);
|
|
105
|
+
return {
|
|
106
|
+
code: transformedCode,
|
|
107
|
+
map: null
|
|
108
|
+
// For simplicity, not generating source maps
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
+
0 && (module.exports = {
|
|
117
|
+
cedarImportDirPlugin
|
|
118
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var index_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(index_exports);
|
|
18
|
+
__reExport(index_exports, require("./runPrerender.js"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./runPrerender.js")
|
|
22
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const getRootHtmlPath: () => string;
|
|
2
|
+
export declare const registerShims: (routerPath: string) => void;
|
|
3
|
+
export declare const writeToDist: (outputHtmlPath: string, renderOutput: string) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Finds, reads and parses the [ts|js]config.json file
|
|
6
|
+
* @returns The config object
|
|
7
|
+
*/
|
|
8
|
+
export declare const parseTypeScriptConfigFiles: () => {
|
|
9
|
+
api: any;
|
|
10
|
+
web: any;
|
|
11
|
+
};
|
|
12
|
+
type CompilerOptionsForPaths = {
|
|
13
|
+
compilerOptions: {
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
paths: Record<string, string[]>;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Extracts and formats the paths from the [ts|js]config.json file
|
|
20
|
+
* @param config The config object
|
|
21
|
+
* @param rootDir {string} Where the jsconfig/tsconfig is loaded from
|
|
22
|
+
*/
|
|
23
|
+
export declare function getPathsFromTypeScriptConfig(config: CompilerOptionsForPaths, rootDir: string): {
|
|
24
|
+
find: string;
|
|
25
|
+
replacement: string;
|
|
26
|
+
}[];
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,eAAe,cAM3B,CAAA;AAED,eAAO,MAAM,aAAa,eAAgB,MAAM,SAiC/C,CAAA;AAED,eAAO,MAAM,WAAW,mBAAoB,MAAM,gBAAgB,MAAM,SAQvE,CAAA;AAGD;;;GAGG;AACH,eAAO,MAAM,0BAA0B;;;CA0BtC,CAAA;AAED,KAAK,uBAAuB,GAAG;IAC7B,eAAe,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;KAAE,CAAA;CACtE,CAAA;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,uBAAuB,EAC/B,OAAO,EAAE,MAAM;UAsBQ,MAAM;iBAAe,MAAM;IAkBnD"}
|
|
@@ -0,0 +1,135 @@
|
|
|
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 internal_exports = {};
|
|
30
|
+
__export(internal_exports, {
|
|
31
|
+
getPathsFromTypeScriptConfig: () => getPathsFromTypeScriptConfig,
|
|
32
|
+
getRootHtmlPath: () => getRootHtmlPath,
|
|
33
|
+
parseTypeScriptConfigFiles: () => parseTypeScriptConfigFiles,
|
|
34
|
+
registerShims: () => registerShims,
|
|
35
|
+
writeToDist: () => writeToDist
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(internal_exports);
|
|
38
|
+
var import_fs = __toESM(require("fs"), 1);
|
|
39
|
+
var import_path = __toESM(require("path"), 1);
|
|
40
|
+
var import_fetch = require("@whatwg-node/fetch");
|
|
41
|
+
var import_typescript = require("typescript");
|
|
42
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
43
|
+
const INDEX_FILE = import_path.default.join((0, import_project_config.getPaths)().web.dist, "index.html");
|
|
44
|
+
const DEFAULT_INDEX = import_path.default.join((0, import_project_config.getPaths)().web.dist, "200.html");
|
|
45
|
+
const getRootHtmlPath = () => {
|
|
46
|
+
if (import_fs.default.existsSync(DEFAULT_INDEX)) {
|
|
47
|
+
return DEFAULT_INDEX;
|
|
48
|
+
} else {
|
|
49
|
+
return INDEX_FILE;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const registerShims = (routerPath) => {
|
|
53
|
+
const rwjsConfig = (0, import_project_config.getConfig)();
|
|
54
|
+
globalThis.RWJS_ENV = {
|
|
55
|
+
RWJS_API_GRAPHQL_URL: rwjsConfig.web.apiGraphQLUrl ?? rwjsConfig.web.apiUrl + "/graphql",
|
|
56
|
+
RWJS_API_URL: rwjsConfig.web.apiUrl,
|
|
57
|
+
__REDWOOD__APP_TITLE: rwjsConfig.web.title
|
|
58
|
+
};
|
|
59
|
+
globalThis.RWJS_DEBUG_ENV = {
|
|
60
|
+
RWJS_SRC_ROOT: (0, import_project_config.getPaths)().web.src
|
|
61
|
+
};
|
|
62
|
+
globalThis.__REDWOOD__PRERENDERING = true;
|
|
63
|
+
globalThis.__REDWOOD__HELMET_CONTEXT = {};
|
|
64
|
+
process.env.__REDWOOD__PRERENDERING = "1";
|
|
65
|
+
globalThis.location = {
|
|
66
|
+
...globalThis.location,
|
|
67
|
+
pathname: routerPath
|
|
68
|
+
};
|
|
69
|
+
if (!globalThis.fetch) {
|
|
70
|
+
globalThis.fetch = import_fetch.fetch;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const writeToDist = (outputHtmlPath, renderOutput) => {
|
|
74
|
+
const dirName = import_path.default.dirname(outputHtmlPath);
|
|
75
|
+
const exist = import_fs.default.existsSync(dirName);
|
|
76
|
+
if (!exist) {
|
|
77
|
+
import_fs.default.mkdirSync(dirName, { recursive: true });
|
|
78
|
+
}
|
|
79
|
+
import_fs.default.writeFileSync(outputHtmlPath, renderOutput);
|
|
80
|
+
};
|
|
81
|
+
const parseTypeScriptConfigFiles = () => {
|
|
82
|
+
const rwPaths = (0, import_project_config.getPaths)();
|
|
83
|
+
const parseConfigFile = (basePath) => {
|
|
84
|
+
let configPath = import_path.default.join(basePath, "tsconfig.json");
|
|
85
|
+
if (!import_fs.default.existsSync(configPath)) {
|
|
86
|
+
configPath = import_path.default.join(basePath, "jsconfig.json");
|
|
87
|
+
if (!import_fs.default.existsSync(configPath)) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return (0, import_typescript.parseConfigFileTextToJson)(
|
|
92
|
+
configPath,
|
|
93
|
+
import_fs.default.readFileSync(configPath, "utf-8")
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
const apiConfig = parseConfigFile(rwPaths.api.base);
|
|
97
|
+
const webConfig = parseConfigFile(rwPaths.web.base);
|
|
98
|
+
return {
|
|
99
|
+
api: apiConfig?.config ?? null,
|
|
100
|
+
web: webConfig?.config ?? null
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
function getPathsFromTypeScriptConfig(config, rootDir) {
|
|
104
|
+
if (!config) {
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
if (!config.compilerOptions?.paths) {
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
const { baseUrl, paths } = config.compilerOptions;
|
|
111
|
+
let absoluteBase;
|
|
112
|
+
if (baseUrl) {
|
|
113
|
+
absoluteBase = import_path.default.isAbsolute(baseUrl) ? baseUrl : import_path.default.join(rootDir, baseUrl);
|
|
114
|
+
} else {
|
|
115
|
+
absoluteBase = rootDir;
|
|
116
|
+
}
|
|
117
|
+
const aliases = [];
|
|
118
|
+
for (const [key, value] of Object.entries(paths)) {
|
|
119
|
+
if (key.match(/src\/|\$api\/\*|types\/\*|\@cedarjs\/.*/g)) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const aliasKey = key.replace("/*", "");
|
|
123
|
+
const aliasValue = import_path.default.join(absoluteBase, value[0].replace("/*", ""));
|
|
124
|
+
aliases.push({ find: aliasKey, replacement: aliasValue });
|
|
125
|
+
}
|
|
126
|
+
return aliases;
|
|
127
|
+
}
|
|
128
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
129
|
+
0 && (module.exports = {
|
|
130
|
+
getPathsFromTypeScriptConfig,
|
|
131
|
+
getRootHtmlPath,
|
|
132
|
+
parseTypeScriptConfigFiles,
|
|
133
|
+
registerShims,
|
|
134
|
+
writeToDist
|
|
135
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|