fix(misc): handle cwd correctly when generating artifacts with as-provided (#22411)
This commit is contained in:
parent
a837f7f877
commit
c20e00cab8
@ -166,6 +166,33 @@ describe('determineArtifactNameAndDirectoryOptions', () => {
|
|||||||
restoreCwd();
|
restoreCwd();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not duplicate the cwd when the provided directory starts with the cwd and format is "as-provided"', async () => {
|
||||||
|
addProjectConfiguration(tree, 'app1', {
|
||||||
|
root: 'apps/app1',
|
||||||
|
projectType: 'application',
|
||||||
|
});
|
||||||
|
setCwd('apps/app1');
|
||||||
|
|
||||||
|
const result = await determineArtifactNameAndDirectoryOptions(tree, {
|
||||||
|
name: 'myComponent',
|
||||||
|
directory: 'apps/app1',
|
||||||
|
nameAndDirectoryFormat: 'as-provided',
|
||||||
|
artifactType: 'component',
|
||||||
|
callingGenerator: '@my-org/my-plugin:component',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result).toStrictEqual({
|
||||||
|
artifactName: 'myComponent',
|
||||||
|
directory: 'apps/app1',
|
||||||
|
fileName: 'myComponent',
|
||||||
|
filePath: 'apps/app1/myComponent.ts',
|
||||||
|
project: 'app1',
|
||||||
|
nameAndDirectoryFormat: 'as-provided',
|
||||||
|
});
|
||||||
|
|
||||||
|
restoreCwd();
|
||||||
|
});
|
||||||
|
|
||||||
it('should return the options as provided when directory is provided', async () => {
|
it('should return the options as provided when directory is provided', async () => {
|
||||||
addProjectConfiguration(tree, 'app1', {
|
addProjectConfiguration(tree, 'app1', {
|
||||||
root: 'apps/app1',
|
root: 'apps/app1',
|
||||||
|
|||||||
@ -237,9 +237,20 @@ function getAsProvidedOptions(
|
|||||||
): NameAndDirectoryOptions {
|
): NameAndDirectoryOptions {
|
||||||
const relativeCwd = getRelativeCwd();
|
const relativeCwd = getRelativeCwd();
|
||||||
|
|
||||||
const asProvidedDirectory = options.directory
|
let asProvidedDirectory: string;
|
||||||
? joinPathFragments(relativeCwd, options.directory)
|
if (options.directory) {
|
||||||
: relativeCwd;
|
// append the directory to the current working directory if it doesn't start with it
|
||||||
|
if (
|
||||||
|
options.directory === relativeCwd ||
|
||||||
|
options.directory.startsWith(`${relativeCwd}/`)
|
||||||
|
) {
|
||||||
|
asProvidedDirectory = options.directory;
|
||||||
|
} else {
|
||||||
|
asProvidedDirectory = joinPathFragments(relativeCwd, options.directory);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
asProvidedDirectory = relativeCwd;
|
||||||
|
}
|
||||||
const asProvidedProject = findProjectFromPath(tree, asProvidedDirectory);
|
const asProvidedProject = findProjectFromPath(tree, asProvidedDirectory);
|
||||||
|
|
||||||
const asProvidedFileName =
|
const asProvidedFileName =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user