Skip to content

Commit f551c0d

Browse files
authoredFeb 18, 2019
feat: supports copy nested directories/files in symlink (#335)
1 parent 2f3ee34 commit f551c0d

File tree

8 files changed

+100
-8
lines changed

8 files changed

+100
-8
lines changed
 

‎package-lock.json

+21-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/processPattern.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default function processPattern(globalRef, pattern) {
1111
const globOptions = Object.assign(
1212
{
1313
cwd: pattern.context,
14+
follow: true,
1415
},
1516
pattern.globOptions || {}
1617
);

‎test/CopyPlugin.test.js

+75-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ describe('apply function', () => {
8585
// Get a mock compiler to pass to plugin.apply
8686
const compiler = opts.compiler || new MockCompiler();
8787

88+
const isWin = process.platform === 'win32';
89+
90+
if (!opts.symlink || isWin) {
91+
if (!opts.options) {
92+
// eslint-disable-next-line no-param-reassign
93+
opts.options = {};
94+
}
95+
96+
if (!opts.options.ignore) {
97+
// eslint-disable-next-line no-param-reassign
98+
opts.options.ignore = [];
99+
}
100+
101+
opts.options.ignore.push('symlink/**/*', 'file-ln.txt', 'directory-ln');
102+
}
103+
88104
new CopyPlugin(opts.patterns, opts.options).apply(compiler);
89105

90106
// Call the registered function with a mock compilation and callback
@@ -657,6 +673,31 @@ describe('apply function', () => {
657673
.then(done)
658674
.catch(done);
659675
});
676+
677+
it('can use a glob to move a file to the root directory from symbolic link', (done) => {
678+
runEmit({
679+
// Windows doesn't support symbolic link
680+
symlink: true,
681+
expectedAssetKeys:
682+
process.platform === 'win32'
683+
? []
684+
: [
685+
'symlink/directory-ln/file.txt',
686+
'symlink/directory-ln/nested-directory/file-in-nested-directory.txt',
687+
'symlink/directory/file.txt',
688+
'symlink/directory/nested-directory/file-in-nested-directory.txt',
689+
'symlink/file-ln.txt',
690+
'symlink/file.txt',
691+
],
692+
patterns: [
693+
{
694+
from: 'symlink/**/*.txt',
695+
},
696+
],
697+
})
698+
.then(done)
699+
.catch(done);
700+
});
660701
});
661702

662703
describe('with file in from', () => {
@@ -1181,7 +1222,7 @@ describe('apply function', () => {
11811222
patterns: [
11821223
{
11831224
from: '**/*',
1184-
ignore: ['file.*'],
1225+
ignore: ['file.*', 'file-in-nested-directory.*'],
11851226
},
11861227
],
11871228
})
@@ -1275,6 +1316,21 @@ describe('apply function', () => {
12751316
.then(done)
12761317
.catch(done);
12771318
});
1319+
1320+
it('can move a file (symbolic link) to the root directory', (done) => {
1321+
// Windows doesn't support symbolic link
1322+
runEmit({
1323+
symlink: true,
1324+
expectedAssetKeys: process.platform === 'win32' ? [] : ['file-ln.txt'],
1325+
patterns: [
1326+
{
1327+
from: 'symlink/file-ln.txt',
1328+
},
1329+
],
1330+
})
1331+
.then(done)
1332+
.catch(done);
1333+
});
12781334
});
12791335

12801336
describe('with directory in from', () => {
@@ -1612,6 +1668,24 @@ describe('apply function', () => {
16121668
.then(done)
16131669
.catch(done);
16141670
});
1671+
1672+
it("can move a directory's contents to the root directory from symbolic link", (done) => {
1673+
runEmit({
1674+
// Windows doesn't support symbolic link
1675+
symlink: true,
1676+
expectedAssetKeys:
1677+
process.platform === 'win32'
1678+
? []
1679+
: ['file.txt', 'nested-directory/file-in-nested-directory.txt'],
1680+
patterns: [
1681+
{
1682+
from: 'symlink/directory-ln',
1683+
},
1684+
],
1685+
})
1686+
.then(done)
1687+
.catch(done);
1688+
});
16151689
});
16161690

16171691
describe('with simple string patterns', () => {

‎test/helpers/symlink/directory-ln

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./directory/

‎test/helpers/symlink/directory/file.txt

Whitespace-only changes.

‎test/helpers/symlink/directory/nested-directory/file-in-nested-directory.txt

Whitespace-only changes.

‎test/helpers/symlink/file-ln.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
file.txt

‎test/helpers/symlink/file.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data

0 commit comments

Comments
 (0)
Please sign in to comment.