├── .gitignore ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── assets └── before-after.gif ├── eslint.config.mjs ├── example └── vite │ ├── .gitignore │ ├── favicon.svg │ ├── index.html │ ├── package.json │ ├── pnpm-lock.yaml │ ├── src │ ├── 10004_bytes.json │ ├── 10004_bytes.json.d.ts │ ├── main.ts │ ├── person.schema.json │ ├── person.schema.json.d.ts │ ├── style.css │ └── vite-env.d.ts │ ├── tsconfig.json │ └── vite.config.ts ├── index.d.ts ├── package.json ├── pnpm-lock.yaml ├── src ├── index.ts ├── rollup.ts ├── vite.ts └── webpack.ts ├── tsconfig.json └── tsup.config.ts /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | # local 107 | # .vscode -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | // Disable the default formatter, use eslint instead 3 | "prettier.enable": false, 4 | "editor.formatOnSave": false, 5 | 6 | // Auto fix 7 | "editor.codeActionsOnSave": { 8 | "source.fixAll.eslint": "explicit", 9 | "source.organizeImports": "never" 10 | }, 11 | 12 | // Silent the stylistic rules in you IDE, but still auto fix them 13 | "eslint.rules.customizations": [ 14 | { "rule": "style/*", "severity": "off", "fixable": true }, 15 | { "rule": "format/*", "severity": "off", "fixable": true }, 16 | { "rule": "*-indent", "severity": "off", "fixable": true }, 17 | { "rule": "*-spacing", "severity": "off", "fixable": true }, 18 | { "rule": "*-spaces", "severity": "off", "fixable": true }, 19 | { "rule": "*-order", "severity": "off", "fixable": true }, 20 | { "rule": "*-dangle", "severity": "off", "fixable": true }, 21 | { "rule": "*-newline", "severity": "off", "fixable": true }, 22 | { "rule": "*quotes", "severity": "off", "fixable": true }, 23 | { "rule": "*semi", "severity": "off", "fixable": true } 24 | ], 25 | 26 | // Enable eslint for all supported languages 27 | "eslint.validate": [ 28 | "javascript", 29 | "javascriptreact", 30 | "typescript", 31 | "typescriptreact", 32 | "vue", 33 | "html", 34 | "markdown", 35 | "json", 36 | "json5", 37 | "jsonc", 38 | "yaml", 39 | "toml", 40 | "xml", 41 | "gql", 42 | "graphql", 43 | "astro", 44 | "svelte", 45 | "css", 46 | "less", 47 | "scss", 48 | "pcss", 49 | "postcss" 50 | ], 51 | // Disable the default formatter, use eslint instead 52 | "prettier.enable": false, 53 | "editor.formatOnSave": false, 54 | 55 | // Auto fix 56 | "editor.codeActionsOnSave": { 57 | "source.fixAll.eslint": "explicit", 58 | "source.organizeImports": "never" 59 | }, 60 | 61 | // Silent the stylistic rules in you IDE, but still auto fix them 62 | "eslint.rules.customizations": [ 63 | { "rule": "style/*", "severity": "off", "fixable": true }, 64 | { "rule": "format/*", "severity": "off", "fixable": true }, 65 | { "rule": "*-indent", "severity": "off", "fixable": true }, 66 | { "rule": "*-spacing", "severity": "off", "fixable": true }, 67 | { "rule": "*-spaces", "severity": "off", "fixable": true }, 68 | { "rule": "*-order", "severity": "off", "fixable": true }, 69 | { "rule": "*-dangle", "severity": "off", "fixable": true }, 70 | { "rule": "*-newline", "severity": "off", "fixable": true }, 71 | { "rule": "*quotes", "severity": "off", "fixable": true }, 72 | { "rule": "*semi", "severity": "off", "fixable": true } 73 | ], 74 | 75 | // Enable eslint for all supported languages 76 | "eslint.validate": [ 77 | "javascript", 78 | "javascriptreact", 79 | "typescript", 80 | "typescriptreact", 81 | "vue", 82 | "html", 83 | "markdown", 84 | "json", 85 | "json5", 86 | "jsonc", 87 | "yaml", 88 | "toml", 89 | "xml", 90 | "gql", 91 | "graphql", 92 | "astro", 93 | "svelte", 94 | "css", 95 | "less", 96 | "scss", 97 | "pcss", 98 | "postcss" 99 | ] 100 | } 101 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Felix Cornelissen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # unplugin-json-dts 2 | 3 | [![NPM version](https://img.shields.io/npm/v/unplugin-json-dts?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-json-dts) 4 | 5 | Automatically generate better typings for json files. Supports json modules. 6 | 7 | ![Comparision of before and after screenshots](/assets/before-after.gif) 8 | 9 | ## Installation 10 | 11 | ```bash 12 | npm i unplugin-json-dts -D 13 | ``` 14 | 15 |
16 | Vite
17 | 18 | ```ts 19 | // vite.config.ts 20 | import jsonDts from 'unplugin-json-dts/vite' 21 | export default defineConfig({ 22 | plugins: [ 23 | jsonDts(), 24 | ], 25 | }) 26 | ``` 27 | 28 |
29 | 30 |
31 | Rollup
32 | 33 | ```ts 34 | // rollup.config.js 35 | import jsonDts from 'unplugin-json-dts/rollup' 36 | export default { 37 | plugins: [ 38 | jsonDts(), 39 | ], 40 | } 41 | ``` 42 | 43 |
44 | 45 | 46 |
47 | Webpack
48 | 49 | ```ts 50 | // webpack.config.js 51 | module.exports = { 52 | /* ... */ 53 | plugins: [ 54 | require('unplugin-json-dts/webpack')() 55 | ] 56 | } 57 | ``` -------------------------------------------------------------------------------- /assets/before-after.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flixcor/unplugin-json-dts/0265647a7fc67c454971da7ecf6f1ba364585835/assets/before-after.gif -------------------------------------------------------------------------------- /eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import antfu from '@antfu/eslint-config' 2 | 3 | export default antfu({ 4 | ignores: ["node_modules","**/node_modules/**","dist","**/dist/**","example","**/example/**","tools","**/tools/**",".eslintrc.js","**/.eslintrc.js/**",".prettierrc.js","**/.prettierrc.js/**"], 5 | formatters: true, 6 | }) 7 | -------------------------------------------------------------------------------- /example/vite/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist 4 | dist-ssr 5 | *.local -------------------------------------------------------------------------------- /example/vite/favicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /example/vite/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite App 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /example/vite/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "unplugin-json-dts-example", 3 | "version": "0.0.0", 4 | "type": "module", 5 | "scripts": { 6 | "dev": "vite" 7 | }, 8 | "devDependencies": { 9 | "typescript": "^5.8.2", 10 | "unplugin-json-dts": "^1.3.1", 11 | "vite": "^6.3.4" 12 | }, 13 | "pnpm": { 14 | "onlyBuiltDependencies": [ 15 | "esbuild" 16 | ] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /example/vite/pnpm-lock.yaml: -------------------------------------------------------------------------------- 1 | lockfileVersion: '9.0' 2 | 3 | settings: 4 | autoInstallPeers: true 5 | excludeLinksFromLockfile: false 6 | 7 | importers: 8 | 9 | .: 10 | devDependencies: 11 | typescript: 12 | specifier: ^5.8.2 13 | version: 5.8.2 14 | unplugin-json-dts: 15 | specifier: ^1.3.1 16 | version: 1.3.1(vite@6.3.4) 17 | vite: 18 | specifier: ^6.3.4 19 | version: 6.3.4 20 | 21 | packages: 22 | 23 | '@esbuild/aix-ppc64@0.25.3': 24 | resolution: {integrity: sha512-W8bFfPA8DowP8l//sxjJLSLkD8iEjMc7cBVyP+u4cEv9sM7mdUCkgsj+t0n/BWPFtv7WWCN5Yzj0N6FJNUUqBQ==} 25 | engines: {node: '>=18'} 26 | cpu: [ppc64] 27 | os: [aix] 28 | 29 | '@esbuild/android-arm64@0.25.3': 30 | resolution: {integrity: sha512-XelR6MzjlZuBM4f5z2IQHK6LkK34Cvv6Rj2EntER3lwCBFdg6h2lKbtRjpTTsdEjD/WSe1q8UyPBXP1x3i/wYQ==} 31 | engines: {node: '>=18'} 32 | cpu: [arm64] 33 | os: [android] 34 | 35 | '@esbuild/android-arm@0.25.3': 36 | resolution: {integrity: sha512-PuwVXbnP87Tcff5I9ngV0lmiSu40xw1At6i3GsU77U7cjDDB4s0X2cyFuBiDa1SBk9DnvWwnGvVaGBqoFWPb7A==} 37 | engines: {node: '>=18'} 38 | cpu: [arm] 39 | os: [android] 40 | 41 | '@esbuild/android-x64@0.25.3': 42 | resolution: {integrity: sha512-ogtTpYHT/g1GWS/zKM0cc/tIebFjm1F9Aw1boQ2Y0eUQ+J89d0jFY//s9ei9jVIlkYi8AfOjiixcLJSGNSOAdQ==} 43 | engines: {node: '>=18'} 44 | cpu: [x64] 45 | os: [android] 46 | 47 | '@esbuild/darwin-arm64@0.25.3': 48 | resolution: {integrity: sha512-eESK5yfPNTqpAmDfFWNsOhmIOaQA59tAcF/EfYvo5/QWQCzXn5iUSOnqt3ra3UdzBv073ykTtmeLJZGt3HhA+w==} 49 | engines: {node: '>=18'} 50 | cpu: [arm64] 51 | os: [darwin] 52 | 53 | '@esbuild/darwin-x64@0.25.3': 54 | resolution: {integrity: sha512-Kd8glo7sIZtwOLcPbW0yLpKmBNWMANZhrC1r6K++uDR2zyzb6AeOYtI6udbtabmQpFaxJ8uduXMAo1gs5ozz8A==} 55 | engines: {node: '>=18'} 56 | cpu: [x64] 57 | os: [darwin] 58 | 59 | '@esbuild/freebsd-arm64@0.25.3': 60 | resolution: {integrity: sha512-EJiyS70BYybOBpJth3M0KLOus0n+RRMKTYzhYhFeMwp7e/RaajXvP+BWlmEXNk6uk+KAu46j/kaQzr6au+JcIw==} 61 | engines: {node: '>=18'} 62 | cpu: [arm64] 63 | os: [freebsd] 64 | 65 | '@esbuild/freebsd-x64@0.25.3': 66 | resolution: {integrity: sha512-Q+wSjaLpGxYf7zC0kL0nDlhsfuFkoN+EXrx2KSB33RhinWzejOd6AvgmP5JbkgXKmjhmpfgKZq24pneodYqE8Q==} 67 | engines: {node: '>=18'} 68 | cpu: [x64] 69 | os: [freebsd] 70 | 71 | '@esbuild/linux-arm64@0.25.3': 72 | resolution: {integrity: sha512-xCUgnNYhRD5bb1C1nqrDV1PfkwgbswTTBRbAd8aH5PhYzikdf/ddtsYyMXFfGSsb/6t6QaPSzxtbfAZr9uox4A==} 73 | engines: {node: '>=18'} 74 | cpu: [arm64] 75 | os: [linux] 76 | 77 | '@esbuild/linux-arm@0.25.3': 78 | resolution: {integrity: sha512-dUOVmAUzuHy2ZOKIHIKHCm58HKzFqd+puLaS424h6I85GlSDRZIA5ycBixb3mFgM0Jdh+ZOSB6KptX30DD8YOQ==} 79 | engines: {node: '>=18'} 80 | cpu: [arm] 81 | os: [linux] 82 | 83 | '@esbuild/linux-ia32@0.25.3': 84 | resolution: {integrity: sha512-yplPOpczHOO4jTYKmuYuANI3WhvIPSVANGcNUeMlxH4twz/TeXuzEP41tGKNGWJjuMhotpGabeFYGAOU2ummBw==} 85 | engines: {node: '>=18'} 86 | cpu: [ia32] 87 | os: [linux] 88 | 89 | '@esbuild/linux-loong64@0.25.3': 90 | resolution: {integrity: sha512-P4BLP5/fjyihmXCELRGrLd793q/lBtKMQl8ARGpDxgzgIKJDRJ/u4r1A/HgpBpKpKZelGct2PGI4T+axcedf6g==} 91 | engines: {node: '>=18'} 92 | cpu: [loong64] 93 | os: [linux] 94 | 95 | '@esbuild/linux-mips64el@0.25.3': 96 | resolution: {integrity: sha512-eRAOV2ODpu6P5divMEMa26RRqb2yUoYsuQQOuFUexUoQndm4MdpXXDBbUoKIc0iPa4aCO7gIhtnYomkn2x+bag==} 97 | engines: {node: '>=18'} 98 | cpu: [mips64el] 99 | os: [linux] 100 | 101 | '@esbuild/linux-ppc64@0.25.3': 102 | resolution: {integrity: sha512-ZC4jV2p7VbzTlnl8nZKLcBkfzIf4Yad1SJM4ZMKYnJqZFD4rTI+pBG65u8ev4jk3/MPwY9DvGn50wi3uhdaghg==} 103 | engines: {node: '>=18'} 104 | cpu: [ppc64] 105 | os: [linux] 106 | 107 | '@esbuild/linux-riscv64@0.25.3': 108 | resolution: {integrity: sha512-LDDODcFzNtECTrUUbVCs6j9/bDVqy7DDRsuIXJg6so+mFksgwG7ZVnTruYi5V+z3eE5y+BJZw7VvUadkbfg7QA==} 109 | engines: {node: '>=18'} 110 | cpu: [riscv64] 111 | os: [linux] 112 | 113 | '@esbuild/linux-s390x@0.25.3': 114 | resolution: {integrity: sha512-s+w/NOY2k0yC2p9SLen+ymflgcpRkvwwa02fqmAwhBRI3SC12uiS10edHHXlVWwfAagYSY5UpmT/zISXPMW3tQ==} 115 | engines: {node: '>=18'} 116 | cpu: [s390x] 117 | os: [linux] 118 | 119 | '@esbuild/linux-x64@0.25.3': 120 | resolution: {integrity: sha512-nQHDz4pXjSDC6UfOE1Fw9Q8d6GCAd9KdvMZpfVGWSJztYCarRgSDfOVBY5xwhQXseiyxapkiSJi/5/ja8mRFFA==} 121 | engines: {node: '>=18'} 122 | cpu: [x64] 123 | os: [linux] 124 | 125 | '@esbuild/netbsd-arm64@0.25.3': 126 | resolution: {integrity: sha512-1QaLtOWq0mzK6tzzp0jRN3eccmN3hezey7mhLnzC6oNlJoUJz4nym5ZD7mDnS/LZQgkrhEbEiTn515lPeLpgWA==} 127 | engines: {node: '>=18'} 128 | cpu: [arm64] 129 | os: [netbsd] 130 | 131 | '@esbuild/netbsd-x64@0.25.3': 132 | resolution: {integrity: sha512-i5Hm68HXHdgv8wkrt+10Bc50zM0/eonPb/a/OFVfB6Qvpiirco5gBA5bz7S2SHuU+Y4LWn/zehzNX14Sp4r27g==} 133 | engines: {node: '>=18'} 134 | cpu: [x64] 135 | os: [netbsd] 136 | 137 | '@esbuild/openbsd-arm64@0.25.3': 138 | resolution: {integrity: sha512-zGAVApJEYTbOC6H/3QBr2mq3upG/LBEXr85/pTtKiv2IXcgKV0RT0QA/hSXZqSvLEpXeIxah7LczB4lkiYhTAQ==} 139 | engines: {node: '>=18'} 140 | cpu: [arm64] 141 | os: [openbsd] 142 | 143 | '@esbuild/openbsd-x64@0.25.3': 144 | resolution: {integrity: sha512-fpqctI45NnCIDKBH5AXQBsD0NDPbEFczK98hk/aa6HJxbl+UtLkJV2+Bvy5hLSLk3LHmqt0NTkKNso1A9y1a4w==} 145 | engines: {node: '>=18'} 146 | cpu: [x64] 147 | os: [openbsd] 148 | 149 | '@esbuild/sunos-x64@0.25.3': 150 | resolution: {integrity: sha512-ROJhm7d8bk9dMCUZjkS8fgzsPAZEjtRJqCAmVgB0gMrvG7hfmPmz9k1rwO4jSiblFjYmNvbECL9uhaPzONMfgA==} 151 | engines: {node: '>=18'} 152 | cpu: [x64] 153 | os: [sunos] 154 | 155 | '@esbuild/win32-arm64@0.25.3': 156 | resolution: {integrity: sha512-YWcow8peiHpNBiIXHwaswPnAXLsLVygFwCB3A7Bh5jRkIBFWHGmNQ48AlX4xDvQNoMZlPYzjVOQDYEzWCqufMQ==} 157 | engines: {node: '>=18'} 158 | cpu: [arm64] 159 | os: [win32] 160 | 161 | '@esbuild/win32-ia32@0.25.3': 162 | resolution: {integrity: sha512-qspTZOIGoXVS4DpNqUYUs9UxVb04khS1Degaw/MnfMe7goQ3lTfQ13Vw4qY/Nj0979BGvMRpAYbs/BAxEvU8ew==} 163 | engines: {node: '>=18'} 164 | cpu: [ia32] 165 | os: [win32] 166 | 167 | '@esbuild/win32-x64@0.25.3': 168 | resolution: {integrity: sha512-ICgUR+kPimx0vvRzf+N/7L7tVSQeE3BYY+NhHRHXS1kBuPO7z2+7ea2HbhDyZdTephgvNvKrlDDKUexuCVBVvg==} 169 | engines: {node: '>=18'} 170 | cpu: [x64] 171 | os: [win32] 172 | 173 | '@rollup/rollup-android-arm-eabi@4.40.1': 174 | resolution: {integrity: sha512-kxz0YeeCrRUHz3zyqvd7n+TVRlNyTifBsmnmNPtk3hQURUyG9eAB+usz6DAwagMusjx/zb3AjvDUvhFGDAexGw==} 175 | cpu: [arm] 176 | os: [android] 177 | 178 | '@rollup/rollup-android-arm64@4.40.1': 179 | resolution: {integrity: sha512-PPkxTOisoNC6TpnDKatjKkjRMsdaWIhyuMkA4UsBXT9WEZY4uHezBTjs6Vl4PbqQQeu6oION1w2voYZv9yquCw==} 180 | cpu: [arm64] 181 | os: [android] 182 | 183 | '@rollup/rollup-darwin-arm64@4.40.1': 184 | resolution: {integrity: sha512-VWXGISWFY18v/0JyNUy4A46KCFCb9NVsH+1100XP31lud+TzlezBbz24CYzbnA4x6w4hx+NYCXDfnvDVO6lcAA==} 185 | cpu: [arm64] 186 | os: [darwin] 187 | 188 | '@rollup/rollup-darwin-x64@4.40.1': 189 | resolution: {integrity: sha512-nIwkXafAI1/QCS7pxSpv/ZtFW6TXcNUEHAIA9EIyw5OzxJZQ1YDrX+CL6JAIQgZ33CInl1R6mHet9Y/UZTg2Bw==} 190 | cpu: [x64] 191 | os: [darwin] 192 | 193 | '@rollup/rollup-freebsd-arm64@4.40.1': 194 | resolution: {integrity: sha512-BdrLJ2mHTrIYdaS2I99mriyJfGGenSaP+UwGi1kB9BLOCu9SR8ZpbkmmalKIALnRw24kM7qCN0IOm6L0S44iWw==} 195 | cpu: [arm64] 196 | os: [freebsd] 197 | 198 | '@rollup/rollup-freebsd-x64@4.40.1': 199 | resolution: {integrity: sha512-VXeo/puqvCG8JBPNZXZf5Dqq7BzElNJzHRRw3vjBE27WujdzuOPecDPc/+1DcdcTptNBep3861jNq0mYkT8Z6Q==} 200 | cpu: [x64] 201 | os: [freebsd] 202 | 203 | '@rollup/rollup-linux-arm-gnueabihf@4.40.1': 204 | resolution: {integrity: sha512-ehSKrewwsESPt1TgSE/na9nIhWCosfGSFqv7vwEtjyAqZcvbGIg4JAcV7ZEh2tfj/IlfBeZjgOXm35iOOjadcg==} 205 | cpu: [arm] 206 | os: [linux] 207 | 208 | '@rollup/rollup-linux-arm-musleabihf@4.40.1': 209 | resolution: {integrity: sha512-m39iO/aaurh5FVIu/F4/Zsl8xppd76S4qoID8E+dSRQvTyZTOI2gVk3T4oqzfq1PtcvOfAVlwLMK3KRQMaR8lg==} 210 | cpu: [arm] 211 | os: [linux] 212 | 213 | '@rollup/rollup-linux-arm64-gnu@4.40.1': 214 | resolution: {integrity: sha512-Y+GHnGaku4aVLSgrT0uWe2o2Rq8te9hi+MwqGF9r9ORgXhmHK5Q71N757u0F8yU1OIwUIFy6YiJtKjtyktk5hg==} 215 | cpu: [arm64] 216 | os: [linux] 217 | 218 | '@rollup/rollup-linux-arm64-musl@4.40.1': 219 | resolution: {integrity: sha512-jEwjn3jCA+tQGswK3aEWcD09/7M5wGwc6+flhva7dsQNRZZTe30vkalgIzV4tjkopsTS9Jd7Y1Bsj6a4lzz8gQ==} 220 | cpu: [arm64] 221 | os: [linux] 222 | 223 | '@rollup/rollup-linux-loongarch64-gnu@4.40.1': 224 | resolution: {integrity: sha512-ySyWikVhNzv+BV/IDCsrraOAZ3UaC8SZB67FZlqVwXwnFhPihOso9rPOxzZbjp81suB1O2Topw+6Ug3JNegejQ==} 225 | cpu: [loong64] 226 | os: [linux] 227 | 228 | '@rollup/rollup-linux-powerpc64le-gnu@4.40.1': 229 | resolution: {integrity: sha512-BvvA64QxZlh7WZWqDPPdt0GH4bznuL6uOO1pmgPnnv86rpUpc8ZxgZwcEgXvo02GRIZX1hQ0j0pAnhwkhwPqWg==} 230 | cpu: [ppc64] 231 | os: [linux] 232 | 233 | '@rollup/rollup-linux-riscv64-gnu@4.40.1': 234 | resolution: {integrity: sha512-EQSP+8+1VuSulm9RKSMKitTav89fKbHymTf25n5+Yr6gAPZxYWpj3DzAsQqoaHAk9YX2lwEyAf9S4W8F4l3VBQ==} 235 | cpu: [riscv64] 236 | os: [linux] 237 | 238 | '@rollup/rollup-linux-riscv64-musl@4.40.1': 239 | resolution: {integrity: sha512-n/vQ4xRZXKuIpqukkMXZt9RWdl+2zgGNx7Uda8NtmLJ06NL8jiHxUawbwC+hdSq1rrw/9CghCpEONor+l1e2gA==} 240 | cpu: [riscv64] 241 | os: [linux] 242 | 243 | '@rollup/rollup-linux-s390x-gnu@4.40.1': 244 | resolution: {integrity: sha512-h8d28xzYb98fMQKUz0w2fMc1XuGzLLjdyxVIbhbil4ELfk5/orZlSTpF/xdI9C8K0I8lCkq+1En2RJsawZekkg==} 245 | cpu: [s390x] 246 | os: [linux] 247 | 248 | '@rollup/rollup-linux-x64-gnu@4.40.1': 249 | resolution: {integrity: sha512-XiK5z70PEFEFqcNj3/zRSz/qX4bp4QIraTy9QjwJAb/Z8GM7kVUsD0Uk8maIPeTyPCP03ChdI+VVmJriKYbRHQ==} 250 | cpu: [x64] 251 | os: [linux] 252 | 253 | '@rollup/rollup-linux-x64-musl@4.40.1': 254 | resolution: {integrity: sha512-2BRORitq5rQ4Da9blVovzNCMaUlyKrzMSvkVR0D4qPuOy/+pMCrh1d7o01RATwVy+6Fa1WBw+da7QPeLWU/1mQ==} 255 | cpu: [x64] 256 | os: [linux] 257 | 258 | '@rollup/rollup-win32-arm64-msvc@4.40.1': 259 | resolution: {integrity: sha512-b2bcNm9Kbde03H+q+Jjw9tSfhYkzrDUf2d5MAd1bOJuVplXvFhWz7tRtWvD8/ORZi7qSCy0idW6tf2HgxSXQSg==} 260 | cpu: [arm64] 261 | os: [win32] 262 | 263 | '@rollup/rollup-win32-ia32-msvc@4.40.1': 264 | resolution: {integrity: sha512-DfcogW8N7Zg7llVEfpqWMZcaErKfsj9VvmfSyRjCyo4BI3wPEfrzTtJkZG6gKP/Z92wFm6rz2aDO7/JfiR/whA==} 265 | cpu: [ia32] 266 | os: [win32] 267 | 268 | '@rollup/rollup-win32-x64-msvc@4.40.1': 269 | resolution: {integrity: sha512-ECyOuDeH3C1I8jH2MK1RtBJW+YPMvSfT0a5NN0nHfQYnDSJ6tUiZH3gzwVP5/Kfh/+Tt7tpWVF9LXNTnhTJ3kA==} 270 | cpu: [x64] 271 | os: [win32] 272 | 273 | '@types/estree@1.0.7': 274 | resolution: {integrity: sha512-w28IoSUCJpidD/TGviZwwMJckNESJZXFu7NBZ5YJ4mEUnNraUn9Pm8HSZm/jDF1pDWYKspWE7oVphigUPRakIQ==} 275 | 276 | acorn@8.14.1: 277 | resolution: {integrity: sha512-OvQ/2pUDKmgfCg++xsTX1wGxfTaszcHVcTctW4UJB4hibJx2HXxxO5UmVgyjMa+ZDsiaf5wWLXYpRWMmBI0QHg==} 278 | engines: {node: '>=0.4.0'} 279 | hasBin: true 280 | 281 | esbuild@0.25.3: 282 | resolution: {integrity: sha512-qKA6Pvai73+M2FtftpNKRxJ78GIjmFXFxd/1DVBqGo/qNhLSfv+G12n9pNoWdytJC8U00TrViOwpjT0zgqQS8Q==} 283 | engines: {node: '>=18'} 284 | hasBin: true 285 | 286 | fdir@6.4.4: 287 | resolution: {integrity: sha512-1NZP+GK4GfuAv3PqKvxQRDMjdSRZjnkq7KfhlNrCNNlZ0ygQFpebfrnfnq/W7fpUnAv9aGWmY1zKx7FYL3gwhg==} 288 | peerDependencies: 289 | picomatch: ^3 || ^4 290 | peerDependenciesMeta: 291 | picomatch: 292 | optional: true 293 | 294 | fsevents@2.3.3: 295 | resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} 296 | engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} 297 | os: [darwin] 298 | 299 | nanoid@3.3.11: 300 | resolution: {integrity: sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==} 301 | engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} 302 | hasBin: true 303 | 304 | picocolors@1.1.1: 305 | resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==} 306 | 307 | picomatch@4.0.2: 308 | resolution: {integrity: sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==} 309 | engines: {node: '>=12'} 310 | 311 | postcss@8.5.3: 312 | resolution: {integrity: sha512-dle9A3yYxlBSrt8Fu+IpjGT8SY8hN0mlaA6GY8t0P5PjIOZemULz/E2Bnm/2dcUOena75OTNkHI76uZBNUUq3A==} 313 | engines: {node: ^10 || ^12 || >=14} 314 | 315 | rollup@4.40.1: 316 | resolution: {integrity: sha512-C5VvvgCCyfyotVITIAv+4efVytl5F7wt+/I2i9q9GZcEXW9BP52YYOXC58igUi+LFZVHukErIIqQSWwv/M3WRw==} 317 | engines: {node: '>=18.0.0', npm: '>=8.0.0'} 318 | hasBin: true 319 | 320 | source-map-js@1.2.1: 321 | resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} 322 | engines: {node: '>=0.10.0'} 323 | 324 | tinyglobby@0.2.13: 325 | resolution: {integrity: sha512-mEwzpUgrLySlveBwEVDMKk5B57bhLPYovRfPAXD5gA/98Opn0rCDj3GtLwFvCvH5RK9uPCExUROW5NjDwvqkxw==} 326 | engines: {node: '>=12.0.0'} 327 | 328 | typescript@5.8.2: 329 | resolution: {integrity: sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ==} 330 | engines: {node: '>=14.17'} 331 | hasBin: true 332 | 333 | unplugin-json-dts@1.3.1: 334 | resolution: {integrity: sha512-AHkUAmsL78pzr3HvpgDAn8ruYrl5gJTRrAt972KW1UtLdtbS9YJoS5nci+ruDvSPwqKw24JmIztfI7YWWA/D9Q==} 335 | engines: {node: '>=22.14'} 336 | peerDependencies: 337 | rollup: ^3 338 | vite: '>=5' 339 | webpack: ^4 || ^5 340 | peerDependenciesMeta: 341 | rollup: 342 | optional: true 343 | vite: 344 | optional: true 345 | webpack: 346 | optional: true 347 | 348 | unplugin@2.2.2: 349 | resolution: {integrity: sha512-Qp+iiD+qCRnUek+nDoYvtWX7tfnYyXsrOnJ452FRTgOyKmTM7TUJ3l+PLPJOOWPTUyKISKp4isC5JJPSXUjGgw==} 350 | engines: {node: '>=18.12.0'} 351 | 352 | vite@6.3.4: 353 | resolution: {integrity: sha512-BiReIiMS2fyFqbqNT/Qqt4CVITDU9M9vE+DKcVAsB+ZV0wvTKd+3hMbkpxz1b+NmEDMegpVbisKiAZOnvO92Sw==} 354 | engines: {node: ^18.0.0 || ^20.0.0 || >=22.0.0} 355 | hasBin: true 356 | peerDependencies: 357 | '@types/node': ^18.0.0 || ^20.0.0 || >=22.0.0 358 | jiti: '>=1.21.0' 359 | less: '*' 360 | lightningcss: ^1.21.0 361 | sass: '*' 362 | sass-embedded: '*' 363 | stylus: '*' 364 | sugarss: '*' 365 | terser: ^5.16.0 366 | tsx: ^4.8.1 367 | yaml: ^2.4.2 368 | peerDependenciesMeta: 369 | '@types/node': 370 | optional: true 371 | jiti: 372 | optional: true 373 | less: 374 | optional: true 375 | lightningcss: 376 | optional: true 377 | sass: 378 | optional: true 379 | sass-embedded: 380 | optional: true 381 | stylus: 382 | optional: true 383 | sugarss: 384 | optional: true 385 | terser: 386 | optional: true 387 | tsx: 388 | optional: true 389 | yaml: 390 | optional: true 391 | 392 | webpack-virtual-modules@0.6.2: 393 | resolution: {integrity: sha512-66/V2i5hQanC51vBQKPH4aI8NMAcBW59FVBs+rC7eGHupMyfn34q7rZIE+ETlJ+XTevqfUhVVBgSUNSW2flEUQ==} 394 | 395 | snapshots: 396 | 397 | '@esbuild/aix-ppc64@0.25.3': 398 | optional: true 399 | 400 | '@esbuild/android-arm64@0.25.3': 401 | optional: true 402 | 403 | '@esbuild/android-arm@0.25.3': 404 | optional: true 405 | 406 | '@esbuild/android-x64@0.25.3': 407 | optional: true 408 | 409 | '@esbuild/darwin-arm64@0.25.3': 410 | optional: true 411 | 412 | '@esbuild/darwin-x64@0.25.3': 413 | optional: true 414 | 415 | '@esbuild/freebsd-arm64@0.25.3': 416 | optional: true 417 | 418 | '@esbuild/freebsd-x64@0.25.3': 419 | optional: true 420 | 421 | '@esbuild/linux-arm64@0.25.3': 422 | optional: true 423 | 424 | '@esbuild/linux-arm@0.25.3': 425 | optional: true 426 | 427 | '@esbuild/linux-ia32@0.25.3': 428 | optional: true 429 | 430 | '@esbuild/linux-loong64@0.25.3': 431 | optional: true 432 | 433 | '@esbuild/linux-mips64el@0.25.3': 434 | optional: true 435 | 436 | '@esbuild/linux-ppc64@0.25.3': 437 | optional: true 438 | 439 | '@esbuild/linux-riscv64@0.25.3': 440 | optional: true 441 | 442 | '@esbuild/linux-s390x@0.25.3': 443 | optional: true 444 | 445 | '@esbuild/linux-x64@0.25.3': 446 | optional: true 447 | 448 | '@esbuild/netbsd-arm64@0.25.3': 449 | optional: true 450 | 451 | '@esbuild/netbsd-x64@0.25.3': 452 | optional: true 453 | 454 | '@esbuild/openbsd-arm64@0.25.3': 455 | optional: true 456 | 457 | '@esbuild/openbsd-x64@0.25.3': 458 | optional: true 459 | 460 | '@esbuild/sunos-x64@0.25.3': 461 | optional: true 462 | 463 | '@esbuild/win32-arm64@0.25.3': 464 | optional: true 465 | 466 | '@esbuild/win32-ia32@0.25.3': 467 | optional: true 468 | 469 | '@esbuild/win32-x64@0.25.3': 470 | optional: true 471 | 472 | '@rollup/rollup-android-arm-eabi@4.40.1': 473 | optional: true 474 | 475 | '@rollup/rollup-android-arm64@4.40.1': 476 | optional: true 477 | 478 | '@rollup/rollup-darwin-arm64@4.40.1': 479 | optional: true 480 | 481 | '@rollup/rollup-darwin-x64@4.40.1': 482 | optional: true 483 | 484 | '@rollup/rollup-freebsd-arm64@4.40.1': 485 | optional: true 486 | 487 | '@rollup/rollup-freebsd-x64@4.40.1': 488 | optional: true 489 | 490 | '@rollup/rollup-linux-arm-gnueabihf@4.40.1': 491 | optional: true 492 | 493 | '@rollup/rollup-linux-arm-musleabihf@4.40.1': 494 | optional: true 495 | 496 | '@rollup/rollup-linux-arm64-gnu@4.40.1': 497 | optional: true 498 | 499 | '@rollup/rollup-linux-arm64-musl@4.40.1': 500 | optional: true 501 | 502 | '@rollup/rollup-linux-loongarch64-gnu@4.40.1': 503 | optional: true 504 | 505 | '@rollup/rollup-linux-powerpc64le-gnu@4.40.1': 506 | optional: true 507 | 508 | '@rollup/rollup-linux-riscv64-gnu@4.40.1': 509 | optional: true 510 | 511 | '@rollup/rollup-linux-riscv64-musl@4.40.1': 512 | optional: true 513 | 514 | '@rollup/rollup-linux-s390x-gnu@4.40.1': 515 | optional: true 516 | 517 | '@rollup/rollup-linux-x64-gnu@4.40.1': 518 | optional: true 519 | 520 | '@rollup/rollup-linux-x64-musl@4.40.1': 521 | optional: true 522 | 523 | '@rollup/rollup-win32-arm64-msvc@4.40.1': 524 | optional: true 525 | 526 | '@rollup/rollup-win32-ia32-msvc@4.40.1': 527 | optional: true 528 | 529 | '@rollup/rollup-win32-x64-msvc@4.40.1': 530 | optional: true 531 | 532 | '@types/estree@1.0.7': {} 533 | 534 | acorn@8.14.1: {} 535 | 536 | esbuild@0.25.3: 537 | optionalDependencies: 538 | '@esbuild/aix-ppc64': 0.25.3 539 | '@esbuild/android-arm': 0.25.3 540 | '@esbuild/android-arm64': 0.25.3 541 | '@esbuild/android-x64': 0.25.3 542 | '@esbuild/darwin-arm64': 0.25.3 543 | '@esbuild/darwin-x64': 0.25.3 544 | '@esbuild/freebsd-arm64': 0.25.3 545 | '@esbuild/freebsd-x64': 0.25.3 546 | '@esbuild/linux-arm': 0.25.3 547 | '@esbuild/linux-arm64': 0.25.3 548 | '@esbuild/linux-ia32': 0.25.3 549 | '@esbuild/linux-loong64': 0.25.3 550 | '@esbuild/linux-mips64el': 0.25.3 551 | '@esbuild/linux-ppc64': 0.25.3 552 | '@esbuild/linux-riscv64': 0.25.3 553 | '@esbuild/linux-s390x': 0.25.3 554 | '@esbuild/linux-x64': 0.25.3 555 | '@esbuild/netbsd-arm64': 0.25.3 556 | '@esbuild/netbsd-x64': 0.25.3 557 | '@esbuild/openbsd-arm64': 0.25.3 558 | '@esbuild/openbsd-x64': 0.25.3 559 | '@esbuild/sunos-x64': 0.25.3 560 | '@esbuild/win32-arm64': 0.25.3 561 | '@esbuild/win32-ia32': 0.25.3 562 | '@esbuild/win32-x64': 0.25.3 563 | 564 | fdir@6.4.4(picomatch@4.0.2): 565 | optionalDependencies: 566 | picomatch: 4.0.2 567 | 568 | fsevents@2.3.3: 569 | optional: true 570 | 571 | nanoid@3.3.11: {} 572 | 573 | picocolors@1.1.1: {} 574 | 575 | picomatch@4.0.2: {} 576 | 577 | postcss@8.5.3: 578 | dependencies: 579 | nanoid: 3.3.11 580 | picocolors: 1.1.1 581 | source-map-js: 1.2.1 582 | 583 | rollup@4.40.1: 584 | dependencies: 585 | '@types/estree': 1.0.7 586 | optionalDependencies: 587 | '@rollup/rollup-android-arm-eabi': 4.40.1 588 | '@rollup/rollup-android-arm64': 4.40.1 589 | '@rollup/rollup-darwin-arm64': 4.40.1 590 | '@rollup/rollup-darwin-x64': 4.40.1 591 | '@rollup/rollup-freebsd-arm64': 4.40.1 592 | '@rollup/rollup-freebsd-x64': 4.40.1 593 | '@rollup/rollup-linux-arm-gnueabihf': 4.40.1 594 | '@rollup/rollup-linux-arm-musleabihf': 4.40.1 595 | '@rollup/rollup-linux-arm64-gnu': 4.40.1 596 | '@rollup/rollup-linux-arm64-musl': 4.40.1 597 | '@rollup/rollup-linux-loongarch64-gnu': 4.40.1 598 | '@rollup/rollup-linux-powerpc64le-gnu': 4.40.1 599 | '@rollup/rollup-linux-riscv64-gnu': 4.40.1 600 | '@rollup/rollup-linux-riscv64-musl': 4.40.1 601 | '@rollup/rollup-linux-s390x-gnu': 4.40.1 602 | '@rollup/rollup-linux-x64-gnu': 4.40.1 603 | '@rollup/rollup-linux-x64-musl': 4.40.1 604 | '@rollup/rollup-win32-arm64-msvc': 4.40.1 605 | '@rollup/rollup-win32-ia32-msvc': 4.40.1 606 | '@rollup/rollup-win32-x64-msvc': 4.40.1 607 | fsevents: 2.3.3 608 | 609 | source-map-js@1.2.1: {} 610 | 611 | tinyglobby@0.2.13: 612 | dependencies: 613 | fdir: 6.4.4(picomatch@4.0.2) 614 | picomatch: 4.0.2 615 | 616 | typescript@5.8.2: {} 617 | 618 | unplugin-json-dts@1.3.1(vite@6.3.4): 619 | dependencies: 620 | unplugin: 2.2.2 621 | optionalDependencies: 622 | vite: 6.3.4 623 | 624 | unplugin@2.2.2: 625 | dependencies: 626 | acorn: 8.14.1 627 | webpack-virtual-modules: 0.6.2 628 | 629 | vite@6.3.4: 630 | dependencies: 631 | esbuild: 0.25.3 632 | fdir: 6.4.4(picomatch@4.0.2) 633 | picomatch: 4.0.2 634 | postcss: 8.5.3 635 | rollup: 4.40.1 636 | tinyglobby: 0.2.13 637 | optionalDependencies: 638 | fsevents: 2.3.3 639 | 640 | webpack-virtual-modules@0.6.2: {} 641 | -------------------------------------------------------------------------------- /example/vite/src/10004_bytes.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "label": "Sourc", 4 | "1": "" 5 | }, 6 | { 7 | "label": "Target language", 8 | "name": "targetLanguage", 9 | "description": "Choose the language of the target words.", 10 | "type": "select", 11 | "options": [ 12 | { "value": "en", "label": "English" }, 13 | { "value": "fr", "label": "French" }, 14 | { "value": "de", "label": "German" }, 15 | { "value": "nb", "label": "Norwegian bokmål" }, 16 | { "value": "nn", "label": "Norwegian nynorsk" }, 17 | { "value": "es", "label": "Spanish" } 18 | ], 19 | "default": "nb" 20 | }, 21 | { 22 | "label": "Words", 23 | "name": "words", 24 | "type": "text", 25 | "optional": true, 26 | "widget": "csv-to-text", 27 | "description": "Add words by uploading a CSV-file or write them in the text field.", 28 | "important": { 29 | "description": "", 30 | "example": "water/sea:w___r,vann/hav:v__n" 31 | } 32 | }, 33 | { 34 | "name": "overallFeedback", 35 | "type": "group", 36 | "label": "Overall Feedback", 37 | "importance": "low", 38 | "expanded": true, 39 | "fields": [ 40 | { 41 | "name": "overallFeedback", 42 | "type": "list", 43 | "widgets": [ 44 | { 45 | "name": "RangeList", 46 | "label": "Default" 47 | } 48 | ], 49 | "importance": "high", 50 | "label": "Define custom feedback for any score range", 51 | "description": "Click the \"Add range\" button to add as many ranges as you need. Example: 0-20% Bad score, 21-91% Average Score, 91-100% Great Score!", 52 | "entity": "range", 53 | "min": 1, 54 | "defaultNum": 1, 55 | "optional": true, 56 | "field": { 57 | "label": "Overall Feedback", 58 | "name": "overallFeedback", 59 | "type": "group", 60 | "importance": "low", 61 | "fields": [ 62 | { 63 | "name": "from", 64 | "type": "number", 65 | "label": "Score Range", 66 | "min": 0, 67 | "max": 100, 68 | "default": 0, 69 | "unit": "%" 70 | }, 71 | { 72 | "name": "to", 73 | "type": "number", 74 | "min": 0, 75 | "max": 100, 76 | "default": 100, 77 | "unit": "%" 78 | }, 79 | { 80 | "name": "feedback", 81 | "type": "text", 82 | "label": "Feedback for defined score range", 83 | "importance": "low", 84 | "placeholder": "Fill in the feedback", 85 | "optional": true 86 | } 87 | ] 88 | } 89 | } 90 | ] 91 | }, 92 | { 93 | "label": "Localization", 94 | "name": "l10n", 95 | "type": "group", 96 | "importance": "low", 97 | "common": true, 98 | "fields": [ 99 | { 100 | "label": "No valid words", 101 | "name": "noValidWords", 102 | "default": "No valid words found. Please check your words and try again.", 103 | "type": "text" 104 | }, 105 | { 106 | "label": "Label for \"Fill in\" answer mode", 107 | "name": "fillInLabel", 108 | "default": "Fill in", 109 | "type": "text" 110 | }, 111 | { 112 | "label": "Label for \"Drag text\" answer mode", 113 | "name": "dragTextLabel", 114 | "default": "Drag text", 115 | "type": "text" 116 | }, 117 | { 118 | "label": "Answer mode label", 119 | "name": "answerModeLabel", 120 | "default": "Change answer mode", 121 | "type": "text" 122 | }, 123 | { 124 | "label": "Language mode label", 125 | "name": "languageModeLabel", 126 | "default": "Swap languages", 127 | "type": "text" 128 | }, 129 | { 130 | "label": "Changed answer mode aria", 131 | "name": "changedAnswerModeAria", 132 | "default": "Changed answer mode to @option", 133 | "type": "text" 134 | }, 135 | { 136 | "label": "Language mode aria", 137 | "name": "languageModeAria", 138 | "default": "Swap language from @sourceLanguage to @targetLanguage", 139 | "type": "text" 140 | }, 141 | { 142 | "label": "Changed language mode aria", 143 | "name": "changedLanguageModeAria", 144 | "default": "Swapped language from @sourceLanguage to @targetLanguage", 145 | "type": "text" 146 | }, 147 | { 148 | "label": "Text for \"Next\" button", 149 | "name": "next", 150 | "default": "Next", 151 | "type": "text" 152 | }, 153 | { 154 | "label": "Text for \"Finish\" button", 155 | "name": "finish", 156 | "default": "Finish", 157 | "type": "text" 158 | }, 159 | { 160 | "label": "Text for \"Restart\" button", 161 | "name": "restart", 162 | "default": "Restart", 163 | "type": "text" 164 | }, 165 | { 166 | "label": "Score label", 167 | "name": "scoreLabel", 168 | "default": "Score", 169 | "type": "text" 170 | }, 171 | { 172 | "label": "Textual representation of the score bar for those using a readspeaker", 173 | "name": "scoreBarLabel", 174 | "default": "You got @score out of @maxScore points", 175 | "type": "text" 176 | }, 177 | { 178 | "label": "Textual representation of the page numbers for those using a readspeaker", 179 | "name": "pageNumberLabel", 180 | "default": "Page @page of @totalPages", 181 | "type": "text" 182 | }, 183 | { 184 | "label": "Feedback text", 185 | "name": "feedbackText", 186 | "default": "Your total score", 187 | "type": "text" 188 | }, 189 | { 190 | "label": "English", 191 | "name": "lang_en", 192 | "default": "English", 193 | "type": "text" 194 | }, 195 | { 196 | "label": "French", 197 | "name": "lang_fr", 198 | "default": "French", 199 | "type": "text" 200 | }, 201 | { 202 | "label": "German", 203 | "name": "lang_de", 204 | "default": "German", 205 | "type": "text" 206 | }, 207 | { 208 | "label": "Norwegian bokmål", 209 | "name": "lang_nb", 210 | "default": "Norwegian bokmål", 211 | "type": "text" 212 | }, 213 | { 214 | "label": "Norwegian nynorsk", 215 | "name": "lang_nn", 216 | "default": "Norwegian nynorsk", 217 | "type": "text" 218 | }, 219 | { 220 | "label": "Spanish", 221 | "name": "lang_es", 222 | "default": "Spanish", 223 | "type": "text" 224 | } 225 | ] 226 | }, 227 | { 228 | "name": "behaviour", 229 | "type": "group", 230 | "label": "Behavioural settings", 231 | "importance": "low", 232 | "description": "These options will let you control how the task behaves.", 233 | "fields": [ 234 | { 235 | "label": "Enable \"Retry\"", 236 | "importance": "low", 237 | "name": "enableRetry", 238 | "type": "boolean", 239 | "default": true 240 | }, 241 | { 242 | "label": "Enable \"Show solution\" button", 243 | "importance": "low", 244 | "name": "enableSolutionsButton", 245 | "type": "boolean", 246 | "default": true 247 | }, 248 | { 249 | "label": "Automatically check answers after input", 250 | "importance": "low", 251 | "name": "autoCheck", 252 | "type": "boolean", 253 | "default": false 254 | }, 255 | { 256 | "name": "caseSensitive", 257 | "importance": "low", 258 | "type": "boolean", 259 | "default": true, 260 | "label": "Case sensitive", 261 | "description": "Makes sure the user input has to be exactly the same as the answer." 262 | }, 263 | { 264 | "label": "Require all fields to be answered before the solution can be viewed", 265 | "description": "This option is only valid if the answer mode is set to \"Fill in\".", 266 | "importance": "low", 267 | "name": "showSolutionsRequiresInput", 268 | "type": "boolean", 269 | "default": true 270 | }, 271 | { 272 | "name": "acceptSpellingErrors", 273 | "type": "boolean", 274 | "label": "Accept minor spelling errors", 275 | "importance": "low", 276 | "description": "If activated, an answer will also count as correct with minor spelling errors (3-9 characters: 1 spelling error, more than 9 characters: 2 spelling errors). This option is only valid if the answer mode is set to \"Fill in\".", 277 | "default": false 278 | }, 279 | { 280 | "label": "Randomize", 281 | "name": "randomize", 282 | "type": "boolean", 283 | "default": true 284 | }, 285 | { 286 | "label": "Show tips", 287 | "name": "showTips", 288 | "type": "boolean", 289 | "default": false 290 | }, 291 | { 292 | "label": "Answer mode", 293 | "name": "answerMode", 294 | "type": "select", 295 | "widget": "radioGroup", 296 | "alignment": "horizontal", 297 | "options": [ 298 | { "label": "Fill in", "value": "fillIn" }, 299 | { "label": "Drag text", "value": "dragText" } 300 | ], 301 | "default": "fillIn" 302 | }, 303 | { 304 | "name": "enableSwitchAnswerModeButton", 305 | "type": "boolean", 306 | "label": "Enable \"Switch answer mode\" button", 307 | "importance": "low", 308 | "description": "Allow the end user to switch between modes \"Fill in\" and \"Drag text\".", 309 | "default": false 310 | }, 311 | { 312 | "name": "enableSwitchWordsButton", 313 | "type": "boolean", 314 | "label": "Enable \"Switch language mode\" button", 315 | "importance": "low", 316 | "description": "Allow the end user to switch between source and target words.", 317 | "default": false 318 | }, 319 | { 320 | "label": "Number of words", 321 | "name": "numberOfWordsToShow", 322 | "description": "Defines how many words will be visible each time. If 0 is set, all words will be shown.", 323 | "type": "number", 324 | "optional": true 325 | } 326 | ] 327 | } 328 | ] 329 | -------------------------------------------------------------------------------- /example/vite/src/10004_bytes.json.d.ts: -------------------------------------------------------------------------------- 1 | declare const json: [ 2 | { 3 | "label": "Sourc", 4 | "1": "" 5 | }, 6 | { 7 | "label": "Target language", 8 | "name": "targetLanguage", 9 | "description": "Choose the language of the target words.", 10 | "type": "select", 11 | "options": [ 12 | { "value": "en", "label": "English" }, 13 | { "value": "fr", "label": "French" }, 14 | { "value": "de", "label": "German" }, 15 | { "value": "nb", "label": "Norwegian bokmål" }, 16 | { "value": "nn", "label": "Norwegian nynorsk" }, 17 | { "value": "es", "label": "Spanish" } 18 | ], 19 | "default": "nb" 20 | }, 21 | { 22 | "label": "Words", 23 | "name": "words", 24 | "type": "text", 25 | "optional": true, 26 | "widget": "csv-to-text", 27 | "description": "Add words by uploading a CSV-file or write them in the text field.", 28 | "important": { 29 | "description": "", 30 | "example": "water/sea:w___r,vann/hav:v__n" 31 | } 32 | }, 33 | { 34 | "name": "overallFeedback", 35 | "type": "group", 36 | "label": "Overall Feedback", 37 | "importance": "low", 38 | "expanded": true, 39 | "fields": [ 40 | { 41 | "name": "overallFeedback", 42 | "type": "list", 43 | "widgets": [ 44 | { 45 | "name": "RangeList", 46 | "label": "Default" 47 | } 48 | ], 49 | "importance": "high", 50 | "label": "Define custom feedback for any score range", 51 | "description": "Click the \"Add range\" button to add as many ranges as you need. Example: 0-20% Bad score, 21-91% Average Score, 91-100% Great Score!", 52 | "entity": "range", 53 | "min": 1, 54 | "defaultNum": 1, 55 | "optional": true, 56 | "field": { 57 | "label": "Overall Feedback", 58 | "name": "overallFeedback", 59 | "type": "group", 60 | "importance": "low", 61 | "fields": [ 62 | { 63 | "name": "from", 64 | "type": "number", 65 | "label": "Score Range", 66 | "min": 0, 67 | "max": 100, 68 | "default": 0, 69 | "unit": "%" 70 | }, 71 | { 72 | "name": "to", 73 | "type": "number", 74 | "min": 0, 75 | "max": 100, 76 | "default": 100, 77 | "unit": "%" 78 | }, 79 | { 80 | "name": "feedback", 81 | "type": "text", 82 | "label": "Feedback for defined score range", 83 | "importance": "low", 84 | "placeholder": "Fill in the feedback", 85 | "optional": true 86 | } 87 | ] 88 | } 89 | } 90 | ] 91 | }, 92 | { 93 | "label": "Localization", 94 | "name": "l10n", 95 | "type": "group", 96 | "importance": "low", 97 | "common": true, 98 | "fields": [ 99 | { 100 | "label": "No valid words", 101 | "name": "noValidWords", 102 | "default": "No valid words found. Please check your words and try again.", 103 | "type": "text" 104 | }, 105 | { 106 | "label": "Label for \"Fill in\" answer mode", 107 | "name": "fillInLabel", 108 | "default": "Fill in", 109 | "type": "text" 110 | }, 111 | { 112 | "label": "Label for \"Drag text\" answer mode", 113 | "name": "dragTextLabel", 114 | "default": "Drag text", 115 | "type": "text" 116 | }, 117 | { 118 | "label": "Answer mode label", 119 | "name": "answerModeLabel", 120 | "default": "Change answer mode", 121 | "type": "text" 122 | }, 123 | { 124 | "label": "Language mode label", 125 | "name": "languageModeLabel", 126 | "default": "Swap languages", 127 | "type": "text" 128 | }, 129 | { 130 | "label": "Changed answer mode aria", 131 | "name": "changedAnswerModeAria", 132 | "default": "Changed answer mode to @option", 133 | "type": "text" 134 | }, 135 | { 136 | "label": "Language mode aria", 137 | "name": "languageModeAria", 138 | "default": "Swap language from @sourceLanguage to @targetLanguage", 139 | "type": "text" 140 | }, 141 | { 142 | "label": "Changed language mode aria", 143 | "name": "changedLanguageModeAria", 144 | "default": "Swapped language from @sourceLanguage to @targetLanguage", 145 | "type": "text" 146 | }, 147 | { 148 | "label": "Text for \"Next\" button", 149 | "name": "next", 150 | "default": "Next", 151 | "type": "text" 152 | }, 153 | { 154 | "label": "Text for \"Finish\" button", 155 | "name": "finish", 156 | "default": "Finish", 157 | "type": "text" 158 | }, 159 | { 160 | "label": "Text for \"Restart\" button", 161 | "name": "restart", 162 | "default": "Restart", 163 | "type": "text" 164 | }, 165 | { 166 | "label": "Score label", 167 | "name": "scoreLabel", 168 | "default": "Score", 169 | "type": "text" 170 | }, 171 | { 172 | "label": "Textual representation of the score bar for those using a readspeaker", 173 | "name": "scoreBarLabel", 174 | "default": "You got @score out of @maxScore points", 175 | "type": "text" 176 | }, 177 | { 178 | "label": "Textual representation of the page numbers for those using a readspeaker", 179 | "name": "pageNumberLabel", 180 | "default": "Page @page of @totalPages", 181 | "type": "text" 182 | }, 183 | { 184 | "label": "Feedback text", 185 | "name": "feedbackText", 186 | "default": "Your total score", 187 | "type": "text" 188 | }, 189 | { 190 | "label": "English", 191 | "name": "lang_en", 192 | "default": "English", 193 | "type": "text" 194 | }, 195 | { 196 | "label": "French", 197 | "name": "lang_fr", 198 | "default": "French", 199 | "type": "text" 200 | }, 201 | { 202 | "label": "German", 203 | "name": "lang_de", 204 | "default": "German", 205 | "type": "text" 206 | }, 207 | { 208 | "label": "Norwegian bokmål", 209 | "name": "lang_nb", 210 | "default": "Norwegian bokmål", 211 | "type": "text" 212 | }, 213 | { 214 | "label": "Norwegian nynorsk", 215 | "name": "lang_nn", 216 | "default": "Norwegian nynorsk", 217 | "type": "text" 218 | }, 219 | { 220 | "label": "Spanish", 221 | "name": "lang_es", 222 | "default": "Spanish", 223 | "type": "text" 224 | } 225 | ] 226 | }, 227 | { 228 | "name": "behaviour", 229 | "type": "group", 230 | "label": "Behavioural settings", 231 | "importance": "low", 232 | "description": "These options will let you control how the task behaves.", 233 | "fields": [ 234 | { 235 | "label": "Enable \"Retry\"", 236 | "importance": "low", 237 | "name": "enableRetry", 238 | "type": "boolean", 239 | "default": true 240 | }, 241 | { 242 | "label": "Enable \"Show solution\" button", 243 | "importance": "low", 244 | "name": "enableSolutionsButton", 245 | "type": "boolean", 246 | "default": true 247 | }, 248 | { 249 | "label": "Automatically check answers after input", 250 | "importance": "low", 251 | "name": "autoCheck", 252 | "type": "boolean", 253 | "default": false 254 | }, 255 | { 256 | "name": "caseSensitive", 257 | "importance": "low", 258 | "type": "boolean", 259 | "default": true, 260 | "label": "Case sensitive", 261 | "description": "Makes sure the user input has to be exactly the same as the answer." 262 | }, 263 | { 264 | "label": "Require all fields to be answered before the solution can be viewed", 265 | "description": "This option is only valid if the answer mode is set to \"Fill in\".", 266 | "importance": "low", 267 | "name": "showSolutionsRequiresInput", 268 | "type": "boolean", 269 | "default": true 270 | }, 271 | { 272 | "name": "acceptSpellingErrors", 273 | "type": "boolean", 274 | "label": "Accept minor spelling errors", 275 | "importance": "low", 276 | "description": "If activated, an answer will also count as correct with minor spelling errors (3-9 characters: 1 spelling error, more than 9 characters: 2 spelling errors). This option is only valid if the answer mode is set to \"Fill in\".", 277 | "default": false 278 | }, 279 | { 280 | "label": "Randomize", 281 | "name": "randomize", 282 | "type": "boolean", 283 | "default": true 284 | }, 285 | { 286 | "label": "Show tips", 287 | "name": "showTips", 288 | "type": "boolean", 289 | "default": false 290 | }, 291 | { 292 | "label": "Answer mode", 293 | "name": "answerMode", 294 | "type": "select", 295 | "widget": "radioGroup", 296 | "alignment": "horizontal", 297 | "options": [ 298 | { "label": "Fill in", "value": "fillIn" }, 299 | { "label": "Drag text", "value": "dragText" } 300 | ], 301 | "default": "fillIn" 302 | }, 303 | { 304 | "name": "enableSwitchAnswerModeButton", 305 | "type": "boolean", 306 | "label": "Enable \"Switch answer mode\" button", 307 | "importance": "low", 308 | "description": "Allow the end user to switch between modes \"Fill in\" and \"Drag text\".", 309 | "default": false 310 | }, 311 | { 312 | "name": "enableSwitchWordsButton", 313 | "type": "boolean", 314 | "label": "Enable \"Switch language mode\" button", 315 | "importance": "low", 316 | "description": "Allow the end user to switch between source and target words.", 317 | "default": false 318 | }, 319 | { 320 | "label": "Number of words", 321 | "name": "numberOfWordsToShow", 322 | "description": "Defines how many words will be visible each time. If 0 is set, all words will be shown.", 323 | "type": "number", 324 | "optional": true 325 | } 326 | ] 327 | } 328 | ] 329 | 330 | export default json; -------------------------------------------------------------------------------- /example/vite/src/main.ts: -------------------------------------------------------------------------------- 1 | import './style.css' 2 | import person from './person.schema.json' 3 | import large from './10004_bytes.json' 4 | 5 | console.log(person.properties.age.type) 6 | console.log(large[0].type) 7 | 8 | const app = document && document.querySelector('#app') 9 | 10 | if(app) { 11 | app.innerHTML = ` 12 |

Hello Vite!

13 | Documentation 14 | ` 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /example/vite/src/person.schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "https://example.com/person.schema.json", 3 | "$schema": "https://json-schema.org/draft-07/schema", 4 | "title": "Person", 5 | "type": "object", 6 | "not-easy-key": {}, 7 | "properties": { 8 | "firstName": { 9 | "type": "string", 10 | "description": "The person's first name." 11 | }, 12 | "lastName": { 13 | "type": "string", 14 | "description": "The person's last name." 15 | }, 16 | "age": { 17 | "description": "Age in years which must be equal to or greater than zero.", 18 | "type": "integer", 19 | "minimum": 0 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /example/vite/src/person.schema.json.d.ts: -------------------------------------------------------------------------------- 1 | export const $id : "https://example.com/person.schema.json"; 2 | export const $schema : "https://json-schema.org/draft-07/schema"; 3 | export const title : "Person"; 4 | export const type : "object"; 5 | export const properties : {"firstName":{"type":"string","description":"The person's first name."},"lastName":{"type":"string","description":"The person's last name."},"age":{"description":"Age in years which must be equal to or greater than zero.","type":"integer","minimum":0}}; 6 | declare const $defaultExport: { 7 | $id: typeof $id, 8 | $schema: typeof $schema, 9 | title: typeof title, 10 | type: typeof type, 11 | "not-easy-key": {}, 12 | properties: typeof properties, 13 | }; 14 | 15 | export default $defaultExport; -------------------------------------------------------------------------------- /example/vite/src/style.css: -------------------------------------------------------------------------------- 1 | #app { 2 | font-family: Avenir, Helvetica, Arial, sans-serif; 3 | -webkit-font-smoothing: antialiased; 4 | -moz-osx-font-smoothing: grayscale; 5 | text-align: center; 6 | color: #2c3e50; 7 | margin-top: 60px; 8 | } 9 | -------------------------------------------------------------------------------- /example/vite/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /example/vite/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "module": "ESNext", 6 | "lib": ["ESNext", "DOM"], 7 | "moduleResolution": "Node", 8 | "strict": true, 9 | "sourceMap": true, 10 | "resolveJsonModule": true, 11 | "esModuleInterop": true, 12 | "noEmit": true, 13 | "noUnusedLocals": true, 14 | "noUnusedParameters": true, 15 | "noImplicitReturns": true 16 | }, 17 | "include": ["./src"] 18 | } 19 | -------------------------------------------------------------------------------- /example/vite/vite.config.ts: -------------------------------------------------------------------------------- 1 | import {defineConfig} from 'vite' 2 | import jsonDts from 'unplugin-json-dts/vite' 3 | 4 | export default defineConfig({ 5 | plugins: [jsonDts()] 6 | }) -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | export { default } from './dist/index' 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "unplugin-json-dts", 3 | "type": "module", 4 | "version": "1.3.2", 5 | "description": "Automatically generate better typings for json files. Supports json modules", 6 | "author": "Felix Cornelissen", 7 | "license": "MIT", 8 | "homepage": "https://github.com/flixcor/unplugin-json-dts#readme", 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/flixcor/unplugin-json-dts.git" 12 | }, 13 | "bugs": { 14 | "url": "https://github.com/flixcor/unplugin-json-dts/issues" 15 | }, 16 | "keywords": [ 17 | "json", 18 | "vite", 19 | "unplugin", 20 | "plugin", 21 | "typescript", 22 | "rollup", 23 | "webpack" 24 | ], 25 | "exports": { 26 | ".": { 27 | "import": "./dist/index.js", 28 | "require": "./dist/index.cjs" 29 | }, 30 | "./*": "./*", 31 | "./rollup": { 32 | "import": "./dist/rollup.js", 33 | "require": "./dist/rollup.cjs" 34 | }, 35 | "./vite": { 36 | "import": "./dist/vite.js", 37 | "require": "./dist/vite.cjs" 38 | }, 39 | "./webpack": { 40 | "import": "./dist/webpack.js", 41 | "require": "./dist/webpack.cjs" 42 | } 43 | }, 44 | "main": "dist/index.cjs", 45 | "module": "dist/index.js", 46 | "types": "dist/index.d.ts", 47 | "typesVersions": { 48 | "*": { 49 | "*": [ 50 | "./dist/*", 51 | "./*" 52 | ] 53 | } 54 | }, 55 | "files": [ 56 | "dist" 57 | ], 58 | "engines": { 59 | "node": ">=22.14" 60 | }, 61 | "scripts": { 62 | "build": "tsup", 63 | "lint": "eslint . --ext .js,.jsx,.ts,.tsx", 64 | "lint:fix": "eslint . --fix --ext .js,.jsx,.ts,.tsx" 65 | }, 66 | "peerDependencies": { 67 | "rollup": "^3", 68 | "vite": ">=5", 69 | "webpack": "^4 || ^5" 70 | }, 71 | "peerDependenciesMeta": { 72 | "rollup": { 73 | "optional": true 74 | }, 75 | "vite": { 76 | "optional": true 77 | }, 78 | "webpack": { 79 | "optional": true 80 | } 81 | }, 82 | "dependencies": { 83 | "unplugin": "^2.3.2" 84 | }, 85 | "devDependencies": { 86 | "@antfu/eslint-config": "^4.12.0", 87 | "@types/node": "^22.14.1", 88 | "eslint": "^9.25.0", 89 | "eslint-plugin-format": "^1.0.1", 90 | "fast-glob": "^3.3.3", 91 | "path": "^0.12.7", 92 | "tsup": "^8.4.0", 93 | "typescript": "^5.8.3" 94 | }, 95 | "pnpm": { 96 | "onlyBuiltDependencies": [ 97 | "esbuild", 98 | "unrs-resolver" 99 | ] 100 | }, 101 | "overrides": { 102 | "esbuild@<0.25.2": "^0.25.2" 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import type { UnpluginFactory } from 'unplugin' 2 | import { existsSync, promises as fs } from 'node:fs' 3 | import { createUnplugin } from 'unplugin' 4 | 5 | const fileRegex = /\.json$/ 6 | const encoding = 'utf-8' 7 | 8 | async function getExisting(fileName: string) { 9 | return existsSync(fileName) 10 | ? await fs.readFile(fileName, encoding) 11 | : '' 12 | } 13 | 14 | function replaceJsonRegularString(code: string) { 15 | return `declare const json: ${code} 16 | export default json;` 17 | } 18 | 19 | function replaceJsonModuleString(code: string) { 20 | const [beforeExport, afterExport] = code.split('export default', 2) 21 | const beforeExportReplaced = beforeExport.replace(/=/g, ':') 22 | const afterExportReplaced = beforeExport 23 | ? afterExport.replace(/^( +)([A-Z|$]+),$/gim, '$1$2: $2,').replace(/:( *[A-Z|$]+)/gi, ': typeof$1') 24 | : afterExport 25 | return `${[ 26 | beforeExportReplaced, 27 | afterExportReplaced, 28 | ].join('declare const $defaultExport:')} 29 | export default $defaultExport;` 30 | } 31 | 32 | async function replaceJsonString(code: string, id: string) { 33 | return !code?.includes('JSON.parse') 34 | && code?.startsWith('export') 35 | ? replaceJsonModuleString(code) 36 | : code?.startsWith('{') 37 | ? replaceJsonRegularString(code) 38 | : replaceJsonRegularString(await fs.readFile(id, encoding)) 39 | } 40 | 41 | export const unpluginFactory: UnpluginFactory = () => ({ 42 | name: 'unplugin-json-dts', 43 | transformInclude(id) { 44 | return fileRegex.test(id) 45 | }, 46 | async transform(code, id) { 47 | const fileName = `${id}.d.ts` 48 | const [existingTyping, newTyping] = await Promise.all([ 49 | getExisting(fileName), 50 | replaceJsonString(code, id), 51 | ]) 52 | if (newTyping !== existingTyping) { 53 | await fs.writeFile(fileName, newTyping, encoding) 54 | } 55 | return { code } 56 | }, 57 | }) 58 | 59 | export const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory) 60 | 61 | export default unplugin 62 | -------------------------------------------------------------------------------- /src/rollup.ts: -------------------------------------------------------------------------------- 1 | import { createRollupPlugin } from 'unplugin' 2 | import { unpluginFactory } from '.' 3 | 4 | export default createRollupPlugin(unpluginFactory) 5 | -------------------------------------------------------------------------------- /src/vite.ts: -------------------------------------------------------------------------------- 1 | import { createVitePlugin } from 'unplugin' 2 | import { unpluginFactory } from '.' 3 | 4 | export default createVitePlugin(unpluginFactory) 5 | -------------------------------------------------------------------------------- /src/webpack.ts: -------------------------------------------------------------------------------- 1 | import { createWebpackPlugin } from 'unplugin' 2 | import { unpluginFactory } from '.' 3 | 4 | export default createWebpackPlugin(unpluginFactory) 5 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2019", 4 | "lib": ["esnext", "DOM"], 5 | "module": "esnext", 6 | "moduleResolution": "node", 7 | "resolveJsonModule": true, 8 | "strict": true, 9 | "strictNullChecks": true, 10 | "esModuleInterop": true, 11 | "skipLibCheck": true 12 | }, 13 | "exclude": [ 14 | "**/dist", 15 | "**/node_modules", 16 | "**/scripts", 17 | "example/*", 18 | "eslint.config.js" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /tsup.config.ts: -------------------------------------------------------------------------------- 1 | import type { Options } from 'tsup' 2 | 3 | export const tsup: Options = { 4 | entry: [ 5 | 'src/*.ts', 6 | ], 7 | format: ['cjs', 'esm'], 8 | dts: true, 9 | cjsInterop: true, 10 | splitting: true, 11 | clean: true, 12 | } 13 | --------------------------------------------------------------------------------