Skip to content

Commit

Permalink
store build dependencies snapshot in pack
Browse files Browse the repository at this point in the history
add snapshot shortcut for package manager managed paths
add cache.managedPaths
  • Loading branch information
sokra committed Aug 13, 2019
1 parent ada11a2 commit e5cecda
Show file tree
Hide file tree
Showing 17 changed files with 823 additions and 72 deletions.
11 changes: 11 additions & 0 deletions declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ declare namespace NodeJS {
}

declare module "neo-async" {
interface QueueObject<T, E> {
push(item: T): void;
drain: () => void;
error: (err: E) => void;
}

export interface Dictionary<T> {
[key: string]: T;
}
Expand Down Expand Up @@ -104,6 +110,11 @@ declare module "neo-async" {
callback?: AsyncResultObjectCallback<T, E>
): void;

export function queue<T, E>(
worker: AsyncFunction<T, E>,
concurrency?: number
): QueueObject<T, E>;

export const forEach: typeof each;
export const forEachLimit: typeof eachLimit;
}
Expand Down
8 changes: 8 additions & 0 deletions declarations/WebpackOptions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ export interface WebpackOptions {
* via the `definition` "MemoryCacheOptions".
*/
export interface MemoryCacheOptions {
/**
* List of paths that are managed by a package manager and can be trusted to not being modified otherwise
*/
managedPaths?: string[];
/**
* In memory caching
*/
Expand Down Expand Up @@ -480,6 +484,10 @@ export interface FileCacheOptions {
* Time in ms after which idle period the initial cache storing should happen (only for store: 'pack' or 'idle')
*/
idleTimeoutForInitialStore?: number;
/**
* List of paths that are managed by a package manager and can be trusted to not being modified otherwise
*/
managedPaths?: string[];
/**
* Name for the cache. Different names will lead to different coexisting caches.
*/
Expand Down
29 changes: 24 additions & 5 deletions examples/persistent-caching/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
```javascript
console.log(process.env.NODE_ENV);

import "./example.css";
import "react";
import "react-dom";
import "acorn";
Expand All @@ -17,13 +18,31 @@ const path = require("path");
module.exports = (env = "development") => ({
mode: env,
infrastructureLogging: {
// Optional: print more verbose logging about caching
level: "verbose"
},
cache: {
type: "filesystem",

// changing the cacheDirectory is optional,
// by default it will be in `node_modules/.cache`
cacheDirectory: path.resolve(__dirname, ".cache")
cacheDirectory: path.resolve(__dirname, ".cache"),

// Add additional dependencies to the build
buildDependencies: {
// recommended to invalidate cache on config changes
// This also makes all dependencies of this file build dependencies
config: [__filename]
// By default webpack and loaders are build dependencies
}
},
module: {
rules: [
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
}
]
}
});
```
Expand All @@ -33,10 +52,10 @@ module.exports = (env = "development") => ({
```
Hash: 0a1b2c3d4e5f6a7b8c9d
Version: webpack 5.0.0-alpha.19
Asset Size Chunks Chunk Names
output.js 1.78 MiB {0} [emitted] main
Asset Size Chunks Chunk Names
output.js 1.8 MiB {0} [emitted] main
Entrypoint main = output.js
chunk {0} output.js (main) 1.54 MiB (javascript) 1.07 KiB (runtime) [entry]
chunk {0} output.js (main) 1.55 MiB (javascript) 1.07 KiB (runtime) [entry]
> ./example.js main
526 chunk modules
530 chunk modules
```
3 changes: 3 additions & 0 deletions examples/persistent-caching/example.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background: red;
}
1 change: 1 addition & 0 deletions examples/persistent-caching/example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
console.log(process.env.NODE_ENV);

import "./example.css";
import "react";
import "react-dom";
import "acorn";
Expand Down
20 changes: 19 additions & 1 deletion examples/persistent-caching/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,30 @@ const path = require("path");
module.exports = (env = "development") => ({
mode: env,
infrastructureLogging: {
// Optional: print more verbose logging about caching
level: "verbose"
},
cache: {
type: "filesystem",

// changing the cacheDirectory is optional,
// by default it will be in `node_modules/.cache`
cacheDirectory: path.resolve(__dirname, ".cache")
cacheDirectory: path.resolve(__dirname, ".cache"),

// Add additional dependencies to the build
buildDependencies: {
// recommended to invalidate cache on config changes
// This also makes all dependencies of this file build dependencies
config: [__filename]
// By default webpack and loaders are build dependencies
}
},
module: {
rules: [
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
}
]
}
});
4 changes: 3 additions & 1 deletion lib/Compilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,9 @@ class Compilation {
this.compiler = compiler;
this.resolverFactory = compiler.resolverFactory;
this.inputFileSystem = compiler.inputFileSystem;
this.fileSystemInfo = new FileSystemInfo(this.inputFileSystem);
this.fileSystemInfo = new FileSystemInfo(this.inputFileSystem, {
managedPaths: compiler.managedPaths
});
if (compiler.fileTimestamps) {
this.fileSystemInfo.addFileTimestamps(compiler.fileTimestamps);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ class Compiler {
this.recordsOutputPath = null;
this.records = {};
/** @type {Set<string>} */
this.managedPaths = new Set();
/** @type {Set<string>} */
this.removedFiles = new Set();
/** @type {Map<string, FileSystemInfoEntry | null>} */
this.fileTimestamps = new Map();
Expand Down
Loading

0 comments on commit e5cecda

Please sign in to comment.