@se-studio/project-build 1.1.17 → 1.1.19

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @se-studio/project-build
2
2
 
3
+ ## 1.1.19
4
+
5
+ ### Patch Changes
6
+
7
+ - 5bbdab9: Document that npm trusted publishing / Release Main configure scripts live at the monorepo root (`scripts/configure-npm-trusted-publishers.sh`, `docs/NPM_TRUSTED_PUBLISHING.md`), not inside this package.
8
+
9
+ ## 1.1.18
10
+
11
+ ### Patch Changes
12
+
13
+ - next dev drops the React debug channel that crashes Chrome on large directories.
14
+
3
15
  ## 1.1.17
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -23,6 +23,13 @@ This package is used by the following apps (and others) for the Tailwind build s
23
23
  - CMS configuration utilities
24
24
  - Environment management
25
25
 
26
+ ### Repo-root npm release scripts (not in this package)
27
+
28
+ Trusted publishing for `@se-studio/*` is configured from the monorepo root via
29
+ `./scripts/configure-npm-trusted-publishers.sh` (workflow `release-main.yml`).
30
+ See [`docs/NPM_TRUSTED_PUBLISHING.md`](../../docs/NPM_TRUSTED_PUBLISHING.md).
31
+ CI Dev versions packages on `dev`; Release Main publishes from `main` only.
32
+
26
33
  ## Installation
27
34
 
28
35
  ```bash
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Dev-only drop of Next's React debug channel.
3
+ *
4
+ * Next 16.3.8 has no config switch for that channel. It replays the Flight
5
+ * debug graph into the browser over the HMR socket. A large page (a directory
6
+ * of cards) crashes the Chrome renderer. Production builds never open it.
7
+ *
8
+ * The client gets an empty stream that stays open. Closing it makes Flight
9
+ * throw "Connection closed" and the page fails to hydrate. The server drains
10
+ * the readable and does not send chunks to the tab. Turbopack HMR is separate.
11
+ *
12
+ * `pnpm install` restores Next. The next `next dev` start applies this again.
13
+ * Called from ensureNextDevFlightPatch so existing next.config.ts files pick
14
+ * it up. Idempotent.
15
+ */
16
+ const fs = require('node:fs');
17
+ const path = require('node:path');
18
+
19
+ const MARKER = 'se-lab-drop-browser-debug-channel';
20
+
21
+ const PRODUCTION_PHASES = new Set([
22
+ 'phase-production-build',
23
+ 'phase-production-server',
24
+ 'phase-export',
25
+ ]);
26
+
27
+ const CLIENT_FILES = ['dist/client/dev/debug-channel.js', 'dist/esm/client/dev/debug-channel.js'];
28
+
29
+ const SERVER_FILES = ['dist/server/dev/debug-channel.js', 'dist/esm/server/dev/debug-channel.js'];
30
+
31
+ function shouldPatch(env = process.env) {
32
+ if (env.NODE_ENV === 'production') {
33
+ return false;
34
+ }
35
+ const phase = env.NEXT_PHASE;
36
+ return !(phase && PRODUCTION_PHASES.has(phase));
37
+ }
38
+
39
+ function nextRoot(cwd) {
40
+ return path.join(cwd, 'node_modules', 'next');
41
+ }
42
+
43
+ function omittedChannelReturn() {
44
+ return ` // ${MARKER}\n return { readable: new ReadableStream() };\n`;
45
+ }
46
+
47
+ function droppingPairReturn() {
48
+ return ` // ${MARKER}\n return { readable: new ReadableStream({ start(controller) { controller.close(); } }), writer: { ready: Promise.resolve(), write() { return Promise.resolve(); }, close() { return Promise.resolve(); }, closed: Promise.resolve() } };\n`;
49
+ }
50
+
51
+ function patchClient(source) {
52
+ const closedReturn =
53
+ ' return { readable: new ReadableStream({ start(controller) { controller.close(); } }) };\n';
54
+ if (source.includes(MARKER)) {
55
+ const next = source
56
+ .replace(
57
+ `function createDebugChannel(requestHeaders) {\n // ${MARKER}\n${closedReturn}`,
58
+ `function createDebugChannel(requestHeaders) {\n${omittedChannelReturn()}`,
59
+ )
60
+ .replace(
61
+ `function createDebugChannel(requestHeaders) {\n // ${MARKER}\n return {};\n`,
62
+ `function createDebugChannel(requestHeaders) {\n${omittedChannelReturn()}`,
63
+ );
64
+ return { source: next, changed: next !== source };
65
+ }
66
+ let next = source.replace(
67
+ 'function createDebugChannel(requestHeaders) {\n',
68
+ `function createDebugChannel(requestHeaders) {\n${omittedChannelReturn()}`,
69
+ );
70
+ next = next.replace(
71
+ 'function getOrCreateDebugChannelReadableWriterPair(requestId) {\n',
72
+ `function getOrCreateDebugChannelReadableWriterPair(requestId) {\n${droppingPairReturn()}`,
73
+ );
74
+ if (next === source) {
75
+ return { source, changed: false, missing: true };
76
+ }
77
+ return { source: next, changed: true };
78
+ }
79
+
80
+ function drainFunction(exportKeyword) {
81
+ const prefix = exportKeyword ? 'export function' : 'function';
82
+ return `${prefix} connectReactDebugChannel(requestId, debugChannel, sendToClient) {
83
+ // ${MARKER}
84
+ const readable = debugChannel && debugChannel.readable;
85
+ if (readable instanceof ReadableStream) {
86
+ readable.pipeTo(new WritableStream()).catch(() => {});
87
+ } else if (readable && typeof readable.resume === 'function') {
88
+ readable.resume();
89
+ if (typeof readable.on === 'function') {
90
+ readable.on('error', () => {});
91
+ }
92
+ }
93
+ }
94
+ `;
95
+ }
96
+
97
+ function patchServer(source) {
98
+ if (source.includes(MARKER)) {
99
+ return { source, changed: false };
100
+ }
101
+ const exported = source.includes('export function connectReactDebugChannel');
102
+ const start = source.indexOf(
103
+ exported ? 'export function connectReactDebugChannel(' : 'function connectReactDebugChannel(',
104
+ );
105
+ const endToken = exported
106
+ ? '\nexport function connectReactDebugChannelForHtmlRequest'
107
+ : '\nfunction connectReactDebugChannelForHtmlRequest';
108
+ const end = source.indexOf(endToken);
109
+ if (start === -1 || end === -1 || end <= start) {
110
+ return { source, changed: false, missing: true };
111
+ }
112
+ const next = source.slice(0, start) + drainFunction(exported) + source.slice(end + 1);
113
+ return { source: next, changed: true };
114
+ }
115
+
116
+ function writeIfChanged(filePath, patch) {
117
+ if (!fs.existsSync(filePath)) {
118
+ console.warn(`[patch-next-dev-browser-debug] missing ${filePath}`);
119
+ return 'missing';
120
+ }
121
+ const source = fs.readFileSync(filePath, 'utf8');
122
+ const result = patch(source);
123
+ if (result.missing) {
124
+ console.warn(`[patch-next-dev-browser-debug] pattern missing in ${filePath}`);
125
+ return 'missing';
126
+ }
127
+ if (!result.changed) {
128
+ return 'already';
129
+ }
130
+ fs.writeFileSync(filePath, result.source);
131
+ return 'patched';
132
+ }
133
+
134
+ function ensureNextDevBrowserDebugPatch(cwd = process.cwd(), env = process.env) {
135
+ if (!shouldPatch(env)) {
136
+ return null;
137
+ }
138
+ const root = nextRoot(cwd);
139
+ const counts = { patched: 0, already: 0, missing: 0 };
140
+ for (const relativePath of CLIENT_FILES) {
141
+ const status = writeIfChanged(path.join(root, relativePath), patchClient);
142
+ counts[status] += 1;
143
+ }
144
+ for (const relativePath of SERVER_FILES) {
145
+ const status = writeIfChanged(path.join(root, relativePath), patchServer);
146
+ counts[status] += 1;
147
+ }
148
+ console.log(
149
+ `[patch-next-dev-browser-debug] done: ${counts.patched} patched, ${counts.already} already patched, ${counts.missing} pattern-missing`,
150
+ );
151
+ return counts;
152
+ }
153
+
154
+ module.exports = {
155
+ ensureNextDevBrowserDebugPatch,
156
+ };
157
+
158
+ if (require.main === module) {
159
+ ensureNextDevBrowserDebugPatch();
160
+ }
@@ -8,6 +8,7 @@
8
8
  */
9
9
  const { spawnSync } = require('node:child_process');
10
10
  const path = require('node:path');
11
+ const { ensureNextDevBrowserDebugPatch } = require('./patch-next-browser-debug.cjs');
11
12
 
12
13
  const PRODUCTION_PHASES = new Set([
13
14
  'phase-production-build',
@@ -40,10 +41,12 @@ function ensureNextDevFlightPatch(cwd = process.cwd(), env = process.env) {
40
41
  `patch-next-flight-debuginfo exited ${result.status ?? 'null'} (signal ${result.signal ?? 'none'})`,
41
42
  );
42
43
  }
44
+ ensureNextDevBrowserDebugPatch(cwd, env);
43
45
  return 0;
44
46
  }
45
47
 
46
48
  module.exports = {
47
49
  ensureNextDevFlightPatch,
50
+ ensureNextDevBrowserDebugPatch,
48
51
  shouldPatchNextDevFlight,
49
52
  };
@@ -2,3 +2,9 @@ export function shouldPatchNextDevFlight(env?: NodeJS.ProcessEnv): boolean;
2
2
 
3
3
  /** Returns null when skipped (production). Returns 0 after a successful patch. */
4
4
  export function ensureNextDevFlightPatch(cwd?: string, env?: NodeJS.ProcessEnv): number | null;
5
+
6
+ /** Drops the Next dev React debug channel. Returns null in production. */
7
+ export function ensureNextDevBrowserDebugPatch(
8
+ cwd?: string,
9
+ env?: NodeJS.ProcessEnv,
10
+ ): { patched: number; already: number; missing: number } | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@se-studio/project-build",
3
- "version": "1.1.17",
3
+ "version": "1.1.19",
4
4
  "description": "Build tools and management scripts for SE Studio projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -81,7 +81,7 @@
81
81
  "vitest": "^5.0.3"
82
82
  },
83
83
  "scripts": {
84
- "build": "tsc --project tsconfig.build.json && cp src/patch-next-dev.cjs src/patch-next-dev.d.ts dist/",
84
+ "build": "tsc --project tsconfig.build.json && cp src/patch-next-dev.cjs src/patch-next-dev.d.ts src/patch-next-browser-debug.cjs dist/",
85
85
  "dev": "tsc --project tsconfig.build.json --watch",
86
86
  "type-check": "tsc --noEmit",
87
87
  "lint": "biome lint .",