Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@spotify/web-scripts

spotify2.6kApache-2.015.0.0TypeScript support: included

Build, lint, test, format, and release your JS/TS library.

readme

web-scripts

Description

Build, lint, test, format, and release your JS/TS library. This CLI tool bundles all the necessary configuration and dependencies so you can focus on the code.

Usage

yarn add --dev @spotify/web-scripts husky

Add the scripts and commit hooks to your package.json:

{
  "scripts": {
    "test": "web-scripts test",
    "lint": "web-scripts lint",
    "format": "web-scripts format",
    "build": "web-scripts build",
    "commit": "web-scripts commit",
    "release": "web-scripts release"
  },
  "husky": {
    "hooks": {
      "commit-msg": "web-scripts commitmsg",
      "pre-commit": "web-scripts precommit"
    }
  }
}

If you plan to use web-scripts build to build ESM, CommonJS, and types for your library with ease, update your package.json to define the locations where those will end up. Read more about our the build script.

{
  "main": "cjs/index.js",
  "module": "esm/index.js",
  "types": "types"
}

Editor support steps

Add a root tsconfig.json:

{
  "extends": "@spotify/web-scripts/config/tsconfig.json",
  "include": ["src"]
}

Add a root prettier.config.js:

module.exports = require('@spotify/web-scripts/config/prettier.config.js');

Add a root .eslintrc.js:

module.exports = require('@spotify/web-scripts/config/eslintrc.js');

Add a root jest.config.js:

module.exports = require('@spotify/web-scripts/config/jest.config.js');

Watchers

Both web-scripts build and web-scripts test support a --watch flag which runs the underlying CLIs (tsc and jest) as watchers.

# re-compile the cjs, esm, and types on each change to your src with tsc
web-scripts build --watch

# re-run the tests that are relevant to your file changes with jest
web-scripts test --watch

The build script

web-scripts build runs three parallel calls to the TypeScript compiler.

  • One of them transpiles the files as CommonJS and outputs it to the cjs directory. Your repo should have "cjs/index.js" set as main in your package.json. You can turn this off using --no-cjs when running build.
  • Another does the exact same thing but only transpiles to EcmaScript modules. This is super helpful if your consuming project is using Babel or TypeScript, and you'll end up avoiding playing games of transpilation telephone along the way. Your repo should have "esm/index.js" set as module in your package.json if using this. You can turn this off with the --no-esm flag when running build.
  • Finally, tsc will be run to output type definitions. Your repo should have the "types" directory set as types in your package.json if using this. You can turn this off with the --no-types flag when running build.

These parallel builds are set up to share resources and work efficiently.

If you need to use Babel for some reason, that's ok! Simply use babel directly instead of using web-scripts build. Teams inside Spotify mix and match which scripts they use to serve their needs. In many cases, tsc is all you need and is lighter and simpler to set up.

Setting up CI publishing (Travis CI)

The following steps should be from your local repository folder.

(Optional but probably mandatory): Visit https://travis-ci.com/account/repositories and click "Sync Account" otherwise the Travis CLI may not be able to register your ENV vars later.

  1. Add a basic .travis.yaml. You probably want something like:
language: node_js
node_js:
  - '14'
branches:
  only:
    - master
cache:
  yarn: true
  directories:
    - node_modules
before_install:
  - curl -o- -L https://yarnpkg.com/install.sh | bash -s
  - export PATH="$HOME/.yarn/bin:$PATH"
script:
  - yarn lint
  - yarn test
  1. Append a "release" stage to the jobs: that invokes web-scripts release:
jobs:
  include:
    - stage: release
      node_js: lts/*
      script: skip # do not run tests again
      deploy:
        provider: script
        skip_cleanup: true
        script:
          - yarn web-scripts release # or `yarn release` if you defined it in your package.json scripts
  1. Install the travis CI CLI: gem install travis
  2. Create an NPM token: https://www.npmjs.com/settings/[NPM USERNAME]/tokens (scope: Read and Publish)
  3. Set the secure ENV var: travis env set NPM_TOKEN YOUR-NPM-TOKEN
  4. Create a Github Token: https://github.com/settings/tokens (required scope: public_repo !)
  5. Set the secure ENV var: travis env set GH_TOKEN YOUR-GH-TOKEN
  6. Commit all your changes with yarn commit, and push.

If you use a scoped public package, such as @yourusername/packagename, then you'll need explicitly set in your package.json:

  "publishConfig": {
    "access": "public"
  },

Otherwise you'll receive an error during release like "You must sign up for private packages" or a missing flag --access=public.

Contributing

To start working in the repo:

yarn
yarn bootstrap

This library provides shared scripts and configs for creating a library at Spotify. It tries to use as much of those scripts and configs for itself, which is why the bootstrap task is required above. Otherwise, you can run within this package itself:

yarn lint
yarn build
yarn test

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

15.0.0 (2023-05-18)

chore

  • deps: upgrade dependencies (ef060c7)
  • node: upgrade required Node version to 18 (9528841)

BREAKING CHANGES

  • node: Node bump from v14 to v18
  • deps: TypeScript bump from v4 to v5, Jest bump from v28 to v29

14.1.6 (2023-02-14)

Bug Fixes

14.1.5 (2023-01-30)

Bug Fixes

14.1.4 (2023-01-19)

Bug Fixes

14.1.3 (2022-12-07)

Bug Fixes

14.1.2 (2022-12-02)

Bug Fixes

  • web-scripts: security vulnerability in glob (a278f21)

14.1.1 (2022-11-25)

Bug Fixes

  • precommit: add in --passWithNoTests flag to enable precommit hook to succeed with no tests (67cba2a), closes #1020

14.1.0 (2022-08-08)

Features

  • package.json/yarn.lock: upgrade minimum version of commitizen to latest (4.2.5) (81ba9e3), closes #1026

14.0.2 (2022-07-15)

Bug Fixes

  • web-scripts: resolve sec issue with ansi-regex, must use ^4.1.1 (85b2c78)
  • web-scripts: resolve sec issue with minimist, must use ^1.2.6 (d52b6a3)

14.0.1 (2022-07-12)

Bug Fixes

  • web-scripts: v14 borked, unpublished, must use v15 (df0acb5)

BREAKING CHANGES

  • web-scripts: v14 borked, unpublished, must use v15

14.0.0 (2022-07-11)

Bug Fixes

  • do not output type declarations for cjs/esm (262a174)
  • web-scripts: fix type declaration output by specifying module (814fc6b)

chore

  • deps: upgrade deps; jest from v27 to v28 (13aff23)

BREAKING CHANGES

  • deps: Jest bump from v27 to v28

13.0.1 (2022-04-19)

Bug Fixes

  • fix peer dependency versioning for eslint (46068c2)

13.0.0 (2022-03-21)

Bug Fixes

  • eslint: specify parserOptions.project (5ea256c)
  • remove parserOptions.project (c901579)
  • update yarn.lock (9ed6d68)

chore

  • update @typescript-eslint from v4 to v5, eslint from v7 to v8 (e284943)
  • update @spotify/eslint-plugin from v11 to v12 (64f9885)
  • update commitlint from v13 to v16 (51edc87)
  • update eslint from v7 to v8 (725749c)
  • update jest-junit from v12 to v13 (40701b0)
  • update semantic-release from v18 to v19 (b9fecfd)

BREAKING CHANGES

  • update semantic-release from v18 to v19
  • update jest-junit from v12 to v13
  • update @typescript-eslint from v4 to v5, eslint from v7 to v8
  • update eslint from v7 to v8
  • update @spotify/eslint-plugin from v11 to v12
  • update commitlint from v13 to v16

12.0.0 (2021-09-22)

Build System

  • deps: bump typescript from 4.3.5 to 4.4.3 (b50b7b3)
  • node: drop support for Node v12. Support only NodeJS >= 14.17.x (be04398)

BREAKING CHANGES

11.0.0 (2021-07-16)

Features

  • add support for Husky v6+ (934ee73)

HEADS UP

  • upgrade prettier from 2.2.x to 2.3.x

  • ⚠️ jest v27: if you have tests using fake timers that break, jest.useFakeTimers('legacy') might be the mitigation (See https://github.com/facebook/jest/issues/11521 for more deets)

  • ⚠️ jest v27: default test environment was changed from "jsdom" to "node" for performance. if you are affected by this change because you use DOM APIs and do not have the test environment explicitly configured, you should be receiving an error when e.g. document is accessed, and you can configure "testEnvironment": "jsdom" or use per-file environment configuration to resolve this.

BREAKING CHANGES

  • upgrade Jest from v26.x to v27.x

    TL;DR --

    • tests using fake timers might break due to a regression
    • default test environment was changed from "jsdom" to "node" for performance
    • The same done test callback may not be called more than once,
    • calling done and returning a Promise may not be combined,
    • a describe block must not return anything,
    • under the hood the test runner jest-jasmine2 was replaced with jest-circus

    For more breaking changes see: https://jestjs.io/blog/2021/05/25/jest-27

10.1.0 (2021-06-30)

INVALID RELEASE

  • This release was a mistake and should have been a major bump. This version has been npm deprecated

10.0.1 (2021-04-27)

Bug Fixes

  • precommit opts destructuring (e8a238f)

10.0.0 (2021-04-14)

Bug Fixes

  • eslint-config: use jest version setting to fix no-deprecated-functions functionality (9a67198)

Build System

Features

  • eslint-config-react: disable react/prop-types rule (d445345)
  • eslint-config-typescript: turn off @typescript-eslint/no-unused-vars (4845031)

BREAKING CHANGES

  • drop support for NodeJS v10.x, which reaches EOL on April 30, 2021.
  • deps: introduces new lint rules for jest that might break existing tests.

9.0.2 (2021-02-26)

Bug Fixes

9.0.1 (2021-02-21)

Bug Fixes

9.0.0 (2020-10-26)

Bug Fixes

Features

  • @spotify/best-practices/no-discouraged-words: switch to warn (f1aed8c)
  • use TypeScript 4 (bbf1164), closes #487 #252

BREAKING CHANGES

  • must upgrade to TypeScript 4 as a consumer; new tsconfig takes advantage of incremental + noEmit

8.1.1 (2020-09-22)

Bug Fixes

  • update eslint-plugin to allow for @typescript-eslint/parser@4 (0363558)

8.1.0 (2020-09-08)

Features

  • eslint-spotify: added eslint-plugin package w/ best-practices/no-discouraged-words (ddbbadc)

8.0.4 (2020-08-26)

Bug Fixes

8.0.3 (2020-08-25)

Bug Fixes

8.0.2 (2020-07-15)

Bug Fixes

  • eslint-config-react: fix peer dependency on eslint-plugin-react-hooks (8591423)

8.0.1 (2020-07-02)

Bug Fixes

  • eslint-config-typescript: turn off naming-convention (ed5eec3)

8.0.0 (2020-06-23)

Features

  • commitlint: v9 (2709cb8)
  • eslint: v7 (55ebb7f)
  • eslint-plugin-jest: minor bump (e1fef3b)
  • jest: v26 (14c37a8)
  • jest-junit: v11 (1ef34c4)
  • semantic-release: minor bump (ded14f4)
  • typescript-eslint: upgrade to latest to support type export syntax (688324b)
  • typescript-eslint/eslint-plugin: v3.4.0 (195400a)

BREAKING CHANGES

  • commitlint: 'improvement' type will now be rejected by this config.
  • eslint: see release notes for eslint v7
  • jest-junit: see jest-junit 11 release notes
  • jest: See jest 26 release notes
  • typescript-eslint: The camelcase rule was deprecated in typescript-eslint. I've tried to replace it with an equivalent naming-convention rule config. I question if we should have this at all.

7.0.2 (2020-05-27)

Bug Fixes

  • web-scripts: positional args were being stripped out (bae75b4)

7.0.1 (2020-05-15)

Bug Fixes

  • web-scripts: unknown command options were parsed twice (d30364b), closes #341

7.0.0 (2020-04-28)

BREAKING CHANGES

  • running web-scripts without arguments exits code 1 now instead of exiting 0
  • prettier 2.0 may introduce breaking changes
  • prettier 2.0 may introduce breaking changes

  • improvement(web-scripts): make stylecheck and typecheck default for lint

the lint script will now default typechecking and stylechecking to true by default. You may shut these off with --no-typecheck and --no-stylecheck.

  • Users who have projects incompatible with TypeScript checks or with projects that do not user prettier will now fail yarn lint.

6.2.0 (2020-04-04)

Features

  • web-scripts: allow custom lint-staged (#276) (49324dc)

6.1.1 (2020-04-03)

Bug Fixes

  • pin ts-jest to 25.2 (48e4cd5)
  • web-scripts: pin ts-jest version to 25.2 (01c9d86)

6.1.0 (2020-03-12)

Features

  • eslint-config-base: add rule for diabling unsafe finally blocks (#230) (5869bf9)

6.0.2 (2020-02-06)

Bug Fixes

  • create-web-scripts-library: format package.json (#194) (2d4b072)

6.0.1 (2020-02-06)

Bug Fixes

  • bump dependencies; fix create-web-scripts-library (ecdd47f)

6.0.0 (2020-01-29)

Build System

  • bump node in engines to 10.18.0 (08ea936)

Features

  • web-scripts: fix lint-staged usage for latest version (5215e25)

BREAKING CHANGES

  • increasing Node version in engines declaration
  • web-scripts: * the --no-fix option has been removed from web-scripts precommit
  • a --no-typecheck was added to web-scripts precommit because the typecheck had to be removed from lint-staged, and so it is no longer aware of which files changed.

5.3.0 (2020-01-29)

Features

  • eslint-config: add eslint-plugin-jest to config (4ac3051)

5.2.1 (2020-01-23)

Bug Fixes

  • web-scripts: get format working, add test (5bcf926)

5.2.0 (2020-01-22)

Features

  • index.js: Add react/jsx-curly-brace-presence rule (fbef1ae)

5.1.0 (2020-01-22)

Features

  • web-scripts: rename postinstall to audit (169f3c1), closes #131

5.0.2 (2020-01-21)

Bug Fixes

  • eslint-config-base: allow triple slashes (8ee981d), closes #117

5.0.1 (2020-01-07)

Bug Fixes

  • create-web-scripts-library: bump template submodule (e4280f4)

5.0.0 (2020-01-06)

Features

  • tsconfig: expose a single tsconfig (5048d6a), closes #21
  • web-scripts: enable declarationMaps on types by default (835793e), closes #17

BREAKING CHANGES

  • tsconfig: deleted a number of exports from tsconfig

4.0.2 (2020-01-03)

Bug Fixes

  • fix commander usage of args for positional args (1a1eb5a)

4.0.1 (2020-01-03)

Bug Fixes

  • use commander v4; re-enable lib checks in TS (e41d9de), closes #95

4.0.0 (2020-01-03)

chore

  • bump engine to >=10.13.0 (9527453)

Features

  • eslint 6 updates (d5444b6)
  • web-scripts: Upgrade to ESLint ^6.8.0 (d0c37e9)

BREAKING CHANGES

  • Minimum Node version has been increased
  • web-scripts: Users of web-scripts that rely on ESLint 5 will see unexpected linting errors.

3.3.1 (2020-01-03)

Bug Fixes

  • create-web-scripts-library: bump template (c7516fa)

3.3.0 (2020-01-03)

Features

3.2.0 (2020-01-02)

Features

  • postinstall: move preinstall to postinstall; make CI-safe (97aa021)
  • web-scripts: web-scripts preinstall (#73) (f043658)
  • web-scripts preinstall: Add test coverage and use enum options (aaed187), closes #73

3.1.0 (2020-01-02)

Bug Fixes

  • stylecheck should use implicit config (9c9a88c)

Features

  • web-scripts lint: Adds optional --stylecheck to lint command (0c3b687)

3.0.1 (2019-10-24)

Bug Fixes

  • eslint-config-react: Add static-variables to react/sort-comp (f0526c0)

3.0.0 (2019-10-10)

Bug Fixes

  • eslint-config: Update typescript-eslint packages to ^2.2.0 (bda6c5f)

BREAKING CHANGES

  • eslint-config: Major version bump

2.1.0 (2019-10-10)

Features

  • use package attributes to determine lint preset (f6151ed), closes #56

2.0.1 (2019-09-27)

Bug Fixes

  • eslint-config-typescript: add no-useless-constructor override (72c6651)

2.0.0 (2019-09-23)

Features

  • eslint-config-base: Add rule for disallowing useless constructors (beab7ec)
  • web-scripts: add format script; use implicit prettier config (e7a15b1)
  • web-scripts: use Jest config in project (a6284a6), closes #39
  • web-scripts: use project ESLint configs (233ed23), closes #39

BREAKING CHANGES

  • web-scripts: users who have Jest configs but do not pass them will begin having that config applied.
  • web-scripts: projects which have ESLint files but do not pass them to web-scripts will start having them automatically applied
  • eslint-config-base: Adding a lint rule which doesn't have a fix, which means that upgrading could break builds due to the new rule.

1.4.0 (2019-09-20)

Features

  • eslint-config: add prettier/react (bfea01a)

1.3.0 (2019-08-30)

Features

  • web-scripts: add checkstyle to lint (0822ae2)

1.2.1 (2019-08-30)

Bug Fixes

  • web-scripts: ignore TypeScript declaration files from coverage (8bcfc7f), closes #45

1.2.0 (2019-07-29)

Features

  • eslint-config: initialize library; use in web-scripts (d209a3f), closes #40

1.1.4 (2019-07-17)

Bug Fixes

  • Add repostiory field to package.json files (fccd2db)
  • deps: fix vulnerabilities (25c7b81)
  • web-scripts: allow all test options to be configured (5750c57), closes #19

1.1.3 (2019-07-02)

Bug Fixes

  • create-web-scripts-library: move web-scripts to devDependency (868354d)

1.1.2 (2019-07-01)

Bug Fixes

  • create-web-scripts-library: add prepublish to release (0323798)

1.1.1 (2019-07-01)

Bug Fixes

  • create-web-scripts-library: make sure that log output is shown (9bff988)

1.1.0 (2019-07-01)

Bug Fixes

  • support ESLint 6 in our configs (59341e3)
  • Updates engines field to node >=10 (b3b4f58)

Features

  • create-web-scripts-library: implement cli and script (ce381f3)

1.0.2 (2019-06-26)

Bug Fixes

  • update dependencies for peerDependency warnings (eceff7c)

1.0.1 (2019-06-24)

Bug Fixes

  • web-scripts: drop the fix command (eb0d61d)