Skip to content

Javascript regression: Hubot tries to load all files in script directories, even if they aren't Javascript #1355

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

Closed
technicalpickles opened this issue Jun 21, 2017 · 9 comments · Fixed by #1357

Comments

@technicalpickles
Copy link
Member

@timothywellsjr posted on the Javascript evolution with a report that hubot was trying to require a YAML in scripts. @mistydemeo asked if the updated hubot is trying to load all files, not just javascript.

It seems like, yes, it is. Here's a dive through the relevant codes:

Compare this to the previous behavior of loadFile which checks if it's a supported require type: https://github.com/hubotio/hubot/pull/1347/files#diff-740956d8fdad73632c4937d631b7c79bL353

cc @gr2m

@technicalpickles
Copy link
Member Author

This would need to be tested, but if anyone is running into it, you could try moving the files out of the scripts directory as a work around. That might require other code changes to account for different paths.

@gr2m
Copy link
Contributor

gr2m commented Jun 21, 2017

Thanks for the research into the problem @technicalpickles, it sounds right. I think we can check for just js and coffee extensions as we don’t support others right now? We can add that check back into loadFile method at

try {

@technicalpickles
Copy link
Member Author

@gr2m I'd use the same check that was there, ie if require.extensions[ext] to preserve existing behavior.

I checked the require.extenisons docs and it says it's deprecated, but not going anywhere. I don't think we need to tackle that as part of this 3.0 release for javascript support.

@gr2m
Copy link
Contributor

gr2m commented Jun 21, 2017

sounds good

@gr2m
Copy link
Contributor

gr2m commented Jun 21, 2017

@technicalpickles I’ll prepare a PR today

@gr2m
Copy link
Contributor

gr2m commented Jun 22, 2017

sorry didn’t manage to yesterday and will be in a meeting all day today. I’ll send a PR tomorrow

@gr2m
Copy link
Contributor

gr2m commented Jun 25, 2017

@technicalpickles @timothywellsjr @mistydemeo I started a PR that should fix the problem:
#1357 – could you give it a try please?

@timothywellsjr
Copy link

👍

@timkinnane
Copy link

Had a question on how to resolve the related issue of adding a warning for when unsupported files are rejected from loading. I was going to address it by adding something like:

this.logger.warning(`${filename} uses unsupported extension, only ${Object.keys(require.extensions).join(', ')} are accepted`)

But getting the list of accepted extensions, I found that it accepts .js, .json and .node. If coffee-script is also required, it will also allow .coffee, .litcoffee and .coffee.md.

Now, most of those should not be accepted by the .loadFile method AND the require.extensions is also depreciated, requiring a // eslint-disable-line at the end of the line just to pass standardjs linting.

Due to the above, why not just use a fixed array of accepted types, being just ['.js', '.coffee']?

timkinnane pushed a commit to timkinnane/hubot-async that referenced this issue Jul 29, 2017
Unsupported extensions were silently omitted from loadFile, this made it hard to debug. The accepted extensions were also incorrect due to use of require.extensions which is depreciated and contained types that are incompatible with hubot to load as scripts - fixes hubotio#1377 related hubotio#1355
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 a pull request may close this issue.

4 participants