Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(misc): use generated directory path as cwd rather than attempting to rederive it #16740

Merged
merged 2 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/create-nx-workspace/src/create-empty-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ export async function createEmptyWorkspace<T extends CreateWorkspaceOptions>(
options.packageManager = packageManager;
}

const directory = getFileName(name);

const args = unparse({
...options,
}).join(' ');

const pmc = getPackageManagerCommand(packageManager);

const command = `new ${name} ${args}`;
const command = `new ${directory} ${args}`;

const workingDir = process.cwd().replace(/\\/g, '/');
let nxWorkspaceRoot = `"${workingDir}"`;
Expand All @@ -56,15 +58,15 @@ export async function createEmptyWorkspace<T extends CreateWorkspaceOptions>(
}
}
let workspaceSetupSpinner = ora(
`Creating your workspace in ${getFileName(name)}`
`Creating your workspace in ${directory}`
).start();

try {
const fullCommand = `${pmc.exec} nx ${command} --nxWorkspaceRoot=${nxWorkspaceRoot}`;
await execAndWait(fullCommand, tmpDir);

workspaceSetupSpinner.succeed(
`Successfully created the workspace: ${getFileName(name)}.`
`Successfully created the workspace: ${directory}.`
);
} catch (e) {
workspaceSetupSpinner.fail();
Expand All @@ -80,5 +82,5 @@ export async function createEmptyWorkspace<T extends CreateWorkspaceOptions>(
} finally {
workspaceSetupSpinner.stop();
}
return join(workingDir, getFileName(name));
return join(workingDir, directory);
}
4 changes: 2 additions & 2 deletions packages/create-nx-workspace/src/create-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ export async function createWorkspace<T extends CreateWorkspaceOptions>(

let nxCloudInstallRes;
if (nxCloud) {
nxCloudInstallRes = await setupNxCloud(name, packageManager);
nxCloudInstallRes = await setupNxCloud(directory, packageManager);
}
if (ci) {
await setupCI(
name,
directory,
ci,
packageManager,
nxCloud && nxCloudInstallRes?.code === 0
Expand Down
5 changes: 2 additions & 3 deletions packages/create-nx-workspace/src/utils/ci/setup-ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { execAndWait } from '../child-process-utils';
import { mapErrorToBodyLines } from '../error-utils';
import { output } from '../output';
import { getPackageManagerCommand, PackageManager } from '../package-manager';
import { getFileName } from '../string-utils';

export async function setupCI(
name: string,
directory: string,
ci: string,
packageManager: PackageManager,
nxCloudSuccessfullyInstalled: boolean
Expand All @@ -27,7 +26,7 @@ export async function setupCI(
const pmc = getPackageManagerCommand(packageManager);
const res = await execAndWait(
`${pmc.exec} nx g @nx/workspace:ci-workflow --ci=${ci}`,
join(process.cwd(), getFileName(name))
directory
);
ciSpinner.succeed('CI workflow has been generated successfully');
return res;
Expand Down
5 changes: 2 additions & 3 deletions packages/create-nx-workspace/src/utils/nx/nx-cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ import { join } from 'path';
import { execAndWait } from '../child-process-utils';
import { output } from '../output';
import { getPackageManagerCommand, PackageManager } from '../package-manager';
import { getFileName } from '../string-utils';
import { mapErrorToBodyLines } from '../error-utils';

export async function setupNxCloud(
name: string,
directory: string,
packageManager: PackageManager
) {
const nxCloudSpinner = ora(`Setting up NxCloud`).start();
try {
const pmc = getPackageManagerCommand(packageManager);
const res = await execAndWait(
`${pmc.exec} nx g nx-cloud:init --no-analytics --installationSource=create-nx-workspace`,
join(process.cwd(), getFileName(name))
directory
);
nxCloudSpinner.succeed('NxCloud has been set up successfully');
return res;
Expand Down