diff --git a/e2e/schematics/application.test.ts b/e2e/schematics/application.test.ts index 93c9b16176..9308ae55e5 100644 --- a/e2e/schematics/application.test.ts +++ b/e2e/schematics/application.test.ts @@ -1,7 +1,7 @@ import { newApp, newLib, newProject, runCLI, updateFile } from '../utils'; describe('Nrwl Workspace', () => { - fit( + it( 'should work', () => { newProject(); diff --git a/packages/schematics/src/affected/affected.spec.ts b/packages/schematics/src/affected/affected.spec.ts index d7381270c4..e55854e2c0 100644 --- a/packages/schematics/src/affected/affected.spec.ts +++ b/packages/schematics/src/affected/affected.spec.ts @@ -137,6 +137,22 @@ describe('Calculates Dependencies Between Apps and Libs', () => { expect(deps).toEqual({ app1: ['app1', 'lib1', 'lib2'], lib1: ['lib1'], lib2: ['lib2'] }); }); + + it('should handle non-ts files', () => { + const deps = dependencies( + 'nrwl', + [ + { + name: 'app1', + files: ['index.html'], + isApp: true + } + ], + () => null + ); + + expect(deps).toEqual({ app1: ['app1'] }); + }); }); describe('affectedApps', () => { @@ -222,5 +238,29 @@ describe('Calculates Dependencies Between Apps and Libs', () => { expect(affected).toEqual(['app1', 'app2']); }); + + it('should handle slashes', () => { + const affected = affectedApps( + 'nrwl', + [ + { + name: 'app1', + files: ['one\\app1.ts', 'two/app1.ts'], + isApp: true + } + ], + file => { + switch (file) { + case 'one/app1.ts': + return ''; + case 'two/app1.ts': + return ''; + } + }, + ['one/app1.ts', 'two/app1.ts'] + ); + + expect(affected).toEqual(['app1']); + }); }); }); diff --git a/packages/schematics/src/affected/affected.ts b/packages/schematics/src/affected/affected.ts index 073c794f73..120bcb3908 100644 --- a/packages/schematics/src/affected/affected.ts +++ b/packages/schematics/src/affected/affected.ts @@ -1,4 +1,5 @@ import * as ts from 'typescript'; +import * as path from 'path'; export type Project = { name: string; isApp: boolean; files: string[] }; @@ -8,6 +9,8 @@ export function affectedApps( fileRead: (s: string) => string, touchedFiles: string[] ): string[] { + projects = normalizeProjects(projects); + touchedFiles = normalizeFiles(touchedFiles); const deps = dependencies(npmScope, projects, fileRead); const touchedProjects = touchedFiles.map(f => { @@ -24,6 +27,19 @@ export function affectedApps( .map(p => p.name); } +function normalizeProjects(projects: Project[]) { + return projects.map(p => { + return { + ...p, + files: normalizeFiles(p.files) + }; + }); +} + +function normalizeFiles(files: string[]): string[] { + return files.map(f => f.replace(/[\\\/]+/g, '/')); +} + export function dependencies( npmScope: string, projects: Project[], @@ -70,8 +86,10 @@ class Deps { } private processFile(projectName: string, filePath: string): void { - const tsFile = ts.createSourceFile(filePath, this.fileRead(filePath), ts.ScriptTarget.Latest, true); - this.processNode(projectName, tsFile); + if (path.extname(filePath) === '.ts') { + const tsFile = ts.createSourceFile(filePath, this.fileRead(filePath), ts.ScriptTarget.Latest, true); + this.processNode(projectName, tsFile); + } } private processNode(projectName: string, node: ts.Node): void { diff --git a/packages/schematics/src/affected/run-affected.ts b/packages/schematics/src/affected/run-affected.ts index b3dfa7ebd7..54262bd127 100644 --- a/packages/schematics/src/affected/run-affected.ts +++ b/packages/schematics/src/affected/run-affected.ts @@ -80,7 +80,7 @@ function allFilesInDir(dirName: string): string[] { fs.readdirSync(dirName).forEach(c => { const child = path.join(dirName, c); try { - if (!fs.statSync(child).isDirectory() && path.extname(child) === '.ts') { + if (!fs.statSync(child).isDirectory()) { res.push(child); } else if (fs.statSync(child).isDirectory()) { res = [...res, ...allFilesInDir(child)];