-
-
Notifications
You must be signed in to change notification settings - Fork 283
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
fix #231 allow square brackets in path #264
Changes from all commits
179e339
9b842b0
8c4405c
a065c7f
d9e9d32
0ffc4f7
e19b4ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const mkdirp = require('mkdirp'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const removeIllegalCharacterForWindows = require('../tests/utils/removeIllegalCharacterForWindows'); | ||
|
||
const baseDir = 'compiled_tests/helpers'; | ||
|
||
const specialFiles = { | ||
'[special?directory]/nested/nestedfile.txt': '', | ||
'[special?directory]/(special-*file).txt': 'special', | ||
'[special?directory]/directoryfile.txt': 'new' | ||
}; | ||
|
||
Object.keys(specialFiles).forEach(function (originFile) { | ||
const file = removeIllegalCharacterForWindows(originFile); | ||
const dir = path.dirname(file); | ||
mkdirp.sync(path.join(baseDir, dir)); | ||
fs.writeFileSync(path.join(baseDir, file), specialFiles[originFile]); | ||
}); | ||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ import cacache from 'cacache'; | |
import isGzip from 'is-gzip'; | ||
import zlib from 'zlib'; | ||
|
||
import removeIllegalCharacterForWindows from './utils/removeIllegalCharacterForWindows'; | ||
|
||
const BUILD_DIR = path.join(__dirname, 'build'); | ||
const HELPER_DIR = path.join(__dirname, 'helpers'); | ||
const TEMP_DIR = path.join(__dirname, 'tempdir'); | ||
|
@@ -58,6 +60,13 @@ describe('apply function', () => { | |
// Ideally we pass in patterns and confirm the resulting assets | ||
const run = (opts) => { | ||
return new Promise((resolve, reject) => { | ||
if (Array.isArray(opts.patterns)) { | ||
opts.patterns.forEach(function (pattern) { | ||
if (pattern.context) { | ||
pattern.context = removeIllegalCharacterForWindows(pattern.context); | ||
} | ||
}); | ||
} | ||
const plugin = CopyWebpackPlugin(opts.patterns, opts.options); | ||
|
||
// Get a mock compiler to pass to plugin.apply | ||
|
@@ -109,7 +118,7 @@ describe('apply function', () => { | |
return run(opts) | ||
.then((compilation) => { | ||
if (opts.expectedAssetKeys && opts.expectedAssetKeys.length > 0) { | ||
expect(compilation.assets).to.have.all.keys(opts.expectedAssetKeys); | ||
expect(compilation.assets).to.have.all.keys(opts.expectedAssetKeys.map(removeIllegalCharacterForWindows)); | ||
} else { | ||
expect(compilation.assets).to.deep.equal({}); | ||
} | ||
|
@@ -268,6 +277,7 @@ describe('apply function', () => { | |
it('can use a glob to move multiple files to the root directory', (done) => { | ||
runEmit({ | ||
expectedAssetKeys: [ | ||
'[!]/hello.txt', | ||
'binextension.bin', | ||
'file.txt', | ||
'file.txt.gz', | ||
|
@@ -289,6 +299,7 @@ describe('apply function', () => { | |
it('can use a glob to move multiple files to a non-root directory', (done) => { | ||
runEmit({ | ||
expectedAssetKeys: [ | ||
'nested/[!]/hello.txt', | ||
'nested/binextension.bin', | ||
'nested/file.txt', | ||
'nested/file.txt.gz', | ||
|
@@ -405,6 +416,7 @@ describe('apply function', () => { | |
it('can use a glob with a full path to move multiple files to the root directory', (done) => { | ||
runEmit({ | ||
expectedAssetKeys: [ | ||
'[!]/hello.txt', | ||
'file.txt', | ||
'directory/directoryfile.txt', | ||
'directory/nested/nestedfile.txt', | ||
|
@@ -423,6 +435,7 @@ describe('apply function', () => { | |
it('can use a glob to move multiple files to a non-root directory with name, hash and ext', (done) => { | ||
runEmit({ | ||
expectedAssetKeys: [ | ||
'nested/[!]/hello-d41d8c.txt', | ||
'nested/binextension-d41d8c.bin', | ||
'nested/file-22af64.txt', | ||
'nested/file.txt-5b311c.gz', | ||
|
@@ -445,13 +458,14 @@ describe('apply function', () => { | |
it('can flatten or normalize glob matches', (done) => { | ||
runEmit({ | ||
expectedAssetKeys: [ | ||
'[!]-hello.txt', | ||
'[special?directory]-(special-*file).txt', | ||
'[special?directory]-directoryfile.txt', | ||
'directory-directoryfile.txt' | ||
], | ||
patterns: [{ | ||
from: '*/*.*', | ||
test: /([^\/]+)\/([^\/]+)\.\w+$/, | ||
test: `([^\\${path.sep}]+)\\${path.sep}([^\\${path.sep}]+)\\.\\w+$`, | ||
to: '[1]-[2].[ext]' | ||
}] | ||
}) | ||
|
@@ -887,6 +901,7 @@ describe('apply function', () => { | |
it('ignores files in pattern', (done) => { | ||
runEmit({ | ||
expectedAssetKeys: [ | ||
'[!]/hello.txt', | ||
'binextension.bin', | ||
'directory/directoryfile.txt', | ||
'directory/nested/nestedfile.txt', | ||
|
@@ -984,7 +999,7 @@ describe('apply function', () => { | |
'nested/nestedfile.txt' | ||
], | ||
patterns: [{ | ||
from: '[special?directory]' | ||
from: (path.sep === '/' ? '[special?directory]' : '[specialdirectory]') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The @evilebottnawi A Windows CI instance would probably be very useful for this plugin since windows pathing is vastly different than linux/MacOS/etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @clydin we already use |
||
}] | ||
}) | ||
.then(done) | ||
|
@@ -1324,6 +1339,7 @@ describe('apply function', () => { | |
it('ignores files that start with a dot', (done) => { | ||
runEmit({ | ||
expectedAssetKeys: [ | ||
'[!]/hello.txt', | ||
'binextension.bin', | ||
'file.txt', | ||
'file.txt.gz', | ||
|
@@ -1384,13 +1400,14 @@ describe('apply function', () => { | |
it('ignores nested directory', (done) => { | ||
runEmit({ | ||
expectedAssetKeys: [ | ||
'[!]/hello.txt', | ||
'binextension.bin', | ||
'file.txt', | ||
'file.txt.gz', | ||
'noextension' | ||
], | ||
options: { | ||
ignore: ['directory/**/*', '\\[special\\?directory\\]/**/*'] | ||
ignore: ['directory/**/*', `[[]special${process.platform === 'win32' ? '' : '[?]'}directory]/**/*`] | ||
}, | ||
patterns: [{ | ||
from: '.' | ||
|
@@ -1401,6 +1418,29 @@ describe('apply function', () => { | |
.catch(done); | ||
}); | ||
|
||
if (path.sep === '/') { | ||
it('ignores nested directory(can use "\\" to escape if path.sep is "/")', (done) => { | ||
runEmit({ | ||
expectedAssetKeys: [ | ||
'[!]/hello.txt', | ||
'binextension.bin', | ||
'file.txt', | ||
'file.txt.gz', | ||
'noextension' | ||
], | ||
options: { | ||
ignore: ['directory/**/*', '\\[special\\?directory\\]/**/*'] | ||
}, | ||
patterns: [{ | ||
from: '.' | ||
}] | ||
|
||
}) | ||
.then(done) | ||
.catch(done); | ||
}); | ||
} | ||
|
||
it('ignores nested directory (glob)', (done) => { | ||
runEmit({ | ||
expectedAssetKeys: [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = function (string) { | ||
return process.platform !== 'win32' ? string : string.replace(/[*?"<>|]/g, ''); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a test with
!
in the file/path should be added to ensure that[!]
works as intended.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@loveky yep, add test