Skip to content

Commit 5bde090

Browse files
authored
Switch from yarn to npm; repair dependency graph (#2576)
- removes yarn.lock, add package-lock.json - upgrades (and in one case downgrades) dependencies to achieve compatibility between peer dependencies (for example, packages that have a peerDependency on react are all compatible with React 17.0.2 now, whereas before some only claimed to be compatible with React <= 16 or React >= 18). - deletes a couple of unused dependencies - refactors one widget (the Featured Challenges carousel) in order to drop our dependency on the unmaintained react-elastic-carousel package.
1 parent 908a823 commit 5bde090

15 files changed

Lines changed: 15079 additions & 8779 deletions

File tree

.github/workflows/node.js.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,21 @@ jobs:
2121
uses: actions/setup-node@v4
2222
with:
2323
node-version: ${{ matrix.node-version }}
24-
cache: 'yarn'
25-
cache-dependency-path: 'yarn.lock'
24+
cache: 'npm'
2625

2726
- name: Install dependencies
28-
# --frozen-lockfile: don't generate a lockfile and fail if an update is needed
29-
run: yarn install --frozen-lockfile
27+
# `npm ci` is like `npm install` but meant for automated environments
28+
# where you want to do a clean install or die trying.
29+
# See https://docs.npmjs.com/cli/v11/commands/npm-ci
30+
run: npm ci
3031

3132
- name: Check for formatting and linting errors
32-
run: yarn run check
33+
run: npm run check
3334

3435
- name: Run build
35-
run: yarn run build
36+
run: npm run build
3637
env:
3738
NODE_OPTIONS: --max-old-space-size=4096
3839

3940
- name: Run the tests
40-
run: yarn test -- --coverage
41+
run: npm run test -- --coverage

DEVELOPMENT.md

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,18 @@ will help you set that up easily.
99
### Basic Dependencies:
1010

1111
* [Node 18, 20 LTS](https://nodejs.org/)
12-
* [yarn](https://yarnpkg.com/)
13-
* [jq](https://stedolan.github.io/jq/)
12+
* [jq](https://jqlang.org/)
1413
* [curl](https://curl.haxx.se/)
1514

1615
### Initial Setup
1716

18-
1. Create a `.env.development.local` file and then look through `.env` at the
17+
1. Create a `.env.local` file and then look through `.env` at the
1918
available configuration options and override any desired settings in your
20-
new `.env.development.local`
19+
new `.env.local`
2120

22-
2. `yarn` to fetch and install NPM modules
21+
2. `npm install` to fetch and install NPM modules
2322

24-
3. `yarn run start` to fire up the front-end development server
23+
3. `npm run start` to fire up the front-end development server
2524

2625
A back-end server from the [maproulette-backend](https://github.com/maproulette/maproulette-backend)
2726
project is also required. You can either install and configure it locally or, if
@@ -33,15 +32,18 @@ key for that server.
3332
To avoid platform specific issues, the UI can be built and run within a docker container.
3433
Note that this will create the development build and not the 'production' build.
3534

36-
1. First make the required `.env.development.local` file. A few overrides are required, like these:
35+
1. First make the required `.env.local` file. A few overrides are required, like these:
3736

3837
```
3938
REACT_APP_URL='http://127.0.0.1:3000'
4039
REACT_APP_SERVER_OAUTH_URL='http://127.0.0.1:9000/auth/authenticate?redirect=http://127.0.0.1:3000'
4140
```
4241

4342
2. Build the image using `docker build --pull -t maproulette-ui .`
44-
3. Start a container from the image using `docker run -itd -p 127.0.0.1:3000:3000 --name maproulette-ui maproulette-ui`
43+
3. Start a container from the image using `docker run -d -p 127.0.0.1:3000:80 maproulette-ui`
44+
45+
Note that if you make changes to the code, you'll need to rebuild the image and restart
46+
the container to see them reflected in the application.
4547

4648
#### Developing with a local back-end server
4749

@@ -81,7 +83,7 @@ Note that this will create the development build and not the 'production' build.
8183
on the command line. See the maproulette-backend docs for details on starting up
8284
the server
8385

84-
6. Edit your `.env.development.local` file in your front-end project and set:
86+
6. Edit your `.env.local` file in your front-end project and set:
8587
```
8688
REACT_APP_SERVER_OAUTH_URL='http://127.0.0.1:9000/auth/authenticate?redirect=http://127.0.0.1:3000'
8789
```
@@ -99,7 +101,7 @@ a local one you have installed. **Please do not use the production API for devel
99101
Alternatively, you can use the server's `super.key` if it has been setup
100102
with one and you have access to it
101103

102-
2. Edit your `.env.development.local` file and override the following config
104+
2. Edit your `.env.local` file and override the following config
103105
variables:
104106
```
105107
REACT_APP_MAP_ROULETTE_SERVER_URL='https://yourserver.com'
@@ -108,7 +110,7 @@ a local one you have installed. **Please do not use the production API for devel
108110
REACT_APP_SERVER_API_KEY='your-api-key-for-that-server'
109111
```
110112

111-
3. Restart your front-end dev server if it's already running (ctrl-c then `yarn
113+
3. Restart your front-end dev server if it's already running (ctrl-c then `npm
112114
run start` again)
113115

114116
4. Point your browser directly at the front-end server, http://127.0.0.1:3000
@@ -122,24 +124,24 @@ a local one you have installed. **Please do not use the production API for devel
122124
123125
1. Stop your front-end server (ctrl-c) if it's running.
124126
2. Pull the latest code
125-
3. `yarn` to install new or updated NPM packages
126-
4. `yarn run start` to restart the front-end server.
127+
3. `npm install` to install new or updated NPM packages
128+
4. `npm run start` to restart the front-end server.
127129

128130
## Staging/Production build:
129131

130132
1. Setup a `.env.production` file with the desired production setting overrides.
131-
* set `REACT_APP_URL='https://myserver.com'`
133+
* set `REACT_APP_URL='https://example.com'`
132134
(substituting your domain, of course)
133-
* set `REACT_APP_MAP_ROULETTE_SERVER_URL='https://myserver.com'`
135+
* set `REACT_APP_MAP_ROULETTE_SERVER_URL='https://example.com'`
134136
* if you wish to use [Matomo/PIWIK](https://github.com/matomo-org/matomo) for
135137
analytics, set `REACT_APP_MATOMO_URL` and `REACT_APP_MATOMO_SITE_ID` to your
136138
tracking url and site id, respectively (see `.env` file for example).
137139
* set feature flags to `enabled` or `disabled` as desired.
138140
* override any other settings from the `.env` file as needed or desired.
139141

140-
2. `yarn` to install and update NPM packages.
142+
2. `npm install` to install and update NPM packages.
141143

142-
3. `yarn run build` to create a minified front-end build in the `build/`
144+
3. `npm run build` to create a minified front-end build in the `build/`
143145
directory.
144146

145147
## Adding Additional and Custom Map Layers
@@ -187,14 +189,24 @@ Release versions follow [Semantic Versioning](https://semver.org/).
187189

188190
## Unit Tests
189191

190-
Unit tests are built with [Jest](https://facebook.github.io/jest/) +
191-
[Enzyme](https://github.com/airbnb/enzyme).
192+
Unit tests are built with [Vitest](https://vitest.dev/),
193+
[React Testing Library](https://testing-library.com/docs/react-testing-library/intro),
194+
and [Enzyme](https://github.com/airbnb/enzyme).
192195

193-
`yarn test` to run them in watch mode.
196+
Use `npm run test` to run them in watch mode.
194197

195198
## Linting and formatting
196199

197-
Run `yarn format` to format your code. Run `yarn lint` to check for lint errors.
200+
Run `npm run format` to format your code. Run `npm run lint` to check for lint
201+
errors (`npm run lint -- --fix` will fix any lint errors that can be corrected
202+
automatically).
203+
204+
Pull requests are run through a CI (Continuous Integration) process that checks
205+
to make sure that code is formatted correctly and that there are no linting
206+
errors. You can run `npm run check` to apply these same checks locally. This
207+
will check to make sure your code is formatted correctly and passes the linter,
208+
but won't make any changes in the event that it isn't (it will just report an
209+
error).
198210

199211
If you want, you can enable a pre-commit hook to check for linting and formatting
200212
issues automatically when you run `git commit`. To enable the check, run this
@@ -204,6 +216,10 @@ command in the root of the repository:
204216
git config core.hooksPath hooks
205217
```
206218

219+
This configures Git to use the hook scripts in the `hooks/` directory. The
220+
`pre-commit` script there is run when Git prepares a commit. That script runs
221+
`npm run check` to ensure there are no linting or formatting errors.
222+
207223
If you want to skip the check for a particular commit (for work-in-progress commits
208224
for example), run `git commit --no-verify`.
209225

@@ -221,8 +237,8 @@ Internationalization and localization is performed via
221237
co-located Messages.js files that contain messages intended for display,
222238
along with default (U.S. English) versions of each message.
223239

224-
A fresh en-US.json file can be built from the latest messages using `yarn run
225-
build-intl`, which is also run automatically as part of the `yarn build` script
240+
A fresh en-US.json file can be built from the latest messages using `npm run
241+
build-intl`, which is also run automatically as part of the `npm run build` script
226242
used for creating production builds.
227243

228244
Translations for other locales are managed through

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ FROM node:18-alpine AS builder
33
WORKDIR /maproulette3
44
RUN apk update && apk add curl git jq
55

6-
COPY package.json yarn.lock ./
7-
RUN yarn install
6+
COPY package.json package-lock.json ./
7+
RUN npm ci
88

99
COPY . .
1010

1111
ENV NODE_OPTIONS="--max-old-space-size=8192"
12-
RUN yarn run build
12+
RUN npm run build
1313

1414
FROM nginx:1.25-alpine
1515

hooks/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
set -ex
33

4-
yarn run check
4+
npm run check

0 commit comments

Comments
 (0)