From b380597a02415efa43e7857b3ddb6778b1931578 Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Fri, 18 Mar 2022 19:14:04 -0400 Subject: [PATCH] fix(core): projects inferrred in apps directory should be inferred as an application (#9379) * fix(core): projects inferrred in apps directory should be inferred as an application * chore(repo): add jest setup back for `nx` --- packages/nx/jest.config.js | 5 +++-- packages/nx/project.json | 8 ++++++++ packages/nx/src/commands/migrate.spec.ts | 1 - packages/nx/src/shared/__snapshots__/logger.spec.ts.snap | 4 ++-- packages/nx/src/shared/workspace.spec.ts | 4 +++- packages/nx/src/shared/workspace.ts | 6 ++++++ .../src/generators/npm-package/npm-package.spec.ts | 1 + 7 files changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/nx/jest.config.js b/packages/nx/jest.config.js index 4ea1aba6fafd3..de2079c69b85d 100644 --- a/packages/nx/jest.config.js +++ b/packages/nx/jest.config.js @@ -1,9 +1,10 @@ module.exports = { - name: 'cli', - preset: '../../jest.config.js', + preset: '../../jest.preset.js', transform: { '^.+\\.[tj]sx?$': 'ts-jest', }, moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'], globals: { 'ts-jest': { tsconfig: '/tsconfig.spec.json' } }, + displayName: 'nx', + testEnvironment: 'node', }; diff --git a/packages/nx/project.json b/packages/nx/project.json index ebf22b972cbe4..55babc0ff9d59 100644 --- a/packages/nx/project.json +++ b/packages/nx/project.json @@ -78,6 +78,14 @@ ] }, "outputs": ["{options.outputFile}"] + }, + "test": { + "executor": "@nrwl/jest:jest", + "options": { + "jestConfig": "packages/nx/jest.config.js", + "passWithNoTests": true + }, + "outputs": ["coverage/packages/nx"] } } } diff --git a/packages/nx/src/commands/migrate.spec.ts b/packages/nx/src/commands/migrate.spec.ts index 5c45007a1b70c..74d93c55f0ada 100644 --- a/packages/nx/src/commands/migrate.spec.ts +++ b/packages/nx/src/commands/migrate.spec.ts @@ -369,7 +369,6 @@ describe('Migration', () => { migrations: [], packageJson: { '@nrwl/workspace': { version: '2.0.0', addToPackageJson: false }, - '@nrwl/cli': { version: '2.0.0', addToPackageJson: false }, '@nrwl/angular': { version: '2.0.0', addToPackageJson: false }, '@nrwl/cypress': { version: '2.0.0', addToPackageJson: false }, '@nrwl/devkit': { addToPackageJson: false, version: '2.0.0' }, diff --git a/packages/nx/src/shared/__snapshots__/logger.spec.ts.snap b/packages/nx/src/shared/__snapshots__/logger.spec.ts.snap index 8e6d123acc221..a831b593a2359 100644 --- a/packages/nx/src/shared/__snapshots__/logger.spec.ts.snap +++ b/packages/nx/src/shared/__snapshots__/logger.spec.ts.snap @@ -1,12 +1,12 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Tao Logger should color the NX prefix 1`] = ` +exports[`Logger should color the NX prefix 1`] = ` " >  NX  some Nx message! " `; -exports[`Tao Logger should log the full stack trace when an object is being passed 1`] = ` +exports[`Logger should log the full stack trace when an object is being passed 1`] = ` "TypeError: Cannot read property 'target' of undefined  at /someuser/node_modules/@storybook/angular/dist/ts3.9/server/angular-devkit-build-webpack.js:145:49  at step (/someuser/node_modules/@storybook/angular/dist/ts3.9/server/angular-devkit-build-webpack.js:69:23) diff --git a/packages/nx/src/shared/workspace.spec.ts b/packages/nx/src/shared/workspace.spec.ts index ef41ca03c6f48..b2dc82467df03 100644 --- a/packages/nx/src/shared/workspace.spec.ts +++ b/packages/nx/src/shared/workspace.spec.ts @@ -14,6 +14,7 @@ const libConfig = (name) => ({ const packageLibConfig = (root) => ({ root, sourceRoot: root, + projectType: 'library', }); describe('Workspaces', () => { @@ -102,7 +103,7 @@ describe('Workspaces', () => { expect(libResults).toEqual('directory-my-lib'); }); - it('should custom directories from beginning', () => { + it('should trim custom directories from beginning', () => { const nxJson: NxJsonConfiguration = { npmScope: '', workspaceLayout: { @@ -161,6 +162,7 @@ describe('Workspaces', () => { expect(resolved.projects['my-package']).toEqual({ root: 'packages/my-package', sourceRoot: 'packages/my-package', + projectType: 'library', }); }); }); diff --git a/packages/nx/src/shared/workspace.ts b/packages/nx/src/shared/workspace.ts index 7ceb7a869d11a..bd021292034db 100644 --- a/packages/nx/src/shared/workspace.ts +++ b/packages/nx/src/shared/workspace.ts @@ -803,6 +803,12 @@ function buildProjectConfigurationFromPackageJson( root: directory, sourceRoot: directory, name, + projectType: + nxJson.workspaceLayout?.appsDir != nxJson.workspaceLayout?.libsDir && + nxJson.workspaceLayout?.appsDir && + directory.startsWith(nxJson.workspaceLayout.appsDir) + ? 'application' + : 'library', }; } diff --git a/packages/workspace/src/generators/npm-package/npm-package.spec.ts b/packages/workspace/src/generators/npm-package/npm-package.spec.ts index 221db25cf046f..82814e1a9c9d4 100644 --- a/packages/workspace/src/generators/npm-package/npm-package.spec.ts +++ b/packages/workspace/src/generators/npm-package/npm-package.spec.ts @@ -105,6 +105,7 @@ describe('@nrwl/workspace:npm-package', () => { expect(tree.exists('packages/my-package/project.json')).toBeFalsy(); expect(tree.exists('packages/my-package/package.json')).toBeTruthy(); expect(readProjectConfiguration(tree, 'my-package')).toEqual({ + projectType: 'library', root: 'packages/my-package', sourceRoot: 'packages/my-package', });