Skip to content

Commit ccb3a00

Browse files
author
Lukas Holzer
authored
fix: fixes an issue where the cache could not save .dot directories (#4843)
Fixes https://github.com/netlify/pillar-workflow/issues/1017
1 parent e5f4c12 commit ccb3a00

File tree

14 files changed

+177
-35
lines changed

14 files changed

+177
-35
lines changed

packages/build/src/core/constants.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export const getConstants = async function ({
2121
}) {
2222
const isLocal = mode !== 'buildbot'
2323
const normalizedCacheDir = getCacheDir({ cacheDir, cwd: buildDir })
24-
2524
const constants = {
2625
// Path to the Netlify configuration file
2726
CONFIG_PATH: configPath,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { mkdir, readdir, writeFile } from 'fs/promises';
2+
import { existsSync } from 'fs';
3+
4+
5+
if (existsSync('dist/.dot')) {
6+
console.log('content inside dist/.dot:');
7+
console.log((await readdir('dist/.dot')).join('\n'));
8+
}
9+
if (existsSync('dist/other')) {
10+
console.log('content inside dist/other:');
11+
console.log((await readdir('dist/other')).join('\n'));
12+
}
13+
14+
console.log('Generate files');
15+
await mkdir('dist/.dot', { recursive: true });
16+
await mkdir('dist/other', { recursive: true });
17+
18+
await Promise.all([
19+
writeFile('dist/.dot/hello.txt', ''),
20+
writeFile('dist/other/index.html', '<h1>hello world</h1>'),
21+
]);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
onPreBuild: async ({ utils }) => {
3+
await utils.cache.restore('dist');
4+
},
5+
onPostBuild: async ({ utils }) => {
6+
await utils.cache.save('dist');
7+
},
8+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name: custom-cache-plugin
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[build]
2+
command = "node build.mjs"
3+
4+
[[plugins]]
5+
package = "/netlify-plugin-cache"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}

packages/build/tests/plugins/snapshots/tests.js.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,80 @@ Generated by [AVA](https://avajs.dev).
19431943
(Netlify Build completed in 1ms)␊
19441944
Build step duration: Netlify Build completed in 1ms`
19451945

1946+
## Cache utils are caching .dot directories as well
1947+
1948+
> Snapshot 1
1949+
1950+
`␊
1951+
Netlify Build ␊
1952+
────────────────────────────────────────────────────────────────␊
1953+
1954+
> Version␊
1955+
@netlify/build 1.0.0␊
1956+
1957+
> Flags␊
1958+
debug: true␊
1959+
repositoryRoot: packages/build/tests/plugins/fixtures/cache_utils␊
1960+
testOpts:␊
1961+
pluginsListUrl: test␊
1962+
silentLingeringProcesses: true␊
1963+
1964+
> Current directory␊
1965+
packages/build/tests/plugins/fixtures/cache_utils␊
1966+
1967+
> Config file␊
1968+
packages/build/tests/plugins/fixtures/cache_utils/netlify.toml␊
1969+
1970+
> Resolved config␊
1971+
build:␊
1972+
command: node build.mjs␊
1973+
commandOrigin: config␊
1974+
publish: packages/build/tests/plugins/fixtures/cache_utils␊
1975+
publishOrigin: default␊
1976+
plugins:␊
1977+
- inputs: {}␊
1978+
origin: config␊
1979+
package: /external/path␊
1980+
1981+
> Context␊
1982+
production␊
1983+
1984+
> Loading plugins␊
1985+
- /external/path from netlify.toml␊
1986+
1987+
1. /external/path (onPreBuild event) ␊
1988+
────────────────────────────────────────────────────────────────␊
1989+
1990+
1991+
(/external/path onPreBuild completed in 1ms)␊
1992+
Build step duration: /external/path onPreBuild completed in 1ms␊
1993+
1994+
2. build.command from netlify.toml ␊
1995+
────────────────────────────────────────────────────────────────␊
1996+
1997+
$ node build.mjs␊
1998+
content inside dist/.dot:␊
1999+
hello.txt␊
2000+
content inside dist/other:␊
2001+
index.html␊
2002+
Generate files␊
2003+
2004+
(build.command completed in 1ms)␊
2005+
Build step duration: build.command completed in 1ms␊
2006+
2007+
3. /external/path (onPostBuild event) ␊
2008+
────────────────────────────────────────────────────────────────␊
2009+
2010+
2011+
(/external/path onPostBuild completed in 1ms)␊
2012+
Build step duration: /external/path onPostBuild completed in 1ms␊
2013+
2014+
Netlify Build Complete ␊
2015+
────────────────────────────────────────────────────────────────␊
2016+
2017+
(Netlify Build completed in 1ms)␊
2018+
Build step duration: Netlify Build completed in 1ms`
2019+
19462020
## Can run list util
19472021

19482022
> Snapshot 1
Binary file not shown.

packages/build/tests/plugins/tests.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@ test('Can run utils', async (t) => {
198198
}
199199
})
200200

201+
test('Cache utils are caching .dot directories as well', async (t) => {
202+
// cleanup cache first
203+
await removeDir([`${FIXTURES_DIR}/cache_utils/dist`, `${FIXTURES_DIR}/cache_utils/.netlify`])
204+
// generate cache
205+
await new Fixture('./fixtures/cache_utils').runWithBuild()
206+
// should have cached files in the output message
207+
const output = await new Fixture('./fixtures/cache_utils').runWithBuild()
208+
t.snapshot(normalizeOutput(output))
209+
})
210+
201211
test('Can run list util', async (t) => {
202212
const output = await new Fixture('./fixtures/functions_list').runWithBuild()
203213
t.snapshot(normalizeOutput(output))

0 commit comments

Comments
 (0)