Skip to content

Commit

Permalink
feat(misc): allow providing a path in the name option of project gene…
Browse files Browse the repository at this point in the history
…rators (nrwl#20274)
  • Loading branch information
leosvelperez authored Nov 21, 2023
1 parent 6f6af7e commit a672cbb
Show file tree
Hide file tree
Showing 5 changed files with 411 additions and 110 deletions.
8 changes: 4 additions & 4 deletions packages/detox/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,12 @@ describe('detox application generator', () => {
});

it('should update configuration', async () => {
const project = readProjectConfiguration(tree, 'my-dir/my-app-e2e');
const project = readProjectConfiguration(tree, 'my-app-e2e');
expect(project.root).toEqual('my-dir/my-app-e2e');
});

it('should update nx.json', async () => {
const project = readProjectConfiguration(tree, 'my-dir/my-app-e2e');
const project = readProjectConfiguration(tree, 'my-app-e2e');
expect(project.tags).toEqual([]);
expect(project.implicitDependencies).toEqual(['my-dir-my-app']);
});
Expand Down Expand Up @@ -368,13 +368,13 @@ describe('detox application generator', () => {
});

it('should update configuration', async () => {
const project = readProjectConfiguration(tree, 'my-dir/my-app-e2e');
const project = readProjectConfiguration(tree, 'my-app-e2e');

expect(project.root).toEqual('my-dir/my-app-e2e');
});

it('should update nx.json', async () => {
const project = readProjectConfiguration(tree, 'my-dir/my-app-e2e');
const project = readProjectConfiguration(tree, 'my-app-e2e');
expect(project.tags).toEqual([]);
expect(project.implicitDependencies).toEqual(['my-dir-my-app']);
});
Expand Down
200 changes: 200 additions & 0 deletions packages/devkit/src/generators/project-name-and-root-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,86 @@ describe('determineProjectNameAndRootOptions', () => {
).rejects.toThrowError();
});

it('should handle providing a path as the project name when format is "as-provided"', async () => {
const result = await determineProjectNameAndRootOptions(tree, {
name: 'shared/libName',
projectType: 'library',
projectNameAndRootFormat: 'as-provided',
callingGenerator: '',
});

expect(result).toEqual({
projectName: 'libName',
names: {
projectSimpleName: 'libName',
projectFileName: 'libName',
},
importPath: '@proj/libName',
projectRoot: 'shared/libName',
projectNameAndRootFormat: 'as-provided',
});
});

it('should handle providing a path including "@" as the project name when format is "as-provided"', async () => {
const result = await determineProjectNameAndRootOptions(tree, {
name: 'shared/@scope/libName',
projectType: 'library',
projectNameAndRootFormat: 'as-provided',
callingGenerator: '',
});

expect(result).toEqual({
projectName: '@scope/libName',
names: {
projectSimpleName: 'libName',
projectFileName: 'libName',
},
importPath: '@scope/libName',
projectRoot: 'shared/@scope/libName',
projectNameAndRootFormat: 'as-provided',
});
});

it('should handle providing a path including "@" with multiple segments as the project name when format is "as-provided"', async () => {
const result = await determineProjectNameAndRootOptions(tree, {
name: 'shared/@scope/libName/testing',
projectType: 'library',
projectNameAndRootFormat: 'as-provided',
callingGenerator: '',
});

expect(result).toEqual({
projectName: '@scope/libName/testing',
names: {
projectSimpleName: 'testing',
projectFileName: 'libName-testing',
},
importPath: '@scope/libName/testing',
projectRoot: 'shared/@scope/libName/testing',
projectNameAndRootFormat: 'as-provided',
});
});

it('should handle providing a path including multiple "@" as the project name when format is "as-provided"', async () => {
const result = await determineProjectNameAndRootOptions(tree, {
name: 'shared/@foo/@scope/libName',
projectType: 'library',
projectNameAndRootFormat: 'as-provided',
callingGenerator: '',
});

expect(result).toEqual({
projectName: '@scope/libName',
names: {
projectSimpleName: 'libName',
projectFileName: 'libName',
},
importPath: '@scope/libName',
projectRoot: 'shared/@foo/@scope/libName',
projectNameAndRootFormat: 'as-provided',
});
});

it('should return the derived project name and directory', async () => {
const result = await determineProjectNameAndRootOptions(tree, {
name: 'libName',
Expand All @@ -334,6 +414,26 @@ describe('determineProjectNameAndRootOptions', () => {
});
});

it('should handle providing a path as the project name when format is "derived"', async () => {
const result = await determineProjectNameAndRootOptions(tree, {
name: 'shared/libName',
projectType: 'library',
projectNameAndRootFormat: 'derived',
callingGenerator: '',
});

expect(result).toEqual({
projectName: 'shared-lib-name',
names: {
projectSimpleName: 'lib-name',
projectFileName: 'shared-lib-name',
},
importPath: '@proj/shared/lib-name',
projectRoot: 'shared/lib-name',
projectNameAndRootFormat: 'derived',
});
});

it('should throw when using a scoped package name as the project name and format is "derived"', async () => {
await expect(
determineProjectNameAndRootOptions(tree, {
Expand Down Expand Up @@ -632,6 +732,86 @@ describe('determineProjectNameAndRootOptions', () => {
).rejects.toThrowError();
});

it('should handle providing a path as the project name when format is "as-provided"', async () => {
const result = await determineProjectNameAndRootOptions(tree, {
name: 'shared/libName',
projectType: 'library',
projectNameAndRootFormat: 'as-provided',
callingGenerator: '',
});

expect(result).toEqual({
projectName: 'libName',
names: {
projectSimpleName: 'libName',
projectFileName: 'libName',
},
importPath: '@proj/libName',
projectRoot: 'shared/libName',
projectNameAndRootFormat: 'as-provided',
});
});

it('should handle providing a path including "@" as the project name when format is "as-provided"', async () => {
const result = await determineProjectNameAndRootOptions(tree, {
name: 'shared/@scope/libName',
projectType: 'library',
projectNameAndRootFormat: 'as-provided',
callingGenerator: '',
});

expect(result).toEqual({
projectName: '@scope/libName',
names: {
projectSimpleName: 'libName',
projectFileName: 'libName',
},
importPath: '@scope/libName',
projectRoot: 'shared/@scope/libName',
projectNameAndRootFormat: 'as-provided',
});
});

it('should handle providing a path including "@" with multiple segments as the project name when format is "as-provided"', async () => {
const result = await determineProjectNameAndRootOptions(tree, {
name: 'shared/@scope/libName/testing',
projectType: 'library',
projectNameAndRootFormat: 'as-provided',
callingGenerator: '',
});

expect(result).toEqual({
projectName: '@scope/libName/testing',
names: {
projectSimpleName: 'testing',
projectFileName: 'libName-testing',
},
importPath: '@scope/libName/testing',
projectRoot: 'shared/@scope/libName/testing',
projectNameAndRootFormat: 'as-provided',
});
});

it('should handle providing a path including multiple "@" as the project name when format is "as-provided"', async () => {
const result = await determineProjectNameAndRootOptions(tree, {
name: 'shared/@foo/@scope/libName',
projectType: 'library',
projectNameAndRootFormat: 'as-provided',
callingGenerator: '',
});

expect(result).toEqual({
projectName: '@scope/libName',
names: {
projectSimpleName: 'libName',
projectFileName: 'libName',
},
importPath: '@scope/libName',
projectRoot: 'shared/@foo/@scope/libName',
projectNameAndRootFormat: 'as-provided',
});
});

it('should return the derived project name and directory', async () => {
const result = await determineProjectNameAndRootOptions(tree, {
name: 'libName',
Expand All @@ -653,6 +833,26 @@ describe('determineProjectNameAndRootOptions', () => {
});
});

it('should handle providing a path as the project name when format is "derived"', async () => {
const result = await determineProjectNameAndRootOptions(tree, {
name: 'shared/libName',
projectType: 'library',
projectNameAndRootFormat: 'derived',
callingGenerator: '',
});

expect(result).toEqual({
projectName: 'shared-lib-name',
names: {
projectSimpleName: 'lib-name',
projectFileName: 'shared-lib-name',
},
importPath: '@proj/shared/lib-name',
projectRoot: 'libs/shared/lib-name',
projectNameAndRootFormat: 'derived',
});
});

it(`should handle window's style paths correctly when format is "derived"`, async () => {
const result = await determineProjectNameAndRootOptions(tree, {
name: 'libName',
Expand Down
Loading

0 comments on commit a672cbb

Please sign in to comment.