Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
dd8f3a0
script to remove artifacts dir
iamVP7 Jun 5, 2016
32ebf32
added null check
iamVP7 Jun 7, 2016
b50b890
added undefined check
iamVP7 Jun 7, 2016
ac40fb5
modified build.js
iamVP7 Jun 7, 2016
31b705c
added the toString() method
iamVP7 Jun 7, 2016
d9510d0
added the toString() method
iamVP7 Jun 7, 2016
7abbbf2
added the toString() method to var
iamVP7 Jun 7, 2016
050ca03
changed tostring
iamVP7 Jun 7, 2016
a09b229
removed toString()
iamVP7 Jun 7, 2016
9547f85
added new String()
iamVP7 Jun 7, 2016
cbb05d3
removed String()
iamVP7 Jun 7, 2016
430d37d
added path comparision using path.resolve method in nodejs
iamVP7 Jun 21, 2016
b729923
added undefined check
iamVP7 Jun 21, 2016
67f7565
Modified construcotr in FileFilter
iamVP7 Jun 28, 2016
724874d
rebasing
iamVP7 Jun 28, 2016
7f5d7f1
modified build.js
iamVP7 Jun 7, 2016
af53c1a
added the toString() method
iamVP7 Jun 7, 2016
e503a92
added the toString() method
iamVP7 Jun 7, 2016
86f78ca
added the toString() method to var
iamVP7 Jun 7, 2016
7701855
changed tostring
iamVP7 Jun 7, 2016
476c4c5
removed toString()
iamVP7 Jun 7, 2016
caefb57
added new String()
iamVP7 Jun 7, 2016
13dc4e9
removed String()
iamVP7 Jun 7, 2016
4769f23
added path comparision using path.resolve method in nodejs
iamVP7 Jun 21, 2016
9688087
added undefined check
iamVP7 Jun 21, 2016
e900e24
Modified construcotr in FileFilter
iamVP7 Jun 28, 2016
c34bb5f
Merge branch 'master' of https://github.com/mozilla/web-ext.git
iamVP7 Jun 30, 2016
eb8e139
Added variable filePathsToIgnore
iamVP7 Jun 30, 2016
bcb8c3c
Merge remote-tracking branch 'Mozilla/master'
iamVP7 Jul 6, 2016
7585db1
Merging with Mozilla repo
iamVP7 Jul 6, 2016
05984c6
Removed trailing unwanted spaces
iamVP7 Jul 6, 2016
97b13a3
Added Test Case
iamVP7 Jul 6, 2016
43cbb08
delete .project file
iamVP7 Jul 6, 2016
e4789bf
Merge branch 'master' of https://github.com/mozilla/web-ext.git
iamVP7 Jul 7, 2016
94c1906
Merging from Mozilla/web-ext
iamVP7 Jul 7, 2016
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
23 changes: 18 additions & 5 deletions src/cmd/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export default function build(
packageCreator=defaultPackageCreator}
: Object = {}): Promise {

if (!fileFilter) {
fileFilter = new FileFilter({
filePathsToIgnore: [path.resolve(artifactsDir)],
});
}

const rebuildAsNeeded = asNeeded; // alias for `build --as-needed`
log.info(`Building web extension from ${sourceDir}`);

Expand Down Expand Up @@ -94,15 +100,16 @@ export function safeFileName(name: string): string {
* Allows or ignores files when creating a ZIP archive.
*/
export class FileFilter {
filesToIgnore: Array<string>;

constructor({filesToIgnore}: Object = {}) {
this.filesToIgnore = filesToIgnore || [
filePatternsToIgnore: Array<string>;
filePathsToIgnore : Array<String>;
constructor({filePatternsToIgnore, filePathsToIgnore}: Object = {}) {
this.filePatternsToIgnore = filePatternsToIgnore || [
'**/*.xpi',
'**/*.zip',
'**/.*', // any hidden file
'**/node_modules',
];
this.filePathsToIgnore = filePathsToIgnore || [] ;
}

/*
Expand All @@ -112,12 +119,18 @@ export class FileFilter {
* file in the folder that is being archived.
*/
wantFile(path: string): boolean {
for (const test of this.filesToIgnore) {
for (const test of this.filePatternsToIgnore) {
if (minimatch(path, test)) {
log.debug(`FileFilter: ignoring file ${path}`);
return false;
}
}
for (const filePath of this.filePathsToIgnore) {
if (filePath === path){
log.debug(`FileFilter: ignoring file path ${path}`);
return false;
}
}
return true;
}
}
13 changes: 11 additions & 2 deletions tests/test-cmd/test.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('build', () => {
it('asks FileFilter what files to include in the ZIP', () => {
let zipFile = new ZipFile();
let fileFilter = new FileFilter({
filesToIgnore: ['**/background-script.js'],
filePatternsToIgnore: ['**/background-script.js'],
});

return withTempDir(
Expand Down Expand Up @@ -217,7 +217,7 @@ describe('build', () => {

it('allows you to override the defaults', () => {
const filter = new FileFilter({
filesToIgnore: ['manifest.json'],
filePatternsToIgnore: ['manifest.json'],
});
assert.equal(filter.wantFile('some.xpi'), true);
assert.equal(filter.wantFile('manifest.json'), false);
Expand All @@ -227,6 +227,15 @@ describe('build', () => {
assert.equal(defaultFilter.wantFile('path/to/node_modules'), false);
});

it('ignores an array of absolute file paths', () => withTempDir(
(tmpDir) => {
const filter = new FileFilter({
filePathsToIgnore: [path.join(tmpDir.path(), 'artifacts')],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to create a temp directory. This argument doesn't have to be a real path. It could simply be /example/path/to/web-ext-artifacts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see one other array item in this list for the purposes of the test. Then you can add an additional filter.wantFile(...) assertion to make sure both array items return false.

});
assert.equal(filter.wantFile(path.join(tmpDir.path(), 'artifacts')),
false);
}
));
});

});