Skip to content

Conversation

@marns
Copy link
Contributor

@marns marns commented Dec 3, 2025

Added a new ESLint rule babylonjs/no-directory-barrel-imports that detects imports resolving to directories with index files when using path mappings.

Related: #17525

Rule by Claude

@bjsplat
Copy link
Collaborator

bjsplat commented Dec 3, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@marns
Copy link
Contributor Author

marns commented Dec 3, 2025

Alternatively we could update addJSToCompiledFiles.ts to account for directory imports (I tried to follow existing pattern of not doing those)

@bjsplat
Copy link
Collaborator

bjsplat commented Dec 3, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Dec 3, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Dec 3, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Dec 3, 2025

@sebavan sebavan requested a review from ryantrem December 3, 2025 22:12
@sebavan
Copy link
Member

sebavan commented Dec 3, 2025

Importing from folders is forbidden by design as we do have side effects and it would be detrimental to the bundled app size.

The rules makes perfect sense even if I was sure we had one already lol

cc @ryantrem and @docEdub to review and test the rule

@sebavan sebavan requested a review from docEdub December 3, 2025 22:17
Copy link
Member

@sebavan sebavan left a comment

Choose a reason for hiding this comment

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

LGTM but not approving to give time for others to review

@sebavan
Copy link
Member

sebavan commented Dec 3, 2025

The build failed proving the rule is working out correctly !!! :-) @marns can you update the branch with the fix so it will be ready to merge

@bjsplat
Copy link
Collaborator

bjsplat commented Dec 3, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Dec 3, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Dec 3, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Dec 3, 2025

marns added 2 commits December 3, 2025 16:14
… some false positives in tools package with different bundling behavior
…r and a file with the same name exist in the same. specifically resolves abstractEngine.ts vs AbstractEngine/ which are ambiguous on case-insensitive file systems i.e. Mac OS
@bjsplat
Copy link
Collaborator

bjsplat commented Dec 4, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Dec 4, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Dec 4, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Dec 4, 2025

@marns
Copy link
Contributor Author

marns commented Dec 4, 2025

@sebavan Updated and passing with a couple of fixes for false positives, including the special case of abstractEngine vs AbstractEngine on Mac 😅

@sebavan
Copy link
Member

sebavan commented Dec 4, 2025

ping @ryantrem and @docEdub

Copy link
Contributor

@docEdub docEdub left a comment

Choose a reason for hiding this comment

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

👍 lgtm

@sebavan sebavan merged commit 8e200c3 into BabylonJS:master Dec 4, 2025
20 checks passed
const importPath = node.source.value as string;

// Skip relative imports and node_modules imports
if (importPath.startsWith(".") || importPath.startsWith("@") || !tsConfig?.compilerOptions?.paths) {
Copy link
Member

Choose a reason for hiding this comment

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

should it not run for relative imports ?

Copy link
Member

Choose a reason for hiding this comment

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

I was wondering about this one as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this PR is for consumers of BJS, not internal imports inside BJS. Will consumers use relative imports?

Copy link
Contributor

Choose a reason for hiding this comment

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

The "consumer" in this case being inspector-v2.

Copy link
Member

Choose a reason for hiding this comment

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

It's still wrong though within core for example to do import { StandardMaterial } from "../Materials", and it seems like it would be nice if this rule caught that as well (unless I'm just misunderstanding the code).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It only checked path mapped imports since these are the ones that produce the ambiguity / error, via pathTransform.ts:transformPackageLocation

I tried applying it to relative paths also and found only one violation, so maybe good to apply broadly if that's a general policy?

#17535

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.

5 participants