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

build-examples: Support namespaced modules #22270

Merged
merged 2 commits into from
Aug 10, 2021

Conversation

marcofugaro
Copy link
Contributor

Related issue: Fixes #22267 (comment)

Description

Add support for namespaced modules in the build-examples script.

Basically this

export {
	computeTangents,
	mergeBufferGeometries,
	mergeBufferAttributes,
	interleaveAttributes,
	estimateBytesUsed,
	mergeVertices,
	toTrianglesDrawMode,
	computeMorphedAttributes,
};

becomes this

THREE.BufferGeometryUtils = {};
THREE.BufferGeometryUtils.computeMorphedAttributes = computeMorphedAttributes;
THREE.BufferGeometryUtils.computeTangents = computeTangents;
THREE.BufferGeometryUtils.estimateBytesUsed = estimateBytesUsed;
THREE.BufferGeometryUtils.interleaveAttributes = interleaveAttributes;
THREE.BufferGeometryUtils.mergeBufferAttributes = mergeBufferAttributes;
THREE.BufferGeometryUtils.mergeBufferGeometries = mergeBufferGeometries;
THREE.BufferGeometryUtils.mergeVertices = mergeVertices;
THREE.BufferGeometryUtils.toTrianglesDrawMode = toTrianglesDrawMode;

I had to add an array to keep track of modules that need to be namespaced, otherwise, there is no way to tell.

@mrdoob
Copy link
Owner

mrdoob commented Aug 4, 2021

Hmm... Is it possible use dynamic imports in the script to see what it exports?

const module = await import('./foo.js');
console.log( module );

@mrdoob mrdoob added this to the r132 milestone Aug 4, 2021
@marcofugaro
Copy link
Contributor Author

marcofugaro commented Aug 4, 2021

@mrdoob to check that there is more than 1 export?

@mrdoob
Copy link
Owner

mrdoob commented Aug 4, 2021

Yes, and if there is a default one.

@marcofugaro
Copy link
Contributor Author

@mrdoob I thought about doing so, but there are some exceptions that prevents this 😅

Currently CameraControls, TransformControls, Geometry, DecalGeometry, VOXLoader, Lut, RollerCoaster, CurveModifier, Lensflare, MarchingCubes, Pass, CSS3DRenderer, CSS2DRenderer, Projector, BokehShader2, DepthLimitedBlurShader, GodRaysShader, SMAAShader, SSAOShader, SSRrShader, SSRShader, ToonShader all export multiple things, and they don't need to be under a namespace.

We need a way to differentiate between modules that export multiple things and modules that need a namespace.

I am doing this with const namespaces = [ 'BufferGeometryUtils' ]; because I couldn't find a better way 😄

@marcofugaro
Copy link
Contributor Author

I could namespace only the modules that end with Utils 🤔

@marcofugaro
Copy link
Contributor Author

@mrdoob done! Now all the files that end with Utils.js are automatically namespaced.

If we merge this and #22284 everything should work fine again!

@mrdoob mrdoob merged commit c2700fb into mrdoob:dev Aug 10, 2021
@mrdoob
Copy link
Owner

mrdoob commented Aug 10, 2021

Thanks!

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.

2 participants