utilium 2.5.3 → 2.5.4

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.
Files changed (2) hide show
  1. package/package.json +5 -2
  2. package/scripts/lice.js +26 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utilium",
3
- "version": "2.5.3",
3
+ "version": "2.5.4",
4
4
  "description": "Typescript utilities",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -41,7 +41,7 @@
41
41
  "homepage": "https://github.com/james-pre/utilium#readme",
42
42
  "devDependencies": {
43
43
  "@eslint/js": "^9.12.0",
44
- "@types/node": "^20.12.7",
44
+ "@types/node": "^22.18.0",
45
45
  "eslint": "^9.12.0",
46
46
  "globals": "^15.10.0",
47
47
  "prettier": "^3.2.5",
@@ -55,5 +55,8 @@
55
55
  },
56
56
  "optionalDependencies": {
57
57
  "@xterm/xterm": "^5.5.0"
58
+ },
59
+ "engines": {
60
+ "node": ">=22.0.0"
58
61
  }
59
62
  }
package/scripts/lice.js CHANGED
@@ -2,12 +2,12 @@
2
2
  // SPDX-License-Identifier: LGPL-3.0-or-later
3
3
  // Copyright (c) 2025 James Prevett
4
4
 
5
- import { existsSync, readdirSync, readFileSync } from 'node:fs';
5
+ import { existsSync, globSync, readdirSync, readFileSync, statSync } from 'node:fs';
6
6
  import { readFile, writeFile } from 'node:fs/promises';
7
7
  import { dirname, join, matchesGlob, relative } from 'node:path';
8
8
  import { parseArgs, styleText } from 'node:util';
9
9
 
10
- const { positionals: dirs, values: opts } = parseArgs({
10
+ const { positionals: inputs, values: opts } = parseArgs({
11
11
  allowPositionals: true,
12
12
  options: {
13
13
  auto: { type: 'boolean', short: 'a', default: false },
@@ -21,7 +21,7 @@ const { positionals: dirs, values: opts } = parseArgs({
21
21
  });
22
22
 
23
23
  if (opts.help) {
24
- console.error(`Usage: lice [options] <dirs...>
24
+ console.error(`Usage: lice [options] <inputs...>
25
25
 
26
26
  Options:
27
27
  -f, --force Force overwrite of existing license headers
@@ -133,40 +133,50 @@ async function write_file(path, display) {
133
133
  return 'overwritten';
134
134
  }
135
135
 
136
- function check_dir(dir, display) {
136
+ function* check_dir(dir, display) {
137
137
  if (should_exclude(dir, display)) return 'skipped';
138
138
 
139
139
  const entries = readdirSync(dir, { withFileTypes: true });
140
140
 
141
- const results = [];
142
-
143
141
  for (const entry of entries) {
144
142
  if (entry.isDirectory()) {
145
- results.push(...check_dir(join(dir, entry.name), join(display, entry.name)));
143
+ yield* check_dir(join(dir, entry.name), join(display, entry.name));
146
144
  continue;
147
145
  }
148
146
 
149
147
  if (!entry.isFile()) continue;
150
148
 
151
149
  const op = opts.write ? write_file : check_file;
152
- results.push(op(join(dir, entry.name), join(display, entry.name)));
150
+ yield op(join(dir, entry.name), join(display, entry.name));
153
151
  }
154
-
155
- return results;
156
152
  }
157
153
 
158
- if (!dirs.length) {
159
- console.error(styleText('red', 'No directories specified'));
154
+ if (!inputs.length) {
155
+ console.error(styleText('red', 'No inputs specified'));
160
156
  process.exit(1);
161
157
  }
162
158
 
163
- if (opts.verbose) console.log('Checking:', dirs.join(', '));
159
+ const globbed = globSync(inputs);
160
+
161
+ if (opts.verbose) console.log('Checking:', globbed.join(', '));
164
162
 
165
163
  const promises = [];
166
164
 
167
- for (const dir of dirs) {
168
- const rel = relative(process.cwd(), dir);
169
- promises.push(...check_dir(dir, rel.startsWith('..') ? dir : rel));
165
+ for (const input of globbed) {
166
+ const rel = relative(process.cwd(), input);
167
+ if (should_exclude(input, rel)) {
168
+ promises.push(Promise.resolve('skipped'));
169
+ continue;
170
+ }
171
+
172
+ const stat = statSync(input);
173
+
174
+ if (stat.isDirectory()) {
175
+ for (const result of check_dir(input, rel)) promises.push(result);
176
+ } else {
177
+ const op = opts.write ? write_file : check_file;
178
+ promises.push(op(input, rel));
179
+ }
170
180
  }
171
181
 
172
182
  const styles = Object.assign(Object.create(null), {