borp 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/borp.js ADDED
@@ -0,0 +1,97 @@
1
+ #! /usr/bin/env node
2
+
3
+ import { parseArgs } from 'node:util'
4
+ import { tap, spec } from 'node:test/reporters'
5
+ import { run } from 'node:test'
6
+ import { glob } from 'glob'
7
+ import { findUp } from 'find-up'
8
+ import { createRequire } from 'node:module'
9
+ import { resolve, join, dirname } from 'node:path'
10
+ import { access, readFile } from 'node:fs/promises'
11
+ import { execa } from 'execa'
12
+
13
+ async function isFileAccessible (filename, directory) {
14
+ try {
15
+ const filePath = directory ? resolve(directory, filename) : filename
16
+ await access(filePath)
17
+ return true
18
+ } catch (err) {
19
+ return false
20
+ }
21
+ }
22
+
23
+ let reporter
24
+ if (process.stdout.isTTY) {
25
+ reporter = spec()
26
+ } else {
27
+ reporter = tap
28
+ }
29
+
30
+ const args = parseArgs({
31
+ args: process.argv.slice(2),
32
+ options: {
33
+ only: { type: 'boolean', short: 'o' },
34
+ watch: { type: 'boolean', short: 'w' },
35
+ pattern: { type: 'string', short: 'p' },
36
+ concurrency: { type: 'string', short: 'c' }
37
+ },
38
+ allowPositionals: true
39
+ })
40
+
41
+ if (args.values.concurrency) {
42
+ args.values.concurrency = parseInt(args.values.concurrency)
43
+ }
44
+
45
+ const tsconfigPath = await findUp('tsconfig.json')
46
+
47
+ let prefix = ''
48
+
49
+ if (tsconfigPath) {
50
+ try {
51
+ const _require = createRequire(process.cwd())
52
+ const typescriptPathCWD = _require.resolve('typescript')
53
+ const tscPath = join(typescriptPathCWD, '..', '..', 'bin', 'tsc')
54
+ if (tscPath) {
55
+ const isAccessible = await isFileAccessible(tscPath)
56
+ if (isAccessible) {
57
+ await execa(tscPath, { cwd: dirname(tsconfigPath), stdio: 'inherit' })
58
+ }
59
+ }
60
+ const tsconfig = JSON.parse(await readFile(tsconfigPath))
61
+ const outDir = tsconfig.compilerOptions.outDir
62
+ if (outDir) {
63
+ prefix = join(dirname(tsconfigPath), outDir)
64
+ }
65
+ } catch (err) {
66
+ console.log(err)
67
+ }
68
+ }
69
+
70
+ let files
71
+ if (args.positionals.length > 0) {
72
+ if (prefix) {
73
+ files = args.positionals.map((file) => join(prefix, file.replace(/ts$/, 'js')))
74
+ } else {
75
+ files = args.positionals
76
+ }
77
+ } else if (args.values.pattern) {
78
+ if (prefix) {
79
+ args.values.pattern = join(prefix, args.values.pattern)
80
+ }
81
+ files = await glob(args.values.pattern, { ignore: 'node_modules/**' })
82
+ } else {
83
+ if (prefix) {
84
+ files = await glob(join(prefix, 'test/**/*.test.{cjs,mjs,js}'), { ignore: 'node_modules/**' })
85
+ } else {
86
+ files = await glob('test/**/*.test.{cjs,mjs,js}', { ignore: 'node_modules/**' })
87
+ }
88
+ }
89
+
90
+ const config = {
91
+ ...args.values,
92
+ files
93
+ }
94
+
95
+ run(config)
96
+ .compose(reporter)
97
+ .pipe(process.stdout)
@@ -0,0 +1,7 @@
1
+ import { test } from 'node:test'
2
+ import { add } from '../src/add.js'
3
+ import { strictEqual } from 'node:assert'
4
+
5
+ test('add', () => {
6
+ strictEqual(add(1, 2), 3)
7
+ })
@@ -0,0 +1,23 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "sourceMap": true,
6
+ "target": "ES2022",
7
+ "module": "NodeNext",
8
+ "moduleResolution": "NodeNext",
9
+ "esModuleInterop": true,
10
+ "strict": true,
11
+ "resolveJsonModule": true,
12
+ "removeComments": true,
13
+ "newLine": "lf",
14
+ "noUnusedLocals": true,
15
+ "noFallthroughCasesInSwitch": true,
16
+ "isolatedModules": true,
17
+ "forceConsistentCasingInFileNames": true,
18
+ "skipLibCheck": true,
19
+ "lib": [
20
+ "ESNext"
21
+ ]
22
+ }
23
+ }
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "name": "borp",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "node:test wrapper with TypeScript support",
6
- "main": "nrts.js",
6
+ "main": "borp.js",
7
7
  "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1"
8
+ "test": "standard | snazzy"
9
9
  },
10
10
  "keywords": [],
11
11
  "author": "Matteo Collina <hello@matteocollina.com>",
12
12
  "license": "MIT",
13
13
  "devDependencies": {
14
14
  "@types/node": "^20.10.0",
15
- "fastify-tsconfig": "^2.0.0",
16
15
  "snazzy": "^9.0.0",
17
16
  "standard": "^17.1.0",
18
17
  "typescript": "^5.3.2"
19
18
  },
20
19
  "dependencies": {
21
- "glob": "^10.3.10",
22
- "tsimp": "^2.0.5"
20
+ "execa": "^8.0.1",
21
+ "find-up": "^7.0.0",
22
+ "glob": "^10.3.10"
23
23
  }
24
24
  }
package/nrts.js DELETED
@@ -1,53 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- import { parseArgs } from 'node:util'
4
- import { tap, spec } from 'node:test/reporters'
5
- import { run } from 'node:test'
6
- import path from 'node:path'
7
- import { glob } from 'glob'
8
- import { createRequire } from 'node:module'
9
-
10
- const tsimpImport = import.meta.resolve('tsimp/import')
11
-
12
- process.env.NODE_OPTIONS ||= '';
13
- process.env.NODE_OPTIONS += `--import=${tsimpImport}`;
14
-
15
- let reporter
16
- if (process.stdout.isTTY) {
17
- reporter = spec()
18
- } else {
19
- reporter = tap
20
- }
21
-
22
- const args = parseArgs({
23
- args: process.argv.slice(2),
24
- options: {
25
- only: { type: 'boolean', short: 'o' },
26
- watch: { type: 'boolean', short: 'w' },
27
- pattern: { type: 'string', short: 'p' },
28
- concurrency: { type: 'string', short: 'c' }
29
- },
30
- allowPositionals: true
31
- })
32
-
33
- if (args.values.concurrency) {
34
- args.values.concurrency = parseInt(args.concurrency)
35
- }
36
-
37
- let files
38
- if (args.positionals.length > 0) {
39
- files = args.positionals
40
- } else if (args.values.pattern) {
41
- files = await glob(args.values.pattern, { ignore: 'node_modules/**' })
42
- } else {
43
- files = await glob('test/**/*.test.[jt]s', { ignore: 'node_modules/**' })
44
- }
45
-
46
- const config = {
47
- ...args.values,
48
- files
49
- }
50
-
51
- run(config)
52
- .compose(reporter)
53
- .pipe(process.stdout);
package/tsconfig.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "fastify-tsconfig",
3
- "compilerOptions": {
4
- "outDir": "dist",
5
- "sourceMap": true
6
- },
7
- "include": [
8
- "src/**/*.ts"
9
- ]
10
- }