From 57ac5296cbb451c1d2abda18d1f1cde5dc270df9 Mon Sep 17 00:00:00 2001 From: Slawomir Koszewski Date: Wed, 28 Oct 2026 19:25:09 +0100 Subject: [PATCH] fix: the declarations of the published package import the other declarations by their .js names. --- CHANGELOG.md | 8 ++++++++ build.mjs | 10 +++++++++- package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bda2d4..89f07b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.1.1 + +fix: the declarations of the published package import the other declarations by their .js names. + +- The `.d.ts` files of the package name the files they import as `.js`, as the compiled + JavaScript does, instead of the `.ts` and `.tsx` files of the source, which the package does not + hold. + ## 0.1.0 feature: sk-react-toolkit holds the server helpers, web components and Vite font plugin shared by manage-ui and sql-query-webui. diff --git a/build.mjs b/build.mjs index 9faa02d..a05cc35 100755 --- a/build.mjs +++ b/build.mjs @@ -4,7 +4,7 @@ // the font plugin's virtual module, README.md, CHANGELOG.md and a package.json whose exports name the compiled files. import { spawnSync } from 'node:child_process'; -import { copyFileSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; +import { copyFileSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; import { join } from 'node:path'; const ROOT = import.meta.dirname; @@ -21,6 +21,14 @@ const tsc = spawnSync(join(ROOT, 'node_modules', '.bin', 'tsc'), ['-p', join(ROO if (tsc.error) fail(`tsc: ${tsc.error.message}; run npm ci first`); if (tsc.status !== 0) process.exit(tsc.status ?? 1); +// The declarations import the other declarations by their .js names, as the compiled JavaScript does. +for (const entry of ENTRIES) { + for (const file of readdirSync(join(DIST, entry)).filter((name) => name.endsWith('.d.ts'))) { + const path = join(DIST, entry, file); + writeFileSync(path, readFileSync(path, 'utf8').replace(/(from\s+|import\s+)(['"])(\.{1,2}\/[^'"]+)\.tsx?\2/g, '$1$2$3.js$2')); + } +} + // The compiled renderApp keeps its import of virtual:font, so its declarations reference the module's declaration. copyFileSync(join(ROOT, 'web', 'virtual-font.d.ts'), join(DIST, 'web', 'virtual-font.d.ts')); const renderApp = join(DIST, 'web', 'renderApp.d.ts'); diff --git a/package-lock.json b/package-lock.json index b4266e5..c49c15d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@koszewscy/sk-react-toolkit", - "version": "0.1.0", + "version": "0.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@koszewscy/sk-react-toolkit", - "version": "0.1.0", + "version": "0.1.1", "devDependencies": { "@emotion/react": "^11.14.0", "@emotion/styled": "^11.14.1", diff --git a/package.json b/package.json index b126993..1414abb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@koszewscy/sk-react-toolkit", - "version": "0.1.0", + "version": "0.1.1", "description": "Shared code of the React and Fastify web applications: web components, server helpers and the Vite font plugin.", "private": true, "type": "module",