Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In findExternal, context should be a string #411

Closed
Satyam opened this issue Jul 4, 2016 · 2 comments
Closed

In findExternal, context should be a string #411

Satyam opened this issue Jul 4, 2016 · 2 comments

Comments

@Satyam
Copy link
Contributor

Satyam commented Jul 4, 2016

(a suggestion I'm not sure about:)

In https://github.com/benmosher/eslint-plugin-import/blob/master/resolvers/webpack/index.js#L174 it might be safer if the second null argument corresponding to the 'context' argument is an empty string instead. Webpack will always provide a string for this argument and no document says it will do otherwise. Under that circumstance, it is normal to use string methods such as indexOf which will make it fail when a null is received. An empty string, I believe, serves the same purpose and doesn't break anything.

@benmosher
Copy link
Member

What should the string value be, ideally? I'm not familiar with external functions, this feature came in via a PR.

I suspect it's supposed to be a file path; could probably provide what is actually expected per Webpack spec.

@Satyam
Copy link
Contributor Author

Satyam commented Jul 4, 2016

It is the absolute pathname to the folder containing the file with the require call. For relative paths, it would allow you to use path.resolve to get the absolute path to the required file, or a path that can be further processed by require.resolve to add the usual defaults (index.js and such).

If you add the following to any webpack.config.js file you might have, you will see what it takes without disturbing the build process:

externals: [
      function (context, request, callback) {
        console.log(context, request);
        if (request[0] === '.') {
          console.log('=>>', require.resolve(path.resolve(context, request)));
        }
        callback();
      }
],

I guess that from https://github.com/benmosher/eslint-plugin-import/blob/master/resolvers/webpack/index.js#L15-L26, using path.dirname(file) instead of null would produce the same result. An extra argument to findExternal with this information would be needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants