包详细信息

@spotify/web-scripts-utils

spotify3.5kApache-2.015.0.0

Private package which contains re-used utils within web-scripts projects

自述文件

@spotify/web-scripts

Actions Status Version

A monorepo of base configs and CLI wrappers used to speed up development @ Spotify.

Want to use it? Check out the CLI documentation to get started!

About this project

web-scripts CLI

@spotify/web-scripts is a CLI that combines shared configuration for building, linting, testing, formatting, and releasing libraries for Node and the browser. It is opinionated, but allows configuration to avoid lock-in. You can also pick and choose which scripts you use. It is inspired by other tooling bundles like react-scripts and kcd-scripts.

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

It is intended to be used within a project as a series of npm scripts.

{
  "devDependencies": {
    "@spotify/web-scripts": "^12.0.0",
    "husky": "^7.0.0"
  },
  "scripts": {
    "build": "web-scripts build",
    "test": "web-scripts test",
    "format": "web-scripts format",
    "lint": "web-scripts lint",
    "commit": "web-scripts commit",
    "release": "web-scripts release",
    "prepare": "husky install && web-scripts audit"
  }
}

Additionally, you'll need to run the following two commands to create the commit and pre-commit hooks:

npx husky set .husky/pre-commit 'yarn web-scripts precommit --no-tests --no-typecheck'

npx husky set .husky/commit-msg 'yarn web-scripts commitmsg --edit="$1"' && \
  sed 's/edit=""/edit="$1"/g' .husky/commit-msg | tee .husky/commit-msg

NOTE: the second command uses sed to hack around this bug in husky that removes $1.

You'll want to add and commit the .husky directory.

View the full CLI documentation for more details on how to get started.

Create a new library

To quickly get started with a new @spotify/web-scripts library, you can build one with our library scaffolding tool:

yarn create @spotify/web-scripts-library my-library-name

Spotify shared configurations

The other projects in this repo are shared configurations for common tools we use for building, linting, and formatting our code. They can be installed separately and used by anyone should they opt to follow our standards. We have a specialized point-of-view on what belongs in our configs. They are all used by the web-scripts CLI by default.

Methodology

We have a few guiding principles for this project.

  1. Style rules should be auto-fixable and if you can, errors should be linted ahead of runtime.
  2. Avoid enforcing code style in static analysis; search for bugs with static analysis, and let auto-formatting deal with code style.
  3. Push "fast" checks as far left as you can. Optimize for code editors/IDEs fixing issues and enforcing things; write Git hooks that catch things as a failsafe; and use static analysis in CI to prevent bad things from getting into master.
  4. web-scripts is meant to be configurable. We want to avoid the "eject" problem. You should be able to easily take the base configs and extend them in your project.
  5. Fewer top-level scripts that encapsulate all behavior for that lifecycle are preferable to lots of smaller, composable scripts. For example, we do yarn lint which includes Prettier, ESLint, and TypeScript checks. We could have done yarn lint, yarn typecheck, and yarn stylecheck. That would have meant pushing "new" linting to all repos on new versions would be much harder, as we would need to communicate that you need to update your invocation in package.json.

Related projects we use

  • TypeScript: a superset of JavaScript which we think helps make code readable and less bug-prone.
  • ESLint: used for static code analysis with some auto-fixing.
  • Prettier: use to format code pre-commit and automatically in your editor.
  • Jest: our preferred JavaScript test framework.
  • husky: allows us to hook into git events in a convenient way.
  • lint-staged: allows us to write pre-commit hooks which target specific paths and run a series of commands.

Contributing

This project adheres to the Open Code of Conduct. By participating, you are expected to honor this code.

This project is an opinionated approach to static analysis, code formatting, testing, and publishing. It's the result of consensus between many web engineers inside Spotify, and the default configs will mostly be written by Spotify employees. We may reject PRs to the ESLint config if we don't agree that the rule makes sense as part of our baseline, for example. Use it if it aligns with your needs!

Running Tests locally

If you get an error like Cannot find module '../cjs' when running yarn test, you need to bootstrap web-scripts.

$ yarn lerna run bootstrap

Releasing

The repo releases automatically on merge to master using semantic-release and lerna in a Github Action, if the commit message has the right semantic-release format

更新日志

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)