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

Add browser field to package.json to fix webpack #308

Merged
merged 1 commit into from Dec 8, 2020

Conversation

josephfrazier
Copy link
Collaborator

This should close #305, see #305 (comment):

Actually, after reading https://webpack.js.org/configuration/resolve/#resolvemainfields more closely, it sounds like adding a browser field to package.json, that points to lib/index.js (same as main) should fix things.

resolve.mainFields
[string]

When importing from an npm package, e.g. import * as D3 from 'd3', this option will determine which fields in its package.json are checked. The default values will vary based upon the target specified in your webpack configuration.

When the target property is set to webworker, web, or left unspecified:

webpack.config.js

module.exports = {
//...
resolve: {
mainFields: ['browser', 'module', 'main']
}
};
For any other target (including node):

webpack.config.js

module.exports = {
//...
resolve: {
mainFields: ['module', 'main']
}
};
For example, consider an arbitrary library called upstream with a package.json that contains the following fields:

{
"browser": "build/upstream.js",
"module": "index"
}
When we import * as Upstream from 'upstream' this will actually resolve to the file in the browser property. The browser property takes precedence because it's the first item in mainFields. Meanwhile, a Node.js application bundled by webpack will first try to resolve using the file in the module field.

I'll open a PR for that.

This should close slevithan#305, see slevithan#305 (comment):

> Actually, after reading https://webpack.js.org/configuration/resolve/#resolvemainfields more closely, it sounds like adding a `browser` field to `package.json`, that points to `lib/index.js` (same as `main`) should fix things.
>
> > resolve.mainFields
> > [string]
> >
> > When importing from an npm package, e.g. import * as D3 from 'd3', this option will determine which fields in its package.json are checked. The default values will vary based upon the target specified in your webpack configuration.
> >
> > When the target property is set to webworker, web, or left unspecified:
> >
> > webpack.config.js
> >
> > module.exports = {
> >   //...
> >   resolve: {
> >     mainFields: ['browser', 'module', 'main']
> >   }
> > };
> > For any other target (including node):
> >
> > webpack.config.js
> >
> > module.exports = {
> >   //...
> >   resolve: {
> >     mainFields: ['module', 'main']
> >   }
> > };
> > For example, consider an arbitrary library called upstream with a package.json that contains the following fields:
> >
> > {
> >   "browser": "build/upstream.js",
> >   "module": "index"
> > }
> > When we import * as Upstream from 'upstream' this will actually resolve to the file in the browser property. The browser property takes precedence because it's the first item in mainFields. Meanwhile, a Node.js application bundled by webpack will first try to resolve using the file in the module field.
>
> I'll open a PR for that.
@josephfrazier josephfrazier marked this pull request as ready for review December 8, 2020 03:41
josephfrazier added a commit to josephfrazier/xregexp that referenced this pull request Dec 8, 2020
Travis CI is no longer providing CI minutes for open source projects: https://news.ycombinator.com/item?id=25338983

It's also been pretty slow: the build for slevithan#308
hasn't started in 13 minutes
@slevithan
Copy link
Owner

Nice research. Based on the docs you linked to, this looks like it will indeed resolve the issue for anyone with webpack's target property set to webworker, web, or left unspecified.

@josephfrazier, do you think this should be released as a 4.4.1 or 4.5.0?

@josephfrazier
Copy link
Collaborator Author

Thanks! This feels like a 4.4.1 bugfix to me

@slevithan slevithan merged commit 45c8546 into slevithan:master Dec 8, 2020
@josephfrazier
Copy link
Collaborator Author

@slevithan are you going to take care of doing the release, or should I?

@josephfrazier josephfrazier deleted the joseph/browser.field branch December 8, 2020 04:21
@slevithan
Copy link
Owner

@josephfrazier If you're okay with doing it, I'd really appreciate it! I'm trying to minimize involvement going forward :( But let me know if you run into any problems and I'll be happy to help!

@josephfrazier
Copy link
Collaborator Author

I should be able to dig up and do all the steps, especially now that you've made it easier with 760ab95

I'll give it a shot and reach out if there's any issues!

josephfrazier added a commit that referenced this pull request Dec 8, 2020
Travis CI is no longer providing CI minutes for open source projects: https://news.ycombinator.com/item?id=25338983

It's also been pretty slow: the build for #308
hasn't started in 13 minutes

The config file is based on the template at https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-nodejs#specifying-the-nodejs-version
@josephfrazier
Copy link
Collaborator Author

@slevithan can I get collaborator access to this repo (https://github.com/slevithan/xregexp/settings/access)?

Specifically, I'd like to add a branch protection rule that requires the new github action check to pass on PRs: https://github.com/josephfrazier/xregexp/settings/branches

@slevithan
Copy link
Owner

@josephfrazier You already had collaborator access, so I'm not sure what's up. I just removed then re-invited you.

@josephfrazier
Copy link
Collaborator Author

josephfrazier commented Dec 8, 2020

Ohh, whoops. I think I meant to ask for maintain or admin access, so I can manage the repo settings at https://github.com/slevithan/xregexp/settings. Here's what it currently looks like for me:

image

josephfrazier added a commit to josephfrazier/xregexp that referenced this pull request Dec 8, 2020
Changes include:

* Remove no longer relevant lastIndex code from replace method, fixes slevithan#287
* Add browser field to package.json to fix webpack: slevithan#308

To generate this commit, I adapted the steps at slevithan#205 (comment)

Here's a fuller list of changes that can be needed with new releases:

> * Version number
>   * Update version number and year in headers, config files, README.
>   * Update year in LICENSE.
>   * Update version number in `XRegExp.version`.
> * Publish
>   * Publish new git tag. E.g.:
>     * `git tag -a v3.1.0 -m "Release 3.1.0"`.
>     * `git push origin v3.1.0`.
>   * `npm publish`.
@slevithan
Copy link
Owner

@josephfrazier I don't see any option to change collaborators' roles/permissions. I'm guessing that's because this is a personal repo, rather than owned by an organization.

I've gone ahead and created a branch protection rule. I set the branch name pattern as master and checked only the option "Require status checks to pass before merging" (with "build" as the selected status check). Let me know if you want me to make any further changes!

(If you continue to need admin access in the future, I'm open to discussing transferring the repo to an organization.)

@josephfrazier
Copy link
Collaborator Author

Thanks, that looks like it did the trick! For an example, see #312

I don't know if we need to bother with an organization yet, I'll see if I hit future barriers

josephfrazier added a commit that referenced this pull request Dec 8, 2020
Changes include:

* Add browser field to package.json to fix webpack: #308

To generate this commit, I adapted the steps at #205 (comment)

> Here's a fuller list of changes that can be needed with new releases:
> 
> * Version number
>   * Update version number and year in headers, config files, README.
>   * Update year in LICENSE.
>   * Update version number in `XRegExp.version`.
> * Publish
>   * Publish new git tag. E.g.:
>     * `git tag -a v3.1.0 -m "Release 3.1.0"`.
>     * `git push origin v3.1.0`.
>   * `npm publish`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Import does not work anymore since version 4.4.0
2 participants