Skip to content

Commit 07cf810

Browse files
committed
Add Node CommonJS regiter build
This adds a build as a first-class export for legacy CommonJS registration in Node.js. This will grow in complexity so it deserves its own module.
1 parent 50e1b77 commit 07cf810

File tree

6 files changed

+45
-8
lines changed

6 files changed

+45
-8
lines changed

fixtures/flight/server/index.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
'use strict';
22

3-
const url = require('url');
4-
5-
require.extensions['.client.js'] = function(module, path) {
6-
module.exports = {
7-
$$typeof: Symbol.for('react.module.reference'),
8-
name: url.pathToFileURL(path).href,
9-
};
10-
};
3+
const register = require('react-transport-dom-webpack/node-register');
4+
register();
115

126
const babelRegister = require('@babel/register');
137

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
export * from './src/ReactFlightWebpackNodeRegister';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = require('./cjs/react-transport-dom-webpack-node-register.js');

packages/react-transport-dom-webpack/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"server.js",
1818
"server.browser.js",
1919
"server.node.js",
20+
"node-register.js",
2021
"cjs/",
2122
"umd/",
2223
"esm/"
@@ -28,6 +29,7 @@
2829
"./server.browser": "./server.browser.js",
2930
"./server.node": "./server.node.js",
3031
"./node-loader": "./esm/react-transport-dom-webpack-node-loader.js",
32+
"./node-register": "./node-register.js",
3133
"./package.json": "./package.json"
3234
},
3335
"browser": {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
const url = require('url');
11+
12+
module.exports = function register() {
13+
(require: any).extensions['.client.js'] = function(module, path) {
14+
module.exports = {
15+
$$typeof: Symbol.for('react.module.reference'),
16+
name: url.pathToFileURL(path).href,
17+
};
18+
};
19+
};

scripts/rollup/bundles.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,15 @@ const bundles = [
295295
externals: [],
296296
},
297297

298+
/******* React Transport DOM Webpack Node.js CommonJS Loader *******/
299+
{
300+
bundleTypes: [NODE_ES2015],
301+
moduleType: RENDERER_UTILS,
302+
entry: 'react-transport-dom-webpack/node-register',
303+
global: 'ReactFlightWebpackNodeRegister',
304+
externals: ['url'],
305+
},
306+
298307
/******* React Transport DOM Server Relay *******/
299308
{
300309
bundleTypes: [FB_WWW_DEV, FB_WWW_PROD],

0 commit comments

Comments
 (0)