npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

tf-dependency-analyzer

v0.1.3

Published

Analyze a terraform directory and get a list of terraform/providers/and modules.

Readme

TF Dependency Analyzer

Allows for discovery of all provider, modules, and the terraform version from a Terraform directory.

Usage

Install

npm install tf-dependency-analyzer

Example

import * as tda from 'tf-dependency-analyzer';

// Find all terraform files in the directory.
const dir = path.join('__tests__', 'fixtures', 'empty');
const files = await tda.findTerraformFiles(dir);

const handlers: FileHandler[] = [];
for (const file of files) {
    const handler = new FileHandler(file, gitHubPAT, gitHubEnterprisePAT, true, true, true, undefined);
    await handler.populate();
    handlers.push(handler);
}

FileHandler class

The FileHandler class is responsible for handling Terraform source files. It provides methods for parsing the file contents and creating instances of Terraform, Module, and Provider classes.

Properties

  • file
    • The path to the Terraform source file.
  • terraformInstances
    • An array of Terraform instances.
  • providerInstances
    • An array of Provider instances.
  • moduleInstances
    • An array of Module instances.
  • analyzeTerraform
    • A boolean indicating whether to analyze Terraform instances.
  • analyzeProviders
    • A boolean indicating whether to analyze provider instances.
  • analyzeModules
    • A boolean indicating whether to analyze module instances.
  • providerVersionMap
    • A Map object containing provider names and their corresponding URLs.

Methods

  • getFileContents(): string
    • Gets the file contents.
  • populate()
    • Populates the terraformInstances, providerInstances, and moduleInstances arrays.
  • getTerraformInstances()
    • Parses the file contents and creates a Terraform instance if the file contains Terraform initialization code.
  • getModuleInstances()
    • Parses the file contents and creates Module instances if the file contains modules.
  • getProviderInstances()
    • Parses the file contents and creates Provider instances if the file contains providers.

Terraform class

The Terraform class represents a Terraform instance.

Properties

  • version
    • The version of Terraform.
  • sourceFile
    • The path to the Terraform source file.
  • needsUpdate
    • Indicates whether the Terraform source file needs to be updated.

Methods

  • isVersionGtRefVersion(refVersion: string): boolean
    • Checks if the current version of Terraform is greater than or equal to the reference version.

Provider class

The Provider class represents a Terraform provider.

Properties

  • name
    • The name of the provider.
  • latestVersion
    • The latestVersion of the provider.
  • refVersion
    • The reference version of the provider in the code.
  • sourceFile
    • The path to the Terraform source file.
  • needsUpdate
    • Indicates whether the Terraform source file needs to be updated.

Methods

  • isVersionGtRefVersion(refVersion: string): boolean
    • Checks if the latest version of the Terraform provider is greater than or equal to the reference version.

Module class

The Module class represents a Terraform module.

Properties

  • latestVersion
    • The latestVersion of the module.
  • refVersion
    • The reference version of the module in the code.
  • sourceFile
    • The path to the Terraform source file.
  • needsUpdate
    • Indicates whether the Terraform source file needs to be updated.
  • latestVersionUrl
    • The URL to the latest version of the module.

Methods

  • isVersionGtRefVersion(refVersion: string): boolean
    • Checks if the latest version of the Terraform module is greater than or equal to the reference version.

helpers.ts

The helpers.ts file contains helper functions and regular expressions.

Regular Expressions

  • versionRegex
    • Regular expression for matching a semantic version number
  • terraformRegex
    • Regular expression for matching a required Terraform version in a .tf file
  • requiredProvidersRegex
    • Regular expression for matching required providers in a .tf file
  • providerRegex
    • Regular expression for matching a provider block in a .tf file
  • providerVersionRegex
    • Regular expression for matching a provider version in a .tf file
  • providerNameRegex
    • Regular expression for matching a provider name in a .tf file
  • providerSourceRegex
    • Regular expression for matching a provider source in a .tf file
  • modRegex
    • Regular expression for matching a module block in a .tf file
  • modSourceGitNoRef
    • Regular expression for matching a Git source URL without a ref in a module block in a .tf file
  • modSourceGitRef
    • Regular expression for matching a Git source URL with a ref in a module block in a .tf file
  • modSourceHttpsNoRef
    • Regular expression for matching an HTTPS source URL without a ref in a module block in a .tf file
  • modSourceHttpsRef
    • Regular expression for matching an HTTPS source URL with a ref in a module block in a .tf file

Methods

  • findTerraformFiles(dir: string): Promise<string[]>
    • Recursively searches a directory for Terraform configuration files with the .tf extension.
  • isDirectory(path: string): Promise<boolean>
    • Checks if a path is a directory.
  • getCurrentTerraformVersion(): Promise<string>
    • Retrieves the latest version of Terraform from the HashiCorp Checkpoint API.
  • getLatestModuleVersionUrl(source: string, gitHubPAT: string, gitHubEnterprisePAT: string): {url: string; authHeader: string; refVersion: string}
    • Generates the URL to the latest version of the Terraform Module.
  • getLatestModuleVersion(url: string, authHeader: string): Promise<string>
    • Retrieves the latest version of the Terraform Module from the GitHub API.
  • getLatestProviderVersionUrl(name: string, sourceOwner: string | undefined): string
    • Generates the URL to the latest version of the Terraform Provider.
  • getLatestProviderVersion(url: string, gitHubPAT: string): Promise<string>
    • Retrieves the latest version of the Terraform Provider from the GitHub API.
  • isUrlValid(url: string): Promise<boolean>
    • Checks if a URL is valid.