Skip to content

Commit

Permalink
chore: add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
sergioramos committed Jun 14, 2020
1 parent d65010d commit e130641
Show file tree
Hide file tree
Showing 23 changed files with 728 additions and 244 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,27 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: '13.x'
- name: Setup Cache
uses: actions/cache@v1
with:
path: .yarn
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
- name: Install dependencies
run: yarn install --immutable --immutable-cache
- name: Benchmark
run: yarn run benchmark
- name: Get branch
uses: rlespinasse/github-slug-action@1.1.0
- name: Release
uses: ridedott/release-me-action@master
if: ${{ env.GITHUB_REF_SLUG == 'master' }}
with:
node-module: true
commit-assets: |
./BENCHMARK.md
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }}
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,37 @@ npm install --save-dev serverless-plugin-tree-shake
plugins:
- serverless-plugin-tree-shake
package:
# no need to spend time doing excluding dev dependencies, given that
# no need to spend time excluding dev dependencies, given that
# serverless-plugin-tree-shake does it already
excludeDevDependencies: false
```

**example output before** (with `excludeDevDependencies` enabled):

```
$ time sls package
33.93s user 20.17s system 82% cpu 1:05.94 total
```

```
$ tree
988 directories, 5978 files
```

**example output after**:

```
$ time sls package
3.77s user 1.27s system 51% cpu 9.724 total
```

```
$ tree
24 directories, 48 files
```

More details: [`BENCHMARK.md`](./BENCHMARK.md).

##### typescript support

This plugins supports typescript natively. It uses the installed typescript package, reads the appropriate config, and transpiles to js according to that config. You can see examples on the [`__fixtures__`](./test/__fixtures__) that start with `ts-`.
Expand All @@ -41,10 +67,13 @@ package:

You can use the `include` and `exclude` global, and per-function, configurations and it will include/exclude the especified files/patterns.

## performance

Check out [`BENCHMARK.md`](./BENCHMARK.md) - auto generated.

## todo

- [ ] tree shake handlers, not only the file tree
- [ ] add benchmarks

## license

Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"plugin"
],
"scripts": {
"benchmark": "node test/benchmark.js",
"eslint": "eslint . --ext .js",
"fmt": "prettier --config package.json --write '**/*'",
"test": "NODE_ENV=test ava --timeout=5m"
Expand All @@ -45,6 +46,7 @@
"devDependencies": {
"apr-for-each": "^3.0.3",
"apr-intercept": "^3.0.4",
"apr-main": "^4.0.3",
"apr-reduce": "^3.0.3",
"ava": "^3.8.2",
"directory-tree": "^2.2.4",
Expand All @@ -55,8 +57,11 @@
"hasha": "^5.2.0",
"husky": "^4.2.5",
"lint-staged": "^10.2.10",
"markdown-table": "^2.0.0",
"path-type": "^4.0.0",
"prettier": "^2.0.5"
"prettier": "^2.0.5",
"pretty-bytes": "^5.3.0",
"pretty-ms": "^7.0.0"
},
"peerDependencies": {
"serverless": "^1.71.3",
Expand Down Expand Up @@ -102,7 +107,7 @@
},
"ava": {
"files": [
"test/*.js"
"test/index.js"
]
}
}
8 changes: 7 additions & 1 deletion test/__fixtures__/ts-ws-all/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
"name": "serverless-plugin-tree-shake-ts-ws-all",
"private": true,
"devDependencies": {
"@zeit/ncc": "^0.22.3",
"serverless": "^1.72.0",
"serverless-plugin-ncc": "^0.4.0",
"serverless-plugin-typescript": "^1.1.9",
"typescript": "^3.9.5"
},
"workspaces": [
"handlers/*",
"framework",
"out",
"plugin"
]
],
"resolutions": {
"ts-loader": "7.0.5"
}
}
11 changes: 9 additions & 2 deletions test/__fixtures__/ts-ws-all/serverless.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
const { name: service } = require('./package.json');

const DISABLE_TREE_SHAKE = Boolean(JSON.parse(process.env.DISABLE_TREE_SHAKE || '0'));
const ENABLE_NCC = Boolean(JSON.parse(process.env.ENABLE_NCC || '0'));

module.exports = {
service,
plugins: ['./plugin'],
plugins: [
DISABLE_TREE_SHAKE && !ENABLE_NCC ? 'serverless-plugin-typescript' : false,
DISABLE_TREE_SHAKE ? false : './plugin',
ENABLE_NCC ? 'serverless-plugin-ncc' : false
].filter(Boolean),
provider: {
name: 'aws',
runtime: 'nodejs12.x',
},
package: {
individually: false,
// we don't need this because of tree-shake
excludeDevDependencies: false,
excludeDevDependencies: DISABLE_TREE_SHAKE,
},
functions: {
hello: {
Expand Down
14 changes: 6 additions & 8 deletions test/__fixtures__/ts-ws-all/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2015",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"allowJs": false,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"inlineSourceMap": true,
"inlineSources": true
"inlineSources": true,
"noEmit": false,
"baseUrl": "."
}
}

0 comments on commit e130641

Please sign in to comment.