-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eslint-cjs-to-esm.js
57 lines (54 loc) · 1.63 KB
/
eslint-cjs-to-esm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env node
import { execa } from "execa";
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
const isWindows = /^win/.test(process.platform);
const eslintBinBasePath = ".bin/eslint";
const eslintBin = require.resolve(isWindows ? `${eslintBinBasePath}.cmd` : eslintBinBasePath);
import url from "node:url";
import path from "node:path";
const __filename__ = url.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename__);
const builtinConfig = path.join(__dirname, ".eslintrc.cjs");
try {
const args = process.argv.slice(2).map(arg => {
// if arg is path like string, convert it absolute path
if (arg.startsWith(".")) {
return path.resolve(arg);
} else {
return arg;
}
});
if (process.env.DEBUG === "eslint-cjs-to-esm") {
console.debug({ args, eslintBin, builtinConfig });
}
const command = isWindows ? eslintBin : "node";
const platformArguments = isWindows ? [] : [eslintBin];
const { stdout, stderr } = await execa(command, [
...platformArguments,
"--config",
builtinConfig,
"--no-eslintrc",
"--no-inline-config",
...args], {
env: {
FORCE_COLOR: "true"
},
localDir: __dirname,
cwd: __dirname
});
if (stdout) {
console.log(stdout);
process.exitCode = 0;
} else {
console.error(stderr);
process.exitCode = 1;
}
} catch (e) {
if (e.stdout) {
console.log(e.stdout);
} else if (e.stderr) {
console.error(e.stderr);
}
process.exit(1);
}