@atlaspack/runtime-js 2.12.1-canary.3613 → 2.12.1-canary.3615
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/lib/helpers/browser/analytics/analytics.js +11 -0
- package/lib/helpers/browser/esm-js-loader-retry.js +18 -10
- package/package.json +8 -8
- package/src/helpers/browser/analytics/analytics.d.ts +6 -0
- package/src/helpers/browser/analytics/analytics.js +6 -0
- package/src/helpers/browser/analytics/analytics.js.flow +8 -0
- package/src/helpers/browser/esm-js-loader-retry.js +19 -7
- package/test/analytics.test.ts +47 -0
|
@@ -44,21 +44,29 @@ async function load(id) {
|
|
|
44
44
|
// Append the current time to the request URL
|
|
45
45
|
// to ensure it has not been cached by the browser
|
|
46
46
|
// eslint-disable-next-line no-undef
|
|
47
|
-
|
|
47
|
+
const result = await __parcel__import__(`${url}?t=${Date.now()}`);
|
|
48
|
+
sendAnalyticsEvent('recovered', url, i);
|
|
49
|
+
return result;
|
|
48
50
|
} catch (error) {
|
|
49
|
-
if (i === maxRetries)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
attempt: i
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
globalThis.dispatchEvent(new CustomEvent('atlaspack:import_retry', event));
|
|
51
|
+
if (i === maxRetries) {
|
|
52
|
+
sendAnalyticsEvent('failure', url, i);
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
sendAnalyticsEvent('progress', url, i);
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
58
|
})();
|
|
61
59
|
}
|
|
62
60
|
return retryState[url];
|
|
63
61
|
}
|
|
62
|
+
function sendAnalyticsEvent(status, targetUrl, attempt) {
|
|
63
|
+
require('./analytics/analytics.js').sendAnalyticsEvent({
|
|
64
|
+
action: 'importRetry',
|
|
65
|
+
attributes: {
|
|
66
|
+
status,
|
|
67
|
+
targetUrl,
|
|
68
|
+
attempt
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
64
72
|
module.exports = load;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/runtime-js",
|
|
3
|
-
"version": "2.12.1-canary.
|
|
3
|
+
"version": "2.12.1-canary.3615+27eca1df6",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -12,16 +12,16 @@
|
|
|
12
12
|
"main": "lib/JSRuntime.js",
|
|
13
13
|
"source": "src/JSRuntime.js",
|
|
14
14
|
"engines": {
|
|
15
|
-
"atlaspack": "2.12.1-canary.
|
|
15
|
+
"atlaspack": "2.12.1-canary.3615+27eca1df6",
|
|
16
16
|
"node": ">= 16.0.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@atlaspack/diagnostic": "2.12.1-canary.
|
|
20
|
-
"@atlaspack/domain-sharding": "2.12.1-canary.
|
|
21
|
-
"@atlaspack/feature-flags": "2.12.1-canary.
|
|
22
|
-
"@atlaspack/plugin": "2.12.1-canary.
|
|
23
|
-
"@atlaspack/utils": "2.12.1-canary.
|
|
19
|
+
"@atlaspack/diagnostic": "2.12.1-canary.3615+27eca1df6",
|
|
20
|
+
"@atlaspack/domain-sharding": "2.12.1-canary.3615+27eca1df6",
|
|
21
|
+
"@atlaspack/feature-flags": "2.12.1-canary.3615+27eca1df6",
|
|
22
|
+
"@atlaspack/plugin": "2.12.1-canary.3615+27eca1df6",
|
|
23
|
+
"@atlaspack/utils": "2.12.1-canary.3615+27eca1df6",
|
|
24
24
|
"nullthrows": "^1.1.1"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "27eca1df6f31abdf1df72f21350b035772302aea"
|
|
27
27
|
}
|
|
@@ -42,14 +42,15 @@ async function load(id) {
|
|
|
42
42
|
// Append the current time to the request URL
|
|
43
43
|
// to ensure it has not been cached by the browser
|
|
44
44
|
// eslint-disable-next-line no-undef
|
|
45
|
-
|
|
45
|
+
const result = await __parcel__import__(`${url}?t=${Date.now()}`);
|
|
46
|
+
sendAnalyticsEvent('recovered', url, i);
|
|
47
|
+
return result;
|
|
46
48
|
} catch (error) {
|
|
47
|
-
if (i === maxRetries)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
);
|
|
49
|
+
if (i === maxRetries) {
|
|
50
|
+
sendAnalyticsEvent('failure', url, i);
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
sendAnalyticsEvent('progress', url, i);
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
})();
|
|
@@ -58,4 +59,15 @@ async function load(id) {
|
|
|
58
59
|
return retryState[url];
|
|
59
60
|
}
|
|
60
61
|
|
|
62
|
+
function sendAnalyticsEvent(status, targetUrl, attempt) {
|
|
63
|
+
require('./analytics/analytics.js').sendAnalyticsEvent({
|
|
64
|
+
action: 'importRetry',
|
|
65
|
+
attributes: {
|
|
66
|
+
status,
|
|
67
|
+
targetUrl,
|
|
68
|
+
attempt,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
61
73
|
module.exports = load;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {sendAnalyticsEvent} from '../src/helpers/browser/analytics/analytics.js';
|
|
2
|
+
import {mock} from 'node:test';
|
|
3
|
+
import type {Mock} from 'node:test';
|
|
4
|
+
import assert from 'node:assert';
|
|
5
|
+
|
|
6
|
+
describe('@atlaspack/analytics', () => {
|
|
7
|
+
let dispatchEventMock: Mock<Window['dispatchEvent']>;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
// @ts-expect-error
|
|
11
|
+
globalThis.CustomEvent = MockCustomEvent;
|
|
12
|
+
dispatchEventMock = mock.fn();
|
|
13
|
+
globalThis.dispatchEvent = dispatchEventMock;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should not throw', () => {
|
|
17
|
+
assert.doesNotThrow(() =>
|
|
18
|
+
sendAnalyticsEvent({
|
|
19
|
+
action: 'test',
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should raise event on window', () => {
|
|
25
|
+
sendAnalyticsEvent({
|
|
26
|
+
action: 'test',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
assert.equal(dispatchEventMock.mock.callCount(), 1);
|
|
30
|
+
assert.deepEqual(dispatchEventMock.mock.calls[0].arguments[0], {
|
|
31
|
+
eventName: 'atlaspack:analytics',
|
|
32
|
+
detail: {
|
|
33
|
+
action: 'test',
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
class MockCustomEvent {
|
|
40
|
+
eventName: string;
|
|
41
|
+
detail: any;
|
|
42
|
+
|
|
43
|
+
constructor(eventName: string, options: any = {}) {
|
|
44
|
+
this.eventName = eventName;
|
|
45
|
+
this.detail = options.detail;
|
|
46
|
+
}
|
|
47
|
+
}
|