@braintree/asset-loader 2.0.4 → 2.1.0

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/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ import loadScript = require("./load-script");
2
2
  import loadStylesheet = require("./load-stylesheet");
3
3
  export { loadScript };
4
4
  export { loadStylesheet };
5
+ export type { AssetLoadError, AssetLoadFailureKind } from "./types";
@@ -1,5 +1,14 @@
1
1
  "use strict";
2
2
  var scriptPromiseCache = {};
3
+ function buildLoadError(src, failureKind, startTime) {
4
+ var suffix = failureKind === "abort" ? "has aborted." : "failed to load.";
5
+ var error = new Error("".concat(src, " ").concat(suffix));
6
+ error.src = src;
7
+ error.failureKind = failureKind;
8
+ error.timing = performance.now() - startTime;
9
+ error.onLine = navigator.onLine;
10
+ return error;
11
+ }
3
12
  function loadScript(options) {
4
13
  var scriptLoadPromise;
5
14
  var stringifiedOptions = JSON.stringify(options);
@@ -28,14 +37,15 @@ function loadScript(options) {
28
37
  script.setAttribute("data-".concat(key), "".concat(attrs[key]));
29
38
  });
30
39
  scriptLoadPromise = new Promise(function (resolve, reject) {
40
+ var startTime = performance.now();
31
41
  script.addEventListener("load", function () {
32
42
  resolve(script);
33
43
  });
34
44
  script.addEventListener("error", function () {
35
- reject(new Error("".concat(options.src, " failed to load.")));
45
+ reject(buildLoadError(options.src, "error", startTime));
36
46
  });
37
47
  script.addEventListener("abort", function () {
38
- reject(new Error("".concat(options.src, " has aborted.")));
48
+ reject(buildLoadError(options.src, "abort", startTime));
39
49
  });
40
50
  container.appendChild(script);
41
51
  });
package/dist/types.d.ts CHANGED
@@ -8,6 +8,13 @@ export type LoadScriptOptions = {
8
8
  type?: string;
9
9
  id?: string;
10
10
  };
11
+ export type AssetLoadFailureKind = "error" | "abort";
12
+ export type AssetLoadError = Error & {
13
+ src: string;
14
+ failureKind: AssetLoadFailureKind;
15
+ timing: number;
16
+ onLine: boolean;
17
+ };
11
18
  export type LoadStylesheetOptions = {
12
19
  href: string;
13
20
  container?: HTMLElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@braintree/asset-loader",
3
- "version": "2.0.4",
3
+ "version": "2.1.0",
4
4
  "description": "A module to load frontend assets.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,7 +15,9 @@
15
15
  "build": "tsc --declaration",
16
16
  "lint": "eslint --ext js,ts .",
17
17
  "posttest": "npm run lint",
18
- "test": "jest"
18
+ "test": "jest",
19
+ "prepare": "husky",
20
+ "commit": "cz"
19
21
  },
20
22
  "repository": {
21
23
  "type": "git",
@@ -29,12 +31,17 @@
29
31
  },
30
32
  "homepage": "https://github.com/braintree/asset-loader#readme",
31
33
  "devDependencies": {
34
+ "@commitlint/cli": "^20.5.0",
35
+ "@commitlint/config-conventional": "^20.5.0",
32
36
  "@types/jest": "^30.0.0",
33
37
  "@types/promise-polyfill": "^6.0.6",
34
38
  "@typescript-eslint/eslint-plugin": "^5.62.0",
39
+ "commitizen": "^4.3.1",
40
+ "cz-customizable": "^7.5.4",
35
41
  "eslint": "^8.57.1",
36
42
  "eslint-config-braintree": "^6.0.1",
37
43
  "eslint-plugin-prettier": "^5.5.4",
44
+ "husky": "^9.1.7",
38
45
  "jest": "^30.2.0",
39
46
  "jest-environment-jsdom": "^30.2.0",
40
47
  "prettier": "^3.7.4",
@@ -51,6 +58,24 @@
51
58
  "tsconfig": "src/__tests__/tsconfig.test.json"
52
59
  }
53
60
  }
61
+ },
62
+ "collectCoverage": true,
63
+ "collectCoverageFrom": [
64
+ "src/**/*.ts",
65
+ "!src/__tests__/**"
66
+ ],
67
+ "coverageThreshold": {
68
+ "global": {
69
+ "lines": 80,
70
+ "statements": 80,
71
+ "branches": 80,
72
+ "functions": 80
73
+ }
74
+ }
75
+ },
76
+ "config": {
77
+ "commitizen": {
78
+ "path": "./node_modules/cz-customizable"
54
79
  }
55
80
  }
56
81
  }