Skip to content

Commit

Permalink
fix: better to determine when glob is used
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Dec 9, 2019
1 parent 51c3680 commit 4826e56
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 9 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ module.exports = {
'/absolute/path/to/dir',
'**/*',
{ glob: '**/*', dot: false },
{
from: '**/*',
globOptions: {
dot: false,
},
},
]),
],
};
Expand All @@ -122,8 +128,14 @@ Output path.
module.exports = {
plugins: [
new CopyPlugin([
{ from: '**/*', to: 'relative/path/to/dest/' },
{ from: '**/*', to: '/absolute/path/to/dest/' },
{
from: '**/*',
to: 'relative/path/to/dest/',
},
{
from: '**/*',
to: '/absolute/path/to/dest/',
},
]),
],
};
Expand Down
22 changes: 15 additions & 7 deletions src/preProcessPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ export default function preProcessPattern(globalRef, pattern) {

pattern =
typeof pattern === 'string'
? {
from: pattern,
}
? { from: pattern }
: Object.assign({}, pattern);

if (pattern.from === '') {
Expand All @@ -42,7 +40,8 @@ export default function preProcessPattern(globalRef, pattern) {
pattern.context = path.join(context, pattern.context);
}

const isFromGlobPatten = isObject(pattern.from) && pattern.from.glob;
const isFromGlobPatten =
(isObject(pattern.from) && pattern.from.glob) || pattern.globOptions;
// Todo remove this in next major
const isToDirectory =
path.extname(pattern.to) === '' || pattern.to.slice(-1) === path.sep;
Expand Down Expand Up @@ -76,12 +75,21 @@ export default function preProcessPattern(globalRef, pattern) {

pattern.fromType = 'glob';

const globOptions = Object.assign({}, pattern.from);
const globOptions = Object.assign(
{},
pattern.globOptions ? pattern.globOptions : pattern.from
);
delete globOptions.glob;

pattern.glob = normalize(pattern.context, pattern.from.glob);
pattern.absoluteFrom = path.resolve(
pattern.context,
pattern.globOptions ? pattern.from : pattern.from.glob
);
pattern.glob = normalize(
pattern.context,
pattern.globOptions ? pattern.from : pattern.from.glob
);
pattern.globOptions = globOptions;
pattern.absoluteFrom = path.resolve(pattern.context, pattern.from.glob);

return Promise.resolve(pattern);
}
Expand Down
32 changes: 32 additions & 0 deletions test/from-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,5 +518,37 @@ describe('from option', () => {
.then(done)
.catch(done);
});

it('should move files with the "globOptions" option', (done) => {
runEmit({
expectedAssetKeys: ['.file.txt', 'file.txt'],
patterns: [
{
from: '*.txt',
globOptions: {
dot: true,
},
},
],
})
.then(done)
.catch(done);
});

it('should move files with the "globOptions" option #2', (done) => {
runEmit({
expectedAssetKeys: ['file.txt'],
patterns: [
{
from: '*.txt',
globOptions: {
dot: false,
},
},
],
})
.then(done)
.catch(done);
});
});
});

0 comments on commit 4826e56

Please sign in to comment.