brick-break 1.1.0 → 1.2.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 CHANGED
@@ -54,12 +54,36 @@ bb go build
54
54
 
55
55
  if it can fail, brick-break can make it funnier.
56
56
 
57
+ ## next.js hmr support
58
+
59
+ for errors that happen while the dev server is running (hot reload), add the component to your layout:
60
+
61
+ ```tsx
62
+ // app/layout.tsx
63
+ import { BrickBreak } from 'brick-break/next'
64
+
65
+ export default function RootLayout({ children }) {
66
+ return (
67
+ <html>
68
+ <body>
69
+ <BrickBreak />
70
+ {children}
71
+ </body>
72
+ </html>
73
+ )
74
+ }
75
+ ```
76
+
77
+ now errors play the sound even during hot reload.
78
+
57
79
  ## how it works
58
80
 
59
81
  1. runs your command
60
82
  2. build fails? plays the sound
61
83
  3. thats it
62
84
 
85
+ (for next.js hmr: watches for the error overlay in the browser)
86
+
63
87
  ## requirements
64
88
 
65
89
  uses your system audio player (already installed):
package/dist/cli.js CHANGED
@@ -8,4 +8,15 @@ if (!args.length) {
8
8
  console.log('example: bb npm run build');
9
9
  process.exit(1);
10
10
  }
11
+ // detect next.js dev mode
12
+ const isNextDev = args.some(a => a.includes('next')) && args.some(a => a === 'dev');
13
+ if (isNextDev) {
14
+ console.log('\x1b[36m');
15
+ console.log('brick-break: for hmr error sounds, add to your layout.tsx:');
16
+ console.log('');
17
+ console.log(" import { BrickBreak } from 'brick-break/next'");
18
+ console.log('');
19
+ console.log(' // then add <BrickBreak /> inside <body>');
20
+ console.log('\x1b[0m');
21
+ }
11
22
  (0, index_1.runCommand)(args);
package/dist/next.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { type ReactNode } from 'react';
2
+ export declare function BrickBreak({ children }: {
3
+ children?: ReactNode;
4
+ }): import("react/jsx-runtime").JSX.Element;
package/dist/next.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ 'use client';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.BrickBreak = BrickBreak;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = require("react");
7
+ let lastPlayed = 0;
8
+ const cooldown = 3000;
9
+ function playSound() {
10
+ const now = Date.now();
11
+ if (now - lastPlayed < cooldown)
12
+ return;
13
+ lastPlayed = now;
14
+ const audio = new Audio('https://unpkg.com/brick-break/sound.mp3');
15
+ audio.play().catch(() => { });
16
+ }
17
+ function BrickBreak({ children }) {
18
+ const seenErrors = (0, react_1.useRef)(new Set());
19
+ (0, react_1.useEffect)(() => {
20
+ if (process.env.NODE_ENV !== 'development')
21
+ return;
22
+ const observer = new MutationObserver(() => {
23
+ // nextjs error overlay
24
+ const dialog = document.querySelector('[data-nextjs-dialog]');
25
+ if (dialog) {
26
+ const errorText = dialog.textContent || '';
27
+ if (!seenErrors.current.has(errorText)) {
28
+ seenErrors.current.add(errorText);
29
+ playSound();
30
+ }
31
+ }
32
+ });
33
+ observer.observe(document.body, { childList: true, subtree: true });
34
+ return () => observer.disconnect();
35
+ }, []);
36
+ return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
37
+ }
package/package.json CHANGED
@@ -1,9 +1,19 @@
1
1
  {
2
2
  "name": "brick-break",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Play a Lego break sound when your build fails",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./next": {
13
+ "types": "./dist/next.d.ts",
14
+ "default": "./dist/next.js"
15
+ }
16
+ },
7
17
  "bin": {
8
18
  "brick-break": "dist/cli.js",
9
19
  "bb": "dist/cli.js"
@@ -23,7 +33,8 @@
23
33
  "error",
24
34
  "fun",
25
35
  "developer-experience",
26
- "nextjs"
36
+ "nextjs",
37
+ "react"
27
38
  ],
28
39
  "author": "ShinniUwU",
29
40
  "license": "MIT",
@@ -35,8 +46,17 @@
35
46
  "bugs": {
36
47
  "url": "https://github.com/ShinniUwU/brick-break/issues"
37
48
  },
49
+ "peerDependencies": {
50
+ "react": ">=18.0.0"
51
+ },
52
+ "peerDependenciesMeta": {
53
+ "react": {
54
+ "optional": true
55
+ }
56
+ },
38
57
  "devDependencies": {
39
58
  "@types/node": "^20.0.0",
59
+ "@types/react": "^18.0.0",
40
60
  "typescript": "^5.0.0"
41
61
  }
42
62
  }