Skip to content

Commit

Permalink
Minor lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Mar 19, 2023
1 parent 3590423 commit b8a70e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,17 @@ precinct.paperwork = (filename, options = {}) => {
const dependencies = precinct(content, options);

if (!options.includeCore) {
return dependencies.filter((dependency) => {
return dependencies.filter(dependency => {
if (dependency.startsWith('node:')) {
return false
return false;
}

// In nodejs 18, node:test is a builtin but shows up under natives["test"], but
// In Node.js 18, node:test is a builtin but shows up under natives["test"], but
// can only be imported by "node:test." We're correcting this so "test" isn't
// unnecessarily stripped from the imports
if (dependency === 'test') {
debug('paperwork: allowing test import to avoid builtin/natives consideration\n');
return true
return true;
}

return !natives[dependency];
Expand Down
27 changes: 14 additions & 13 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const fs = require('fs');
const path = require('path');
const rewire = require('rewire');
const sinon = require('sinon');
const ast = require('./fixtures/exampleAST');
const ast = require('./fixtures/exampleAST.js');

const precinct = rewire('../index.js');

function read(filename) {
Expand Down Expand Up @@ -163,7 +164,7 @@ describe('node-precinct', () => {

describe('paperwork', () => {
it('grabs dependencies of jsx files', () => {
const result = precinct.paperwork(`${__dirname}/fixtures/module.jsx`);
const result = precinct.paperwork(path.join(__dirname, '/fixtures/module.jsx'));
const expected = ['./es6NoImport'];

assert.deepEqual(result, expected);
Expand All @@ -186,10 +187,10 @@ describe('node-precinct', () => {
});

it('returns the dependencies for the given filepath', () => {
assert.notEqual(precinct.paperwork(`${__dirname}/fixtures/es6.js`).length, 0);
assert.notEqual(precinct.paperwork(`${__dirname}/fixtures/styles.scss`).length, 0);
assert.notEqual(precinct.paperwork(`${__dirname}/fixtures/typescript.ts`).length, 0);
assert.notEqual(precinct.paperwork(`${__dirname}/fixtures/styles.css`).length, 0);
assert.notEqual(precinct.paperwork(path.join(__dirname, '/fixtures/es6.js')).length, 0);
assert.notEqual(precinct.paperwork(path.join(__dirname, '/fixtures/styles.scss')).length, 0);
assert.notEqual(precinct.paperwork(path.join(__dirname, '/fixtures/typescript.ts')).length, 0);
assert.notEqual(precinct.paperwork(path.join(__dirname, '/fixtures/styles.css')).length, 0);
});

it('throws if the file cannot be found', () => {
Expand All @@ -199,21 +200,21 @@ describe('node-precinct', () => {
});

it('filters out core modules if options.includeCore is false', () => {
const deps = precinct.paperwork(`${__dirname}/fixtures/coreModules.js`, {
const deps = precinct.paperwork(path.join(__dirname, '/fixtures/coreModules.js'), {
includeCore: false
});

assert.equal(deps.length, 0);
});

it('handles cjs files as commonjs', () => {
const deps = precinct.paperwork(`${__dirname}/fixtures/commonjs.cjs`);
const deps = precinct.paperwork(path.join(__dirname, '/fixtures/commonjs.cjs'));
assert.equal(deps.includes('./a'), true);
assert.equal(deps.includes('./b'), true);
});

it('does not filter out core modules by default', () => {
const deps = precinct.paperwork(`${__dirname}/fixtures/coreModules.js`);
const deps = precinct.paperwork(path.join(__dirname, '/fixtures/coreModules.js'));
assert.notEqual(deps.length, 0);
});

Expand All @@ -226,7 +227,7 @@ describe('node-precinct', () => {
}
};

precinct.paperwork(`${__dirname}/fixtures/amd.js`, {
precinct.paperwork(path.join(__dirname, '/fixtures/amd.js'), {
includeCore: false,
amd: config.amd
});
Expand All @@ -240,7 +241,7 @@ describe('node-precinct', () => {
const stub = sinon.stub().returns([]);
const revert = precinct.__set__('precinct', stub);

precinct.paperwork(`${__dirname}/fixtures/amd.js`, {
precinct.paperwork(path.join(__dirname, '/fixtures/amd.js'), {
amd: {
skipLazyLoaded: true
}
Expand Down Expand Up @@ -349,12 +350,12 @@ describe('node-precinct', () => {
assert.deepEqual(deps, ['streams']);
});

it("understands quirks around some modules only being addressable via node: prefix", () => {
it('understands quirks around some modules only being addressable via node: prefix', () => {
const deps = precinct.paperwork(path.join(__dirname, 'fixtures', 'requiretest.js'), {
includeCore: false
});
assert.deepEqual(deps, ['test']);
})
});
});

describe('that uses dynamic imports', () => {
Expand Down

0 comments on commit b8a70e1

Please sign in to comment.