From e91adf1abe8964dbd92a48df28fa3aa5782226c6 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Sat, 4 Jan 2025 02:13:59 +0900 Subject: [PATCH 01/21] chore: swtich to rolldown bundling --- package.json | 4 + pnpm-lock.yaml | 308 +++++++++++++++++++++++++++++++ scripts/build-rolldown.ts | 335 ++++++++++++++++++++++++++++++++++ scripts/rolldown.ts | 372 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 1019 insertions(+) create mode 100644 scripts/build-rolldown.ts create mode 100644 scripts/rolldown.ts diff --git a/package.json b/package.json index 870447fca..ff3484843 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "preview:size-vue-i18n": "pnpm --filter @intlify/size-check-vue-i18n preview", "release": "bumpp package.json packages/**/package.json --commit \"release: v\" --push --tag", "size": "tsx ./scripts/build.ts --size && tsx ./scripts/size.ts", + "size:rolldown": "tsx ./scripts/build-rolldown.ts", "size:report": "tsx ./scripts/report-size.ts", "test": "run-s lint test:cover check-install test:e2e", "test:cover": "pnpm test:unit --coverage", @@ -85,12 +86,14 @@ "@intlify/core-base": "workspace:*", "@intlify/message-compiler": "workspace:*", "@microsoft/api-extractor": "7.15.2", + "@rolldown/plugin-node-polyfills": "^1.0.0", "@rollup/plugin-commonjs": "^25.0.0", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.0.2", "@rollup/plugin-replace": "^5.0.2", "@rollup/plugin-terser": "^0.4.3", "@secretlint/secretlint-rule-preset-recommend": "^3.1.0", + "@swc/core": "^1.10.4", "@textlint-rule/textlint-rule-no-unmatched-pair": "^2.0.0", "@types/eslint": "^9.6.1", "@types/js-yaml": "^4.0.5", @@ -124,6 +127,7 @@ "playwright-core": "^1.45.3", "prettier": "^3.3.3", "rc": "^1.2.8", + "rolldown": "1.0.0-beta.1", "rollup": "^4.21.2", "rollup-plugin-node-builtins": "^2.1.2", "rollup-plugin-node-globals": "^1.4.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bd07c7e11..0a7cca4cc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -24,6 +24,9 @@ importers: '@microsoft/api-extractor': specifier: 7.15.2 version: 7.15.2 + '@rolldown/plugin-node-polyfills': + specifier: ^1.0.0 + version: 1.0.0 '@rollup/plugin-commonjs': specifier: ^25.0.0 version: 25.0.7(rollup@4.22.4) @@ -42,6 +45,9 @@ importers: '@secretlint/secretlint-rule-preset-recommend': specifier: ^3.1.0 version: 3.3.0 + '@swc/core': + specifier: ^1.10.4 + version: 1.10.4 '@textlint-rule/textlint-rule-no-unmatched-pair': specifier: ^2.0.0 version: 2.0.2 @@ -141,6 +147,9 @@ importers: rc: specifier: ^1.2.8 version: 1.2.8 + rolldown: + specifier: 1.0.0-beta.1 + version: 1.0.0-beta.1 rollup: specifier: ^4.21.2 version: 4.22.4 @@ -945,6 +954,15 @@ packages: search-insights: optional: true + '@emnapi/core@1.3.1': + resolution: {integrity: sha512-pVGjBIt1Y6gg3EJN8jTcfpP/+uuRksIo055oE/OBkDNcjZqVbfkWCksG1Jp4yZnj3iKWyWX8fdG/j6UDYPbFog==} + + '@emnapi/runtime@1.3.1': + resolution: {integrity: sha512-kEBmG8KyqtxJZv+ygbEim+KCGtIq1fC22Ms3S4ziXmYKm8uyoLX0MHONVKwp+9opg390VaKRNt4a7A9NwmpNhw==} + + '@emnapi/wasi-threads@1.0.1': + resolution: {integrity: sha512-iIBu7mwkq4UQGeMEM8bLwNK962nXdhodeScX4slfQnRhEMMzvYivHhutCIk8uojvmASXXPC2WNEjwxFWk72Oqw==} + '@esbuild/aix-ppc64@0.20.2': resolution: {integrity: sha512-D+EBOJHXdNZcLJRBkhENNG8Wji2kgc9AZ9KiPr1JuZjsNtyHzrsfLRrY0tk2H2aoFu6RANO1y1iPPUCDYWkb5g==} engines: {node: '>=12'} @@ -1456,6 +1474,9 @@ packages: '@microsoft/tsdoc@0.14.2': resolution: {integrity: sha512-9b8mPpKrfeGRuhFH5iO1iwCLeIIsV6+H1sRfxbkoGXIyQE2BTsPd9zqSqQJ+pv5sJ/hT5M1zvOFL02MnEezFug==} + '@napi-rs/wasm-runtime@0.2.6': + resolution: {integrity: sha512-z8YVS3XszxFTO73iwvFDNpQIzdMmSDTP/mB3E/ucR37V3Sx57hSExcXyMoNwaucWxnsWf4xfbZv0iZ30jr0M4Q==} + '@nodelib/fs.scandir@2.1.5': resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} @@ -1610,6 +1631,69 @@ packages: resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} engines: {node: '>=14'} + '@rolldown/binding-darwin-arm64@1.0.0-beta.1': + resolution: {integrity: sha512-e4QpTp7eu61JilK958i21RK/HniwVLjZgfShqoQY1VM+KDYz90cNuopKQ3Z3oCkvyAN3xI8IaRhy02nlxdR/DA==} + cpu: [arm64] + os: [darwin] + + '@rolldown/binding-darwin-x64@1.0.0-beta.1': + resolution: {integrity: sha512-+WHRLrogJl99EQ6HtYhy7EwIZ1wicD0RSX2T5mjfOM6AmPwPTXQ0n6MKOs1abU6ZyCj5Izlo6rLsao0h9FMUDA==} + cpu: [x64] + os: [darwin] + + '@rolldown/binding-freebsd-x64@1.0.0-beta.1': + resolution: {integrity: sha512-ZP9Q1q4IfvJ8dfWTHOF3cquNpAKuQQ+kZJQTxo85fGnKqtqMWFNouaBVd79pqCxU3w4oIjuZ8o55qNDomMTbVA==} + cpu: [x64] + os: [freebsd] + + '@rolldown/binding-linux-arm-gnueabihf@1.0.0-beta.1': + resolution: {integrity: sha512-B/R4Vt8f8z/WmW9Y9NMgA+t5bCfRLmgZohs5mWf8KoD5FRlpvJtCo/SnD7fEg9npHEP5A28+Cikiyd7aCcKPSA==} + cpu: [arm] + os: [linux] + + '@rolldown/binding-linux-arm64-gnu@1.0.0-beta.1': + resolution: {integrity: sha512-xkGD+YLH+vQZiqxKEsXe8xS/owQXkyARaNB9NfFrAacLoNIRZM5UEZGNKxXyRWd1kSEkYkJ3/WiqvGGCcqUg1A==} + cpu: [arm64] + os: [linux] + + '@rolldown/binding-linux-arm64-musl@1.0.0-beta.1': + resolution: {integrity: sha512-Ey2UxKFL74JuWpdNl9stpV0kxHZIgCWCEUnDnpQ1hcBwO9KwDM5qicLtXfsjozD6vt+xzbrL2D/uTrziYZ7IDQ==} + cpu: [arm64] + os: [linux] + + '@rolldown/binding-linux-x64-gnu@1.0.0-beta.1': + resolution: {integrity: sha512-a8QP35x/3mggWqCpFtaF3/PbWl5P9QKpP/muk3iMPgzrXto8zPsEl3imsP3EBh4KwanBVHIf8pEkBQ+/7iMTgQ==} + cpu: [x64] + os: [linux] + + '@rolldown/binding-linux-x64-musl@1.0.0-beta.1': + resolution: {integrity: sha512-uIqKwnkZjTY8FmqGMaSjwtWlCdV88LV9bjdkv+mb7I+BBw+9cJlIQy0P8YnGEOEcnDPis/SiraCpkJ/eHYaSZw==} + cpu: [x64] + os: [linux] + + '@rolldown/binding-wasm32-wasi@1.0.0-beta.1': + resolution: {integrity: sha512-RB+gbhwZtTbKbvHzUcaRFva2ONCUTuxDEb/b3/rd3O82OTPUZzOY24mqreiXH1XG09p6WFXSE8dzUrN120Q29w==} + engines: {node: '>=14.21.3'} + cpu: [wasm32] + + '@rolldown/binding-win32-arm64-msvc@1.0.0-beta.1': + resolution: {integrity: sha512-NSccQD7+9vhEfDMc8HyODuUU1jLYEsEiICc1zwmbeg0FXx1pwpFpZZQby4bAMnK2obav7D9FfsruYWodhNdIqQ==} + cpu: [arm64] + os: [win32] + + '@rolldown/binding-win32-ia32-msvc@1.0.0-beta.1': + resolution: {integrity: sha512-bUQOqqHfqgX9gHGZFGVYQRtc4+9diFDS/f85dKrzzUg7MF91ZU9mJUoemL4eyyj3B83N3FlHZtAPvDX3N2Zz8A==} + cpu: [ia32] + os: [win32] + + '@rolldown/binding-win32-x64-msvc@1.0.0-beta.1': + resolution: {integrity: sha512-k8Ld05OlxkzR/+Ob8+IESaZ4uFcgLwbbwtUZLoryn3S6lCogkclcN/4m1wo/PyWtUAWF5mdz83SrkRL8dS4AqA==} + cpu: [x64] + os: [win32] + + '@rolldown/plugin-node-polyfills@1.0.0': + resolution: {integrity: sha512-JUmEhvz+B6+0AaeUGvZ7SnJec7wpwYqZ+FcAng1I3UVGYKA1uSmE1H4vKHUewU665Nb37znDd9N4o/iImmKeVg==} + '@rollup/plugin-commonjs@25.0.7': resolution: {integrity: sha512-nEvcR+LRjEjsaSsc4x3XZfCCvZIaSMenZu/OiwOKGN2UhQpAYI7ru7czFvyWbErlpoGjnSX3D5Ch5FcMA3kRWQ==} engines: {node: '>=14.0.0'} @@ -1944,6 +2028,81 @@ packages: resolution: {integrity: sha512-X1Iui3FUNZP18EUvysTHxt+Avu2nlVzyf90YM8OYgP6SGzTzzX/0JgObfO1AQQDzuZtNNz29bVh8h5R97JrjxA==} engines: {node: '>=8'} + '@swc/core-darwin-arm64@1.10.4': + resolution: {integrity: sha512-sV/eurLhkjn/197y48bxKP19oqcLydSel42Qsy2zepBltqUx+/zZ8+/IS0Bi7kaWVFxerbW1IPB09uq8Zuvm3g==} + engines: {node: '>=10'} + cpu: [arm64] + os: [darwin] + + '@swc/core-darwin-x64@1.10.4': + resolution: {integrity: sha512-gjYNU6vrAUO4+FuovEo9ofnVosTFXkF0VDuo1MKPItz6e2pxc2ale4FGzLw0Nf7JB1sX4a8h06CN16/pLJ8Q2w==} + engines: {node: '>=10'} + cpu: [x64] + os: [darwin] + + '@swc/core-linux-arm-gnueabihf@1.10.4': + resolution: {integrity: sha512-zd7fXH5w8s+Sfvn2oO464KDWl+ZX1MJiVmE4Pdk46N3PEaNwE0koTfgx2vQRqRG4vBBobzVvzICC3618WcefOA==} + engines: {node: '>=10'} + cpu: [arm] + os: [linux] + + '@swc/core-linux-arm64-gnu@1.10.4': + resolution: {integrity: sha512-+UGfoHDxsMZgFD3tABKLeEZHqLNOkxStu+qCG7atGBhS4Slri6h6zijVvf4yI5X3kbXdvc44XV/hrP/Klnui2A==} + engines: {node: '>=10'} + cpu: [arm64] + os: [linux] + + '@swc/core-linux-arm64-musl@1.10.4': + resolution: {integrity: sha512-cDDj2/uYsOH0pgAnDkovLZvKJpFmBMyXkxEG6Q4yw99HbzO6QzZ5HDGWGWVq/6dLgYKlnnmpjZCPPQIu01mXEg==} + engines: {node: '>=10'} + cpu: [arm64] + os: [linux] + + '@swc/core-linux-x64-gnu@1.10.4': + resolution: {integrity: sha512-qJXh9D6Kf5xSdGWPINpLGixAbB5JX8JcbEJpRamhlDBoOcQC79dYfOMEIxWPhTS1DGLyFakAx2FX/b2VmQmj0g==} + engines: {node: '>=10'} + cpu: [x64] + os: [linux] + + '@swc/core-linux-x64-musl@1.10.4': + resolution: {integrity: sha512-A76lIAeyQnHCVt0RL/pG+0er8Qk9+acGJqSZOZm67Ve3B0oqMd871kPtaHBM0BW3OZAhoILgfHW3Op9Q3mx3Cw==} + engines: {node: '>=10'} + cpu: [x64] + os: [linux] + + '@swc/core-win32-arm64-msvc@1.10.4': + resolution: {integrity: sha512-e6j5kBu4fIY7fFxFxnZI0MlEovRvp50Lg59Fw+DVbtqHk3C85dckcy5xKP+UoXeuEmFceauQDczUcGs19SRGSQ==} + engines: {node: '>=10'} + cpu: [arm64] + os: [win32] + + '@swc/core-win32-ia32-msvc@1.10.4': + resolution: {integrity: sha512-RSYHfdKgNXV/amY5Tqk1EWVsyQnhlsM//jeqMLw5Fy9rfxP592W9UTumNikNRPdjI8wKKzNMXDb1U29tQjN0dg==} + engines: {node: '>=10'} + cpu: [ia32] + os: [win32] + + '@swc/core-win32-x64-msvc@1.10.4': + resolution: {integrity: sha512-1ujYpaqfqNPYdwKBlvJnOqcl+Syn3UrQ4XE0Txz6zMYgyh6cdU6a3pxqLqIUSJ12MtXRA9ZUhEz1ekU3LfLWXw==} + engines: {node: '>=10'} + cpu: [x64] + os: [win32] + + '@swc/core@1.10.4': + resolution: {integrity: sha512-ut3zfiTLORMxhr6y/GBxkHmzcGuVpwJYX4qyXWuBKkpw/0g0S5iO1/wW7RnLnZbAi8wS/n0atRZoaZlXWBkeJg==} + engines: {node: '>=10'} + peerDependencies: + '@swc/helpers': '*' + peerDependenciesMeta: + '@swc/helpers': + optional: true + + '@swc/counter@0.1.3': + resolution: {integrity: sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==} + + '@swc/types@0.1.17': + resolution: {integrity: sha512-V5gRru+aD8YVyCOMAjMpWR1Ui577DD5KSJsHP8RAxopAH22jFz6GZd/qxqjO6MJHQhcsjvjOFXyDhyLQUnMveQ==} + '@textlint-rule/textlint-rule-no-unmatched-pair@2.0.2': resolution: {integrity: sha512-oE7vVmjCsKcbLy2/igBh0qvDmfbcAgjFfOCbhaOxxgXqD9hDKbnG+vxIPmRl27u2PwijZCQI+5r7FyiVVS/kyw==} @@ -2014,6 +2173,9 @@ packages: '@textlint/utils@12.6.1': resolution: {integrity: sha512-HJkqYXT2FAAHDM5XLFpQLF/CEdm8c2ltMeKmPBSSty1VfPXQMi8tGPT1b58b8KWh6dVmi7w0YYB7NrquuzXOKA==} + '@tybys/wasm-util@0.9.0': + resolution: {integrity: sha512-6+7nlbMVX/PVDCwaIQ8nTOPveOcFLSt8GcXdx8hD0bt39uWxYT88uXzqTd4fTvqta7oeUJqudepapKNt2DYJFw==} + '@types/argparse@1.0.38': resolution: {integrity: sha512-ebDJ9b0e702Yr7pWgB0jzm+CX4Srzz8RcXtLJDJB+BSccqMa36uyH/zUsSYao5+BD1ytv3k3rPYCq4mAE1hsXA==} @@ -6173,6 +6335,15 @@ packages: ripemd160@2.0.2: resolution: {integrity: sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==} + rolldown@1.0.0-beta.1: + resolution: {integrity: sha512-19B2HoY3zcR7Um+zVDOvV1gQ1d6acUIouCUMGxvlZ/0kTjcMSFr8tuLWmRRYIV7y1mrgPbJRd1cPFVd4p1l8nQ==} + hasBin: true + peerDependencies: + '@babel/runtime': '>=7' + peerDependenciesMeta: + '@babel/runtime': + optional: true + rollup-plugin-node-builtins@2.1.2: resolution: {integrity: sha512-bxdnJw8jIivr2yEyt8IZSGqZkygIJOGAWypXvHXnwKAbUcN4Q/dGTx7K0oAJryC/m6aq6tKutltSeXtuogU6sw==} @@ -8032,6 +8203,22 @@ snapshots: transitivePeerDependencies: - '@algolia/client-search' + '@emnapi/core@1.3.1': + dependencies: + '@emnapi/wasi-threads': 1.0.1 + tslib: 2.6.2 + optional: true + + '@emnapi/runtime@1.3.1': + dependencies: + tslib: 2.6.2 + optional: true + + '@emnapi/wasi-threads@1.0.1': + dependencies: + tslib: 2.6.2 + optional: true + '@esbuild/aix-ppc64@0.20.2': optional: true @@ -8462,6 +8649,13 @@ snapshots: '@microsoft/tsdoc@0.14.2': {} + '@napi-rs/wasm-runtime@0.2.6': + dependencies: + '@emnapi/core': 1.3.1 + '@emnapi/runtime': 1.3.1 + '@tybys/wasm-util': 0.9.0 + optional: true + '@nodelib/fs.scandir@2.1.5': dependencies: '@nodelib/fs.stat': 2.0.5 @@ -8610,6 +8804,46 @@ snapshots: '@pkgjs/parseargs@0.11.0': optional: true + '@rolldown/binding-darwin-arm64@1.0.0-beta.1': + optional: true + + '@rolldown/binding-darwin-x64@1.0.0-beta.1': + optional: true + + '@rolldown/binding-freebsd-x64@1.0.0-beta.1': + optional: true + + '@rolldown/binding-linux-arm-gnueabihf@1.0.0-beta.1': + optional: true + + '@rolldown/binding-linux-arm64-gnu@1.0.0-beta.1': + optional: true + + '@rolldown/binding-linux-arm64-musl@1.0.0-beta.1': + optional: true + + '@rolldown/binding-linux-x64-gnu@1.0.0-beta.1': + optional: true + + '@rolldown/binding-linux-x64-musl@1.0.0-beta.1': + optional: true + + '@rolldown/binding-wasm32-wasi@1.0.0-beta.1': + dependencies: + '@napi-rs/wasm-runtime': 0.2.6 + optional: true + + '@rolldown/binding-win32-arm64-msvc@1.0.0-beta.1': + optional: true + + '@rolldown/binding-win32-ia32-msvc@1.0.0-beta.1': + optional: true + + '@rolldown/binding-win32-x64-msvc@1.0.0-beta.1': + optional: true + + '@rolldown/plugin-node-polyfills@1.0.0': {} + '@rollup/plugin-commonjs@25.0.7(rollup@4.22.4)': dependencies: '@rollup/pluginutils': 5.1.0(rollup@4.22.4) @@ -8971,6 +9205,58 @@ snapshots: '@stroncium/procfs@1.2.1': {} + '@swc/core-darwin-arm64@1.10.4': + optional: true + + '@swc/core-darwin-x64@1.10.4': + optional: true + + '@swc/core-linux-arm-gnueabihf@1.10.4': + optional: true + + '@swc/core-linux-arm64-gnu@1.10.4': + optional: true + + '@swc/core-linux-arm64-musl@1.10.4': + optional: true + + '@swc/core-linux-x64-gnu@1.10.4': + optional: true + + '@swc/core-linux-x64-musl@1.10.4': + optional: true + + '@swc/core-win32-arm64-msvc@1.10.4': + optional: true + + '@swc/core-win32-ia32-msvc@1.10.4': + optional: true + + '@swc/core-win32-x64-msvc@1.10.4': + optional: true + + '@swc/core@1.10.4': + dependencies: + '@swc/counter': 0.1.3 + '@swc/types': 0.1.17 + optionalDependencies: + '@swc/core-darwin-arm64': 1.10.4 + '@swc/core-darwin-x64': 1.10.4 + '@swc/core-linux-arm-gnueabihf': 1.10.4 + '@swc/core-linux-arm64-gnu': 1.10.4 + '@swc/core-linux-arm64-musl': 1.10.4 + '@swc/core-linux-x64-gnu': 1.10.4 + '@swc/core-linux-x64-musl': 1.10.4 + '@swc/core-win32-arm64-msvc': 1.10.4 + '@swc/core-win32-ia32-msvc': 1.10.4 + '@swc/core-win32-x64-msvc': 1.10.4 + + '@swc/counter@0.1.3': {} + + '@swc/types@0.1.17': + dependencies: + '@swc/counter': 0.1.3 + '@textlint-rule/textlint-rule-no-unmatched-pair@2.0.2': dependencies: sentence-splitter: 5.0.0 @@ -9138,6 +9424,11 @@ snapshots: '@textlint/utils@12.6.1': {} + '@tybys/wasm-util@0.9.0': + dependencies: + tslib: 2.6.2 + optional: true + '@types/argparse@1.0.38': {} '@types/body-parser@1.19.5': @@ -14002,6 +14293,23 @@ snapshots: hash-base: 3.1.0 inherits: 2.0.4 + rolldown@1.0.0-beta.1: + dependencies: + zod: 3.23.8 + optionalDependencies: + '@rolldown/binding-darwin-arm64': 1.0.0-beta.1 + '@rolldown/binding-darwin-x64': 1.0.0-beta.1 + '@rolldown/binding-freebsd-x64': 1.0.0-beta.1 + '@rolldown/binding-linux-arm-gnueabihf': 1.0.0-beta.1 + '@rolldown/binding-linux-arm64-gnu': 1.0.0-beta.1 + '@rolldown/binding-linux-arm64-musl': 1.0.0-beta.1 + '@rolldown/binding-linux-x64-gnu': 1.0.0-beta.1 + '@rolldown/binding-linux-x64-musl': 1.0.0-beta.1 + '@rolldown/binding-wasm32-wasi': 1.0.0-beta.1 + '@rolldown/binding-win32-arm64-msvc': 1.0.0-beta.1 + '@rolldown/binding-win32-ia32-msvc': 1.0.0-beta.1 + '@rolldown/binding-win32-x64-msvc': 1.0.0-beta.1 + rollup-plugin-node-builtins@2.1.2: dependencies: browserify-fs: 1.0.0 diff --git a/scripts/build-rolldown.ts b/scripts/build-rolldown.ts new file mode 100644 index 000000000..c2ac07601 --- /dev/null +++ b/scripts/build-rolldown.ts @@ -0,0 +1,335 @@ +/* +Produces production builds and stitches together d.ts files. + +To specify the package to build, simply pass its name and the desired build +formats to output (defaults to `buildOptions.formats` specified in that package, +or "esm,cjs"): + +``` +# name supports fuzzy match. will build all packages with name containing "core-base": +pnpm build core-base + +# specify the format to output +pnpm build core --formats cjs +``` +*/ + +import { spawnSync } from 'node:child_process' +import { existsSync, promises as fs } from 'node:fs' +import path from 'node:path' +import { fileURLToPath } from 'node:url' +import { parseArgs } from 'node:util' +import { brotliCompressSync, gzipSync } from 'node:zlib' +import pc from 'picocolors' +import { rolldown } from 'rolldown' +import { createConfigsForPackage } from './rolldown' +import { + targets as allTargets, + checkSizeDistFiles, + displaySize, + fuzzyMatchTarget, + readJson +} from './utils' + +import type { OutputOptions } from 'rolldown' + +const __dirname = fileURLToPath(new URL('.', import.meta.url)) +const commit = spawnSync('git', ['rev-parse', '--short=7', 'HEAD']) + .stdout.toString() + .trim() + +const { values, positionals: targets } = parseArgs({ + allowPositionals: true, + options: { + formats: { + type: 'string', + short: 'f' + }, + devOnly: { + type: 'boolean', + short: 'd' + }, + prodOnly: { + type: 'boolean', + short: 'p' + }, + withTypes: { + type: 'boolean', + short: 't' + }, + sourceMap: { + type: 'boolean', + short: 's' + }, + release: { + type: 'boolean' + }, + all: { + type: 'boolean', + short: 'a' + }, + size: { + type: 'boolean' + } + } +}) + +const { + formats: rawFormats, + all: buildAllMatching, + devOnly, + prodOnly, + withTypes: buildTypes, + sourceMap, + release: isRelease, + size +} = values + +const formats = rawFormats?.split(',') +const sizeDir = path.resolve(__dirname, '../temp/size') + +async function main() { + await run() + + async function run() { + if (size) { + await fs.mkdir(sizeDir, { recursive: true }) + } + + // const rtsCachePath = path.resolve(__dirname, './node_modules/.rts2_cache') + // if (isRelease && existsSync(rtsCachePath)) { + // // remove build cache for release builds to avoid outdated enum values + // await fs.rm(rtsCachePath, { recursive: true }) + // } + + const resolvedTargets = targets.length + ? await fuzzyMatchTarget(targets, buildAllMatching) + : await allTargets() + await buildAll(resolvedTargets) + + if (size) { + await checkAllSizes(resolvedTargets) + } + + if (buildTypes) { + // TODO: build types + } + } + + async function buildAll(targets: string[]) { + const start = performance.now() + const all = [] + let count = 0 + for (const target of targets) { + const configs = await createConfigsForTarget(target) + if (configs) { + all.push( + Promise.all( + configs.map(c => + rolldown(c).then(bundle => { + return bundle.write(c.output as OutputOptions).then(() => { + // @ts-expect-error + return path.join('packages', target, c.output.file) + }) + }) + ) + ).then(files => { + files.forEach(f => { + count++ + console.log(pc.gray('built: ') + pc.green(f)) + }) + }) + ) + } + } + await Promise.all(all) + // await runParallel(os.cpus().length, targets, build) + console.log( + `\n${count} files built in ${(performance.now() - start).toFixed(2)}ms.` + ) + } + + async function createConfigsForTarget(target: string) { + const pkgDir = path.resolve(__dirname, `../packages/${target}`) + const pkg = await readJson(`${pkgDir}/package.json`) + + // only build published packages for release + if (isRelease && pkg.private) { + return + } + + // if building a specific format, do not remove dist. + if (!formats && existsSync(`${pkgDir}/dist`)) { + await fs.rm(`${pkgDir}/dist`, { recursive: true }) + } + + return createConfigsForPackage({ + target, + commit, + formats, + prodOnly, + sourceMap + }) + // const env = + // (pkg.buildOptions && pkg.buildOptions.env) || + // (devOnly ? 'development' : 'production') + // await execa( + // 'rollup', + // [ + // '-c', + // '--environment', + // [ + // `COMMIT:${commit}`, + // `NODE_ENV:${env}`, + // `TARGET:${target}`, + // formats ? `FORMATS:${formats}` : ``, + // buildTypes ? `TYPES:true` : ``, + // prodOnly ? `PROD_ONLY:true` : ``, + // sourceMap ? `SOURCE_MAP:true` : `` + // ] + // .filter(Boolean) + // .join(',') + // ], + // { stdio: 'inherit' } + // ) + + /* + if (buildTypes && pkg.types) { + console.log() + console.log( + pc.bold(pc.yellow(`Rolling up type definitions for ${target}...`)) + ) + + // build types + const extractorConfigPath = path.resolve(pkgDir, `api-extractor.json`) + const extractorConfig = + ExtractorConfig.loadFileAndPrepare(extractorConfigPath) + const extractorResult = Extractor.invoke(extractorConfig, { + localBuild: true, + showVerboseMessages: true + }) + + if (extractorResult.succeeded) { + // concat additional d.ts to rolled-up dts + const typesDir = path.resolve(pkgDir, 'types') + if (existsSync(typesDir)) { + const dtsPath = path.resolve(pkgDir, pkg.types) + const existing = await fs.readFile(dtsPath, 'utf-8') + const typeFiles = await fs.readdir(typesDir) + const toAdd = await Promise.all( + typeFiles.map(file => + fs.readFile(path.resolve(typesDir, file), 'utf-8') + ) + ) + await fs.writeFile(dtsPath, existing + '\n' + toAdd.join('\n')) + } + console.log(pc.bold(pc.green(`API Extractor completed successfully.`))) + } else { + console.error( + `API Extractor completed with ${extractorResult.errorCount} errors` + + ` and ${extractorResult.warningCount} warnings` + ) + process.exitCode = 1 + } + + if (['vue-i18n', 'petite-vue-i18n'].includes(target)) { + console.log() + console.log( + pc.bold(pc.yellow(`Appending Vue type definitions for ${target}...`)) + ) + + let content = '' + + try { + content = await fs.readFile( + path.resolve(pkgDir, 'src/vue.d.ts'), + 'utf-8' + ) + } catch (e) { + console.error( + `Failed in opening Vue type definition file with error code: ${(e as NodeJS.ErrnoException).code}` + ) + process.exitCode = 1 + } + + try { + const marker = + '// --- THE CONTENT BELOW THIS LINE WILL BE APPENDED TO DTS FILE IN DIST DIRECTORY --- //' + const data = content.slice(content.indexOf(marker) + marker.length) + + await fs.appendFile(path.resolve(pkgDir, `dist/${target}.d.ts`), data) + } catch (e) { + console.error('Failed in appending Vue type definitions', e) + process.exitCode = 1 + } + + console.log( + pc.bold( + pc.green(`Appending Vue type definitions completed successfully.`) + ) + ) + } + + await fs.rm(`${pkgDir}/dist/packages`, { recursive: true }) + } + */ + } + + async function checkAllSizes(targets: string[]) { + if (devOnly) { + return + } + console.log() + for (const target of targets) { + await checkSize(target) + } + console.log() + } + + async function checkSize(target: string) { + const pkgDir = path.resolve(`packages/${target}`) + const files = await checkSizeDistFiles(pkgDir) + for (const file of files) { + await checkFileSize(`${pkgDir}/dist/${file}`) + } + } + + async function checkFileSize(filePath: string) { + if (!existsSync(filePath)) { + return + } + const file = await fs.readFile(filePath) + const filename = path.basename(filePath) + + const gzipped = gzipSync(file) + const brotli = brotliCompressSync(file) + console.log( + `📦 ${pc.green( + pc.bold(path.basename(filePath)) + )} - min: ${displaySize(file.length)} / gzip: ${displaySize(gzipped.length)} / brotli: ${displaySize(brotli.length)}` + ) + + if (size) { + const sizeContents = JSON.stringify( + { + file: filename, + size: file.length, + gzip: gzipped.length, + brotli: brotli.length + }, + null, + 2 + ) + await fs.writeFile( + path.resolve(sizeDir, `${filename}.json`), + sizeContents, + 'utf-8' + ) + } + } +} + +main().catch(err => { + console.error(err) + process.exit(1) +}) diff --git a/scripts/rolldown.ts b/scripts/rolldown.ts new file mode 100644 index 000000000..0876bc917 --- /dev/null +++ b/scripts/rolldown.ts @@ -0,0 +1,372 @@ +import polyfillNode from '@rolldown/plugin-node-polyfills' +import { minify as minifySwc } from '@swc/core' +import { createRequire } from 'node:module' +import path from 'node:path' +import { fileURLToPath } from 'node:url' +import pc from 'picocolors' +import { entries } from './aliases' +// @ts-expect-error -- experimental +import { replacePlugin } from 'rolldown/experimental' + +import type { OutputOptions, Plugin, RolldownOptions } from 'rolldown' + +const require = createRequire(import.meta.url) +const __dirname = fileURLToPath(new URL('.', import.meta.url)) + +const masterVersion = require('../package.json').version +const packagesDir = path.resolve(__dirname, '../packages') + +export function createConfigsForPackage({ + target, + commit, + formats, + devOnly = false, + prodOnly = false, + sourceMap = false + // localDev = false, + // inlineDeps = false +}: { + target: string + commit: string + formats?: string[] + devOnly?: boolean + prodOnly?: boolean + sourceMap?: boolean + localDev?: boolean + inlineDeps?: boolean +}) { + const packageDir = path.resolve(packagesDir, target) + const resolve = (p: string) => path.resolve(packageDir, p) + const pkg = require(resolve(`package.json`)) + const packageOptions = (pkg.buildOptions || {}) as { + name: string + formats?: string[] + prod?: boolean + enableNonBrowserBranches?: boolean + } + const name = path.basename(packageDir) + + const banner = `/*! +* ${name} v${pkg.version} +* (c) 2016-present ${pkg.author.name} and contributors +* Released under the ${pkg.license} License. +*/` + + // TODO: + /* + const stubs = { + [`dist/${name}.cjs`]: `${name}.cjs.js`, + [`dist/${name}.mjs`]: `${name}.esm-bundler.js`, + [`dist/${name}.runtime.mjs`]: `${name}.runtime.esm-bundler.js`, + [`dist/${name}.prod.cjs`]: `${name}.cjs.prod.js` + } + */ + + const outputConfigs: Record = { + mjs: { + file: `dist/${name}.mjs`, + format: `es` + }, + 'mjs-node': { + file: `dist/${name}.node.mjs`, + format: `es` + }, + browser: { + file: `dist/${name}.esm-browser.js`, + format: `es` + }, + cjs: { + // file: `dist/${name}.cjs.js`, + file: `dist/${name}.cjs`, + format: `cjs` + }, + global: { + file: `dist/${name}.global.js`, + format: `iife` + }, + // runtime-only builds, for '@intlify/core' and 'vue-i18n' package only + 'mjs-runtime': { + file: `dist/${name}.runtime.mjs`, + format: `es` + }, + 'mjs-node-runtime': { + file: `dist/${name}.runtime.node.mjs`, + format: `es` + }, + 'browser-runtime': { + file: `dist/${name}.runtime.esm-browser.js`, + format: 'es' + }, + 'global-runtime': { + file: `dist/${name}.runtime.global.js`, + format: 'iife' + } + } + + const resolvedFormats = ( + formats || + packageOptions.formats || ['esm-bundler', 'cjs'] + ) + .filter(Boolean) + .filter((format: string) => outputConfigs[format]) + + const packageConfigs = prodOnly + ? [] + : resolvedFormats.map((format: string) => + createConfig(format, outputConfigs[format]) + ) + + if (!devOnly) { + resolvedFormats.forEach((format: string) => { + if (packageOptions.prod === false) { + return + } + if (format === 'cjs') { + packageConfigs.push(createProductionConfig(format)) + } + if (/^(global|browser)(-runtime)?/.test(format)) { + packageConfigs.push(createMinifiedConfig(format)) + } + }) + } + + function createConfig( + format: string, + output: OutputOptions, + plugins: Plugin[] = [] + ): RolldownOptions { + if (!output) { + console.log(pc.yellow(`invalid format: "${format}"`)) + process.exit(1) + } + + const isProductionBuild = + process.env.__DEV__ === 'false' || + /\.prod\.[cm]?js$/.test(String(output.file) || '') + const isBundlerESMBuild = /mjs/.test(format) + const isBrowserESMBuild = /browser/.test(format) + const isNodeBuild = + String(output.file).includes('.node.') || + format === 'cjs' || + format === 'cjs-lite' + const isGlobalBuild = /global/.test(format) + const isRuntimeOnlyBuild = /runtime/.test(format) + const isLite = /petite-vue-i18n/.test(name) + + output.dir = resolve('dist') + output.sourcemap = sourceMap + output.banner = banner + output.externalLiveBindings = false + if ( + name === 'vue-i18n' || + name === 'vue-i18n-core' || + name === 'petite-vue-i18n' + ) { + output.globals = { + vue: 'Vue', + '@vue/devtools-api': 'VueDevtoolsApi' + } + } + if (isGlobalBuild) { + output.name = packageOptions.name + } + + const entryFile = /runtime/.test(format) ? `src/runtime.ts` : `src/index.ts` + + function resolveDefine() { + const defines: Record = { + __COMMIT__: `"${commit}"`, + __VERSION__: `'${masterVersion}'`, + /* + __DEV__: + ['vue-i18n', 'petite-vue-i18n'].includes(name) && isNodeBuild + ? 'false' // tree-shake devtools + : isBundlerESMBuild + ? // preserve to be handled by bundlers + `(process.env.NODE_ENV !== 'production')` + : // hard coded dev/prod builds + !isProductionBuild, + */ + // this is only used during Vue's internal tests + __TEST__: `false`, + // If the build is expected to run directly in the browser (global / esm builds) + __BROWSER__: String(isBrowserESMBuild), + __GLOBAL__: String(isGlobalBuild), + // for runtime only + __RUNTIME__: String(isRuntimeOnlyBuild), + // bundle filename + // __BUNDLE_FILENAME__: `'${path.parse(String(output.file || '')).base || ''}'`, + __ESM_BUNDLER__: String(isBundlerESMBuild), + __ESM_BROWSER__: String(isBrowserESMBuild), + // is targeting Node (SSR)? + __NODE_JS__: String(isNodeBuild), + // for lite version + __LITE__: String(isLite), + // feature flags + __FEATURE_FULL_INSTALL__: isBundlerESMBuild + ? `__VUE_I18N_FULL_INSTALL__` + : `true`, + __FEATURE_LEGACY_API__: isBundlerESMBuild + ? `__VUE_I18N_LEGACY_API__` + : `true`, + __FEATURE_PROD_VUE_DEVTOOLS__: + ['vue-i18n', 'petite-vue-i18n'].includes(name) && isNodeBuild + ? 'false' // tree-shake devtools + : isBundlerESMBuild + ? `__VUE_PROD_DEVTOOLS__` + : `false`, + __FEATURE_PROD_INTLIFY_DEVTOOLS__: isBundlerESMBuild + ? `__INTLIFY_PROD_DEVTOOLS__` + : `false`, + __FEATURE_DROP_MESSAGE_COMPILER__: isBundlerESMBuild + ? `__INTLIFY_DROP_MESSAGE_COMPILER__` + : `false` + // ...(isProductionBuild && isBrowserESMBuild + // ? { + // 'emitError(': `/*#__PURE__*/ emitError(`, + // 'createCompileError(': `/*#__PURE__*/ createCompileError(`, + // 'throw createCoreError(': `throw Error(`, + // 'throw createI18nError(': `throw Error(` + // } + // : {}) + } + + if (!isBundlerESMBuild) { + // hard coded dev/prod builds + defines.__DEV__ = String(!isProductionBuild) + } + + // allow inline overrides like + //__LITE__=true pnpm build core-base + Object.keys(defines).forEach(key => { + if (key in process.env) { + const value = process.env[key] + assert(typeof value === 'string') + defines[key] = value + } + }) + + return defines + } + + function resolveReplace() { + const replacements: Record = {} + + if (isBundlerESMBuild) { + Object.assign(replacements, { + // preserve to be handled by bundlers + __DEV__: + ['vue-i18n', 'petite-vue-i18n'].includes(name) && isNodeBuild + ? 'false' // tree-shake devtools + : isBundlerESMBuild + ? // preserve to be handled by bundlers + `(process.env.NODE_ENV !== 'production')` + : // hard coded dev/prod builds + !isProductionBuild + }) + } + + if (isProductionBuild && isBrowserESMBuild) { + Object.assign(replacements, { + 'emitError(': `/*#__PURE__*/ emitError(`, + 'createCompileError(': `/*#__PURE__*/ createCompileError(`, + 'throw createCoreError(': `throw Error(`, + 'throw createI18nError(': `throw Error(` + }) + } + + if (Object.keys(replacements).length) { + return [replacePlugin(replacements)] + } else { + return [] + } + } + + function resolveExternal() { + return isGlobalBuild || isBrowserESMBuild + ? ['vue'] // packageOptions.enableNonBrowserBranches + : // ? packageOptions.enableFullBundleForEsmBrowser && isBrowserESMBuild + // ? [] + // : ['vue'] // packageOptions.enableNonBrowserBranches + // Node / esm-bundler builds. Externalize everything. + [ + ...Object.keys(pkg.dependencies || {}), + ...Object.keys(pkg.peerDependencies || {}) + ] + } + + function resolveNodePlugins() { + const nodePlugins = + (format === 'cjs' && Object.keys(pkg.devDependencies || {}).length) || + packageOptions.enableNonBrowserBranches + ? [...(format === 'cjs' ? [] : [polyfillNode()])] + : [] + return nodePlugins + } + + return { + input: resolve(entryFile), + // Global and Browser ESM builds inlines everything so that they can be + // used alone. + external: resolveExternal(), + define: resolveDefine(), + platform: format === 'cjs' ? 'node' : 'browser', + resolve: { + alias: entries + }, + plugins: [ + ...resolveReplace(), + ...resolveNodePlugins(), + ...plugins + // TODO: stub + ], + output, + treeshake: { + // https://github.com/rolldown/rolldown/issues/1917 + moduleSideEffects: false + } + } + } + + function createProductionConfig(format: string): RolldownOptions { + const extension = format === 'cjs' || format === 'mjs' ? format : 'js' + const descriptor = format === 'cjs' || format === 'mjs' ? '' : `.${format}` + return createConfig(format, { + file: `dist/${name}${descriptor}.prod.${extension}`, + format: outputConfigs[format].format + }) + } + + function createMinifiedConfig(format: string): RolldownOptions { + return createConfig( + format, + { + file: String(outputConfigs[format].file).replace(/\.js$/, '.prod.js'), + format: outputConfigs[format].format + }, + [ + { + name: 'swc-minify', + async renderChunk(contents, _, { format }) { + const { code } = await minifySwc(contents, { + module: format === 'es', + format: { + comments: false + }, + compress: { + ecma: 2016, + pure_getters: true + }, + safari10: true, + mangle: true + }) + // swc removes banner + return { code: banner + code, map: null } + } + } + ] + ) + } + + return packageConfigs +} From 52de5ca216dbe238831aecf5a92e0ef2d98207ae Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Sat, 4 Jan 2025 02:20:09 +0900 Subject: [PATCH 02/21] fix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ff3484843..10e5445cb 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "preview:size-vue-i18n": "pnpm --filter @intlify/size-check-vue-i18n preview", "release": "bumpp package.json packages/**/package.json --commit \"release: v\" --push --tag", "size": "tsx ./scripts/build.ts --size && tsx ./scripts/size.ts", - "size:rolldown": "tsx ./scripts/build-rolldown.ts", + "build:rolldown": "tsx ./scripts/build-rolldown.ts", "size:report": "tsx ./scripts/report-size.ts", "test": "run-s lint test:cover check-install test:e2e", "test:cover": "pnpm test:unit --coverage", From 1a18e85b5d30c29e6cfab13c9f51e8fc5ec61285 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Sat, 4 Jan 2025 10:08:09 +0900 Subject: [PATCH 03/21] fix: rolldown errors --- packages/core-base/src/index.ts | 12 ++++-------- packages/petite-vue-i18n/src/index.ts | 15 +++++++-------- packages/petite-vue-i18n/src/runtime.ts | 15 +++++++-------- packages/vue-i18n-core/src/index.ts | 17 ++++++++--------- packages/vue-i18n/src/index.ts | 17 ++++++++--------- packages/vue-i18n/src/runtime.ts | 17 ++++++++--------- scripts/rolldown.ts | 7 ++++++- 7 files changed, 48 insertions(+), 52 deletions(-) diff --git a/packages/core-base/src/index.ts b/packages/core-base/src/index.ts index bf4a71ec1..0ce608303 100644 --- a/packages/core-base/src/index.ts +++ b/packages/core-base/src/index.ts @@ -1,21 +1,17 @@ import { initFeatureFlags } from './misc' -export { +export { createCompileError } from '@intlify/message-compiler' +export type { CompileError, CompileErrorCodes, - createCompileError, ResourceNode } from '@intlify/message-compiler' export * from './compilation' export * from './context' export * from './datetime' export * from './devtools' -export { - CORE_ERROR_CODES_EXTEND_POINT, - CoreError, - CoreErrorCodes, - createCoreError -} from './errors' +export { CORE_ERROR_CODES_EXTEND_POINT, createCoreError } from './errors' +export type { CoreError, CoreErrorCodes } from './errors' export * from './fallbacker' export * from './number' export * from './resolver' diff --git a/packages/petite-vue-i18n/src/index.ts b/packages/petite-vue-i18n/src/index.ts index 9f3895960..7b0e76f6c 100644 --- a/packages/petite-vue-i18n/src/index.ts +++ b/packages/petite-vue-i18n/src/index.ts @@ -13,7 +13,7 @@ if (__ESM_BUNDLER__ && !__TEST__) { // register message compiler at petite-vue-i18n registerMessageCompiler(compile) -export { +export type { CompileError, DateTimeOptions, FallbackLocale, @@ -47,7 +47,7 @@ export { RemovedIndexResources, TranslateOptions } from '@intlify/core-base' -export { +export type { Composer, ComposerCustom, ComposerDateTimeFormatting, @@ -66,20 +66,19 @@ export { MissingHandler, VueMessageType } from '../../vue-i18n-core/src/composer' -export { +export { createI18n, useI18n } from '../../vue-i18n-core/src/i18n' +export type { ComposerAdditionalOptions, ComposerExtender, - createI18n, ExportedGlobalComposer, I18n, I18nAdditionalOptions, I18nMode, I18nOptions, I18nScope, - useI18n, UseI18nOptions } from '../../vue-i18n-core/src/i18n' -export { +export type { Choice, DateTimeFormatResult, LocaleMessageObject, @@ -95,9 +94,9 @@ export { VueI18nTranslation, WarnHtmlInMessageLevel } from '../../vue-i18n-core/src/legacy' -export { I18nPluginOptions } from '../../vue-i18n-core/src/plugin' +export type { I18nPluginOptions } from '../../vue-i18n-core/src/plugin' export { VERSION } from './../../vue-i18n-core/src/misc' -export { Disposer } from './../../vue-i18n-core/src/types' +export type { Disposer } from './../../vue-i18n-core/src/types' export type { IsEmptyObject, diff --git a/packages/petite-vue-i18n/src/runtime.ts b/packages/petite-vue-i18n/src/runtime.ts index a2898353f..5135f3b9d 100644 --- a/packages/petite-vue-i18n/src/runtime.ts +++ b/packages/petite-vue-i18n/src/runtime.ts @@ -13,7 +13,7 @@ if (__ESM_BUNDLER__ && !__TEST__) { // register message compiler for jit compilation registerMessageCompiler(compile) -export { +export type { CompileError, DateTimeOptions, FallbackLocale, @@ -46,7 +46,7 @@ export { RemovedIndexResources, TranslateOptions } from '@intlify/core-base' -export { +export type { Composer, ComposerCustom, ComposerDateTimeFormatting, @@ -65,20 +65,19 @@ export { MissingHandler, VueMessageType } from '../../vue-i18n-core/src/composer' -export { +export { createI18n, useI18n } from '../../vue-i18n-core/src/i18n' +export type { ComposerAdditionalOptions, ComposerExtender, - createI18n, ExportedGlobalComposer, I18n, I18nAdditionalOptions, I18nMode, I18nOptions, I18nScope, - useI18n, UseI18nOptions } from '../../vue-i18n-core/src/i18n' -export { +export type { Choice, DateTimeFormatResult, LocaleMessageObject, @@ -94,9 +93,9 @@ export { VueI18nTranslation, WarnHtmlInMessageLevel } from '../../vue-i18n-core/src/legacy' -export { I18nPluginOptions } from '../../vue-i18n-core/src/plugin' +export type { I18nPluginOptions } from '../../vue-i18n-core/src/plugin' export { VERSION } from './../../vue-i18n-core/src/misc' -export { Disposer } from './../../vue-i18n-core/src/types' +export type { Disposer } from './../../vue-i18n-core/src/types' export type { IsEmptyObject, diff --git a/packages/vue-i18n-core/src/index.ts b/packages/vue-i18n-core/src/index.ts index 0543dc82a..a5e1cb809 100644 --- a/packages/vue-i18n-core/src/index.ts +++ b/packages/vue-i18n-core/src/index.ts @@ -2,7 +2,7 @@ import { setDevToolsHook } from '@intlify/core-base' import { getGlobalThis } from '@intlify/shared' import { initDev, initFeatureFlags } from './misc' -export { +export type { CompileError, DateTimeOptions, FallbackLocale, @@ -36,7 +36,7 @@ export { SchemaParams, TranslateOptions } from '@intlify/core-base' -export { +export type { BaseFormatProps, ComponentI18nScope, DatetimeFormat, @@ -50,7 +50,7 @@ export { Translation, TranslationProps } from './components' -export { +export type { Composer, ComposerCustom, ComposerDateTimeFormatting, @@ -69,10 +69,10 @@ export { MissingHandler, VueMessageType } from './composer' -export { +export { createI18n, useI18n } from './i18n' +export type { ComposerAdditionalOptions, ComposerExtender, - createI18n, ExportedGlobalComposer, I18n, I18nAdditionalOptions, @@ -80,10 +80,9 @@ export { I18nMode, I18nOptions, I18nScope, - useI18n, UseI18nOptions } from './i18n' -export { +export type { Choice, DateTimeFormatResult, LocaleMessageObject, @@ -100,8 +99,8 @@ export { WarnHtmlInMessageLevel } from './legacy' export { VERSION } from './misc' -export { I18nPluginOptions } from './plugin' -export { Disposer } from './types' +export type { I18nPluginOptions } from './plugin' +export type { Disposer } from './types' export type { IsEmptyObject, diff --git a/packages/vue-i18n/src/index.ts b/packages/vue-i18n/src/index.ts index a614a9d44..13b291fe0 100644 --- a/packages/vue-i18n/src/index.ts +++ b/packages/vue-i18n/src/index.ts @@ -23,7 +23,7 @@ registerMessageResolver(resolveValue) // register fallback locale at vue-i18n registerLocaleFallbacker(fallbackWithLocaleChain) -export { +export type { CompileError, DateTimeOptions, FallbackLocale, @@ -55,7 +55,7 @@ export { RemovedIndexResources, TranslateOptions } from '@intlify/core-base' -export { +export type { BaseFormatProps, ComponentI18nScope, DatetimeFormat, @@ -69,7 +69,7 @@ export { Translation, TranslationProps } from '../../vue-i18n-core/src/components' -export { +export type { Composer, ComposerCustom, ComposerDateTimeFormatting, @@ -88,10 +88,10 @@ export { MissingHandler, VueMessageType } from '../../vue-i18n-core/src/composer' -export { +export { createI18n, useI18n } from '../../vue-i18n-core/src/i18n' +export type { ComposerAdditionalOptions, ComposerExtender, - createI18n, ExportedGlobalComposer, I18n, I18nAdditionalOptions, @@ -99,10 +99,9 @@ export { I18nMode, I18nOptions, I18nScope, - useI18n, UseI18nOptions } from '../../vue-i18n-core/src/i18n' -export { +export type { Choice, DateTimeFormatResult, LocaleMessageObject, @@ -118,9 +117,9 @@ export { VueI18nTranslation, WarnHtmlInMessageLevel } from '../../vue-i18n-core/src/legacy' -export { I18nPluginOptions } from '../../vue-i18n-core/src/plugin' +export type { I18nPluginOptions } from '../../vue-i18n-core/src/plugin' export { VERSION } from './../../vue-i18n-core/src/misc' -export { Disposer } from './../../vue-i18n-core/src/types' +export type { Disposer } from './../../vue-i18n-core/src/types' export type { IsEmptyObject, diff --git a/packages/vue-i18n/src/runtime.ts b/packages/vue-i18n/src/runtime.ts index 16df9e3f6..a267a023e 100644 --- a/packages/vue-i18n/src/runtime.ts +++ b/packages/vue-i18n/src/runtime.ts @@ -23,7 +23,7 @@ registerMessageResolver(resolveValue) // register fallback locale at vue-i18n registerLocaleFallbacker(fallbackWithLocaleChain) -export { +export type { CompileError, DateTimeOptions, FallbackLocale, @@ -54,7 +54,7 @@ export { RemovedIndexResources, TranslateOptions } from '@intlify/core-base' -export { +export type { BaseFormatProps, ComponentI18nScope, DatetimeFormat, @@ -68,7 +68,7 @@ export { Translation, TranslationProps } from '../../vue-i18n-core/src/components' -export { +export type { Composer, ComposerCustom, ComposerDateTimeFormatting, @@ -87,10 +87,10 @@ export { MissingHandler, VueMessageType } from '../../vue-i18n-core/src/composer' -export { +export { createI18n, useI18n } from '../../vue-i18n-core/src/i18n' +export type { ComposerAdditionalOptions, ComposerExtender, - createI18n, ExportedGlobalComposer, I18n, I18nAdditionalOptions, @@ -98,10 +98,9 @@ export { I18nMode, I18nOptions, I18nScope, - useI18n, UseI18nOptions } from '../../vue-i18n-core/src/i18n' -export { +export type { Choice, DateTimeFormatResult, LocaleMessageObject, @@ -117,9 +116,9 @@ export { VueI18nTranslation, WarnHtmlInMessageLevel } from '../../vue-i18n-core/src/legacy' -export { I18nPluginOptions } from '../../vue-i18n-core/src/plugin' +export type { I18nPluginOptions } from '../../vue-i18n-core/src/plugin' export { VERSION } from './../../vue-i18n-core/src/misc' -export { Disposer } from './../../vue-i18n-core/src/types' +export type { Disposer } from './../../vue-i18n-core/src/types' export type { IsEmptyObject, diff --git a/scripts/rolldown.ts b/scripts/rolldown.ts index 0876bc917..480c811af 100644 --- a/scripts/rolldown.ts +++ b/scripts/rolldown.ts @@ -144,7 +144,9 @@ export function createConfigsForPackage({ process.env.__DEV__ === 'false' || /\.prod\.[cm]?js$/.test(String(output.file) || '') const isBundlerESMBuild = /mjs/.test(format) - const isBrowserESMBuild = /browser/.test(format) + const isBrowserESMBuild = + /browser/.test(format) && !packageOptions.enableNonBrowserBranches + // const isCJSBuild = format === 'cjs' const isNodeBuild = String(output.file).includes('.node.') || format === 'cjs' || @@ -157,6 +159,9 @@ export function createConfigsForPackage({ output.sourcemap = sourceMap output.banner = banner output.externalLiveBindings = false + // if (isCJSBuild) { + // output.esModule = true + // } if ( name === 'vue-i18n' || name === 'vue-i18n-core' || From 74bbb8dfdafcc8d7cdd6afe5065630aa7fb3e825 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Sun, 5 Jan 2025 21:26:56 +0900 Subject: [PATCH 04/21] fix: wrong exporting --- packages/vue-i18n-core/src/index.ts | 3 +-- packages/vue-i18n/src/index.ts | 7 +++++-- packages/vue-i18n/src/runtime.ts | 7 +++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/vue-i18n-core/src/index.ts b/packages/vue-i18n-core/src/index.ts index a5e1cb809..aa0b66f49 100644 --- a/packages/vue-i18n-core/src/index.ts +++ b/packages/vue-i18n-core/src/index.ts @@ -69,14 +69,13 @@ export type { MissingHandler, VueMessageType } from './composer' -export { createI18n, useI18n } from './i18n' +export { createI18n, I18nInjectionKey, useI18n } from './i18n' export type { ComposerAdditionalOptions, ComposerExtender, ExportedGlobalComposer, I18n, I18nAdditionalOptions, - I18nInjectionKey, I18nMode, I18nOptions, I18nScope, diff --git a/packages/vue-i18n/src/index.ts b/packages/vue-i18n/src/index.ts index 13b291fe0..cbab3cc4a 100644 --- a/packages/vue-i18n/src/index.ts +++ b/packages/vue-i18n/src/index.ts @@ -88,14 +88,17 @@ export type { MissingHandler, VueMessageType } from '../../vue-i18n-core/src/composer' -export { createI18n, useI18n } from '../../vue-i18n-core/src/i18n' +export { + createI18n, + I18nInjectionKey, + useI18n +} from '../../vue-i18n-core/src/i18n' export type { ComposerAdditionalOptions, ComposerExtender, ExportedGlobalComposer, I18n, I18nAdditionalOptions, - I18nInjectionKey, I18nMode, I18nOptions, I18nScope, diff --git a/packages/vue-i18n/src/runtime.ts b/packages/vue-i18n/src/runtime.ts index a267a023e..2b36102d0 100644 --- a/packages/vue-i18n/src/runtime.ts +++ b/packages/vue-i18n/src/runtime.ts @@ -87,14 +87,17 @@ export type { MissingHandler, VueMessageType } from '../../vue-i18n-core/src/composer' -export { createI18n, useI18n } from '../../vue-i18n-core/src/i18n' +export { + createI18n, + I18nInjectionKey, + useI18n +} from '../../vue-i18n-core/src/i18n' export type { ComposerAdditionalOptions, ComposerExtender, ExportedGlobalComposer, I18n, I18nAdditionalOptions, - I18nInjectionKey, I18nMode, I18nOptions, I18nScope, From 9a1fcbcdb85ced9f77aa87364f1216ec890d56da Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Sun, 5 Jan 2025 22:48:05 +0900 Subject: [PATCH 05/21] fix: output dist files --- scripts/build-rolldown.ts | 7 +++++- scripts/rolldown.ts | 47 +++++++++++++-------------------------- 2 files changed, 21 insertions(+), 33 deletions(-) diff --git a/scripts/build-rolldown.ts b/scripts/build-rolldown.ts index c2ac07601..8f032ce1a 100644 --- a/scripts/build-rolldown.ts +++ b/scripts/build-rolldown.ts @@ -129,7 +129,12 @@ async function main() { rolldown(c).then(bundle => { return bundle.write(c.output as OutputOptions).then(() => { // @ts-expect-error - return path.join('packages', target, c.output.file) + return path.join( + 'packages', + target, + 'dist', + path.basename(c.output.file) + ) }) }) ) diff --git a/scripts/rolldown.ts b/scripts/rolldown.ts index 480c811af..d39d56b92 100644 --- a/scripts/rolldown.ts +++ b/scripts/rolldown.ts @@ -47,7 +47,7 @@ export function createConfigsForPackage({ const name = path.basename(packageDir) const banner = `/*! -* ${name} v${pkg.version} +* ${pkg.name} v${pkg.version} * (c) 2016-present ${pkg.author.name} and contributors * Released under the ${pkg.license} License. */` @@ -64,41 +64,40 @@ export function createConfigsForPackage({ const outputConfigs: Record = { mjs: { - file: `dist/${name}.mjs`, + file: resolve(`dist/${name}.mjs`), format: `es` }, 'mjs-node': { - file: `dist/${name}.node.mjs`, + file: resolve(`dist/${name}.node.mjs`), format: `es` }, browser: { - file: `dist/${name}.esm-browser.js`, + file: resolve(`dist/${name}.esm-browser.js`), format: `es` }, cjs: { - // file: `dist/${name}.cjs.js`, - file: `dist/${name}.cjs`, + file: resolve(`dist/${name}.cjs`), format: `cjs` }, global: { - file: `dist/${name}.global.js`, + file: resolve(`dist/${name}.global.js`), format: `iife` }, // runtime-only builds, for '@intlify/core' and 'vue-i18n' package only 'mjs-runtime': { - file: `dist/${name}.runtime.mjs`, + file: resolve(`dist/${name}.runtime.mjs`), format: `es` }, 'mjs-node-runtime': { - file: `dist/${name}.runtime.node.mjs`, + file: resolve(`dist/${name}.runtime.node.mjs`), format: `es` }, 'browser-runtime': { - file: `dist/${name}.runtime.esm-browser.js`, + file: resolve(`dist/${name}.runtime.esm-browser.js`), format: 'es' }, 'global-runtime': { - file: `dist/${name}.runtime.global.js`, + file: resolve(`dist/${name}.runtime.global.js`), format: 'iife' } } @@ -155,7 +154,7 @@ export function createConfigsForPackage({ const isRuntimeOnlyBuild = /runtime/.test(format) const isLite = /petite-vue-i18n/.test(name) - output.dir = resolve('dist') + // output.dir = resolve('dist') output.sourcemap = sourceMap output.banner = banner output.externalLiveBindings = false @@ -182,16 +181,6 @@ export function createConfigsForPackage({ const defines: Record = { __COMMIT__: `"${commit}"`, __VERSION__: `'${masterVersion}'`, - /* - __DEV__: - ['vue-i18n', 'petite-vue-i18n'].includes(name) && isNodeBuild - ? 'false' // tree-shake devtools - : isBundlerESMBuild - ? // preserve to be handled by bundlers - `(process.env.NODE_ENV !== 'production')` - : // hard coded dev/prod builds - !isProductionBuild, - */ // this is only used during Vue's internal tests __TEST__: `false`, // If the build is expected to run directly in the browser (global / esm builds) @@ -226,14 +215,6 @@ export function createConfigsForPackage({ __FEATURE_DROP_MESSAGE_COMPILER__: isBundlerESMBuild ? `__INTLIFY_DROP_MESSAGE_COMPILER__` : `false` - // ...(isProductionBuild && isBrowserESMBuild - // ? { - // 'emitError(': `/*#__PURE__*/ emitError(`, - // 'createCompileError(': `/*#__PURE__*/ createCompileError(`, - // 'throw createCoreError(': `throw Error(`, - // 'throw createI18nError(': `throw Error(` - // } - // : {}) } if (!isBundlerESMBuild) { @@ -337,7 +318,7 @@ export function createConfigsForPackage({ const extension = format === 'cjs' || format === 'mjs' ? format : 'js' const descriptor = format === 'cjs' || format === 'mjs' ? '' : `.${format}` return createConfig(format, { - file: `dist/${name}${descriptor}.prod.${extension}`, + file: resolve(`dist/${name}${descriptor}.prod.${extension}`), format: outputConfigs[format].format }) } @@ -346,7 +327,9 @@ export function createConfigsForPackage({ return createConfig( format, { - file: String(outputConfigs[format].file).replace(/\.js$/, '.prod.js'), + file: resolve( + String(outputConfigs[format].file).replace(/\.js$/, '.prod.js') + ), format: outputConfigs[format].format }, [ From 13edbea231c7c65aff20cff654d365dc30a03256 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Sun, 5 Jan 2025 23:03:43 +0900 Subject: [PATCH 06/21] fix: generate stub file --- scripts/build-rolldown.ts | 2 +- scripts/rolldown.ts | 39 ++++++++++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/scripts/build-rolldown.ts b/scripts/build-rolldown.ts index 8f032ce1a..e8773dc5d 100644 --- a/scripts/build-rolldown.ts +++ b/scripts/build-rolldown.ts @@ -128,11 +128,11 @@ async function main() { configs.map(c => rolldown(c).then(bundle => { return bundle.write(c.output as OutputOptions).then(() => { - // @ts-expect-error return path.join( 'packages', target, 'dist', + // @ts-expect-error path.basename(c.output.file) ) }) diff --git a/scripts/rolldown.ts b/scripts/rolldown.ts index d39d56b92..b64e1f694 100644 --- a/scripts/rolldown.ts +++ b/scripts/rolldown.ts @@ -1,5 +1,6 @@ import polyfillNode from '@rolldown/plugin-node-polyfills' import { minify as minifySwc } from '@swc/core' +import { promises as fs } from 'node:fs' import { createRequire } from 'node:module' import path from 'node:path' import { fileURLToPath } from 'node:url' @@ -52,15 +53,14 @@ export function createConfigsForPackage({ * Released under the ${pkg.license} License. */` - // TODO: - /* const stubs = { - [`dist/${name}.cjs`]: `${name}.cjs.js`, - [`dist/${name}.mjs`]: `${name}.esm-bundler.js`, - [`dist/${name}.runtime.mjs`]: `${name}.runtime.esm-bundler.js`, - [`dist/${name}.prod.cjs`]: `${name}.cjs.prod.js` + [resolve(`dist/${name}.cjs`)]: resolve(`dist/${name}.cjs.js`), + [resolve(`dist/${name}.mjs`)]: resolve(`dist/${name}.esm-bundler.js`), + [resolve(`dist/${name}.runtime.mjs`)]: resolve( + `dist/${name}.runtime.esm-bundler.js` + ), + [resolve(`dist/${name}.prod.cjs`)]: resolve(`dist/${name}.cjs.prod.js`) } - */ const outputConfigs: Record = { mjs: { @@ -138,6 +138,7 @@ export function createConfigsForPackage({ console.log(pc.yellow(`invalid format: "${format}"`)) process.exit(1) } + const rawFile = output.file const isProductionBuild = process.env.__DEV__ === 'false' || @@ -303,8 +304,28 @@ export function createConfigsForPackage({ plugins: [ ...resolveReplace(), ...resolveNodePlugins(), - ...plugins - // TODO: stub + ...plugins, + { + name: 'write-stub', + async writeBundle() { + if (rawFile == null) { + return + } + const stub = stubs[rawFile] + if (!stub) { + return + } + + const filename = path.basename(rawFile) + const contents = + format === 'cjs' + ? `module.exports = require('./${filename}')` + : `export * from './${filename}'` + + await fs.writeFile(stub, contents) + // console.log(`created stub ${pc.bold(path.join('packages', target, 'dist', path.basename(stub)))}`) + } + } ], output, treeshake: { From 5c3dc608994f2e2bfa428df2635158adf6dd6bc7 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 6 Jan 2025 00:25:55 +0900 Subject: [PATCH 07/21] fix: add type definition generating script with oxc-transform --- package.json | 2 + pnpm-lock.yaml | 129 ++++++++++++++++++++++++++++++++++++-- scripts/build-rolldown.ts | 2 +- scripts/build-types.ts | 93 +++++++++++++++++++++++++++ 4 files changed, 221 insertions(+), 5 deletions(-) create mode 100644 scripts/build-types.ts diff --git a/package.json b/package.json index 10e5445cb..2347c5297 100644 --- a/package.json +++ b/package.json @@ -109,6 +109,7 @@ "eslint-config-prettier": "^9.1.0", "eslint-plugin-vue": "^9.28.0", "execa": "^9.3.0", + "fast-glob": "^3.3.3", "fixpack": "^4.0.0", "get-port-please": "^3.1.2", "globals": "^15.9.0", @@ -121,6 +122,7 @@ "mitata": "^1.0.20", "npm-run-all2": "^7.0.0", "opener": "^1.5.2", + "oxc-transform": "^0.44.0", "pathe": "^1.1.2", "picocolors": "^1.0.0", "pkg-pr-new": "^0.0.37", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0a7cca4cc..568847e94 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -93,6 +93,9 @@ importers: execa: specifier: ^9.3.0 version: 9.3.0 + fast-glob: + specifier: ^3.3.3 + version: 3.3.3 fixpack: specifier: ^4.0.0 version: 4.0.0 @@ -129,6 +132,9 @@ importers: opener: specifier: ^1.5.2 version: 1.5.2 + oxc-transform: + specifier: ^0.44.0 + version: 0.44.0 pathe: specifier: ^1.1.2 version: 1.1.2 @@ -1545,6 +1551,46 @@ packages: '@octokit/types@13.5.0': resolution: {integrity: sha512-HdqWTf5Z3qwDVlzCrP8UJquMwunpDiMPt5er+QjGzL4hqr/vBVY/MauQgS1xWxCDT1oMx1EULyqxncdCY/NVSQ==} + '@oxc-transform/binding-darwin-arm64@0.44.0': + resolution: {integrity: sha512-bgJg3+TypUMDAWTMKXws2TL45FcTOAtYJObuXvPTyanUDR16Lgara+lCWZkJQDrq+WngNdzYBkTn6gJZwlcS8g==} + cpu: [arm64] + os: [darwin] + + '@oxc-transform/binding-darwin-x64@0.44.0': + resolution: {integrity: sha512-+YR/7VWCakghk8RGa9KTAB6+ZCLUMdk6TCpch8aYrP7QKZqHBFkzJr4e+Ewhhxuqc+ULQ/eA4B7TZzd/LkTj2w==} + cpu: [x64] + os: [darwin] + + '@oxc-transform/binding-linux-arm64-gnu@0.44.0': + resolution: {integrity: sha512-xNBejh63+V/xwZlwDzzvSje9M1EYajedLYewxXeA0oH+AxwMK24jgn5qhXi38kp28Mhn/PNNss2UETTCpNJGGg==} + cpu: [arm64] + os: [linux] + + '@oxc-transform/binding-linux-arm64-musl@0.44.0': + resolution: {integrity: sha512-19/jSDBV9+/JtFCg2FMoP4hjibNV4PskTkgzuxpktbJWZnQiDEbbTuOE7MFKZqTXd3okEZ2NqhMNeQEVj1+ULg==} + cpu: [arm64] + os: [linux] + + '@oxc-transform/binding-linux-x64-gnu@0.44.0': + resolution: {integrity: sha512-OuZlXynZdr2PPBIdZ0jA8sWYrhYTKW2m+9sYAtgHNHiKeJr7NGTxyTLfjNaLNt0Ji71z6X5eVX4QRVFwnfoEQg==} + cpu: [x64] + os: [linux] + + '@oxc-transform/binding-linux-x64-musl@0.44.0': + resolution: {integrity: sha512-lDIh5r2atVR72iPsBuhPbM3B67rINakWMMUDa64eJtJcvlgIaqyybQhiRWCbzUErE5cSBnvXgViJLsq7PRrtEA==} + cpu: [x64] + os: [linux] + + '@oxc-transform/binding-win32-arm64-msvc@0.44.0': + resolution: {integrity: sha512-JKmmVMw+c+cG0wnCkOUavNGoFqbGggk1RjRC7UGYWrFK10YS48Wyg4pXAW4XwYTzWD4N15ooSO6c6lO40uCEog==} + cpu: [arm64] + os: [win32] + + '@oxc-transform/binding-win32-x64-msvc@0.44.0': + resolution: {integrity: sha512-jeUzJE32z4j/9tVlrVGiIgLRzHMbBAGl47GGQhFpjS2s9+lXxT0PubosMKbFAPnlbUPJTDusebttA+DWhWgFuA==} + cpu: [x64] + os: [win32] + '@parcel/watcher-android-arm64@2.4.1': resolution: {integrity: sha512-LOi/WTbbh3aTn2RYddrO8pnapixAziFl6SMxHM69r3tvdSm94JtCenaKgk1GRg5FJ5wpMCpHeW+7yqPlvZv7kg==} engines: {node: '>= 10.0.0'} @@ -2985,6 +3031,10 @@ packages: resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==} engines: {node: '>=8'} + braces@3.0.3: + resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==} + engines: {node: '>=8'} + brorand@1.1.0: resolution: {integrity: sha512-cKV8tMCEpQs4hK/ik71d6LrPOnpkpGBR0wzxqr68g2m/LB2GxVYQroAjMJZRVM1Y4BCjCKc3vAamxSzOY2RP+w==} @@ -3923,6 +3973,10 @@ packages: resolution: {integrity: sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==} engines: {node: '>=8.6.0'} + fast-glob@3.3.3: + resolution: {integrity: sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==} + engines: {node: '>=8.6.0'} + fast-json-stable-stringify@2.1.0: resolution: {integrity: sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==} @@ -3980,6 +4034,10 @@ packages: resolution: {integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==} engines: {node: '>=8'} + fill-range@7.1.1: + resolution: {integrity: sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==} + engines: {node: '>=8'} + filter-obj@5.1.0: resolution: {integrity: sha512-qWeTREPoT7I0bifpPUXtxkZJ1XJzxWtfoWWkdVGqa+eCr3SHW/Ocp89o8vLvbUuQnadybJpjOKu4V+RwO6sGng==} engines: {node: '>=14.16'} @@ -5318,6 +5376,10 @@ packages: resolution: {integrity: sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==} engines: {node: '>=8.6'} + micromatch@4.0.8: + resolution: {integrity: sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==} + engines: {node: '>=8.6'} + miller-rabin@4.0.1: resolution: {integrity: sha512-115fLhvZVqWwHPbClyntxEVfVDfl9DLLTuJvq3g2O/Oxi8AiNouAHvDSzHS0viUJc+V5vm3eq91Xwqn9dp4jRA==} hasBin: true @@ -5686,6 +5748,9 @@ packages: resolution: {integrity: sha512-B5JU3cabzk8c67mRRd3ECmROafjYMXbuzlwtqdM8IbS8ktlTix8aFGb2bAGKrSRIlnfKwovGUUr72JUPyOb6kQ==} engines: {node: '>=0.10.0'} + oxc-transform@0.44.0: + resolution: {integrity: sha512-T9o8PWvhYCJWK25MD0qmAQTeIgMkD7NvCFzzqzdFSDHP03wh6B6yy+7nLn1Scw+TsT82QQaaaD5bRl/ATLaPdQ==} + p-finally@1.0.0: resolution: {integrity: sha512-LICb2p9CB7FS+0eR1oqWnHhp0FljGLZCWBE9aix0Uye9W8LTQPwMTYVGWQWIw9RdQiDg4+epXQODwIYJtSJaow==} engines: {node: '>=4'} @@ -8740,6 +8805,30 @@ snapshots: dependencies: '@octokit/openapi-types': 22.2.0 + '@oxc-transform/binding-darwin-arm64@0.44.0': + optional: true + + '@oxc-transform/binding-darwin-x64@0.44.0': + optional: true + + '@oxc-transform/binding-linux-arm64-gnu@0.44.0': + optional: true + + '@oxc-transform/binding-linux-arm64-musl@0.44.0': + optional: true + + '@oxc-transform/binding-linux-x64-gnu@0.44.0': + optional: true + + '@oxc-transform/binding-linux-x64-musl@0.44.0': + optional: true + + '@oxc-transform/binding-win32-arm64-msvc@0.44.0': + optional: true + + '@oxc-transform/binding-win32-x64-msvc@0.44.0': + optional: true + '@parcel/watcher-android-arm64@2.4.1': optional: true @@ -9609,7 +9698,7 @@ snapshots: '@typescript-eslint/types': 8.4.0 '@typescript-eslint/visitor-keys': 8.4.0 debug: 4.3.7(supports-color@6.1.0) - fast-glob: 3.3.2 + fast-glob: 3.3.3 is-glob: 4.0.3 minimatch: 9.0.5 semver: 7.6.3 @@ -10461,6 +10550,10 @@ snapshots: dependencies: fill-range: 7.0.1 + braces@3.0.3: + dependencies: + fill-range: 7.1.1 + brorand@1.1.0: {} browserify-aes@1.2.0: @@ -10542,7 +10635,7 @@ snapshots: '@jsdevtools/ez-spawn': 3.0.4 c12: 1.7.0 cac: 6.7.14 - fast-glob: 3.3.2 + fast-glob: 3.3.3 js-yaml: 4.1.0 prompts: 2.4.2 semver: 7.6.0 @@ -11642,6 +11735,14 @@ snapshots: merge2: 1.4.1 micromatch: 4.0.5 + fast-glob@3.3.3: + dependencies: + '@nodelib/fs.stat': 2.0.5 + '@nodelib/fs.walk': 1.2.8 + glob-parent: 5.1.2 + merge2: 1.4.1 + micromatch: 4.0.8 + fast-json-stable-stringify@2.1.0: {} fast-levenshtein@2.0.6: {} @@ -11696,6 +11797,10 @@ snapshots: dependencies: to-regex-range: 5.0.1 + fill-range@7.1.1: + dependencies: + to-regex-range: 5.0.1 + filter-obj@5.1.0: {} finalhandler@1.2.0(supports-color@6.1.0): @@ -12010,7 +12115,7 @@ snapshots: dependencies: array-union: 2.1.0 dir-glob: 3.0.1 - fast-glob: 3.3.2 + fast-glob: 3.3.3 ignore: 5.3.1 merge2: 1.4.1 slash: 3.0.0 @@ -12018,7 +12123,7 @@ snapshots: globby@14.0.1: dependencies: '@sindresorhus/merge-streams': 2.2.0 - fast-glob: 3.3.2 + fast-glob: 3.3.3 ignore: 5.3.1 path-type: 5.0.0 slash: 5.1.0 @@ -13234,6 +13339,11 @@ snapshots: braces: 3.0.2 picomatch: 2.3.1 + micromatch@4.0.8: + dependencies: + braces: 3.0.3 + picomatch: 2.3.1 + miller-rabin@4.0.1: dependencies: bn.js: 4.12.0 @@ -13625,6 +13735,17 @@ snapshots: os-homedir@1.0.2: {} + oxc-transform@0.44.0: + optionalDependencies: + '@oxc-transform/binding-darwin-arm64': 0.44.0 + '@oxc-transform/binding-darwin-x64': 0.44.0 + '@oxc-transform/binding-linux-arm64-gnu': 0.44.0 + '@oxc-transform/binding-linux-arm64-musl': 0.44.0 + '@oxc-transform/binding-linux-x64-gnu': 0.44.0 + '@oxc-transform/binding-linux-x64-musl': 0.44.0 + '@oxc-transform/binding-win32-arm64-msvc': 0.44.0 + '@oxc-transform/binding-win32-x64-msvc': 0.44.0 + p-finally@1.0.0: {} p-finally@2.0.1: {} diff --git a/scripts/build-rolldown.ts b/scripts/build-rolldown.ts index e8773dc5d..5062f76e5 100644 --- a/scripts/build-rolldown.ts +++ b/scripts/build-rolldown.ts @@ -112,7 +112,7 @@ async function main() { } if (buildTypes) { - // TODO: build types + await import('./build-types') } } diff --git a/scripts/build-types.ts b/scripts/build-types.ts new file mode 100644 index 000000000..a8049aacf --- /dev/null +++ b/scripts/build-types.ts @@ -0,0 +1,93 @@ +import { globSync } from 'fast-glob' +import { + existsSync, + mkdirSync, + readFileSync, + rmSync, + writeFileSync +} from 'node:fs' +import path from 'node:path' +import { fileURLToPath } from 'node:url' +import { isolatedDeclaration } from 'oxc-transform' + +const __dirname = fileURLToPath(new URL('.', import.meta.url)) + +if (existsSync(path.resolve(__dirname, '../temp/packages'))) { + rmSync(path.resolve(__dirname, '../temp/packages'), { recursive: true }) +} + +let errs = '' +let start = performance.now() +let count = 0 + +const IGNORES = [ + 'format-explorer', + 'size-check-core', + 'size-check-vue-i18n', + 'size-check-vue-i18n' +] + +for (const file of globSync( + path.resolve(__dirname, '../packages/*/src/**/*.ts') +)) { + for (const ignore of IGNORES) { + if (file.includes(ignore)) { + continue + } + } + + const ts = readFileSync(file, 'utf-8') + const dts = isolatedDeclaration(file, ts, { + sourcemap: false, + stripInternal: true + }) + if (dts.errors.length) { + dts.errors.forEach(err => { + // temporary workaround for https://github.com/oxc-project/oxc/issues/5668 + if (!err.message.includes('set value(_: S)')) { + console.error(err) + } + errs += err.message + '\n' + }) + } + + write(path.join('temp', file.replace(/\.ts$/, '.d.ts')), dts.code) + count++ +} + +console.log( + `\n${count} isolated dts files generated in ${(performance.now() - start).toFixed(2)}ms.` +) + +if (errs) { + write(path.join('temp', 'oxc-iso-decl-errors.txt'), errs) +} + +console.log('bundling dts with rollup-plugin-dts...') + +// bundle with rollup-plugin-dts +// const rollupConfigs = (await import('../rollup.dts.config.js')).default + +start = performance.now() + +// await Promise.all( +// rollupConfigs.map(c => +// rollup(c).then(bundle => { +// return bundle.write(c.output).then(() => { +// console.log(pc.gray('built: ') + pc.blue(c.output.file)) +// }) +// }), +// ), +// ) + +console.log( + `bundled dts generated in ${(performance.now() - start).toFixed(2)}ms.` +) + +function write(file: string, content: string) { + const dir = path.dirname(file) + if (!existsSync(dir)) { + mkdirSync(dir, { recursive: true }) + } + writeFileSync(file, content) +} From c1206607a9915b846742ed86813358b2c572efe4 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 6 Jan 2025 00:37:03 +0900 Subject: [PATCH 08/21] chore: drop unnecesary scripts --- package.json | 3 - pnpm-lock.yaml | 51 ---------------- scripts/bump.ts | 150 ------------------------------------------------ 3 files changed, 204 deletions(-) delete mode 100644 scripts/bump.ts diff --git a/package.json b/package.json index 2347c5297..610e6f9a9 100644 --- a/package.json +++ b/package.json @@ -96,7 +96,6 @@ "@swc/core": "^1.10.4", "@textlint-rule/textlint-rule-no-unmatched-pair": "^2.0.0", "@types/eslint": "^9.6.1", - "@types/js-yaml": "^4.0.5", "@types/jsdom": "^21.1.1", "@types/node": "^22.10.3", "@types/rc": "^1.2.4", @@ -113,8 +112,6 @@ "fixpack": "^4.0.0", "get-port-please": "^3.1.2", "globals": "^15.9.0", - "globby": "^14.0.1", - "js-yaml": "^4.1.0", "jsdom": "^24.0.0", "lint-staged": "^15.2.2", "listhen": "^1.7.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 568847e94..fd9c06b44 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -54,9 +54,6 @@ importers: '@types/eslint': specifier: ^9.6.1 version: 9.6.1 - '@types/js-yaml': - specifier: ^4.0.5 - version: 4.0.9 '@types/jsdom': specifier: ^21.1.1 version: 21.1.6 @@ -105,12 +102,6 @@ importers: globals: specifier: ^15.9.0 version: 15.9.0 - globby: - specifier: ^14.0.1 - version: 14.0.1 - js-yaml: - specifier: ^4.1.0 - version: 4.1.0 jsdom: specifier: ^24.0.0 version: 24.0.0 @@ -2062,10 +2053,6 @@ packages: resolution: {integrity: sha512-SME/vtXaJcnQ/HpeV6P82Egy+jThn11IKfwW8+/XVoRD0rmPHVTeKMtww1oWdVnMykzVPjmrDN9S8NBndPEHCQ==} engines: {node: '>=8'} - '@sindresorhus/merge-streams@2.2.0': - resolution: {integrity: sha512-UTce8mUwUW0RikMb/eseJ7ys0BRkZVFB86orHzrfW12ZmFtym5zua8joZ4L7okH2dDFHkcFjqnZ5GocWBXOFtA==} - engines: {node: '>=18'} - '@sindresorhus/merge-streams@4.0.0': resolution: {integrity: sha512-tlqY9xq5ukxTUZBmoOp+m61cqwQD5pHJtFY3Mn8CA8ps6yghLH/Hw8UPdqg4OLmFW3IFlcXnQNmo/dh8HzXYIQ==} engines: {node: '>=18'} @@ -2255,9 +2242,6 @@ packages: '@types/http-errors@2.0.4': resolution: {integrity: sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA==} - '@types/js-yaml@4.0.9': - resolution: {integrity: sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==} - '@types/jsdom@21.1.6': resolution: {integrity: sha512-/7kkMsC+/kMs7gAYmmBR9P0vGTnOoLhQhyhQJSlXGI5bzTHp6xdo0TtKWQAsz6pmSAeVqKSbqeyP6hytqr9FDw==} @@ -4313,10 +4297,6 @@ packages: resolution: {integrity: sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==} engines: {node: '>=10'} - globby@14.0.1: - resolution: {integrity: sha512-jOMLD2Z7MAhyG8aJpNOpmziMOP4rPLcc95oQPKXBazW82z+CEgPFBQvEpRUa1KeIMUJo4Wsm+q6uzO/Q/4BksQ==} - engines: {node: '>=18'} - globby@6.1.0: resolution: {integrity: sha512-KVbFv2TQtbzCoxAnfD6JcHZTYCzyliEaaeM/gH8qQdkKr5s0OP9scEgvdcngyk7AVdY6YVW/TJHd+lQ/Df3Daw==} engines: {node: '>=0.10.0'} @@ -5935,10 +5915,6 @@ packages: resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==} engines: {node: '>=8'} - path-type@5.0.0: - resolution: {integrity: sha512-5HviZNaZcfqP95rwpv+1HDgUamezbqdSYTyzjTvwtJSnIH+3vnbmWsItli8OFEndS984VT55M3jduxZbX351gg==} - engines: {node: '>=12'} - pathe@1.1.2: resolution: {integrity: sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ==} @@ -6634,10 +6610,6 @@ packages: resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==} engines: {node: '>=8'} - slash@5.1.0: - resolution: {integrity: sha512-ZA6oR3T/pEyuqwMgAKT0/hAv8oAXckzbkmR0UkUosQ+Mc4RxGoJkRmwHgHufaenlyAgE1Mxgpdcrf75y6XcnDg==} - engines: {node: '>=14.16'} - slice-ansi@0.0.4: resolution: {integrity: sha512-up04hB2hR92PgjpyU3y/eg91yIBILyjVY26NvvciY3EVVPjybkMszMpXQ9QAkcS3I5rtJBDLoTxxg+qvW8c7rw==} engines: {node: '>=0.10.0'} @@ -7293,10 +7265,6 @@ packages: unenv@1.9.0: resolution: {integrity: sha512-QKnFNznRxmbOF1hDgzpqrlIf6NC5sbZ2OJ+5Wl3OX8uM+LUJXbj4TXvLJCtwbPTmbMHCLIz6JLKNinNsMShK9g==} - unicorn-magic@0.1.0: - resolution: {integrity: sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ==} - engines: {node: '>=18'} - unified@8.4.2: resolution: {integrity: sha512-JCrmN13jI4+h9UAyKEoGcDZV+i1E7BLFuG7OsaDvTXI5P0qhHX+vZO/kOhz9jn8HGENDKbwSeB0nVOg4gVStGA==} @@ -9288,8 +9256,6 @@ snapshots: dependencies: execa: 2.1.0 - '@sindresorhus/merge-streams@2.2.0': {} - '@sindresorhus/merge-streams@4.0.0': {} '@stroncium/procfs@1.2.1': {} @@ -9563,8 +9529,6 @@ snapshots: '@types/http-errors@2.0.4': {} - '@types/js-yaml@4.0.9': {} - '@types/jsdom@21.1.6': dependencies: '@types/node': 22.10.3 @@ -12120,15 +12084,6 @@ snapshots: merge2: 1.4.1 slash: 3.0.0 - globby@14.0.1: - dependencies: - '@sindresorhus/merge-streams': 2.2.0 - fast-glob: 3.3.3 - ignore: 5.3.1 - path-type: 5.0.0 - slash: 5.1.0 - unicorn-magic: 0.1.0 - globby@6.1.0: dependencies: array-union: 1.0.2 @@ -13904,8 +13859,6 @@ snapshots: path-type@4.0.0: {} - path-type@5.0.0: {} - pathe@1.1.2: {} pathval@2.0.0: {} @@ -14759,8 +14712,6 @@ snapshots: slash@3.0.0: {} - slash@5.1.0: {} - slice-ansi@0.0.4: {} slice-ansi@4.0.0: @@ -15497,8 +15448,6 @@ snapshots: node-fetch-native: 1.6.2 pathe: 1.1.2 - unicorn-magic@0.1.0: {} - unified@8.4.2: dependencies: '@types/unist': 2.0.10 diff --git a/scripts/bump.ts b/scripts/bump.ts deleted file mode 100644 index 5c01a5ec7..000000000 --- a/scripts/bump.ts +++ /dev/null @@ -1,150 +0,0 @@ -import { promises as fs } from 'node:fs' -import { execSync } from 'node:child_process' -import { resolve, dirname } from 'node:path' -import { fileURLToPath } from 'node:url' -import { globby } from 'globby' -import yaml from 'js-yaml' - -const __dirname = dirname(fileURLToPath(new URL('.', import.meta.url))) - -type Deps = { - name: string - range: string - type: string -} -type DepsReviver = (deps: Deps) => Deps | void - -async function loadPackage(dir: string) { - const pkgPath = resolve(dir, 'package.json') - const data = JSON.parse(await fs.readFile(pkgPath, 'utf-8').catch(() => '{}')) - const save = () => fs.writeFile(pkgPath, JSON.stringify(data, null, 2) + '\n') - // const save = () => - // console.log(`package: ${dir}`, JSON.stringify(data, null, 2)) - - const updateDeps = (reviver: DepsReviver) => { - for (const type of [ - 'dependencies', - 'devDependencies', - 'optionalDependencies', - 'peerDependencies' - ]) { - if (!data[type]) { - continue - } - for (const e of Object.entries(data[type])) { - const dep = { name: e[0], range: e[1] as string, type } - delete data[type][dep.name] - const updated = reviver(dep) || dep - data[updated.type] = data[updated.type] || {} - data[updated.type][updated.name] = updated.range - } - } - } - - return { - dir, - data, - save, - updateDeps - } -} - -type ThenArg = T extends PromiseLike ? U : T -type Package = ThenArg> -type WorkspaceData = { - packages: string[] -} - -async function loadWorkspaceData(path: string): Promise { - const workspacesYaml = await fs.readFile(path, 'utf-8') - const data = (yaml.load(workspacesYaml) as WorkspaceData).packages - return Array.isArray(data) ? data : [] -} - -async function loadWorkspace(dir: string, workspaces?: string[]) { - const workspacePkg = await loadPackage(dir) - if (workspaces) { - workspacePkg.data.workspaces = [...workspaces] - } else { - const workspacesYaml = await loadWorkspaceData( - resolve(__dirname, './pnpm-workspace.yaml') - ) - workspacePkg.data.workspaces = [...workspacesYaml] - } - - const pkgDirs = await globby(workspacePkg.data.workspaces, { - onlyDirectories: true - }) - - const packages: Package[] = [] - - for (const pkgDir of pkgDirs) { - const pkg = await loadPackage(pkgDir) - if (!pkg.data.name) { - continue - } - packages.push(pkg) - } - - const find = (name: string) => { - const pkg = packages.find(pkg => pkg.data.name === name) - if (!pkg) { - throw new Error('Workspace package not found: ' + name) - } - return pkg - } - - const rename = (from: string, to: string) => { - find(from).data.name = to - for (const pkg of packages) { - pkg.updateDeps(dep => { - if (dep.name === from && !dep.range.startsWith('npm:')) { - dep.range = 'npm:' + to + '@' + dep.range - } - }) - } - } - - const setVersion = (name: string, newVersion: string) => { - find(name).data.version = newVersion - for (const pkg of packages.filter(p => !p.data.private)) { - pkg.updateDeps(dep => { - if (dep.name === name) { - dep.range = newVersion - } - }) - } - } - - const save = async () => Promise.all(packages.map(pkg => pkg.save())) - - return { - dir, - workspacePkg, - packages, - save, - find, - rename, - setVersion - } -} - -async function main() { - const workspace = await loadWorkspace(process.cwd(), ['packages/*']) - - const commit = execSync('git rev-parse --short HEAD').toString('utf-8').trim() - const release = `${workspace.workspacePkg.data.version}-${commit}` - - for (const pkg of workspace.packages.filter(p => !p.data.private)) { - workspace.setVersion(pkg.data.name, release) - const newname = pkg.data.name + '-nightly' - workspace.rename(pkg.data.name, newname) - } - - await workspace.save() -} - -main().catch(err => { - console.error(err) - process.exit(1) -}) From f3aefb66bdc2ea2e43e07073fc67227ef8ef1bd9 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 6 Jan 2025 11:59:49 +0900 Subject: [PATCH 09/21] fix: isolatedDeclaration build errors for oxc --- package.json | 2 +- packages/core-base/src/context.ts | 2 +- packages/core-base/src/datetime.ts | 2 +- packages/core-base/src/devtools.ts | 8 +- packages/core-base/src/errors.ts | 2 +- packages/core-base/src/fallbacker.ts | 2 +- packages/core-base/src/format.ts | 2 +- packages/core-base/src/number.ts | 2 +- packages/core-base/src/warnings.ts | 2 +- packages/format-explorer/src/theme.ts | 2 +- packages/message-compiler/src/errors.ts | 2 +- packages/message-compiler/src/mangler.ts | 2 +- packages/message-compiler/src/scanner.ts | 6 +- packages/shared/src/utils.ts | 13 +- packages/shared/src/warn.ts | 2 +- .../src/components/DatetimeFormat.ts | 84 +++---- .../src/components/NumberFormat.ts | 83 ++++--- .../src/components/Translation.ts | 110 ++++----- packages/vue-i18n-core/src/components/base.ts | 3 +- packages/vue-i18n-core/src/errors.ts | 6 +- packages/vue-i18n-core/src/misc.ts | 2 +- packages/vue-i18n-core/src/symbols.ts | 24 +- packages/vue-i18n-core/src/warnings.ts | 2 +- pnpm-lock.yaml | 210 +++++++++--------- scripts/build-types.ts | 4 +- 25 files changed, 296 insertions(+), 283 deletions(-) diff --git a/package.json b/package.json index 610e6f9a9..bb7530121 100644 --- a/package.json +++ b/package.json @@ -153,7 +153,7 @@ "trash-cli": "^6.0.0", "tslib": "^2.6.2", "tsx": "^4.11.2", - "typescript": "^5.5.3", + "typescript": "^5.6.3", "typescript-eslint": "^8.4.0", "vitepress": "1.5.0", "vitest": "^2.1.5", diff --git a/packages/core-base/src/context.ts b/packages/core-base/src/context.ts index dcfe923f3..4a49ea0a1 100644 --- a/packages/core-base/src/context.ts +++ b/packages/core-base/src/context.ts @@ -333,7 +333,7 @@ export interface CoreInternalContext { * Intlify core-base version * @internal */ -export const VERSION = __VERSION__ +export const VERSION: string = __VERSION__ export const NOT_REOSLVED = -1 diff --git a/packages/core-base/src/datetime.ts b/packages/core-base/src/datetime.ts index 9bd98f4c4..2ba5d145d 100644 --- a/packages/core-base/src/datetime.ts +++ b/packages/core-base/src/datetime.ts @@ -295,7 +295,7 @@ export function datetime< } /** @internal */ -export const DATETIME_FORMAT_OPTIONS_KEYS = [ +export const DATETIME_FORMAT_OPTIONS_KEYS: string[] = [ 'localeMatcher', 'weekday', 'era', diff --git a/packages/core-base/src/devtools.ts b/packages/core-base/src/devtools.ts index 20b0f26db..ababcdabd 100644 --- a/packages/core-base/src/devtools.ts +++ b/packages/core-base/src/devtools.ts @@ -30,10 +30,14 @@ export function initI18nDevTools( }) } -export const translateDevTools = +export const translateDevTools: ReturnType = /* #__PURE__*/ createDevToolsHook('function:translate') -function createDevToolsHook(hook: IntlifyDevToolsHooks) { +function createDevToolsHook( + hook: IntlifyDevToolsHooks +): ( + payloads: IntlifyDevToolsHookPayloads[IntlifyDevToolsHooks] +) => void | null { return (payloads: IntlifyDevToolsHookPayloads[IntlifyDevToolsHooks]) => devtools && devtools.emit(hook, payloads) } diff --git a/packages/core-base/src/errors.ts b/packages/core-base/src/errors.ts index d63ed43f9..2cbadfc83 100644 --- a/packages/core-base/src/errors.ts +++ b/packages/core-base/src/errors.ts @@ -8,7 +8,7 @@ import type { BaseError } from '@intlify/shared' export interface CoreError extends BaseError {} export const CoreErrorCodes = { - INVALID_ARGUMENT: COMPILE_ERROR_CODES_EXTEND_POINT, // 17 + INVALID_ARGUMENT: COMPILE_ERROR_CODES_EXTEND_POINT as number, // 17 INVALID_DATE_ARGUMENT: 18, INVALID_ISO_DATE_ARGUMENT: 19, NOT_SUPPORT_NON_STRING_MESSAGE: 20, diff --git a/packages/core-base/src/fallbacker.ts b/packages/core-base/src/fallbacker.ts index 4f9eeb3c6..67e9ba103 100644 --- a/packages/core-base/src/fallbacker.ts +++ b/packages/core-base/src/fallbacker.ts @@ -35,7 +35,7 @@ export function getLocale( let _resolveLocale: string /** @internal */ -export function resolveLocale(locale: Locale | LocaleDetector) { +export function resolveLocale(locale: Locale | LocaleDetector): string { if (isString(locale)) { return locale } else { diff --git a/packages/core-base/src/format.ts b/packages/core-base/src/format.ts index fba8eed02..95eb7f770 100644 --- a/packages/core-base/src/format.ts +++ b/packages/core-base/src/format.ts @@ -163,7 +163,7 @@ export function formatMessagePart( const PROPS_TYPE = ['t', 'type'] -export function resolveType(node: Node) { +export function resolveType(node: Node): ReturnType { return resolveProps(node, PROPS_TYPE) } diff --git a/packages/core-base/src/number.ts b/packages/core-base/src/number.ts index fb70d60b8..0ef5aea1b 100644 --- a/packages/core-base/src/number.ts +++ b/packages/core-base/src/number.ts @@ -290,7 +290,7 @@ export function number< } /** @internal */ -export const NUMBER_FORMAT_OPTIONS_KEYS = [ +export const NUMBER_FORMAT_OPTIONS_KEYS: string[] = [ 'localeMatcher', 'style', 'currency', diff --git a/packages/core-base/src/warnings.ts b/packages/core-base/src/warnings.ts index 8c53ec2ac..3b0e2adc1 100644 --- a/packages/core-base/src/warnings.ts +++ b/packages/core-base/src/warnings.ts @@ -10,7 +10,7 @@ export const CoreWarnCodes = { EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER: 7 } as const -export const CORE_WARN_CODES_EXTEND_POINT = 8 +export const CORE_WARN_CODES_EXTEND_POINT: number = 8 export type CoreWarnCodes = (typeof CoreWarnCodes)[keyof typeof CoreWarnCodes] diff --git a/packages/format-explorer/src/theme.ts b/packages/format-explorer/src/theme.ts index 99da1081a..9e1b2f67e 100644 --- a/packages/format-explorer/src/theme.ts +++ b/packages/format-explorer/src/theme.ts @@ -241,4 +241,4 @@ export default { 'editorCursor.foreground': '#AEAFAD', 'editorWhitespace.foreground': '#4B4E55' } -} +} as const diff --git a/packages/message-compiler/src/errors.ts b/packages/message-compiler/src/errors.ts index 07b711c44..ce64eb727 100644 --- a/packages/message-compiler/src/errors.ts +++ b/packages/message-compiler/src/errors.ts @@ -48,7 +48,7 @@ export const CompileErrorCodes = { // Special value for higher-order compilers to pick up the last code // to avoid collision of error codes. // This should always be kept as the last item. -export const COMPILE_ERROR_CODES_EXTEND_POINT = 17 +export const COMPILE_ERROR_CODES_EXTEND_POINT: number = 17 export type CompileErrorCodes = (typeof CompileErrorCodes)[keyof typeof CompileErrorCodes] diff --git a/packages/message-compiler/src/mangler.ts b/packages/message-compiler/src/mangler.ts index d8ab6189a..f23bd4265 100644 --- a/packages/message-compiler/src/mangler.ts +++ b/packages/message-compiler/src/mangler.ts @@ -19,7 +19,7 @@ const ERROR_DOMAIN = 'minifier' /* eslint-disable @typescript-eslint/no-explicit-any */ -export function mangle(node: Node) { +export function mangle(node: Node): void { node.t = node.type switch (node.type) { diff --git a/packages/message-compiler/src/scanner.ts b/packages/message-compiler/src/scanner.ts index 09496337d..bcd73a061 100644 --- a/packages/message-compiler/src/scanner.ts +++ b/packages/message-compiler/src/scanner.ts @@ -16,8 +16,10 @@ export interface Scanner { export const CHAR_SP = ' ' export const CHAR_CR = '\r' export const CHAR_LF = '\n' -export const CHAR_LS = String.fromCharCode(0x2028) -export const CHAR_PS = String.fromCharCode(0x2029) +export const CHAR_LS: ReturnType = + String.fromCharCode(0x2028) +export const CHAR_PS: ReturnType = + String.fromCharCode(0x2029) export function createScanner(str: string): Scanner { const _buf = str diff --git a/packages/shared/src/utils.ts b/packages/shared/src/utils.ts index f967df0cf..7323ca921 100644 --- a/packages/shared/src/utils.ts +++ b/packages/shared/src/utils.ts @@ -3,7 +3,7 @@ * written by kazuya kawaguchi */ -export const inBrowser = typeof window !== 'undefined' +export const inBrowser: boolean = typeof window !== 'undefined' export let mark: (tag: string) => void | undefined export let measure: ( @@ -79,7 +79,7 @@ export const isRegExp = (val: unknown): val is RegExp => export const isEmptyObject = (val: unknown): val is boolean => isPlainObject(val) && Object.keys(val).length === 0 -export const assign = Object.assign +export const assign: typeof Object.assign = Object.assign const _create = Object.create export const create = (obj: object | null = null): object => _create(obj) @@ -124,7 +124,7 @@ export function hasOwn(obj: object | Array, key: string): boolean { * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts */ -export const isArray = Array.isArray +export const isArray: typeof Array.isArray = Array.isArray export const isFunction = (val: unknown): val is Function => typeof val === 'function' export const isString = (val: unknown): val is string => typeof val === 'string' @@ -140,7 +140,8 @@ export const isPromise = (val: unknown): val is Promise => { return isObject(val) && isFunction(val.then) && isFunction(val.catch) } -export const objectToString = Object.prototype.toString +export const objectToString: typeof Object.prototype.toString = + Object.prototype.toString export const toTypeString = (value: unknown): string => objectToString.call(value) @@ -167,8 +168,8 @@ const RANGE = 2 export function generateCodeFrame( source: string, - start = 0, - end = source.length + start: number = 0, + end: number = source.length ): string { const lines = source.split(/\r?\n/) let count = 0 diff --git a/packages/shared/src/warn.ts b/packages/shared/src/warn.ts index 332be0018..771d8b091 100644 --- a/packages/shared/src/warn.ts +++ b/packages/shared/src/warn.ts @@ -10,7 +10,7 @@ export function warn(msg: string, err?: Error): void { const hasWarned: Record = {} -export function warnOnce(msg: string) { +export function warnOnce(msg: string): void { if (!hasWarned[msg]) { hasWarned[msg] = true warn(msg) diff --git a/packages/vue-i18n-core/src/components/DatetimeFormat.ts b/packages/vue-i18n-core/src/components/DatetimeFormat.ts index 1a98b6e80..f9cb9667f 100644 --- a/packages/vue-i18n-core/src/components/DatetimeFormat.ts +++ b/packages/vue-i18n-core/src/components/DatetimeFormat.ts @@ -3,11 +3,11 @@ import { assign } from '@intlify/shared' import { defineComponent } from 'vue' import { useI18n } from '../i18n' import { DatetimePartsSymbol } from '../symbols' -import { baseFormatProps } from './base' +import { BaseFormatPropsValidators } from './base' import { renderFormatter } from './formatRenderer' import type { DateTimeOptions } from '@intlify/core-base' -import type { VNodeProps } from 'vue' +import type { ComponentOptions, SetupContext, VNodeProps } from 'vue' import type { Composer, ComposerInternal } from '../composer' import type { BaseFormatProps } from './base' import type { FormattableProps } from './formatRenderer' @@ -22,47 +22,47 @@ export type DatetimeFormatProps = FormattableProps< Intl.DateTimeFormatOptions > -export const DatetimeFormatImpl = /* #__PURE__*/ defineComponent({ - /* eslint-disable */ - name: 'i18n-d', - props: assign( - { - value: { - type: [Number, Date], - required: true +// TODO: +export const DatetimeFormatImpl: ComponentOptions = + /* #__PURE__*/ defineComponent({ + name: 'i18n-d', // eslint-disable-line vue/component-definition-name-casing + props: /*#__PURE__*/ assign( + { + value: { + type: [Number, Date], + required: true + }, + format: { + type: [String, Object] + } }, - format: { - type: [String, Object] - } - }, - baseFormatProps - ), - /* eslint-enable */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - setup(props: any, context: any): any { - const i18n = - props.i18n || - (useI18n({ - useScope: props.scope as 'global' | 'parent', - __useComponent: true - }) as unknown as Composer & ComposerInternal) + BaseFormatPropsValidators + ), - return renderFormatter< - FormattableProps, - number | Date, - Intl.DateTimeFormatOptions, - DateTimeOptions, - Intl.DateTimeFormatPart - >( - props as DatetimeFormatProps, - context, - DATETIME_FORMAT_OPTIONS_KEYS, - (...args: unknown[]) => - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (i18n as any)[DatetimePartsSymbol](...args) - ) - } -}) + setup(props: DatetimeFormatProps, context: SetupContext) { + const i18n = + props.i18n || + (useI18n({ + useScope: props.scope as 'global' | 'parent', + __useComponent: true + }) as unknown as Composer & ComposerInternal) + + return renderFormatter< + FormattableProps, + number | Date, + Intl.DateTimeFormatOptions, + DateTimeOptions, + Intl.DateTimeFormatPart + >( + props as DatetimeFormatProps, + context, + DATETIME_FORMAT_OPTIONS_KEYS, + (...args: unknown[]) => + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (i18n as any)[DatetimePartsSymbol](...args) + ) + } + }) /** * Datetime Format Component @@ -87,4 +87,4 @@ export const DatetimeFormat = DatetimeFormatImpl as unknown as { } } -export const I18nD = DatetimeFormat +export const I18nD: typeof DatetimeFormat = DatetimeFormat diff --git a/packages/vue-i18n-core/src/components/NumberFormat.ts b/packages/vue-i18n-core/src/components/NumberFormat.ts index 75cf887af..65748fb0e 100644 --- a/packages/vue-i18n-core/src/components/NumberFormat.ts +++ b/packages/vue-i18n-core/src/components/NumberFormat.ts @@ -3,11 +3,11 @@ import { assign } from '@intlify/shared' import { defineComponent } from 'vue' import { useI18n } from '../i18n' import { NumberPartsSymbol } from '../symbols' -import { baseFormatProps } from './base' +import { BaseFormatPropsValidators } from './base' import { renderFormatter } from './formatRenderer' import type { NumberOptions } from '@intlify/core-base' -import type { VNodeProps } from 'vue' +import type { ComponentOptions, SetupContext, VNodeProps } from 'vue' import type { Composer, ComposerInternal } from '../composer' import type { BaseFormatProps } from './base' import type { FormattableProps } from './formatRenderer' @@ -22,47 +22,46 @@ export type NumberFormatProps = FormattableProps< Intl.NumberFormatOptions > -export const NumberFormatImpl = /*#__PURE__*/ defineComponent({ - /* eslint-disable */ - name: 'i18n-n', - props: assign( - { - value: { - type: Number, - required: true +// TODO: +export const NumberFormatImpl: ComponentOptions = + /*#__PURE__*/ defineComponent({ + name: 'i18n-n', // eslint-disable-line vue/component-definition-name-casing + props: /*#__PURE__*/ assign( + { + value: { + type: Number, + required: true + }, + format: { + type: [String, Object] + } }, - format: { - type: [String, Object] - } - }, - baseFormatProps - ), - /* eslint-enable */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - setup(props: any, context: any): any { - const i18n = - props.i18n || - (useI18n({ - useScope: props.scope as 'global' | 'parent', - __useComponent: true - }) as unknown as Composer & ComposerInternal) + BaseFormatPropsValidators + ), + setup(props: NumberFormatProps, context: SetupContext) { + const i18n = + props.i18n || + (useI18n({ + useScope: props.scope as 'global' | 'parent', + __useComponent: true + }) as unknown as Composer & ComposerInternal) - return renderFormatter< - FormattableProps, - number, - Intl.NumberFormatOptions, - NumberOptions, - Intl.NumberFormatPart - >( - props as NumberFormatProps, - context, - NUMBER_FORMAT_OPTIONS_KEYS, - (...args: unknown[]) => - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (i18n as any)[NumberPartsSymbol](...args) - ) - } -}) + return renderFormatter< + FormattableProps, + number, + Intl.NumberFormatOptions, + NumberOptions, + Intl.NumberFormatPart + >( + props as NumberFormatProps, + context, + NUMBER_FORMAT_OPTIONS_KEYS, + (...args: unknown[]) => + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (i18n as any)[NumberPartsSymbol](...args) + ) + } + }) /** * export the public type for h/tsx inference @@ -92,4 +91,4 @@ export const NumberFormat = NumberFormatImpl as unknown as { } } -export const I18nN = NumberFormat +export const I18nN: typeof NumberFormat = NumberFormat diff --git a/packages/vue-i18n-core/src/components/Translation.ts b/packages/vue-i18n-core/src/components/Translation.ts index bb11b3a94..661e925ed 100644 --- a/packages/vue-i18n-core/src/components/Translation.ts +++ b/packages/vue-i18n-core/src/components/Translation.ts @@ -2,11 +2,16 @@ import { assign, create, isNumber, isObject, isString } from '@intlify/shared' import { defineComponent, h } from 'vue' import { useI18n } from '../i18n' import { TranslateVNodeSymbol } from '../symbols' -import { baseFormatProps } from './base' +import { BaseFormatPropsValidators } from './base' import { getFragmentableTag, getInterpolateArg } from './utils' import type { TranslateOptions } from '@intlify/core-base' -import type { VNodeChild, VNodeProps } from 'vue' +import type { + ComponentOptions, + SetupContext, + VNodeChild, + VNodeProps +} from 'vue' import type { Composer, ComposerInternal } from '../composer' import type { BaseFormatProps } from './base' @@ -28,60 +33,59 @@ export interface TranslationProps extends BaseFormatProps { plural?: number | string } -export const TranslationImpl = /*#__PURE__*/ defineComponent({ - /* eslint-disable */ - name: 'i18n-t', - props: assign( - { - keypath: { - type: String, - required: true +export const TranslationImpl: ComponentOptions = + /*#__PURE__*/ defineComponent({ + name: 'i18n-t', // eslint-disable-line vue/component-definition-name-casing + props: /*#__PURE__*/ assign( + {}, + { + keypath: { + type: String, + required: true + }, + plural: { + type: [Number, String], + // eslint-disable-next-line @typescript-eslint/no-explicit-any + validator: (val: any): boolean => isNumber(val) || !isNaN(val) + } }, - plural: { - type: [Number, String], + BaseFormatPropsValidators + ), + setup(props: TranslationProps, context: SetupContext) { + const { slots, attrs } = context + // NOTE: avoid https://github.com/microsoft/rushstack/issues/1050 + const i18n = + props.i18n || + (useI18n({ + useScope: props.scope as 'global' | 'parent', + __useComponent: true + }) as unknown as Composer & ComposerInternal) - validator: (val: any): boolean => isNumber(val) || !isNaN(val) + return (): VNodeChild => { + const keys = Object.keys(slots).filter(key => key !== '_') + const options = create() as TranslateOptions + if (props.locale) { + options.locale = props.locale + } + if (props.plural !== undefined) { + options.plural = isString(props.plural) ? +props.plural : props.plural + } + const arg = getInterpolateArg(context, keys) + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const children = (i18n as any)[TranslateVNodeSymbol]( + props.keypath, + arg, + options + ) + const assignedAttrs = assign(create(), attrs) + const tag = + isString(props.tag) || isObject(props.tag) + ? props.tag + : getFragmentableTag() + return h(tag, assignedAttrs, children) } - }, - baseFormatProps - ), - /* eslint-enable */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - setup(props: any, context: any): any { - const { slots, attrs } = context - // NOTE: avoid https://github.com/microsoft/rushstack/issues/1050 - const i18n = - props.i18n || - (useI18n({ - useScope: props.scope as 'global' | 'parent', - __useComponent: true - }) as unknown as Composer & ComposerInternal) - - return (): VNodeChild => { - const keys = Object.keys(slots).filter(key => key !== '_') - const options = create() as TranslateOptions - if (props.locale) { - options.locale = props.locale - } - if (props.plural !== undefined) { - options.plural = isString(props.plural) ? +props.plural : props.plural - } - const arg = getInterpolateArg(context, keys) - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const children = (i18n as any)[TranslateVNodeSymbol]( - props.keypath, - arg, - options - ) - const assignedAttrs = assign(create(), attrs) - const tag = - isString(props.tag) || isObject(props.tag) - ? props.tag - : getFragmentableTag() - return h(tag, assignedAttrs, children) } - } -}) + }) /** * export the public type for h/tsx inference @@ -143,4 +147,4 @@ export const Translation = TranslationImpl as unknown as { } } -export const I18nT = Translation +export const I18nT: typeof Translation = Translation diff --git a/packages/vue-i18n-core/src/components/base.ts b/packages/vue-i18n-core/src/components/base.ts index 40ed4c40f..776ee9be1 100644 --- a/packages/vue-i18n-core/src/components/base.ts +++ b/packages/vue-i18n-core/src/components/base.ts @@ -48,7 +48,8 @@ export interface BaseFormatProps { i18n?: Composer } -export const baseFormatProps = { +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export const BaseFormatPropsValidators: Record = { tag: { type: [String, Object] }, diff --git a/packages/vue-i18n-core/src/errors.ts b/packages/vue-i18n-core/src/errors.ts index c9cc541b1..961d62c9b 100644 --- a/packages/vue-i18n-core/src/errors.ts +++ b/packages/vue-i18n-core/src/errors.ts @@ -1,6 +1,6 @@ import { - createCompileError, - CORE_ERROR_CODES_EXTEND_POINT + CORE_ERROR_CODES_EXTEND_POINT, + createCompileError } from '@intlify/core-base' import type { BaseError } from '@intlify/shared' @@ -9,7 +9,7 @@ export interface I18nError extends BaseError {} export const I18nErrorCodes = { // composer module errors - UNEXPECTED_RETURN_TYPE: CORE_ERROR_CODES_EXTEND_POINT, // 24 + UNEXPECTED_RETURN_TYPE: CORE_ERROR_CODES_EXTEND_POINT as number, // 24 // legacy module errors INVALID_ARGUMENT: 25, // i18n module errors diff --git a/packages/vue-i18n-core/src/misc.ts b/packages/vue-i18n-core/src/misc.ts index fb4af9b94..9668b3328 100644 --- a/packages/vue-i18n-core/src/misc.ts +++ b/packages/vue-i18n-core/src/misc.ts @@ -8,7 +8,7 @@ import { getGlobalThis } from '@intlify/shared' * * @VueI18nGeneral */ -export const VERSION = __VERSION__ +export const VERSION: string = __VERSION__ /** * This is only called in esm-bundler builds. diff --git a/packages/vue-i18n-core/src/symbols.ts b/packages/vue-i18n-core/src/symbols.ts index 6f93a04dc..c1c7b8f3f 100644 --- a/packages/vue-i18n-core/src/symbols.ts +++ b/packages/vue-i18n-core/src/symbols.ts @@ -1,14 +1,18 @@ import { makeSymbol } from '@intlify/shared' -export const TranslateVNodeSymbol = +export const TranslateVNodeSymbol: symbol = /* #__PURE__*/ makeSymbol('__translateVNode') -export const DatetimePartsSymbol = /* #__PURE__*/ makeSymbol('__datetimeParts') -export const NumberPartsSymbol = /* #__PURE__*/ makeSymbol('__numberParts') -export const EnableEmitter = /* #__PURE__*/ makeSymbol('__enableEmitter') -export const DisableEmitter = /* #__PURE__*/ makeSymbol('__disableEmitter') -export const SetPluralRulesSymbol = makeSymbol('__setPluralRules') -export const DevToolsMetaSymbol = makeSymbol('__intlifyMeta') -export const InejctWithOptionSymbol = +export const DatetimePartsSymbol: symbol = + /* #__PURE__*/ makeSymbol('__datetimeParts') +export const NumberPartsSymbol: symbol = + /* #__PURE__*/ makeSymbol('__numberParts') +export const EnableEmitter: symbol = + /* #__PURE__*/ makeSymbol('__enableEmitter') +export const DisableEmitter: symbol = + /* #__PURE__*/ makeSymbol('__disableEmitter') +export const SetPluralRulesSymbol: symbol = makeSymbol('__setPluralRules') +export const DevToolsMetaSymbol: symbol = makeSymbol('__intlifyMeta') +export const InejctWithOptionSymbol: symbol = /* #__PURE__*/ makeSymbol('__injectWithOption') -export const ExtendSymbol = /* #__PURE__*/ makeSymbol('__extend') -export const DisposeSymbol = /* #__PURE__*/ makeSymbol('__dispose') +export const ExtendSymbol: symbol = /* #__PURE__*/ makeSymbol('__extend') +export const DisposeSymbol: symbol = /* #__PURE__*/ makeSymbol('__dispose') diff --git a/packages/vue-i18n-core/src/warnings.ts b/packages/vue-i18n-core/src/warnings.ts index 5cea1f658..9bdd104a7 100644 --- a/packages/vue-i18n-core/src/warnings.ts +++ b/packages/vue-i18n-core/src/warnings.ts @@ -2,7 +2,7 @@ import { CORE_WARN_CODES_EXTEND_POINT } from '@intlify/core-base' import { format } from '@intlify/shared' export const I18nWarnCodes = { - FALLBACK_TO_ROOT: CORE_WARN_CODES_EXTEND_POINT, // 8 + FALLBACK_TO_ROOT: CORE_WARN_CODES_EXTEND_POINT as number, // 8 NOT_FOUND_PARENT_SCOPE: 9, IGNORE_OBJ_FLATTEN: 10, /** diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fd9c06b44..bec6d267f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -158,7 +158,7 @@ importers: version: 1.4.0 rollup-plugin-typescript2: specifier: ^0.36.0 - version: 0.36.0(rollup@4.22.4)(typescript@5.5.4) + version: 0.36.0(rollup@4.22.4)(typescript@5.7.2) secretlint: specifier: ^3.2.0 version: 3.3.0 @@ -226,20 +226,20 @@ importers: specifier: ^4.11.2 version: 4.11.2 typescript: - specifier: ^5.5.3 - version: 5.5.4 + specifier: ^5.6.3 + version: 5.7.2 typescript-eslint: specifier: ^8.4.0 - version: 8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.5.4) + version: 8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.7.2) vitepress: specifier: 1.5.0 - version: 1.5.0(@algolia/client-search@4.23.2)(@types/node@22.10.3)(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.5.4)))(jiti@1.21.0)(postcss@8.4.49)(search-insights@2.13.0)(terser@5.27.0)(tsx@4.11.2)(typescript@5.5.4)(yaml@2.3.4) + version: 1.5.0(@algolia/client-search@4.23.2)(@types/node@22.10.3)(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.7.2)))(jiti@1.21.0)(postcss@8.4.49)(search-insights@2.13.0)(terser@5.27.0)(tsx@4.11.2)(typescript@5.7.2)(yaml@2.3.4) vitest: specifier: ^2.1.5 version: 2.1.5(@types/node@22.10.3)(jiti@1.21.0)(jsdom@24.0.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4) vue: specifier: 3.5.13 - version: 3.5.13(typescript@5.5.4) + version: 3.5.13(typescript@5.7.2) vue-i18n: specifier: workspace:* version: link:packages/vue-i18n @@ -325,17 +325,17 @@ importers: dependencies: vue: specifier: 3.5.13 - version: 3.5.13(typescript@5.5.4) + version: 3.5.13(typescript@5.7.2) vue-i18n: specifier: workspace:* version: link:../../../packages/vue-i18n vue-router: specifier: ^4.0.5 - version: 4.2.5(vue@3.5.13(typescript@5.5.4)) + version: 4.2.5(vue@3.5.13(typescript@5.7.2)) devDependencies: '@intlify/vue-i18n-loader': specifier: ^3.2.0 - version: 3.3.0(vue@3.5.13(typescript@5.5.4)) + version: 3.3.0(vue@3.5.13(typescript@5.7.2)) '@vue/compiler-sfc': specifier: ^3.2.0 version: 3.4.19 @@ -353,7 +353,7 @@ importers: version: 4.1.1(file-loader@6.2.0(webpack@4.47.0(webpack-cli@3.3.12)))(webpack@4.47.0(webpack-cli@3.3.12)) vue-loader: specifier: ^16.8.0 - version: 16.8.3(@vue/compiler-sfc@3.4.19)(vue@3.5.13(typescript@5.5.4))(webpack@4.47.0(webpack-cli@3.3.12)) + version: 16.8.3(@vue/compiler-sfc@3.4.19)(vue@3.5.13(typescript@5.7.2))(webpack@4.47.0(webpack-cli@3.3.12)) webpack: specifier: ^4.44.0 version: 4.47.0(webpack-cli@3.3.12) @@ -397,17 +397,17 @@ importers: dependencies: vue: specifier: 3.5.13 - version: 3.5.13(typescript@5.5.4) + version: 3.5.13(typescript@5.7.2) vue-i18n: specifier: workspace:* version: link:../../packages/vue-i18n devDependencies: '@vitejs/plugin-vue': specifier: ^4.2.3 - version: 4.6.2(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.5.4)) + version: 4.6.2(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.7.2)) '@vitejs/plugin-vue-jsx': specifier: ^3.0.2 - version: 3.1.0(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.5.4)) + version: 3.1.0(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.7.2)) '@vue/compiler-sfc': specifier: ^3.3.4 version: 3.4.19 @@ -416,7 +416,7 @@ importers: version: 6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4) vue-tsc: specifier: ^1.8.5 - version: 1.8.27(typescript@5.5.4) + version: 1.8.27(typescript@5.7.2) examples/type-safe/global-type-definition: dependencies: @@ -534,11 +534,11 @@ importers: version: 1.0.2 vue: specifier: 3.5.13 - version: 3.5.13(typescript@5.5.4) + version: 3.5.13(typescript@5.7.2) devDependencies: '@vitejs/plugin-vue': specifier: ^5.0.0 - version: 5.0.4(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.5.4)) + version: 5.0.4(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.7.2)) '@vue/compiler-sfc': specifier: ^3.3.4 version: 3.4.19 @@ -547,7 +547,7 @@ importers: version: 6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4) vue-tsc: specifier: ^2.0.0 - version: 2.0.0(typescript@5.5.4) + version: 2.0.0(typescript@5.7.2) packages/message-compiler: dependencies: @@ -571,7 +571,7 @@ importers: version: 6.5.1 vue: specifier: 3.5.13 - version: 3.5.13(typescript@5.5.4) + version: 3.5.13(typescript@5.7.2) devDependencies: '@intlify/devtools-types': specifier: workspace:* @@ -596,11 +596,11 @@ importers: version: link:../petite-vue-i18n vue: specifier: 3.5.13 - version: 3.5.13(typescript@5.5.4) + version: 3.5.13(typescript@5.7.2) devDependencies: '@vitejs/plugin-vue': specifier: ^5.0.0 - version: 5.0.4(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.5.4)) + version: 5.0.4(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.7.2)) '@vue/compiler-sfc': specifier: ^3.3.4 version: 3.4.19 @@ -609,20 +609,20 @@ importers: version: 6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4) vue-tsc: specifier: ^2.0.0 - version: 2.0.0(typescript@5.5.4) + version: 2.0.0(typescript@5.7.2) packages/size-check-vue-i18n: dependencies: vue: specifier: 3.5.13 - version: 3.5.13(typescript@5.5.4) + version: 3.5.13(typescript@5.7.2) vue-i18n: specifier: workspace:* version: link:../vue-i18n devDependencies: '@vitejs/plugin-vue': specifier: ^5.0.0 - version: 5.0.4(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.5.4)) + version: 5.0.4(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.7.2)) '@vue/compiler-sfc': specifier: ^3.3.4 version: 3.4.19 @@ -631,7 +631,7 @@ importers: version: 6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4) vue-tsc: specifier: ^2.0.0 - version: 2.0.0(typescript@5.5.4) + version: 2.0.0(typescript@5.7.2) packages/vue-i18n: dependencies: @@ -646,7 +646,7 @@ importers: version: 6.5.1 vue: specifier: 3.5.13 - version: 3.5.13(typescript@5.5.4) + version: 3.5.13(typescript@5.7.2) devDependencies: '@intlify/devtools-types': specifier: workspace:* @@ -665,7 +665,7 @@ importers: version: 6.5.1 vue: specifier: 3.5.13 - version: 3.5.13(typescript@5.5.4) + version: 3.5.13(typescript@5.7.2) devDependencies: '@intlify/devtools-types': specifier: workspace:* @@ -7235,8 +7235,8 @@ packages: engines: {node: '>=14.17'} hasBin: true - typescript@5.5.4: - resolution: {integrity: sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==} + typescript@5.7.2: + resolution: {integrity: sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==} engines: {node: '>=14.17'} hasBin: true @@ -8571,14 +8571,14 @@ snapshots: - rollup - supports-color - '@intlify/vue-i18n-loader@3.3.0(vue@3.5.13(typescript@5.5.4))': + '@intlify/vue-i18n-loader@3.3.0(vue@3.5.13(typescript@5.7.2))': dependencies: '@intlify/bundle-utils': 1.0.0 '@intlify/shared': 9.11.0 js-yaml: 4.1.0 json5: 2.2.3 loader-utils: 2.0.4 - vue: 3.5.13(typescript@5.5.4) + vue: 3.5.13(typescript@5.7.2) '@isaacs/cliui@8.0.2': dependencies: @@ -9607,34 +9607,34 @@ snapshots: '@types/web-bluetooth@0.0.20': {} - '@typescript-eslint/eslint-plugin@8.4.0(@typescript-eslint/parser@8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.5.4))(eslint@9.9.1(jiti@1.21.0))(typescript@5.5.4)': + '@typescript-eslint/eslint-plugin@8.4.0(@typescript-eslint/parser@8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.7.2))(eslint@9.9.1(jiti@1.21.0))(typescript@5.7.2)': dependencies: '@eslint-community/regexpp': 4.10.0 - '@typescript-eslint/parser': 8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.5.4) + '@typescript-eslint/parser': 8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.7.2) '@typescript-eslint/scope-manager': 8.4.0 - '@typescript-eslint/type-utils': 8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.5.4) - '@typescript-eslint/utils': 8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.5.4) + '@typescript-eslint/type-utils': 8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.7.2) + '@typescript-eslint/utils': 8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.7.2) '@typescript-eslint/visitor-keys': 8.4.0 eslint: 9.9.1(jiti@1.21.0) graphemer: 1.4.0 ignore: 5.3.1 natural-compare: 1.4.0 - ts-api-utils: 1.3.0(typescript@5.5.4) + ts-api-utils: 1.3.0(typescript@5.7.2) optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.2 transitivePeerDependencies: - supports-color - '@typescript-eslint/parser@8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.5.4)': + '@typescript-eslint/parser@8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.7.2)': dependencies: '@typescript-eslint/scope-manager': 8.4.0 '@typescript-eslint/types': 8.4.0 - '@typescript-eslint/typescript-estree': 8.4.0(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 8.4.0(typescript@5.7.2) '@typescript-eslint/visitor-keys': 8.4.0 debug: 4.3.7(supports-color@6.1.0) eslint: 9.9.1(jiti@1.21.0) optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.2 transitivePeerDependencies: - supports-color @@ -9643,21 +9643,21 @@ snapshots: '@typescript-eslint/types': 8.4.0 '@typescript-eslint/visitor-keys': 8.4.0 - '@typescript-eslint/type-utils@8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.5.4)': + '@typescript-eslint/type-utils@8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.7.2)': dependencies: - '@typescript-eslint/typescript-estree': 8.4.0(typescript@5.5.4) - '@typescript-eslint/utils': 8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 8.4.0(typescript@5.7.2) + '@typescript-eslint/utils': 8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.7.2) debug: 4.3.7(supports-color@6.1.0) - ts-api-utils: 1.3.0(typescript@5.5.4) + ts-api-utils: 1.3.0(typescript@5.7.2) optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.2 transitivePeerDependencies: - eslint - supports-color '@typescript-eslint/types@8.4.0': {} - '@typescript-eslint/typescript-estree@8.4.0(typescript@5.5.4)': + '@typescript-eslint/typescript-estree@8.4.0(typescript@5.7.2)': dependencies: '@typescript-eslint/types': 8.4.0 '@typescript-eslint/visitor-keys': 8.4.0 @@ -9666,18 +9666,18 @@ snapshots: is-glob: 4.0.3 minimatch: 9.0.5 semver: 7.6.3 - ts-api-utils: 1.3.0(typescript@5.5.4) + ts-api-utils: 1.3.0(typescript@5.7.2) optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.2 transitivePeerDependencies: - supports-color - '@typescript-eslint/utils@8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.5.4)': + '@typescript-eslint/utils@8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.7.2)': dependencies: '@eslint-community/eslint-utils': 4.4.0(eslint@9.9.1(jiti@1.21.0)) '@typescript-eslint/scope-manager': 8.4.0 '@typescript-eslint/types': 8.4.0 - '@typescript-eslint/typescript-estree': 8.4.0(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 8.4.0(typescript@5.7.2) eslint: 9.9.1(jiti@1.21.0) transitivePeerDependencies: - supports-color @@ -9690,13 +9690,13 @@ snapshots: '@ungap/structured-clone@1.2.0': {} - '@vitejs/plugin-vue-jsx@3.1.0(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.5.4))': + '@vitejs/plugin-vue-jsx@3.1.0(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.7.2))': dependencies: '@babel/core': 7.23.9 '@babel/plugin-transform-typescript': 7.23.6(@babel/core@7.23.9) '@vue/babel-plugin-jsx': 1.2.1(@babel/core@7.23.9) vite: 6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4) - vue: 3.5.13(typescript@5.5.4) + vue: 3.5.13(typescript@5.7.2) transitivePeerDependencies: - supports-color @@ -9705,20 +9705,20 @@ snapshots: vite: 6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4) vue: 3.5.13(typescript@5.3.3) - '@vitejs/plugin-vue@4.6.2(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.5.4))': + '@vitejs/plugin-vue@4.6.2(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.7.2))': dependencies: vite: 6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4) - vue: 3.5.13(typescript@5.5.4) + vue: 3.5.13(typescript@5.7.2) - '@vitejs/plugin-vue@5.0.4(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.5.4))': + '@vitejs/plugin-vue@5.0.4(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.7.2))': dependencies: vite: 6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4) - vue: 3.5.13(typescript@5.5.4) + vue: 3.5.13(typescript@5.7.2) - '@vitejs/plugin-vue@5.1.4(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.5.4))': + '@vitejs/plugin-vue@5.1.4(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.7.2))': dependencies: vite: 6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4) - vue: 3.5.13(typescript@5.5.4) + vue: 3.5.13(typescript@5.7.2) '@vitest/coverage-v8@2.1.5(vitest@2.1.5(@types/node@22.10.3)(jiti@1.21.0)(jsdom@24.0.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))': dependencies: @@ -9923,9 +9923,9 @@ snapshots: '@vue/compiler-dom': 3.5.13 '@vue/shared': 3.5.13 - '@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.5.4))': + '@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.7.2))': dependencies: - vue: 3.5.13(typescript@5.5.4) + vue: 3.5.13(typescript@5.7.2) optional: true '@vue/devtools-api@6.5.1': {} @@ -9965,7 +9965,7 @@ snapshots: optionalDependencies: typescript: 5.3.3 - '@vue/language-core@1.8.27(typescript@5.5.4)': + '@vue/language-core@1.8.27(typescript@5.7.2)': dependencies: '@volar/language-core': 1.11.1 '@volar/source-map': 1.11.1 @@ -9977,9 +9977,9 @@ snapshots: path-browserify: 1.0.1 vue-template-compiler: 2.7.16 optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.2 - '@vue/language-core@2.0.0(typescript@5.5.4)': + '@vue/language-core@2.0.0(typescript@5.7.2)': dependencies: '@volar/language-core': 2.1.0 '@vue/compiler-dom': 3.5.12 @@ -9989,7 +9989,7 @@ snapshots: path-browserify: 1.0.1 vue-template-compiler: 2.7.16 optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.2 '@vue/reactivity@3.5.13': dependencies: @@ -10013,11 +10013,11 @@ snapshots: '@vue/shared': 3.5.13 vue: 3.5.13(typescript@5.3.3) - '@vue/server-renderer@3.5.13(vue@3.5.13(typescript@5.5.4))': + '@vue/server-renderer@3.5.13(vue@3.5.13(typescript@5.7.2))': dependencies: '@vue/compiler-ssr': 3.5.13 '@vue/shared': 3.5.13 - vue: 3.5.13(typescript@5.5.4) + vue: 3.5.13(typescript@5.7.2) '@vue/shared@3.4.19': {} @@ -10025,21 +10025,21 @@ snapshots: '@vue/shared@3.5.13': {} - '@vueuse/core@11.1.0(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.5.4)))(vue@3.5.13(typescript@5.5.4))': + '@vueuse/core@11.1.0(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.7.2)))(vue@3.5.13(typescript@5.7.2))': dependencies: '@types/web-bluetooth': 0.0.20 '@vueuse/metadata': 11.1.0 - '@vueuse/shared': 11.1.0(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.5.4)))(vue@3.5.13(typescript@5.5.4)) - vue-demi: 0.14.10(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.5.4)))(vue@3.5.13(typescript@5.5.4)) + '@vueuse/shared': 11.1.0(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.7.2)))(vue@3.5.13(typescript@5.7.2)) + vue-demi: 0.14.10(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.7.2)))(vue@3.5.13(typescript@5.7.2)) transitivePeerDependencies: - '@vue/composition-api' - vue - '@vueuse/integrations@11.1.0(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.5.4)))(focus-trap@7.6.0)(vue@3.5.13(typescript@5.5.4))': + '@vueuse/integrations@11.1.0(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.7.2)))(focus-trap@7.6.0)(vue@3.5.13(typescript@5.7.2))': dependencies: - '@vueuse/core': 11.1.0(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.5.4)))(vue@3.5.13(typescript@5.5.4)) - '@vueuse/shared': 11.1.0(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.5.4)))(vue@3.5.13(typescript@5.5.4)) - vue-demi: 0.14.10(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.5.4)))(vue@3.5.13(typescript@5.5.4)) + '@vueuse/core': 11.1.0(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.7.2)))(vue@3.5.13(typescript@5.7.2)) + '@vueuse/shared': 11.1.0(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.7.2)))(vue@3.5.13(typescript@5.7.2)) + vue-demi: 0.14.10(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.7.2)))(vue@3.5.13(typescript@5.7.2)) optionalDependencies: focus-trap: 7.6.0 transitivePeerDependencies: @@ -10048,9 +10048,9 @@ snapshots: '@vueuse/metadata@11.1.0': {} - '@vueuse/shared@11.1.0(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.5.4)))(vue@3.5.13(typescript@5.5.4))': + '@vueuse/shared@11.1.0(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.7.2)))(vue@3.5.13(typescript@5.7.2))': dependencies: - vue-demi: 0.14.10(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.5.4)))(vue@3.5.13(typescript@5.5.4)) + vue-demi: 0.14.10(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.7.2)))(vue@3.5.13(typescript@5.7.2)) transitivePeerDependencies: - '@vue/composition-api' - vue @@ -14400,7 +14400,7 @@ snapshots: process-es6: 0.11.6 rollup-pluginutils: 2.8.2 - rollup-plugin-typescript2@0.36.0(rollup@4.22.4)(typescript@5.5.4): + rollup-plugin-typescript2@0.36.0(rollup@4.22.4)(typescript@5.7.2): dependencies: '@rollup/pluginutils': 4.2.1 find-cache-dir: 3.3.2 @@ -14408,7 +14408,7 @@ snapshots: rollup: 4.22.4 semver: 7.6.0 tslib: 2.6.2 - typescript: 5.5.4 + typescript: 5.7.2 rollup-pluginutils@2.8.2: dependencies: @@ -15333,9 +15333,9 @@ snapshots: try-resolve@1.0.1: {} - ts-api-utils@1.3.0(typescript@5.5.4): + ts-api-utils@1.3.0(typescript@5.7.2): dependencies: - typescript: 5.5.4 + typescript: 5.7.2 tslib@2.6.2: {} @@ -15404,13 +15404,13 @@ snapshots: typedarray@0.0.6: {} - typescript-eslint@8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.5.4): + typescript-eslint@8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.7.2): dependencies: - '@typescript-eslint/eslint-plugin': 8.4.0(@typescript-eslint/parser@8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.5.4))(eslint@9.9.1(jiti@1.21.0))(typescript@5.5.4) - '@typescript-eslint/parser': 8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.5.4) - '@typescript-eslint/utils': 8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.5.4) + '@typescript-eslint/eslint-plugin': 8.4.0(@typescript-eslint/parser@8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.7.2))(eslint@9.9.1(jiti@1.21.0))(typescript@5.7.2) + '@typescript-eslint/parser': 8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.7.2) + '@typescript-eslint/utils': 8.4.0(eslint@9.9.1(jiti@1.21.0))(typescript@5.7.2) optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.2 transitivePeerDependencies: - eslint - supports-color @@ -15419,7 +15419,7 @@ snapshots: typescript@5.3.3: {} - typescript@5.5.4: {} + typescript@5.7.2: {} ufo@1.4.0: {} @@ -15692,7 +15692,7 @@ snapshots: tsx: 4.11.2 yaml: 2.3.4 - vitepress@1.5.0(@algolia/client-search@4.23.2)(@types/node@22.10.3)(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.5.4)))(jiti@1.21.0)(postcss@8.4.49)(search-insights@2.13.0)(terser@5.27.0)(tsx@4.11.2)(typescript@5.5.4)(yaml@2.3.4): + vitepress@1.5.0(@algolia/client-search@4.23.2)(@types/node@22.10.3)(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.7.2)))(jiti@1.21.0)(postcss@8.4.49)(search-insights@2.13.0)(terser@5.27.0)(tsx@4.11.2)(typescript@5.7.2)(yaml@2.3.4): dependencies: '@docsearch/css': 3.6.2 '@docsearch/js': 3.6.2(@algolia/client-search@4.23.2)(search-insights@2.13.0) @@ -15701,17 +15701,17 @@ snapshots: '@shikijs/transformers': 1.22.2 '@shikijs/types': 1.22.2 '@types/markdown-it': 14.1.2 - '@vitejs/plugin-vue': 5.1.4(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.5.4)) + '@vitejs/plugin-vue': 5.1.4(vite@6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4))(vue@3.5.13(typescript@5.7.2)) '@vue/devtools-api': 7.6.3 '@vue/shared': 3.5.12 - '@vueuse/core': 11.1.0(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.5.4)))(vue@3.5.13(typescript@5.5.4)) - '@vueuse/integrations': 11.1.0(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.5.4)))(focus-trap@7.6.0)(vue@3.5.13(typescript@5.5.4)) + '@vueuse/core': 11.1.0(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.7.2)))(vue@3.5.13(typescript@5.7.2)) + '@vueuse/integrations': 11.1.0(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.7.2)))(focus-trap@7.6.0)(vue@3.5.13(typescript@5.7.2)) focus-trap: 7.6.0 mark.js: 8.11.1 minisearch: 7.1.0 shiki: 1.22.2 vite: 6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4) - vue: 3.5.13(typescript@5.5.4) + vue: 3.5.13(typescript@5.7.2) optionalDependencies: postcss: 8.4.49 transitivePeerDependencies: @@ -15788,11 +15788,11 @@ snapshots: vm-browserify@1.1.2: {} - vue-demi@0.14.10(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.5.4)))(vue@3.5.13(typescript@5.5.4)): + vue-demi@0.14.10(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.7.2)))(vue@3.5.13(typescript@5.7.2)): dependencies: - vue: 3.5.13(typescript@5.5.4) + vue: 3.5.13(typescript@5.7.2) optionalDependencies: - '@vue/composition-api': 1.7.2(vue@3.5.13(typescript@5.5.4)) + '@vue/composition-api': 1.7.2(vue@3.5.13(typescript@5.7.2)) vue-eslint-parser@9.4.3(eslint@9.9.1(jiti@1.21.0)): dependencies: @@ -15807,7 +15807,7 @@ snapshots: transitivePeerDependencies: - supports-color - vue-loader@16.8.3(@vue/compiler-sfc@3.4.19)(vue@3.5.13(typescript@5.5.4))(webpack@4.47.0(webpack-cli@3.3.12)): + vue-loader@16.8.3(@vue/compiler-sfc@3.4.19)(vue@3.5.13(typescript@5.7.2))(webpack@4.47.0(webpack-cli@3.3.12)): dependencies: chalk: 4.1.2 hash-sum: 2.0.0 @@ -15815,17 +15815,17 @@ snapshots: webpack: 4.47.0(webpack-cli@3.3.12) optionalDependencies: '@vue/compiler-sfc': 3.4.19 - vue: 3.5.13(typescript@5.5.4) + vue: 3.5.13(typescript@5.7.2) vue-router@4.2.5(vue@3.5.13(typescript@5.3.3)): dependencies: '@vue/devtools-api': 6.5.1 vue: 3.5.13(typescript@5.3.3) - vue-router@4.2.5(vue@3.5.13(typescript@5.5.4)): + vue-router@4.2.5(vue@3.5.13(typescript@5.7.2)): dependencies: '@vue/devtools-api': 6.5.1 - vue: 3.5.13(typescript@5.5.4) + vue: 3.5.13(typescript@5.7.2) vue-template-compiler@2.7.16: dependencies: @@ -15839,19 +15839,19 @@ snapshots: semver: 7.6.0 typescript: 5.3.3 - vue-tsc@1.8.27(typescript@5.5.4): + vue-tsc@1.8.27(typescript@5.7.2): dependencies: '@volar/typescript': 1.11.1 - '@vue/language-core': 1.8.27(typescript@5.5.4) + '@vue/language-core': 1.8.27(typescript@5.7.2) semver: 7.6.0 - typescript: 5.5.4 + typescript: 5.7.2 - vue-tsc@2.0.0(typescript@5.5.4): + vue-tsc@2.0.0(typescript@5.7.2): dependencies: '@volar/typescript': 2.1.0 - '@vue/language-core': 2.0.0(typescript@5.5.4) + '@vue/language-core': 2.0.0(typescript@5.7.2) semver: 7.6.0 - typescript: 5.5.4 + typescript: 5.7.2 vue@3.5.13(typescript@5.3.3): dependencies: @@ -15863,15 +15863,15 @@ snapshots: optionalDependencies: typescript: 5.3.3 - vue@3.5.13(typescript@5.5.4): + vue@3.5.13(typescript@5.7.2): dependencies: '@vue/compiler-dom': 3.5.13 '@vue/compiler-sfc': 3.5.13 '@vue/runtime-dom': 3.5.13 - '@vue/server-renderer': 3.5.13(vue@3.5.13(typescript@5.5.4)) + '@vue/server-renderer': 3.5.13(vue@3.5.13(typescript@5.7.2)) '@vue/shared': 3.5.13 optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.2 w3c-xmlserializer@5.0.0: dependencies: diff --git a/scripts/build-types.ts b/scripts/build-types.ts index a8049aacf..23b079685 100644 --- a/scripts/build-types.ts +++ b/scripts/build-types.ts @@ -27,9 +27,7 @@ const IGNORES = [ 'size-check-vue-i18n' ] -for (const file of globSync( - path.resolve(__dirname, '../packages/*/src/**/*.ts') -)) { +for (const file of globSync('packages/*/src/**/*.ts')) { for (const ignore of IGNORES) { if (file.includes(ignore)) { continue From 28ef521811cc64772b10f706e34166d6d0fe8e6a Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 6 Jan 2025 15:26:11 +0900 Subject: [PATCH 10/21] fix: export lite module for petite-vue-i18n --- eslint.config.mjs | 2 + package.json | 2 +- packages/petite-vue-i18n/package.json | 1 + packages/petite-vue-i18n/src/index.ts | 26 ++- packages/petite-vue-i18n/src/runtime.ts | 29 ++-- packages/petite-vue-i18n/src/vue.d.ts | 23 +-- .../vue-i18n-core/api-extractor-petite.json | 7 + packages/vue-i18n-core/package.json | 18 ++ packages/vue-i18n-core/petite.js | 7 + packages/vue-i18n-core/src/index.ts | 2 +- packages/vue-i18n-core/src/misc.ts | 4 + packages/vue-i18n-core/src/petite.ts | 92 +++++++++++ packages/vue-i18n/package.json | 1 + packages/vue-i18n/src/index.ts | 60 +++---- packages/vue-i18n/src/runtime.ts | 60 +++---- pnpm-lock.yaml | 6 + rollup.config.mjs | 154 ++++++++++-------- scripts/build.ts | 64 +++++--- tsconfig.json | 4 +- 19 files changed, 360 insertions(+), 202 deletions(-) create mode 100644 packages/vue-i18n-core/api-extractor-petite.json create mode 100644 packages/vue-i18n-core/petite.js create mode 100644 packages/vue-i18n-core/src/petite.ts diff --git a/eslint.config.mjs b/eslint.config.mjs index f80384985..074104857 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -95,7 +95,9 @@ export default [ 'shim.d.ts', '.eslintcache', '.eslintrc.cjs', + 'packages/*/vite.config.ts', 'packages/*/index.js', + 'packages/vue-i18n-core/petite.js', 'docsgen.config.js', 'scripts/api/*.js' ] diff --git a/package.json b/package.json index bb7530121..0409da579 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "bench:simple-jit-aot": "node --expose-gc ./benchmark/simple-jit-aot.mjs", "build": "tsx ./scripts/build.ts", "build:explorer": "pnpm --filter @intlify/message-format-explorer build", + "build:rolldown": "tsx ./scripts/build-rolldown.ts", "build:size": "pnpm build && run-p build:size-*", "build:size-core": "pnpm --filter @intlify/size-check-core build", "build:size-petite-vue-i18n": "pnpm --filter @intlify/size-check-petite-vue-i18n build", @@ -74,7 +75,6 @@ "preview:size-vue-i18n": "pnpm --filter @intlify/size-check-vue-i18n preview", "release": "bumpp package.json packages/**/package.json --commit \"release: v\" --push --tag", "size": "tsx ./scripts/build.ts --size && tsx ./scripts/size.ts", - "build:rolldown": "tsx ./scripts/build-rolldown.ts", "size:report": "tsx ./scripts/report-size.ts", "test": "run-s lint test:cover check-install test:e2e", "test:cover": "pnpm test:unit --coverage", diff --git a/packages/petite-vue-i18n/package.json b/packages/petite-vue-i18n/package.json index ccb15b1d8..97162f603 100644 --- a/packages/petite-vue-i18n/package.json +++ b/packages/petite-vue-i18n/package.json @@ -37,6 +37,7 @@ "dependencies": { "@intlify/core-base": "workspace:*", "@intlify/shared": "workspace:*", + "@intlify/vue-i18n-core": "workspace:*", "@vue/devtools-api": "^6.5.0" }, "devDependencies": { diff --git a/packages/petite-vue-i18n/src/index.ts b/packages/petite-vue-i18n/src/index.ts index 7b0e76f6c..5c4b915cb 100644 --- a/packages/petite-vue-i18n/src/index.ts +++ b/packages/petite-vue-i18n/src/index.ts @@ -4,7 +4,7 @@ import { setDevToolsHook } from '@intlify/core-base' import { getGlobalThis } from '@intlify/shared' -import { initDev, initFeatureFlags } from '../../vue-i18n-core/src/misc' +import { initDev, initFeatureFlags } from '@intlify/vue-i18n-core/petite' if (__ESM_BUNDLER__ && !__TEST__) { initFeatureFlags() @@ -47,10 +47,13 @@ export type { RemovedIndexResources, TranslateOptions } from '@intlify/core-base' +export { createI18n, useI18n, VERSION } from '@intlify/vue-i18n-core/petite' export type { Composer, + ComposerAdditionalOptions, ComposerCustom, ComposerDateTimeFormatting, + ComposerExtender, ComposerNumberFormatting, ComposerOptions, ComposerResolveLocaleMessageTranslation, @@ -63,21 +66,19 @@ export type { DefineDateTimeFormat, DefineLocaleMessage, DefineNumberFormat, - MissingHandler, - VueMessageType -} from '../../vue-i18n-core/src/composer' -export { createI18n, useI18n } from '../../vue-i18n-core/src/i18n' -export type { - ComposerAdditionalOptions, - ComposerExtender, + Disposer, ExportedGlobalComposer, I18n, I18nAdditionalOptions, I18nMode, I18nOptions, + I18nPluginOptions, I18nScope, - UseI18nOptions -} from '../../vue-i18n-core/src/i18n' + MissingHandler, + UseI18nOptions, + VueMessageType +} from '@intlify/vue-i18n-core/petite' + export type { Choice, DateTimeFormatResult, @@ -93,10 +94,7 @@ export type { VueI18nResolveLocaleMessageTranslation, VueI18nTranslation, WarnHtmlInMessageLevel -} from '../../vue-i18n-core/src/legacy' -export type { I18nPluginOptions } from '../../vue-i18n-core/src/plugin' -export { VERSION } from './../../vue-i18n-core/src/misc' -export type { Disposer } from './../../vue-i18n-core/src/types' +} from '@intlify/vue-i18n-core/petite' export type { IsEmptyObject, diff --git a/packages/petite-vue-i18n/src/runtime.ts b/packages/petite-vue-i18n/src/runtime.ts index 5135f3b9d..d9d40abb9 100644 --- a/packages/petite-vue-i18n/src/runtime.ts +++ b/packages/petite-vue-i18n/src/runtime.ts @@ -4,7 +4,7 @@ import { setDevToolsHook } from '@intlify/core-base' import { getGlobalThis } from '@intlify/shared' -import { initDev, initFeatureFlags } from '../../vue-i18n-core/src/misc' +import { initDev, initFeatureFlags } from '@intlify/vue-i18n-core/petite' if (__ESM_BUNDLER__ && !__TEST__) { initFeatureFlags() @@ -46,44 +46,41 @@ export type { RemovedIndexResources, TranslateOptions } from '@intlify/core-base' +export { createI18n, useI18n, VERSION } from '@intlify/vue-i18n-core/petite' export type { + Choice, Composer, + ComposerAdditionalOptions, ComposerCustom, ComposerDateTimeFormatting, + ComposerExtender, ComposerNumberFormatting, ComposerOptions, ComposerResolveLocaleMessageTranslation, ComposerTranslation, CustomBlock, CustomBlocks, + DateTimeFormatResult, DefaultDateTimeFormatSchema, DefaultLocaleMessageSchema, DefaultNumberFormatSchema, DefineDateTimeFormat, DefineLocaleMessage, DefineNumberFormat, - MissingHandler, - VueMessageType -} from '../../vue-i18n-core/src/composer' -export { createI18n, useI18n } from '../../vue-i18n-core/src/i18n' -export type { - ComposerAdditionalOptions, - ComposerExtender, + Disposer, ExportedGlobalComposer, I18n, I18nAdditionalOptions, I18nMode, I18nOptions, + I18nPluginOptions, I18nScope, - UseI18nOptions -} from '../../vue-i18n-core/src/i18n' -export type { - Choice, - DateTimeFormatResult, LocaleMessageObject, + MissingHandler, NumberFormatResult, PluralizationRulesMap, TranslateResult, + UseI18nOptions, VueI18n, VueI18nDateTimeFormatting, VueI18nExtender, @@ -91,11 +88,9 @@ export type { VueI18nOptions, VueI18nResolveLocaleMessageTranslation, VueI18nTranslation, + VueMessageType, WarnHtmlInMessageLevel -} from '../../vue-i18n-core/src/legacy' -export type { I18nPluginOptions } from '../../vue-i18n-core/src/plugin' -export { VERSION } from './../../vue-i18n-core/src/misc' -export type { Disposer } from './../../vue-i18n-core/src/types' +} from '@intlify/vue-i18n-core/petite' export type { IsEmptyObject, diff --git a/packages/petite-vue-i18n/src/vue.d.ts b/packages/petite-vue-i18n/src/vue.d.ts index 862d9e77c..296f85541 100644 --- a/packages/petite-vue-i18n/src/vue.d.ts +++ b/packages/petite-vue-i18n/src/vue.d.ts @@ -1,22 +1,23 @@ -import type { NamedValue, JsonPaths } from '@intlify/core-base' import type { - TranslateOptions, + IsEmptyObject, IsNever, - IsEmptyObject + NamedValue, + TranslateOptions } from '@intlify/core-base' -import type { CustomBlocks } from '../../vue-i18n-core/src/composer' import type { + CustomBlocks, DefineLocaleMessage, - RemovedIndexResources -} from '../../vue-i18n-core/src/composer' -import type { + ExportedGlobalComposer, + RemovedIndexResources, + TranslateResult, VueI18n, - VueI18nOptions, - TranslateResult -} from '../../vue-i18n-core/src/legacy' -import type { ExportedGlobalComposer } from '../../vue-i18n-core/src/i18n' + VueI18nOptions +} from '@intlify/vue-i18n-core/petite' // --- THE CONTENT BELOW THIS LINE WILL BE APPENDED TO DTS FILE IN DIST DIRECTORY --- // + +import type { JsonPaths } from '@intlify/core-base' + declare module 'vue' { /** * Component Custom Options for Vue I18n diff --git a/packages/vue-i18n-core/api-extractor-petite.json b/packages/vue-i18n-core/api-extractor-petite.json new file mode 100644 index 000000000..c5afc490a --- /dev/null +++ b/packages/vue-i18n-core/api-extractor-petite.json @@ -0,0 +1,7 @@ +{ + "extends": "../../api-extractor.json", + "mainEntryPointFilePath": "./dist/packages//src/petite.d.ts", + "dtsRollup": { + "publicTrimmedFilePath": "./dist/petite-vue-i18n-core.d.ts" + } +} diff --git a/packages/vue-i18n-core/package.json b/packages/vue-i18n-core/package.json index 25fea6c07..c83192054 100644 --- a/packages/vue-i18n-core/package.json +++ b/packages/vue-i18n-core/package.json @@ -59,6 +59,7 @@ }, "exports": { ".": { + "types": "./dist/vue-i18n-core.d.ts", "import": "./dist/vue-i18n-core.mjs", "browser": "./dist/vue-i18n-core.esm-browser.js", "node": { @@ -74,6 +75,23 @@ } } }, + "./petite": { + "types": "./dist/petite-vue-i18n-core.d.ts", + "import": "./dist/petite-vue-i18n-core.mjs", + "browser": "./dist/petite-vue-i18n-core.esm-browser.js", + "node": { + "import": { + "production": "./petite-dist/vue-i18n-core.prod.cjs", + "development": "./petite-dist/vue-i18n-core.mjs", + "default": "./dist/petite-vue-i18n-core.mjs" + }, + "require": { + "production": "./dist/petite-vue-i18n-core.prod.cjs", + "development": "./dist/petite-vue-i18n-core.cjs", + "default": "./petite.js" + } + } + }, "./dist/*": "./dist/*", "./package.json": "./package.json" }, diff --git a/packages/vue-i18n-core/petite.js b/packages/vue-i18n-core/petite.js new file mode 100644 index 000000000..44e0a7a2b --- /dev/null +++ b/packages/vue-i18n-core/petite.js @@ -0,0 +1,7 @@ +'use strict' + +if (process.env.NODE_ENV === 'production') { + module.exports = require('./dist/petite-vue-i18n-core.prod.cjs') +} else { + module.exports = require('./dist/petite-vue-i18n-core.cjs') +} diff --git a/packages/vue-i18n-core/src/index.ts b/packages/vue-i18n-core/src/index.ts index aa0b66f49..e4cfeb26d 100644 --- a/packages/vue-i18n-core/src/index.ts +++ b/packages/vue-i18n-core/src/index.ts @@ -97,7 +97,7 @@ export type { VueI18nTranslation, WarnHtmlInMessageLevel } from './legacy' -export { VERSION } from './misc' +export { initDev, initFeatureFlags, VERSION } from './misc' export type { I18nPluginOptions } from './plugin' export type { Disposer } from './types' diff --git a/packages/vue-i18n-core/src/misc.ts b/packages/vue-i18n-core/src/misc.ts index 9668b3328..6ac48df4c 100644 --- a/packages/vue-i18n-core/src/misc.ts +++ b/packages/vue-i18n-core/src/misc.ts @@ -13,6 +13,8 @@ export const VERSION: string = __VERSION__ /** * This is only called in esm-bundler builds. * istanbul-ignore-next + * + * @internal */ export function initFeatureFlags(): void { if (typeof __FEATURE_FULL_INSTALL__ !== 'boolean') { @@ -35,6 +37,8 @@ export function initFeatureFlags(): void { /** * This is only called development env * istanbul-ignore-next + * + * @internal */ export function initDev(): void { if (__BROWSER__) { diff --git a/packages/vue-i18n-core/src/petite.ts b/packages/vue-i18n-core/src/petite.ts new file mode 100644 index 000000000..bb80756fd --- /dev/null +++ b/packages/vue-i18n-core/src/petite.ts @@ -0,0 +1,92 @@ +export type { + CompileError, + DateTimeOptions, + FallbackLocale, + DateTimeFormat as IntlDateTimeFormat, + DateTimeFormats as IntlDateTimeFormats, + FormatMatcher as IntlFormatMatcher, + LocaleMatcher as IntlLocaleMatcher, + NumberFormat as IntlNumberFormat, + NumberFormats as IntlNumberFormats, + LinkedModifiers, + Locale, + LocaleMessage, + LocaleMessageDictionary, + LocaleMessages, + LocaleMessageType, + LocaleMessageValue, + LocaleParams, + MessageCompiler, + MessageCompilerContext, + MessageContext, + MessageFunction, + MessageFunctions, + MessageResolver, + NamedValue, + NumberOptions, + Path, + PathValue, + PluralizationRule, + PostTranslationHandler, + RemovedIndexResources, + SchemaParams, + TranslateOptions +} from '@intlify/core-base' +export type { + Composer, + ComposerCustom, + ComposerDateTimeFormatting, + ComposerNumberFormatting, + ComposerOptions, + ComposerResolveLocaleMessageTranslation, + ComposerTranslation, + CustomBlock, + CustomBlocks, + DefaultDateTimeFormatSchema, + DefaultLocaleMessageSchema, + DefaultNumberFormatSchema, + DefineDateTimeFormat, + DefineLocaleMessage, + DefineNumberFormat, + MissingHandler, + VueMessageType +} from './composer' +export { createI18n, useI18n } from './i18n' +export type { + ComposerAdditionalOptions, + ComposerExtender, + ExportedGlobalComposer, + I18n, + I18nAdditionalOptions, + I18nMode, + I18nOptions, + I18nScope, + UseI18nOptions +} from './i18n' +export type { + Choice, + DateTimeFormatResult, + LocaleMessageObject, + NumberFormatResult, + PluralizationRulesMap, + TranslateResult, + VueI18n, + VueI18nDateTimeFormatting, + VueI18nExtender, + VueI18nNumberFormatting, + VueI18nOptions, + VueI18nResolveLocaleMessageTranslation, + VueI18nTranslation, + WarnHtmlInMessageLevel +} from './legacy' +export { initDev, initFeatureFlags, VERSION } from './misc' +export type { I18nPluginOptions } from './plugin' +export type { Disposer } from './types' + +export type { + IsEmptyObject, + IsNever, + PickupFormatPathKeys, + PickupKeys, + PickupPaths +} from '@intlify/core-base' diff --git a/packages/vue-i18n/package.json b/packages/vue-i18n/package.json index 412b87024..052543701 100644 --- a/packages/vue-i18n/package.json +++ b/packages/vue-i18n/package.json @@ -37,6 +37,7 @@ "dependencies": { "@intlify/core-base": "workspace:*", "@intlify/shared": "workspace:*", + "@intlify/vue-i18n-core": "workspace:*", "@vue/devtools-api": "^6.5.0" }, "devDependencies": { diff --git a/packages/vue-i18n/src/index.ts b/packages/vue-i18n/src/index.ts index cbab3cc4a..f690fb6e1 100644 --- a/packages/vue-i18n/src/index.ts +++ b/packages/vue-i18n/src/index.ts @@ -8,7 +8,7 @@ import { setDevToolsHook } from '@intlify/core-base' import { getGlobalThis } from '@intlify/shared' -import { initDev, initFeatureFlags } from '../../vue-i18n-core/src/misc' +import { initDev, initFeatureFlags } from '@intlify/vue-i18n-core' if (__ESM_BUNDLER__ && !__TEST__) { initFeatureFlags() @@ -55,62 +55,58 @@ export type { RemovedIndexResources, TranslateOptions } from '@intlify/core-base' +export { + createI18n, + I18nInjectionKey, + useI18n, + VERSION +} from '@intlify/vue-i18n-core' export type { BaseFormatProps, + Choice, ComponentI18nScope, - DatetimeFormat, - DatetimeFormatProps, - FormattableProps, - I18nD, - I18nN, - I18nT, - NumberFormat, - NumberFormatProps, - Translation, - TranslationProps -} from '../../vue-i18n-core/src/components' -export type { Composer, + ComposerAdditionalOptions, ComposerCustom, ComposerDateTimeFormatting, + ComposerExtender, ComposerNumberFormatting, ComposerOptions, ComposerResolveLocaleMessageTranslation, ComposerTranslation, CustomBlock, CustomBlocks, + DatetimeFormat, + DatetimeFormatProps, + DateTimeFormatResult, DefaultDateTimeFormatSchema, DefaultLocaleMessageSchema, DefaultNumberFormatSchema, DefineDateTimeFormat, DefineLocaleMessage, DefineNumberFormat, - MissingHandler, - VueMessageType -} from '../../vue-i18n-core/src/composer' -export { - createI18n, - I18nInjectionKey, - useI18n -} from '../../vue-i18n-core/src/i18n' -export type { - ComposerAdditionalOptions, - ComposerExtender, + Disposer, ExportedGlobalComposer, + FormattableProps, I18n, I18nAdditionalOptions, + I18nD, I18nMode, + I18nN, I18nOptions, + I18nPluginOptions, I18nScope, - UseI18nOptions -} from '../../vue-i18n-core/src/i18n' -export type { - Choice, - DateTimeFormatResult, + I18nT, LocaleMessageObject, + MissingHandler, + NumberFormat, + NumberFormatProps, NumberFormatResult, PluralizationRulesMap, TranslateResult, + Translation, + TranslationProps, + UseI18nOptions, VueI18n, VueI18nDateTimeFormatting, VueI18nExtender, @@ -118,11 +114,9 @@ export type { VueI18nOptions, VueI18nResolveLocaleMessageTranslation, VueI18nTranslation, + VueMessageType, WarnHtmlInMessageLevel -} from '../../vue-i18n-core/src/legacy' -export type { I18nPluginOptions } from '../../vue-i18n-core/src/plugin' -export { VERSION } from './../../vue-i18n-core/src/misc' -export type { Disposer } from './../../vue-i18n-core/src/types' +} from '@intlify/vue-i18n-core' export type { IsEmptyObject, diff --git a/packages/vue-i18n/src/runtime.ts b/packages/vue-i18n/src/runtime.ts index 2b36102d0..76e24f07f 100644 --- a/packages/vue-i18n/src/runtime.ts +++ b/packages/vue-i18n/src/runtime.ts @@ -8,7 +8,7 @@ import { setDevToolsHook } from '@intlify/core-base' import { getGlobalThis } from '@intlify/shared' -import { initDev, initFeatureFlags } from '../../vue-i18n-core/src/misc' +import { initDev, initFeatureFlags } from '@intlify/vue-i18n-core' if (__ESM_BUNDLER__ && !__TEST__) { initFeatureFlags() @@ -54,62 +54,58 @@ export type { RemovedIndexResources, TranslateOptions } from '@intlify/core-base' +export { + createI18n, + I18nInjectionKey, + useI18n, + VERSION +} from '@intlify/vue-i18n-core' export type { BaseFormatProps, + Choice, ComponentI18nScope, - DatetimeFormat, - DatetimeFormatProps, - FormattableProps, - I18nD, - I18nN, - I18nT, - NumberFormat, - NumberFormatProps, - Translation, - TranslationProps -} from '../../vue-i18n-core/src/components' -export type { Composer, + ComposerAdditionalOptions, ComposerCustom, ComposerDateTimeFormatting, + ComposerExtender, ComposerNumberFormatting, ComposerOptions, ComposerResolveLocaleMessageTranslation, ComposerTranslation, CustomBlock, CustomBlocks, + DatetimeFormat, + DatetimeFormatProps, + DateTimeFormatResult, DefaultDateTimeFormatSchema, DefaultLocaleMessageSchema, DefaultNumberFormatSchema, DefineDateTimeFormat, DefineLocaleMessage, DefineNumberFormat, - MissingHandler, - VueMessageType -} from '../../vue-i18n-core/src/composer' -export { - createI18n, - I18nInjectionKey, - useI18n -} from '../../vue-i18n-core/src/i18n' -export type { - ComposerAdditionalOptions, - ComposerExtender, + Disposer, ExportedGlobalComposer, + FormattableProps, I18n, I18nAdditionalOptions, + I18nD, I18nMode, + I18nN, I18nOptions, + I18nPluginOptions, I18nScope, - UseI18nOptions -} from '../../vue-i18n-core/src/i18n' -export type { - Choice, - DateTimeFormatResult, + I18nT, LocaleMessageObject, + MissingHandler, + NumberFormat, + NumberFormatProps, NumberFormatResult, PluralizationRulesMap, TranslateResult, + Translation, + TranslationProps, + UseI18nOptions, VueI18n, VueI18nDateTimeFormatting, VueI18nExtender, @@ -117,11 +113,9 @@ export type { VueI18nOptions, VueI18nResolveLocaleMessageTranslation, VueI18nTranslation, + VueMessageType, WarnHtmlInMessageLevel -} from '../../vue-i18n-core/src/legacy' -export type { I18nPluginOptions } from '../../vue-i18n-core/src/plugin' -export { VERSION } from './../../vue-i18n-core/src/misc' -export type { Disposer } from './../../vue-i18n-core/src/types' +} from '@intlify/vue-i18n-core' export type { IsEmptyObject, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bec6d267f..22ffae17e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -566,6 +566,9 @@ importers: '@intlify/shared': specifier: workspace:* version: link:../shared + '@intlify/vue-i18n-core': + specifier: workspace:* + version: link:../vue-i18n-core '@vue/devtools-api': specifier: ^6.5.0 version: 6.5.1 @@ -641,6 +644,9 @@ importers: '@intlify/shared': specifier: workspace:* version: link:../shared + '@intlify/vue-i18n-core': + specifier: workspace:* + version: link:../vue-i18n-core '@vue/devtools-api': specifier: ^6.5.0 version: 6.5.1 diff --git a/rollup.config.mjs b/rollup.config.mjs index 2110de3e9..f16c6f513 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -39,64 +39,87 @@ const stubs = { [`dist/${name}.prod.cjs`]: `${name}.cjs.prod.js` } -const outputConfigs = { - mjs: { - file: `dist/${name}.mjs`, - format: `es` - }, - 'mjs-node': { - file: `dist/${name}.node.mjs`, - format: `es` - }, - browser: { - file: `dist/${name}.esm-browser.js`, - format: `es` - }, - cjs: { - // file: `dist/${name}.cjs.js`, - file: `dist/${name}.cjs`, - format: `cjs` - }, - global: { - file: `dist/${name}.global.js`, - format: `iife` - }, - // runtime-only builds, for '@intlify/core' and 'vue-i18n' package only - 'mjs-runtime': { - file: `dist/${name}.runtime.mjs`, - format: `es` - }, - 'mjs-node-runtime': { - file: `dist/${name}.runtime.node.mjs`, - format: `es` - }, - 'browser-runtime': { - file: `dist/${name}.runtime.esm-browser.js`, - format: 'es' - }, - 'global-runtime': { - file: `dist/${name}.runtime.global.js`, - format: 'iife' +function resolveOutputConfigs(name, ns = '') { + return { + mjs: { + file: `dist/${ns}${name}.mjs`, + format: `es` + }, + 'mjs-node': { + file: `dist/${ns}${name}.node.mjs`, + format: `es` + }, + browser: { + file: `dist/${ns}${name}.esm-browser.js`, + format: `es` + }, + cjs: { + file: `dist/${ns}${name}.cjs`, + format: `cjs` + }, + global: { + file: `dist/${ns}${name}.global.js`, + format: `iife` + }, + // runtime-only builds, for '@intlify/core' and 'vue-i18n' package only + 'mjs-runtime': { + file: `dist/${ns}${name}.runtime.mjs`, + format: `es` + }, + 'mjs-node-runtime': { + file: `dist/${ns}${name}.runtime.node.mjs`, + format: `es` + }, + 'browser-runtime': { + file: `dist/${ns}${name}.runtime.esm-browser.js`, + format: 'es' + }, + 'global-runtime': { + file: `dist/${ns}${name}.runtime.global.js`, + format: 'iife' + } } } +const outputConfigs = resolveOutputConfigs(name) const defaultFormats = ['esm-bundler', 'cjs'] const inlineFormats = process.env.FORMATS && process.env.FORMATS.split(',') const packageFormats = inlineFormats || packageOptions.formats || defaultFormats -const packageConfigs = process.env.PROD_ONLY + +let packageConfigs = process.env.PROD_ONLY ? [] : packageFormats.map(format => createConfig(format, outputConfigs[format])) +const petiteOutputConfigs = + name === 'vue-i18n-core' ? resolveOutputConfigs(name, 'petite-') : {} + +if (name === 'vue-i18n-core') { + packageConfigs = [ + ...packageConfigs, + ...packageFormats.map(format => + createConfig(format, petiteOutputConfigs[format]) + ) + ] +} + if (process.env.NODE_ENV === 'production') { packageFormats.forEach(format => { if (packageOptions.prod === false) { return } if (format === 'cjs') { - packageConfigs.push(createProductionConfig(format)) + packageConfigs.push(createProductionConfig(format, name)) + if (name === 'vue-i18n-core') { + packageConfigs.push(createProductionConfig(format, name, 'petite-')) + } } if (/^(global|browser)(-runtime)?/.test(format)) { - packageConfigs.push(createMinifiedConfig(format)) + packageConfigs.push(createMinifiedConfig(format, outputConfigs[format])) + if (name === 'vue-i18n-core') { + packageConfigs.push( + createMinifiedConfig(format, petiteOutputConfigs[format]) + ) + } } }) } @@ -135,7 +158,8 @@ function createConfig(format, _output, plugins = []) { output.file.includes('.node.') || format === 'cjs' || format === 'cjs-lite' const isGlobalBuild = /global/.test(format) const isRuntimeOnlyBuild = /runtime/.test(format) - const isLite = /petite-vue-i18n/.test(name) + // const isLite = /petite-vue-i18n/.test(name) + const isLite = /petite-vue-i18n/.test(output.file) if (isGlobalBuild) { output.name = packageOptions.name @@ -162,7 +186,14 @@ function createConfig(format, _output, plugins = []) { // during a single build. hasTSChecked = true - const entryFile = /runtime/.test(format) ? `src/runtime.ts` : `src/index.ts` + const entryFile = + name !== 'vue-i18n-core' + ? /runtime/.test(format) + ? `src/runtime.ts` + : `src/index.ts` + : !/petite-vue-i18n/.test(output.file) + ? `src/index.ts` + : `src/petite.ts` const external = isGlobalBuild || isBrowserESMBuild @@ -355,32 +386,27 @@ function createReplacePlugin( }) } -function createProductionConfig(format) { - // const extension = format === 'cjs' ? 'cjs' : 'js' - // const descriptor = format === 'cjs' ? '' : `.${format}` +function createProductionConfig(format, name, ns = '') { const extension = format === 'cjs' || format === 'mjs' ? format : 'js' const descriptor = format === 'cjs' || format === 'mjs' ? '' : `.${format}` return createConfig(format, { - file: `dist/${name}${descriptor}.prod.${extension}`, + file: `dist/${ns}${name}${descriptor}.prod.${extension}`, format: outputConfigs[format].format }) } -function createMinifiedConfig(format) { - return createConfig( - format, - { - file: outputConfigs[format].file.replace(/\.js$/, '.prod.js'), - format: outputConfigs[format].format - }, - [ - terser({ - module: /^esm/.test(format), - compress: { - ecma: 2015 - }, - safari10: true - }) - ] - ) +function createMinifiedConfig(format, output) { + const newOutput = { + file: output.file.replace(/\.js$/, '.prod.js'), + format: output.format + } + return createConfig(format, newOutput, [ + terser({ + module: /^esm/.test(format), + compress: { + ecma: 2015 + }, + safari10: true + }) + ]) } diff --git a/scripts/build.ts b/scripts/build.ts index bc6e37285..e7bcfb4e3 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -182,37 +182,47 @@ async function main() { console.log( pc.bold(pc.yellow(`Rolling up type definitions for ${target}...`)) ) - // build types - const extractorConfigPath = path.resolve(pkgDir, `api-extractor.json`) - const extractorConfig = - ExtractorConfig.loadFileAndPrepare(extractorConfigPath) - const extractorResult = Extractor.invoke(extractorConfig, { - localBuild: true, - showVerboseMessages: true - }) - - if (extractorResult.succeeded) { - // concat additional d.ts to rolled-up dts - const typesDir = path.resolve(pkgDir, 'types') - if (existsSync(typesDir)) { - const dtsPath = path.resolve(pkgDir, pkg.types) - const existing = await fs.readFile(dtsPath, 'utf-8') - const typeFiles = await fs.readdir(typesDir) - const toAdd = await Promise.all( - typeFiles.map(file => - fs.readFile(path.resolve(typesDir, file), 'utf-8') + const _extractorConfigPath = path.resolve(pkgDir, `api-extractor.json`) + const extractorConfigPaths = [_extractorConfigPath] + if (target === 'vue-i18n-core') { + extractorConfigPaths.push( + path.resolve(pkgDir, `api-extractor-petite.json`) + ) + } + + for (const extractorConfigPath of extractorConfigPaths) { + const extractorConfig = + ExtractorConfig.loadFileAndPrepare(extractorConfigPath) + const extractorResult = Extractor.invoke(extractorConfig, { + localBuild: true, + showVerboseMessages: true + }) + + if (extractorResult.succeeded) { + // concat additional d.ts to rolled-up dts + const typesDir = path.resolve(pkgDir, 'types') + if (existsSync(typesDir)) { + const dtsPath = path.resolve(pkgDir, pkg.types) + const existing = await fs.readFile(dtsPath, 'utf-8') + const typeFiles = await fs.readdir(typesDir) + const toAdd = await Promise.all( + typeFiles.map(file => + fs.readFile(path.resolve(typesDir, file), 'utf-8') + ) ) + await fs.writeFile(dtsPath, existing + '\n' + toAdd.join('\n')) + } + console.log( + pc.bold(pc.green(`API Extractor completed successfully.`)) ) - await fs.writeFile(dtsPath, existing + '\n' + toAdd.join('\n')) + } else { + console.error( + `API Extractor completed with ${extractorResult.errorCount} errors` + + ` and ${extractorResult.warningCount} warnings` + ) + process.exitCode = 1 } - console.log(pc.bold(pc.green(`API Extractor completed successfully.`))) - } else { - console.error( - `API Extractor completed with ${extractorResult.errorCount} errors` + - ` and ${extractorResult.warningCount} warnings` - ) - process.exitCode = 1 } if (['vue-i18n', 'petite-vue-i18n'].includes(target)) { diff --git a/tsconfig.json b/tsconfig.json index 5b8c3cde8..5755a65c7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -43,6 +43,7 @@ "baseUrl": ".", /* Base directory to resolve non-absolute module names. */ "paths": { "@intlify/*": ["packages/*/src"], + "@intlify/vue-i18n-core/petite": ["packages/vue-i18n-core/src/petite"], "vue-i18n": ["packages/vue-i18n/src"] }, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ @@ -53,6 +54,7 @@ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ "resolveJsonModule": true, /* Include modules imported with '.json' extension. */ + // "isolatedDeclarations": true, /* Source Map Options */ // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ @@ -73,7 +75,7 @@ "packages/global.d.ts", "packages/*/src", "packages/*/test", - "packages/*/*.config.ts", + // TODO: "packages/*/*.config.ts", "scripts", "e2e", "shim.d.ts", From 6460cbeba09881b162a4d50d2226a56fcd41fab2 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 6 Jan 2025 15:36:51 +0900 Subject: [PATCH 11/21] fix: update stubs --- rollup.config.mjs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/rollup.config.mjs b/rollup.config.mjs index f16c6f513..62efe8272 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -32,11 +32,13 @@ const banner = `/*! // ensure TS checks only once for each build let hasTSChecked = false -const stubs = { - [`dist/${name}.cjs`]: `${name}.cjs.js`, - [`dist/${name}.mjs`]: `${name}.esm-bundler.js`, - [`dist/${name}.runtime.mjs`]: `${name}.runtime.esm-bundler.js`, - [`dist/${name}.prod.cjs`]: `${name}.cjs.prod.js` +function resolveStubs(name, ns = '') { + return { + [`dist/${ns}${name}.cjs`]: `${ns}${name}.cjs.js`, + [`dist/${ns}${name}.mjs`]: `${ns}${name}.esm-bundler.js`, + [`dist/${ns}${name}.runtime.mjs`]: `${ns}${name}.runtime.esm-bundler.js`, + [`dist/${ns}${name}.prod.cjs`]: `${ns}${name}.cjs.prod.js` + } } function resolveOutputConfigs(name, ns = '') { @@ -102,6 +104,9 @@ if (name === 'vue-i18n-core') { ] } +let stubs = resolveStubs(name) +stubs = Object.assign({}, stubs, resolveStubs(name, 'petite-')) + if (process.env.NODE_ENV === 'production') { packageFormats.forEach(format => { if (packageOptions.prod === false) { @@ -153,12 +158,9 @@ function createConfig(format, _output, plugins = []) { process.env.__DEV__ === 'false' || /\.prod\.[cm]?js$/.test(output.file) const isBundlerESMBuild = /mjs/.test(format) const isBrowserESMBuild = /browser/.test(format) - // const isNodeBuild = format === 'cjs' || format === 'cjs-lite' - const isNodeBuild = - output.file.includes('.node.') || format === 'cjs' || format === 'cjs-lite' + const isNodeBuild = output.file.includes('.node.') || format === 'cjs' const isGlobalBuild = /global/.test(format) const isRuntimeOnlyBuild = /runtime/.test(format) - // const isLite = /petite-vue-i18n/.test(name) const isLite = /petite-vue-i18n/.test(output.file) if (isGlobalBuild) { From fc76187a6d65c100aa38cce76efc6e875c65ab98 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 6 Jan 2025 16:11:14 +0900 Subject: [PATCH 12/21] fix: update from rollup config --- scripts/rolldown.ts | 205 ++++++++++++++++++++++++++------------------ 1 file changed, 122 insertions(+), 83 deletions(-) diff --git a/scripts/rolldown.ts b/scripts/rolldown.ts index b64e1f694..456070030 100644 --- a/scripts/rolldown.ts +++ b/scripts/rolldown.ts @@ -53,55 +53,67 @@ export function createConfigsForPackage({ * Released under the ${pkg.license} License. */` - const stubs = { - [resolve(`dist/${name}.cjs`)]: resolve(`dist/${name}.cjs.js`), - [resolve(`dist/${name}.mjs`)]: resolve(`dist/${name}.esm-bundler.js`), - [resolve(`dist/${name}.runtime.mjs`)]: resolve( - `dist/${name}.runtime.esm-bundler.js` - ), - [resolve(`dist/${name}.prod.cjs`)]: resolve(`dist/${name}.cjs.prod.js`) + function resolveStubs(name: string, ns = '') { + return { + [`dist/${ns}${name}.cjs`]: `${ns}${name}.cjs.js`, + [`dist/${ns}${name}.mjs`]: `${ns}${name}.esm-bundler.js`, + [`dist/${ns}${name}.runtime.mjs`]: `${ns}${name}.runtime.esm-bundler.js`, + [`dist/${ns}${name}.prod.cjs`]: `${ns}${name}.cjs.prod.js` + } } - const outputConfigs: Record = { - mjs: { - file: resolve(`dist/${name}.mjs`), - format: `es` - }, - 'mjs-node': { - file: resolve(`dist/${name}.node.mjs`), - format: `es` - }, - browser: { - file: resolve(`dist/${name}.esm-browser.js`), - format: `es` - }, - cjs: { - file: resolve(`dist/${name}.cjs`), - format: `cjs` - }, - global: { - file: resolve(`dist/${name}.global.js`), - format: `iife` - }, - // runtime-only builds, for '@intlify/core' and 'vue-i18n' package only - 'mjs-runtime': { - file: resolve(`dist/${name}.runtime.mjs`), - format: `es` - }, - 'mjs-node-runtime': { - file: resolve(`dist/${name}.runtime.node.mjs`), - format: `es` - }, - 'browser-runtime': { - file: resolve(`dist/${name}.runtime.esm-browser.js`), - format: 'es' - }, - 'global-runtime': { - file: resolve(`dist/${name}.runtime.global.js`), - format: 'iife' + function resolveOutputConfigs( + name: string, + ns = '' + ): Record { + return { + mjs: { + file: resolve(`dist/${ns}${name}.mjs`), + format: `es` + }, + 'mjs-node': { + file: resolve(`dist/${ns}${name}.node.mjs`), + format: `es` + }, + browser: { + file: resolve(`dist/${ns}${name}.esm-browser.js`), + format: `es` + }, + cjs: { + file: resolve(`dist/${ns}${name}.cjs`), + format: `cjs` + }, + global: { + file: resolve(`dist/${ns}${name}.global.js`), + format: `iife` + }, + // runtime-only builds, for '@intlify/core' and 'vue-i18n' package only + 'mjs-runtime': { + file: resolve(`dist/${ns}${name}.runtime.mjs`), + format: `es` + }, + 'mjs-node-runtime': { + file: resolve(`dist/${ns}${name}.runtime.node.mjs`), + format: `es` + }, + 'browser-runtime': { + file: resolve(`dist/${ns}${name}.runtime.esm-browser.js`), + format: 'es' + }, + 'global-runtime': { + file: resolve(`dist/${ns}${name}.runtime.global.js`), + format: 'iife' + } } } + let stubs = resolveStubs(name) + if (name === 'vue-i18n-core') { + stubs = Object.assign({}, stubs, resolveStubs(name, 'petite-')) + } + + const outputConfigs = resolveOutputConfigs(name) + const resolvedFormats = ( formats || packageOptions.formats || ['esm-bundler', 'cjs'] @@ -109,22 +121,42 @@ export function createConfigsForPackage({ .filter(Boolean) .filter((format: string) => outputConfigs[format]) - const packageConfigs = prodOnly + let packageConfigs = prodOnly ? [] : resolvedFormats.map((format: string) => createConfig(format, outputConfigs[format]) ) + const petiteOutputConfigs = + name === 'vue-i18n-core' ? resolveOutputConfigs(name, 'petite-') : {} + + if (name === 'vue-i18n-core') { + packageConfigs = [ + ...packageConfigs, + ...resolvedFormats.map(format => + createConfig(format, petiteOutputConfigs[format]) + ) + ] + } + if (!devOnly) { resolvedFormats.forEach((format: string) => { if (packageOptions.prod === false) { return } if (format === 'cjs') { - packageConfigs.push(createProductionConfig(format)) + packageConfigs.push(createProductionConfig(format, name)) + if (name === 'vue-i18n-core') { + packageConfigs.push(createProductionConfig(format, name, 'petite-')) + } } if (/^(global|browser)(-runtime)?/.test(format)) { - packageConfigs.push(createMinifiedConfig(format)) + packageConfigs.push(createMinifiedConfig(format, outputConfigs[format])) + if (name === 'vue-i18n-core') { + packageConfigs.push( + createMinifiedConfig(format, petiteOutputConfigs[format]) + ) + } } }) } @@ -148,12 +180,10 @@ export function createConfigsForPackage({ /browser/.test(format) && !packageOptions.enableNonBrowserBranches // const isCJSBuild = format === 'cjs' const isNodeBuild = - String(output.file).includes('.node.') || - format === 'cjs' || - format === 'cjs-lite' + String(output.file).includes('.node.') || format === 'cjs' const isGlobalBuild = /global/.test(format) const isRuntimeOnlyBuild = /runtime/.test(format) - const isLite = /petite-vue-i18n/.test(name) + const isLite = /petite-vue-i18n/.test(String(output.file)) // output.dir = resolve('dist') output.sourcemap = sourceMap @@ -176,7 +206,14 @@ export function createConfigsForPackage({ output.name = packageOptions.name } - const entryFile = /runtime/.test(format) ? `src/runtime.ts` : `src/index.ts` + const entryFile = + name !== 'vue-i18n-core' + ? /runtime/.test(format) + ? `src/runtime.ts` + : `src/index.ts` + : !/petite-vue-i18n/.test(String(output.file)) + ? `src/index.ts` + : `src/petite.ts` function resolveDefine() { const defines: Record = { @@ -335,46 +372,48 @@ export function createConfigsForPackage({ } } - function createProductionConfig(format: string): RolldownOptions { + function createProductionConfig( + format: string, + name: string, + ns = '' + ): RolldownOptions { const extension = format === 'cjs' || format === 'mjs' ? format : 'js' const descriptor = format === 'cjs' || format === 'mjs' ? '' : `.${format}` return createConfig(format, { - file: resolve(`dist/${name}${descriptor}.prod.${extension}`), + file: resolve(`dist/${ns}${name}${descriptor}.prod.${extension}`), format: outputConfigs[format].format }) } - function createMinifiedConfig(format: string): RolldownOptions { - return createConfig( - format, + function createMinifiedConfig( + format: string, + output: OutputOptions + ): RolldownOptions { + const newOutput = { + file: String(output.file).replace(/\.js$/, '.prod.js'), + format: output.format + } + return createConfig(format, newOutput, [ { - file: resolve( - String(outputConfigs[format].file).replace(/\.js$/, '.prod.js') - ), - format: outputConfigs[format].format - }, - [ - { - name: 'swc-minify', - async renderChunk(contents, _, { format }) { - const { code } = await minifySwc(contents, { - module: format === 'es', - format: { - comments: false - }, - compress: { - ecma: 2016, - pure_getters: true - }, - safari10: true, - mangle: true - }) - // swc removes banner - return { code: banner + code, map: null } - } + name: 'swc-minify', + async renderChunk(contents, _, { format }) { + const { code } = await minifySwc(contents, { + module: format === 'es', + format: { + comments: false + }, + compress: { + ecma: 2016, + pure_getters: true + }, + safari10: true, + mangle: true + }) + // swc removes banner + return { code: banner + code, map: null } } - ] - ) + } + ]) } return packageConfigs From 5086b23bb9aa4d6592beaa11608c5766edf78d70 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 6 Jan 2025 16:26:23 +0900 Subject: [PATCH 13/21] fix: vue-i18n type generation --- packages/vue-i18n/src/vue.d.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/vue-i18n/src/vue.d.ts b/packages/vue-i18n/src/vue.d.ts index adee667c2..5d0986d9d 100644 --- a/packages/vue-i18n/src/vue.d.ts +++ b/packages/vue-i18n/src/vue.d.ts @@ -2,7 +2,6 @@ import type { DateTimeOptions, IsEmptyObject, IsNever, - JsonPaths, Locale, LocaleMessageValue, MessageFunction, @@ -11,28 +10,27 @@ import type { PickupFormatPathKeys, TranslateOptions } from '@intlify/core-base' -import type { - DatetimeFormat, - NumberFormat, - Translation -} from '../../vue-i18n-core/src/components' import type { CustomBlocks, + DatetimeFormat, + DateTimeFormatResult, DefineDateTimeFormat, DefineLocaleMessage, - RemovedIndexResources, - VueMessageType -} from '../../vue-i18n-core/src/composer' -import type { ExportedGlobalComposer } from '../../vue-i18n-core/src/i18n' -import type { - DateTimeFormatResult, + ExportedGlobalComposer, + NumberFormat, NumberFormatResult, + RemovedIndexResources, TranslateResult, + Translation, VueI18n, - VueI18nOptions -} from '../../vue-i18n-core/src/legacy' + VueI18nOptions, + VueMessageType +} from '@intlify/vue-i18n-core' // --- THE CONTENT BELOW THIS LINE WILL BE APPENDED TO DTS FILE IN DIST DIRECTORY --- // + +import type { JsonPaths } from '@intlify/core-base' + declare module 'vue' { /** * Component Custom Options for Vue I18n From 52897794164bed8e144a948628148065f665b2df Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 6 Jan 2025 16:26:46 +0900 Subject: [PATCH 14/21] chore: ignore format and lint --- .prettierignore | 3 ++- eslint.config.mjs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.prettierignore b/.prettierignore index a41a93d2d..d8f25524a 100644 --- a/.prettierignore +++ b/.prettierignore @@ -4,4 +4,5 @@ docs coverage tsconfig.json api-extractor.json -README.md \ No newline at end of file +README.md +temp diff --git a/eslint.config.mjs b/eslint.config.mjs index 074104857..add504a49 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -93,6 +93,7 @@ export default [ '**/test/**', '**/examples/**', 'shim.d.ts', + 'temp/**', '.eslintcache', '.eslintrc.cjs', 'packages/*/vite.config.ts', From 65aaefe29253ef1516a187506e64fde065d5bca8 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 6 Jan 2025 23:31:44 +0900 Subject: [PATCH 15/21] fix: refactor codes --- packages/vue-i18n-core/src/i18n.ts | 19 ------------------- packages/vue-i18n-core/src/misc.ts | 8 ++++---- packages/vue-i18n-core/src/vue.d.ts | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 23 deletions(-) create mode 100644 packages/vue-i18n-core/src/vue.d.ts diff --git a/packages/vue-i18n-core/src/i18n.ts b/packages/vue-i18n-core/src/i18n.ts index d4f2f4649..84ca4818b 100644 --- a/packages/vue-i18n-core/src/i18n.ts +++ b/packages/vue-i18n-core/src/i18n.ts @@ -60,25 +60,6 @@ import type { } from './legacy' import type { Disposer } from './types' -declare module 'vue' { - // eslint-disable-next-line - interface App { - __VUE_I18N__?: I18n & I18nInternal - __VUE_I18N_SYMBOL__?: InjectionKey | string - } -} - -// internal Component Instance API isCE -declare module 'vue' { - export interface ComponentInternalInstance { - /** - * @internal - * is custom element? - */ - isCE?: boolean - } -} - /** * I18n Options for `createI18n` * diff --git a/packages/vue-i18n-core/src/misc.ts b/packages/vue-i18n-core/src/misc.ts index 6ac48df4c..67640a09c 100644 --- a/packages/vue-i18n-core/src/misc.ts +++ b/packages/vue-i18n-core/src/misc.ts @@ -12,9 +12,9 @@ export const VERSION: string = __VERSION__ /** * This is only called in esm-bundler builds. - * istanbul-ignore-next + * @description **Don't use this function in your application code.** * - * @internal + * istanbul-ignore-next */ export function initFeatureFlags(): void { if (typeof __FEATURE_FULL_INSTALL__ !== 'boolean') { @@ -36,9 +36,9 @@ export function initFeatureFlags(): void { /** * This is only called development env - * istanbul-ignore-next + * @description **Don't use this function in your application code.** * - * @internal + * istanbul-ignore-next */ export function initDev(): void { if (__BROWSER__) { diff --git a/packages/vue-i18n-core/src/vue.d.ts b/packages/vue-i18n-core/src/vue.d.ts new file mode 100644 index 000000000..237f9b4ae --- /dev/null +++ b/packages/vue-i18n-core/src/vue.d.ts @@ -0,0 +1,21 @@ +import type { InjectionKey } from 'vue' +import type { I18n, I18nInternal } from './i18n' + +declare module 'vue' { + // eslint-disable-next-line + export interface App { + __VUE_I18N__?: I18n & I18nInternal + __VUE_I18N_SYMBOL__?: InjectionKey | string + } +} + +// internal Component Instance API isCE +declare module 'vue' { + export interface ComponentInternalInstance { + /** + * @internal + * iskk custom element? + */ + isCE?: boolean + } +} From fc79919f3328ad176c83634500975cb536704250 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 6 Jan 2025 23:32:07 +0900 Subject: [PATCH 16/21] fix: bundle dts files --- package.json | 4 +- pnpm-lock.yaml | 174 +++++++++++++++++++++++++++++++------- scripts/build-rolldown.ts | 4 +- scripts/build-types.ts | 148 ++++++++++++++++++-------------- scripts/dts.ts | 85 +++++++++++++++++++ 5 files changed, 318 insertions(+), 97 deletions(-) create mode 100644 scripts/dts.ts diff --git a/package.json b/package.json index 0409da579..565ff3516 100644 --- a/package.json +++ b/package.json @@ -115,12 +115,13 @@ "jsdom": "^24.0.0", "lint-staged": "^15.2.2", "listhen": "^1.7.2", + "magic-string": "^0.30.17", "markdown-table": "^3.0.4", "mitata": "^1.0.20", "npm-run-all2": "^7.0.0", "opener": "^1.5.2", + "oxc-parser": "^0.44.0", "oxc-transform": "^0.44.0", - "pathe": "^1.1.2", "picocolors": "^1.0.0", "pkg-pr-new": "^0.0.37", "playwright-core": "^1.45.3", @@ -128,6 +129,7 @@ "rc": "^1.2.8", "rolldown": "1.0.0-beta.1", "rollup": "^4.21.2", + "rollup-plugin-dts": "^6.1.1", "rollup-plugin-node-builtins": "^2.1.2", "rollup-plugin-node-globals": "^1.4.0", "rollup-plugin-typescript2": "^0.36.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 22ffae17e..f6fb42975 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -111,6 +111,9 @@ importers: listhen: specifier: ^1.7.2 version: 1.7.2 + magic-string: + specifier: ^0.30.17 + version: 0.30.17 markdown-table: specifier: ^3.0.4 version: 3.0.4 @@ -123,12 +126,12 @@ importers: opener: specifier: ^1.5.2 version: 1.5.2 + oxc-parser: + specifier: ^0.44.0 + version: 0.44.0 oxc-transform: specifier: ^0.44.0 version: 0.44.0 - pathe: - specifier: ^1.1.2 - version: 1.1.2 picocolors: specifier: ^1.0.0 version: 1.0.0 @@ -150,6 +153,9 @@ importers: rollup: specifier: ^4.21.2 version: 4.22.4 + rollup-plugin-dts: + specifier: ^6.1.1 + version: 6.1.1(rollup@4.22.4)(typescript@5.7.2) rollup-plugin-node-builtins: specifier: ^2.1.2 version: 2.1.2 @@ -781,6 +787,10 @@ packages: resolution: {integrity: sha512-CgH3s1a96LipHCmSUmYFPwY7MNx8C3avkq7i4Wl3cfa662ldtUe4VM1TPXX70pfmrlWTb6jLqTYrZyT2ZTJBgA==} engines: {node: '>=6.9.0'} + '@babel/code-frame@7.26.2': + resolution: {integrity: sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ==} + engines: {node: '>=6.9.0'} + '@babel/compat-data@7.23.5': resolution: {integrity: sha512-uU27kfDRlhfKl+w1U6vp16IuvSLtjAxdArVXPa9BvLkrr7CYIsxH5adpHObeAGY/41+syctUWOZ140a2Rvkgjw==} engines: {node: '>=6.9.0'} @@ -867,14 +877,14 @@ packages: resolution: {integrity: sha512-pO9KhhRcuUyGnJWwyEgnRJTSIZHiT+vMD0kPeD+so0l7mxkMT19g3pjY9GTnHySck/hDzq+dtW/4VgnMkippsQ==} engines: {node: '>=6.9.0'} - '@babel/helper-validator-identifier@7.22.20': - resolution: {integrity: sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==} - engines: {node: '>=6.9.0'} - '@babel/helper-validator-identifier@7.24.7': resolution: {integrity: sha512-rR+PBcQ1SMQDDyF6X0wxtG8QyLCgUB0eRAGguqRLfkCA87l7yAP7ehq8SNj96OOGTO8OBV70KhuFYcIkHXOg0w==} engines: {node: '>=6.9.0'} + '@babel/helper-validator-identifier@7.25.9': + resolution: {integrity: sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==} + engines: {node: '>=6.9.0'} + '@babel/helper-validator-option@7.23.5': resolution: {integrity: sha512-85ttAOMLsr53VgXkTbkx8oA6YTfT4q7/HzXSLEYmjcSTJPMPQtvq1BD79Byep5xMUYbGRzEpDsjUf3dyp54IKw==} engines: {node: '>=6.9.0'} @@ -1439,9 +1449,6 @@ packages: '@jridgewell/source-map@0.3.5': resolution: {integrity: sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ==} - '@jridgewell/sourcemap-codec@1.4.15': - resolution: {integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==} - '@jridgewell/sourcemap-codec@1.5.0': resolution: {integrity: sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==} @@ -1548,6 +1555,49 @@ packages: '@octokit/types@13.5.0': resolution: {integrity: sha512-HdqWTf5Z3qwDVlzCrP8UJquMwunpDiMPt5er+QjGzL4hqr/vBVY/MauQgS1xWxCDT1oMx1EULyqxncdCY/NVSQ==} + '@oxc-parser/binding-darwin-arm64@0.44.0': + resolution: {integrity: sha512-JioiiO64lejtmmwTBImSGYBAZiYywK+hj79NgQyMt5G+is+kQF2jRZMuvbRQZr7ewGh2QA70Sw+wlf4wbwQWnw==} + cpu: [arm64] + os: [darwin] + + '@oxc-parser/binding-darwin-x64@0.44.0': + resolution: {integrity: sha512-STXi4QwBhqnqR0AhkFGkh83If1lDS6YHH1v9itmiQgIga545pNywpS7eiJa129whUPk129wg0KuVrx5G8ffOgw==} + cpu: [x64] + os: [darwin] + + '@oxc-parser/binding-linux-arm64-gnu@0.44.0': + resolution: {integrity: sha512-XHzPke9TUD1QD8PZPEYSO/TlHqiYjTH/wqSiWy8v1ZaQv+OPaE/V3WQl9hj7PKy9gOOa1Io66ssfWBbd1miRrQ==} + cpu: [arm64] + os: [linux] + + '@oxc-parser/binding-linux-arm64-musl@0.44.0': + resolution: {integrity: sha512-tMjg+K1rFcABdw8mC4+8DJdhxmcB5VflN66YJ4v76Bf2nzi14Ceegw1Bc8nbbp6u0oe24kd5pJkrxQtOeYQrlA==} + cpu: [arm64] + os: [linux] + + '@oxc-parser/binding-linux-x64-gnu@0.44.0': + resolution: {integrity: sha512-Mg4FLd/aoYIt37akmWQmVqCLxmDIVVkqTxGFp8AiwVjy0DPLWRTX51sqwzaJi8PU/nqUamPdhofPPhEnrudDNQ==} + cpu: [x64] + os: [linux] + + '@oxc-parser/binding-linux-x64-musl@0.44.0': + resolution: {integrity: sha512-NTiHusZP0fWiVskHn4LIA1U5qaC360owCj26Qcx4XLSV5at3rcxsssE+wRtWUpzhAO+PKB4riQ8fDPDJNXzAtw==} + cpu: [x64] + os: [linux] + + '@oxc-parser/binding-win32-arm64-msvc@0.44.0': + resolution: {integrity: sha512-7FaJZcvFtf+Ht1akywBKLwbDC9YHh/+bIFFlF2Mi/SF4RUNzjnYIbgzNhcG4V5dtlQLB6JDe28dIFKM9UZAL5A==} + cpu: [arm64] + os: [win32] + + '@oxc-parser/binding-win32-x64-msvc@0.44.0': + resolution: {integrity: sha512-ShIawSz6LxxF/6IhyxAjeB7dkyqyqE/121lIyhn8WGPtW8kbZgIcfb/WU7T7CVaLMwuBOe5fAQvSk3wOiqoh1w==} + cpu: [x64] + os: [win32] + + '@oxc-project/types@0.44.0': + resolution: {integrity: sha512-2apz8ZnFX2vuZn7qnNY5feVjuT4MGyoirt9tmJCoYMQBeHFaDRpOlqbgZ3N+ICFc5fxdpQK6EMP4kOXtUejOeg==} + '@oxc-transform/binding-darwin-arm64@0.44.0': resolution: {integrity: sha512-bgJg3+TypUMDAWTMKXws2TL45FcTOAtYJObuXvPTyanUDR16Lgara+lCWZkJQDrq+WngNdzYBkTn6gJZwlcS8g==} cpu: [arm64] @@ -5180,9 +5230,8 @@ packages: magic-string@0.30.12: resolution: {integrity: sha512-Ea8I3sQMVXr8JhN4z+H/d8zwo+tYDgHE9+5G4Wnrwhs0gaK9fXTKx0Tw5Xwsd/bCPTTZNRAdpyzvoeORe9LYpw==} - magic-string@0.30.7: - resolution: {integrity: sha512-8vBuFF/I/+OSLRmdf2wwFCJCz+nSn0m6DPvGH1fS/KiQoSaR+sETbov0eIk9KhEKy8CYqIkIAnbohxT/4H0kuA==} - engines: {node: '>=12'} + magic-string@0.30.17: + resolution: {integrity: sha512-sNPKHvyjVf7gyjwS4xGTaW/mCnF8wnjtifKBEhxfZ7E/S8tQ0rssrwGNn6q8JH/ohItJfSQp9mBtQYuTlH5QnA==} magicast@0.3.5: resolution: {integrity: sha512-L0WhttDl+2BOsybvEOLK7fW3UA0OQ0IQ2d6Zl2x/a6vVRs3bAY0ECOSHHeL5jD+SbOpOCUEi0y1DgHEn9Qn1AQ==} @@ -5734,6 +5783,9 @@ packages: resolution: {integrity: sha512-B5JU3cabzk8c67mRRd3ECmROafjYMXbuzlwtqdM8IbS8ktlTix8aFGb2bAGKrSRIlnfKwovGUUr72JUPyOb6kQ==} engines: {node: '>=0.10.0'} + oxc-parser@0.44.0: + resolution: {integrity: sha512-AlYw0Gmw38Q4fL2q09T1qdrA6hgP7IMl69Yu5Eb7RMsncTHyU3rfhqoXYjjudLYvqArjk6zKlCYT8qB4cd+/SQ==} + oxc-transform@0.44.0: resolution: {integrity: sha512-T9o8PWvhYCJWK25MD0qmAQTeIgMkD7NvCFzzqzdFSDHP03wh6B6yy+7nLn1Scw+TsT82QQaaaD5bRl/ATLaPdQ==} @@ -6391,6 +6443,13 @@ packages: '@babel/runtime': optional: true + rollup-plugin-dts@6.1.1: + resolution: {integrity: sha512-aSHRcJ6KG2IHIioYlvAOcEq6U99sVtqDDKVhnwt70rW6tsz3tv5OSjEiWcgzfsHdLyGXZ/3b/7b/+Za3Y6r1XA==} + engines: {node: '>=16'} + peerDependencies: + rollup: ^3.29.4 || ^4 + typescript: ^4.5 || ^5.0 + rollup-plugin-node-builtins@2.1.2: resolution: {integrity: sha512-bxdnJw8jIivr2yEyt8IZSGqZkygIJOGAWypXvHXnwKAbUcN4Q/dGTx7K0oAJryC/m6aq6tKutltSeXtuogU6sw==} @@ -8026,6 +8085,13 @@ snapshots: '@babel/highlight': 7.23.4 chalk: 2.4.2 + '@babel/code-frame@7.26.2': + dependencies: + '@babel/helper-validator-identifier': 7.25.9 + js-tokens: 4.0.0 + picocolors: 1.1.1 + optional: true + '@babel/compat-data@7.23.5': {} '@babel/core@7.23.9': @@ -8106,7 +8172,7 @@ snapshots: '@babel/helper-module-imports': 7.22.15 '@babel/helper-simple-access': 7.22.5 '@babel/helper-split-export-declaration': 7.22.6 - '@babel/helper-validator-identifier': 7.22.20 + '@babel/helper-validator-identifier': 7.24.7 '@babel/helper-optimise-call-expression@7.22.5': dependencies: @@ -8137,10 +8203,11 @@ snapshots: '@babel/helper-string-parser@7.24.8': {} - '@babel/helper-validator-identifier@7.22.20': {} - '@babel/helper-validator-identifier@7.24.7': {} + '@babel/helper-validator-identifier@7.25.9': + optional: true + '@babel/helper-validator-option@7.23.5': {} '@babel/helpers@7.23.9': @@ -8153,7 +8220,7 @@ snapshots: '@babel/highlight@7.23.4': dependencies: - '@babel/helper-validator-identifier': 7.22.20 + '@babel/helper-validator-identifier': 7.24.7 chalk: 2.4.2 js-tokens: 4.0.0 @@ -8207,7 +8274,7 @@ snapshots: '@babel/types@7.23.9': dependencies: '@babel/helper-string-parser': 7.23.4 - '@babel/helper-validator-identifier': 7.22.20 + '@babel/helper-validator-identifier': 7.24.7 to-fast-properties: 2.0.0 '@babel/types@7.25.6': @@ -8485,7 +8552,7 @@ snapshots: escodegen: 2.1.0 estree-walker: 2.0.2 jsonc-eslint-parser: 1.4.1 - magic-string: 0.30.7 + magic-string: 0.30.12 mlly: 1.6.1 source-map: 0.6.1 yaml-eslint-parser: 0.3.2 @@ -8501,7 +8568,7 @@ snapshots: escodegen: 2.1.0 estree-walker: 2.0.2 jsonc-eslint-parser: 2.4.0 - magic-string: 0.30.7 + magic-string: 0.30.12 mlly: 1.6.1 source-map-js: 1.0.2 yaml-eslint-parser: 1.2.2 @@ -8620,8 +8687,6 @@ snapshots: '@jridgewell/gen-mapping': 0.3.3 '@jridgewell/trace-mapping': 0.3.22 - '@jridgewell/sourcemap-codec@1.4.15': {} - '@jridgewell/sourcemap-codec@1.5.0': {} '@jridgewell/trace-mapping@0.3.22': @@ -8779,6 +8844,32 @@ snapshots: dependencies: '@octokit/openapi-types': 22.2.0 + '@oxc-parser/binding-darwin-arm64@0.44.0': + optional: true + + '@oxc-parser/binding-darwin-x64@0.44.0': + optional: true + + '@oxc-parser/binding-linux-arm64-gnu@0.44.0': + optional: true + + '@oxc-parser/binding-linux-arm64-musl@0.44.0': + optional: true + + '@oxc-parser/binding-linux-x64-gnu@0.44.0': + optional: true + + '@oxc-parser/binding-linux-x64-musl@0.44.0': + optional: true + + '@oxc-parser/binding-win32-arm64-msvc@0.44.0': + optional: true + + '@oxc-parser/binding-win32-x64-msvc@0.44.0': + optional: true + + '@oxc-project/types@0.44.0': {} + '@oxc-transform/binding-darwin-arm64@0.44.0': optional: true @@ -8914,7 +9005,7 @@ snapshots: estree-walker: 2.0.2 glob: 8.1.0 is-reference: 1.2.1 - magic-string: 0.30.7 + magic-string: 0.30.17 optionalDependencies: rollup: 4.22.4 @@ -8938,7 +9029,7 @@ snapshots: '@rollup/plugin-replace@5.0.5(rollup@4.22.4)': dependencies: '@rollup/pluginutils': 5.1.0(rollup@4.22.4) - magic-string: 0.30.7 + magic-string: 0.30.17 optionalDependencies: rollup: 4.22.4 @@ -9735,7 +9826,7 @@ snapshots: istanbul-lib-report: 3.0.1 istanbul-lib-source-maps: 5.0.6 istanbul-reports: 3.1.7 - magic-string: 0.30.12 + magic-string: 0.30.17 magicast: 0.3.5 std-env: 3.8.0 test-exclude: 7.0.1 @@ -9755,7 +9846,7 @@ snapshots: dependencies: '@vitest/spy': 2.1.5 estree-walker: 3.0.3 - magic-string: 0.30.12 + magic-string: 0.30.17 optionalDependencies: vite: 6.0.0(@types/node@22.10.3)(jiti@1.21.0)(terser@5.27.0)(tsx@4.11.2)(yaml@2.3.4) @@ -9771,7 +9862,7 @@ snapshots: '@vitest/snapshot@2.1.5': dependencies: '@vitest/pretty-format': 2.1.5 - magic-string: 0.30.12 + magic-string: 0.30.17 pathe: 1.1.2 '@vitest/spy@2.1.5': @@ -9886,7 +9977,7 @@ snapshots: '@vue/compiler-ssr': 3.4.19 '@vue/shared': 3.4.19 estree-walker: 2.0.2 - magic-string: 0.30.7 + magic-string: 0.30.12 postcss: 8.4.35 source-map-js: 1.0.2 @@ -13025,9 +13116,9 @@ snapshots: dependencies: '@jridgewell/sourcemap-codec': 1.5.0 - magic-string@0.30.7: + magic-string@0.30.17: dependencies: - '@jridgewell/sourcemap-codec': 1.4.15 + '@jridgewell/sourcemap-codec': 1.5.0 magicast@0.3.5: dependencies: @@ -13696,6 +13787,19 @@ snapshots: os-homedir@1.0.2: {} + oxc-parser@0.44.0: + dependencies: + '@oxc-project/types': 0.44.0 + optionalDependencies: + '@oxc-parser/binding-darwin-arm64': 0.44.0 + '@oxc-parser/binding-darwin-x64': 0.44.0 + '@oxc-parser/binding-linux-arm64-gnu': 0.44.0 + '@oxc-parser/binding-linux-arm64-musl': 0.44.0 + '@oxc-parser/binding-linux-x64-gnu': 0.44.0 + '@oxc-parser/binding-linux-x64-musl': 0.44.0 + '@oxc-parser/binding-win32-arm64-msvc': 0.44.0 + '@oxc-parser/binding-win32-x64-msvc': 0.44.0 + oxc-transform@0.44.0: optionalDependencies: '@oxc-transform/binding-darwin-arm64': 0.44.0 @@ -14390,6 +14494,14 @@ snapshots: '@rolldown/binding-win32-ia32-msvc': 1.0.0-beta.1 '@rolldown/binding-win32-x64-msvc': 1.0.0-beta.1 + rollup-plugin-dts@6.1.1(rollup@4.22.4)(typescript@5.7.2): + dependencies: + magic-string: 0.30.17 + rollup: 4.22.4 + typescript: 5.7.2 + optionalDependencies: + '@babel/code-frame': 7.26.2 + rollup-plugin-node-builtins@2.1.2: dependencies: browserify-fs: 1.0.0 @@ -15763,7 +15875,7 @@ snapshots: chai: 5.1.2 debug: 4.3.7(supports-color@6.1.0) expect-type: 1.1.0 - magic-string: 0.30.12 + magic-string: 0.30.17 pathe: 1.1.2 std-env: 3.8.0 tinybench: 2.9.0 diff --git a/scripts/build-rolldown.ts b/scripts/build-rolldown.ts index 5062f76e5..9ad6198c9 100644 --- a/scripts/build-rolldown.ts +++ b/scripts/build-rolldown.ts @@ -22,6 +22,7 @@ import { parseArgs } from 'node:util' import { brotliCompressSync, gzipSync } from 'node:zlib' import pc from 'picocolors' import { rolldown } from 'rolldown' +import { buildTypings } from './build-types' import { createConfigsForPackage } from './rolldown' import { targets as allTargets, @@ -112,7 +113,7 @@ async function main() { } if (buildTypes) { - await import('./build-types') + await buildTypings(resolvedTargets) } } @@ -148,7 +149,6 @@ async function main() { } } await Promise.all(all) - // await runParallel(os.cpus().length, targets, build) console.log( `\n${count} files built in ${(performance.now() - start).toFixed(2)}ms.` ) diff --git a/scripts/build-types.ts b/scripts/build-types.ts index 23b079685..42eed7bd9 100644 --- a/scripts/build-types.ts +++ b/scripts/build-types.ts @@ -1,91 +1,113 @@ -import { globSync } from 'fast-glob' -import { - existsSync, - mkdirSync, - readFileSync, - rmSync, - writeFileSync -} from 'node:fs' +import { glob } from 'fast-glob' +import { existsSync, promises as fs } from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' import { isolatedDeclaration } from 'oxc-transform' +import pc from 'picocolors' +import { rollup } from 'rollup' +import { createDtsConfig } from './dts' const __dirname = fileURLToPath(new URL('.', import.meta.url)) -if (existsSync(path.resolve(__dirname, '../temp/packages'))) { - rmSync(path.resolve(__dirname, '../temp/packages'), { recursive: true }) -} - -let errs = '' -let start = performance.now() -let count = 0 - const IGNORES = [ - 'format-explorer', - 'size-check-core', - 'size-check-vue-i18n', - 'size-check-vue-i18n' + /format-explorer/, + /size-check-core/, + /size-check-vue-i18n/, + /size-check-vue-i18n/ ] -for (const file of globSync('packages/*/src/**/*.ts')) { +function isIgnore(file: string) { + let ignored = false for (const ignore of IGNORES) { - if (file.includes(ignore)) { - continue + if (ignore.test(file)) { + ignored = true + break } } + return ignored +} - const ts = readFileSync(file, 'utf-8') - const dts = isolatedDeclaration(file, ts, { - sourcemap: false, - stripInternal: true - }) - if (dts.errors.length) { - dts.errors.forEach(err => { - // temporary workaround for https://github.com/oxc-project/oxc/issues/5668 - if (!err.message.includes('set value(_: S)')) { - console.error(err) - } - errs += err.message + '\n' +export async function buildTypings(targets: string[]) { + if (existsSync(path.resolve(__dirname, '../temp/packages'))) { + await fs.rm(path.resolve(__dirname, '../temp/packages'), { + recursive: true }) } - write(path.join('temp', file.replace(/\.ts$/, '.d.ts')), dts.code) - count++ -} + let errs = '' + let start = performance.now() + let count = 0 -console.log( - `\n${count} isolated dts files generated in ${(performance.now() - start).toFixed(2)}ms.` -) + for (const file of await glob('packages/*/src/**/*.ts')) { + if (isIgnore(file)) { + continue + } -if (errs) { - write(path.join('temp', 'oxc-iso-decl-errors.txt'), errs) -} + const ts = await fs.readFile(file, 'utf-8') + const dts = isolatedDeclaration(file, ts, { + sourcemap: false, + stripInternal: true + }) + if (dts.errors.length) { + dts.errors.forEach(err => { + // temporary workaround for https://github.com/oxc-project/oxc/issues/5668 + if (!err.message.includes('set value(_: S)')) { + console.error(err) + } + errs += err.message + '\n' + }) + } + + const filepath = /\.d\.ts$/.test(file) + ? file + : file.replace(/\.ts$/, '.d.ts') + await write(path.join('temp', filepath), dts.code) + count++ + } -console.log('bundling dts with rollup-plugin-dts...') + console.log( + `\n${count} isolated dts files generated in ${(performance.now() - start).toFixed(2)}ms.` + ) -// bundle with rollup-plugin-dts -// const rollupConfigs = (await import('../rollup.dts.config.js')).default + if (errs) { + await write(path.join('temp', 'oxc-iso-decl-errors.txt'), errs) + } + + console.log('bundling dts ...') -start = performance.now() + // bundle with rollup-plugin-dts + const rollupConfigs = await createDtsConfig(targets) -// await Promise.all( -// rollupConfigs.map(c => -// rollup(c).then(bundle => { -// return bundle.write(c.output).then(() => { -// console.log(pc.gray('built: ') + pc.blue(c.output.file)) -// }) -// }), -// ), -// ) + start = performance.now() -console.log( - `bundled dts generated in ${(performance.now() - start).toFixed(2)}ms.` -) + const all: Promise[] = [] + for (const [dtsPath, config] of Object.entries(rollupConfigs)) { + const s = rollup(config).then(bundle => { + if (config.output == null) { + throw new Error('output is required') + } + if (Array.isArray(config.output)) { + throw new Error('output must be an object') + } + const output = config.output + return bundle.write(output).then(() => { + console.log(pc.gray('built: ') + pc.blue(dtsPath)) + return dtsPath + }) + }) + all.push(s) + } + await Promise.all(all) + + console.log( + `${all.length} bundled dts generated in ${(performance.now() - start).toFixed(2)}ms.` + ) +} -function write(file: string, content: string) { +async function write(file: string, content: string) { const dir = path.dirname(file) if (!existsSync(dir)) { - mkdirSync(dir, { recursive: true }) + await fs.mkdir(dir, { recursive: true }) } - writeFileSync(file, content) + await fs.writeFile(file, content) } diff --git a/scripts/dts.ts b/scripts/dts.ts new file mode 100644 index 000000000..819258a12 --- /dev/null +++ b/scripts/dts.ts @@ -0,0 +1,85 @@ +import MagicString from 'magic-string' +import { existsSync, promises as fs } from 'node:fs' +import path from 'node:path' +import { fileURLToPath } from 'node:url' +import dts from 'rollup-plugin-dts' + +import type { Plugin, RollupOptions } from 'rollup' + +const __dirname = fileURLToPath(new URL('.', import.meta.url)) + +if (!existsSync(path.resolve(__dirname, '../temp/packages'))) { + console.warn('no temp dts files found. run `pnpm build:rolldown` first') + process.exit(1) +} + +export async function createDtsConfig(targets: string[]) { + const packages = await fs.readdir(path.resolve(__dirname, '../temp/packages')) + const targetPackages = targets + ? packages.filter(pkg => targets.includes(pkg)) + : packages + + return targetPackages.reduce( + (acc, pkg) => { + const key = `packages/${pkg}/dist/${pkg}.d.ts` + acc[key] = { + input: path.resolve( + __dirname, + `../temp/packages/${pkg}/src/index.d.ts` + ), + output: { + file: path.resolve(__dirname, `../packages/${pkg}/dist/${pkg}.d.ts`), + format: 'es' + }, + plugins: [ + dts(), + ...(pkg === 'vue-i18n' || pkg === 'petite-vue-i18n' + ? [appendTypes(pkg)] + : []), + ...(pkg === 'vue-i18n-core' ? [copyDts()] : []) + ], + onwarn(warning, warn) { + if ( + warning.code === 'UNRESOLVED_IMPORT' && + !warning.exporter?.startsWith('.') + ) { + return + } + warn(warning) + } + } + return acc + }, + {} as Record + ) +} + +function appendTypes(pkg: string): Plugin { + return { + name: 'append-types', + async renderChunk(code) { + const template = path.resolve( + __dirname, + `../packages/${pkg}/src/vue.d.ts` + ) + const s = new MagicString(code) + const ts = await fs.readFile(template, 'utf-8') + s.prepend(ts + `\n`) + return s.toString() + } + } +} + +function copyDts(): Plugin { + return { + name: 'copy-dts', + async writeBundle(_, output) { + const s = output['vue-i18n-core.d.ts'] as { code: string } + const petiteDts = path.resolve( + __dirname, + `../packages/vue-i18n-core/dist/petite-vue-i18n-core.d.ts` + ) + await fs.writeFile(petiteDts, s.code, 'utf8') + } + } +} From 8b71b1ecdedb3df12076228b279f2c6c8aef584d Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 6 Jan 2025 23:45:56 +0900 Subject: [PATCH 17/21] chore: add ci for rolldown build --- .github/workflows/ci.yml | 76 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d895df888..b3c8e121a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,6 +78,41 @@ jobs: path: packages/*/dist key: build-vue-i18n-os-${{ matrix.os }}-${{ github.sha }} + build-rolldown: + name: Build with rolldown + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + node: [18] + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout codes + uses: actions/checkout@v4 + + - name: Enable corepack + run: corepack enable + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install --no-frozen-lockfile + + - name: Build codes + run: | + pnpm build:rolldown --withTypes + + - name: Cache dist + uses: actions/cache@v4 + with: + path: packages/*/dist + key: build-rolldown-vue-i18n-os-${{ matrix.os }}-${{ github.sha }} + test-unit: name: Unit test strategy: @@ -147,3 +182,44 @@ jobs: - name: Run e2e tests run: pnpm test:e2e + + test-e2e-rolldown: + name: E2E test for rolldown build + + needs: + - build-rolldown + + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + node: [18.19, 20, 22] + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout codes + uses: actions/checkout@v4 + + - name: Enable corepack + run: corepack enable + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install --no-frozen-lockfile + + - name: Install Playwright + run: pnpm playwright-core install chromium + + - name: Restore dist cache + uses: actions/cache@v4 + with: + path: packages/*/dist + key: build-rolldown-vue-i18n-os-${{ matrix.os }}-${{ github.sha }} + + - name: Run e2e tests + run: pnpm test:e2e From 917dad12999765e447e6a873aaedc0f2f6657277 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 6 Jan 2025 23:50:22 +0900 Subject: [PATCH 18/21] fix: dts scripts --- scripts/dts.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/dts.ts b/scripts/dts.ts index 819258a12..c98745dce 100644 --- a/scripts/dts.ts +++ b/scripts/dts.ts @@ -8,12 +8,12 @@ import type { Plugin, RollupOptions } from 'rollup' const __dirname = fileURLToPath(new URL('.', import.meta.url)) -if (!existsSync(path.resolve(__dirname, '../temp/packages'))) { - console.warn('no temp dts files found. run `pnpm build:rolldown` first') - process.exit(1) -} - export async function createDtsConfig(targets: string[]) { + if (!existsSync(path.resolve(__dirname, '../temp/packages'))) { + console.warn('no temp dts files found. run `pnpm build:rolldown` first') + process.exit(1) + } + const packages = await fs.readdir(path.resolve(__dirname, '../temp/packages')) const targetPackages = targets ? packages.filter(pkg => targets.includes(pkg)) From e34d1ad98383a31d3000c294412628798bb9dee2 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Tue, 7 Jan 2025 00:17:22 +0900 Subject: [PATCH 19/21] fix: update deps --- package.json | 1 + pnpm-lock.yaml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/package.json b/package.json index 565ff3516..48bab14f6 100644 --- a/package.json +++ b/package.json @@ -85,6 +85,7 @@ "@eslint/js": "^9.9.1", "@intlify/core-base": "workspace:*", "@intlify/message-compiler": "workspace:*", + "@intlify/vue-i18n-core": "workspace:*", "@microsoft/api-extractor": "7.15.2", "@rolldown/plugin-node-polyfills": "^1.0.0", "@rollup/plugin-commonjs": "^25.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f6fb42975..e8a360168 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -21,6 +21,9 @@ importers: '@intlify/message-compiler': specifier: workspace:* version: link:packages/message-compiler + '@intlify/vue-i18n-core': + specifier: workspace:* + version: link:packages/vue-i18n-core '@microsoft/api-extractor': specifier: 7.15.2 version: 7.15.2 From 2120e87ada819e8eedceef406a26809deb1ef70f Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Tue, 7 Jan 2025 00:23:24 +0900 Subject: [PATCH 20/21] chore: disable e2e for rolldown --- .github/workflows/ci.yml | 60 ++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3c8e121a..f198744ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -183,43 +183,43 @@ jobs: - name: Run e2e tests run: pnpm test:e2e - test-e2e-rolldown: - name: E2E test for rolldown build + # test-e2e-rolldown: + # name: E2E test for rolldown build - needs: - - build-rolldown + # needs: + # - build-rolldown - strategy: - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - node: [18.19, 20, 22] + # strategy: + # matrix: + # os: [ubuntu-latest, windows-latest, macos-latest] + # node: [18.19, 20, 22] - runs-on: ${{ matrix.os }} + # runs-on: ${{ matrix.os }} - steps: - - name: Checkout codes - uses: actions/checkout@v4 + # steps: + # - name: Checkout codes + # uses: actions/checkout@v4 - - name: Enable corepack - run: corepack enable + # - name: Enable corepack + # run: corepack enable - - name: Setup node - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node }} - cache: 'pnpm' + # - name: Setup node + # uses: actions/setup-node@v4 + # with: + # node-version: ${{ matrix.node }} + # cache: 'pnpm' - - name: Install dependencies - run: pnpm install --no-frozen-lockfile + # - name: Install dependencies + # run: pnpm install --no-frozen-lockfile - - name: Install Playwright - run: pnpm playwright-core install chromium + # - name: Install Playwright + # run: pnpm playwright-core install chromium - - name: Restore dist cache - uses: actions/cache@v4 - with: - path: packages/*/dist - key: build-rolldown-vue-i18n-os-${{ matrix.os }}-${{ github.sha }} + # - name: Restore dist cache + # uses: actions/cache@v4 + # with: + # path: packages/*/dist + # key: build-rolldown-vue-i18n-os-${{ matrix.os }}-${{ github.sha }} - - name: Run e2e tests - run: pnpm test:e2e + # - name: Run e2e tests + # run: pnpm test:e2e From 8609c633b6405f4624c48bd2631ca4e9649dd95a Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Tue, 7 Jan 2025 00:49:09 +0900 Subject: [PATCH 21/21] chore: refactor rollup building --- api-extractor.json | 2 +- rollup.config.mjs | 8 +++++++- scripts/build.ts | 22 +++++++++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/api-extractor.json b/api-extractor.json index 3261413ed..66d483c65 100644 --- a/api-extractor.json +++ b/api-extractor.json @@ -303,7 +303,7 @@ * * DEFAULT VALUE: "warning" */ - "logLevel": "warning", + "logLevel": "none", /* FIXME: Change to "warning" */ /** * When addToApiReportFile is true: If API Extractor is configured to write an API report file (.api.md), diff --git a/rollup.config.mjs b/rollup.config.mjs index 62efe8272..d017270bb 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -296,7 +296,13 @@ function createConfig(format, _output, plugins = []) { ], output, onwarn: (msg, warn) => { - if (!/Circular/.test(msg)) { + if ( + !( + msg.code == 'CIRCULAR_DEPENDENCY' || + msg.code == 'EMPTY_BUNDLE' || + msg.code == 'UNRESOLVED_IMPORT' + ) + ) { warn(msg) } }, diff --git a/scripts/build.ts b/scripts/build.ts index e7bcfb4e3..3ca8614c8 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -109,6 +109,10 @@ async function main() { if (size) { await checkAllSizes(resolvedTargets) } + + if (buildTypes) { + await buildTypingsAll(resolvedTargets) + } } async function buildAll(targets: string[]) { @@ -117,6 +121,12 @@ async function main() { console.log(`\nbuilt in ${(performance.now() - start).toFixed(2)}ms.`) } + async function buildTypingsAll(targets: string[]) { + const start = performance.now() + await runParallel(os.cpus().length, targets, buildTypings) + console.log(`\nbundle dts in ${(performance.now() - start).toFixed(2)}ms.`) + } + async function runParallel( maxConcurrency: number, source: string[], @@ -176,8 +186,18 @@ async function main() { ], { stdio: 'inherit' } ) + } + + async function buildTypings(target: string) { + const pkgDir = path.resolve(__dirname, `../packages/${target}`) + const pkg = await readJson(`${pkgDir}/package.json`) + + // only build published packages for release + if (isRelease && pkg.private) { + return + } - if (buildTypes && pkg.types) { + if (pkg.types) { console.log() console.log( pc.bold(pc.yellow(`Rolling up type definitions for ${target}...`))