-
Notifications
You must be signed in to change notification settings - Fork 70
fix: fixes an issue where the cache could not save .dot directories #4843
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
21 changes: 21 additions & 0 deletions
21
packages/build/tests/plugins/fixtures/cache_utils/build.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { mkdir, readdir, writeFile } from 'fs/promises'; | ||
import { existsSync } from 'fs'; | ||
|
||
|
||
if (existsSync('dist/.dot')) { | ||
console.log('content inside dist/.dot:'); | ||
console.log((await readdir('dist/.dot')).join('\n')); | ||
} | ||
if (existsSync('dist/other')) { | ||
console.log('content inside dist/other:'); | ||
console.log((await readdir('dist/other')).join('\n')); | ||
} | ||
|
||
console.log('Generate files'); | ||
await mkdir('dist/.dot', { recursive: true }); | ||
await mkdir('dist/other', { recursive: true }); | ||
|
||
await Promise.all([ | ||
writeFile('dist/.dot/hello.txt', ''), | ||
writeFile('dist/other/index.html', '<h1>hello world</h1>'), | ||
]); |
8 changes: 8 additions & 0 deletions
8
packages/build/tests/plugins/fixtures/cache_utils/netlify-plugin-cache/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
onPreBuild: async ({ utils }) => { | ||
await utils.cache.restore('dist'); | ||
}, | ||
onPostBuild: async ({ utils }) => { | ||
await utils.cache.save('dist'); | ||
}, | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/build/tests/plugins/fixtures/cache_utils/netlify-plugin-cache/manifest.yaml
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 @@ | ||
name: custom-cache-plugin |
5 changes: 5 additions & 0 deletions
5
packages/build/tests/plugins/fixtures/cache_utils/netlify.toml
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,5 @@ | ||
[build] | ||
command = "node build.mjs" | ||
|
||
[[plugins]] | ||
package = "/netlify-plugin-cache" |
3 changes: 3 additions & 0 deletions
3
packages/build/tests/plugins/fixtures/cache_utils/package.json
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,3 @@ | ||
{ | ||
"type": "commonjs" | ||
} |
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
Binary file not shown.
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
File renamed without changes.
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,26 +1,33 @@ | ||
import { promises as fs } from 'fs' | ||
|
||
import { pathExists } from 'path-exists' | ||
import { expect, test, vi } from 'vitest' | ||
import { SpyInstance, afterEach, beforeEach, expect, test, vi } from 'vitest' | ||
|
||
import { restore, save } from '../src/main.js' | ||
|
||
import { createTmpDir, removeFiles } from './helpers/main.js' | ||
|
||
test('Should allow changing the cache directory', async () => { | ||
const [cacheDir, srcDir] = await Promise.all([createTmpDir(), createTmpDir()]) | ||
const cwdSpy = vi.spyOn(process, 'cwd').mockImplementation(() => srcDir) | ||
try { | ||
const srcFile = `${srcDir}/test` | ||
await fs.writeFile(srcFile, '') | ||
expect(await save(srcFile, { cacheDir })).toBe(true) | ||
const cachedFiles = await fs.readdir(cacheDir) | ||
expect(cachedFiles.length).toBe(1) | ||
await removeFiles(srcFile) | ||
expect(await restore(srcFile, { cacheDir })).toBe(true) | ||
expect(await pathExists(srcFile)).toBe(true) | ||
} finally { | ||
await removeFiles([cacheDir, srcDir]) | ||
} | ||
let cacheDir, srcDir: string | ||
let cwdSpy: SpyInstance<[], string> | ||
|
||
beforeEach(async () => { | ||
cacheDir = await createTmpDir() | ||
srcDir = await createTmpDir() | ||
cwdSpy = vi.spyOn(process, 'cwd').mockImplementation(() => srcDir) | ||
}) | ||
|
||
afterEach(async () => { | ||
await removeFiles([cacheDir, srcDir]) | ||
cwdSpy.mockRestore() | ||
}) | ||
|
||
test('Should allow changing the cache directory', async () => { | ||
const srcFile = `${srcDir}/test` | ||
await fs.writeFile(srcFile, '') | ||
expect(await save(srcFile, { cacheDir })).toBe(true) | ||
const cachedFiles = await fs.readdir(cacheDir) | ||
expect(cachedFiles.length).toBe(1) | ||
await removeFiles(srcFile) | ||
expect(await restore(srcFile, { cacheDir })).toBe(true) | ||
expect(await pathExists(srcFile)).toBe(true) | ||
}) |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the comment, but wouldn't it be better to do some explicit matching here so we do not even need the comment?
Something like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point I hate those snapshots anyway π