@samitouri / QOS-React-2 / commits / ce40f1dc2f

Use assets API + writeToDisk instead of directly writing to disk (#20402)

Sebastian Markbåge committed Dec 7, 2020 at 20:54 UTC ce40f1dc2f8e0869ae4b484e7248a449efba64c8
3 files changed +18 -10
fixtures/flight/config/webpackDevServer.config.js
+3
@@ -90,6 +90,9 @@ module.exports = function(proxy, allowedHost) {
90 watchOptions: {
91 ignored: ignoredFiles(paths.appSrc),
92 },
93 + writeToDisk: filePath => {
94 + return /react-client-manifest\.json$/.test(filePath);
95 + },
96 https: getHttpsConfig(),
97 host,
98 overlay: false,
fixtures/flight/server/handler.server.js
+1 -1
@@ -10,7 +10,7 @@ module.exports = function(req, res) {
10 import('../src/App.server.js').then(m => {
11 const dist = process.env.NODE_ENV === 'development' ? 'dist' : 'build';
12 readFile(
13 - resolve(__dirname, `../${dist}/react-transport-manifest.json`),
13 + resolve(__dirname, `../${dist}/react-client-manifest.json`),
14 'utf8',
15 (err, data) => {
16 if (err) {
packages/react-transport-dom-webpack/src/ReactFlightWebpackPlugin.js
+14 -9
@@ -7,8 +7,7 @@
7 * @flow
8 */
9
10 -import {mkdirSync, writeFileSync} from 'fs';
11 -import {dirname, resolve, join} from 'path';
10 +import {join} from 'path';
11 import {pathToFileURL} from 'url';
12
13 import asyncLib from 'neo-async';
@@ -48,6 +47,7 @@ type Options = {
47 isServer: boolean,
48 clientReferences?: ClientReferencePath | $ReadOnlyArray<ClientReferencePath>,
49 chunkName?: string,
50 + manifestFilename?: string,
51 };
52
53 const PLUGIN_NAME = 'React Transport Plugin';
@@ -55,6 +55,8 @@ const PLUGIN_NAME = 'React Transport Plugin';
55 export default class ReactFlightWebpackPlugin {
56 clientReferences: $ReadOnlyArray<ClientReferencePath>;
57 chunkName: string;
58 + manifestFilename: string;
59 +
60 constructor(options: Options) {
61 if (!options || typeof options.isServer !== 'boolean') {
62 throw new Error(
@@ -88,6 +90,8 @@ export default class ReactFlightWebpackPlugin {
90 } else {
91 this.chunkName = 'client[index]';
92 }
93 + this.manifestFilename =
94 + options.manifestFilename || 'react-client-manifest.json';
95 }
96
97 apply(compiler: any) {
@@ -189,13 +193,14 @@ export default class ReactFlightWebpackPlugin {
193 });
194 });
195 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 + };
204 });
205 }
206