|
1 | 1 | #!/usr/bin/env node
|
2 | 2 |
|
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)); |
24 | 24 | }
|
25 | 25 | }
|
26 | 26 |
|
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) |
29 | 30 | : exports => exports;
|
30 | 31 |
|
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