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 🙏

© 2024 – Pkg Stats / Ryan Hefner

intermodular

v0.40.0

Published

Easy file operations between node.js modules and auto logging to help building zero-config boilerplates, postinstall and other scripts.

Downloads

33

Readme

See documentation at https://intermodular.ozum.net.

Intermodular

Easy file operations between node.js modules and auto logging to help building zero-config boilerplates, postinstall and other scripts.

Installation

npm install intermodular

Synopsis

import Intermodular from "intermodular";

const intermodular = await Intermodular.new();
const targetModule = intermodular.targetModule;

// Copy all files from `my-boilerplate/config/` to `my-project/`
await intermodular.copy("config", ".");

// Update project's `package.json`.
targetModule.package.set("description", `My awesome project of ${targetModule.name}`);

// Get some deep data from cosmiconfig compatible config file from `my-project/.my-boilerplaterc` or any cosmiconfig compatible way automatically.
const buildFlags = intermodular.config.get("build.flags");
targetModule.package.set("scripts.build": `tsc ${buildFlags}`);

// Read and update target eslint configuration.
const eslintConfig = await targetModule.read("eslint", { cosmiconfig: true });
eslintConfig.set("rules.lines-between-class-members", ["warn", "always", { exceptAfterSingleLine: true }]);

await targetModule.saveAll();

await targetModule.install("lodash");
await targetModule.execute("tsc", ["-b"]);

API

intermodular

Type aliases

CopyFilterFunction

Ƭ CopyFilterFunction: function

Defined in src/util/types.ts:22

Type for function to filter copied files.

Type declaration:

▸ (fullSourcePath: string, fullTargetPath: string, isSourceDirectory: boolean, isTargetDirectory: boolean, sourceContent?: string | DataFile, targetContent?: string | DataFile): boolean | Promise‹boolean›

Sync callback function to filter copied files.

Parameters:

| Name | Type | Description | | ------------------- | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | fullSourcePath | string | path of source file. | | fullTargetPath | string | path of target file. | | isSourceDirectory | boolean | is whether source path is a directory. | | isTargetDirectory | boolean | is whether target path is a directory. | | sourceContent? | string | DataFile | is string content or {@link DataFile https://www.npmjs.com/package/edit-config} instance if content of source file is parseble object. If file does not exist or is a directory, this is undefined. | | targetContent? | string | DataFile | is string content or {@link DataFile https://www.npmjs.com/package/edit-config} instance if content of target file is parseble object. If file does not exist or is a directory, this is undefined. |


DependencyType

Ƭ DependencyType: "dependencies" | "devDependencies" | "peerDependencies" | "optionalDependencies"

Defined in src/util/types.ts:9

Dependency types for Node.js modules.


PackageManager

Ƭ PackageManager: "npm" | "yarn"

Defined in src/util/types.ts:6

Package manager


PredicateFileOperation

Ƭ PredicateFileOperation: function

Defined in src/util/types.ts:12

Type of callback function to test whether related file operation should be done.

Type declaration:

▸ (fileContent?: string | DataFile): Promise‹boolean› | boolean

Callback function to test whether related file operation should be done.

Parameters:

| Name | Type | | -------------- | ---------------------- | | fileContent? | string | DataFile |


StdioOption

Ƭ StdioOption: "pipe" | "ignore" | "inherit" | Array‹"pipe" | "ipc" | "ignore" | "inherit" | Stream | number | undefined›

Defined in src/util/types.ts:70

Variables

Const ALL_DEPENDENCIES

ALL_DEPENDENCIES: string[] = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]

Defined in src/module.ts:11


swc

swc: "/Users/ozum/Development/intermodular/node_modules/@swc/core/index"

Defined in src/intermodular.ts:12

Classes

Class: Intermodular

Hierarchy

  • Intermodular

Properties

Readonly config

config: DataFile

Defined in src/intermodular.ts:22

Configuration for source module in target module as a DataFile instance.


Readonly logger

logger: Logger

Defined in src/intermodular.ts:25

Winston compatible logger.


Readonly sourceModule

sourceModule: Module

Defined in src/intermodular.ts:16

Module instance of node module which is used as source for modification operations such as copy, update.


Readonly targetModule

targetModule: Module

Defined in src/intermodular.ts:19

Module instance of node module which is used as target for modification operations such as copy, update.

Methods

areEquivalentFiles

areEquivalentFiles(sourceModuleFilePath: string, targetModuleFilePath: string): Promise‹boolean›

Defined in src/intermodular.ts:211

Returns whether given files from source module and target module are equal using method described below:

  • For data files such as JSON or YAML, returns whether they are deeply equal. (Objects does not have to have same key order.)
  • For .js and .ts files, files are transpiled and minified then copmpared. (To overcome comment and simple format changes.)
  • For other files returns whether their string content are equal.

Example

intermodular("module-files/src/address.js", "src/address.js");
intermodular("module-files/config/.eslintrc", ".eslintrc");
intermodular("module-files/some.txt", "some.txt");

Parameters:

| Name | Type | Default | Description | | ---------------------- | ------ | -------------------- | ------------------------------------------------------------------------------------------------------------------- | | sourceModuleFilePath | string | - | is the file path relative to source module root. | | targetModuleFilePath | string | sourceModuleFilePath | is the file path relative to target module root. If not provided uses same relative path as sourceModuleFilePath. |

Returns: Promise‹boolean›

whether given files are equivalent.


command

command(cmd: string, options?: ExecuteOptions): Promise‹ExecaReturnValue›

Defined in src/intermodular.ts:190

Executes given command using execa.command with cwd as target module's root. Additionally adds source module's node_modules/.bin to path.

Example

intermodular.command("ls"); // Run `ls`.
intermodular.command("ls -al", { stdio: "inherit" }); // Run `ls -al`.

Parameters:

| Name | Type | Description | | ---------- | --------------------------------------------- | ----------------------------------------------------------- | | cmd | string | is command to execute. | | options? | ExecuteOptions | are passed to Execa. |

Returns: Promise‹ExecaReturnValue›

[[ExecaReturnValue]] instance.

command(cmd: string, options?: ExecuteOptions‹null›): Promise‹ExecaReturnValue‹Buffer››

Defined in src/intermodular.ts:191

Parameters:

| Name | Type | | ---------- | --------------------------------------------------- | | cmd | string | | options? | ExecuteOptions‹null› |

Returns: Promise‹ExecaReturnValue‹Buffer››


copy

copy(sourcePath: string, targetPath: string, copyOptions: CopyOptions): Promise‹string[]›

Defined in src/intermodular.ts:124

Copies a file or directory from pathInSourceModule relative to source module root to pathInTargetModulerelative to target module root. The directory can have contents. Like cp -r. IMPORTANT: Note that if source is a directory it will copy everything inside of this directory, not the entire directory itself.

Example

// Copy everything in `/path/to/project/node_modules/module-a/src/config/` to `/path/to/project/`
const copiedPaths = copySync("src/config", ".");
const copiedFiles = copySync("src/config", ".", { excludeDirFromReturn: true });

Parameters:

| Name | Type | Default | Description | | ------------- | --------------------------------------- | ---------- | ------------------------------------------------- | | sourcePath | string | - | is source to copy from. | | targetPath | string | sourcePath | is destination to copy to. Cannot be a directory. | | copyOptions | CopyOptions | {} | - |

Returns: Promise‹string[]›

copied files and directories. Directories can be optionally excluded.


execute

execute(bin: string, args?: string[], options?: ExecuteOptions): Promise‹ExecaReturnValue›

Defined in src/intermodular.ts:154

Executes given command using execa with given arguments and options with cwd as target module's root. Applies sensible default options. Additionally adds source module's node_modules/.bin to path.

Example

intermodular.execute("ls"); // Run `ls`.
intermodular.execute("ls", ["-al"], { stdio: "inherit" }); // Run `ls -al`.

Parameters:

| Name | Type | Description | | ---------- | --------------------------------------------- | ----------------------------------------------------------- | | bin | string | is binary file to execute. | | args? | string[] | are arguments to pass to executable. | | options? | ExecuteOptions | are passed to Execa. |

Returns: Promise‹ExecaReturnValue›

[[ExecaReturnValue]] instance.

execute(bin: string, args?: string[], options?: ExecuteOptions‹null›): Promise‹ExecaReturnValue‹Buffer››

Defined in src/intermodular.ts:155

Parameters:

| Name | Type | | ---------- | --------------------------------------------------- | | bin | string | | args? | string[] | | options? | ExecuteOptions‹null› |

Returns: Promise‹ExecaReturnValue‹Buffer››

execute(bin: string, options?: ExecuteOptions): Promise‹ExecaReturnValue›

Defined in src/intermodular.ts:168

Executes given command using execa with given arguments and options with cwd as target module's root. Applies sensible default options. Additionally adds source module's node_modules/.bin to path.

Example

intermodular.execute("ls"); // Run `ls`.
intermodular.execute("ls", { stdio: "inherit" }); // Run `ls`.

Parameters:

| Name | Type | Description | | ---------- | --------------------------------------------- | ----------------------------------------------------------- | | bin | string | is binary file to execute. | | options? | ExecuteOptions | are passed to Execa. |

Returns: Promise‹ExecaReturnValue›

[[ExecaReturnValue]] instance.

execute(bin: string, options?: ExecuteOptions‹null›): Promise‹ExecaReturnValue‹Buffer››

Defined in src/intermodular.ts:169

Parameters:

| Name | Type | | ---------- | --------------------------------------------------- | | bin | string | | options? | ExecuteOptions‹null› |

Returns: Promise‹ExecaReturnValue‹Buffer››


log

log(logLevel: LogLevel, message: string): void

Defined in src/intermodular.ts:40

Logs given message with required level using logger provided during object construction.

Parameters:

| Name | Type | Description | | ---------- | -------- | ---------------------------- | | logLevel | LogLevel | is the level to log message. | | message | string | is the message to log. |

Returns: void


Static isEnvSet

isEnvSet(variable: string): boolean

Defined in src/intermodular.ts:285

Returns whether variable is set in environment variables and not empty.

Parameters:

| Name | Type | Description | | ---------- | ------ | --------------------------------------------- | | variable | string | is name of the environment variable to check. |

Returns: boolean

whether given environment variable is set and not empty.


Static new

new(__namedParameters: object): Promise‹Intermodular

Defined in src/intermodular.ts:242

Creates and returns Intermodular instance.

Parameters:

Default value __namedParameters: object= {}

are options

| Name | Type | Description | | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | | commandStdio | undefined | "pipe" | "ignore" | "inherit" | undefined | number | "pipe" | "ignore" | "inherit" | internal‹› | "ipc"[] | - | | logger | undefined | Logger | is Winston compatible logger or console. | | overwrite | undefined | false | true | is whether to overwrite files by default. | | source | undefined | string | Module‹› | is the source module or a path in source module. By default immediate parent's root dir is used. Immediate parent is the file which calls this method. | | target | undefined | string | Module‹› | is the target module or a path in target module. By default process.env.INIT_CWD or process.env.CWD is used whichever is first available. |

Returns: Promise‹Intermodular

Intermodular instance.


Static parseEnv

parseEnvT›(variable: string, defaultValue?: T): string | number | Record‹string, any› | T | undefined

Defined in src/intermodular.ts:299

Parses and returns variable environment variable. If value is JSON object, parses using JSON5 and returns it as a JavaScript object. Otherwise returns defaultValue.

Type parameters:

T

Parameters:

| Name | Type | Description | | --------------- | ------ | ----------------------------------------------------------------- | | variable | string | is Name of the environment variable | | defaultValue? | T | is value to return if no environment variable is set or is empty. |

Returns: string | number | Record‹string, any› | T | undefined

environment variable (if possible as an object) or default value.

Class: Module

Class which provides information and modification methods for a module.

Hierarchy

  • Module

Properties

Readonly isTypeScript

isTypeScript: boolean

Defined in src/module.ts:32

Whether module is a TypeScript project.


Readonly package

package: DataFile

Defined in src/module.ts:29

DataFile instance of package.json.


Readonly packageManager

packageManager: PackageManager

Defined in src/module.ts:26

Package manager of the module.


Readonly root

root: string

Defined in src/module.ts:23

Absolute path of the module's root directory, where package.json is located.

Accessors

name

get name(): string

Defined in src/module.ts:77

Name of the module as defined in package.json.

Returns: string


nameWithoutUser

get nameWithoutUser(): string

Defined in src/module.ts:82

Name of the module without user name. For example: typescript for @microsoft/typescript.

Returns: string

Methods

cloneWithSharedManager

cloneWithSharedManager(__namedParameters: object): Module

Defined in src/module.ts:66

Creates a new Module instance from current instance, which shares Data File Manager with current Module. Multiple instance work over same files efficiently and without collision.

Parameters:

Default value __namedParameters: object= {}

| Name | Type | | ----------- | ---------------------------------- | | logger | undefined | Logger | | overwrite | undefined | false | true |

Returns: Module

Module instance.


command

command(cmd: string, options?: ExecuteOptions): Promise‹ExecaReturnValue›

Defined in src/module.ts:408

Executes given command using execa.command with given options. Applies sensible default options.

Example

module.command("ls"); // Run `ls`.
module.command("ls -al", { stdio: "inherit" }); // Run `ls -al`.

Parameters:

| Name | Type | Description | | ---------- | --------------------------------------------- | ----------------------------------------------------------- | | cmd | string | is command to execute. | | options? | ExecuteOptions | are passed to Execa. |

Returns: Promise‹ExecaReturnValue›

[[ExecaReturnValue]] instance.

command(cmd: string, options?: ExecuteOptions‹null›): Promise‹ExecaReturnValue‹Buffer››

Defined in src/module.ts:409

Parameters:

| Name | Type | | ---------- | --------------------------------------------------- | | cmd | string | | options? | ExecuteOptions‹null› |

Returns: Promise‹ExecaReturnValue‹Buffer››


createDirectory

createDirectory(path: string): Promise‹void›

Defined in src/module.ts:308

Ensures that the directory exists. If the directory structure does not exist, it is created similar to mkdir -p.

Parameters:

| Name | Type | Description | | ------ | ------ | -------------------------------------------------------- | | path | string | is the path relative to module root or an absolute path. |

Returns: Promise‹void›


execute

execute(bin: string, args?: string[], options?: ExecuteOptions): Promise‹ExecaReturnValue›

Defined in src/module.ts:364

Executes given command using execa with given arguments and options. Applies sensible default options.

Example

module.execute("ls"); // Run `ls`.
module.execute("ls", ["-al"], { stdio: "inherit" }); // Run `ls -al`.

Parameters:

| Name | Type | Description | | ---------- | --------------------------------------------- | ----------------------------------------------------------- | | bin | string | is binary file to execute. | | args? | string[] | are arguments to pass to executable. | | options? | ExecuteOptions | are passed to Execa. |

Returns: Promise‹ExecaReturnValue›

[[ExecaReturnValue]] instance.

execute(bin: string, args?: string[], options?: ExecuteOptions‹null›): Promise‹ExecaReturnValue‹Buffer››

Defined in src/module.ts:365

Parameters:

| Name | Type | | ---------- | --------------------------------------------------- | | bin | string | | args? | string[] | | options? | ExecuteOptions‹null› |

Returns: Promise‹ExecaReturnValue‹Buffer››

execute(bin: string, options?: ExecuteOptions): Promise‹ExecaReturnValue›

Defined in src/module.ts:377

Executes given command using execa with given arguments and options. Applies sensible default options.

Example

module.execute("ls"); // Run `ls`.
module.execute("ls", { stdio: "inherit" }); // Run `ls`.

Parameters:

| Name | Type | Description | | ---------- | --------------------------------------------- | ----------------------------------------------------------- | | bin | string | is binary file to execute. | | options? | ExecuteOptions | are passed to Execa. |

Returns: Promise‹ExecaReturnValue›

[[ExecaReturnValue]] instance.

execute(bin: string, options?: ExecuteOptions‹null›): Promise‹ExecaReturnValue‹Buffer››

Defined in src/module.ts:378

Parameters:

| Name | Type | | ---------- | --------------------------------------------------- | | bin | string | | options? | ExecuteOptions‹null› |

Returns: Promise‹ExecaReturnValue‹Buffer››


exists

exists(path: string): Promise‹boolean›

Defined in src/module.ts:283

Checks whether given path exists.

Parameters:

| Name | Type | Description | | ------ | ------ | -------------------------------------------------------- | | path | string | is the path relative to module root or an absolute path. |

Returns: Promise‹boolean›

whether given path exists.


getDependencyVersion

getDependencyVersion(moduleName: string, dependencyTypes: string[]): string | undefined

Defined in src/module.ts:93

Fetches a dependent module's version from given dependency types.

Parameters:

| Name | Type | Default | Description | | ----------------- | -------- | ---------------- | -------------------------------------------------- | | moduleName | string | - | is the name of the module to get version of. | | dependencyTypes | string[] | ALL_DEPENDENCIES | are array of dependency types to search module in. |

Returns: string | undefined

version of the moduleName || undefined.


hasAnyDependency

hasAnyDependency(moduleNames: string | string[], dependencyTypes: string[]): boolean

Defined in src/module.ts:105

Checks whether given module or any of the modules exist in given dependency types.

Parameters:

| Name | Type | Default | Description | | ----------------- | ---------------------- | ---------------- | -------------------------------------------------- | | moduleNames | string | string[] | - | are the name of the module to search for. | | dependencyTypes | string[] | ALL_DEPENDENCIES | are array of dependency types to search module in. |

Returns: boolean

whether moduleName exists in one of the dependency types.


ifAnyDependency

ifAnyDependencyT, F›(moduleNames: string | string[]): boolean

Defined in src/module.ts:109

Checks single or multiple module's existence in any of the package.json dependencies.

Type parameters:

T

F

Parameters:

| Name | Type | Description | | ------------- | ---------------------- | ---------------------------------------------------------------------- | | moduleNames | string | string[] | are Module or modules to check whether this module has any dependency. |

Returns: boolean

trueValue if module depends on any of the moduleNames. Otherwise returns falseValue.

ifAnyDependencyT, F›(moduleNames: string | string[], t: T): T | false

Defined in src/module.ts:110

Checks single or multiple module's existence in any of the package.json dependencies.

Type parameters:

T

F

Parameters:

| Name | Type | | ------------- | ---------------------- | | moduleNames | string | string[] | | t | T |

Returns: T | false

trueValue if module depends on any of the moduleNames. Otherwise returns falseValue.

ifAnyDependencyT, F›(moduleNames: string | string[], t: T, f: F, dependencyTypes?: DependencyType[]): T | F

Defined in src/module.ts:111

Checks single or multiple module's existence in any of the package.json dependencies.

Type parameters:

T

F

Parameters:

| Name | Type | | ------------------ | ----------------------------------- | | moduleNames | string | string[] | | t | T | | f | F | | dependencyTypes? | DependencyType[] |

Returns: T | F

trueValue if module depends on any of the moduleNames. Otherwise returns falseValue.


install

install(packageNames: string | string[], __namedParameters: object): Promise‹void›

Defined in src/module.ts:435

Installs node modules using specified package manager.

Parameters:

Default value packageNames: string | string[]= []

are package name or array of package names.

Default value __namedParameters: object= {}

| Name | Type | Default | Description | | ------ | ----------------------------------------------------------------------------------------------- | -------------------------------- | --------------------------------------------------------------------- | | type | "dependencies" | "devDependencies" | "peerDependencies" | "optionalDependencies" | "dependencies" as DependencyType | is the dependency type of the package. dev, peer, optional etc. |

Returns: Promise‹void›


isDirectory

isDirectory(path: string): Promise‹boolean›

Defined in src/module.ts:293

Returns whether given path is a directory.

Parameters:

| Name | Type | Description | | ------ | ------ | -------------------------------------------------------- | | path | string | is the path relative to module root or an absolute path. |

Returns: Promise‹boolean›

whether given path is a directory.


isEqual

isEqual(path: string, content: string | Record‹string, any›): Promise‹boolean›

Defined in src/module.ts:347

Checks whether content of pathInModule file is equal to data by making string comparison (for strings) or deep comparison (for objects).

Example

const isConfigEqual = module.isEqual("config.json", { someData: 4 });
const textEqual = module.isEqual("some.txt", "content");

Parameters:

| Name | Type | Description | | --------- | --------------------------------- | ------------------------------------------------------------ | | path | string | is the path relative to module root or an absolute path. | | content | string | Record‹string, any› | is string or JavaScript object to compare to file's content. |

Returns: Promise‹boolean›

whether the file is equal to given content.


pathOf

pathOf(...parts: string[]): string

Defined in src/module.ts:135

Returns absolute path for given relative path to module root. If given path is an absolute path, returns it directly.

Example

module.pathOf("images", "photo.jpg"); // -> /path/to/root/images/photo.jpg
module.pathOf("/usr", "bin"); // -> /usr/bin

Parameters:

| Name | Type | Description | | ---------- | -------- | -------------------------------- | | ...parts | string[] | are path or array of path parts. |

Returns: string

absolute path to given destination.


read

read(path: string, options?: ManagerLoadOptions): Promise‹DataFile | string | undefined›

Defined in src/module.ts:185

Reads and if possible returns DataFile otherwise file content. If file does not exist returns undefined. If options.defaultData is true, file will be created using options.defaultData if it does not exist.

see Module.readData, Module.readRaw

throws if given path is a directory.

Parameters:

| Name | Type | Description | | ---------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ | | path | string | is the path relative to module root or an absolute path. | | options? | ManagerLoadOptions | are options passed to Manager.load of edit-config. See here. |

Returns: Promise‹DataFile | string | undefined›

DataFile instance, file content or undefined.


readData

readData(path: string, options?: ManagerLoadOptions): Promise‹DataFile›

Defined in src/module.ts:171

Reads file and creates DataFile instance using Manager.

Parameters:

| Name | Type | Description | | ---------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ | | path | string | is the path relative to module root or an absolute path. | | options? | ManagerLoadOptions | are options passed to Manager.load of edit-config. See here. |

Returns: Promise‹DataFile›


readRaw

readRaw(path: string): Promise‹string›

Defined in src/module.ts:161

Asynchronously reads the entire contents of a file using utf8 encoding.

Parameters:

| Name | Type | Description | | ------ | ------ | -------------------------------------------------------- | | path | string | is the path relative to module root or an absolute path. |

Returns: Promise‹string›

file contents.


relativePathOf

relativePathOf(...parts: string[]): string

Defined in src/module.ts:150

Returns relative path to module root for given absolute path. If given path is a relative path, returns it directly.

Example

module.relativePathOf("/path/to/module/src/my-file.js"); // -> src/my-file.js
module.relativePathOf("src/my-file.js"); // -> src/my-file.js

Parameters:

| Name | Type | Description | | ---------- | -------- | -------------------------------- | | ...parts | string[] | are path or array of path parts. |

Returns: string

path relative to module's root.


remove

remove(path: string, __namedParameters: object): Promise‹string | undefined›

Defined in src/module.ts:258

Removes file or directory relative to module's root. Removes directory even it has files in it. If the path does not exist, silently does nothing.

Parameters:

path: string

is the path relative to module root or an absolute path.

Default value __namedParameters: object= {}

| Name | Type | | ----------- | ------------------------- | | condition | undefined | function |

Returns: Promise‹string | undefined›

file path relative to module root if file is removed, undefined otherwise.


removeEmptyDirs

removeEmptyDirs(path: string): Promise‹string[]›

Defined in src/module.ts:271

Removes empty directories recursively for given path relative to module root.

Parameters:

| Name | Type | Description | | ------ | ------ | -------------------------------------------------------- | | path | string | is the path relative to module root or an absolute path. |

Returns: Promise‹string[]›

array of deleted directories.


rename

rename(oldPath: string, newPath: string, __namedParameters: object): Promise‹boolean›

Defined in src/module.ts:320

Renames given path.

Parameters:

oldPath: string

is the old path relative to module root or an absolute path.

newPath: string

is the new path relative to module root or an absolute path.

Default value __namedParameters: object= {}

| Name | Type | Default | Description | | ----------- | ------- | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | | overwrite | boolean | this.#overwrite | is whether to allow rename operation if target path already exists. Silently ignores operation if overwrite is not allowed and target path exists. |

Returns: Promise‹boolean›

whether file is renamed.


saveAll

saveAll(): Promise‹void›

Defined in src/module.ts:424

Saves all read data files.

Returns: Promise‹void›


uninstall

uninstall(packageNames: string | string[]): Promise‹void›

Defined in src/module.ts:455

Uninstalls node modules using specified package manager.

Parameters:

| Name | Type | Default | Description | | -------------- | ---------------------- | ------- | ------------------------------------------- | | packageNames | string | string[] | [] | are package name or array of package names. |

Returns: Promise‹void›


write

write(path: string, content: object | string, __namedParameters: object): Promise‹string | DataFile | undefined›

Defined in src/module.ts:222

Writes given content to file. If content is an object, it is serialized. If prettier configuration and module is available and content is formatted using prettier.

Parameters:

path: string

is the path relative to module root or an absolute path.

Default value content: object | string= ""

is the content to write to file.

Default value __namedParameters: object= {}

| Name | Type | Default | Description | | --------------- | ------------------------- | --------------- | --------------------------------------------------------------------------------------- | | condition | undefined | function | - | - | | defaultFormat | "json" | "yaml" | "json" | is the format to be used in serialization if file does not exist and content is object. | | overwrite | boolean | this.#overwrite | is whether to overwrite existing file. |

Returns: Promise‹string | DataFile | undefined›

written content or [[DataFile]] if file is written, undefined otherwise.


Static new

new(options: object): Promise‹Module

Defined in src/module.ts:482

Creates and returns a Module instance.

Parameters:

Default value options: object= {}

are options.

| Name | Type | Description | | ----------------- | ---------------------------------- | ------------------------------------------------------------------------------ | | commandStdio? | StdioOption | is the default stdio option to be used with command and execute methods. | | cwd? | undefined | string | is starting directory to start search for module root from. | | logger? | Logger | is Winston compatible Logger to be used when logging. | | overwrite? | undefined | false | true | is whether to overwrite files by default. | | packageManager? | PackageManager | is package manager used by module. |

Returns: Promise‹Module

Module instance.

Interfaces

Interface: CopyOptions

Copy options based on fs-extra copy options.

Hierarchy

  • CopyOptions

Properties

Optional dereference

dereference? : undefined | false | true

Defined in src/util/types.ts:46

Dereference symlinks, default is false.


Optional errorOnExist

errorOnExist? : undefined | false | true

Defined in src/util/types.ts:52

When overwrite is false and the destination exists, throw an error. Default is false.


Optional excludeDirFromReturn

excludeDirFromReturn? : undefined | false | true

Defined in src/util/types.ts:58

Whether to exclude directories from return value. If this is true only paths of copied files returned but not directories.


Optional filter

filter? : CopyFilterFunction

Defined in src/util/types.ts:54

Function to filter copied files. Return true to include, false to exclude. Can also return a Promise that resolves to true or false (or pass in an async function)


Optional overwrite

overwrite? : undefined | false | true

Defined in src/util/types.ts:48

Overwrite existing file or directory, default is true. Note that the copy operation will silently fail if you set this to false and the destination exists. Use the errorOnExist option to change this behavior.


Optional preserveTimestamps

preserveTimestamps? : undefined | false | true

Defined in src/util/types.ts:50

When true, will set last modification and access times to the ones of the original source files. When false, timestamp behavior is OS-dependent. Default is false.


Optional recursive

recursive? : undefined | false | true

Defined in src/util/types.ts:56

fs-extra.copy recursive option.

Interface: ExecuteOptions ‹EncodingType

Extended options for module.execute and module.command

Type parameters

EncodingType

Hierarchy

  • Options‹EncodingType›

    ExecuteOptions

Properties

Optional Readonly all

all? : undefined | false | true

Inherited from ExecuteOptions.all

Defined in node_modules/execa/index.d.ts:96

Add an .all property on the promise and the resolved value. The property contains the output of the process with stdout and stderr interleaved.

default false


Optional Readonly argv0

argv0? : undefined | string

Inherited from ExecuteOptions.argv0

Defined in node_modules/execa/index.d.ts:129

Explicitly set the value of argv[0] sent to the child process. This will be set to command or file if not specified.


Optional Readonly buffer

buffer? : undefined | false | true

Inherited from ExecuteOptions.buffer

Defined in node_modules/execa/index.d.ts:61

Buffer the output from the spawned process. When set to false, you must read the output of stdout and stderr (or all if the all option is true). Otherwise the returned promise will not be resolved/rejected.

If the spawned process fails, error.stdout, error.stderr, and error.all will contain the buffered data.

default true


Optional Readonly cleanup

cleanup? : undefined | false | true

Inherited from ExecuteOptions.cleanup

Defined in node_modules/execa/index.d.ts:23

Kill the spawned process when the parent process exits unless either:

  • the spawned process is detached
  • the parent process is terminated abruptly, for example, with SIGKILL as opposed to SIGTERM or a normal exit

default true


Optional Readonly cwd

cwd? : undefined | string

Inherited from ExecuteOptions.cwd

Defined in node_modules/execa/index.d.ts:117

Current working directory of the child process.

default process.cwd()


Optional Readonly detached

detached? : undefined | false | true

Inherited from ExecuteOptions.detached

Defined in node_modules/execa/index.d.ts:156

Prepare child to run independently of its parent process. Specific behavior depends on the platform.

default false


Optional Readonly encoding

encoding? : EncodingType

Inherited from ExecuteOptions.encoding

Defined in node_modules/execa/index.d.ts:185

Specify the character encoding used to decode the stdout and stderr output. If set to null, then stdout and stderr will be a Buffer instead of a string.

default 'utf8'


Optional Readonly env

env? : NodeJS.ProcessEnv

Inherited from ExecuteOptions.env

Defined in node_modules/execa/index.d.ts:124

Environment key-value pairs. Extends automatically from process.env. Set extendEnv to false if you don't want this.

default process.env


Optional Readonly execPath

execPath? : undefined | string

Inherited from ExecuteOptions.execPath

Defined in node_modules/execa/index.d.ts:52

Path to the Node.js executable to use in child processes.

This can be either an absolute path or a path relative to the cwd option.

Requires preferLocal to be true.

For example, this can be used together with get-node to run a specific Node.js version in a child process.

default process.execPath


Optional exitOnProcessFailure

exitOnProcessFailure? : undefined | false | true

Defined in src/util/types.ts:64

Exits using process.exit(errCode) if error is originated from shell. Otherwise throws as usual. Errors originated from node.js always throw.


Optional Readonly extendEnv

extendEnv? : undefined | false | true

Inherited from ExecuteOptions.extendEnv

Defined in node_modules/execa/index.d.ts:110

Set to false if you don't want to extend the environment variables when providing the env property.

default true


Optional Readonly gid

gid? : undefined | number

Inherited from ExecuteOptions.gid

Defined in node_modules/execa/index.d.ts:166

Sets the group identity of the process.


Optional Readonly input

input? : string | Buffer | ReadableStream

Inherited from ExecuteOptions.input

Defined in node_modules/execa/index.d.ts:227

Write some input to the stdin of your binary.


Optional Readonly killSignal

killSignal? : string | number

Inherited from ExecuteOptions.killSignal

Defined in node_modules/execa/index.d.ts:206

Signal value to be used when the spawned process will be killed.

default 'SIGTERM'


Optional Readonly localDir

localDir? : undefined | string

Inherited from ExecuteOptions.localDir

Defined in node_modules/execa/index.d.ts:39

Preferred path to find locally installed binaries in (use with preferLocal).

default process.cwd()


Optional Readonly maxBuffer

maxBuffer? : undefined | number

Inherited from ExecuteOptions.maxBuffer

Defined in node_modules/execa/index.d.ts:199

Largest amount of data in bytes allowed on stdout or stderr. Default: 100 MB.

default 100_000_000


Optional Readonly preferLocal

preferLocal? : undefined | false | true

Inherited from ExecuteOptions.preferLocal

Defined in node_modules/execa/index.d.ts:32

Prefer locally installed binaries when looking for a binary to execute.

If you $ npm install foo, you can then execa('foo').

default false


Optional Readonly reject

reject? : undefined | false | true

Inherited from ExecuteOptions.reject

Defined in node_modules/execa/index.d.ts:89

Setting this to false resolves the promise with the error instead of rejecting it.

default true


Optional Readonly serialization

serialization? : "json" | "advanced"

Inherited from ExecuteOptions.serialization

Defined in node_modules/execa/index.d.ts:149

Specify the kind of serialization used for sending messages between processes when using the stdio: 'ipc' option or execa.node():

  • json: Uses JSON.stringify() and JSON.parse().
  • advanced: Uses v8.serialize()

Requires Node.js 13.2.0 or later.

More info.

default 'json'


Optional Readonly shell

shell? : boolean | string

Inherited from ExecuteOptions.shell

Defined in node_modules/execa/index.d.ts:178

If true, runs command inside of a shell. Uses /bin/sh on UNIX and cmd.exe on Windows. A different shell can be specified as a string. The shell should understand the -c switch on UNIX or /d /s /c on Windows.

We recommend against using this option since it is:

  • not cross-platform, encouraging shell-specific syntax.
  • slower, because of the additional shell interpretation.
  • unsafe, potentially allowing command injection.

default false


Optional Readonly stderr

stderr? : StdioOption

Inherited from ExecuteOptions.stderr

Defined in node_modules/execa/index.d.ts:82

Same options as stdio.

default 'pipe'


Optional Readonly stdin

stdin? : StdioOption

Inherited from ExecuteOptions.stdin

Defined in node_modules/execa/index.d.ts:68

Same options as stdio.

default 'pipe'


Optional stdio

stdio? : StdioOption

Overrides void

Defined in src/util/types.ts:66

The options.stdio option is used to configure the pipes that are established between the parent and child process.


Optional Readonly stdout

stdout? : StdioOption

Inherited from ExecuteOptions.stdout

Defined in node_modules/execa/index.d.ts:75

Same options as stdio.

default 'pipe'


Optional Readonly stripFinalNewline

stripFinalNewline? : undefined | false | true

Inherited from ExecuteOptions.stripFinalNewline

Defined in node_modules/execa/index.d.ts:103

Strip the final newline character from the output.

default true


Optional Readonly timeout

timeout? : undefined | number

Inherited from ExecuteOptions.timeout

Defined in node_modules/execa/index.d.ts:192

If timeout is greater than 0, the parent will send the signal identified by the killSignal property (the default is SIGTERM) if the child runs longer than timeout milliseconds.

**`def