Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
03c434b
feat: switch to framework info
erezrokah Jan 6, 2021
54f2344
fix: use dev instead of watch
erezrokah Jan 7, 2021
9f697f9
test: fix detect-server test
erezrokah Jan 7, 2021
3b70530
refactor: code cleanup
erezrokah Jan 7, 2021
5dd4c18
fix: use staticAssetsDirectory where applicable
erezrokah Mar 16, 2021
2577c75
refactor: use exclusive flags instead of manual validation
erezrokah Mar 16, 2021
80d391d
refactor: code cleanup
erezrokah Mar 17, 2021
c954cf1
refactor: code cleanup
erezrokah Mar 18, 2021
1a18528
refactor: cleanup detection code
erezrokah Mar 18, 2021
154ef97
fix: update log message
erezrokah Mar 18, 2021
1d4374e
fix: remove vite detector
erezrokah Apr 21, 2021
b32abba
refactor: cleanup code and fix eleventy tests
erezrokah Apr 22, 2021
ff73065
chore: remove log
erezrokah May 26, 2021
39afead
fix(command-dev): handle custom framework
erezrokah May 26, 2021
706df6a
chore: remove redwoodjs
erezrokah Jun 3, 2021
d4708cb
chore: remove svelte kit
erezrokah Jun 6, 2021
fab41c8
fix: handlem multiple detected frameworks
erezrokah Jun 15, 2021
1e0e5ef
chore: some code cleanup
erezrokah Jun 30, 2021
2e78cad
feat: make logs nicer
erezrokah Jun 30, 2021
2aa90a0
test(frameworks): replace unit tests with integration tests
erezrokah Jun 30, 2021
f748ace
test: fix tests in CI
erezrokah Jul 1, 2021
2d1700b
docs: fix docs
erezrokah Jul 1, 2021
21efa2d
test: normalize backslash in snapshots
erezrokah Jul 1, 2021
ae4ddfb
fix: fix framework process handling
erezrokah Jul 1, 2021
350fde5
fix: update tests
erezrokah Jul 11, 2021
89127c8
fix(windows): pass commandWithoutArgs to isNonExistingCommandError
erezrokah Jul 11, 2021
0671ee6
test: update snapshots
erezrokah Jul 12, 2021
e170646
fix: don't run detection if both command and targetPort are configured
erezrokah Jul 13, 2021
80bda0c
fix(command-dev-docs): update examples and netlify-dev
erezrokah Jul 13, 2021
bfbb432
fix(deps): update framework-info
erezrokah Jul 13, 2021
ed6cae1
test: remove frameworks list from snapshot
erezrokah Jul 13, 2021
8f9bdb8
Merge branch 'main' into feat/use_framework_info
erezrokah Jul 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/commands/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ netlify dev

```bash
$ netlify dev
$ netlify dev -c "yarn start"
$ netlify dev -c hugo
$ netlify dev -d public
$ netlify dev -c "hugo server -w" --targetPort 1313
```

---
Expand Down
38 changes: 17 additions & 21 deletions docs/netlify-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ alias ndeploy="netlify deploy --prod"
alias nd="netlify dev"
alias ndl="netlify dev --live"
alias nfc="netlify functions:create"
alias ndx="netlify dev:exec "
alias ndx="netlify dev:exec"
```

</details>
Expand All @@ -68,22 +68,21 @@ USAGE
$ netlify dev

OPTIONS
-c, --command=command command to run
-f, --functions=functions Specify a functions folder to serve
-o, --offline disables any features that require network access
-p, --port=port Specify port of netlify dev
-l, --live Start a public live session
-c, --command=command command to run
-d, --dir=dir dir with static files
-f, --functions=functions specify a functions folder to serve
-l, --live start a public live session
-o, --offline disables any features that require network access
-p, --port=port port of netlify dev
--targetPort=targetPort port of target app server

DESCRIPTION
The dev command will run a local dev server with Netlify's Edge Logic proxies and redirects, serverless functions, and addons
The dev command will run a local dev server with Netlify's proxy and redirect rules

EXAMPLES
$ netlify dev
$ netlify dev -c "yarn start"
$ netlify dev -c hugo

COMMANDS
dev:exec Exec command
$ netlify dev -d public
$ netlify dev -c "hugo server -w" --targetPort 1313
```

## Live Share
Expand All @@ -96,8 +95,6 @@ netlify dev --live

You will get a URL that looks like `https://clever-cray-2aa156-6639f3.netlify.live/`. This can be accessed by anyone as long as you keep your session open.

> Note: there are currently known issues with ending the live session alongside your webdevserver, as well as with live reloading. We are working on fixing it, and would appreciate repro cases, or you may check [existing issues with the `--live` tag](https://github.com/netlify/netlify-dev-plugin/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A--live). In the mean time you can run `ps aux | grep live-tunnel` and kill these sessions manually.

## netlify.toml [dev] block

Netlify Dev is meant to work with zero config for the majority of users, by using its detector system. However you may wish to assert more control over its behavior, and should make use of the new `[dev]` block in `netlify.toml` to do so:
Expand All @@ -109,7 +106,7 @@ Netlify Dev is meant to work with zero config for the majority of users, by usin
functions = "functions" # netlify dev uses this directory to scaffold and serve your functions
publish = "dist"

# note: each of these fields are OPTIONAL, with an exception that when you’re specifying "command" and "targetPort", you must specify framework = "#custom"
# note: each of these fields are OPTIONAL
[dev]
command = "yarn start" # Command to start your dev server
targetPort = 3000 # The port for your application server, framework or site generator
Expand All @@ -126,15 +123,14 @@ Netlify Dev is meant to work with zero config for the majority of users, by usin

## Project detection

Netlify Dev will attempt to detect the site generator or build command that you are using, and run these on your behalf, while adding other development utilities. If you have a JavaScript project, it looks for the best `package.json` script to run for you, using simple heuristics, so you can use the full flexibility of npm scripts. We may add more intelligence to this in the future.
Netlify Dev will attempt to detect the site generator or build command that you are using, and run these on your behalf, while adding other development utilities. If you have a JavaScript project, it looks for the best `package.json` script to run for you, using simple heuristics, so you can use the full flexibility of npm scripts.

**Overriding the detectors**: The number of [project types which Netlify Dev can detect](https://github.com/netlify/cli/tree/main/src/detectors) is growing, but if yours is not yet supported (contributions welcome!), you can instruct Netlify Dev to run the project on your behalf by declaring it in a `[dev]` block of your `netlify.toml` file.
**Overriding framework detection**: The number of [frameworks which Netlify Dev can detect](https://github.com/netlify/framework-info/tree/main/src/frameworks) is growing, but if yours is not yet supported (contributions welcome!), you can instruct Netlify Dev to run the project on your behalf by declaring it in a `[dev]` block of your `netlify.toml` file.

```toml
# sample dev block in the toml
# note: each of these fields are OPTIONAL and should only be used if you need an override
[dev]
framework = "#custom"
command = "yarn start" # Command to start your dev server
targetPort = 3000 # # The port for your application server, framework or site generator
port = 8888 # The port that the netlify dev will be accessible on
Expand All @@ -152,8 +148,8 @@ against your project.

Possible values of `framework`:

- `#auto` (default) to check of all [available frameworks](https://github.com/netlify/cli/tree/main/src/detectors).
- One of the frameworks as specified [here](https://github.com/netlify/cli/tree/main/src/detectors).
- `#auto` (default) to check of all [available frameworks](https://github.com/netlify/framework-info/tree/main/src/frameworks).
- One of the framework ids as specified [here](https://github.com/netlify/framework-info/tree/main/src/frameworks).
- `#static` for a static file server
- `#custom` to use the `command` option to run an app server and `targetPort` option to connect to it

Expand All @@ -170,7 +166,7 @@ As for which port to use while doing local development in Netlify Dev, always se
```bash
┌──────────────────────────────────────────────────────────────┐
│ │
│ [Netlify Dev] Server now ready on http://localhost:64939
│ [Netlify Dev] Server now ready on http://localhost:8888
│ │
└──────────────────────────────────────────────────────────────┘
```
Expand Down
14 changes: 7 additions & 7 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"dependencies": {
"@netlify/build": "^15.11.2",
"@netlify/config": "^12.6.0",
"@netlify/framework-info": "^5.7.1",
"@netlify/framework-info": "^5.7.2",
"@netlify/plugin-edge-handlers": "^1.11.21",
"@netlify/plugins-list": "^2.19.1",
"@netlify/routing-local-proxy": "^0.30.2",
Expand Down
26 changes: 15 additions & 11 deletions src/commands/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const waitPort = require('wait-port')

const { startFunctionsServer } = require('../../lib/functions/server')
const Command = require('../../utils/command')
const { serverSettings } = require('../../utils/detect-server')
const { detectServerSettings } = require('../../utils/detect-server-settings')
const { getSiteInformation, injectEnvVariables } = require('../../utils/dev')
const { startLiveTunnel } = require('../../utils/live-tunnel')
const { NETLIFYDEV, NETLIFYDEVLOG, NETLIFYDEVWARN, NETLIFYDEVERR } = require('../../utils/logo')
Expand All @@ -31,7 +31,7 @@ const startStaticServer = async ({ settings, log }) => {
})

await promisify(server.start.bind(server))()
log(`\n${NETLIFYDEVLOG} Server listening to`, settings.frameworkPort)
log(`\n${NETLIFYDEVLOG} Static server listening to`, settings.frameworkPort)
}

const isNonExistingCommandError = ({ command, error }) => {
Expand All @@ -53,14 +53,14 @@ const isNonExistingCommandError = ({ command, error }) => {
}

const startFrameworkServer = async function ({ settings, log, exit }) {
if (settings.noCmd) {
if (settings.useStaticServer) {
return await startStaticServer({ settings, log })
}

log(`${NETLIFYDEVLOG} Starting Netlify Dev with ${settings.framework || 'custom config'}`)

// we use reject=false to avoid rejecting synchronously when the command doesn't exist
const frameworkProcess = execa(settings.command, settings.args, { preferLocal: true, reject: false })
const frameworkProcess = execa.command(settings.command, { preferLocal: true, reject: false })
Copy link
Contributor Author

Choose a reason for hiding this comment

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

framework-info returns a single string of the command + arguments

frameworkProcess.stdout.pipe(stripAnsiCc.stream()).pipe(process.stdout)
frameworkProcess.stderr.pipe(stripAnsiCc.stream()).pipe(process.stderr)
process.stdin.pipe(frameworkProcess.stdin)
Expand All @@ -70,17 +70,17 @@ const startFrameworkServer = async function ({ settings, log, exit }) {
// eslint-disable-next-line promise/catch-or-return,promise/prefer-await-to-then
frameworkProcess.then(async () => {
const result = await frameworkProcess
const [commandWithoutArgs] = settings.command.split(' ')
// eslint-disable-next-line promise/always-return
if (result.failed && isNonExistingCommandError({ command: settings.command, error: result })) {
if (result.failed && isNonExistingCommandError({ command: commandWithoutArgs, error: result })) {
log(
NETLIFYDEVERR,
`Failed launching framework server. Please verify ${chalk.magenta(`'${settings.command}'`)} exists`,
`Failed launching framework server. Please verify ${chalk.magenta(`'${commandWithoutArgs}'`)} exists`,
)
} else {
const commandWithArgs = `${settings.command} ${settings.args.join(' ')}`
const errorMessage = result.failed
? `${NETLIFYDEVERR} ${result.shortMessage}`
: `${NETLIFYDEVWARN} "${commandWithArgs}" exited with code ${result.exitCode}`
: `${NETLIFYDEVWARN} "${settings.command}" exited with code ${result.exitCode}`

log(`${errorMessage}. Shutting down Netlify Dev server`)
}
Expand All @@ -98,7 +98,7 @@ const startFrameworkServer = async function ({ settings, log, exit }) {
port: settings.frameworkPort,
output: 'silent',
timeout: FRAMEWORK_PORT_TIMEOUT,
...(settings.disableLocalServerPolling ? {} : { protocol: 'http' }),
...(settings.pollingStrategies.includes('HTTP') && { protocol: 'http' }),
})

if (!open) {
Expand Down Expand Up @@ -208,7 +208,7 @@ class DevCommand extends Command {

let settings = {}
try {
settings = await serverSettings(devConfig, flags, site.root, log)
settings = await detectServerSettings(devConfig, flags, site.root, log)
} catch (error) {
log(NETLIFYDEVERR, error.message)
exit(1)
Expand Down Expand Up @@ -249,7 +249,11 @@ DevCommand.description = `Local dev server
The dev command will run a local dev server with Netlify's proxy and redirect rules
`

DevCommand.examples = ['$ netlify dev', '$ netlify dev -c "yarn start"', '$ netlify dev -c hugo']
DevCommand.examples = [
'$ netlify dev',
'$ netlify dev -d public',
'$ netlify dev -c "hugo server -w" --targetPort 1313',
]

DevCommand.strict = false

Expand Down
64 changes: 0 additions & 64 deletions src/detectors/README.md

This file was deleted.

26 changes: 0 additions & 26 deletions src/detectors/angular.js

This file was deleted.

25 changes: 0 additions & 25 deletions src/detectors/brunch.js

This file was deleted.

31 changes: 0 additions & 31 deletions src/detectors/create-react-app.js

This file was deleted.

Loading