Skip to content

Commit

Permalink
chore: update dts generation
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re committed Sep 11, 2023
1 parent 100a986 commit a989b5a
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-windows-repair.md
@@ -0,0 +1,5 @@
---
"ultrahtml": patch
---

Bundle type definitions in `.d.ts` files
5 changes: 5 additions & 0 deletions .changeset/young-rings-sell.md
@@ -0,0 +1,5 @@
---
"ultrahtml": patch
---

Update typings to include bundled libraries
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -13,7 +13,7 @@
},
"homepage": "https://github.com/natemoo-re/ultrahtml#README",
"scripts": {
"build": "node scripts/build.js && tsc -p .",
"build": "node scripts/build.js",
"lint": "prettier \"**/*.{js,ts,md}\"",
"dev": "vitest",
"test": "vitest run"
Expand Down Expand Up @@ -64,16 +64,17 @@
"@changesets/cli": "^2.18.1",
"@types/stylis": "^4.0.2",
"chalk": "^5.1.2",
"dts-bundle-generator": "^8.0.1",
"esbuild": "^0.14.51",
"globby": "^13.1.2",
"gzip-size": "^7.0.0",
"markdown-it": "^13.0.1",
"media-query-fns": "^2.0.0",
"npm-run-all": "^4.1.5",
"parsel-js": "^1.0.2",
"prettier": "^2.5.1",
"pretty-bytes": "^6.0.0",
"stylis": "^4.1.2",
"media-query-fns": "^2.0.0",
"typescript": "^4.7.4",
"vitest": "^0.20.2"
}
Expand Down
36 changes: 27 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions scripts/build.js
@@ -1,8 +1,12 @@
import { writeFileSync, mkdirSync } from 'node:fs';
import path from 'node:path';

import { build } from "esbuild";
import { globby } from 'globby';
import { gzipSizeFromFileSync } from 'gzip-size';
import bytes from 'pretty-bytes';
import colors from 'chalk';
import { generateDtsBundle } from 'dts-bundle-generator'

async function run() {
const files = await globby(['src/**/*.ts', '!src/env.d.ts']);
Expand Down Expand Up @@ -30,6 +34,26 @@ async function run() {
)
}
await Promise.all(promises);
const bundles = generateDtsBundle(files.map(filePath => {
/** @type {import('dts-bundle-generator').EntryPointConfig} */
const config = {
filePath,
libraries: {
inlinedLibraries: ['media-query-fns']
},
output: {
exportReferencedTypes: false,
}
}
return config;
}), { preferredConfigPath: 'tsconfig.json' });
for (let i = 0; i < files.length; i++) {
const dts = bundles[i];
const file = files[i].replace('src', 'dist').replace('.ts', '.d.ts')
mkdirSync(path.join(file, '..'), { recursive: true })
writeFileSync(file, dts, { encoding: 'utf8' })
}

for (const [file, size] of Object.entries(output).sort(([a], [b]) => a.localeCompare(b))) {
console.log(`${file} ${colors.green(size)}`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Expand Up @@ -288,7 +288,7 @@ class Walker {
async visit(node: Node, parent?: Node, index?: number): Promise<void> {
await this.callback(node, parent, index);
if (Array.isArray(node.children)) {
let promises = [];
let promises: Promise<void>[] = [];
for (let i = 0; i < node.children.length; i++) {
const child = node.children[i];
promises.push(this.visit(child, node, i));
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Expand Up @@ -4,6 +4,7 @@
"declaration": true,
"emitDeclarationOnly": true,
"strict": true,
"noImplicitAny": false,
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
Expand Down

0 comments on commit a989b5a

Please sign in to comment.