Skip to content

Commit 712d31f

Browse files
chore: drop node 20, refactor. (#19)
1 parent d05f907 commit 712d31f

8 files changed

Lines changed: 33 additions & 19 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ By default `@knighted/module` transforms the one-to-one [differences between ES
2222

2323
## Requirements
2424

25-
- Node >= 20.11.0
25+
- Node >= 22.21.1
2626

2727
## Install
2828

docs/cjs-to-esm.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Scope
44

55
- Rewrites CommonJS modules to ESM when `target: 'module'` with `transformSyntax` enabled.
6-
- Assumes Node 20.11+ runtime with native ESM.
6+
- Assumes Node 22.21+ runtime with native ESM.
77
- Skips lowering when `module` or `exports` are shadowed at module scope to avoid mis-compilation.
88
- Deprecated CJS features (`require.extensions`, `module.parent`, legacy folder-as-module resolution) are left as-is.
99

docs/helpers-vs-utils.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Helpers vs utils
2+
3+
## Intent
4+
5+
- `helpers/`: small, pure AST-shape predicates/utilities. They inspect nodes but do not mutate `MagicString`, maintain state, or depend on transformation options. Safe to import anywhere (including formatters) without side effects.
6+
- `utils/`: transformation plumbing and shared state. They may build/consume metadata, track identifiers/exports, or mutate `MagicString`/strings. Formatters and the main `format` pass call into these.
7+
8+
## Conventions
9+
10+
- `helpers/` should not import from `utils/` to keep them dependency-light. `utils/` may import `helpers/`.
11+
- Keep `helpers/` functions small and specific (e.g., identifier/name guards, skip checks). If it holds cross-pass state or writes code, it belongs in `utils/`.
12+
- When adding a new helper, check if it needs options or shared tables; if so, place it in `utils/` instead.
13+
14+
## Current layout (Dec 2025)
15+
16+
- `helpers/`: identifier/name helpers.
17+
- `utils/`: exports collection, identifier tracking, language/specifier helpers, misc transformation utilities.
18+
19+
## Maintenance tips
20+
21+
- Periodically run a quick grep to remove unused helpers.
22+
- If a helper starts mutating code or carrying state, move it into `utils/`.

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@knighted/module",
3-
"version": "1.0.0-beta.3",
3+
"version": "1.0.0-beta.4",
44
"description": "Transforms differences between ES modules and CommonJS.",
55
"type": "module",
66
"main": "dist/module.js",
@@ -27,7 +27,7 @@
2727
"#formatters/*.js": "./src/formatters/*.js"
2828
},
2929
"engines": {
30-
"node": ">=20.11.0"
30+
"node": ">=22.21.1"
3131
},
3232
"engineStrict": true,
3333
"scripts": {

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import type { Node } from 'oxc-parser'
55
import type { Specifier } from '@knighted/specifier'
66

77
import type { IdentMeta, SpannedNode, Scope, CjsExport } from './types.js'
8-
import { scopes as scopeNodes } from './helpers/scope.js'
98
import { identifier } from './helpers/identifier.js'
9+
import { scopeNodes } from './utils/scopeNodes.js'
1010

1111
type UpdateSrcLang = Parameters<Specifier['updateSrc']>[1]
1212
const getLangFromExt = (filename: string): UpdateSrcLang => {

src/utils/identifiers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import type { Node } from 'oxc-parser'
22

33
import type { IdentMeta, SpannedNode, Scope } from '../types.js'
44
import { ancestorWalk } from '#walk'
5-
import { scopes as scopeNodes } from '#helpers/scope.js'
65
import { identifier } from '#helpers/identifier.js'
6+
import { scopeNodes } from './scopeNodes.js'
77

88
const collectScopeIdentifiers = (node: Node, scopes: Scope[]) => {
99
const { type } = node
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import type { Node } from 'oxc-parser'
2-
3-
const scopes = [
1+
const scopeNodes = [
42
'BlockStatement',
53
'FunctionDeclaration',
64
'FunctionExpression',
@@ -11,10 +9,4 @@ const scopes = [
119
'StaticBlock',
1210
]
1311

14-
const scope = {
15-
isScope(node: Node) {
16-
return scopes.includes(node.type)
17-
},
18-
}
19-
20-
export { scopes, scope }
12+
export { scopeNodes }

0 commit comments

Comments
 (0)