diff --git a/package.json b/package.json index 86f79ad..0270620 100644 --- a/package.json +++ b/package.json @@ -39,9 +39,7 @@ "test:e2e-push": "karma start karma/e2e.push.karma.conf.js", "test:e2e-gaIntegration": "karma start karma/e2e.gaIntegration.karma.conf.js", "test:e2e-consumer": "karma start karma/e2e.consumer.karma.conf.js", - "pretest-ts-decls": "npm run build:esm && npm run build:cjs && npm link", - "test-ts-decls": "./scripts/ts-tests.sh", - "posttest-ts-decls": "npm unlink && npm install", + "test-ts-decls": "tsc --build ts-tests", "publish:rc": "npm run check && npm run build && npm publish --tag rc", "publish:stable": "npm run check && npm run build && npm publish" }, diff --git a/scripts/ts-tests.sh b/scripts/ts-tests.sh deleted file mode 100755 index f3a9491..0000000 --- a/scripts/ts-tests.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -cd ts-tests ## Go to typescript tests folder -echo "Installing dependencies for TypeScript declarations testing..." -npm install ## Install dependencies -echo "Dependencies installed, linking the package." -npm link @splitsoftware/splitio-browserjs ## Link to the cloned code -echo "Running tsc compiler." -../node_modules/.bin/tsc ## Run typescript compiler. No need for flags as we have a tsconfig.json file - -if [ $? -eq 0 ] -then - echo "✅ Successfully compiled TS tests." - npm unlink @splitsoftware/splitio-browserjs - exit 0 -else - echo "☠️ Error compiling TS tests." - npm unlink @splitsoftware/splitio-browserjs - exit 1 -fi diff --git a/ts-tests/.gitignore b/ts-tests/.gitignore deleted file mode 100644 index e00a366..0000000 --- a/ts-tests/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -index.js -package-lock.json -node_modules/ \ No newline at end of file diff --git a/ts-tests/index.ts b/ts-tests/index.ts index facca4d..c7dc6d8 100644 --- a/ts-tests/index.ts +++ b/ts-tests/index.ts @@ -11,6 +11,8 @@ * @author Nico Zelaya */ +/// +/// import { SplitFactory as SplitFactoryFull, InLocalStorage as InLocalStorageFull, GoogleAnalyticsToSplit as GoogleAnalyticsToSplitFull, SplitToGoogleAnalytics as SplitToGoogleAnalyticsFull, DebugLogger as DebugLoggerFull, InfoLogger as InfoLoggerFull, WarnLogger as WarnLoggerFull, ErrorLogger as ErrorLoggerFull, PluggableStorage as PluggableStorageFull } from '@splitsoftware/splitio-browserjs/full'; import { SplitFactory, InLocalStorage, GoogleAnalyticsToSplit, SplitToGoogleAnalytics, DebugLogger, InfoLogger, WarnLogger, ErrorLogger, LocalhostFromObject, PluggableStorage } from '@splitsoftware/splitio-browserjs'; diff --git a/ts-tests/package.json b/ts-tests/package.json deleted file mode 100644 index 0a34f53..0000000 --- a/ts-tests/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "ts-tests", - "version": "1.0.0", - "description": "SDK tests for TypeScript declaration files", - "author": "Nico Zelaya", - "license": "Apache-2.0", - "repository": { - "type": "git", - "url": "git+https://github.com/splitio/javascript-browser-client.git" - }, - "dependencies": {} -} diff --git a/ts-tests/tsconfig.json b/ts-tests/tsconfig.json index 4adc239..a0ceeb0 100644 --- a/ts-tests/tsconfig.json +++ b/ts-tests/tsconfig.json @@ -2,7 +2,8 @@ "compilerOptions": { "noImplicitAny": true, "target": "es5", - "module": "commonjs" + "module": "commonjs", + "noEmit": true }, "files": [ "index" diff --git a/types/full/index.d.ts b/types/full/index.d.ts index 50536af..d54c0af 100644 --- a/types/full/index.d.ts +++ b/types/full/index.d.ts @@ -3,9 +3,8 @@ // Definitions by: Nico Zelaya /// -export = JsSdk; -declare module JsSdk { +declare module '@splitsoftware/splitio-browserjs/full' { /** * Full version of the Split.io sdk factory function. * diff --git a/types/index.d.ts b/types/index.d.ts index 25d89a9..b9ce9f1 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -3,9 +3,8 @@ // Definitions by: Nico Zelaya /// -export = JsSdk; -declare module JsSdk { +declare module '@splitsoftware/splitio-browserjs' { /** * Slim version of the Split.io sdk factory function. * diff --git a/types/splitio.d.ts b/types/splitio.d.ts index d54f534..03b0f31 100644 --- a/types/splitio.d.ts +++ b/types/splitio.d.ts @@ -72,7 +72,7 @@ interface ISettings { retriesOnFailureBeforeReady: number, eventsFirstPushWindow: number }, - readonly storage?: SplitIO.StorageSyncFactory | SplitIO.StorageAsyncFactory, + readonly storage: SplitIO.StorageSyncFactory | SplitIO.StorageAsyncFactory, readonly urls: { events: string, sdk: string, @@ -92,7 +92,7 @@ interface ISettings { splitFilters: SplitIO.SplitFilter[], impressionsMode: SplitIO.ImpressionsMode, enabled: boolean, - localhostMode?: SplitIO.LocalhostFactory + localhostMode?: SplitIO.LocalhostFactory, }, readonly userConsent: SplitIO.ConsentStatus } @@ -220,7 +220,7 @@ interface ISharedSettings { * Possible values are 'DEBUG' and 'OPTIMIZED'. * - DEBUG: will send all the impressions generated (recommended only for debugging purposes). * - OPTIMIZED: will send unique impressions to Split Servers avoiding a considerable amount of traffic that duplicated impressions could generate. - * @property {String} impressionsMode + * @property {string} impressionsMode * @default 'OPTIMIZED' */ impressionsMode?: SplitIO.ImpressionsMode, @@ -392,7 +392,7 @@ declare namespace SplitIO { */ type Event = 'init::timeout' | 'init::ready' | 'init::cache-ready' | 'state::update'; /** - * Split attributes should be on object with values of type string or number (dates should be sent as millis since epoch). + * Split attributes should be on object with values of type string, boolean, number (dates should be sent as millis since epoch) or array of strings or numbers. * @typedef {Object.} Attributes * @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#attribute-syntax} */ @@ -406,7 +406,7 @@ declare namespace SplitIO { type AttributeType = string | number | boolean | Array; /** * Split properties should be an object with values of type string, number, boolean or null. Size limit of ~31kb. - * @typedef {Object.} Attributes + * @typedef {Object.} Properties * @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#track */ type Properties = { @@ -495,10 +495,10 @@ declare namespace SplitIO { } }; /** - * A promise that will be resolved with that SplitView. - * @typedef {Promise} SplitView + * A promise that will be resolved with that SplitView or null if the split is not found. + * @typedef {Promise} SplitView */ - type SplitViewAsync = Promise; + type SplitViewAsync = Promise; /** * An array containing the SplitIO.SplitView elements. */ @@ -885,7 +885,7 @@ declare namespace SplitIO { /** * Settings interface for SDK instances created on the browser. * @interface IBrowserSettings - * @extends ISharedSettings + * @extends IBrowserBasicSettings * @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#configuration} */ interface IBrowserSettings extends IBrowserBasicSettings { @@ -1467,20 +1467,20 @@ declare namespace SplitIO { * @function names * @returns {SplitNames} The lists of Split names. */ - names(): SplitNames, + names(): SplitNames; /** * Get the array of splits data in SplitView format. * @function splits * @returns {SplitViews} The list of SplitIO.SplitView. */ - splits(): SplitViews, + splits(): SplitViews; /** * Get the data of a split in SplitView format. * @function split * @param {string} splitName The name of the split we wan't to get info of. - * @returns {SplitView} The SplitIO.SplitView of the given split. + * @returns {SplitView | null} The SplitIO.SplitView of the given split or null if the split is not found. */ - split(splitName: string): SplitView, + split(splitName: string): SplitView | null; } /** * Representation of a manager instance with asynchronous storage of the SDK. @@ -1493,19 +1493,19 @@ declare namespace SplitIO { * @function names * @returns {SplitNamesAsync} A promise that will resolve to the array of Splitio.SplitNames. */ - names(): SplitNamesAsync, + names(): SplitNamesAsync; /** * Get the array of splits data in SplitView format. * @function splits * @returns {SplitViewsAsync} A promise that will resolve to the SplitIO.SplitView list. */ - splits(): SplitViewsAsync, + splits(): SplitViewsAsync; /** * Get the data of a split in SplitView format. * @function split * @param {string} splitName The name of the split we wan't to get info of. - * @returns {SplitViewAsync} A promise that will resolve to the SplitIO.SplitView value. + * @returns {SplitViewAsync} A promise that will resolve to the SplitIO.SplitView value or null if the split is not found. */ - split(splitName: string): SplitViewAsync, + split(splitName: string): SplitViewAsync; } }