Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: supports copy nested directories/files in symlink #335

Merged
merged 2 commits into from
Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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