mirror of
https://github.com/elastic/kibana.git
synced 2025-06-28 03:01:21 -04:00
Fix @kbn/import-resolver detection of nested node_modules (#162391)
Ensure that a plugin containing a nested `node_modules` folder correctly identifies imports from that folder as regular node modules instead of relative imports. Kibana should currently only have a single root `node_modules` folder, so this should not be a real issue. However, if for some reason a stray `node_modules` folder is created, this commit will make sure it's not introducing hard to debug ESLint errors.
This commit is contained in:
parent
a79e9c7374
commit
70b337a135
4 changed files with 13 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -11,6 +11,7 @@ node_modules
|
||||||
!/src/dev/npm/integration_tests/__fixtures__/fixture1/node_modules
|
!/src/dev/npm/integration_tests/__fixtures__/fixture1/node_modules
|
||||||
!/src/dev/notice/__fixtures__/node_modules
|
!/src/dev/notice/__fixtures__/node_modules
|
||||||
!/packages/kbn-import-resolver/src/__fixtures__/node_modules
|
!/packages/kbn-import-resolver/src/__fixtures__/node_modules
|
||||||
|
!/packages/kbn-import-resolver/src/__fixtures__/packages/box/node_modules
|
||||||
trash
|
trash
|
||||||
/optimize
|
/optimize
|
||||||
/built_assets
|
/built_assets
|
||||||
|
|
0
packages/kbn-import-resolver/src/__fixtures__/packages/box/node_modules/bar/index.js
generated
vendored
Normal file
0
packages/kbn-import-resolver/src/__fixtures__/packages/box/node_modules/bar/index.js
generated
vendored
Normal file
|
@ -86,7 +86,7 @@ export class ImportResolver {
|
||||||
|
|
||||||
getPackageIdForPath(path: string) {
|
getPackageIdForPath(path: string) {
|
||||||
const relative = Path.relative(this.cwd, path);
|
const relative = Path.relative(this.cwd, path);
|
||||||
if (relative.startsWith('..')) {
|
if (relative.startsWith('..') || path.includes(NODE_MODULE_SEG)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,17 @@ describe('#resolve()', () => {
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('resolves nested node_module imports', () => {
|
||||||
|
expect(resolver.resolve('bar', Path.join(FIXTURES_DIR, 'packages', 'box')))
|
||||||
|
.toMatchInlineSnapshot(`
|
||||||
|
Object {
|
||||||
|
"absolute": <absolute path>/packages/kbn-import-resolver/src/__fixtures__/packages/box/node_modules/bar/index.js,
|
||||||
|
"nodeModule": "bar",
|
||||||
|
"type": "file",
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
it('resolves requests to src/', () => {
|
it('resolves requests to src/', () => {
|
||||||
expect(resolver.resolve('src/core/public', FIXTURES_DIR)).toMatchInlineSnapshot(`
|
expect(resolver.resolve('src/core/public', FIXTURES_DIR)).toMatchInlineSnapshot(`
|
||||||
Object {
|
Object {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue