Skip to content

Commit

Permalink
fix: incrementalCacheHandlerPath should work with a default export
Browse files Browse the repository at this point in the history
  • Loading branch information
ztanner committed Aug 24, 2023
1 parent 80e6f07 commit aeaa503
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,7 @@ export default async function build(
CacheHandler = require(path.isAbsolute(incrementalCacheHandlerPath)
? incrementalCacheHandlerPath
: path.join(dir, incrementalCacheHandlerPath))
CacheHandler = CacheHandler.default || CacheHandler
}

const { ipcPort, ipcValidationKey } = await initialize({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
process.env.CUSTOM_CACHE_HANDLER = require.resolve(
'./cache-handler-default-export.js'
)
require('./app-static.test')
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
process.env.CUSTOM_CACHE_HANDLER = '1'
process.env.CUSTOM_CACHE_HANDLER = require.resolve('./cache-handler.js')
require('./app-static.test')
27 changes: 27 additions & 0 deletions test/e2e/app-dir/app-static/cache-handler-default-export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'
Object.defineProperty(exports, '__esModule', { value: true })

const cache = new Map()

var CacheHandler = /** @class */ (function () {
function CacheHandler(options) {
this.options = options
this.cache = cache
console.log('initialized custom cache-handler')
}
CacheHandler.prototype.get = function (key) {
console.log('cache-handler get', key)
return Promise.resolve(this.cache.get(key))
}
CacheHandler.prototype.set = function (key, data) {
console.log('cache-handler set', key)
this.cache.set(key, {
value: data,
lastModified: Date.now(),
})
return Promise.resolve(undefined)
}
return CacheHandler
})()

exports.default = CacheHandler
4 changes: 1 addition & 3 deletions test/e2e/app-dir/app-static/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
module.exports = {
experimental: {
logging: 'verbose',
incrementalCacheHandlerPath: process.env.CUSTOM_CACHE_HANDLER
? require.resolve('./cache-handler.js')
: undefined,
incrementalCacheHandlerPath: process.env.CUSTOM_CACHE_HANDLER,
},
// assetPrefix: '/assets',
rewrites: async () => {
Expand Down

0 comments on commit aeaa503

Please sign in to comment.