Repository: googlemaps/js-api-loader
Pull request #479 (2021-12-14 06:04:27)

build(deps-dev): bump @types/google.maps from 3.46.0 to 3.47.2
Bumps [@types/google.maps](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/google.maps) from 3.46.0 to 3.47.2.
<details>
<summary>Commits</summary>
<ul>
<li>See full diff in <a href="https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/google.maps">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=@types/google.maps&package-manager=npm_and_yarn&previous-version=3.46.0&new-version=3.47.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

codecov[bot]: # [Codecov](https://codecov.io/gh/googlemaps/js-api-loader/pull/479?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps) Report
> Merging [#479](https://codecov.io/gh/googlemaps/js-api-loader/pull/479?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps) (029ab7f) into [main](https://codecov.io/gh/googlemaps/js-api-loader/commit/64bb4728ea8dcdce8a3029e54d14608270d7badf?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps) (64bb472) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/googlemaps/js-api-loader/pull/479/graphs/tree.svg?width=650&height=150&src=pr&token=aAmgcWFXMs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps)](https://codecov.io/gh/googlemaps/js-api-loader/pull/479?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps)

```diff
@@            Coverage Diff            @@
##              main      #479   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          123       123           
  Branches        25        25           
=========================================
  Hits           123       123           
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/googlemaps/js-api-loader/pull/479?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/googlemaps/js-api-loader/pull/479?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps). Last update [64bb472...029ab7f](https://codecov.io/gh/googlemaps/js-api-loader/pull/479?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps).


Patch:
diff --git a/package-lock.json b/package-lock.json
index 0375789..3f14bce 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
 {
   "name": "@googlemaps/js-api-loader",
-  "version": "1.12.11",
+  "version": "1.13.1",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
@@ -4053,9 +4053,9 @@
       "dev": true
     },
     "@types/google.maps": {
-      "version": "3.46.0",
-      "resolved": "https://registry.npmjs.org/@types/google.maps/-/google.maps-3.46.0.tgz",
-      "integrity": "sha512-TvrN/+XkDSblCrkx9bJXSrYOrDeUgiPl1ec215vv4mYBuvU3YOAq0XVB32dV6r7ySctqJO1M7aEgVJsJZOgrmQ==",
+      "version": "3.47.2",
+      "resolved": "https://registry.npmjs.org/@types/google.maps/-/google.maps-3.47.2.tgz",
+      "integrity": "sha512-mFmt428CY4UN49U8KH5J4RfcdkeRu6SZyPIXxU1MA0pnHb4pqn/c/whawTodB3pkKWe8F9fXfUlpBFsk9HucXw==",
       "dev": true
     },
     "@types/graceful-fs": {
diff --git a/package.json b/package.json
index 747197c..0f936ee 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@googlemaps/js-api-loader",
-  "version": "1.12.11",
+  "version": "1.13.1",
   "description": "Wrapper for the loading of Google Maps JavaScript API script in the browser",
   "keywords": [
     "google",
@@ -21,7 +21,8 @@
   "module": "dist/index.esm.js",
   "types": "dist/index.d.ts",
   "files": [
-    "dist/*"
+    "dist/",
+    "src/"
   ],
   "scripts": {
     "docs": "typedoc src/index.ts && cp -r dist docs/dist && cp -r examples docs/examples",
diff --git a/rollup.config.js b/rollup.config.js
index 8b60966..a785023 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -34,7 +34,7 @@ export default [
   {
     input: "src/index.ts",
     plugins: [
-      typescript({ tsconfig: "./tsconfig.json" }),
+      typescript({ tsconfig: "./tsconfig.json", declarationDir: "./" }),
 
       nodeResolve(resolveOptions),
       commonjs(),
diff --git a/src/index.ts b/src/index.ts
index e8fc2f3..f476a84 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -27,7 +27,7 @@ declare global {
 
 export const DEFAULT_ID = "__googleMapsScriptId";
 
-type Libraries = (
+export type Libraries = (
   | "drawing"
   | "geometry"
   | "localContext"
@@ -165,6 +165,16 @@ export interface LoaderOptions {
   retries?: number;
 }
 
+/**
+ * The status of the [[Loader]].
+ */
+export enum LoaderStatus {
+  INITIALIZED,
+  LOADING,
+  SUCCESS,
+  FAILURE,
+}
+
 /**
  * [[Loader]] makes it easier to add Google Maps JavaScript API to your application
  * dynamically using
@@ -314,6 +324,19 @@ export class Loader {
     };
   }
 
+  public get status(): LoaderStatus {
+    if (this.errors.length) {
+      return LoaderStatus.FAILURE;
+    }
+    if (this.done) {
+      return LoaderStatus.SUCCESS;
+    }
+    if (this.loading) {
+      return LoaderStatus.LOADING;
+    }
+    return LoaderStatus.INITIALIZED;
+  }
+
   private get failed(): boolean {
     return this.done && !this.loading && this.errors.length >= this.retries + 1;
   }


Test patch:
diff --git a/src/index.test.ts b/src/index.test.ts
index 43fe595..06242cd 100644
--- a/src/index.test.ts
+++ b/src/index.test.ts
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 /* eslint @typescript-eslint/no-explicit-any: 0 */
-import { DEFAULT_ID, Loader, LoaderOptions } from ".";
+import { DEFAULT_ID, Loader, LoaderOptions, LoaderStatus } from ".";
 
 jest.useFakeTimers();
 
@@ -54,6 +54,7 @@ test.each([
 ])("createUrl is correct", (options: LoaderOptions, expected: string) => {
   const loader = new Loader(options);
   expect(loader.createUrl()).toEqual(expected);
+  expect(loader.status).toBe(LoaderStatus.INITIALIZED);
 });
 
 test("uses default id if empty string", () => {
@@ -128,6 +129,7 @@ test("script onerror should reject promise", async () => {
   expect(loader["done"]).toBeTruthy();
   expect(loader["loading"]).toBeFalsy();
   expect(loader["errors"].length).toBe(1);
+  expect(loader.status).toBe(LoaderStatus.FAILURE);
 });
 
 test("script onerror should reject promise with multiple loaders", async () => {
@@ -301,6 +303,7 @@ test("singleton should be used", () => {
 
   loader["done"] = true;
   expect(extraLoader["done"]).toBe(loader["done"]);
+  expect(loader.status).toBe(LoaderStatus.SUCCESS);
 });
 
 test("singleton should throw with different options", () => {
@@ -333,7 +336,7 @@ test("loader should resolve immediately when failed loading", async () => {
 test("loader should wait if already loading", () => {
   const loader = new Loader({ apiKey: "foo", retries: 0 });
   loader["loading"] = true;
-
+  expect(loader.status).toBe(LoaderStatus.LOADING);
   loader.load();
 });