Commit Graph

313 Commits

Author SHA1 Message Date
Andy
921a54ed22 Fix tests order (#2565) 2019-07-17 19:35:30 +02:00
Andy
7e3a5a7e2c [now dev] Allow now dev as package.json script (#2559)
* [now dev] Allow `now dev` as package.json script

* Fix absolute path for now dev

* Fix directory issue

* Typo

* Update src/commands/dev/dev.ts

Co-Authored-By: Nathan Rajlich <n@n8.io>

* Whitespace

* Make code simpler

* Extend type

* Update errors/now-dev-as-dev-script.md

Co-Authored-By: Nathan Rajlich <n@n8.io>

* Update errors/now-dev-as-dev-script.md

Co-Authored-By: Nathan Rajlich <n@n8.io>
2019-07-17 19:35:14 +02:00
Nathan Rajlich
4d0c638688 [now dev] Wait for updateBuilders() to complete before stop() completes (#2551)
* [now dev] Wait for `updateBuilders()` to complete before `stop()` completes

Since #2477, the unit tests related to `now dev` have become flaky, and
need to be retried a couple of times before running successfully. My
theory is that this is related to having concurrent `yarn` processes
operating on the builders module directory, causing corruption with yarn's
cache. Waiting for the lazy updating `yarn` process to complete makes
sense to me, hopefully CircleCI agrees.

* Debugging "list the scopes" integration test

* Moar debug

* Use regular `require()` when not in a webpack build (ava tests)

* Remove debug
2019-07-17 19:34:27 +02:00
Nathan Rajlich
01b9913204 [now dev] Bundle the most popular core builders into CLI binary with lazy builder updates (#2477)
* [now dev] Bundle the most popular core builders into CLI binary

Makes Now CLI bundle a tarball inside its snapshot filesystem that
includes the following builders:

 * @now/go
 * @now/next
 * @now/node
 * @now/php
 * @now/static-build

The tarball is generated by the `build.js` script and ensures the
"latest" version of the builders are included into the tarball.

When `now dev` is run, the tarball will be extracted upon the first
run to make these builders "pre-installed" to avoid the "Installing
builders" phase during boot-up.

Overall, this should make booting up `now dev` a lot faster, and help
with offline support.

* Don't install builders if they are bundled

* Persist `assets` dir to CircleCI workspace

* Delete build assets

* Fix installing builders from URL

* Finish builder installation filtering logic

* Still install `@now/build-utils`

* Implement builders installation "stale-while-revalidate"

* Remove `console.time()`

* Fix unit test

* Add `Readonly<>` to `BuilderWithPackage` type props

* Add debug log stack trace upon builder update failure
2019-07-17 19:33:54 +02:00
Andy Bitz
9291efcfc3 Revert "Include tests from 15.7.0-canary.17"
This reverts commit 350d63eacd.
2019-07-12 15:25:10 +02:00
Sophearak Tha
350d63eacd Include tests from 15.7.0-canary.17 2019-07-12 15:05:35 +02:00
Max
a4fdc8561c Disable automatic signup (#2530)
* Disable automatic signup

* Use shorter error message

* Update tests

* Update tests with user info

* Create tmpDir before tests

* Tweak fixtures and assertions for new login

* Don't pre-create the test directory in CI

* Use `os.homedir` instead of `~` in tests

* Pre-create auth directory conditionally
2019-07-12 14:53:12 +02:00
Nathan Rajlich
98d511b03c [now dev] Render directory listing for Now v2 projects (#2528)
* [now dev] Render directory listing for Now v2 projects

Before directory listings only worked for "all static" deployments since
`now dev` would shell out to `serve-handler` to do the rendering.

Now the directory listing rendering logic is moved into `now dev` which
allows projects with Lambdas to also serve the directory listing
(previously they would just 404).

This removes the special-casing of "all static" deployments so that
there's only one code path.

Fixes #2161.
Fixes #2417.

* Move `serve-handler/src/directory` types to root

* Set `Content-Length` header for dir listing

* Add unit tests for directory listing

* Fix unit test
2019-07-12 14:52:50 +02:00
Nathan Rajlich
855940c6fc [now dev] Update serve-handler to v6.1.0 and enable etag option (#2525)
* [now dev] Update `serve-handler` to v6.1.0 and enable `etag` option

Sending the `ETag` response header matches how Now in production works.

* Test file contents as well
2019-07-12 14:52:34 +02:00
Nathan Rajlich
ac794e704d Add .gitignore file to test/fixtures/unit/now-dev-default-builds-and-routes (#2524) 2019-07-12 14:52:27 +02:00
Nathan Rajlich
20ee6752ad [now dev] Revert "Add etag response header for Lambda invocations" (#2520)
* [now dev] Revert "Add `etag` response header for Lambda invocations"

This reverts commit f80f1f79a6 (#2502).

`ETag` header is only sent in production when the lambda function sets
the "stale-while-revalidate" cache-control header, which will be
implemented in a separate PR.

* Remove `etag` test assertion
2019-07-12 14:52:10 +02:00
Andy
27730b4568 [now dev] Fix @now/static-build sorting (#2519)
* [now dev] Fix @now/static-build sorting

* Change tests

* Update src/util/dev/server.ts

Co-Authored-By: Nathan Rajlich <n@n8.io>
2019-07-12 14:51:32 +02:00
Andy
00c792297a [now dev] Tests for routing and apply default frontend builder last (#2518) 2019-07-12 14:51:25 +02:00
Sophearak Tha
d11f8e4ebf Simplify builds output message (#2512)
* Simplify builds output message

* Properly stop the spinner

* Handle stop spinning properly and remove unused import

* Update src/commands/deploy/latest.js

Co-Authored-By: Leo Lamprecht <mindrun@icloud.com>

* Update src/commands/deploy/latest.js

Co-Authored-By: Leo Lamprecht <mindrun@icloud.com>

* Properly handle stop spinning at build failed

* Update build failed message

* Remove unused variable

* Remove punctuation in error message

* Update integration test reflect latest change
2019-07-12 14:50:49 +02:00
Nathan Rajlich
020f9d8da5 [now dev] Add test case for lazily installing builders (#2510)
This is a follow up for #2509 to add a unit/regression test ensuring
correct functionality.
2019-07-12 14:50:26 +02:00
Andy
a40f0b6d65 [now dev] Add support for deployments without now.json (#2498)
* [now-dev] Add zero config

* Update @now/build-utils

* Update @now/build-utils

* Escape glob

* Fix windows and group globbing

* Made sure routes and builds get updated on file events

* Removed useless check

* Add unit tests

* Use fetch instead of get
2019-07-12 14:50:02 +02:00
Nathan Rajlich
69f81e0ab9 [now dev] Set Now response headers when proxy passing in routes (#2500)
* [now dev] Set Now response headers when proxy passing in `routes`

* Fix unit test
2019-07-12 14:49:53 +02:00
Nathan Rajlich
cf4eebbc95 [now dev] Allow cache-control header to be overwritten (#2501)
* [now dev] Allow `cache-control` header to be overwritten

This matches the behavior in production.

* Add `now-dev-headers` unit test fixture

* Remove `console.error()` call
2019-07-07 16:40:31 +00:00
Nathan Rajlich
3383798bf1 [now dev] Add etag response header for Lambda invocations (#2502)
This matches the behavior in production.
2019-07-07 16:40:28 +00:00
Nathan Rajlich
aba51841a2 [now dev] Set "must-revalidate" cache-control response header (#2499)
This matches the production router behavior, and prevents running `now
dev` on a different project from serving stale content from a different
project.

Also update the `x-now-id` header to match the production behavior (it
changed at some point).
2019-07-07 16:40:22 +00:00
Nathan Rajlich
64fe29bfea Remove mkdirp-promise (#2478)
Use the implemention from `fs-extra` instead.
2019-07-05 11:25:10 -07:00
Andy
9b23d61720 Change url for revert-alias tests to make it more reliable (#2471)
* Change url for revert-alias tests to make it more reliable

* Use project name from now.json

* Remove unused import in tests
2019-06-28 12:12:10 +02:00
Steven
dd6dbbfc9b [now dev] Improve tests for @now/build-utils@canary (#2444) 2019-06-21 11:39:00 +00:00
Steven
7ceeaf9a6a [now dev] Use canary @now/build-utils or stable based on builders (#2441)
* [now dev] Use canary build utils or stable

* Fix version selection

* Fix test

* Fix typo

* Add tests for getBuildUtils

* Add `latest`
2019-06-21 11:38:48 +00:00
Nathan Rajlich
1380c9fb2c [now dev] Move helper modules to src/util/dev (#2422)
This organization is consistent with how other commands are structured.
2019-06-13 13:55:57 +00:00
Nathan Rajlich
a8d4b7826f [now dev] Implement continue: true routes (#2413)
* [now dev] Implement `continue: true` routes

Fixes #2088.

* Add `continue: true` unit test

* Add a `continue: true` unit test that matches
2019-06-13 13:55:39 +00:00
Nathan Rajlich
593bcb1025 Add whoami command back (#2411)
* Add `whoami` command back

It was accidentally removed.

Fixes #2410.

* Add `whoami` regression test
2019-06-13 13:55:34 +00:00
JJ Kasper
ece9f46798 [now-dev] Add checking of RegExp src with beginning slash (#2398)
* Add checking of RegExp src with beginning slash

* Move slash no slash check to same line

* Add unit test for dev-router
2019-06-13 13:55:29 +00:00
Luc
ba6ddc380d [now update] Add integration test (#2405)
* add simple integration to test `now update`

* remove `.only`

* verify that `now --version` includes `canary`
2019-06-05 15:12:45 -07:00
Andy
8b8af21445 Fix now rm and decrease total projects for now ls (#2404)
* Use v4 instead to prevent listing the same deployment multiple times

* Remove the latestDeployments since it is depracted and doesn't have the
`readyState` property and only get 35 projects instead of 50 to lower
the rate limit

* Fix tests
2019-06-05 15:12:32 -07:00
Nathan Rajlich
42b24b4904 [now dev] Strip prefixed / when doing routes matching (#2361)
* [now dev] Strip prefixed `/` when doing routes matching

The prefixed `/` is implicit when matching routes, so strip them
so that they are optional. This matches the behavior in production.

* Fix unit tests

* More readable

* Add unit test
2019-06-05 15:11:48 -07:00
Nathan Rajlich
a31c29fc13 [now dev] Use empty string for missing matches (#2376)
Rather than `undefined`. This matches the behavior in production.

Fixes #2375.
2019-06-05 15:11:32 -07:00
Andy
418d550f2a Increase the time we wait for the aliasing (#2360) 2019-05-20 19:15:25 +00:00
Nathan Rajlich
80ebd659fc [now dev] Use the dev server cwd as builder's workPath (#2326)
* [now dev] Use the dev server `cwd` as builder's `workPath`

Rather than copying the source files into a temporary directory,
simply use the existing source files in the `cwd`. This will make
subsequent boots of `now dev` be faster (i.e. because the `node_modules`
directory will already be in place), as well as use much less space on
the filesystem because temporary directory are no longer being used.

This will require some changes to the builders and `@now/build-utils`,
to ensure that the `download()` function is always installing into
`workPath`, and that the `meta` object passed to the `build()` function
is also passed into the `download()` function.

For example:

 - https://github.com/zeit/now-builders/pull/474
 - https://github.com/zeit/now-builders/pull/475

* Update `@now/build-utils` to v0.5.5-canary.1

This makes `download()` be a no-op when running in `now dev`.

* Add test case for `@now/next`

* Fix debug log formatting
2019-05-20 19:14:56 +00:00
Nathan Rajlich
2d16c36f8d Re-enable "try to create a builds deployments with wrong config" integration test (#2337)
It was temporarily disabled due to server-side issues, but that has been
fixed now.
2019-05-20 19:14:51 +00:00
Nathan Rajlich
91b4e7a308 [now dev] Mix in routes query params when proxying to a URL (#2330)
* [now dev] Mix in routes query params when proxying to a URL

Fixes #2289.

* Refactor unit tests and add a unit test for proxy passing with query params

* Fix TypeScript compile error

* [DEBUG] Disable proxy pass unit test

* Run unit tests serially

* Remove `console.error()` in unit test

* Temporarily disable integration test "try to create a builds deployments with wrong config"
2019-05-20 19:14:40 +00:00
Nathan Rajlich
3398e6da27 [now dev] Implement methods in routes config (#2306)
Fixes #2148.
2019-05-03 17:21:51 -07:00
Nathan Rajlich
db15047cc1 [now dev] Install builders with yarn instead of npm (#2272)
* [now dev] Install builders with `yarn` instead of `npm`

Also invokes via `process.execPath` so that the pkg'd node is used
instead of a global one.

Depends on #2270.

* Install `yarn` to the builder cache dir

Not the `node_modules/.bin` dir, because `yarn` cleans up that directory
when installing modules, so it deletes itself.

* Remove unnecessary unit test

* Always install `yarn`

* Pass in the `yarnPath` to `installBuilders()`

* Restore unit test

* Remove unused `delimiter` import

Co-Authored-By: TooTallNate <n@n8.io>
2019-04-30 10:14:22 +00:00
Leo Lamprecht
8114ede173 Do not print installing builders for no builds (#2266)
* Do not print installing builders for no builds

* Added unit test
2019-04-29 14:59:48 +00:00
Leo Lamprecht
f53feed8f5 Make the message for when the server is running shorter (#2262) 2019-04-29 14:59:40 +00:00
Andy
1bf4af7269 Wait for aliases in tests (#2257) 2019-04-29 14:59:22 +00:00
Leo Lamprecht
e383c2c4d6 Revert "Add a logout test case" (#2258)
This reverts commit 5754360684c1e34b0351fadd9e2a6e5ef4b8b82f.
2019-04-29 14:59:18 +00:00
Olli Vanhoja
8fce8bb75d Use the single request logout endpoint (#2201)
Logout by deleting the currently used auth token.
2019-04-29 14:59:14 +00:00
JJ Kasper
2822c314eb Update to make sure query isn't stripped (#2246)
* Update to make sure query isn't stripped
before ProxyPass in dev-server

* Add test for stripping query

* normalize semis in test
2019-04-29 14:58:51 +00:00
Nathan Rajlich
28a478311c [now dev] Remove requiresInitialBuild and make shouldServe() optional for v2 Builders (#2209)
* [now dev] Remove `requiresInitialBuild` and make `shouldServe()` optional for v2 Builders

`@now/next` will be removing `shouldServe()` in favor of returning
a `routes` config array upon bootup. This makes now dev's
`shouldServe()` wrapper function support matching a `routes` config
entry when `shouldServe()` is not defined.

* Remove `console.error()` debugging calls

* Remove `mergeRoutes()` logic

This was incorrect behavior, and more like what `continue: true` is
supposed to do.

* Remove invalid test case

* Remove from the `files` array when ENOENT occurs in file watcher

* Prettier

* Pass workPath to builder.shouldServe() (#2211)
2019-04-25 15:01:05 +00:00
Nathan Rajlich
276860aead [now dev] Resolve built routes after matching builder (#2208)
* [now dev] Resolve built routes after matching builder

This removes the `combineRoutes()` function since it was problematic and
triggered rebuilds upon every HTTP request, which is not necessary and
makes development slower.

Now, when an HTTP request comes in, the `now.json` routes are resolved
first, and then the matched build is checked if it defines any `routes`
in the build output. If it does, and a matching route is found then the
route is handled accordingly.

* Fix dev router unit tests

* Only try to match build routes if `.length > 0`

* Remove `routes` config from `@now/static` build results

This would cause an infinite loop of resolving `entrypoint` to
`entrypoint`, and is not necessary for this builder.
2019-04-25 15:00:56 +00:00
Amio
8e4d7d769e Made sure support for routes works as expected (#2194)
* Fix lost concat result

* Made it work

* Fixed several tests

* Fixed more tests

* Fixed tests
2019-04-25 15:00:27 +00:00
Andy
9994fc0824 Now CLI gets a fixed alias (#2189) 2019-04-18 21:25:57 +02:00
Andy
e03d16462f Add tests for the new automatic aliasing in the v9 API (#2180)
* Add tests for the new automatic aliasing in the v9 API

* Show a more descriptive message

* Await sleep

* Add sleep to test

* Decrease sleep
2019-04-17 21:05:48 +02:00
Nathan Rajlich
6748053233 [now dev] Refactor to support shouldServe() in Now Builders (#2134)
* WIP refactor to Now Builders v2 API

* More WIP

* Finish up refactor

* Remove `BuiltAsset` type

These properties are on the the `BuildMatch` interface now.

* Fix `handle: filesystem` route post-refactor

* Prettier

* Update src/commands/dev/lib/builder-cache.ts

Co-Authored-By: leo <mindrun@icloud.com>
2019-04-11 11:30:46 +00:00