From 609a8ca5c2d18392a837df5882536dfd41af2ee0 Mon Sep 17 00:00:00 2001 From: Nazmus Sayad <87106526+NazmusSayad@users.noreply.github.com> Date: Mon, 23 Sep 2024 18:07:47 +0600 Subject: [PATCH] dev mode can now rull all kind of things --- .gitignore | 5 + .npmignore | 2 + LICENSE => LICENSE.md | 0 build.cjs | 4 +- package-lock.json | 362 ++++++++++-------------------------------- package.json | 9 +- src/__lab__/index.ts | 4 +- src/program/build.ts | 29 ++-- src/program/dev.ts | 29 +++- src/program/init.ts | 13 +- src/scripts/tsc.ts | 7 +- src/utils.ts | 18 ++- 12 files changed, 172 insertions(+), 310 deletions(-) rename LICENSE => LICENSE.md (100%) diff --git a/.gitignore b/.gitignore index 6704566..6b1b25d 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,8 @@ dist # TernJS port file .tern-port + + +# npmize +.npmize +node_modules \ No newline at end of file diff --git a/.npmignore b/.npmignore index 0214632..6a6144d 100644 --- a/.npmignore +++ b/.npmignore @@ -1,4 +1,6 @@ * !dist/** !README.md +!LICENSE.md !package.json +__lab__ \ No newline at end of file diff --git a/LICENSE b/LICENSE.md similarity index 100% rename from LICENSE rename to LICENSE.md diff --git a/build.cjs b/build.cjs index 55b7948..19028d0 100644 --- a/build.cjs +++ b/build.cjs @@ -1,5 +1,5 @@ -const shelljs = require('shelljs') +const crossSpawn = require('cross-spawn') const fs = require('fs') fs.rmSync('./dist', { recursive: true, force: true }) -shelljs.exec('tsc') +crossSpawn.sync('tsc', { stdio: 'inherit' }) diff --git a/package-lock.json b/package-lock.json index 1700dc0..252e1f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,17 +11,16 @@ "dependencies": { "@babel/parser": "^7.25.6", "ansi-colors": "^4.1.3", - "lskit": "^1.0.0", + "cross-spawn": "^7.0.3", "noarg": "^3.1.0", - "shelljs": "^0.8.5", "typescript": "^5.6.2" }, "bin": { "npmize": "dist/index.js" }, "devDependencies": { - "@types/node": "^18.19.50", - "@types/shelljs": "^0.8.15" + "@types/cross-spawn": "^6.0.6", + "@types/node": "^22.5.5" } }, "node_modules/@babel/helper-string-parser": { @@ -111,18 +110,17 @@ } }, "node_modules/@inquirer/core": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/@inquirer/core/-/core-9.1.0.tgz", - "integrity": "sha512-RZVfH//2ytTjmaBIzeKT1zefcQZzuruwkpTwwbe/i2jTl4o9M+iML5ChULzz6iw1Ok8iUBBsRCjY2IEbD8Ft4w==", + "version": "9.2.1", + "resolved": "https://registry.npmjs.org/@inquirer/core/-/core-9.2.1.tgz", + "integrity": "sha512-F2VBt7W/mwqEU4bL0RnHNZmC/OxzNx9cOYxHqnXX3MP6ruYvZUZAW9imgN9+h/uBT/oP8Gh888J2OZSbjSeWcg==", "license": "MIT", "dependencies": { - "@inquirer/figures": "^1.0.5", - "@inquirer/type": "^1.5.3", + "@inquirer/figures": "^1.0.6", + "@inquirer/type": "^2.0.0", "@types/mute-stream": "^0.0.4", - "@types/node": "^22.5.2", + "@types/node": "^22.5.5", "@types/wrap-ansi": "^3.0.0", "ansi-escapes": "^4.3.2", - "cli-spinners": "^2.9.2", "cli-width": "^4.1.0", "mute-stream": "^1.0.0", "signal-exit": "^4.1.0", @@ -134,21 +132,18 @@ "node": ">=18" } }, - "node_modules/@inquirer/core/node_modules/@types/node": { - "version": "22.5.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.4.tgz", - "integrity": "sha512-FDuKUJQm/ju9fT/SeX/6+gBzoPzlVCzfzmGkwKvRHQVxi4BntVbyIwf6a4Xn62mrvndLiml6z/UBXIdEVjQLXg==", + "node_modules/@inquirer/core/node_modules/@inquirer/type": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@inquirer/type/-/type-2.0.0.tgz", + "integrity": "sha512-XvJRx+2KR3YXyYtPUUy+qd9i7p+GO9Ko6VIIpWlBrpWwXDv8WLFeHTxz35CfQFUiBMLXlGHhGzys7lqit9gWag==", "license": "MIT", "dependencies": { - "undici-types": "~6.19.2" + "mute-stream": "^1.0.0" + }, + "engines": { + "node": ">=18" } }, - "node_modules/@inquirer/core/node_modules/undici-types": { - "version": "6.19.8", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", - "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", - "license": "MIT" - }, "node_modules/@inquirer/editor": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@inquirer/editor/-/editor-2.2.0.tgz", @@ -178,9 +173,9 @@ } }, "node_modules/@inquirer/figures": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/@inquirer/figures/-/figures-1.0.5.tgz", - "integrity": "sha512-79hP/VWdZ2UVc9bFGJnoQ/lQMpL74mGgzSYX1xUqCVk7/v73vJCMw1VuyWN1jGkZ9B3z7THAbySqGbCNefcjfA==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@inquirer/figures/-/figures-1.0.6.tgz", + "integrity": "sha512-yfZzps3Cso2UbM7WlxKwZQh2Hs6plrbjs1QnzQDZhK2DgyCo6D8AaHps9olkNcUFlcYERMqU3uJSp1gmy3s/qQ==", "license": "MIT", "engines": { "node": ">=18" @@ -293,9 +288,9 @@ } }, "node_modules/@inquirer/type": { - "version": "1.5.3", - "resolved": "https://registry.npmjs.org/@inquirer/type/-/type-1.5.3.tgz", - "integrity": "sha512-xUQ14WQGR/HK5ei+2CvgcwoH9fQ4PgPGmVFSN0pc1+fVyDL3MREhyAY7nxEErSu6CkllBM3D7e3e+kOvtu+eIg==", + "version": "1.5.5", + "resolved": "https://registry.npmjs.org/@inquirer/type/-/type-1.5.5.tgz", + "integrity": "sha512-MzICLu4yS7V8AA61sANROZ9vT1H3ooca5dSmI1FjZkzq7o/koMsRfQSzRtFo+F3Ao4Sf1C0bpLKejpKB/+j6MA==", "license": "MIT", "dependencies": { "mute-stream": "^1.0.0" @@ -304,24 +299,16 @@ "node": ">=18" } }, - "node_modules/@types/glob": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.2.0.tgz", - "integrity": "sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==", + "node_modules/@types/cross-spawn": { + "version": "6.0.6", + "resolved": "https://registry.npmjs.org/@types/cross-spawn/-/cross-spawn-6.0.6.tgz", + "integrity": "sha512-fXRhhUkG4H3TQk5dBhQ7m/JDdSNHKwR2BBia62lhwEIq9xGiQKLxd6LymNhn47SjXhsUEPmxi+PKw2OkW4LLjA==", "dev": true, "license": "MIT", "dependencies": { - "@types/minimatch": "*", "@types/node": "*" } }, - "node_modules/@types/minimatch": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-5.1.2.tgz", - "integrity": "sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/mute-stream": { "version": "0.0.4", "resolved": "https://registry.npmjs.org/@types/mute-stream/-/mute-stream-0.0.4.tgz", @@ -332,23 +319,12 @@ } }, "node_modules/@types/node": { - "version": "18.19.50", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.50.tgz", - "integrity": "sha512-xonK+NRrMBRtkL1hVCc3G+uXtjh1Al4opBLjqVmipe5ZAaBYWW6cNAiBVZ1BvmkBhep698rP3UM3aRAdSALuhg==", - "license": "MIT", - "dependencies": { - "undici-types": "~5.26.4" - } - }, - "node_modules/@types/shelljs": { - "version": "0.8.15", - "resolved": "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.8.15.tgz", - "integrity": "sha512-vzmnCHl6hViPu9GNLQJ+DZFd6BQI2DBTUeOvYHqkWQLMfKAAQYMb/xAmZkTogZI/vqXHCWkqDRymDI5p0QTi5Q==", - "dev": true, + "version": "22.5.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.5.tgz", + "integrity": "sha512-Xjs4y5UPO/CLdzpgR6GirZJx36yScjh73+2NlLlkFRSoQN8B0DpfXPdZGnvVmLRLOsqDpOfTNv7D9trgGhmOIA==", "license": "MIT", "dependencies": { - "@types/glob": "~7.2.0", - "@types/node": "*" + "undici-types": "~6.19.2" } }, "node_modules/@types/wrap-ansi": { @@ -405,40 +381,12 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/balanced-match": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "license": "MIT" - }, - "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==", - "license": "MIT", - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, "node_modules/chardet": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==", "license": "MIT" }, - "node_modules/cli-spinners": { - "version": "2.9.2", - "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.2.tgz", - "integrity": "sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==", - "license": "MIT", - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/cli-table3": { "version": "0.6.5", "resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.6.5.tgz", @@ -481,11 +429,19 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "license": "MIT" }, - "node_modules/concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", - "license": "MIT" + "node_modules/cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } }, "node_modules/emoji-regex": { "version": "8.0.0", @@ -507,54 +463,6 @@ "node": ">=4" } }, - "node_modules/fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", - "license": "ISC" - }, - "node_modules/function-bind": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", - "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "deprecated": "Glob versions prior to v9 are no longer supported", - "license": "ISC", - "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/hasown": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", - "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", - "license": "MIT", - "dependencies": { - "function-bind": "^1.1.2" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -567,47 +475,6 @@ "node": ">=0.10.0" } }, - "node_modules/inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", - "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", - "license": "ISC", - "dependencies": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "node_modules/inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "license": "ISC" - }, - "node_modules/interpret": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", - "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==", - "license": "MIT", - "engines": { - "node": ">= 0.10" - } - }, - "node_modules/is-core-module": { - "version": "2.15.1", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.15.1.tgz", - "integrity": "sha512-z0vtXSwucUJtANQWldhbtbt7BnL0vxiFjIdDLAatwhDYty2bad6s+rijD6Ri4YuYJubLzIJLUidCh09e1djEVQ==", - "license": "MIT", - "dependencies": { - "hasown": "^2.0.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", @@ -617,22 +484,11 @@ "node": ">=8" } }, - "node_modules/lskit": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/lskit/-/lskit-1.0.0.tgz", - "integrity": "sha512-IJEmiRtYAh19nxo+jIR9GQwBtIVNIFWb7wq4IN5D2J6++gFoLmoPbQSPQNhxIbpgnqKT/1JUonMQEVAgYjXPQg==" - }, - "node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "license": "ISC", - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "license": "ISC" }, "node_modules/mute-stream": { "version": "1.0.0", @@ -653,15 +509,6 @@ "cli-table3": "^0.6.5" } }, - "node_modules/once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", - "license": "ISC", - "dependencies": { - "wrappy": "1" - } - }, "node_modules/os-tmpdir": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", @@ -671,47 +518,13 @@ "node": ">=0.10.0" } }, - "node_modules/path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", "license": "MIT", "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/path-parse": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", - "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", - "license": "MIT" - }, - "node_modules/rechoir": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", - "integrity": "sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==", - "dependencies": { - "resolve": "^1.1.6" - }, - "engines": { - "node": ">= 0.10" - } - }, - "node_modules/resolve": { - "version": "1.22.8", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", - "integrity": "sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==", - "license": "MIT", - "dependencies": { - "is-core-module": "^2.13.0", - "path-parse": "^1.0.7", - "supports-preserve-symlinks-flag": "^1.0.0" - }, - "bin": { - "resolve": "bin/resolve" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "node": ">=8" } }, "node_modules/safer-buffer": { @@ -720,21 +533,25 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "license": "MIT" }, - "node_modules/shelljs": { - "version": "0.8.5", - "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", - "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", - "license": "BSD-3-Clause", + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "license": "MIT", "dependencies": { - "glob": "^7.0.0", - "interpret": "^1.0.0", - "rechoir": "^0.6.2" - }, - "bin": { - "shjs": "bin/shjs" + "shebang-regex": "^3.0.0" }, "engines": { - "node": ">=4" + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "license": "MIT", + "engines": { + "node": ">=8" } }, "node_modules/signal-exit": { @@ -775,18 +592,6 @@ "node": ">=8" } }, - "node_modules/supports-preserve-symlinks-flag": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", - "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", @@ -834,11 +639,26 @@ } }, "node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", "license": "MIT" }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/wrap-ansi": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", @@ -853,12 +673,6 @@ "node": ">=8" } }, - "node_modules/wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", - "license": "ISC" - }, "node_modules/yoctocolors-cjs": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/yoctocolors-cjs/-/yoctocolors-cjs-2.1.2.tgz", diff --git a/package.json b/package.json index e5d0ad6..fc99f8b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "npmize", "description": "Let's create an npm package without worrying about anything.", - "version": "1.0.14", + "version": "1.0.16", "bin": "./dist/index.js", "scripts": { "dev": "tsc -w", @@ -12,14 +12,13 @@ "dependencies": { "@babel/parser": "^7.25.6", "ansi-colors": "^4.1.3", - "lskit": "^1.0.0", + "cross-spawn": "^7.0.3", "noarg": "^3.1.0", - "shelljs": "^0.8.5", "typescript": "^5.6.2" }, "devDependencies": { - "@types/node": "^18.19.50", - "@types/shelljs": "^0.8.15" + "@types/cross-spawn": "^6.0.6", + "@types/node": "^22.5.5" }, "keywords": [ "npm", diff --git a/src/__lab__/index.ts b/src/__lab__/index.ts index 03a42b2..2a64499 100644 --- a/src/__lab__/index.ts +++ b/src/__lab__/index.ts @@ -4,5 +4,5 @@ import { app } from '../app' import '../main' // app.start(['init', '../npmize-test']) -app.start(['dev', '../npmize-test', '--module', 'mjs']) -// app.start(['build', '../npmize-test']) +// app.start(['dev', '../npmize-test', '--module', 'mjs']) +app.start(['build', '../npmize-test', '--module', 'mjs']) diff --git a/src/program/build.ts b/src/program/build.ts index e88df28..178f1c2 100644 --- a/src/program/build.ts +++ b/src/program/build.ts @@ -1,30 +1,35 @@ +import { + cleanDir, + moveFiles, + getAllFiles, + getNodeModulesTempDir, +} from '../utils' import fs from 'fs' import path from 'path' -import * as lskit from 'lskit' import tsc from '../scripts/tsc' import { CompileOptions } from './types.t' import updateImports from '../updateImports' import pushNodeCode from '../scripts/pushNodeCode' -import { cleanDir, getNodeModulesTempDir, moveFiles } from '../utils' export default function (rootPath: string, options: CompileOptions) { console.log(`Build started at ${rootPath}`) console.log('') const outDir = path.resolve(options.tsConfig?.outDir!) + if (!outDir) throw new Error('tsConfig.outDir is required') cleanDir(outDir) if (options.module) { - runBuild(rootPath, outDir, options.module, options) - } else { - runBuild(rootPath, outDir, 'cjs', options) - runBuild(rootPath, outDir, 'mjs', options) + return runBuild(rootPath, outDir, options.module, options) } + + runBuild(rootPath, outDir, 'cjs', options) + runBuild(rootPath, outDir, 'mjs', options) } function runBuild( rootPath: string, - outDir: string, + fullOutDir: string, moduleType: Exclude, options: Omit ) { @@ -35,11 +40,13 @@ function runBuild( tsc(rootPath, [ ...options.tsc, - `--outDir ${tempOutDir}`, - `--module ${moduleType === 'cjs' ? 'commonjs' : 'esnext'}`, + '--outDir', + tempOutDir, + '--module', + moduleType === 'cjs' ? 'commonjs' : 'esnext', ]) - const files = lskit.sync(tempOutDir) + const files = getAllFiles(tempOutDir) const updatedImports = updateImports( rootPath, tempOutDir, @@ -49,7 +56,7 @@ function runBuild( files ) - const movedFiles = moveFiles(tempOutDir, outDir, updatedImports) + const movedFiles = moveFiles(tempOutDir, fullOutDir, updatedImports) if (moduleType === 'mjs' && options.node && movedFiles.length) { console.log('Enabling Node.js __dirname and __filename...') pushNodeCode(...movedFiles) diff --git a/src/program/dev.ts b/src/program/dev.ts index 76f89c7..912c57d 100644 --- a/src/program/dev.ts +++ b/src/program/dev.ts @@ -7,12 +7,27 @@ import pushNodeCode from '../scripts/pushNodeCode' import { cleanDir, getNodeModulesTempDir, moveFiles } from '../utils' export default function (rootPath: string, options: CompileOptions) { - options.module ??= 'cjs' + const outDir = options.tsConfig?.outDir + if (!outDir) throw new Error('tsConfig.outDir is required') - const finalOutDir = path.resolve(options.tsConfig?.outDir!) + if (options.module) { + return runDev(rootPath, outDir, options.module, options) + } + + runDev(rootPath, outDir, 'cjs', options) + runDev(rootPath, outDir, 'mjs', options) +} + +function runDev( + rootPath: string, + shortOutDir: string, + moduleType: Exclude, + options: Omit +) { + const finalOutDir = path.resolve(shortOutDir) cleanDir(finalOutDir) - const tempOutDir = getNodeModulesTempDir(rootPath, 'dev-' + options.module) + const tempOutDir = getNodeModulesTempDir(rootPath, 'dev-' + moduleType) cleanDir(tempOutDir) function makeOutFiles(filename: string, outModule: 'cjs' | 'mjs') { @@ -35,15 +50,17 @@ export default function (rootPath: string, options: CompileOptions) { fs.watch(tempOutDir, { recursive: true }, (event, filename) => { if (event !== 'change' || !filename) return if (!(filename.endsWith('.js') || filename.endsWith('.ts'))) return - makeOutFiles(filename, options.module!) + makeOutFiles(filename, moduleType) }) tsc( rootPath, [ ...options.tsc, - `--outDir ${tempOutDir}`, - `--module ${options.module === 'cjs' ? 'commonjs' : 'esnext'}`, + '--outDir', + tempOutDir, + '--module', + moduleType === 'cjs' ? 'commonjs' : 'esnext', '--watch', ], true diff --git a/src/program/init.ts b/src/program/init.ts index 8078132..11030f2 100644 --- a/src/program/init.ts +++ b/src/program/init.ts @@ -1,12 +1,12 @@ import fs from 'fs' import path from 'path' -import shelljs from 'shelljs' -import config from '../config' +import crossSpawn from 'cross-spawn' import ansiColors from 'ansi-colors' +import { updateTSConfig } from '../scripts/tsconfig' +import ghWorkflows from '../scripts/ghWorkflows' import packageJSON from '../scripts/packageJSON' import { writeFileSync } from '../utils' -import ghWorkflows from '../scripts/ghWorkflows' -import { updateTSConfig } from '../scripts/tsconfig' +import config from '../config' export default function (basePath: string, options: InitOptions) { console.log(`\x1b[1m\x1b[35m▓▒░ NPMIZE ░▒▓\x1b[0m\n`) @@ -32,7 +32,10 @@ export default function (basePath: string, options: InitOptions) { } if (options.installPackages) { - shelljs.cd(basePath).exec('npm install npmize typescript --save-dev') + crossSpawn.sync('npm', ['install', '--save-dev', 'typescript', 'ts-node'], { + cwd: basePath, + stdio: 'inherit', + }) } else { console.log(ansiColors.bgGreen(' INFO: '), 'TypeScript is disabled') } diff --git a/src/scripts/tsc.ts b/src/scripts/tsc.ts index ea96c19..4fe4515 100644 --- a/src/scripts/tsc.ts +++ b/src/scripts/tsc.ts @@ -1,5 +1,8 @@ -import shelljs from 'shelljs' +import crossSpawn from 'cross-spawn' export default function (cwd: string, args: string[], async = false) { - shelljs.exec(['npx', 'tsc', ...args].join(' '), { cwd, async }) + crossSpawn.sync('npx', ['tsc', ...args], { + cwd, + stdio: 'inherit', + }) } diff --git a/src/utils.ts b/src/utils.ts index 27b0037..f4fad4e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,8 +1,8 @@ import fs from 'fs' import path from 'path' -import shelljs from 'shelljs' -import config from './config' +import crossSpawn from 'cross-spawn' import packageJSON from './scripts/packageJSON' +import config from './config' export function cleanDir(dir: string, createDir = true) { if (fs.existsSync(dir)) { @@ -75,8 +75,20 @@ export function confirmDir(...paths: string[]) { } export function getNodeVersion() { - const nodeVersion = shelljs.exec('node -v', { silent: true }).stdout.trim() + const nodeVersion = crossSpawn.sync('node', ['-v']).stdout.toString().trim() if (nodeVersion) { return Number.parseInt(nodeVersion.replace('v', '')) } } + +export function getAllFiles(dir: string): string[] { + const getTarget = (target: string): string[] => { + if (fs.statSync(target).isFile()) return [target] + + return fs + .readdirSync(target) + .flatMap((file) => getTarget(path.join(target, file))) + } + + return getTarget(dir) +}