Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove rimraf dependency in favor of Node native rm #602

Merged
merged 8 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "./build/lib/index.js",
"typings": "./build/lib/index.d.ts",
"scripts": {
"clean": "rimraf build",
"clean": "node script/clean.js",
"build": "yarn clean && tsc -p ./tsconfig.json && tsc -p ./examples/tsconfig.json",
"prepack": "yarn build && yarn test",
"postpublish": "git push --follow-tags",
Expand Down Expand Up @@ -36,11 +36,9 @@
"devDependencies": {
"@types/node": "20",
"@types/progress": "^2.0.1",
"@types/rimraf": "2.0.2",
"@types/temp": "^0.9.4",
"node-test-github-reporter": "^1.2.0",
"prettier": "^3.3.1",
"rimraf": "^5.0.7",
"temp": "^0.9.4",
"tsx": "^4.10.5",
"typescript": "^5.4.5"
Expand Down
6 changes: 6 additions & 0 deletions script/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { rm } = require('fs/promises')
const { join } = require('path')

rm(join(__dirname, '..', 'build'), { recursive: true, force: true }).catch(
console.error
)
54 changes: 17 additions & 37 deletions script/test.mjs
Original file line number Diff line number Diff line change
@@ -1,43 +1,23 @@
import { spawn } from 'child_process'
import { glob } from 'glob'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So turns out I was depending on a sub-dependency of rimraf here so when I removed it glob disappeared as well but that lead to a nice cleanup in this script as well, utilizing the recursive option of readdir

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup indeed 🥹

import { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
import { join } from 'path'
import { readdir } from 'fs/promises'

if (process.argv.some(arg => ['-h', '--help'].includes(arg))) {
console.log(`Usage: ${process.argv0} [kind]`)
console.log(
' kind: The kind of tests to run (e.g. "fast", "slow", "external", "all")'
)
process.exit(0)
function reporter(r) {
return ['--test-reporter', r, '--test-reporter-destination', 'stdout']
}

;(async function (kind) {
const wildcard = kind && kind !== 'all' ? `${kind}/**` : '**'
const files = await glob(`test/${wildcard}/*-test.ts`)
const reporterDestinationArgs = ['--test-reporter-destination', 'stdout']
const specTestReporterArgs = [
'--test-reporter',
'spec',
...reporterDestinationArgs,
]
const files = await readdir('test', { recursive: true }).then(x =>
x.filter(f => f.endsWith('-test.ts')).map(f => join('test', f))
)

const testReporterArgs = process.env.GITHUB_ACTIONS
? [
'--test-reporter',
'node-test-github-reporter',
...reporterDestinationArgs,
...specTestReporterArgs,
]
: specTestReporterArgs
process.env.LOCAL_GIT_DIRECTORY = 'git'

spawn('node', ['--import', 'tsx', ...testReporterArgs, '--test', ...files], {
stdio: 'inherit',
env: {
...process.env,
LOCAL_GIT_DIRECTORY: resolve(
dirname(fileURLToPath(import.meta.url)),
'../git/'
),
},
}).on('exit', process.exit)
})(process.argv[2])
const args = [
...['--import', 'tsx'],
'--test',
...reporter('spec'),
...(process.env.GITHUB_ACTIONS ? reporter('node-test-github-reporter') : []),
...files,
]

spawn('node', args, { stdio: 'inherit' }).on('exit', process.exit)
Loading