Skip to content

Commit

Permalink
Infer debug mode from flag instead of env var
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Mar 6, 2023
1 parent cdfdadf commit 4cd7293
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 'src/**/*.test.{ts,tsx}'",
"test": "mochette -c tsconfig.cjs.json -r tools/test-setup.js '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",
Expand Down
2 changes: 1 addition & 1 deletion src/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Will be tree-shaken out in prod builds
*/
export function debug(...args: any[]) {
if (process.env.DEBUG) {
if (__DEBUG__) {
// eslint-disable-next-line no-console
console.log(...args);
}
Expand Down
2 changes: 2 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ declare module "*.css" {
declare module "@preact-list-versions" {
export const preactVersions: string[];
}

declare const __DEBUG__: boolean;
2 changes: 1 addition & 1 deletion src/shells/shared/panel/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async function initDevtools() {
effect(() => storeHighlightUpdates(store.profiler.highlightUpdates.value));
effect(() => storeDebugMode(store.debugMode.value));

if (process.env.DEBUG) {
if (__DEBUG__) {
(window as any).store = store;
}

Expand Down
2 changes: 1 addition & 1 deletion src/view/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function createStore(): Store {
listeners.forEach(fn => fn && fn(name, data));
};

const debugMode = signal(!!process.env.DEBUG);
const debugMode = signal(!!__DEBUG__);

const nodes = signal<Map<ID, DevNode>>(new Map());
const roots = signal<ID[]>([]);
Expand Down
2 changes: 1 addition & 1 deletion test-e2e/fixtures/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default defineConfig({
jsxFragment: "Fragment",
jsxInject: "",
define: {
"process.env.DEBUG": JSON.stringify(false),
__DEBUG__: JSON.stringify(false),
},
},

Expand Down
2 changes: 1 addition & 1 deletion tools/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async function build(browser) {
}

const define = {
"process.env.DEBUG": DEBUG,
__DEBUG__: DEBUG,
"process.env.BROWSER": JSON.stringify(browser),
};

Expand Down
1 change: 1 addition & 0 deletions tools/test-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global.__DEBUG__ = false;

0 comments on commit 4cd7293

Please sign in to comment.