Skip to content

Commit 8f90edc

Browse files
committed
Convert RSCWebpackLoader to TypeScript
1 parent a3ad230 commit 8f90edc

File tree

5 files changed

+442
-36
lines changed

5 files changed

+442
-36
lines changed

node_package/src/RSCWebpackLoader.js

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { pathToFileURL } from 'url';
2+
import { LoaderDefinition } from 'webpack';
3+
4+
const RSCWebpackLoader: LoaderDefinition = function RSCWebpackLoader(source, sourceMap) {
5+
// Mark loader as async since we're doing async operations
6+
const callback = this.async();
7+
8+
(async () => {
9+
// Convert file path to URL format
10+
const fileUrl = pathToFileURL(this.resourcePath).href;
11+
12+
// eslint-disable-next-line no-new-func
13+
const { load } = await new Function('return import("react-server-dom-webpack/node-loader")')() as
14+
typeof import('react-server-dom-webpack/node-loader');
15+
return load(fileUrl, null, async () => ({
16+
format: 'module',
17+
source,
18+
}));
19+
})().then(
20+
result => callback(null, result.source, sourceMap),
21+
error => callback(error),
22+
);
23+
};
24+
25+
export default RSCWebpackLoader;

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
"react-server-dom-webpack": "18.3.0-canary-670811593-20240322",
5353
"redux": "^4.2.1",
5454
"ts-jest": "^29.2.5",
55-
"typescript": "^5.6.2"
55+
"typescript": "^5.6.2",
56+
"webpack": "^5.97.1"
5657
},
5758
"dependencies": {},
5859
"peerDependencies": {
@@ -71,7 +72,7 @@
7172
"prepack": "nps build.prepack",
7273
"prepare": "nps build.prepack",
7374
"prepublishOnly": "yarn run build",
74-
"build": "yarn run clean && yarn run tsc --declaration && cp node_package/src/RSCWebpackLoader.js node_package/lib",
75+
"build": "yarn run clean && yarn run tsc --declaration",
7576
"build-watch": "yarn run clean && yarn run tsc --watch",
7677
"lint": "nps eslint",
7778
"check": "yarn run lint && yarn run test && yarn run type-check",

tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@
1212
"target": "es5",
1313
"typeRoots": ["./node_modules/@types", "./node_package/types"]
1414
},
15-
"include": ["node_package/src/**/*", "node_package/types/**/*"],
16-
"exclude": ["node_package/src/RSCWebpackLoader.js"]
15+
"include": ["node_package/src/**/*", "node_package/types/**/*"]
1716
}

0 commit comments

Comments
 (0)