-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixes an issue where the cache could not save .dot directories (#…
- Loading branch information
1 parent
e5f4c12
commit ccb3a00
Showing
14 changed files
with
177 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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