Skip to content

Commit b227866

Browse files
authored
Merge pull request #19 from digitalmaas/next
New Release
2 parents 01073b0 + 99411e0 commit b227866

File tree

15 files changed

+3271
-2058
lines changed

15 files changed

+3271
-2058
lines changed

.circleci/config.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ jobs:
55
- image: circleci/node:10
66
steps:
77
- checkout
8-
- run: npm ci
8+
- run: npm ci --verbose
99
- run: npm test
1010

1111
release:
1212
docker:
1313
- image: circleci/node:10
1414
steps:
1515
- checkout
16-
- run: npm ci
16+
- run: npm ci --verbose
1717
- run: npm run release
1818

1919
workflows:
@@ -26,4 +26,6 @@ workflows:
2626
- run_tests
2727
filters:
2828
branches:
29-
only: master
29+
only:
30+
- master
31+
- next

.eslintrc.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
1+
'use strict'
2+
3+
const prettierrc = require('./.prettierrc.json')
4+
const engines = require('./package.json').engines
5+
16
module.exports = {
27
root: true,
38
parserOptions: {
4-
ecmaVersion: 6,
5-
sourceType: 'script'
9+
ecmaVersion: 2018,
10+
sourceType: 'module'
611
},
712
env: {
8-
node: true,
9-
es6: true,
10-
jest: true
13+
node: true
1114
},
1215
plugins: [
13-
'standard',
14-
'prettier'
16+
'node',
17+
'prettierx'
1518
],
1619
extends: [
20+
'eslint:recommended',
21+
'plugin:node/recommended',
1722
'standard',
18-
'prettier',
19-
'prettier/standard'
23+
'plugin:prettierx/standardx'
2024
],
25+
settings: {
26+
prettierx: {
27+
usePrettierrc: true,
28+
editorconfig: true
29+
}
30+
},
2131
rules: {
22-
'space-before-function-paren': ['error', 'always']
32+
'require-atomic-updates': 0,
33+
'node/no-extraneous-require': 0,
34+
'node/no-unsupported-features/es-syntax': ['error', { version: engines.node }],
35+
'prettierx/options': ['error', prettierrc]
2336
}
2437
}

.huskyrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"hooks": {
3+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
4+
"pre-commit": "lint-staged",
5+
"pre-push": "npm test"
6+
}
7+
}

.lintstagedrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"*.js": "./node_modules/.bin/eslint --fix"
3+
}

.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
!LICENSE
88
!package.json
99
!index.js
10-
!lib/**/*
10+
!lib/

.prettierrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"printWidth": 100,
3+
"semi": false,
4+
"singleQuote": true,
5+
"jsxBracketSameLine": true,
6+
"endOfLine": "lf",
7+
"spaceBeforeFunctionParen": true
8+
}

.releaserc.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
2-
"branch": "master",
2+
"branches": [
3+
"master",
4+
{
5+
"name": "next",
6+
"prerelease": "rc",
7+
"channel": "next"
8+
}
9+
],
310
"plugins": [
411
[
512
"@semantic-release/commit-analyzer",
@@ -42,8 +49,7 @@
4249
[
4350
"@semantic-release/changelog",
4451
{
45-
"changelogFile": "CHANGELOG.md",
46-
"changelogTitle": "Changelog"
52+
"changelogFile": "CHANGELOG.md"
4753
}
4854
],
4955
"@semantic-release/git",

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
# [2.3.0-rc.1](https://github.com/digitalmaas/serverless-plugin-browserifier/compare/v2.2.1-rc.1...v2.3.0-rc.1) (2020-03-23)
2+
3+
4+
### Bug Fixes
5+
6+
* fix packaging issue involving `graceful-fs` ([2099e52](https://github.com/digitalmaas/serverless-plugin-browserifier/commit/2099e52412942faf8282cd55e1c0d36bcc0f06ad))
7+
* improve bundling code, use output stream `open` event ([b19ec43](https://github.com/digitalmaas/serverless-plugin-browserifier/commit/b19ec43651425e68219678e4a598cc5d2b1b1da9))
8+
9+
10+
### Features
11+
12+
* add SLS_BROWSERIFIER_DEBUG flag ([1dac77e](https://github.com/digitalmaas/serverless-plugin-browserifier/commit/1dac77e52dbd7defd6b9bce20e79791ef5eb1f58))
13+
14+
## [2.2.1-rc.1](https://github.com/digitalmaas/serverless-plugin-browserifier/compare/v2.2.0...v2.2.1-rc.1) (2020-02-10)
15+
16+
17+
### Bug Fixes
18+
19+
* update dependencies, trying to fix weird issues with sls 1.62.x ([55f04aa](https://github.com/digitalmaas/serverless-plugin-browserifier/commit/55f04aa65cf5ca2713067cde0bd07497f87dfba2))
20+
121
Changelog
222

323
# [2.2.0](https://github.com/digitalmaas/serverless-plugin-browserifier/compare/v2.1.0...v2.2.0) (2020-02-06)

README.md

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ Serverless Browserifier Plugin
99

1010
> A [Serverless](https://serverless.com) v1 plugin that uses [`browserify`][browserify-url] to bundle your Node.js Lambda functions.
1111
12+
1. [Motivation](#motivation)
13+
1. [Installation](#installation)
14+
1. [Basic Setup](#basic-setup)
15+
1. [Advanced Configuration](#advanced-configuration)
16+
1. [FAQ](#faq)
17+
1. [Useful Information](#useful-information)
18+
1. [License](#license)
19+
20+
1221
Motivation
1322
----------
1423

@@ -41,6 +50,9 @@ From your target serverless project, run:
4150
npm install serverless-plugin-browserifier --save-dev
4251
```
4352

53+
Basic Setup
54+
-----------
55+
4456
Add the plugin to your `serverless.yml`:
4557

4658
```yaml
@@ -52,11 +64,13 @@ package:
5264
5365
The `package.individually` setting must be set -- either on global or function level -- to allow minimal bundle size based on each lambda's entrypoint.
5466

67+
You're all set! Use your normal serverless commands to package and deploy.
5568

56-
Configuration
57-
-------------
5869

59-
For most use cases you should **NOT** need to do any configuration. You can, however, introduce custom configuration.
70+
Advanced Configuration
71+
----------------------
72+
73+
For most use cases you should **NOT** need to do any extra configuration. That said, the ability is present if you need it.
6074

6175
The base config for browserify is read from the `custom.browserify` section of `serverless.yml`. All [browserify options][browserify-options] are supported (most are auto configured by this plugin). This plugin adds one special option `disable` which if `true` will bypass this plugin.
6276

@@ -99,22 +113,21 @@ functions:
99113
```
100114

101115

102-
Usage
103-
-----
116+
### Debugging
104117

105118
When this plugin is enabled, and `package.individually` is `true`, running `serverless deploy` and `serverless deploy -f <funcName>` will automatically browserify your Node.js lambda code.
106119

107-
If you want to see more information about the process, simply set `SLS_DEBUG=*`. Example:
120+
If you want to see more information about the process, simply set envvar `SLS_DEBUG=*` for full serverless debug output, or `SLS_BROWSERIFIER_DEBUG=*` for plugin only debug messages. Example:
121+
108122
```
109123
$ export SLS_DEBUG=*
110124
$ sls deploy function -v -f usersGet
111125
```
112126

113-
You can also verify your bundles by simply using `sls package`, which bundles everything up but does not deploy.
127+
You may also verify your bundles by simply using `sls package`, which bundles everything up but does not deploy.
114128

115129

116-
Using browserify plugins/transforms
117-
-----------------------------------
130+
### Using browserify plugins/transforms
118131

119132
If you want to use browserify plugins, you can easily do that by using the global browserify options. As the plugin merely passes that up to browserify, as if it is calling the main [`browserify`][browserify-options] function, you can use it to add any transformations you want.
120133

@@ -146,10 +159,9 @@ custom:
146159
For an in-depth example, please check [this issue](https://github.com/digitalmaas/serverless-plugin-browserifier/issues/8).
147160

148161

149-
Best practices
150-
--------------
162+
### Best practices
151163

152-
__If using it with AWS, use discrete SDK clients!__
164+
#### If using it with AWS, use discrete SDK clients!
153165

154166
The official [aws-sdk-js][aws-sdk] officially [supports browserify][aws-sdk-support]. That allows us to further reduce the size of our bundles (and Lambda memory usage and speed) by loading only what is strictly needed.
155167

@@ -162,7 +174,7 @@ const S3 = require('aws-sdk/clients/s3')
162174
const s3 = new S3()
163175
```
164176

165-
__Ignore AWS SDK!__
177+
#### Ignore AWS SDK!
166178

167179
Although you can use discrete clients (see item above), AWS Lambda service always bundles up the latest SDK version in its Lambda container image. That means that, even if you don't add AWS SDK to your bundle, it will still be available in runtime.
168180

@@ -176,6 +188,36 @@ custom:
176188
- aws-sdk/clients/s3
177189
```
178190

191+
To help you out, here's a script you can use to hide `aws-sdk` and all its clients from browserify. You can use it in your custom config for the plugin in _serverless.yml_:
192+
193+
```yml
194+
# serverless.yml
195+
196+
custom:
197+
browserify: browserify: ${file(./custom.browserify.js)}
198+
```
199+
200+
```js
201+
// custom.browserify.js
202+
//
203+
const fs = require('fs')
204+
const path = require('path')
205+
206+
module.exports = function browserifyOptions () {
207+
return {
208+
// any other valid browserify configuration...
209+
noParse: ['/**/*.json'],
210+
exclude: ['aws-sdk', ...getAllAwsSdkClients()]
211+
}
212+
}
213+
214+
function getAllAwsSdkClients () {
215+
return fs
216+
.readdirSync('./node_modules/aws-sdk/clients', { withFileTypes: true })
217+
.filter(file => file.isFile() && path.extname(file.name) === '.js')
218+
.map(file => `aws-sdk/clients/${path.basename(file.name, '.js')}`)
219+
}
220+
```
179221

180222
FAQ
181223
---
@@ -193,7 +235,7 @@ __Avoid mixing this plugin with other plugins that modify serverless' packaging
193235
This plugin _hijacks_ the normal serverless packaging process, so it will probably conflict with other plugins that use similar mechanisms.
194236

195237

196-
Useful information
238+
Useful Information
197239
------------------
198240

199241
- [List of browserify's transforms][useful-transforms-list]

index.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class BrowserifierPlugin {
1515
this.S = serverless
1616
this._b = {
1717
options,
18+
debugOn: Boolean(process.env.SLS_DEBUG) || Boolean(process.env.SLS_BROWSERIFIER_DEBUG),
1819
isDisabled: get(this.S, 'service.custom.browserify.disable', false),
1920
servicePath: path.join(this.S.config.servicePath || os.tmpdir(), '.serverless'),
2021
runtimeIsNode: get(this.S, 'service.provider.runtime', '').indexOf('nodejs') !== -1,
@@ -33,25 +34,25 @@ class BrowserifierPlugin {
3334
}
3435

3536
_prepareAllFunctions () {
36-
return Promise
37-
.bind(this)
37+
return Promise.bind(this)
3838
.then(this._validate)
3939
.then(this._computeGlobalConfig)
4040
.then(() => {
4141
const fns = this._getAllFunctions()
4242
this.S.cli.log(`Browserifier: Preparing ${fns.length} function(s)...`)
43-
return Promise.all(fns.map(name => this._bootstrap(name).reflect()))
43+
return Promise.map(fns, name => this._bootstrap(name).reflect())
44+
})
45+
.then(results => {
46+
return results
47+
.filter(inspection => inspection.isRejected())
48+
.forEach(inspection => this._handleSkip(inspection.reason()))
4449
})
45-
.then(results => results
46-
.filter(inspection => inspection.isRejected())
47-
.forEach(inspection => this._handleSkip(inspection.reason())))
4850
.catch(this._handleSkip)
4951
.tapCatch(this._warnFailure)
5052
}
5153

5254
_prepareFunction () {
53-
return Promise
54-
.bind(this)
55+
return Promise.bind(this)
5556
.then(this._validate)
5657
.then(this._computeGlobalConfig)
5758
.then(() => this._bootstrap(this._b.options.function))
@@ -60,16 +61,14 @@ class BrowserifierPlugin {
6061
}
6162

6263
_bundleAllFunctions () {
63-
return Promise
64-
.bind(this)
64+
return Promise.bind(this)
6565
.then(this._validate)
6666
.then(() => Promise.all(this._getAllFunctions().map(name => this._bundle(name))))
6767
.tapCatch(this._warnFailure)
6868
}
6969

7070
_bundleFunction () {
71-
return Promise
72-
.bind(this)
71+
return Promise.bind(this)
7372
.then(this._validate)
7473
.then(() => this._bundle(this._b.options.function))
7574
.tapCatch(this._warnFailure)

0 commit comments

Comments
 (0)