@brillout/docpress 0.12.2 → 0.12.3
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/components/Link.tsx +1 -1
- package/dist/components/Link.js +2 -1
- package/dist/utils/assert.d.ts +4 -1
- package/dist/utils/assert.js +24 -7
- package/package.json +1 -1
- package/utils/assert.ts +24 -6
package/components/Link.tsx
CHANGED
|
@@ -82,7 +82,7 @@ function getLinkTextData(href: string, pageContext: PageContextResolved, doNotIn
|
|
|
82
82
|
const { hrefPathname, hrefHash } = parseHref(href)
|
|
83
83
|
|
|
84
84
|
const linkData = findLinkData(hrefPathname || pageContext.urlPathname, pageContext)
|
|
85
|
-
|
|
85
|
+
if (!linkData) return null
|
|
86
86
|
const isLinkOnSamePage = linkData.url === pageContext.urlPathname
|
|
87
87
|
if (!hrefPathname) assert(isLinkOnSamePage)
|
|
88
88
|
|
package/dist/components/Link.js
CHANGED
|
@@ -54,7 +54,8 @@ function getLinkText(_a) {
|
|
|
54
54
|
function getLinkTextData(href, pageContext, doNotInferSectionTitle) {
|
|
55
55
|
var _a = parseHref(href), hrefPathname = _a.hrefPathname, hrefHash = _a.hrefHash;
|
|
56
56
|
var linkData = findLinkData(hrefPathname || pageContext.urlPathname, pageContext);
|
|
57
|
-
|
|
57
|
+
if (!linkData)
|
|
58
|
+
return null;
|
|
58
59
|
var isLinkOnSamePage = linkData.url === pageContext.urlPathname;
|
|
59
60
|
if (!hrefPathname)
|
|
60
61
|
assert(isLinkOnSamePage);
|
package/dist/utils/assert.d.ts
CHANGED
|
@@ -3,4 +3,7 @@ export { assertUsage };
|
|
|
3
3
|
export { assertWarning };
|
|
4
4
|
declare function assert(condition: unknown, debugInfo?: unknown): asserts condition;
|
|
5
5
|
declare function assertUsage(condition: unknown, msg: string): asserts condition;
|
|
6
|
-
declare function assertWarning(condition: unknown, msg: string
|
|
6
|
+
declare function assertWarning(condition: unknown, msg: string, { onlyOnce, showStackTrace }?: {
|
|
7
|
+
onlyOnce?: boolean | string;
|
|
8
|
+
showStackTrace?: true;
|
|
9
|
+
}): void;
|
package/dist/utils/assert.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export { assert };
|
|
2
2
|
export { assertUsage };
|
|
3
3
|
export { assertWarning };
|
|
4
|
+
import { getGlobalObject } from './getGlobalObject';
|
|
4
5
|
var devModeKey = '__docpress_dev_mode';
|
|
6
|
+
var globalObject = getGlobalObject('utils/assert.ts', {
|
|
7
|
+
alreadyLogged: new Set(),
|
|
8
|
+
});
|
|
5
9
|
if (isBrowser()) {
|
|
6
10
|
;
|
|
7
11
|
window.toggleDevMode = toggleDevMode;
|
|
@@ -66,18 +70,31 @@ function toggleDevMode() {
|
|
|
66
70
|
}
|
|
67
71
|
console.log("DEV MODE ".concat(isEnabled() ? 'enabled' : 'disabled'));
|
|
68
72
|
}
|
|
69
|
-
function assertWarning(condition, msg) {
|
|
73
|
+
function assertWarning(condition, msg, _a) {
|
|
74
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.onlyOnce, onlyOnce = _c === void 0 ? true : _c, showStackTrace = _b.showStackTrace;
|
|
70
75
|
if (condition) {
|
|
71
76
|
return;
|
|
72
77
|
}
|
|
73
|
-
msg = '[DocPress][Warning] ' + msg;
|
|
74
78
|
var err = new Error(msg);
|
|
75
|
-
if (import.meta.env.DEV) {
|
|
76
|
-
|
|
77
|
-
if (isDevMode())
|
|
78
|
-
window.alert(err);
|
|
79
|
+
if (!import.meta.env.DEV) {
|
|
80
|
+
throw err;
|
|
79
81
|
}
|
|
80
82
|
else {
|
|
81
|
-
|
|
83
|
+
if (onlyOnce) {
|
|
84
|
+
var alreadyLogged = globalObject.alreadyLogged;
|
|
85
|
+
var key = onlyOnce === true ? msg : onlyOnce;
|
|
86
|
+
if (alreadyLogged.has(key))
|
|
87
|
+
return;
|
|
88
|
+
alreadyLogged.add(key);
|
|
89
|
+
}
|
|
90
|
+
msg = '[DocPress][Warning] ' + msg;
|
|
91
|
+
if (!showStackTrace) {
|
|
92
|
+
console.warn(msg);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
console.warn(err);
|
|
96
|
+
}
|
|
97
|
+
if (isDevMode())
|
|
98
|
+
window.alert(err);
|
|
82
99
|
}
|
|
83
100
|
}
|
package/package.json
CHANGED
package/utils/assert.ts
CHANGED
|
@@ -2,7 +2,11 @@ export { assert }
|
|
|
2
2
|
export { assertUsage }
|
|
3
3
|
export { assertWarning }
|
|
4
4
|
|
|
5
|
+
import { getGlobalObject } from './getGlobalObject'
|
|
5
6
|
const devModeKey = '__docpress_dev_mode'
|
|
7
|
+
const globalObject = getGlobalObject('utils/assert.ts', {
|
|
8
|
+
alreadyLogged: new Set<string>(),
|
|
9
|
+
})
|
|
6
10
|
|
|
7
11
|
if (isBrowser()) {
|
|
8
12
|
;(window as any).toggleDevMode = toggleDevMode
|
|
@@ -70,16 +74,30 @@ function toggleDevMode() {
|
|
|
70
74
|
console.log(`DEV MODE ${isEnabled() ? 'enabled' : 'disabled'}`)
|
|
71
75
|
}
|
|
72
76
|
|
|
73
|
-
function assertWarning(
|
|
77
|
+
function assertWarning(
|
|
78
|
+
condition: unknown,
|
|
79
|
+
msg: string,
|
|
80
|
+
{ onlyOnce = true, showStackTrace }: { onlyOnce?: boolean | string; showStackTrace?: true } = {},
|
|
81
|
+
) {
|
|
74
82
|
if (condition) {
|
|
75
83
|
return
|
|
76
84
|
}
|
|
77
|
-
msg = '[DocPress][Warning] ' + msg
|
|
78
85
|
const err = new Error(msg)
|
|
79
|
-
if (import.meta.env.DEV) {
|
|
80
|
-
console.warn(err)
|
|
81
|
-
if (isDevMode()) window.alert(err)
|
|
82
|
-
} else {
|
|
86
|
+
if (!import.meta.env.DEV) {
|
|
83
87
|
throw err
|
|
88
|
+
} else {
|
|
89
|
+
if (onlyOnce) {
|
|
90
|
+
const { alreadyLogged } = globalObject
|
|
91
|
+
const key = onlyOnce === true ? msg : onlyOnce
|
|
92
|
+
if (alreadyLogged.has(key)) return
|
|
93
|
+
alreadyLogged.add(key)
|
|
94
|
+
}
|
|
95
|
+
msg = '[DocPress][Warning] ' + msg
|
|
96
|
+
if (!showStackTrace) {
|
|
97
|
+
console.warn(msg)
|
|
98
|
+
} else {
|
|
99
|
+
console.warn(err)
|
|
100
|
+
}
|
|
101
|
+
if (isDevMode()) window.alert(err)
|
|
84
102
|
}
|
|
85
103
|
}
|