javascript Submodule
Constructs
Biome
Biome component.
Initializers
import { javascript } from 'projen'
new javascript.Biome(project: NodeProject, options?: BiomeOptions)
| Name | Type | Description |
|---|---|---|
| | No description. |
| | No description. |
projectRequired
- Type: NodeProject
optionsOptional
- Type: BiomeOptions
Methods
| Name | Description |
|---|---|
| Returns a string representation of this construct. |
| Called after synthesis. |
| Called before synthesis. |
| Synthesizes files to the project output directory. |
| No description. |
toString
public toString(): string
Returns a string representation of this construct.
postSynthesize
public postSynthesize(): void
Called after synthesis.
Order is not guaranteed.
preSynthesize
public preSynthesize(): void
Called before synthesis.
synthesize
public synthesize(): void
Synthesizes files to the project output directory.
addFilePattern
public addFilePattern(pattern: string): void
patternRequired
- Type: string
Static Functions
| Name | Description |
|---|---|
| Checks if x is a construct. |
| Test whether the given construct is a component. |
| No description. |
isConstruct
import { javascript } from 'projen'
javascript.Biome.isConstruct(x: any)
Checks if x is a construct.
Use this method instead of instanceof to properly detect Construct
instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on
disk are seen as independent, completely different libraries. As a
consequence, the class Construct in each copy of the constructs library
is seen as a different class, and an instance of one class will not test as
instanceof the other class. npm install will not create installations
like this, but users may manually symlink construct libraries together or
use a monorepo tool: in those cases, multiple copies of the constructs
library can be accidentally installed, and instanceof will behave
unpredictably. It is safest to avoid using instanceof, and using
this type-testing method instead.
xRequired
- Type: any
Any object.
isComponent
import { javascript } from 'projen'
javascript.Biome.isComponent(x: any)
Test whether the given construct is a component.
xRequired
- Type: any
of
import { javascript } from 'projen'
javascript.Biome.of(project: Project)
projectRequired
- Type: projen.Project
Properties
| Name | Type | Description |
|---|---|---|
| constructs.Node | The tree node. |
| projen.Project | No description. |
| projen.JsonFile | Biome configuration file content. |
| projen.Task | Biome task. |
nodeRequired
public readonly node: Node;
- Type: constructs.Node
The tree node.
projectRequired
public readonly project: Project;
- Type: projen.Project
fileRequired
public readonly file: JsonFile;
- Type: projen.JsonFile
Biome configuration file content.
taskRequired
public readonly task: Task;
- Type: projen.Task
Biome task.
Bundler
Adds support for bundling JavaScript applications and dependencies into a single file.
In the future, this will also supports bundling websites.
Initializers
import { javascript } from 'projen'
new javascript.Bundler(project: Project, options?: BundlerOptions)
| Name | Type | Description |
|---|---|---|
| projen.Project | No description. |
| | No description. |
projectRequired
- Type: projen.Project
optionsOptional
- Type: BundlerOptions
Methods
| Name | Description |
|---|---|
| Returns a string representation of this construct. |
| Called after synthesis. |
| Called before synthesis. |
| Synthesizes files to the project output directory. |
| Adds a task to the project which bundles a specific entrypoint and all of its dependencies into a single javascript output file. |
toString
public toString(): string
Returns a string representation of this construct.
postSynthesize
public postSynthesize(): void
Called after synthesis.
Order is not guaranteed.
preSynthesize
public preSynthesize(): void
Called before synthesis.
synthesize
public synthesize(): void
Synthesizes files to the project output directory.
addBundle
public addBundle(entrypoint: string, options: AddBundleOptions): Bundle
Adds a task to the project which bundles a specific entrypoint and all of its dependencies into a single javascript output file.
entrypointRequired
- Type: string
The relative path of the artifact within the project.
optionsRequired
- Type: AddBundleOptions
Bundling options.
Static Functions
| Name | Description |
|---|---|
| Checks if x is a construct. |
| Test whether the given construct is a component. |
| Returns the Bundler instance associated with a project or undefined if there is no Bundler. |
isConstruct
import { javascript } from 'projen'
javascript.Bundler.isConstruct(x: any)
Checks if x is a construct.
Use this method instead of instanceof to properly detect Construct
instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on
disk are seen as independent, completely different libraries. As a
consequence, the class Construct in each copy of the constructs library
is seen as a different class, and an instance of one class will not test as
instanceof the other class. npm install will not create installations
like this, but users may manually symlink construct libraries together or
use a monorepo tool: in those cases, multiple copies of the constructs
library can be accidentally installed, and instanceof will behave
unpredictably. It is safest to avoid using instanceof, and using
this type-testing method instead.
xRequired
- Type: any
Any object.
isComponent
import { javascript } from 'projen'
javascript.Bundler.isComponent(x: any)
Test whether the given construct is a component.
xRequired
- Type: any
of
import { javascript } from 'projen'
javascript.Bundler.of(project: Project)
Returns the Bundler instance associated with a project or undefined if there is no Bundler.
projectRequired
- Type: projen.Project
The project.
Properties
| Name | Type | Description |
|---|---|---|
| constructs.Node | The tree node. |
| projen.Project | No description. |
| string | Root bundle directory. |
| projen.Task | Gets or creates the singleton "bundle" task of the project. |
| string | The semantic version requirement for esbuild (if defined). |
nodeRequired
public readonly node: Node;
- Type: constructs.Node
The tree node.
projectRequired
public readonly project: Project;
- Type: projen.Project
bundledirRequired
public readonly bundledir: string;
- Type: string
Root bundle directory.
bundleTaskRequired
public readonly bundleTask: Task;
- Type: projen.Task
Gets or creates the singleton "bundle" task of the project.
If the project doesn't have a "bundle" task, it will be created and spawned during the pre-compile phase.
esbuildVersionOptional
public readonly esbuildVersion: string;
- Type: string
The semantic version requirement for esbuild (if defined).
Eslint
Represents eslint configuration.
Initializers
import { javascript } from 'projen'
new javascript.Eslint(project: NodeProject, options: EslintOptions)
| Name | Type | Description |
|---|---|---|
| | No description. |
| | No description. |
projectRequired
- Type: NodeProject
optionsRequired
- Type: EslintOptions
Methods
| Name | Description |
|---|---|
| Returns a string representation of this construct. |
| Called after synthesis. |
| Called before synthesis. |
| Synthesizes files to the project output directory. |
| Adds an extends item to the eslint configuration. |
| Do not lint these files. |
| Add a file, glob pattern or directory with source files to lint (e.g. [ "src" ]). |
| Add an eslint override. |
| Adds an eslint plugin. |
| Add an eslint rule. |
| Add a glob file pattern which allows importing dev dependencies. |
toString
public toString(): string
Returns a string representation of this construct.
postSynthesize
public postSynthesize(): void
Called after synthesis.
Order is not guaranteed.
preSynthesize
public preSynthesize(): void
Called before synthesis.
synthesize
public synthesize(): void
Synthesizes files to the project output directory.
addExtends
public addExtends(extendList: ...string[]): void
Adds an extends item to the eslint configuration.
extendListRequired
- Type: ...string[]
The list of "extends" to add.
addIgnorePattern
public addIgnorePattern(pattern: string): void
Do not lint these files.
patternRequired
- Type: string
addLintPattern
public addLintPattern(pattern: string): void
Add a file, glob pattern or directory with source files to lint (e.g. [ "src" ]).
patternRequired
- Type: string
addOverride
public addOverride(override: EslintOverride): void
Add an eslint override.
overrideRequired
- Type: EslintOverride
addPlugins
public addPlugins(plugins: ...string[]): void
Adds an eslint plugin.
pluginsRequired
- Type: ...string[]
The names of plugins to add.
addRules
public addRules(rules: {[ key: string ]: any}): void
Add an eslint rule.
rulesRequired
- Type: {[ key: string ]: any}
allowDevDeps
public allowDevDeps(pattern: string): void
Add a glob file pattern which allows importing dev dependencies.
patternRequired
- Type: string
glob pattern.
Static Functions
| Name | Description |
|---|---|
| Checks if x is a construct. |
| Test whether the given construct is a component. |
| Returns the singleton Eslint component of a project or undefined if there is none. |
isConstruct
import { javascript } from 'projen'
javascript.Eslint.isConstruct(x: any)
Checks if x is a construct.
Use this method instead of instanceof to properly detect Construct
instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on
disk are seen as independent, completely different libraries. As a
consequence, the class Construct in each copy of the constructs library
is seen as a different class, and an instance of one class will not test as
instanceof the other class. npm install will not create installations
like this, but users may manually symlink construct libraries together or
use a monorepo tool: in those cases, multiple copies of the constructs
library can be accidentally installed, and instanceof will behave
unpredictably. It is safest to avoid using instanceof, and using
this type-testing method instead.
xRequired
- Type: any
Any object.
isComponent
import { javascript } from 'projen'
javascript.Eslint.isComponent(x: any)
Test whether the given construct is a component.
xRequired
- Type: any
of
import { javascript } from 'projen'
javascript.Eslint.of(project: Project)
Returns the singleton Eslint component of a project or undefined if there is none.
projectRequired
- Type: projen.Project
Properties
| Name | Type | Description |
|---|---|---|
| constructs.Node | The tree node. |
| projen.Project | No description. |
| any | Direct access to the eslint configuration (escape hatch). |
| projen.Task | eslint task. |
| projen.ObjectFile | The underlying config file. |
| string[] | File patterns that should not be linted. |
| string[] | Returns an immutable copy of the lintPatterns being used by this eslint configuration. |
| | eslint overrides. |
| {[ key: string ]: any} | eslint rules. |
nodeRequired
public readonly node: Node;
- Type: constructs.Node
The tree node.
projectRequired
public readonly project: Project;
- Type: projen.Project
configRequired
public readonly config: any;
- Type: any
Direct access to the eslint configuration (escape hatch).
eslintTaskRequired
public readonly eslintTask: Task;
- Type: projen.Task
eslint task.
fileRequired
public readonly file: ObjectFile;
- Type: projen.ObjectFile
The underlying config file.
ignorePatternsRequired
public readonly ignorePatterns: string[];
- Type: string[]
File patterns that should not be linted.
lintPatternsRequired
public readonly lintPatterns: string[];
- Type: string[]
Returns an immutable copy of the lintPatterns being used by this eslint configuration.
overridesRequired
public readonly overrides: EslintOverride[];
- Type: EslintOverride[]
eslint overrides.
rulesRequired
public readonly rules: {[ key: string ]: any};
- Type: {[ key: string ]: any}
eslint rules.
Jest
Installs the following npm scripts:.
test, intended for testing locally and in CI. Will update snapshots unless updateSnapshot: UpdateSnapshot: NEVER is set.
test:watch, intended for automatically rerunning tests when files change.test:update, intended for testing locally and updating snapshots to match the latest unit under test. Only available whenupdateSnapshot: UpdateSnapshot: NEVER.
Initializers
import { javascript } from 'projen'
new javascript.Jest(scope: IConstruct, options?: JestOptions)
| Name | Type | Description |
|---|---|---|
| constructs.IConstruct | No description. |
| | No description. |
scopeRequired
- Type: constructs.IConstruct
optionsOptional
- Type: JestOptions
Methods
| Name | Description |
|---|---|
| Returns a string representation of this construct. |
| Called after synthesis. |
| Called before synthesis. |
| Synthesizes files to the project output directory. |
| No description. |
| Adds one or more moduleNameMapper entries to Jest's configuration. |
| Adds one or more modulePaths to Jest's configuration. |
| No description. |
| Adds one or more roots to Jest's configuration. |
| Adds a a setup file to Jest's setupFiles configuration. |
| Adds a a setup file to Jest's setupFilesAfterEnv configuration. |
| No description. |
| Adds a test match pattern. |
| Adds a watch ignore pattern. |
| Build standard test match patterns for a directory. |
toString
public toString(): string
Returns a string representation of this construct.
postSynthesize
public postSynthesize(): void
Called after synthesis.
Order is not guaranteed.
preSynthesize
public preSynthesize(): void
Called before synthesis.
synthesize
public synthesize(): void
Synthesizes files to the project output directory.
addIgnorePattern
public addIgnorePattern(pattern: string): void
patternRequired
- Type: string
addModuleNameMappers
public addModuleNameMappers(moduleNameMapperAdditions: {[ key: string ]: string | string[]}): void
Adds one or more moduleNameMapper entries to Jest's configuration.
Will overwrite if the same key is used as a pre-existing one.
moduleNameMapperAdditionsRequired
- Type: {[ key: string ]: string | string[]}
A map from regular expressions to module names or to arrays of module names that allow to stub out resources, like images or styles with a single module.
addModulePaths
public addModulePaths(modulePaths: ...string[]): void
Adds one or more modulePaths to Jest's configuration.
modulePathsRequired
- Type: ...string[]
An array of absolute paths to additional locations to search when resolving modules *.
addReporter
public addReporter(reporter: JestReporter): void
reporterRequired
- Type: JestReporter
addRoots
public addRoots(roots: ...string[]): void
Adds one or more roots to Jest's configuration.
rootsRequired
- Type: ...string[]
A list of paths to directories that Jest should use to search for files in.
addSetupFile
public addSetupFile(file: string): void
Adds a a setup file to Jest's setupFiles configuration.
fileRequired
- Type: string
File path to setup file.
addSetupFileAfterEnv
public addSetupFileAfterEnv(file: string): void
Adds a a setup file to Jest's setupFilesAfterEnv configuration.
fileRequired
- Type: string
File path to setup file.
addSnapshotResolver
public addSnapshotResolver(file: string): void
fileRequired
- Type: string
addTestMatch
public addTestMatch(pattern: string): void
Adds a test match pattern.
patternRequired
- Type: string
glob pattern to match for tests.
addWatchIgnorePattern
public addWatchIgnorePattern(pattern: string): void
Adds a watch ignore pattern.
patternRequired
- Type: string
The pattern (regular expression).
discoverTestMatchPatternsForDirs
public discoverTestMatchPatternsForDirs(dirs: string[], options?: JestDiscoverTestMatchPatternsForDirsOptions): void
Build standard test match patterns for a directory.
dirsRequired
- Type: string[]
The directories to add test matches for.
Matches any folder if not specified or an empty array.
optionsOptional
Options for building test match patterns.
Static Functions
| Name | Description |
|---|---|
| Checks if x is a construct. |
| Test whether the given construct is a component. |
| Returns the singleton Jest component of a project or undefined if there is none. |
isConstruct
import { javascript } from 'projen'
javascript.Jest.isConstruct(x: any)
Checks if x is a construct.
Use this method instead of instanceof to properly detect Construct
instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on
disk are seen as independent, completely different libraries. As a
consequence, the class Construct in each copy of the constructs library
is seen as a different class, and an instance of one class will not test as
instanceof the other class. npm install will not create installations
like this, but users may manually symlink construct libraries together or
use a monorepo tool: in those cases, multiple copies of the constructs
library can be accidentally installed, and instanceof will behave
unpredictably. It is safest to avoid using instanceof, and using
this type-testing method instead.
xRequired
- Type: any
Any object.
isComponent
import { javascript } from 'projen'
javascript.Jest.isComponent(x: any)
Test whether the given construct is a component.
xRequired
- Type: any
of
import { javascript } from 'projen'
javascript.Jest.of(project: Project)
Returns the singleton Jest component of a project or undefined if there is none.
projectRequired
- Type: projen.Project
Properties
| Name | Type | Description |
|---|---|---|
| constructs.Node | The tree node. |
| | No description. |
| any | Escape hatch. |
| string | Jest version, including @ symbol, like @^29. |
| projen.JsonFile | Jest config file. |
nodeRequired
public readonly node: Node;
- Type: constructs.Node
The tree node.
projectRequired
public readonly project: NodeProject;
- Type: NodeProject
configRequired
public readonly config: any;
- Type: any
Escape hatch.
jestVersionRequired
public readonly jestVersion: string;
- Type: string
Jest version, including @ symbol, like @^29.
fileOptional
public readonly file: JsonFile;
- Type: projen.JsonFile
Jest config file.
undefined if settings are written to package.json
LicenseChecker
Enforces allowed licenses used by dependencies.
Initializers
import { javascript } from 'projen'
new javascript.LicenseChecker(scope: Construct, options: LicenseCheckerOptions)
| Name | Type | Description |
|---|---|---|
| constructs.Construct | No description. |
| | No description. |
scopeRequired
- Type: constructs.Construct
optionsRequired
- Type: LicenseCheckerOptions
Methods
| Name | Description |
|---|---|
| Returns a string representation of this construct. |
| Called after synthesis. |
| Called before synthesis. |
| Synthesizes files to the project output directory. |
toString
public toString(): string
Returns a string representation of this construct.
postSynthesize
public postSynthesize(): void
Called after synthesis.
Order is not guaranteed.
preSynthesize
public preSynthesize(): void
Called before synthesis.
synthesize
public synthesize(): void
Synthesizes files to the project output directory.
Static Functions
| Name | Description |
|---|---|
| Checks if x is a construct. |
| Test whether the given construct is a component. |
isConstruct
import { javascript } from 'projen'
javascript.LicenseChecker.isConstruct(x: any)
Checks if x is a construct.
Use this method instead of instanceof to properly detect Construct
instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on
disk are seen as independent, completely different libraries. As a
consequence, the class Construct in each copy of the constructs library
is seen as a different class, and an instance of one class will not test as
instanceof the other class. npm install will not create installations
like this, but users may manually symlink construct libraries together or
use a monorepo tool: in those cases, multiple copies of the constructs
library can be accidentally installed, and instanceof will behave
unpredictably. It is safest to avoid using instanceof, and using
this type-testing method instead.
xRequired
- Type: any
Any object.
isComponent
import { javascript } from 'projen'
javascript.LicenseChecker.isComponent(x: any)
Test whether the given construct is a component.
xRequired
- Type: any
Properties
| Name | Type | Description |
|---|---|---|
| constructs.Node | The tree node. |
| projen.Project | No description. |
| projen.Task | No description. |
nodeRequired
public readonly node: Node;
- Type: constructs.Node
The tree node.
projectRequired
public readonly project: Project;
- Type: projen.Project
taskRequired
public readonly task: Task;
- Type: projen.Task
NodePackage
Represents the npm package.json file.
Initializers
import { javascript } from 'projen'
new javascript.NodePackage(project: Project, options?: NodePackageOptions)
| Name | Type | Description |
|---|---|---|
| projen.Project | No description. |
| | No description. |
projectRequired
- Type: projen.Project
optionsOptional
- Type: NodePackageOptions
Methods
| Name | Description |
|---|---|
| Returns a string representation of this construct. |
| Called after synthesis. |
| Called before synthesis. |
| Synthesizes files to the project output directory. |
| No description. |
| Defines bundled dependencies. |
| Defines normal dependencies. |
| Defines development/test dependencies. |
| Adds an engines requirement to your package. |
| Directly set fields in package.json. |
| Adds keywords to package.json (deduplicated). |
| Defines resolutions for dependencies to change the normally resolved version of a dependency to something else. |
| Defines peer dependencies. |
| Sets the package version. |
| Indicates if a script by the given name is defined. |
| Removes an npm script (always successful). |
| Add a npm package.json script. |
| Attempt to resolve the currently installed version for a given dependency. |
toString
public toString(): string
Returns a string representation of this construct.
postSynthesize
public postSynthesize(): void
Called after synthesis.
Order is not guaranteed.
preSynthesize
public preSynthesize(): void
Called before synthesis.
synthesize
public synthesize(): void
Synthesizes files to the project output directory.
addBin
public addBin(bins: {[ key: string ]: string}): void
binsRequired
- Type: {[ key: string ]: string}
addBundledDeps
public addBundledDeps(deps: ...string[]): void
Defines bundled dependencies.
Bundled dependencies will be added as normal dependencies as well as to the
bundledDependencies section of your package.json.
depsRequired
- Type: ...string[]
Names modules to install.
By default, the the dependency will
be installed in the next npx projen run and the version will be recorded
in your package.json file. You can upgrade manually or using yarn add/upgrade. If you wish to specify a version range use this syntax:
module@^7.
addDeps
public addDeps(deps: ...string[]): void
Defines normal dependencies.
depsRequired
- Type: ...string[]
Names modules to install.
By default, the the dependency will
be installed in the next npx projen run and the version will be recorded
in your package.json file. You can upgrade manually or using yarn add/upgrade. If you wish to specify a version range use this syntax:
module@^7.
addDevDeps
public addDevDeps(deps: ...string[]): void
Defines development/test dependencies.
depsRequired
- Type: ...string[]
Names modules to install.
By default, the the dependency will
be installed in the next npx projen run and the version will be recorded
in your package.json file. You can upgrade manually or using yarn add/upgrade. If you wish to specify a version range use this syntax:
module@^7.
addEngine
public addEngine(engine: string, version: string): void
Adds an engines requirement to your package.
engineRequired
- Type: string
The engine (e.g. node).
versionRequired
- Type: string
The semantic version requirement (e.g. ^10).
addField
public addField(name: string, value: any): void
Directly set fields in package.json.
nameRequired
- Type: string
field name.
valueRequired
- Type: any
field value.
addKeywords
public addKeywords(keywords: ...string[]): void
Adds keywords to package.json (deduplicated).
keywordsRequired
- Type: ...string[]
The keywords to add.
addPackageResolutions
public addPackageResolutions(resolutions: ...string[]): void
Defines resolutions for dependencies to change the normally resolved version of a dependency to something else.
resolutionsRequired
- Type: ...string[]
Names resolutions to be added.
Specify a version or
range with this syntax:
module@^7
addPeerDeps
public addPeerDeps(deps: ...string[]): void
Defines peer dependencies.
When adding peer dependencies, a devDependency will also be added on the pinned version of the declared peer. This will ensure that you are testing your code against the minimum version required from your consumers.
depsRequired
- Type: ...string[]
Names modules to install.
By default, the the dependency will
be installed in the next npx projen run and the version will be recorded
in your package.json file. You can upgrade manually or using yarn add/upgrade. If you wish to specify a version range use this syntax:
module@^7.
addVersion
public addVersion(version: string): void
Sets the package version.
versionRequired
- Type: string
Package version.
hasScript
hasScriptpublic hasScript(name: string): boolean
Indicates if a script by the given name is defined.
nameRequired
- Type: string
The name of the script.
removeScript
public removeScript(name: string): void
Removes an npm script (always successful).
nameRequired
- Type: string
The name of the script.
setScript
public setScript(name: string, command: string): void
Add a npm package.json script.
nameRequired
- Type: string
The script name.
commandRequired
- Type: string
The command to execute.
tryResolveDependencyVersion
public tryResolveDependencyVersion(dependencyName: string): string
Attempt to resolve the currently installed version for a given dependency.
dependencyNameRequired
- Type: string
Dependency to resolve for.
Static Functions
| Name | Description |
|---|---|
| Checks if x is a construct. |
| Test whether the given construct is a component. |
| Returns the NodePackage instance associated with a project or undefined if there is no NodePackage. |
isConstruct
import { javascript } from 'projen'
javascript.NodePackage.isConstruct(x: any)
Checks if x is a construct.
Use this method instead of instanceof to properly detect Construct
instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on
disk are seen as independent, completely different libraries. As a
consequence, the class Construct in each copy of the constructs library
is seen as a different class, and an instance of one class will not test as
instanceof the other class. npm install will not create installations
like this, but users may manually symlink construct libraries together or
use a monorepo tool: in those cases, multiple copies of the constructs
library can be accidentally installed, and instanceof will behave
unpredictably. It is safest to avoid using instanceof, and using
this type-testing method instead.
xRequired
- Type: any
Any object.
isComponent
import { javascript } from 'projen'
javascript.NodePackage.isComponent(x: any)
Test whether the given construct is a component.
xRequired
- Type: any
of
import { javascript } from 'projen'
javascript.NodePackage.of(project: Project)
Returns the NodePackage instance associated with a project or undefined if there is no NodePackage.
projectRequired
- Type: projen.Project
The project.
Properties
| Name | Type | Description |
|---|---|---|
| constructs.Node | The tree node. |
| projen.Project | No description. |
| boolean | Allow project to take library dependencies. |
| string | The module's entrypoint (e.g. lib/index.js). |
| projen.JsonFile | The package.json file. |
| string | Renders yarn install or npm install with lockfile update (not frozen). |
| projen.Task | The task for installing project dependencies (frozen). |
| string | Returns the command to execute in order to install all dependencies (always frozen). |
| projen.Task | The task for installing project dependencies (non-frozen). |
| string | The name of the lock file. |
| any | No description. |
| | npm package access level. |
| boolean | Should provenance statements be generated when package is published. |
| string | The npm registry host (e.g. registry.npmjs.org). |
| string | npm registry (e.g. https://registry.npmjs.org). Use npmRegistryHost to get just the host name. |
| | The package manager to use. |
| string | The name of the npm package. |
| string | The command which executes "projen". |
| string | The version of Bun to use if using Bun as a package manager. |
| | Options for npm packages using AWS CodeArtifact. |
| string | The SPDX license of this module. |
| string | Maximum node version supported by this package. |
| string | The minimum node version required by this package to function. |
| string | GitHub secret which contains the NPM token to use when publishing packages. |
| string | The version of PNPM to use if using PNPM as a package manager. |
| | Options for privately hosted scoped packages. |
nodeRequired
public readonly node: Node;
- Type: constructs.Node
The tree node.
projectRequired
public readonly project: Project;
- Type: projen.Project
allowLibraryDependenciesRequired
public readonly allowLibraryDependencies: boolean;
- Type: boolean
Allow project to take library dependencies.
entrypointRequired
public readonly entrypoint: string;
- Type: string
The module's entrypoint (e.g. lib/index.js).
fileRequired
public readonly file: JsonFile;
- Type: projen.JsonFile
The package.json file.
installAndUpdateLockfileCommandRequired
public readonly installAndUpdateLockfileCommand: string;
- Type: string
Renders yarn install or npm install with lockfile update (not frozen).
installCiTaskRequired
public readonly installCiTask: Task;
- Type: projen.Task
The task for installing project dependencies (frozen).
installCommandRequired
public readonly installCommand: string;
- Type: string
Returns the command to execute in order to install all dependencies (always frozen).
installTaskRequired
public readonly installTask: Task;
- Type: projen.Task
The task for installing project dependencies (non-frozen).
lockFileRequired
public readonly lockFile: string;
- Type: string
The name of the lock file.
manifestRequired
manifest- Deprecated: use
addField(x, y)
public readonly manifest: any;
- Type: any
npmAccessRequired
public readonly npmAccess: NpmAccess;
- Type: NpmAccess
npm package access level.
npmProvenanceRequired
public readonly npmProvenance: boolean;
- Type: boolean
Should provenance statements be generated when package is published.
npmRegistryRequired
public readonly npmRegistry: string;
- Type: string
The npm registry host (e.g. registry.npmjs.org).
npmRegistryUrlRequired
public readonly npmRegistryUrl: string;
- Type: string
npm registry (e.g. https://registry.npmjs.org). Use npmRegistryHost to get just the host name.
packageManagerRequired
public readonly packageManager: NodePackageManager;
- Type: NodePackageManager
The package manager to use.
packageNameRequired
public readonly packageName: string;
- Type: string
The name of the npm package.
projenCommandRequired
projenCommand- Deprecated: use
project.projenCommandinstead.
public readonly projenCommand: string;
- Type: string
The command which executes "projen".
bunVersionOptional
public readonly bunVersion: string;
- Type: string
The version of Bun to use if using Bun as a package manager.
codeArtifactOptionsOptional
public readonly codeArtifactOptions: CodeArtifactOptions;
- Type: CodeArtifactOptions
- Default: undefined
Options for npm packages using AWS CodeArtifact.
This is required if publishing packages to, or installing scoped packages from AWS CodeArtifact
licenseOptional
public readonly license: string;
- Type: string
The SPDX license of this module.
undefined if this package is not licensed.
maxNodeVersionOptional
public readonly maxNodeVersion: string;
- Type: string
Maximum node version supported by this package.
The value indicates the package is incompatible with newer versions.
minNodeVersionOptional
public readonly minNodeVersion: string;
- Type: string
The minimum node version required by this package to function.
This value indicates the package is incompatible with older versions.
npmTokenSecretOptional
public readonly npmTokenSecret: string;
- Type: string
GitHub secret which contains the NPM token to use when publishing packages.
pnpmVersionOptional
public readonly pnpmVersion: string;
- Type: string
The version of PNPM to use if using PNPM as a package manager.
scopedPackagesOptionsOptional
public readonly scopedPackagesOptions: ScopedPackagesOptions[];
- Type: ScopedPackagesOptions[]
- Default: undefined
Options for privately hosted scoped packages.
NodeProject
Node.js project.
Initializers
import { javascript } from 'projen'
new javascript.NodeProject(options: NodeProjectOptions)
| Name | Type | Description |
|---|---|---|
| | No description. |
optionsRequired
- Type: NodeProjectOptions
Methods
| Name | Description |
|---|---|
| Returns a string representation of this construct. |
| Exclude the matching files from pre-synth cleanup. |
| Adds a .gitignore pattern. |
| Adds patterns to be ignored by npm. |
| Adds a new task to this project. |
| Prints a "tip" message during synthesis. |
| Marks the provided file(s) as being generated. |
| Called after all components are synthesized. |
| Called before all components are synthesized. |
| Removes a task from a project. |
| Returns the shell command to execute in order to run a task. |
| Synthesize all project files into outdir. |
| Finds a file at the specified relative path within this project and all its subprojects. |
| Finds a json file by name. |
| Finds an object file (like JsonFile, YamlFile, etc.) by name. |
| Finds a file at the specified relative path within this project and removes it. |
| No description. |
| Defines bundled dependencies. |
| DEPRECATED. |
| Defines normal dependencies. |
| Defines development/test dependencies. |
| Directly set fields in package.json. |
| Adds keywords to package.json (deduplicated). |
| Defines peer dependencies. |
| Replaces the contents of multiple npm package.json scripts. |
| DEPRECATED. |
| Indicates if a script by the name name is defined. |
| Removes the npm script (always successful). |
| Returns the set of workflow steps which should be executed to bootstrap a workflow. |
| Replaces the contents of an npm package.json script. |
toString
public toString(): string
Returns a string representation of this construct.
addExcludeFromCleanup
public addExcludeFromCleanup(globs: ...string[]): void
Exclude the matching files from pre-synth cleanup.
Can be used when, for example, some source files include the projen marker and we don't want them to be erased during synth.
globsRequired
- Type: ...string[]
The glob patterns to match.
addGitIgnore
public addGitIgnore(pattern: string): void
Adds a .gitignore pattern.
patternRequired
- Type: string
The glob pattern to ignore.
addPackageIgnore
public addPackageIgnore(pattern: string): void
Adds patterns to be ignored by npm.
patternRequired
- Type: string
The pattern to ignore.
addTask
public addTask(name: string, props?: TaskOptions): Task
Adds a new task to this project.
This will fail if the project already has a task with this name.
nameRequired
- Type: string
The task name to add.
propsOptional
- Type: projen.TaskOptions
Task properties.
addTip
addTippublic addTip(message: string): void
Prints a "tip" message during synthesis.
messageRequired
- Type: string
The message.
annotateGenerated
public annotateGenerated(glob: string): void
Marks the provided file(s) as being generated.
This is achieved using the github-linguist attributes. Generated files do not count against the repository statistics and language breakdown.
https://github.com/github/linguist/blob/master/docs/overrides.md
globRequired
- Type: string
the glob pattern to match (could be a file path).
postSynthesize
public postSynthesize(): void
Called after all components are synthesized.
Order is not guaranteed.
preSynthesize
public preSynthesize(): void
Called before all components are synthesized.
removeTask
public removeTask(name: string): Task
Removes a task from a project.
nameRequired
- Type: string
The name of the task to remove.
runTaskCommand
public runTaskCommand(task: Task): string
Returns the shell command to execute in order to run a task.
This will
typically be npx projen TASK.
taskRequired
- Type: projen.Task
The task for which the command is required.
synth
public synth(): void
Synthesize all project files into outdir.
- Call "this.preSynthesize()"
- Delete all generated files
- Synthesize all subprojects
- Synthesize all components of this project
- Call "postSynthesize()" for all components of this project
- Call "this.postSynthesize()"
tryFindFile
public tryFindFile(filePath: string): FileBase
Finds a file at the specified relative path within this project and all its subprojects.
filePathRequired
- Type: string
The file path.
If this path is relative, it will be resolved from the root of this project.
tryFindJsonFile
tryFindJsonFilepublic tryFindJsonFile(filePath: string): JsonFile
Finds a json file by name.
filePathRequired
- Type: string
The file path.
tryFindObjectFile
public tryFindObjectFile(filePath: string): ObjectFile
Finds an object file (like JsonFile, YamlFile, etc.) by name.
filePathRequired
- Type: string
The file path.
tryRemoveFile
public tryRemoveFile(filePath: string): FileBase
Finds a file at the specified relative path within this project and removes it.
filePathRequired
- Type: string
The file path.
If this path is relative, it will be resolved from the root of this project.
addBins
public addBins(bins: {[ key: string ]: string}): void
binsRequired
- Type: {[ key: string ]: string}
addBundledDeps
public addBundledDeps(deps: ...string[]): void
Defines bundled dependencies.
Bundled dependencies will be added as normal dependencies as well as to the
bundledDependencies section of your package.json.
depsRequired
- Type: ...string[]
Names modules to install.
By default, the the dependency will
be installed in the next npx projen run and the version will be recorded
in your package.json file. You can upgrade manually or using yarn add/upgrade. If you wish to specify a version range use this syntax:
module@^7.
addCompileCommand
addCompileCommandpublic addCompileCommand(commands: ...string[]): void
DEPRECATED.
commandsRequired
- Type: ...string[]
addDeps
public addDeps(deps: ...string[]): void
Defines normal dependencies.
depsRequired
- Type: ...string[]
Names modules to install.
By default, the the dependency will
be installed in the next npx projen run and the version will be recorded
in your package.json file. You can upgrade manually or using yarn add/upgrade. If you wish to specify a version range use this syntax:
module@^7.
addDevDeps
public addDevDeps(deps: ...string[]): void
Defines development/test dependencies.
depsRequired
- Type: ...string[]
Names modules to install.
By default, the the dependency will
be installed in the next npx projen run and the version will be recorded
in your package.json file. You can upgrade manually or using yarn add/upgrade. If you wish to specify a version range use this syntax:
module@^7.
addFields
public addFields(fields: {[ key: string ]: any}): void
Directly set fields in package.json.
fieldsRequired
- Type: {[ key: string ]: any}
The fields to set.
addKeywords
public addKeywords(keywords: ...string[]): void
Adds keywords to package.json (deduplicated).
keywordsRequired
- Type: ...string[]
The keywords to add.
addPeerDeps
public addPeerDeps(deps: ...string[]): void
Defines peer dependencies.
When adding peer dependencies, a devDependency will also be added on the pinned version of the declared peer. This will ensure that you are testing your code against the minimum version required from your consumers.
depsRequired
- Type: ...string[]
Names modules to install.
By default, the the dependency will
be installed in the next npx projen run and the version will be recorded
in your package.json file. You can upgrade manually or using yarn add/upgrade. If you wish to specify a version range use this syntax:
module@^7.
addScripts
public addScripts(scripts: {[ key: string ]: string}): void
Replaces the contents of multiple npm package.json scripts.
scriptsRequired
- Type: {[ key: string ]: string}
The scripts to set.
addTestCommand
addTestCommandpublic addTestCommand(commands: ...string[]): void
DEPRECATED.
commandsRequired
- Type: ...string[]
hasScript
hasScriptpublic hasScript(name: string): boolean
Indicates if a script by the name name is defined.
nameRequired
- Type: string
The name of the script.
removeScript
public removeScript(name: string): void
Removes the npm script (always successful).
nameRequired
- Type: string
The name of the script.
renderWorkflowSetup
public renderWorkflowSetup(options?: RenderWorkflowSetupOptions): JobStep[]
Returns the set of workflow steps which should be executed to bootstrap a workflow.
optionsOptional
Options.
setScript
public setScript(name: string, command: string): void
Replaces the contents of an npm package.json script.
nameRequired
- Type: string
The script name.
commandRequired
- Type: string
The command to execute.
Static Functions
| Name | Description |
|---|---|
| Checks if x is a construct. |
| Test whether the given construct is a project. |
| Find the closest ancestor project for given construct. |
isConstruct
import { javascript } from 'projen'
javascript.NodeProject.isConstruct(x: any)
Checks if x is a construct.
Use this method instead of instanceof to properly detect Construct
instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on
disk are seen as independent, completely different libraries. As a
consequence, the class Construct in each copy of the constructs library
is seen as a different class, and an instance of one class will not test as
instanceof the other class. npm install will not create installations
like this, but users may manually symlink construct libraries together or
use a monorepo tool: in those cases, multiple copies of the constructs
library can be accidentally installed, and instanceof will behave
unpredictably. It is safest to avoid using instanceof, and using
this type-testing method instead.
xRequired
- Type: any
Any object.
isProject
import { javascript } from 'projen'
javascript.NodeProject.isProject(x: any)
Test whether the given construct is a project.
xRequired
- Type: any
of
import { javascript } from 'projen'
javascript.NodeProject.of(construct: IConstruct)
Find the closest ancestor project for given construct.
When given a project, this it the project itself.
constructRequired
- Type: constructs.IConstruct
Properties
| Name | Type | Description |
|---|---|---|
| constructs.Node | The tree node. |
| projen.Task | No description. |
| boolean | Whether to commit the managed files by default. |
| projen.Task | No description. |
| projen.Component[] | Returns all the components within this project. |
| projen.Dependencies | Project dependencies. |
| boolean | Whether or not the project is being ejected. |
| projen.FileBase[] | All files in this project. |
| projen.GitAttributesFile | The .gitattributes file for this repository. |
| projen.IgnoreFile | .gitignore. |
| projen.Logger | Logging utilities. |
| string | Project name. |
| string | Absolute output directory of this project. |
| projen.Task | No description. |
| projen.Task | No description. |
| projen.Task | No description. |
| projen.ProjectBuild | Manages the build process of the project. |
| string | The command to use in order to run the projen CLI. |
| projen.Project | The root project. |
| projen.Project[] | Returns all the subprojects within this project. |
| projen.Tasks | Project tasks. |
| projen.Task | No description. |
| projen.Task | This is the "default" task, the one that executes "projen". |
| projen.InitProject | The options used when this project is bootstrapped via projen new. |
| projen.Project | A parent project. |
| projen.ProjectType | No description. |
| projen.github.AutoApprove | Auto approve set up for this project. |
| projen.vscode.DevContainer | Access for .devcontainer.json (used for GitHub Codespaces). |
| projen.github.GitHub | Access all github components. |
| projen.Gitpod | Access for Gitpod. |
| projen.vscode.VsCode | Access all VSCode components. |
| boolean | No description. |
| string | The build output directory. |
| string | The location of the npm tarball after build (${artifactsDirectory}/js). |
| | No description. |
| string | No description. |
| any | No description. |
| | The .npmrc file. |
| | API for managing the node package. |
| | The package manager to use. |
| string | The command to use to run scripts (e.g. yarn run or npm run depends on the package manager). |
| projen.github.AutoMerge | Component that sets up mergify for merging approved pull requests. |
| | No description. |
| projen.build.BuildWorkflow | The PR build GitHub workflow. |
| string | The job ID of the build workflow. |
| | The Jest configuration (if enabled). |
| string | Maximum node version supported by this package. |
| string | The minimum node version required by this package to function. |
| projen.IgnoreFile | The .npmignore file. |
| | No description. |
| projen.release.Publisher | Package publisher. |
| projen.release.Release | Release management. |
| | The upgrade workflow. |
nodeRequired
public readonly node: Node;
- Type: constructs.Node
The tree node.
buildTaskRequired
public readonly buildTask: Task;
- Type: projen.Task
commitGeneratedRequired
public readonly commitGenerated: boolean;
- Type: boolean
Whether to commit the managed files by default.
compileTaskRequired
public readonly compileTask: Task;
- Type: projen.Task
componentsRequired
public readonly components: Component[];
- Type: projen.Component[]
Returns all the components within this project.
depsRequired
public readonly deps: Dependencies;
- Type: projen.Dependencies
Project dependencies.
ejectedRequired
public readonly ejected: boolean;
- Type: boolean
Whether or not the project is being ejected.
filesRequired
public readonly files: FileBase[];
- Type: projen.FileBase[]
All files in this project.
gitattributesRequired
public readonly gitattributes: GitAttributesFile;
- Type: projen.GitAttributesFile
The .gitattributes file for this repository.
gitignoreRequired
public readonly gitignore: IgnoreFile;
- Type: projen.IgnoreFile
.gitignore.
loggerRequired
public readonly logger: Logger;
- Type: projen.Logger
Logging utilities.
nameRequired
public readonly name: string;
- Type: string
Project name.
outdirRequired
public readonly outdir: string;
- Type: string
Absolute output directory of this project.
packageTaskRequired
public readonly packageTask: Task;
- Type: projen.Task
postCompileTaskRequired
public readonly postCompileTask: Task;
- Type: projen.Task
preCompileTaskRequired
public readonly preCompileTask: Task;
- Type: projen.Task
projectBuildRequired
public readonly projectBuild: ProjectBuild;
- Type: projen.ProjectBuild
Manages the build process of the project.
projenCommandRequired
public readonly projenCommand: string;
- Type: string
The command to use in order to run the projen CLI.
rootRequired
public readonly root: Project;
- Type: projen.Project
The root project.
subprojectsRequired
public readonly subprojects: Project[];
- Type: projen.Project[]
Returns all the subprojects within this project.
tasksRequired
public readonly tasks: Tasks;
- Type: projen.Tasks
Project tasks.
testTaskRequired
public readonly testTask: Task;
- Type: projen.Task
defaultTaskOptional
public readonly defaultTask: Task;
- Type: projen.Task
This is the "default" task, the one that executes "projen".
Undefined if the project is being ejected.
initProjectOptional
public readonly initProject: InitProject;
- Type: projen.InitProject
The options used when this project is bootstrapped via projen new.
It includes the original set of options passed to the CLI and also the JSII FQN of the project type.
parentOptional
public readonly parent: Project;
- Type: projen.Project
A parent project.
If undefined, this is the root project.
projectTypeRequired
public readonly projectType: ProjectType;
- Type: projen.ProjectType
autoApproveOptional
public readonly autoApprove: AutoApprove;
- Type: projen.github.AutoApprove
Auto approve set up for this project.
devContainerOptional
public readonly devContainer: DevContainer;
- Type: projen.vscode.DevContainer
Access for .devcontainer.json (used for GitHub Codespaces).
This will be undefined if devContainer boolean is false
githubOptional
public readonly github: GitHub;
- Type: projen.github.GitHub
Access all github components.
This will be undefined for subprojects.
gitpodOptional
public readonly gitpod: Gitpod;
- Type: projen.Gitpod
Access for Gitpod.
This will be undefined if gitpod boolean is false
vscodeOptional
public readonly vscode: VsCode;
- Type: projen.vscode.VsCode
Access all VSCode components.
This will be undefined for subprojects.
allowLibraryDependenciesRequired
allowLibraryDependencies- Deprecated: use
package.allowLibraryDependencies
public readonly allowLibraryDependencies: boolean;
- Type: boolean
artifactsDirectoryRequired
public readonly artifactsDirectory: string;
- Type: string
The build output directory.
An npm tarball will be created under the js
subdirectory. For example, if this is set to dist (the default), the npm
tarball will be placed under dist/js/boom-boom-1.2.3.tg.
artifactsJavascriptDirectoryRequired
public readonly artifactsJavascriptDirectory: string;
- Type: string
The location of the npm tarball after build (${artifactsDirectory}/js).
bundlerRequired
public readonly bundler: Bundler;
- Type: Bundler
entrypointRequired
entrypoint- Deprecated: use
package.entrypoint
public readonly entrypoint: string;
- Type: string
manifestRequired
manifest- Deprecated: use
package.addField(x, y)
public readonly manifest: any;
- Type: any
npmrcRequired
public readonly npmrc: NpmConfig;
- Type: NpmConfig
The .npmrc file.
packageRequired
public readonly package: NodePackage;
- Type: NodePackage
API for managing the node package.
packageManagerRequired
packageManager- Deprecated: use
package.packageManager
public readonly packageManager: NodePackageManager;
- Type: NodePackageManager
The package manager to use.
runScriptCommandRequired
public readonly runScriptCommand: string;
- Type: string
The command to use to run scripts (e.g. yarn run or npm run depends on the package manager).
autoMergeOptional
public readonly autoMerge: AutoMerge;
- Type: projen.github.AutoMerge
Component that sets up mergify for merging approved pull requests.
biomeOptional
public readonly biome: Biome;
- Type: Biome
buildWorkflowOptional
public readonly buildWorkflow: BuildWorkflow;
- Type: projen.build.BuildWorkflow
The PR build GitHub workflow.
undefined if buildWorkflow is disabled.
buildWorkflowJobIdOptional
public readonly buildWorkflowJobId: string;
- Type: string
The job ID of the build workflow.
jestOptional
public readonly jest: Jest;
- Type: Jest
The Jest configuration (if enabled).
maxNodeVersionOptional
public readonly maxNodeVersion: string;
- Type: string
Maximum node version supported by this package.
The value indicates the package is incompatible with newer versions.
minNodeVersionOptional
public readonly minNodeVersion: string;
- Type: string
The minimum node version required by this package to function.
This value indicates the package is incompatible with older versions.
npmignoreOptional
public readonly npmignore: IgnoreFile;
- Type: projen.IgnoreFile
The .npmignore file.
prettierOptional
public readonly prettier: Prettier;
- Type: Prettier
publisherOptional
publisher- Deprecated: use
release.publisher.
public readonly publisher: Publisher;
- Type: projen.release.Publisher
Package publisher.
This will be undefined if the project does not have a
release workflow.
releaseOptional
public readonly release: Release;
- Type: projen.release.Release
Release management.
upgradeWorkflowOptional
public readonly upgradeWorkflow: UpgradeDependencies;
- Type: UpgradeDependencies
The upgrade workflow.
Constants
| Name | Type | Description |
|---|---|---|
| string | The name of the default task (the task executed when projen is run without arguments). |
DEFAULT_TASKRequired
public readonly DEFAULT_TASK: string;
- Type: string
The name of the default task (the task executed when projen is run without arguments).
Normally this task should synthesize the project files.
NpmConfig
File representing the local NPM config in .npmrc.
Initializers
import { javascript } from 'projen'
new javascript.NpmConfig(project: NodeProject, options?: NpmConfigOptions)
| Name | Type | Description |
|---|---|---|
| | No description. |
| | No description. |
projectRequired
- Type: NodeProject
optionsOptional
- Type: NpmConfigOptions
Methods
| Name | Description |
|---|---|
| Returns a string representation of this construct. |
| Called after synthesis. |
| Called before synthesis. |
| Synthesizes files to the project output directory. |
| configure a generic property. |
| configure a scoped registry. |
toString
public toString(): string
Returns a string representation of this construct.
postSynthesize
public postSynthesize(): void
Called after synthesis.
Order is not guaranteed.
preSynthesize
public preSynthesize(): void
Called before synthesis.
synthesize
public synthesize(): void
Synthesizes files to the project output directory.
addConfig
public addConfig(name: string, value: string): void
configure a generic property.
nameRequired
- Type: string
the name of the property.
valueRequired
- Type: string
the value of the property.
addRegistry
public addRegistry(url: string, scope?: string): void
configure a scoped registry.