@cedarjs/prerender 0.9.0 → 0.9.1-next.19
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/browserUtils/index.js +4 -31
- package/dist/build-and-import/buildAndImport.d.ts +12 -0
- package/dist/build-and-import/buildAndImport.d.ts.map +1 -0
- package/dist/build-and-import/buildAndImport.js +142 -0
- package/dist/build-and-import/load-tsconfig.d.js +0 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.d.ts +23 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.d.ts.map +1 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.js +149 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-directory-named-imports.d.ts +3 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-directory-named-imports.d.ts.map +1 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-directory-named-imports.js +49 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-external.d.ts +9 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-external.d.ts.map +1 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-external.js +91 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.d.ts +24 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.d.ts.map +1 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.js +24 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-inject-file-globals.d.ts +3 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-inject-file-globals.d.ts.map +1 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-inject-file-globals.js +32 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-prerender-media-imports.d.ts +25 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-prerender-media-imports.d.ts.map +1 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-prerender-media-imports.js +84 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-routes-auto-loader.d.ts +6 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-routes-auto-loader.d.ts.map +1 -0
- package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-routes-auto-loader.js +117 -0
- package/dist/build-and-import/rollupPlugins/utils.d.ts +3 -0
- package/dist/build-and-import/rollupPlugins/utils.d.ts.map +1 -0
- package/dist/build-and-import/rollupPlugins/utils.js +43 -0
- package/dist/build-and-import/utils.d.ts +14 -0
- package/dist/build-and-import/utils.d.ts.map +1 -0
- package/dist/build-and-import/utils.js +30 -0
- package/dist/detection/{index.d.ts → detection.d.ts} +1 -1
- package/dist/detection/detection.d.ts.map +1 -0
- package/dist/detection/detection.js +24 -0
- package/dist/errors.js +4 -30
- package/dist/graphql/graphql.d.ts +5 -5
- package/dist/graphql/graphql.d.ts.map +1 -1
- package/dist/graphql/graphql.js +17 -52
- package/dist/graphql/node-runner.d.ts +11 -0
- package/dist/graphql/node-runner.d.ts.map +1 -0
- package/dist/graphql/node-runner.js +90 -0
- package/dist/graphql/vite-plugin-cedar-auto-import.d.ts +2 -0
- package/dist/graphql/vite-plugin-cedar-auto-import.d.ts.map +1 -0
- package/dist/graphql/vite-plugin-cedar-auto-import.js +77 -0
- package/dist/graphql/vite-plugin-cedar-import-dir.d.ts +19 -0
- package/dist/graphql/vite-plugin-cedar-import-dir.d.ts.map +1 -0
- package/dist/graphql/vite-plugin-cedar-import-dir.js +84 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -22
- package/dist/internal.d.ts +24 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +66 -52
- package/dist/runPrerender.d.ts.map +1 -1
- package/dist/runPrerender.js +116 -137
- package/package.json +24 -12
- package/dist/babelPlugins/babel-plugin-redwood-cell.d.ts +0 -5
- package/dist/babelPlugins/babel-plugin-redwood-cell.d.ts.map +0 -1
- package/dist/babelPlugins/babel-plugin-redwood-cell.js +0 -115
- package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts +0 -5
- package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.d.ts.map +0 -1
- package/dist/babelPlugins/babel-plugin-redwood-prerender-media-imports.js +0 -94
- package/dist/babelPlugins/utils.d.ts +0 -2
- package/dist/babelPlugins/utils.d.ts.map +0 -1
- package/dist/babelPlugins/utils.js +0 -49
- package/dist/detection/index.d.ts.map +0 -1
- package/dist/detection/index.js +0 -48
|
@@ -1,36 +1,10 @@
|
|
|
1
|
-
|
|
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 browserUtils_exports = {};
|
|
20
|
-
__export(browserUtils_exports, {
|
|
21
|
-
BrowserOnly: () => BrowserOnly,
|
|
22
|
-
isBrowser: () => isBrowser,
|
|
23
|
-
isPrerendering: () => isPrerendering,
|
|
24
|
-
useIsBrowser: () => useIsBrowser
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(browserUtils_exports);
|
|
27
|
-
var import_react = require("react");
|
|
1
|
+
import { useMemo } from "react";
|
|
28
2
|
const isPrerendering = () => {
|
|
29
3
|
return globalThis.__REDWOOD__PRERENDERING ?? false;
|
|
30
4
|
};
|
|
31
5
|
const isBrowser = !isPrerendering();
|
|
32
6
|
const useIsBrowser = () => {
|
|
33
|
-
return
|
|
7
|
+
return useMemo(() => {
|
|
34
8
|
return !globalThis?.__REDWOOD__PRERENDERING;
|
|
35
9
|
}, []);
|
|
36
10
|
};
|
|
@@ -38,10 +12,9 @@ const BrowserOnly = ({ children }) => {
|
|
|
38
12
|
const isBrowser2 = useIsBrowser();
|
|
39
13
|
return isBrowser2 ? children : null;
|
|
40
14
|
};
|
|
41
|
-
|
|
42
|
-
0 && (module.exports = {
|
|
15
|
+
export {
|
|
43
16
|
BrowserOnly,
|
|
44
17
|
isBrowser,
|
|
45
18
|
isPrerendering,
|
|
46
19
|
useIsBrowser
|
|
47
|
-
}
|
|
20
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface Options {
|
|
2
|
+
/** The filepath to bundle and require */
|
|
3
|
+
filepath: string;
|
|
4
|
+
/**
|
|
5
|
+
* Preserve compiled temporary file for debugging
|
|
6
|
+
* Default to `process.env.BUNDLE_REQUIRE_PRESERVE`
|
|
7
|
+
*/
|
|
8
|
+
preserveTemporaryFile?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function buildAndImport(options: Options): Promise<Record<string, React.FunctionComponent>>;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=buildAndImport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildAndImport.d.ts","sourceRoot":"","sources":["../../src/build-and-import/buildAndImport.ts"],"names":[],"mappings":"AAoCA,UAAU,OAAO;IACf,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAA;IAEhB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC;AAED,wBAAsB,cAAc,CAClC,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAmIlD"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import alias from "@rollup/plugin-alias";
|
|
4
|
+
import commonjs from "@rollup/plugin-commonjs";
|
|
5
|
+
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
6
|
+
import replace from "@rollup/plugin-replace";
|
|
7
|
+
import { rollup } from "rollup";
|
|
8
|
+
import { swc } from "rollup-plugin-swc3";
|
|
9
|
+
import unimportPlugin from "unimport/unplugin";
|
|
10
|
+
import { getConfig, getPaths, projectIsEsm } from "@cedarjs/project-config";
|
|
11
|
+
import {
|
|
12
|
+
getPathsFromTypeScriptConfig,
|
|
13
|
+
parseTypeScriptConfigFiles
|
|
14
|
+
} from "../internal.js";
|
|
15
|
+
import { cellTransformPlugin } from "./rollupPlugins/rollup-plugin-cedarjs-cell.js";
|
|
16
|
+
import { cedarjsDirectoryNamedImportPlugin } from "./rollupPlugins/rollup-plugin-cedarjs-directory-named-imports.js";
|
|
17
|
+
import { externalPlugin } from "./rollupPlugins/rollup-plugin-cedarjs-external.js";
|
|
18
|
+
import { ignoreHtmlAndCssImportsPlugin } from "./rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.js";
|
|
19
|
+
import { injectFileGlobalsPlugin } from "./rollupPlugins/rollup-plugin-cedarjs-inject-file-globals.js";
|
|
20
|
+
import { cedarjsPrerenderMediaImportsPlugin } from "./rollupPlugins/rollup-plugin-cedarjs-prerender-media-imports.js";
|
|
21
|
+
import { cedarjsRoutesAutoLoaderPlugin } from "./rollupPlugins/rollup-plugin-cedarjs-routes-auto-loader.js";
|
|
22
|
+
import { getPkgType, isValidJsFile, makeFilePath } from "./utils.js";
|
|
23
|
+
const fix = (f) => f;
|
|
24
|
+
const tsconfigPathsToRegExp = (paths) => {
|
|
25
|
+
return Object.keys(paths || {}).map((key) => {
|
|
26
|
+
return new RegExp(`^${key.replace(/\*/g, ".*")}$`);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
async function buildAndImport(options) {
|
|
30
|
+
if (!isValidJsFile(options.filepath)) {
|
|
31
|
+
throw new Error(`${options.filepath} is not a valid JS file`);
|
|
32
|
+
}
|
|
33
|
+
const tsConfigs = parseTypeScriptConfigFiles();
|
|
34
|
+
const resolvePaths = tsconfigPathsToRegExp(
|
|
35
|
+
tsConfigs.web?.compilerOptions?.paths || {}
|
|
36
|
+
);
|
|
37
|
+
const config = getConfig();
|
|
38
|
+
const useTrustedDocumentsGqlTag = config.graphql.trustedDocuments;
|
|
39
|
+
const webBase = getPaths().web.base;
|
|
40
|
+
const outDir = path.join(getPaths().web.dist, "__prerender");
|
|
41
|
+
if (!fs.existsSync(outDir)) {
|
|
42
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
43
|
+
}
|
|
44
|
+
const isEsm = projectIsEsm();
|
|
45
|
+
const build = await rollup({
|
|
46
|
+
input: [options.filepath],
|
|
47
|
+
output: {
|
|
48
|
+
dir: outDir
|
|
49
|
+
},
|
|
50
|
+
jsx: "react-jsx",
|
|
51
|
+
logLevel: "debug",
|
|
52
|
+
external: ["react", "react-dom"],
|
|
53
|
+
plugins: [
|
|
54
|
+
externalPlugin({
|
|
55
|
+
notExternal: resolvePaths,
|
|
56
|
+
filepath: options.filepath
|
|
57
|
+
}),
|
|
58
|
+
nodeResolve({
|
|
59
|
+
preferBuiltins: true,
|
|
60
|
+
exportConditions: ["node"],
|
|
61
|
+
extensions: [".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs"]
|
|
62
|
+
}),
|
|
63
|
+
// @ts-expect-error - Ignore type errors for now
|
|
64
|
+
replace({
|
|
65
|
+
preventAssignment: true,
|
|
66
|
+
"process.env.NODE_ENV": '"production"'
|
|
67
|
+
}),
|
|
68
|
+
fix(alias)({
|
|
69
|
+
entries: [
|
|
70
|
+
{
|
|
71
|
+
find: "src",
|
|
72
|
+
replacement: getPaths().web.src
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
find: "$api",
|
|
76
|
+
replacement: getPaths().api.base
|
|
77
|
+
},
|
|
78
|
+
...getPathsFromTypeScriptConfig(tsConfigs.web, webBase)
|
|
79
|
+
]
|
|
80
|
+
}),
|
|
81
|
+
ignoreHtmlAndCssImportsPlugin(),
|
|
82
|
+
cellTransformPlugin(),
|
|
83
|
+
cedarjsRoutesAutoLoaderPlugin(),
|
|
84
|
+
cedarjsDirectoryNamedImportPlugin(),
|
|
85
|
+
cedarjsPrerenderMediaImportsPlugin(),
|
|
86
|
+
fix(commonjs)(),
|
|
87
|
+
swc({ sourceMaps: true }),
|
|
88
|
+
unimportPlugin.rollup({
|
|
89
|
+
imports: [
|
|
90
|
+
// import React from 'react'
|
|
91
|
+
{
|
|
92
|
+
name: "default",
|
|
93
|
+
as: "React",
|
|
94
|
+
from: "react"
|
|
95
|
+
},
|
|
96
|
+
// import { gql } from 'graphql-tag'
|
|
97
|
+
!useTrustedDocumentsGqlTag && isEsm && {
|
|
98
|
+
name: "gql",
|
|
99
|
+
from: "graphql-tag"
|
|
100
|
+
},
|
|
101
|
+
// import gql from 'graphql-tag'
|
|
102
|
+
!useTrustedDocumentsGqlTag && !isEsm && {
|
|
103
|
+
name: "default",
|
|
104
|
+
as: "gql",
|
|
105
|
+
from: "graphql-tag"
|
|
106
|
+
},
|
|
107
|
+
// import { gql } from 'src/graphql/gql'
|
|
108
|
+
useTrustedDocumentsGqlTag && {
|
|
109
|
+
name: "gql",
|
|
110
|
+
from: `web/src/graphql/gql`
|
|
111
|
+
}
|
|
112
|
+
].filter((v) => Boolean(v))
|
|
113
|
+
}),
|
|
114
|
+
injectFileGlobalsPlugin()
|
|
115
|
+
]
|
|
116
|
+
});
|
|
117
|
+
try {
|
|
118
|
+
const { output } = await build.generate({
|
|
119
|
+
dir: outDir,
|
|
120
|
+
format: getPkgType() === "module" ? "es" : "cjs",
|
|
121
|
+
exports: "auto",
|
|
122
|
+
sourcemap: "inline"
|
|
123
|
+
});
|
|
124
|
+
for (const chunk of output) {
|
|
125
|
+
if (chunk.type !== "chunk") {
|
|
126
|
+
throw new Error("[bundle-require] Expected chunk output");
|
|
127
|
+
}
|
|
128
|
+
const chunkPath = path.join(outDir, chunk.fileName);
|
|
129
|
+
await fs.promises.writeFile(chunkPath, chunk.code, "utf8");
|
|
130
|
+
}
|
|
131
|
+
const importPath = makeFilePath(path.join(outDir, output[0].fileName));
|
|
132
|
+
return import(importPath);
|
|
133
|
+
} finally {
|
|
134
|
+
if (!options.preserveTemporaryFile) {
|
|
135
|
+
await fs.promises.rm(outDir, { recursive: true, force: true });
|
|
136
|
+
}
|
|
137
|
+
await build.close();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export {
|
|
141
|
+
buildAndImport
|
|
142
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Plugin } from 'rollup';
|
|
2
|
+
/**
|
|
3
|
+
* Vite plugin that wraps files with a suffix of `Cell` in Redwood's `createCell`
|
|
4
|
+
* higher order component. The HOC deals with the lifecycle methods during a GraphQL query.
|
|
5
|
+
*
|
|
6
|
+
* This transforms:
|
|
7
|
+
* ```js
|
|
8
|
+
* export const QUERY = gql`...`
|
|
9
|
+
* export const Loading = () => <div>Loading...</div>
|
|
10
|
+
* export const Success = ({ data }) => <div>{data}</div>
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Into:
|
|
14
|
+
* ```js
|
|
15
|
+
* import { createCell } from '@cedarjs/web'
|
|
16
|
+
* export const QUERY = gql`...`
|
|
17
|
+
* export const Loading = () => <div>Loading...</div>
|
|
18
|
+
* export const Success = ({ data }) => <div>{data}</div>
|
|
19
|
+
* export default createCell({ QUERY, Loading, Success, displayName: 'MyCell' })
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function cellTransformPlugin(): Plugin;
|
|
23
|
+
//# sourceMappingURL=rollup-plugin-cedarjs-cell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollup-plugin-cedarjs-cell.d.ts","sourceRoot":"","sources":["../../../src/build-and-import/rollupPlugins/rollup-plugin-cedarjs-cell.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAmBpC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAmK5C"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { parse as parsePath } from "node:path";
|
|
2
|
+
import babelGenerator from "@babel/generator";
|
|
3
|
+
import { parse } from "@babel/parser";
|
|
4
|
+
import babelTraverse from "@babel/traverse";
|
|
5
|
+
const traverse = babelTraverse.default;
|
|
6
|
+
const generate = babelGenerator.default;
|
|
7
|
+
const EXPECTED_EXPORTS_FROM_CELL = [
|
|
8
|
+
"beforeQuery",
|
|
9
|
+
"QUERY",
|
|
10
|
+
"data",
|
|
11
|
+
"isEmpty",
|
|
12
|
+
"afterQuery",
|
|
13
|
+
"Loading",
|
|
14
|
+
"Success",
|
|
15
|
+
"Failure",
|
|
16
|
+
"Empty"
|
|
17
|
+
];
|
|
18
|
+
function cellTransformPlugin() {
|
|
19
|
+
return {
|
|
20
|
+
name: "cedar-cell-transform",
|
|
21
|
+
transform(code, id) {
|
|
22
|
+
if (!id.match(/Cell\.[jt]sx?$/)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const ast = parse(code, {
|
|
27
|
+
sourceType: "module",
|
|
28
|
+
plugins: [
|
|
29
|
+
"jsx",
|
|
30
|
+
"typescript",
|
|
31
|
+
"decorators-legacy",
|
|
32
|
+
"classProperties",
|
|
33
|
+
"objectRestSpread",
|
|
34
|
+
"asyncGenerators",
|
|
35
|
+
"functionBind",
|
|
36
|
+
"exportDefaultFrom",
|
|
37
|
+
"exportNamespaceFrom",
|
|
38
|
+
"dynamicImport",
|
|
39
|
+
"nullishCoalescingOperator",
|
|
40
|
+
"optionalChaining"
|
|
41
|
+
]
|
|
42
|
+
});
|
|
43
|
+
const exportNames = [];
|
|
44
|
+
let hasDefaultExport = false;
|
|
45
|
+
traverse(ast, {
|
|
46
|
+
ExportDefaultDeclaration() {
|
|
47
|
+
hasDefaultExport = true;
|
|
48
|
+
},
|
|
49
|
+
ExportNamedDeclaration(path) {
|
|
50
|
+
const declaration = path.node.declaration;
|
|
51
|
+
if (!declaration) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
let name;
|
|
55
|
+
if (declaration.type === "VariableDeclaration") {
|
|
56
|
+
const id2 = declaration.declarations[0].id;
|
|
57
|
+
name = id2.name;
|
|
58
|
+
}
|
|
59
|
+
if (declaration.type === "FunctionDeclaration") {
|
|
60
|
+
name = declaration?.id?.name;
|
|
61
|
+
}
|
|
62
|
+
if (name && EXPECTED_EXPORTS_FROM_CELL.includes(name)) {
|
|
63
|
+
exportNames.push(name);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
const hasQueryOrDataExport = exportNames.includes("QUERY") || exportNames.includes("data");
|
|
68
|
+
if (hasDefaultExport || !hasQueryOrDataExport) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const createCellHookName = exportNames.includes("data") ? "createServerCell" : "createCell";
|
|
72
|
+
const importFrom = exportNames.includes("data") ? "@cedarjs/web/dist/components/cell/createServerCell" : "@cedarjs/web";
|
|
73
|
+
traverse(ast, {
|
|
74
|
+
Program(path) {
|
|
75
|
+
const importDeclaration = {
|
|
76
|
+
type: "ImportDeclaration",
|
|
77
|
+
specifiers: [
|
|
78
|
+
{
|
|
79
|
+
type: "ImportSpecifier",
|
|
80
|
+
imported: {
|
|
81
|
+
type: "Identifier",
|
|
82
|
+
name: createCellHookName
|
|
83
|
+
},
|
|
84
|
+
local: {
|
|
85
|
+
type: "Identifier",
|
|
86
|
+
name: createCellHookName
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
],
|
|
90
|
+
source: { type: "StringLiteral", value: importFrom }
|
|
91
|
+
};
|
|
92
|
+
path.node.body.unshift(importDeclaration);
|
|
93
|
+
const objectProperties = [
|
|
94
|
+
...exportNames.map((name) => ({
|
|
95
|
+
type: "ObjectProperty",
|
|
96
|
+
key: { type: "Identifier", name },
|
|
97
|
+
value: { type: "Identifier", name },
|
|
98
|
+
shorthand: true,
|
|
99
|
+
computed: false
|
|
100
|
+
})),
|
|
101
|
+
// Add the displayName property
|
|
102
|
+
{
|
|
103
|
+
type: "ObjectProperty",
|
|
104
|
+
key: { type: "Identifier", name: "displayName" },
|
|
105
|
+
value: {
|
|
106
|
+
type: "StringLiteral",
|
|
107
|
+
value: parsePath(id).name
|
|
108
|
+
},
|
|
109
|
+
shorthand: false,
|
|
110
|
+
computed: false
|
|
111
|
+
}
|
|
112
|
+
];
|
|
113
|
+
const exportDefaultDeclaration = {
|
|
114
|
+
type: "ExportDefaultDeclaration",
|
|
115
|
+
declaration: {
|
|
116
|
+
type: "CallExpression",
|
|
117
|
+
callee: {
|
|
118
|
+
type: "Identifier",
|
|
119
|
+
name: createCellHookName
|
|
120
|
+
},
|
|
121
|
+
arguments: [
|
|
122
|
+
{
|
|
123
|
+
type: "ObjectExpression",
|
|
124
|
+
properties: objectProperties
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
path.node.body.push(exportDefaultDeclaration);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
const result = generate(ast, {
|
|
133
|
+
retainLines: true,
|
|
134
|
+
compact: false
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
code: result.code,
|
|
138
|
+
map: result.map
|
|
139
|
+
};
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.warn(`Failed to transform Cell file ${id}:`, error);
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
export {
|
|
148
|
+
cellTransformPlugin
|
|
149
|
+
};
|
package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-directory-named-imports.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollup-plugin-cedarjs-directory-named-imports.d.ts","sourceRoot":"","sources":["../../../src/build-and-import/rollupPlugins/rollup-plugin-cedarjs-directory-named-imports.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAmCpC,wBAAgB,iCAAiC,IAAI,MAAM,CA+B1D"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { resolveFile } from "@cedarjs/project-config";
|
|
4
|
+
function getNewPath(value, filename) {
|
|
5
|
+
const dirname = path.dirname(value);
|
|
6
|
+
const basename = path.basename(value);
|
|
7
|
+
const indexImportPath = [dirname, basename, "index"].join("/");
|
|
8
|
+
const resolvedFile = resolveFile(
|
|
9
|
+
path.resolve(path.dirname(filename), indexImportPath)
|
|
10
|
+
);
|
|
11
|
+
if (resolvedFile) {
|
|
12
|
+
return resolvedFile;
|
|
13
|
+
} else {
|
|
14
|
+
const dirnameImportPath = [dirname, basename, basename].join("/");
|
|
15
|
+
const dirnameResolvedFile = resolveFile(
|
|
16
|
+
path.resolve(path.dirname(filename), dirnameImportPath)
|
|
17
|
+
);
|
|
18
|
+
if (dirnameResolvedFile) {
|
|
19
|
+
return dirnameResolvedFile;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
function cedarjsDirectoryNamedImportPlugin() {
|
|
25
|
+
return {
|
|
26
|
+
name: "cedarjs-directory-named-import",
|
|
27
|
+
resolveId(id, importer) {
|
|
28
|
+
if (!importer || importer.includes("/node_modules/")) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const resolvedPath = path.resolve(path.dirname(importer), id);
|
|
32
|
+
if (fs.existsSync(resolvedPath)) {
|
|
33
|
+
const stats = fs.statSync(resolvedPath);
|
|
34
|
+
if (stats.isFile()) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const newPath = getNewPath(id, importer);
|
|
39
|
+
if (!newPath) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const resolvedDirnamePath = path.resolve(path.dirname(importer), newPath);
|
|
43
|
+
return resolvedDirnamePath;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
cedarjsDirectoryNamedImportPlugin
|
|
49
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Plugin as RollupPlugin } from 'rollup';
|
|
2
|
+
/** A rollup plugin to mark node_modules as external */
|
|
3
|
+
export declare const externalPlugin: ({ external, notExternal, filepath, externalNodeModules, }: {
|
|
4
|
+
filepath: string;
|
|
5
|
+
external?: (string | RegExp)[];
|
|
6
|
+
notExternal?: (string | RegExp)[];
|
|
7
|
+
externalNodeModules?: boolean;
|
|
8
|
+
}) => RollupPlugin;
|
|
9
|
+
//# sourceMappingURL=rollup-plugin-cedarjs-external.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollup-plugin-cedarjs-external.d.ts","sourceRoot":"","sources":["../../../src/build-and-import/rollupPlugins/rollup-plugin-cedarjs-external.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,QAAQ,CAAA;AAKpD,uDAAuD;AACvD,eAAO,MAAM,cAAc,8DAKxB;IACD,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IAC9B,WAAW,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IACjC,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAC9B,KAAG,YAmFH,CAAA"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
const PATH_NODE_MODULES_RE = /[\/\\]node_modules[\/\\]/;
|
|
4
|
+
const externalPlugin = ({
|
|
5
|
+
external,
|
|
6
|
+
notExternal,
|
|
7
|
+
filepath,
|
|
8
|
+
externalNodeModules = true
|
|
9
|
+
}) => {
|
|
10
|
+
const extNodeModules = externalNodeModules ?? !filepath.match(PATH_NODE_MODULES_RE);
|
|
11
|
+
const builtinModules = /* @__PURE__ */ new Set([
|
|
12
|
+
"assert",
|
|
13
|
+
"buffer",
|
|
14
|
+
"child_process",
|
|
15
|
+
"cluster",
|
|
16
|
+
"crypto",
|
|
17
|
+
"dgram",
|
|
18
|
+
"dns",
|
|
19
|
+
"domain",
|
|
20
|
+
"events",
|
|
21
|
+
"fs",
|
|
22
|
+
"http",
|
|
23
|
+
"https",
|
|
24
|
+
"net",
|
|
25
|
+
"os",
|
|
26
|
+
"path",
|
|
27
|
+
"punycode",
|
|
28
|
+
"querystring",
|
|
29
|
+
"readline",
|
|
30
|
+
"stream",
|
|
31
|
+
"string_decoder",
|
|
32
|
+
"tls",
|
|
33
|
+
"tty",
|
|
34
|
+
"url",
|
|
35
|
+
"util",
|
|
36
|
+
"v8",
|
|
37
|
+
"vm",
|
|
38
|
+
"zlib",
|
|
39
|
+
"constants",
|
|
40
|
+
"sys",
|
|
41
|
+
"module",
|
|
42
|
+
"process",
|
|
43
|
+
"inspector",
|
|
44
|
+
"async_hooks",
|
|
45
|
+
"http2",
|
|
46
|
+
"perf_hooks",
|
|
47
|
+
"trace_events",
|
|
48
|
+
"worker_threads",
|
|
49
|
+
"repl",
|
|
50
|
+
"timers"
|
|
51
|
+
]);
|
|
52
|
+
return {
|
|
53
|
+
name: "bundle-require:external",
|
|
54
|
+
resolveId(id, importer) {
|
|
55
|
+
if (builtinModules.has(id) || id.startsWith("node:")) {
|
|
56
|
+
return { id, external: true };
|
|
57
|
+
}
|
|
58
|
+
if (match(id, external)) {
|
|
59
|
+
return { id, external: true };
|
|
60
|
+
}
|
|
61
|
+
if (match(id, notExternal)) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
if (extNodeModules && id.match(PATH_NODE_MODULES_RE)) {
|
|
65
|
+
const resolved = id.startsWith(".") && importer ? path.resolve(path.dirname(importer), id) : id;
|
|
66
|
+
return {
|
|
67
|
+
id: pathToFileURL(resolved).toString(),
|
|
68
|
+
external: true
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (id.startsWith(".") || path.isAbsolute(id)) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
return { id, external: true };
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
function match(id, patterns) {
|
|
79
|
+
if (!patterns) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return patterns.some((p) => {
|
|
83
|
+
if (p instanceof RegExp) {
|
|
84
|
+
return p.test(id);
|
|
85
|
+
}
|
|
86
|
+
return id === p || id.startsWith(p + "/");
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
export {
|
|
90
|
+
externalPlugin
|
|
91
|
+
};
|
package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Plugin as RollupPlugin } from 'rollup';
|
|
2
|
+
/**
|
|
3
|
+
* A Rollup plugin that ignores imports of HTML and CSS files by replacing them with empty modules.
|
|
4
|
+
* This is useful when bundling code that imports these files for webpack or other bundlers,
|
|
5
|
+
* but you want Rollup to ignore them during the build process.
|
|
6
|
+
*
|
|
7
|
+
* @param options Configuration options
|
|
8
|
+
* @returns Rollup plugin
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```js
|
|
12
|
+
* import { ignoreHtmlAndCssImportsPlugin } from './rollup-plugin-ignore-html-and-css-imports'
|
|
13
|
+
*
|
|
14
|
+
* export default {
|
|
15
|
+
* plugins: [
|
|
16
|
+
* ignoreHtmlAndCssImportsPlugin({
|
|
17
|
+
* removeExtensions: ['.html', '.css', '.scss', '.sass']
|
|
18
|
+
* })
|
|
19
|
+
* ]
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const ignoreHtmlAndCssImportsPlugin: () => RollupPlugin;
|
|
24
|
+
//# sourceMappingURL=rollup-plugin-cedarjs-ignore-html-and-css-imports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollup-plugin-cedarjs-ignore-html-and-css-imports.d.ts","sourceRoot":"","sources":["../../../src/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,QAAQ,CAAA;AAEpD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,6BAA6B,QAAO,YAyBhD,CAAA"}
|
package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-ignore-html-and-css-imports.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const ignoreHtmlAndCssImportsPlugin = () => {
|
|
2
|
+
const fileTypes = [".html", ".scss", ".css"];
|
|
3
|
+
return {
|
|
4
|
+
name: "ignore-html-and-css-imports",
|
|
5
|
+
resolveId(id) {
|
|
6
|
+
if (fileTypes.some((ext) => id.endsWith(ext))) {
|
|
7
|
+
return {
|
|
8
|
+
id: `\0virtual:ignore-${id}`,
|
|
9
|
+
external: false
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
},
|
|
14
|
+
load(id) {
|
|
15
|
+
if (id.startsWith("\0virtual:ignore-")) {
|
|
16
|
+
return "export default {};";
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
ignoreHtmlAndCssImportsPlugin
|
|
24
|
+
};
|
package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-inject-file-globals.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollup-plugin-cedarjs-inject-file-globals.d.ts","sourceRoot":"","sources":["../../../src/build-and-import/rollupPlugins/rollup-plugin-cedarjs-inject-file-globals.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,QAAQ,CAAA;AAQpD,eAAO,MAAM,uBAAuB,QAAO,YA6B1C,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { JS_EXT_RE } from "../utils.js";
|
|
4
|
+
const DIRNAME_VAR_NAME = "__injected_dirname__";
|
|
5
|
+
const FILENAME_VAR_NAME = "__injected_filename__";
|
|
6
|
+
const IMPORT_META_URL_VAR_NAME = "__injected_import_meta_url__";
|
|
7
|
+
const injectFileGlobalsPlugin = () => {
|
|
8
|
+
return {
|
|
9
|
+
name: "bundle-require:inject-file-globals",
|
|
10
|
+
transform(code, id) {
|
|
11
|
+
if (!JS_EXT_RE.test(id)) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const transformedCode = code.replace(/\b__filename\b/g, FILENAME_VAR_NAME).replace(/\b__dirname\b/g, DIRNAME_VAR_NAME).replace(/\bimport\.meta\.url\b/g, IMPORT_META_URL_VAR_NAME);
|
|
15
|
+
const injectLines = [
|
|
16
|
+
`const ${FILENAME_VAR_NAME} = ${JSON.stringify(id)};`,
|
|
17
|
+
`const ${DIRNAME_VAR_NAME} = ${JSON.stringify(path.dirname(id))};`,
|
|
18
|
+
`const ${IMPORT_META_URL_VAR_NAME} = ${JSON.stringify(
|
|
19
|
+
pathToFileURL(id).href
|
|
20
|
+
)};`
|
|
21
|
+
];
|
|
22
|
+
return {
|
|
23
|
+
code: injectLines.join("\n") + "\n" + transformedCode,
|
|
24
|
+
// TODO: Generate a proper source map
|
|
25
|
+
map: { mappings: "" }
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
injectFileGlobalsPlugin
|
|
32
|
+
};
|
package/dist/build-and-import/rollupPlugins/rollup-plugin-cedarjs-prerender-media-imports.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Plugin } from 'rollup';
|
|
2
|
+
export interface PrerenderMediaImportsOptions {
|
|
3
|
+
extensions?: string[];
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* A Rollup plugin that transforms media imports during prerendering.
|
|
7
|
+
*
|
|
8
|
+
* This plugin processes imports of media files (images, fonts, etc.) and either:
|
|
9
|
+
* 1. Replaces them with the built asset path from the Vite manifest, or
|
|
10
|
+
* 2. Converts them to base64 data URLs if not found in the manifest
|
|
11
|
+
*
|
|
12
|
+
* # Example transformation
|
|
13
|
+
*
|
|
14
|
+
* ```javascript
|
|
15
|
+
* // Before
|
|
16
|
+
* import logo from './logo.png'
|
|
17
|
+
*
|
|
18
|
+
* // After (if in manifest)
|
|
19
|
+
* const logo = 'assets/logo-abc123.png'
|
|
20
|
+
*
|
|
21
|
+
* // After (if not in manifest)
|
|
22
|
+
* const logo = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...'
|
|
23
|
+
*/
|
|
24
|
+
export declare function cedarjsPrerenderMediaImportsPlugin(options?: PrerenderMediaImportsOptions): Plugin;
|
|
25
|
+
//# sourceMappingURL=rollup-plugin-cedarjs-prerender-media-imports.d.ts.map
|