Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 9e8c921

Browse files
Fatmerosen-vladimirov
authored andcommitted
fix: fix hmr for platform specific files in linked plugins (#946)
* fix: override correctly webpack's watchFileSystem * fix: remove ExtraWatchWebpackPlugin from config files * chore: update demo apps
1 parent f0c62fb commit 9e8c921

File tree

6 files changed

+27
-32
lines changed

6 files changed

+27
-32
lines changed

‎demo/JavaScriptApp/webpack.config.js‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const nsWebpack = require("nativescript-dev-webpack");
55
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
66
const CleanWebpackPlugin = require("clean-webpack-plugin");
77
const CopyWebpackPlugin = require("copy-webpack-plugin");
8-
const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin');
98
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
109
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
1110
const TerserPlugin = require("terser-webpack-plugin");
@@ -236,9 +235,6 @@ module.exports = env => {
236235
}),
237236
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
238237
new nsWebpack.WatchStateLoggerPlugin(),
239-
new ExtraWatchWebpackPlugin({
240-
files: [`node_modules/**/*.${platform}.js`]
241-
})
242238
],
243239
};
244240

‎demo/TypeScriptApp/webpack.config.js‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target
66
const CleanWebpackPlugin = require("clean-webpack-plugin");
77
const CopyWebpackPlugin = require("copy-webpack-plugin");
88
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
9-
const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin');
109
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
1110
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
1211
const TerserPlugin = require("terser-webpack-plugin");
@@ -267,9 +266,6 @@ module.exports = env => {
267266
useTypescriptIncrementalApi: true,
268267
memoryLimit: 4096
269268
}),
270-
new ExtraWatchWebpackPlugin({
271-
files: [`node_modules/**/*.${platform}.ts`]
272-
})
273269
],
274270
};
275271

‎plugins/PlatformFSPlugin.ts‎

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ export class PlatformFSPlugin {
3333
public apply(compiler) {
3434
this.context = compiler.context;
3535
compiler.inputFileSystem = mapFileSystem({
36-
fs: compiler.inputFileSystem,
3736
platform: this.platform,
3837
platforms: this.platforms,
3938
ignore: this.ignore,
40-
context: this.context
39+
context: this.context,
40+
compiler
4141
});
4242
}
4343
}
@@ -46,15 +46,16 @@ export interface MapFileSystemArgs {
4646
/**
4747
* This is the underlying webpack compiler.inputFileSystem, its interface is similar to Node's fs.
4848
*/
49-
readonly fs: any;
5049
readonly context: string;
5150
readonly platform: string;
5251
readonly platforms: ReadonlyArray<string>;
5352
readonly ignore: ReadonlyArray<string>;
53+
readonly compiler: any;
5454
}
5555

5656
export function mapFileSystem(args: MapFileSystemArgs): any {
57-
let { fs, platform, platforms, ignore, context } = args;
57+
let { platform, platforms, ignore, context, compiler } = args;
58+
const fs = compiler.inputFileSystem;
5859
ignore = args.ignore || [];
5960

6061
const minimatchFileFilters = ignore.map(pattern => {
@@ -122,7 +123,8 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
122123
}
123124

124125
const platformSuffix = "." + platform + ".";
125-
mappedFS.watch = function(
126+
const baseWatch = compiler.watchFileSystem.watch;
127+
compiler.watchFileSystem.watch = function(
126128
files,
127129
dirs,
128130
missing,
@@ -135,11 +137,15 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
135137
missingModified,
136138
fileTimestamps,
137139
contextTimestamps
140+
) => void,
141+
callbackUndelayed: (
142+
filename,
143+
timestamp
138144
) => void) {
139145

140146
const mappedFiles = listWithPlatformSpecificFiles(files);
141147

142-
const callbackCalled = function(
148+
const newCallback = function(
143149
err,
144150
filesModified,
145151
contextModified,
@@ -148,13 +154,17 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
148154
contextTimestamps) {
149155

150156
const mappedFilesModified = filterIgnoredFilesAlienFilesAndMap(filesModified);
151-
152157
const mappedTimestamps = new Map();
153-
for(const file in fileTimestamps) {
154-
const timestamp = fileTimestamps[file];
158+
const fileTimestampsAsArray = Array.from(fileTimestamps);
159+
160+
for (const entry of fileTimestampsAsArray) {
161+
const file = entry[0];
162+
const timestamp = entry[1];
155163
mappedTimestamps.set(file, timestamp);
164+
156165
const platformSuffixIndex = file.lastIndexOf(platformSuffix);
157166
if (platformSuffixIndex != -1) {
167+
// file name without platform suffix
158168
const mappedFile = file.substr(0, platformSuffixIndex) + file.substr(platformSuffixIndex + platformSuffix.length - 1);
159169
if (!(mappedFile in fileTimestamps)) {
160170
mappedTimestamps.set(mappedFile, timestamp);
@@ -165,7 +175,12 @@ export function mapFileSystem(args: MapFileSystemArgs): any {
165175
callback.call(this, err, mappedFilesModified, contextModified, missingModified, mappedTimestamps, contextTimestamps);
166176
}
167177

168-
fs.watch(mappedFiles, dirs, missing, startTime, watchOptions, callbackCalled);
178+
const newCallbackUndelayed = function(filename, timestamp) {
179+
compiler.watchFileSystem.inputFileSystem.purge(filename);
180+
callbackUndelayed(filename, timestamp);
181+
};
182+
183+
baseWatch.apply(compiler.watchFileSystem.watch, [mappedFiles, dirs, missing, startTime, watchOptions, newCallback, newCallbackUndelayed]);
169184
}
170185

171186
/**

‎templates/webpack.javascript.js‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const nsWebpack = require("nativescript-dev-webpack");
55
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
66
const CleanWebpackPlugin = require("clean-webpack-plugin");
77
const CopyWebpackPlugin = require("copy-webpack-plugin");
8-
const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin');
98
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
109
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
1110
const TerserPlugin = require("terser-webpack-plugin");
@@ -234,10 +233,7 @@ module.exports = env => {
234233
platforms,
235234
}),
236235
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
237-
new nsWebpack.WatchStateLoggerPlugin(),
238-
new ExtraWatchWebpackPlugin({
239-
files: [`node_modules/**/*.${platform}.js`]
240-
})
236+
new nsWebpack.WatchStateLoggerPlugin()
241237
],
242238
};
243239

‎templates/webpack.typescript.js‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target
66
const CleanWebpackPlugin = require("clean-webpack-plugin");
77
const CopyWebpackPlugin = require("copy-webpack-plugin");
88
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
9-
const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin');
109
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
1110
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
1211
const TerserPlugin = require("terser-webpack-plugin");
@@ -265,9 +264,6 @@ module.exports = env => {
265264
async: false,
266265
useTypescriptIncrementalApi: true,
267266
memoryLimit: 4096
268-
}),
269-
new ExtraWatchWebpackPlugin({
270-
files: [`node_modules/**/*.${platform}.ts`]
271267
})
272268
],
273269
};

‎templates/webpack.vue.js‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const { join, relative, resolve, sep } = require("path");
33
const webpack = require("webpack");
44
const CleanWebpackPlugin = require("clean-webpack-plugin");
55
const CopyWebpackPlugin = require("copy-webpack-plugin");
6-
const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin');
76
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
87
const TerserPlugin = require("terser-webpack-plugin");
98

@@ -258,10 +257,7 @@ module.exports = env => {
258257
platforms,
259258
}),
260259
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
261-
new nsWebpack.WatchStateLoggerPlugin(),
262-
new ExtraWatchWebpackPlugin({
263-
files: [`node_modules/**/*.${platform}.ts`, `node_modules/**/*.${platform}.js`]
264-
})
260+
new nsWebpack.WatchStateLoggerPlugin()
265261
],
266262
};
267263

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /