Skip to content

Commit 7517f1b

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix-cli
2 parents 995f1c2 + eda4a64 commit 7517f1b

28 files changed

+150
-95
lines changed

packages/waku/src/lib/builder/build.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { INTERNAL_setAllEnv, unstable_getBuildOptions } from '../../server.js';
1111
import type { EntriesPrd } from '../types.js';
1212
import type { ConfigDev } from '../config.js';
1313
import { resolveConfigDev } from '../config.js';
14-
import { EXTENSIONS } from '../constants.js';
1514
import type { PathSpec } from '../utils/path.js';
1615
import {
1716
decodeFilePathFromAbsolute,
@@ -49,6 +48,7 @@ import { rscEnvPlugin } from '../plugins/vite-plugin-rsc-env.js';
4948
import { rscPrivatePlugin } from '../plugins/vite-plugin-rsc-private.js';
5049
import { rscManagedPlugin } from '../plugins/vite-plugin-rsc-managed.js';
5150
import {
51+
EXTENSIONS,
5252
DIST_ENTRIES_JS,
5353
DIST_PUBLIC,
5454
DIST_ASSETS,

packages/waku/src/lib/builder/constants.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
export const EXTENSIONS = ['.js', '.ts', '.tsx', '.jsx', '.mjs', '.cjs'];
2+
export const SRC_MAIN = 'main';
3+
export const SRC_ENTRIES = 'entries';
4+
15
// Some file and dir names for dist
26
// We may change this in the future
37
export const DIST_ENTRIES_JS = 'entries.js';

packages/waku/src/lib/constants.ts

-3
This file was deleted.

packages/waku/src/lib/middleware/dev-server-impl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import viteReact from '@vitejs/plugin-react';
66

77
import type { EntriesDev } from '../types.js';
88
import { resolveConfigDev } from '../config.js';
9-
import { SRC_MAIN, SRC_ENTRIES } from '../constants.js';
9+
import { SRC_MAIN, SRC_ENTRIES } from '../builder/constants.js';
1010
import {
1111
decodeFilePathFromAbsolute,
1212
joinPath,

packages/waku/src/lib/plugins/vite-plugin-deploy-aws-lambda.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import path from 'node:path';
22
import { writeFileSync } from 'node:fs';
33
import type { Plugin } from 'vite';
44

5-
import { unstable_getBuildOptions } from '../../server.js';
6-
import { SRC_ENTRIES } from '../constants.js';
7-
import { DIST_PUBLIC } from '../builder/constants.js';
5+
import {
6+
unstable_getBuildOptions,
7+
unstable_builderConstants,
8+
} from '../../server.js';
89

10+
const { SRC_ENTRIES, DIST_PUBLIC } = unstable_builderConstants;
911
const SERVE_JS = 'serve-aws-lambda.js';
1012

1113
const lambdaStreaming = process.env.DEPLOY_AWS_LAMBDA_STREAMING === 'true';

packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import path from 'node:path';
1313
import type { Plugin } from 'vite';
1414

1515
import { emitPlatformData } from '../builder/platform-data.js';
16-
import { unstable_getBuildOptions } from '../../server.js';
17-
import { DIST_PUBLIC } from '../builder/constants.js';
18-
import { SRC_ENTRIES } from '../constants.js';
16+
import {
17+
unstable_getBuildOptions,
18+
unstable_builderConstants,
19+
} from '../../server.js';
1920

21+
const { SRC_ENTRIES, DIST_PUBLIC } = unstable_builderConstants;
2022
const SERVE_JS = 'serve-cloudflare.js';
2123

2224
const getServeJsContent = (srcEntriesFile: string) => `

packages/waku/src/lib/plugins/vite-plugin-deploy-deno.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import type { Plugin } from 'vite';
22

3-
import { unstable_getBuildOptions } from '../../server.js';
4-
import { SRC_ENTRIES } from '../constants.js';
5-
import { DIST_PUBLIC } from '../builder/constants.js';
3+
import {
4+
unstable_getBuildOptions,
5+
unstable_builderConstants,
6+
} from '../../server.js';
67

8+
const { SRC_ENTRIES, DIST_PUBLIC } = unstable_builderConstants;
79
const SERVE_JS = 'serve-deno.js';
810

911
const getServeJsContent = (

packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import path from 'node:path';
22
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
33
import type { Plugin } from 'vite';
44

5-
import { unstable_getBuildOptions } from '../../server.js';
6-
import { SRC_ENTRIES } from '../constants.js';
7-
import { DIST_PUBLIC } from '../builder/constants.js';
5+
import {
6+
unstable_getBuildOptions,
7+
unstable_builderConstants,
8+
} from '../../server.js';
89

10+
const { SRC_ENTRIES, DIST_PUBLIC } = unstable_builderConstants;
911
const SERVE_JS = 'serve-netlify.js';
1012

1113
const getServeJsContent = (srcEntriesFile: string) => `

packages/waku/src/lib/plugins/vite-plugin-deploy-partykit.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import path from 'node:path';
22
import { existsSync, writeFileSync } from 'node:fs';
33
import type { Plugin } from 'vite';
44

5-
import { unstable_getBuildOptions } from '../../server.js';
6-
import { SRC_ENTRIES } from '../constants.js';
7-
import { DIST_PUBLIC } from '../builder/constants.js';
5+
import {
6+
unstable_getBuildOptions,
7+
unstable_builderConstants,
8+
} from '../../server.js';
89

10+
const { SRC_ENTRIES, DIST_PUBLIC } = unstable_builderConstants;
911
const SERVE_JS = 'serve-partykit.js';
1012

1113
const getServeJsContent = (srcEntriesFile: string) => `

packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import path from 'node:path';
22
import { cpSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
33
import type { Plugin } from 'vite';
44

5-
import { unstable_getBuildOptions } from '../../server.js';
6-
import { SRC_ENTRIES } from '../constants.js';
7-
import { DIST_PUBLIC } from '../builder/constants.js';
85
import { emitPlatformData } from '../builder/platform-data.js';
6+
import {
7+
unstable_getBuildOptions,
8+
unstable_builderConstants,
9+
} from '../../server.js';
910

11+
const { SRC_ENTRIES, DIST_PUBLIC } = unstable_builderConstants;
1012
const SERVE_JS = 'serve-vercel.js';
1113

1214
const getServeJsContent = (

packages/waku/src/lib/plugins/vite-plugin-dev-commonjs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { transformWithEsbuild } from 'vite';
22
import type { Plugin } from 'vite';
33

4-
import { EXTENSIONS } from '../constants.js';
4+
import { EXTENSIONS } from '../builder/constants.js';
55
import { extname } from '../utils/path.js';
66

77
// https://github.com/vite-plugin/vite-plugin-commonjs/blob/5e3294e78fabb037e12aab75433908fbee17192a/src/utils.ts#L9-L15

packages/waku/src/lib/plugins/vite-plugin-fs-router-typegen.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Plugin } from 'vite';
22
import { readdir, writeFile } from 'node:fs/promises';
33
import { existsSync, readFileSync } from 'node:fs';
4-
import { SRC_ENTRIES, EXTENSIONS } from '../constants.js';
4+
import { SRC_ENTRIES, EXTENSIONS } from '../builder/constants.js';
55
import { joinPath } from '../utils/path.js';
66
import { isIgnoredPath } from '../utils/fs-router.js';
77
import { getGrouplessPath } from '../utils/create-pages.js';

packages/waku/src/lib/plugins/vite-plugin-nonjs-resolve.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Plugin } from 'vite';
22

3-
import { EXTENSIONS } from '../constants.js';
3+
import { EXTENSIONS } from '../builder/constants.js';
44
import { extname } from '../utils/path.js';
55

66
export function nonjsResolvePlugin(): Plugin {

packages/waku/src/lib/plugins/vite-plugin-rsc-analyze.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Plugin } from 'vite';
22
import * as swc from '@swc/core';
33

4-
import { EXTENSIONS } from '../constants.js';
4+
import { EXTENSIONS } from '../builder/constants.js';
55
import { extname } from '../utils/path.js';
66
import { parseOpts } from '../utils/swc.js';
77
// HACK: Is it common to depend on another plugin like this?

packages/waku/src/lib/plugins/vite-plugin-rsc-delegate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Plugin, ViteDevServer } from 'vite';
22
import * as swc from '@swc/core';
33

4-
import { EXTENSIONS } from '../constants.js';
4+
import { EXTENSIONS } from '../builder/constants.js';
55
import { extname } from '../utils/path.js';
66
import { parseOpts } from '../utils/swc.js';
77
import type { HotUpdatePayload } from './vite-plugin-rsc-hmr.js';

packages/waku/src/lib/plugins/vite-plugin-rsc-entries.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'node:path';
33
import { normalizePath } from 'vite';
44
import type { Plugin } from 'vite';
55

6-
import { SRC_ENTRIES } from '../constants.js';
6+
import { SRC_ENTRIES } from '../builder/constants.js';
77
import { extname, joinPath } from '../utils/path.js';
88
import { treeshake, removeObjectProperty } from '../utils/treeshake.js';
99

packages/waku/src/lib/plugins/vite-plugin-rsc-index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Plugin } from 'vite';
22

3-
import { SRC_MAIN } from '../constants.js';
3+
import { SRC_MAIN } from '../builder/constants.js';
44

55
export function rscIndexPlugin(opts: {
66
basePath: string;

packages/waku/src/lib/plugins/vite-plugin-rsc-managed.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Plugin } from 'vite';
22

3-
import { EXTENSIONS, SRC_MAIN, SRC_ENTRIES } from '../constants.js';
3+
import { EXTENSIONS, SRC_MAIN, SRC_ENTRIES } from '../builder/constants.js';
44
import { extname, joinPath, filePathToFileURL } from '../utils/path.js';
55

66
const stripExt = (fname: string) => {

packages/waku/src/lib/plugins/vite-plugin-rsc-rsdw.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Plugin } from 'vite';
2+
import * as swc from '@swc/core';
23

34
const patchRsdw = (code: string, type: 'SERVER' | 'CLIENT') => {
45
code = code.replace(
@@ -68,7 +69,9 @@ export function rscRsdwPlugin(): Plugin {
6869
'/react-server-dom-webpack_server__edge.js',
6970
].some((suffix) => file!.endsWith(suffix))
7071
) {
71-
return patchRsdw(code, 'SERVER');
72+
return swc.transformSync(patchRsdw(code, 'SERVER'), {
73+
sourceMaps: true,
74+
});
7275
}
7376
if (
7477
[
@@ -80,7 +83,9 @@ export function rscRsdwPlugin(): Plugin {
8083
'/react-server-dom-webpack_client__edge.js',
8184
].some((suffix) => file!.endsWith(suffix))
8285
) {
83-
return patchRsdw(code, 'CLIENT');
86+
return swc.transformSync(patchRsdw(code, 'CLIENT'), {
87+
sourceMaps: true,
88+
});
8489
}
8590
if (code.includes('function requireAsyncModule(id)')) {
8691
throw new Error('rscRsdwPlugin: Untransformed file: ' + file);

packages/waku/src/lib/plugins/vite-plugin-rsc-transform.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Plugin } from 'vite';
22
import * as swc from '@swc/core';
33

4-
import { EXTENSIONS } from '../constants.js';
4+
import { EXTENSIONS } from '../builder/constants.js';
55
import { extname, joinPath } from '../utils/path.js';
66
import { parseOpts } from '../utils/swc.js';
77

@@ -68,7 +68,10 @@ import { unstable_callServerRsc as callServerRsc } from 'waku/minimal/client';
6868
export ${name === 'default' ? name : `const ${name} =`} createServerReference('${getServerId()}#${name}', callServerRsc);
6969
`;
7070
}
71-
return newCode;
71+
return swc.transformSync(newCode, {
72+
jsc: { parser: parseOpts(ext), target: 'esnext' },
73+
sourceMaps: true,
74+
});
7275
}
7376
};
7477

@@ -100,7 +103,10 @@ export ${name === 'default' ? name : `const ${name} =`} () => {
100103
};
101104
`;
102105
}
103-
return newCode;
106+
return swc.transformSync(newCode, {
107+
jsc: { parser: parseOpts(ext), target: 'esnext' },
108+
sourceMaps: true,
109+
});
104110
}
105111
};
106112

@@ -773,15 +779,17 @@ import { registerClientReference as __waku_registerClientReference } from 'react
773779
export ${name === 'default' ? name : `const ${name} =`} __waku_registerClientReference(() => { throw new Error('It is not possible to invoke a client function from the server: ${getClientId()}#${name}'); }, '${getClientId()}', '${name}');
774780
`;
775781
}
776-
return newCode;
782+
return swc.transformSync(newCode, {
783+
jsc: { parser: parseOpts(ext), target: 'esnext' },
784+
sourceMaps: true,
785+
});
777786
}
778787
let transformed =
779788
hasUseServer && transformExportedServerFunctions(mod, getServerId);
780789
transformed = transformInlineServerFunctions(mod, getServerId) || transformed;
781790
if (transformed) {
782791
mod.body.splice(findLastImportIndex(mod), 0, ...serverInitCode);
783-
const newCode = swc.printSync(mod).code;
784-
return newCode;
792+
return swc.printSync(mod, { sourceMaps: true });
785793
}
786794
};
787795

packages/waku/src/lib/renderers/html.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { injectRSCPayload } from 'rsc-html-stream/server';
66

77
import type * as WakuMinimalClientType from '../../minimal/client.js';
88
import type { ConfigDev, ConfigPrd } from '../config.js';
9-
import { SRC_MAIN } from '../constants.js';
9+
import { SRC_MAIN } from '../builder/constants.js';
1010
import { concatUint8Arrays } from '../utils/stream.js';
1111
import { filePathToFileURL } from '../utils/path.js';
1212
import { encodeRscPath } from './utils.js';

packages/waku/src/router/client.ts

+21-4
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,12 @@ const InnerRouter = ({
563563
);
564564
};
565565

566+
type Elements = Record<string, unknown>;
567+
type EnhanceFetch = (fetchFn: typeof fetch) => typeof fetch;
568+
type EnhanceCreateData = (
569+
createData: (responsePromise: Promise<Response>) => Promise<Elements>,
570+
) => (responsePromise: Promise<Response>) => Promise<Elements>;
571+
566572
// Note: The router data must be a stable mutable object (array).
567573
type RouterData = [
568574
locationListeners?: Set<(path: string, query: string) => void>,
@@ -576,12 +582,19 @@ const DEFAULT_ROUTER_DATA: RouterData = [];
576582
export function Router({
577583
routerData = DEFAULT_ROUTER_DATA,
578584
initialRoute = parseRouteFromLocation(),
585+
unstable_enhanceFetch,
586+
unstable_enhanceCreateData,
587+
}: {
588+
routerData?: RouterData;
589+
initialRoute?: RouteProps;
590+
unstable_enhanceFetch?: EnhanceFetch;
591+
unstable_enhanceCreateData?: EnhanceCreateData;
579592
}) {
580593
const initialRscPath = encodeRoutePath(initialRoute.path);
581594
const locationListeners = (routerData[0] ||= new Set());
582595
const staticPathSet = (routerData[1] ||= new Set());
583596
const cachedIdSet = (routerData[2] ||= new Set());
584-
const unstable_enhanceFetch =
597+
const enhanceFetch =
585598
(fetchFn: typeof fetch) =>
586599
(input: RequestInfo | URL, init: RequestInit = {}) => {
587600
const skipStr = JSON.stringify(Array.from(cachedIdSet));
@@ -593,7 +606,7 @@ export function Router({
593606
}
594607
return fetchFn(input, init);
595608
};
596-
const unstable_enhanceCreateData =
609+
const enhanceCreateData =
597610
(
598611
createData: (
599612
responsePromise: Promise<Response>,
@@ -641,8 +654,12 @@ export function Router({
641654
{
642655
initialRscPath,
643656
initialRscParams,
644-
unstable_enhanceFetch,
645-
unstable_enhanceCreateData,
657+
unstable_enhanceFetch: unstable_enhanceFetch
658+
? (fn) => unstable_enhanceFetch(enhanceFetch(fn))
659+
: enhanceFetch,
660+
unstable_enhanceCreateData: unstable_enhanceCreateData
661+
? (fn) => unstable_enhanceCreateData(enhanceCreateData(fn))
662+
: enhanceCreateData,
646663
},
647664
createElement(InnerRouter, {
648665
routerData: routerData as Required<RouterData>,

packages/waku/src/router/fs-router.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import { createPages, METHODS } from './create-pages.js';
77
import type { Method } from './create-pages.js';
88

9-
import { EXTENSIONS } from '../lib/constants.js';
9+
import { EXTENSIONS } from '../lib/builder/constants.js';
1010
import { isIgnoredPath } from '../lib/utils/fs-router.js';
1111

1212
const DO_NOT_BUNDLE = '';

packages/waku/src/server.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { getContext } from './middleware/context.js';
22

3+
export * as unstable_builderConstants from './lib/builder/constants.js';
4+
export { emitPlatformData as unstable_emitPlatfromData } from './lib/builder/platform-data.js';
5+
36
// The use of `globalThis` in this file is more or less a hack.
47
// It should be revisited with a better solution.
58

0 commit comments

Comments
 (0)