From dd694b62f62fdc0d67c3dac94e0ee16fd2f6040e Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Wed, 26 Aug 2020 21:47:46 -0700 Subject: [PATCH] build: use ts-transform-default-export for index.d.ts (#304) --- package.json | 2 +- rollup.config.js | 7 ++++++- scripts/replace-legacy-export.cjs | 11 ----------- 3 files changed, 7 insertions(+), 13 deletions(-) delete mode 100755 scripts/replace-legacy-export.cjs diff --git a/package.json b/package.json index 762b123e..c53042e6 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "compile": "tsc", "postcompile": "npm run build:cjs", "build:cjs": "rollup -c", - "postbuild:cjs": "node scripts/replace-legacy-export.cjs", "prepare": "npm run compile" }, "repository": { @@ -65,6 +64,7 @@ "serve": "^11.3.2", "standardx": "^5.0.0", "start-server-and-test": "^1.11.2", + "ts-transform-default-export": "^1.0.2", "typescript": "^4.0.0" }, "files": [ diff --git a/rollup.config.js b/rollup.config.js index 935ebda1..a1dbd5c9 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,4 +1,5 @@ import ts from '@wessberg/rollup-plugin-ts' +import transformDefaultExport from 'ts-transform-default-export' const output = { format: 'cjs', @@ -12,6 +13,10 @@ export default { input: './lib/index.ts', output, plugins: [ - ts({ /* options */ }) + ts({ + transformers: ({ program }) => ({ + afterDeclarations: transformDefaultExport(program) + }) + }) ] } diff --git a/scripts/replace-legacy-export.cjs b/scripts/replace-legacy-export.cjs deleted file mode 100755 index c4af84bd..00000000 --- a/scripts/replace-legacy-export.cjs +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env node -'use strict' - -const { readFileSync, writeFileSync } = require('fs') - -// Cleanup the export statement in CJS typings file generated by rollup: -const legacyTypings = require('path').resolve(__dirname, '../build/index.cjs.d.ts') -const contents = readFileSync(legacyTypings, 'utf8').replace( - 'export { yargsParser as default };', 'export = yargsParser;' -) -writeFileSync(legacyTypings, contents, 'utf8')