generated from chiffre-io/template-library
-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Having two bundles is burdensome, their interop exposed the emitter and didn't allow using Symbols, but moreover they didn't allow switching debug info at runtime without rebuilding/redeploying the app, which is inconvenient. Instead, log lines are only rendered to string for user timings and logged in rich format to the console if there is a special key in localStorage, that follows the `debug` package convention, without importing all the bells and whistles around it. The patched marker has also been replaced by the package version, in order to facilitate debugging even further by looking which version is being used in production builds.
- Loading branch information
Showing
17 changed files
with
283 additions
and
1,896 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
# Place ourselves in the package directory | ||
cd "$(dirname "$0")/.." | ||
|
||
# Copy the README & License from the root of the repository | ||
cp -f ../../README.md ../../LICENSE ./ | ||
|
||
# Patch the version from package.json | ||
VERSION=$(node -p "require('./package.json').version") | ||
sed -i '' "s/0.0.0-inject-version-here/${VERSION}/g" dist/index.{js,cjs} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { sprintf } from './debug' | ||
|
||
describe('debug/sprintf', () => { | ||
test('%s', () => { | ||
expect(sprintf('%s', 'foo')).toBe('foo') | ||
expect(sprintf('%s', 1)).toBe('1') | ||
expect(sprintf('%s', true)).toBe('true') | ||
expect(sprintf('%s', null)).toBe('null') | ||
expect(sprintf('%s', undefined)).toBe('undefined') | ||
expect(sprintf('%s', {})).toBe('[object Object]') | ||
expect(sprintf('%s', [])).toBe('') | ||
}) | ||
test('%O', () => { | ||
expect(sprintf('%O', 'foo')).toBe('"foo"') | ||
expect(sprintf('%O', 1)).toBe('1') | ||
expect(sprintf('%O', true)).toBe('true') | ||
expect(sprintf('%O', null)).toBe('null') | ||
expect(sprintf('%O', undefined)).toBe('undefined') | ||
expect(sprintf('%O', {})).toBe('{}') | ||
expect(sprintf('%O', [])).toBe('[]') | ||
expect(sprintf('%O', { hello: 'world' })).toBe('{hello:"world"}') | ||
}) | ||
test('All together now', () => { | ||
expect(sprintf('%s %O', 'foo', { hello: 'world' })).toBe( | ||
'foo {hello:"world"}' | ||
) | ||
expect(sprintf('%O %s', { hello: 'world' }, 'foo')).toBe( | ||
'{hello:"world"} foo' | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const enabled = | ||
(typeof window === 'object' && | ||
localStorage.getItem('debug')?.includes('next-usequerystate')) ?? | ||
false | ||
|
||
export function debug(message: string, ...args: any[]) { | ||
if (!enabled) { | ||
return | ||
} | ||
const msg = sprintf(message, ...args) | ||
performance.mark(msg) | ||
console.debug(message, ...args) | ||
} | ||
|
||
export function sprintf(base: string, ...args: any[]) { | ||
return base.replace(/%[sfdO]/g, match => { | ||
const arg = args.shift() | ||
if (match === '%O' && arg) { | ||
return JSON.stringify(arg).replace(/"([^"]+)":/g, '$1:') | ||
} else { | ||
return String(arg) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.