@embeddable.com/sdk-core 3.9.3 → 3.9.4
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/index.esm.js +20 -1
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +20 -1
- package/lib/index.js.map +1 -1
- package/lib/utils.d.ts +1 -0
- package/package.json +1 -1
- package/src/build.ts +3 -0
- package/src/cleanup.test.ts +4 -0
- package/src/cleanup.ts +4 -1
- package/src/utils.test.ts +16 -0
- package/src/utils.ts +18 -0
package/lib/utils.d.ts
CHANGED
|
@@ -21,3 +21,4 @@ export declare const removeBuildSuccessFlag: () => Promise<void>;
|
|
|
21
21
|
*/
|
|
22
22
|
export declare const checkBuildSuccess: () => Promise<boolean>;
|
|
23
23
|
export declare const getSDKVersions: () => Record<string, string>;
|
|
24
|
+
export declare const hrtimeToISO8601: (hrtime: number[] | null | undefined) => String;
|
package/package.json
CHANGED
package/src/build.ts
CHANGED
|
@@ -18,6 +18,7 @@ export default async () => {
|
|
|
18
18
|
const breadcrumbs: string[] = [];
|
|
19
19
|
|
|
20
20
|
try {
|
|
21
|
+
const startTime = process.hrtime();
|
|
21
22
|
checkNodeVersion();
|
|
22
23
|
breadcrumbs.push("checkNodeVersion");
|
|
23
24
|
removeBuildSuccessFlag();
|
|
@@ -44,6 +45,8 @@ export default async () => {
|
|
|
44
45
|
// NOTE: likely this will be called inside the loop above if we decide to support clients with mixed frameworks simultaneously.
|
|
45
46
|
breadcrumbs.push("generate");
|
|
46
47
|
await generate(config, "sdk-react");
|
|
48
|
+
// Calculating build time in seconds
|
|
49
|
+
config.buildTime = process.hrtime(startTime);
|
|
47
50
|
breadcrumbs.push("cleanup");
|
|
48
51
|
await cleanup(config);
|
|
49
52
|
await storeBuildSuccessFlag();
|
package/src/cleanup.test.ts
CHANGED
|
@@ -9,6 +9,7 @@ const ctx = {
|
|
|
9
9
|
stencilBuild: "stencilBuild",
|
|
10
10
|
buildDir: "buildDir",
|
|
11
11
|
},
|
|
12
|
+
buildTime: [80, 525000],
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
vi.mock("node:fs/promises", () => ({
|
|
@@ -77,6 +78,9 @@ describe("cleanup", () => {
|
|
|
77
78
|
sdkVersions: {},
|
|
78
79
|
packageManager: "npm",
|
|
79
80
|
packageManagerVersion: "10.7.0",
|
|
81
|
+
metrics: {
|
|
82
|
+
buildTime: "PT1M20.001S",
|
|
83
|
+
},
|
|
80
84
|
},
|
|
81
85
|
}),
|
|
82
86
|
);
|
package/src/cleanup.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { findFiles } from "@embeddable.com/sdk-utils";
|
|
2
2
|
import * as fs from "node:fs/promises";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
-
import { getSDKVersions } from "./utils";
|
|
4
|
+
import { getSDKVersions, hrtimeToISO8601 } from "./utils";
|
|
5
5
|
|
|
6
6
|
export default async (ctx: any) => {
|
|
7
7
|
await extractBuild(ctx);
|
|
@@ -55,6 +55,9 @@ export async function createManifest({
|
|
|
55
55
|
sdkVersions,
|
|
56
56
|
packageManager,
|
|
57
57
|
packageManagerVersion,
|
|
58
|
+
metrics: {
|
|
59
|
+
buildTime: hrtimeToISO8601(ctx.buildTime),
|
|
60
|
+
},
|
|
58
61
|
},
|
|
59
62
|
};
|
|
60
63
|
|
package/src/utils.test.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
storeBuildSuccessFlag,
|
|
6
6
|
checkBuildSuccess,
|
|
7
7
|
SUCCESS_FLAG_FILE,
|
|
8
|
+
hrtimeToISO8601,
|
|
8
9
|
} from "./utils";
|
|
9
10
|
|
|
10
11
|
const startMock = {
|
|
@@ -114,4 +115,19 @@ describe("utils", () => {
|
|
|
114
115
|
expect(result).toBe(false);
|
|
115
116
|
});
|
|
116
117
|
});
|
|
118
|
+
|
|
119
|
+
describe("hrtimeToISO8601", () => {
|
|
120
|
+
test.each([
|
|
121
|
+
{ input: [0, 0], expected: "PT0.000S" },
|
|
122
|
+
{ input: [75, 0], expected: "PT1M15.000S" }, // 1 minute and 15 seconds
|
|
123
|
+
{ input: [2, 500000000], expected: "PT2.500S" }, // 2.5 seconds
|
|
124
|
+
{ input: [0, 123456789], expected: "PT0.123S" }, // 0.123 seconds
|
|
125
|
+
{ input: [0, 500000000], expected: "PT0.500S" }, // 0.5 seconds
|
|
126
|
+
{ input: [1, 0], expected: "PT1.000S" }, // 1 second
|
|
127
|
+
{ input: null, expected: "" },
|
|
128
|
+
{ input: undefined, expected: "" },
|
|
129
|
+
])("converts hrtime $input to $expected", ({ input, expected }) => {
|
|
130
|
+
expect(hrtimeToISO8601(input)).toBe(expected);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
117
133
|
});
|
package/src/utils.ts
CHANGED
|
@@ -125,3 +125,21 @@ export const getSDKVersions = () => {
|
|
|
125
125
|
|
|
126
126
|
return sdkVersions;
|
|
127
127
|
};
|
|
128
|
+
|
|
129
|
+
export const hrtimeToISO8601 = (
|
|
130
|
+
hrtime: number[] | null | undefined,
|
|
131
|
+
): String => {
|
|
132
|
+
if (hrtime === null || hrtime === undefined) {
|
|
133
|
+
return "";
|
|
134
|
+
}
|
|
135
|
+
const seconds = hrtime[0];
|
|
136
|
+
const nanoseconds = hrtime[1];
|
|
137
|
+
|
|
138
|
+
// Convert time components
|
|
139
|
+
const totalSeconds = seconds + nanoseconds / 1e9;
|
|
140
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
141
|
+
const remainingSeconds = totalSeconds % 60;
|
|
142
|
+
|
|
143
|
+
// Format ISO 8601 duration without hours
|
|
144
|
+
return `PT${minutes > 0 ? minutes + "M" : ""}${remainingSeconds.toFixed(3)}S`;
|
|
145
|
+
};
|