Skip to content

containsPackageJson

reference
1 min readUpdated

Kind: Function

Source: tools/gulp/util/task-helpers.ts

Checks if the directory contains a package.json file

containsPackageJson checks whether a specified directory contains a package.json file. It is used by Gulp task helpers to identify Node.js package directories before applying package-specific build, packaging, or dependency-processing logic.

Signature

ts
function containsPackageJson(dir: string)

Parameters

NameType
dirstring

Diagram

mermaid
graph LR
  A[Directory path] --> B[containsPackageJson]
  B --> C{package.json exists?}
  C -->|Yes| D[Return true]
  C -->|No| E[Return false]

Usage

ts
import { containsPackageJson } from './tools/gulp/util/task-helpers';

const packageDirectory = './extensions/my-extension';

if (containsPackageJson(packageDirectory)) {
	console.log('This directory is a Node.js package.');
} else {
	console.log('No package.json found.');
}

AI Coding Instructions

  • Pass a directory path, not a path to package.json itself; the helper performs the filename check internally.
  • Use this helper before running package-specific Gulp tasks or reading package metadata.
  • Treat a false result as an expected condition for non-package directories rather than an error.
  • Keep filesystem existence checks centralized through this utility when working in Gulp task helpers.

Was this page helpful?

Download as PDF
containsPackageJson — NestJS head-to-head