Skip to content

Commit 10ba0ea

Browse files
committed
feat: dep & CI updates & minor modernisation
1 parent f69713e commit 10ba0ea

7 files changed

Lines changed: 154 additions & 78 deletions

File tree

.github/dependabot.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ updates:
77
commit-message:
88
prefix: 'chore'
99
include: 'scope'
10+
cooldown:
11+
default-days: 5
1012
- package-ecosystem: 'npm'
1113
directory: '/'
1214
schedule:
1315
interval: 'daily'
1416
commit-message:
1517
prefix: 'chore'
1618
include: 'scope'
19+
cooldown:
20+
default-days: 5
Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,56 @@
11
name: Test & Maybe Release
22
on: [push, pull_request]
3+
34
jobs:
45
test:
56
strategy:
67
fail-fast: false
78
matrix:
8-
node: [16.x, 18.x, lts/*, current]
9+
node: [lts/*, current]
910
os: [macos-latest, ubuntu-latest, windows-latest]
1011
runs-on: ${{ matrix.os }}
1112
steps:
1213
- name: Checkout Repository
13-
uses: actions/checkout@v4
14+
uses: actions/checkout@v6
1415
- name: Use Node.js ${{ matrix.node }}
15-
uses: actions/setup-node@v3.8.1
16+
uses: actions/setup-node@v6
1617
with:
1718
node-version: ${{ matrix.node }}
1819
- name: Install Dependencies
20+
run: npm install --no-progress
21+
- name: Check build is up to date
1922
run: |
20-
npm install --no-progress
23+
npm run build
24+
git diff --exit-code || (echo "::error::Build artifacts not committed. Run 'npm run build' and commit the changes." && exit 1)
2125
- name: Run tests
22-
run: |
23-
npm config set script-shell bash
24-
npm run test:ci
26+
run: npm test
27+
2528
release:
2629
name: Release
2730
needs: test
2831
runs-on: ubuntu-latest
2932
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
33+
permissions:
34+
contents: write
35+
issues: write
36+
pull-requests: write
37+
id-token: write
3038
steps:
3139
- name: Checkout
32-
uses: actions/checkout@v4
40+
uses: actions/checkout@v6
3341
with:
3442
fetch-depth: 0
3543
- name: Setup Node.js
36-
uses: actions/setup-node@v3.8.1
44+
uses: actions/setup-node@v6
3745
with:
3846
node-version: lts/*
47+
registry-url: 'https://registry.npmjs.org'
3948
- name: Install dependencies
40-
run: |
41-
npm install --no-progress --no-package-lock --no-save
49+
run: npm install --no-progress --no-package-lock --no-save
4250
- name: Build
43-
run: |
44-
npm run build
45-
- name: Install plugins
46-
run: |
47-
npm install \
48-
@semantic-release/commit-analyzer \
49-
conventional-changelog-conventionalcommits \
50-
@semantic-release/release-notes-generator \
51-
@semantic-release/npm \
52-
@semantic-release/github \
53-
@semantic-release/git \
54-
@semantic-release/changelog \
55-
--no-progress --no-package-lock --no-save
51+
run: npm run build
5652
- name: Release
5753
env:
5854
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
55+
NPM_CONFIG_PROVENANCE: true
6056
run: npx semantic-release
61-

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
package-lock.json

README.md

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# readfiletree
22

3-
Deserialise an file/directory tree into an object. Available in npm as *readfiletree*
3+
[![NPM](https://nodei.co/npm/readfiletree.svg?style=flat&data=n,v&color=blue)](https://nodei.co/npm/readfiletree/)
44

5-
[![NPM](https://nodei.co/npm/readfiletree.svg)](https://nodei.co/npm/readfiletree/)
5+
Deserialize a file/directory tree into an object. Particularly useful for testing where you need to do a `deepStrictEqual()` on a simple tree of files. **See [mkfiletree](https://github.com/rvagg/node-mkfiletree) for file tree serialization.**
66

7-
Particularly useful for testing where you need to do a `deepStrictEqual()` on a simple tree of files. **See [mkfiletree](https://github.com/rvagg/mkfiletree) for file tree serialisation.**
7+
## Requirements
88

9-
### async readfiletree(directory)
9+
Node.js >= 20
10+
11+
## API
12+
13+
### await readfiletree(directory)
1014

1115
Read the directory and the files it contains, recursively, and return an object representing the directory structure with nodes containing the utf8 string contents of each file.
1216

@@ -36,19 +40,19 @@ The directory structure created above looks like the following:
3640

3741
```
3842
$ find /tmp/testfiles11240-23530-r7rs3 -type f -exec sh -c "echo '\n{}: ' && cat '{}'" \;
39-
/tmp/testfiles11240-23530-r7rs3/afile.txt:
40-
file contents
41-
/tmp/testfiles11240-23530-r7rs3/adir/deeper/depths.txt:
42-
whoa...
43-
/tmp/testfiles11240-23530-r7rs3/adir/two.txt:
44-
a
45-
b
46-
c
47-
48-
/tmp/testfiles11240-23530-r7rs3/adir/one.txt:
49-
1
50-
2
51-
3
43+
/tmp/testfiles11240-23530-r7rs3/afile.txt:
44+
file contents
45+
/tmp/testfiles11240-23530-r7rs3/adir/deeper/depths.txt:
46+
whoa...
47+
/tmp/testfiles11240-23530-r7rs3/adir/two.txt:
48+
a
49+
b
50+
c
51+
52+
/tmp/testfiles11240-23530-r7rs3/adir/one.txt:
53+
1
54+
2
55+
3
5256
5357
```
5458

@@ -67,24 +71,6 @@ And the output of the program should be the same as the input to *mkfiletree*:
6771
}
6872
```
6973

70-
*Copyright (c) 2012 [Rod Vagg](https://github.com/rvagg)
71-
72-
Made available under the MIT licence:
73-
74-
Permission is hereby granted, free of charge, to any person obtaining a copy
75-
of this software and associated documentation files (the "Software"), to deal
76-
in the Software without restriction, including without limitation the rights
77-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
78-
copies of the Software, and to permit persons to whom the Software is furnished
79-
to do so, subject to the following conditions:
80-
81-
The above copyright notice and this permission notice shall be included in all
82-
copies or substantial portions of the Software.
74+
## License
8375

84-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
85-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
86-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
87-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
88-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
89-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
90-
SOFTWARE.
76+
**readfiletree** is Copyright (c) 2012 Rod Vagg [@rvagg](https://github.com/rvagg) and licenced under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.

package.json

Lines changed: 98 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,112 @@
1212
"version": "2.0.0",
1313
"main": "readfiletree.js",
1414
"type": "module",
15+
"exports": "./readfiletree.js",
16+
"engines": {
17+
"node": ">=20"
18+
},
1519
"license": "MIT",
1620
"scripts": {
1721
"lint": "standard",
18-
"test": "npm run lint && node tests.js",
19-
"test:ci": "npm run lint && node tests.js",
20-
"build": "true"
22+
"build": "true",
23+
"test:unit": "node --test tests.js",
24+
"test": "npm run lint && npm run test:unit"
2125
},
2226
"devDependencies": {
27+
"@semantic-release/changelog": "^6.0.3",
28+
"@semantic-release/commit-analyzer": "^13.0.1",
29+
"@semantic-release/git": "^10.0.1",
30+
"@semantic-release/github": "^12.0.2",
31+
"@semantic-release/npm": "^13.1.3",
32+
"@semantic-release/release-notes-generator": "^14.1.0",
33+
"conventional-changelog-conventionalcommits": "^9.1.0",
2334
"mkfiletree": "^3.0.0",
24-
"standard": "^17.1.0"
35+
"semantic-release": "^25.0.2",
36+
"standard": "^17.1.2"
2537
},
2638
"repository": {
2739
"type": "git",
28-
"url": "https://github.com/rvagg/node-readfiletree.git"
40+
"url": "https://github.com/rvagg/readfiletree.git"
41+
},
42+
"release": {
43+
"branches": [
44+
"master"
45+
],
46+
"plugins": [
47+
[
48+
"@semantic-release/commit-analyzer",
49+
{
50+
"preset": "conventionalcommits",
51+
"releaseRules": [
52+
{
53+
"breaking": true,
54+
"release": "major"
55+
},
56+
{
57+
"revert": true,
58+
"release": "patch"
59+
},
60+
{
61+
"type": "feat",
62+
"release": "minor"
63+
},
64+
{
65+
"type": "fix",
66+
"release": "patch"
67+
},
68+
{
69+
"type": "chore",
70+
"release": "patch"
71+
},
72+
{
73+
"type": "docs",
74+
"release": "patch"
75+
},
76+
{
77+
"type": "test",
78+
"release": "patch"
79+
},
80+
{
81+
"scope": "no-release",
82+
"release": false
83+
}
84+
]
85+
}
86+
],
87+
[
88+
"@semantic-release/release-notes-generator",
89+
{
90+
"preset": "conventionalcommits",
91+
"presetConfig": {
92+
"types": [
93+
{
94+
"type": "feat",
95+
"section": "Features"
96+
},
97+
{
98+
"type": "fix",
99+
"section": "Bug Fixes"
100+
},
101+
{
102+
"type": "chore",
103+
"section": "Trivial Changes"
104+
},
105+
{
106+
"type": "docs",
107+
"section": "Trivial Changes"
108+
},
109+
{
110+
"type": "test",
111+
"section": "Tests"
112+
}
113+
]
114+
}
115+
}
116+
],
117+
"@semantic-release/changelog",
118+
"@semantic-release/npm",
119+
"@semantic-release/github",
120+
"@semantic-release/git"
121+
]
29122
}
30123
}

readfiletree.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* Copyright (c) 2012 Rod Vagg <@rvagg> */
2-
import fs from 'fs/promises'
3-
import path from 'path'
2+
import fs from 'node:fs/promises'
3+
import path from 'node:path'
44

55
export async function readfiletree (dir, obj) {
66
if (obj == null) {

tests.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import assert from 'assert'
1+
import { test } from 'node:test'
2+
import assert from 'node:assert'
23
import * as mkfiletree from 'mkfiletree'
34
import { readfiletree } from './readfiletree.js'
45

5-
function mkfixture () { // make a new copy each time, ensure no edits at any depth
6+
function mkfixture () {
67
return {
78
'foo.txt': 'FOO!',
89
bar: {
@@ -16,14 +17,10 @@ function mkfixture () { // make a new copy each time, ensure no edits at any dep
1617
}
1718
}
1819

19-
async function test () {
20+
test('readfiletree reads a file tree into an object', async () => {
2021
const dir = await mkfiletree.makeTemp('readfiletree_test', mkfixture())
2122
assert(dir)
2223
const obj = await readfiletree(dir)
2324
assert.deepStrictEqual(obj, mkfixture())
24-
}
25-
26-
test().catch((err) => {
27-
console.error(err)
28-
process.exit(1)
25+
await mkfiletree.cleanUp()
2926
})

0 commit comments

Comments
 (0)