|
1 | 1 | #!/usr/bin/env node |
2 | 2 |
|
3 | 3 | const {existsSync} = require(`fs`); |
4 | | -const {createRequire, createRequireFromPath} = require(`module`); |
| 4 | +const {createRequire, register} = require(`module`); |
5 | 5 | const {resolve} = require(`path`); |
| 6 | +const {pathToFileURL} = require(`url`); |
6 | 7 |
|
7 | 8 | const relPnpApiPath = "../../../../.pnp.cjs"; |
8 | 9 |
|
9 | 10 | const absPnpApiPath = resolve(__dirname, relPnpApiPath); |
10 | | -const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath); |
| 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); |
11 | 16 |
|
12 | 17 | if (existsSync(absPnpApiPath)) { |
13 | 18 | if (!process.versions.pnp) { |
14 | | - // Setup the environment to be able to require eslint/lib/api.js |
| 19 | + // Setup the environment to be able to require eslint |
15 | 20 | require(absPnpApiPath).setup(); |
| 21 | + if (isPnpLoaderEnabled && register) { |
| 22 | + register(pathToFileURL(absPnpLoaderPath)); |
| 23 | + } |
16 | 24 | } |
17 | 25 | } |
18 | 26 |
|
19 | | -// Defer to the real eslint/lib/api.js your application uses |
20 | | -module.exports = absRequire(`eslint/lib/api.js`); |
| 27 | +const wrapWithUserWrapper = existsSync(absUserWrapperPath) |
| 28 | + ? exports => absRequire(absUserWrapperPath)(exports) |
| 29 | + : exports => exports; |
| 30 | + |
| 31 | +// Defer to the real eslint your application uses |
| 32 | +module.exports = wrapWithUserWrapper(absRequire(`eslint`)); |
0 commit comments