Skip to content

Commit

Permalink
[AIRFLOW-6272] Switch from npm to yarnpkg for managing front-end depe…
Browse files Browse the repository at this point in the history
…ndencies (apache#6844)

It is:

- quicker to install
- easier to get repeatable results
- Takes up less space (130MB/15k files vs 190MB/23k files)
- nicer to user (has better help)
  • Loading branch information
ashb authored and potiuk committed Dec 19, 2019
1 parent 0f1de0b commit 2a157e3
Show file tree
Hide file tree
Showing 11 changed files with 5,265 additions and 11,521 deletions.
4 changes: 2 additions & 2 deletions BREEZE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,9 @@ Installing Dependencies for a Single Breeze Session
...................................................

You can install dependencies inside the container using ``sudo apt install``, ``pip install`` or
``npm install`` (in ``airflow/www`` folder) respectively. This is useful if you want to test something
``yarn install`` (in ``airflow/www`` folder) respectively. This is useful if you want to test something
quickly while you are in the container. However, these changes are not retained: they disappear once you
exit the container (except for theh npm dependencies if your sources are mounted to the container).
exit the container (except for theh node.js dependencies if your sources are mounted to the container).
Therefore, if you want to retain a new dependency, follow the second option described below.

Adding Dependencies Permanently
Expand Down
53 changes: 27 additions & 26 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -314,20 +314,20 @@ development machine before continuing with migration.
~/airflow/airflow/migrations/versions/12341123_add_new_field_to_db.py
node / npm Javascript Environment Setup
================================================
Node.js Environment Setup
=========================

``airflow/www/`` contains all npm-managed, front-end assets. Flask-Appbuilder
``airflow/www/`` contains all yarn-managed, front-end assets. Flask-Appbuilder
itself comes bundled with jQuery and bootstrap. While they may be phased out
over time, these packages are currently not managed with npm.
over time, these packages are currently not managed with yarn.

Make sure you are using recent versions of node and npm. No problems have been
found with node\>=8.11.3 and npm\>=6.1.3.
Make sure you are using recent versions of node and yarn. No problems have been
found with node\>=8.11.3 and yarn\>=1.19.1

Installing npm and its packages
Installing yarn and its packages
-------------------------------

Make sure npm is available in your environment.
Make sure yarn is available in your environment.

To install it on macOS:

Expand All @@ -336,22 +336,19 @@ To install it on macOS:
.. code-block:: bash
brew install node --without-npm
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh
brew install yarn
yarn config set prefix ~/.yarn
2. Add ``~/.npm-packages/bin`` to your ``PATH`` so that commands you install
2. Add ``~/.yarn/bin`` to your ``PATH`` so that commands you install
globally are usable.

3. Set up your ``.bashrc`` file and then ``source ~/.bashrc`` to reflect the
change.
You can also follow `general npm installation
instructions <https://docs.npmjs.com/downloading-and-installing-node-js-and-npm>`__.
For example:

.. code-block:: bash
export PATH="$HOME/.npm-packages/bin:$PATH"
export PATH="$HOME/.yarn/bin:$PATH"
4. Install third party libraries defined in ``package.json`` by running the
following commands within the ``airflow/www/`` directory:
Expand All @@ -361,31 +358,35 @@ To install it on macOS:
# from the root of the repository, move to where our JS package.json lives
cd airflow/www/
# run npm install to fetch all the dependencies
npm install
# run yarn install to fetch all the dependencies
yarn install
These commands install the libraries in a new ``node_modules/`` folder within
``www/``.

Should you add or upgrade an npm package, which involves changing
``package.json``, you'll need to re-run ``npm install`` and push the newly generated
``package-lock.json`` file so that we get a reproducible build.
Should you add or upgrade an node package, you should run:
``yarn add --dev <package>`` for packages needed in development
or
``yarn add <package>`` for packages used by the code
and push the newly generated ``package.json`` and ``yarn.lock`` file so that we
get a reproducible build. See the `Yarn docs
<https://yarnpkg.com/en/docs/cli/add#adding-dependencies->`_ for more info


Generating Bundled Files with npm
---------------------------------
Generating Bundled Files with yarn
----------------------------------

To parse and generate bundled files for Airflow, run either of the following
commands:

.. code-block:: bash
# Compiles the production / optimized js & css
npm run prod
yarn run prod
# Starts a web server that manages and updates your assets as you modify them
npm run dev
yarn run dev
Javascript Style Guide
Expand All @@ -405,10 +406,10 @@ commands:
.. code-block:: bash
# Check JS code in .js and .html files, and report any errors/warnings
npm run lint
yarn run lint
# Check JS code in .js and .html files, report any errors/warnings and fix them if possible
npm run lint:fix
yarn run lint:fix
Contribution Workflow Example
==============================
Expand Down
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ RUN apt-get update \

# Install basic apt dependencies
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - >/dev/null \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
apt-utils \
Expand All @@ -73,6 +75,7 @@ RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
rsync \
sasl2-bin \
sudo \
yarn \
&& apt-get autoremove -yqq --purge \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
Expand Down Expand Up @@ -293,12 +296,11 @@ RUN \
# Install NPM dependencies here. The NPM dependencies don't change that often and we already have pip
# installed dependencies in case of CI optimised build, so it is ok to install NPM deps here
# Rather than after setup.py is added.
COPY airflow/www/package-lock.json ${AIRFLOW_SOURCES}/airflow/www/package-lock.json
COPY airflow/www/package.json ${AIRFLOW_SOURCES}/airflow/www/package.json
COPY airflow/www/yarn.lock airflow/www/package.json ${AIRFLOW_SOURCES}/airflow/www/

WORKDIR ${AIRFLOW_SOURCES}/airflow/www

RUN npm ci
RUN yarn install --frozen-lockfile

WORKDIR ${AIRFLOW_SOURCES}

Expand All @@ -322,11 +324,11 @@ RUN pip install -e ".[${AIRFLOW_EXTRAS}]"

WORKDIR ${AIRFLOW_SOURCES}/airflow/www

# Copy all www files here so that we can run npm building for production
# Copy all www files here so that we can run yarn building for production
COPY airflow/www/ ${AIRFLOW_SOURCES}/airflow/www/

# Package NPM for production
RUN npm run prod
RUN yarn run prod

COPY ./scripts/docker/entrypoint.sh /entrypoint.sh

Expand Down
4 changes: 2 additions & 2 deletions airflow/www/compile_assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ if [[ -d airflow/www/static/dist ]]; then
fi

cd airflow/www/
npm install
npm run build
yarn install --frozen-lockfile
yarn run build
cd ../..
Loading

0 comments on commit 2a157e3

Please sign in to comment.