-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add hot-hook/register entrypoint loader (#5)
- Loading branch information
1 parent
4d1a480
commit fa6ed2e
Showing
19 changed files
with
353 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
"hot-hook": patch | ||
--- | ||
|
||
This PR adds a new way of configuring hot-hook. This allows you to configure hot-hook without having to modify your codebase. | ||
|
||
We introduce a new `hot-hook/register` entrypoint that can be used with Node.JS's `--import` flag. By using this method, the Hot Hook hook will be loaded at application startup without you needing to use `hot.init` in your codebase. It can be used as follows: | ||
|
||
```bash | ||
node --import=hot-hook/register ./src/index.js | ||
``` | ||
|
||
Be careful if you also use a loader to transpile to TS (`ts-node` or `tsx`), hot-hook must be placed in the second position, after the TS loader : | ||
|
||
```bash | ||
node --import=tsx --import=hot-hook/register ./src/index.ts | ||
``` | ||
|
||
To configure boundaries and other files, you'll need to use your application's `package.json` file, in the `hot-hook` key. For example: | ||
|
||
```jsonc | ||
// package.json | ||
{ | ||
"hot-hook": { | ||
"boundaries": [ | ||
"./src/controllers/**/*.tsx" | ||
] | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import * as http from 'node:http' | ||
|
||
const server = http.createServer(async (request, response) => { | ||
const app = await import('./app.js', import.meta.hot?.boundary) | ||
const app = await import('./app.js') | ||
app.default(request, response) | ||
}) | ||
|
||
server.listen(8080) | ||
server.listen(3000) | ||
|
||
console.log('Server running at http://localhost:8080/') | ||
console.log('Server running at http://localhost:3000/') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { resolve } from 'node:path' | ||
import { hot } from './hot.js' | ||
import { readPackageUp } from 'read-package-up' | ||
|
||
const pkgJson = await readPackageUp() | ||
if (!pkgJson) { | ||
throw new Error('Could not find package.json') | ||
} | ||
|
||
const { packageJson, path: packageJsonPath } = pkgJson | ||
const hotHookConfig = packageJson['hot-hook'] | ||
|
||
await hot.init({ | ||
root: hotHookConfig?.root ? resolve(packageJsonPath, packageJson['hot-hook'].root) : undefined, | ||
boundaries: packageJson['hot-hook']?.boundaries, | ||
ignore: ['**/node_modules/**'].concat(packageJson['hot-hook']?.ignore || []), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.