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

Default the glob options follow & strict to true, with new options to override #1104

Merged
merged 6 commits into from
Dec 8, 2017
Merged
Show file tree
Hide file tree
Changes from 4 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
13 changes: 13 additions & 0 deletions packages/workbox-build/src/_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ import './_version.mjs';
*
* E.g. `['**\/ignored.html']`
*
* @property {Boolean} [globFollow=true] Follow symlinked directories when
* expanding ** patterns. Note that this can result in a lot of duplicate

Choose a reason for hiding this comment

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

Could you add single quotes around the patterns like: '**'

* references in the presence of cyclic links.
*
* E.g. `true`

Choose a reason for hiding this comment

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

Can you remove the e.g. true piece.

*
* @property {Boolean} [globStrict=true] When an unusual error is encountered
* when attempting to read a directory, the process will just continue on in
* search of other matches. Set the strict option to raise an error in these
* cases.
*
* E.g. `true`

Choose a reason for hiding this comment

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

Please remove this - Our JSDocs will call out the default value.

*
* @property {Object<String,Array|string>} [templatedUrls]
* If a URL is rendered generated based on some server-side logic, its contents
* may depend on multiple files or on some other unique string value.
Expand Down
12 changes: 11 additions & 1 deletion packages/workbox-build/src/lib/get-file-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,22 @@ const errors = require('./errors');
const getFileSize = require('./get-file-size');
const getFileHash = require('./get-file-hash');

module.exports = ({globDirectory, globIgnores, globPattern}) => {
module.exports = (globOptions) => {
const {
globDirectory,
globIgnores,
globPattern,
globFollow,
globStrict,
} = globOptions;
let globbedFiles;
try {
globbedFiles = glob.sync(globPattern, {
cwd: globDirectory,
ignore: globIgnores,
follow: typeof globFollow !== 'undefined'? globFollow : true,

Choose a reason for hiding this comment

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

@jeffposnick you've been doing some work on the defaults, is this the best approach or should this be moved to a defaults value.

strict: typeof globStrict !== 'undefined'? globStrict : true,

});
} catch (err) {
throw new Error(errors['unable-to-glob-files'] + ` '${err.message}'`);
Expand Down
42 changes: 42 additions & 0 deletions test/workbox-build/node/lib/get-file-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,46 @@ describe(`[workbox-build] lib/get-file-details.js`, function() {
size: SIZE,
}]);
});

it(`should call sync with follow and strict options by default`, function() {
const getFileDetails = proxyquire(MODULE_PATH, {
'glob': {
sync: (pattern, options) => {
expect(options.follow).to.be.true;
expect(options.strict).to.be.true;

return [FILE1];
},
},
'./get-file-size': (value) => SIZE,
'./get-file-hash': (value) => HASH,
});

getFileDetails({
globDirectory: GLOB_DIRECTORY,
globPattern: GLOB_PATTERN,
});
});

it(`should call sync with follow and strict options with value`, function() {
const getFileDetails = proxyquire(MODULE_PATH, {
'glob': {
sync: (pattern, options) => {
expect(options.follow).to.be.false;
expect(options.strict).to.be.false;

return [FILE1];
},
},
'./get-file-size': (value) => SIZE,
'./get-file-hash': (value) => HASH,
});

getFileDetails({
globDirectory: GLOB_DIRECTORY,
globPattern: GLOB_PATTERN,
globFollow: false,
globStrict: false,
});
});
});