Skip to content

Commit 0db0d37

Browse files
authored
fix(cli): add missing .npmrc (#175)
### TL;DR Fixed monorepo initialization by properly handling dotfiles during template creation. ### What changed? - Moved `renameFiles()` call before package manager setup to ensure dotfiles are renamed early in the initialization process - Added `.npmrc` and `.yarnrc.yml` to the list of files that need to be renamed - Renamed template files to use underscore prefix (`_npmrc`, `_yarnrc.yml`) to avoid git ignoring them - Added existence check before attempting to rename files to prevent errors - Updated file renaming logic to handle cases where source files might not exist ### How to test? 1. Create a new monorepo using the CLI 2. Verify that `.gitignore`, `.npmrc`, and `.yarnrc.yml` files are correctly created 3. Test with different package managers (npm, yarn, pnpm) to ensure proper initialization ### Why make this change? Dotfiles like `.npmrc` and `.yarnrc.yml` are essential for proper package manager configuration in monorepos. The previous implementation didn't properly handle these files during template creation, which could lead to missing configuration files. This change ensures all necessary dotfiles are correctly created during monorepo initialization.
1 parent 0fb43d9 commit 0db0d37

7 files changed

Lines changed: 27 additions & 11 deletions

File tree

packages/global/snap-tests/new-monorepo/snap.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ qwik-ts qwik
4040
vite new --lib packages/my-lib
4141

4242

43-
> cd hello-vite-plus && ls # check files
43+
> cd hello-vite-plus && ls -a . # check files
44+
.
45+
..
46+
.gitignore
47+
.npmrc
4448
README.md
4549
apps
4650
package.json
@@ -59,7 +63,9 @@ vite.config.ts
5963
vite run dev
6064

6165

62-
> cd hello-vite-plus && ls apps
66+
> cd hello-vite-plus && ls -a apps
67+
.
68+
..
6369
my-app
6470
website
6571

@@ -76,7 +82,9 @@ website
7682
vite run dev
7783

7884

79-
> cd hello-vite-plus && ls packages
85+
> cd hello-vite-plus && ls -a packages
86+
.
87+
..
8088
my-lib
8189

8290
> cd hello-vite-plus && vp new --lib tools/my-tool --template default # add lib new not exists tools directory
@@ -92,5 +100,7 @@ my-lib
92100
vite run dev
93101

94102

95-
> cd hello-vite-plus && ls tools
103+
> cd hello-vite-plus && ls -a tools
104+
.
105+
..
96106
my-tool

packages/global/snap-tests/new-monorepo/steps.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"commands": [
33
"vp new -h # show help",
44
"vp new --template vanilla-ts --monorepo --pm pnpm --git false --overwrite hello-vite-plus # create monorepo",
5-
"cd hello-vite-plus && ls # check files",
5+
"cd hello-vite-plus && ls -a . # check files",
66
"cd hello-vite-plus && vp new --app --template vanilla-ts apps/my-app # add app",
7-
"cd hello-vite-plus && ls apps",
7+
"cd hello-vite-plus && ls -a apps",
88
"cd hello-vite-plus && vp new --lib packages/my-lib --template react # add lib",
9-
"cd hello-vite-plus && ls packages",
9+
"cd hello-vite-plus && ls -a packages",
1010
"cd hello-vite-plus && vp new --lib tools/my-tool --template default # add lib new not exists tools directory",
11-
"cd hello-vite-plus && ls tools"
11+
"cd hello-vite-plus && ls -a tools"
1212
]
1313
}

packages/global/snap-tests/new-singlerepo/snap.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
vite run dev
1010

1111

12-
> cd hello-vite-plus && ls # check files
12+
> cd hello-vite-plus && ls -a . # check files
13+
.
14+
..
15+
.gitignore
16+
.npmrc
1317
index.html
1418
package.json
1519
public
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"commands": [
33
"vp new --template vanilla-ts --monorepo false --pm pnpm --git false --overwrite hello-vite-plus # create singlerepo",
4-
"cd hello-vite-plus && ls # check files"
4+
"cd hello-vite-plus && ls -a . # check files"
55
]
66
}

packages/global/src/new.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ async function initMonorepo(rootProjectDir: string, packageManager: string) {
755755
'templates/monorepo',
756756
);
757757
copyDir(templateDir, rootProjectDir);
758+
renameFiles(rootProjectDir);
758759
if (packageManager === 'pnpm') {
759760
// remove workspaces field
760761
editFile(path.join(rootProjectDir, 'package.json'), (content) => {
@@ -784,11 +785,12 @@ async function initMonorepo(rootProjectDir: string, packageManager: string) {
784785
}
785786

786787
await setPackageManager(rootProjectDir, packageManager);
787-
renameFiles(rootProjectDir);
788788
}
789789

790790
const RENAME_FILES: Record<string, string> = {
791791
_gitignore: '.gitignore',
792+
_npmrc: '.npmrc',
793+
'_yarnrc.yml': '.yarnrc.yml',
792794
};
793795

794796
function renameFiles(projectDir: string) {
File renamed without changes.

0 commit comments

Comments
 (0)