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

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

+5
.changeset/calm-tomatoes-chew.md
···
···
+
---
+
'wonka': minor
+
---
+
+
Implement `d.ts` bundling. Only a single `wonka.d.ts` typings file will now be available to TypeScript.
+4 -3
package.json
···
"source": "./src/index.ts",
"main": "./dist/wonka",
"module": "./dist/wonka.mjs",
-
"types": "./dist/types/index.d.ts",
"exports": {
".": {
"import": "./dist/wonka.mjs",
"require": "./dist/wonka.js",
-
"types": "./dist/types/index.d.ts",
"source": "./src/index.ts"
},
"./package.json": "./package.json"
···
"eslint": "^8.29.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
-
"flowgen": "^1.20.1",
"glob": "^8.0.3",
"husky-v4": "^4.3.8",
"lint-staged": "^13.0.4",
···
"rimraf": "^3.0.2",
"rollup": "^3.5.1",
"rollup-plugin-cjs-check": "^1.0.1",
"tslib": "^2.4.1",
"typescript": "^4.9.3",
"vitest": "^0.25.3",
···
"source": "./src/index.ts",
"main": "./dist/wonka",
"module": "./dist/wonka.mjs",
+
"types": "./dist/wonka.d.ts",
"exports": {
".": {
"import": "./dist/wonka.mjs",
"require": "./dist/wonka.js",
+
"types": "./dist/wonka.d.ts",
"source": "./src/index.ts"
},
"./package.json": "./package.json"
···
"eslint": "^8.29.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
+
"flowgen": "^1.21.0",
"glob": "^8.0.3",
"husky-v4": "^4.3.8",
"lint-staged": "^13.0.4",
···
"rimraf": "^3.0.2",
"rollup": "^3.5.1",
"rollup-plugin-cjs-check": "^1.0.1",
+
"rollup-plugin-dts": "^5.1.1",
"tslib": "^2.4.1",
"typescript": "^4.9.3",
"vitest": "^0.25.3",
+27 -4
pnpm-lock.yaml
···
eslint: ^8.29.0
eslint-config-prettier: ^8.5.0
eslint-plugin-prettier: ^4.2.1
-
flowgen: ^1.20.1
glob: ^8.0.3
husky-v4: ^4.3.8
lint-staged: ^13.0.4
···
rimraf: ^3.0.2
rollup: ^3.5.1
rollup-plugin-cjs-check: ^1.0.1
tslib: ^2.4.1
typescript: ^4.9.3
vitest: ^0.25.3
···
eslint: 8.29.0
eslint-config-prettier: 8.5.0_eslint@8.29.0
eslint-plugin-prettier: 4.2.1_nrhoyyjffvfyk4vtlt5destxgm
-
flowgen: 1.20.1
glob: 8.0.3
husky-v4: 4.3.8
lint-staged: 13.0.4
···
rimraf: 3.0.2
rollup: 3.5.1
rollup-plugin-cjs-check: 1.0.1_rollup@3.5.1
tslib: 2.4.1
typescript: 4.9.3
vitest: 0.25.3
···
resolution: {integrity: sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==}
dev: true
-
/flowgen/1.20.1:
-
resolution: {integrity: sha512-Wus3KAhsOF7CiZGkBKZawf0AJXe06Wot6UGQt7h9QS6MBtBkFgG30wTAgpy1byA3FKYb059vO341XtN8LUhenQ==}
hasBin: true
dependencies:
'@babel/code-frame': 7.18.6
···
sourcemap-codec: 1.4.8
dev: true
/map-obj/1.0.1:
resolution: {integrity: sha512-7N/q3lyZ+LVCp7PzuxrJr4KMbBE2hW7BT7YNia330OFxIf4d3r5zVpicP2650l7CPN6RM9zOJRl3NGpqSiw3Eg==}
engines: {node: '>=0.10.0'}
···
'@rollup/pluginutils': 5.0.2_rollup@3.5.1
cjs-module-lexer: 1.2.2
rollup: 3.5.1
dev: true
/rollup/2.79.1:
···
eslint: ^8.29.0
eslint-config-prettier: ^8.5.0
eslint-plugin-prettier: ^4.2.1
+
flowgen: ^1.21.0
glob: ^8.0.3
husky-v4: ^4.3.8
lint-staged: ^13.0.4
···
rimraf: ^3.0.2
rollup: ^3.5.1
rollup-plugin-cjs-check: ^1.0.1
+
rollup-plugin-dts: ^5.1.1
tslib: ^2.4.1
typescript: ^4.9.3
vitest: ^0.25.3
···
eslint: 8.29.0
eslint-config-prettier: 8.5.0_eslint@8.29.0
eslint-plugin-prettier: 4.2.1_nrhoyyjffvfyk4vtlt5destxgm
+
flowgen: 1.21.0
glob: 8.0.3
husky-v4: 4.3.8
lint-staged: 13.0.4
···
rimraf: 3.0.2
rollup: 3.5.1
rollup-plugin-cjs-check: 1.0.1_rollup@3.5.1
+
rollup-plugin-dts: 5.1.1_rt6svyh24sgpogwv5hms77uhpq
tslib: 2.4.1
typescript: 4.9.3
vitest: 0.25.3
···
resolution: {integrity: sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==}
dev: true
+
/flowgen/1.21.0:
+
resolution: {integrity: sha512-pFNFFyMLRmW6njhOIm5TrbGUDTv64aujmys2KrkRE2NYD8sXwJUyicQRwU5SPRBRJnFSD/FNlnHo2NnHI5eJSw==}
hasBin: true
dependencies:
'@babel/code-frame': 7.18.6
···
sourcemap-codec: 1.4.8
dev: true
+
/magic-string/0.27.0:
+
resolution: {integrity: sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==}
+
engines: {node: '>=12'}
+
dependencies:
+
'@jridgewell/sourcemap-codec': 1.4.14
+
dev: true
+
/map-obj/1.0.1:
resolution: {integrity: sha512-7N/q3lyZ+LVCp7PzuxrJr4KMbBE2hW7BT7YNia330OFxIf4d3r5zVpicP2650l7CPN6RM9zOJRl3NGpqSiw3Eg==}
engines: {node: '>=0.10.0'}
···
'@rollup/pluginutils': 5.0.2_rollup@3.5.1
cjs-module-lexer: 1.2.2
rollup: 3.5.1
+
dev: true
+
+
/rollup-plugin-dts/5.1.1_rt6svyh24sgpogwv5hms77uhpq:
+
resolution: {integrity: sha512-zpgo52XmnLg8w4k3MScinFHZK1+ro6r7uVe34fJ0Ee8AM45FvgvTuvfWWaRgIpA4pQ1BHJuu2ospncZhkcJVeA==}
+
engines: {node: '>=v14'}
+
peerDependencies:
+
rollup: ^3.0.0
+
typescript: ^4.1
+
dependencies:
+
magic-string: 0.27.0
+
rollup: 3.5.1
+
typescript: 4.9.3
+
optionalDependencies:
+
'@babel/code-frame': 7.18.6
dev: true
/rollup/2.79.1:
+19 -14
scripts/flow-typings-plugin.mjs
···
-
import { resolve, basename, dirname, join } from 'path';
-
import { writeFileSync } from 'fs';
import { compiler, beautify } from 'flowgen';
-
import glob from 'glob';
-
function flowTypings() {
return {
name: 'flow-typings',
-
async writeBundle() {
-
const cwd = process.cwd();
-
for (const file of glob.sync('dist/types/**/*.d.ts')) {
-
const fullpath = resolve(cwd, file);
-
const flowdef = beautify(compiler.compileDefinitionFile(fullpath));
-
const name = basename(fullpath, '.d.ts');
-
const filepath = dirname(fullpath);
-
const newpath = join(filepath, name + '.js.flow');
-
const definition = flowdef.replace(/import/g, 'import type');
-
writeFileSync(newpath, '// @flow\n\n' + definition);
}
},
};
}
···
import { compiler, beautify } from 'flowgen';
function flowTypings() {
return {
name: 'flow-typings',
+
async renderChunk(code, chunk) {
+
if (chunk.fileName.endsWith('d.ts')) {
+
// NOTE: Computed property names will be omitted
+
code = code.replace(/\[Symbol\.\w+\][?()]*:(?:.*);\n?/g, '');
+
+
let flowdef = compiler.compileDefinitionString(code);
+
+
flowdef = beautify(flowdef);
+
flowdef = flowdef.replace(/import/g, 'import type');
+
flowdef = `// @flow\n\n${flowdef}`;
+
+
this.emitFile({
+
type: 'asset',
+
name: chunk.name,
+
fileName: `${chunk.name}.js.flow`,
+
source: flowdef,
+
});
}
+
+
return null;
},
};
}
+46 -8
scripts/rollup.config.mjs
···
import buble from '@rollup/plugin-buble';
import terser from '@rollup/plugin-terser';
import cjsCheck from 'rollup-plugin-cjs-check';
import flowTypings from './flow-typings-plugin.mjs';
-
const plugins = [
resolve({
extensions: ['.mjs', '.js', '.ts'],
mainFields: ['module', 'jsnext', 'main'],
···
sourceMap: true,
sourceRoot: './',
noEmit: false,
-
declaration: true,
-
declarationDir: './dist/types/',
target: 'esnext',
},
}),
cjsCheck(),
-
flowTypings(),
buble({
transforms: {
···
}),
];
const output = format => {
const extension = format === 'esm' ? '.mjs' : '.js';
return {
···
};
};
-
const config = {
input: {
wonka: './src/index.ts',
},
onwarn: () => {},
external: () => false,
-
plugins,
treeshake: {
unknownGlobalSideEffects: false,
tryCatchDeoptimization: false,
moduleSideEffects: false,
},
-
output: [output('esm'), output('cjs')],
};
-
export default config;
···
import buble from '@rollup/plugin-buble';
import terser from '@rollup/plugin-terser';
import cjsCheck from 'rollup-plugin-cjs-check';
+
import dts from 'rollup-plugin-dts';
import flowTypings from './flow-typings-plugin.mjs';
+
const commonPlugins = [
resolve({
extensions: ['.mjs', '.js', '.ts'],
mainFields: ['module', 'jsnext', 'main'],
···
sourceMap: true,
sourceRoot: './',
noEmit: false,
+
declaration: false,
target: 'esnext',
},
}),
+
];
+
const jsPlugins = [
+
...commonPlugins,
cjsCheck(),
buble({
transforms: {
···
}),
];
+
const dtsPlugins = [
+
...commonPlugins,
+
dts(),
+
flowTypings(),
+
];
+
const output = format => {
const extension = format === 'esm' ? '.mjs' : '.js';
return {
···
};
};
+
const commonConfig = {
input: {
wonka: './src/index.ts',
},
onwarn: () => {},
external: () => false,
treeshake: {
unknownGlobalSideEffects: false,
tryCatchDeoptimization: false,
moduleSideEffects: false,
},
};
+
const jsConfig = {
+
...commonConfig,
+
plugins: jsPlugins,
+
output: [
+
output('esm'),
+
output('cjs'),
+
],
+
};
+
+
const dtsConfig = {
+
...commonConfig,
+
input: {
+
wonka: './src/index.ts',
+
},
+
onwarn: () => {},
+
external: () => false,
+
plugins: dtsPlugins,
+
treeshake: {
+
unknownGlobalSideEffects: false,
+
tryCatchDeoptimization: false,
+
moduleSideEffects: false,
+
},
+
output: {
+
dir: './dist',
+
entryFileNames: '[name].d.ts',
+
format: 'es'
+
},
+
};
+
+
export default [
+
jsConfig,
+
dtsConfig,
+
];