Skip to content

Commit

Permalink
feat(@aws-amplify/storage): publish ES2015/ESM artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
aldo-roman committed Dec 11, 2018
1 parent 17ff4bb commit d6d418d
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 89 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ lerna-debug.log
node_modules/**
packages/*/node_modules/**
packages/**/lib/
packages/**/tsc-out/
packages/**/dist/
packages/**/es/
.DS_Store
Expand Down
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,21 @@
"lerna": "2.11.0",
"pre-commit": "^1.2.2",
"rimraf": "^2.6.2",
"rollup": "^0.67.4",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-typescript": "^1.0.0",
"rollup-plugin-copy-glob": "^0.2.2",
"source-map-loader": "^0.2.1",
"ts-jest": "^22.0.0",
"tslint": "^5.7.0",
"tslint-config-airbnb": "^5.8.0",
"typedoc": "^0.11.0",
"typescript": "^2.9.2",
"typescript-formatter": "^6.0.0",
"tslib": "^1.9.3",
"uglifyjs-webpack-plugin": "^0.4.6",
"webpack": "^3.5.5"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
import StorageProvider from '../../src/Providers/AWSS3Provider';
import {AWSS3Provider as StorageProvider} from '../../src/providers/AWSS3Provider';
import { Hub, Credentials } from '@aws-amplify/core';
import * as S3 from 'aws-sdk/clients/s3';



S3.prototype.getSignedUrl = jest.fn((key, params) => {
return 'url';
});
Expand Down
28 changes: 14 additions & 14 deletions packages/storage/__tests__/Storage-unit-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import AWSStorageProvider from '../src/Providers/AWSS3Provider';
import { default as Storage } from "../src/Storage";
import { AWSS3Provider as AWSStorageProvider } from '../src/providers/AWSS3Provider';
import { Storage } from '../src/Storage';

const credentials = {
accessKeyId: 'accessKeyId',
Expand All @@ -9,7 +9,7 @@ const credentials = {
identityId: 'identityId',
authenticated: true
};

const options = {
bucket: 'bucket',
region: 'region',
Expand Down Expand Up @@ -51,7 +51,7 @@ describe('Storage', () => {
describe('configure test', () => {
test('happy case', () => {
const storage = new Storage();

const aws_options = {
aws_user_files_s3_bucket: 'bucket',
aws_user_files_s3_bucket_region: 'region'
Expand All @@ -68,7 +68,7 @@ describe('Storage', () => {
});

describe('get test', async () => {
test('get object without download', async () => {
test('get object without download', async () => {
const get_spyon = jest.spyOn(AWSStorageProvider.prototype, 'get').mockImplementation(() => {
return ;
});
Expand All @@ -79,16 +79,16 @@ describe('Storage', () => {
await storage.get('key', {
Storage: {
AWSS3: {
bucket: 'bucket',
region: 'us-east-1',
bucket: 'bucket',
region: 'us-east-1',
}
}
}) ;
expect(get_spyon).toBeCalled();
get_spyon.mockClear();
});
});


describe('put test', () => {
test('put object succefully', async () => {
Expand All @@ -102,8 +102,8 @@ describe('Storage', () => {
await storage.put('key','object',{
Storage: {
AWSS3: {
bucket: 'bucket',
region: 'us-east-1',
bucket: 'bucket',
region: 'us-east-1',
}
}
}) ;
Expand All @@ -124,8 +124,8 @@ describe('Storage', () => {
await storage.remove('key', {
Storage: {
AWSS3: {
bucket: 'bucket',
region: 'us-east-1',
bucket: 'bucket',
region: 'us-east-1',
}
}
}) ;
Expand All @@ -146,8 +146,8 @@ describe('Storage', () => {
await storage.list('path', {
Storage: {
AWSS3: {
bucket: 'bucket',
region: 'us-east-1',
bucket: 'bucket',
region: 'us-east-1',
}
}
}) ;
Expand Down
34 changes: 7 additions & 27 deletions packages/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"name": "@aws-amplify/storage",
"version": "1.0.23-unstable.1",
"description": "Storage category of aws-amplify",
"main": "./lib/index.js",
"module": "./lib/index.js",
"typings": "./lib/index.d.ts",
"main": "./dist/index.cjs.js",
"module": "./dist/index.esm.js",
"typings": "./dist/index.d.ts",
"publishConfig": {
"access": "public"
},
"scripts": {
"test": "tslint 'src/**/*.ts' && jest --coverage",
"build-with-test": "npm run clean && npm test && tsc && webpack",
"build": "npm run clean && tsc && webpack",
"clean": "rimraf lib lib-esm dist",
"build-with-test": "npm test && npm run build",
"build": "npm run clean && tsc -p tsconfig.es5.json && tsc -p tsconfig.es2015.json && rollup -c",
"clean": "rimraf tsc-out dist",
"format": "tsfmt --useTsfmt tsfmt.json -r src/**/*.ts",
"lint": "tslint 'src/**/*.ts'"
},
Expand All @@ -27,27 +27,7 @@
},
"homepage": "https://github.com/aws/aws-amplify#readme",
"devDependencies": {
"@types/jest": "^20.0.8",
"@types/node": "^8.10.15",
"awesome-typescript-loader": "^3.2.2",
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"compression-webpack-plugin": "^1.1.3",
"find": "^0.2.7",
"jest": "^22.4.3",
"json-loader": "^0.5.7",
"prepend-file": "^1.3.1",
"prettier": "^1.7.4",
"rimraf": "^2.6.2",
"source-map-loader": "^0.2.1",
"ts-jest": "^22.0.0",
"tslint": "^5.7.0",
"tslint-config-airbnb": "^5.8.0",
"typescript-formatter": "^6.0.0",
"uglifyjs-webpack-plugin": "^0.4.6",
"webpack": "^3.5.5"
"typescript": "^3.2.2"
},
"dependencies": {
"@aws-amplify/core": "^1.0.20-unstable.0"
Expand Down
48 changes: 48 additions & 0 deletions packages/storage/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import pkg from './package.json';
import tscES5 from './tsconfig.es5.json';
import tscES2015 from './tsconfig.es2015.json';
import resolve from 'rollup-plugin-node-resolve';
import sourceMaps from 'rollup-plugin-sourcemaps';
import copy from 'rollup-plugin-copy-glob';

const external = [
'@aws-amplify/core',
'aws-sdk/clients/s3'
];
export default [
{
input: tscES5.compilerOptions.outDir + '/index.js',
output: [
{
file: pkg.main,
format: 'cjs',
name: 'index',
sourcemap: true,
exports: 'named'
}
],
plugins: [
resolve(),
sourceMaps(),
],
external
},
{
input: tscES2015.compilerOptions.outDir + '/index.js',
output: [
{
file: pkg.module,
format: 'esm',
name: 'index',
sourcemap: true,
exports: 'named'
}
],
plugins: [
resolve(),
sourceMaps(),
copy([{files: 'tsc-out/esm/**/*.d.ts', dest: 'dist'}])
],
external
}
]
3 changes: 0 additions & 3 deletions packages/storage/src/Providers/index.ts

This file was deleted.

8 changes: 4 additions & 4 deletions packages/storage/src/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

import { ConsoleLogger as Logger, Parser } from '@aws-amplify/core';
import AWSS3Provider from './Providers/AWSS3Provider';
import { AWSS3Provider } from './providers';
import { StorageProvider } from './types';

const logger = new Logger('StorageClass');
Expand All @@ -21,7 +21,7 @@ const DEFAULT_PROVIDER = 'AWSS3';
/**
* Provide storage methods to use AWS S3
*/
export default class StorageClass {
export class Storage {
/**
* @private
*/
Expand All @@ -32,7 +32,7 @@ export default class StorageClass {
/**
* @public
*/
public vault: StorageClass;
public vault: Storage;

/**
* Initialize Storage
Expand Down Expand Up @@ -141,7 +141,7 @@ export default class StorageClass {

/**
* Put a file in storage bucket specified to configure method
* @param {Stirng} key - key of the object
* @param {String} key - key of the object
* @param {Object} object - File to be put in bucket
* @param {Object} [config] - { level : private|protected|public, contentType: MIME Types,
* progressCallback: function }
Expand Down
9 changes: 4 additions & 5 deletions packages/storage/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
* and limitations under the License.
*/

import StorageClass from './Storage';
import { StorageProvider } from './types';
import { Storage as StorageClass} from './Storage';

import Amplify, { ConsoleLogger as Logger } from '@aws-amplify/core';

Expand Down Expand Up @@ -40,6 +39,6 @@ const Storage = _instance;
Amplify.register(Storage);

export default Storage;
export { StorageClass };
export { StorageProvider };
export * from './Providers';
export { Storage, StorageClass };
export * from './providers';
export * from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const dispatchStorageEvent = (track, attrs, metrics) => {
/**
* Provide storage methods to use AWS S3
*/
export default class AWSS3Provider implements StorageProvider{
export class AWSS3Provider implements StorageProvider {

static CATEGORY = 'Storage';
static PROVIDER_NAME = 'AWSS3';
Expand Down Expand Up @@ -144,7 +144,7 @@ export default class AWSS3Provider implements StorageProvider{

/**
* Put a file in S3 bucket specified to configure method
* @param {Stirng} key - key of the object
* @param {String} key - key of the object
* @param {Object} object - File to be put in Amazon S3 bucket
* @param {Object} [config] - { level : private|protected|public, contentType: MIME Types,
* progressCallback: function }
Expand Down
1 change: 1 addition & 0 deletions packages/storage/src/providers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AWSS3Provider } from './AWSS3Provider';
8 changes: 8 additions & 0 deletions packages/storage/tsconfig.es2015.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./tsc-out/esm",
"target": "es2015",
"module": "es2015"
}
}
8 changes: 8 additions & 0 deletions packages/storage/tsconfig.es5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./tsc-out/cjs",
"target": "es5",
"module": "es2015"
}
}
5 changes: 1 addition & 4 deletions packages/storage/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//WARNING: If you are manually specifying files to compile then the tsconfig.json is completely ignored, you must use command line flags
{
"compilerOptions": {
"outDir": "./lib/",
"target": "es5",
"noImplicitAny": false,
"lib": [
"es5",
Expand All @@ -12,7 +10,6 @@
"es2017.object"
],
"sourceMap": true,
"module": "commonjs",
"moduleResolution": "node",
"allowJs": false,
"declaration": true,
Expand All @@ -21,7 +18,7 @@
"../../node_modules/@types"
],
// temporary fix
"types": ["node", "lodash"]
"types": ["node"]
},
"include": [
"src/**/*"
Expand Down
Loading

0 comments on commit d6d418d

Please sign in to comment.