mirror of
https://github.com/vercel/commerce.git
synced 2025-06-18 21:21:21 +00:00
Update TS config based on the selected provider
This commit is contained in:
parent
40cf6247cf
commit
73ad0aa9c1
@ -1,4 +1,5 @@
|
||||
{
|
||||
"updateTSConfig": true,
|
||||
"features": {
|
||||
"wishlist": true,
|
||||
"customCheckout": false
|
||||
|
@ -2,7 +2,10 @@
|
||||
* This file is expected to be used in next.config.js only
|
||||
*/
|
||||
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
const merge = require('deepmerge')
|
||||
const prettier = require('prettier')
|
||||
|
||||
const PROVIDERS = ['bigcommerce', 'shopify']
|
||||
|
||||
@ -31,7 +34,7 @@ function withCommerceConfig(nextConfig = {}) {
|
||||
)
|
||||
}
|
||||
|
||||
const commerceNextConfig = require(`../${name}/next.config`)
|
||||
const commerceNextConfig = require(path.join('../', name, 'next.config'))
|
||||
const config = merge(commerceNextConfig, nextConfig)
|
||||
|
||||
config.env = config.env || {}
|
||||
@ -40,6 +43,20 @@ function withCommerceConfig(nextConfig = {}) {
|
||||
if (v) config.env[`COMMERCE_${k.toUpperCase()}_ENABLED`] = true
|
||||
})
|
||||
|
||||
// Update paths in `tsconfig.json` to point to the selected provider
|
||||
if (config.commerce.updateTSConfig) {
|
||||
const tsconfigPath = path.join(process.cwd(), 'tsconfig.json')
|
||||
const tsconfig = require(tsconfigPath)
|
||||
|
||||
tsconfig.compilerOptions.paths['@framework'] = [`framework/${name}`]
|
||||
tsconfig.compilerOptions.paths['@framework/*'] = [`framework/${name}/*`]
|
||||
|
||||
fs.writeFileSync(
|
||||
tsconfigPath,
|
||||
prettier.format(JSON.stringify(tsconfig), { parser: 'json' })
|
||||
)
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
|
@ -44,4 +44,5 @@ module.exports = withCommerceConfig({
|
||||
},
|
||||
})
|
||||
|
||||
// Don't delete this console log, useful to see the commerce config in Vercel deployments
|
||||
console.log('next.config.js', JSON.stringify(module.exports, null, 2))
|
||||
|
Loading…
x
Reference in New Issue
Block a user