From b15d6e93e70a50605f9a1187ea104d7e280447e4 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Thu, 10 Dec 2020 06:15:37 +0000 Subject: [PATCH] [Flight] Make PG and FS server-only (#20424) * Make react-fs server-only * Make react-pg server-only --- ...dex.browser.js => index.browser.server.js} | 0 packages/react-fs/index.js | 7 ++++--- .../{index.node.js => index.node.server.js} | 0 ...dex.browser.js => index.browser.server.js} | 4 ++-- packages/react-fs/npm/index.js | 5 ++++- packages/react-fs/npm/index.node.js | 7 ------- packages/react-fs/npm/index.node.server.js | 7 +++++++ packages/react-fs/package.json | 19 ++++++++++++++----- ...dex.browser.js => index.browser.server.js} | 0 packages/react-pg/index.js | 7 ++++--- .../{index.node.js => index.node.server.js} | 0 ...dex.browser.js => index.browser.server.js} | 4 ++-- packages/react-pg/npm/index.js | 5 ++++- packages/react-pg/npm/index.node.js | 7 ------- packages/react-pg/npm/index.node.server.js | 7 +++++++ packages/react-pg/package.json | 19 ++++++++++++++----- .../react-server-dom-webpack/package.json | 3 --- scripts/rollup/bundles.js | 8 ++++---- 18 files changed, 66 insertions(+), 43 deletions(-) rename packages/react-fs/{index.browser.js => index.browser.server.js} (100%) rename packages/react-fs/{index.node.js => index.node.server.js} (100%) rename packages/react-fs/npm/{index.browser.js => index.browser.server.js} (59%) delete mode 100644 packages/react-fs/npm/index.node.js create mode 100644 packages/react-fs/npm/index.node.server.js rename packages/react-pg/{index.browser.js => index.browser.server.js} (100%) rename packages/react-pg/{index.node.js => index.node.server.js} (100%) rename packages/react-pg/npm/{index.browser.js => index.browser.server.js} (59%) delete mode 100644 packages/react-pg/npm/index.node.js create mode 100644 packages/react-pg/npm/index.node.server.js diff --git a/packages/react-fs/index.browser.js b/packages/react-fs/index.browser.server.js similarity index 100% rename from packages/react-fs/index.browser.js rename to packages/react-fs/index.browser.server.js diff --git a/packages/react-fs/index.js b/packages/react-fs/index.js index ceb2071c4f055..02bc45822d62e 100644 --- a/packages/react-fs/index.js +++ b/packages/react-fs/index.js @@ -7,6 +7,7 @@ * @flow */ -'use strict'; - -export * from './index.node'; +throw new Error( + 'React FS cannot be used outside a react-server environment. ' + + 'You must configure Node.js using the `--conditions react-server` flag.', +); diff --git a/packages/react-fs/index.node.js b/packages/react-fs/index.node.server.js similarity index 100% rename from packages/react-fs/index.node.js rename to packages/react-fs/index.node.server.js diff --git a/packages/react-fs/npm/index.browser.js b/packages/react-fs/npm/index.browser.server.js similarity index 59% rename from packages/react-fs/npm/index.browser.js rename to packages/react-fs/npm/index.browser.server.js index d08a7383d699f..1bb15134d6590 100644 --- a/packages/react-fs/npm/index.browser.js +++ b/packages/react-fs/npm/index.browser.server.js @@ -1,7 +1,7 @@ 'use strict'; if (process.env.NODE_ENV === 'production') { - module.exports = require('./cjs/react-fs.browser.production.min.js'); + module.exports = require('./cjs/react-fs.browser.production.min.server.js'); } else { - module.exports = require('./cjs/react-fs.browser.development.js'); + module.exports = require('./cjs/react-fs.browser.development.server.js'); } diff --git a/packages/react-fs/npm/index.js b/packages/react-fs/npm/index.js index ee510df2ad686..39ea7955e3f34 100644 --- a/packages/react-fs/npm/index.js +++ b/packages/react-fs/npm/index.js @@ -1,3 +1,6 @@ 'use strict'; -module.exports = require('./index.node'); +throw new Error( + 'React FS cannot be used outside a react-server environment. ' + + 'You must configure Node.js using the `--conditions react-server` flag.' +); diff --git a/packages/react-fs/npm/index.node.js b/packages/react-fs/npm/index.node.js deleted file mode 100644 index fa1d5b986e658..0000000000000 --- a/packages/react-fs/npm/index.node.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -if (process.env.NODE_ENV === 'production') { - module.exports = require('./cjs/react-fs.node.production.min.js'); -} else { - module.exports = require('./cjs/react-fs.node.development.js'); -} diff --git a/packages/react-fs/npm/index.node.server.js b/packages/react-fs/npm/index.node.server.js new file mode 100644 index 0000000000000..58f2b422839bd --- /dev/null +++ b/packages/react-fs/npm/index.node.server.js @@ -0,0 +1,7 @@ +'use strict'; + +if (process.env.NODE_ENV === 'production') { + module.exports = require('./cjs/react-fs.node.production.min.server.js'); +} else { + module.exports = require('./cjs/react-fs.node.development.server.js'); +} diff --git a/packages/react-fs/package.json b/packages/react-fs/package.json index d3f9586725e0a..b83cebf3b25cd 100644 --- a/packages/react-fs/package.json +++ b/packages/react-fs/package.json @@ -13,14 +13,23 @@ "README.md", "build-info.json", "index.js", - "index.node.js", - "index.browser.js", + "index.node.server.js", + "index.browser.server.js", "cjs/" ], + "exports": { + ".": { + "react-server": { + "node": "./index.node.server.js", + "browser": "./index.browser.server.js" + }, + "default": "./index.js" + }, + "./index.node.server": "./index.node.server.js", + "./index.browser.server": "./index.browser.server.js", + "./package.json": "./package.json" + }, "peerDependencies": { "react": "^17.0.0" - }, - "browser": { - "./index.js": "./index.browser.js" } } diff --git a/packages/react-pg/index.browser.js b/packages/react-pg/index.browser.server.js similarity index 100% rename from packages/react-pg/index.browser.js rename to packages/react-pg/index.browser.server.js diff --git a/packages/react-pg/index.js b/packages/react-pg/index.js index ceb2071c4f055..cdf76f5d7632a 100644 --- a/packages/react-pg/index.js +++ b/packages/react-pg/index.js @@ -7,6 +7,7 @@ * @flow */ -'use strict'; - -export * from './index.node'; +throw new Error( + 'React PG cannot be used outside a react-server environment. ' + + 'You must configure Node.js using the `--conditions react-server` flag.', +); diff --git a/packages/react-pg/index.node.js b/packages/react-pg/index.node.server.js similarity index 100% rename from packages/react-pg/index.node.js rename to packages/react-pg/index.node.server.js diff --git a/packages/react-pg/npm/index.browser.js b/packages/react-pg/npm/index.browser.server.js similarity index 59% rename from packages/react-pg/npm/index.browser.js rename to packages/react-pg/npm/index.browser.server.js index 6e11ea9c992e1..175cec16ae3e6 100644 --- a/packages/react-pg/npm/index.browser.js +++ b/packages/react-pg/npm/index.browser.server.js @@ -1,7 +1,7 @@ 'use strict'; if (process.env.NODE_ENV === 'production') { - module.exports = require('./cjs/react-pg.browser.production.min.js'); + module.exports = require('./cjs/react-pg.browser.production.min.server.js'); } else { - module.exports = require('./cjs/react-pg.browser.development.js'); + module.exports = require('./cjs/react-pg.browser.development.server.js'); } diff --git a/packages/react-pg/npm/index.js b/packages/react-pg/npm/index.js index ee510df2ad686..64e0b2b2b59b1 100644 --- a/packages/react-pg/npm/index.js +++ b/packages/react-pg/npm/index.js @@ -1,3 +1,6 @@ 'use strict'; -module.exports = require('./index.node'); +throw new Error( + 'React PG cannot be used outside a react-server environment. ' + + 'You must configure Node.js using the `--conditions react-server` flag.' +); diff --git a/packages/react-pg/npm/index.node.js b/packages/react-pg/npm/index.node.js deleted file mode 100644 index a351531e3c902..0000000000000 --- a/packages/react-pg/npm/index.node.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -if (process.env.NODE_ENV === 'production') { - module.exports = require('./cjs/react-pg.node.production.min.js'); -} else { - module.exports = require('./cjs/react-pg.node.development.js'); -} diff --git a/packages/react-pg/npm/index.node.server.js b/packages/react-pg/npm/index.node.server.js new file mode 100644 index 0000000000000..c49f5fe6453ed --- /dev/null +++ b/packages/react-pg/npm/index.node.server.js @@ -0,0 +1,7 @@ +'use strict'; + +if (process.env.NODE_ENV === 'production') { + module.exports = require('./cjs/react-pg.node.production.min.server.js'); +} else { + module.exports = require('./cjs/react-pg.node.development.server.js'); +} diff --git a/packages/react-pg/package.json b/packages/react-pg/package.json index 9f8575414eb45..83a8b31c256c4 100644 --- a/packages/react-pg/package.json +++ b/packages/react-pg/package.json @@ -13,15 +13,24 @@ "README.md", "build-info.json", "index.js", - "index.node.js", - "index.browser.js", + "index.node.server.js", + "index.browser.server.js", "cjs/" ], + "exports": { + ".": { + "react-server": { + "node": "./index.node.server.js", + "browser": "./index.browser.server.js" + }, + "default": "./index.js" + }, + "./index.node.server": "./index.node.server.js", + "./index.browser.server": "./index.browser.server.js", + "./package.json": "./package.json" + }, "peerDependencies": { "react": "^17.0.0", "pg": "*" - }, - "browser": { - "./index.js": "./index.browser.js" } } diff --git a/packages/react-server-dom-webpack/package.json b/packages/react-server-dom-webpack/package.json index 711ffb37d68e8..8c7be6ca6682f 100644 --- a/packages/react-server-dom-webpack/package.json +++ b/packages/react-server-dom-webpack/package.json @@ -38,9 +38,6 @@ "./node-register": "./node-register.js", "./package.json": "./package.json" }, - "browser": { - "./writer.js": "./writer.browser.server.js" - }, "main": "index.js", "repository": { "type" : "git", diff --git a/scripts/rollup/bundles.js b/scripts/rollup/bundles.js index 46af927e3f64a..9c6a8c8a95d86 100644 --- a/scripts/rollup/bundles.js +++ b/scripts/rollup/bundles.js @@ -157,7 +157,7 @@ const bundles = [ { bundleTypes: [NODE_DEV, NODE_PROD], moduleType: ISOMORPHIC, - entry: 'react-fs/index.browser', + entry: 'react-fs/index.browser.server', global: 'ReactFilesystem', externals: [], }, @@ -166,7 +166,7 @@ const bundles = [ { bundleTypes: [NODE_DEV, NODE_PROD], moduleType: ISOMORPHIC, - entry: 'react-fs/index.node', + entry: 'react-fs/index.node.server', global: 'ReactFilesystem', externals: ['react', 'fs/promises', 'path'], }, @@ -175,7 +175,7 @@ const bundles = [ { bundleTypes: [NODE_DEV, NODE_PROD], moduleType: ISOMORPHIC, - entry: 'react-pg/index.browser', + entry: 'react-pg/index.browser.server', global: 'ReactPostgres', externals: [], }, @@ -184,7 +184,7 @@ const bundles = [ { bundleTypes: [NODE_DEV, NODE_PROD], moduleType: ISOMORPHIC, - entry: 'react-pg/index.node', + entry: 'react-pg/index.node.server', global: 'ReactPostgres', externals: ['react', 'pg'], },