GithubHelp home page GithubHelp logo

Comments (11)

sokra avatar sokra commented on May 5, 2024 1

we can resolve without log first and in case of an error we do an additional resolve with log.

from enhanced-resolve.

gdborton avatar gdborton commented on May 5, 2024

@TheLarkInn @sokra thoughts?

from enhanced-resolve.

TheLarkInn avatar TheLarkInn commented on May 5, 2024

Wow. This def seems like a huge win. Thanks for tagging us (GitHub notifications are the worst :( )

I'm all for this change. do you have a partial implementation so far?

PS: Congrats on submitting your first webpack/enhanced-resolve issue 🎉 🍾

from enhanced-resolve.

TheLarkInn avatar TheLarkInn commented on May 5, 2024

@sokra we could probably decouple the logger a bit better and just pass a debug flag to the resolver/factory.

TBH I only ever see this information actually show when I'm working on enhanced-resolve locally, and never during a webpack build even with --verbose. So maybe we could remove it entirely except for when local development like you mentioned.

from enhanced-resolve.

gdborton avatar gdborton commented on May 5, 2024

I don't have any implementation in mind as I wasn't sure how else the log might get used. Personally I'd rather see it removed completely (or maybe only available through an internal flag?).

I don't really like the idea of adding an option for disabling a feature no one uses. Especially considering the biggest hurdle to adopting webpack is the config.

I don't mind doing the work though if we can find a reasonable solution.

from enhanced-resolve.

TheLarkInn avatar TheLarkInn commented on May 5, 2024

I agree I think we should just have it as part of our test fixtures and local Dev if needed. It is very helpful for resolver plugin Dev also.

from enhanced-resolve.

niieani avatar niieani commented on May 5, 2024

If you run webpack programatically, you can use this workaround (prior to requiring webpack) to get the above mentioned speed bump:

// useful Webpack performance benefit until this is resolved: https://github.com/webpack/enhanced-resolve/issues/88
const Module = require('module')

function createCallbackMock(callback, options, message, messageOptional) {
  return function callbackMock() {
    // eslint-disable-next-line prefer-rest-params
    return callback.apply(this, arguments)
  }
}

// magic for mocking modules
const originalLoad = Module._load
function mockModuleLoader(...mocks) {
  Module._load = function load(request, parent, isMain) {
    for (const mock of mocks) {
      const mockedModuleExports = mock(request, parent, isMain)
      if (mockedModuleExports !== undefined) {
        return mockedModuleExports
      }
    }
    return originalLoad.apply(undefined, arguments)
  }
}

// let's mock the 'createInnerCallback' file:
const createCallbackRegExp = /\/enhanced-resolve\/lib\/createInnerCallback.js$/
mockModuleLoader(
  (request, parent, isMain) => {
    const filename = Module._resolveFilename(request, parent, isMain)
    return createCallbackRegExp.test(filename) ? createCallbackMock : undefined
  }
)

This effectively replaces the module.exports of the createInnerCallback.js file with a dummy method.

from enhanced-resolve.

TheLarkInn avatar TheLarkInn commented on May 5, 2024

Actually now that I think about this, we could leave as an empty fn and patch the logger when needed.

from enhanced-resolve.

ljharb avatar ljharb commented on May 5, 2024

I like that approach in general; it pushes all the perf cost to the error path, which doesn't matter if it's fast or not.

from enhanced-resolve.

mikesherov avatar mikesherov commented on May 5, 2024

OK, so it seems like we make a new function like doResolveWithLogging that'll call doResolve and on error, recall doResolve with the createInnerCallback version attached?

from enhanced-resolve.

TheLarkInn avatar TheLarkInn commented on May 5, 2024

That sounds right to me.

from enhanced-resolve.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.