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

Remove "noParse" in favor of "parseFilter" #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 4 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,10 @@ Deps.prototype.walk = function (id, parent, cb) {
});

function fromSource (file, src, pkg) {
var deps = rec.noparse ? [] : self.parseDeps(file, src);
if (deps) fromDeps(file, src, pkg, deps);
var deps;
if (opts.parseFilter && !opts.parseFilter(id, file, pkg)) deps = [];
else deps = self.parseDeps(file, src);
fromDeps(file, src, pkg, deps);
}

function fromDeps (file, src, pkg, deps) {
Expand Down Expand Up @@ -423,14 +425,8 @@ Deps.prototype.walk = function (id, parent, cb) {
};

Deps.prototype.parseDeps = function (file, src, cb) {
if (this.options.noParse === true) return [];
if (/\.json$/.test(file)) return [];

if (Array.isArray(this.options.noParse)
&& this.options.noParse.indexOf(file) >= 0) {
return [];
}

try { var deps = detective(src) }
catch (ex) {
var message = ex && ex.message ? ex.message : ex;
Expand Down
8 changes: 4 additions & 4 deletions readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,17 @@ package.json at all.
If defined, `opts.filter(id)` should return truthy for all the ids to include
and falsey for all the ids to skip.

* `opts.parseFilter` - a function (id, file, pkg) to skip parsing for
dependencies. Use this for large dependencies like jquery or threejs
which take forever to parse.

* `opts.postFilter` - a function (id, file, pkg) that gets called after `id` has
been resolved. Return false to skip this file.

* `opts.packageFilter` - transform the parsed package.json contents before using
the values. `opts.packageFilter(pkg, dir)` should return the new `pkg` object to
use.

* `opts.noParse` - an array of absolute paths to not parse for dependencies. Use
this for large dependencies like jquery or threejs which take forever to parse.

* `opts.cache` - an object mapping filenames to file objects to skip costly io

* `opts.packageCache` - an object mapping filenames to their parent package.json
Expand All @@ -102,7 +103,6 @@ Input objects should be string filenames or objects with these parameters:

* `row.file` - filename
* `row.expose` - name to be exposed as
* `row.noparse` when true, don't parse the file contents for dependencies

or objects can specify transforms:

Expand Down
39 changes: 0 additions & 39 deletions test/noparse_row.js

This file was deleted.

8 changes: 6 additions & 2 deletions test/noparse.js → test/parse_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ var sources = Object.keys(files).reduce(function (acc, file) {
return acc;
}, {});

test('noParse', function (t) {
test('parse filter', function (t) {
t.plan(1);
var p = parser({ noParse: [ files.foo ] });
var p = parser({
parseFilter: function (id, file, pkg) {
return file !== files.foo;
}
});
p.end(files.main);
var rows = [];

Expand Down