Skip to content

Latest commit

 

History

History
144 lines (108 loc) · 7.03 KB

Installation.md

File metadata and controls

144 lines (108 loc) · 7.03 KB

Want to get started quickly?

Install requirements

You need Node, Yarn (or npm) and watchman.

  • node -v should be >= 24.14.1
  • yarn --version should be the in-tree 4.13.0 version. See instructions on how to use it on your OS. For example, you might need to run: corepack enable.

You also need a C compiler:

  • Linux: GCC 4.6 or later
  • OS X: Xcode 5.0 or later

WSL

Add the following to your /etc/wsl.conf if not yet present. This prevents WSL from regenerating the /etc/hosts as well as the /etc/resolv.conf:

[network]
generateResolvConf=false
generateHosts = false

Fixed issues

Previously, using Windows Subsystem for Linux required remapping localhost to the IPv6 loopback address in /etc/hosts, because webpack-dev-server binds ::1 only (webpack.config.js) and src/server/server.js used to proxy to it by the localhost hostname — which on stock WSL resolves only to 127.0.0.1, causing ECONNREFUSED. src/server/app.js now targets the literal [::1] address instead, so this is no longer required for yarn run dev to work. If you still hit other WSL networking issues, you may need to add the following to your /etc/hosts:

::1     ip6-localhost ip6-loopback localhost

Install watchman

Version

A bit newer version of watchman is now required and 4.9.0 is no longer supported. Working versions include at least

  • 20220320.140531.0
  • 20240407.093313.0

OS X

brew install watchman

Other

It's possible to run prebuilt binaries from some release with these instructions or in some systems to build the binaries from code following these instructions.

Installation

  • yarn install

Start development version

yarn run dev runs scripts/dev.sh, which starts Relay, the Express dev server (node --watch), webpack-dev-server, the SVG sprite watcher (yarn sprites --watch) and yarn packages-watch (lerna run watch --stream --concurrency 12) in parallel. packages-watch builds every digitransit-component, digitransit-store and digitransit-search-util package once and then keeps watching/rebuilding them, so a manual yarn setup/yarn packages-build is not required beforehand.

Lerna ignores --parallel because nx.json has targetDefaults, so --concurrency must be at least the number of packages with a watch script (currently 12); with fewer, the rest never start, since a watcher never finishes. Nx is pinned to 23.2.0 in resolutions: from 23.3.0 on, Lerna's --stream is ignored and the output is replaced by Nx's task spinner.

There's also a lighter-weight yarn dev-nowatch, which only runs the Express dev server and webpack-dev-server (no Relay/package watchers). Since it skips packages-watch, on a fresh clone you must run yarn packages-build yourself first, or webpack fails with Module not found errors for @digitransit-component/*/@digitransit-search-util/*/ @digitransit-store/* packages. It also doesn't populate _static, so run yarn static and yarn sprites first too.

Start production version

Modifying sub-modules and components

While yarn run dev is running, changes to files in digitransit-component, digitransit-store and digitransit-search-util (including its query-utils Relay queries, which are also watched by a dedicated relay-compiler --watch in scripts/dev.sh) are picked up automatically by live watchers and rebuilt in the background — no manual rebuild step is needed.

Analyse webpack bundle

  • run: CONFIG=hsl NODE_ENV=production node node_modules/.bin/webpack --json > _static/digitransit.json
  • run: yarn webpack-bundle-analyzer _static/digitransit.json

Using Git Hooks

Husky (npm-package) is used for setting up the git hooks (.git/hooks/) that will allow custom scripts to be run on the repository. Look up 'husky' in package.json to see the details.

Configuration application

Digitransit ui can be configured in multiple ways. You can

  • Change between National and Regional versions using CONFIG parameter
    • Alternatively, use BASE_CONFIG if server is supposed to serve multiple configurations which have same base configuration. It is used server side at start up and request's host specific config based on host or x-forwarded-host header is merged into it before returning config to client.
  • Switch API backend using API_URL parameter

Note that you can combine multiple configuration parameters.

Run environment vs. build mode

  • RUN_ENV (development / production) — deployment tier. Server-only env var; read during config assembly to pick dev vs prod backends and mirrored into window.config for the client. Check it via isDevRunEnv(config) (src/server/utils/envUtils.js, see its JSDoc for details). yarn dev sets RUN_ENV=development; deployments set it via Kubernetes / -e RUN_ENV=….
  • NODE_ENV (development / production) — build mode; 'development' only for the local yarn dev server / a dev bundle. Not the deployment tier — one production bundle runs on every tier; use RUN_ENV/isDevRunEnv for that. Always check it via a literal process.env.NODE_ENV comparison written inline (=== 'development', !== 'production', etc.), not through an imported/computed constant — see docs/Webpack.md for why.

Changing National/Regional version (optional)

Start national version

  • yarn run build
  • yarn run start

Start HSL version

  • yarn run build
  • CONFIG=hsl yarn run start

Changing urls for OpenTripPlanner, Geocoding, Service alerts and Vehicle positions (optional)

By default digitransit-ui uses services from https://dev-api.digitransit.fi but you can override API server like so:

  • yarn run build
  • API_URL=https://api.digitransit.fi yarn run start

If you want to specify different URL (not just base URL) for individual services, you can define variables OTP_URL, MAP_URL and/or GEOCODING_BASE_URL (URL path before /search or /reverse).

  • yarn run build
  • GEOCODING_BASE_URL=https://api.digitransit.fi/geocoding/v1 OTP_URL=https://api.digitransit.fi/routing/v2/finland/ yarn run start

These are API endpoint base URLs rather than web pages, and require an API key. See the Digitransit API documentation.

Configuring static message URL with env variable

  • STATIC_MESSAGE_URL=https://dev-yleisviesti.digitransit.fi yarn run start