@hyperfrontend/project-scope/tech/build

build

Build-tool detectors for the JavaScript/TypeScript build ecosystem.

Covers Webpack, Vite, Rollup, esbuild, Babel, SWC, and Parcel. Each tool exposes its <tool>Detector plus a <TOOL>_CONFIG_PATTERNS constant describing the config-file shapes it recognizes. detectBuildTools runs all detectors and returns the aggregate BuildToolDetection[]. Detectors are unopinionated about preferred build tooling — they return what they find and at what confidence; consumers decide what to do with the results.

API Reference

ƒ Functions

§function

babelDetector(projectPath: string, packageJson?: PackageJson): BuildToolDetection

Detect Babel in project.

Parameters

NameTypeDescription
§projectPath
string
Project directory path
§packageJson?
PackageJson
Optional pre-loaded package.json

Returns

BuildToolDetection
Detection result or null if not detected

Example

Detecting Babel compiler

const result = babelDetector('/path/to/project', {
  name: 'my-app',
  devDependencies: { '@babel/core': '^7.23.0', '@babel/preset-env': '^7.23.0' }
})
// => {
//   id: 'babel',
//   name: 'Babel',
//   version: '7.23.0',
//   confidence: 60,
//   detectedFrom: [
//     { type: 'package.json', field: 'dependencies.@babel/core' },
//     { type: 'package.json', field: 'dependencies (@babel packages)' }
//   ]
// }
§function

detectBuildTools(projectPath: string, packageJson?: PackageJson): BuildToolDetection[]

Detect all build tools in project.

Parameters

NameTypeDescription
§projectPath
string
Project directory path
§packageJson?
PackageJson
Optional pre-loaded package.json

Returns

BuildToolDetection[]
Array of detected build tools, sorted by confidence

Example

Detecting multiple build tools

const tools = detectBuildTools('/path/to/project', {
  name: 'my-app',
  devDependencies: {
    'vite': '^5.0.0',
    '@vitejs/plugin-react': '^4.0.0',
    '@babel/core': '^7.23.0'
  }
})
// => [
//   { id: 'vite', name: 'Vite', version: '5.0.0', confidence: 70, ... },
//   { id: 'babel', name: 'Babel', version: '7.23.0', confidence: 50, ... }
// ]
§function

esbuildDetector(projectPath: string, packageJson?: PackageJson): BuildToolDetection

Detect esbuild in project.

Parameters

NameTypeDescription
§projectPath
string
Project directory path
§packageJson?
PackageJson
Optional pre-loaded package.json

Returns

BuildToolDetection
Detection result or null if not detected

Example

Detecting esbuild bundler

const result = esbuildDetector('/path/to/project', {
  name: 'my-lib',
  devDependencies: { 'esbuild': '^0.19.0' },
  scripts: { 'build': 'esbuild src/index.ts --bundle --outfile=dist/index.js' }
})
// => {
//   id: 'esbuild',
//   name: 'esbuild',
//   version: '0.19.0',
//   confidence: 80,
//   detectedFrom: [
//     { type: 'package.json', field: 'dependencies.esbuild' },
//     { type: 'package.json', field: 'scripts.build' }
//   ]
// }
§function

parcelDetector(projectPath: string, packageJson?: PackageJson): BuildToolDetection

Detect Parcel in project.

Parameters

NameTypeDescription
§projectPath
string
Project directory path
§packageJson?
PackageJson
Optional pre-loaded package.json

Returns

BuildToolDetection
Detection result or null if not detected

Example

Detecting Parcel bundler

const result = parcelDetector('/path/to/project', {
  name: 'my-app',
  devDependencies: { 'parcel': '^2.10.0' },
  scripts: { 'dev': 'parcel src/index.html', 'build': 'parcel build src/index.html' }
})
// => {
//   id: 'parcel',
//   name: 'Parcel',
//   version: '2.10.0',
//   confidence: 80,
//   detectedFrom: [
//     { type: 'package.json', field: 'dependencies.parcel' },
//     { type: 'package.json', field: 'scripts.dev' },
//     { type: 'package.json', field: 'scripts.build' }
//   ]
// }
§function

rollupDetector(projectPath: string, packageJson?: PackageJson): BuildToolDetection

Detect Rollup in project.

Parameters

NameTypeDescription
§projectPath
string
Project directory path
§packageJson?
PackageJson
Optional pre-loaded package.json

Returns

BuildToolDetection
Detection result or null if not detected

Example

Detecting Rollup bundler

const result = rollupDetector('/path/to/project', {
  name: 'my-lib',
  devDependencies: {
    'rollup': '^4.0.0',
    '@rollup/plugin-node-resolve': '^15.0.0',
    '@rollup/plugin-commonjs': '^25.0.0'
  }
})
// => {
//   id: 'rollup',
//   name: 'Rollup',
//   version: '4.0.0',
//   confidence: 65,
//   detectedFrom: [
//     { type: 'package.json', field: 'dependencies.rollup' },
//     { type: 'package.json', field: 'dependencies (rollup plugins)' }
//   ]
// }
§function

swcDetector(projectPath: string, packageJson?: PackageJson): BuildToolDetection

Detect SWC in project.

Parameters

NameTypeDescription
§projectPath
string
Project directory path
§packageJson?
PackageJson
Optional pre-loaded package.json

Returns

BuildToolDetection
Detection result or null if not detected

Example

Detecting SWC compiler

const result = swcDetector('/path/to/project', {
  name: 'my-app',
  devDependencies: { '@swc/core': '^1.3.0', '@swc/cli': '^0.1.0' }
})
// => {
//   id: 'swc',
//   name: 'SWC',
//   version: '1.3.0',
//   confidence: 70,
//   detectedFrom: [
//     { type: 'package.json', field: 'dependencies.@swc/core' },
//     { type: 'package.json', field: 'dependencies.@swc/cli' }
//   ]
// }
§function

viteDetector(projectPath: string, packageJson?: PackageJson): BuildToolDetection

Detect Vite in project.

Parameters

NameTypeDescription
§projectPath
string
Project directory path
§packageJson?
PackageJson
Optional pre-loaded package.json

Returns

BuildToolDetection
Detection result or null if not detected

Example

Detecting Vite build tool

const result = viteDetector('/path/to/project', {
  name: 'my-app',
  devDependencies: {
    'vite': '^5.0.0',
    '@vitejs/plugin-react': '^4.0.0',
    'vitest': '^1.0.0'
  }
})
// => {
//   id: 'vite',
//   name: 'Vite',
//   version: '5.0.0',
//   confidence: 80,
//   detectedFrom: [
//     { type: 'package.json', field: 'dependencies.vite' },
//     { type: 'package.json', field: 'dependencies.vitest' },
//     { type: 'package.json', field: 'dependencies (vite plugins)' }
//   ]
// }
§function

webpackDetector(projectPath: string, packageJson?: PackageJson): BuildToolDetection

Detect Webpack in project.

Parameters

NameTypeDescription
§projectPath
string
Project directory path
§packageJson?
PackageJson
Optional pre-loaded package.json

Returns

BuildToolDetection
Detection result or null if not detected

Example

Detecting Webpack bundler

const result = webpackDetector('/path/to/project', {
  name: 'my-app',
  devDependencies: { 'webpack': '^5.89.0', 'webpack-cli': '^5.1.0' },
  scripts: { 'build': 'webpack --mode production' }
})
// => {
//   id: 'webpack',
//   name: 'Webpack',
//   version: '5.89.0',
//   confidence: 65,
//   detectedFrom: [
//     { type: 'package.json', field: 'dependencies.webpack' },
//     { type: 'package.json', field: 'dependencies.webpack-cli' },
//     { type: 'package.json', field: 'scripts.build' }
//   ]
// }

Interfaces

§interface

BuildToolDetection

Build tool detection result.

Properties

§confidence:number
Detection confidence (0-100)
§configPath?:string
Config file path
§detectedFrom:DetectionSource[]
Detection sources
§id:string
Tool identifier
§name:string
Human-readable name
§version?:string
Detected version
§interface

BuildToolDetector

Build tool detector interface.

Properties

§id:string
Tool identifier
§name:string
Human-readable name

Variables

§type

BABEL_CONFIG_PATTERNS

Config patterns for Babel
§type

buildToolDetectors

All build tool detectors
§type

PARCEL_CONFIG_PATTERNS

Config patterns for Parcel
§type

ROLLUP_CONFIG_PATTERNS

Config patterns for Rollup
§type

SWC_CONFIG_PATTERNS

Config patterns for SWC
§type

VITE_CONFIG_PATTERNS

Config patterns for Vite
§type

WEBPACK_CONFIG_PATTERNS

Config patterns for Webpack