From de575f7a80d9337f9689394af99dc7cc096e9452 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Mon, 14 Jun 2021 19:41:39 +0200 Subject: [PATCH] add a tsconfig.js file --- framework/commerce/config.js | 22 ++------------ tsconfig.js | 56 ++++++++++++++++++++++++++++++++++++ tsconfig.json | 2 +- 3 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 tsconfig.js diff --git a/framework/commerce/config.js b/framework/commerce/config.js index 48f0d526b..05e62e1a1 100644 --- a/framework/commerce/config.js +++ b/framework/commerce/config.js @@ -50,27 +50,11 @@ function withCommerceConfig(nextConfig = {}) { // Update paths in `tsconfig.json` to point to the selected provider if (config.commerce.updateTSConfig !== false) { - const tsconfigPath = path.join(process.cwd(), 'tsconfig.json') - const tsconfig = require(tsconfigPath) - - tsconfig.compilerOptions.paths['@framework'] = [`framework/${name}`] - tsconfig.compilerOptions.paths['@framework/*'] = [`framework/${name}/*`] - - // When running for production it may be useful to exclude the other providers - // from TS checking - if (process.env.VERCEL) { - const exclude = tsconfig.exclude.filter( - (item) => !item.startsWith('framework/') - ) - - tsconfig.exclude = PROVIDERS.reduce((exclude, current) => { - if (current !== name) exclude.push(`framework/${current}`) - return exclude - }, exclude) - } + const staticTsconfigPath = path.join(process.cwd(), 'tsconfig.json') + const tsconfig = require('../../tsconfig.js') fs.writeFileSync( - tsconfigPath, + staticTsconfigPath, prettier.format(JSON.stringify(tsconfig), { parser: 'json' }) ) } diff --git a/tsconfig.js b/tsconfig.js new file mode 100644 index 000000000..50008b723 --- /dev/null +++ b/tsconfig.js @@ -0,0 +1,56 @@ +const PROVIDERS = ['bigcommerce', 'shopify', 'swell', 'vendure'] + +function getProviderName() { + return ( + process.env.COMMERCE_PROVIDER || + (process.env.BIGCOMMERCE_STOREFRONT_API_URL + ? 'bigcommerce' + : process.env.NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN + ? 'shopify' + : process.env.NEXT_PUBLIC_SWELL_STORE_ID + ? 'swell' + : null) + ) +} + +const name = getProviderName() + +module.exports = { + compilerOptions: { + baseUrl: '.', + target: 'esnext', + lib: ['dom', 'dom.iterable', 'esnext'], + allowJs: true, + skipLibCheck: true, + strict: true, + forceConsistentCasingInFileNames: true, + noEmit: true, + esModuleInterop: true, + module: 'esnext', + moduleResolution: 'node', + resolveJsonModule: true, + isolatedModules: true, + jsx: 'preserve', + paths: { + '@lib/*': ['lib/*'], + '@utils/*': ['utils/*'], + '@config/*': ['config/*'], + '@assets/*': ['assets/*'], + '@components/*': ['components/*'], + '@commerce': ['framework/commerce'], + '@commerce/*': ['framework/commerce/*'], + // Update paths to point to the selected provider + '@framework': [`framework/${name}`], + '@framework/*': [`framework/${name}/*`], + }, + }, + include: ['next-env.d.ts', '**/*.d.ts', '**/*.ts', '**/*.tsx', '**/*.js'], + exclude: [ + 'node_modules', + // When running for production it may be useful to exclude the other providers + // from TS checking + ...(process.env.VERCEL + ? PROVIDERS.filter((p) => p !== name).map((p) => `framework/${p}`) + : []), + ], +} diff --git a/tsconfig.json b/tsconfig.json index 96e4359e5..e20f37099 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,5 +27,5 @@ } }, "include": ["next-env.d.ts", "**/*.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"], - "exclude": ["node_modules", "framework/swell", "framework/vendure"] + "exclude": ["node_modules"] }