diff --git a/src/rules/no-internal-import.js b/src/rules/no-internal-import.js index 90f2152..165bea3 100644 --- a/src/rules/no-internal-import.js +++ b/src/rules/no-internal-import.js @@ -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) { diff --git a/test/fixture/yarn/packages/bar/nested/index.js b/test/fixture/yarn/packages/bar/nested/index.js new file mode 100644 index 0000000..e69de29 diff --git a/test/rules/no-internal-import.test.js b/test/rules/no-internal-import.test.js index 4a8bdab..5620661 100644 --- a/test/rules/no-internal-import.test.js +++ b/test/rules/no-internal-import.test.js @@ -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'),