From a989b5a11b38697b20550fcb550a8ffc2a2f92f3 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Mon, 11 Sep 2023 00:06:18 -0500 Subject: [PATCH] chore: update dts generation --- .changeset/angry-windows-repair.md | 5 +++++ .changeset/young-rings-sell.md | 5 +++++ package.json | 5 +++-- pnpm-lock.yaml | 36 ++++++++++++++++++++++-------- scripts/build.js | 24 ++++++++++++++++++++ src/index.ts | 2 +- tsconfig.json | 1 + 7 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 .changeset/angry-windows-repair.md create mode 100644 .changeset/young-rings-sell.md diff --git a/.changeset/angry-windows-repair.md b/.changeset/angry-windows-repair.md new file mode 100644 index 0000000..d688dbb --- /dev/null +++ b/.changeset/angry-windows-repair.md @@ -0,0 +1,5 @@ +--- +"ultrahtml": patch +--- + +Bundle type definitions in `.d.ts` files diff --git a/.changeset/young-rings-sell.md b/.changeset/young-rings-sell.md new file mode 100644 index 0000000..7d49603 --- /dev/null +++ b/.changeset/young-rings-sell.md @@ -0,0 +1,5 @@ +--- +"ultrahtml": patch +--- + +Update typings to include bundled libraries diff --git a/package.json b/package.json index eda627f..a46c3f9 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a0daca0..a881a73 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,7 @@ specifiers: '@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 @@ -21,6 +22,7 @@ devDependencies: '@changesets/cli': 2.24.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 @@ -493,8 +495,9 @@ packages: wrap-ansi: 6.2.0 dev: true - /cliui/7.0.4: - resolution: {integrity: sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==} + /cliui/8.0.1: + resolution: {integrity: sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==} + engines: {node: '>=12'} dependencies: string-width: 4.2.3 strip-ansi: 6.0.1 @@ -630,6 +633,15 @@ packages: path-type: 4.0.0 dev: true + /dts-bundle-generator/8.0.1: + resolution: {integrity: sha512-9JVw78/OXdKfq+RUrmpLm6WAUJp+aOUGEHimVqIlOEH2VugRt1I8CVIoQZlirWZko+/SVZkNgpWCyZubUuzzPA==} + engines: {node: '>=14.0.0'} + hasBin: true + dependencies: + typescript: 5.2.2 + yargs: 17.7.2 + dev: true + /duplexer/0.1.2: resolution: {integrity: sha512-jtD6YG370ZCIi/9GTaJKQxWTZD045+4R4hTk/x1UyoqadyJ9x9CgSi1RlVDQF8U2sxLLSnFkCaMihqljHIWgMg==} dev: true @@ -2082,7 +2094,7 @@ packages: smartwrap: 2.0.2 strip-ansi: 6.0.1 wcwidth: 1.0.1 - yargs: 17.5.1 + yargs: 17.7.2 dev: true /type-detect/4.0.8: @@ -2111,6 +2123,12 @@ packages: hasBin: true dev: true + /typescript/5.2.2: + resolution: {integrity: sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==} + engines: {node: '>=14.17'} + hasBin: true + dev: true + /uc.micro/1.0.6: resolution: {integrity: sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==} dev: true @@ -2279,8 +2297,8 @@ packages: decamelize: 1.2.0 dev: true - /yargs-parser/21.0.1: - resolution: {integrity: sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg==} + /yargs-parser/21.1.1: + resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==} engines: {node: '>=12'} dev: true @@ -2301,17 +2319,17 @@ packages: yargs-parser: 18.1.3 dev: true - /yargs/17.5.1: - resolution: {integrity: sha512-t6YAJcxDkNX7NFYiVtKvWUz8l+PaKTLiL63mJYWR2GnHq2gjEWISzsLp9wg3aY36dY1j+gfIEL3pIF+XlJJfbA==} + /yargs/17.7.2: + resolution: {integrity: sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==} engines: {node: '>=12'} dependencies: - cliui: 7.0.4 + cliui: 8.0.1 escalade: 3.1.1 get-caller-file: 2.0.5 require-directory: 2.1.1 string-width: 4.2.3 y18n: 5.0.8 - yargs-parser: 21.0.1 + yargs-parser: 21.1.1 dev: true /yocto-queue/0.1.0: diff --git a/scripts/build.js b/scripts/build.js index b53c77f..23c51b3 100644 --- a/scripts/build.js +++ b/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']); @@ -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)}`); } diff --git a/src/index.ts b/src/index.ts index fbd2d93..e4ffe11 100644 --- a/src/index.ts +++ b/src/index.ts @@ -288,7 +288,7 @@ class Walker { async visit(node: Node, parent?: Node, index?: number): Promise { await this.callback(node, parent, index); if (Array.isArray(node.children)) { - let promises = []; + let promises: Promise[] = []; for (let i = 0; i < node.children.length; i++) { const child = node.children[i]; promises.push(this.visit(child, node, i)); diff --git a/tsconfig.json b/tsconfig.json index a9456df..0a93ade 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,7 @@ "declaration": true, "emitDeclarationOnly": true, "strict": true, + "noImplicitAny": false, "moduleResolution": "NodeNext", "esModuleInterop": true, "forceConsistentCasingInFileNames": true,