fix(misc): nx init should add .nx/cache to gitignore (#19961)

This commit is contained in:
Craigory Coppola 2023-10-31 18:23:51 -04:00 committed by GitHub
parent eed2cc5810
commit 18f71d25e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 1 deletions

View File

@ -13,6 +13,7 @@ import {
initCloud,
printFinalMessage,
runInstall,
updateGitIgnore,
} from './utils';
type Options = Pick<InitArgs, 'nxCloud' | 'interactive' | 'cacheable'>;
@ -88,6 +89,7 @@ export async function addNxToMonorepo(options: Options) {
scriptOutputs
);
updateGitIgnore(repoRoot);
addDepsToPackageJson(repoRoot);
output.log({ title: '📦 Installing dependencies' });

View File

@ -23,6 +23,7 @@ import {
markRootPackageJsonAsNxProject,
printFinalMessage,
runInstall,
updateGitIgnore,
} from './utils';
import { nxVersion } from '../../../utils/versions';
@ -117,6 +118,7 @@ export async function addNxToNest(options: Options, packageJson: PackageJson) {
const pmc = getPackageManagerCommand();
updateGitIgnore(repoRoot);
addDepsToPackageJson(repoRoot);
addNestPluginToPackageJson(repoRoot);
markRootPackageJsonAsNxProject(

View File

@ -11,6 +11,7 @@ import {
markRootPackageJsonAsNxProject,
printFinalMessage,
runInstall,
updateGitIgnore,
} from './utils';
type Options = Pick<InitArgs, 'nxCloud' | 'interactive' | 'cacheable'>;
@ -72,6 +73,7 @@ export async function addNxToNpmRepo(options: Options) {
const pmc = getPackageManagerCommand();
updateGitIgnore(repoRoot);
addDepsToPackageJson(repoRoot);
markRootPackageJsonAsNxProject(
repoRoot,

View File

@ -17,6 +17,7 @@ import {
} from '../../../utils/package-manager';
import { joinPathFragments } from '../../../utils/path';
import { nxVersion } from '../../../utils/versions';
import { readFileSync, writeFileSync } from 'fs';
export async function askAboutNxCloud(): Promise<boolean> {
return await enquirer
@ -121,6 +122,17 @@ export function addDepsToPackageJson(repoRoot: string) {
writeJsonFile(path, json);
}
export function updateGitIgnore(root: string) {
const ignorePath = join(root, '.gitignore');
try {
let contents = readFileSync(ignorePath, 'utf-8');
if (!contents.includes('.nx/cache')) {
contents = [contents, '', '.nx/cache'].join('\n');
writeFileSync(ignorePath, contents, 'utf-8');
}
} catch {}
}
export function runInstall(
repoRoot: string,
pmc: PackageManagerCommands = getPackageManagerCommand()

View File

@ -2,7 +2,6 @@ import { execSync } from 'child_process';
import { prompt } from 'enquirer';
import { existsSync } from 'fs';
import { prerelease } from 'semver';
import * as parser from 'yargs-parser';
import { addNxToMonorepo } from './implementation/add-nx-to-monorepo';
import { addNxToNest } from './implementation/add-nx-to-nest';
import { addNxToNpmRepo } from './implementation/add-nx-to-npm-repo';