Skip to content

Commit

Permalink
feat: supports copy nested directories/files in symlink (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Feb 18, 2019
1 parent 2f3ee34 commit f551c0d
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 8 deletions.
28 changes: 21 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/processPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function processPattern(globalRef, pattern) {
const globOptions = Object.assign(
{
cwd: pattern.context,
follow: true,
},
pattern.globOptions || {}
);
Expand Down
76 changes: 75 additions & 1 deletion test/CopyPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ describe('apply function', () => {
// Get a mock compiler to pass to plugin.apply
const compiler = opts.compiler || new MockCompiler();

const isWin = process.platform === 'win32';

if (!opts.symlink || isWin) {
if (!opts.options) {
// eslint-disable-next-line no-param-reassign
opts.options = {};
}

if (!opts.options.ignore) {
// eslint-disable-next-line no-param-reassign
opts.options.ignore = [];
}

opts.options.ignore.push('symlink/**/*', 'file-ln.txt', 'directory-ln');
}

new CopyPlugin(opts.patterns, opts.options).apply(compiler);

// Call the registered function with a mock compilation and callback
Expand Down Expand Up @@ -657,6 +673,31 @@ describe('apply function', () => {
.then(done)
.catch(done);
});

it('can use a glob to move a file to the root directory from symbolic link', (done) => {
runEmit({
// Windows doesn't support symbolic link
symlink: true,
expectedAssetKeys:
process.platform === 'win32'
? []
: [
'symlink/directory-ln/file.txt',
'symlink/directory-ln/nested-directory/file-in-nested-directory.txt',
'symlink/directory/file.txt',
'symlink/directory/nested-directory/file-in-nested-directory.txt',
'symlink/file-ln.txt',
'symlink/file.txt',
],
patterns: [
{
from: 'symlink/**/*.txt',
},
],
})
.then(done)
.catch(done);
});
});

describe('with file in from', () => {
Expand Down Expand Up @@ -1181,7 +1222,7 @@ describe('apply function', () => {
patterns: [
{
from: '**/*',
ignore: ['file.*'],
ignore: ['file.*', 'file-in-nested-directory.*'],
},
],
})
Expand Down Expand Up @@ -1275,6 +1316,21 @@ describe('apply function', () => {
.then(done)
.catch(done);
});

it('can move a file (symbolic link) to the root directory', (done) => {
// Windows doesn't support symbolic link
runEmit({
symlink: true,
expectedAssetKeys: process.platform === 'win32' ? [] : ['file-ln.txt'],
patterns: [
{
from: 'symlink/file-ln.txt',
},
],
})
.then(done)
.catch(done);
});
});

describe('with directory in from', () => {
Expand Down Expand Up @@ -1612,6 +1668,24 @@ describe('apply function', () => {
.then(done)
.catch(done);
});

it("can move a directory's contents to the root directory from symbolic link", (done) => {
runEmit({
// Windows doesn't support symbolic link
symlink: true,
expectedAssetKeys:
process.platform === 'win32'
? []
: ['file.txt', 'nested-directory/file-in-nested-directory.txt'],
patterns: [
{
from: 'symlink/directory-ln',
},
],
})
.then(done)
.catch(done);
});
});

describe('with simple string patterns', () => {
Expand Down
1 change: 1 addition & 0 deletions test/helpers/symlink/directory-ln
Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/helpers/symlink/file-ln.txt
1 change: 1 addition & 0 deletions test/helpers/symlink/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data

0 comments on commit f551c0d

Please sign in to comment.