rsbuild-plugin-react-router 0.1.1 → 0.3.0
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 +185 -204
- package/dist/451.js +1087 -0
- package/dist/bounded-cache.d.ts +1 -0
- package/dist/build-manifest.d.ts +1 -1
- package/dist/build-output-transforms.d.ts +30 -0
- package/dist/concurrency.d.ts +2 -0
- package/dist/config-imports.d.ts +3 -0
- package/dist/constants.d.ts +3 -0
- package/dist/dev-generation.d.ts +25 -0
- package/dist/dev-runtime-artifacts.d.ts +39 -0
- package/dist/dev-runtime-compilation.d.ts +32 -0
- package/dist/dev-runtime-controller.d.ts +14 -0
- package/dist/dev-runtime-session.d.ts +34 -0
- package/dist/dev-server.d.ts +11 -2
- package/dist/export-utils.d.ts +15 -7
- package/dist/index.cjs +3085 -1272
- package/dist/index.d.ts +4 -1
- package/dist/index.js +2039 -1299
- package/dist/lazy-compilation.d.ts +5 -0
- package/dist/manifest.d.ts +32 -9
- package/dist/modify-browser-manifest.d.ts +30 -13
- package/dist/parallel-route-transform-protocol.d.ts +25 -0
- package/dist/parallel-route-transform-worker.d.ts +1 -0
- package/dist/parallel-route-transform-worker.js +38 -0
- package/dist/parallel-route-transforms.d.ts +14 -0
- package/dist/performance.d.ts +26 -0
- package/dist/plugin-utils.d.ts +2 -12
- package/dist/prerender-build.d.ts +32 -0
- package/dist/prerender.d.ts +28 -2
- package/dist/react-router-config.d.ts +8 -1
- package/dist/route-artifacts.d.ts +33 -0
- package/dist/route-ast.d.ts +21 -0
- package/dist/route-chunks.d.ts +9 -1
- package/dist/route-component-transform.d.ts +5 -0
- package/dist/route-export-pruning.d.ts +6 -0
- package/dist/route-export-resolution.d.ts +5 -0
- package/dist/route-transform-tasks.d.ts +47 -0
- package/dist/route-watch.d.ts +27 -0
- package/dist/server-build-plan.d.ts +22 -0
- package/dist/server-utils.d.ts +3 -2
- package/dist/templates/entry.client.js +3 -3
- package/dist/templates/entry.server.cjs +11 -8
- package/dist/templates/entry.server.js +5 -5
- package/dist/typegen.d.ts +2 -0
- package/dist/types.d.ts +30 -12
- package/dist/virtual-modules.d.ts +2 -0
- package/dist/warnings/warn-on-client-source-maps.d.ts +1 -0
- package/dist/yuku.d.ts +15 -0
- package/package.json +26 -22
- package/src/bounded-cache.ts +18 -0
- package/src/build-manifest.ts +168 -0
- package/src/build-output-transforms.ts +273 -0
- package/src/concurrency.ts +34 -0
- package/src/config-imports.ts +45 -0
- package/src/constants.ts +91 -0
- package/src/dev-generation.ts +700 -0
- package/src/dev-runtime-artifacts.ts +207 -0
- package/src/dev-runtime-compilation.ts +92 -0
- package/src/dev-runtime-controller.ts +462 -0
- package/src/dev-runtime-session.ts +184 -0
- package/src/dev-server.ts +58 -0
- package/src/export-utils.ts +219 -0
- package/src/index.ts +1025 -0
- package/src/lazy-compilation.ts +94 -0
- package/src/manifest.ts +480 -0
- package/src/modify-browser-manifest.ts +245 -0
- package/src/parallel-route-transform-protocol.ts +35 -0
- package/src/parallel-route-transform-worker.ts +82 -0
- package/src/parallel-route-transforms.ts +332 -0
- package/src/performance.ts +254 -0
- package/src/plugin-utils.ts +82 -0
- package/src/prerender-build.ts +623 -0
- package/src/prerender.ts +367 -0
- package/src/react-router-config.ts +220 -0
- package/src/route-artifacts.ts +155 -0
- package/src/route-ast.ts +163 -0
- package/src/route-chunks.ts +857 -0
- package/src/route-component-transform.ts +314 -0
- package/src/route-config.ts +106 -0
- package/src/route-export-pruning.ts +668 -0
- package/src/route-export-resolution.ts +329 -0
- package/src/route-transform-tasks.ts +249 -0
- package/src/route-watch.ts +322 -0
- package/src/server-build-plan.ts +91 -0
- package/src/server-utils.ts +210 -0
- package/src/ssr-externals.ts +59 -0
- package/src/templates/context.ts +12 -0
- package/src/templates/entry.client.tsx +12 -0
- package/src/templates/entry.server.tsx +76 -0
- package/src/typegen.ts +49 -0
- package/src/types.ts +82 -0
- package/src/validation/validate-plugin-order.ts +76 -0
- package/src/virtual-modules.ts +30 -0
- package/src/warnings/warn-on-client-source-maps.ts +96 -0
- package/src/yuku.ts +67 -0
- package/dist/906.js +0 -1
- package/dist/946.js +0 -1
- package/dist/babel.d.ts +0 -8
- package/dist/rslib-runtime.js +0 -23
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { PassThrough } from 'node:stream';
|
|
2
|
+
import { createReadableStreamFromReadable } from '@react-router/node';
|
|
3
|
+
import { isbot } from 'isbot';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import type { RenderToPipeableStreamOptions } from 'react-dom/server';
|
|
6
|
+
import { renderToPipeableStream } from 'react-dom/server';
|
|
7
|
+
import type {
|
|
8
|
+
// AppLoadContext,
|
|
9
|
+
EntryContext,
|
|
10
|
+
} from 'react-router';
|
|
11
|
+
import { ServerRouter } from 'react-router';
|
|
12
|
+
|
|
13
|
+
const ABORT_DELAY = 5_000;
|
|
14
|
+
|
|
15
|
+
export default function handleRequest(
|
|
16
|
+
request: Request,
|
|
17
|
+
responseStatusCode: number,
|
|
18
|
+
responseHeaders: Headers,
|
|
19
|
+
routerContext: EntryContext
|
|
20
|
+
// loadContext: AppLoadContext
|
|
21
|
+
): Promise<Response> {
|
|
22
|
+
return new Promise<Response>((resolve, reject) => {
|
|
23
|
+
let shellRendered = false;
|
|
24
|
+
let statusCode = responseStatusCode;
|
|
25
|
+
const userAgent = request.headers.get('user-agent');
|
|
26
|
+
|
|
27
|
+
// Ensure requests from bots and SPA Mode renders wait for all content to load before responding
|
|
28
|
+
// https://react.dev/reference/react-dom/server/renderToPipeableStream#waiting-for-all-content-to-load-for-crawlers-and-static-generation
|
|
29
|
+
const readyOption: keyof RenderToPipeableStreamOptions =
|
|
30
|
+
(userAgent && isbot(userAgent)) || routerContext.isSpaMode
|
|
31
|
+
? 'onAllReady'
|
|
32
|
+
: 'onShellReady';
|
|
33
|
+
let abortDelay: ReturnType<typeof setTimeout> | undefined;
|
|
34
|
+
let ready = false;
|
|
35
|
+
|
|
36
|
+
const { pipe, abort } = renderToPipeableStream(
|
|
37
|
+
<ServerRouter context={routerContext} url={request.url} />,
|
|
38
|
+
{
|
|
39
|
+
[readyOption]() {
|
|
40
|
+
ready = true;
|
|
41
|
+
if (readyOption === 'onAllReady' && abortDelay) {
|
|
42
|
+
clearTimeout(abortDelay);
|
|
43
|
+
}
|
|
44
|
+
shellRendered = true;
|
|
45
|
+
const body = new PassThrough();
|
|
46
|
+
const stream = createReadableStreamFromReadable(body);
|
|
47
|
+
|
|
48
|
+
responseHeaders.set('Content-Type', 'text/html');
|
|
49
|
+
|
|
50
|
+
resolve(
|
|
51
|
+
new Response(stream, {
|
|
52
|
+
headers: responseHeaders,
|
|
53
|
+
status: statusCode,
|
|
54
|
+
})
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
pipe(body);
|
|
58
|
+
},
|
|
59
|
+
onShellError(error: unknown) {
|
|
60
|
+
reject(error);
|
|
61
|
+
},
|
|
62
|
+
onError(error: unknown) {
|
|
63
|
+
statusCode = 500;
|
|
64
|
+
if (shellRendered) {
|
|
65
|
+
console.error(error);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
abortDelay = setTimeout(abort, ABORT_DELAY);
|
|
72
|
+
if (readyOption === 'onAllReady' && ready) {
|
|
73
|
+
clearTimeout(abortDelay);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
package/src/typegen.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { RsbuildPluginAPI } from '@rsbuild/core';
|
|
2
|
+
import type { ResultPromise } from 'execa';
|
|
3
|
+
|
|
4
|
+
export const registerReactRouterTypegen = (api: RsbuildPluginAPI): void => {
|
|
5
|
+
let typegenProcess: ResultPromise | undefined;
|
|
6
|
+
|
|
7
|
+
api.onBeforeStartDevServer(async () => {
|
|
8
|
+
if (typegenProcess) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const { execa } = await import('execa');
|
|
12
|
+
const process = execa(
|
|
13
|
+
'npx',
|
|
14
|
+
['--yes', 'react-router', 'typegen', '--watch'],
|
|
15
|
+
{
|
|
16
|
+
stdio: 'inherit',
|
|
17
|
+
detached: false,
|
|
18
|
+
cleanup: true,
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
typegenProcess = process;
|
|
22
|
+
process
|
|
23
|
+
.catch(() => {
|
|
24
|
+
// Ignore errors when the process is killed on server shutdown.
|
|
25
|
+
})
|
|
26
|
+
.finally(() => {
|
|
27
|
+
if (typegenProcess === process) {
|
|
28
|
+
typegenProcess = undefined;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
api.onCloseDevServer(async () => {
|
|
34
|
+
const process = typegenProcess;
|
|
35
|
+
typegenProcess = undefined;
|
|
36
|
+
if (!process) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
process.kill('SIGTERM');
|
|
40
|
+
await process.catch(() => undefined);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
api.onBeforeBuild(async () => {
|
|
44
|
+
const { execa } = await import('execa');
|
|
45
|
+
await execa('npx', ['--yes', 'react-router', 'typegen'], {
|
|
46
|
+
stdio: 'inherit',
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { RsbuildConfig } from '@rsbuild/core';
|
|
2
|
+
|
|
3
|
+
export type Route = {
|
|
4
|
+
id: string;
|
|
5
|
+
parentId?: string;
|
|
6
|
+
file: string;
|
|
7
|
+
path?: string;
|
|
8
|
+
index?: boolean;
|
|
9
|
+
caseSensitive?: boolean;
|
|
10
|
+
children?: Route[];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type PluginOptions = {
|
|
14
|
+
/**
|
|
15
|
+
* Whether to disable automatic middleware setup for custom server implementation.
|
|
16
|
+
* Use this when you want to handle server setup manually.
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
customServer?: boolean;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The output format for server builds.
|
|
23
|
+
* When set to "module", no package.json will be emitted.
|
|
24
|
+
* @default "module"
|
|
25
|
+
*/
|
|
26
|
+
serverOutput?: 'module' | 'commonjs';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Federation mode configuration
|
|
30
|
+
*/
|
|
31
|
+
federation?: boolean;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Opt in to Rsbuild's dev-only lazy compilation behavior.
|
|
35
|
+
*
|
|
36
|
+
* React Router hydration modules remain eager so initial dev requests can
|
|
37
|
+
* load the browser manifest and route modules without lazy proxy delays.
|
|
38
|
+
*
|
|
39
|
+
* @default undefined
|
|
40
|
+
*/
|
|
41
|
+
lazyCompilation?: NonNullable<RsbuildConfig['dev']>['lazyCompilation'];
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Emit structured React Router plugin timing logs.
|
|
45
|
+
* @default false
|
|
46
|
+
*/
|
|
47
|
+
logPerformance?: boolean;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Run route transforms in a worker-thread pool.
|
|
51
|
+
* Pass `true` to force the default worker count, a positive integer to set
|
|
52
|
+
* the worker count, or `false` to disable.
|
|
53
|
+
* @default Automatically enabled for 256+ resolved routes. The automatic
|
|
54
|
+
* pool uses available CPU cores minus 2.
|
|
55
|
+
*/
|
|
56
|
+
parallelRouteTransform?: boolean | number;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Called when the route graph changes during development.
|
|
60
|
+
* Programmatic/custom servers can use this to recreate their Rsbuild server;
|
|
61
|
+
* the CLI uses its built-in reload-server watcher when this is omitted. This
|
|
62
|
+
* notification is not awaited, so it may safely close the current server.
|
|
63
|
+
*/
|
|
64
|
+
onRouteTopologyChange?: () => void | Promise<void>;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type RouteManifestItem = Omit<Route, 'file' | 'children'> & {
|
|
68
|
+
module: string;
|
|
69
|
+
clientActionModule?: string;
|
|
70
|
+
clientLoaderModule?: string;
|
|
71
|
+
clientMiddlewareModule?: string;
|
|
72
|
+
hydrateFallbackModule?: string;
|
|
73
|
+
hasAction: boolean;
|
|
74
|
+
hasLoader: boolean;
|
|
75
|
+
hasClientAction: boolean;
|
|
76
|
+
hasClientLoader: boolean;
|
|
77
|
+
hasClientMiddleware: boolean;
|
|
78
|
+
hasDefaultExport: boolean;
|
|
79
|
+
hasErrorBoundary: boolean;
|
|
80
|
+
imports: string[];
|
|
81
|
+
css: string[];
|
|
82
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { RsbuildConfig } from '@rsbuild/core';
|
|
2
|
+
|
|
3
|
+
function pluginId(name: string) {
|
|
4
|
+
return `rsbuild:${name}`;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function flattenPlugins(input: unknown): Array<{ name?: string }> {
|
|
8
|
+
if (!Array.isArray(input)) return [];
|
|
9
|
+
const out: Array<{ name?: string }> = [];
|
|
10
|
+
for (const item of input) {
|
|
11
|
+
if (!item) continue;
|
|
12
|
+
if (Array.isArray(item)) {
|
|
13
|
+
out.push(...flattenPlugins(item));
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (typeof (item as any)?.then === 'function') {
|
|
17
|
+
// Skip promises - normalized config should already be resolved.
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (typeof item === 'object') {
|
|
21
|
+
out.push(item as any);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function indexOfPlugin(plugins: Array<{ name?: string }>, names: string[]) {
|
|
28
|
+
return plugins.findIndex(p => (p?.name ? names.includes(p.name) : false));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type PluginOrderIssue =
|
|
32
|
+
| {
|
|
33
|
+
kind: 'error';
|
|
34
|
+
message: string;
|
|
35
|
+
}
|
|
36
|
+
| {
|
|
37
|
+
kind: 'warn';
|
|
38
|
+
message: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export function validatePluginOrderFromConfig(
|
|
42
|
+
config: RsbuildConfig
|
|
43
|
+
): PluginOrderIssue[] {
|
|
44
|
+
const plugins = flattenPlugins(config.plugins);
|
|
45
|
+
const issues: PluginOrderIssue[] = [];
|
|
46
|
+
|
|
47
|
+
// Best-effort port of upstream validate-plugin-order:
|
|
48
|
+
// - `rsbuild:mdx` must be before `rsbuild:react-router` so that route files
|
|
49
|
+
// can be authored in MDX and still have exports parsed correctly.
|
|
50
|
+
const rrIndex = indexOfPlugin(plugins, ['rsbuild:react-router']);
|
|
51
|
+
const mdxIndex = indexOfPlugin(plugins, [pluginId('mdx')]);
|
|
52
|
+
if (rrIndex >= 0 && mdxIndex >= 0 && mdxIndex > rrIndex) {
|
|
53
|
+
issues.push({
|
|
54
|
+
kind: 'error',
|
|
55
|
+
message:
|
|
56
|
+
`The \"rsbuild:mdx\" plugin should be placed before the React Router plugin ` +
|
|
57
|
+
`in your Rsbuild config. This ensures route modules authored in MDX are ` +
|
|
58
|
+
`compiled before React Router inspects route exports.`,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Rsbuild/React Router expectation: user should also include React support
|
|
63
|
+
// (JSX transform + refresh). We can only warn since Rsbuild configs may not
|
|
64
|
+
// use React at all (or may provide a custom JSX pipeline).
|
|
65
|
+
const hasReact = plugins.some(p => p?.name === pluginId('react'));
|
|
66
|
+
if (rrIndex >= 0 && !hasReact) {
|
|
67
|
+
issues.push({
|
|
68
|
+
kind: 'warn',
|
|
69
|
+
message:
|
|
70
|
+
`React Router plugin detected without \"rsbuild:react\". If you are using ` +
|
|
71
|
+
`JSX/TSX route modules, add \"@rsbuild/plugin-react\" to your plugins list.`,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return issues;
|
|
76
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const VIRTUAL_MODULE_PREFIX = 'virtual/react-router/';
|
|
2
|
+
|
|
3
|
+
export const getVirtualModuleFilePath = (moduleId: string): string => {
|
|
4
|
+
if (!moduleId.startsWith(VIRTUAL_MODULE_PREFIX)) {
|
|
5
|
+
throw new Error(
|
|
6
|
+
`Virtual module id must start with ${JSON.stringify(VIRTUAL_MODULE_PREFIX)}: ${moduleId}`
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const relativeId = moduleId.slice(VIRTUAL_MODULE_PREFIX.length);
|
|
11
|
+
const segments = relativeId.split('/');
|
|
12
|
+
if (
|
|
13
|
+
!relativeId ||
|
|
14
|
+
segments.some(segment => !segment || segment === '.' || segment === '..')
|
|
15
|
+
) {
|
|
16
|
+
throw new Error(`Invalid virtual module id: ${moduleId}`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return `node_modules/${moduleId}.js`;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const mapVirtualModules = (
|
|
23
|
+
modules: Record<string, string>
|
|
24
|
+
): Record<string, string> =>
|
|
25
|
+
Object.fromEntries(
|
|
26
|
+
Object.entries(modules).map(([moduleId, contents]) => [
|
|
27
|
+
getVirtualModuleFilePath(moduleId),
|
|
28
|
+
contents,
|
|
29
|
+
])
|
|
30
|
+
);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { NormalizedConfig } from '@rsbuild/core';
|
|
2
|
+
|
|
3
|
+
type Warn = (message: string) => void;
|
|
4
|
+
type ToolsRspackConfig = NonNullable<NormalizedConfig['tools']>['rspack'];
|
|
5
|
+
type SourceMapConfigObject = { js?: unknown };
|
|
6
|
+
|
|
7
|
+
function isProdBuild(mode?: string): boolean {
|
|
8
|
+
// Prefer Rsbuild's normalized `mode` (explicit) and fall back to NODE_ENV.
|
|
9
|
+
return mode === 'production' || process.env.NODE_ENV === 'production';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function isSourceMapEnabled(value: unknown): boolean {
|
|
13
|
+
// Rsbuild normalizes `output.sourceMap` into either:
|
|
14
|
+
// - boolean
|
|
15
|
+
// - { js?: devtool; css: boolean }
|
|
16
|
+
if (value === true) return true;
|
|
17
|
+
if (value === false || value == null) return false;
|
|
18
|
+
if (typeof value === 'string') return true;
|
|
19
|
+
if (typeof value === 'object') {
|
|
20
|
+
const js = (value as SourceMapConfigObject).js;
|
|
21
|
+
// Any truthy devtool string/object means source maps are on for JS.
|
|
22
|
+
return Boolean(js);
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isDevtoolSourceMap(value: unknown): boolean {
|
|
28
|
+
if (value === true) return true;
|
|
29
|
+
if (value == null || value === false) return false;
|
|
30
|
+
if (typeof value === 'string') {
|
|
31
|
+
return value.includes('source-map');
|
|
32
|
+
}
|
|
33
|
+
// Unknown object shape - treat as enabled to be safe.
|
|
34
|
+
return typeof value === 'object';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getClientSourceMapSetting(
|
|
38
|
+
normalized: NormalizedConfig,
|
|
39
|
+
clientEnvName = 'web'
|
|
40
|
+
): unknown {
|
|
41
|
+
// Prefer environment setting, fallback to global.
|
|
42
|
+
return (
|
|
43
|
+
normalized.environments?.[clientEnvName]?.output?.sourceMap ??
|
|
44
|
+
normalized.output?.sourceMap
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function getClientDevtoolSetting(
|
|
49
|
+
normalized: NormalizedConfig,
|
|
50
|
+
clientEnvName = 'web'
|
|
51
|
+
): unknown {
|
|
52
|
+
const envTools = normalized.environments?.[clientEnvName]?.tools?.rspack;
|
|
53
|
+
const rootTools = normalized.tools?.rspack;
|
|
54
|
+
return (
|
|
55
|
+
getDevtoolFromRspackConfig(envTools) ??
|
|
56
|
+
getDevtoolFromRspackConfig(rootTools)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function getDevtoolFromRspackConfig(config?: ToolsRspackConfig): unknown {
|
|
61
|
+
if (!config) return undefined;
|
|
62
|
+
if (typeof config === 'function') return undefined;
|
|
63
|
+
if (typeof config !== 'object') return undefined;
|
|
64
|
+
return (config as { devtool?: unknown }).devtool;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function warnOnClientSourceMaps(
|
|
68
|
+
normalized: NormalizedConfig,
|
|
69
|
+
warn: Warn,
|
|
70
|
+
clientEnvName = 'web'
|
|
71
|
+
): void {
|
|
72
|
+
// Only warn on production builds.
|
|
73
|
+
if (!isProdBuild(normalized.mode)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const sourceMapSetting = getClientSourceMapSetting(normalized, clientEnvName);
|
|
78
|
+
const devtoolSetting = getClientDevtoolSetting(normalized, clientEnvName);
|
|
79
|
+
if (
|
|
80
|
+
!isSourceMapEnabled(sourceMapSetting) &&
|
|
81
|
+
!isDevtoolSourceMap(devtoolSetting)
|
|
82
|
+
) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
warn(
|
|
87
|
+
[
|
|
88
|
+
'',
|
|
89
|
+
' WARNING: Source maps are enabled in production',
|
|
90
|
+
' This makes your server code publicly visible in the browser.',
|
|
91
|
+
' This is highly discouraged! If you insist, ensure that you are using',
|
|
92
|
+
' environment variables for secrets and not hard-coding them in your source code.',
|
|
93
|
+
'',
|
|
94
|
+
].join('\n')
|
|
95
|
+
);
|
|
96
|
+
}
|
package/src/yuku.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parse as yukuParse,
|
|
3
|
+
walk,
|
|
4
|
+
type ParseOptions,
|
|
5
|
+
type ParseResult,
|
|
6
|
+
} from 'yuku-parser';
|
|
7
|
+
import type { Rspack } from '@rsbuild/core';
|
|
8
|
+
import { print } from 'yuku-codegen';
|
|
9
|
+
|
|
10
|
+
export const parse = (
|
|
11
|
+
code: string,
|
|
12
|
+
options: ParseOptions = {}
|
|
13
|
+
): ParseResult => {
|
|
14
|
+
const result = yukuParse(code, {
|
|
15
|
+
...options,
|
|
16
|
+
sourceType: options.sourceType ?? 'module',
|
|
17
|
+
lang: options.lang ?? 'tsx',
|
|
18
|
+
attachComments: options.attachComments ?? true,
|
|
19
|
+
});
|
|
20
|
+
const errors = result.diagnostics.filter(
|
|
21
|
+
diagnostic => diagnostic.severity === 'error'
|
|
22
|
+
);
|
|
23
|
+
if (errors.length > 0) {
|
|
24
|
+
throw new Error(errors.map(error => error.message).join('\n'));
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const traverse: typeof walk = walk;
|
|
30
|
+
|
|
31
|
+
export const generate = (
|
|
32
|
+
ast: ParseResult | { type: 'Program' },
|
|
33
|
+
options: {
|
|
34
|
+
sourceMaps?: boolean;
|
|
35
|
+
filename?: string;
|
|
36
|
+
sourceFileName?: string;
|
|
37
|
+
} = {}
|
|
38
|
+
): { code: string; map: Rspack.RawSourceMap | null } => {
|
|
39
|
+
const result = 'program' in ast ? ast : { program: ast, lineStarts: [] };
|
|
40
|
+
const generated = print(result.program as Parameters<typeof print>[0], {
|
|
41
|
+
comments: true,
|
|
42
|
+
sourceMaps: options.sourceMaps
|
|
43
|
+
? {
|
|
44
|
+
lineStarts: result.lineStarts,
|
|
45
|
+
file: options.filename,
|
|
46
|
+
sourceFileName: options.sourceFileName,
|
|
47
|
+
}
|
|
48
|
+
: undefined,
|
|
49
|
+
});
|
|
50
|
+
if (generated.errors.length > 0) {
|
|
51
|
+
throw new Error(generated.errors.map(error => error.message).join('\n'));
|
|
52
|
+
}
|
|
53
|
+
const map = generated.map
|
|
54
|
+
? {
|
|
55
|
+
...generated.map,
|
|
56
|
+
file: generated.map.file ?? options.filename ?? '',
|
|
57
|
+
sourceRoot: generated.map.sourceRoot ?? undefined,
|
|
58
|
+
sourcesContent:
|
|
59
|
+
generated.map.sourcesContent?.map(source => source ?? '') ??
|
|
60
|
+
undefined,
|
|
61
|
+
}
|
|
62
|
+
: null;
|
|
63
|
+
|
|
64
|
+
return { code: generated.code, map };
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type { ParseResult };
|
package/dist/906.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ServerRouter, createRequestHandler, matchRoutes } from "react-router";
|
package/dist/946.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { StrictMode, createElement, startTransition } from "react";
|
package/dist/babel.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { types as Babel } from '@babel/core';
|
|
2
|
-
import { type ParseResult, parse } from '@babel/parser';
|
|
3
|
-
import type { NodePath } from '@babel/traverse';
|
|
4
|
-
import * as t from '@babel/types';
|
|
5
|
-
declare const traverse: typeof import('@babel/traverse').default;
|
|
6
|
-
declare const generate: typeof import('@babel/generator').default;
|
|
7
|
-
export { traverse, generate, parse, t };
|
|
8
|
-
export type { Babel, NodePath, ParseResult };
|
package/dist/rslib-runtime.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
var __webpack_module_cache__ = {};
|
|
2
|
-
function __webpack_require__(moduleId) {
|
|
3
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
4
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
5
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
6
|
-
exports: {}
|
|
7
|
-
};
|
|
8
|
-
return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.exports;
|
|
9
|
-
}
|
|
10
|
-
__webpack_require__.add = function(modules) {
|
|
11
|
-
Object.assign(__webpack_require__.m, modules);
|
|
12
|
-
}, __webpack_require__.n = (module)=>{
|
|
13
|
-
var getter = module && module.__esModule ? ()=>module.default : ()=>module;
|
|
14
|
-
return __webpack_require__.d(getter, {
|
|
15
|
-
a: getter
|
|
16
|
-
}), getter;
|
|
17
|
-
}, __webpack_require__.d = (exports, definition)=>{
|
|
18
|
-
for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key) && Object.defineProperty(exports, key, {
|
|
19
|
-
enumerable: !0,
|
|
20
|
-
get: definition[key]
|
|
21
|
-
});
|
|
22
|
-
}, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
23
|
-
export { __webpack_require__ };
|