diff --git a/.gitignore b/.gitignore index a37723c0..5c5b7b19 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,7 @@ gradle-app.setting ### VSCode ### *.code-workspace +bin/ ### WebStorm ### # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm diff --git a/package-lock.json b/package-lock.json index c4b8530f..69ec7057 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,9 +15,11 @@ "@babel/register": "^7.18.9", "@enonic-types/global": "^7.11.2", "@enonic-types/lib-event": "^7.11.2", + "@types/react": "^18.0.26", "autoprefixer": "^10.4.13", "babel-loader": "^9.1.2", "browserslist-config-enonic": "^1.0.7", + "core-js": "^3.27.2", "cross-env": "^7.0.3", "css-loader": "^6.7.3", "cssnano": "^5.1.14", @@ -32,9 +34,12 @@ "postcss": "^8.4.21", "postcss-loader": "^7.0.2", "postcss-normalize": "^10.0.1", + "q-i": "^2.0.1", "ramda": "^0.28.0", + "rimraf": "^4.1.2", "sass-loader": "^13.2.0", "style-loader": "^3.3.1", + "swc-loader": "^0.2.3", "terser-webpack-plugin": "^5.3.6", "ts-loader": "^9.4.2", "typescript": "^4.9.4", @@ -1819,6 +1824,260 @@ "node": ">=10" } }, + "node_modules/@npmcli/move-file/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/@npmcli/move-file/node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@npmcli/move-file/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/@npmcli/move-file/node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@swc/core": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.26.tgz", + "integrity": "sha512-U7vEsaLn3IGg0XCRLJX/GTkK9WIfFHUX5USdrp1L2QD29sWPe25HqNndXmUR9KytzKmpDMNoUuHyiuhpVrnNeQ==", + "dev": true, + "hasInstallScript": true, + "peer": true, + "engines": { + "node": ">=10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/swc" + }, + "optionalDependencies": { + "@swc/core-darwin-arm64": "1.3.26", + "@swc/core-darwin-x64": "1.3.26", + "@swc/core-linux-arm-gnueabihf": "1.3.26", + "@swc/core-linux-arm64-gnu": "1.3.26", + "@swc/core-linux-arm64-musl": "1.3.26", + "@swc/core-linux-x64-gnu": "1.3.26", + "@swc/core-linux-x64-musl": "1.3.26", + "@swc/core-win32-arm64-msvc": "1.3.26", + "@swc/core-win32-ia32-msvc": "1.3.26", + "@swc/core-win32-x64-msvc": "1.3.26" + } + }, + "node_modules/@swc/core-darwin-arm64": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.26.tgz", + "integrity": "sha512-FWWflBfKRYrUJtko2xiedC5XCa31O75IZZqnTWuLpe9g3C5tnUuF3M8LSXZS/dn6wprome1MhtG9GMPkSYkhkg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "peer": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-darwin-x64": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.3.26.tgz", + "integrity": "sha512-0uQeebAtsewqJ2b35aPZstGrylwd6oJjUyAJOfVJNbremFSJ5JzytB3NoDCIw7CT5UQrSRpvD3mU95gfdQjDGA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "peer": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-arm-gnueabihf": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.26.tgz", + "integrity": "sha512-06T+LbVFlyciQtwrUB5/a16A1ju1jFoYvd/hq9TWhf7GrtL43U7oJIgqMOPHx2j0+Ps2R3S6R/UUN5YXu618zA==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-arm64-gnu": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.26.tgz", + "integrity": "sha512-2NT/0xALPfK+U01qIlHxjkGdIj6F0txhu1U2v6B0YP2+k0whL2gCgYeg9QUvkYEXSD5r1Yx+vcb2R/vaSCSClg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-arm64-musl": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.26.tgz", + "integrity": "sha512-64KrTay9hC0mTvZ1AmEFmNEwV5QDjw9U7PJU5riotSc28I+Q/ZoM0qcSFW9JRRa6F2Tr+IfMtyv8+eB2//BQ5g==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-x64-gnu": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.26.tgz", + "integrity": "sha512-Te8G13l3dcRM1Mf3J4JzGUngzNXLKnMYlUmBOYN/ORsx7e+VNelR3zsTLHC0+0jGqELDgqvMyzDfk+dux/C/bQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-x64-musl": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.26.tgz", + "integrity": "sha512-nqQWuSM6OTKepUiQ9+rXgERq/JiO72RBOpXKO2afYppsL96sngjIRewV74v5f6IAfyzw+k+AhC5pgRA4Xu/Jkg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-win32-arm64-msvc": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.26.tgz", + "integrity": "sha512-xx34mx+9IBV1sun7sxoNFiqNom9wiOuvsQFJUyQptCnZHgYwOr9OI204LBF95dCcBCZsTm2hT1wBnySJOeimYw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "peer": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-win32-ia32-msvc": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.26.tgz", + "integrity": "sha512-48LZ/HKNuU9zl8c7qG6IQKb5rBCwmJgysGOmEGzTRBYxAf/x6Scmt0aqxCoV4J02HOs2WduCBDnhUKsSQ2kcXQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "peer": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-win32-x64-msvc": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.26.tgz", + "integrity": "sha512-UPe7S+MezD/S6cKBIc50TduGzmw6PBz1Ms5p+5wDLOKYNS/LSEM4iRmLwvePzP5X8mOyesXrsbwxLy8KHP65Yw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "peer": true, + "engines": { + "node": ">=10" + } + }, "node_modules/@tootallnate/once": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz", @@ -1899,6 +2158,29 @@ "integrity": "sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==", "dev": true }, + "node_modules/@types/prop-types": { + "version": "15.7.5", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz", + "integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==", + "dev": true + }, + "node_modules/@types/react": { + "version": "18.0.26", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.26.tgz", + "integrity": "sha512-hCR3PJQsAIXyxhTNSiDFY//LhnMZWpNNr5etoCqx/iUfGc5gXWtQR2Phl908jVR6uPXacojQWTg4qRpkxTuGug==", + "dev": true, + "dependencies": { + "@types/prop-types": "*", + "@types/scheduler": "*", + "csstype": "^3.0.2" + } + }, + "node_modules/@types/scheduler": { + "version": "0.16.2", + "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", + "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==", + "dev": true + }, "node_modules/@webassemblyjs/ast": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz", @@ -2612,6 +2894,21 @@ "node": "*" } }, + "node_modules/cacache/node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/call-bind": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", @@ -2860,6 +3157,17 @@ "url": "https://github.com/sponsors/mesqueeb" } }, + "node_modules/core-js": { + "version": "3.27.2", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.27.2.tgz", + "integrity": "sha512-9ashVQskuh5AZEZ1JdQWp1GqSoC1e1G87MzRqg2gIfVAQ7Qn9K+uFj8EcniUFA4P2NLZfV+TOlX1SzoKfo+s7w==", + "dev": true, + "hasInstallScript": true, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } + }, "node_modules/core-js-compat": { "version": "3.25.2", "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.25.2.tgz", @@ -3121,6 +3429,12 @@ "node": ">=8.0.0" } }, + "node_modules/csstype": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz", + "integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==", + "dev": true + }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -3720,6 +4034,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/get-own-enumerable-property-symbols": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-3.0.2.tgz", + "integrity": "sha512-I0UBV/XOz1XkIJHEUDMZAbzCThU/H8DxmSfmdGcKPnVhu2VfFqr34jr9777IyaTYvxjedWhqVIilEDsCdP5G6g==", + "dev": true + }, "node_modules/get-stdin": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz", @@ -4375,6 +4695,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-obj": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", + "integrity": "sha512-l4RyHgRqGN4Y3+9JHVrNqO+tN0rV5My76uW5/nuO4K1b6vw5G8d/cmFjP9tRfEsdhZNt0IFdZuK/c2Vr4Nb+Qg==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/is-plain-obj": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz", @@ -4412,6 +4741,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-regexp": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-regexp/-/is-regexp-1.0.0.tgz", + "integrity": "sha512-7zjFAPO4/gwyQAAgRRmqeEeyIICSdmCqa3tsVHMdBzaXXRiqopZL4Cyghg/XulGWrtABTpbnYYzzIRffLkP4oA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/is-shared-array-buffer": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/is-shared-array-buffer/-/is-shared-array-buffer-1.0.2.tgz", @@ -5289,6 +5627,21 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/node-gyp/node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/node-gyp/node_modules/semver": { "version": "7.3.7", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", @@ -5611,6 +5964,21 @@ "encoding": "^0.1.13" } }, + "node_modules/node-sass/node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/node-sass/node_modules/semver": { "version": "7.3.8", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", @@ -6775,6 +7143,20 @@ "node": ">=6" } }, + "node_modules/q-i": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/q-i/-/q-i-2.0.1.tgz", + "integrity": "sha512-tr7CzPNxkBDBuPzqi/HDUS4uBOppb91akNTeh56TYio8TiIeXp2Yp8ea9NmDu2DmGH35ZjJDq6C3E4SepVZ4bQ==", + "dev": true, + "dependencies": { + "ansi-styles": "^3.2.0", + "is-plain-object": "^2.0.4", + "stringify-object": "^3.2.0" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/quick-lru": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-4.0.1.tgz", @@ -7218,62 +7600,20 @@ } }, "node_modules/rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-4.1.2.tgz", + "integrity": "sha512-BlIbgFryTbw3Dz6hyoWFhKk+unCcHMSkZGrTFVAx2WmttdBSonsdtRlwiuTbDqTKr+UlXIUqJVS4QT5tUzGENQ==", "dev": true, - "dependencies": { - "glob": "^7.1.3" - }, "bin": { - "rimraf": "bin.js" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/rimraf/node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "node_modules/rimraf/node_modules/glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "dev": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" + "rimraf": "dist/cjs/src/bin.js" }, "engines": { - "node": "*" + "node": ">=14" }, "funding": { "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/rimraf/node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, "node_modules/safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", @@ -7791,6 +8131,20 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/stringify-object": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/stringify-object/-/stringify-object-3.3.0.tgz", + "integrity": "sha512-rHqiFh1elqCQ9WPLIC8I0Q/g/wj5J1eMkyoiD6eoQApWHP0FtlK7rqnhmabL5VUY9JQCcqwwvlOaSuutekgyrw==", + "dev": true, + "dependencies": { + "get-own-enumerable-property-symbols": "^3.0.0", + "is-obj": "^1.0.1", + "is-regexp": "^1.0.0" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/strip-ansi": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", @@ -7910,6 +8264,16 @@ "node": ">= 10" } }, + "node_modules/swc-loader": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/swc-loader/-/swc-loader-0.2.3.tgz", + "integrity": "sha512-D1p6XXURfSPleZZA/Lipb3A8pZ17fP4NObZvFCDjK/OKljroqDpPmsBdTraWhVBqUNpcWBQY1imWdoPScRlQ7A==", + "dev": true, + "peerDependencies": { + "@swc/core": "^1.2.147", + "webpack": ">=2" + } + }, "node_modules/tapable": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz", @@ -9890,8 +10254,151 @@ "requires": { "mkdirp": "^1.0.4", "rimraf": "^3.0.2" + }, + "dependencies": { + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + } } }, + "@swc/core": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.26.tgz", + "integrity": "sha512-U7vEsaLn3IGg0XCRLJX/GTkK9WIfFHUX5USdrp1L2QD29sWPe25HqNndXmUR9KytzKmpDMNoUuHyiuhpVrnNeQ==", + "dev": true, + "peer": true, + "requires": { + "@swc/core-darwin-arm64": "1.3.26", + "@swc/core-darwin-x64": "1.3.26", + "@swc/core-linux-arm-gnueabihf": "1.3.26", + "@swc/core-linux-arm64-gnu": "1.3.26", + "@swc/core-linux-arm64-musl": "1.3.26", + "@swc/core-linux-x64-gnu": "1.3.26", + "@swc/core-linux-x64-musl": "1.3.26", + "@swc/core-win32-arm64-msvc": "1.3.26", + "@swc/core-win32-ia32-msvc": "1.3.26", + "@swc/core-win32-x64-msvc": "1.3.26" + } + }, + "@swc/core-darwin-arm64": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.26.tgz", + "integrity": "sha512-FWWflBfKRYrUJtko2xiedC5XCa31O75IZZqnTWuLpe9g3C5tnUuF3M8LSXZS/dn6wprome1MhtG9GMPkSYkhkg==", + "dev": true, + "optional": true, + "peer": true + }, + "@swc/core-darwin-x64": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.3.26.tgz", + "integrity": "sha512-0uQeebAtsewqJ2b35aPZstGrylwd6oJjUyAJOfVJNbremFSJ5JzytB3NoDCIw7CT5UQrSRpvD3mU95gfdQjDGA==", + "dev": true, + "optional": true, + "peer": true + }, + "@swc/core-linux-arm-gnueabihf": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.26.tgz", + "integrity": "sha512-06T+LbVFlyciQtwrUB5/a16A1ju1jFoYvd/hq9TWhf7GrtL43U7oJIgqMOPHx2j0+Ps2R3S6R/UUN5YXu618zA==", + "dev": true, + "optional": true, + "peer": true + }, + "@swc/core-linux-arm64-gnu": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.26.tgz", + "integrity": "sha512-2NT/0xALPfK+U01qIlHxjkGdIj6F0txhu1U2v6B0YP2+k0whL2gCgYeg9QUvkYEXSD5r1Yx+vcb2R/vaSCSClg==", + "dev": true, + "optional": true, + "peer": true + }, + "@swc/core-linux-arm64-musl": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.26.tgz", + "integrity": "sha512-64KrTay9hC0mTvZ1AmEFmNEwV5QDjw9U7PJU5riotSc28I+Q/ZoM0qcSFW9JRRa6F2Tr+IfMtyv8+eB2//BQ5g==", + "dev": true, + "optional": true, + "peer": true + }, + "@swc/core-linux-x64-gnu": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.26.tgz", + "integrity": "sha512-Te8G13l3dcRM1Mf3J4JzGUngzNXLKnMYlUmBOYN/ORsx7e+VNelR3zsTLHC0+0jGqELDgqvMyzDfk+dux/C/bQ==", + "dev": true, + "optional": true, + "peer": true + }, + "@swc/core-linux-x64-musl": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.26.tgz", + "integrity": "sha512-nqQWuSM6OTKepUiQ9+rXgERq/JiO72RBOpXKO2afYppsL96sngjIRewV74v5f6IAfyzw+k+AhC5pgRA4Xu/Jkg==", + "dev": true, + "optional": true, + "peer": true + }, + "@swc/core-win32-arm64-msvc": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.26.tgz", + "integrity": "sha512-xx34mx+9IBV1sun7sxoNFiqNom9wiOuvsQFJUyQptCnZHgYwOr9OI204LBF95dCcBCZsTm2hT1wBnySJOeimYw==", + "dev": true, + "optional": true, + "peer": true + }, + "@swc/core-win32-ia32-msvc": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.26.tgz", + "integrity": "sha512-48LZ/HKNuU9zl8c7qG6IQKb5rBCwmJgysGOmEGzTRBYxAf/x6Scmt0aqxCoV4J02HOs2WduCBDnhUKsSQ2kcXQ==", + "dev": true, + "optional": true, + "peer": true + }, + "@swc/core-win32-x64-msvc": { + "version": "1.3.26", + "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.26.tgz", + "integrity": "sha512-UPe7S+MezD/S6cKBIc50TduGzmw6PBz1Ms5p+5wDLOKYNS/LSEM4iRmLwvePzP5X8mOyesXrsbwxLy8KHP65Yw==", + "dev": true, + "optional": true, + "peer": true + }, "@tootallnate/once": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz", @@ -9966,6 +10473,29 @@ "integrity": "sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==", "dev": true }, + "@types/prop-types": { + "version": "15.7.5", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz", + "integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==", + "dev": true + }, + "@types/react": { + "version": "18.0.26", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.26.tgz", + "integrity": "sha512-hCR3PJQsAIXyxhTNSiDFY//LhnMZWpNNr5etoCqx/iUfGc5gXWtQR2Phl908jVR6uPXacojQWTg4qRpkxTuGug==", + "dev": true, + "requires": { + "@types/prop-types": "*", + "@types/scheduler": "*", + "csstype": "^3.0.2" + } + }, + "@types/scheduler": { + "version": "0.16.2", + "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", + "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==", + "dev": true + }, "@webassemblyjs/ast": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz", @@ -10512,6 +11042,15 @@ "requires": { "brace-expansion": "^1.1.7" } + }, + "rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } } } }, @@ -10711,6 +11250,12 @@ "is-what": "^3.14.1" } }, + "core-js": { + "version": "3.27.2", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.27.2.tgz", + "integrity": "sha512-9ashVQskuh5AZEZ1JdQWp1GqSoC1e1G87MzRqg2gIfVAQ7Qn9K+uFj8EcniUFA4P2NLZfV+TOlX1SzoKfo+s7w==", + "dev": true + }, "core-js-compat": { "version": "3.25.2", "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.25.2.tgz", @@ -10892,6 +11437,12 @@ "css-tree": "^1.1.2" } }, + "csstype": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz", + "integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==", + "dev": true + }, "debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -11336,6 +11887,12 @@ "has-symbols": "^1.0.3" } }, + "get-own-enumerable-property-symbols": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-3.0.2.tgz", + "integrity": "sha512-I0UBV/XOz1XkIJHEUDMZAbzCThU/H8DxmSfmdGcKPnVhu2VfFqr34jr9777IyaTYvxjedWhqVIilEDsCdP5G6g==", + "dev": true + }, "get-stdin": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz", @@ -11805,6 +12362,12 @@ "has-tostringtag": "^1.0.0" } }, + "is-obj": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", + "integrity": "sha512-l4RyHgRqGN4Y3+9JHVrNqO+tN0rV5My76uW5/nuO4K1b6vw5G8d/cmFjP9tRfEsdhZNt0IFdZuK/c2Vr4Nb+Qg==", + "dev": true + }, "is-plain-obj": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz", @@ -11830,6 +12393,12 @@ "has-tostringtag": "^1.0.0" } }, + "is-regexp": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-regexp/-/is-regexp-1.0.0.tgz", + "integrity": "sha512-7zjFAPO4/gwyQAAgRRmqeEeyIICSdmCqa3tsVHMdBzaXXRiqopZL4Cyghg/XulGWrtABTpbnYYzzIRffLkP4oA==", + "dev": true + }, "is-shared-array-buffer": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/is-shared-array-buffer/-/is-shared-array-buffer-1.0.2.tgz", @@ -12495,6 +13064,15 @@ "set-blocking": "^2.0.0" } }, + "rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, "semver": { "version": "7.3.7", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", @@ -12745,6 +13323,15 @@ "minizlib": "^2.1.2" } }, + "rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, "semver": { "version": "7.3.8", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", @@ -13535,6 +14122,17 @@ "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", "dev": true }, + "q-i": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/q-i/-/q-i-2.0.1.tgz", + "integrity": "sha512-tr7CzPNxkBDBuPzqi/HDUS4uBOppb91akNTeh56TYio8TiIeXp2Yp8ea9NmDu2DmGH35ZjJDq6C3E4SepVZ4bQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.0", + "is-plain-object": "^2.0.4", + "stringify-object": "^3.2.0" + } + }, "quick-lru": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-4.0.1.tgz", @@ -13885,48 +14483,10 @@ "dev": true }, "rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "dev": true, - "requires": { - "glob": "^7.1.3" - }, - "dependencies": { - "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "requires": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "dev": true, - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - }, - "minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, - "requires": { - "brace-expansion": "^1.1.7" - } - } - } + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-4.1.2.tgz", + "integrity": "sha512-BlIbgFryTbw3Dz6hyoWFhKk+unCcHMSkZGrTFVAx2WmttdBSonsdtRlwiuTbDqTKr+UlXIUqJVS4QT5tUzGENQ==", + "dev": true }, "safe-buffer": { "version": "5.1.2", @@ -14330,6 +14890,17 @@ "es-abstract": "^1.19.5" } }, + "stringify-object": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/stringify-object/-/stringify-object-3.3.0.tgz", + "integrity": "sha512-rHqiFh1elqCQ9WPLIC8I0Q/g/wj5J1eMkyoiD6eoQApWHP0FtlK7rqnhmabL5VUY9JQCcqwwvlOaSuutekgyrw==", + "dev": true, + "requires": { + "get-own-enumerable-property-symbols": "^3.0.0", + "is-obj": "^1.0.1", + "is-regexp": "^1.0.0" + } + }, "strip-ansi": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", @@ -14409,6 +14980,13 @@ } } }, + "swc-loader": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/swc-loader/-/swc-loader-0.2.3.tgz", + "integrity": "sha512-D1p6XXURfSPleZZA/Lipb3A8pZ17fP4NObZvFCDjK/OKljroqDpPmsBdTraWhVBqUNpcWBQY1imWdoPScRlQ7A==", + "dev": true, + "requires": {} + }, "tapable": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz", diff --git a/package.json b/package.json index 5e8b47e5..929fda84 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "build:client": "webpack --config webpack.client.config.js --color", "build:server": "webpack --config webpack.server.config.js --color", "build": "run-p -c build:*", + "clean": "rimraf build", "dist:client": "cross-env NODE_ENV=production webpack --config webpack.client.config.js --color", "dist:server": "cross-env NODE_ENV=production webpack --config webpack.server.config.js --color --hide-modules", "dist": "run-p -c dist:*" @@ -19,9 +20,11 @@ "@babel/register": "^7.18.9", "@enonic-types/global": "^7.11.2", "@enonic-types/lib-event": "^7.11.2", + "@types/react": "^18.0.26", "autoprefixer": "^10.4.13", "babel-loader": "^9.1.2", "browserslist-config-enonic": "^1.0.7", + "core-js": "^3.27.2", "cross-env": "^7.0.3", "css-loader": "^6.7.3", "cssnano": "^5.1.14", @@ -36,9 +39,12 @@ "postcss": "^8.4.21", "postcss-loader": "^7.0.2", "postcss-normalize": "^10.0.1", + "q-i": "^2.0.1", "ramda": "^0.28.0", + "rimraf": "^4.1.2", "sass-loader": "^13.2.0", "style-loader": "^3.3.1", + "swc-loader": "^0.2.3", "terser-webpack-plugin": "^5.3.6", "ts-loader": "^9.4.2", "typescript": "^4.9.4", diff --git a/src/main/resources/lib/monitor/monitor.ts b/src/main/resources/lib/monitor/monitor.ts index d4d14fd1..08d27fda 100644 --- a/src/main/resources/lib/monitor/monitor.ts +++ b/src/main/resources/lib/monitor/monitor.ts @@ -1,4 +1,5 @@ -import {EnonicEvent, listener} from '@enonic-types/lib-event'; +import type {EnonicEvent} from '@enonic-types/lib-event'; +import {listener} from '/lib/xp/event'; function logEvent({timestamp, data}: EnonicEvent): void { log.info(`${new Date(timestamp)}: ${JSON.stringify(data)}`); diff --git a/src/main/resources/lib/observe/observe.es6 b/src/main/resources/lib/observe/observe.ts similarity index 88% rename from src/main/resources/lib/observe/observe.es6 rename to src/main/resources/lib/observe/observe.ts index 34774b53..0a0977ab 100644 --- a/src/main/resources/lib/observe/observe.es6 +++ b/src/main/resources/lib/observe/observe.ts @@ -1,6 +1,6 @@ import {listener} from '/lib/xp/event'; -const logEvent = (event) => { +const logEvent = (event: unknown) => { log.info(JSON.stringify(event)); }; diff --git a/src/main/resources/lib/testTreeShaking.ts b/src/main/resources/lib/testTreeShaking.ts new file mode 100644 index 00000000..eea0e246 --- /dev/null +++ b/src/main/resources/lib/testTreeShaking.ts @@ -0,0 +1,12 @@ +const NOT_EXIST = 'not exist'; +const EXIST = 'exist'; + +export function notImportedFunction() { + log.info(`${NOT_EXIST}: This function should exist in /build/resources/main/lib/testTreeShaking.js, but NOT in /build/resources/main/main.js`); + return; +} + +export function importedFunction() { + log.info(`${EXIST}: This function should exist in /build/resources/main/lib/testTreeShaking.js and /build/resources/main/main.js`); + return; +} diff --git a/src/main/resources/main.es6 b/src/main/resources/main.es6 deleted file mode 100644 index 66f28771..00000000 --- a/src/main/resources/main.es6 +++ /dev/null @@ -1,3 +0,0 @@ -import { init } from './lib/observe/observe'; - -init(); diff --git a/src/main/resources/main.ts b/src/main/resources/main.ts new file mode 100644 index 00000000..ffade30e --- /dev/null +++ b/src/main/resources/main.ts @@ -0,0 +1,11 @@ +import { init } from '/lib/observe/observe'; // Using absolute path, so it will be externaled (not inlined). +import { importedFunction } from './lib/testTreeShaking'; // Using relative path so it will be inlined (not externaled) + +// Test that descontruction works after transpilation. +const obj = {prop:'value'}; +const {prop} = obj; +log.info(prop); + +importedFunction(); + +init(); diff --git a/tsconfig.json b/tsconfig.json index 906245d9..a0d31c13 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,24 +1,124 @@ -{ +{ // https://www.typescriptlang.org/tsconfig "compilerOptions": { - "target": "es5", - "module": "commonjs", - "moduleResolution": "node", - "sourceMap": false, - "allowSyntheticDefaultImports": true, - "esModuleInterop": true, - "allowJs": true, + + //───────────────────────────────────────────────────────────────────── + // Type Checking + //───────────────────────────────────────────────────────────────────── + // Ensures that your files are parsed in the ECMAScript strict mode, and emit “use strict” for each source file. + // ECMAScript strict mode was introduced in ES5 and provides behavior tweaks to the runtime of the JavaScript engine to improve performance, and makes a set of errors throw instead of silently ignoring them. + "alwaysStrict": true, + "noImplicitAny": true, "noImplicitReturns": true, "noImplicitThis": true, + + // The strict flag enables a wide range of type checking behavior that results in stronger guarantees of program correctness. + // Turning this on is equivalent to enabling all of the strict mode family options, which are outlined below. + // You can then turn off individual strict mode family checks as needed. + // Future versions of TypeScript may introduce additional stricter checking under this flag, so upgrades of TypeScript might result in new type errors in your program. + // When appropriate and possible, a corresponding flag will be added to disable that behavior. + "strict": true, + + // When strictNullChecks is false, null and undefined are effectively ignored by the language. This can lead to unexpected errors at runtime. + // When strictNullChecks is true, null and undefined have their own distinct types and you’ll get a type error if you try to use them where a concrete value is expected. "strictNullChecks": true, + + //───────────────────────────────────────────────────────────────────── + // Modules + //───────────────────────────────────────────────────────────────────── + "baseUrl": "./", + + // Default: + // CommonJS if target is ES3 or ES5, + // ES6/ES2015 otherwise. + // Allowed: + // none, commonjs, amd, umd, system, es6/es2015, es2020, es2022, esnext, node16, nodenext + // "module": "commonjs", + "module": "es6", + + // Default: + // Classic if module is AMD, UMD, System or ES6/ES2015 + // Matches if module is node12 or nodenext + // Node otherwise. + // Allowed: + // classic, node, node16, nodenext + "moduleResolution": "node", + + "paths": { + "/lib/xp/*": ["node_modules/@enonic-types/lib-*"], + "/lib/*": ["src/main/resources/lib/*"], // So one can import local libs with absolute path (same as Enonic does during runtime). + }, + + // By default all visible ”@types” packages are included in your compilation. + // Packages in node_modules/@types of any enclosing folder are considered visible. + // For example, that means packages within ./node_modules/@types/, + // ../node_modules/@types/, ../../node_modules/@types/, and so on. + // If typeRoots is specified, only packages under typeRoots will be included. "typeRoots": [ "node_modules/@types", "node_modules/@enonic-types" ], - "baseUrl": "./", - "paths": { - "/lib/xp/*": ["node_modules/@enonic-types/lib-*"], - } + + // By default all visible ”@types” packages are included in your compilation. + // Packages in node_modules/@types of any enclosing folder are considered visible. + // For example, that means packages within ./node_modules/@types/, + // ../node_modules/@types/, ../../node_modules/@types/, and so on. + // If types is specified, only packages listed will be included in the global scope. + // This feature differs from typeRoots in that it is about specifying only the exact + // types you want included, whereas typeRoots supports saying you want particular folders. + // "types": [ + // "@enonic-types/global", // No point, already added via typeRoots + // "@enonic-types/lib-event" // No point, since it doesn't affect global scope + // ], + + //───────────────────────────────────────────────────────────────────── + // Emit + //───────────────────────────────────────────────────────────────────── + "outDir": "build/ts", // So it doesn't complain about overwriting files under ./src + "sourceMap": false, + + //───────────────────────────────────────────────────────────────────── + // JavaScript Support + //───────────────────────────────────────────────────────────────────── + // Allow JavaScript files to be imported inside your project, instead of just .ts and .tsx files. + // This flag can be used as a way to incrementally add TypeScript files into JS projects by allowing the .ts and .tsx files to live along-side existing JavaScript files. + // "allowJs": true, + + //───────────────────────────────────────────────────────────────────── + // Interop Constraints + //───────────────────────────────────────────────────────────────────── + // When set to true, allowSyntheticDefaultImports allows you to write an import like: + // import React from "react"; + // instead of: + // import * as React from "react"; + "allowSyntheticDefaultImports": true, + + // By default (with esModuleInterop false or not set) TypeScript treats CommonJS/AMD/UMD modules similar to ES6 modules. + // + // In doing this, there are two parts in particular which turned out to be flawed assumptions: + // * a namespace import like import * as moment from "moment" acts the same as const moment = require("moment") + // * a default import like import moment from "moment" acts the same as const moment = require("moment").default + // + // This mis-match causes these two issues: + // 1. the ES6 modules spec states that a namespace import (import * as x) can only be an object, + // by having TypeScript treating it the same as = require("x") then TypeScript allowed for the import to be treated as a function and be callable. + // That’s not valid according to the spec. + // 2. while accurate to the ES6 modules spec, most libraries with CommonJS/AMD/UMD modules didn’t conform as strictly as TypeScript’s implementation. + // + // Turning on esModuleInterop will fix both of these problems in the code transpiled by TypeScript. The first changes the behavior in the compiler, the second is fixed by two new helper functions which provide a shim to ensure compatibility in the emitted JavaScript: + "esModuleInterop": true, + + //───────────────────────────────────────────────────────────────────── + // Language and Environment + //───────────────────────────────────────────────────────────────────── + // Default: + // ES3 + // Allowed: + // es3,es5,es6/es2015,es2016,es2017,es2018,es2019,es2020,es2021,es2022,esnext + // "target": "es5", // We're letting swc handle the transpilation + // "target": "es6", + // "target": "es2016", + "target": "esnext", // Seems like tree-shaking (in node_modules) works regardless of target }, "exclude": [ "assets", diff --git a/webpack.server.config.js b/webpack.server.config.js index 81ddacfd..fa2608d5 100644 --- a/webpack.server.config.js +++ b/webpack.server.config.js @@ -1,3 +1,4 @@ +// const {print} = require('q-i'); const path = require('path'); const glob = require('glob'); const R = require('ramda'); @@ -19,44 +20,72 @@ const RESOURCES_PATH = 'src/main/resources'; const config = { context: path.join(__dirname, RESOURCES_PATH), + devtool: false, // Source maps are not usable in server scripts entry: {}, externals: [ - /^\/lib\/(.+|\$)$/i + /^\/lib\/(.+|\$)$/i, + // { + // TS externals + // '@enonic-types/lib-event': '/lib/xp/event', // NOTE: I don't think this does anything + // JS externals + // NOTE: These are covered by the general regexp rule above + // '/lib/xp/event': '/lib/xp/event', + // '/lib/enonic/static': '/lib/enonic/static', + // } ], - output: { - path: path.join(__dirname, '/build/resources/main'), - filename: '[name].js', - libraryTarget: 'commonjs' - }, - resolve: { - extensions: [], - }, - externals: { - // TS externals - '@enonic-types/lib-event': '/lib/xp/event', - // JS externals - '/lib/xp/event': '/lib/xp/event', - '/lib/enonic/static': '/lib/enonic/static', - }, + mode: env.type, optimization: { + minimize: true, + // minimize: false, // DEBUG minimizer: [ new TerserPlugin({ + // extractComments: false, + extractComments: true, terserOptions: { compress: { - drop_console: false, + // defaults: false // (default: true) -- Pass false to disable most default enabled compress transforms. Useful when you only want to enable a few compress options while disabling the rest. + // dead_code: false, // (default: true) -- remove unreachable code + drop_console: true, // (default: false) -- Pass true to discard calls to console.* functions. If you wish to drop a specific function call such as console.info and/or retain side effects from function arguments after dropping the function call then use pure_funcs instead. + keep_classnames: true, // (default: false) -- Pass true to prevent the compressor from discarding class names. Pass a regular expression to only keep class names matching that regex. See also: the keep_classnames mangle option. + keep_fnames: true, // (default: false) -- Pass true to prevent the compressor from discarding function names. Pass a regular expression to only keep function names matching that regex. Useful for code relying on Function.prototype.name. See also: the keep_fnames mangle option. + module: true, // (default false) -- Pass true when compressing an ES6 module. Strict mode is implied and the toplevel option as well. + passes: 10, // (default: 1) -- The maximum number of times to run compress. In some cases more than one pass leads to further compressed code. Keep in mind more passes will take more time. + toplevel: true, // (default: false) -- drop unreferenced functions ("funcs") and/or variables ("vars") in the top level scope (false by default, true to drop both unreferenced functions and variables) + // unused: false, // (default: true) -- drop unreferenced functions and variables (simple direct variable assignments do not count as references unless set to "keep_assign") }, - keep_classnames: true, - keep_fnames: true, - } + format: { // format or output (default null) — pass an object if you wish to specify additional format options. The defaults are optimized for best compression. + // comments: 'all', // (default "some") -- by default it keeps JSDoc-style comments that contain "@license" or "@preserve", pass true or "all" to preserve all comments, false to omit comments in the output, a regular expression string (e.g. /^!/) or a function. + // max_line_len: 80, // (default false) -- maximum line length (for minified code) + semicolons: false, // (default true) -- separate statements with semicolons. If you pass false then whenever possible we will use a newline instead of a semicolon, leading to more readable output of minified code (size before gzip could be smaller; size after gzip insignificantly larger). + }, + keep_classnames: true, // (default: undefined) - pass true to prevent discarding or mangling of class names. Pass a regular expression to only keep class names matching that regex. + keep_fnames: true, // (default: false) - pass true to prevent discarding or mangling of function names. Pass a regular expression to only keep class names matching that regex. Useful for code relying on Function.prototype.name. If the top level minify option keep_classnames is undefined it will be overridden with the value of the top level minify option keep_fnames. + // mangle: false, // (default true) — pass false to skip mangling names, or pass an object to specify mangle options (see below). + mangle: { + keep_classnames: true, // (default false) -- Pass true to not mangle class names. Pass a regular expression to only keep class names matching that regex. See also: the keep_classnames compress option. + keep_fnames: true, // (default false) -- Pass true to not mangle function names. Pass a regular expression to only keep class names matching that regex. Useful for code relying on Function.prototype.name. See also: the keep_fnames compress option. + module: true, // (default false) -- Pass true an ES6 modules, where the toplevel scope is not the global scope. Implies toplevel. + toplevel: true, // (default false) -- Pass true to mangle names declared in the top level scope. + }, + module: true, // (default false) — Use when minifying an ES6 module. "use strict" is implied and names can be mangled on the top scope. If compress or mangle is enabled then the toplevel option will be enabled. + // sourceMap: {} (default false) - pass an object if you wish to specify source map options. + toplevel: true, // (default false) - set to true if you wish to enable top level variable and function name mangling and to drop unused variables and functions. + }, }), ], splitChunks: { minSize: 30000, }, + // usedExports: true // webpack 4? + }, + output: { + path: path.join(__dirname, '/build/resources/main'), + filename: '[name].js', + libraryTarget: 'commonjs' + }, + resolve: { + extensions: [], }, - mode: env.type, - // Source maps are not usable in server scripts - devtool: false, }; // ---------------------------------------------------------------------------- @@ -74,65 +103,115 @@ function listEntries(extensions, ignoreList) { } // TYPESCRIPT -function addTypeScriptSupport(cfg) { - const rule = { - test: /\.ts$/, - exclude: /node_modules/, - loader: 'ts-loader', - options: { - configFile: 'tsconfig.json', - } - }; +// function addTypeScriptSupport(cfg) { +// const rule = { +// test: /\.ts$/, +// exclude: /node_modules/, +// loader: 'ts-loader', +// options: { +// configFile: 'tsconfig.json', +// } +// }; - const entries = listEntries('ts', [ - // Add additional files to the ignore list. - // The following path will be transformed to 'src/main/resources/types.ts: - 'types.ts' - ]).filter(entry => entry.indexOf('.d.ts') === -1); +// const entries = listEntries('ts', [ +// // Add additional files to the ignore list. +// // The following path will be transformed to 'src/main/resources/types.ts: +// 'types.ts' +// ]).filter(entry => entry.indexOf('.d.ts') === -1); - return R.pipe( - setEntriesForPath(entries), - addRule(rule), - addPlugin(new ProvidePlugin({ - 'Object.assign': [path.join(__dirname, RESOURCES_PATH, 'polyfills'), 'assign'] - })), - prependExtensions(['.ts', '.json']) - )(cfg); -} +// return R.pipe( +// setEntriesForPath(entries), +// addRule(rule), +// addPlugin(new ProvidePlugin({ +// 'Object.assign': [path.join(__dirname, RESOURCES_PATH, 'polyfills'), 'assign'] +// })), +// prependExtensions(['.ts', '.json']) +// )(cfg); +// } // BABEL -function addBabelSupport(cfg) { - const rule = { - test: /\.(es6?|js)$/, - exclude: /node_modules/, - loader: 'babel-loader', - options: { - babelrc: false, - plugins: [], - presets: [ - [ - '@babel/preset-env', - { - // Use custom Browserslist config - targets: 'node 0.10', - // Polyfills are not required in runtime - useBuiltIns: false - }, - ], - ] - } - }; +// function addBabelSupport(cfg) { +// const rule = { +// test: /\.(es6?|js)$/, +// exclude: /node_modules/, +// loader: 'babel-loader', +// options: { +// babelrc: false, +// plugins: [], +// presets: [ +// [ +// '@babel/preset-env', +// { +// // Use custom Browserslist config +// targets: 'node 0.10', +// // Polyfills are not required in runtime +// useBuiltIns: false +// }, +// ], +// ] +// } +// }; + +// const entries = listEntries('{js,es,es6}', [ +// // Add additional files to the ignore list. +// // The following path will be transformed to 'src/main/resources/lib/observe/observe.ts': +// 'lib/observe/observe.ts' +// ]); - const entries = listEntries('{js,es,es6}', [ - // Add additional files to the ignore list. - // The following path will be transformed to 'src/main/resources/lib/observe/observe.es6': - 'lib/observe/observe.es6' - ]); +// return R.pipe( +// setEntriesForPath(entries), +// addRule(rule), +// prependExtensions(['.js', '.es', '.es6', '.json']) +// )(cfg); +// } +// SWC (instead of typescript and babel) +function addSWC(cfg) { + const rule = { + test: /\.([ejt]s6?)?$/, + use: { + loader: 'swc-loader', + options: { + env: { + coreJs: '3.27.2', + // mode: 'entry', + // mode: 'usage', + }, + jsc: { + keepClassNames: true, + minify: { + compress: { + dead_code: true, // defaults to false + drop_console: true, // defaults to false + // ecma: 6, // defaults to 5 + keep_classnames: true, // defaults to false. + keep_fargs: true, // defaults to false. + // module, // Ignored. Currently, all files are treated as module + // toplevel: false, // defaults to true + // unused: false // defaults to true + }, + mangle: true + }, + parser: { + syntax: 'typescript' + }, + target: 'es5', + }, + minify: true, + module: { + type: 'commonjs' + }, + // sync: true, // Run syncronously to get correct error messages + } + }, + exclude: /node_modules/, + } + const entries = listEntries('{ts,js,es,es6}',[]) + .filter(entry => entry.indexOf('.d.ts') === -1); return R.pipe( setEntriesForPath(entries), addRule(rule), - prependExtensions(['.js', '.es', '.es6', '.json']) + prependExtensions(['.ts', '.js', '.es', '.es6', '.json']) )(cfg); } @@ -141,6 +220,8 @@ function addBabelSupport(cfg) { // ---------------------------------------------------------------------------- module.exports = R.pipe( - addBabelSupport, - addTypeScriptSupport + // addBabelSupport, + // addTypeScriptSupport, + addSWC, )(config); +// print(module.exports, { maxItems: Infinity }); \ No newline at end of file