Commit Graph

2 Commits

Author SHA1 Message Date
Nathan Rajlich
fd3c110c02 [now dev] Use pcre-to-regexp to match routes (#2027)
* [now dev] Use `pcre-to-regexp` to match `routes`

The now.json `routes` support PCRE syntax like named captures,
so use the `pcre-to-regexp` module to match the routes.

Fixes #2023.

* Pass the resolved router `dest` and query params to the Lambda
2019-04-01 13:01:57 +02:00
Amio
02b3c5f535 Add now dev (#1883)
* [WIP] now-dev

* try invoking lambda

* add error status to dev-server

* add basic routing

* add entry for custom @now/static builder

* honor .gitignore & .nowignore while collecting files

* add route for single static file

* add test fixtures for now-dev (nodejs)

* fix miss typed @now/statics

* import types from @now/build-utils

* fix typo @now/statics -> @now/static

* revamped router

* typescript-eslint-parser -> @typescript-eslint/parser

Eliminate error while running pre-commit hooks:

  SUPPORTED TYPESCRIPT VERSIONS: ~3.1.1
  YOUR TYPESCRIPT VERSION: 3.2.2

* send files from local @now/static builder

* use serve-handler when no now.json

* remove http-proxy

* add type def for serve-handler

* code cleanup

* move type declarations to types.ts

* dont rely on `this.cwd` while running builder

* more type definitions

* fix invoking error

* clean code

* better debug logging

* refined request handler logic

* handle /favicon.ico with serve-handler

* make builder-cache self contained

* move builder works to dev-builder.ts

* add proxy_pass handler

* support named groups in routes

* fix creating cache dir error

* add "--nodejs-preview" solely for nodejs

* clean require.cache after required user js

* fix router & header issue in nodejs preview

* [wip] add tests for dev-router

* add tests for dev-router

* lookup "/index.*" for indexes

* refine logging

* [WIP] `now dev` progress point

Actually invoking the `@zeit/fun` module at this point.

Still lots of work to be done…

* Update `@zeit/fun` to v0.0.4

* Remove `--nodejs-preview`

To be replaced by `@zeit/fun`.

* Remove `decache` and `import-fresh`

Leftover from the `--nodejs-preview`.

* Remove "declaration: true" from `tsconfig.json`

Otherwise the ncc `dist` dir ends up full of generated `.d.ts` files.

* Remove `ignore` dep, always use `@zeit/dockerignore`

* Use tarball URL for `@zeit/fun`

Because `@zeit/fun` is not yet public on npm.

* Regenerate `yarn.lock` to fix bad integrity check on fun tarball

* Upgrade to `@zeit/fun` v0.0.6

With re-written unzipping logic utilizing `yauzl`.

* Add lambda function handling logic for the HTTP response

* Match the lambda invoke shape that Now's proxy provides

* Move deps to devDependencies

* Update `@zeit/fun` to v0.0.8

* Update `@zeit/ncc` to v0.15.0

* Attempt to fix unit test for `wait()` helper function

* Add `build.sh` script to work around ncc issues

* Fix `build.sh` script for BSD's chmod

No `--changes` flag.

* Update `@zeit/fun` to v0.0.11

* Update `@zeit/fun` to v0.0.12

* Tweak some comments

* Update `@zeit/fun` to v0.0.13

* Add `now.json` env vars to lambda functions

* Finish removing `--nodejs-preview` flag

* Style tweaks

* Use `npm-package-arg` to parse the "use" builder

* Styling

* Use the parsed `pathname` when matching routes

The querystring portion needs to be removed to match properly.

* Update `@zeit/fun` to v0.1.1

* Support `-d` for debug flag

It was already listed as such in the `--help` output.

* List the `dist/runtimes` dir as pkg "assets"

* Update `@now/build-utils` to v0.4.37-canary.0

* Update `@zeit/fun` to v0.2.0

* Update `@zeit/fun` to v0.2.1

* Rewrite the `req.url` to fix serving FileFsRef assets

* Disable re-building, build all `builds` upon server bootup

* 404 is not a redirect

* warning on more than one argument

* Fix `index` without a file extension matching

* Update `@zeit/fun` to v0.2.2

* Use `async-listen`

* Add shutdown cleanup logic

* Rename `buildLambdas()` to `executeBuilds()`

* Rename `lambda` prop to `fn`

* Misc tweaks

* Pass `isDev: true` to the builder `build()` function

* Use `Object.assign()` instead of object spread

* Set `res.statusCode` instead of `writeHead()`

* Create Lambda functions during build-time

This way, the lambda instance is re-used for subsequent HTTP requests

* Wait for cleanup operations to complete in `stop()`

* Destructure `path` for join()

* Add some missing types

* Store the `buildConfig` on the assets for reverse lookup

* Remove `console.log()`

* Attempt to make globbing faster and ignore files more accurately

* Rewrite `installBuilders()` to be idempotent

So that npm is not executed for canary tags, for example.

This is done by comparing the contents of the package.json file rather
then the `node_modules` directory.

* Use `ignore` instead of `@zeit/dockerignore` for glob-gitignore

It seems that the object produced by `@zeit/dockerignore` is not
compatible with the `glob-gitignore` module, so use the vanilla
`ignore` module instead for now as a workaround.

* Implement a `GlobIgnore` class to replace `glob-gitignore`

This allows us to continue using `@zeit/dockerignore` for proper
consistency.

Closes #1899.

* Prettier

* Skip installing built-in builders (i.e. `@now/static`)

* Remove `console.error()` calls

* Use a deterministic `workPath` directory

So that the same one is re-used in-between subsequent boots of `now dev`

* Add `now.json` validation logic

* Fix serving static assets outside the project working directory

This fixes, for example, `@now/mdx-deck` which outputs static files
from its build process.

* Add comment

* Validate the `now.json` file before launching the dev server

* Respect `maxLambdaSize` config

Closes #1950.

* Add `@types/bytes` dependency

* Make `maxLambdaSize` be optional

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

* WIP force reload in browser = rebuild asset behavior

* Resolve the `asset` again after re-build

* Remove logging

* Update `@zeit/fun` to v0.3.0

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

Sets `npm_config_target` to the proper Node.js version for native
modules.

* Update `@zeit/fun` to v0.3.1

* Fix "hard refresh to reload" after the first rebuild

The `buildConfig` and `buildEntry` proper were not being set on the
rebuilt assets, causing the rebuild to only work the first time.

Now fixed.

* Add logic for the `now dev cache clean` command (#1977)

* Added the cache-clean command

* censer code :)

* Fix non-route match `dest` param

This makes the `go-image-to-ascii` work, since the query param URL gets
properly routed to the `/` route.

* Add support for `FileBlob` outputs

Fixes `@now/optipng`, `@now/html-minifier` and `@now/md` builders.

* Remove `console.error()` call

* Add `now dev cache clean` command

* Use the `assetKey` to look up the Content-Type on FileBlobs

Instead of the `fsPath` of the entrypoint file.

This fixes `@now/md` to return `text/html` Content-Type instead of
`text/markdown` which does not render properly in the web browser.

* Update `@zeit/ncc` to v0.16.1

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

* Regenerate `yarn.lock` file

* Remove leading `/` on build `src` specifications

* Use `rsync` to copy over all of `fun`'s runtime files

* Update `@zeit/fun` to v0.5.0

* Update `@zeit/fun` to v0.5.1

* try/catch the lambda invoke and send 500 upon error

* Add `rsync` to CircleCI build

* Convert `errors.js` to TypeScript to fix compilation errors

* Also accept `Cache-Control: no-cache` for rebuilding

* Prettier

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

* Update `@zeit/ncc` to v0.17.0 (#2017)

* Install `@zeit/fun` from npm

* Remove `console.error()` call

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

* Create `NowError` subclasses

* Add `LambdaSizeExceededError`

* Return early if there's no builds
2019-04-01 13:01:57 +02:00