Skip to content

Commit

Permalink
[Flight] Make PG and FS server-only (facebook#20424)
Browse files Browse the repository at this point in the history
* Make react-fs server-only

* Make react-pg server-only
  • Loading branch information
gaearon authored and koto committed Jun 15, 2021
1 parent 4d3dd61 commit a35d175
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 43 deletions.
File renamed without changes.
7 changes: 4 additions & 3 deletions packages/react-fs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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');
}
5 changes: 4 additions & 1 deletion packages/react-fs/npm/index.js
Original file line number Diff line number Diff line change
@@ -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.'
);
7 changes: 0 additions & 7 deletions packages/react-fs/npm/index.node.js

This file was deleted.

7 changes: 7 additions & 0 deletions packages/react-fs/npm/index.node.server.js
Original file line number Diff line number Diff line change
@@ -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');
}
19 changes: 14 additions & 5 deletions packages/react-fs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
File renamed without changes.
7 changes: 4 additions & 3 deletions packages/react-pg/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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');
}
5 changes: 4 additions & 1 deletion packages/react-pg/npm/index.js
Original file line number Diff line number Diff line change
@@ -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.'
);
7 changes: 0 additions & 7 deletions packages/react-pg/npm/index.node.js

This file was deleted.

7 changes: 7 additions & 0 deletions packages/react-pg/npm/index.node.server.js
Original file line number Diff line number Diff line change
@@ -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');
}
19 changes: 14 additions & 5 deletions packages/react-pg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
3 changes: 0 additions & 3 deletions packages/react-server-dom-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
},
Expand All @@ -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'],
},
Expand All @@ -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: [],
},
Expand All @@ -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'],
},
Expand Down

0 comments on commit a35d175

Please sign in to comment.