Skip to content

Commit

Permalink
fix: update dependencies, trying to fix weird issues with sls 1.62.x
Browse files Browse the repository at this point in the history
- add `next` tag support
- upgrade most dependencies
- remove unneeded bluebird promisy
  • Loading branch information
nolde committed Feb 10, 2020
1 parent 01073b0 commit 55f04aa
Show file tree
Hide file tree
Showing 12 changed files with 3,755 additions and 2,156 deletions.
8 changes: 5 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ jobs:
- image: circleci/node:10
steps:
- checkout
- run: npm ci
- run: npm ci --verbose
- run: npm test

release:
docker:
- image: circleci/node:10
steps:
- checkout
- run: npm ci
- run: npm ci --verbose
- run: npm run release

workflows:
Expand All @@ -26,4 +26,6 @@ workflows:
- run_tests
filters:
branches:
only: master
only:
- master
- next
33 changes: 23 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
'use strict'

const prettierrc = require('./.prettierrc.json')
const engines = require('./package.json').engines

module.exports = {
root: true,
parserOptions: {
ecmaVersion: 6,
sourceType: 'script'
ecmaVersion: 2018,
sourceType: 'module'
},
env: {
node: true,
es6: true,
jest: true
node: true
},
plugins: [
'standard',
'prettier'
'node',
'prettierx'
],
extends: [
'eslint:recommended',
'plugin:node/recommended',
'standard',
'prettier',
'prettier/standard'
'plugin:prettierx/standardx'
],
settings: {
prettierx: {
usePrettierrc: true,
editorconfig: true
}
},
rules: {
'space-before-function-paren': ['error', 'always']
'require-atomic-updates': 0,
'node/no-extraneous-require': 0,
'node/no-unsupported-features/es-syntax': ['error', { version: engines.node }],
'prettierx/options': ['error', prettierrc]
}
}
7 changes: 7 additions & 0 deletions .huskyrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "lint-staged",
"pre-push": "npm test"
}
}
3 changes: 3 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"*.js": "./node_modules/.bin/eslint --fix"
}
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
!LICENSE
!package.json
!index.js
!lib/**/*
!lib/
8 changes: 8 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"printWidth": 100,
"semi": false,
"singleQuote": true,
"jsxBracketSameLine": true,
"endOfLine": "lf",
"spaceBeforeFunctionParen": true
}
12 changes: 9 additions & 3 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"branch": "master",
"branches": [
"master",
{
"name": "next",
"prerelease": "rc",
"channel": "next"
}
],
"plugins": [
[
"@semantic-release/commit-analyzer",
Expand Down Expand Up @@ -42,8 +49,7 @@
[
"@semantic-release/changelog",
{
"changelogFile": "CHANGELOG.md",
"changelogTitle": "Changelog"
"changelogFile": "CHANGELOG.md"
}
],
"@semantic-release/git",
Expand Down
20 changes: 9 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@ class BrowserifierPlugin {
}

_prepareAllFunctions () {
return Promise
.bind(this)
return Promise.bind(this)
.then(this._validate)
.then(this._computeGlobalConfig)
.then(() => {
const fns = this._getAllFunctions()
this.S.cli.log(`Browserifier: Preparing ${fns.length} function(s)...`)
return Promise.all(fns.map(name => this._bootstrap(name).reflect()))
})
.then(results => results
.filter(inspection => inspection.isRejected())
.forEach(inspection => this._handleSkip(inspection.reason())))
.then(results =>
results
.filter(inspection => inspection.isRejected())
.forEach(inspection => this._handleSkip(inspection.reason()))
)
.catch(this._handleSkip)
.tapCatch(this._warnFailure)
}

_prepareFunction () {
return Promise
.bind(this)
return Promise.bind(this)
.then(this._validate)
.then(this._computeGlobalConfig)
.then(() => this._bootstrap(this._b.options.function))
Expand All @@ -60,16 +60,14 @@ class BrowserifierPlugin {
}

_bundleAllFunctions () {
return Promise
.bind(this)
return Promise.bind(this)
.then(this._validate)
.then(() => Promise.all(this._getAllFunctions().map(name => this._bundle(name))))
.tapCatch(this._warnFailure)
}

_bundleFunction () {
return Promise
.bind(this)
return Promise.bind(this)
.then(this._validate)
.then(() => this._bundle(this._b.options.function))
.tapCatch(this._warnFailure)
Expand Down
44 changes: 25 additions & 19 deletions lib/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const archiver = require('archiver')
const filesize = require('filesize')
const globby = require('globby')
const path = require('path')

const fs = Promise.promisifyAll(require('fs-extra'))
const fs = require('fs-extra')

/// //////////////////////// exports && main functions

Expand All @@ -18,11 +17,10 @@ module.exports = {

function bundle (functionName) {
const data = this._b.functionConfigCache[functionName]
if (!(data)) {
if (!data) {
return Promise.resolve()
}
return Promise
.bind(this)
return Promise.bind(this)
.return(data)
.then(prepareIncludes)
.then(runBrowserify)
Expand All @@ -34,8 +32,7 @@ function bootstrap (functionName) {
if (process.env.SLS_DEBUG) {
this.S.cli.log(`Browserifier: Preparing "${functionName}"...`)
}
return Promise
.bind(this)
return Promise.bind(this)
.return(functionName)
.then(prepareInitialData)
.then(this._validateFunction)
Expand All @@ -51,7 +48,10 @@ function prepareInitialData (functionName) {
outputFolder: path.join(this._b.servicePath, functionName),
functionObject: this.S.service.getFunction(functionName),
functionBrowserifyConfig: this._getFunctionConfig(functionName),
outputBundle: path.relative(this.S.config.servicePath, path.join(this._b.servicePath, `${functionName}.zip`))
outputBundle: path.relative(
this.S.config.servicePath,
path.join(this._b.servicePath, `${functionName}.zip`)
)
}
}

Expand Down Expand Up @@ -85,10 +85,10 @@ function runBrowserify (data) {
cfg.exclude.forEach(file => b.exclude(file))
cfg.ignore.forEach(file => b.ignore(file))
cfg.external.forEach(file => b.external(file))
return Promise
.fromCallback(cb => b.bundle(cb))
return Promise.fromCallback(cb => b.bundle(cb))
.then(bundleBuffer => {
const handlerPath = path.join(data.outputFolder, data.functionObject.handler.split('.')[0] + '.js')
let handlerPath = data.functionObject.handler.split('.')[0] + '.js'
handlerPath = path.join(data.outputFolder, handlerPath)
fs.mkdirsSync(path.dirname(handlerPath), '0777') // handler may be in a subdir
return Promise.fromCallback(cb => fs.writeFile(handlerPath, bundleBuffer, cb))
})
Expand All @@ -104,7 +104,7 @@ function zip (data) {
const output = fs.createWriteStream(outputFile)
const archive = archiver.create('zip')
output.on('close', () => resolve(archive.pointer()))
archive.on('error', (err) => reject(err))
archive.on('error', err => reject(err))
archive.pipe(output)
archive.directory(data.outputFolder, '')
archive.finalize()
Expand All @@ -116,22 +116,28 @@ function zip (data) {
}

function clean (data) {
fs.remove(data.outputFolder)
fs.removeSync(data.outputFolder)
if (fs.existsSync(data.workaroundFilePath)) {
fs.remove(data.workaroundFilePath)
fs.removeSync(data.workaroundFilePath)
}
delete this._b.functionConfigCache[data.functionName]
}

function fixServerlessConfig (data) {
data.workaroundFilePath = path.relative(this.S.config.servicePath, path.join(this._b.servicePath, 'fool-serverless.txt'))
return fs.ensureFileAsync(data.workaroundFilePath)
.then(() => fs.writeFileAsync(data.workaroundFilePath, 'fool packaging step'))
const wafp = path.join(this._b.servicePath, 'fool-serverless.txt')
data.workaroundFilePath = path.relative(this.S.config.servicePath, wafp)
return fs
.ensureFile(data.workaroundFilePath)
.then(() => {
return Promise.fromCallback(cb => {
return fs.writeFile(data.workaroundFilePath, 'fool packaging step', cb)
})
})
.then(() => {
data.functionObject.package = {
individually: true,
exclude: [ '**/*' ],
include: [ data.workaroundFilePath ],
exclude: ['**/*'],
include: [data.workaroundFilePath],
artifact: data.outputBundle
}
return data
Expand Down
32 changes: 24 additions & 8 deletions lib/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ module.exports = {
if (this.S.service.package) {
// Merge together package.exclude and custom.browserify.exclude
if (this.S.service.package.exclude && this.S.service.package.exclude.length) {
this._b.globalBrowserifyConfig.exclude = union(this.S.service.package.exclude, this._b.globalBrowserifyConfig.exclude)
this._b.globalBrowserifyConfig.exclude = union(
this.S.service.package.exclude,
this._b.globalBrowserifyConfig.exclude
)
}
// Save service package.include
if (this.S.service.package.include && this.S.service.package.include.length) {
this._b.globalBrowserifyConfig.include = this.S.service.package.include
}
}
if (process.env.SLS_DEBUG) {
this.S.cli.log('Browserifier: Computed globalBrowserifyConfig: ' + JSON.stringify(this._b.globalBrowserifyConfig))
const computed = JSON.stringify(this._b.globalBrowserifyConfig)
this.S.cli.log('Browserifier: Computed globalBrowserifyConfig: ' + computed)
}
},

Expand All @@ -37,7 +41,7 @@ module.exports = {
_getBrowserifyDefaultConfig () {
const version = this._getBrowserifyVersion()
if (semver.lt(version, '13.3.0')) {
throw new this.S.classes.Error('Minimal \'browserify\' version supported is v13.3.0.', 'skip')
throw new this.S.classes.Error("Minimal 'browserify' version supported is v13.3.0.", 'skip')
}
this.S.cli.log('Browserifier: Using browserify@' + version)
// Props disable, exclude, include, external and ignore are not browserify
Expand Down Expand Up @@ -101,9 +105,14 @@ module.exports = {
*/
_getFunctionConfig (functionName) {
const functionObject = this.S.service.getFunction(functionName)
const functionBrowserifyConfig = Object.assign({}, this._b.globalBrowserifyConfig, functionObject.browserify || {})
const functionBrowserifyConfig = Object.assign(
{},
this._b.globalBrowserifyConfig,
functionObject.browserify || {}
)
if (process.env.SLS_DEBUG) {
this.S.cli.log(`Browserifier: functionObject for ${functionName}: ${JSON.stringify(functionObject)}`)
const computed = JSON.stringify(functionObject)
this.S.cli.log(`Browserifier: functionObject for ${functionName}: ${computed}`)
}
if (!functionBrowserifyConfig.entries.length) {
const bundleEntryPt = functionObject.handler.split('.')[0] + '.js'
Expand All @@ -112,15 +121,22 @@ module.exports = {
if (functionObject.package) {
// Merge together functions.FUNCTION.package.exclude and browserify exclude
if (functionObject.package.exclude && functionObject.package.exclude.length) {
functionBrowserifyConfig.exclude = union(functionBrowserifyConfig.exclude, functionObject.package.exclude)
functionBrowserifyConfig.exclude = union(
functionBrowserifyConfig.exclude,
functionObject.package.exclude
)
}
// Merge together service and function includes
if (functionObject.package.include && functionObject.package.include.length) {
functionBrowserifyConfig.include = union(functionBrowserifyConfig.include, functionObject.package.include)
functionBrowserifyConfig.include = union(
functionBrowserifyConfig.include,
functionObject.package.include
)
}
}
if (process.env.SLS_DEBUG) {
this.S.cli.log('Browserifier: Computed function BrowserifierConfig: ' + JSON.stringify(functionBrowserifyConfig))
const computed = JSON.stringify(functionBrowserifyConfig)
this.S.cli.log('Browserifier: Computed function BrowserifierConfig: ' + computed)
}
return functionBrowserifyConfig
}
Expand Down
Loading

0 comments on commit 55f04aa

Please sign in to comment.