fix(core): handle projects with directories correctly (#2194)
This commit is contained in:
parent
ebfa64570e
commit
f9da4d93d5
@ -5,6 +5,7 @@ import {
|
|||||||
ProjectGraphNodeRecords
|
ProjectGraphNodeRecords
|
||||||
} from '../project-graph-models';
|
} from '../project-graph-models';
|
||||||
import { TypeScriptImportLocator } from './typescript-import-locator';
|
import { TypeScriptImportLocator } from './typescript-import-locator';
|
||||||
|
import { normalizedProjectRoot } from '../../shared';
|
||||||
|
|
||||||
export function buildExplicitTypeScriptDependencies(
|
export function buildExplicitTypeScriptDependencies(
|
||||||
ctx: ProjectGraphContext,
|
ctx: ProjectGraphContext,
|
||||||
@ -29,8 +30,14 @@ export function buildExplicitTypeScriptDependencies(
|
|||||||
});
|
});
|
||||||
|
|
||||||
function findTargetProject(importExpr, nodes) {
|
function findTargetProject(importExpr, nodes) {
|
||||||
return Object.keys(nodes).find(projectName =>
|
return Object.keys(nodes).find(projectName => {
|
||||||
importExpr.startsWith(`@${ctx.nxJson.npmScope}/${projectName}`)
|
const p = nodes[projectName];
|
||||||
);
|
const normalizedRoot = normalizedProjectRoot(p);
|
||||||
|
return (
|
||||||
|
importExpr === `@${ctx.nxJson.npmScope}/${normalizedRoot}` ||
|
||||||
|
importExpr.startsWith(`@${ctx.nxJson.npmScope}/${normalizedRoot}#`) ||
|
||||||
|
importExpr.startsWith(`@${ctx.nxJson.npmScope}/${normalizedRoot}/`)
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,9 +43,9 @@ describe('project graph', () => {
|
|||||||
sourceRoot: 'libs/ui/src',
|
sourceRoot: 'libs/ui/src',
|
||||||
projectType: 'library'
|
projectType: 'library'
|
||||||
},
|
},
|
||||||
util: {
|
'shared-util': {
|
||||||
root: 'libs/util/',
|
root: 'libs/shared/util/',
|
||||||
sourceRoot: 'libs/util/src',
|
sourceRoot: 'libs/shared/util/src',
|
||||||
projectType: 'library'
|
projectType: 'library'
|
||||||
},
|
},
|
||||||
api: {
|
api: {
|
||||||
@ -62,7 +62,7 @@ describe('project graph', () => {
|
|||||||
demo: { tags: [], implicitDependencies: ['api'] },
|
demo: { tags: [], implicitDependencies: ['api'] },
|
||||||
'demo-e2e': { tags: [] },
|
'demo-e2e': { tags: [] },
|
||||||
ui: { tags: [] },
|
ui: { tags: [] },
|
||||||
util: { tags: [] }
|
'shared-util': { tags: [] }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
filesJson = {
|
filesJson = {
|
||||||
@ -76,9 +76,9 @@ describe('project graph', () => {
|
|||||||
describe('whatever', () => {});
|
describe('whatever', () => {});
|
||||||
`,
|
`,
|
||||||
'./libs/ui/src/index.ts': stripIndents`
|
'./libs/ui/src/index.ts': stripIndents`
|
||||||
import * as util from '@nrwl/util';
|
import * as util from '@nrwl/shared/util';
|
||||||
`,
|
`,
|
||||||
'./libs/util/src/index.ts': stripIndents`
|
'./libs/shared/util/src/index.ts': stripIndents`
|
||||||
import * as happyNrwl from 'happy-nrwl';
|
import * as happyNrwl from 'happy-nrwl';
|
||||||
`,
|
`,
|
||||||
'./package.json': JSON.stringify(packageJson),
|
'./package.json': JSON.stringify(packageJson),
|
||||||
@ -101,7 +101,7 @@ describe('project graph', () => {
|
|||||||
'demo-e2e': { name: 'demo-e2e', type: 'e2e' },
|
'demo-e2e': { name: 'demo-e2e', type: 'e2e' },
|
||||||
demo: { name: 'demo', type: 'app' },
|
demo: { name: 'demo', type: 'app' },
|
||||||
ui: { name: 'ui', type: 'lib' },
|
ui: { name: 'ui', type: 'lib' },
|
||||||
util: { name: 'util', type: 'lib' }
|
'shared-util': { name: 'shared-util', type: 'lib' }
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(graph.dependencies).toMatchObject({
|
expect(graph.dependencies).toMatchObject({
|
||||||
@ -112,23 +112,23 @@ describe('project graph', () => {
|
|||||||
{ type: DependencyType.implicit, source: 'demo', target: 'api' },
|
{ type: DependencyType.implicit, source: 'demo', target: 'api' },
|
||||||
{ type: DependencyType.static, source: 'demo', target: 'ui' }
|
{ type: DependencyType.static, source: 'demo', target: 'ui' }
|
||||||
]),
|
]),
|
||||||
ui: [{ type: DependencyType.static, source: 'ui', target: 'util' }]
|
ui: [{ type: DependencyType.static, source: 'ui', target: 'shared-util' }]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle circular dependencies', () => {
|
it('should handle circular dependencies', () => {
|
||||||
filesJson['./libs/util/src/index.ts'] = stripIndents`
|
filesJson['./libs/shared/util/src/index.ts'] = stripIndents`
|
||||||
import * as util from '@nrwl/ui';
|
import * as ui from '@nrwl/ui';
|
||||||
import * as happyNrwl from 'happy-nrwl';
|
import * as happyNrwl from 'happy-nrwl';
|
||||||
`;
|
`;
|
||||||
vol.fromJSON(filesJson, '/root');
|
vol.fromJSON(filesJson, '/root');
|
||||||
|
|
||||||
const graph = createProjectGraph();
|
const graph = createProjectGraph();
|
||||||
|
|
||||||
expect(graph.dependencies['util']).toEqual([
|
expect(graph.dependencies['shared-util']).toEqual([
|
||||||
{
|
{
|
||||||
type: DependencyType.static,
|
type: DependencyType.static,
|
||||||
source: 'util',
|
source: 'shared-util',
|
||||||
target: 'ui'
|
target: 'ui'
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
@ -136,7 +136,7 @@ describe('project graph', () => {
|
|||||||
{
|
{
|
||||||
type: DependencyType.static,
|
type: DependencyType.static,
|
||||||
source: 'ui',
|
source: 'ui',
|
||||||
target: 'util'
|
target: 'shared-util'
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -286,6 +286,7 @@ export function readWorkspaceFiles(): FileData[] {
|
|||||||
|
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getProjectNodes(
|
export function getProjectNodes(
|
||||||
workspaceJson: any,
|
workspaceJson: any,
|
||||||
nxJson: NxJson
|
nxJson: NxJson
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user