From a0a2a6de768be4fa23103f3eee4d39e23ac6eab0 Mon Sep 17 00:00:00 2001 From: Victor Savkin Date: Sat, 28 Dec 2019 11:53:28 -0500 Subject: [PATCH] Revert "fix(core): add import to project string comparitor locator" This reverts commit 9fea0bc02ba4fe1c7239c821c8be31bf2ee24715. --- .../import-project-root.spec.ts | 143 ------------------ .../build-dependencies/import-project-root.ts | 39 ----- .../project-graph/build-dependencies/index.ts | 1 - .../src/core/project-graph/project-graph.ts | 3 +- 4 files changed, 1 insertion(+), 185 deletions(-) delete mode 100644 packages/workspace/src/core/project-graph/build-dependencies/import-project-root.spec.ts delete mode 100644 packages/workspace/src/core/project-graph/build-dependencies/import-project-root.ts diff --git a/packages/workspace/src/core/project-graph/build-dependencies/import-project-root.spec.ts b/packages/workspace/src/core/project-graph/build-dependencies/import-project-root.spec.ts deleted file mode 100644 index 0866baa149..0000000000 --- a/packages/workspace/src/core/project-graph/build-dependencies/import-project-root.spec.ts +++ /dev/null @@ -1,143 +0,0 @@ -import { buildImportsToProjectRoots } from './import-project-root'; -import { - AddProjectDependency, - DependencyType, - ProjectGraphContext, - ProjectGraphNode -} from '../../project-graph'; - -import { fs, vol } from 'memfs'; -import { join } from 'path'; - -describe('buildImportsToProjectRoots', () => { - let addDependency: AddProjectDependency; - let ctx: ProjectGraphContext; - let projects: Record; - let fileRead: (path: string) => string; - let fsJson; - beforeEach(() => { - addDependency = jest.fn(); - fileRead = p => fs.readFileSync(join('/root', p)).toString(); - const workspaceJson = { - projects: { - proj1: {} - } - }; - const nxJson = { - npmScope: 'proj', - projects: { - proj1: {} - } - }; - fsJson = { - 'workspace.json': JSON.stringify(workspaceJson), - 'nx.json': JSON.stringify(nxJson), - 'libs/proj1/index.ts': `import '@proj/proj2'; - import('@proj/proj3'); - const a = { loadChildren: '@proj/proj4#a' };`, - 'libs/proj2/index.ts': `export const a = 0;`, - 'libs/proj3/index.ts': `export const a = 0;`, - 'libs/proj4/index.ts': `export const a = 0;` - }; - vol.fromJSON(fsJson, '/root'); - - ctx = { - workspaceJson, - nxJson, - fileMap: { - proj1: [ - { - file: 'libs/proj1/index.ts', - mtime: 0, - ext: '.ts' - } - ], - proj2: [ - { - file: 'libs/proj2/index.ts', - mtime: 0, - ext: '.ts' - } - ], - proj3: [ - { - file: 'libs/proj3/index.ts', - mtime: 0, - ext: '.ts' - } - ], - proj4: [ - { - file: 'libs/proj4/index.ts', - mtime: 0, - ext: '.ts' - } - ] - } - }; - projects = { - proj1: { - name: 'proj1', - type: 'lib', - data: { - root: 'libs/proj1', - files: [] - } - }, - proj2: { - name: 'proj2', - type: 'lib', - data: { - root: 'libs/proj2', - files: [] - } - }, - proj3: { - name: 'proj3', - type: 'lib', - data: { - root: 'libs/proj3', - files: [] - } - }, - proj4: { - name: 'proj4', - type: 'lib', - data: { - root: 'libs/proj4', - files: [] - } - } - }; - }); - - it('should draw static dependencies from imports', () => { - buildImportsToProjectRoots(ctx, projects, addDependency, fileRead); - - expect(addDependency).toHaveBeenCalledWith( - DependencyType.static, - 'proj1', - 'proj2' - ); - }); - - it('should draw dynamic dependencies from import()', () => { - buildImportsToProjectRoots(ctx, projects, addDependency, fileRead); - - expect(addDependency).toHaveBeenCalledWith( - DependencyType.dynamic, - 'proj1', - 'proj3' - ); - }); - - it('should draw dynamic dependencies from loadChildren', () => { - buildImportsToProjectRoots(ctx, projects, addDependency, fileRead); - - expect(addDependency).toHaveBeenCalledWith( - DependencyType.dynamic, - 'proj1', - 'proj4' - ); - }); -}); diff --git a/packages/workspace/src/core/project-graph/build-dependencies/import-project-root.ts b/packages/workspace/src/core/project-graph/build-dependencies/import-project-root.ts deleted file mode 100644 index 9b11d6cfac..0000000000 --- a/packages/workspace/src/core/project-graph/build-dependencies/import-project-root.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { - AddProjectDependency, - DependencyType, - ProjectGraphContext, - ProjectGraphNode, - ProjectGraphNodeRecords -} from '../project-graph-models'; -import { TypeScriptImportLocator } from './typescript-import-locator'; -import { normalizedProjectRoot } from '../../file-utils'; - -export function buildImportsToProjectRoots( - ctx: ProjectGraphContext, - nodes: ProjectGraphNodeRecords, - addDependency: AddProjectDependency, - fileRead: (s: string) => string -) { - const importLocator = new TypeScriptImportLocator(fileRead); - - Object.keys(ctx.fileMap).forEach(source => { - Object.values(ctx.fileMap[source]).forEach(f => { - importLocator.fromFile( - f.file, - (importExpr: string, filePath: string, type: DependencyType) => { - const targetProjectName = Object.keys(nodes).find(projectName => { - const p = nodes[projectName]; - const normalizedRoot = normalizedProjectRoot(p); - const normalizedImportExpr = importExpr.split('#')[0]; - const projectImport = `@${ctx.nxJson.npmScope}/${normalizedRoot}`; - return normalizedImportExpr.startsWith(projectImport); - }); - - if (targetProjectName) { - addDependency(type, source, targetProjectName); - } - } - ); - }); - }); -} diff --git a/packages/workspace/src/core/project-graph/build-dependencies/index.ts b/packages/workspace/src/core/project-graph/build-dependencies/index.ts index 8602df93df..7bfc04761e 100644 --- a/packages/workspace/src/core/project-graph/build-dependencies/index.ts +++ b/packages/workspace/src/core/project-graph/build-dependencies/index.ts @@ -1,5 +1,4 @@ export * from './build-dependencies'; -export * from './import-project-root'; export * from './implicit-project-dependencies'; export * from './explicit-project-dependencies'; export * from './explicit-npm-dependencies'; diff --git a/packages/workspace/src/core/project-graph/project-graph.ts b/packages/workspace/src/core/project-graph/project-graph.ts index 7f699eb0df..d95334547e 100644 --- a/packages/workspace/src/core/project-graph/project-graph.ts +++ b/packages/workspace/src/core/project-graph/project-graph.ts @@ -26,8 +26,7 @@ import { BuildDependencies, buildExplicitNpmDependencies, buildExplicitTypeScriptDependencies, - buildImplicitProjectDependencies, - buildImportsToProjectRoots + buildImplicitProjectDependencies } from './build-dependencies'; import { assertWorkspaceValidity } from '../assert-workspace-validity'; import { normalizeNxJson } from '../normalize-nx-json';