From a38041f995df468aa82c3cc72632cb67eec40bdb Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Sun, 29 Dec 2019 11:04:53 -0500 Subject: [PATCH] (refactor): use path constants instead of custom resolveApp (#402) - and use ensureDistFolder since that exists now - and use async readJSON since most were converted before --- src/constants.ts | 1 + src/createRollupConfig.ts | 9 ++------- src/index.ts | 4 ++-- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index ac3eac7f9..f448e6cae 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -2,6 +2,7 @@ import { resolveApp } from './utils'; export const paths = { appPackageJson: resolveApp('package.json'), + tsconfigJson: resolveApp('tsconfig.json'), testsSetup: resolveApp('test/setupTests.ts'), appRoot: resolveApp('.'), appSrc: resolveApp('src'), diff --git a/src/createRollupConfig.ts b/src/createRollupConfig.ts index 2e5d38cc9..112580463 100644 --- a/src/createRollupConfig.ts +++ b/src/createRollupConfig.ts @@ -1,9 +1,4 @@ -import { - safeVariableName, - safePackageName, - external, - resolveApp, -} from './utils'; +import { safeVariableName, safePackageName, external } from './utils'; import { paths } from './constants'; import { RollupOptions } from 'rollup'; import { terser } from 'rollup-plugin-terser'; @@ -50,7 +45,7 @@ export async function createRollupConfig( let tsconfigJSON; try { - tsconfigJSON = fs.readJSONSync(resolveApp('tsconfig.json')); + tsconfigJSON = await fs.readJSON(paths.tsconfigJson); } catch (e) {} return { diff --git a/src/index.ts b/src/index.ts index 56196bc49..4b8e117ea 100755 --- a/src/index.ts +++ b/src/index.ts @@ -44,7 +44,7 @@ const prog = sade('tsdx'); let appPackageJson: PackageJson; try { - appPackageJson = fs.readJSONSync(resolveApp('package.json')); + appPackageJson = fs.readJSONSync(paths.appPackageJson); } catch (e) {} // check for custom tsdx.config.js @@ -463,7 +463,7 @@ prog const logger = await createProgressEstimator(); if (opts.format.includes('cjs')) { try { - await util.promisify(mkdirp)(resolveApp('./dist')); + await ensureDistFolder(); const promise = writeCjsEntryFile(opts.name).catch(logError); logger(promise, 'Creating entry file'); } catch (e) {