From 345e220af30005a8204a04ebc9b60ec2e510e30b Mon Sep 17 00:00:00 2001 From: Brian Donovan <1938+eventualbuddha@users.noreply.github.com> Date: Tue, 12 Jan 2021 10:44:16 -0800 Subject: [PATCH] build(election-manager): add to the yarn workspace Something changed such that the `assert` module that gets bundled no longer has the `strict` property, so I switched it to `strictEqual` instead of `strict.equal`. --- .circleci/config.yml | 5 +- apps/election-manager/.circleci/config.yml | 35 - apps/election-manager/package.json | 24 +- apps/election-manager/script/react-scripts | 67 + apps/election-manager/src/AppRoot.tsx | 4 +- .../src/__snapshots__/App.test.tsx.snap | 496 +- apps/election-manager/tsconfig.json | 13 +- apps/election-manager/yarn.lock | 13900 ---------------- package.json | 2 + yarn.lock | 3078 +++- 10 files changed, 3258 insertions(+), 14366 deletions(-) delete mode 100644 apps/election-manager/.circleci/config.yml create mode 100755 apps/election-manager/script/react-scripts delete mode 100644 apps/election-manager/yarn.lock diff --git a/.circleci/config.yml b/.circleci/config.yml index 6b1fe3b9eb..0044395ece 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -118,14 +118,15 @@ jobs: - checkout - restore_cache: key: - dotcache-cache-{{checksum ".circleci/config.yml" }}-{{ checksum "apps/election-manager/yarn.lock" }} + dotcache-cache-{{checksum ".circleci/config.yml" }}-{{ checksum "yarn.lock" }} - run: name: Setup Dependencies command: yarn --cwd apps/election-manager install --frozen-lockfile - save_cache: key: - dotcache-cache-{{checksum ".circleci/config.yml" }}-{{ checksum "apps/election-manager/yarn.lock" }} + dotcache-cache-{{checksum ".circleci/config.yml" }}-{{ checksum "yarn.lock" }} paths: + - node_modules - apps/election-manager/node_modules - run: name: Run Linters diff --git a/apps/election-manager/.circleci/config.yml b/apps/election-manager/.circleci/config.yml deleted file mode 100644 index 3878604b40..0000000000 --- a/apps/election-manager/.circleci/config.yml +++ /dev/null @@ -1,35 +0,0 @@ -version: 2 -jobs: - test-frontend-and-server: - docker: - - image: circleci/node:12.10.0-browsers - steps: - - checkout - - restore_cache: - key: - dotcache-cache-{{checksum ".circleci/config.yml" }}-{{ checksum - "client/package.json" }} - - run: - name: Setup Dependencies - command: yarn --cwd client install --frozen-lockfile - - run: - name: Setup Code Climate test-reporter - command: | - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - chmod +x ./cc-test-reporter - - save_cache: # special step to save the dependency cache - key: - dotcache-cache-{{checksum ".circleci/config.yml" }}-{{ checksum - "client/package.json" }} - paths: - - ~/.cache - - run: # run tests - name: Run Front-End Test and Coverage - command: | - yarn --cwd client test:coverage - -workflows: - version: 2 - test-frontend-and-server: - jobs: - - test-frontend-and-server diff --git a/apps/election-manager/package.json b/apps/election-manager/package.json index acc26ff0d9..0658e87875 100644 --- a/apps/election-manager/package.json +++ b/apps/election-manager/package.json @@ -3,19 +3,19 @@ "version": "0.1.0", "private": true, "scripts": { - "build": "react-scripts build", - "eject": "react-scripts eject", + "build": "script/react-scripts build", + "eject": "script/react-scripts eject", "format": "prettier '**/*.+(css|graphql|json|less|md|mdx|sass|scss|yaml|yml)' --write", - "lint": "tsc --noEmit && eslint '*/**/*.{js,jsx,ts,tsx}' --quiet && yarn stylelint:run", - "lint:fix": "tsc --noEmit && eslint '*/**/*.{js,jsx,ts,tsx}' --fix --quiet && yarn stylelint:run --fix", - "start": "react-scripts start", + "lint": "tsc --build && eslint '*/**/*.{js,jsx,ts,tsx}' --quiet && yarn stylelint:run", + "lint:fix": "tsc --build && eslint '*/**/*.{js,jsx,ts,tsx}' --fix --quiet && yarn stylelint:run --fix", + "start": "script/react-scripts start", "stylelint:run": "stylelint 'src/**/*.{js,jsx,ts,tsx}' && stylelint 'src/**/*.css' --config .stylelintrc-css.js", - "test": "react-scripts test --env=jest-environment-jsdom-sixteen", + "test": "script/react-scripts test --env=jest-environment-jsdom-sixteen", "test:coverage": "yarn test --coverage --watchAll=false" }, "husky": { "hooks": { - "pre-commit": "tsc && lint-staged" + "pre-commit": "tsc --build && lint-staged" } }, "lint-staged": { @@ -117,21 +117,21 @@ "@typescript-eslint/eslint-plugin": "^4.11.0", "@typescript-eslint/parser": "^4.11.0", "eslint-config-airbnb": "^17.1.1", - "eslint-config-prettier": "^6.10.0", + "eslint-config-prettier": "^7.1.0", "eslint-config-react-app": "^5.2.1", "eslint-plugin-cypress": "^2.9.0", "eslint-plugin-flowtype": "^5.2.0", "eslint-plugin-import": "^2.20.1", "eslint-plugin-jest": "^23.6.0", "eslint-plugin-jsx-a11y": "^6.2.3", - "eslint-plugin-no-array-sort-mutation": "../../libs/eslint-plugin-no-array-sort-mutation", - "eslint-plugin-prettier": "^3.1.2", + "eslint-plugin-no-array-sort-mutation": "^1.0.0", + "eslint-plugin-prettier": "^3.3.1", "eslint-plugin-react": "^7.18.3", "eslint-plugin-react-hooks": "^4.0.5", "husky": "^4.2.1", "jest-environment-jsdom-sixteen": "^1.0.3", "lint-staged": "^10.0.7", - "prettier": "^2.0.5", + "prettier": "^2.2.1", "react-test-renderer": "^16.13.1", "sort-package-json": "^1.44.0", "stylelint": "^13.1.0", @@ -140,4 +140,4 @@ "stylelint-config-styled-components": "^0.1.1", "stylelint-processor-styled-components": "^1.9.0" } -} \ No newline at end of file +} diff --git a/apps/election-manager/script/react-scripts b/apps/election-manager/script/react-scripts new file mode 100755 index 0000000000..54a595bb4e --- /dev/null +++ b/apps/election-manager/script/react-scripts @@ -0,0 +1,67 @@ +#!/usr/bin/env node + +/** + * Wrapper script around `react-scripts` to ensure monorepo dependencies are + * built before running and are watched to build on change. + */ + +// @ts-check + +const ora = require('ora') +const { spawn } = require('child_process') + +/** + * @param {() => void} onCompile + * @returns {import('child_process').ChildProcess} + */ +function watchCompileTS(onCompile) { + const tsc = spawn('yarn', ['--silent', 'tsc', '--build', '--watch'], { + stdio: 'pipe', + }) + + tsc.stdout.setEncoding('utf-8') + + tsc.stdout.on( + 'data', + /** @param {string} chunk */ (chunk) => { + if (/Found \d+ errors?\. Watching for file changes\./.test(chunk)) { + onCompile() + } + } + ) + + return tsc +} + +/** + * @param {string[]} args + * @returns {import('child_process').ChildProcess} + */ +function runApp(args) { + const app = spawn('yarn', ['--silent', 'react-scripts', ...args], { + stdio: 'inherit', + }) + + return app +} + +const spinner = ora('Running initial build…').start() +let app +const tsc = watchCompileTS(() => { + if (!app) { + spinner.stop() + app = runApp(process.argv.slice(2)) + + app.on('exit', (code) => { + process.exit(code) + }) + } +}) + +process.on('exit', () => { + tsc.kill() + + if (app) { + app.kill() + } +}) diff --git a/apps/election-manager/src/AppRoot.tsx b/apps/election-manager/src/AppRoot.tsx index a556f9c2e9..ca7fc8e456 100644 --- a/apps/election-manager/src/AppRoot.tsx +++ b/apps/election-manager/src/AppRoot.tsx @@ -1,4 +1,4 @@ -import { strict as assert } from 'assert' +import * as assert from 'assert' import React, { useState, useRef, useEffect, useCallback } from 'react' import { useInterval } from 'use-interval' import { RouteComponentProps } from 'react-router-dom' @@ -56,7 +56,7 @@ const AppRoot: React.FC = ({ storage }) => { if (electionDefinition) { const { electionData, electionHash } = electionDefinition - assert.equal(sha256(electionData), electionHash) + assert.strictEqual(sha256(electionData), electionHash) return electionDefinition } }, [storage]) diff --git a/apps/election-manager/src/__snapshots__/App.test.tsx.snap b/apps/election-manager/src/__snapshots__/App.test.tsx.snap index 75e487c6b3..5c23864fb3 100644 --- a/apps/election-manager/src/__snapshots__/App.test.tsx.snap +++ b/apps/election-manager/src/__snapshots__/App.test.tsx.snap @@ -5,16 +5,16 @@ exports[`printing ballots, print report, and test decks 1`] = ` aria-hidden="true" >

Test Deck @@ -34,7 +34,7 @@ exports[`printing ballots, print report, and test decks 1`] = `

Voting @@ -67,30 +67,30 @@ exports[`printing ballots, print report, and test decks 1`] = `
Election Manager
Voting @@ -229,30 +229,30 @@ exports[`printing ballots, print report, and test decks 2`] = `
Election Manager