From 1baeefedf1debbba9537fccabbcf3b822de7e5b0 Mon Sep 17 00:00:00 2001 From: Ferris <3579192+code-ape@users.noreply.github.com> Date: Fri, 20 May 2022 05:54:36 -0400 Subject: [PATCH] Allow Knex 2.x with Typescript to be installed via git (#5187) --- .github/workflows/integration-tests.yml | 10 ++++++--- .husky/pre-commit | 0 package.json | 5 ++--- scripts/clean.js | 29 +++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) mode change 100644 => 100755 .husky/pre-commit create mode 100755 scripts/clean.js diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index d836e63f..c38c7637 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -110,6 +110,10 @@ jobs: always-auth: false node-version: ${{ matrix.node-version }} - - run: npm install - - run: npm pack - - run: npm install -g + - name: Test npm git dependency + shell: bash + run: | + mkdir TMP/ + echo "{ \"dependencies\": { \"knex\": \"git+file://$(pwd)/\" } }" > TMP/package.json + cd TMP/ + npm install --verbose diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100644 new mode 100755 diff --git a/package.json b/package.json index 45bcc940..65ad0a61 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ }, "scripts": { "build": "npm run build:gitignore && npm run build:ts", - "clean": "git clean -f -X lib/", + "clean": "node scripts/clean.js", "build:ts": "tsc", "build:gitignore": "node scripts/update_gitignore_for_tsc_output.js run", "format": "prettier --write \"{lib,bin,scripts,test}/**/*.js\"", @@ -99,8 +99,7 @@ }, "lint-staged": { "*.{js,json}": [ - "prettier --write", - "git add" + "prettier --write" ] }, "devDependencies": { diff --git a/scripts/clean.js b/scripts/clean.js new file mode 100755 index 00000000..fa1b7884 --- /dev/null +++ b/scripts/clean.js @@ -0,0 +1,29 @@ +#!/usr/bin/env node + +const fs = require('fs') +const path = require('path') +const { execSync } = require("child_process"); + +function main() { + const repoDir = path.dirname(__dirname) + const gitDir = path.join(repoDir, '.git') + const gitDirExists = doesDirectoryExist(gitDir) + if (!gitDirExists) { + console.log("No .git directory detected so can not clean 'lib/'. Exiting.") + process.exit(0) + } + console.log("Cleaning 'lib/' of outputted files from Typescript compilation ...") + const cmd = 'git clean -f -X lib/' + const output = execSync(cmd, { cwd: repoDir }) + console.log(output.toString('utf8')) + console.log('Done') +} + +function doesDirectoryExist(p) { + if (fs.existsSync(p)) { + return fs.lstatSync(p).isDirectory() + } + return false +} + +main()