Skip to content

Commit

Permalink
fix: include index files when traversing files field (#17)
Browse files Browse the repository at this point in the history
* feat: consider files field from package.json

* chore: added empty folder to fix the tests

* fix: eslint

* fix: index files are included, non-existent packages not throwing error

Co-authored-by: blam <[email protected]>
  • Loading branch information
shmidt-i and blam committed Nov 15, 2020
1 parent 07f6bdc commit 266bd60
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/rules/no-internal-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,22 @@ export const create = context => {
// supposed to be part of the public API of the package
const absolutePathsForFiles =
matchedPackage.package.files &&
matchedPackage.package.files.map(file => {
matchedPackage.package.files.reduce((acc, file) => {
const fileOrDirOrGlob = path.join(packageRoot, file);
acc.push(fileOrDirOrGlob);

try {
if (fs.lstatSync(fileOrDirOrGlob).isDirectory()) {
return path.join(fileOrDirOrGlob, '**', '*');
// Need to also include
// all of the files inside the folder
acc.push(path.join(fileOrDirOrGlob, '**', '*'));
}
return fileOrDirOrGlob;
} catch (e) {
return fileOrDirOrGlob;
// do nothing
}
});

return acc;
}, []);
const absoluteInternalPath = path.join(packageRoot, internalPath);

if (absolutePathsForFiles) {
Expand Down
Empty file.
8 changes: 8 additions & 0 deletions test/rules/no-internal-import.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ ruleTester.run(RULE, monorepo.rules[RULE], {
code: `import { pkg } from 'bar/nested/allowedToo'`,
filename: path.join(fixtures, 'packages/bar/index.js'),
},
{
code: `import { pkg } from 'bar/nested'`,
filename: path.join(fixtures, 'packages/bar/index.js'),
},
{
code: `import { pkg } from 'non-existent-package/nested'`,
filename: path.join(fixtures, 'packages/bar/index.js'),
},
{
code: `import { pkg } from 'bar/nested/this/is/also/allowed'`,
filename: path.join(fixtures, 'packages/bar/index.js'),
Expand Down

0 comments on commit 266bd60

Please sign in to comment.