From f909dd4ab13869bd127e01cb2cdb05ed7df3eba6 Mon Sep 17 00:00:00 2001 From: shoonia Date: Sun, 24 Nov 2024 16:23:15 +0200 Subject: [PATCH 01/11] Try --- .gitignore | 4 + eslint.config.js | 5 +- jest.config.js | 10 +- package-lock.json | 184 +++++++++--------- package.json | 6 +- rollup.build.js | 33 ++++ rollup.config.js | 45 ++--- src/plugins/html/index.d.ts | 11 ++ src/plugins/html/index.ts | 6 + src/plugins/html/package.json | 18 ++ tests/DOMEvents/$.spec.tsx | 2 +- tests/HTMLTemplateElement.spec.tsx | 2 +- tests/e2e.add-item.spec.tsx | 2 +- .../{Extend.spec.tsx => extensions.spec.tsx} | 2 +- tests/plugins/html.spec.tsx | 26 +++ tests/tsconfig.json | 5 +- tsconfig.json | 4 + 17 files changed, 239 insertions(+), 126 deletions(-) create mode 100644 rollup.build.js create mode 100644 src/plugins/html/index.d.ts create mode 100644 src/plugins/html/index.ts create mode 100644 src/plugins/html/package.json rename tests/lib/{Extend.spec.tsx => extensions.spec.tsx} (97%) create mode 100644 tests/plugins/html.spec.tsx diff --git a/.gitignore b/.gitignore index be706d28..fdcc400f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,9 @@ jsx-runtime/ dist/ __test/ +plugins/ +!src/plugins/ +!tests/plugins/ + .DS_Store *.tgz diff --git a/eslint.config.js b/eslint.config.js index 6a0616b5..03a58ead 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -4,8 +4,9 @@ import ts from 'typescript-eslint'; export default ts.config( { ignores: [ - 'babel-preset/', - 'jsx-runtime/', + './babel-preset/', + './jsx-runtime/', + './plugins/' ], }, js.configs.recommended, diff --git a/jest.config.js b/jest.config.js index 984f5fce..04bc5593 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,12 +1,18 @@ /** @type {import('jest').Config} */ const config = { cache: false, - rootDir: 'tests', + rootDir: '.', transform: { '\\.tsx?$': 'babel-jest', }, setupFilesAfterEnv: [ - '/utils/jest-setup.ts' + '/tests/utils/jest-setup.ts' + ], + moduleNameMapper: { + 'jsx-dom-runtime/$1': '/$1', + }, + modulePathIgnorePatterns: [ + '/src/', ], testEnvironment: 'jest-environment-jsdom', extensionsToTreatAsEsm: ['.tsx', '.ts'], diff --git a/package-lock.json b/package-lock.json index 651ebf37..8ecb400c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,9 +30,9 @@ "babel-plugin-transform-lhs-constants": "^1.2.0", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", - "rollup": "^4.27.3", + "rollup": "^4.27.4", "size-limit": "^11.1.6", - "typescript": "^5.6.3", + "typescript": "^5.7.2", "typescript-eslint": "^8.15.0" }, "peerDependencies": { @@ -1943,9 +1943,9 @@ } }, "node_modules/@rollup/rollup-android-arm-eabi": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.27.3.tgz", - "integrity": "sha512-EzxVSkIvCFxUd4Mgm4xR9YXrcp976qVaHnqom/Tgm+vU79k4vV4eYTjmRvGfeoW8m9LVcsAy/lGjcgVegKEhLQ==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.27.4.tgz", + "integrity": "sha512-2Y3JT6f5MrQkICUyRVCw4oa0sutfAsgaSsb0Lmmy1Wi2y7X5vT9Euqw4gOsCyy0YfKURBg35nhUKZS4mDcfULw==", "cpu": [ "arm" ], @@ -1957,9 +1957,9 @@ ] }, "node_modules/@rollup/rollup-android-arm64": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.27.3.tgz", - "integrity": "sha512-LJc5pDf1wjlt9o/Giaw9Ofl+k/vLUaYsE2zeQGH85giX2F+wn/Cg8b3c5CDP3qmVmeO5NzwVUzQQxwZvC2eQKw==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.27.4.tgz", + "integrity": "sha512-wzKRQXISyi9UdCVRqEd0H4cMpzvHYt1f/C3CoIjES6cG++RHKhrBj2+29nPF0IB5kpy9MS71vs07fvrNGAl/iA==", "cpu": [ "arm64" ], @@ -1971,9 +1971,9 @@ ] }, "node_modules/@rollup/rollup-darwin-arm64": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.27.3.tgz", - "integrity": "sha512-OuRysZ1Mt7wpWJ+aYKblVbJWtVn3Cy52h8nLuNSzTqSesYw1EuN6wKp5NW/4eSre3mp12gqFRXOKTcN3AI3LqA==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.27.4.tgz", + "integrity": "sha512-PlNiRQapift4LNS8DPUHuDX/IdXiLjf8mc5vdEmUR0fF/pyy2qWwzdLjB+iZquGr8LuN4LnUoSEvKRwjSVYz3Q==", "cpu": [ "arm64" ], @@ -1985,9 +1985,9 @@ ] }, "node_modules/@rollup/rollup-darwin-x64": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.27.3.tgz", - "integrity": "sha512-xW//zjJMlJs2sOrCmXdB4d0uiilZsOdlGQIC/jjmMWT47lkLLoB1nsNhPUcnoqyi5YR6I4h+FjBpILxbEy8JRg==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.27.4.tgz", + "integrity": "sha512-o9bH2dbdgBDJaXWJCDTNDYa171ACUdzpxSZt+u/AAeQ20Nk5x+IhA+zsGmrQtpkLiumRJEYef68gcpn2ooXhSQ==", "cpu": [ "x64" ], @@ -1999,9 +1999,9 @@ ] }, "node_modules/@rollup/rollup-freebsd-arm64": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.27.3.tgz", - "integrity": "sha512-58E0tIcwZ+12nK1WiLzHOD8I0d0kdrY/+o7yFVPRHuVGY3twBwzwDdTIBGRxLmyjciMYl1B/U515GJy+yn46qw==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.27.4.tgz", + "integrity": "sha512-NBI2/i2hT9Q+HySSHTBh52da7isru4aAAo6qC3I7QFVsuhxi2gM8t/EI9EVcILiHLj1vfi+VGGPaLOUENn7pmw==", "cpu": [ "arm64" ], @@ -2013,9 +2013,9 @@ ] }, "node_modules/@rollup/rollup-freebsd-x64": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.27.3.tgz", - "integrity": "sha512-78fohrpcVwTLxg1ZzBMlwEimoAJmY6B+5TsyAZ3Vok7YabRBUvjYTsRXPTjGEvv/mfgVBepbW28OlMEz4w8wGA==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.27.4.tgz", + "integrity": "sha512-wYcC5ycW2zvqtDYrE7deary2P2UFmSh85PUpAx+dwTCO9uw3sgzD6Gv9n5X4vLaQKsrfTSZZ7Z7uynQozPVvWA==", "cpu": [ "x64" ], @@ -2027,9 +2027,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-gnueabihf": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.27.3.tgz", - "integrity": "sha512-h2Ay79YFXyQi+QZKo3ISZDyKaVD7uUvukEHTOft7kh00WF9mxAaxZsNs3o/eukbeKuH35jBvQqrT61fzKfAB/Q==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.27.4.tgz", + "integrity": "sha512-9OwUnK/xKw6DyRlgx8UizeqRFOfi9mf5TYCw1uolDaJSbUmBxP85DE6T4ouCMoN6pXw8ZoTeZCSEfSaYo+/s1w==", "cpu": [ "arm" ], @@ -2041,9 +2041,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-musleabihf": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.27.3.tgz", - "integrity": "sha512-Sv2GWmrJfRY57urktVLQ0VKZjNZGogVtASAgosDZ1aUB+ykPxSi3X1nWORL5Jk0sTIIwQiPH7iE3BMi9zGWfkg==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.27.4.tgz", + "integrity": "sha512-Vgdo4fpuphS9V24WOV+KwkCVJ72u7idTgQaBoLRD0UxBAWTF9GWurJO9YD9yh00BzbkhpeXtm6na+MvJU7Z73A==", "cpu": [ "arm" ], @@ -2055,9 +2055,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-gnu": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.27.3.tgz", - "integrity": "sha512-FPoJBLsPW2bDNWjSrwNuTPUt30VnfM8GPGRoLCYKZpPx0xiIEdFip3dH6CqgoT0RnoGXptaNziM0WlKgBc+OWQ==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.27.4.tgz", + "integrity": "sha512-pleyNgyd1kkBkw2kOqlBx+0atfIIkkExOTiifoODo6qKDSpnc6WzUY5RhHdmTdIJXBdSnh6JknnYTtmQyobrVg==", "cpu": [ "arm64" ], @@ -2069,9 +2069,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-musl": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.27.3.tgz", - "integrity": "sha512-TKxiOvBorYq4sUpA0JT+Fkh+l+G9DScnG5Dqx7wiiqVMiRSkzTclP35pE6eQQYjP4Gc8yEkJGea6rz4qyWhp3g==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.27.4.tgz", + "integrity": "sha512-caluiUXvUuVyCHr5DxL8ohaaFFzPGmgmMvwmqAITMpV/Q+tPoaHZ/PWa3t8B2WyoRcIIuu1hkaW5KkeTDNSnMA==", "cpu": [ "arm64" ], @@ -2083,9 +2083,9 @@ ] }, "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.27.3.tgz", - "integrity": "sha512-v2M/mPvVUKVOKITa0oCFksnQQ/TqGrT+yD0184/cWHIu0LoIuYHwox0Pm3ccXEz8cEQDLk6FPKd1CCm+PlsISw==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.27.4.tgz", + "integrity": "sha512-FScrpHrO60hARyHh7s1zHE97u0KlT/RECzCKAdmI+LEoC1eDh/RDji9JgFqyO+wPDb86Oa/sXkily1+oi4FzJQ==", "cpu": [ "ppc64" ], @@ -2097,9 +2097,9 @@ ] }, "node_modules/@rollup/rollup-linux-riscv64-gnu": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.27.3.tgz", - "integrity": "sha512-LdrI4Yocb1a/tFVkzmOE5WyYRgEBOyEhWYJe4gsDWDiwnjYKjNs7PS6SGlTDB7maOHF4kxevsuNBl2iOcj3b4A==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.27.4.tgz", + "integrity": "sha512-qyyprhyGb7+RBfMPeww9FlHwKkCXdKHeGgSqmIXw9VSUtvyFZ6WZRtnxgbuz76FK7LyoN8t/eINRbPUcvXB5fw==", "cpu": [ "riscv64" ], @@ -2111,9 +2111,9 @@ ] }, "node_modules/@rollup/rollup-linux-s390x-gnu": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.27.3.tgz", - "integrity": "sha512-d4wVu6SXij/jyiwPvI6C4KxdGzuZOvJ6y9VfrcleHTwo68fl8vZC5ZYHsCVPUi4tndCfMlFniWgwonQ5CUpQcA==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.27.4.tgz", + "integrity": "sha512-PFz+y2kb6tbh7m3A7nA9++eInGcDVZUACulf/KzDtovvdTizHpZaJty7Gp0lFwSQcrnebHOqxF1MaKZd7psVRg==", "cpu": [ "s390x" ], @@ -2125,9 +2125,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-gnu": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.27.3.tgz", - "integrity": "sha512-/6bn6pp1fsCGEY5n3yajmzZQAh+mW4QPItbiWxs69zskBzJuheb3tNynEjL+mKOsUSFK11X4LYF2BwwXnzWleA==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.27.4.tgz", + "integrity": "sha512-Ni8mMtfo+o/G7DVtweXXV/Ol2TFf63KYjTtoZ5f078AUgJTmaIJnj4JFU7TK/9SVWTaSJGxPi5zMDgK4w+Ez7Q==", "cpu": [ "x64" ], @@ -2139,9 +2139,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-musl": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.27.3.tgz", - "integrity": "sha512-nBXOfJds8OzUT1qUreT/en3eyOXd2EH5b0wr2bVB5999qHdGKkzGzIyKYaKj02lXk6wpN71ltLIaQpu58YFBoQ==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.27.4.tgz", + "integrity": "sha512-5AeeAF1PB9TUzD+3cROzFTnAJAcVUGLuR8ng0E0WXGkYhp6RD6L+6szYVX+64Rs0r72019KHZS1ka1q+zU/wUw==", "cpu": [ "x64" ], @@ -2153,9 +2153,9 @@ ] }, "node_modules/@rollup/rollup-win32-arm64-msvc": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.27.3.tgz", - "integrity": "sha512-ogfbEVQgIZOz5WPWXF2HVb6En+kWzScuxJo/WdQTqEgeyGkaa2ui5sQav9Zkr7bnNCLK48uxmmK0TySm22eiuw==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.27.4.tgz", + "integrity": "sha512-yOpVsA4K5qVwu2CaS3hHxluWIK5HQTjNV4tWjQXluMiiiu4pJj4BN98CvxohNCpcjMeTXk/ZMJBRbgRg8HBB6A==", "cpu": [ "arm64" ], @@ -2167,9 +2167,9 @@ ] }, "node_modules/@rollup/rollup-win32-ia32-msvc": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.27.3.tgz", - "integrity": "sha512-ecE36ZBMLINqiTtSNQ1vzWc5pXLQHlf/oqGp/bSbi7iedcjcNb6QbCBNG73Euyy2C+l/fn8qKWEwxr+0SSfs3w==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.27.4.tgz", + "integrity": "sha512-KtwEJOaHAVJlxV92rNYiG9JQwQAdhBlrjNRp7P9L8Cb4Rer3in+0A+IPhJC9y68WAi9H0sX4AiG2NTsVlmqJeQ==", "cpu": [ "ia32" ], @@ -2181,9 +2181,9 @@ ] }, "node_modules/@rollup/rollup-win32-x64-msvc": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.27.3.tgz", - "integrity": "sha512-vliZLrDmYKyaUoMzEbMTg2JkerfBjn03KmAw9CykO0Zzkzoyd7o3iZNam/TpyWNjNT+Cz2iO3P9Smv2wgrR+Eg==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.27.4.tgz", + "integrity": "sha512-3j4jx1TppORdTAoBJRd+/wJRGCPC0ETWkXOecJ6PPZLj6SptXkrXcNqdj0oclbKML6FkQltdz7bBA3rUSirZug==", "cpu": [ "x64" ], @@ -2508,9 +2508,9 @@ "peer": true }, "node_modules/@types/node": { - "version": "22.9.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.9.0.tgz", - "integrity": "sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==", + "version": "22.9.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.9.3.tgz", + "integrity": "sha512-F3u1fs/fce3FFk+DAxbxc78DF8x0cY09RRL8GnXLmkJ1jvx3TtPdWoTT5/NiYfI5ASqXBmfqJi9dZ3gxMx4lzw==", "dev": true, "license": "MIT", "dependencies": { @@ -3197,9 +3197,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001680", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001680.tgz", - "integrity": "sha512-rPQy70G6AGUMnbwS1z6Xg+RkHYPAi18ihs47GH0jcxIG7wArmPgY3XbS2sRdBbxJljp3thdT8BIqv9ccCypiPA==", + "version": "1.0.30001684", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001684.tgz", + "integrity": "sha512-G1LRwLIQjBQoyq0ZJGqGIJUXzJ8irpbjHLpVRXDvBEScFJ9b17sgK6vlx0GAJFE21okD7zXl08rRRUfq6HdoEQ==", "dev": true, "funding": [ { @@ -3575,9 +3575,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.63", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.63.tgz", - "integrity": "sha512-ddeXKuY9BHo/mw145axlyWjlJ1UBt4WK3AlvkT7W2AbqfRQoacVoRUCF6wL3uIx/8wT9oLKXzI+rFqHHscByaA==", + "version": "1.5.64", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.64.tgz", + "integrity": "sha512-IXEuxU+5ClW2IGEYFC2T7szbyVgehupCWQe5GNh+H065CD6U6IFN0s4KeAMFGNmQolRU4IV7zGBWSYMmZ8uuqQ==", "dev": true, "license": "ISC" }, @@ -6374,9 +6374,9 @@ } }, "node_modules/psl": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/psl/-/psl-1.10.0.tgz", - "integrity": "sha512-KSKHEbjAnpUuAUserOq0FxGXCUrzC3WniuSJhvdbs102rL55266ZcHBqLWOsG30spQMlPdpy7icATiAQehg/iA==", + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.13.0.tgz", + "integrity": "sha512-BFwmFXiJoFqlUpZ5Qssolv15DMyc84gTBds1BjsV1BfXEo1UyyD7GsmN67n7J77uRhoSNW1AXtXKPLcBFQn9Aw==", "dev": true, "license": "MIT", "dependencies": { @@ -6560,9 +6560,9 @@ } }, "node_modules/rollup": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.27.3.tgz", - "integrity": "sha512-SLsCOnlmGt9VoZ9Ek8yBK8tAdmPHeppkw+Xa7yDlCEhDTvwYei03JlWo1fdc7YTfLZ4tD8riJCUyAgTbszk1fQ==", + "version": "4.27.4", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.27.4.tgz", + "integrity": "sha512-RLKxqHEMjh/RGLsDxAEsaLO3mWgyoU6x9w6n1ikAzet4B3gI2/3yP6PWY2p9QzRTh6MfEIXB3MwsOY0Iv3vNrw==", "dev": true, "license": "MIT", "dependencies": { @@ -6576,24 +6576,24 @@ "npm": ">=8.0.0" }, "optionalDependencies": { - "@rollup/rollup-android-arm-eabi": "4.27.3", - "@rollup/rollup-android-arm64": "4.27.3", - "@rollup/rollup-darwin-arm64": "4.27.3", - "@rollup/rollup-darwin-x64": "4.27.3", - "@rollup/rollup-freebsd-arm64": "4.27.3", - "@rollup/rollup-freebsd-x64": "4.27.3", - "@rollup/rollup-linux-arm-gnueabihf": "4.27.3", - "@rollup/rollup-linux-arm-musleabihf": "4.27.3", - "@rollup/rollup-linux-arm64-gnu": "4.27.3", - "@rollup/rollup-linux-arm64-musl": "4.27.3", - "@rollup/rollup-linux-powerpc64le-gnu": "4.27.3", - "@rollup/rollup-linux-riscv64-gnu": "4.27.3", - "@rollup/rollup-linux-s390x-gnu": "4.27.3", - "@rollup/rollup-linux-x64-gnu": "4.27.3", - "@rollup/rollup-linux-x64-musl": "4.27.3", - "@rollup/rollup-win32-arm64-msvc": "4.27.3", - "@rollup/rollup-win32-ia32-msvc": "4.27.3", - "@rollup/rollup-win32-x64-msvc": "4.27.3", + "@rollup/rollup-android-arm-eabi": "4.27.4", + "@rollup/rollup-android-arm64": "4.27.4", + "@rollup/rollup-darwin-arm64": "4.27.4", + "@rollup/rollup-darwin-x64": "4.27.4", + "@rollup/rollup-freebsd-arm64": "4.27.4", + "@rollup/rollup-freebsd-x64": "4.27.4", + "@rollup/rollup-linux-arm-gnueabihf": "4.27.4", + "@rollup/rollup-linux-arm-musleabihf": "4.27.4", + "@rollup/rollup-linux-arm64-gnu": "4.27.4", + "@rollup/rollup-linux-arm64-musl": "4.27.4", + "@rollup/rollup-linux-powerpc64le-gnu": "4.27.4", + "@rollup/rollup-linux-riscv64-gnu": "4.27.4", + "@rollup/rollup-linux-s390x-gnu": "4.27.4", + "@rollup/rollup-linux-x64-gnu": "4.27.4", + "@rollup/rollup-linux-x64-musl": "4.27.4", + "@rollup/rollup-win32-arm64-msvc": "4.27.4", + "@rollup/rollup-win32-ia32-msvc": "4.27.4", + "@rollup/rollup-win32-x64-msvc": "4.27.4", "fsevents": "~2.3.2" } }, @@ -7021,9 +7021,9 @@ } }, "node_modules/typescript": { - "version": "5.6.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz", - "integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz", + "integrity": "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==", "dev": true, "license": "Apache-2.0", "bin": { diff --git a/package.json b/package.json index caa0aed4..20244f37 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "import": "./jsx-runtime/index.js", "require": "./jsx-runtime/index.cjs" }, + "./plugins/*": "./plugins/*", "./babel-preset": "./babel-preset/index.cjs", "./package.json": "./package.json" }, @@ -55,14 +56,15 @@ "babel-plugin-transform-lhs-constants": "^1.2.0", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", - "rollup": "^4.27.3", + "rollup": "^4.27.4", "size-limit": "^11.1.6", - "typescript": "^5.6.3", + "typescript": "^5.7.2", "typescript-eslint": "^8.15.0" }, "files": [ "babel-preset", "jsx-runtime", + "plugins", "index.d.ts" ], "keywords": [ diff --git a/rollup.build.js b/rollup.build.js new file mode 100644 index 00000000..9b113559 --- /dev/null +++ b/rollup.build.js @@ -0,0 +1,33 @@ +import { existsSync } from 'node:fs'; +import { rm, mkdir, readdir, cp } from 'node:fs/promises'; + +export const emptyDir = async (path) => { + if (existsSync(path)) await rm(path, { recursive: true }); + await mkdir(path); +}; + +export const buildPlugins = async (plugins) => { + const [files] = await Promise.all([ + readdir('./src/plugins'), + cp('./src/plugins', './plugins', { recursive: true }), + ]); + + return files.map((i) => { + return { + input: `./plugins/${i}/index.ts`, + output: [ + { + file: `./plugins/${i}/index.js`, + format: 'es', + }, + // { + // file: `./plugins/${i}/index.cjs`, + // format: 'cjs', + // esModule: false, + // }, + ], + external: ['jsx-dom-runtime'], + plugins, + }; + }); +}; diff --git a/rollup.config.js b/rollup.config.js index e97afe52..0bf60e89 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,23 +1,9 @@ -import { existsSync } from 'node:fs'; -import { rm, mkdir, writeFile } from 'node:fs/promises'; +import { writeFile } from 'node:fs/promises'; import { babel } from '@rollup/plugin-babel'; import { nodeResolve } from '@rollup/plugin-node-resolve'; -import pkg from './package.json' with { type: 'json' }; - -const emptyDir = async (path) => { - if (existsSync(path)) await rm(path, { recursive: true }); - await mkdir(path); -}; -await Promise.all([ - emptyDir('./babel-preset'), - emptyDir('./jsx-runtime'), -]); - -await writeFile( - './jsx-runtime/index.d.ts', - 'export * from "../index"', -); +import pkg from './package.json' with { type: 'json' }; +import { emptyDir, buildPlugins } from './rollup.build.js'; const extensions = ['.ts']; @@ -38,7 +24,22 @@ const plugins = [ }), ]; +await Promise.all([ + emptyDir('./babel-preset'), + emptyDir('./jsx-runtime'), + emptyDir('./plugins'), +]); + +const [list] = await Promise.all([ + buildPlugins(plugins), + writeFile( + './jsx-runtime/index.d.ts', + 'export * from "../index"', + ), +]); + export default [ + ...list, { input: 'src/babel/index.ts', output: [ @@ -58,11 +59,11 @@ export default [ file: pkg.module, format: 'es', }, - { - file: pkg.main, - format: 'cjs', - esModule: false, - }, + // { + // file: pkg.main, + // format: 'cjs', + // esModule: false, + // }, ], plugins, }, diff --git a/src/plugins/html/index.d.ts b/src/plugins/html/index.d.ts new file mode 100644 index 00000000..65696ba2 --- /dev/null +++ b/src/plugins/html/index.d.ts @@ -0,0 +1,11 @@ +export declare function initHtml(): void + +declare global { + namespace JSX { + interface Attributes { + innerHTML?: string + innerText?: string + textContent?: string + } + } +} diff --git a/src/plugins/html/index.ts b/src/plugins/html/index.ts new file mode 100644 index 00000000..b135e8df --- /dev/null +++ b/src/plugins/html/index.ts @@ -0,0 +1,6 @@ +import { properties } from 'jsx-dom-runtime'; + +export const initHtml = () => /*#__PURE__*/ properties + .add('innerHTML') + .add('innerText') + .add('textContent'); diff --git a/src/plugins/html/package.json b/src/plugins/html/package.json new file mode 100644 index 00000000..fd2193da --- /dev/null +++ b/src/plugins/html/package.json @@ -0,0 +1,18 @@ +{ + "name": "@jsx-dom-runtime/html", + "version": "0.1.0", + "private": true, + "type": "module", + "main": "index.cjs", + "module": "index.js", + "types": "./index.d.ts", + "exports": { + ".": { + "types": "./index.d.ts", + "import": "./index.js", + "require": "./index.cjs" + } + }, + "sideEffects": false, + "license": "MIT" +} diff --git a/tests/DOMEvents/$.spec.tsx b/tests/DOMEvents/$.spec.tsx index 98733e2d..6b104a08 100644 --- a/tests/DOMEvents/$.spec.tsx +++ b/tests/DOMEvents/$.spec.tsx @@ -1,7 +1,7 @@ import { jest } from '@jest/globals'; import { fireEvent } from '@testing-library/dom'; -import { jsx } from '../..'; +import { jsx } from 'jsx-dom-runtime'; describe('$', () => { it('should add a few handlers', () => { diff --git a/tests/HTMLTemplateElement.spec.tsx b/tests/HTMLTemplateElement.spec.tsx index be19d607..98c29ba7 100644 --- a/tests/HTMLTemplateElement.spec.tsx +++ b/tests/HTMLTemplateElement.spec.tsx @@ -1,4 +1,4 @@ -import { useRef } from '..'; +import { useRef } from 'jsx-dom-runtime'; describe('HTMLTemplateElement', () => { it('should append child node', () => { diff --git a/tests/e2e.add-item.spec.tsx b/tests/e2e.add-item.spec.tsx index 34e44097..bcb30b95 100644 --- a/tests/e2e.add-item.spec.tsx +++ b/tests/e2e.add-item.spec.tsx @@ -1,4 +1,4 @@ -import { useRef } from '..'; +import { useRef } from 'jsx-dom-runtime'; import { Driver } from './utils'; describe('e2e test', () => { diff --git a/tests/lib/Extend.spec.tsx b/tests/lib/extensions.spec.tsx similarity index 97% rename from tests/lib/Extend.spec.tsx rename to tests/lib/extensions.spec.tsx index 7cdfa4a9..49c14988 100644 --- a/tests/lib/Extend.spec.tsx +++ b/tests/lib/extensions.spec.tsx @@ -1,6 +1,6 @@ import { extensions } from 'jsx-dom-runtime'; -describe('Extend', () => { +describe('extensions', () => { afterEach(() => { extensions.clear(); }); diff --git a/tests/plugins/html.spec.tsx b/tests/plugins/html.spec.tsx new file mode 100644 index 00000000..bd4af3c3 --- /dev/null +++ b/tests/plugins/html.spec.tsx @@ -0,0 +1,26 @@ +import { initHtml } from 'jsx-dom-runtime/plugins/html'; + +initHtml(); + +describe('properties', () => { + it('should add support of `textContent` property', () => { + expect(
).not.toHaveAttribute('textcontent'); + expect(
).toHaveInnerHTML('context'); + }); + + it('should add support of `innerHTML` property', () => { + expect(

).not.toHaveAttribute('innerhtml'); + expect(

).toHaveInnerHTML('

html

'); + }); + + it('should add support of `innerText` property', () => { + expect().not.toHaveAttribute('innertext'); + expect().toHaveInnerHTML('text'); + }); + + it('should transform', async () => { + await expect('
').toBeTransform( + 'import{jsx as _jsx}from"jsx-dom-runtime";/*#__PURE__*/_jsx("div",{textContent:"context"});' + ); + }); +}); diff --git a/tests/tsconfig.json b/tests/tsconfig.json index 3aa9087f..57700dba 100644 --- a/tests/tsconfig.json +++ b/tests/tsconfig.json @@ -16,8 +16,9 @@ "DOM" ], "paths": { - "jsx-dom-runtime": [".."], - "jsx-dom-runtime/jsx-runtime": [".."], + "jsx-dom-runtime": ["../jsx-runtime"], + "jsx-dom-runtime/jsx-runtime": ["../jsx-runtime"], + "jsx-dom-runtime/plugins/*": ["../plugins/*"], } }, "include": [ diff --git a/tsconfig.json b/tsconfig.json index c71fef1e..90c828eb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,6 +15,10 @@ "ES2023", "DOM" ], + "paths": { + "jsx-dom-runtime": ["."], + "jsx-dom-runtime/*": ["./*"], + } }, "include": [ "./tests/**/*.ts", From 52aa3785b6278546d34241d2fcc230681e6312b9 Mon Sep 17 00:00:00 2001 From: shoonia Date: Thu, 28 Nov 2024 00:38:59 +0200 Subject: [PATCH 02/11] Add html plugin --- .gitignore | 4 +- jest.config.js | 3 -- rollup.build.js | 51 +++++++++++---------- rollup.config.js | 10 ++-- src/index.ts | 2 +- src/{jsxRuntime.ts => jsx-runtime/index.ts} | 0 src/lib/Template.ts | 2 +- src/plugins/html/index.d.ts | 1 - src/plugins/html/index.ts | 3 +- src/plugins/html/package.json | 18 -------- tests/lib/properties.spec.tsx | 31 ------------- tests/plugins/html.spec.tsx | 5 -- tests/tsconfig.json | 3 +- 13 files changed, 40 insertions(+), 93 deletions(-) rename src/{jsxRuntime.ts => jsx-runtime/index.ts} (100%) delete mode 100644 src/plugins/html/package.json diff --git a/.gitignore b/.gitignore index fdcc400f..bf7f464f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,11 @@ node_modules/ babel-preset/ -jsx-runtime/ dist/ __test/ +jsx-runtime/ +!src/jsx-runtime/ + plugins/ !src/plugins/ !tests/plugins/ diff --git a/jest.config.js b/jest.config.js index 04bc5593..fbcddb58 100644 --- a/jest.config.js +++ b/jest.config.js @@ -8,9 +8,6 @@ const config = { setupFilesAfterEnv: [ '/tests/utils/jest-setup.ts' ], - moduleNameMapper: { - 'jsx-dom-runtime/$1': '/$1', - }, modulePathIgnorePatterns: [ '/src/', ], diff --git a/rollup.build.js b/rollup.build.js index 9b113559..52dda4a1 100644 --- a/rollup.build.js +++ b/rollup.build.js @@ -1,5 +1,5 @@ import { existsSync } from 'node:fs'; -import { rm, mkdir, readdir, cp } from 'node:fs/promises'; +import { rm, mkdir, readdir, copyFile } from 'node:fs/promises'; export const emptyDir = async (path) => { if (existsSync(path)) await rm(path, { recursive: true }); @@ -7,27 +7,32 @@ export const emptyDir = async (path) => { }; export const buildPlugins = async (plugins) => { - const [files] = await Promise.all([ - readdir('./src/plugins'), - cp('./src/plugins', './plugins', { recursive: true }), - ]); + const files = await readdir('./src/plugins'); - return files.map((i) => { - return { - input: `./plugins/${i}/index.ts`, - output: [ - { - file: `./plugins/${i}/index.js`, - format: 'es', - }, - // { - // file: `./plugins/${i}/index.cjs`, - // format: 'cjs', - // esModule: false, - // }, - ], - external: ['jsx-dom-runtime'], - plugins, - }; - }); + return Promise.all( + files.map(async (i) => { + await mkdir(`./plugins/${i}`); + await copyFile( + `./src/plugins/${i}/index.d.ts`, + `./plugins/${i}/index.d.ts`, + ); + + return { + input: `./src/plugins/${i}/index.ts`, + output: [ + { + file: `./plugins/${i}/index.js`, + format: 'es', + }, + { + file: `./plugins/${i}/index.cjs`, + format: 'cjs', + esModule: false, + }, + ], + external: ['../../jsx-runtime'], + plugins, + }; + }), + ); }; diff --git a/rollup.config.js b/rollup.config.js index 0bf60e89..6f72fb72 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -59,11 +59,11 @@ export default [ file: pkg.module, format: 'es', }, - // { - // file: pkg.main, - // format: 'cjs', - // esModule: false, - // }, + { + file: pkg.main, + format: 'cjs', + esModule: false, + }, ], plugins, }, diff --git a/src/index.ts b/src/index.ts index 67c6266b..7bac9a8e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -export * from './jsxRuntime'; +export * from './jsx-runtime'; export * from './lib/useRef'; export * from './lib/Template'; export * from './lib/useText'; diff --git a/src/jsxRuntime.ts b/src/jsx-runtime/index.ts similarity index 100% rename from src/jsxRuntime.ts rename to src/jsx-runtime/index.ts diff --git a/src/lib/Template.ts b/src/lib/Template.ts index dd30f767..4d1fb912 100644 --- a/src/lib/Template.ts +++ b/src/lib/Template.ts @@ -1,4 +1,4 @@ -import { jsx } from '../jsxRuntime'; +import { jsx } from '../jsx-runtime'; export const parseFromString = (html: string) => /*#__PURE__*/ jsx('template', { diff --git a/src/plugins/html/index.d.ts b/src/plugins/html/index.d.ts index 65696ba2..a571f336 100644 --- a/src/plugins/html/index.d.ts +++ b/src/plugins/html/index.d.ts @@ -4,7 +4,6 @@ declare global { namespace JSX { interface Attributes { innerHTML?: string - innerText?: string textContent?: string } } diff --git a/src/plugins/html/index.ts b/src/plugins/html/index.ts index b135e8df..7a05ae59 100644 --- a/src/plugins/html/index.ts +++ b/src/plugins/html/index.ts @@ -1,6 +1,5 @@ -import { properties } from 'jsx-dom-runtime'; +import { properties } from '../../jsx-runtime'; export const initHtml = () => /*#__PURE__*/ properties .add('innerHTML') - .add('innerText') .add('textContent'); diff --git a/src/plugins/html/package.json b/src/plugins/html/package.json deleted file mode 100644 index fd2193da..00000000 --- a/src/plugins/html/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "@jsx-dom-runtime/html", - "version": "0.1.0", - "private": true, - "type": "module", - "main": "index.cjs", - "module": "index.js", - "types": "./index.d.ts", - "exports": { - ".": { - "types": "./index.d.ts", - "import": "./index.js", - "require": "./index.cjs" - } - }, - "sideEffects": false, - "license": "MIT" -} diff --git a/tests/lib/properties.spec.tsx b/tests/lib/properties.spec.tsx index b0ec883b..4a71ba71 100644 --- a/tests/lib/properties.spec.tsx +++ b/tests/lib/properties.spec.tsx @@ -3,13 +3,6 @@ import { properties } from 'jsx-dom-runtime'; /* eslint-disable @typescript-eslint/no-namespace */ declare global { namespace JSX { - // it should add types for all JSX elements - interface Attributes { - textContent?: string; - innerHTML?: string; - } - - // it should add types only for Audio element interface HTMLAudioElementAttributes { volume?: number; muted?: boolean; @@ -18,30 +11,6 @@ declare global { } describe('properties', () => { - it('should add support of `textContent` property', () => { - expect(
).toHaveAttribute('textcontent', 'hello'); - expect(
).toHaveTextContent(''); - - properties.add('textContent'); - - expect(
).not.toHaveAttribute('textcontent'); - expect(
).toHaveTextContent('hello'); - - properties.delete('textContent'); - }); - - it('should add html to component', () => { - expect(
).toHaveAttribute('innerhtml', '

text

'); - expect(
).toHaveInnerHTML(''); - - properties.add('innerHTML'); - - expect(
).not.toHaveAttribute('innerhtml'); - expect(
).toHaveInnerHTML('

text

'); - - properties.delete('innerHTML'); - }); - it('should add support of `volume` property', () => { expect(