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

Package detail

egg-bin

eggjs88.9k6.13.0TypeScript support: included

egg developer tool

readme

egg-bin

NPM version build status Test coverage Known Vulnerabilities npm download Node.js Version

egg developer tool, extends @artus-cli/artus-cli.


Install

npm i egg-bin --save-dev

Usage

Add egg-bin to package.json scripts:

{
  "scripts": {
    "dev": "egg-bin dev",
    "test-local": "egg-bin test",
    "test": "npm run lint -- --fix && npm run test-local",
    "cov": "egg-bin cov",
    "lint": "eslint .",
    "ci": "npm run lint && npm run cov"
  }
}

Command

All the commands support these specific options:

  • --inspect
  • --inspect-brk
  • --typescript / --ts enable typescript support. Auto detect from package.json's pkg.egg.typescript, or pkg.dependencies.typescript/pkg.devDependencies.typescript.
  • --base / --baseDir application's root path, default to process.cwd().
  • --require will add to execArgv, support multiple. Also support read from package.json's pkg.egg.require
  • --dry-run / -d whether dry-run the test command, just show the command
egg-bin [command] --inspect
egg-bin [command] --inspect-brk
egg-bin [command] --typescript
egg-bin [command] --base /foo/bar

dev

Start dev cluster on local env, it will start a master, an agent and a worker.

egg-bin dev

dev options

  • --framework egg web framework root path.
  • --port server port. If not specified, the port is obtained in the following order: egg.js configuration config/config.*.js > process.env.EGG_BIN_DEFAULT_PORT > 7001 > other available ports.
  • --workers worker process number, default to 1 worker at local mode.
  • --sticky start a sticky cluster server, default to false.

debug/inspect on VSCode

Create .vscode/launch.json file:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Egg Debug",
      "runtimeExecutable": "npm",
      "runtimeArgs": [
        "run",
        "dev",
        "--",
        "--inspect-brk"
      ],
      "console": "integratedTerminal",
      "restart": true,
      "protocol": "auto",
      "port": 9229,
      "autoAttachChildProcesses": true
    },
    {
      "type": "node",
      "request": "launch",
      "name": "Egg Test",
      "runtimeExecutable": "npm",
      "runtimeArgs": [
        "run",
        "test-local",
        "--",
        "--inspect-brk"
      ],
      "protocol": "auto",
      "port": 9229,
      "autoAttachChildProcesses": true
    }
  ]
}

test

Using mocha to run test.

egg-bin test [...files] [options]
  • files is optional, default to test/**/*.test.ts
  • test/fixtures, test/node_modules is always exclude.

auto require test/.setup.ts

If test/.setup.ts file exists, it will be auto require as the first test file.

test
  ├── .setup.ts
  └── foo.test.ts

test options

You can pass any mocha argv.

  • --timeout milliseconds, default to 60000
  • --changed / -c only test changed test files(test files means files that match ${pwd}/test/**/*.test.(js|ts))
  • --parallel enable mocha parallel mode, default to false.
  • --auto-agent auto start agent in mocha master agent.
  • --jobs number of jobs to run in parallel, default to os.cpus().length - 1.
  • --mochawesome enable mochawesome reporter, default to true.

test environment

Environment is also support, will use it if options not provide.

You can set TESTS env to set the tests directory, it support glob grammar.

TESTS=test/a.test.ts egg-bin test

And the reporter can set by the TEST_REPORTER env, default is spec.

TEST_REPORTER=doc egg-bin test

The test timeout can set by TEST_TIMEOUT env, default is 60000 ms.

TEST_TIMEOUT=2000 egg-bin test

cov

Using mocha and [c8] to run code coverage, it support all test params above.

Coverage reporter will output text-summary, json and lcov.

cov options

You can pass any mocha argv.

  • -x add dir ignore coverage, support multiple argv
  • --prerequire prerequire files for coverage instrument, you can use this options if load files slowly when call mm.app or mm.cluster
  • --typescript / --ts enable typescript support. If true, will auto add .ts extension and ignore typings and d.ts.
  • --c8 c8 instruments passthrough. you can use this to overwrite egg-bin's default c8 instruments and add additional ones.
    • egg-bin have some default instruments passed to c8 like -r and --temp-directory
    • egg-bin cov --c8="-r teamcity -r text" --c8-report=true
  • also support all test params above.

cov environment

You can set COV_EXCLUDES env to add dir ignore coverage.

COV_EXCLUDES="app/plugins/c*,app/autocreate/**" egg-bin cov

Custom egg-bin for your team

See https://artus-cli.github.io

License

MIT

Contributors

Contributors

Made with contributors-img.

changelog

Changelog

6.13.0 (2024-12-11)

Features

6.12.0 (2024-12-10)

Features

6.11.0 (2024-12-08)

Features

6.10.0 (2024-06-11)

Features

  • [Snyk] Security upgrade c8 from 9.1.0 to 10.0.0 (#272) (2535a8e)

6.9.0 (2024-05-08)

Features

6.8.1 (2024-03-06)

Bug Fixes

6.8.0 (2024-02-01)

Features

  • supports retrieving the port from the configuration file (#251) (07e150f)

6.7.0 (2024-01-09)

Features

6.6.0 (2024-01-07)

Features

  • should run ets on pkg.egg.declarations = true (#248) (018801a)

6.5.2 (2023-09-16)

Bug Fixes

  • ignore ExperimentalWarning on esm module (#241) (6a2521a)

6.5.1 (2023-09-16)

Bug Fixes

6.5.0 (2023-09-15)

Features

6.4.2 (2023-08-05)

Bug Fixes

  • convert unhandled rejection to uncaught exception (#235) (1e25880)

6.4.1 (2023-06-03)

Bug Fixes

6.4.0 (2023-04-18)

Features

  • append cobertura to support diff line coverage (#227) (ddf732f)
  • output cobertura report by default (#228) (8818a3d)

6.3.0 (2023-04-06)

Features

6.1.2 (2023-02-17)

Bug Fixes

  • should support windows and Node.js 14 (#223) (8f1b709)

6.1.1 (2023-02-14)

Bug Fixes

6.1.0 (2023-02-14)

Features

6.0.0 (2023-02-12)

⚠ BREAKING CHANGES

  • drop Node.js 14 support and more deprecated features

Features

5.13.4 (2023-02-09)

Bug Fixes

5.13.3 (2023-02-06)

Bug Fixes

5.13.2 (2023-02-03)

Bug Fixes

  • should set ETS_FRAMEWORK to real framework package name (#214) (fb3eb6a)

5.13.1 (2023-01-30)

Bug Fixes

  • ignore ets when the current app don't has a framework dependencies (#213) (666a342)

5.13.0 (2023-01-18)

Features

  • use util.debug instead of debug module (#212) (33c95c2)

5.12.3 (2023-01-13)

Bug Fixes

  • require tscompiler on current process (#207) (3462835)

5.12.2 (2023-01-11)

Bug Fixes

5.12.1 (2023-01-10)

Bug Fixes

5.12.0 (2023-01-09)

Features

5.11.3 (2023-01-06)

Bug Fixes

5.11.2 (2023-01-05)

Bug Fixes

  • use node to run postinstall script (f17347b)

5.11.1 (2023-01-05)

Bug Fixes

  • should set ETS_CWD to INIT_CWD on postinstall (#202) (a57c1d4)

5.11.0 (2023-01-05)

Features

5.10.0 (2023-01-03)

Features

  • use mochawesome-with-mocha and enable mochawesome by default (#200) (efa6ef5)

5.9.0 (2022-12-18)

Features

  • auto require tsconfig-paths/register on typescript command (#199) (82e3e3e)

5.8.1 (2022-12-18)

Bug Fixes

5.8.0 (2022-12-18)

Features

  • [BREAKING CHANGE] drop espower support (#197) (1fc3624)

5.7.0 (2022-12-18)

Features

5.6.1 (2022-12-17)

Bug Fixes

  • revert mochawesome to false by default (#195) (9c48e10)

5.6.0 (2022-12-17)

Features

5.5.0 / 2022-11-19

features

5.4.1 / 2022-11-15

fixes

others

5.4.0 / 2022-11-11

features

5.3.3 / 2022-11-10

fixes

5.3.2 / 2022-11-09

fixes

5.3.1 / 2022-11-05

fixes

5.3.0 / 2022-11-04

features

5.2.0 / 2022-07-15

features

5.1.2 / 2022-07-05

fixes

5.1.1 / 2022-06-23

fixes

5.1.0 / 2022-06-04

others

5.0.0 / 2022-06-04

features

others

4.18.1 / 2022-02-18

fixes

4.18.0 / 2022-02-16

features

4.17.0 / 2022-01-21

others

4.16.4 / 2021-07-09

others

4.16.3 / 2021-07-08

fixes

others

4.16.2 / 2021-05-14

fixes

4.16.1 / 2021-04-25

fixes

4.16.0 / 2021-04-23

features

4.15.0 / 2020-07-03

features

4.14.1 / 2020-01-02

fixes

4.14.0 / 2019-10-12

features

fixes

others

4.13.2 / 2019-09-27

fixes

4.13.1 / 2019-04-28

others

4.13.0 / 2019-04-23

features

4.12.3 / 2019-04-09

fixes

others

4.12.2 / 2019-04-04

fixes

4.12.1 / 2019-03-26

fixes

4.12.0 / 2019-03-20

others

4.11.1 / 2019-03-06

fixes

4.11.0 / 2019-02-15

  • feat: intergration with egg-ts-helper (#123)

4.10.0 / 2019-01-04

features

* [[`904103f`](https://github.com/eggjs/egg-bin/commit/904103fe673e93bdf600f6eace4121cf4bf15d9b)] - feat: support read egg.require from package.json (#121) (吖猩 <<whxaxes@qq.com>>)

docs

* [[`0d553f6`](https://github.com/eggjs/egg-bin/commit/0d553f641155bc3ee9cc9d459a0ddff238c6c691)] - docs: test timeout is 6000ms (#115) (BiosSun <<biossun@gmail.com>>)

4.9.0 / 2018-09-19

features

fixes

4.8.5 / 2018-09-11

  • feat: remove correct-source-map.js (#109)

4.8.4 / 2018-09-06

  • fix: package.json to reduce vulnerabilities (#108)

4.8.3 / 2018-08-27

fixes

4.8.2 / 2018-08-23

features

4.8.1 / 2018-08-01

  • fix: fixed ts-node ignore files (#105)

4.8.0 / 2018-07-31

  • chore: update deps (#104)
  • feat(cov): add nyc instrument passthrough (#103)

4.7.1 / 2018-06-29

  • fix: should exit when no test files found (#100)

4.7.0 / 2018-04-18

  • feat: add ts env in command (#98)

4.6.3 / 2018-04-05

  • fix: should only read pkg if argv.typescript not pass (#97)

4.6.2 / 2018-04-02

fixes

4.6.1 / 2018-03-31

  • fix: remove ts extensions by default (#94)

4.6.0 / 2018-03-30

  • chore: don't need to log at vscode and webstorm (#93)
  • feat: support egg.typescript (#92)
  • feat: cov support typescript (#91)

4.5.0 / 2018-03-28

  • feat: support typescript (#89)
  • feat: set EGG_MASTER_CLOSE_TIMEOUT when run dev (#88)

4.4.1 / 2018-03-26

  • feat: revert egg-bin check (#90)

4.4.0 / 2018-02-24

  • feat: egg-bin check (#87)

4.3.7 / 2017-12-13

fixes

4.3.6 / 2017-11-30

  • deps: autod@3.0 (#85)
  • test: Node 8.7.0 has improved stack for promise (#84)

4.3.5 / 2017-10-10

fixes

others

4.3.4 / 2017-10-09

Upgrade mocha@4, see https://boneskull.com/mocha-v4-nears-release

fixes

4.3.3 / 2017-09-21

  • chore: dont print devtools link at vscode (#75)

4.3.2 / 2017-09-14

fixes

4.3.1 / 2017-09-13

features

fixes

others

4.3.0 / 2017-09-07

others

4.2.0 / 2017-08-30

  • feat: support $NODE_DEBUG_OPTION (#71)

4.1.0 / 2017-08-02

  • feat: add egg-bin autod --check command (#70)

4.0.5 / 2017-07-05

  • fix: only hotfix spawn-wrap on windows (#69)

4.0.4 / 2017-06-21

  • fix: remove temp excludes
  • feat(cov): add prerequire option (#53)

4.0.3 / 2017-06-21

  • fix: There is a case sensitive issue from spawn-wrap on Windows (#67)

4.0.2 / 2017-06-20

  • fix: should support multi exclude dirs (#66)

4.0.1 / 2017-06-20

  • fix: ignore frontend files and document files (#65)

4.0.0 / 2017-06-20

  • feat: use nyc instead of istanbul (#63)

3.7.0 / 2017-06-19

  • feat: cov support output json-summary (#64)

3.6.0 / 2017-06-14

  • feat: support cov command in win32 (#52)
  • test: skip assert error stack on node >= 7.0.0 (#61)
  • fix: clean more mocha error stack (#60)

3.5.0 / 2017-06-08

  • feat: simplify mocha error stack (#59)

3.4.2 / 2017-06-04

  • fix: use context.env instead of process.env (#58)

3.4.1 / 2017-06-01

  • fix: don't pass prerequire (#57)

3.4.0 / 2017-05-18

  • feat(cov): add prerequire option (#53)

3.3.2 / 2017-04-28

  • feat: change default timeout to 60000 (#50)

3.3.1 / 2017-04-25

  • fix: cov replaced warning at win (#49)

3.3.0 / 2017-04-17

  • feat: pass --check to pkgfiles (#48)

3.2.1 / 2017-04-01

  • fix: -x only support string (#47)

3.2.0 / 2017-03-29

  • feat: extractArgv refactor & extract debug port
  • feat: extractArgv support expose_debug_as

3.1.0 / 2017-03-21

  • feat: use unparseArgv from common-bin (#45)

3.0.1 / 2017-03-21

  • fix(cov): istanbul path env (#44)

3.0.0 / 2017-03-21

  • refactor: [BREAKING_CHANGE] use common-bin 2.x (#41)

2.4.0 / 2017-03-09

  • deps: upgrade istanbul to 1.1.0-alpha.1 (#43)

2.3.0 / 2017-03-08

  • fix: add missing deps (#42)
  • feat: update pkg.files that if file exists (#37)
  • refactor: use framework (#39)

2.2.3 / 2017-02-25

  • fix: support egg-bin dev --cluster and --baseDir (#36)

2.2.2 / 2017-02-25

  • fix: use co-mocha instead of thunk-mocha (#38)

2.2.1 / 2017-02-19

  • fix: support node4 (#35)

2.2.0 / 2017-02-15

  • feat: commands support specific execArgv(harmony) (#33)
  • docs: missing debug description for zh-cn (#34)

2.1.0 / 2017-02-14

  • feat: add sticky mode support (#32)

2.0.2 / 2017-01-24

  • fix: .setup.js should be the first test file (#30)

2.0.1 / 2017-01-17

  • fix: should support -p (#27)
  • docs: use V8 Inspector Integration for debug

2.0.0 / 2017-01-16

  • feat(debug): [BREAKING_CHANGE] remove iron-node (#26)

1.10.1 / 2017-01-16

  • fix: should pass customEgg to startCluster (#25)

1.10.0 / 2016-12-28

  • feat: auto require setup file (#24)

1.9.1 / 2016-12-16

  • fix: make sure dev command eggPath can be override (#23)

1.9.0 / 2016-12-16

  • feat: auto detect available port (#22)

1.8.1 / 2016-12-14

  • fix: add power-assert to deps (#21)

1.8.0 / 2016-12-14

  • feat: build-in intelli-espower-loader (#20)

1.7.0 / 2016-11-03

  • feat: try to use --inspect first (#19)

1.6.0 / 2016-10-28

  • feat: use test when run cov on Windows (#18)

1.5.3 / 2016-10-28

  • fix: wait more time for Window :cry: (#17)

1.5.2 / 2016-10-26

  • fix(cov): wait 1 second for Windows (#16)

1.5.1 / 2016-10-20

  • fix: link mocha bin from inner file (#15)
  • docs:add egg-bin dev options doc (#14)

1.5.0 / 2016-10-16

  • test: exports mocha bin (#13)

1.4.0 / 2016-09-29

  • feat(dev): pass debug args to execArgv (#12)

1.3.0 / 2016-08-19

  • feat: resolve istanbul path for coffee (#9)

1.2.1 / 2016-08-18

  • fix: can not find iron-node in subprocess (#8)

1.2.0 / 2016-08-04

  • feat: add COV_EXCLUDES for coverage excludes (#7)

1.1.1 / 2016-08-03

  • chore(deps): upgrade mocha@3 and glob@7 (#6)

1.1.0 / 2016-07-29

  • feat: support mocha custom require args (#5)
  • refactor: use common-bin (#4)

1.0.2 / 2016-07-12

  • refactor: rename DevCommand.js to dev_command.js (#3)
  • chore: add security check badge (#2)
  • refactor: use egg-utils (#1)

1.0.1 / 2016-06-20

  • fix: let sub class can override getFrameworkOrEggPath

1.0.0 / 2016-06-19

  • init version