-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): convert-to-monorepo support for root project without proje…
…ct.json (#26507) This PR fixes `convert-to-monorepo` generator, so it works after `nx init` on a single project. ## Current Behavior If you use : ``` npm create vite react-app -- --template=react-ts cd react-app npx nx init ``` Then, you'll get an error when running `nx g convert-to-monorepo`. ``` NX The following projects are defined in multiple locations: - react-app: - . - packages/react-app To fix this, set a unique name for each project in a project.json inside the project's root. If the project does not currently have a project.json, you can create one that contains only a name. MultipleProjectsWithSameNameError: The following projects are defined in multiple locations: - react-app: - . - packages/react-app - ``` ## Expected Behavior The generator should work, and you can run commands successfully afterwards (e.g. `nx serve react-app`). ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
- Loading branch information
Showing
4 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...ges/workspace/src/generators/convert-to-monorepo/convert-to-monorepo.from-nx-init.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'nx/src/internal-testing-utils/mock-project-graph'; | ||
|
||
import { | ||
readJson, | ||
readProjectConfiguration, | ||
Tree, | ||
updateJson, | ||
} from '@nx/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import { monorepoGenerator } from './convert-to-monorepo'; | ||
|
||
describe('monorepo generator', () => { | ||
let tree: Tree; | ||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
it('should convert a root package without a project.json', async () => { | ||
updateJson(tree, 'package.json', (json) => { | ||
json.name = 'demo'; | ||
// Make this a root project | ||
json.nx = {}; | ||
return json; | ||
}); | ||
|
||
await monorepoGenerator(tree, {}); | ||
|
||
expect(tree.exists('packages/demo/project.json')).toBeTruthy(); | ||
expect(readProjectConfiguration(tree, 'demo')).toMatchObject({ | ||
name: 'demo', | ||
}); | ||
expect(readJson(tree, 'package.json').name).toBe('@demo/source'); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
packages/workspace/src/generators/convert-to-monorepo/convert-to-monorepo.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters