Skip to content

Commit 0cc8564

Browse files
committed
v2.0.1
1 parent aa81847 commit 0cc8564

File tree

12 files changed

+1804
-513
lines changed

12 files changed

+1804
-513
lines changed

.eslintrc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"extends": [
3+
"eslint:recommended",
4+
"plugin:@typescript-eslint/recommended",
5+
"prettier",
6+
"prettier/@typescript-eslint"
7+
],
8+
"parser": "@typescript-eslint/parser",
9+
"plugins": [
10+
"@typescript-eslint",
11+
"import",
12+
"prettier"
13+
],
14+
"parserOptions": {
15+
"sourceType": "module",
16+
"ecmaFeatures": {
17+
"jsx": true
18+
}
19+
},
20+
"settings": {
21+
"import/extensions": [
22+
".ts",
23+
".tsx"
24+
]
25+
},
26+
"env": {
27+
"es6": true,
28+
"browser": true,
29+
"serviceworker": true,
30+
"node": true
31+
},
32+
"rules": {
33+
"prefer-const": "error",
34+
"import/order": "error",
35+
"prettier/prettier": "error"
36+
}
37+
}

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## 2.0.1 (2020-11-20)
2+
3+
Fixes:
4+
- Import `google` namespace through `import type` instead of `import` to avoid compiler errors
5+
6+
## 2.0.0 (2020-11-20)
7+
8+
Breaking changes:
9+
- Moved declaration of `google.ima` namespace from global scope to module scope to avoid type clashes, it now has to be imported explicitly: `import type { google } from '@alugha/ima;`
10+
11+
Technical changes:
12+
- Updated from TypeScript `2.6` to `4.1`
13+
- Updated from Prettier `1.10` to `2.2`
14+
- Migrated from TSLint to ESLint

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The MIT License (MIT)
22

3-
**Copyright 2018 Alugha GmbH**
3+
**Copyright 2020 Alugha GmbH**
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ For information on the Google IMA SDK itself, please visit
1717
With promises and CommonJS modules:
1818

1919
```typescript
20-
const { loadImaSdk } = require("@alugha/ima");
20+
const { loadImaSdk, google } = require("@alugha/ima");
2121

2222
loadImaSdk()
2323
.then(ima => {
@@ -35,7 +35,7 @@ loadImaSdk()
3535
With `async` / `await` and ES2015 modules:
3636

3737
```typescript
38-
import { loadImaSdk } from "@alugha/ima";
38+
import { loadImaSdk, google } from "@alugha/ima";
3939

4040
const example = async () => {
4141
try {

package.json

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"name": "@alugha/ima",
3-
"version": "1.2.0",
4-
"description":
5-
"A library for asynchronously loading the Google IMA SDK with static typing for the SDK",
3+
"version": "2.0.1",
4+
"description": "A library for asynchronously loading the Google IMA SDK with static typing for the SDK",
65
"license": "MIT",
76
"author": "Niklas Korz <nk@alugha.com>",
87
"homepage": "https://alugha.com",
@@ -13,34 +12,50 @@
1312
"bugs": {
1413
"url": "https://github.com/alugha/typed-ima-sdk/issues"
1514
},
16-
"files": ["lib", "typings"],
15+
"files": [
16+
"lib"
17+
],
1718
"main": "lib/cjs/index.js",
1819
"jsnext:main": "lib/esm/index.js",
1920
"module": "lib/esm/index.js",
2021
"typings": "lib/typings/index.d.ts",
2122
"scripts": {
2223
"precommit": "lint-staged",
2324
"prepare": "yarn compile",
24-
"lint": "yarn lint:cmd src/**/*.ts",
25-
"lint:cmd": "tslint -p tsconfig.json -c tslint.json",
25+
"lint": "eslint src/**/*.ts",
2626
"precompile": "rimraf lib",
27-
"compile": "yarn compile:esm && yarn compile:cjs",
27+
"compile": "yarn compile:esm && yarn compile:cjs && cp src/ima.d.ts lib/typings",
2828
"compile:esm": "tsc --project tsconfig.json",
2929
"compile:cjs": "tsc --project tsconfig.cjs.json"
3030
},
3131
"lint-staged": {
32-
"*.ts": ["yarn lint:cmd --fix", "git add"],
33-
"*.md": ["prettier --write", "git add"],
34-
"*.json": ["prettier --write", "git add"]
32+
"*.ts": [
33+
"yarn lint--fix",
34+
"git add"
35+
],
36+
"*.md": [
37+
"prettier --write",
38+
"git add"
39+
],
40+
"*.json": [
41+
"prettier --write",
42+
"git add"
43+
]
3544
},
3645
"devDependencies": {
37-
"husky": "^0.14.3",
38-
"lint-staged": "^6.1.0",
39-
"prettier": "^1.10.2",
40-
"rimraf": "^2.6.2",
41-
"tslint": "^5.9.1",
42-
"tslint-config-prettier": "^1.6.0",
43-
"tslint-plugin-prettier": "^1.3.0",
44-
"typescript": "^2.6.2"
46+
"@typescript-eslint/eslint-plugin": "^4.8.1",
47+
"@typescript-eslint/parser": "^4.8.1",
48+
"eslint": "^7.13.0",
49+
"eslint-config-prettier": "^6.15.0",
50+
"eslint-plugin-import": "^2.22.1",
51+
"eslint-plugin-prettier": "^3.1.4",
52+
"husky": "^4.3.0",
53+
"lint-staged": "^10.5.1",
54+
"prettier": "^2.2.0",
55+
"rimraf": "^3.0.2",
56+
"tslint": "^6.1.3",
57+
"tslint-config-prettier": "^1.18.0",
58+
"tslint-plugin-prettier": "^2.3.0",
59+
"typescript": "^4.1.2"
4560
}
4661
}

typings/ima.d.ts renamed to src/ima.d.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
declare namespace google {
1+
/* eslint-disable @typescript-eslint/no-unused-vars */
2+
/* eslint-disable @typescript-eslint/no-explicit-any */
3+
export namespace google {
24
/**
35
* The Google IMA SDK for HTML5 V3 allows developers to request and track VAST ads in a HTML5 video environment. For platform compatibility information and a detailed list of the video ad features supported by each of the IMA SDKs, see Support and Compatibility.
46
*
@@ -44,7 +46,7 @@ declare namespace google {
4446
getCompanionAds(
4547
adSlotWidth: number,
4648
adSlotHeight: number,
47-
settings?: CompanionAdSelectionSettings,
49+
settings?: CompanionAdSelectionSettings
4850
): CompanionAd[];
4951
/**
5052
* Returns the content type of the currently selected creative, or empty string if no creative is selected or the content type is unavailable. For linear ads, the content type is only going to be available after the START event, when the media file is selected.
@@ -181,7 +183,7 @@ declare namespace google {
181183
constructor(
182184
containerElement: HTMLElement,
183185
videoElement?: HTMLVideoElement,
184-
clickTrackingElement?: HTMLElement,
186+
clickTrackingElement?: HTMLElement
185187
);
186188
/**
187189
* Destroys internal state and previously created DOM elements. The IMA SDK will be unloaded and no further calls to any APIs should be made.
@@ -621,7 +623,7 @@ declare namespace google {
621623
public addEventListener(
622624
type: AdsManagerLoadedEvent.Type,
623625
listener: AdsManagerLoadedEvent.Listener,
624-
useCapture?: boolean,
626+
useCapture?: boolean
625627
): void;
626628
/**
627629
* Adds an event listener for the specified type.
@@ -632,7 +634,7 @@ declare namespace google {
632634
public addEventListener(
633635
type: AdErrorEvent.Type,
634636
listener: AdErrorEvent.Listener,
635-
useCapture?: boolean,
637+
useCapture?: boolean
636638
): void;
637639
/**
638640
* Removes an event listener for the specified type.
@@ -643,7 +645,7 @@ declare namespace google {
643645
public removeEventListener(
644646
type: AdsManagerLoadedEvent.Type,
645647
listener: AdsManagerLoadedEvent.Listener,
646-
useCapture?: boolean,
648+
useCapture?: boolean
647649
): void;
648650
/**
649651
* Removes an event listener for the specified type.
@@ -654,7 +656,7 @@ declare namespace google {
654656
public removeEventListener(
655657
type: AdErrorEvent.Type,
656658
listener: AdErrorEvent.Listener,
657-
useCapture?: boolean,
659+
useCapture?: boolean
658660
): void;
659661
/**
660662
* Signals to the SDK that the content is finished. This will allow the SDK to play post-roll ads, if any are loaded via ad rules.
@@ -690,7 +692,7 @@ declare namespace google {
690692
addEventListener(
691693
type: AdEvent.Type,
692694
listener: AdEvent.Listener,
693-
useCapture?: boolean,
695+
useCapture?: boolean
694696
): void;
695697
/**
696698
* Adds an event listener for the specified type.
@@ -701,7 +703,7 @@ declare namespace google {
701703
addEventListener(
702704
type: AdErrorEvent.Type,
703705
listener: AdErrorEvent.Listener,
704-
useCapture?: boolean,
706+
useCapture?: boolean
705707
): void;
706708
/**
707709
* Removes an event listener for the specified type.
@@ -712,7 +714,7 @@ declare namespace google {
712714
removeEventListener(
713715
type: AdEvent.Type,
714716
listener: AdEvent.Listener,
715-
useCapture?: boolean,
717+
useCapture?: boolean
716718
): void;
717719
/**
718720
* Removes an event listener for the specified type.
@@ -723,7 +725,7 @@ declare namespace google {
723725
removeEventListener(
724726
type: AdErrorEvent.Type,
725727
listener: AdErrorEvent.Listener,
726-
useCapture?: boolean,
728+
useCapture?: boolean
727729
): void;
728730
/**
729731
* Collapse the current ad. This is no-op for HTML5 SDK.
@@ -772,7 +774,7 @@ declare namespace google {
772774
width: number,
773775
height: number,
774776
viewMode: ViewMode,
775-
videoElement?: HTMLVideoElement,
777+
videoElement?: HTMLVideoElement
776778
): void;
777779
/**
778780
* Returns true if a custom click tracking element is being used for click tracking on the current ad. Custom click tracking is only used when an optional click tracking element is provided to the AdDisplayContainer, custom playback is used, and the current ad is not an AdSense/AdX ad.
@@ -821,7 +823,7 @@ declare namespace google {
821823
* @param adsRenderingSettings The updated ads rendering settings.
822824
*/
823825
updateAdsRenderingSettings(
824-
adsRenderingSettings: Partial<AdsRenderingSettings>,
826+
adsRenderingSettings: Partial<AdsRenderingSettings>
825827
): void;
826828
}
827829

@@ -840,7 +842,7 @@ declare namespace google {
840842
currentTime: number;
841843
duration: number;
842844
},
843-
adsRenderingSettings?: Partial<AdsRenderingSettings>,
845+
adsRenderingSettings?: Partial<AdsRenderingSettings>
844846
): AdsManager;
845847
/**
846848
* @returns During ads load request it is possible to provide an object that is available once the ads load is complete. One possible use case: relate ads response to a specific request and use user request content object as a key for identifying the response.
@@ -1166,7 +1168,7 @@ declare namespace google {
11661168
* @param mode The desired companion backfill mode.
11671169
*/
11681170
public setCompanionBackfill(
1169-
mode: ImaSdkSettings.CompanionBackfillMode,
1171+
mode: ImaSdkSettings.CompanionBackfillMode
11701172
): void;
11711173
/**
11721174
* Sets whether to disable custom playback on iOS 10+ browsers. If true, ads will play inline if the content video is inline. This enables TrueView skippable ads. However, the ad will stay inline and not support iOS's native fullscreen. When false, ads will play in the same player as your content. The value set here when an AdDisplayContainer is created is used for the lifetime of the container. The default value is false.

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/// <reference path="../typings/ima.d.ts" />
2-
3-
export { default as loadImaSdk } from './loadImaSdk';
4-
export { default as loadScript } from './loadScript';
1+
import type { google } from "./ima";
2+
export { default as loadImaSdk } from "./loadImaSdk";
3+
export { default as loadScript } from "./loadScript";
54
export type ImaSdk = typeof google.ima;
5+
export { google };

src/loadImaSdk.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
/// <reference path="../typings/ima.d.ts" />
2-
import loadScript from './loadScript';
1+
import type { google } from "./ima";
2+
import loadScript from "./loadScript";
33

4-
declare global {
5-
interface Window {
6-
google: {
7-
ima: typeof google.ima;
8-
};
9-
}
4+
interface ImaWindow {
5+
google: {
6+
ima: typeof google.ima;
7+
};
108
}
119

12-
const imaSdkSrc = '//imasdk.googleapis.com/js/sdkloader/ima3.js';
10+
const imaSdkSrc = "//imasdk.googleapis.com/js/sdkloader/ima3.js";
1311
let pendingPromise: Promise<typeof google.ima> | null = null;
1412

1513
const promiseFinished = () => {
1614
pendingPromise = null;
1715
};
1816

1917
const loadImaSdk = (): Promise<typeof google.ima> => {
20-
if (window.google && window.google.ima) {
21-
return Promise.resolve(window.google.ima);
18+
const w = (window as unknown) as ImaWindow;
19+
if (w.google && w.google.ima) {
20+
return Promise.resolve(w.google.ima);
2221
}
2322
if (pendingPromise) {
2423
return pendingPromise;
2524
}
26-
pendingPromise = loadScript(imaSdkSrc).then(() => window.google.ima);
25+
pendingPromise = loadScript(imaSdkSrc).then(() => w.google.ima);
2726
pendingPromise.then(promiseFinished).catch(promiseFinished);
2827
return pendingPromise;
2928
};

src/loadScript.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Asynchronous loader for external scripts
22

3-
const loadScript = (src: string) =>
3+
const loadScript = (src: string): Promise<Event> =>
44
new Promise((resolve, reject) => {
5-
const script = document.createElement('script');
5+
const script = document.createElement("script");
66
script.async = true;
77
script.src = src;
88
script.onload = resolve;

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
"declaration": true,
1818
"declarationDir": "./lib/typings"
1919
},
20-
"include": ["./typings/**/*", "./src/**/*"],
20+
"include": ["./src/**/*"],
2121
"exclude": ["./node_modules", "./lib"]
2222
}

0 commit comments

Comments
 (0)