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

Dev framework matching and functions:invoke bug fixes #857

Closed

Conversation

MuffinTheMan
Copy link
Contributor

@MuffinTheMan MuffinTheMan commented Apr 24, 2020

- Summary

Fixes #847
I believe this might also fix #441

When running netlify dev with framework = "svelte" in the [dev] section of netlify.toml, I got the error: Unsupported value provided for "framework" option in config.

It turns out the logic would've required me to use framework = "svelte.js.js", because .js was being appended to the file name we wanted to check "svelte" against instead of appending .js to `"svelte" to check against the file name. This has been fixed.

I also noticed that the svelte.js settings weren't actually being used (I noticed because I couldn't run netlify dev, since I wasn't providing a targetPort, which should've been pulled from proxyPort in svelte.js). I ended up merging the defaults from svelte.js (or the corresponding detector for whichever framework is being used) into settings to make use of these defaults.

Finally, I noticed that parameters were not being passed properly into the serverSettings function from FunctionsInvokeCommand.run(), which was resulting in NPEs in my situation when calling serverSettings (when running netlify functions:invoke). The proper parameters (hopefully) are now being passed, and console.log is being sent through as the log function (seemed like the simplest solution at this time).

- Test plan

Run netlify dev with some option framework = "svelte" (or some other valid framework) and verify the dev server is run and can be reached properly.

In my case, netlify.toml:

[build]
    command = "npm run build"
    functions = "./functions"
    publish = "public"

[dev]
    framework = "svelte"
    command = "npm run start"
    publish = "public"

Verify you can invoke a function via netlify function:invoke with some test function like:

exports.handler = function(event, context) {
  return { statusCode: 200, body: 'hello' }
}

Note: this isn't working for me (but it makes it further than it did before the fixes in this PR, since it at least doesn't die from an NPE); there appears to be some other bug that I would appreciate feedback on so I can perhaps track it down. I can run the function properly by directly hitting the localhost url when running netlify dev. Here's what I get:

? Invoke with emulated Netlify Identity authentication headers? (pass --identity/--no-identity to override) No // Note: this also fails with Yes
ran into an error invoking your function
FetchError: request to http:https://localhost:8888/.netlify/functions/test-function failed, reason: connect ECONNREFUSED 127.0.0.1:8888
    at ClientRequest.<anonymous> (/Users/caleb/git-other/cli/node_modules/node-fetch/lib/index.js:1455:11)
    at ClientRequest.emit (events.js:209:13)
    at Socket.socketErrorListener (_http_client.js:406:9)
    at Socket.emit (events.js:209:13)
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at processTicksAndRejections (internal/process/task_queues.js:77:11) {
  message: 'request to http:https://localhost:8888/.netlify/functions/test-function failed, reason: connect ECONNREFUSED 127.0.0.1:8888',
  type: 'system',
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED'
}

- Description for the changelog

netlify dev framework config and function:invoke bug fixes

- A picture of a cute animal (not mandatory but encouraged)

close-up-photography-of-fawn-pug-covered-with-brown-cloth-374898

Caleb Larsen added 3 commits April 23, 2020 21:55
… into consideration values in detectorsFiles ending in '.js' while devConfig.framework value shouldn't.
…plit config.dev and flags into two separate parameters when passing into serverSettings() instead of merging them.
@@ -41,7 +41,8 @@ class FunctionsInvokeCommand extends Command {
process.exit(1)
}

let settings = await serverSettings(Object.assign({}, config.dev, flags))
// Pass in console.log as the logger for now.
let settings = await serverSettings(config.dev, flags, console.log)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could be wrong on this; but it didn't appear that config.dev and flags should be getting merged here and passed as the devConfig argument to serverSettings when it takes in flags as the second argument. Also, we'll get an NPE with nothing passed for the third argument (log).

Also, it appears there will be some conflicts with #843.


// detectorsFiles end in '.js`; but devConfig.framework shouldn't. To test for match, append '.js' to devConfig.framework.
const detectorName = detectorsFiles.find(dt => dt === `${devConfig.framework}.js`)
if (!detectorName) throw new Error(`Unsupported value '${devConfig.framework}' provided for "framework" option in config`)
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 appears .js was being appended to the wrong value here. Also, I added the actual unsupported value to the error so it's a more helpful error (hopefully).

const detector = loadDetector(detectorName)
const detectorResult = detector()
if (!detectorResult) throw new Error(`Specified "framework" detector "${devConfig.framework}" did not pass requirements for your project`)

settings.args = chooseDefaultArgs(detectorResult.possibleArgsArrs)
// Merge detectorResult default settings into settings Object.
Object.assign(settings, detectorResult)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this is right; but it didn't appear we were really using the detectorResult fully (chooseDefaultArgs() looks like it doesn't pull in all the defaults that we want).

@MuffinTheMan
Copy link
Contributor Author

MuffinTheMan commented Apr 24, 2020

I'm not sure why the checks are failing, because npm test shows all pass when I run locally. Could it be that I pushed another commit before the initial checks had completed? Is there a way to trigger them again without pushing another change?

Edit: I just pushed after merging in the latest from master, which caused the tests to run again...and they still failed (but they still pass for me locally 😕).

@jon-sully
Copy link
Contributor

Confirm that I've seen most of these things pop up tonight after updating as well. Ended up rolling back to 2.46.0 because even when spoofing the framework jekyll.js.js it was still erroring in trying to call flags.dir a little lower in that detect file. 2.46 is working great for me😅 just need to manually invoke some functions tonight 😜

@erezrokah
Copy link
Contributor

Is this still relevant? Looks like both of the issues in this PR are resolved by #843
@RaeesBhatti ?

@RaeesBhatti
Copy link
Contributor

Yes, we can close this. Thanks for the hints @MuffinTheMan

@RaeesBhatti RaeesBhatti closed this Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants