Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

copy-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

copy-webpack-plugin - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

6

CHANGELOG.md

@@ -0,1 +1,7 @@

## 0.3.0 (Nov 27, 2015)
* Added `ignore` option that function lie `.gitignore`
* Improved Windows support
## 0.2.0 (Oct 28, 2015)

@@ -2,0 +8,0 @@

49

index.js

@@ -6,5 +6,6 @@ var _ = require('lodash');

var dir = Promise.promisifyAll(require('node-dir'));
var minimatch = require('minimatch');
function apply(patterns, compiler) {
function apply(patterns, opts, compiler) {

@@ -15,2 +16,8 @@ var baseDir = compiler.options.context;

var lastGlobalUpdate = 0;
if (!opts) {
opts = {};
}
var ignoreList = opts.ignore;

@@ -33,8 +40,15 @@ compiler.plugin('emit', function(compilation, cb) {

forceWrite: forceWrite,
lastGlobalUpdate: lastGlobalUpdate
lastGlobalUpdate: lastGlobalUpdate,
ignoreList: ignoreList
});
} else {
// Skip if it matches any of our ignore list
if (shouldIgnore(relSrc, ignoreList)) {
return;
}
fileDependencies.push(absSrc);
if ((path.extname(relDest) === '' || // doesn't have an extension
_.last(relDest) === '/' || // doesn't end in a slash
_.last(relDest) === path.sep || // ends in a path separator
_.last(relDest) === '/' || // ends in a slash (kept for compatibility)
pattern.toType === 'dir') && // is explicitly a dir

@@ -115,11 +129,17 @@ pattern.toType !== 'file') { // is not explicitly a file

var lastGlobalUpdate = opts.lastGlobalUpdate;
var ignoreList = opts.ignoreList;
return dir.filesAsync(absDirSrc)
.each(function(absFileSrc) {
var relFileSrc = absFileSrc.replace(absDirSrc, '');
var relFileSrc = path.relative(absDirSrc, absFileSrc);
var relFileDest = path.join(relDirDest, relFileSrc);
// Skip if it matches any of our ignore list
if (shouldIgnore(relFileSrc, ignoreList)) {
return;
}
// Make sure it doesn't start with the separator
if (_.first(relFileDest) === '/') {
relFileDest = relFileDest.substr(1);
if (_.first(relFileDest) === path.sep) {
relFileDest = relFileDest.slice(1);
}

@@ -137,3 +157,16 @@

module.exports = function(patterns) {
function shouldIgnore(pathName, ignoreList) {
var matched = _.find(ignoreList, function(glob) {
return minimatch(pathName, glob, {
matchBase: true
});
});
if (matched) {
return true;
} else {
return false;
}
}
module.exports = function(patterns, options) {
if (_.isUndefined(patterns)) {

@@ -148,4 +181,4 @@ patterns = [];

return {
apply: apply.bind(this, patterns)
apply: apply.bind(this, patterns, options)
};
};

8

package.json
{
"name": "copy-webpack-plugin",
"version": "0.2.0",
"version": "0.3.0",
"description": "Copy files and directories in webpack",

@@ -23,10 +23,12 @@ "main": "index.js",

"lodash": "^3.10.1",
"minimatch": "^3.0.0",
"node-dir": "^0.1.10"
},
"scripts": {
"test": "mocha"
"test": "node ./node_modules/mocha/bin/mocha"
},
"devDependencies": {
"chai": "^3.4.0"
"chai": "^3.4.0",
"mocha": "^2.3.4"
}
}

@@ -15,4 +15,38 @@ ## Copy Webpack Plugin

`new CopyWebpackPlugin([patterns], options)`
A pattern looks like:
`{ from: 'source', to: 'dest' }`
Pattern properties:
* `from`
- is required
- can be an absolute or path relative to the context
- can be a file or directory
* `to`
- is optional
- is relative to the context root
- defaults to `'/'`
- must be a directory if `from` is a directory
* `toType`
- is optional
- is ignored if `from` is a directory
- defaults to `'file'` if `to` has an extension
- defaults to `'dir'` if `to` doesn't have an extension
* `force`
- is optional
- defaults to `false`
- forces the plugin to overwrite files staged by previous plugins
Available options:
* `ignore`
- an array of files and directories to ignore
- accepts globs
- globs are evaluated on the `from` path, relative to the context
### Examples
```javascript
var CopyWebpackPlugin = require('copy-webpack-plugin');
var path = require('path');

@@ -23,13 +57,36 @@ module.exports = {

new CopyWebpackPlugin([
// File examples
// {context}/file.txt
{ from: 'path/to/file.txt' },
// {context}/path/to/build/file.txt
{ from: 'path/to/file.txt', to: 'path/to/build/file.txt' },
// {context}/path/to/build/directory/file.txt
{ from: 'path/to/file.txt', to: 'path/to/build/directory' },
{ from: 'path/to/file.txt', to: 'file/without/extension', toType: 'file' },
{ from: 'path/to/file.txt', to: 'directory/with/extension.ext', toType: 'dir' },
// Directory examples
// Copy directory contents to {context}/
{ from: 'path/to/directory' },
{ from: 'path/to/directory', to: 'path/to/build/directory' }
])
// Copy directory contents to {context}/path/to/build/directory
{ from: 'path/to/directory', to: 'path/to/build/directory' },
// {context}/file/without/extension
{
from: 'path/to/file.txt',
to: 'file/without/extension',
toType: 'file'
},
// {context}/directory/with/extension.ext/file.txt
{
from: 'path/to/file.txt',
to: 'directory/with/extension.ext',
toType: 'dir'
}
], {
ignore: [
// Doesn't copy any files with a txt extension
'*.txt'
]
})
]

@@ -39,45 +96,10 @@ };

### Common patterns
### Testing
* Copy from file to file. The destination file can be renamed.
[![Build Status](https://drone.io/github.com/kevlened/copy-webpack-plugin/status.png)](https://drone.io/github.com/kevlened/copy-webpack-plugin/latest)
{ from: 'path/to/file.txt', to: 'path/to/build/file.txt' }
Run `npm test`
* Copy from file to directory
{ from: 'path/to/file.txt', to: 'path/to/build/directory' }
* Copy from directory to directory. The destination directory can be renamed.
{ from: 'path/to/directory', to: 'path/to/build/directory' }
### Special cases
* Copy from file to root
{ from: 'path/to/file.txt' }
* Copy from directory to root
{ from: 'path/to/directory' }
* Copy from file to directory that has an extension. If the `to` parameter has an extension, the plugin assumes the target is a file. Provide `toType` to override this behavior.
{ from: 'path/to/file.txt', to: 'directory/with/extension.ext', toType: 'dir' }
* Copy from file to file without an extension. If the `to` parameter doesn't have an extension, the plugin assumes the target is a directory. Provide `toType` to override this behavior.
{ from: 'path/to/file.txt', to: 'file/without/extension', toType: 'file' }
* Overwrite existing file. By default, assets that are staged by previous plugins aren't overwritten. Provide `force` to override this behavior.
{ from: 'path/to/file.txt', force: true }
{ from: 'path/to/directory', force: true }
### Testing
Run `mocha`
### License
MIT

@@ -12,16 +12,16 @@ var expect = require('chai').expect;

function MockCompiler() {
this.options = {
context: HELPER_DIR
};
this.options = {
context: HELPER_DIR
};
}
MockCompiler.prototype.plugin = function(type, fn) {
switch(type) {
case 'emit':
this.emitFn = fn;
break;
case 'after-emit':
this.afterEmitFn = fn;
break;
}
switch(type) {
case 'emit':
this.emitFn = fn;
break;
case 'after-emit':
this.afterEmitFn = fn;
break;
}
};

@@ -31,341 +31,440 @@

// Ideally we pass in patterns and confirm the resulting assets
function run(opts) {
return new Promise(function(resolve, reject) {
var plugin = new CopyWebpackPlugin(opts.patterns);
// Ideally we pass in patterns and confirm the resulting assets
function run(opts) {
return new Promise(function(resolve, reject) {
var plugin = new CopyWebpackPlugin(opts.patterns, opts.options);
// Get a mock compiler to pass to plugin.apply
var compiler = opts.compiler || new MockCompiler();
plugin.apply(compiler);
// Get a mock compiler to pass to plugin.apply
var compiler = opts.compiler || new MockCompiler();
plugin.apply(compiler);
// Call the registered function with a mock compilation and callback
var compilation = _.extend({
errors: [],
assets: {},
fileDependencies: [],
contextDependencies: []
}, opts.compilation);
// Call the registered function with a mock compilation and callback
var compilation = _.extend({
errors: [],
assets: {},
fileDependencies: [],
contextDependencies: []
}, opts.compilation);
// Execute the functions in series
Promise.each([compiler.emitFn, compiler.afterEmitFn], function(fn) {
return new Promise(function(res, rej) {
try {
fn(compilation, res);
} catch(e) {
rej(e);
}
});
})
.then(function() {
if (compilation.errors.length > 0) {
throw compilation.errors[0];
}
resolve(compilation);
})
.catch(reject);
});
}
// Execute the functions in series
Promise.each([compiler.emitFn, compiler.afterEmitFn], function(fn) {
return new Promise(function(res, rej) {
try {
fn(compilation, res);
} catch(e) {
rej(e);
}
});
})
.then(function() {
if (compilation.errors.length > 0) {
throw compilation.errors[0];
}
resolve(compilation);
})
.catch(reject);
});
}
function runEmit(opts) {
return run(opts)
.then(function(compilation) {
if (opts.expectedAssetKeys && opts.expectedAssetKeys.length > 0) {
expect(compilation.assets).to.have.all.keys(opts.expectedAssetKeys);
} else {
expect(compilation.assets).to.be.empty;
}
});
}
function runEmit(opts) {
return run(opts)
.then(function(compilation) {
if (opts.expectedAssetKeys && opts.expectedAssetKeys.length > 0) {
// Replace all paths with platform-specific paths
var expectedAssetKeys = _.map(opts.expectedAssetKeys, path.normalize);
expect(compilation.assets).to.have.all.keys(expectedAssetKeys);
} else {
expect(compilation.assets).to.be.empty;
}
});
}
function runForce(opts) {
opts.compilation = {
assets: {}
};
opts.compilation.assets[opts.existingAsset] = {
source: function() {
return 'existing';
}
};
return run(opts)
.then(function(compilation) {
var assetContent = compilation.assets[opts.existingAsset].source().toString();
expect(assetContent).to.equal(opts.expectedAssetContent);
});
}
function runForce(opts) {
opts.compilation = {
assets: {}
};
opts.compilation.assets[opts.existingAsset] = {
source: function() {
return 'existing';
}
};
return run(opts)
.then(function(compilation) {
var assetContent = compilation.assets[opts.existingAsset].source().toString();
expect(assetContent).to.equal(opts.expectedAssetContent);
});
}
function runChange(opts) {
// Create two test files
fs.writeFileSync(opts.newFileLoc1);
fs.writeFileSync(opts.newFileLoc2);
function runChange(opts) {
// Create two test files
fs.writeFileSync(opts.newFileLoc1);
fs.writeFileSync(opts.newFileLoc2);
// Create a reference to the compiler
var compiler = new MockCompiler();
var compilation = {
errors: [],
assets: {},
fileDependencies: [],
contextDependencies: []
};
return run({
compiler: compiler,
patterns: opts.patterns
})
// mtime is only measured in whole seconds
.delay(1000)
.then(function() {
// Create a reference to the compiler
var compiler = new MockCompiler();
var compilation = {
errors: [],
assets: {},
fileDependencies: [],
contextDependencies: []
};
return run({
compiler: compiler,
patterns: opts.patterns
})
// mtime is only measured in whole seconds
.delay(1000)
.then(function() {
// Change a file
fs.appendFileSync(opts.newFileLoc1, 'extra');
// Change a file
fs.appendFileSync(opts.newFileLoc1, 'extra');
// Trigger another compile
return new Promise(function(res, rej) {
compiler.emitFn(compilation, res);
});
})
.then(function() {
return compilation;
})
.finally(function() {
fs.unlinkSync(opts.newFileLoc1);
fs.unlinkSync(opts.newFileLoc2);
});
}
// Trigger another compile
return new Promise(function(res, rej) {
compiler.emitFn(compilation, res);
});
})
.then(function() {
return compilation;
})
.finally(function() {
fs.unlinkSync(opts.newFileLoc1);
fs.unlinkSync(opts.newFileLoc2);
});
}
describe('error handling', function() {
it('doesn\'t throw an error if no patterns are passed', function(done) {
runEmit({
patterns: undefined,
expectedAssetKeys: []
})
.then(done)
.catch(done);
});
describe('error handling', function() {
it('doesn\'t throw an error if no patterns are passed', function(done) {
runEmit({
patterns: undefined,
expectedAssetKeys: []
})
.then(done)
.catch(done);
});
it('throws an error if the patterns are an object', function() {
var createPluginWithObject = function() {
new CopyWebpackPlugin({});
};
expect(createPluginWithObject).to.throw(Error);
});
it('throws an error if the patterns are an object', function() {
var createPluginWithObject = function() {
new CopyWebpackPlugin({});
};
expect(createPluginWithObject).to.throw(Error);
});
it('throws an error if the patterns are null', function() {
var createPluginWithNull = function() {
new CopyWebpackPlugin(null);
};
expect(createPluginWithNull).to.throw(Error);
});
});
it('throws an error if the patterns are null', function() {
var createPluginWithNull = function() {
new CopyWebpackPlugin(null);
};
expect(createPluginWithNull).to.throw(Error);
});
});
describe('with file in from', function() {
it('can move a file to the root directory', function(done) {
runEmit({
patterns: [{ from: 'file.txt' }],
expectedAssetKeys: ['file.txt']
})
.then(done)
.catch(done);
});
describe('with file in from', function() {
it('can move a file to the root directory', function(done) {
runEmit({
patterns: [{ from: 'file.txt' }],
expectedAssetKeys: ['file.txt']
})
.then(done)
.catch(done);
});
it('can move a file to a new directory without a forward slash', function(done) {
runEmit({
patterns: [{ from: 'file.txt', to: 'newdirectory' }],
expectedAssetKeys: ['newdirectory/file.txt']
})
.then(done)
.catch(done);
});
it('can use an absolute path to move a file to the root directory', function(done) {
var absolutePath = path.resolve(HELPER_DIR, 'file.txt');
runEmit({
patterns: [{ from: absolutePath }],
expectedAssetKeys: ['file.txt']
})
.then(done)
.catch(done);
});
it('can move a file to a new directory with a forward slash', function(done) {
runEmit({
patterns: [{ from: 'file.txt', to: 'newdirectory/' }],
expectedAssetKeys: ['newdirectory/file.txt']
})
.then(done)
.catch(done);
});
it('can move a file to a new directory without a forward slash', function(done) {
runEmit({
patterns: [{ from: 'file.txt', to: 'newdirectory' }],
expectedAssetKeys: ['newdirectory/file.txt']
})
.then(done)
.catch(done);
});
it('can move a file to a new directory with an extension', function(done) {
runEmit({
patterns: [{ from: 'file.txt', to: 'newdirectory.ext', toType: 'dir' }],
expectedAssetKeys: ['newdirectory.ext/file.txt']
})
.then(done)
.catch(done);
});
it('can move a file to a new directory with a forward slash', function(done) {
runEmit({
patterns: [{ from: 'file.txt', to: 'newdirectory/' }],
expectedAssetKeys: ['newdirectory/file.txt']
})
.then(done)
.catch(done);
});
it('can move a file to a new directory with an extension and forward slash', function(done) {
runEmit({
patterns: [{ from: 'file.txt', to: 'newdirectory.ext/' }],
expectedAssetKeys: ['newdirectory.ext/file.txt']
})
.then(done)
.catch(done);
});
it('can move a file to a new directory with an extension', function(done) {
runEmit({
patterns: [{ from: 'file.txt', to: 'newdirectory.ext', toType: 'dir' }],
expectedAssetKeys: ['newdirectory.ext/file.txt']
})
.then(done)
.catch(done);
});
it('can move a file to a new file with a different name', function(done) {
runEmit({
patterns: [{ from: 'file.txt', to: 'newname.txt' }],
expectedAssetKeys: ['newname.txt']
})
.then(done)
.catch(done);
});
it('can move a file to a new directory with an extension and forward slash', function(done) {
runEmit({
patterns: [{ from: 'file.txt', to: 'newdirectory.ext/' }],
expectedAssetKeys: ['newdirectory.ext/file.txt']
})
.then(done)
.catch(done);
});
it('can move a file to a new file with no extension', function(done) {
runEmit({
patterns: [{ from: 'file.txt', to: 'newname', toType: 'file' }],
expectedAssetKeys: ['newname']
})
.then(done)
.catch(done);
});
it('can move a file to a new file with a different name', function(done) {
runEmit({
patterns: [{ from: 'file.txt', to: 'newname.txt' }],
expectedAssetKeys: ['newname.txt']
})
.then(done)
.catch(done);
});
it('can move a nested file to the root directory', function(done) {
runEmit({
patterns: [{ from: 'directory/directoryfile.txt' }],
expectedAssetKeys: ['directoryfile.txt']
})
.then(done)
.catch(done);
});
it('can move a file to a new file with no extension', function(done) {
runEmit({
patterns: [{ from: 'file.txt', to: 'newname', toType: 'file' }],
expectedAssetKeys: ['newname']
})
.then(done)
.catch(done);
});
it('can move a nested file to a new directory', function(done) {
runEmit({
patterns: [{ from: 'directory/directoryfile.txt', to: 'newdirectory' }],
expectedAssetKeys: ['newdirectory/directoryfile.txt']
})
.then(done)
.catch(done);
});
it('can move a nested file to the root directory', function(done) {
runEmit({
patterns: [{ from: 'directory/directoryfile.txt' }],
expectedAssetKeys: ['directoryfile.txt']
})
.then(done)
.catch(done);
});
it('won\'t overwrite a file already in the compilation', function(done) {
runForce({
patterns: [{ from: 'file.txt' }],
existingAsset: 'file.txt',
expectedAssetContent: 'existing'
})
.then(done)
.catch(done);
});
it('can use an absolute path to move a nested file to the root directory', function(done) {
var absolutePath = path.resolve(HELPER_DIR, 'directory', 'directoryfile.txt');
runEmit({
patterns: [{ from: absolutePath }],
expectedAssetKeys: ['directoryfile.txt']
})
.then(done)
.catch(done);
});
it('can force overwrite of a file already in the compilation', function(done) {
runForce({
patterns: [{ from: 'file.txt', force: true }],
existingAsset: 'file.txt',
expectedAssetContent: 'new'
})
.then(done)
.catch(done);
});
it('can move a nested file to a new directory', function(done) {
runEmit({
patterns: [{ from: 'directory/directoryfile.txt', to: 'newdirectory' }],
expectedAssetKeys: ['newdirectory/directoryfile.txt']
})
.then(done)
.catch(done);
});
it('adds the file to the watch list', function(done) {
run({
patterns: [{ from: 'file.txt' }]
})
.then(function(compilation) {
var absFrom = path.join(HELPER_DIR, 'file.txt');
expect(compilation.fileDependencies).to.have.members([absFrom]);
})
.then(done)
.catch(done);
});
it('can use an absolute path to move a nested file to a new directory', function(done) {
var absolutePath = path.resolve(HELPER_DIR, 'directory', 'directoryfile.txt');
runEmit({
patterns: [{ from: absolutePath, to: 'newdirectory' }],
expectedAssetKeys: ['newdirectory/directoryfile.txt']
})
.then(done)
.catch(done);
});
it('only include files that have changed', function(done) {
runChange({
patterns: [{ from: 'tempfile1.txt' }, { from: 'tempfile2.txt' }],
newFileLoc1: path.join(HELPER_DIR, 'tempfile1.txt'),
newFileLoc2: path.join(HELPER_DIR, 'tempfile2.txt')
})
.then(function(compilation) {
expect(compilation.assets).to.have.key('tempfile1.txt');
expect(compilation.assets).not.to.have.key('tempfile2.txt');
})
.then(done)
.catch(done);
});
});
it('won\'t overwrite a file already in the compilation', function(done) {
runForce({
patterns: [{ from: 'file.txt' }],
existingAsset: 'file.txt',
expectedAssetContent: 'existing'
})
.then(done)
.catch(done);
});
describe('with directory in from', function() {
it('can move a directory\'s contents to the root directory', function(done) {
runEmit({
patterns: [{ from: 'directory' }],
expectedAssetKeys: ['directoryfile.txt', 'nested/nestedfile.txt']
})
.then(done)
.catch(done);
});
it('can force overwrite of a file already in the compilation', function(done) {
runForce({
patterns: [{ from: 'file.txt', force: true }],
existingAsset: 'file.txt',
expectedAssetContent: 'new'
})
.then(done)
.catch(done);
});
it('can move a directory\'s contents to a new directory', function(done) {
runEmit({
patterns: [{ from: 'directory', to: 'newdirectory' }],
expectedAssetKeys: ['newdirectory/directoryfile.txt','newdirectory/nested/nestedfile.txt']
})
.then(done)
.catch(done);
});
it('adds the file to the watch list', function(done) {
run({
patterns: [{ from: 'file.txt' }]
})
.then(function(compilation) {
var absFrom = path.join(HELPER_DIR, 'file.txt');
expect(compilation.fileDependencies).to.have.members([absFrom]);
})
.then(done)
.catch(done);
});
it('can move a nested directory\'s contents to the root directory', function(done) {
runEmit({
patterns: [{ from: 'directory/nested' }],
expectedAssetKeys: ['nestedfile.txt']
})
.then(done)
.catch(done);
});
it('only include files that have changed', function(done) {
runChange({
patterns: [{ from: 'tempfile1.txt' }, { from: 'tempfile2.txt' }],
newFileLoc1: path.join(HELPER_DIR, 'tempfile1.txt'),
newFileLoc2: path.join(HELPER_DIR, 'tempfile2.txt')
})
.then(function(compilation) {
expect(compilation.assets).to.have.key('tempfile1.txt');
expect(compilation.assets).not.to.have.key('tempfile2.txt');
})
.then(done)
.catch(done);
});
});
it('can move a nested directory\'s contents to a new directory', function(done) {
runEmit({
patterns: [{ from: 'directory/nested', to: 'newdirectory' }],
expectedAssetKeys: ['newdirectory/nestedfile.txt']
})
.then(done)
.catch(done);
});
describe('with directory in from', function() {
it('can move a directory\'s contents to the root directory', function(done) {
runEmit({
patterns: [{ from: 'directory' }],
expectedAssetKeys: ['directoryfile.txt', 'nested/nestedfile.txt']
})
.then(done)
.catch(done);
});
it('won\'t overwrite a file already in the compilation', function(done) {
runForce({
patterns: [{ from: 'directory' }],
existingAsset: 'directoryfile.txt',
expectedAssetContent: 'existing'
})
.then(done)
.catch(done);
});
it('can use an absolute path to move a directory\'s contents to the root directory', function(done) {
var absolutePath = path.resolve(HELPER_DIR, 'directory');
runEmit({
patterns: [{ from: absolutePath }],
expectedAssetKeys: ['directoryfile.txt', 'nested/nestedfile.txt']
})
.then(done)
.catch(done);
});
it('can force overwrite of a file already in the compilation', function(done) {
runForce({
patterns: [{ from: 'directory', force: true }],
existingAsset: 'directoryfile.txt',
expectedAssetContent: 'new'
})
.then(done)
.catch(done);
});
it('can move a directory\'s contents to a new directory', function(done) {
runEmit({
patterns: [{ from: 'directory', to: 'newdirectory' }],
expectedAssetKeys: ['newdirectory/directoryfile.txt','newdirectory/nested/nestedfile.txt']
})
.then(done)
.catch(done);
});
it('adds the directory to the watch list', function(done) {
run({
patterns: [{ from: 'directory' }]
})
.then(function(compilation) {
var absFrom = path.join(HELPER_DIR, 'directory');
expect(compilation.contextDependencies).to.have.members([absFrom]);
})
.then(done)
.catch(done);
});
it('can move a nested directory\'s contents to the root directory', function(done) {
runEmit({
patterns: [{ from: 'directory/nested' }],
expectedAssetKeys: ['nestedfile.txt']
})
.then(done)
.catch(done);
});
it('only include files that have changed', function(done) {
runChange({
patterns: [{ from: 'directory' }],
newFileLoc1: path.join(HELPER_DIR, 'directory', 'tempfile1.txt'),
newFileLoc2: path.join(HELPER_DIR, 'directory', 'tempfile2.txt')
})
.then(function(compilation) {
expect(compilation.assets).to.have.key('tempfile1.txt');
expect(compilation.assets).not.to.have.key('tempfile2.txt');
})
.then(done)
.catch(done);
});
});
it('can move a nested directory\'s contents to a new directory', function(done) {
runEmit({
patterns: [{ from: 'directory/nested', to: 'newdirectory' }],
expectedAssetKeys: ['newdirectory/nestedfile.txt']
})
.then(done)
.catch(done);
});
it('can use an absolute path to move a nested directory\'s contents to a new directory', function(done) {
var absolutePath = path.resolve(HELPER_DIR, 'directory', 'nested');
runEmit({
patterns: [{ from: absolutePath, to: 'newdirectory' }],
expectedAssetKeys: ['newdirectory/nestedfile.txt']
})
.then(done)
.catch(done);
});
it('won\'t overwrite a file already in the compilation', function(done) {
runForce({
patterns: [{ from: 'directory' }],
existingAsset: 'directoryfile.txt',
expectedAssetContent: 'existing'
})
.then(done)
.catch(done);
});
it('can force overwrite of a file already in the compilation', function(done) {
runForce({
patterns: [{ from: 'directory', force: true }],
existingAsset: 'directoryfile.txt',
expectedAssetContent: 'new'
})
.then(done)
.catch(done);
});
it('adds the directory to the watch list', function(done) {
run({
patterns: [{ from: 'directory' }]
})
.then(function(compilation) {
var absFrom = path.join(HELPER_DIR, 'directory');
expect(compilation.contextDependencies).to.have.members([absFrom]);
})
.then(done)
.catch(done);
});
it('only include files that have changed', function(done) {
runChange({
patterns: [{ from: 'directory' }],
newFileLoc1: path.join(HELPER_DIR, 'directory', 'tempfile1.txt'),
newFileLoc2: path.join(HELPER_DIR, 'directory', 'tempfile2.txt')
})
.then(function(compilation) {
expect(compilation.assets).to.have.key('tempfile1.txt');
expect(compilation.assets).not.to.have.key('tempfile2.txt');
})
.then(done)
.catch(done);
});
});
describe('options', function() {
describe('ignore', function() {
it('ignores files when from is a file', function(done) {
runEmit({
patterns: [
{ from: 'file.txt' },
{ from: 'directory/directoryfile.txt' }
],
options: {
ignore: [
'file.*'
]
},
expectedAssetKeys: ['directoryfile.txt']
})
.then(done)
.catch(done);
});
it('ignores files when from is a directory', function(done) {
runEmit({
patterns: [{ from: 'directory' }],
options: {
ignore: [
'*/nestedfile.*'
]
},
expectedAssetKeys: ['directoryfile.txt']
})
.then(done)
.catch(done);
});
it('ignores files with a certain extension', function(done) {
runEmit({
patterns: [{ from: 'directory' }],
options: {
ignore: [
'*.txt'
]
},
expectedAssetKeys: []
})
.then(done)
.catch(done);
});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc