Skip to content

assertNoDuplicates throw with more context#10419

Merged
nicolo-ribaudo merged 1 commit intobabel:masterfrom
hjdivad:hjdivad/duplicates-with-context
Oct 2, 2019
Merged

assertNoDuplicates throw with more context#10419
nicolo-ribaudo merged 1 commit intobabel:masterfrom
hjdivad:hjdivad/duplicates-with-context

Conversation

@hjdivad
Copy link
Copy Markdown
Contributor

@hjdivad hjdivad commented Sep 9, 2019

Q                       A
Fixed Issues? Fixes #9778
Patch: Bug Fix? No
Major: Breaking Change? No
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR Link N/A
Any Dependency Changes? No
License MIT

When users see errors like

Duplicate plugin/preset detected.
If you'd like to use two separate instances of a plugin,
they need separate names, e.g.

  plugins: [
    ['some-plugin', {}],
    ['some-plugin', {}, 'some unique name'],
  ]

It can be difficult to determine the source of the conflict, especially
in a larger build system.

This commit outputs what is known about the plugins that actually
conflict, which can be helpful for users to determine the root cause of
the conflict.

New example output on conflict:

Duplicate plugin/preset detected.
If you'd like to use two separate instances of a plugin,
they need separate names, e.g.

  plugins: [
    ['some-plugin', {}],
    ['some-plugin', {}, 'some unique name'],
  ]

Duplicates detected are:
[
      "root": "/Users/dhamilto/src/linkedin/ember-cli-pemberly-m3",
      "name": "ember-m3"
    },
    "dirname": "/Users/dhamilto/src/linkedin/ember-cli-pemberly-m3",
    "ownPass": false,
    "file": {
      "request": "/Users/dhamilto/src/linkedin/ember-cli-pemberly-m3/node_modules/ember-compatibilit
y-helpers/comparision-plugin.js",
      "resolved": "/Users/dhamilto/src/linkedin/ember-cli-pemberly-m3/node_modules/ember-compatibili
ty-helpers/comparision-plugin.js"
    }
  },
  {
    "alias": "/Users/dhamilto/src/linkedin/ember-cli-pemberly-m3/node_modules/ember-compatibility-he
y-helpers/comparision-plugin.js",
      "resolved": "/Users/dhamilto/src/linkedin/ember-cli-pemberly-m3/node_modules/ember-compatibili
ty-helpers/comparision-plugin.js"
    }
  }
]

Partially addresses #9778

When users see errors like

```
Duplicate plugin/preset detected.
If you'd like to use two separate instances of a plugin,
they need separate names, e.g.

  plugins: [
    ['some-plugin', {}],
    ['some-plugin', {}, 'some unique name'],
  ]
```

It can be difficult to determine the source of the conflict, especially
in a larger build system.

This commit outputs what is known about the plugins that actually
conflict, which can be helpful for users to determine the root cause of
the conflict.

Partially addresses babel#9778
@hjdivad
Copy link
Copy Markdown
Contributor Author

hjdivad commented Sep 9, 2019

Note that this commit only outputs the conflicts that triggered a particular assertion.

It could in principle output all conflicts, but I'd be concerned about the output getting too large.

Copy link
Copy Markdown
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @hjdivad! Debugging these errors is quite hard (since it contains no context on which plugins/presets were causing the issue), with these changes we can have a bit more of a fighting chance....

@babel-bot
Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/11526/

1 similar comment
@babel-bot
Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/11526/

plugins: [plugin, plugin],
plugins: [
[plugin, undefined, "my-plugin"],
[plugin, undefined, "my-plugin"],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it throw if you don't specify the my-plugin name here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolo-ribaudo the example output in the pr is a case where no name is specified. Because I'm serializing it with JSON.stringify you don't see the name key in the output at all.

The output for this test is:

      Duplicate plugin/preset detected.
      If you'd like to use two separate instances of a plugin,
      they need separate names, e.g.

        plugins: [
          ['some-plugin', {}],
          ['some-plugin', {}, 'some unique name'],
        ]

      Duplicates detected are:
      [
        {
          "name": "my-plugin",
          "alias": "base$0",
          "dirname": "/Users/dhamilto/src/babel/babel/packages/babel-core/test",
          "ownPass": false
        },
        {
          "name": "my-plugin",
          "alias": "base$1",
          "dirname": "/Users/dhamilto/src/babel/babel/packages/babel-core/test",
          "ownPass": false
        }
      ]

With the name omitted, the output becomes:

      Duplicate plugin/preset detected.
      If you'd like to use two separate instances of a plugin,
      they need separate names, e.g.

        plugins: [
          ['some-plugin', {}],
          ['some-plugin', {}, 'some unique name'],
        ]

      Duplicates detected are:
      [
        {
          "alias": "base$0",
          "dirname": "/Users/dhamilto/src/babel/babel/packages/babel-core/test",
          "ownPass": false
        },
        {
          "alias": "base$1",
          "dirname": "/Users/dhamilto/src/babel/babel/packages/babel-core/test",
          "ownPass": false
        }
      ]

@nicolo-ribaudo nicolo-ribaudo added area: errors pkg: core PR: Polish 💅 A type of pull request used for our changelog categories labels Sep 9, 2019
@rwjblue
Copy link
Copy Markdown
Member

rwjblue commented Sep 20, 2019

Any thoughts on this one? Not sure what the process itself is to move forward here...

@rwjblue
Copy link
Copy Markdown
Member

rwjblue commented Oct 2, 2019

@nicolo-ribaudo - 👋 I'd love some progress here, we are often times getting bug reports for the current error that require us to manually throw a console.log into node_modules/@babel/core/lib/config/config-descriptors.js to see any useful information.

Copy link
Copy Markdown
Member

@hzoo hzoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great and sorely needed! thanks @hjdivad and @rwjblue - we just merged a something one regarding filenames #10511

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

Labels

area: errors outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: core PR: Polish 💅 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

babel-core doesn't list which plugins/presets are duplicated

6 participants