示例
minimatch 10.1.1: Handle comment prefixes, negation flags, basename matching, dotfiles, and globstar segments in minimatch
已验证示例 — npm minimatch 10.1.1: Handle comment prefixes, negation flags, basename matching, dotfiles, and globstar segments in minimatch. contract 在 node 22 …
sha256:3ae907b811ef9a96a655b6cdb6cbaf64b9acc9b816653b98a3ea8d76e57b190c
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 2
- 构建过它的签名密钥
- 2
声明的环境
node linux x64 node node npm
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-18 |
| node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-18 |
案例
HOW- 目标
- Handle comment prefixes, negation flags, basename matching, dotfiles, and globstar segments in minimatch
- 符号
-
- minimatch
- 环境
- node
- 创建时间
- 2026-08-18T00:17:47Z
契约
- assert minimatch treats leading hash characters as comments that match nothing by default, requiring nocomment or backslash escaping to match literal hashes
- assert negation patterns with leading exclamation marks invert matches by default, while flipNegate preserves positive matches and nonegate matches literal exclamation marks
- assert matchBase matches slash-less patterns against path basenames but is ignored when the pattern contains a slash
- assert dotfiles are excluded from wildcards and globstars by default unless explicitly matched or dot mode is enabled
- assert globstar matches zero or more directory levels when isolated between slashes but acts as a single wildcard when concatenated with other characters
文件
- NOTES.md
- csx.json
- package-lock.json
- package.json
- test/contract.mjs
源代码
# Minimatch Pattern Semantics and Matching Options
## Search Result and Prior Samples
A query for `minimatch@10.1.1` returned sample `sha256:585ab2a8ea43909cb7e47145ba967133e7da688e33baa7e055319539c3675105`, which verified brace expansion, partial matching, magic detection, filtering, and escape utilities. This sample investigates a distinct set of pattern parsing behaviors and options in `minimatch`: leading hash comments, leading exclamation negation handling, `matchBase` behavior, dotfile filtering, and globstar segment isolation.
## Pinned Release
- `minimatch`: `10.1.1`
## Observed Behavior and Traps
1. **Leading Hash (`#`) Comment Interpretation**:
- By default, patterns starting with `#` are treated as comment lines and match nothing.
- For example, `minimatch('#header', '#header')` returns `false`.
- To match a filename starting with `#`, either the `nocomment: true` option must be passed or the hash must be escaped as `\#header`.
- A naive expectation that `#header` matches `#header` directly fails silently with a false negative (returning `false` instead of `true`).
2. **Negation (`!`), `flipNegate`, and `nonegate`**:
- A leading `!` negates the match outcome by default (`minimatch('app.js', '!*.js')` is `false`, `minimatch('app.txt', '!*.js')` is `true`).
- Enabling `flipNegate: true` returns `true` when the underlying pattern matches (`minimatch('app.js', '!*.js', { flipNegate: true })` returns `true`).
- Enabling `nonegate: true` treats `!` as a literal character rather than a negation prefix (`minimatch('!app.js', '!*.js', { nonegate: true })` returns `true`).
3. **`matchBase` Slash-less Restriction**:
- `matchBase: true` matches a pattern without slashes against the basename of a nested path (`minimatch('src/components/button.js', '*.js', { matchBase: true })` returns `true`).
- When `matchBase` is `false`, `*.js` only matches root-level files.
- If the pattern contains any slash (e.g. `components/*.js`), `matchBase` has no effect and matching evaluates against the full path from root.
4. **Dotfile Exclusion**:
- By default (`dot: false`), wildcard `*` and globstar `**` do not match leading dots in filenames or directory segments (`minimatch('.env', '*')` and `minimatch('src/.config/app.json', 'src/**/app.json')` return `false`).
- Matching dotfiles requires either explicit dot patterns (`.*`) or passing `dot: true`.
5. **Globstar Zero-Segment Matching and Isolation**:
- An isolated globstar `**` between slashes matches zero or more directory segments (`minimatch('src/index.js', 'src/**/index.js')` returns `true`).
- When `**` is concatenated with characters in a segment (e.g., `src/**index.js`), it behaves as a single wildcard `*` rather than crossing directory boundaries.
{"case":{"believed":"patterns starting with a hash character match literal hash-prefixed filenames by default","caseId":"case:sha256:37691ac51126f1ba0907f6fd5f07c83a874d9b195f79e991c8888418ee6d8bb5","contract":["assert minimatch treats leading hash characters as comments that match nothing by default, requiring nocomment or backslash escaping to match literal hashes","assert negation patterns with leading exclamation marks invert matches by default, while flipNegate preserves positive matches and nonegate matches literal exclamation marks","assert matchBase matches slash-less patterns against path basenames but is ignored when the pattern contains a slash","assert dotfiles are excluded from wildcards and globstars by default unless explicitly matched or dot mode is enabled","assert globstar matches zero or more directory levels when isolated between slashes but acts as a single wildcard when concatenated with other characters"],"goal":"Handle comment prefixes, negation flags, basename matching, dotfiles, and globstar segments in minimatch","kind":"HOW","packages":["pkg:npm/minimatch@10.1.1"],"schemaVersion":1,"symbols":["minimatch"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"node","os":"linux","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/minimatch@10.1.1"],"schemaVersion":1,"symbols":["minimatch"],"verifierAdapter":"node-typescript@1"}
{
"name": "minimatch-contract",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "minimatch-contract",
"version": "1.0.0",
"dependencies": {
"minimatch": "10.1.1"
}
},
"node_modules/@isaacs/balanced-match": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/@isaacs/balanced-match/-/balanced-match-4.0.1.tgz",
"integrity": "sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ==",
"license": "MIT",
"engines": {
"node": "20 || >=22"
}
},
"node_modules/@isaacs/brace-expansion": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@isaacs/brace-expansion/-/brace-expansion-5.0.1.tgz",
"integrity": "sha512-WMz71T1JS624nWj2n2fnYAuPovhv7EUhk69R6i9dsVyzxt5eM3bjwvgk9L+APE1TRscGysAVMANkB0jh0LQZrQ==",
"license": "MIT",
"dependencies": {
"@isaacs/balanced-match": "^4.0.1"
},
"engines": {
"node": "20 || >=22"
}
},
"node_modules/minimatch": {
"version": "10.1.1",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.1.1.tgz",
"integrity": "sha512-enIvLvRAFZYXJzkCYG5RKmPfrFArdLv+R+lbQ53BmIMLIry74bjKzX6iHAm8WYamJkhSSEabrWN5D97XnKObjQ==",
"license": "BlueOak-1.0.0",
"dependencies": {
"@isaacs/brace-expansion": "^5.0.0"
},
"engines": {
"node": "20 || >=22"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
}
}
}
{
"name": "minimatch-contract",
"version": "1.0.0",
"type": "module",
"dependencies": {
"minimatch": "10.1.1"
}
}
import assert from 'node:assert/strict';
import { minimatch } from 'minimatch';
// 1. Comment handling: leading '#' is treated as a comment and matches nothing unless disabled or escaped
assert.strictEqual(minimatch('#header', '#header'), false);
assert.strictEqual(minimatch('#header', '#header', { nocomment: true }), true);
assert.strictEqual(minimatch('#header', '\\#header'), true);
// 2. Negation: leading '!' inverts match; flipNegate restores positive evaluation; nonegate treats '!' literally
assert.strictEqual(minimatch('app.js', '!*.js'), false);
assert.strictEqual(minimatch('app.txt', '!*.js'), true);
assert.strictEqual(minimatch('app.js', '!*.js', { flipNegate: true }), true);
assert.strictEqual(minimatch('!app.js', '!*.js', { nonegate: true }), true);
// 3. matchBase behavior: matches basenames only if pattern contains no slashes
assert.strictEqual(minimatch('src/components/button.js', '*.js'), false);
assert.strictEqual(minimatch('src/components/button.js', '*.js', { matchBase: true }), true);
assert.strictEqual(minimatch('src/components/button.js', 'components/*.js', { matchBase: true }), false);
// 4. Dotfile behavior: leading dot paths excluded by default unless explicitly matched or dot: true is passed
assert.strictEqual(minimatch('.env', '*'), false);
assert.strictEqual(minimatch('.env', '.*'), true);
assert.strictEqual(minimatch('src/.config/app.json', 'src/**/app.json'), false);
assert.strictEqual(minimatch('src/.config/app.json', 'src/**/app.json', { dot: true }), true);
// 5. Globstar behavior: '**' spans zero or more path segments only when isolated between slashes
assert.strictEqual(minimatch('src/index.js', 'src/**/index.js'), true);
assert.strictEqual(minimatch('src/nested/dir/index.js', 'src/**/index.js'), true);
assert.strictEqual(minimatch('src/a/b/index.js', 'src/**index.js'), false);