New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FLUID-5799, FLUID-5967: Reducing Fragility #5
Conversation
Will check that the specified remote actually exists, and throw an error if it doesn't. Also added options to specify the remote name.
Updated the tests and README
Bumped the version to 2.0.0 because of backwards incompatible changes. |
@amb26 also I noticed when switching to ESLint that it seems to run against the files in the node_modules directory. Everything seems to be passing; which makes me feel lucky or perhaps it isn't running against those files, but is still adding them to the count. |
"use strict"; | ||
|
||
var publish = {}; | ||
var path = require("path"); | ||
var extend = require("extend"); | ||
|
||
// TODO: The supported version of node.js does not yet support ES6 template strings | ||
// When version node.js 4.x.x is supported this can be replaced by native support. | ||
var es6Template = require("es6-template-strings"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why we can't make node 4.x, the current LTS, the minimum supported version for this project. I don't believe anyone in our communities is working with any earlier version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amb26 I agree we should be able to set the minimum to 4.0.0. However, while exploring ES6 template literals. ( https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals ) it is required that the literal use "`". These back ticks fail our JSON linting. I can't actually find anywhere that indicates that they should be valid or not in JSON. Any thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving in es6-template-strings based on our conversation in the channel.
https://botbot.me/freenode/fluid-work/2016-08-30/?msg=72191253&page=1
@amb26 ready for more review |
programmatically and via a command line flag.
@@ -0,0 +1,80 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please could you update this to our new shared eslint repo - thanks!
@@ -127,6 +141,17 @@ publish.standard(); | |||
</tr> | |||
<tr> | |||
<td> | |||
<code>checkRemoteCmd</code> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This material doesn't appear in this diff (yet) but this is the closest line:
i) There's a typo where "--standard" appears twice, presumably the first instance should be "--version"
ii) The heading named "Node" is pretty confusing and it's unclear what it refers to. There should be some text here to explain what is being documented
iii) There then seems to be some kind of missing heading since the docs then continue with "parameters" again which is a duplicate.
iv) The JSON-encoded form for accepting "options" will be pretty hard for users to use. We should instead accept standard UNIX-style key-value pairs which will be applied to the options individually - for example,
fluid-publish remoteName="origin" --standard
etc.
Instead of being passed in as a stringified options object, each individual option is now taken in as a key/value pair.
@amb26 updated to sharable eslint configuration, cleaned up README, and changed command line options to be key/value pairs as you recommended. |
We should update this pull so that it executes any "prepublish" script registered in package.json before publishing to npm, now that we are making use of this step within Infusion with fluid-project/infusion#760 |
@amb26 i thought that would just happen automatically when we tried to do an NPM publish. |
@jobara I guess that's right - sorry for not thinking too clearly. I had forgotten how the workflow of this utility works. |
@@ -39,20 +44,15 @@ publish.getPkg = function (moduleRoot) { | |||
return require(modulePkgPath); | |||
}; | |||
|
|||
var pkg = publish.getPkg(__dirname); | |||
var defaults = pkg.defaultOptions; | |||
|
|||
/** | |||
* Processes the argv command line arguments into an object | |||
* | |||
* @returns {Object} - the CLI arguments as an options object | |||
*/ | |||
publish.getCLIOpts = function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add some docs here to explain what format the options are expected to be in - e.g. that they must be in units which contain no spaces, with an "=" character separating key from value, with "false" interpreted as a boolean, and an absence of "=" indicating true.
We should also fix up the irregularity that doesn't specially interpret "true" even though we interpret "false".
*/ | ||
publish.execSyncFromTemplate = function (cmdTemplate, cmdValues, hint, isTest) { | ||
var cmdStr = es6Template(cmdTemplate, cmdValues); | ||
publish.log("Executing Command: " + cmdStr + "\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the "\n" character is unnecessary here since console.log already starts a new line
@@ -287,7 +304,8 @@ publish.clean = function (moduleRoot, options) { | |||
* @param options {Object} - see defaultOptions in package.json for possible values | |||
*/ | |||
publish.dev = function (isTest, options) { | |||
var opts = extend(true, {}, defaults, options); | |||
var publishPkg = publish.getPkg(__dirname); | |||
var opts = extend(true, {}, publishPkg.defaultOptions, options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make publish.dev more robust to ensure that it does cleanup if something goes wrong - for example, if npm publish fails, the working copy is left dirty with the modified package.json. We should make sure that we always run publish.clean even in the event of a failure.
The cleanup will happen even in cases where the publishing or tagging steps fail. This way the repo won't be left in a "dirty" state.
The getCLIOpts method now converts both "true" and "false" to their respective booleans.
@amb26 ready for more review |
As discussed in #fluid-work today, we should fix our npm publish step to avoid polluting the "latest" dist tag: https://botbot.me/freenode/fluid-work/2016-12-19/?msg=78159639&page=1 |
@amb26 thanks for catching the issue with tagging dev releases. I've implemented a fix and added it to this PR. Ready for more review. |
<code>publishDevHint</code> | ||
</td> | ||
<td> | ||
A hint for addressing an issue where publishing to the registry fails. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description should distinguish from publishHint
A hint for addressing an issue where publishing to the registry fails. | ||
</td> | ||
<td> | ||
"Ensure that you have access to publish to the registry and that the current version does not already exist.\nIf the tag already exists use a new tag name or run \"npm dist-tag rm ${packageName} ${tag}\" to remove the existing one.\nAlso ensure that the tag name is valid (i.e. doesn't conform to a valid semver range like v1.4 or 1.4).\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last sentence is puzzlingly worded - is it the case that a tag name CANNOT correspond to a semver version, or is it the opposite?
var publishCmd = options.publishCmd || defaults.publishCmd; | ||
publish.execSync(publishCmd); | ||
var pubCmd = isDev ? options.publishDevCmd : options.publishCmd; | ||
publish.execSyncFromTemplate(pubCmd, options, options.publishHint); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this command doesn't use options.publishDevHint when publishing a dev release, as I imagine it should
@@ -318,81 +318,68 @@ console.log("\n*** publish.pubImpl ***"); | |||
|
|||
var pubImplFixture = [{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A small strategy hint comment would help the reader here - something like 'In the cases where commands should not execute, their entry in the structure has been filled with a placeholder string beginning "shouldn't"'
"grunt-jsonlint": "1.0.4", | ||
"sinon": "^1.17.1" | ||
"sinon": "1.17.1" | ||
}, | ||
"defaultOptions": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for the future - this strategy of packing configuration options into package.json is cute, but doesn't actually enable reuse of the functionality. In order to customise these strings, the user has to fork this module and change them! When we start work on the "mature multirepo fluid-publish" sketched out in #7, we should move this module over to being a standard Infusion component and have all these options as part of its defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the default values aren't easily modifiable. In execution they are, but I agree that's not great for reuse and building upon.
@amb26 ready for more review. |
"changesHint": "Address uncommitted changes: Commit \"git commit -a\", Stash \"git stash\" or Clean \"git reset --hard\"\n", | ||
"checkRemoteHint": "Run \"git remote -v\" for a list of available remote repositories.\n", | ||
"publishHint": "Ensure that you have access to publish to the registry and that the current version does not already exist.\n", | ||
"publishDevHint": "Ensure that you have access to publish to the registry and that the current version does not already exist.\nIf the tag already exists use a new tag name or run \"npm dist-tag rm ${packageName} ${tag}\" to remove the existing one.\nTags share a namespace with versions. To reduce confusion, tags that can be interpreted as semver values, will be rejected.\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't understand what the last two sentences of this hint are trying to explain. When it says, "will be rejected", who is going to do the rejecting? I don't see that you have implemented any behaviour to implement this rejecting. Also, isn't the point of publishing dev releases that the system automatically computes the version number, and does not do any tagging? Perhaps this comment is talking about npm tags rather than git tags. But I thought that all we did with these was to apply "dist" to the latest full release, not to dev releases. I am completely confused! Can you reduce the confusion further :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amb26 yes, this refers to NPM tags, not version control tags. The command used is publishDevCmd": "npm publish --tag ${devTag}
and devTag defaults to "dev". However, if a user were to override the dev tag to say "v2.2" or something of that sort, it would be rejected by NPM. So the rejection is not happening by fluid-publish but by NPM.
@amb26 ready for more review. |
https://issues.fluidproject.org/browse/FLUID-5799
Addresses the three areas of issues as indicated in FLUID-5799
Also updated to ESLint
Added an option to retrieve the module's own version.
https://issues.fluidproject.org/browse/FLUID-5967