Repository: preactjs/preact-devtools
Pull request #476 (2023-04-01 08:33:40)

Run GitHub Action on pull request event


Patch:
diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml
index 8eef6c7..a06ca76 100644
--- a/.github/workflows/nodejs.yml
+++ b/.github/workflows/nodejs.yml
@@ -1,6 +1,12 @@
 name: Node CI
 
-on: [push]
+on:
+  push:
+    branches:
+    - main
+  pull_request:
+    branches:
+    - main
 
 jobs:
   build:
diff --git a/package.json b/package.json
index ef71c66..32fb9c4 100644
--- a/package.json
+++ b/package.json
@@ -27,7 +27,7 @@
 		"build:inline": "node tools/build.mjs --browser inline && tsc -p tsconfig.inline.json",
 		"archive": "git archive --format zip --output dist/source-code.zip main",
 		"lint": "eslint 'src/**/*.{ts,tsx}' 'test-e2e/**/*.ts'",
-		"test": "mochette -c tsconfig.cjs.json -r tools/test-setup.js 'src/**/*.test.{ts,tsx}'",
+		"test": "mochette -c tsconfig.cjs.json 'src/**/*.test.{ts,tsx}'",
 		"test:e2e": "node tools/fetch-preact-versions.mjs && playwright test",
 		"test:e2e:10": "PREACT_VERSION=10 npm run test:e2e",
 		"test:e2e:11": "PREACT_VERSION=11 npm run test:e2e",
@@ -36,7 +36,7 @@
 		"dev": "npm run dev:serve",
 		"dev:serve": "vite test-e2e/fixtures --port 8100",
 		"run:chrome": "node tools/build.mjs --browser chrome --debug && mkdir -p ./profiles/chrome && node tools/run-chrome.js",
-		"run:firefox": "node tools/build.mjs --browser firefox --debug && mkdir -p ./profiles/firefox && web-ext run --source-dir ./dist/firefox-debug/ --start-url https://preactjs.com --firefox-profile=./profiles/firefox --keep-profile-changes",
+		"run:firefox": "node tools/build.mjs --browser firefox --debug && mkdir -p ./profiles/firefox && web-ext run --source-dir ./dist/firefox/ --start-url https://preactjs.com --firefox-profile=./profiles/firefox --keep-profile-changes",
 		"release": "node tools/release.js"
 	},
 	"repository": {
diff --git a/src/debug.ts b/src/debug.ts
index 09bf117..6d57da0 100644
--- a/src/debug.ts
+++ b/src/debug.ts
@@ -2,7 +2,7 @@
  * Will be tree-shaken out in prod builds
  */
 export function debug(...args: any[]) {
-	if (__DEBUG__) {
+	if (process.env.DEBUG) {
 		// eslint-disable-next-line no-console
 		console.log(...args);
 	}
diff --git a/src/global.d.ts b/src/global.d.ts
index 64920d3..4b855de 100644
--- a/src/global.d.ts
+++ b/src/global.d.ts
@@ -6,5 +6,3 @@ declare module "*.css" {
 declare module "@preact-list-versions" {
 	export const preactVersions: string[];
 }
-
-declare const __DEBUG__: boolean;
diff --git a/src/shells/shared/panel/panel.ts b/src/shells/shared/panel/panel.ts
index 04fcf8d..20a7ca4 100644
--- a/src/shells/shared/panel/panel.ts
+++ b/src/shells/shared/panel/panel.ts
@@ -90,7 +90,7 @@ async function initDevtools() {
 	effect(() => storeHighlightUpdates(store.profiler.highlightUpdates.value));
 	effect(() => storeDebugMode(store.debugMode.value));
 
-	if (__DEBUG__) {
+	if (process.env.DEBUG) {
 		(window as any).store = store;
 	}
 
diff --git a/src/view/store/index.ts b/src/view/store/index.ts
index ea50de3..4fa5015 100644
--- a/src/view/store/index.ts
+++ b/src/view/store/index.ts
@@ -17,7 +17,7 @@ export function createStore(): Store {
 		listeners.forEach(fn => fn && fn(name, data));
 	};
 
-	const debugMode = signal(!!__DEBUG__);
+	const debugMode = signal(!!process.env.DEBUG);
 
 	const nodes = signal<Map<ID, DevNode>>(new Map());
 	const roots = signal<ID[]>([]);
diff --git a/tools/build-plugins/esbuild-plugins.mjs b/tools/build-plugins/esbuild-plugins.mjs
index 87a0bb7..40a9760 100644
--- a/tools/build-plugins/esbuild-plugins.mjs
+++ b/tools/build-plugins/esbuild-plugins.mjs
@@ -158,10 +158,9 @@ export function inlineHookPlugin(dir) {
 /**
  * @param {string} dir
  * @param {string} browser
- * @param {boolean} debug
  * @returns {import("esbuild").Plugin}
  */
-export function archivePlugin(dir, browser, debug) {
+export function archivePlugin(dir, browser) {
 	return {
 		name: "archive-plugin",
 		setup(build) {
@@ -170,7 +169,7 @@ export function archivePlugin(dir, browser, debug) {
 
 				// Package extension
 				const output = fsSync.createWriteStream(
-					path.join(dir, `${browser}${debug ? "-debug" : ""}.zip`),
+					path.join(dir, `${browser}.zip`),
 				);
 				const archive = archiver("zip", { zlib: { level: 9 } });
 
diff --git a/tools/build.mjs b/tools/build.mjs
index 5fc5155..4509b0a 100644
--- a/tools/build.mjs
+++ b/tools/build.mjs
@@ -79,7 +79,7 @@ async function run() {
 run();
 
 async function build(browser) {
-	const dist = `dist/${browser}${DEBUG ? "-debug" : ""}`;
+	const dist = `dist/${browser}`;
 	// eslint-disable-next-line no-console
 	console.log(`${kl.dim("Browser:")} ${kl.cyan(browser)}`);
 	const start = Date.now();
@@ -102,7 +102,7 @@ async function build(browser) {
 	}
 
 	const define = {
-		__DEBUG__: DEBUG,
+		"process.env.DEBUG": DEBUG,
 		"process.env.BROWSER": JSON.stringify(browser),
 	};
 
@@ -161,7 +161,7 @@ async function build(browser) {
 							path.join(dist, "panel", "empty-panel.html"),
 					  ],
 			),
-			!isInline && archivePlugin("dist", browser, DEBUG),
+			!isInline && archivePlugin("dist", browser),
 			!isInline && !process.env.CI && gitSourcePlugin(),
 		].filter(Boolean),
 	});
diff --git a/tools/run-chrome.js b/tools/run-chrome.js
index eb6981a..15df3f4 100644
--- a/tools/run-chrome.js
+++ b/tools/run-chrome.js
@@ -3,7 +3,7 @@ const { chromium } = require("playwright-chromium");
 const path = require("path");
 
 async function main() {
-	const extension = path.join(__dirname, "..", "dist", "chrome-debug");
+	const extension = path.join(__dirname, "..", "dist", "chrome");
 	const browser = await chromium.launchPersistentContext("./profiles/chrome", {
 		args: [
 			`--disable-extensions-except=${extension}`,


Test patch:
diff --git a/test-e2e/fixtures/vite.config.ts b/test-e2e/fixtures/vite.config.ts
index 439cce8..516e10a 100644
--- a/test-e2e/fixtures/vite.config.ts
+++ b/test-e2e/fixtures/vite.config.ts
@@ -23,7 +23,7 @@ export default defineConfig({
 						jsxFragment: "Fragment",
 						jsxInject: "",
 						define: {
-							__DEBUG__: JSON.stringify(false),
+							"process.env.DEBUG": JSON.stringify(false),
 						},
 					},
 
diff --git a/tools/test-setup.js b/tools/test-setup.js
deleted file mode 100644
index 922a169..0000000
--- a/tools/test-setup.js
+++ /dev/null
@@ -1,1 +0,0 @@
-global.__DEBUG__ = false;