Skip to content

Commit

Permalink
Merge pull request #19 from ericclemmons/19-execArgv
Browse files Browse the repository at this point in the history
Support "-r" flags via child_process.fork/spawn?
  • Loading branch information
ericclemmons committed Jan 29, 2019
2 parents 1cd6781 + cd9f1f8 commit 57adae2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -47,6 +47,8 @@ For customizing the `node` runtime, you can use `NODE_OPTIONS`.
For example, [TypeScript][typescript] can be enabled via [ts-node][ts-node]:

```shell
polydev --require ts-node/register
# Or
NODE_OPTIONS="--require ts-node/register" polydev
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"private": true,
"scripts": {
"postinstall": "yarn workspace polydev link",
"dev": "DEBUG=polydev polydev",
"dev": "DEBUG=polydev polydev -r ts-node/register",
"dev:server": "DEBUG=polydev node server",
"release": "cd packages/polydev && npx np --yolo",
"prestart": "yarn workspace next-example build",
Expand Down
2 changes: 2 additions & 0 deletions packages/polydev/README.md
Expand Up @@ -47,6 +47,8 @@ For customizing the `node` runtime, you can use `NODE_OPTIONS`.
For example, [TypeScript][typescript] can be enabled via [ts-node][ts-node]:

```shell
polydev --require ts-node/register
# Or
NODE_OPTIONS="--require ts-node/register" polydev
```

Expand Down
14 changes: 13 additions & 1 deletion packages/polydev/bin/polydev
@@ -1,3 +1,15 @@
#!/usr/bin/env node

require("../src/server")
const child_process = require("child_process")
const path = require("path")

const serverPath = path.resolve(__dirname, "../src/server.js")
const [, , ...args] = process.argv

// Remove polydev custom flags
const execArgv = args.filter(arg => !["--open"].includes(arg))

// Spawn server via node + flags
child_process.fork(serverPath, args, {
execArgv
})
2 changes: 2 additions & 0 deletions packages/polydev/src/middleware/router/launcher.js
Expand Up @@ -31,10 +31,12 @@ async function startHandler() {
// Next.js returns a Promise for when the server is ready
let handler = await getLatestHandler()

// @ts-ignore
if (module.hot) {
let recentlySaved = false

if (typeof handler === "function") {
// @ts-ignore
module.hot.accept(handlerPath, async () => {
if (recentlySaved) {
console.log(`♻️ Restarting ${handlerPath}`)
Expand Down

0 comments on commit 57adae2

Please sign in to comment.