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

feat: add serve command #5351

Merged
merged 48 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
087f7dd
feat: add `--serve` flag to `dev` command
eduardoboucas Dec 23, 2022
b3f582d
refactor: simplify internal directory clean up
eduardoboucas Dec 23, 2022
90402fd
refactor: load built functions
eduardoboucas Jan 2, 2023
d5652e7
refactor: make things nicer
eduardoboucas Jan 2, 2023
ac6a845
refactor: add const
eduardoboucas Jan 2, 2023
134bf3f
feat: show debug message
eduardoboucas Jan 3, 2023
d782283
refactor: rename variable
eduardoboucas Jan 3, 2023
7a0d578
Merge branch 'main' into feat/serve-command
eduardoboucas Jan 3, 2023
5411c3c
chore: add `extract-zip` dependency
eduardoboucas Jan 3, 2023
05e9dc3
chore: update snapshots
eduardoboucas Jan 3, 2023
3ec828b
refactor: conditionally set `quiet` flag
eduardoboucas Jan 3, 2023
1a89050
refactor: simplify code
eduardoboucas Jan 3, 2023
2d8d2d0
chore: update docs
eduardoboucas Jan 3, 2023
78c35b6
refactor: rename flag to `prod`
eduardoboucas Jan 3, 2023
0bcc9a2
refactor: update message
eduardoboucas Jan 3, 2023
4090013
feat: do not set `NETLIFY_DEV` when `prod` is set
eduardoboucas Jan 3, 2023
9be736b
chore: remove lint exceptions
eduardoboucas Jan 3, 2023
e3eea4a
Apply suggestions from code review
eduardoboucas Jan 3, 2023
2934233
refactor: treat `NETLIFY_DEV` consistently across function types
eduardoboucas Jan 3, 2023
ebb2334
refactor: add `internal` source for env vars
eduardoboucas Jan 3, 2023
01df8a3
fix: handle internal vars correctly
eduardoboucas Jan 3, 2023
59297c1
chore: update docs
eduardoboucas Jan 3, 2023
917fc13
refactor: remove unused variable
eduardoboucas Jan 3, 2023
ae74853
feat: set `context=production` when `prod` is used
eduardoboucas Jan 4, 2023
f3cc600
refactor: add beta label
eduardoboucas Jan 4, 2023
32cf4b5
feat: create separate `serve` command
eduardoboucas Jan 6, 2023
4739d22
Update src/commands/serve/serve.mjs
eduardoboucas Jan 6, 2023
42ae1bb
refactor: remove unused flags
eduardoboucas Jan 6, 2023
f4f31fb
refactor: abort server when build fails
eduardoboucas Jan 6, 2023
28bd294
refactor: always start functions server
eduardoboucas Jan 9, 2023
f4a2dfd
Merge branch 'main' into feat/serve-command
eduardoboucas Jan 9, 2023
dbd9dcc
chore: remove ESLint directive
eduardoboucas Jan 9, 2023
bc5c59d
fix: fix imports
eduardoboucas Jan 9, 2023
496783a
refactor: always start functions server
eduardoboucas Jan 9, 2023
a92f755
refactor: ensure internal functions directory
eduardoboucas Jan 9, 2023
af00758
refactor: reinstate functions server check
eduardoboucas Jan 9, 2023
48872f6
Merge branch 'feat/serve-command' into feat/serve-command-2
eduardoboucas Jan 9, 2023
e357598
refactor: add missing import
eduardoboucas Jan 9, 2023
66dc887
fix: fix imports
eduardoboucas Jan 9, 2023
b8f9666
Merge branch 'main' into feat/serve-command-2
eduardoboucas Jan 9, 2023
f28d164
refactor: move logic for ensuring internal functions directory
eduardoboucas Jan 9, 2023
7306853
chore: fix test
eduardoboucas Jan 9, 2023
4c55658
chore: update docs
eduardoboucas Jan 9, 2023
96e79a1
chore: update snapshot
eduardoboucas Jan 9, 2023
431e531
refactor: add log message
eduardoboucas Jan 9, 2023
c873f68
Update src/commands/serve/serve.mjs
eduardoboucas Jan 9, 2023
ad1dbf4
chore: update docs
eduardoboucas Jan 9, 2023
527efcf
Merge branch 'main' into feat/serve-command-2
eduardoboucas Jan 9, 2023
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
6 changes: 6 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,11 @@ module.exports = {
],
},
},
{
files: ['tests/**/*'],
rules: {
'require-await': 'off',
},
},
],
}
1 change: 1 addition & 0 deletions docs/commands/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ netlify dev
- `live` (*boolean*) - start a public live session
- `offline` (*boolean*) - disables any features that require network access
- `port` (*string*) - port of netlify dev
- `prod` (*boolean*) - (Beta) build the site for production and serve locally
- `sessionId` (*string*) - (Graph) connect to cloud session with ID [sessionId]
- `targetPort` (*string*) - port of target app server
- `debug` (*boolean*) - Print debugging information
Expand Down
73 changes: 73 additions & 0 deletions npm-shrinkwrap.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
"execa": "^5.0.0",
"express": "^4.17.1",
"express-logging": "^1.1.1",
"extract-zip": "^2.0.1",
"fastify": "^4.10.2",
"find-up": "^5.0.0",
"flush-write-stream": "^2.0.0",
Expand Down
21 changes: 16 additions & 5 deletions src/commands/base-command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,7 @@ export default class BaseCommand extends Command {
return await resolveConfig({
config: options.config,
cwd,
context:
options.context ||
process.env.CONTEXT ||
// Dev commands have a default context of `dev`, otherwise we let netlify/config handle default behavior
(['dev', 'dev:exec'].includes(this.name()) ? 'dev' : undefined),
context: options.context || process.env.CONTEXT || this.getDefaultContext(),
debug: this.opts().debug,
siteId: options.siteId || (typeof options.site === 'string' && options.site) || state.get('siteId'),
token,
Expand Down Expand Up @@ -505,4 +501,19 @@ export default class BaseCommand extends Command {
exit(1)
}
}

/**
* Returns the context that should be used in case one hasn't been explicitly
* set. The default context is `dev` most of the time, but some commands may
* wish to override that.
*
* @returns {string}
*/
getDefaultContext() {
if (this.name() === 'serve') {
return 'production'
}

return 'dev'
}
}
Loading