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

Allow node-red to load nodes with .cjs file extension #4433

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Pezmc
Copy link

@Pezmc Pezmc commented Nov 10, 2023

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Fixes #4431

Updates the loader to no-longer assume that the node file always .js as a file extension for the javascript.

.cjs files work without issue, but previously node-red would try to load a template called file-name.cjs instead of file-name.html, which meant nodes would be missing from the palette despite showing as loaded in settings.

Templates failing to load are silently ignored, in case a node has no associated template, so no error would be displayed but there would be no front-end node available:

}).catch(err => {
// ENOENT means no html file. We can live with that. But any other error
// should be fatal
// node.err = "Error: "+node.template+" does not exist";
node.types = node.types || [];
if (err.code !== 'ENOENT') {
node.err = err.toString();
}
return node;
});

Before

For example node from #4431 (https://github.com/Pezmc/node-red-test-node)

Screenshot 2023-11-10 at 18 32 26

Screenshot 2023-11-10 at 18 32 33

After

Screenshot 2023-11-10 at 18 21 04

Screenshot 2023-11-10 at 18 32 01

Proposed changes

Checklist

  • I have read the contribution guidelines
  • For non-bugfix PRs, I have discussed this change on the forum/slack team.
  • I have run npm run test to verify the unit tests pass
  • [-] I have added suitable unit tests to cover the new/changed functionality - Seemingly no test coverage in this area

@knolleary
Copy link
Member

Change looks good, however there is another place where we make this assumption/substitution.

These code paths are related to loading 'bare' node files out of the ~/.node-red/nodes directory - ones that are not packaged as modules. It's a bit of an edge case, but then, so is using .cjs anyway ;)

@Pezmc
Copy link
Author

Pezmc commented Jan 8, 2024

I didn't find any usage (or test coverage) of getLocalFile in https://github.com/Pezmc/node-red/blob/4920611b69f124757f4c97b3f97c6f3fe7854f5c/packages/node_modules/@node-red/registry/lib/localfilesystem.js#L593 but I have updated it!

@Pezmc
Copy link
Author

Pezmc commented Jan 8, 2024

@knolleary Updated above, used a slightly closer guard to ensure only js files are checked.

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.

Node with .cjs suffix does not load properly
2 participants