Skip to content

Commit

Permalink
Running with *.js and '*.js' (quoted) should behave the same (#84)
Browse files Browse the repository at this point in the history
- Normalize `<script.js>` and `<script.js.map>` paths. '\'./js/foo.min.js\'' => './js/foo.min.js'
- Update dependencies

resolves #84
  • Loading branch information
nikolay-borzov committed Feb 21, 2019
1 parent dad7652 commit 8df9921
Show file tree
Hide file tree
Showing 4 changed files with 332 additions and 398 deletions.
19 changes: 17 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,19 @@ const doc = [
* @typedef {Object.<string, number>} FileSizeMap
*/

const ESCAPED_QUOTE_REGEX = new RegExp('\\\'', 'g');

const helpers = {
/**
* Remove extra single quotes around path.
* '\'./js/foo.min.js\'' => './js/foo.min.js'
*/
normalizePathArgument(path) {
if (!path) { return path; }

return path.replace(ESCAPED_QUOTE_REGEX, '');
},

/**
* @param {(Buffer|string)} file Path to file or Buffer
*/
Expand Down Expand Up @@ -566,7 +578,7 @@ function writeToHtml(html) {

fs.writeFileSync(tempName, html);

open(tempName, {wait: false}).catch(error => {
open(tempName, { wait: false }).catch(error => {
console.error('Unable to open web browser. ' + error);
console.error('Either run with --html, --json or --tsv, or view HTML for the visualization at:');
console.error(tempName);
Expand All @@ -579,7 +591,10 @@ if (require.main === module) {

validateArgs(args);

const bundles = getBundles(args['<script.js>'], args['<script.js.map>']);
const scriptPath = helpers.normalizePathArgument(args['<script.js>']);
const scriptMapPath = helpers.normalizePathArgument(args['<script.js.map>']);

const bundles = getBundles(scriptPath, scriptMapPath);

if (bundles.length === 0) {
throw new Error('No file(s) found');
Expand Down
Loading

0 comments on commit 8df9921

Please sign in to comment.