Skip to content

Commit 0b691b3

Browse files
committed
fix: node 22 imports
1 parent 23295ae commit 0b691b3

7 files changed

Lines changed: 53 additions & 34 deletions

File tree

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ npm install @donedeal0/codefather --save-dev
7272
- If a `.github/CODEOWNERS` file is present, it will be used to generate the config.
7373
- Accepts two optional flags:
7474
- `json`: generates a json config file instead of a `ts` one.
75-
- `overwrite`: overwrite an existing codefather config.
75+
- `overwrite`: overwrites an existing codefather config.
7676
- example: `npm run codefather-init json overwrite`
7777
- `codefather-github`: similar to `codefather`, but designed to run in a GitHub Action environment
7878

@@ -87,8 +87,8 @@ You can either add a script shortcut in your `package.json`:
8787
Or directly run the commands with `npx`:
8888

8989
```bash
90-
npx codefather
9190
npx codefather-init
91+
npx codefather
9292
```
9393

9494
## CONFIG
@@ -188,6 +188,19 @@ git config user.username # return DonCorleone
188188

189189
In a Github Action, `codefather` will use Github's API, so you don't have to worry about the git config.
190190

191+
## How to Write Rules
192+
193+
- Match all files in a folder (recursively): `src/myfolder/`
194+
- Match a specific file: `src/myfolder/file.ts`
195+
- Match files by extension in a folder (glob): `src/folder/*.css`
196+
- Match files by extension in a folder (regex): `/^src\/folder\/.*\.css$/`
197+
- Match any file in any subfolder: `src/**`
198+
- Match any file in the repository: `**`
199+
- Match dotfiles: `.env`
200+
- Use `*` for single-level matches, `**` for recursive matches
201+
202+
ℹ️ *More examples are available in the test files. Codefather's matching patterns follow classic file matcher rules, like GitHub CODEOWNERS.*
203+
191204
<hr/>
192205

193206
# GITHUB ACTION

cli/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env node
22
import { runCheck } from "./run-check/index.js";
3-
export * from "@shared/models";
43

54
runCheck();

package-lock.json

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

package.json

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@
77
"files": [
88
"dist"
99
],
10-
"main": "dist/index.cjs",
11-
"module": "dist/index.js",
10+
"type": "module",
1211
"types": "dist/index.d.ts",
13-
"publishConfig": {
14-
"access": "public"
15-
},
16-
"exports": {
17-
".": {
18-
"types": "./dist/index.d.ts",
19-
"import": "./dist/index.js",
20-
"require": "./dist/index.cjs"
21-
}
12+
"bin": {
13+
"codefather": "./dist/index.mjs",
14+
"codefather-github": "./dist/scripts/github.mjs",
15+
"codefather-init": "./dist/scripts/init.mjs"
2216
},
2317
"repository": {
2418
"type": "git",
@@ -30,9 +24,11 @@
3024
"funding": {
3125
"type": "github",
3226
"url": "https://github.com/sponsors/DoneDeal0"
27+
},
28+
"publishConfig": {
29+
"access": "public"
3330
},
3431
"readme": "./README.md",
35-
"type": "module",
3632
"declaration": true,
3733
"keywords": [
3834
"codeowners",
@@ -74,11 +70,6 @@
7470
"godfather",
7571
"authorization"
7672
],
77-
"bin": {
78-
"codefather": "./dist/index.js",
79-
"codefather-github": "./dist/scripts/github.js",
80-
"codefather-init": "./dist/scripts/init.js"
81-
},
8273
"scripts": {
8374
"build": "tsup",
8475
"codefather-github": "npm run build && node dist/scripts/github.js",
@@ -94,7 +85,7 @@
9485
"dependencies": {
9586
"@actions/github": "^6.0.1",
9687
"@octokit/rest": "^22.0.0",
97-
"tsx": "^4.20.3"
88+
"esbuild": "^0.25.8"
9889
},
9990
"devDependencies": {
10091
"@commitlint/cli": "^19.8.1",
@@ -114,7 +105,7 @@
114105
"swc-loader": "^0.2.6",
115106
"ts-node": "^10.9.2",
116107
"tsup": "^8.5.0",
117-
"typescript-eslint": "^8.38.0",
118-
"typescript": "^5.8.3"
108+
"typescript": "^5.8.3",
109+
"typescript-eslint": "^8.38.0"
119110
}
120111
}

shared/loader/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import fs from "fs";
22
import path from "path";
3-
import { pathToFileURL } from "url";
43
import { getRandomMessage } from "@shared/messages";
54
import { MessageType, type CodefatherConfig } from "@shared/models";
65
import { safeJSONParse } from "@shared/parser";
6+
import { transform } from "esbuild";
77

88
export async function loadConfig(): Promise<CodefatherConfig> {
99
try {
@@ -13,9 +13,14 @@ export async function loadConfig(): Promise<CodefatherConfig> {
1313
const jsonPath = path.resolve(root, "codefather.json");
1414

1515
if (fs.existsSync(tsPath)) {
16-
const { register } = await import("tsx/esm/api");
17-
register();
18-
const config = await import(pathToFileURL(tsPath).href);
16+
const tsCode = fs.readFileSync(tsPath, "utf-8");
17+
const { code } = await transform(tsCode, {
18+
loader: "ts",
19+
format: "esm",
20+
});
21+
22+
const dataUrl = `data:text/javascript;base64,${Buffer.from(code).toString("base64")}`;
23+
const config = await import(dataUrl);
1924
// a typescript file import may have several 'default' levels depending on the environment
2025
return config?.default?.default || config?.default || config;
2126
}

shared/parser/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export function safeJSONParse<T>(json: string): T {
44
// eslint-disable-next-line @typescript-eslint/no-unused-vars
55
} catch (_) {
66
throw new Error(
7-
"Your JSON file is invalid. You gotta respect the rules if you want my help."
7+
"Your codefather.json file is invalid. You gotta respect the rules if you want my help."
88
);
99
}
1010
}

tsup.config.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ export default defineConfig([
77
"scripts/init": "scripts/init/index.ts",
88
"scripts/github": "scripts/github/index.ts",
99
},
10-
format: ["cjs", "esm"],
1110
dts: {
12-
entry: ["cli/index.ts"],
11+
entry: ["shared/models/index.ts"],
1312
resolve: true,
1413
},
15-
splitting: true,
14+
format: ["esm"],
15+
splitting: false,
1616
clean: true,
1717
treeshake: true,
1818
shims: true,
1919
minify: true,
2020
platform: "node",
21-
name: "MAIN",
22-
external: ["tsx"],
21+
name: "CLI",
22+
external: ["esbuild"],
23+
outExtension: () => ({ js: ".mjs" }),
2324
},
2425
]);

0 commit comments

Comments
 (0)