Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: distribute via webpack bundling #22

Merged
merged 2 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .azure-pipelines-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ steps:
displayName: "Check linting"
condition: succeededOrFailed()

# Check types
- script: yarn lint:types
displayName: "Check types"
condition: succeededOrFailed()

# Run test:ci
- script: yarn test:ci
displayName: "Run tests"
Expand Down
24 changes: 13 additions & 11 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
version: "2"
plugins:
eslint:
enabled: true

exclude_patterns:
- "test/"
- "src/**/*.spec.ts"
- .azure-pipelines-steps.yml
- .azure-pipelines.yml
- ".circleci/"
- "bin/"
- "docs/"
- "patches/"
- "util/"
- ".codeclimate.yml"
- ".eslintrc.js"
- ".gitignore"
- ".npmignore"
- ".prettierignore"
- "CHANGELOG.md"
- "README.md"
- "aws-spot-price.code-workspace"
- "bin/"
- "CHANGELOG.md"
- "commitlint.config.js"
- "docs/"
- "package.json"
- "patches/"
- "README.md"
- "src/**/*.spec.ts"
- "test/"
- "tsconfig.json"
- "util/"
- "yarn.lock"
- sonar-project.properties
- sonar-project.properties
- webpack.config.js

checks:
file-lines:
Expand Down
5 changes: 3 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ module.exports = {
],
plugins: ['@typescript-eslint', 'prettier'],
rules: {
'no-console': 0,
'import/no-extraneous-dependencies': 0,
'import/prefer-default-export': 0,
'no-console': 0,
'no-param-reassign': 0,
'prettier/prettier': 'error',
},
overrides: [
{
files: ['test/*.js'],
files: ['test/*.js', 'webpack.config.js'],
rules: {
'@typescript-eslint/explicit-function-return-type': 0,
'@typescript-eslint/no-var-requires': 0,
Expand Down
6 changes: 5 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ coverage
docs/
junit.xml
node_modules/
patches/
sonar-project.properties
src/
stats.json
test/
tsconfig*.json
util/
util/
webpack.config.js
yarn.lock
2 changes: 1 addition & 1 deletion bin/aws-spot-price
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require('../dist/cli.js');
require('../dist/aws-spot-price.bundle');
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
"postinstall": "patch-package",
"clean": "rm -rf dist && rm -rf coverage",
"build:ec2-types": "ts-node -T util/generate-ec2-types.ts",
"build": "tsc",
"build": "webpack",
"changelog": "conventional-changelog -i CHANGELOG.md -s -p angular",
"test": "jest --runInBand --verbose",
"test:coverage": "yarn test --coverage",
"test:ci": "yarn test:coverage --ci --reporters=jest-junit --coverageReporters lcov --coverageReporters cobertura",
"lint": "eslint **/*.ts",
"lint:types": "tsc",
"semantic-release": "semantic-release"
},
"config": {
Expand Down Expand Up @@ -93,14 +94,6 @@
"publishConfig": {
"tag": "next"
},
"dependencies": {
"aws-sdk": "^2.544.0",
"ora": "^4.0.2",
"patch-package": "^6.2.0",
"prompts": "^2.2.1",
"table": "^5.4.6",
"yargs": "^14.2.0"
},
"devDependencies": {
"@commitlint/cli": "^8.2.0",
"@semantic-release/changelog": "^3.0.4",
Expand All @@ -115,6 +108,7 @@
"@types/yargs": "^13.0.3",
"@typescript-eslint/eslint-plugin": "^2.3.0",
"@typescript-eslint/parser": "^2.3.0",
"aws-sdk": "^2.544.0",
"commitizen": "^4.0.3",
"conventional-changelog-cli": "^2.0.25",
"cz-conventional-changelog": "3.0.2",
Expand All @@ -131,11 +125,19 @@
"jest-mock-console": "^1.0.0",
"lodash": "^4.17.15",
"nock": "^11.4.0",
"ora": "^4.0.2",
"patch-package": "^6.2.0",
"postinstall-postinstall": "^2.0.0",
"prettier": "^1.18.2",
"prompts": "^2.2.1",
"semantic-release": "^15.13.27",
"table": "^5.4.6",
"ts-jest": "^24.1.0",
"ts-loader": "^6.2.1",
"ts-node": "^8.4.1",
"typescript": "^3.6.3"
"typescript": "^3.6.3",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.9",
"yargs": "^14.2.0"
}
}
2 changes: 1 addition & 1 deletion src/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe('cli', () => {
});

describe('test by spawnSync', () => {
const cliJsPath = resolve(__dirname, '../dist/cli.js');
const cliJsPath = resolve(__dirname, '../dist/aws-spot-price.bundle.js');
it('should stdout help screen', () => {
const s = spawnSync('node', [cliJsPath, '--help'], { encoding: 'utf-8' });
expect(s.stdout).toMatchSnapshot();
Expand Down
13 changes: 6 additions & 7 deletions src/lib/credential.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { config, STS } from 'aws-sdk';
import STS = require('aws-sdk/clients/sts');

type AuthErrorCode = 'CredentialsNotFound' | 'UnAuthorized';

Expand All @@ -17,21 +17,20 @@ export const awsCredentialsCheck = async (options?: {
secretAccessKey?: string;
}): Promise<void> => {
const { accessKeyId, secretAccessKey } = options || {};

const sts = new STS({
accessKeyId,
secretAccessKey,
});
if (
!accessKeyId &&
!secretAccessKey &&
!config.credentials &&
!sts.config.credentials &&
!(process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY)
) {
throw new AuthError('AWS credentials unavailable.', 'CredentialsNotFound');
}

try {
const sts = new STS({
accessKeyId,
secretAccessKey,
});
await sts.getCallerIdentity().promise();
} catch (error) {
throw new AuthError(error.message, 'UnAuthorized');
Expand Down
2 changes: 1 addition & 1 deletion src/lib/lib.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EC2 } from 'aws-sdk';
import * as EC2 from 'aws-sdk/clients/ec2';
import * as ora from 'ora';
import { table } from 'table';

Expand Down
4 changes: 1 addition & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
"sourceMap": true,
"downlevelIteration": true,
"rootDir": "src",
"outDir": "dist",
"experimentalDecorators": true,
"emitDecoratorMetadata": true
"noEmit": true
},
"files": [
"src/cli.ts",
Expand Down
2 changes: 1 addition & 1 deletion util/generate-spot-prices-mock-data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EC2 } from 'aws-sdk';
import * as EC2 from 'aws-sdk/clients/ec2';
import { readFileSync, writeFileSync } from 'fs';
import { find, uniqWith, xorWith } from 'lodash';
import { resolve } from 'path';
Expand Down
33 changes: 33 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const path = require('path');

module.exports = {
mode: 'production',
entry: path.resolve(__dirname, 'src/cli.ts'),
resolve: {
extensions: ['.js', '.json', '.ts'],
},
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, 'dist'),
filename: 'aws-spot-price.bundle.js',
},
stats: {
warningsFilter: [/node_modules\/yargs/],
},
target: 'node',
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
},
],
},
};
Loading