Giter Site home page Giter Site logo

Comments (11)

alexander-akait avatar alexander-akait commented on April 28, 2024 1

@jpbriggs408 There is a fix #18152, I decide to avoid proxy check, because it is not universal (we can't undestand when it is a plain object or a proxied object, except node.js utils ), so let's just keep unsafeCache as is and avoid the object creation

from webpack.

alexander-akait avatar alexander-akait commented on April 28, 2024

I see your problem

from webpack.

alexander-akait avatar alexander-akait commented on April 28, 2024

I found two solution:

  1. in convertToResolveOptions:
const unsafeCache = options.unsafeCache;
const normalizedOptions = removeOperations(
  resolveByProperty(options, "byDependency", dependencyType)
);
if (unsafeCache !== undefined) {
  normalizedOptions.unsafeCache = unsafeCache;
}

return normalizedOptions;

This is not a universal solution, we assume that only there a proxy can be used for unsafeCache

  1. Implement const removeOperations = (obj, ignoredKeys = []) => { /* ... */ } and so put unsafeCache in ignoredKeys, so keep them as is without deep merging, like the 1. but just improving

  2. Make Proxy to be VALUE_TYPE_ATOM in getValueType, but it is only for Node.js, so if somebody will want to bundle webpack for browser, it will not work

const getValueType = value => {
	if (value === undefined) {
		return VALUE_TYPE_UNDEFINED;
	} else if (value === DELETE) {
		return VALUE_TYPE_DELETE;
	} else if (util.types.isProxy(value)) {
		return VALUE_TYPE_ATOM;
	} else if (Array.isArray(value)) {
		if (value.lastIndexOf("...") !== -1) return VALUE_TYPE_ARRAY_EXTEND;
		return VALUE_TYPE_ATOM;
	} else if (
		typeof value === "object" &&
		value !== null &&
		(!value.constructor || value.constructor === Object)
	) {
		return VALUE_TYPE_OBJECT;
	}
	return VALUE_TYPE_ATOM;
};

All solutions works with your repo. But yeah, that is intresting problem, because we use getValueType in many places, and so these places will not work with Proxy

Want to get some feedback from you

from webpack.

alexander-akait avatar alexander-akait commented on April 28, 2024

Another solution like 3. but we can make it smarty:

if (util.types.isProxy(value) || value.__isProxy) {
}

and

fileSystemAwareCache.__isProxy = true;

so it give ability to mark Proxy in a browser

from webpack.

jpbriggs408 avatar jpbriggs408 commented on April 28, 2024

Thank you for the quick response!

Options 1 and 2 seem like the safest immediate fixes with minimal impact, though we acknowledge they might not cover all future scenarios.

Option 3 (and its browser-compatible variant) do offer a more universal fix. It does seem like the most ideal solution to our specific problem. However, our main concern revolves around potential side-effects across other getValueType usages. It would be great to know more about the specific operations removeOperations aims to exclude from your perspective. That would help us to gauge this option's viability better. That being said, we only pass in our custom cache object in the development environment, but browser compatibility is important to us.

from webpack.

icyflame0 avatar icyflame0 commented on April 28, 2024

see if this helps

const fileSystemAwareCache = new Proxy({}, {
get(target, key, receiver) {
if (key in target) {
const entry = target[key];
if (entry && fs.existsSync(entry.path)) {
return entry;
} else {
delete target[key];
}
}
return undefined;
},

set(target, key, value, receiver) {
    target[key] = value;
    return true;
}

});

from webpack.

jpbriggs408 avatar jpbriggs408 commented on April 28, 2024

@alexander-akait thank you so much! I think this solution makes a lot of sense.

If documentation needs to be updated, I'm happy to take a crack at it. Let me know, and thanks again!

from webpack.

alexander-akait avatar alexander-akait commented on April 28, 2024

I don't thank we need document it, because it is like a bug

from webpack.

jpbriggs408 avatar jpbriggs408 commented on April 28, 2024

Totally reasonable! In webpack's documentation, it isn't clear that an object can be passed, but that is outlined in enhanced-resolve's code which is sufficient enough to me.

from webpack.

mpmartinez-etsy avatar mpmartinez-etsy commented on April 28, 2024

@alexander-akait thank you for this fix, we really appreciate it! Would we be able to get a release cut with this fix in it at your convenience?

from webpack.

alexander-akait avatar alexander-akait commented on April 28, 2024

Yeah, this week

from webpack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.