Skip to content

Commit 324f81c

Browse files
fix(qwik-nx): deduce layout directory (#152)
1 parent 95c0423 commit 324f81c

File tree

22 files changed

+4011
-349
lines changed

22 files changed

+4011
-349
lines changed

packages/qwik-nx/src/generators/application/__snapshots__/generator.spec.ts.snap

Lines changed: 408 additions & 0 deletions
Large diffs are not rendered by default.

packages/qwik-nx/src/generators/application/generator.spec.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
2-
import { Tree, readProjectConfiguration } from '@nx/devkit';
2+
import { Tree, joinPathFragments, readProjectConfiguration } from '@nx/devkit';
33

44
import generator from './generator';
55
import { QwikAppGeneratorSchema } from './schema';
@@ -77,4 +77,30 @@ describe('qwik-nx generator', () => {
7777
expect(appTree.exists('apps/myapp-e2e/cypress.config.ts')).toBeTruthy();
7878
});
7979
});
80+
81+
describe('should be able to resolve directory path based on the workspace layout', () => {
82+
test.each`
83+
directory | expectedProjectName | projectRoot
84+
${'/frontend'} | ${'frontend-myapp'} | ${'apps/frontend/myapp'}
85+
${'apps'} | ${'myapp'} | ${'apps/myapp'}
86+
${'/apps/frontend'} | ${'frontend-myapp'} | ${'apps/frontend/myapp'}
87+
${'apps/frontend'} | ${'frontend-myapp'} | ${'apps/frontend/myapp'}
88+
${'/packages'} | ${'myapp'} | ${'packages/myapp'}
89+
${'/packages/frontend'} | ${'frontend-myapp'} | ${'packages/frontend/myapp'}
90+
`(
91+
'when directory is "$directory" should generate "$expectedProjectName" with project\'s root at "$projectRoot"',
92+
async ({ directory, expectedProjectName, projectRoot }) => {
93+
await generator(appTree, { ...defaultOptions, directory });
94+
const config = readProjectConfiguration(appTree, expectedProjectName);
95+
96+
expect(config.root).toBe(projectRoot);
97+
expect(config).toMatchSnapshot(
98+
JSON.stringify(directory, expectedProjectName)
99+
);
100+
expect(
101+
appTree.exists(joinPathFragments(projectRoot, 'vite.config.ts'))
102+
).toBeTruthy();
103+
}
104+
);
105+
});
80106
});

packages/qwik-nx/src/generators/application/utils/normalize-options.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
extractLayoutDirectory,
23
getWorkspaceLayout,
34
names,
45
normalizePath,
@@ -9,8 +10,9 @@ import { getRelativePathToRootTsConfig } from '@nx/js';
910
import { NormalizedSchema, QwikAppGeneratorSchema } from '../schema';
1011

1112
function normalizeDirectory(options: QwikAppGeneratorSchema) {
12-
return options.directory
13-
? `${names(options.directory).fileName}/${names(options.name).fileName}`
13+
const { projectDirectory } = extractLayoutDirectory(options.directory ?? '');
14+
return projectDirectory
15+
? `${names(projectDirectory).fileName}/${names(options.name).fileName}`
1416
: names(options.name).fileName;
1517
}
1618

@@ -25,7 +27,8 @@ export function normalizeOptions(
2527
const appDirectory = normalizeDirectory(options);
2628
const appProjectName = normalizeProjectName(options);
2729

28-
const { appsDir } = getWorkspaceLayout(host);
30+
const { layoutDirectory } = extractLayoutDirectory(options.directory ?? '');
31+
const appsDir = layoutDirectory ?? getWorkspaceLayout(host).appsDir;
2932
const projectRoot = normalizePath(`${appsDir}/${appDirectory}`);
3033

3134
const parsedTags = options.tags

0 commit comments

Comments
 (0)