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

Make the build / run / test process Windows-compatible by adding NPM scripts for all the tasks. #13536

Merged
merged 14 commits into from
May 24, 2017

Conversation

DanReyLop
Copy link
Contributor

This PR is a split of #12583, a bit smaller so it's easier to review and less risky.

This PR keeps the Makefile and all its tasks intact. So now, both systems
(NPM and make) should work, but NPM is used everywhere (CircleCI, Dockerfile, css-hot-loader).

To keep the PR reasonably small, I've ommited any documentation changes.

cc/ @blowery @gziolo @gwwar @stephanethomas

@matticbot
Copy link
Contributor

@matticbot matticbot added the [Size] XL Probably needs to be broken down into multiple smaller issues label May 1, 2017
@DanReyLop DanReyLop added Build Framework [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels May 1, 2017
@gziolo
Copy link
Member

gziolo commented May 2, 2017

From CircleCi:

screen shot 2017-05-02 at 08 39 48

It's present in other branches, too ... :)

outputOptions;

if ( 'development' === config( 'env' ) ) {
Copy link
Member

@gziolo gziolo May 2, 2017

Choose a reason for hiding this comment

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

It looks like bundleEnv wasn't used at all before. Why do we want to exit early for development env?

Copy link
Contributor Author

@DanReyLop DanReyLop May 2, 2017

Choose a reason for hiding this comment

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

In the Makefile, the bundler is only run when env != development, here: https://github.com/Automattic/wp-calypso/blob/master/Makefile#L188

That (conditionals) is hard to replicate in NPM scripts, so I opted for always running the bundler (here) and exit early if env == development.

Copy link
Member

Choose a reason for hiding this comment

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

Cool 👍 Now it makes perfect sense :)

@@ -8,9 +8,10 @@

var async = require( 'async' ),
camelCase = require( 'lodash/camelCase' ),
config = require( 'config' ),
config = require( '../../config' ),
Copy link
Member

Choose a reason for hiding this comment

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

Does it break otherwise? This config thing is really confusing :(

Copy link
Contributor Author

@DanReyLop DanReyLop May 2, 2017

Choose a reason for hiding this comment

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

No, it doesn't break. I probably made this change before I figured out how NODE_PATH works. I've just reverted it to remove some noise.

@DanReyLop DanReyLop force-pushed the try/build-with-npm-scripts branch from 7cdd335 to 17c750b Compare May 2, 2017 07:04
@gziolo
Copy link
Member

gziolo commented May 2, 2017

I testes the following command on macOS Sierra:

  • npm run analyze-bundles
  • npm run clean
  • npm run distclean
  • npm start
  • npm test

Everything works as expected.

I'm wondering if pre commands always work properly. In the case of npm run analyze-bundles it does't execute prebuild (npm run -s install-if-needed). See:

Grzegorzs-MacBook-Pro:wp-calypso gziolo$ npm run analyze-bundles

wp-calypso@0.17.0 preanalyze-bundles /Users/gziolo/PhpstormProjects/wp-calypso
cross-env WEBPACK_OUTPUT_JSON=1 CALYPSO_ENV=production npm run -s build

Rendering Complete, saving .css file...
Wrote CSS to /Users/gziolo/PhpstormProjects/wp-calypso/public/directly.css
Rendering Complete, saving .css file...
Wrote CSS to /Users/gziolo/PhpstormProjects/wp-calypso/public/editor.css
Rendering Complete, saving .css file...
Wrote CSS to /Users/gziolo/PhpstormProjects/wp-calypso/public/style.css
Building: proptypes-index.json
Rendering Complete, saving .css file...
Wrote Source Map to /Users/gziolo/PhpstormProjects/wp-calypso/public/style-debug.css.map
Wrote CSS to /Users/gziolo/PhpstormProjects/wp-calypso/public/style-debug.css
Saving: /Users/gziolo/PhpstormProjects/wp-calypso/public/style-rtl.css
Time: 21s 838.901ms

@DanReyLop
Copy link
Contributor Author

I'm wondering if pre commands always work properly. In the case of npm run analyze-bundles it does't execute prebuild (npm run -s install-if-needed).

That's expected. It is executing prebuild, it just isn't showing in the console. I've added -s (--silent) to all the npm run commands so running a build isn't too noisy. So, if you run npm run command, in the console you'll only see lines for precommand, command and postcommand, not for the dependant subcommands.

@gziolo
Copy link
Member

gziolo commented May 2, 2017

It needs more testing, but otherwise it looks awesome 👍

Copy link
Contributor

@stephanethomas stephanethomas left a comment

Choose a reason for hiding this comment

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

I had very minor comments, but otherwise the code looks good.

*/

const fs = require( 'fs' );
const shrinkwrap = require( __dirname + '/../npm-shrinkwrap.json' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really have to use __dirname here? What about the following?

const shrinkwrap = require( '../npm-shrinkwrap.json' );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, it's not needed. Fixed.

package.json Outdated
@@ -32,6 +32,7 @@
"bounding-client-rect": "1.0.5",
"browser-filesaver": "1.1.0",
"chalk": "1.0.0",
"check-node-version": "2.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be a typo: the latest version is 2.1.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a typo, 2.0.1 was the latest version until 2 days ago :)

Bumped to the latest.

package.json Outdated
@@ -61,11 +63,12 @@
"flux": "2.1.1",
"fuse.js": "2.6.1",
"get-video-id": "2.1.4",
"globby": "3.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

What about using the latest version, which is 6.1.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one may have been a typo... 3.0.1 is quite old.

Bumped to the latest.

@stephanethomas
Copy link
Contributor

I tried on Ubuntu and I could run Calypso without any apparent issue. I tried the following commands:

npm install
npm start
npm run eslint-branch
npm run lint
npm run update-deps

There is this strange error about Yarn when I run npm start though:

> wp-calypso@0.17.0 prestart /var/sources-others/calypso
> npm run -s install-if-needed && ( check-node-version --package || exit 0 )

node: 6.10.2
npm: 3.10.10
/bin/sh: 1: yarn: not found

@DanReyLop
Copy link
Contributor Author

There is this strange error about Yarn when I run npm start though:

Did you try it after my latest change? It was a bug that was fixed in the latest version of check-node-version: parshap/check-node-version#11

It's not really an error because we don't have a yarn version requirement listed in package.json, but that output can be confusing.

@stephanethomas
Copy link
Contributor

Did you try it after my latest change? It was a bug that was fixed in the latest version of check-node-version

No I didn't test that change. Glad to hear it was fixed!

@matticbot
Copy link
Contributor

@DanReyLop This PR needs a rebase

@matticbot
Copy link
Contributor

@DanReyLop This PR needs a rebase

@DanReyLop
Copy link
Contributor Author

So... is this ready to ship? 2 people tested it in OS X and Ubuntu with no apparent issues, and CI is passing (using the new build commands).

@matticbot
Copy link
Contributor

@DanReyLop This PR needs a rebase

@matticbot
Copy link
Contributor

@DanReyLop This PR needs a rebase

@DanReyLop
Copy link
Contributor Author

If there is no objection, I plan to merge this PR next Wednesday at noon UTC.

Since Dockerfile uses the make build command, the risk to the actual production build is minimal. CircleCI has been running using the new npm scripts, without any issue. Plus, 2 people have already tested it.

@gziolo
Copy link
Member

gziolo commented May 20, 2017

I'll give it another try on Monday or Tuesday :)

@gziolo
Copy link
Member

gziolo commented May 22, 2017

Tested again on Mac OS X:

  • npm run analyze-bundles
  • npm run build
  • npm run build-docker
  • npm run clean
  • npm run docker
  • npm run lint:css- it errors locally
  • npm run lint:js - it errors locally
  • npm start
  • npm run translate
  • npm run update-deps

@gziolo
Copy link
Member

gziolo commented May 22, 2017

When loading http://calypso.localhost:3000/read/a8c I see the following error on JS console:

screen shot 2017-05-22 at 14 26 57

It probably needs another rebase with master.

@gziolo
Copy link
Member

gziolo commented May 22, 2017

After executing npm run update-deps I have modified npm-shrinkwrap.json file. It would be a good idea to update regenerate it again in this branch just before merging it with master.

Technically npm run lint:js works, but it errors. At the same time Circle CI build passes, so I'm assuming there are differences in configuration.

@@ -5,9 +5,9 @@ test:
pre:
- ? |
# make the build-server and i18n string data in parallel
if [[ "$CIRCLE_NODE_INDEX" == 0 ]]; then NODE_ENV=test make build-server; fi
if [[ "$CIRCLE_NODE_INDEX" == 0 ]]; then NODE_ENV=test npm run build-server; fi
Copy link
Member

Choose a reason for hiding this comment

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

Can we revert changes made to Circle CI config file and put them in the follow up PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could, but... why? CircleCI is passing using the new build system, which gives some reassurance that it works.

@gziolo gziolo added [Status] Needs Author Reply and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels May 22, 2017
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

I think we should double check why linter fails locally and remove changed applied to Circle CI config file. We should also make sure Calypso works properly. It is probably some unlucky coincidence that Reader errors.

Once this is done I'm happy to approve this patch.

@DanReyLop
Copy link
Contributor Author

Technically npm run lint:js works, but it errors. At the same time Circle CI build passes, so I'm assuming there are differences in configuration.

npm run lint:js runs it on the whole codebase (which still has a ton of lint errors), while CircleCI only lints the files that were modified in the branch. A more practical command to run locally is npm run eslint-branch.

npm run lint:css isn't run by CircleCI at all, it's giving hundreds of errors since forever (in master too).

After executing npm run update-deps I have modified npm-shrinkwrap.json file. It would be a good idea to update regenerate it again in this branch just before merging it with master.

Done :)

When loading http://calypso.localhost:3000/read/a8c I see the following error on JS console:

I've merged with master again, that solved it for me.

@DanReyLop DanReyLop added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] Needs Author Reply labels May 24, 2017
# Conflicts:
#	npm-shrinkwrap.json
#	package.json
@DanReyLop DanReyLop merged commit 45dcdae into master May 24, 2017
@DanReyLop DanReyLop deleted the try/build-with-npm-scripts branch May 24, 2017 16:22
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label May 24, 2017
"test-test": "cross-env NODE_ENV=test NODE_PATH=test:client TEST_ROOT=test node test/runner.js",
"test-test:watch": "nodemon -e js,jsx --exec npm run -s test-test",
"translate": "i18n-calypso --format pot --output-file ./calypso-strings.pot -e date \"**/*.js\" \"**/*.jsx\" \"!build/**\" \"!node_modules/**\" \"!public/**\" \"!client/extensions/**\"",
"update-deps": "npm run -s rm -- node_modules && npm run -s rm -- npm-shrinkwrap.json && npm install && npm install && npm shrinkwrap --dev"
Copy link
Contributor

Choose a reason for hiding this comment

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

@DanReyLop Sorry, I missed this earlier, but do you mind adding a --no-optional flag to each of the install commands in a follow up PR? eg npm install --no-optional

Currently this will add fsevents to the shinkwrap that will throw errors in the docker image.

screen shot 2017-05-24 at 10 21 39 am

See also #5386

Copy link
Contributor Author

@DanReyLop DanReyLop May 24, 2017

Choose a reason for hiding this comment

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

Is that still a problem? npm 3.10.9 and lower had that issue, but it was fixed in 3.10.10 (which is what we're using). See: https://github.com/npm/npm/releases/tag/v3.10.10

Copy link
Contributor

@gwwar gwwar May 24, 2017

Choose a reason for hiding this comment

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

screen shot 2017-05-24 at 10 40 04 am

Nice, it no longer tries to build fsevents from scratch. Ignore my above comment then. 😄

I also tested to see if we still need the double install, and it looks like that has finally been fixed too, so we can cut this down to one npm install

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice! I'll gladly remove yet another hack on my next PR :)
I never had the "double install" problem, so I wasn't sure how did it manifest itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

After we updated to npm 3, it used to show up very consistently after you removed node_modules + the shrinkwrap. Basically you'd npm install and then a second npm install would install more stuff!

Looks like it was closed out a while ago, see: npm/npm#10727

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gwwar Just to be on the safe side, I won't remove the second npm install. According to this PR: npm/npm#12811 (comment) the fix was included in npm 4.0.5, so we'll better wait till October :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me 👍

@astralbodies
Copy link
Contributor

Was the desktop app build tested with this PR? I'm having problems building on CircleCI but not on my macOS machine.

@DanReyLop
Copy link
Contributor Author

@astralbodies I tried funning make build-desktop, but not building the full wp-desktop. What error are you getting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build Framework [Size] XL Probably needs to be broken down into multiple smaller issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants