Mirror: 🎩 A tiny but capable push & pull stream library for TypeScript and Flow
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: Implement bundled d.ts output (#135)

authored by

Phil Pluckthun and committed by
GitHub
9c062ac3 e82aa6aa

+101 -29
+5
.changeset/calm-tomatoes-chew.md
··· 1 + --- 2 + 'wonka': minor 3 + --- 4 + 5 + Implement `d.ts` bundling. Only a single `wonka.d.ts` typings file will now be available to TypeScript.
+4 -3
package.json
··· 6 6 "source": "./src/index.ts", 7 7 "main": "./dist/wonka", 8 8 "module": "./dist/wonka.mjs", 9 - "types": "./dist/types/index.d.ts", 9 + "types": "./dist/wonka.d.ts", 10 10 "exports": { 11 11 ".": { 12 12 "import": "./dist/wonka.mjs", 13 13 "require": "./dist/wonka.js", 14 - "types": "./dist/types/index.d.ts", 14 + "types": "./dist/wonka.d.ts", 15 15 "source": "./src/index.ts" 16 16 }, 17 17 "./package.json": "./package.json" ··· 87 87 "eslint": "^8.29.0", 88 88 "eslint-config-prettier": "^8.5.0", 89 89 "eslint-plugin-prettier": "^4.2.1", 90 - "flowgen": "^1.20.1", 90 + "flowgen": "^1.21.0", 91 91 "glob": "^8.0.3", 92 92 "husky-v4": "^4.3.8", 93 93 "lint-staged": "^13.0.4", ··· 96 96 "rimraf": "^3.0.2", 97 97 "rollup": "^3.5.1", 98 98 "rollup-plugin-cjs-check": "^1.0.1", 99 + "rollup-plugin-dts": "^5.1.1", 99 100 "tslib": "^2.4.1", 100 101 "typescript": "^4.9.3", 101 102 "vitest": "^0.25.3",
+27 -4
pnpm-lock.yaml
··· 18 18 eslint: ^8.29.0 19 19 eslint-config-prettier: ^8.5.0 20 20 eslint-plugin-prettier: ^4.2.1 21 - flowgen: ^1.20.1 21 + flowgen: ^1.21.0 22 22 glob: ^8.0.3 23 23 husky-v4: ^4.3.8 24 24 lint-staged: ^13.0.4 ··· 27 27 rimraf: ^3.0.2 28 28 rollup: ^3.5.1 29 29 rollup-plugin-cjs-check: ^1.0.1 30 + rollup-plugin-dts: ^5.1.1 30 31 tslib: ^2.4.1 31 32 typescript: ^4.9.3 32 33 vitest: ^0.25.3 ··· 50 51 eslint: 8.29.0 51 52 eslint-config-prettier: 8.5.0_eslint@8.29.0 52 53 eslint-plugin-prettier: 4.2.1_nrhoyyjffvfyk4vtlt5destxgm 53 - flowgen: 1.20.1 54 + flowgen: 1.21.0 54 55 glob: 8.0.3 55 56 husky-v4: 4.3.8 56 57 lint-staged: 13.0.4 ··· 59 60 rimraf: 3.0.2 60 61 rollup: 3.5.1 61 62 rollup-plugin-cjs-check: 1.0.1_rollup@3.5.1 63 + rollup-plugin-dts: 5.1.1_rt6svyh24sgpogwv5hms77uhpq 62 64 tslib: 2.4.1 63 65 typescript: 4.9.3 64 66 vitest: 0.25.3 ··· 1818 1820 resolution: {integrity: sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==} 1819 1821 dev: true 1820 1822 1821 - /flowgen/1.20.1: 1822 - resolution: {integrity: sha512-Wus3KAhsOF7CiZGkBKZawf0AJXe06Wot6UGQt7h9QS6MBtBkFgG30wTAgpy1byA3FKYb059vO341XtN8LUhenQ==} 1823 + /flowgen/1.21.0: 1824 + resolution: {integrity: sha512-pFNFFyMLRmW6njhOIm5TrbGUDTv64aujmys2KrkRE2NYD8sXwJUyicQRwU5SPRBRJnFSD/FNlnHo2NnHI5eJSw==} 1823 1825 hasBin: true 1824 1826 dependencies: 1825 1827 '@babel/code-frame': 7.18.6 ··· 2480 2482 sourcemap-codec: 1.4.8 2481 2483 dev: true 2482 2484 2485 + /magic-string/0.27.0: 2486 + resolution: {integrity: sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==} 2487 + engines: {node: '>=12'} 2488 + dependencies: 2489 + '@jridgewell/sourcemap-codec': 1.4.14 2490 + dev: true 2491 + 2483 2492 /map-obj/1.0.1: 2484 2493 resolution: {integrity: sha512-7N/q3lyZ+LVCp7PzuxrJr4KMbBE2hW7BT7YNia330OFxIf4d3r5zVpicP2650l7CPN6RM9zOJRl3NGpqSiw3Eg==} 2485 2494 engines: {node: '>=0.10.0'} ··· 3105 3114 '@rollup/pluginutils': 5.0.2_rollup@3.5.1 3106 3115 cjs-module-lexer: 1.2.2 3107 3116 rollup: 3.5.1 3117 + dev: true 3118 + 3119 + /rollup-plugin-dts/5.1.1_rt6svyh24sgpogwv5hms77uhpq: 3120 + resolution: {integrity: sha512-zpgo52XmnLg8w4k3MScinFHZK1+ro6r7uVe34fJ0Ee8AM45FvgvTuvfWWaRgIpA4pQ1BHJuu2ospncZhkcJVeA==} 3121 + engines: {node: '>=v14'} 3122 + peerDependencies: 3123 + rollup: ^3.0.0 3124 + typescript: ^4.1 3125 + dependencies: 3126 + magic-string: 0.27.0 3127 + rollup: 3.5.1 3128 + typescript: 4.9.3 3129 + optionalDependencies: 3130 + '@babel/code-frame': 7.18.6 3108 3131 dev: true 3109 3132 3110 3133 /rollup/2.79.1:
+19 -14
scripts/flow-typings-plugin.mjs
··· 1 - import { resolve, basename, dirname, join } from 'path'; 2 - import { writeFileSync } from 'fs'; 3 1 import { compiler, beautify } from 'flowgen'; 4 2 5 - import glob from 'glob'; 6 - 7 3 function flowTypings() { 8 4 return { 9 5 name: 'flow-typings', 10 - async writeBundle() { 11 - const cwd = process.cwd(); 12 - for (const file of glob.sync('dist/types/**/*.d.ts')) { 13 - const fullpath = resolve(cwd, file); 14 - const flowdef = beautify(compiler.compileDefinitionFile(fullpath)); 15 - const name = basename(fullpath, '.d.ts'); 16 - const filepath = dirname(fullpath); 17 - const newpath = join(filepath, name + '.js.flow'); 18 - const definition = flowdef.replace(/import/g, 'import type'); 19 - writeFileSync(newpath, '// @flow\n\n' + definition); 6 + async renderChunk(code, chunk) { 7 + if (chunk.fileName.endsWith('d.ts')) { 8 + // NOTE: Computed property names will be omitted 9 + code = code.replace(/\[Symbol\.\w+\][?()]*:(?:.*);\n?/g, ''); 10 + 11 + let flowdef = compiler.compileDefinitionString(code); 12 + 13 + flowdef = beautify(flowdef); 14 + flowdef = flowdef.replace(/import/g, 'import type'); 15 + flowdef = `// @flow\n\n${flowdef}`; 16 + 17 + this.emitFile({ 18 + type: 'asset', 19 + name: chunk.name, 20 + fileName: `${chunk.name}.js.flow`, 21 + source: flowdef, 22 + }); 20 23 } 24 + 25 + return null; 21 26 }, 22 27 }; 23 28 }
+46 -8
scripts/rollup.config.mjs
··· 4 4 import buble from '@rollup/plugin-buble'; 5 5 import terser from '@rollup/plugin-terser'; 6 6 import cjsCheck from 'rollup-plugin-cjs-check'; 7 + import dts from 'rollup-plugin-dts'; 7 8 8 9 import flowTypings from './flow-typings-plugin.mjs'; 9 10 10 - const plugins = [ 11 + const commonPlugins = [ 11 12 resolve({ 12 13 extensions: ['.mjs', '.js', '.ts'], 13 14 mainFields: ['module', 'jsnext', 'main'], ··· 27 28 sourceMap: true, 28 29 sourceRoot: './', 29 30 noEmit: false, 30 - declaration: true, 31 - declarationDir: './dist/types/', 31 + declaration: false, 32 32 target: 'esnext', 33 33 }, 34 34 }), 35 + ]; 35 36 37 + const jsPlugins = [ 38 + ...commonPlugins, 36 39 cjsCheck(), 37 - flowTypings(), 38 40 39 41 buble({ 40 42 transforms: { ··· 86 88 }), 87 89 ]; 88 90 91 + const dtsPlugins = [ 92 + ...commonPlugins, 93 + dts(), 94 + flowTypings(), 95 + ]; 96 + 89 97 const output = format => { 90 98 const extension = format === 'esm' ? '.mjs' : '.js'; 91 99 return { ··· 111 119 }; 112 120 }; 113 121 114 - const config = { 122 + const commonConfig = { 115 123 input: { 116 124 wonka: './src/index.ts', 117 125 }, 118 126 onwarn: () => {}, 119 127 external: () => false, 120 - plugins, 121 128 treeshake: { 122 129 unknownGlobalSideEffects: false, 123 130 tryCatchDeoptimization: false, 124 131 moduleSideEffects: false, 125 132 }, 126 - output: [output('esm'), output('cjs')], 127 133 }; 128 134 129 - export default config; 135 + const jsConfig = { 136 + ...commonConfig, 137 + plugins: jsPlugins, 138 + output: [ 139 + output('esm'), 140 + output('cjs'), 141 + ], 142 + }; 143 + 144 + const dtsConfig = { 145 + ...commonConfig, 146 + input: { 147 + wonka: './src/index.ts', 148 + }, 149 + onwarn: () => {}, 150 + external: () => false, 151 + plugins: dtsPlugins, 152 + treeshake: { 153 + unknownGlobalSideEffects: false, 154 + tryCatchDeoptimization: false, 155 + moduleSideEffects: false, 156 + }, 157 + output: { 158 + dir: './dist', 159 + entryFileNames: '[name].d.ts', 160 + format: 'es' 161 + }, 162 + }; 163 + 164 + export default [ 165 + jsConfig, 166 + dtsConfig, 167 + ];