Skip to content
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

Rewrite Makefile using NPS Scripts. Closes #2352 #3195

Merged
merged 1 commit into from Jan 15, 2018

Conversation

TedYav
Copy link
Contributor

@TedYav TedYav commented Jan 8, 2018

Addresses #2352

Updated version of #3194
Commit has correct Git credentials this time and Travis / Appveyor configs are now properly updated.

Description of the Change

Where possible, I tried to exactly duplicate the design of the Makefile using nps. I've tested it by running build and test commands, as well as granular testing of individual commands against a vanilla repo to ensure it's running the same commands.

Important notes:

  • removed the ==> [<ACTION> :: <SUBACTION>] output from makefile as nps does this automatically
  • did not recreate make .PHONY as this appeared to be a hack for GNU make. I'm not sure if some kind of file watching capability is desired. Perhaps this can be added back if needed.
  • removed the dependency check (SRC_FILES variable) from Makefile as I didn't see a big reason to include this in nps build command
  • code coverage is still enabled by setting COVERAGE environment variable to true. I removed the ability to set this via a command line flag as it created issues when nps spawns child processes
  • make is now nps build
  • any scripts which depend on make but were not in package.json will be broken
  • npm run <xxx> commands are now npm start <xxx> or nps <xxx>
  • scripts can only be run as nps <xxx> if nps is in user's path. However, npm start <xxx> will work regardless.

Alternate Designs

Possible modifications:

  • Can use npsUtils.concurrently.nps to run tests in parallel. This has pros and cons.
  • Can add documentation on how to use nps if needed
  • I'm tempted to eliminate all the constants from the top for NYC, MOCHA, etc, though I imagine these may be useful in case a developer wants to temporarily direct these scripts to use a different installation

Why should this be in core?

Discussed this briefly with @boneskull on Gitter back in early 2016. Didn't get around to doing it till now (my bad).

Benefits

Makefile gone!

Possible Drawbacks

Any code that depends on make commands will need to be updated.

Applicable issues

This should not be a breaking change, unless there is some code I'm not aware of that depends on make commands (possibly some CI type operations)

@TedYav
Copy link
Contributor Author

TedYav commented Jan 8, 2018

Not sure where to configure netlify --> it is failing because npm run buildDocs is now npm start buildDocs.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 90.018% when pulling 7c830a6 on TedYav:make-to-npm-scripts into a723b8f on mochajs:master.

@TedYav TedYav force-pushed the make-to-npm-scripts branch 3 times, most recently from efde20d to d6680e7 Compare January 8, 2018 03:27
@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 90.018% when pulling d6680e7 on TedYav:make-to-npm-scripts into a723b8f on mochajs:master.

@TedYav
Copy link
Contributor Author

TedYav commented Jan 8, 2018

Not sure why CI is failing.

Travis failed because a test timed out:

  1) file utils
       "before each" hook for "should accept a glob "path" value":
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

And appveyor appears to be having an issue executing Mocha from the CLI, possibly due to a difference in the way make versus nps runs commands on Windows. Perhaps I need to invert the / delimiter between bin/mocha or add ./ ?:

nps is executing `test.node.bdd` : bin/mocha --ui bdd test/interfaces/bdd.spec
'bin' is not recognized as an internal or external command,
operable program or batch file.
The script called "test.node.bdd" which runs "bin/mocha --ui bdd test/interfaces/bdd.spec" failed with exit code 1 https://github.com/kentcdodds/nps/blob/v5.7.1/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code

Don't have Windows machine near to test.

@boneskull
Copy link
Member

you could try node bin/mocha

@boneskull
Copy link
Member

travis test may be flake. you could try to increase the timeout to like 3000ms for that test

@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 90.018% when pulling 72681ef on TedYav:make-to-npm-scripts into a723b8f on mochajs:master.

@boneskull
Copy link
Member

I'm not sure where the netlify configuration lives

@boneskull
Copy link
Member

OK, we're waiting on @Munter for information about the netlify failure, but since everything else is passing I can review this. 😝

Copy link
Member

@boneskull boneskull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks awesome, thanks!

I just have a couple tweaks, but everything looks really solid. great work

@@ -1,176 +0,0 @@
BROWSERIFY := "node_modules/.bin/browserify"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of this red is the best part of the PR

return `${prefix} ${MOCHA} ${params}`;
}

module.exports = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would absolutely love it if we added description fields to everything here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kk — check over them in case anything is off. 👍

build: `browserify ./browser-entry --plugin ./scripts/dedefine --ignore 'fs' --ignore 'glob' --ignore 'path' --ignore 'supports-color' > mocha.js`,
lint: {
default: 'nps lint.code lint.markdown',
code: 'eslint . bin/*',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even though we're not running this on AppVeyor, it should still work on windows. please use double quotes around globs: 'eslint . "bin/*"'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. If anyone has access to a Windows machine too it'd be awesome to do a dry run and be sure these commands work as expected.

prebuildDocs: 'rm -rf docs/_dist && node scripts/docs-update-toc.js',
buildDocs: 'nps prebuildDocs && bundle exec jekyll build --source ./docs --destination ./docs/_site --config ./docs/_config.yml --safe --drafts && nps postbuildDocs',
postbuildDocs: 'buildProduction docs/_site/index.html --outroot docs/_dist --canonicalroot https://mochajs.org/ --optimizeimages --svgo --inlinehtmlimage 9400 --inlinehtmlscript 0 --asyncscripts && cp docs/_headers docs/_dist/_headers && node scripts/netlify-headers.js >> docs/_dist/_headers',
prewatchDocs: 'node scripts/docs-update-toc.js',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember if nps supports pre- and post- scripts. does it? when we were running this with npm, prewatchDocs would get run before watchDocs when doing npm run watchDocs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think it does, but the pre and post commands are explicitly inserted into the nps commands for that. I did move prepublishOnly back to package.json as I suspect it wouldn't trigger on npm publish if it was in package-scripts.js

}
},
browser: {
default: 'nps ' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would prefer one of a multiline template string or array w/ join

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise for other multiline strings in this file

const MOCHA = `node ${path.join('bin', 'mocha')}`;
const TM_BUNDLE = 'JavaScript\\ mocha.tmbundle';

function test (testName, params) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a little comment explaining what this does

@boneskull boneskull added the semver-patch implementation requires increase of "patch" version number; "bug fixes" label Jan 9, 2018
Munter added a commit that referenced this pull request Jan 9, 2018
The Netlify build configuration currently only resides in their admin panel. This configuration file should hopefully override those settings to allow outside contributors to make refactoring changes

Refs #3195
@Munter Munter mentioned this pull request Jan 9, 2018
Munter added a commit that referenced this pull request Jan 9, 2018
The Netlify build configuration currently only resides in their admin panel. This configuration file should hopefully override those settings to allow outside contributors to make refactoring changes

Refs #3195
@Munter
Copy link
Member

Munter commented Jan 9, 2018

@TedYav I've just merged a netlify.toml config file on master. If you rebase you should be able to adjust configuration of the build script on this branch

@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 90.018% when pulling 1ae7483 on TedYav:make-to-npm-scripts into e8b5592 on mochajs:master.

@boneskull boneskull added the type: chore generally involving deps, tooling, configuration, etc. label Jan 9, 2018
@TedYav
Copy link
Contributor Author

TedYav commented Jan 9, 2018

I'm going to rebase and squash my commits. Hopefully Travis failure was a one off and we should be good to go. Let me know if anything else is desired (i.e. updating docs to say npm start <xxx> instead of make <xxx>

@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 90.018% when pulling f8b0029 on TedYav:make-to-npm-scripts into ac1dd70 on mochajs:master.

@TedYav
Copy link
Contributor Author

TedYav commented Jan 9, 2018

I noticed another commit dropped TextMate integration. I can eliminate the TM command to even this up. Also can merge master into this branch to fix conflicts if desired.
Edit: went ahead and did it. @boneskull lemme know if you'd like any other changes :)

@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 90.018% when pulling 45ba261 on TedYav:make-to-npm-scripts into c7730a6 on mochajs:master.

@boneskull
Copy link
Member

Thanks. super awesome!

@boneskull boneskull merged commit 0a3e32b into mochajs:master Jan 15, 2018
@TedYav TedYav deleted the make-to-npm-scripts branch January 15, 2018 23:17
@boneskull boneskull added this to the v5.0.0 milestone Jan 17, 2018
@boneskull boneskull added area: repository tooling concerning ease of contribution and removed type: chore generally involving deps, tooling, configuration, etc. labels Jan 17, 2018
sgilroy pushed a commit to TwineHealth/mocha that referenced this pull request Feb 27, 2019
The Netlify build configuration currently only resides in their admin panel. This configuration file should hopefully override those settings to allow outside contributors to make refactoring changes

Refs mochajs#3195
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: repository tooling concerning ease of contribution semver-patch implementation requires increase of "patch" version number; "bug fixes"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants