goatly 0.1.0 → 0.1.1
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/README.md +853 -1
- package/bin/goatly.js +91 -0
- package/dist/cli/index.js +234 -0
- package/dist/compat/gatsby-node-entry.js +16 -0
- package/dist/compat/gatsby-package.json +6 -0
- package/dist/compat/md5-file.js +47 -0
- package/dist/compat-apis.json +72 -0
- package/dist/compat-apis.json.js +62 -0
- package/dist/graphql.js +3 -0
- package/dist/node/actions/index.js +619 -0
- package/dist/node/actions/job-store.js +180 -0
- package/dist/node/actions/jobs.js +174 -0
- package/dist/node/api-runner.js +258 -0
- package/dist/node/bootstrap.js +539 -0
- package/dist/node/build/assets.js +110 -0
- package/dist/node/build/incremental.js +208 -0
- package/dist/node/build/index.js +752 -0
- package/dist/node/build/memory-governor.js +448 -0
- package/dist/node/build/output-dirs.js +70 -0
- package/dist/node/build/page-data.js +40 -0
- package/dist/node/build/page-files.js +54 -0
- package/dist/node/build/partitioned-state.js +258 -0
- package/dist/node/build/query-worker.js +536 -0
- package/dist/node/build/query-workers.js +832 -0
- package/dist/node/build/render-worker.js +131 -0
- package/dist/node/build/state.js +24 -0
- package/dist/node/build/timing-breakdown.js +155 -0
- package/dist/node/build/worker-pool.js +236 -0
- package/dist/node/cache-layout.js +99 -0
- package/dist/node/cache.js +1430 -0
- package/dist/node/compat/chokidar-shim.js +148 -0
- package/dist/node/compat/core-utils-lmdb.js +145 -0
- package/dist/node/compat/create-node-id-shim.js +1 -0
- package/dist/node/compat/module-hooks.js +245 -0
- package/dist/node/compat/redux-shim.js +1 -0
- package/dist/node/config/index.js +162 -0
- package/dist/node/config/not-found-pages.js +95 -0
- package/dist/node/datastore/codec.js +144 -0
- package/dist/node/datastore/index.js +127 -0
- package/dist/node/datastore/logfile/cache.js +89 -0
- package/dist/node/datastore/logfile/index.js +1329 -0
- package/dist/node/datastore/logfile/record.js +71 -0
- package/dist/node/datastore/types.js +1 -0
- package/dist/node/develop/express-compat.js +207 -0
- package/dist/node/develop/graphiql.js +22 -0
- package/dist/node/develop/hydration-report.js +41 -0
- package/dist/node/develop/index.js +618 -0
- package/dist/node/develop/local-url.js +10 -0
- package/dist/node/develop/ssr-runner.js +66 -0
- package/dist/node/gql.js +5 -0
- package/dist/node/index.js +15 -0
- package/dist/node/info.js +270 -0
- package/dist/node/internal-plugins/data-bridge.js +196 -0
- package/dist/node/internal-plugins/page-creator.js +318 -0
- package/dist/node/loader/import-module.js +160 -0
- package/dist/node/node-helpers.js +66 -0
- package/dist/node/not-found-pages.js +220 -0
- package/dist/node/plugins/api-list.js +12 -0
- package/dist/node/plugins/load-plugins.js +427 -0
- package/dist/node/plugins/resolve-plugin.js +79 -0
- package/dist/node/plugins/static-exports.js +64 -0
- package/dist/node/query/compile.js +326 -0
- package/dist/node/query/dependencies.js +45 -0
- package/dist/node/query/execute.js +417 -0
- package/dist/node/query/extract.js +372 -0
- package/dist/node/query/gql-tada-introspection.js +124 -0
- package/dist/node/query/graphql-env.js +231 -0
- package/dist/node/query/graphql-runner.js +79 -0
- package/dist/node/redux/actions.js +1 -0
- package/dist/node/redux/index.js +133 -0
- package/dist/node/redux/node-changes.js +128 -0
- package/dist/node/redux/reducers.js +193 -0
- package/dist/node/redux/state.js +71 -0
- package/dist/node/renderer.js +124 -0
- package/dist/node/reporter-transports.js +259 -0
- package/dist/node/reporter.js +497 -0
- package/dist/node/schema/date.js +539 -0
- package/dist/node/schema/extensions.js +315 -0
- package/dist/node/schema/index.js +542 -0
- package/dist/node/schema/infer.js +388 -0
- package/dist/node/schema/inline-objects.js +128 -0
- package/dist/node/schema/naming.js +20 -0
- package/dist/node/schema/node-model.js +207 -0
- package/dist/node/schema/query-engine.js +1808 -0
- package/dist/node/schema/resolver-kinds.js +7 -0
- package/dist/node/schema/resolvers.js +273 -0
- package/dist/node/schema/type-builders.js +45 -0
- package/dist/node/schema/types.js +241 -0
- package/dist/node/serve.js +90 -0
- package/dist/node/site-page-nodes.js +277 -0
- package/dist/node/types.js +1 -0
- package/dist/node/utils/content-digest.js +107 -0
- package/dist/node/utils/create-node-id.js +51 -0
- package/dist/node/utils/env.js +24 -0
- package/dist/node/utils/fs-retry.js +74 -0
- package/dist/node/utils/memory-signals.js +410 -0
- package/dist/node/utils/memory.js +400 -0
- package/dist/node/utils/murmurhash.js +32 -0
- package/dist/node/utils/parser.js +33 -0
- package/dist/node/utils/partition-hash.js +19 -0
- package/dist/node/utils/paths.js +122 -0
- package/dist/node/utils/resolver.js +48 -0
- package/dist/node/utils/runtime.js +5 -0
- package/dist/node/utils/serializable.js +41 -0
- package/dist/node/utils/strings.js +41 -0
- package/dist/node/vite/config.js +289 -0
- package/dist/node/vite/paths.js +12 -0
- package/dist/node/vite/plugin-deps.js +232 -0
- package/dist/node/vite/plugin.js +281 -0
- package/dist/node/vite/react-compiler.js +362 -0
- package/dist/node/vite/source-files.js +83 -0
- package/dist/node/vite/static-image.js +136 -0
- package/dist/node/vite/styled-components.js +73 -0
- package/dist/node/vite/transforms.js +299 -0
- package/dist/node/wasm-data/host.js +406 -0
- package/dist/node/wasm-data/lower.js +406 -0
- package/dist/node/wasm-data/runner.js +79 -0
- package/dist/node/wasm-data/worker.js +95 -0
- package/dist/reporter.js +5 -0
- package/dist/runtime/api-runner.js +81 -0
- package/dist/runtime/app.js +256 -0
- package/dist/runtime/client-entry.js +4 -0
- package/dist/runtime/client.js +383 -0
- package/dist/runtime/default-html.js +31 -0
- package/dist/runtime/head-markup.js +100 -0
- package/dist/runtime/head-sync.js +101 -0
- package/dist/runtime/head-tags.js +45 -0
- package/dist/runtime/hydration-report.js +111 -0
- package/dist/runtime/index.js +12 -0
- package/dist/runtime/link.js +293 -0
- package/dist/runtime/loader.js +449 -0
- package/dist/runtime/not-found.js +61 -0
- package/dist/runtime/page-renderer.js +35 -0
- package/dist/runtime/preamble.js +47 -0
- package/dist/runtime/react-compat.js +14 -0
- package/dist/runtime/renderer-shared.js +10 -0
- package/dist/runtime/renderers/react-client.js +14 -0
- package/dist/runtime/renderers/react-server.js +99 -0
- package/dist/runtime/renderers/react.js +17 -0
- package/dist/runtime/renderers/types.js +1 -0
- package/dist/runtime/root-error-handlers.js +29 -0
- package/dist/runtime/router/history.js +132 -0
- package/dist/runtime/router/index.js +240 -0
- package/dist/runtime/router/utils.js +118 -0
- package/dist/runtime/script.js +110 -0
- package/dist/runtime/scroll.js +40 -0
- package/dist/runtime/slice.js +11 -0
- package/dist/runtime/ssr.js +240 -0
- package/dist/runtime/static-query.js +47 -0
- package/dist/utils.js +4 -0
- package/package.json +105 -3
- package/types/graphql-tada.d.ts +223 -0
- package/types/graphql.d.ts +2 -0
- package/types/index.d.ts +2287 -0
- package/types/node.d.ts +380 -0
- package/types/reporter.d.ts +187 -0
- package/types/router.d.ts +102 -0
- package/types/vendor/gql-tada.d.ts +2529 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { store } from "../redux/index.js";
|
|
2
|
+
import { resolveApiFile } from "../loader/import-module.js";
|
|
3
|
+
import { getStaticExports, isCommonJsSource } from "../plugins/static-exports.js";
|
|
4
|
+
import { pick, rankRoutes } from "../../runtime/router/utils.js";
|
|
5
|
+
import { slash } from "../utils/paths.js";
|
|
6
|
+
import { transformCjsImportsInEsm, transformCommonJsApiFile, transformGraphQLTags, transformHtmlBodyJsx, transformRequireInEsm } from "./transforms.js";
|
|
7
|
+
import { runtimeDir } from "./paths.js";
|
|
8
|
+
import { getRenderer } from "../renderer.js";
|
|
9
|
+
import { isSourceFile, nodeModulesPluginDirs } from "./source-files.js";
|
|
10
|
+
import { notFoundPagePaths, runtimeNotFoundPages } from "../not-found-pages.js";
|
|
11
|
+
import { getDataStore } from "../datastore/index.js";
|
|
12
|
+
import { warnIfPageQueryIsIgnored } from "../query/compile.js";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
import fs from "node:fs";
|
|
15
|
+
import { transformWithOxc } from "vite";
|
|
16
|
+
// src/node/vite/plugin.ts
|
|
17
|
+
const VIRTUAL = {
|
|
18
|
+
asyncRequires: "virtual:goatly/async-requires",
|
|
19
|
+
browserPlugins: "virtual:goatly/browser-plugins",
|
|
20
|
+
ssrPlugins: "virtual:goatly/ssr-plugins",
|
|
21
|
+
html: "virtual:goatly/html",
|
|
22
|
+
matchPaths: "virtual:goatly/match-paths",
|
|
23
|
+
notFoundPages: "virtual:goatly/not-found-pages",
|
|
24
|
+
redirects: "virtual:goatly/redirects",
|
|
25
|
+
runtimeConfig: "virtual:goatly/runtime-config",
|
|
26
|
+
staticQueryPrefix: "virtual:goatly/static-query/",
|
|
27
|
+
renderer: "virtual:goatly/renderer",
|
|
28
|
+
rendererServer: "virtual:goatly/renderer-server",
|
|
29
|
+
rendererClient: "virtual:goatly/renderer-client"
|
|
30
|
+
};
|
|
31
|
+
function serializeOptions(options) {
|
|
32
|
+
return JSON.stringify(options ?? {}, (key, value) => {
|
|
33
|
+
if (typeof value === "function") return void 0;
|
|
34
|
+
if (value instanceof RegExp) return value.toString();
|
|
35
|
+
if (value && typeof value === "object" && "module" in value && "resolve" in value && "pluginOptions" in value) {
|
|
36
|
+
const { module: _m, gatsbyNodeModule: _g, ...rest } = value;
|
|
37
|
+
return rest;
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function getPageComponents() {
|
|
43
|
+
const map = /* @__PURE__ */ new Map();
|
|
44
|
+
for (const component of store.getState().components.values()) map.set(component.componentChunkName, component.componentPath);
|
|
45
|
+
return map;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Ranked match paths, plus static pages that would otherwise be shadowed by a matchPath. (Not those
|
|
49
|
+
* of sections' 404 pages: unknown URLs of a section get its 404 page anyway, with status 404.)
|
|
50
|
+
*/
|
|
51
|
+
function computeMatchPaths() {
|
|
52
|
+
const pages = [...store.getState().pages.values()];
|
|
53
|
+
const notFound = notFoundPagePaths();
|
|
54
|
+
const withMatch = pages.filter((p) => p.matchPath && !notFound.has(p.path));
|
|
55
|
+
if (withMatch.length === 0) return [];
|
|
56
|
+
const routes = withMatch.map((p) => ({
|
|
57
|
+
path: p.matchPath,
|
|
58
|
+
page: p.path
|
|
59
|
+
}));
|
|
60
|
+
const shadowed = pages.filter((p) => !p.matchPath && pick(routes, p.path)).map((p) => ({
|
|
61
|
+
path: p.path.replace(/\/$/, "") || "/",
|
|
62
|
+
page: p.path
|
|
63
|
+
}));
|
|
64
|
+
return rankRoutes([...shadowed, ...routes]).map((r) => ({
|
|
65
|
+
path: r.page,
|
|
66
|
+
matchPath: r.path
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
function pluginEntries(kind) {
|
|
70
|
+
return store.getState().flattenedPlugins.map((p) => ({
|
|
71
|
+
plugin: p,
|
|
72
|
+
file: kind === "browser" ? p.gatsbyBrowserPath : p.gatsbySSRPath
|
|
73
|
+
})).filter((e) => !!e.file);
|
|
74
|
+
}
|
|
75
|
+
/** (roughly) whether a .js file contains JSX */
|
|
76
|
+
const JSX_RE = /<\/?[A-Za-z]|<>/;
|
|
77
|
+
/**
|
|
78
|
+
* For Vite's dependency scanner (`optimizeDeps.rolldownOptions.plugins`): compiles JSX in the `.js`
|
|
79
|
+
* files that the goatly plugin compiles too (site sources, themes, npm plugins). Otherwise the
|
|
80
|
+
* scan fails on them, Vite skips pre-bundling and reloads the page once it found the dependencies.
|
|
81
|
+
*/
|
|
82
|
+
function scanJsxInJsPlugin(jsx) {
|
|
83
|
+
const pluginDirs = nodeModulesPluginDirs();
|
|
84
|
+
return {
|
|
85
|
+
name: "goatly:scan-jsx-in-js",
|
|
86
|
+
transform: {
|
|
87
|
+
filter: { id: /\.(m|c)?js$/ },
|
|
88
|
+
async handler(code, id) {
|
|
89
|
+
const file = slash(id);
|
|
90
|
+
if (!isSourceFile(file, pluginDirs) || !JSX_RE.test(code)) return null;
|
|
91
|
+
try {
|
|
92
|
+
return { code: (await transformWithOxc(code, file, {
|
|
93
|
+
lang: "jsx",
|
|
94
|
+
jsx: {
|
|
95
|
+
runtime: jsx.jsxRuntime === "classic" ? "classic" : "automatic",
|
|
96
|
+
importSource: jsx.jsxImportSource
|
|
97
|
+
}
|
|
98
|
+
})).code };
|
|
99
|
+
} catch {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** per resolved file: what the dev server converts it to, when it is a CommonJS module */
|
|
107
|
+
const cjsExportsCache = /* @__PURE__ */ new Map();
|
|
108
|
+
/** `exports.__esModule = true` / `Object.defineProperty(exports, "__esModule", …)` (Babel, tsc) */
|
|
109
|
+
const ES_MODULE_FLAG_RE = /\b(?:module\.)?exports\.__esModule\s*=|\bObject\.defineProperty\(\s*(?:module\.)?exports\s*,\s*["']__esModule["']/;
|
|
110
|
+
/**
|
|
111
|
+
* The CommonJS module that `spec` (imported by `importer`) resolves to, when the dev server serves
|
|
112
|
+
* it converted to ESM: its static export names and whether it was compiled from ESM. `null` for ES
|
|
113
|
+
* modules, pre-bundled dependencies (Vite's own interop applies to them), virtual modules and
|
|
114
|
+
* specifiers that don't resolve.
|
|
115
|
+
*/
|
|
116
|
+
async function cjsExportsOf(plugin, spec, importer) {
|
|
117
|
+
const resolved = await plugin.resolve(spec, importer, { skipSelf: true });
|
|
118
|
+
if (!resolved || resolved.external || resolved.id.startsWith("\0")) return null;
|
|
119
|
+
const file = resolved.id.split("?")[0];
|
|
120
|
+
if (!/\.(c?js)$/.test(file) || file.includes("/.vite/") || file.includes("/.cache/vite/")) return null;
|
|
121
|
+
let exports = cjsExportsCache.get(file);
|
|
122
|
+
if (exports === void 0) {
|
|
123
|
+
let code;
|
|
124
|
+
try {
|
|
125
|
+
code = fs.readFileSync(file, "utf8");
|
|
126
|
+
} catch {}
|
|
127
|
+
exports = code !== void 0 && isCommonJsSource(code) ? {
|
|
128
|
+
names: getStaticExports(file, code).filter((n) => /^[A-Za-z_$][\w$]*$/.test(n) && n !== "default" && n !== "__esModule"),
|
|
129
|
+
esModule: ES_MODULE_FLAG_RE.test(code)
|
|
130
|
+
} : null;
|
|
131
|
+
cjsExportsCache.set(file, exports);
|
|
132
|
+
}
|
|
133
|
+
return exports;
|
|
134
|
+
}
|
|
135
|
+
function goatlyVitePlugin(ctx) {
|
|
136
|
+
const program = () => store.getState().program;
|
|
137
|
+
const headTagsModule = slash(path.join(runtimeDir, "head-tags.js"));
|
|
138
|
+
const pluginDirs = nodeModulesPluginDirs();
|
|
139
|
+
const isUserFile = (file) => isSourceFile(file, pluginDirs);
|
|
140
|
+
const apiFilePattern = /\/gatsby-(browser|ssr)\.(js|jsx|cjs|mjs)$/;
|
|
141
|
+
let isServe = false;
|
|
142
|
+
return {
|
|
143
|
+
name: "goatly",
|
|
144
|
+
enforce: "pre",
|
|
145
|
+
api: {
|
|
146
|
+
apiVersion: 1,
|
|
147
|
+
getDataStore
|
|
148
|
+
},
|
|
149
|
+
configResolved(config) {
|
|
150
|
+
isServe = config.command === "serve";
|
|
151
|
+
},
|
|
152
|
+
resolveId(id) {
|
|
153
|
+
if (id === VIRTUAL.renderer) return slash(getRenderer().runtime.shared);
|
|
154
|
+
if (id === VIRTUAL.rendererServer) return slash(getRenderer().runtime.server);
|
|
155
|
+
if (id === VIRTUAL.rendererClient) return slash(getRenderer().runtime.client);
|
|
156
|
+
if (id.startsWith("virtual:goatly/")) return `\0${id}`;
|
|
157
|
+
return null;
|
|
158
|
+
},
|
|
159
|
+
load(id) {
|
|
160
|
+
if (!id.startsWith("\0virtual:goatly/")) return null;
|
|
161
|
+
const name = id.slice(1);
|
|
162
|
+
const state = store.getState();
|
|
163
|
+
if (name === VIRTUAL.asyncRequires) return `export const components = {\n${[...getPageComponents()].map(([chunk, file]) => ` ${JSON.stringify(chunk)}: () => import(${JSON.stringify(file)}),`).join("\n")}\n}\n`;
|
|
164
|
+
if (name === VIRTUAL.browserPlugins || name === VIRTUAL.ssrPlugins) {
|
|
165
|
+
const entries = pluginEntries(name === VIRTUAL.browserPlugins ? "browser" : "ssr");
|
|
166
|
+
const imports = entries.map((e, i) => `import * as p${i} from ${JSON.stringify(slash(e.file))};`);
|
|
167
|
+
const list = entries.map((e, i) => ` { name: ${JSON.stringify(e.plugin.name)}, plugin: p${i}, options: ${serializeOptions(e.plugin.pluginOptions)} },`);
|
|
168
|
+
return `${imports.join("\n")}\nexport default [\n${list.join("\n")}\n]\n`;
|
|
169
|
+
}
|
|
170
|
+
if (name === VIRTUAL.html) {
|
|
171
|
+
const file = resolveApiFile(path.join(program().directory, "src"), "html") ?? path.join(runtimeDir, "default-html.js");
|
|
172
|
+
return `export { default } from ${JSON.stringify(slash(file))}\n`;
|
|
173
|
+
}
|
|
174
|
+
if (name === VIRTUAL.matchPaths) return `export default ${JSON.stringify(computeMatchPaths())}\n`;
|
|
175
|
+
if (name === VIRTUAL.notFoundPages) return `export default ${JSON.stringify(runtimeNotFoundPages())}\n`;
|
|
176
|
+
if (name === VIRTUAL.redirects) return `export default ${JSON.stringify(state.redirects.filter((r) => r.redirectInBrowser))}\n`;
|
|
177
|
+
if (name === VIRTUAL.runtimeConfig) return `export default ${JSON.stringify({
|
|
178
|
+
buildHash: ctx.buildHash,
|
|
179
|
+
dev: ctx.command === "develop",
|
|
180
|
+
devSSR: ctx.devSSR
|
|
181
|
+
})}\n`;
|
|
182
|
+
if (name.startsWith(VIRTUAL.staticQueryPrefix)) {
|
|
183
|
+
const hash = name.slice(VIRTUAL.staticQueryPrefix.length);
|
|
184
|
+
const data = ctx.getStaticQueryResult(hash);
|
|
185
|
+
return `export default { hash: ${JSON.stringify(hash)}, data: ${JSON.stringify(data ?? null)} }\n`;
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
},
|
|
189
|
+
transform: {
|
|
190
|
+
filter: { id: /\.(m|c)?[jt]sx?(\?.*)?$/ },
|
|
191
|
+
async handler(code, id) {
|
|
192
|
+
if (id.startsWith("\0")) return null;
|
|
193
|
+
const file = id.split("?")[0];
|
|
194
|
+
let result = null;
|
|
195
|
+
if (isServe && !file.includes("/.vite/") && !file.includes("/.cache/vite/") && isCommonJsSource(code)) {
|
|
196
|
+
const converted = transformCommonJsApiFile(code, file);
|
|
197
|
+
if (converted != null) {
|
|
198
|
+
code = converted;
|
|
199
|
+
result = { code };
|
|
200
|
+
}
|
|
201
|
+
} else if (isServe && (isUserFile(file) || apiFilePattern.test(file)) && !file.includes("/.vite/") && !file.includes("/.cache/vite/")) {
|
|
202
|
+
const r = transformRequireInEsm(code, id);
|
|
203
|
+
if (r) {
|
|
204
|
+
code = r.code;
|
|
205
|
+
result = r;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (isServe && result === null && file.includes("/node_modules/") && !file.includes("/.vite/") && !file.includes("/.cache/vite/")) {
|
|
209
|
+
const r = await transformCjsImportsInEsm(code, id, (spec) => cjsExportsOf(this, spec, id));
|
|
210
|
+
if (r) {
|
|
211
|
+
code = r.code;
|
|
212
|
+
result = r;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (code.includes("graphql")) {
|
|
216
|
+
const r = transformGraphQLTags(code, id, { virtualPrefix: VIRTUAL.staticQueryPrefix });
|
|
217
|
+
if (r) {
|
|
218
|
+
if (r.exportsPageQuery && isUserFile(file)) warnIfPageQueryIsIgnored(file);
|
|
219
|
+
code = r.code;
|
|
220
|
+
result = {
|
|
221
|
+
code: r.code,
|
|
222
|
+
map: r.map
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (isUserFile(file) && !/\/src\/html\.[jt]sx?$/.test(file) && (code.includes("<html") || code.includes("<body"))) {
|
|
227
|
+
const r = transformHtmlBodyJsx(code, id, headTagsModule);
|
|
228
|
+
if (r) {
|
|
229
|
+
code = r.code;
|
|
230
|
+
result = r;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (ctx.reactCompiler && isUserFile(file) && !file.includes("/.vite/") && !file.includes("/.cache/vite/") && !ctx.precompiledDirs?.some((re) => re.test(file))) {
|
|
234
|
+
const isServer = this.environment?.config?.consumer === "server";
|
|
235
|
+
let r;
|
|
236
|
+
try {
|
|
237
|
+
r = ctx.reactCompiler(code, file, isServer);
|
|
238
|
+
} catch (e) {
|
|
239
|
+
this.error(e);
|
|
240
|
+
}
|
|
241
|
+
if (r) {
|
|
242
|
+
code = r.code;
|
|
243
|
+
result = r;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (/\.(m|c)?js$/.test(file) && isUserFile(file) && JSX_RE.test(code)) {
|
|
247
|
+
const isClient = this.environment?.config?.consumer !== "server";
|
|
248
|
+
const out = await transformWithOxc(code, file, {
|
|
249
|
+
lang: "jsx",
|
|
250
|
+
sourcemap: true,
|
|
251
|
+
jsx: {
|
|
252
|
+
runtime: ctx.jsxRuntime === "classic" ? "classic" : "automatic",
|
|
253
|
+
importSource: ctx.jsxImportSource,
|
|
254
|
+
development: isServe,
|
|
255
|
+
refresh: isServe && isClient ? {} : void 0
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
result = {
|
|
259
|
+
code: out.code,
|
|
260
|
+
map: out.map
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
return result;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
/** Re-sends a static query module to the browser after its data changed (develop). */
|
|
269
|
+
async function invalidateVirtualModule(server, name) {
|
|
270
|
+
for (const env of Object.values(server.environments)) {
|
|
271
|
+
const mod = env.moduleGraph.getModuleById(`\0${name}`);
|
|
272
|
+
if (mod) {
|
|
273
|
+
env.moduleGraph.invalidateModule(mod);
|
|
274
|
+
if (env.name === "client") await env.reloadModule(mod);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function fileExists(p) {
|
|
279
|
+
return fs.existsSync(p);
|
|
280
|
+
}
|
|
281
|
+
export { VIRTUAL, computeMatchPaths, fileExists, getPageComponents, goatlyVitePlugin, invalidateVirtualModule, scanJsxInJsPlugin };
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { store } from "../redux/index.js";
|
|
2
|
+
import reporter from "../reporter.js";
|
|
3
|
+
import { importModule } from "../loader/import-module.js";
|
|
4
|
+
import { findInstalledPackage } from "../info.js";
|
|
5
|
+
import { slash } from "../utils/paths.js";
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import { pathToFileURL } from "node:url";
|
|
10
|
+
// src/node/vite/react-compiler.ts
|
|
11
|
+
/**
|
|
12
|
+
* React Compiler without Babel: the `reactCompiler` option of gatsby-config, or
|
|
13
|
+
* `babel-plugin-react-compiler` in the site's Babel config (`.babelrc`, `babel.config.*`) or
|
|
14
|
+
* registered with `setBabelPlugin`, runs Oxc's Rust port of React Compiler (the optional peer
|
|
15
|
+
* dependency `oxc-transform-react`) on the site's sources, before their JSX is compiled.
|
|
16
|
+
*/
|
|
17
|
+
const BABEL_PLUGIN_RE = /(^|[\\/])babel-plugin-react-compiler([\\/]|$)/;
|
|
18
|
+
const BABEL_PLUGIN_NAMES = /* @__PURE__ */ new Set(["babel-plugin-react-compiler", "react-compiler"]);
|
|
19
|
+
const OPTION_KEYS = [
|
|
20
|
+
"compilationMode",
|
|
21
|
+
"panicThreshold",
|
|
22
|
+
"target",
|
|
23
|
+
"gating",
|
|
24
|
+
"dynamicGating",
|
|
25
|
+
"outputMode",
|
|
26
|
+
"reportDiagnostics",
|
|
27
|
+
"eslintSuppressionRules",
|
|
28
|
+
"flowSuppressions",
|
|
29
|
+
"ignoreUseNoForget",
|
|
30
|
+
"customOptOutDirectives",
|
|
31
|
+
"sources",
|
|
32
|
+
"environment"
|
|
33
|
+
];
|
|
34
|
+
const ENUMS = {
|
|
35
|
+
compilationMode: [
|
|
36
|
+
"infer",
|
|
37
|
+
"syntax",
|
|
38
|
+
"annotation",
|
|
39
|
+
"all"
|
|
40
|
+
],
|
|
41
|
+
panicThreshold: [
|
|
42
|
+
"none",
|
|
43
|
+
"critical_errors",
|
|
44
|
+
"all_errors"
|
|
45
|
+
],
|
|
46
|
+
target: [
|
|
47
|
+
"17",
|
|
48
|
+
"18",
|
|
49
|
+
"19"
|
|
50
|
+
],
|
|
51
|
+
outputMode: [
|
|
52
|
+
"client",
|
|
53
|
+
"ssr",
|
|
54
|
+
"lint"
|
|
55
|
+
]
|
|
56
|
+
};
|
|
57
|
+
const isPlainObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
58
|
+
const isStringArray = (v) => Array.isArray(v) && v.every((s) => typeof s === "string");
|
|
59
|
+
/** Problems of a `reactCompiler` option in gatsby-config (empty when it is valid). */
|
|
60
|
+
function validateReactCompilerConfig(value) {
|
|
61
|
+
if (value === void 0 || typeof value === "boolean") return [];
|
|
62
|
+
if (!isPlainObject(value)) return [`"reactCompiler" must be true, false or an object of React Compiler options`];
|
|
63
|
+
const problems = [];
|
|
64
|
+
for (const [key, allowed] of Object.entries(ENUMS)) {
|
|
65
|
+
const v = value[key];
|
|
66
|
+
if (v !== void 0 && !allowed.includes(String(v))) problems.push(`"reactCompiler.${key}" must be one of ${allowed.map((a) => `"${a}"`).join(", ")}, got ${JSON.stringify(v)}`);
|
|
67
|
+
}
|
|
68
|
+
for (const key of ["eslintSuppressionRules", "customOptOutDirectives"]) if (value[key] !== void 0 && !isStringArray(value[key])) problems.push(`"reactCompiler.${key}" must be an array of strings`);
|
|
69
|
+
if (value.sources !== void 0 && typeof value.sources !== "function" && !isStringArray(value.sources)) problems.push(`"reactCompiler.sources" must be an array of strings or a function`);
|
|
70
|
+
for (const key of [
|
|
71
|
+
"gating",
|
|
72
|
+
"dynamicGating",
|
|
73
|
+
"environment"
|
|
74
|
+
]) if (value[key] !== void 0 && !isPlainObject(value[key])) problems.push(`"reactCompiler.${key}" must be an object`);
|
|
75
|
+
if (isPlainObject(value.gating) && (typeof value.gating.source !== "string" || typeof value.gating.importSpecifierName !== "string")) problems.push(`"reactCompiler.gating" needs a "source" and an "importSpecifierName"`);
|
|
76
|
+
if (isPlainObject(value.dynamicGating) && typeof value.dynamicGating.source !== "string") problems.push(`"reactCompiler.dynamicGating" needs a "source"`);
|
|
77
|
+
return problems;
|
|
78
|
+
}
|
|
79
|
+
/** Option keys of a `reactCompiler` object that are not React Compiler options of Oxc. */
|
|
80
|
+
function unknownReactCompilerKeys(value) {
|
|
81
|
+
if (!isPlainObject(value)) return [];
|
|
82
|
+
return Object.keys(value).filter((k) => !OPTION_KEYS.includes(k));
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Maps the options of `babel-plugin-react-compiler` to the `reactCompiler` option. Options Oxc's
|
|
86
|
+
* port has no equivalent for (e.g. `logger`, function-valued environment settings) are returned in
|
|
87
|
+
* `ignored`. `noEmit: true` becomes `outputMode: "lint"`.
|
|
88
|
+
*/
|
|
89
|
+
function fromBabelPluginOptions(babel = {}) {
|
|
90
|
+
const config = {};
|
|
91
|
+
const ignored = [];
|
|
92
|
+
for (const [key, value] of Object.entries(babel)) {
|
|
93
|
+
if (value === void 0 || value === null) continue;
|
|
94
|
+
if (key === "noEmit") {
|
|
95
|
+
if (value === true && babel.outputMode === void 0) config.outputMode = "lint";
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (key === "environment" && isPlainObject(value)) {
|
|
99
|
+
const env = {};
|
|
100
|
+
for (const [k, v] of Object.entries(value)) if (typeof v === "function") ignored.push(`environment.${k}`);
|
|
101
|
+
else env[k] = v;
|
|
102
|
+
config.environment = env;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (!OPTION_KEYS.includes(key)) {
|
|
106
|
+
ignored.push(key);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
config[key] = value;
|
|
110
|
+
}
|
|
111
|
+
if (typeof config.target === "number") config.target = String(config.target);
|
|
112
|
+
return {
|
|
113
|
+
config,
|
|
114
|
+
ignored
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/** `[name, options]` of a Babel plugin entry, when it is babel-plugin-react-compiler */
|
|
118
|
+
function matchBabelEntry(entry) {
|
|
119
|
+
const [name, options] = Array.isArray(entry) ? entry : [entry, void 0];
|
|
120
|
+
if (typeof name !== "string") return null;
|
|
121
|
+
if (!BABEL_PLUGIN_NAMES.has(name) && !BABEL_PLUGIN_RE.test(name)) return null;
|
|
122
|
+
return isPlainObject(options) ? options : {};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Options of `babel-plugin-react-compiler` registered via `setBabelPlugin` for `stage` (merged in
|
|
126
|
+
* order); without one for `stage`, another stage's apply (as for styled-components).
|
|
127
|
+
*/
|
|
128
|
+
function findReactCompilerBabelRegistration(stage) {
|
|
129
|
+
const stages = store.getState().babelrc.stages;
|
|
130
|
+
const candidates = [stage, ...Object.keys(stages).filter((s) => s !== stage)];
|
|
131
|
+
for (const s of candidates) {
|
|
132
|
+
const matches = (stages[s]?.plugins ?? []).filter((p) => typeof p?.name === "string" && BABEL_PLUGIN_RE.test(p.name));
|
|
133
|
+
if (matches.length) return Object.assign({}, ...matches.map((p) => p.options ?? {}));
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
/** Babel's config files, in the order Babel looks for them in the site's root */
|
|
138
|
+
const BABEL_CONFIG_FILES = [
|
|
139
|
+
"babel.config.js",
|
|
140
|
+
"babel.config.cjs",
|
|
141
|
+
"babel.config.mjs",
|
|
142
|
+
"babel.config.json",
|
|
143
|
+
".babelrc",
|
|
144
|
+
".babelrc.js",
|
|
145
|
+
".babelrc.cjs",
|
|
146
|
+
".babelrc.mjs",
|
|
147
|
+
".babelrc.json"
|
|
148
|
+
];
|
|
149
|
+
/** a stand-in for Babel's config API, for function configs (`module.exports = (api) => ...`) */
|
|
150
|
+
function babelApiStub(envName) {
|
|
151
|
+
const cache = () => void 0;
|
|
152
|
+
cache.forever = cache.never = () => void 0;
|
|
153
|
+
cache.using = (fn) => fn();
|
|
154
|
+
cache.invalidate = (fn) => fn();
|
|
155
|
+
return {
|
|
156
|
+
version: "7.0.0",
|
|
157
|
+
cache,
|
|
158
|
+
env: (match) => match === void 0 ? envName : typeof match === "function" ? match(envName) : [].concat(match).includes(envName),
|
|
159
|
+
caller: () => void 0,
|
|
160
|
+
assertVersion: () => void 0
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/** plugins of a Babel config object, including those of `env[envName]` */
|
|
164
|
+
function babelConfigPlugins(config, envName) {
|
|
165
|
+
if (!isPlainObject(config)) return [];
|
|
166
|
+
const plugins = Array.isArray(config.plugins) ? config.plugins : [];
|
|
167
|
+
const envPlugins = config.env?.[envName]?.plugins;
|
|
168
|
+
return Array.isArray(envPlugins) ? [...plugins, ...envPlugins] : plugins;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Options of `babel-plugin-react-compiler` in the site's Babel config file (Gatsby uses the site's
|
|
172
|
+
* `.babelrc` or `babel.config.*`), or null without one. Top-level `plugins` and those of
|
|
173
|
+
* `env.development`/`env.production` count; `overrides` are not read.
|
|
174
|
+
*/
|
|
175
|
+
async function findReactCompilerInBabelConfig(directory, stage) {
|
|
176
|
+
const envName = process.env.BABEL_ENV || (stage.startsWith("build") ? "production" : "development");
|
|
177
|
+
for (const name of BABEL_CONFIG_FILES) {
|
|
178
|
+
const file = path.join(directory, name);
|
|
179
|
+
if (!fs.existsSync(file)) continue;
|
|
180
|
+
let config;
|
|
181
|
+
try {
|
|
182
|
+
if (name === ".babelrc" || name.endsWith(".json")) config = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
183
|
+
else {
|
|
184
|
+
const mod = await importModule(file);
|
|
185
|
+
config = mod?.default ?? mod;
|
|
186
|
+
if (typeof config === "function") config = await config(babelApiStub(envName));
|
|
187
|
+
}
|
|
188
|
+
} catch (e) {
|
|
189
|
+
reporter.verbose(`React Compiler: could not read "${file}": ${e.message}`);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
for (const entry of babelConfigPlugins(config, envName)) {
|
|
193
|
+
const options = matchBabelEntry(entry);
|
|
194
|
+
if (options) return {
|
|
195
|
+
file,
|
|
196
|
+
options
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* The React version React Compiler targets: the installed `react` (17, 18 or 19+), or 19 with
|
|
204
|
+
* another renderer (Redact provides `react/compiler-runtime`).
|
|
205
|
+
*/
|
|
206
|
+
function detectReactCompilerTarget(directory, rendererName) {
|
|
207
|
+
if (rendererName !== "react") return "19";
|
|
208
|
+
const version = findInstalledPackage(directory, "react")?.version;
|
|
209
|
+
if (!version) return "19";
|
|
210
|
+
const major = Number.parseInt(version ?? "", 10);
|
|
211
|
+
if (major <= 17) return "17";
|
|
212
|
+
if (major === 18) return "18";
|
|
213
|
+
return "19";
|
|
214
|
+
}
|
|
215
|
+
/** Normalizes the effective options (gatsby-config or Babel) into what the transform uses. */
|
|
216
|
+
function resolveReactCompilerOptions(config, ctx) {
|
|
217
|
+
const c = config === true ? {} : config;
|
|
218
|
+
const outputMode = c.outputMode ?? "client";
|
|
219
|
+
const { sources, reportDiagnostics } = c;
|
|
220
|
+
const rest = {};
|
|
221
|
+
for (const key of OPTION_KEYS) if (![
|
|
222
|
+
"sources",
|
|
223
|
+
"reportDiagnostics",
|
|
224
|
+
"outputMode"
|
|
225
|
+
].includes(key) && c[key] !== void 0) rest[key] = c[key];
|
|
226
|
+
return {
|
|
227
|
+
options: {
|
|
228
|
+
...rest,
|
|
229
|
+
target: c.target ?? ctx.target,
|
|
230
|
+
...Array.isArray(sources) ? { sources } : typeof sources === "function" ? { sources: [""] } : {}
|
|
231
|
+
},
|
|
232
|
+
outputMode,
|
|
233
|
+
reportDiagnostics: reportDiagnostics ?? outputMode === "lint",
|
|
234
|
+
sourcesFilter: typeof sources === "function" ? sources : void 0,
|
|
235
|
+
source: ctx.source
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
let loaded;
|
|
239
|
+
/** Loads `oxc-transform-react` from goatly's dependencies or the site's. */
|
|
240
|
+
function loadOxcTransformReact(directory) {
|
|
241
|
+
return loaded ??= (async () => {
|
|
242
|
+
for (const base of [import.meta.url, path.join(directory, "package.json")]) {
|
|
243
|
+
let resolved;
|
|
244
|
+
try {
|
|
245
|
+
resolved = createRequire(base).resolve("oxc-transform-react");
|
|
246
|
+
} catch {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
return import(pathToFileURL(resolved).href);
|
|
250
|
+
}
|
|
251
|
+
loaded = void 0;
|
|
252
|
+
throw new Error("oxc-transform-react is not installed");
|
|
253
|
+
})();
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Whether `react-compiler-runtime` (needed with React 17/18) is installed for the site: looked up in
|
|
257
|
+
* node_modules like Vite resolves the site's imports (not NODE_PATH).
|
|
258
|
+
*/
|
|
259
|
+
function hasCompilerRuntimePackage(directory) {
|
|
260
|
+
return !!findInstalledPackage(directory, "react-compiler-runtime");
|
|
261
|
+
}
|
|
262
|
+
let announced = false;
|
|
263
|
+
/**
|
|
264
|
+
* The React Compiler setup for `stage`: from the `reactCompiler` option of gatsby-config, else
|
|
265
|
+
* from `babel-plugin-react-compiler` in Babel's config (`setBabelPlugin`, `.babelrc`,
|
|
266
|
+
* `babel.config.*`). Null when React Compiler is off. Panics when `oxc-transform-react` (or, for
|
|
267
|
+
* React 17/18, `react-compiler-runtime`) is missing.
|
|
268
|
+
*/
|
|
269
|
+
async function resolveReactCompiler(stage, rendererName) {
|
|
270
|
+
const { config, program } = store.getState();
|
|
271
|
+
const directory = program.directory;
|
|
272
|
+
let effective = null;
|
|
273
|
+
let source = "gatsby-config";
|
|
274
|
+
if (config.reactCompiler !== void 0) {
|
|
275
|
+
if (config.reactCompiler === false) return null;
|
|
276
|
+
effective = config.reactCompiler;
|
|
277
|
+
} else {
|
|
278
|
+
const registered = findReactCompilerBabelRegistration(stage);
|
|
279
|
+
const fromFile = registered ? null : await findReactCompilerInBabelConfig(directory, stage);
|
|
280
|
+
const babelOptions = registered ?? fromFile?.options;
|
|
281
|
+
if (!babelOptions) return null;
|
|
282
|
+
source = registered ? "setBabelPlugin" : path.basename(fromFile.file);
|
|
283
|
+
const { config: mapped, ignored } = fromBabelPluginOptions(babelOptions);
|
|
284
|
+
const problems = validateReactCompilerConfig(mapped);
|
|
285
|
+
if (problems.length) reporter.panic(`Invalid babel-plugin-react-compiler options (${source}):\n- ${problems.join("\n- ")}`);
|
|
286
|
+
if (ignored.length && !announced) reporter.warn(`React Compiler: the babel-plugin-react-compiler options ${ignored.map((k) => `"${k}"`).join(", ")} (${source}) have no equivalent in Oxc's React Compiler and are ignored.`);
|
|
287
|
+
effective = mapped;
|
|
288
|
+
}
|
|
289
|
+
const target = detectReactCompilerTarget(directory, rendererName);
|
|
290
|
+
const resolved = resolveReactCompilerOptions(effective, {
|
|
291
|
+
stage,
|
|
292
|
+
target,
|
|
293
|
+
source
|
|
294
|
+
});
|
|
295
|
+
try {
|
|
296
|
+
await loadOxcTransformReact(directory);
|
|
297
|
+
} catch {
|
|
298
|
+
reporter.panic(`React Compiler is enabled (${source}), and goatly runs it with Oxc's port instead of Babel: install the "oxc-transform-react" package (e.g. npm install -D oxc-transform-react).`);
|
|
299
|
+
}
|
|
300
|
+
const effectiveTarget = resolved.options.target;
|
|
301
|
+
if (resolved.outputMode !== "lint" && (effectiveTarget === "17" || effectiveTarget === "18") && !hasCompilerRuntimePackage(directory)) reporter.panic(`React Compiler targets React ${effectiveTarget}, whose compiled components import "react-compiler-runtime": install it (e.g. npm install react-compiler-runtime).`);
|
|
302
|
+
if (!announced) {
|
|
303
|
+
announced = true;
|
|
304
|
+
reporter.info(`React Compiler (Oxc, experimental) is on (${source}): target React ${effectiveTarget}, ${resolved.outputMode === "lint" ? "lint only (the code is left unchanged)" : `${resolved.outputMode} output`}`);
|
|
305
|
+
}
|
|
306
|
+
return resolved;
|
|
307
|
+
}
|
|
308
|
+
/** for tests */
|
|
309
|
+
function resetReactCompilerState() {
|
|
310
|
+
announced = false;
|
|
311
|
+
reported.clear();
|
|
312
|
+
}
|
|
313
|
+
/** the diagnostics last reported per file, so that each change is reported once */
|
|
314
|
+
const reported = /* @__PURE__ */ new Map();
|
|
315
|
+
/** Formats one Oxc diagnostic for the terminal. */
|
|
316
|
+
function formatDiagnostic(error) {
|
|
317
|
+
return (error.codeframe ?? `${error.message}${error.helpMessage ? `\n${error.helpMessage}` : ""}`).replace(/^\n+/, "").trimEnd();
|
|
318
|
+
}
|
|
319
|
+
const isCompilerDiagnostic = (e) => (e.codeframe ?? "").includes("react-compiler") || e.message.includes("React Compiler");
|
|
320
|
+
/** The transform of the `goatly` Vite plugin, for files it decided are the site's sources. */
|
|
321
|
+
async function createReactCompilerTransform(resolved, directory) {
|
|
322
|
+
const { transformSync } = await loadOxcTransformReact(directory);
|
|
323
|
+
const outputFor = (isServer) => resolved.outputMode === "lint" ? "lint" : isServer && resolved.outputMode === "ssr" ? "ssr" : "client";
|
|
324
|
+
return (code, file, isServer) => {
|
|
325
|
+
if (file.endsWith(".d.ts")) return null;
|
|
326
|
+
if (resolved.sourcesFilter && !resolved.sourcesFilter(file)) return null;
|
|
327
|
+
const lang = /\.(m|c)?js$/.test(file) ? "jsx" : void 0;
|
|
328
|
+
const outputMode = outputFor(isServer);
|
|
329
|
+
const result = transformSync(file, code, {
|
|
330
|
+
lang,
|
|
331
|
+
sourcemap: true,
|
|
332
|
+
jsx: "preserve",
|
|
333
|
+
reactCompiler: {
|
|
334
|
+
...resolved.options,
|
|
335
|
+
outputMode,
|
|
336
|
+
reportDiagnostics: resolved.reportDiagnostics
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
if (result.fatal) {
|
|
340
|
+
if (!result.errors.some(isCompilerDiagnostic)) return null;
|
|
341
|
+
throw new Error(`React Compiler failed on ${file}:\n${result.errors.map(formatDiagnostic).join("\n\n")}`);
|
|
342
|
+
}
|
|
343
|
+
if (resolved.reportDiagnostics) {
|
|
344
|
+
const diagnostics = result.errors.filter(isCompilerDiagnostic);
|
|
345
|
+
const signature = diagnostics.map(formatDiagnostic).join("\n\n");
|
|
346
|
+
if ((reported.get(file) ?? "") !== signature) {
|
|
347
|
+
reported.set(file, signature);
|
|
348
|
+
if (signature) {
|
|
349
|
+
const rel = slash(path.relative(directory, file)) || file;
|
|
350
|
+
reporter.warn(`React Compiler: ${diagnostics.length} diagnostic${diagnostics.length === 1 ? "" : "s"} in ${rel}\n${signature}`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
if (outputMode === "lint") return null;
|
|
355
|
+
if (outputMode === "client" && !/compiler-runtime["']/.test(result.code)) return null;
|
|
356
|
+
return {
|
|
357
|
+
code: result.code,
|
|
358
|
+
map: result.map
|
|
359
|
+
};
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
export { BABEL_CONFIG_FILES, createReactCompilerTransform, detectReactCompilerTarget, findReactCompilerBabelRegistration, findReactCompilerInBabelConfig, formatDiagnostic, fromBabelPluginOptions, loadOxcTransformReact, resetReactCompilerState, resolveReactCompiler, resolveReactCompilerOptions, unknownReactCompilerKeys, validateReactCompilerConfig };
|