Skip to content

Commit

Permalink
Merge 95cacde into 8043a30
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-a-calles-mba committed Jul 21, 2020
2 parents 8043a30 + 95cacde commit 5849cae
Show file tree
Hide file tree
Showing 10 changed files with 463 additions and 120 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,33 @@ me to take it over and continue working on the project. That helped to revive it

## Release Notes

* 5.3.3
* default webpackConfig.node should be false #502
* Fix yarn list --json stdOut parsing. fixes #388 #516
* Updated release notes #585
* Updated Node versions in CI #587
* Remove optional peer dependencies #542
* Check for node runtimes first #579

* 5.3.2
* Fix eslint prettier #518
* Add TypeScript definition #520
* Project dependencies updated #524
* fix typescript example lockfile #526
* Typescript example babel loader #527
* Bump tar from 2.2.1 to 2.2.2 in /examples/babel #544
* Bump acorn from 6.3.0 to 6.4.1 in /examples/typescript #562
* Bump eslint-utils from 1.4.0 to 1.4.3 #567
* Bump handlebars from 4.1.2 to 4.7.6 #568
* Addressed npm security vulnerabilities #569
* Bump https-proxy-agent from 2.2.2 to 2.2.4 #572
* Bump https-proxy-agent from 2.2.2 to 2.2.4 in /examples/typescript #573
* Bump extend from 3.0.1 to 3.0.2 in /examples/babel #574
* Bump stringstream from 0.0.5 to 0.0.6 in /examples/babel #575
* Bump tough-cookie from 2.3.2 to 2.3.4 in /examples/babel #576
* Bump sshpk from 1.13.1 to 1.16.1 in /examples/babel #577
* Bump debug from 2.6.8 to 2.6.9 in /examples/babel #578

* 5.3.1
* Fixed bug that prevented to use handlers using import [#505][link-505]
* Do not print empty lines in webpack stats [#499][link-499]
Expand Down
35 changes: 27 additions & 8 deletions lib/packExternalModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,32 @@ function getProdModules(externalModules, packagePath, dependencyGraph, forceExcl
const peerDependencies = require(modulePackagePath).peerDependencies;
if (!_.isEmpty(peerDependencies)) {
this.options.verbose && this.serverless.cli.log(`Adding explicit peers for dependency ${module.external}`);
const peerModules = getProdModules.call(
this,
_.map(peerDependencies, (value, key) => ({ external: key })),
packagePath,
dependencyGraph,
forceExcludes
);
Array.prototype.push.apply(prodModules, peerModules);

const peerDependenciesMeta = require(modulePackagePath).peerDependenciesMeta;

if (!_.isEmpty(peerDependenciesMeta)) {
_.forEach(peerDependencies, (value, key) => {
if (peerDependenciesMeta[key] && peerDependenciesMeta[key].optional === true) {
this.options.verbose &&
this.serverless.cli.log(
`Skipping peers dependency ${key} for dependency ${module.external} because it's optional`
);

_.unset(peerDependencies, key);
}
});
}

if (!_.isEmpty(peerDependencies)) {
const peerModules = getProdModules.call(
this,
_.map(peerDependencies, (value, key) => ({ external: key })),
packagePath,
dependencyGraph,
forceExcludes
);
Array.prototype.push.apply(prodModules, peerModules);
}
}
} catch (e) {
this.serverless.cli.log(`WARNING: Could not check for peer dependencies of ${module.external}`);
Expand Down Expand Up @@ -424,3 +442,4 @@ module.exports = {
});
}
};

8 changes: 7 additions & 1 deletion lib/packagers/yarn.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ class Yarn {
return BbPromise.reject(err);
})
.then(processOutput => processOutput.stdout)
.then(depJson => BbPromise.try(() => JSON.parse(depJson)))
.then(stdout =>
BbPromise.try(() => {
const lines = Utils.splitLines(stdout);
const parsedLines = _.map(lines, Utils.safeJsonParse);
return _.find(parsedLines, line => line && line.type === 'tree');
})
)
.then(parsedTree => {
const convertTrees = trees =>
_.reduce(
Expand Down
24 changes: 16 additions & 8 deletions lib/packagers/yarn.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,22 @@ describe('yarn', () => {
});

it('should transform yarn trees to npm dependencies', () => {
const testYarnResult = `{"type":"tree","data":{"type":"list","trees":[
{"name":"archiver@2.1.1","children":[],"hint":null,"color":"bold",
"depth":0},{"name":"bluebird@3.5.1","children":[],"hint":null,"color":
"bold","depth":0},{"name":"fs-extra@4.0.3","children":[],"hint":null,
"color":"bold","depth":0},{"name":"mkdirp@0.5.1","children":[{"name":
"minimist@0.0.8","children":[],"hint":null,"color":"bold","depth":0}],
"hint":null,"color":null,"depth":0},{"name":"@sls/webpack@1.0.0",
"children":[],"hint":null,"color":"bold","depth":0}]}}`;
const testYarnResult =
'{"type":"activityStart","data":{"id":0}}\n' +
'{"type":"activityTick","data":{"id":0,"name":"archiver@^2.1.1"}}\n' +
'{"type":"activityTick","data":{"id":0,"name":"bluebird@^3.5.1"}}\n' +
'{"type":"activityTick","data":{"id":0,"name":"fs-extra@^4.0.3"}}\n' +
'{"type":"activityTick","data":{"id":0,"name":"mkdirp@^0.5.1"}}\n' +
'{"type":"activityTick","data":{"id":0,"name":"minimist@^0.0.8"}}\n' +
'{"type":"activityTick","data":{"id":0,"name":"@sls/webpack@^1.0.0"}}\n' +
'{"type":"tree","data":{"type":"list","trees":[' +
'{"name":"archiver@2.1.1","children":[],"hint":null,"color":"bold",' +
'"depth":0},{"name":"bluebird@3.5.1","children":[],"hint":null,"color":' +
'"bold","depth":0},{"name":"fs-extra@4.0.3","children":[],"hint":null,' +
'"color":"bold","depth":0},{"name":"mkdirp@0.5.1","children":[{"name":' +
'"minimist@0.0.8","children":[],"hint":null,"color":"bold","depth":0}],' +
'"hint":null,"color":null,"depth":0},{"name":"@sls/webpack@1.0.0",' +
'"children":[],"hint":null,"color":"bold","depth":0}]}}\n';
const expectedResult = {
problems: [],
dependencies: {
Expand Down
16 changes: 15 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,24 @@ function spawnProcess(command, args, options) {
});
}

function safeJsonParse(str) {
try {
return JSON.parse(str);
} catch (e) {
return null;
}
}

function splitLines(str) {
return _.split(str, /\r?\n/);
}

module.exports = {
guid,
purgeCache,
searchAndProcessCache,
SpawnError,
spawnProcess
spawnProcess,
safeJsonParse,
splitLines
};
16 changes: 16 additions & 0 deletions lib/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,20 @@ describe('Utils', () => {
return expect(Utils.spawnProcess('cmd', [])).to.be.rejectedWith(Utils.SpawnError);
});
});

describe('safeJsonParse', () => {
it('should parse valid JSON', () => {
expect(Utils.safeJsonParse('{"foo": "bar"}')).to.deep.equal({ foo: 'bar' });
});

it('should return null for invalid JSON', () => {
expect(Utils.safeJsonParse('{"foo":')).to.equal(null);
});
});

describe('splitLines', () => {
it('should split on new line characters', () => {
expect(Utils.splitLines('a\r\nb\nc')).to.deep.equal([ 'a', 'b', 'c' ]);
});
});
});
13 changes: 11 additions & 2 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ module.exports = {
_.merge(entries, entry);
} else {
_.forEach(functions, (func, index) => {
const entry = getEntryForFunction.call(this, functions[index], this.serverless.service.getFunction(func));
_.merge(entries, entry);
const loadedFunc = this.serverless.service.getFunction(func);
const runtime = loadedFunc.runtime || this.serverless.service.provider.runtime;
if (runtime.match(/^node/)) {
const entry = getEntryForFunction.call(this, functions[index], loadedFunc);
_.merge(entries, entry);
}
});
}

Expand Down Expand Up @@ -145,6 +149,11 @@ module.exports = {
filename: '[name].js'
};
}

// Default node
if (!this.webpackConfig.node || _.isEmpty(this.webpackConfig.node)) {
this.webpackConfig.node = false;
}

// Custom output path
if (this.options.out) {
Expand Down
94 changes: 94 additions & 0 deletions tests/data/rp-package-optional.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"_from": "request-promise",
"_id": "request-promise@4.2.1",
"_inBundle": false,
"_integrity": "sha1-fuxWyJMXqCLL/qmbA5zlQ8LhX2c=",
"_location": "/request-promise",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "request-promise",
"name": "request-promise",
"escapedName": "request-promise",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/request-promise/-/request-promise-4.2.1.tgz",
"_shasum": "7eec56c89317a822cbfea99b039ce543c2e15f67",
"_spec": "request-promise",
"_where": "C:\\Projects\\serverless\\test\\babel-dynamically-entries",
"author": {
"name": "Nicolai Kamenzky",
"url": "https://github.com/analog-nico"
},
"bugs": {
"url": "https://github.com/request/request-promise/issues"
},
"bundleDependencies": false,
"dependencies": {
"bluebird": "^3.5.0",
"request-promise-core": "1.1.1",
"stealthy-require": "^1.1.0",
"tough-cookie": ">=2.3.0"
},
"deprecated": false,
"description": "The simplified HTTP request client 'request' with Promise support. Powered by Bluebird.",
"devDependencies": {
"body-parser": "~1.15.2",
"chai": "~3.5.0",
"chalk": "~1.1.3",
"gulp": "~3.9.1",
"gulp-coveralls": "~0.1.4",
"gulp-eslint": "~2.1.0",
"gulp-istanbul": "~1.0.0",
"gulp-mocha": "~2.2.0",
"lodash": "~4.13.1",
"publish-please": "~2.1.4",
"request": "^2.34.0",
"rimraf": "~2.5.3",
"run-sequence": "~1.2.2"
},
"engines": {
"node": ">=0.10.0"
},
"homepage": "https://github.com/request/request-promise#readme",
"keywords": [
"xhr",
"http",
"https",
"promise",
"request",
"then",
"thenable",
"bluebird"
],
"license": "ISC",
"main": "./lib/rp.js",
"name": "request-promise",
"peerDependencies": {
"request": "^2.34",
"canvas": "^2.5.0"
},
"peerDependenciesMeta": {
"canvas": {
"optional": true
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/request/request-promise.git"
},
"scripts": {
"prepublish": "publish-please guard",
"publish-please": "publish-please",
"test": "gulp ci",
"test-publish": "gulp ci-no-cov"
},
"version": "4.2.1"
}
Loading

0 comments on commit 5849cae

Please sign in to comment.