or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

code-coverage.mdcode-formatting.mdcode-linting.mdfile-cleanup.mdindex.mdprocess-management.mdtest-execution.mdtypescript-compilation.md

index.mddocs/

0

# @loopback/build

1

2

@loopback/build is a comprehensive set of build tools and configurations specifically designed for LoopBack 4 and other TypeScript projects. It provides command-line utilities for TypeScript compilation, code linting, formatting, testing, and coverage, along with programmatic APIs for integration into build workflows.

3

4

## Package Information

5

6

- **Package Name**: @loopback/build

7

- **Package Type**: npm

8

- **Language**: TypeScript/JavaScript

9

- **Installation**: `npm install @loopback/build --save-dev`

10

11

## Core Imports

12

13

```typescript

14

import {

15

tsc,

16

prettier,

17

mocha,

18

nyc,

19

clean,

20

runCLI,

21

runShell,

22

mergeMochaConfigs,

23

typeScriptPath

24

} from "@loopback/build";

25

```

26

27

For CommonJS:

28

29

```javascript

30

const {

31

tsc,

32

prettier,

33

mocha,

34

nyc,

35

clean,

36

runCLI,

37

runShell,

38

mergeMochaConfigs,

39

typeScriptPath

40

} = require("@loopback/build");

41

```

42

43

## Basic Usage

44

45

```json

46

{

47

"scripts": {

48

"build": "lb-tsc",

49

"build:watch": "lb-tsc --watch",

50

"clean": "lb-clean",

51

"lint": "npm run prettier:check && npm run eslint",

52

"lint:fix": "npm run prettier:fix && npm run eslint:fix",

53

"prettier:cli": "lb-prettier \"**/*.ts\" \"**/*.js\"",

54

"prettier:check": "npm run prettier:cli -- -l",

55

"prettier:fix": "npm run prettier:cli -- --write",

56

"eslint": "lb-eslint --report-unused-disable-directives .",

57

"eslint:fix": "npm run eslint -- --fix",

58

"pretest": "npm run clean && npm run build",

59

"test": "lb-mocha \"dist/__tests__\"",

60

"posttest": "npm run lint"

61

}

62

}

63

```

64

65

## Architecture

66

67

@loopback/build is built around several key components:

68

69

- **CLI Tools**: Command-line executables (`lb-tsc`, `lb-eslint`, etc.) that wrap popular development tools

70

- **Programmatic API**: Node.js functions for programmatic access to build operations

71

- **Utility Functions**: Helper functions for CLI resolution, configuration loading, and process management

72

- **Default Configurations**: Pre-configured settings for TypeScript, ESLint, Prettier, Mocha, and NYC

73

- **Console Log Detection**: Advanced Mocha integration that detects and fails on unexpected console output

74

75

## Capabilities

76

77

### TypeScript Compilation

78

79

TypeScript compiler wrapper with support for ttypescript plugins, resource copying, and automatic configuration generation.

80

81

```typescript { .api }

82

function tsc(argv: string[], options?: RunOptions): ChildProcess | string;

83

```

84

85

[TypeScript Compilation](./typescript-compilation.md)

86

87

### Code Linting

88

89

ESLint integration with automatic configuration discovery and LoopBack-specific rules through the `lb-eslint` CLI command.

90

91

[Code Linting](./code-linting.md)

92

93

### Code Formatting

94

95

Prettier integration with configuration discovery and file pattern support.

96

97

```typescript { .api }

98

function prettier(argv: string[], options?: RunOptions): ChildProcess | string;

99

```

100

101

[Code Formatting](./code-formatting.md)

102

103

### Test Execution

104

105

Mocha test runner with console log detection, configuration merging, and enhanced error reporting.

106

107

```typescript { .api }

108

function mocha(argv: string[], options?: RunOptions): ChildProcess | string;

109

```

110

111

[Test Execution](./test-execution.md)

112

113

### Code Coverage

114

115

NYC code coverage wrapper for generating test coverage reports.

116

117

```typescript { .api }

118

function nyc(argv: string[], options?: RunOptions): ChildProcess | string;

119

```

120

121

[Code Coverage](./code-coverage.md)

122

123

### File Cleanup

124

125

Utility for safely removing build artifacts and temporary files.

126

127

```typescript { .api }

128

function clean(argv: string[], options?: RunOptions): string;

129

```

130

131

[File Cleanup](./file-cleanup.md)

132

133

### Process Management

134

135

Core utilities for running CLI commands and managing child processes.

136

137

```typescript { .api }

138

function runCLI(

139

cli: string,

140

args: string[],

141

options?: RunCLIOptions

142

): ChildProcess | string;

143

144

function runShell(

145

command: string,

146

args: string[],

147

options?: RunShellOptions

148

): ChildProcess | string;

149

```

150

151

[Process Management](./process-management.md)

152

153

## Types

154

155

```typescript { .api }

156

import { ChildProcess } from "child_process";

157

158

interface RunOptions {

159

dryRun?: boolean;

160

cwd?: string;

161

resolveFromProjectFirst?: boolean;

162

}

163

164

interface RunCLIOptions extends RunOptions {

165

nodeArgs?: string[];

166

}

167

168

interface RunShellOptions extends RunOptions {

169

stdio?: string;

170

env?: Record<string, string>;

171

shell?: boolean;

172

}

173

174

interface MochaConfig {

175

timeout?: number;

176

require?: string | string[];

177

[key: string]: any;

178

}

179

```