Skip to content

Commit 6c63529

Browse files
committed
Fixed globbing and now using path.isAbsolute()
1 parent 7584861 commit 6c63529

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

index.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,8 @@ function apply(patterns, opts, compiler) {
3939

4040
// Determine if this is an absolute to
4141
var absDest;
42-
if (os.platform() === 'win32') {
43-
var winRootMatcher = /^[A-z]:\\\\/;
44-
if (winRootMatcher.test(relDest)) {
45-
absDest = relDest;
46-
}
47-
} else {
48-
if (relDest[0] === '/') {
49-
absDest = relDest;
50-
}
42+
if (path.isAbsolute(relDest)) {
43+
absDest = relDest;
5144
}
5245

5346
var forceWrite = !!pattern.force;
@@ -76,7 +69,7 @@ function apply(patterns, opts, compiler) {
7669

7770
return globAsync(relSrc, {cwd: baseDir})
7871
.each(function(relFileSrc) {
79-
72+
8073
// Skip if it matches any of our ignore list
8174
if (shouldIgnore(relFileSrc, ignoreList)) {
8275
return;
@@ -98,8 +91,12 @@ function apply(patterns, opts, compiler) {
9891
}
9992

10093
if (!stat && relFileDirname !== baseDir) {
101-
// If the file is in a subdirectory (from globbing), we should correctly map the dest folder
102-
relFileDest = path.join(path.relative(baseDir, relFileDirname), path.basename(relFileSrc));
94+
if (path.isAbsolute(relFileSrc)) {
95+
// If the file is in a subdirectory (from globbing), we should correctly map the dest folder
96+
relFileDest = path.join(path.relative(baseDir, relFileDirname), path.basename(relFileSrc));
97+
} else {
98+
relFileDest = relFileSrc;
99+
}
103100
} else if (toLooksLikeDirectory(pattern)) {
104101
relFileDest = path.join(relFileDest, path.basename(relFileSrc));
105102
} else {

test/index.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,35 @@ describe('apply function', function() {
194194
.then(done)
195195
.catch(done);
196196
});
197-
197+
198198
it('can use a glob to move a file to the root directory', function(done) {
199199
runEmit({
200-
patterns: [{ from: path.join(HELPER_DIR, '*.txt') }],
200+
patterns: [{ from: '*.txt' }],
201201
expectedAssetKeys: ['file.txt']
202202
})
203203
.then(done)
204204
.catch(done);
205205
});
206206

207207
it('can use a glob to move multiple files to the root directory', function(done) {
208+
runEmit({
209+
patterns: [{ from: '**/*.txt' }],
210+
expectedAssetKeys: ['file.txt', 'directory/directoryfile.txt', 'directory/nested/nestedfile.txt']
211+
})
212+
.then(done)
213+
.catch(done);
214+
});
215+
216+
it('can use a glob with a full path to move a file to the root directory', function(done) {
217+
runEmit({
218+
patterns: [{ from: path.join(HELPER_DIR, '*.txt') }],
219+
expectedAssetKeys: ['file.txt']
220+
})
221+
.then(done)
222+
.catch(done);
223+
});
224+
225+
it('can use a glob with a full path to move multiple files to the root directory', function(done) {
208226
runEmit({
209227
patterns: [{ from: path.join(HELPER_DIR, '**/*.txt') }],
210228
expectedAssetKeys: ['file.txt', 'directory/directoryfile.txt', 'directory/nested/nestedfile.txt']

0 commit comments

Comments
 (0)