fix: dependency matching for multi-line imports (#34)
* fix: Fix dependency matching for multi-line imports * tests
This commit is contained in:
Родитель
01f89d8b8e
Коммит
4d26e2ae8e
|
@ -12,7 +12,7 @@ export const getDependencies = (
|
|||
requiredDependencies: PackageDependencies,
|
||||
optionalDependencies: PackageDependencies,
|
||||
) => {
|
||||
const matches = fileContent.matchAll(/import .* from ['"](.*?)['"];/g);
|
||||
const matches = fileContent.matchAll(/from ['"](.*?)['"];/g);
|
||||
|
||||
const dependenciesInCode = Array.from(matches).reduce((dependencies, match) => {
|
||||
if (!match[1].startsWith('react/')) {
|
||||
|
|
|
@ -6,11 +6,19 @@ describe('getDependencies', () => {
|
|||
import { stuff } from 'dependency';
|
||||
import * as allStuff from 'dependency1';
|
||||
import { moreStuff } from '@dependency/dependency';
|
||||
import {
|
||||
someOtherStuff,
|
||||
} from "@multiline/importDouble";
|
||||
import {
|
||||
someOtherStuff,
|
||||
} from '@multiline/import';
|
||||
`;
|
||||
const deps = getDependencies(code, {}, {});
|
||||
|
||||
expect(deps).toEqual({
|
||||
'@dependency/dependency': 'latest',
|
||||
'@multiline/importDouble': 'latest',
|
||||
'@multiline/import': 'latest',
|
||||
dependency: 'latest',
|
||||
dependency1: 'latest',
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче