-
Notifications
You must be signed in to change notification settings - Fork 117
fix(cli): traverse parent directories to find vite.config.ts in vp pack #1072
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
Merged
+252
−10
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
24fb2f7
fix(cli): traverse parent directories to find vite.config.ts in vp pack
kazupon 24c3c14
fix(cli): add CJS/MJS config file tests and improve catch comment
kazupon ec46391
Merge branch 'main' into fix/942
Brooooooklyn 2160c52
fix(cli): skip traverseUp when --no-config is specified in vp pack
kazupon b520491
Merge branch 'main' into fix/942
fengmk2 f167248
perf(cli): prioritize vite.config.ts in config file search order
kazupon fa87e26
Merge branch 'main' into fix/942
fengmk2 52bfd37
Merge branch 'main' into fix/942
fengmk2 2aa31df
test: update command-pack-monorepo snap test for cache invalidation
fengmk2 925fd97
test: skip command-pack-monorepo snap test on win32
fengmk2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,23 @@ | ||
| { | ||
| "ignoredPlatforms": ["win32"], | ||
| "commands": [ | ||
| { | ||
| "command": "vp run hello#build # should build the library", | ||
| "ignoreOutput": true | ||
| }, | ||
| "ls packages/hello/dist # should have the library", | ||
| "vp run hello#build 2>&1 | grep 'cache hit' # should hit cache", | ||
| "vp run hello#build 2>&1 # should hit cache but not working for now", | ||
| { | ||
| "command": "vp run array-config#build # should build the library supports array config", | ||
| "ignoreOutput": true | ||
| }, | ||
| "ls packages/array-config/dist # should have the library", | ||
| "vp run array-config#build 2>&1 | grep 'cache hit' # should hit cache", | ||
| "vp run array-config#build 2>&1 # should hit cache but not working", | ||
| { | ||
| "command": "vp run default-config#build # should build the library supports default config", | ||
| "ignoreOutput": true | ||
| }, | ||
| "ls packages/default-config/dist # should have the library", | ||
| "vp run default-config#build 2>&1 | grep 'cache hit' # should hit cache" | ||
| "vp run default-config#build 2>&1 # should hit cache but not working" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import fs from 'node:fs'; | ||
| import { mkdtempSync } from 'node:fs'; | ||
| import { tmpdir } from 'node:os'; | ||
| import path from 'node:path'; | ||
|
|
||
| import { afterEach, beforeEach, describe, expect, it } from 'vitest'; | ||
|
|
||
| import { findViteConfigUp } from '../resolve-vite-config'; | ||
|
|
||
| describe('findViteConfigUp', () => { | ||
| let tempDir: string; | ||
|
|
||
| beforeEach(() => { | ||
| // Resolve symlinks (macOS /var -> /private/var) to match path.resolve behavior | ||
| tempDir = fs.realpathSync(mkdtempSync(path.join(tmpdir(), 'vite-config-test-'))); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| fs.rmSync(tempDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| it('should find config in the start directory', () => { | ||
| fs.writeFileSync(path.join(tempDir, 'vite.config.ts'), ''); | ||
| const result = findViteConfigUp(tempDir, tempDir); | ||
| expect(result).toBe(path.join(tempDir, 'vite.config.ts')); | ||
| }); | ||
|
|
||
| it('should find config in a parent directory', () => { | ||
| const subDir = path.join(tempDir, 'packages', 'my-lib'); | ||
| fs.mkdirSync(subDir, { recursive: true }); | ||
| fs.writeFileSync(path.join(tempDir, 'vite.config.ts'), ''); | ||
|
|
||
| const result = findViteConfigUp(subDir, tempDir); | ||
| expect(result).toBe(path.join(tempDir, 'vite.config.ts')); | ||
| }); | ||
|
|
||
| it('should find config in an intermediate directory', () => { | ||
| const subDir = path.join(tempDir, 'packages', 'my-lib', 'src'); | ||
| fs.mkdirSync(subDir, { recursive: true }); | ||
| fs.writeFileSync(path.join(tempDir, 'packages', 'vite.config.ts'), ''); | ||
|
|
||
| const result = findViteConfigUp(subDir, tempDir); | ||
| expect(result).toBe(path.join(tempDir, 'packages', 'vite.config.ts')); | ||
| }); | ||
|
|
||
| it('should return undefined when no config exists', () => { | ||
| const subDir = path.join(tempDir, 'packages', 'my-lib'); | ||
| fs.mkdirSync(subDir, { recursive: true }); | ||
|
|
||
| const result = findViteConfigUp(subDir, tempDir); | ||
| expect(result).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should not traverse beyond stopDir', () => { | ||
| const parentConfig = path.join(tempDir, 'vite.config.ts'); | ||
| fs.writeFileSync(parentConfig, ''); | ||
| const stopDir = path.join(tempDir, 'packages'); | ||
| const subDir = path.join(stopDir, 'my-lib'); | ||
| fs.mkdirSync(subDir, { recursive: true }); | ||
|
|
||
| const result = findViteConfigUp(subDir, stopDir); | ||
| // Should not find the config in tempDir because stopDir is packages/ | ||
| expect(result).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should prefer the closest config file', () => { | ||
| const subDir = path.join(tempDir, 'packages', 'my-lib'); | ||
| fs.mkdirSync(subDir, { recursive: true }); | ||
| fs.writeFileSync(path.join(tempDir, 'vite.config.ts'), ''); | ||
| fs.writeFileSync(path.join(tempDir, 'packages', 'vite.config.ts'), ''); | ||
|
|
||
| const result = findViteConfigUp(subDir, tempDir); | ||
| expect(result).toBe(path.join(tempDir, 'packages', 'vite.config.ts')); | ||
| }); | ||
|
|
||
| it('should find .js config files', () => { | ||
| const subDir = path.join(tempDir, 'packages', 'my-lib'); | ||
| fs.mkdirSync(subDir, { recursive: true }); | ||
| fs.writeFileSync(path.join(tempDir, 'vite.config.js'), ''); | ||
|
|
||
| const result = findViteConfigUp(subDir, tempDir); | ||
| expect(result).toBe(path.join(tempDir, 'vite.config.js')); | ||
| }); | ||
|
|
||
| it('should find .mts config files', () => { | ||
| const subDir = path.join(tempDir, 'packages', 'my-lib'); | ||
| fs.mkdirSync(subDir, { recursive: true }); | ||
| fs.writeFileSync(path.join(tempDir, 'vite.config.mts'), ''); | ||
|
|
||
| const result = findViteConfigUp(subDir, tempDir); | ||
| expect(result).toBe(path.join(tempDir, 'vite.config.mts')); | ||
| }); | ||
|
|
||
| it('should find .cjs config files', () => { | ||
| const subDir = path.join(tempDir, 'packages', 'my-lib'); | ||
| fs.mkdirSync(subDir, { recursive: true }); | ||
| fs.writeFileSync(path.join(tempDir, 'vite.config.cjs'), ''); | ||
|
|
||
| const result = findViteConfigUp(subDir, tempDir); | ||
| expect(result).toBe(path.join(tempDir, 'vite.config.cjs')); | ||
| }); | ||
|
|
||
| it('should find .cts config files', () => { | ||
| const subDir = path.join(tempDir, 'packages', 'my-lib'); | ||
| fs.mkdirSync(subDir, { recursive: true }); | ||
| fs.writeFileSync(path.join(tempDir, 'vite.config.cts'), ''); | ||
|
|
||
| const result = findViteConfigUp(subDir, tempDir); | ||
| expect(result).toBe(path.join(tempDir, 'vite.config.cts')); | ||
| }); | ||
|
|
||
| it('should find .mjs config files', () => { | ||
| const subDir = path.join(tempDir, 'packages', 'my-lib'); | ||
| fs.mkdirSync(subDir, { recursive: true }); | ||
| fs.writeFileSync(path.join(tempDir, 'vite.config.mjs'), ''); | ||
|
|
||
| const result = findViteConfigUp(subDir, tempDir); | ||
| expect(result).toBe(path.join(tempDir, 'vite.config.mjs')); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.