Skip to content

Commit be2ad48

Browse files
authored
fix: remove swc binaries (#17)
1 parent 7822aed commit be2ad48

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @ts-check
22
const path = require('path')
33

4+
const { ODB_FUNCTION_NAME, HANDLER_FUNCTION_NAME } = require('./constants')
45
const { restoreCache, saveCache } = require('./helpers/cacheBuild')
56
const copyNextDist = require('./helpers/copyNextDist')
67
const generateFunctions = require('./helpers/generateFunctions')
@@ -76,11 +77,20 @@ module.exports = {
7677

7778
async onPostBuild({
7879
netlifyConfig,
80+
constants: { FUNCTIONS_DIST = '.netlify/functions' },
7981
utils: {
8082
build: { failBuild },
83+
run,
8184
cache,
8285
},
8386
}) {
87+
// Remove swc binaries from the zipfile if present. Yes, it's a hack, but it drops >10MB from the zipfile when bundling with zip-it-and-ship-it
88+
for (const func of [ODB_FUNCTION_NAME, HANDLER_FUNCTION_NAME]) {
89+
await run(`zip`, [`-d`, path.join(FUNCTIONS_DIST, `${func}.zip`), '*node_modules/@next/swc-*']).catch(() => {
90+
// This throws if there's none of these in the zipfile
91+
})
92+
}
93+
8494
const siteRoot = getNextRoot({ netlifyConfig })
8595
const { distDir } = await getNextConfig(failBuild, siteRoot)
8696
await saveCache({ cache, distDir, siteRoot })

test/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ const utils = {
2323
throw new Error(message)
2424
},
2525
},
26+
run: async () => void 0,
2627
cache: {
27-
save() {},
28-
restore() {},
28+
save: jest.fn(),
29+
restore: jest.fn(),
2930
},
3031
}
3132

0 commit comments

Comments
 (0)