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

Making a require conditional requires clearing the cache #5833

Closed
mischnic opened this issue Feb 13, 2021 · 3 comments · Fixed by #6541
Closed

Making a require conditional requires clearing the cache #5833

mischnic opened this issue Feb 13, 2021 · 3 comments · Fixed by #6541

Comments

@mischnic
Copy link
Member

🐛 bug report

Wrapping an existing dependency in an if statement doesn't wrap the dependency (with a cached build).

💁 Possible Solution

dep.meta.shouldWrap is overwritten when reading the dependency from cache?

💻 Code Sample

// if (Date.now() < 0) {
	const x = require("./something");

	console.log(x);
// }
  1. parcel build index.js
  2. Comment in the first and last line
  3. parcel build index.js. something is still being executed.

🌍 Your Environment

Software Version(s)
Parcel 560d060
@devongovett
Copy link
Member

Still an issue?

@devongovett devongovett added this to the v2.0.0-rc.0 milestone Jun 26, 2021
@mischnic
Copy link
Member Author

Yes, output of step 1:

var $30c2bb3b4d10773c$exports = {};
console.log("!");


console.log($30c2bb3b4d10773c$exports); // }

output of step 2 (the imported asset isn't wrapped):

var $30c2bb3b4d10773c$exports = {};
console.log("!");


if (Date.now() < 0) {
    const x = $30c2bb3b4d10773c$exports;
    console.log(x);
}

@devongovett
Copy link
Member

I think this is the problem:

if (existing) {
invariant(existing.type === 'dependency');
depNode.value.meta = existing.value.meta;
}

Looks like it was added in 3edfae0

I guess it needs to somehow merge the meta properties added by the resolver with the properties returned by the transformer? We'd need to store these separately I suppose so that either request can re-run without the other re-running and the result should be the same. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants