Skip to content

Commit ce40f1d

Browse files
authored
Use assets API + writeToDisk instead of directly writing to disk (#20402)
1 parent 0512cd6 commit ce40f1d

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

fixtures/flight/config/webpackDevServer.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ module.exports = function(proxy, allowedHost) {
9090
watchOptions: {
9191
ignored: ignoredFiles(paths.appSrc),
9292
},
93+
writeToDisk: filePath => {
94+
return /react-client-manifest\.json$/.test(filePath);
95+
},
9396
https: getHttpsConfig(),
9497
host,
9598
overlay: false,

fixtures/flight/server/handler.server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = function(req, res) {
1010
import('../src/App.server.js').then(m => {
1111
const dist = process.env.NODE_ENV === 'development' ? 'dist' : 'build';
1212
readFile(
13-
resolve(__dirname, `../${dist}/react-transport-manifest.json`),
13+
resolve(__dirname, `../${dist}/react-client-manifest.json`),
1414
'utf8',
1515
(err, data) => {
1616
if (err) {

packages/react-transport-dom-webpack/src/ReactFlightWebpackPlugin.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
* @flow
88
*/
99

10-
import {mkdirSync, writeFileSync} from 'fs';
11-
import {dirname, resolve, join} from 'path';
10+
import {join} from 'path';
1211
import {pathToFileURL} from 'url';
1312

1413
import asyncLib from 'neo-async';
@@ -48,13 +47,16 @@ type Options = {
4847
isServer: boolean,
4948
clientReferences?: ClientReferencePath | $ReadOnlyArray<ClientReferencePath>,
5049
chunkName?: string,
50+
manifestFilename?: string,
5151
};
5252

5353
const PLUGIN_NAME = 'React Transport Plugin';
5454

5555
export default class ReactFlightWebpackPlugin {
5656
clientReferences: $ReadOnlyArray<ClientReferencePath>;
5757
chunkName: string;
58+
manifestFilename: string;
59+
5860
constructor(options: Options) {
5961
if (!options || typeof options.isServer !== 'boolean') {
6062
throw new Error(
@@ -88,6 +90,8 @@ export default class ReactFlightWebpackPlugin {
8890
} else {
8991
this.chunkName = 'client[index]';
9092
}
93+
this.manifestFilename =
94+
options.manifestFilename || 'react-client-manifest.json';
9195
}
9296

9397
apply(compiler: any) {
@@ -189,13 +193,14 @@ export default class ReactFlightWebpackPlugin {
189193
});
190194
});
191195
const output = JSON.stringify(json, null, 2);
192-
const filename = resolve(
193-
compiler.options.output.path,
194-
'react-transport-manifest.json',
195-
);
196-
mkdirSync(dirname(filename), {recursive: true});
197-
// TODO: Use webpack's emit API and read from the devserver.
198-
writeFileSync(filename, output);
196+
compilation.assets[this.manifestFilename] = {
197+
source() {
198+
return output;
199+
},
200+
size() {
201+
return output.length;
202+
},
203+
};
199204
});
200205
}
201206

0 commit comments

Comments
 (0)