From e932524774b78bc78730b8786f959c125e4193f4 Mon Sep 17 00:00:00 2001 From: "Rong Sen Ng (motss)" Date: Fri, 4 Feb 2022 15:24:47 +0800 Subject: [PATCH] ci: drop zx in favor of simple Node script --- package.json | 8 ++++---- postinstall.mjs | 48 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index af76aff..3a3583d 100644 --- a/package.json +++ b/package.json @@ -47,10 +47,10 @@ "build": "npm run clean && npm run ts", "check": "package-check", "clean": "rm -rf .*cache *.log .swc/ coverage/ dist/ logs/", - "postinstall": "npm x -y --prefer-online -- zx@latest ./postinstall.mjs", + "postinstall": "node postinstall.mjs", "lint": "eslint src --ext .js,.ts", - "lint:commit": "npm x -y --prefer-online -- commitlint@latest --edit", "lint:build": "npm run lint -- --config .build.eslintrc.json", + "lint:commit": "npm x -y -- commitlint@latest --edit", "pre-commit": "package-check && nano-staged && tsc --noEmit", "prepublishOnly": "package-check && npm run lint:build && npm run build", "test": "c8 --reporter=lcov --exclude=src/tests uvu -r @swc/register src/tests", @@ -58,8 +58,8 @@ "watch": "tsc --watch" }, "simple-git-hooks": { - "commit-msg": "npm run lint:commit", - "pre-commit": "npm run pre-commit" + "pre-commit": "npm run pre-commit", + "commit-msg": "npm run lint:commit" }, "commitlint": { "extends": [ diff --git a/postinstall.mjs b/postinstall.mjs index bb442ba..92277ac 100644 --- a/postinstall.mjs +++ b/postinstall.mjs @@ -1,18 +1,44 @@ -#!/usr/bin/env zx +#!/usr/bin/env node -const { - CI, - INIT_CWD, -} = process.env; +import { spawn } from 'node:child_process' +import { readFile } from 'node:fs/promises'; const { - name: moduleName, -} = JSON.parse(await fs.readFile('./package.json', { encoding: 'utf-8' })); + CI = false, + INIT_CWD = '', +} = process.env; if ( - CI != 'true' && - !INIT_CWD.endsWith(`node_modules/${moduleName}`) && - INIT_CWD.endsWith(moduleName) + CI !== 'true' ) { - await $`simple-git-hooks && npm dedupe`; + const { + name: moduleName, + } = JSON.parse(await readFile('./package.json', { encoding: 'utf-8' })); + + if ( + !INIT_CWD.endsWith(`node_modules/${moduleName}`) && + INIT_CWD.endsWith(moduleName) + ) { + const cmd = 'simple-git-hooks && npm dedupe'; + + process.stdout.write(cmd); + process.stdout.write('\n\n'); + + const postinstall = spawn( + cmd, + [], + { + shell: true, + windowsHide: true, + } + ); + + postinstall.stdout.on('data', (data) => { + process.stdout.write(data); + }); + + postinstall.stderr.on('data', (data) => { + process.stderr.write(data); + }); + } }