-
Notifications
You must be signed in to change notification settings - Fork 40
chore: swap globby with tinyglobby #1017
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
Open
l2ysho
wants to merge
17
commits into
master
Choose a base branch
from
1007-swap-globby-with-tinyglobby
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
bf24828
swapt globby for tinyglobby
l2ysho 2747b91
support nested gitignores
l2ysho b9c816c
update test
l2ysho 6db1f11
fix gitignore paths
l2ysho 4742277
Merge branch 'master' into 1007-swap-globby-with-tinyglobby
l2ysho 039076e
remove ignore and use git ls-files
l2ysho 45fa8bc
remove unused tests
l2ysho e4147a9
Merge remote-tracking branch 'origin/1007-swap-globby-with-tinyglobby…
l2ysho fca261d
update package lock
l2ysho 1d6434d
fix test
l2ysho e3a8cf2
feat: fall back to ignore package for gitignore rules when git is una…
l2ysho fc73b3d
refactor: use async readFile, add comment on CJS cast, add nested git…
l2ysho 2c4611b
Merge branch 'master' into 1007-swap-globby-with-tinyglobby
l2ysho b1657f6
feat(gitignore-fallback): add parent .gitignore support
l2ysho 66a89b1
Merge branch 'master' into 1007-swap-globby-with-tinyglobby
l2ysho e027073
Merge branch 'master' into 1007-swap-globby-with-tinyglobby
l2ysho 857f8b8
Merge branch 'master' into 1007-swap-globby-with-tinyglobby
l2ysho 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
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,162 @@ | ||
| import { mkdirSync, writeFileSync } from 'node:fs'; | ||
| import { join } from 'node:path'; | ||
|
|
||
| import { ensureFolderExistsSync } from '../../../src/lib/files.js'; | ||
| import { getActorLocalFilePaths } from '../../../src/lib/utils.js'; | ||
| import { useTempPath } from '../../__setup__/hooks/useTempPath.js'; | ||
|
|
||
| // Mock execSync to simulate git not being available. | ||
| // vi.mock is hoisted before imports, so utils.ts gets the mocked version. | ||
| vi.mock('node:child_process', async (importOriginal) => { | ||
| const original = await importOriginal<typeof import('node:child_process')>(); | ||
| return { | ||
| ...original, | ||
| execSync: () => { | ||
| throw new Error('not a git repository'); | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| const TEST_DIR = 'gitignore-fallback-test-dir'; | ||
| const FOLDERS = ['src', 'src/utils']; | ||
| const FOLDERS_TO_IGNORE = ['dist', 'src/generated']; | ||
| const FILES = ['main.js', 'src/index.js', 'src/utils/helper.js']; | ||
| const FILES_IN_IGNORED_DIR = ['dist/bundle.js', 'src/generated/types.js']; | ||
| const FILES_TO_IGNORE = ['debug.log']; | ||
|
|
||
| describe('Utils - gitignore fallback (no git)', () => { | ||
| const { tmpPath, joinPath, beforeAllCalls, afterAllCalls } = useTempPath(TEST_DIR, { | ||
| create: true, | ||
| remove: true, | ||
| cwd: false, | ||
| cwdParent: false, | ||
| }); | ||
|
|
||
| beforeAll(async () => { | ||
| await beforeAllCalls(); | ||
|
|
||
| // NOTE: No git init here — execSync is mocked to throw, triggering the fallback path. | ||
|
|
||
| FOLDERS.concat(FOLDERS_TO_IGNORE).forEach((folder) => { | ||
| ensureFolderExistsSync(tmpPath, folder); | ||
| }); | ||
|
|
||
| FILES.concat(FILES_TO_IGNORE, FILES_IN_IGNORED_DIR).forEach((file) => | ||
| writeFileSync(joinPath(file), 'content', { flag: 'w' }), | ||
| ); | ||
|
|
||
| const toIgnore = FOLDERS_TO_IGNORE.concat(FILES_TO_IGNORE).join('\n'); | ||
| writeFileSync(joinPath('.gitignore'), toIgnore, { flag: 'w' }); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await afterAllCalls(); | ||
| }); | ||
|
|
||
| it('should exclude files listed in .gitignore when git is unavailable', async () => { | ||
| const paths = await getActorLocalFilePaths(tmpPath); | ||
|
|
||
| FILES.forEach((file) => expect(paths).toContain(file)); | ||
| FILES_IN_IGNORED_DIR.concat(FILES_TO_IGNORE).forEach((file) => expect(paths).not.toContain(file)); | ||
| }); | ||
| }); | ||
|
|
||
| const NESTED_TEST_DIR = 'gitignore-nested-test-dir'; | ||
|
|
||
| describe('Utils - nested .gitignore scoping (no git)', () => { | ||
| const { tmpPath, joinPath, beforeAllCalls, afterAllCalls } = useTempPath(NESTED_TEST_DIR, { | ||
| create: true, | ||
| remove: true, | ||
| cwd: false, | ||
| cwdParent: false, | ||
| }); | ||
|
|
||
| beforeAll(async () => { | ||
| await beforeAllCalls(); | ||
|
|
||
| // Create directory structure | ||
| ensureFolderExistsSync(tmpPath, 'src'); | ||
| ensureFolderExistsSync(tmpPath, 'src/internal'); | ||
|
|
||
| // Create files: one public, one that should be scoped-ignored by src/.gitignore | ||
| writeFileSync(joinPath('src/public.js'), 'content', { flag: 'w' }); | ||
| writeFileSync(joinPath('src/internal/secret.js'), 'content', { flag: 'w' }); | ||
|
|
||
| // Only a nested .gitignore — the root has no entry for src/internal | ||
| writeFileSync(joinPath('src/.gitignore'), 'internal/', { flag: 'w' }); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await afterAllCalls(); | ||
| }); | ||
|
|
||
| it('should exclude files matched by a nested .gitignore scoped to its own directory', async () => { | ||
| const paths = await getActorLocalFilePaths(tmpPath); | ||
|
|
||
| // src/public.js should be present | ||
| expect(paths).toContain('src/public.js'); | ||
|
|
||
| // src/internal/secret.js should be excluded by src/.gitignore's `internal/` rule | ||
| expect(paths).not.toContain('src/internal/secret.js'); | ||
| }); | ||
| }); | ||
|
|
||
| const PARENT_TEST_DIR = 'gitignore-parent-test-dir'; | ||
|
|
||
| describe('Utils - parent .gitignore applied to subproject (no git)', () => { | ||
| // tmpPath is the "project root" that holds the parent .gitignore. | ||
| // The actual cwd passed to getActorLocalFilePaths is tmpPath/subproject/. | ||
| const { tmpPath, beforeAllCalls, afterAllCalls } = useTempPath(PARENT_TEST_DIR, { | ||
| create: true, | ||
| remove: true, | ||
| cwd: false, | ||
| cwdParent: false, | ||
| }); | ||
|
|
||
| let subprojectPath: string; | ||
|
|
||
| beforeAll(async () => { | ||
| await beforeAllCalls(); | ||
|
|
||
| subprojectPath = join(tmpPath, 'subproject'); | ||
|
|
||
| // Parent .gitignore — rules that should apply to everything inside subproject/. | ||
| // No fake .git is needed: the ancestor-walker already stops at the apify-cli | ||
| // repo root (.git lives there) before touching its own .gitignore. | ||
| writeFileSync(join(tmpPath, '.gitignore'), '*.secret\nbuild/\n', { flag: 'w' }); | ||
|
|
||
| // Subproject directory structure | ||
| mkdirSync(subprojectPath, { recursive: true }); | ||
| ensureFolderExistsSync(subprojectPath, 'src'); | ||
| ensureFolderExistsSync(subprojectPath, 'build'); | ||
|
|
||
| // Files that should be kept | ||
| writeFileSync(join(subprojectPath, 'main.js'), 'content', { flag: 'w' }); | ||
| writeFileSync(join(subprojectPath, 'src', 'utils.js'), 'content', { flag: 'w' }); | ||
|
|
||
| // Files/dirs that should be excluded by parent .gitignore | ||
| writeFileSync(join(subprojectPath, 'config.secret'), 'content', { flag: 'w' }); | ||
| writeFileSync(join(subprojectPath, 'src', 'db.secret'), 'content', { flag: 'w' }); | ||
| writeFileSync(join(subprojectPath, 'build', 'output.js'), 'content', { flag: 'w' }); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await afterAllCalls(); | ||
| }); | ||
|
|
||
| it('should exclude files matched by *.secret pattern in parent .gitignore', async () => { | ||
| const paths = await getActorLocalFilePaths(subprojectPath); | ||
|
|
||
| expect(paths).toContain('main.js'); | ||
| expect(paths).toContain('src/utils.js'); | ||
|
|
||
| expect(paths).not.toContain('config.secret'); | ||
| expect(paths).not.toContain('src/db.secret'); | ||
| }); | ||
|
|
||
| it('should exclude directory matched by build/ pattern in parent .gitignore', async () => { | ||
| const paths = await getActorLocalFilePaths(subprojectPath); | ||
|
|
||
| expect(paths).not.toContain('build/output.js'); | ||
| }); | ||
| }); |
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.