From ac51ecd87dc517a6a96d1e75dccc027cc8e5c81d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20Aslan?= Date: Thu, 25 Jan 2024 11:56:03 +0100 Subject: [PATCH 1/5] implemented prepublishOnly script for npm publish --- package-lock.json | 547 +++++++++++++++++++++++++++++++------- package.json | 3 +- scripts/compiler.js | 60 +++++ scripts/prepublishOnly.js | 75 ++++++ vite/index.js | 17 ++ vite/preCompiler.js | 58 ++-- 6 files changed, 623 insertions(+), 137 deletions(-) create mode 100644 scripts/compiler.js create mode 100644 scripts/prepublishOnly.js diff --git a/package-lock.json b/package-lock.json index 88c81203..ae2f47e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -435,6 +435,19 @@ "dev": true, "license": "Python-2.0" }, + "node_modules/array-buffer-byte-length": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/array-buffer-byte-length/-/array-buffer-byte-length-1.0.0.tgz", + "integrity": "sha512-LPuwb2P+NrQw3XhxGc36+XSvuBPopovXYTR9Ew++Du9Yb/bx5AzBfrIsBoj0EZUifjQU+sHL21sseZ3jerWO/A==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "is-array-buffer": "^3.0.1" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/array.prototype.every": { "version": "1.1.3", "dev": true, @@ -452,6 +465,27 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/arraybuffer.prototype.slice": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/arraybuffer.prototype.slice/-/arraybuffer.prototype.slice-1.0.2.tgz", + "integrity": "sha512-yMBKppFur/fbHu9/6USUe03bZ4knMYiwFBcyiaXB8Go0qNehwX6inYPzK9U0NeQvGxKthcmHcaR8P5MStSRBAw==", + "dev": true, + "dependencies": { + "array-buffer-byte-length": "^1.0.0", + "call-bind": "^1.0.2", + "define-properties": "^1.2.0", + "es-abstract": "^1.22.1", + "get-intrinsic": "^1.2.1", + "is-array-buffer": "^3.0.2", + "is-shared-array-buffer": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/astral-regex": { "version": "2.0.0", "dev": true, @@ -542,12 +576,14 @@ } }, "node_modules/call-bind": { - "version": "1.0.2", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.5.tgz", + "integrity": "sha512-C3nQxfFZxFRVoJoGKKI8y3MOEo129NQ+FgQ08iye+Mk4zNZZGdjfs06bVTr+DBSlA66Q2VEcMki/cUCP4SercQ==", "dev": true, - "license": "MIT", "dependencies": { - "function-bind": "^1.1.1", - "get-intrinsic": "^1.0.2" + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.1", + "set-function-length": "^1.1.1" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -757,15 +793,35 @@ "dev": true, "license": "MIT" }, + "node_modules/define-data-property": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.1.tgz", + "integrity": "sha512-E7uGkTzkk1d0ByLeSc6ZsFS79Axg+m1P/VsgYsxHgiuc3tFSj+MjMIwe90FC4lOAZzNBdY7kkO2P2wKdsQ1vgQ==", + "dev": true, + "dependencies": { + "get-intrinsic": "^1.2.1", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/define-properties": { - "version": "1.1.3", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz", + "integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==", "dev": true, - "license": "MIT", "dependencies": { - "object-keys": "^1.0.12" + "define-data-property": "^1.0.1", + "has-property-descriptors": "^1.0.0", + "object-keys": "^1.1.1" }, "engines": { "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, "node_modules/defined": { @@ -819,30 +875,50 @@ "license": "MIT" }, "node_modules/es-abstract": { - "version": "1.19.1", + "version": "1.22.3", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.22.3.tgz", + "integrity": "sha512-eiiY8HQeYfYH2Con2berK+To6GrK2RxbPawDkGq4UiCQQfZHb6wX9qQqkbpPqaxQFcl8d9QzZqo0tGE0VcrdwA==", "dev": true, - "license": "MIT", "dependencies": { - "call-bind": "^1.0.2", + "array-buffer-byte-length": "^1.0.0", + "arraybuffer.prototype.slice": "^1.0.2", + "available-typed-arrays": "^1.0.5", + "call-bind": "^1.0.5", + "es-set-tostringtag": "^2.0.1", "es-to-primitive": "^1.2.1", - "function-bind": "^1.1.1", - "get-intrinsic": "^1.1.1", + "function.prototype.name": "^1.1.6", + "get-intrinsic": "^1.2.2", "get-symbol-description": "^1.0.0", - "has": "^1.0.3", - "has-symbols": "^1.0.2", - "internal-slot": "^1.0.3", - "is-callable": "^1.2.4", - "is-negative-zero": "^2.0.1", + "globalthis": "^1.0.3", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.0", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3", + "hasown": "^2.0.0", + "internal-slot": "^1.0.5", + "is-array-buffer": "^3.0.2", + "is-callable": "^1.2.7", + "is-negative-zero": "^2.0.2", "is-regex": "^1.1.4", - "is-shared-array-buffer": "^1.0.1", + "is-shared-array-buffer": "^1.0.2", "is-string": "^1.0.7", - "is-weakref": "^1.0.1", - "object-inspect": "^1.11.0", + "is-typed-array": "^1.1.12", + "is-weakref": "^1.0.2", + "object-inspect": "^1.13.1", "object-keys": "^1.1.1", - "object.assign": "^4.1.2", - "string.prototype.trimend": "^1.0.4", - "string.prototype.trimstart": "^1.0.4", - "unbox-primitive": "^1.0.1" + "object.assign": "^4.1.4", + "regexp.prototype.flags": "^1.5.1", + "safe-array-concat": "^1.0.1", + "safe-regex-test": "^1.0.0", + "string.prototype.trim": "^1.2.8", + "string.prototype.trimend": "^1.0.7", + "string.prototype.trimstart": "^1.0.7", + "typed-array-buffer": "^1.0.0", + "typed-array-byte-length": "^1.0.0", + "typed-array-byte-offset": "^1.0.0", + "typed-array-length": "^1.0.4", + "unbox-primitive": "^1.0.2", + "which-typed-array": "^1.1.13" }, "engines": { "node": ">= 0.4" @@ -874,6 +950,20 @@ "dev": true, "license": "MIT" }, + "node_modules/es-set-tostringtag": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.0.2.tgz", + "integrity": "sha512-BuDyupZt65P9D2D2vA/zqcI3G5xRsklm5N3xCwuiy+/vKy8i0ifdsQP1sLgO4tZDSCaQUSnmC48khknGMV3D2Q==", + "dev": true, + "dependencies": { + "get-intrinsic": "^1.2.2", + "has-tostringtag": "^1.0.0", + "hasown": "^2.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/es-to-primitive": { "version": "1.2.1", "dev": true, @@ -1369,11 +1459,6 @@ "is-callable": "^1.1.3" } }, - "node_modules/foreach": { - "version": "2.0.5", - "dev": true, - "license": "MIT" - }, "node_modules/foreground-child": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-2.0.0.tgz", @@ -1407,15 +1492,46 @@ } }, "node_modules/function-bind": { - "version": "1.1.1", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", "dev": true, - "license": "MIT" + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/function.prototype.name": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/function.prototype.name/-/function.prototype.name-1.1.6.tgz", + "integrity": "sha512-Z5kx79swU5P27WEayXM1tBi5Ze/lbIyiNgU3qyXUOf9b2rgXYyF9Dy9Cx+IQv/Lc8WCG6L82zwUPpSS9hGehIg==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "define-properties": "^1.2.0", + "es-abstract": "^1.22.1", + "functions-have-names": "^1.2.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } }, "node_modules/functional-red-black-tree": { "version": "1.0.1", "dev": true, "license": "MIT" }, + "node_modules/functions-have-names": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz", + "integrity": "sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -1426,13 +1542,15 @@ } }, "node_modules/get-intrinsic": { - "version": "1.1.1", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.2.tgz", + "integrity": "sha512-0gSo4ml/0j98Y3lngkFEot/zhiCeWsbYIlZ+uZOVgzLyLaUw7wxUL+nCTP0XJvJg1AXulJRI3UJi8GsbDuxdGA==", "dev": true, - "license": "MIT", "dependencies": { - "function-bind": "^1.1.1", - "has": "^1.0.3", - "has-symbols": "^1.0.1" + "function-bind": "^1.1.2", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3", + "hasown": "^2.0.0" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -1510,6 +1628,33 @@ "node": ">=4" } }, + "node_modules/globalthis": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/globalthis/-/globalthis-1.0.3.tgz", + "integrity": "sha512-sFdI5LyBiNTHjRd7cGPWapiHWMOXKyuBNX/cWJ3NfzrZQVa8GI/8cofCl74AOVqq9W5kNmguTIzJ/1s2gyI9wA==", + "dev": true, + "dependencies": { + "define-properties": "^1.1.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/gopd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", + "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "dev": true, + "dependencies": { + "get-intrinsic": "^1.1.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/has": { "version": "1.0.3", "dev": true, @@ -1541,9 +1686,10 @@ } }, "node_modules/has-bigints": { - "version": "1.0.1", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz", + "integrity": "sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ==", "dev": true, - "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -1568,10 +1714,35 @@ "node": ">=4" } }, + "node_modules/has-property-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.1.tgz", + "integrity": "sha512-VsX8eaIewvas0xnvinAe9bw4WfIeODpGYikiWYLH+dma0Jw6KHYqWiWfhQlgOVK8D6PvjubK5Uc4P0iIhIcNVg==", + "dev": true, + "dependencies": { + "get-intrinsic": "^1.2.2" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz", + "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==", + "dev": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/has-symbols": { - "version": "1.0.2", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", "dev": true, - "license": "MIT", "engines": { "node": ">= 0.4" }, @@ -1593,6 +1764,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/hasown": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.0.tgz", + "integrity": "sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==", + "dev": true, + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/html-escaper": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", @@ -1675,12 +1858,13 @@ "license": "ISC" }, "node_modules/internal-slot": { - "version": "1.0.3", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.6.tgz", + "integrity": "sha512-Xj6dv+PsbtwyPpEflsejS+oIZxmMlV44zAhG479uYu89MsjcYOhCFnNyKrkJrihbsiasQyY0afoCl/9BLR65bg==", "dev": true, - "license": "MIT", "dependencies": { - "get-intrinsic": "^1.1.0", - "has": "^1.0.3", + "get-intrinsic": "^1.2.2", + "hasown": "^2.0.0", "side-channel": "^1.0.4" }, "engines": { @@ -1702,6 +1886,20 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-array-buffer": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/is-array-buffer/-/is-array-buffer-3.0.2.tgz", + "integrity": "sha512-y+FyyR/w8vfIRq4eQcM1EYgSTnmHXPqaF+IgzgraytCFq5Xh8lllDVmAZolPJiZttZLeFSINPYMaEJ7/vWUa1w==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "get-intrinsic": "^1.2.0", + "is-typed-array": "^1.1.10" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-bigint": { "version": "1.0.4", "dev": true, @@ -1729,9 +1927,10 @@ } }, "node_modules/is-callable": { - "version": "1.2.4", + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", + "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==", "dev": true, - "license": "MIT", "engines": { "node": ">= 0.4" }, @@ -1740,11 +1939,12 @@ } }, "node_modules/is-core-module": { - "version": "2.8.1", + "version": "2.13.1", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.1.tgz", + "integrity": "sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==", "dev": true, - "license": "MIT", "dependencies": { - "has": "^1.0.3" + "hasown": "^2.0.0" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -1870,9 +2070,13 @@ } }, "node_modules/is-shared-array-buffer": { - "version": "1.0.1", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-shared-array-buffer/-/is-shared-array-buffer-1.0.2.tgz", + "integrity": "sha512-sqN2UDu1/0y6uvXyStCOzyhAjCSlHceFoMKJW8W9EU9cvic/QdsZ0kEU93HEy3IUEFZIiH/3w+AH/UQbPHNdhA==", "dev": true, - "license": "MIT", + "dependencies": { + "call-bind": "^1.0.2" + }, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -1917,15 +2121,12 @@ } }, "node_modules/is-typed-array": { - "version": "1.1.8", + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.12.tgz", + "integrity": "sha512-Z14TF2JNG8Lss5/HMqt0//T9JeHXttXy5pH/DBU4vi98ozO2btxzq9MwYDZYnKwU8nRsz/+GVFVRDq3DkVuSPg==", "dev": true, - "license": "MIT", "dependencies": { - "available-typed-arrays": "^1.0.5", - "call-bind": "^1.0.2", - "es-abstract": "^1.18.5", - "foreach": "^2.0.5", - "has-tostringtag": "^1.0.0" + "which-typed-array": "^1.1.11" }, "engines": { "node": ">= 0.4" @@ -2414,9 +2615,10 @@ } }, "node_modules/minimatch": { - "version": "3.0.4", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dev": true, - "license": "ISC", "dependencies": { "brace-expansion": "^1.1.7" }, @@ -2425,9 +2627,13 @@ } }, "node_modules/minimist": { - "version": "1.2.5", + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", "dev": true, - "license": "MIT" + "funding": { + "url": "https://github.com/sponsors/ljharb" + } }, "node_modules/ms": { "version": "2.1.2", @@ -2485,9 +2691,10 @@ } }, "node_modules/object-inspect": { - "version": "1.12.0", + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz", + "integrity": "sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ==", "dev": true, - "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -2516,13 +2723,14 @@ } }, "node_modules/object.assign": { - "version": "4.1.2", + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.5.tgz", + "integrity": "sha512-byy+U7gp+FVwmyzKPYhW2h5l3crpmGsxl7X2s8y43IgxvG4g3QZ6CffDtsNQy1WsmZpQbO+ybo0AlW7TY6DcBQ==", "dev": true, - "license": "MIT", "dependencies": { - "call-bind": "^1.0.0", - "define-properties": "^1.1.3", - "has-symbols": "^1.0.1", + "call-bind": "^1.0.5", + "define-properties": "^1.2.1", + "has-symbols": "^1.0.3", "object-keys": "^1.1.1" }, "engines": { @@ -2787,12 +2995,14 @@ } }, "node_modules/regexp.prototype.flags": { - "version": "1.4.1", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.1.tgz", + "integrity": "sha512-sy6TXMN+hnP/wMy+ISxg3krXx7BAtWVO4UouuCN/ziM9UEne0euamVNafDfvC83bRNr95y0V5iijeDQFUNpvrg==", "dev": true, - "license": "MIT", "dependencies": { "call-bind": "^1.0.2", - "define-properties": "^1.1.3" + "define-properties": "^1.2.0", + "set-function-name": "^2.0.0" }, "engines": { "node": ">= 0.4" @@ -2822,11 +3032,12 @@ } }, "node_modules/resolve": { - "version": "1.22.0", + "version": "1.22.8", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", + "integrity": "sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==", "dev": true, - "license": "MIT", "dependencies": { - "is-core-module": "^2.8.1", + "is-core-module": "^2.13.0", "path-parse": "^1.0.7", "supports-preserve-symlinks-flag": "^1.0.0" }, @@ -2908,11 +3119,52 @@ "tslib": "^2.1.0" } }, + "node_modules/safe-array-concat": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/safe-array-concat/-/safe-array-concat-1.1.0.tgz", + "integrity": "sha512-ZdQ0Jeb9Ofti4hbt5lX3T2JcAamT9hfzYU1MNB+z/jaEbB6wfFfPIR/zEORmZqobkCCJhSjodobH6WHNmJ97dg==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.5", + "get-intrinsic": "^1.2.2", + "has-symbols": "^1.0.3", + "isarray": "^2.0.5" + }, + "engines": { + "node": ">=0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/safe-array-concat/node_modules/isarray": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", + "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", + "dev": true + }, "node_modules/safe-buffer": { "version": "5.1.2", "dev": true, "license": "MIT" }, + "node_modules/safe-regex-test": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/safe-regex-test/-/safe-regex-test-1.0.2.tgz", + "integrity": "sha512-83S9w6eFq12BBIJYvjMux6/dkirb8+4zJRA9cxNBVb7Wq5fJBW+Xze48WqR8pxua7bDuAaaAxtVVd4Idjp1dBQ==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.5", + "get-intrinsic": "^1.2.2", + "is-regex": "^1.1.4" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/semver": { "version": "7.5.4", "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", @@ -2928,6 +3180,36 @@ "node": ">=10" } }, + "node_modules/set-function-length": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.0.tgz", + "integrity": "sha512-4DBHDoyHlM1IRPGYcoxexgh67y4ueR53FKV1yyxwFMY7aCqcN/38M1+SwZ/qJQ8iLv7+ck385ot4CcisOAPT9w==", + "dev": true, + "dependencies": { + "define-data-property": "^1.1.1", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.2", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/set-function-name": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/set-function-name/-/set-function-name-2.0.1.tgz", + "integrity": "sha512-tMNCiqYVkXIZgc2Hnoy2IvC/f8ezc5koaRFkCjrpWzGpCd3qbZXPzVy9MAZzK1ch/X0jvSkojys3oqJN0qCmdA==", + "dev": true, + "dependencies": { + "define-data-property": "^1.0.1", + "functions-have-names": "^1.2.3", + "has-property-descriptors": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/shebang-command": { "version": "2.0.0", "dev": true, @@ -3071,13 +3353,14 @@ } }, "node_modules/string.prototype.trim": { - "version": "1.2.5", + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/string.prototype.trim/-/string.prototype.trim-1.2.8.tgz", + "integrity": "sha512-lfjY4HcixfQXOfaqCvcBuOIapyaroTXhbkfJN3gcB1OtyupngWK4sEET9Knd0cXd28kTUqu/kHoV4HKSJdnjiQ==", "dev": true, - "license": "MIT", "dependencies": { "call-bind": "^1.0.2", - "define-properties": "^1.1.3", - "es-abstract": "^1.19.1" + "define-properties": "^1.2.0", + "es-abstract": "^1.22.1" }, "engines": { "node": ">= 0.4" @@ -3087,24 +3370,28 @@ } }, "node_modules/string.prototype.trimend": { - "version": "1.0.4", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.7.tgz", + "integrity": "sha512-Ni79DqeB72ZFq1uH/L6zJ+DKZTkOtPIHovb3YZHQViE+HDouuU4mBrLOLDn5Dde3RF8qw5qVETEjhu9locMLvA==", "dev": true, - "license": "MIT", "dependencies": { "call-bind": "^1.0.2", - "define-properties": "^1.1.3" + "define-properties": "^1.2.0", + "es-abstract": "^1.22.1" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/string.prototype.trimstart": { - "version": "1.0.4", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.7.tgz", + "integrity": "sha512-NGhtDFu3jCEm7B4Fy0DpLewdJQOZcQ0rGbwQ/+stjnrp2i+rlKeCvos9hOIeCmqwratM47OBxY7uFZzjxHXmrg==", "dev": true, - "license": "MIT", "dependencies": { "call-bind": "^1.0.2", - "define-properties": "^1.1.3" + "define-properties": "^1.2.0", + "es-abstract": "^1.22.1" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -3387,14 +3674,80 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/typed-array-buffer": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/typed-array-buffer/-/typed-array-buffer-1.0.0.tgz", + "integrity": "sha512-Y8KTSIglk9OZEr8zywiIHG/kmQ7KWyjseXs1CbSo8vC42w7hg2HgYTxSWwP0+is7bWDc1H+Fo026CpHFwm8tkw==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "get-intrinsic": "^1.2.1", + "is-typed-array": "^1.1.10" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/typed-array-byte-length": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/typed-array-byte-length/-/typed-array-byte-length-1.0.0.tgz", + "integrity": "sha512-Or/+kvLxNpeQ9DtSydonMxCx+9ZXOswtwJn17SNLvhptaXYDJvkFFP5zbfU/uLmvnBJlI4yrnXRxpdWH/M5tNA==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "for-each": "^0.3.3", + "has-proto": "^1.0.1", + "is-typed-array": "^1.1.10" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/typed-array-byte-offset": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/typed-array-byte-offset/-/typed-array-byte-offset-1.0.0.tgz", + "integrity": "sha512-RD97prjEt9EL8YgAgpOkf3O4IF9lhJFr9g0htQkm0rchFp/Vx7LW5Q8fSXXub7BXAODyUQohRMyOc3faCPd0hg==", + "dev": true, + "dependencies": { + "available-typed-arrays": "^1.0.5", + "call-bind": "^1.0.2", + "for-each": "^0.3.3", + "has-proto": "^1.0.1", + "is-typed-array": "^1.1.10" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/typed-array-length": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/typed-array-length/-/typed-array-length-1.0.4.tgz", + "integrity": "sha512-KjZypGq+I/H7HI5HlOoGHkWUUGq+Q0TPhQurLbyrVrvnKTBgzLhIJ7j6J/XTQOi0d1RjyZ0wdas8bKs2p0x3Ng==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "for-each": "^0.3.3", + "is-typed-array": "^1.1.9" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/unbox-primitive": { - "version": "1.0.1", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", + "integrity": "sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw==", "dev": true, - "license": "MIT", "dependencies": { - "function-bind": "^1.1.1", - "has-bigints": "^1.0.1", - "has-symbols": "^1.0.2", + "call-bind": "^1.0.2", + "has-bigints": "^1.0.2", + "has-symbols": "^1.0.3", "which-boxed-primitive": "^1.0.2" }, "funding": { @@ -3532,16 +3885,16 @@ } }, "node_modules/which-typed-array": { - "version": "1.1.7", + "version": "1.1.13", + "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.13.tgz", + "integrity": "sha512-P5Nra0qjSncduVPEAr7xhoF5guty49ArDTwzJ/yNuPIbZppyRxFQsRCWrocxIY+CnMVG+qfbU2FmDKyvSGClow==", "dev": true, - "license": "MIT", "dependencies": { "available-typed-arrays": "^1.0.5", - "call-bind": "^1.0.2", - "es-abstract": "^1.18.5", - "foreach": "^2.0.5", - "has-tostringtag": "^1.0.0", - "is-typed-array": "^1.1.7" + "call-bind": "^1.0.4", + "for-each": "^0.3.3", + "gopd": "^1.0.1", + "has-tostringtag": "^1.0.0" }, "engines": { "node": ">= 0.4" diff --git a/package.json b/package.json index e0b13dac..264df648 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "test": "c8 npm run test:run", "test:run": "tape '{,!(node_modules)/**/}*.test.js' | tap-diff", "lint": "eslint '**/*.js'", - "lint:fix": "eslint '**/*.js' --fix" + "lint:fix": "eslint '**/*.js' --fix", + "prepublishOnly": "node scripts/prepublishOnly.js" }, "lint-staged": { "*.js": [ diff --git a/scripts/compiler.js b/scripts/compiler.js new file mode 100644 index 00000000..376c2c2b --- /dev/null +++ b/scripts/compiler.js @@ -0,0 +1,60 @@ +/* + * Copyright 2023 Comcast Cable Communications Management, LLC + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +import parser from '../src/lib/templateparser/parser.js' +import generator from '../src/lib/codegenerator/generator.js' +import path from 'path' + +export default (source, filePath) => { + if (source.indexOf('Blits.Component(') > -1 || source.indexOf('Blits.Application(') > -1) { + // get the start of the template key in de component configuration object + const templateKeyRegex = /template:\s*([`"'])*/g + const templateStartResult = templateKeyRegex.exec(source) + + if (templateStartResult) { + const typeOfQuotesUsed = templateStartResult[1] + const templateStartIndex = templateStartResult.index + + // get the template contents from the configuration object + const templateContentsRegex = new RegExp(`${typeOfQuotesUsed}([\\s\\S]*?)${typeOfQuotesUsed}`) + const templateContentResult = templateContentsRegex.exec(source.slice(templateStartIndex)) + const templateEndIndex = + templateStartIndex + templateContentResult.index + templateContentResult[0].length + + // Parse the template + let resourceName = 'Blits.Application' + if (source.indexOf('Blits.Component(') > -1) { + resourceName = source.match(/Blits\.Component\(['"](.*)['"]\s*,/)[1] + } + const componentPath = path.relative(process.cwd(), filePath) + const parsed = parser(templateContentResult[1], resourceName, null, componentPath) + + // Generate the code + const code = generator.call({ components: {} }, parsed) + + // Insert the code in the component using the 'code' key, replacing the template key + const replacement = `code: { render: ${code.render.toString()}, effects: [${code.effects.map( + (fn) => fn.toString() + ',' + )}], context: {}}` + const newSource = + source.substring(0, templateStartIndex) + replacement + source.substring(templateEndIndex) + + return newSource + } + } + return source +} diff --git a/scripts/prepublishOnly.js b/scripts/prepublishOnly.js new file mode 100644 index 00000000..a72742a3 --- /dev/null +++ b/scripts/prepublishOnly.js @@ -0,0 +1,75 @@ +/* + * Copyright 2023 Comcast Cable Communications Management, LLC + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +import fs from 'fs' +import path from 'path' +import compiler from './compiler.js' +import { exec } from 'child_process' + +const currentDir = process.cwd() +const targetDir = path.resolve(currentDir, 'src') +const componentDirs = ['src/components'] + +function precompileComponents(directory) { + console.log(`Checking files in ${directory} for components to precompile`) + const files = fs.readdirSync(directory) + + for (const file of files) { + const filePath = path.join(directory, file) + const filePathRelative = path.relative(currentDir, filePath) + const stat = fs.statSync(filePath) + + if (stat.isDirectory()) { + if (componentDirs.includes(filePathRelative)) { + precompileComponents(filePath) + } + } else if ( + componentDirs.includes(path.dirname(filePathRelative)) && + (file.endsWith('.js') || file.endsWith('.ts')) + ) { + const source = fs.readFileSync(filePath, 'utf-8') + const newSource = compiler(source, filePath) + fs.writeFileSync(filePath, newSource) + + // only format the file if it was changed + if (source !== newSource) { + formatFileWithESLint(filePath) + } + } + } + + console.log('Finished processing files suitable for precompilation') +} + +function formatFileWithESLint(filePath) { + const command = `eslint "${filePath}" --fix` + + exec(command, (error, stdout, stderr) => { + if (error) { + console.error(`Execution Error: ${error.message}`) + console.error(`Exit Code: ${error.code}`) + } + if (stderr) { + console.error(`ESLint Error: ${stderr}`) + } + if (stdout) { + console.log(`ESLint Output: ${stdout}`) + } + }) +} + +precompileComponents(targetDir) diff --git a/vite/index.js b/vite/index.js index f4200353..3cc6f39e 100644 --- a/vite/index.js +++ b/vite/index.js @@ -1,3 +1,20 @@ +/* + * Copyright 2023 Comcast Cable Communications Management, LLC + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + import preCompiler from './preCompiler.js' import { importChunkUrl } from '@lightningjs/vite-plugin-import-chunk-url' diff --git a/vite/preCompiler.js b/vite/preCompiler.js index 9955b2a4..6846c9dd 100644 --- a/vite/preCompiler.js +++ b/vite/preCompiler.js @@ -1,6 +1,21 @@ -import parser from '../src/lib/templateparser/parser.js' -import generator from '../src/lib/codegenerator/generator.js' -import path from 'path' +/* + * Copyright 2023 Comcast Cable Communications Management, LLC + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +import compiler from '../scripts/compiler.js' export default function () { let config @@ -11,42 +26,7 @@ export default function () { }, transform(source, filePath) { if (config.blits && config.blits.precompile === false) return source - if (source.indexOf('Blits.Component(') > -1 || source.indexOf('Blits.Application(') > -1) { - // get the start of the template key in de component configuration object - const templateKeyRegex = /template:\s*([`"'])*/g - const templateStartResult = templateKeyRegex.exec(source) - const typeOfQuotesUsed = templateStartResult[1] - const templateStartIndex = templateStartResult.index - - // get the template contents from the configuration object - const templateContentsRegex = new RegExp( - `${typeOfQuotesUsed}([\\s\\S]*?)${typeOfQuotesUsed}` - ) - - const templateContentResult = templateContentsRegex.exec(source.slice(templateStartIndex)) - const templateEndIndex = - templateStartIndex + templateContentResult.index + templateContentResult[0].length - - // Parse the template - let resourceName = 'Blits.Application' - if (source.indexOf('Blits.Component(') > -1) { - resourceName = source.match(/Blits\.Component\(['"](.*)['"]\s*,/)[1] - } - const componentPath = path.relative(process.cwd(), filePath) - const parsed = parser(templateContentResult[1], resourceName, null, componentPath) - - // Generate the code - const code = generator.call({ components: {} }, parsed) - - // Insert the code in the component using the 'code' key, replacing the template key - const replacement = `code: { render: ${code.render.toString()}, effects: [${code.effects.map( - (fn) => fn.toString() + ',' - )}], context: {}}` - const newSource = - source.substring(0, templateStartIndex) + replacement + source.substring(templateEndIndex) - - return newSource - } + return compiler(source, filePath) }, } } From f1af947885fbcf290ca0557c7bfa287439d2da16 Mon Sep 17 00:00:00 2001 From: Michiel van der Geest Date: Tue, 30 Jan 2024 09:35:06 +0100 Subject: [PATCH 2/5] Moved precompiler functionality from scripts folder into src folder. --- scripts/prepublishOnly.js | 2 +- scripts/compiler.js => src/lib/precompiler/precompiler.js | 4 ++-- vite/preCompiler.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename scripts/compiler.js => src/lib/precompiler/precompiler.js (95%) diff --git a/scripts/prepublishOnly.js b/scripts/prepublishOnly.js index a72742a3..96a423bd 100644 --- a/scripts/prepublishOnly.js +++ b/scripts/prepublishOnly.js @@ -17,7 +17,7 @@ import fs from 'fs' import path from 'path' -import compiler from './compiler.js' +import compiler from '../src/lib/precompiler/compiler.js' import { exec } from 'child_process' const currentDir = process.cwd() diff --git a/scripts/compiler.js b/src/lib/precompiler/precompiler.js similarity index 95% rename from scripts/compiler.js rename to src/lib/precompiler/precompiler.js index 376c2c2b..ebb0d0de 100644 --- a/scripts/compiler.js +++ b/src/lib/precompiler/precompiler.js @@ -15,8 +15,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -import parser from '../src/lib/templateparser/parser.js' -import generator from '../src/lib/codegenerator/generator.js' +import parser from '../templateparser/parser.js' +import generator from '../codegenerator/generator.js' import path from 'path' export default (source, filePath) => { diff --git a/vite/preCompiler.js b/vite/preCompiler.js index 6846c9dd..9a26201d 100644 --- a/vite/preCompiler.js +++ b/vite/preCompiler.js @@ -15,7 +15,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import compiler from '../scripts/compiler.js' +import compiler from '../src/lib/precompiler/precompiler.js' export default function () { let config From 4c7db2ff730a432c0209700cbf8edcf5c44ac42d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20Aslan?= Date: Tue, 30 Jan 2024 10:19:30 +0100 Subject: [PATCH 3/5] fixed issues related to prepublish script & precompiler --- scripts/prepublishOnly.js | 2 +- src/lib/precompiler/precompiler.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/prepublishOnly.js b/scripts/prepublishOnly.js index 96a423bd..df049941 100644 --- a/scripts/prepublishOnly.js +++ b/scripts/prepublishOnly.js @@ -17,7 +17,7 @@ import fs from 'fs' import path from 'path' -import compiler from '../src/lib/precompiler/compiler.js' +import compiler from '../src/lib/precompiler/precompiler.js' import { exec } from 'child_process' const currentDir = process.cwd() diff --git a/src/lib/precompiler/precompiler.js b/src/lib/precompiler/precompiler.js index ebb0d0de..f26241f4 100644 --- a/src/lib/precompiler/precompiler.js +++ b/src/lib/precompiler/precompiler.js @@ -20,7 +20,11 @@ import generator from '../codegenerator/generator.js' import path from 'path' export default (source, filePath) => { - if (source.indexOf('Blits.Component(') > -1 || source.indexOf('Blits.Application(') > -1) { + if ( + source.indexOf('Blits.Component(') > -1 || + source.indexOf('Blits.Application(') > -1 || + /=>\s*Component\(['"][A-Za-z]+['"],/s.test(source) // blits component + ) { // get the start of the template key in de component configuration object const templateKeyRegex = /template:\s*([`"'])*/g const templateStartResult = templateKeyRegex.exec(source) From db3270ee8c33cfc9262e9f7c18f62387fcfbb97a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20Aslan?= Date: Wed, 31 Jan 2024 07:14:09 +0100 Subject: [PATCH 4/5] fixed double commas issue between effects fns in generated code --- src/lib/precompiler/precompiler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/precompiler/precompiler.js b/src/lib/precompiler/precompiler.js index f26241f4..d9fcc585 100644 --- a/src/lib/precompiler/precompiler.js +++ b/src/lib/precompiler/precompiler.js @@ -51,8 +51,8 @@ export default (source, filePath) => { const code = generator.call({ components: {} }, parsed) // Insert the code in the component using the 'code' key, replacing the template key - const replacement = `code: { render: ${code.render.toString()}, effects: [${code.effects.map( - (fn) => fn.toString() + ',' + const replacement = `/* eslint-disable no-unused-vars */ \ncode: { render: ${code.render.toString()}, effects: [${code.effects.map( + (fn) => fn.toString() )}], context: {}}` const newSource = source.substring(0, templateStartIndex) + replacement + source.substring(templateEndIndex) From b4456f2d1cf5c4461a5829b53406d94357701ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20Aslan?= Date: Wed, 31 Jan 2024 13:17:06 +0100 Subject: [PATCH 5/5] refactored prepublish script & implemented postpublish script --- package.json | 3 +- scripts/postpublish.js | 59 +++++++++++++++++++++++++++++++++++++++ scripts/prepublishOnly.js | 51 +++++++++++++++++++-------------- 3 files changed, 91 insertions(+), 22 deletions(-) create mode 100644 scripts/postpublish.js diff --git a/package.json b/package.json index 0253f6e4..f54f2a5e 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "test:run": "tape '{,!(node_modules)/**/}*.test.js' | tap-diff", "lint": "eslint '**/*.js'", "lint:fix": "eslint '**/*.js' --fix", - "prepublishOnly": "node scripts/prepublishOnly.js" + "prepublishOnly": "node scripts/prepublishOnly.js", + "postpublish": "node scripts/postpublish.js" }, "lint-staged": { "*.js": [ diff --git a/scripts/postpublish.js b/scripts/postpublish.js new file mode 100644 index 00000000..6f01afc2 --- /dev/null +++ b/scripts/postpublish.js @@ -0,0 +1,59 @@ +/* + * Copyright 2023 Comcast Cable Communications Management, LLC + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +import fs from 'fs' +import path from 'path' + +const currentDir = process.cwd() +const componentDirs = ['src/components'] + +function precompileCleanUp() { + for (const dir of componentDirs) { + const fullDir = path.resolve(currentDir, dir) + console.log(`Checking files in ${fullDir} for original files that precompiler created`) + processDirectory(fullDir) + } + console.log('Finished restoring original files after precompile') +} + +function processDirectory(directory) { + const files = fs.readdirSync(directory) + + for (const file of files) { + const filePath = path.join(directory, file) + const stat = fs.statSync(filePath) + + if (stat.isDirectory()) { + processDirectory(filePath) + } else if (/\.(orig\.(js|ts))$/.test(file)) { + restoreOriginalFile(filePath) + } + } +} + +function restoreOriginalFile(filePath) { + const originalFilePath = filePath.replace(/\.orig\.(j|t)s$/, '.$1s') + console.log(`Restoring original file ${originalFilePath}`) + + // Restore the original file by copying the backup file over it + fs.copyFileSync(filePath, originalFilePath) + + // Delete the backup file + fs.unlinkSync(filePath) +} + +precompileCleanUp() diff --git a/scripts/prepublishOnly.js b/scripts/prepublishOnly.js index df049941..696e9076 100644 --- a/scripts/prepublishOnly.js +++ b/scripts/prepublishOnly.js @@ -21,38 +21,47 @@ import compiler from '../src/lib/precompiler/precompiler.js' import { exec } from 'child_process' const currentDir = process.cwd() -const targetDir = path.resolve(currentDir, 'src') const componentDirs = ['src/components'] -function precompileComponents(directory) { - console.log(`Checking files in ${directory} for components to precompile`) +function precompileComponents() { + for (const dir of componentDirs) { + const fullDir = path.resolve(currentDir, dir) + console.log(`Checking files in ${fullDir} for components to precompile`) + processDirectory(fullDir) + } + console.log('Finished processing files suitable for precompilation') +} + +function processDirectory(directory) { const files = fs.readdirSync(directory) for (const file of files) { const filePath = path.join(directory, file) - const filePathRelative = path.relative(currentDir, filePath) const stat = fs.statSync(filePath) if (stat.isDirectory()) { - if (componentDirs.includes(filePathRelative)) { - precompileComponents(filePath) - } - } else if ( - componentDirs.includes(path.dirname(filePathRelative)) && - (file.endsWith('.js') || file.endsWith('.ts')) - ) { - const source = fs.readFileSync(filePath, 'utf-8') - const newSource = compiler(source, filePath) - fs.writeFileSync(filePath, newSource) - - // only format the file if it was changed - if (source !== newSource) { - formatFileWithESLint(filePath) - } + processDirectory(filePath) + } else if (/^(?!.*\.orig\.(js|ts)$).*\.(js|ts)$/.test(file)) { + // only process files that don't end in .orig.js or .orig.ts + processFile(filePath) } } +} - console.log('Finished processing files suitable for precompilation') +function processFile(filePath) { + console.log(`Precompiling ${filePath}`) + // backup the file + const backupFilePath = filePath.replace(/\.(j|t)s$/, '.orig.$1s') + fs.copyFileSync(filePath, backupFilePath) + + const source = fs.readFileSync(filePath, 'utf-8') + const newSource = compiler(source, filePath) + fs.writeFileSync(filePath, newSource) + + // only format the file if it was changed + if (source !== newSource) { + formatFileWithESLint(filePath) + } } function formatFileWithESLint(filePath) { @@ -72,4 +81,4 @@ function formatFileWithESLint(filePath) { }) } -precompileComponents(targetDir) +precompileComponents()