Skip to content

Commit

Permalink
Merge pull request #88 from netlify-team-account-1/ignore-node-prefix
Browse files Browse the repository at this point in the history
[paperwork] take node: prefix as indicator for being a core module
  • Loading branch information
mrjoelkemp authored Oct 25, 2021
2 parents b6ba63f + c1d9700 commit 673e51b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ precinct.paperwork = function(filename, options = {}) {

if (!options.includeCore) {
return deps.filter(function(d) {
if (d.startsWith('node:')) {
return false;
}
return !natives[d];
});
}
Expand Down
10 changes: 10 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,16 @@ describe('node-precinct', function() {
});
});

describe('that imports node-internal with node:-prefix', () => {
it('assumes that it exists', () => {
var deps = precinct.paperwork(path.join(__dirname, 'internalNodePrefix.js'), {
includeCore: false
});
assert(!deps.includes('node:nonexistant'));
assert.deepEqual(deps, ['streams']);
});
});

describe('that uses dynamic imports', function() {
it('grabs the dynamic import', function() {
var es6 = precinct(read('es6DynamicImport.js'));
Expand Down
2 changes: 2 additions & 0 deletions test/internalNodePrefix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const someModule = require("node:nonexistant")
const anotherModule = require("streams")

0 comments on commit 673e51b

Please sign in to comment.