11.0.1 • Published 21 days ago

@loopback/build v11.0.1

Weekly downloads
23,894
License
MIT
Repository
github
Last release
21 days ago

@loopback/build

This module contains a set of common scripts and default configurations to build LoopBack 4 or other TypeScript modules, including:

  • lb-tsc: Use tsc to compile typescript files
  • lb-eslint: Run eslint
  • lb-prettier: Run prettier
  • lb-mocha: Run mocha to execute test cases
  • lb-nyc: Run nyc

These scripts first try to locate the CLI from target project dependencies and fall back to bundled ones in @loopback/build.

Basic use

To use @loopback/build for your package:

  1. Run the following command to add @loopback/build as a dev dependency.

npm i @loopback/build --save-dev

  1. Configure your project package.json as follows:
"scripts": {
    "build": "lb-tsc",
    "build:watch": "lb-tsc --watch",
    "clean": "lb-clean",
    "lint": "npm run prettier:check && npm run eslint",
    "lint:fix": "npm run prettier:fix && npm run eslint:fix",
    "prettier:cli": "lb-prettier \"**/*.ts\" \"**/*.js\"",
    "prettier:check": "npm run prettier:cli -- -l",
    "prettier:fix": "npm run prettier:cli -- --write",
    "eslint": "lb-eslint --report-unused-disable-directives .",
    "eslint:fix": "npm run eslint -- --fix",
    "pretest": "npm run clean && npm run build",
    "test": "lb-mocha \"dist/__tests__\"",
    "posttest": "npm run lint",
    "start": "npm run build && node .",
    "prepublishOnly": "npm run test"
  },

Please remember to replace your-module-name with the name of your module.

Now you run the scripts, such as:

  • npm run build - Compile TypeScript files and copy resources (non .ts files) to outDir
  • npm test - Run all mocha tests
  • npm run lint - Run eslint and prettier on source files
  1. Override default configurations in your project
  • lb-tsc

    By default, lb-tsc searches your project's root directory for tsconfig.build.json then tsconfig.json. If neither of them exists, a tsconfig.json will be created to extend from @loopback/build/config/tsconfig.common.json.

    To customize the configuration:

    • Create tsconfig.build.json or tsconfig.json in your project's root directory

      {
        "$schema": "http://json.schemastore.org/tsconfig",
        "extends": "@loopback/build/config/tsconfig.common.json",
        "compilerOptions": {
          "outDir": "dist",
          "rootDir": "src"
        },
        "include": ["src"]
      }
    • Set options explicitly for the script

      lb-tsc -p tsconfig.json --target es2017 --outDir dist

      For more information, see https://www.typescriptlang.org/docs/handbook/compiler-options.html.

    • The following un-official compiler options are available:

      OptionDescription
      --copy-resourcesCopy all non-typescript files from src and test to outDir, preserving their relative paths.
    • Using ttypescript

      Stability: ⚠️Experimental⚠️

      If you would like to use ttypescript and its available plugins, you can substitute lb-tsc with lb-ttsc, or pass the option lb-tsc --use-ttypescript. If ttypescript is not installed, the default TypeScript compiler tsc will be used instead.

  1. Run builds
npm run build
  1. Run code coverage reports
  • lb-nyc

    lb-nyc is a simple wrapper for nyc.

    To customize the configuration:

    • Create .nycrc in your project's root directory

      {
        "include": ["dist"],
        "exclude": ["dist/__tests__/"],
        "extension": [".js", ".ts"],
        "reporter": ["text", "html"],
        "exclude-after-remap": false
      }
    • Update your package.json scripts:

      "precoverage": "npm test",
      "coverage": "open coverage/index.html",
      "coverage:ci": "lb-nyc report --reporter=text-lcov | coveralls",
      "test": "lb-nyc npm run mocha",
      "test:ci": "lb-nyc npm run mocha"

      coverage:ci sets up integration with Coveralls.

A note on console logs printed by tests

We consider (console) logging from tests as a bad practice, because such logs usually clutter the test output and make it difficult to distinguish legitimate error messages from the noise.

By default, lb-mocha detects when the tests and/or the application tested have printed console logs and fails the test run with the following message:

=== ATTENTION - INVALID USAGE OF CONSOLE LOGS DETECTED ===

If you need more information about behavior in the test, then the first choice should be to use a better or more descriptive error assertion. If that's not possible, then use debug statements to print additional information when explicitly requested.

A typical situation is that a test is sending an HTTP request and the server responds with an error code as expected. However, because the server is configured to log failed requests, it will print a log also for requests where the failure was expected and intentional. The solution is to configure your REST server to suppress error messages for that specific error code only. Our @loopback/testlab module is providing a helper createUnexpectedHttpErrorLogger that makes this task super easy.

Alternatively, it's also possible to disable detection of console logs by calling lb-mocha with --allow-console-logs argument.

Contributions

Tests

run npm test from the root folder.

Contributors

See all contributors.

License

MIT

11.0.1

21 days ago

11.0.0

2 months ago

10.1.5

4 months ago

10.1.4

5 months ago

10.1.1

10 months ago

10.1.2

9 months ago

10.1.3

8 months ago

10.1.0

10 months ago

10.0.0

12 months ago

9.0.9

1 year ago

9.0.10

1 year ago

9.0.8

1 year ago

9.0.7

1 year ago

9.0.6

1 year ago

9.0.5

1 year ago

9.0.4

2 years ago

9.0.3

2 years ago

9.0.2

2 years ago

9.0.1

2 years ago

9.0.0

2 years ago

8.1.2

2 years ago

8.1.1

2 years ago

8.1.0

2 years ago

8.0.1

2 years ago

8.0.0

2 years ago

7.0.2

3 years ago

7.0.1

3 years ago

7.0.0

3 years ago

6.4.1

3 years ago

6.4.0

3 years ago

6.3.1

3 years ago

6.3.0

3 years ago

6.2.9

3 years ago

6.2.8

3 years ago

6.2.7

3 years ago

6.2.6

3 years ago

6.2.5

4 years ago

6.2.4

4 years ago

6.2.3

4 years ago

6.2.2

4 years ago

6.2.1

4 years ago

6.2.0

4 years ago

6.1.1

4 years ago

6.1.0

4 years ago

6.0.0

4 years ago

5.4.3

4 years ago

5.4.2

4 years ago

5.4.1

4 years ago

5.4.0

4 years ago

5.3.1

4 years ago

5.3.0

4 years ago

5.2.0

4 years ago

5.1.0

4 years ago

5.0.1

4 years ago

5.0.0

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.1.1

4 years ago

3.1.0

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.1.0

4 years ago

2.0.16

4 years ago

2.0.15

5 years ago

2.0.14

5 years ago

2.0.13

5 years ago

2.0.12

5 years ago

2.0.11

5 years ago

2.0.10

5 years ago

2.0.9

5 years ago

2.0.8

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.7.1

5 years ago

1.7.0

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.5

5 years ago

1.5.4

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

6 years ago

0.8.0

6 years ago

0.7.6

6 years ago

0.7.5

6 years ago

0.7.4

6 years ago

0.7.3

6 years ago

0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.14

6 years ago

0.6.13

6 years ago

0.6.12

6 years ago

0.6.11

6 years ago

0.6.10

6 years ago

0.6.9

6 years ago

0.6.8

6 years ago

0.6.7

6 years ago

0.6.6

6 years ago

0.6.5

6 years ago

0.6.4

6 years ago

0.6.3

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

4.0.0-alpha.13

6 years ago

4.0.0-alpha.12

6 years ago

4.0.0-alpha.11

6 years ago

4.0.0-alpha.10

6 years ago

4.0.0-alpha.9

6 years ago

4.0.0-alpha.8

6 years ago

4.0.0-alpha.7

6 years ago

4.0.0-alpha.6

6 years ago

4.0.0-alpha.5

6 years ago

4.0.0-alpha.4

6 years ago

4.0.0-alpha.3

7 years ago

4.0.0-alpha.2

7 years ago

4.0.0-alpha.1

7 years ago