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
tsfunction containsPackageJson(dir: string)
Parameters
| Name | Type |
|---|---|
dir | string |
Diagram
mermaidgraph LR A[Directory path] --> B[containsPackageJson] B --> C{package.json exists?} C -->|Yes| D[Return true] C -->|No| E[Return false]
Usage
tsimport { 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.jsonitself; the helper performs the filename check internally. - Use this helper before running package-specific Gulp tasks or reading package metadata.
- Treat a
falseresult 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?