Coder Social home page Coder Social logo

Comments (4)

alexander-akait avatar alexander-akait commented on May 21, 2024

Can you create small github repo and provide structure, I need to undestand strcuture and how you are importing this in code, thank you

from enhanced-resolve.

Galcarmi avatar Galcarmi commented on May 21, 2024

Hey @alexander-akait thanks for responding 🙏🏽,
Here's a minimal reproducible example: https://github.com/Galcarmi/WebpackResolvingIssue
I added a detailed readme file

edit: oops, forgot to add the dist folders, fixed it now in the example

from enhanced-resolve.

alexander-akait avatar alexander-akait commented on May 21, 2024

@Galcarmi After looking at your code I want to say - your structure is not consistent, top level packages have one logic, inner packages have another, anyway there is an example how you can solve it:

class CustomResolverPlugin {
  _isAbsoluteOrRelativePath(request) {
    return request.startsWith("/") || request.startsWith("./") || request.startsWith("..");
  }

  apply(resolver) {
    const source = resolver.ensureHook("raw-module");
    const target = resolver.ensureHook("undescribed-resolve-in-package");

    resolver
      .getHook(source)
      .tapAsync("NpmResolverPlugin", (resolveRequest, resolveContext, callback) => {
        const { request } = resolveRequest;

        if (this._isAbsoluteOrRelativePath(request)) {
          callback();

          return;
        }

          const packageMatch = /^(@[^/]+\/)?[^/]+/.exec(request);
          if (!packageMatch) return callback();
          const packageName = packageMatch[0];
          const innerInternalRequest = request.slice(packageName.length);

          const innerRequest = innerInternalRequest.length === 0 ? `.${innerInternalRequest}` : ".";

        try {
            const modulePath = path.join(__dirname, 'external_modules', 'current_version_start', packageName, 'current_version_end', packageName, innerInternalRequest);


            const obj = {
                ...resolveRequest,
                path: modulePath,
                fullySpecified: request.fullySpecified && innerRequest !== ".",
                request: innerRequest,
                module: false
            };

            resolver.doResolve(target, obj, null, resolveContext, callback);
        } catch {
          callback();
        }
      });
  }
}

Note - it is just an example, some things are missing - you need to use this logic https://github.com/webpack/enhanced-resolve/blob/main/lib/ModulesInHierarchicalDirectoriesPlugin.js#L49 and check is it directory, if not - add missing dependecies, otherwise in the watch mode if you add a new package, watcher will not triggered

from enhanced-resolve.

Galcarmi avatar Galcarmi commented on May 21, 2024

@alexander-akait thanks 🙏🏽🙏🏽🙏🏽 i'll try it

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.