From 73ad0aa9c1587c73c0ac19c890a21340715ea9ad Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Wed, 17 Mar 2021 14:53:29 -0600 Subject: [PATCH] Update TS config based on the selected provider --- commerce.config.json | 1 + framework/commerce/config.js | 19 ++++++++++++++++++- next.config.js | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/commerce.config.json b/commerce.config.json index 08ea78814..5776a727c 100644 --- a/commerce.config.json +++ b/commerce.config.json @@ -1,4 +1,5 @@ { + "updateTSConfig": true, "features": { "wishlist": true, "customCheckout": false diff --git a/framework/commerce/config.js b/framework/commerce/config.js index fec443604..a337f26bb 100644 --- a/framework/commerce/config.js +++ b/framework/commerce/config.js @@ -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 } diff --git a/next.config.js b/next.config.js index c71bce855..c8694f1e0 100644 --- a/next.config.js +++ b/next.config.js @@ -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))