Skip to content

Commit

Permalink
Add Node CommonJS regiter build
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sebmarkbage committed Nov 17, 2020
1 parent 50e1b77 commit 07cf810
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 8 deletions.
10 changes: 2 additions & 8 deletions fixtures/flight/server/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
'use strict';

const url = require('url');

require.extensions['.client.js'] = function(module, path) {
module.exports = {
$$typeof: Symbol.for('react.module.reference'),
name: url.pathToFileURL(path).href,
};
};
const register = require('react-transport-dom-webpack/node-register');
register();

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

Expand Down
10 changes: 10 additions & 0 deletions packages/react-transport-dom-webpack/node-register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

export * from './src/ReactFlightWebpackNodeRegister';
3 changes: 3 additions & 0 deletions packages/react-transport-dom-webpack/npm/node-register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('./cjs/react-transport-dom-webpack-node-register.js');
2 changes: 2 additions & 0 deletions packages/react-transport-dom-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"server.js",
"server.browser.js",
"server.node.js",
"node-register.js",
"cjs/",
"umd/",
"esm/"
Expand All @@ -28,6 +29,7 @@
"./server.browser": "./server.browser.js",
"./server.node": "./server.node.js",
"./node-loader": "./esm/react-transport-dom-webpack-node-loader.js",
"./node-register": "./node-register.js",
"./package.json": "./package.json"
},
"browser": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

const url = require('url');

module.exports = function register() {
(require: any).extensions['.client.js'] = function(module, path) {
module.exports = {
$$typeof: Symbol.for('react.module.reference'),
name: url.pathToFileURL(path).href,
};
};
};
9 changes: 9 additions & 0 deletions scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,15 @@ const bundles = [
externals: [],
},

/******* React Transport DOM Webpack Node.js CommonJS Loader *******/
{
bundleTypes: [NODE_ES2015],
moduleType: RENDERER_UTILS,
entry: 'react-transport-dom-webpack/node-register',
global: 'ReactFlightWebpackNodeRegister',
externals: ['url'],
},

/******* React Transport DOM Server Relay *******/
{
bundleTypes: [FB_WWW_DEV, FB_WWW_PROD],
Expand Down

0 comments on commit 07cf810

Please sign in to comment.