@byline/cli 0.10.5 → 0.10.6
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.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Browser-only stub for `node:async_hooks`. Aliased into the client
|
|
2
|
+
// environment by vite.config.ts so @byline/core's logger module can
|
|
3
|
+
// destructure `AsyncLocalStorage` without tripping Vite's
|
|
4
|
+
// "module externalized for browser compatibility" warnings.
|
|
5
|
+
//
|
|
6
|
+
// The runtime behaviour matches @byline/core's own no-op fallback —
|
|
7
|
+
// store reads return undefined and `run` just invokes the callback.
|
|
8
|
+
|
|
9
|
+
export class AsyncLocalStorage<T> {
|
|
10
|
+
getStore(): T | undefined {
|
|
11
|
+
return undefined
|
|
12
|
+
}
|
|
13
|
+
run<R>(_store: T, fn: (...args: unknown[]) => R, ...args: unknown[]): R {
|
|
14
|
+
return fn(...args)
|
|
15
|
+
}
|
|
16
|
+
enterWith(_store: T): void {}
|
|
17
|
+
disable(): void {}
|
|
18
|
+
exit<R>(fn: (...args: unknown[]) => R, ...args: unknown[]): R {
|
|
19
|
+
return fn(...args)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -4,7 +4,32 @@ import { tanstackStart } from '@tanstack/react-start/plugin/vite'
|
|
|
4
4
|
import tailwindcss from '@tailwindcss/vite'
|
|
5
5
|
import viteReact from '@vitejs/plugin-react'
|
|
6
6
|
import { nitro } from 'nitro/vite'
|
|
7
|
-
import {
|
|
7
|
+
import { fileURLToPath } from 'node:url'
|
|
8
|
+
import { defineConfig, type Plugin } from 'vite'
|
|
9
|
+
|
|
10
|
+
// Browser-only stub for `node:async_hooks`. @byline/core's logger module does
|
|
11
|
+
// `await import('node:async_hooks')` at top level and falls back to a no-op
|
|
12
|
+
// store on failure — but Vite's externalized-Node-builtin shim warns on every
|
|
13
|
+
// property access (including `.then`), polluting the dev console. Aliasing to
|
|
14
|
+
// our own shim short-circuits the warnings while preserving identical runtime
|
|
15
|
+
// behaviour. SSR keeps the real Node module via the unscoped import.
|
|
16
|
+
const browserAsyncHooksShim = fileURLToPath(
|
|
17
|
+
new URL('./byline/async-hooks.browser.ts', import.meta.url),
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
// Vite plugin form of the alias above. `EnvironmentResolveOptions.alias`
|
|
21
|
+
// doesn't exist in Vite 8's per-environment types, so we scope the
|
|
22
|
+
// rewrite via `this.environment.name` inside `resolveId`. SSR keeps the
|
|
23
|
+
// real Node module untouched.
|
|
24
|
+
const browserAsyncHooksAlias = (): Plugin => ({
|
|
25
|
+
name: 'byline:browser-async-hooks-alias',
|
|
26
|
+
enforce: 'pre',
|
|
27
|
+
resolveId(source) {
|
|
28
|
+
if (source !== 'node:async_hooks') return null
|
|
29
|
+
if (this.environment?.name !== 'client') return null
|
|
30
|
+
return browserAsyncHooksShim
|
|
31
|
+
},
|
|
32
|
+
})
|
|
8
33
|
|
|
9
34
|
// Inline every `@byline/*` package through Vite's SSR pipeline. The
|
|
10
35
|
// regex catches future packages without requiring a config edit. The
|
|
@@ -36,37 +61,59 @@ const config = defineConfig({
|
|
|
36
61
|
tsconfigPaths: true,
|
|
37
62
|
},
|
|
38
63
|
environments: {
|
|
39
|
-
// In Vite 8's environments API, per-environment `optimizeDeps`
|
|
40
|
-
//
|
|
41
|
-
// plugin
|
|
42
|
-
// own entries, which
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
// We therefore place our client-side pre-bundling overrides here,
|
|
46
|
-
// alongside the SSR resolver config.
|
|
47
|
-
//
|
|
48
|
-
// `@base-ui/react` and `@base-ui/utils` need eager pre-bundling for
|
|
49
|
-
// two reasons working in tension:
|
|
50
|
-
//
|
|
51
|
-
// 1. `@base-ui/utils/store/useStore` imports `use-sync-external-
|
|
52
|
-
// store/shim`, which is pure CJS (`module.exports = require(…)`).
|
|
53
|
-
// Vite's CJS-to-ESM conversion can fail to synthesise the named
|
|
54
|
-
// `useSyncExternalStore` export when the module is discovered
|
|
55
|
-
// mid-graph — the browser then throws SyntaxError on first import.
|
|
56
|
-
// Pre-bundling as an upfront optimisation unit fixes synthesis.
|
|
57
|
-
//
|
|
58
|
-
// 2. @byline/ui imports many @base-ui/react subpaths (`/accordion`,
|
|
59
|
-
// `/dialog`, etc.) and each LATE discovery triggers a re-optimise
|
|
60
|
-
// that shifts cache hashes — leaving in-flight imports referencing
|
|
61
|
-
// old hashes. Eager `include` brings them into the first
|
|
62
|
-
// optimisation pass and reduces re-optimisation churn.
|
|
64
|
+
// In Vite 8's environments API, per-environment `optimizeDeps` and
|
|
65
|
+
// `resolve` take precedence over root-level equivalents. TanStack Start's
|
|
66
|
+
// plugin populates `environments.client.optimizeDeps.include` with its
|
|
67
|
+
// own entries, which supersedes any root-level include. Client-side
|
|
68
|
+
// pre-bundling overrides therefore live here, alongside the SSR
|
|
69
|
+
// resolver config.
|
|
63
70
|
client: {
|
|
64
71
|
optimizeDeps: {
|
|
72
|
+
// Vite's `resolve.alias` runs in its own request pipeline — it does
|
|
73
|
+
// NOT propagate into the dep-optimizer's pre-bundle pass. @byline/core
|
|
74
|
+
// is pre-bundled, so we additionally rewrite `node:async_hooks` inside
|
|
75
|
+
// Rolldown. Without this, the optimized chunk keeps a bare
|
|
76
|
+
// `import('node:async_hooks')` that Vite's runtime then resolves to
|
|
77
|
+
// its noisy browser-external stub.
|
|
78
|
+
rolldownOptions: {
|
|
79
|
+
plugins: [
|
|
80
|
+
{
|
|
81
|
+
name: 'alias-node-async-hooks',
|
|
82
|
+
resolveId(source) {
|
|
83
|
+
if (source === 'node:async_hooks') {
|
|
84
|
+
return browserAsyncHooksShim
|
|
85
|
+
}
|
|
86
|
+
return null
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
65
91
|
include: [
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
92
|
+
// Force pre-bundling of these @byline/ui subpaths so the dep
|
|
93
|
+
// optimizer walks into them and inlines their CJS deps — notably
|
|
94
|
+
// `@base-ui/utils/store/useStore` and `use-sync-external-store/shim`.
|
|
95
|
+
//
|
|
96
|
+
// Without this, those CJS modules are reached via Vite's regular
|
|
97
|
+
// module pipeline at runtime, where the on-the-fly CJS->ESM interop
|
|
98
|
+
// can fail to synthesise the named `useSyncExternalStore` export.
|
|
99
|
+
// The browser then throws a SyntaxError, the route never hydrates,
|
|
100
|
+
// and forms fall back to native GET behaviour.
|
|
101
|
+
//
|
|
102
|
+
// A workspace consumer (e.g. apps/webapp inside the bylinecms.dev
|
|
103
|
+
// monorepo) doesn't strictly need this list — Vite's scanner walks
|
|
104
|
+
// workspace source directly and auto-discovers each @base-ui/react
|
|
105
|
+
// subpath. Published @byline/ui pre-bundles as a single artifact,
|
|
106
|
+
// so the scanner never sees those subpaths and they leak through to
|
|
107
|
+
// runtime CJS interop. Listing the subpaths here is harmless in the
|
|
108
|
+
// workspace case and required in the published case.
|
|
109
|
+
//
|
|
110
|
+
// We intentionally do NOT pre-bundle @byline/host-tanstack-start
|
|
111
|
+
// subpaths — they transitively pull in @tanstack/start-server-core,
|
|
112
|
+
// which references Vite-virtual modules (e.g.
|
|
113
|
+
// `tanstack-start-injected-head-scripts:v`) that the dep optimizer
|
|
114
|
+
// cannot resolve.
|
|
115
|
+
'@byline/ui/react/admin',
|
|
116
|
+
'@byline/ui/react/services',
|
|
70
117
|
],
|
|
71
118
|
},
|
|
72
119
|
},
|
|
@@ -84,6 +131,7 @@ const config = defineConfig({
|
|
|
84
131
|
exclude: ssrExternal,
|
|
85
132
|
},
|
|
86
133
|
plugins: [
|
|
134
|
+
browserAsyncHooksAlias(),
|
|
87
135
|
devtools(),
|
|
88
136
|
nitro({
|
|
89
137
|
// @byline/ui ships compiled JS that does `import './foo_module.css'`.
|
|
@@ -99,7 +147,7 @@ const config = defineConfig({
|
|
|
99
147
|
// bundled, so we externalize it (and other native deps) here at
|
|
100
148
|
// the Nitro level — Vite's `ssr.external` only applies to Vite's
|
|
101
149
|
// own builder, not Nitro's.
|
|
102
|
-
|
|
150
|
+
rolldownConfig: {
|
|
103
151
|
external: [
|
|
104
152
|
// Explicit problem-packages kept external so Node resolves them
|
|
105
153
|
// as singletons from the module cache at runtime.
|
|
@@ -115,7 +163,7 @@ const config = defineConfig({
|
|
|
115
163
|
// throws: "Cannot read properties of null (reading
|
|
116
164
|
// 'useSyncExternalStore')".
|
|
117
165
|
//
|
|
118
|
-
// Marking react/react-dom as
|
|
166
|
+
// Marking react/react-dom as bundler externals forces `_libs` to
|
|
119
167
|
// emit `__require('react')` instead of inlining a closure, so both
|
|
120
168
|
// code paths hit the same Node.js module-cache singleton.
|
|
121
169
|
'react',
|