Movatterモバイル変換


[0]ホーム

URL:


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

Commit8570383

Browse files
refactor: avoid extra file (#1806)
1 parent6bf471c commit8570383

File tree

2 files changed

+67
-85
lines changed

2 files changed

+67
-85
lines changed

‎lib/cached-child-compiler.js

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
'use strict';
2525

2626
// Import types
27-
/**@typedef {import("webpack/lib/Compiler.js")} WebpackCompiler */
28-
/**@typedef {import("webpack/lib/Compilation.js")} WebpackCompilation */
27+
/**@typedef {import("webpack/lib/Compiler.js")} Compiler */
28+
/**@typedef {import("webpack/lib/Compilation.js")} Compilation */
29+
/**@typedef {import("webpack/lib/FileSystemInfo").Snapshot} Snapshot */
2930
/**@typedef {{hash: string, entry: any, content: string }} ChildCompilationResultEntry */
30-
/**@typedef {import("./file-watcher-api").Snapshot} Snapshot */
3131
/**@typedef {{fileDependencies: string[], contextDependencies: string[], missingDependencies: string[]}} FileDependencies */
3232
/**@typedef {{
3333
dependencies: FileDependencies,
@@ -38,24 +38,23 @@
3838
}} ChildCompilationResult */
3939

4040
const{ HtmlWebpackChildCompiler}=require('./child-compiler');
41-
constfileWatcherApi=require('./file-watcher-api');
4241

4342
/**
4443
* This plugin is a singleton for performance reasons.
4544
* To keep track if a plugin does already exist for the compiler they are cached
4645
* in this map
47-
*@type {WeakMap<WebpackCompiler, PersistentChildCompilerSingletonPlugin>}}
46+
*@type {WeakMap<Compiler, PersistentChildCompilerSingletonPlugin>}}
4847
*/
4948
constcompilerMap=newWeakMap();
5049

5150
classCachedChildCompilation{
5251
/**
53-
*@param {WebpackCompiler} compiler
52+
*@param {Compiler} compiler
5453
*/
5554
constructor(compiler){
5655
/**
5756
*@private
58-
*@type {WebpackCompiler}
57+
*@type {Compiler}
5958
*/
6059
this.compiler=compiler;
6160
// Create a singleton instance for the compiler
@@ -114,6 +113,60 @@ class CachedChildCompilation {
114113
}
115114

116115
classPersistentChildCompilerSingletonPlugin{
116+
/**
117+
*
118+
*@param {{fileDependencies: string[], contextDependencies: string[], missingDependencies: string[]}} fileDependencies
119+
*@param {Compilation} mainCompilation
120+
*@param {number} startTime
121+
*/
122+
staticcreateSnapshot(fileDependencies,mainCompilation,startTime){
123+
returnnewPromise((resolve,reject)=>{
124+
mainCompilation.fileSystemInfo.createSnapshot(
125+
startTime,
126+
fileDependencies.fileDependencies,
127+
fileDependencies.contextDependencies,
128+
fileDependencies.missingDependencies,
129+
null,
130+
(err,snapshot)=>{
131+
if(err){
132+
returnreject(err);
133+
}
134+
resolve(snapshot);
135+
}
136+
);
137+
});
138+
}
139+
140+
/**
141+
* Returns true if the files inside this snapshot
142+
* have not been changed
143+
*
144+
*@param {Snapshot} snapshot
145+
*@param {Compilation} mainCompilation
146+
*@returns {Promise<boolean>}
147+
*/
148+
staticisSnapshotValid(snapshot,mainCompilation){
149+
returnnewPromise((resolve,reject)=>{
150+
mainCompilation.fileSystemInfo.checkSnapshotValid(
151+
snapshot,
152+
(err,isValid)=>{
153+
if(err){
154+
reject(err);
155+
}
156+
resolve(isValid);
157+
}
158+
);
159+
});
160+
}
161+
162+
staticwatchFiles(mainCompilation,fileDependencies){
163+
Object.keys(fileDependencies).forEach((depencyTypes)=>{
164+
fileDependencies[depencyTypes].forEach(fileDependency=>{
165+
mainCompilation[depencyTypes].add(fileDependency);
166+
});
167+
});
168+
}
169+
117170
constructor(){
118171
/**
119172
*@private
@@ -158,7 +211,7 @@ class PersistentChildCompilerSingletonPlugin {
158211

159212
/**
160213
* apply is called by the webpack main compiler during the start phase
161-
*@param {WebpackCompiler} compiler
214+
*@param {Compiler} compiler
162215
*/
163216
apply(compiler){
164217
/**@type Promise<ChildCompilationResult> */
@@ -216,7 +269,7 @@ class PersistentChildCompilerSingletonPlugin {
216269
// this might possibly cause bugs if files were changed inbetween
217270
// compilation start and snapshot creation
218271
compiledEntriesPromise.then((childCompilationResult)=>{
219-
returnfileWatcherApi.createSnapshot(childCompilationResult.dependencies,mainCompilation,compilationStartTime);
272+
returnPersistentChildCompilerSingletonPlugin.createSnapshot(childCompilationResult.dependencies,mainCompilation,compilationStartTime);
220273
}).then((snapshot)=>{
221274
previousFileSystemSnapshot=snapshot;
222275
});
@@ -309,7 +362,7 @@ class PersistentChildCompilerSingletonPlugin {
309362
* Verify that the cache is still valid
310363
*@private
311364
*@param {Snapshot | undefined} snapshot
312-
*@param {WebpackCompilation} mainCompilation
365+
*@param {Compilation} mainCompilation
313366
*@returns {Promise<boolean>}
314367
*/
315368
isCacheValid(snapshot,mainCompilation){
@@ -328,14 +381,14 @@ class PersistentChildCompilerSingletonPlugin {
328381
if(!snapshot){
329382
returnPromise.resolve(false);
330383
}
331-
returnfileWatcherApi.isSnapShotValid(snapshot,mainCompilation);
384+
returnPersistentChildCompilerSingletonPlugin.isSnapshotValid(snapshot,mainCompilation);
332385
}
333386

334387
/**
335388
* Start to compile all templates
336389
*
337390
*@private
338-
*@param {WebpackCompilation} mainCompilation
391+
*@param {Compilation} mainCompilation
339392
*@param {string[]} entries
340393
*@returns {Promise<ChildCompilationResult>}
341394
*/
@@ -366,11 +419,11 @@ class PersistentChildCompilerSingletonPlugin {
366419

367420
/**
368421
*@private
369-
*@param {WebpackCompilation} mainCompilation
422+
*@param {Compilation} mainCompilation
370423
*@param {FileDependencies} files
371424
*/
372425
watchFiles(mainCompilation,files){
373-
fileWatcherApi.watchFiles(mainCompilation,files);
426+
PersistentChildCompilerSingletonPlugin.watchFiles(mainCompilation,files);
374427
}
375428
}
376429

‎lib/file-watcher-api.js

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp