Skip to content

Instantly share code, notes, and snippets.

@DanielHoffmann
Created January 13, 2022 17:29
Show Gist options
  • Select an option

  • Save DanielHoffmann/e9737f46cc7421ac5c227d583cd59f1f to your computer and use it in GitHub Desktop.

Select an option

Save DanielHoffmann/e9737f46cc7421ac5c227d583cd59f1f to your computer and use it in GitHub Desktop.

Revisions

  1. DanielHoffmann created this gist Jan 13, 2022.
    26 changes: 26 additions & 0 deletions eslint.resolver.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    // used so eslint-plugin-import can properly resolve dependencies using yarn2

    let pnp

    try {
    pnp = require(`./.pnp.cjs`)
    } catch (error) {
    // not a problem
    }

    const NOTFOUND = { found: false }

    module.exports = {
    interfaceVersion: 2,
    resolve: (source, file) => {
    if (!pnp) {
    throw new Error(`This resolver is meant to be used with pnp, but no pnp file was found`)
    }

    try {
    return { found: true, path: pnp.resolveRequest(source, file) }
    } catch (error) {
    return NOTFOUND
    }
    },
    }