@c9up/ream 0.2.23 → 0.2.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Codemods.d.ts +1 -0
- package/dist/Codemods.d.ts.map +1 -1
- package/dist/Codemods.js +44 -0
- package/dist/Codemods.js.map +1 -1
- package/dist/Ignitor.d.ts +50 -0
- package/dist/Ignitor.d.ts.map +1 -1
- package/dist/Ignitor.js +15 -15
- package/dist/Ignitor.js.map +1 -1
- package/dist/dev/fullReload.d.ts +23 -0
- package/dist/dev/fullReload.d.ts.map +1 -0
- package/dist/dev/fullReload.js +26 -0
- package/dist/dev/fullReload.js.map +1 -0
- package/dist/dev/hmr.d.ts +52 -4
- package/dist/dev/hmr.d.ts.map +1 -1
- package/dist/dev/hmr.js +75 -9
- package/dist/dev/hmr.js.map +1 -1
- package/dist/dev/hotGlob.d.ts +35 -0
- package/dist/dev/hotGlob.d.ts.map +1 -0
- package/dist/dev/hotGlob.js +92 -0
- package/dist/dev/hotGlob.js.map +1 -0
- package/dist/dev/hotGraph.d.ts +58 -0
- package/dist/dev/hotGraph.d.ts.map +1 -0
- package/dist/dev/hotGraph.js +91 -0
- package/dist/dev/hotGraph.js.map +1 -0
- package/dist/dev/hotWatcher.d.ts +34 -0
- package/dist/dev/hotWatcher.d.ts.map +1 -0
- package/dist/dev/hotWatcher.js +72 -0
- package/dist/dev/hotWatcher.js.map +1 -0
- package/dist/env/loadEnvFiles.d.ts +13 -0
- package/dist/env/loadEnvFiles.d.ts.map +1 -1
- package/dist/env/loadEnvFiles.js +65 -13
- package/dist/env/loadEnvFiles.js.map +1 -1
- package/dist/hot.d.ts +13 -16
- package/dist/hot.d.ts.map +1 -1
- package/dist/hot.js +161 -84
- package/dist/hot.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/events.darwin-arm64.node +0 -0
- package/events.darwin-x64.node +0 -0
- package/events.linux-arm64-gnu.node +0 -0
- package/events.linux-x64-gnu.node +0 -0
- package/events.win32-x64-msvc.node +0 -0
- package/index.darwin-arm64.node +0 -0
- package/index.darwin-x64.node +0 -0
- package/index.linux-arm64-gnu.node +0 -0
- package/index.linux-x64-gnu.node +0 -0
- package/index.win32-x64-msvc.node +0 -0
- package/package.json +4 -7
- package/scheduler.darwin-arm64.node +0 -0
- package/scheduler.darwin-x64.node +0 -0
- package/scheduler.linux-arm64-gnu.node +0 -0
- package/scheduler.linux-x64-gnu.node +0 -0
- package/scheduler.win32-x64-msvc.node +0 -0
- package/src/Codemods.ts +53 -0
- package/src/Ignitor.ts +68 -14
- package/src/dev/fullReload.ts +34 -0
- package/src/dev/hmr.ts +102 -9
- package/src/dev/hotGlob.ts +91 -0
- package/src/dev/hotGraph.ts +109 -0
- package/src/dev/hotWatcher.ts +89 -0
- package/src/env/loadEnvFiles.ts +69 -14
- package/src/hot.ts +169 -102
- package/src/index.ts +1 -1
package/src/env/loadEnvFiles.ts
CHANGED
|
@@ -1,41 +1,82 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs'
|
|
2
|
-
import { fileURLToPath } from 'node:url'
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
3
3
|
import { parseEnv } from 'node:util'
|
|
4
4
|
import { interpolate } from './interpolate.js'
|
|
5
5
|
import { normalizeNodeEnv } from './nodeEnv.js'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* Ignitor (HTTP/console boot) and `Env.create()` (config/test flow), mirroring
|
|
10
|
-
* AdonisJS which loads env in every flow.
|
|
8
|
+
* The `.env*` files that will be read, most-specific first.
|
|
11
9
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* Exported because `@c9up/ream/hot` has to WATCH exactly this list: nothing
|
|
11
|
+
* imports an env file, so hot-hook's dependency tree never sees one and an
|
|
12
|
+
* edit to `.env` changed nothing at all. A second copy of the list in the
|
|
13
|
+
* loader entry would drift from this one the first time the naming changes.
|
|
15
14
|
*
|
|
16
|
-
* @param
|
|
17
|
-
* @param options.skipEnvLocal Skip `.env.local` (the test flow does, so a
|
|
18
|
-
* developer's local overrides don't leak into tests).
|
|
15
|
+
* @param options.skipEnvLocal Skip `.env.local` — see {@link loadEnvFiles}.
|
|
19
16
|
*/
|
|
20
|
-
export function
|
|
17
|
+
export function envFileNames(options: { skipEnvLocal?: boolean } = {}): string[] {
|
|
21
18
|
// Normalised, so `NODE_ENV=prod` loads `.env.production` — the file the
|
|
22
19
|
// deployment actually wrote — instead of looking for `.env.prod`.
|
|
23
20
|
const raw = normalizeNodeEnv(process.env.NODE_ENV)
|
|
24
21
|
const nodeEnv = raw === 'unknown' ? undefined : raw
|
|
25
|
-
|
|
22
|
+
return [
|
|
26
23
|
nodeEnv ? `.env.${nodeEnv}.local` : null,
|
|
27
24
|
options.skipEnvLocal ? null : '.env.local',
|
|
28
25
|
nodeEnv ? `.env.${nodeEnv}` : null,
|
|
29
26
|
'.env',
|
|
30
27
|
].filter((name): name is string => name !== null)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Where the `.env*` files are read from.
|
|
32
|
+
*
|
|
33
|
+
* Normally beside the application, which is what `appRoot` names. A BUILT
|
|
34
|
+
* application moves: `start/env.js` sits in `dist/`, so `new URL('../',
|
|
35
|
+
* import.meta.url)` resolves there and the files at the project root become
|
|
36
|
+
* invisible — `ream start` died on a `.env` it was standing next to.
|
|
37
|
+
*
|
|
38
|
+
* `ENV_PATH` is AdonisJS's own variable for this, named and shaped the same
|
|
39
|
+
* way: a DIRECTORY to read the files from, as in
|
|
40
|
+
* `ENV_PATH=/etc/secrets node server.js`. An application moving over keeps
|
|
41
|
+
* whatever it already sets.
|
|
42
|
+
*
|
|
43
|
+
* It is also why the ordering rule stays here rather than in the CLI: node's
|
|
44
|
+
* `--env-file` applies files last-wins while this loader applies them
|
|
45
|
+
* most-specific-first, and a second copy of that would be one to keep in step
|
|
46
|
+
* forever.
|
|
47
|
+
*/
|
|
48
|
+
function envDirectory(appRoot: URL): URL {
|
|
49
|
+
const override = process.env.ENV_PATH
|
|
50
|
+
if (override === undefined || override.trim() === '') return appRoot
|
|
51
|
+
// A directory URL, so `new URL('.env', directory)` lands inside it rather
|
|
52
|
+
// than beside it.
|
|
53
|
+
return pathToFileURL(override.endsWith('/') ? override : `${override}/`)
|
|
54
|
+
}
|
|
31
55
|
|
|
32
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Load `.env` files into `process.env` — the shared primitive behind both the
|
|
58
|
+
* Ignitor (HTTP/console boot) and `Env.create()` (config/test flow), mirroring
|
|
59
|
+
* AdonisJS which loads env in every flow.
|
|
60
|
+
*
|
|
61
|
+
* Order is most-specific-first and "already-present wins", so the shell / CI
|
|
62
|
+
* always overrides the files. Missing files are skipped silently. Uses Node's
|
|
63
|
+
* built-in parser — no dependency.
|
|
64
|
+
*
|
|
65
|
+
* @param appRoot Directory URL the `.env*` files are resolved against.
|
|
66
|
+
* @param options.skipEnvLocal Skip `.env.local` (the test flow does, so a
|
|
67
|
+
* developer's local overrides don't leak into tests).
|
|
68
|
+
*/
|
|
69
|
+
export function loadEnvFiles(appRoot: URL, options: { skipEnvLocal?: boolean } = {}): void {
|
|
70
|
+
const directory = envDirectory(appRoot)
|
|
71
|
+
let found = false
|
|
72
|
+
for (const name of envFileNames(options)) {
|
|
33
73
|
let contents: string
|
|
34
74
|
try {
|
|
35
|
-
contents = readFileSync(fileURLToPath(new URL(name,
|
|
75
|
+
contents = readFileSync(fileURLToPath(new URL(name, directory)), 'utf8')
|
|
36
76
|
} catch {
|
|
37
77
|
continue // file absent — nothing to load
|
|
38
78
|
}
|
|
79
|
+
found = true
|
|
39
80
|
const parsed = parseEnv(contents)
|
|
40
81
|
for (const [key, value] of Object.entries(parsed)) {
|
|
41
82
|
if (typeof value !== 'string' || process.env[key] !== undefined) continue
|
|
@@ -49,4 +90,18 @@ export function loadEnvFiles(appRoot: URL, options: { skipEnvLocal?: boolean } =
|
|
|
49
90
|
})
|
|
50
91
|
}
|
|
51
92
|
}
|
|
93
|
+
|
|
94
|
+
// Upstream raises when `ENV_PATH` names a place with no env file in it, and
|
|
95
|
+
// for the reason silence would be wrong: the variable is somebody saying
|
|
96
|
+
// where the file IS. A typo in the path would otherwise start a server on
|
|
97
|
+
// whatever defaults happened to be around, which is how a deployment reads
|
|
98
|
+
// its staging config in production and nobody finds out until later.
|
|
99
|
+
//
|
|
100
|
+
// Without `ENV_PATH` a missing file stays silent: an application may have
|
|
101
|
+
// none at all, and every value may come from the environment.
|
|
102
|
+
if (!found && process.env.ENV_PATH !== undefined && process.env.ENV_PATH.trim() !== '') {
|
|
103
|
+
throw new Error(
|
|
104
|
+
`ENV_PATH points at ${process.env.ENV_PATH}, which holds none of ${envFileNames(options).join(', ')}`,
|
|
105
|
+
)
|
|
106
|
+
}
|
|
52
107
|
}
|
package/src/hot.ts
CHANGED
|
@@ -5,132 +5,199 @@
|
|
|
5
5
|
*
|
|
6
6
|
* node --import @swc-node/register/esm-register --import @c9up/ream/hot bin/server.ts
|
|
7
7
|
*
|
|
8
|
-
* It
|
|
9
|
-
*
|
|
10
|
-
* boundary changes it invalidates just that module instead of the process. The
|
|
11
|
-
* `hotHook` key in the application's `package.json` configures it, exactly as
|
|
12
|
-
* upstream reads it.
|
|
8
|
+
* It replaces a module that changed instead of the process that was serving it,
|
|
9
|
+
* so the container, the pools and the connections survive a save.
|
|
13
10
|
*
|
|
14
|
-
* NAMED DEVIATION —
|
|
11
|
+
* NAMED DEVIATION — this is ream's own, where AdonisJS uses `hot-hook`.
|
|
15
12
|
*
|
|
16
|
-
* Upstream
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
13
|
+
* Upstream ships that package in its starter kit, which means every application
|
|
14
|
+
* installs it, and one created before the convention existed silently loses hot
|
|
15
|
+
* reloading. The parts that once justified a library are now in Node:
|
|
16
|
+
* `module.registerHooks` gives the import graph, `fs.watch` gives the changes.
|
|
17
|
+
* What is left is the decision of what to invalidate, which is this file and
|
|
18
|
+
* its three neighbours — and no entry in anyone's `package.json`.
|
|
22
19
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
20
|
+
* The graph comes from the resolver rather than from reading files: a resolve
|
|
21
|
+
* hook is handed the importer and the imported, which is exactly an edge, and
|
|
22
|
+
* it sees a dynamic import at the moment it happens rather than guessing at it
|
|
23
|
+
* from the source.
|
|
27
24
|
*/
|
|
28
25
|
|
|
26
|
+
import { existsSync, writeSync } from 'node:fs'
|
|
27
|
+
import { readFile } from 'node:fs/promises'
|
|
28
|
+
import { registerHooks } from 'node:module'
|
|
29
|
+
import { dirname, relative, resolve as resolvePath } from 'node:path'
|
|
30
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
31
|
+
import { fullReloadNotice } from './dev/fullReload.js'
|
|
29
32
|
import { hotReloadHappened } from './dev/hmr.js'
|
|
30
|
-
import {
|
|
33
|
+
import { readHotHookConfig } from './dev/hotConfig.js'
|
|
34
|
+
import { globMatcher } from './dev/hotGlob.js'
|
|
35
|
+
import { HotGraph } from './dev/hotGraph.js'
|
|
36
|
+
import { watchProject } from './dev/hotWatcher.js'
|
|
37
|
+
import { envFileNames } from './env/loadEnvFiles.js'
|
|
31
38
|
|
|
32
39
|
/** Exit code meaning "restart me" — see `EXIT_RESTART` in the CLI's dev module. */
|
|
33
40
|
const FULL_RELOAD_EXIT_CODE = 75
|
|
34
41
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
restart?: string[]
|
|
41
|
-
ignore?: string[]
|
|
42
|
-
throwWhenBoundariesAreNotDynamicallyImported?: boolean
|
|
43
|
-
onFullReloadAsked?: () => void
|
|
44
|
-
}): Promise<void>
|
|
45
|
-
}
|
|
42
|
+
/** The query parameter that makes the loader fetch a module again. */
|
|
43
|
+
const VERSION_PARAM = 'ream_hot'
|
|
44
|
+
|
|
45
|
+
/** Directories a project keeps its own code in — the CLI watches the same list. */
|
|
46
|
+
const WATCH_DIRS = ['app', 'bin', 'config', 'start', 'database', 'providers', 'commands']
|
|
46
47
|
|
|
47
|
-
const
|
|
48
|
-
const
|
|
48
|
+
const packageJsonPath = resolvePath(process.cwd(), 'package.json')
|
|
49
|
+
const root = dirname(packageJsonPath)
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
let config: HotHookConfig = {}
|
|
51
|
+
let config = {}
|
|
52
52
|
try {
|
|
53
53
|
config = readHotHookConfig(JSON.parse(await readFile(packageJsonPath, 'utf8')))
|
|
54
54
|
} catch {
|
|
55
|
-
// No package.json, or unreadable:
|
|
56
|
-
//
|
|
55
|
+
// No package.json, or unreadable: a project with no boundaries declared gets
|
|
56
|
+
// a working server that restarts on change, which is the old behaviour.
|
|
57
57
|
}
|
|
58
|
+
const { boundaries = [], restart = [] } = config as { boundaries?: string[]; restart?: string[] }
|
|
58
59
|
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
// Env files are not modules: nothing imports one, so the graph never sees them
|
|
61
|
+
// and an edit to `.env` did nothing at all — the values are read once, at boot.
|
|
62
|
+
// They always restart.
|
|
63
|
+
const restartFiles = new Set(
|
|
64
|
+
envFileNames()
|
|
65
|
+
.map((name) => resolvePath(root, name))
|
|
66
|
+
.filter((file) => existsSync(file)),
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* `metaFiles` entries that asked for a restart.
|
|
71
|
+
*
|
|
72
|
+
* Non-module files the application owns — translations, view templates — live
|
|
73
|
+
* in `reamrc.ts` because the BUILD has to copy them. A change to one is
|
|
74
|
+
* invisible to the import graph, so the only way it can do anything in
|
|
75
|
+
* development is by being named here.
|
|
76
|
+
*
|
|
77
|
+
* `reloadServer: false` is the interesting default, and the one upstream picks
|
|
78
|
+
* for translations: the entry exists so the file ships, and an edit does NOT
|
|
79
|
+
* restart. NAMED DEVIATION — upstream still logs such a change, because its
|
|
80
|
+
* watcher covers the whole project anyway. This one watches a fixed list of
|
|
81
|
+
* directories on purpose (`resources/` belongs to the asset watcher, and a
|
|
82
|
+
* stylesheet edit must not restart the server), so a `false` entry is simply
|
|
83
|
+
* not watched. The observable behaviour is the same: nothing happens.
|
|
84
|
+
*/
|
|
85
|
+
async function readReloadPatterns(): Promise<string[]> {
|
|
86
|
+
try {
|
|
87
|
+
const rc = (await import(pathToFileURL(resolvePath(root, 'reamrc.ts')).href)) as {
|
|
88
|
+
default?: { metaFiles?: Array<{ pattern?: unknown; reloadServer?: unknown }> }
|
|
89
|
+
}
|
|
90
|
+
return (rc.default?.metaFiles ?? [])
|
|
91
|
+
.filter((entry) => entry.reloadServer === true && typeof entry.pattern === 'string')
|
|
92
|
+
.map((entry) => String(entry.pattern))
|
|
93
|
+
} catch {
|
|
94
|
+
// No rc file, or one that does not load. The server itself reports a broken
|
|
95
|
+
// rc far more clearly than the loader could, and a dev server that refuses
|
|
96
|
+
// to start because of a watch list helps nobody.
|
|
97
|
+
return []
|
|
98
|
+
}
|
|
66
99
|
}
|
|
67
100
|
|
|
68
|
-
|
|
69
|
-
// no business in a production install of the framework. So it is resolved from
|
|
70
|
-
// the project directory rather than from this file — under pnpm's strict layout
|
|
71
|
-
// a bare `import("hot-hook")` here looks inside @c9up/ream and finds nothing.
|
|
72
|
-
// It is the same reason upstream passes `hot-hook/register` from the app's own
|
|
73
|
-
// cwd instead of re-exporting it from the framework.
|
|
74
|
-
const { createRequire } = await import('node:module')
|
|
75
|
-
const { pathToFileURL } = await import('node:url')
|
|
101
|
+
const reloadPatterns = await readReloadPatterns()
|
|
76
102
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
103
|
+
/**
|
|
104
|
+
* The directory a pattern lives under — everything before its first wildcard.
|
|
105
|
+
*
|
|
106
|
+
* `resources/lang/**\/*.json` is watched as `resources/lang`. Watching the
|
|
107
|
+
* project root instead would pull in `node_modules` and the build output.
|
|
108
|
+
*/
|
|
109
|
+
function watchRootOf(pattern: string): string {
|
|
110
|
+
const segments = pattern.replace(/^\.\//, '').split('/')
|
|
111
|
+
const fixed: string[] = []
|
|
112
|
+
for (const segment of segments) {
|
|
113
|
+
if (/[*?{[]/.test(segment)) break
|
|
114
|
+
fixed.push(segment)
|
|
85
115
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// Loud, and it names the fix. Silence here would start a perfectly healthy
|
|
89
|
-
// server that never picks up an edit, which reads as "HMR is broken" rather
|
|
90
|
-
// than "HMR is not installed".
|
|
91
|
-
//
|
|
92
|
-
// It does NOT throw: a dev server that refuses to start is worse than one
|
|
93
|
-
// without hot reloading, and the CLI only loads this file when it has
|
|
94
|
-
// already seen hot-hook in the project — so reaching here means it went
|
|
95
|
-
// missing under a running session.
|
|
96
|
-
console.error(
|
|
97
|
-
`[ream] hot module replacement is unavailable: ${error instanceof Error ? error.message : String(error)}\n` +
|
|
98
|
-
'[ream] Install it with: pnpm add -D hot-hook, then restart `ream dev`.\n' +
|
|
99
|
-
'[ream] Until then the server runs, but an edit will not be picked up.',
|
|
100
|
-
)
|
|
116
|
+
// A pattern that is a bare glob has no directory to narrow to.
|
|
117
|
+
return fixed.slice(0, -1).join('/') || fixed.join('/')
|
|
101
118
|
}
|
|
102
119
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
const relativeToRoot = (file: string): string => relative(root, file).replace(/\\/g, '/')
|
|
121
|
+
const matchesBoundary = globMatcher(boundaries)
|
|
122
|
+
const matchesRestartGlob = globMatcher([...restart, ...reloadPatterns])
|
|
123
|
+
|
|
124
|
+
const graph = new HotGraph({
|
|
125
|
+
isBoundary: (file) => matchesBoundary(relativeToRoot(file)),
|
|
126
|
+
isRestart: (file) => restartFiles.has(file) || matchesRestartGlob(relativeToRoot(file)),
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Track every edge the resolver reports, and hand back a versioned URL for a
|
|
131
|
+
* module that has been invalidated.
|
|
132
|
+
*
|
|
133
|
+
* The version travels in the URL because that is the only handle V8 offers: a
|
|
134
|
+
* module is keyed by its URL, so a different one is a different module. The
|
|
135
|
+
* parameter is stripped off the importer before delegating, or a relative
|
|
136
|
+
* specifier would be resolved against a URL that does not name a directory.
|
|
137
|
+
*/
|
|
138
|
+
registerHooks({
|
|
139
|
+
resolve(specifier, context, nextResolve) {
|
|
140
|
+
let parentURL = context.parentURL
|
|
141
|
+
let parentPath: string | undefined
|
|
142
|
+
if (typeof parentURL === 'string' && parentURL.startsWith('file:')) {
|
|
143
|
+
const url = new URL(parentURL)
|
|
144
|
+
if (url.searchParams.has(VERSION_PARAM)) {
|
|
145
|
+
url.searchParams.delete(VERSION_PARAM)
|
|
146
|
+
parentURL = url.href
|
|
147
|
+
}
|
|
148
|
+
parentPath = fileURLToPath(url)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const result = nextResolve(specifier, { ...context, parentURL })
|
|
152
|
+
if (!result.url.startsWith('file:')) return result
|
|
153
|
+
|
|
154
|
+
const resolved = new URL(result.url)
|
|
155
|
+
resolved.searchParams.delete(VERSION_PARAM)
|
|
156
|
+
const file = fileURLToPath(resolved)
|
|
157
|
+
graph.link(file, parentPath)
|
|
158
|
+
|
|
159
|
+
const version = graph.version(file)
|
|
160
|
+
if (version === 0) return result
|
|
161
|
+
resolved.searchParams.set(VERSION_PARAM, String(version))
|
|
162
|
+
return { ...result, url: resolved.href }
|
|
163
|
+
},
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
/** Print a line that must survive the exit on the very next statement. */
|
|
167
|
+
function sayNow(line: string): void {
|
|
168
|
+
// Synchronously: a piped stdout — what `ream dev` hands this process when it
|
|
169
|
+
// runs an asset watcher alongside — is asynchronous, and the line would be
|
|
170
|
+
// dropped on the way out.
|
|
171
|
+
try {
|
|
172
|
+
writeSync(1, `${line}\n`)
|
|
173
|
+
} catch {
|
|
174
|
+
// The parent can close the pipe first on Ctrl-C. Losing the line is fine.
|
|
125
175
|
}
|
|
126
|
-
return true
|
|
127
176
|
}
|
|
128
177
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
178
|
+
watchProject({
|
|
179
|
+
root,
|
|
180
|
+
directories: [
|
|
181
|
+
...WATCH_DIRS,
|
|
182
|
+
// Whatever a `reloadServer: true` entry named, and nothing else: the
|
|
183
|
+
// directories above are the ones the graph can reason about.
|
|
184
|
+
...reloadPatterns.map(watchRootOf).filter((dir) => dir !== ''),
|
|
185
|
+
],
|
|
186
|
+
files: [...restartFiles].map((file) => relative(root, file)),
|
|
187
|
+
onChange: (file) => {
|
|
188
|
+
const decision = graph.decide(file)
|
|
189
|
+
if (decision.kind === 'ignore') return
|
|
190
|
+
if (decision.kind === 'reload') {
|
|
191
|
+
sayNow(fullReloadNotice(decision.file, decision.reason, relativeToRoot))
|
|
192
|
+
// Exiting on a known code is how the Rust parent learns it must restart —
|
|
193
|
+
// see `EXIT_RESTART` in the CLI's dev module.
|
|
194
|
+
process.exit(FULL_RELOAD_EXIT_CODE)
|
|
195
|
+
}
|
|
196
|
+
// The router caches a promoted controller per route, and the kernel drops
|
|
197
|
+
// that cache when this counter moves. Without it the swap happens and the
|
|
198
|
+
// process keeps serving the class it promoted: a stable PID and stale
|
|
199
|
+
// output, which is exactly how it was first reported.
|
|
200
|
+
hotReloadHappened()
|
|
201
|
+
sayNow(`[ream] hot swap — ${relativeToRoot(file)}`)
|
|
202
|
+
},
|
|
136
203
|
})
|
package/src/index.ts
CHANGED