Skip to content

Commit

Permalink
feat: use compiler.inputFileSystem instead fs (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored and michael-ciniawsky committed Jan 29, 2018
1 parent ea0c05f commit 158f821
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -31,6 +31,7 @@
"babel-preset-es2015": "^6.6.0",
"chai": "^3.4.0",
"eslint": "^2.9.0",
"enhanced-resolve": "^3.4.1",
"mocha": "^2.4.5",
"ncp": "^2.0.0",
"standard-version": "^4.2.0",
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Expand Up @@ -74,6 +74,7 @@ function CopyWebpackPlugin(patterns = [], options = {}) {
fileDependencies,
contextDependencies,
context,
inputFileSystem: compiler.inputFileSystem,
output: compiler.options.output.path,
ignore: options.ignore || [],
copyUnmodified: options.copyUnmodified,
Expand Down
5 changes: 2 additions & 3 deletions src/preProcessPattern.js
@@ -1,4 +1,3 @@
import fs from 'fs';
import pify from 'pify';
import path from 'path';
import isGlob from 'is-glob';
Expand All @@ -9,7 +8,7 @@ import isObject from './utils/isObject';
const isTemplateLike = /(\[ext\])|(\[name\])|(\[path\])|(\[folder\])|(\[emoji(:\d+)?\])|(\[(\w+:)?hash(:\w+)?(:\d+)?\])|(\[\d+\])/;

export default function preProcessPattern(globalRef, pattern) {
const {info, debug, warning, context,
const {info, debug, warning, context, inputFileSystem,
fileDependencies, contextDependencies, compilation} = globalRef;

pattern = typeof pattern === 'string' ? {
Expand Down Expand Up @@ -59,7 +58,7 @@ export default function preProcessPattern(globalRef, pattern) {

debug(`determined '${pattern.from}' to be read from '${pattern.absoluteFrom}'`);

return pify(fs.stat)(pattern.absoluteFrom)
return pify(inputFileSystem).stat(pattern.absoluteFrom)
.catch(() => {
// If from doesn't appear to be a glob, then log a warning
if (isGlob(pattern.from) || pattern.from.indexOf('*') !== -1) {
Expand Down
7 changes: 3 additions & 4 deletions src/writeFile.js
@@ -1,4 +1,3 @@
import fs from 'fs';
import pify from 'pify';
import loaderUtils from 'loader-utils';
import path from 'path';
Expand All @@ -8,9 +7,9 @@ import { name, version } from '../package.json';
import findCacheDir from 'find-cache-dir';

export default function writeFile(globalRef, pattern, file) {
const {info, debug, compilation, fileDependencies, written, copyUnmodified} = globalRef;
const {info, debug, compilation, fileDependencies, written, inputFileSystem, copyUnmodified} = globalRef;

return pify(fs.stat)(file.absoluteFrom)
return pify(inputFileSystem).stat(file.absoluteFrom)
.then((stat) => {
// We don't write empty directories
if (stat.isDirectory()) {
Expand All @@ -23,7 +22,7 @@ export default function writeFile(globalRef, pattern, file) {
}

info(`reading ${file.absoluteFrom} to write to assets`);
return pify(fs.readFile)(file.absoluteFrom)
return pify(inputFileSystem).readFile(file.absoluteFrom)
.then((content) => {
if (pattern.transform) {
const transform = (content, absoluteFrom) => {
Expand Down
4 changes: 4 additions & 0 deletions tests/index.js
Expand Up @@ -2,6 +2,8 @@
import {
expect
} from 'chai';
import NodeJsInputFileSystem from 'enhanced-resolve/lib/NodeJsInputFileSystem';
import CachedInputFileSystem from 'enhanced-resolve/lib/CachedInputFileSystem';

// ensure we don't mess up classic imports
const CopyWebpackPlugin = require('./../dist/index');
Expand Down Expand Up @@ -32,6 +34,8 @@ class MockCompiler {
};
}

this.inputFileSystem = new CachedInputFileSystem(new NodeJsInputFileSystem(), 0);

this.outputFileSystem = {
constructor: {
name: 'NotMemoryFileSystem'
Expand Down

0 comments on commit 158f821

Please sign in to comment.