Skip to content

Commit c31bd59

Browse files
authored
Merge pull request #2700 from srod/develop
feat: migrate to Vitest 4 Test Projects and add CodeRabbit auto-reviews
2 parents 8df5a01 + 9fd5573 commit c31bd59

56 files changed

Lines changed: 231 additions & 59 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.coderabbit.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: "en-US"
2+
reviews:
3+
profile: "chill"
4+
auto_review:
5+
enabled: true
6+
auto_incremental_review: true
7+
base_branches:
8+
- develop

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ jobs:
3838
uses: codecov/codecov-action@v5
3939
with:
4040
token: ${{ secrets.CODECOV_TOKEN }}
41-
directory: ./packages
41+
files: ./coverage/coverage-final.json
4242
fail_ci_if_error: false
4343
verbose: true

CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ This branch (`main`) uses **Bun** as the package manager and runtime.
1515
- **Build**: `bun run build`
1616
- **Lint**: `bun run lint` | **Format**: `bun run format`
1717
- **Test all**: `bun run test`
18-
- **Test single package**: `bun test packages/<name>` (e.g., `bun test packages/core`)
19-
- **Test single file**: `bun test packages/core/__tests__/core.test.ts`
18+
- **Test single package**: `bun run test packages/<name>` (e.g., `bun run test packages/core`)
19+
- **Test single file**: `bun run test packages/core/__tests__/core.test.ts`
2020
- **Typecheck**: `bun run typecheck`
2121
- **CI (full)**: `bun run ci`
2222

SECURITY.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
| Version | Supported |
6+
| ------- | ------------------ |
7+
| 9.x | :white_check_mark: |
8+
| < 9.0 | :x: |
9+
10+
## Reporting a Vulnerability
11+
12+
We take the security of node-minify seriously. If you believe you have found a security vulnerability, please report it to us through responsible disclosure.
13+
14+
### How to Report
15+
16+
Do **not** open a public GitHub issue for security vulnerabilities. Instead, please email: **rodolphe@2clics.net**
17+
18+
### What to Include
19+
20+
When reporting a vulnerability, please include:
21+
- A clear description of the issue
22+
- Steps to reproduce the issue
23+
- Any relevant code samples or payloads
24+
- Your assessment of the impact
25+
26+
### Response Timeline
27+
28+
- We will acknowledge receipt of your report within **72 hours**
29+
- You can expect an initial assessment within **7 days**
30+
- We will provide updates on the status of your report at least every **7 days**
31+
- Once the vulnerability is confirmed, we will release a security patch as quickly as possible
32+
33+
### Scope
34+
35+
This policy applies to the node-minify monorepo and its packages:
36+
- @node-minify/core
37+
- All compressor packages (@node-minify/*)
38+
- The CLI tool
39+
40+
Note: This does not include vulnerabilities in third-party compressors (esbuild, terser, lightningcss, etc.) - those should be reported to their respective maintainers.
41+
42+
### Recognition
43+
44+
We appreciate responsible disclosure and will credit researchers in any security advisory, unless they prefer to remain anonymous.

bun.lock

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

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@
2323
"build:deps": "bun run --filter '@node-minify/utils' build && bun run --filter '@node-minify/run' build",
2424
"build:docs": "bun run --filter '@node-minify/docs' build",
2525
"check-exports": "bun run --filter '*' check-exports",
26-
"ci": "bun run build && bun run check-exports && bun run lint && bun run typecheck && bun run test:ci",
26+
"ci": "bun run build && bun run check-exports && bun run lint && bun run typecheck && bun run test:coverage",
2727
"clean": "bun run clean:build",
2828
"clean:build": "bunx rimraf packages/*/dist docs/dist docs/.astro",
2929
"clean:test": "bunx rimraf tests/tmp/*.{js,js.map,css,html,json}",
3030
"dev": "bun run --filter '*' dev",
3131
"lint": "bun run --filter '*' lint",
3232
"local-release": "bun run changeset:version && bun run changeset:release",
33-
"test": "bun run --filter '*' test",
34-
"test:watch": "bun run --filter '*' test:watch",
35-
"test:ci": "bun run --filter '*' test:ci",
33+
"test": "vitest run",
34+
"test:watch": "vitest",
3635
"test:coverage": "vitest run --coverage",
3736
"changeset": "changeset",
3837
"changeset:version": "changeset version && bun install --no-frozen-lockfile",

packages/babel-minify/__tests__/babel-minify.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,19 @@ describe("Package: babel-minify", async () => {
4141
).rejects.toThrow("Babel minification failed: empty result");
4242
spy.mockRestore();
4343
});
44+
45+
test("should pass through non-string presets unchanged", async () => {
46+
const minifyPreset = (await import("babel-preset-minify")).default;
47+
const result = await babelMinify({
48+
content: "var x = 1;",
49+
settings: {
50+
options: {
51+
// Pass the preset module directly instead of a string
52+
presets: [minifyPreset],
53+
},
54+
},
55+
} as any);
56+
expect(result.code).toBeDefined();
57+
});
4458
});
4559
});

packages/babel-minify/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@
4747
"lint": "biome lint .",
4848
"prepublishOnly": "bun run build",
4949
"test": "vitest run",
50-
"test:ci": "vitest run --coverage",
50+
"test:coverage": "vitest run --coverage",
5151
"test:watch": "vitest",
5252
"typecheck": "tsc --noEmit",
5353
"dev": "tsdown src/index.ts --watch"
5454
},
5555
"dependencies": {
5656
"@node-minify/utils": "workspace:*",
5757
"babel-core": "6.26.3",
58+
"babel-preset-env": "1.7.0",
5859
"babel-preset-minify": "0.5.2"
5960
},
6061
"devDependencies": {
6162
"@node-minify/types": "workspace:*",
62-
"@types/babel-core": "^6.25.10",
63-
"babel-preset-env": "1.7.0"
63+
"@types/babel-core": "^6.25.10"
6464
}
65-
}
65+
}

packages/babel-minify/src/index.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,22 @@
77
import type { CompressorResult, MinifierOptions } from "@node-minify/types";
88
import { readFile, warnDeprecation } from "@node-minify/utils";
99
import { transform } from "babel-core";
10+
import env from "babel-preset-env";
1011
import minify from "babel-preset-minify";
1112

13+
type BabelPreset = typeof minify | typeof env;
14+
1215
type BabelOptions = {
13-
presets: (string | typeof minify)[];
16+
presets: (string | BabelPreset)[];
17+
};
18+
19+
/**
20+
* Known presets that we can resolve directly to avoid Babel 6's runtime module resolution,
21+
* which can fail in monorepos or when the working directory differs from the package location.
22+
*/
23+
const knownPresets: Record<string, BabelPreset> = {
24+
env,
25+
minify,
1426
};
1527

1628
/**
@@ -43,7 +55,16 @@ export async function babelMinify({
4355
babelOptions.presets = presets.concat(babelrcPresets);
4456
}
4557

46-
if (!babelOptions.presets.includes("minify")) {
58+
// Resolve known preset strings to their imported modules to avoid
59+
// Babel 6's runtime resolution which fails in monorepos/different cwd
60+
babelOptions.presets = babelOptions.presets.map((preset) =>
61+
typeof preset === "string" && preset in knownPresets
62+
? knownPresets[preset]
63+
: preset
64+
);
65+
66+
// Ensure minify preset is always included
67+
if (!babelOptions.presets.includes(minify)) {
4768
babelOptions.presets = babelOptions.presets.concat([minify]);
4869
}
4970

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
declare module "babel-preset-env";
12
declare module "babel-preset-minify";

0 commit comments

Comments
 (0)