Skip to content

Commit

Permalink
fix: turn on the template npmrc lock file (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
winchesHe authored Nov 12, 2024
1 parent 87fda63 commit 654349e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/actions/init-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as p from '@clack/prompts';
import chalk from 'chalk';
import {join} from 'pathe';

import {changeNpmrc} from '@helpers/actions/init/change-npmrc';
import {downloadTemplate} from '@helpers/fetch';
import {fixPnpm} from '@helpers/fix';
import {checkInitOptions} from '@helpers/init';
Expand Down Expand Up @@ -73,10 +74,13 @@ export async function initAction(_projectName: string, options: InitActionOption
renameTemplate(VITE_DIR, projectName);
}

const npmrcFile = resolver(`${ROOT}/${projectName}/.npmrc`);

/** ======================== Change default npmrc content ======================== */
changeNpmrc(npmrcFile);

/** ======================== Pnpm setup (optional) ======================== */
if (packageName === 'pnpm') {
const npmrcFile = resolver(`${ROOT}/${projectName}/.npmrc`);

fixPnpm(npmrcFile, true, false, ({message}) => {
p.log.message(message);
});
Expand Down
11 changes: 11 additions & 0 deletions src/helpers/actions/init/change-npmrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {writeFileSync} from 'node:fs';

const DEFAULT_NPMRC_CONTENT = `package-lock=true`;

/**
* Change the npmrc file to the default content
* Currently it is using `package-lock=false` which won't generate the lockfile
*/
export function changeNpmrc(npmrcFile: string) {
writeFileSync(npmrcFile, DEFAULT_NPMRC_CONTENT, 'utf-8');
}

0 comments on commit 654349e

Please sign in to comment.