-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Use package.json names for AMD bundles #12019
Conversation
scripts/rollup/build.js
Outdated
sourcemap: false, | ||
amd: { | ||
id: bundle.entry, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs trailing comma (just run yarn prettier
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I'd run that. I'll double-check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
```js define('', ['require', 'exports', 'react', 'react-dom'] // … var React = require('react'); ``` throws a [mismatched define error](https://requirejs.org/docs/errors.html#mismatch) when used with RequireJS because the current AMD definitions don't specify module names. This patch passes the bundle names into `rollup`, so the AMD definitions can use them. By naming the builds, they can be [consumed from the Bazel build tool](https://github.com/bazelbuild/rules_typescript/issues/102). I have minimal familiarity with AMD. I don't believe adding module names should affect other environments.
c5bdab2
to
b6708a8
Compare
<div id="container"></div> | ||
<script> | ||
requirejs.config({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth still trying to test this? Does this trigger some other code path in RequireJS?
Maybe we could copy the fixtures?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure which route you'd prefer. I did test both before opening the PR.
Options:
- Merge as-is.
- Include
react-dom
as a script andreact
in this map (or vice versa - we could even have dev test one combo and prod test the other). - Make a new pair of fixtures that tests the map style.
Which would you prefer? If you'd like both, would they each live as folders in fixtures
, or as subfolders of fixtures/requirejs
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Top-level folders in fixtures
sound fine, let's keep both versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've never used RequireJS before, so I'm certainly not the expert. Perusing its source, it looks like define(name
is inserted into defQueue
, but it's not obvious how config.paths
gets registered.
I didn't originally add 2 sets of fixtures because ensuring that define(name
and paths[name]
worked the same way seemed like a RequireJS concern (rather than a React one), but I'm happy to add a second set if you think it's worthwhile. (I also don't know who/how fixtures are tested - is it just a manual smoketest, or is checking them part of a process?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a manual smoketest.
I'm not an expert either—do what you think is reasonable and we'll try to review :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined to leave it as-is. My inclination is that it's RequireJS's responsibility to ensure that config.paths
works with define(name
, and that adding fixtures to React that assert that adds noise more than value.
I feel more confident in this direction because I did test the old style before updating the fixture - they both work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I just saw that you did request both fixtures. It got lost in the thread. I'll add them.
b6708a8
to
1e0df7b
Compare
@gaearon and I were unsure if fixtures for both `<script src>` and `config.paths` were useful or redundant. We're erring towards including both.
1e0df7b
to
8884207
Compare
Can you please bring it up to date? |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution. |
Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you! |
Currently, the AMD distributions don't specify module names. Therefore, when they are inlined in a bundle or imported with a
script
tag:RequireJS throws mismatched define errors:
This patch passes the bundle names into
rollup
, so the AMD definitions can use them.By naming the builds, they can be easily consumed from the Bazel build tool. Bazel inlines AMD dependencies, but doesn't otherwise transpile their module syntaxes.
I have minimal familiarity with AMD. I don't believe adding module names should affect other environments.