Skip to content

Commit 4ecd365

Browse files
fix(ci): patch vsce minimatch v10 compatibility
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9b74027 commit 4ecd365

File tree

1 file changed

+55
-16
lines changed

1 file changed

+55
-16
lines changed

scripts/patch-eslint-minimatch.mjs

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,63 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
33

4-
const filePath = path.resolve('node_modules/@eslint/eslintrc/lib/config-array/override-tester.js');
5-
const expected = 'import minimatch from "minimatch";';
6-
const replacement = 'import { minimatch } from "minimatch";';
4+
const applyPatch = ({ filePath, expected, replacement, label }) => {
5+
if (!fs.existsSync(filePath)) {
6+
throw new Error(`Expected file for ${label} at ${filePath}`);
7+
}
78

8-
if (!fs.existsSync(filePath)) {
9-
throw new Error(`Expected ESLint override tester at ${filePath}`);
10-
}
9+
const source = fs.readFileSync(filePath, 'utf8');
10+
if (source.includes(replacement)) {
11+
console.log(`${label} patch already applied`);
12+
return;
13+
}
1114

12-
const source = fs.readFileSync(filePath, 'utf8');
15+
if (!source.includes(expected)) {
16+
throw new Error(`Expected pattern not found for ${label}`);
17+
}
1318

14-
if (source.includes(replacement)) {
15-
console.log('eslint minimatch patch already applied');
16-
process.exit(0);
17-
}
19+
fs.writeFileSync(filePath, source.replace(expected, replacement));
20+
console.log(`patched ${label}`);
21+
};
1822

19-
if (!source.includes(expected)) {
20-
throw new Error('Expected ESLint minimatch import pattern not found');
21-
}
23+
applyPatch({
24+
filePath: path.resolve('node_modules/@eslint/eslintrc/lib/config-array/override-tester.js'),
25+
expected: 'import minimatch from "minimatch";',
26+
replacement: 'import { minimatch } from "minimatch";',
27+
label: '@eslint/eslintrc minimatch import'
28+
});
2229

23-
fs.writeFileSync(filePath, source.replace(expected, replacement));
24-
console.log('patched @eslint/eslintrc minimatch import for minimatch v10');
30+
{
31+
const filePath = path.resolve('node_modules/@vscode/vsce/out/package.js');
32+
if (!fs.existsSync(filePath)) {
33+
throw new Error(`Expected file for @vscode/vsce minimatch runtime shim at ${filePath}`);
34+
}
35+
36+
const source = fs.readFileSync(filePath, 'utf8');
37+
const importLine = 'const minimatch_1 = __importDefault(require("minimatch"));';
38+
const oldShim =
39+
'if (typeof minimatch_1.default !== "function" && typeof minimatch_1.default?.minimatch === "function") {\n' +
40+
' minimatch_1.default = minimatch_1.default.minimatch;\n' +
41+
'}';
42+
const newShim =
43+
'if (typeof minimatch_1.default !== "function") {\n' +
44+
' const minimatchFallback = typeof minimatch_1.minimatch === "function"\n' +
45+
' ? minimatch_1.minimatch\n' +
46+
' : (typeof minimatch_1.default?.minimatch === "function" ? minimatch_1.default.minimatch : undefined);\n' +
47+
' if (minimatchFallback) {\n' +
48+
' minimatch_1.default = minimatchFallback;\n' +
49+
' }\n' +
50+
'}';
51+
52+
if (source.includes(newShim)) {
53+
console.log('@vscode/vsce minimatch runtime shim patch already applied');
54+
} else if (source.includes(oldShim)) {
55+
fs.writeFileSync(filePath, source.replace(oldShim, newShim));
56+
console.log('patched @vscode/vsce minimatch runtime shim');
57+
} else if (source.includes(importLine)) {
58+
fs.writeFileSync(filePath, source.replace(importLine, `${importLine}\n${newShim}`));
59+
console.log('patched @vscode/vsce minimatch runtime shim');
60+
} else {
61+
throw new Error('Expected pattern not found for @vscode/vsce minimatch runtime shim');
62+
}
63+
}

0 commit comments

Comments
 (0)