Skip to content

Commit c43ff0a

Browse files
authored
Update eslint.js
1.Used consistent variable names (PNP_API_PATH, isPnpAvailable, etc.) for better understanding, 2.Optimized existsSync Calls 3.Refactored Conditionals for Clarity 4.Better Readability & Structure
1 parent 1022682 commit c43ff0a

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

.yarn/sdks/eslint/bin/eslint.js

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
#!/usr/bin/env node
22

3-
const {existsSync} = require(`fs`);
4-
const {createRequire, register} = require(`module`);
5-
const {resolve} = require(`path`);
6-
const {pathToFileURL} = require(`url`);
7-
8-
const relPnpApiPath = "../../../../.pnp.cjs";
9-
10-
const absPnpApiPath = resolve(__dirname, relPnpApiPath);
11-
const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`);
12-
const absRequire = createRequire(absPnpApiPath);
13-
14-
const absPnpLoaderPath = resolve(absPnpApiPath, `../.pnp.loader.mjs`);
15-
const isPnpLoaderEnabled = existsSync(absPnpLoaderPath);
16-
17-
if (existsSync(absPnpApiPath)) {
18-
if (!process.versions.pnp) {
19-
// Setup the environment to be able to require eslint/bin/eslint.js
20-
require(absPnpApiPath).setup();
21-
if (isPnpLoaderEnabled && register) {
22-
register(pathToFileURL(absPnpLoaderPath));
23-
}
3+
const { existsSync } = require("fs");
4+
const { createRequire, register } = require("module");
5+
const { resolve } = require("path");
6+
const { pathToFileURL } = require("url");
7+
8+
// Define paths
9+
const PNP_API_PATH = resolve(__dirname, "../../../../.pnp.cjs");
10+
const PNP_LOADER_PATH = resolve(PNP_API_PATH, "../.pnp.loader.mjs");
11+
const USER_WRAPPER_PATH = resolve(__dirname, "./sdk.user.cjs");
12+
13+
const requireFromPnp = createRequire(PNP_API_PATH);
14+
const isPnpAvailable = existsSync(PNP_API_PATH);
15+
const isPnpLoaderEnabled = existsSync(PNP_LOADER_PATH);
16+
const isUserWrapperAvailable = existsSync(USER_WRAPPER_PATH);
17+
18+
//setup PnP environment If required
19+
if (isPnpAvailable && !process.versions.pnp) {
20+
require(PNP_API_PATH).setup();
21+
22+
if (isPnpLoaderEnabled && register) {
23+
register(pathToFileURL(PNP_LOADER_PATH));
2424
}
2525
}
2626

27-
const wrapWithUserWrapper = existsSync(absUserWrapperPath)
28-
? exports => absRequire(absUserWrapperPath)(exports)
27+
// apply user wrapper if It exists
28+
const wrapWithUserWrapper = isUserWrapperAvailable
29+
? exports => requireFromPnp(USER_WRAPPER_PATH)(exports)
2930
: exports => exports;
3031

31-
// Defer to the real eslint/bin/eslint.js your application uses
32-
module.exports = wrapWithUserWrapper(absRequire(`eslint/bin/eslint.js`));
32+
// export ESLint from the appropriate Location
33+
module.exports = wrapWithUserWrapper(requireFromPnp("eslint/bin/eslint.js"));
34+

0 commit comments

Comments
 (0)