Skip to content

fix: fix memoization #128

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 1 commit into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions helpers/getNextConfig.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
'use strict'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed by moize (otherwise, it throws).


const { resolve } = require('path')

let nextConfig
const moize = require('moize')

// Load next.config.js
const getNextConfig = async function (failBuild = defaultFailBuild) {
// Memoizes `nextConfig`
if (nextConfig !== undefined) {
return nextConfig
}

// We cannot load `next` at the top-level because we validate whether the
// site is using `next` inside `onPreBuild`.
const { PHASE_PRODUCTION_BUILD } = require('next/constants')
const loadConfig = require('next/dist/next-server/server/config').default

try {
nextConfig = await loadConfig(PHASE_PRODUCTION_BUILD, resolve('.'))
return await loadConfig(PHASE_PRODUCTION_BUILD, resolve('.'))
} catch (error) {
return failBuild('Error loading your next.config.js.', { error })
}

return nextConfig
}

const moizedGetNextConfig = moize(getNextConfig, { maxSize: 1e3, isPromise: true })

const defaultFailBuild = function (message, { error }) {
throw new Error(`${message}\n${error.stack}`)
}

module.exports = getNextConfig
module.exports = moizedGetNextConfig
15 changes: 5 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"fs-extra": "^9.1.0",
"jimp": "^0.16.1",
"make-dir": "^3.1.0",
"moize": "^6.0.0",
"semver": "^7.3.2"
},
"devDependencies": {
Expand Down