piral-debug-utils 0.14.14-beta.3753 → 0.14.14
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/esm/DebugRouteSwitch.d.ts +10 -0
- package/esm/DebugRouteSwitch.js +33 -0
- package/esm/DebugRouteSwitch.js.map +1 -0
- package/esm/emulator.js +34 -14
- package/esm/emulator.js.map +1 -1
- package/esm/types.d.ts +4 -0
- package/lib/DebugRouteSwitch.d.ts +10 -0
- package/lib/DebugRouteSwitch.js +38 -0
- package/lib/DebugRouteSwitch.js.map +1 -0
- package/lib/emulator.js +34 -14
- package/lib/emulator.js.map +1 -1
- package/lib/types.d.ts +4 -0
- package/package.json +3 -3
- package/src/DebugRouteSwitch.tsx +52 -0
- package/src/emulator.ts +38 -14
- package/src/types.ts +5 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export declare function freezeRouteRefresh(): () => void;
|
|
3
|
+
export interface DebugRouteSwitch {
|
|
4
|
+
NotFound: React.ComponentType;
|
|
5
|
+
paths: Array<{
|
|
6
|
+
path: string;
|
|
7
|
+
Component: React.ComponentType;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
export declare const DebugRouteSwitch: React.FC<DebugRouteSwitch>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Switch, Route } from 'react-router';
|
|
3
|
+
const debugRouteCache = {
|
|
4
|
+
active: 0,
|
|
5
|
+
paths: [],
|
|
6
|
+
refresh: undefined,
|
|
7
|
+
};
|
|
8
|
+
export function freezeRouteRefresh() {
|
|
9
|
+
debugRouteCache.active++;
|
|
10
|
+
return () => {
|
|
11
|
+
var _a;
|
|
12
|
+
debugRouteCache.active--;
|
|
13
|
+
if (!debugRouteCache.active) {
|
|
14
|
+
(_a = debugRouteCache.refresh) === null || _a === void 0 ? void 0 : _a.call(debugRouteCache, (s) => s + 1);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export const DebugRouteSwitch = ({ paths, NotFound }) => {
|
|
19
|
+
const [_, triggerChange] = React.useState(0);
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
debugRouteCache.refresh = triggerChange;
|
|
22
|
+
return () => {
|
|
23
|
+
debugRouteCache.refresh = undefined;
|
|
24
|
+
};
|
|
25
|
+
}, []);
|
|
26
|
+
if (!debugRouteCache.active) {
|
|
27
|
+
debugRouteCache.paths = paths;
|
|
28
|
+
}
|
|
29
|
+
return (React.createElement(Switch, null,
|
|
30
|
+
debugRouteCache.paths.map(({ path, Component }) => (React.createElement(Route, { exact: true, key: path, path: path, component: Component }))),
|
|
31
|
+
React.createElement(Route, { component: NotFound })));
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=DebugRouteSwitch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DebugRouteSwitch.js","sourceRoot":"","sources":["../src/DebugRouteSwitch.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,eAAe,GAAG;IACtB,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,EAAE;IACT,OAAO,EAAE,SAAS;CACnB,CAAC;AAEF,MAAM,UAAU,kBAAkB;IAChC,eAAe,CAAC,MAAM,EAAE,CAAC;IAEzB,OAAO,GAAG,EAAE;;QACV,eAAe,CAAC,MAAM,EAAE,CAAC;QAEzB,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE;YAC3B,MAAA,eAAe,CAAC,OAAO,+CAAvB,eAAe,EAAW,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;SACjD;IACH,CAAC,CAAC;AACJ,CAAC;AAUD,MAAM,CAAC,MAAM,gBAAgB,GAA+B,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE;IAClF,MAAM,CAAC,CAAC,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE7C,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,eAAe,CAAC,OAAO,GAAG,aAAa,CAAC;QACxC,OAAO,GAAG,EAAE;YACV,eAAe,CAAC,OAAO,GAAG,SAAS,CAAC;QACtC,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE;QAC3B,eAAe,CAAC,KAAK,GAAG,KAAK,CAAC;KAC/B;IAED,OAAO,CACL,oBAAC,MAAM;QACJ,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAClD,oBAAC,KAAK,IAAC,KAAK,QAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,GAAI,CAC7D,CAAC;QACF,oBAAC,KAAK,IAAC,SAAS,EAAE,QAAQ,GAAI,CACvB,CACV,CAAC;AACJ,CAAC,CAAC"}
|
package/esm/emulator.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { isfunc, setupPilet } from 'piral-base';
|
|
2
|
+
import { freezeRouteRefresh, DebugRouteSwitch } from './DebugRouteSwitch';
|
|
2
3
|
export function withEmulatorPilets(requestPilets, options) {
|
|
3
|
-
const { loadPilet, createApi, injectPilet, piletApiFallback = '/$pilet-api' } = options;
|
|
4
|
+
const { loadPilet, createApi, injectPilet, integrate, piletApiFallback = '/$pilet-api' } = options;
|
|
4
5
|
// check if pilets should be loaded
|
|
5
6
|
const loadPilets = sessionStorage.getItem('dbg:load-pilets') === 'on';
|
|
6
7
|
const noPilets = () => Promise.resolve([]);
|
|
7
8
|
const requester = loadPilets ? requestPilets : noPilets;
|
|
9
|
+
integrate === null || integrate === void 0 ? void 0 : integrate({
|
|
10
|
+
components: {
|
|
11
|
+
RouteSwitch: DebugRouteSwitch,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
8
14
|
return () => {
|
|
9
15
|
const promise = requester();
|
|
10
16
|
// the window['dbg:pilet-api'] should point to an API address used as a proxy, fall back to '/$pilet-api' if unavailable
|
|
@@ -15,6 +21,8 @@ export function withEmulatorPilets(requestPilets, options) {
|
|
|
15
21
|
: `${location.origin}${piletApi[0] === '/' ? '' : '/'}${piletApi}`;
|
|
16
22
|
const updateTarget = initialTarget.replace('http', 'ws');
|
|
17
23
|
const ws = new WebSocket(updateTarget);
|
|
24
|
+
const timeoutCache = {};
|
|
25
|
+
const timeout = 150;
|
|
18
26
|
const appendix = fetch(initialTarget)
|
|
19
27
|
.then((res) => res.json())
|
|
20
28
|
.then((item) => (Array.isArray(item) ? item : [item]));
|
|
@@ -23,20 +31,32 @@ export function withEmulatorPilets(requestPilets, options) {
|
|
|
23
31
|
if (!hardRefresh) {
|
|
24
32
|
// standard setting is to just perform an inject
|
|
25
33
|
const meta = JSON.parse(data);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
const name = meta.name;
|
|
35
|
+
// like a debounce; only one change of the current pilet should be actively processed
|
|
36
|
+
clearTimeout(timeoutCache[name]);
|
|
37
|
+
// some bundlers may have fired before writing to the disk
|
|
38
|
+
// so we give them a bit of time before actually loading the pilet
|
|
39
|
+
timeoutCache[name] = setTimeout(() => {
|
|
40
|
+
// we should make sure to only refresh the page / router if pilets have been loaded
|
|
41
|
+
const unfreeze = freezeRouteRefresh();
|
|
42
|
+
// tear down pilet
|
|
43
|
+
injectPilet({ name });
|
|
44
|
+
// load and evaluate pilet
|
|
45
|
+
loadPilet(meta).then((pilet) => {
|
|
46
|
+
try {
|
|
47
|
+
if (isfunc(injectPilet)) {
|
|
48
|
+
injectPilet(pilet);
|
|
49
|
+
}
|
|
50
|
+
// setup actual pilet
|
|
51
|
+
setupPilet(pilet, createApi);
|
|
52
|
+
// disable route cache, should be zero again and lead to route refresh
|
|
53
|
+
unfreeze();
|
|
33
54
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.error(error);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}, timeout);
|
|
40
60
|
}
|
|
41
61
|
else {
|
|
42
62
|
location.reload();
|
package/esm/emulator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emulator.js","sourceRoot":"","sources":["../src/emulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAkB,UAAU,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"emulator.js","sourceRoot":"","sources":["../src/emulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAkB,UAAU,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAG1E,MAAM,UAAU,kBAAkB,CAAC,aAA6B,EAAE,OAAiC;IACjG,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,gBAAgB,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC;IACnG,mCAAmC;IACnC,MAAM,UAAU,GAAG,cAAc,CAAC,OAAO,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;IACtE,MAAM,QAAQ,GAAmB,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC3D,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC;IAExD,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAG;QACV,UAAU,EAAE;YACV,WAAW,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M,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;YAC3E,OAAO,CAAC,GAAG,UAAU,EAAE,GAAG,WAAW,CAAC,CAAC;QACzC,CAAC,CAAC,CACH,CAAC;IACN,CAAC,CAAC;AACJ,CAAC"}
|
package/esm/types.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export interface EmulatorConnectorOptions {
|
|
|
5
5
|
loadPilet: PiletLoader;
|
|
6
6
|
injectPilet?(pilet: Pilet): void;
|
|
7
7
|
piletApiFallback?: string;
|
|
8
|
+
integrate?(components: EmulatorComponents): void;
|
|
8
9
|
}
|
|
9
10
|
export interface ChangeSet {
|
|
10
11
|
state?: boolean;
|
|
@@ -13,6 +14,9 @@ export interface ChangeSet {
|
|
|
13
14
|
extensions?: boolean;
|
|
14
15
|
dependencies?: boolean;
|
|
15
16
|
}
|
|
17
|
+
export interface EmulatorComponents {
|
|
18
|
+
components: Record<string, FC>;
|
|
19
|
+
}
|
|
16
20
|
export interface DebugComponents {
|
|
17
21
|
wrappers: Record<string, FC>;
|
|
18
22
|
components: Record<string, FC>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export declare function freezeRouteRefresh(): () => void;
|
|
3
|
+
export interface DebugRouteSwitch {
|
|
4
|
+
NotFound: React.ComponentType;
|
|
5
|
+
paths: Array<{
|
|
6
|
+
path: string;
|
|
7
|
+
Component: React.ComponentType;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
export declare const DebugRouteSwitch: React.FC<DebugRouteSwitch>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DebugRouteSwitch = exports.freezeRouteRefresh = void 0;
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const react_router_1 = require("react-router");
|
|
6
|
+
const debugRouteCache = {
|
|
7
|
+
active: 0,
|
|
8
|
+
paths: [],
|
|
9
|
+
refresh: undefined,
|
|
10
|
+
};
|
|
11
|
+
function freezeRouteRefresh() {
|
|
12
|
+
debugRouteCache.active++;
|
|
13
|
+
return () => {
|
|
14
|
+
var _a;
|
|
15
|
+
debugRouteCache.active--;
|
|
16
|
+
if (!debugRouteCache.active) {
|
|
17
|
+
(_a = debugRouteCache.refresh) === null || _a === void 0 ? void 0 : _a.call(debugRouteCache, (s) => s + 1);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
exports.freezeRouteRefresh = freezeRouteRefresh;
|
|
22
|
+
const DebugRouteSwitch = ({ paths, NotFound }) => {
|
|
23
|
+
const [_, triggerChange] = React.useState(0);
|
|
24
|
+
React.useEffect(() => {
|
|
25
|
+
debugRouteCache.refresh = triggerChange;
|
|
26
|
+
return () => {
|
|
27
|
+
debugRouteCache.refresh = undefined;
|
|
28
|
+
};
|
|
29
|
+
}, []);
|
|
30
|
+
if (!debugRouteCache.active) {
|
|
31
|
+
debugRouteCache.paths = paths;
|
|
32
|
+
}
|
|
33
|
+
return (React.createElement(react_router_1.Switch, null,
|
|
34
|
+
debugRouteCache.paths.map(({ path, Component }) => (React.createElement(react_router_1.Route, { exact: true, key: path, path: path, component: Component }))),
|
|
35
|
+
React.createElement(react_router_1.Route, { component: NotFound })));
|
|
36
|
+
};
|
|
37
|
+
exports.DebugRouteSwitch = DebugRouteSwitch;
|
|
38
|
+
//# sourceMappingURL=DebugRouteSwitch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DebugRouteSwitch.js","sourceRoot":"","sources":["../src/DebugRouteSwitch.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,+CAA6C;AAE7C,MAAM,eAAe,GAAG;IACtB,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,EAAE;IACT,OAAO,EAA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2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withEmulatorPilets = void 0;
|
|
4
4
|
const piral_base_1 = require("piral-base");
|
|
5
|
+
const DebugRouteSwitch_1 = require("./DebugRouteSwitch");
|
|
5
6
|
function withEmulatorPilets(requestPilets, options) {
|
|
6
|
-
const { loadPilet, createApi, injectPilet, piletApiFallback = '/$pilet-api' } = options;
|
|
7
|
+
const { loadPilet, createApi, injectPilet, integrate, piletApiFallback = '/$pilet-api' } = options;
|
|
7
8
|
// check if pilets should be loaded
|
|
8
9
|
const loadPilets = sessionStorage.getItem('dbg:load-pilets') === 'on';
|
|
9
10
|
const noPilets = () => Promise.resolve([]);
|
|
10
11
|
const requester = loadPilets ? requestPilets : noPilets;
|
|
12
|
+
integrate === null || integrate === void 0 ? void 0 : integrate({
|
|
13
|
+
components: {
|
|
14
|
+
RouteSwitch: DebugRouteSwitch_1.DebugRouteSwitch,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
11
17
|
return () => {
|
|
12
18
|
const promise = requester();
|
|
13
19
|
// the window['dbg:pilet-api'] should point to an API address used as a proxy, fall back to '/$pilet-api' if unavailable
|
|
@@ -18,6 +24,8 @@ function withEmulatorPilets(requestPilets, options) {
|
|
|
18
24
|
: `${location.origin}${piletApi[0] === '/' ? '' : '/'}${piletApi}`;
|
|
19
25
|
const updateTarget = initialTarget.replace('http', 'ws');
|
|
20
26
|
const ws = new WebSocket(updateTarget);
|
|
27
|
+
const timeoutCache = {};
|
|
28
|
+
const timeout = 150;
|
|
21
29
|
const appendix = fetch(initialTarget)
|
|
22
30
|
.then((res) => res.json())
|
|
23
31
|
.then((item) => (Array.isArray(item) ? item : [item]));
|
|
@@ -26,20 +34,32 @@ function withEmulatorPilets(requestPilets, options) {
|
|
|
26
34
|
if (!hardRefresh) {
|
|
27
35
|
// standard setting is to just perform an inject
|
|
28
36
|
const meta = JSON.parse(data);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
const name = meta.name;
|
|
38
|
+
// like a debounce; only one change of the current pilet should be actively processed
|
|
39
|
+
clearTimeout(timeoutCache[name]);
|
|
40
|
+
// some bundlers may have fired before writing to the disk
|
|
41
|
+
// so we give them a bit of time before actually loading the pilet
|
|
42
|
+
timeoutCache[name] = setTimeout(() => {
|
|
43
|
+
// we should make sure to only refresh the page / router if pilets have been loaded
|
|
44
|
+
const unfreeze = (0, DebugRouteSwitch_1.freezeRouteRefresh)();
|
|
45
|
+
// tear down pilet
|
|
46
|
+
injectPilet({ name });
|
|
47
|
+
// load and evaluate pilet
|
|
48
|
+
loadPilet(meta).then((pilet) => {
|
|
49
|
+
try {
|
|
50
|
+
if ((0, piral_base_1.isfunc)(injectPilet)) {
|
|
51
|
+
injectPilet(pilet);
|
|
52
|
+
}
|
|
53
|
+
// setup actual pilet
|
|
54
|
+
(0, piral_base_1.setupPilet)(pilet, createApi);
|
|
55
|
+
// disable route cache, should be zero again and lead to route refresh
|
|
56
|
+
unfreeze();
|
|
36
57
|
}
|
|
37
|
-
(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error(error);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}, timeout);
|
|
43
63
|
}
|
|
44
64
|
else {
|
|
45
65
|
location.reload();
|
package/lib/emulator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emulator.js","sourceRoot":"","sources":["../src/emulator.ts"],"names":[],"mappings":";;;AAAA,2CAAgE;
|
|
1
|
+
{"version":3,"file":"emulator.js","sourceRoot":"","sources":["../src/emulator.ts"],"names":[],"mappings":";;;AAAA,2CAAgE;AAChE,yDAA0E;AAG1E,SAAgB,kBAAkB,CAAC,aAA6B,EAAE,OAAiC;IACjG,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EA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C,MAAM,EAAE,CAAC;aACnB;QACH,CAAC,CAAC;QAEF,OAAO,OAAO;aACX,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,OAAO,CAAC,KAAK,CAAC,mFAAmF,EAAE,GAAG,CAAC,CAAC;YACxG,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC;aACD,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CACf,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE;YAC5B,MAAM,eAAe,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YACvD,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;YAC3E,OAAO,CAAC,GAAG,UAAU,EAAE,GAAG,WAAW,CAAC,CAAC;QACzC,CAAC,CAAC,CACH,CAAC;IACN,CAAC,CAAC;AACJ,CAAC;AAvFD,gDAuFC"}
|
package/lib/types.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export interface EmulatorConnectorOptions {
|
|
|
5
5
|
loadPilet: PiletLoader;
|
|
6
6
|
injectPilet?(pilet: Pilet): void;
|
|
7
7
|
piletApiFallback?: string;
|
|
8
|
+
integrate?(components: EmulatorComponents): void;
|
|
8
9
|
}
|
|
9
10
|
export interface ChangeSet {
|
|
10
11
|
state?: boolean;
|
|
@@ -13,6 +14,9 @@ export interface ChangeSet {
|
|
|
13
14
|
extensions?: boolean;
|
|
14
15
|
dependencies?: boolean;
|
|
15
16
|
}
|
|
17
|
+
export interface EmulatorComponents {
|
|
18
|
+
components: Record<string, FC>;
|
|
19
|
+
}
|
|
16
20
|
export interface DebugComponents {
|
|
17
21
|
wrappers: Record<string, FC>;
|
|
18
22
|
components: Record<string, FC>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-debug-utils",
|
|
3
|
-
"version": "0.14.14
|
|
3
|
+
"version": "0.14.14",
|
|
4
4
|
"description": "Utilities for debugging Piral instances.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"piral",
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"piral-base": "0.14.14
|
|
41
|
+
"piral-base": "^0.14.14"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"piral-base": "0.14.x",
|
|
45
45
|
"react": ">=16.8.0",
|
|
46
46
|
"react-router": ">=5.0.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "0562c909cc402eeeff4907c9db564f5265a12973"
|
|
49
49
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Switch, Route } from 'react-router';
|
|
3
|
+
|
|
4
|
+
const debugRouteCache = {
|
|
5
|
+
active: 0,
|
|
6
|
+
paths: [],
|
|
7
|
+
refresh: undefined,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function freezeRouteRefresh() {
|
|
11
|
+
debugRouteCache.active++;
|
|
12
|
+
|
|
13
|
+
return () => {
|
|
14
|
+
debugRouteCache.active--;
|
|
15
|
+
|
|
16
|
+
if (!debugRouteCache.active) {
|
|
17
|
+
debugRouteCache.refresh?.((s: number) => s + 1);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface DebugRouteSwitch {
|
|
23
|
+
NotFound: React.ComponentType;
|
|
24
|
+
paths: Array<{
|
|
25
|
+
path: string;
|
|
26
|
+
Component: React.ComponentType;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const DebugRouteSwitch: React.FC<DebugRouteSwitch> = ({ paths, NotFound }) => {
|
|
31
|
+
const [_, triggerChange] = React.useState(0);
|
|
32
|
+
|
|
33
|
+
React.useEffect(() => {
|
|
34
|
+
debugRouteCache.refresh = triggerChange;
|
|
35
|
+
return () => {
|
|
36
|
+
debugRouteCache.refresh = undefined;
|
|
37
|
+
};
|
|
38
|
+
}, []);
|
|
39
|
+
|
|
40
|
+
if (!debugRouteCache.active) {
|
|
41
|
+
debugRouteCache.paths = paths;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Switch>
|
|
46
|
+
{debugRouteCache.paths.map(({ path, Component }) => (
|
|
47
|
+
<Route exact key={path} path={path} component={Component} />
|
|
48
|
+
))}
|
|
49
|
+
<Route component={NotFound} />
|
|
50
|
+
</Switch>
|
|
51
|
+
);
|
|
52
|
+
};
|
package/src/emulator.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { isfunc, PiletRequester, setupPilet } from 'piral-base';
|
|
2
|
+
import { freezeRouteRefresh, DebugRouteSwitch } from './DebugRouteSwitch';
|
|
2
3
|
import { EmulatorConnectorOptions } from './types';
|
|
3
4
|
|
|
4
5
|
export function withEmulatorPilets(requestPilets: PiletRequester, options: EmulatorConnectorOptions): PiletRequester {
|
|
5
|
-
const { loadPilet, createApi, injectPilet, piletApiFallback = '/$pilet-api' } = options;
|
|
6
|
+
const { loadPilet, createApi, injectPilet, integrate, piletApiFallback = '/$pilet-api' } = options;
|
|
6
7
|
// check if pilets should be loaded
|
|
7
8
|
const loadPilets = sessionStorage.getItem('dbg:load-pilets') === 'on';
|
|
8
9
|
const noPilets: PiletRequester = () => Promise.resolve([]);
|
|
9
10
|
const requester = loadPilets ? requestPilets : noPilets;
|
|
10
11
|
|
|
12
|
+
integrate?.({
|
|
13
|
+
components: {
|
|
14
|
+
RouteSwitch: DebugRouteSwitch,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
|
|
11
18
|
return () => {
|
|
12
19
|
const promise = requester();
|
|
13
20
|
|
|
@@ -20,6 +27,8 @@ export function withEmulatorPilets(requestPilets: PiletRequester, options: Emula
|
|
|
20
27
|
: `${location.origin}${piletApi[0] === '/' ? '' : '/'}${piletApi}`;
|
|
21
28
|
const updateTarget = initialTarget.replace('http', 'ws');
|
|
22
29
|
const ws = new WebSocket(updateTarget);
|
|
30
|
+
const timeoutCache = {};
|
|
31
|
+
const timeout = 150;
|
|
23
32
|
|
|
24
33
|
const appendix = fetch(initialTarget)
|
|
25
34
|
.then((res) => res.json())
|
|
@@ -31,22 +40,37 @@ export function withEmulatorPilets(requestPilets: PiletRequester, options: Emula
|
|
|
31
40
|
if (!hardRefresh) {
|
|
32
41
|
// standard setting is to just perform an inject
|
|
33
42
|
const meta = JSON.parse(data);
|
|
43
|
+
const name = meta.name;
|
|
34
44
|
|
|
35
|
-
//
|
|
36
|
-
|
|
45
|
+
// like a debounce; only one change of the current pilet should be actively processed
|
|
46
|
+
clearTimeout(timeoutCache[name]);
|
|
37
47
|
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
// some bundlers may have fired before writing to the disk
|
|
49
|
+
// so we give them a bit of time before actually loading the pilet
|
|
50
|
+
timeoutCache[name] = setTimeout(() => {
|
|
51
|
+
// we should make sure to only refresh the page / router if pilets have been loaded
|
|
52
|
+
const unfreeze = freezeRouteRefresh();
|
|
53
|
+
|
|
54
|
+
// tear down pilet
|
|
55
|
+
injectPilet({ name } as any);
|
|
44
56
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
57
|
+
// load and evaluate pilet
|
|
58
|
+
loadPilet(meta).then((pilet) => {
|
|
59
|
+
try {
|
|
60
|
+
if (isfunc(injectPilet)) {
|
|
61
|
+
injectPilet(pilet);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// setup actual pilet
|
|
65
|
+
setupPilet(pilet, createApi);
|
|
66
|
+
|
|
67
|
+
// disable route cache, should be zero again and lead to route refresh
|
|
68
|
+
unfreeze();
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error(error);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}, timeout);
|
|
50
74
|
} else {
|
|
51
75
|
location.reload();
|
|
52
76
|
}
|
package/src/types.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface EmulatorConnectorOptions {
|
|
|
6
6
|
loadPilet: PiletLoader;
|
|
7
7
|
injectPilet?(pilet: Pilet): void;
|
|
8
8
|
piletApiFallback?: string;
|
|
9
|
+
integrate?(components: EmulatorComponents): void;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export interface ChangeSet {
|
|
@@ -16,6 +17,10 @@ export interface ChangeSet {
|
|
|
16
17
|
dependencies?: boolean;
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
export interface EmulatorComponents {
|
|
21
|
+
components: Record<string, FC>;
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
export interface DebugComponents {
|
|
20
25
|
wrappers: Record<string, FC>;
|
|
21
26
|
components: Record<string, FC>;
|