-
-
Notifications
You must be signed in to change notification settings - Fork 594
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
test(run): add test broken in the latest rollup #241
Conversation
@lukastaegert I guess this happens because of circular dependencies. This is a tradeoff of reusing stuff in dynamic chunks. Would be good to have a warning for such cases. I didn't found any in my circular dependencies warnings though I could miss it because I have ~100 in graphql server. |
@TrySound a few CI issues to clear up there. |
I found case where new rollup fails with run plugin. When entry point and dynamic import use the same module chunk.modules becomes empty. Run checks `chunk.modules[input]` for some reason which fails when chunk.modules is empty.
cf346b7
to
e7890b2
Compare
This does not always work and was already broken before Rollup 2: https://github.com/rollup/plugins/blob/master/packages/run/lib/index.js#L52-L55 The point is that when Rollup cannot match the export signature of an entry chunk because it needs to add additional exports, it will create a facade chunk that reexports exactly those exports that the original entry point exposed. A facade chunk will have its However you can use the Also note that if a plugin just wants to read options, it should NOT use the const path = require('path');
const childProcess = require('child_process');
module.exports = (opts = {}) => {
let input;
let proc;
const args = opts.args || [];
const forkOptions = opts.options || opts;
delete forkOptions.args;
return {
name: 'run',
// As stated above, do not use options here
buildStart(opts) {
let inputs = opts.input;
if (typeof inputs === 'string') {
inputs = [inputs];
}
if (typeof inputs === 'object') {
inputs = Object.values(inputs);
}
if (inputs.length > 1) {
throw new Error(`@rollup/plugin-run only works with a single entry point`);
}
input = path.resolve(inputs[0]);
},
generateBundle(outputOptions, bundle, isWrite) {
if (!isWrite) {
this.error(`@rollup/plugin-run currently only works with bundles that are written to disk`);
}
},
writeBundle(outputOptions, bundle) {
const dir = outputOptions.dir || path.dirname(outputOptions.file);
const entryFileName = Object.keys(bundle)
.find(fileName => bundle[fileName].facadeModuleId === input);
if (entryFileName) {
if (proc) proc.kill();
proc = childProcess.fork(path.join(dir, entryFileName), args, forkOptions);
} else {
this.error(`@rollup/plugin-run could not find output chunk`);
}
}
};
}; |
Awesome! Thanks for response @lukastaegert. I'll try to cover all cases with tests. |
Ref #241 (comment) - take input from latest options when build is started - check facade id instead of modules list
Ref #241 (comment) - take input from latest options when build is started - check facade id instead of modules list
…292) Ref #241 (comment) - take input from latest options when build is started - check facade id instead of modules list
…ollup#292) Ref rollup#241 (comment) - take input from latest options when build is started - check facade id instead of modules list
…(#292) Ref rollup/plugins#241 (comment) - take input from latest options when build is started - check facade id instead of modules list
#192 Rollup Plugin Name:
run
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
I found case where new rollup fails with run plugin.
When entry point and dynamic import use the same module
chunk.modules becomes empty. Run checks
chunk.modules[input]
for somereason which fails when chunk.modules is empty.
@lukastaegert could you take a look?