Skip to content

Commit

Permalink
chore(credential-provider-cognito-identity): export es modules (#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Feb 7, 2020
1 parent 1bdfed2 commit 4c8eb6c
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 37 deletions.
4 changes: 3 additions & 1 deletion packages/credential-provider-cognito-identity/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const base = require("../../jest.config.base.js");

module.exports = {
...base
...base,
//only test cjs dist, avoid testing the package twice
testPathIgnorePatterns: ["/node_modules/", "/es/"]
};
10 changes: 7 additions & 3 deletions packages/credential-provider-cognito-identity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
"version": "1.0.0-alpha.14",
"scripts": {
"prepublishOnly": "tsc",
"pretest": "tsc -p tsconfig.test.json",
"pretest": "yarn build:cjs && yarn build:es",
"build:cjs": "tsc -p tsconfig.json",
"build:es": "tsc -p tsconfig.es.json",
"test": "jest"
},
"main": "./build/index.js",
"types": "./build/index.d.ts",
"main": "./dist/cjs/index.js",
"module": "./dist/es/index.js",
"types": "./dist/cjs/index.d.ts",
"sideEffects": false,
"author": {
"name": "AWS SDK for JavaScript Team",
"url": "https://aws.amazon.com/javascript/"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Storage } from "./Storage";
import { ProviderError } from "@aws-sdk/property-provider";

const STORE_NAME = "IdentityIds";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { fromCognitoIdentityPool } from "./fromCognitoIdentityPool";
import { ProviderError } from "@aws-sdk/property-provider";
import { GetIdCommand } from "@aws-sdk/client-cognito-identity";
import { Storage } from "./Storage";

jest.mock("./fromCognitoIdentity", () => {
const promiseFunc = jest.fn().mockResolvedValue({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
/**
* @jest-environment node
*/

import { localStorage } from "./localStorage";
import { localStorage as storage } from "./localStorage";
import { InMemoryStorage } from "./InMemoryStorage";

describe("localStorage", () => {
//use node run time in jest(default jsdom)
// set store and restore indexedDB and localStorage before and after the test
let indexDB: any = undefined;
let localStorage: any = undefined;
beforeEach(() => {
if (typeof self === "object") indexDB = self.indexedDB;
if (typeof window === "object") localStorage = window.localStorage;
});
afterEach(() => {
if (typeof self === "object") defineProperty(self, "indexedDB", indexDB);
if (typeof window === "object")
defineProperty(window, "localStorage", localStorage);
});
it("should return an in-memory storage implementation when indexDB or localStorage is not available", () => {
expect(localStorage()).toBeInstanceOf(InMemoryStorage);
defineProperty(self, "indexedDB", null);
defineProperty(window, "localStorage", null);
expect(storage()).toBeInstanceOf(InMemoryStorage);
});
});

const defineProperty = (object: any, name: string, value: any) => {
Object.defineProperty(object, name, {
value,
configurable: true
});
};
20 changes: 20 additions & 0 deletions packages/credential-provider-cognito-identity/tsconfig.es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"target": "es5",
"module": "esnext",
"moduleResolution": "node",
"declaration": false,
"declarationDir": null,
"downlevelIteration": true,
"lib": [
"dom",
"es5",
"es2015.promise",
"es2015.collection",
"es2015.iterable",
"es2015.symbol.wellknown"
],
"outDir": "dist/es"
}
}
17 changes: 6 additions & 11 deletions packages/credential-provider-cognito-identity/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
{
"compilerOptions": {
"target": "es5",
"target": "es2017",
"module": "commonjs",
"declaration": true,
"strict": true,
"sourceMap": true,
"downlevelIteration": true,
"importHelpers": true,
"noEmitHelpers": true,
"lib": [
"dom",
"es5",
"es2015.promise",
"es2015.collection",
"es2015.iterable",
"es2015.symbol.wellknown"
],
"lib": ["dom"],
"rootDir": "./src",
"outDir": "./build",
"incremental": true
"outDir": "dist/cjs",
"incremental": true,
"declarationDir": "./dist/cjs",
"noUnusedLocals": true
}
}
13 changes: 0 additions & 13 deletions packages/credential-provider-cognito-identity/tsconfig.test.json

This file was deleted.

0 comments on commit 4c8eb6c

Please sign in to comment.