brick-break 1.2.1 → 1.3.1
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/README.md +9 -1
- package/dist/cli.js +54 -8
- package/dist/next.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,7 +56,15 @@ if it can fail, brick-break can make it funnier.
|
|
|
56
56
|
|
|
57
57
|
## next.js hmr support
|
|
58
58
|
|
|
59
|
-
for errors that happen while the dev server is running (hot reload)
|
|
59
|
+
for errors that happen while the dev server is running (hot reload):
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
bb init
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
this automatically adds `<BrickBreak />` to your layout.tsx.
|
|
66
|
+
|
|
67
|
+
or add it manually:
|
|
60
68
|
|
|
61
69
|
```tsx
|
|
62
70
|
// app/layout.tsx
|
package/dist/cli.js
CHANGED
|
@@ -2,21 +2,67 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const index_1 = require("./index");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
5
7
|
const args = process.argv.slice(2);
|
|
6
8
|
if (!args.length) {
|
|
7
9
|
console.log('usage: bb <command>');
|
|
10
|
+
console.log(' bb init - setup next.js hmr support');
|
|
8
11
|
console.log('example: bb npm run build');
|
|
9
12
|
process.exit(1);
|
|
10
13
|
}
|
|
11
|
-
//
|
|
14
|
+
// handle init command
|
|
15
|
+
if (args[0] === 'init') {
|
|
16
|
+
const layoutPaths = [
|
|
17
|
+
(0, path_1.join)(process.cwd(), 'app/layout.tsx'),
|
|
18
|
+
(0, path_1.join)(process.cwd(), 'src/app/layout.tsx'),
|
|
19
|
+
(0, path_1.join)(process.cwd(), 'app/layout.jsx'),
|
|
20
|
+
(0, path_1.join)(process.cwd(), 'src/app/layout.jsx'),
|
|
21
|
+
];
|
|
22
|
+
const layoutPath = layoutPaths.find(p => (0, fs_1.existsSync)(p));
|
|
23
|
+
if (!layoutPath) {
|
|
24
|
+
console.log('\x1b[31merror: no layout.tsx found\x1b[0m');
|
|
25
|
+
console.log('make sure you are in a next.js project root');
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
let content = (0, fs_1.readFileSync)(layoutPath, 'utf-8');
|
|
29
|
+
if (content.includes('brick-break')) {
|
|
30
|
+
console.log('\x1b[33mbrick-break already installed in layout\x1b[0m');
|
|
31
|
+
process.exit(0);
|
|
32
|
+
}
|
|
33
|
+
// add import at the top (after other imports or 'use client')
|
|
34
|
+
const importLine = "import { BrickBreak } from 'brick-break/next'\n";
|
|
35
|
+
if (content.includes("'use client'") || content.includes('"use client"')) {
|
|
36
|
+
content = content.replace(/(["']use client["'][\s\n]*)/, `$1${importLine}`);
|
|
37
|
+
}
|
|
38
|
+
else if (content.includes('import ')) {
|
|
39
|
+
content = content.replace(/(import .+\n)/, `${importLine}$1`);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
content = importLine + content;
|
|
43
|
+
}
|
|
44
|
+
// add <BrickBreak /> after <body> or <body ...>
|
|
45
|
+
content = content.replace(/(<body[^>]*>)(\s*)/, '$1$2<BrickBreak />\n ');
|
|
46
|
+
(0, fs_1.writeFileSync)(layoutPath, content);
|
|
47
|
+
console.log('\x1b[32m✓ added BrickBreak to ' + layoutPath + '\x1b[0m');
|
|
48
|
+
console.log('hmr errors will now play the sound');
|
|
49
|
+
process.exit(0);
|
|
50
|
+
}
|
|
51
|
+
// detect next.js dev mode - show hint if not already setup
|
|
12
52
|
const isNextDev = args.some(a => a.includes('next')) && args.some(a => a === 'dev');
|
|
13
53
|
if (isNextDev) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
54
|
+
const layoutPaths = [
|
|
55
|
+
(0, path_1.join)(process.cwd(), 'app/layout.tsx'),
|
|
56
|
+
(0, path_1.join)(process.cwd(), 'src/app/layout.tsx'),
|
|
57
|
+
(0, path_1.join)(process.cwd(), 'app/layout.jsx'),
|
|
58
|
+
(0, path_1.join)(process.cwd(), 'src/app/layout.jsx'),
|
|
59
|
+
];
|
|
60
|
+
const layoutPath = layoutPaths.find(p => (0, fs_1.existsSync)(p));
|
|
61
|
+
const alreadySetup = layoutPath && (0, fs_1.readFileSync)(layoutPath, 'utf-8').includes('brick-break');
|
|
62
|
+
if (!alreadySetup) {
|
|
63
|
+
console.log('\x1b[36m');
|
|
64
|
+
console.log('brick-break: for hmr error sounds, run: bb init');
|
|
65
|
+
console.log('\x1b[0m');
|
|
66
|
+
}
|
|
21
67
|
}
|
|
22
68
|
(0, index_1.runCommand)(args);
|
package/dist/next.js
CHANGED
|
@@ -20,10 +20,10 @@ function BrickBreak({ children }) {
|
|
|
20
20
|
if (process.env.NODE_ENV !== 'development')
|
|
21
21
|
return;
|
|
22
22
|
const observer = new MutationObserver(() => {
|
|
23
|
-
// nextjs error overlay
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
26
|
-
const errorText =
|
|
23
|
+
// nextjs error overlay (nextjs 16+ uses nextjs-portal)
|
|
24
|
+
const portal = document.querySelector('nextjs-portal');
|
|
25
|
+
if (portal) {
|
|
26
|
+
const errorText = portal.textContent || '';
|
|
27
27
|
if (!seenErrors.current.has(errorText)) {
|
|
28
28
|
seenErrors.current.add(errorText);
|
|
29
29
|
playSound();
|