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

Fix CLI and dynamic import workflow bugs #1907

Merged
merged 4 commits into from
Jan 26, 2018
Merged

Conversation

guybedford
Copy link
Contributor

In the process of putting together some example material these came up that were missed with some of the changes.

@guybedford
Copy link
Contributor Author

The example workflow I found these on was for rollup/rollupjs.org#110.

@@ -11,7 +11,7 @@ function fn (num) {
}

function dynamic (num) {
return Promise.resolve(require("./dep2.js"))
return Promise.resolve({ default: require("./dep2.js") })
.then(dep2 => {
return dep2.mult(num);
});
Copy link
Member

Choose a reason for hiding this comment

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

As you can see here with this change, the code will be broken (you would need to write dep2.default.mult(num) to make it work).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is no longer happening now.

src/Chunk.ts Outdated
left: 'Promise.resolve(require(',
right: '))'
left: 'Promise.resolve({ default: require(',
right: ') })'
Copy link
Member

Choose a reason for hiding this comment

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

What is the scenario you hope to fix here? Test? As you can see with the test below, this makes named exports no longer work (and again shows that we probably need functional tests). My feeling is that the correct approach would be more complicated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch. Ok so the rule is this:

  • When the dynamic import is an external module, we need to treat it as { default: module } as that is how interop works when importing CommonJS from ES modules.
  • When the dynamic import is a known module from our current bundle operation, we treat it as a full module object, as it's effectively within our private interface for bundling.

I've added the adjustments to make these cases work out now.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

This looks good now (though I did not run all cases myself) 👍

@lukastaegert lukastaegert added this to the 0.55.1 milestone Jan 25, 2018
@lukastaegert lukastaegert changed the base branch from master to release-0.55.1 January 26, 2018 05:51
@lukastaegert lukastaegert merged commit 89b8083 into release-0.55.1 Jan 26, 2018
@@ -10,7 +10,7 @@ import { BatchWarnings } from './batchWarnings';
import { SourceMap } from 'magic-string';

export default function build (inputOptions: InputOptions, outputOptions: OutputOptions[], warnings: BatchWarnings, silent = false) {
const useStdout = outputOptions.length === 1 && !outputOptions[0].file && inputOptions.input instanceof Array === false;
const useStdout = outputOptions.length === 1 && !outputOptions[0].file && !outputOptions[0].dir;
Copy link
Member

Choose a reason for hiding this comment

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

Even though I just merged this, there is one minor thing I just noticed: If inputOptions is an array of length one and you specify neither output.dir nor output.file, generate will return undefined for the code and rollup will fail. I will revert this particular change for this release for now as the previous behaviour also better corresponded to this check

const codeSplitting = inputOptions.experimentalCodeSplitting && inputOptions.input instanceof Array;
and we'll need to find a better solution here

@guybedford
Copy link
Contributor Author

guybedford commented Jan 26, 2018 via email

@lukastaegert lukastaegert deleted the workflow-bugs branch January 27, 2018 09:05
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.

None yet

2 participants