Skip to content

Commit

Permalink
Upgrade deps
Browse files Browse the repository at this point in the history
Mostly to fix security issue but also to keep them updated.

Also:
- fix an ESLint error: `8:16  error  Do not access Object.prototype method 'hasOwnProperty' from target object  no-prototype-builtins`
- run prettier (following update)
- update `format` script with `$(pwd)` to fix issue with higher version of ESLint (>5)
- prettier now run on every js files
  • Loading branch information
j0k3r authored and vicary committed Jan 6, 2021
1 parent 6664753 commit b4df61a
Show file tree
Hide file tree
Showing 24 changed files with 3,358 additions and 2,259 deletions.
10 changes: 5 additions & 5 deletions examples/babel-multiple-statically-entries/first.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ export const hello = (event, context, cb) => {
const p = new Promise((resolve, reject) => {
resolve('success');
});
p
.then(r => cb(null, {
p.then(r =>
cb(null, {
message: 'Go Serverless Webpack (Babel) v1.0! First module!',
event,
}))
.catch(e => cb(e));
event
})
).catch(e => cb(e));
};
10 changes: 5 additions & 5 deletions examples/babel-multiple-statically-entries/second.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ export const hello = (event, context, cb) => {
const p = new Promise((resolve, reject) => {
resolve('success');
});
p
.then(r => cb(null, {
p.then(r =>
cb(null, {
message: 'Go Serverless Webpack (Babel) v1.0! Second module!',
event,
}))
.catch(e => cb(e));
event
})
).catch(e => cb(e));
};
4 changes: 2 additions & 2 deletions examples/babel-multiple-statically-entries/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
second: ['./second.js']
},
target: 'node',
mode: slsw.lib.webpack.isLocal ? 'development': 'production',
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
module: {
rules: [
{
Expand All @@ -18,7 +18,7 @@ module.exports = {
{
loader: 'babel-loader'
}
],
]
}
]
},
Expand Down
18 changes: 9 additions & 9 deletions examples/babel-webpack-4/handlers/first.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ export const hello = (event, context, cb) => {

// Do not return the promise as we use the callback
// This resolved promise would be be in the application library code in a real-world application and provide the results
App.handleFirst(event) // eslint-disable-line promise/catch-or-return
.then(result => ({
statusCode: 200,
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify(result)
}))
.asCallback(cb);
App.handleFirst(event) // eslint-disable-line promise/catch-or-return
.then(result => ({
statusCode: 200,
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify(result)
}))
.asCallback(cb);

return;
};
18 changes: 9 additions & 9 deletions examples/babel-webpack-4/handlers/second.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ export const hello = (event, context, cb) => {

// Do not return the promise as we use the callback
// This resolved promise would be be in the application library code in a real-world application and provide the results
App.handleSecond(event) // eslint-disable-line promise/catch-or-return
.then(result => ({
statusCode: 200,
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify(result)
}))
.asCallback(cb);
App.handleSecond(event) // eslint-disable-line promise/catch-or-return
.then(result => ({
statusCode: 200,
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify(result)
}))
.asCallback(cb);

return;
};
6 changes: 3 additions & 3 deletions examples/babel-webpack-4/lib/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class App {
from: 'First lambda ;-)',
event
};

return BbPromise.resolve(myDemoResult);
}

Expand All @@ -19,7 +19,7 @@ export class App {
from: 'Second lambda ;-)',
event
};

return BbPromise.resolve(myDemoResult);
}
}
}
4 changes: 2 additions & 2 deletions examples/babel-webpack-4/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const nodeExternals = require('webpack-node-externals');
module.exports = {
entry: slsw.lib.entries,
target: 'node',
mode: slsw.lib.webpack.isLocal ? 'development': 'production',
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
optimization: {
// We no not want to minimize our code.
minimize: false
Expand All @@ -25,7 +25,7 @@ module.exports = {
{
loader: 'babel-loader'
}
],
]
}
]
},
Expand Down
8 changes: 4 additions & 4 deletions examples/include-external-npm-packages/handler.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

var AWS = require('aws-sdk');
var fbgraph = require('fbgraph');
const AWS = require('aws-sdk');
const fbgraph = require('fbgraph');

module.exports.hello = function (event, context, cb) {
cb(null, { message: 'hello fb & aws', event });
}
cb(null, { message: 'hello fb & aws', event });
};
2 changes: 1 addition & 1 deletion examples/include-external-npm-packages/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const nodeExternals = require('webpack-node-externals');

module.exports = {
entry: slsw.lib.entries,
mode: slsw.lib.webpack.isLocal ? 'development': 'production',
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
target: 'node',
externals: [nodeExternals()] // exclude external modules
};
4 changes: 2 additions & 2 deletions examples/multiple-statically-entries/first.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

module.exports.hello = function (event, context, cb) {
cb(null, { message: 'First module', event });
}
cb(null, { message: 'First module', event });
};
4 changes: 2 additions & 2 deletions examples/multiple-statically-entries/second.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

module.exports.hello = function (event, context, cb) {
cb(null, { message: 'Second module', event });
}
cb(null, { message: 'Second module', event });
};
4 changes: 2 additions & 2 deletions examples/multiple-statically-entries/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ module.exports = {
second: './second.js'
},
target: 'node',
mode: slsw.lib.webpack.isLocal ? 'development': 'production',
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js'
},
}
};
15 changes: 5 additions & 10 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('ServerlessWebpack', () => {
let ServerlessWebpack;
let moduleStub;

before(function() {
before(function () {
// Mockery might take some time to clear the cache. So add 3 seconds to the default timeout.
this.timeout(5000);

Expand Down Expand Up @@ -59,15 +59,10 @@ describe('ServerlessWebpack', () => {
it('should expose a lib object', () => {
const lib = ServerlessWebpack.lib;
expect(lib).to.be.an('object');
expect(lib)
.to.have.a.property('entries')
.that.is.an('object').that.is.empty;
expect(lib)
.to.have.a.property('webpack')
.that.is.an('object')
.that.deep.equals({
isLocal: false
});
expect(lib).to.have.a.property('entries').that.is.an('object').that.is.empty;
expect(lib).to.have.a.property('webpack').that.is.an('object').that.deep.equals({
isLocal: false
});
});

describe('with a TS webpack configuration', () => {
Expand Down
20 changes: 5 additions & 15 deletions lib/Configuration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,13 @@ describe('Configuration', () => {

it('should set default configuration without custom', () => {
const config = new Configuration();
expect(config)
.to.have.a.property('_config')
.that.deep.equals(expectedDefaults);
expect(config).to.have.a.property('_config').that.deep.equals(expectedDefaults);
expect(config).to.have.a.property('hasLegacyConfig').that.is.false;
});

it('should set default configuration without webpack property', () => {
const config = new Configuration({});
expect(config)
.to.have.a.property('_config')
.that.deep.equals(expectedDefaults);
expect(config).to.have.a.property('_config').that.deep.equals(expectedDefaults);
expect(config).to.have.a.property('hasLegacyConfig').that.is.false;
});
});
Expand All @@ -45,17 +41,13 @@ describe('Configuration', () => {
it('should use custom.webpackIncludeModules', () => {
const testCustom = { webpackIncludeModules: { forceInclude: ['mod1'] } };
const config = new Configuration(testCustom);
expect(config)
.to.have.a.property('includeModules')
.that.deep.equals(testCustom.webpackIncludeModules);
expect(config).to.have.a.property('includeModules').that.deep.equals(testCustom.webpackIncludeModules);
});

it('should use custom.webpack as string', () => {
const testCustom = { webpack: 'myWebpackFile.js' };
const config = new Configuration(testCustom);
expect(config)
.to.have.a.property('webpackConfig')
.that.equals('myWebpackFile.js');
expect(config).to.have.a.property('webpackConfig').that.equals('myWebpackFile.js');
});

it('should detect it', () => {
Expand All @@ -70,9 +62,7 @@ describe('Configuration', () => {
webpack: 'myWebpackFile.js'
};
const config = new Configuration(testCustom);
expect(config)
.to.have.a.property('includeModules')
.that.deep.equals(testCustom.webpackIncludeModules);
expect(config).to.have.a.property('includeModules').that.deep.equals(testCustom.webpackIncludeModules);
expect(config._config).to.deep.equal({
webpackConfig: 'myWebpackFile.js',
includeModules: { forceInclude: ['mod1'] },
Expand Down
2 changes: 1 addition & 1 deletion lib/packagers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const registeredPackagers = {
* @param {string} packagerId - Well known packager id.
* @returns {BbPromise<Packager>} - Promised packager to allow packagers be created asynchronously.
*/
module.exports.get = function(packagerId) {
module.exports.get = function (packagerId) {
if (!_.has(registeredPackagers, packagerId)) {
const message = `Could not find packager '${packagerId}'`;
this.serverless.cli.log(`ERROR: ${message}`);
Expand Down
4 changes: 2 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ function guid() {
* @param {string} moduleName
*/
function purgeCache(moduleName) {
return searchAndProcessCache(moduleName, function(mod) {
return searchAndProcessCache(moduleName, function (mod) {
delete require.cache[mod.id];
}).then(() => {
_.forEach(_.keys(module.constructor._pathCache), function(cacheKey) {
_.forEach(_.keys(module.constructor._pathCache), function (cacheKey) {
if (cacheKey.indexOf(moduleName) > 0) {
delete module.constructor._pathCache[cacheKey];
}
Expand Down
20 changes: 5 additions & 15 deletions lib/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,9 @@ describe('Utils', () => {
describe('SpawnError', () => {
it('should store stdout and stderr', () => {
const err = new Utils.SpawnError('message', 'stdout', 'stderr');
expect(err)
.to.have.a.property('message')
.that.equals('message');
expect(err)
.to.have.a.property('stdout')
.that.equals('stdout');
expect(err)
.to.have.a.property('stderr')
.that.equals('stderr');
expect(err).to.have.a.property('message').that.equals('message');
expect(err).to.have.a.property('stdout').that.equals('stdout');
expect(err).to.have.a.property('stderr').that.equals('stderr');
});

it('should print message and stderr', () => {
Expand Down Expand Up @@ -96,12 +90,8 @@ describe('Utils', () => {
childMock.on.reset();
childMock.on.withArgs('close').yields(0);
return expect(Utils.spawnProcess('cmd', [])).to.be.fulfilled.then(result => {
expect(result)
.to.have.a.property('stdout')
.that.equals('myOutData');
expect(result)
.to.have.a.property('stderr')
.that.equals('myErrData');
expect(result).to.have.a.property('stdout').that.equals('myOutData');
expect(result).to.have.a.property('stderr').that.equals('myErrData');
return null;
});
});
Expand Down
5 changes: 4 additions & 1 deletion lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ module.exports = {
// Move preferred file extensions to the beginning
const sortedFiles = _.uniq(
_.concat(
_.sortBy(_.filter(files, file => _.includes(preferredExtensions, path.extname(file))), a => _.size(a)),
_.sortBy(
_.filter(files, file => _.includes(preferredExtensions, path.extname(file))),
a => _.size(a)
),
files
)
);
Expand Down
6 changes: 3 additions & 3 deletions lib/wpwatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ module.exports = {
callback();
} else if (canEmit && currentCompileWatch === null) {
// eslint-disable-next-line promise/no-promise-in-callback
currentCompileWatch = BbPromise.resolve(this.serverless.pluginManager.spawn('webpack:compile:watch')).then(
() => this.serverless.cli.log('Watching for changes...')
);
currentCompileWatch = BbPromise.resolve(
this.serverless.pluginManager.spawn('webpack:compile:watch')
).then(() => this.serverless.cli.log('Watching for changes...'));
}
});
};
Expand Down
Loading

0 comments on commit b4df61a

Please sign in to comment.