javascript
Submodule
Constructs
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. |
project
Required
- Type: projen.Project
options
Optional
- 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.
entrypoint
Required
- Type: string
The relative path of the artifact within the project.
options
Required
- 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.
x
Required
- Type: any
Any object.
isComponent
import { javascript } from 'projen'
javascript.Bundler.isComponent(x: any)
Test whether the given construct is a component.
x
Required
- 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.
project
Required
- 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). |
node
Required
public readonly node: Node;
- Type: constructs.Node
The tree node.
project
Required
public readonly project: Project;
- Type: projen.Project
bundledir
Required
public readonly bundledir: string;
- Type: string
Root bundle directory.
bundleTask
Required
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.
esbuildVersion
Optional
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. |
project
Required
- Type: NodeProject
options
Required
- 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.
extendList
Required
- Type: ...string[]
The list of "extends" to add.
addIgnorePattern
public addIgnorePattern(pattern: string): void
Do not lint these files.
pattern
Required
- Type: string
addLintPattern
public addLintPattern(pattern: string): void
Add a file, glob pattern or directory with source files to lint (e.g. [ "src" ]).
pattern
Required
- Type: string
addOverride
public addOverride(override: EslintOverride): void
Add an eslint override.
override
Required
- Type: EslintOverride
addPlugins
public addPlugins(plugins: ...string[]): void
Adds an eslint plugin.
plugins
Required
- Type: ...string[]
The names of plugins to add.
addRules
public addRules(rules: {[ key: string ]: any}): void
Add an eslint rule.
rules
Required
- Type: {[ key: string ]: any}
allowDevDeps
public allowDevDeps(pattern: string): void
Add a glob file pattern which allows importing dev dependencies.
pattern
Required
- 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.
x
Required
- Type: any
Any object.
isComponent
import { javascript } from 'projen'
javascript.Eslint.isComponent(x: any)
Test whether the given construct is a component.
x
Required
- 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.
project
Required
- 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. |
node
Required
public readonly node: Node;
- Type: constructs.Node
The tree node.
project
Required
public readonly project: Project;
- Type: projen.Project
config
Required
public readonly config: any;
- Type: any
Direct access to the eslint configuration (escape hatch).
eslintTask
Required
public readonly eslintTask: Task;
- Type: projen.Task
eslint task.
file
Required
public readonly file: ObjectFile;
- Type: projen.ObjectFile
The underlying config file.
ignorePatterns
Required
public readonly ignorePatterns: string[];
- Type: string[]
File patterns that should not be linted.
lintPatterns
Required
public readonly lintPatterns: string[];
- Type: string[]
Returns an immutable copy of the lintPatterns being used by this eslint configuration.
overrides
Required
public readonly overrides: EslintOverride[];
- Type: EslintOverride[]
eslint overrides.
rules
Required
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(project: NodeProject, options?: JestOptions)
Name | Type | Description |
---|---|---|
|
| No description. |
|
| No description. |
project
Required
- Type: NodeProject
options
Optional
- 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
pattern
Required
- 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.
moduleNameMapperAdditions
Required
- 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.
modulePaths
Required
- Type: ...string[]
An array of absolute paths to additional locations to search when resolving modules *.
addReporter
public addReporter(reporter: JestReporter): void
reporter
Required
- Type: JestReporter
addRoots
public addRoots(roots: ...string[]): void
Adds one or more roots to Jest's configuration.
roots
Required
- 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.
file
Required
- Type: string
File path to setup file.
addSetupFileAfterEnv
public addSetupFileAfterEnv(file: string): void
Adds a a setup file to Jest's setupFilesAfterEnv configuration.
file
Required
- Type: string
File path to setup file.
addSnapshotResolver
public addSnapshotResolver(file: string): void
file
Required
- Type: string
addTestMatch
public addTestMatch(pattern: string): void
Adds a test match pattern.
pattern
Required
- Type: string
glob pattern to match for tests.
addWatchIgnorePattern
public addWatchIgnorePattern(pattern: string): void
Adds a watch ignore pattern.
pattern
Required
- Type: string
The pattern (regular expression).
discoverTestMatchPatternsForDirs
public discoverTestMatchPatternsForDirs(dirs: string[], options?: JestDiscoverTestMatchPatternsForDirsOptions): void
Build standard test match patterns for a directory.
dirs
Required
- Type: string[]
The directories to add test matches for.
Matches any folder if not specified or an empty array.
options
Optional
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.
x
Required
- Type: any
Any object.
isComponent
import { javascript } from 'projen'
javascript.Jest.isComponent(x: any)
Test whether the given construct is a component.
x
Required
- 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.
project
Required
- Type: projen.Project
Properties
Name | Type | Description |
---|---|---|
| constructs.Node | The tree node. |
| projen.Project | No description. |
| any | Escape hatch. |
| string | Jest version, including @ symbol, like @^29 . |
| projen.JsonFile | Jest config file. |
node
Required
public readonly node: Node;
- Type: constructs.Node
The tree node.
project
Required
public readonly project: Project;
- Type: projen.Project
config
Required
public readonly config: any;
- Type: any
Escape hatch.
jestVersion
Required
public readonly jestVersion: string;
- Type: string
Jest version, including @
symbol, like @^29
.
file
Optional
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. |
scope
Required
- Type: constructs.Construct
options
Required
- 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.
x
Required
- Type: any
Any object.
isComponent
import { javascript } from 'projen'
javascript.LicenseChecker.isComponent(x: any)
Test whether the given construct is a component.
x
Required
- Type: any
Properties
Name | Type | Description |
---|---|---|
| constructs.Node | The tree node. |
| projen.Project | No description. |
| projen.Task | No description. |
node
Required
public readonly node: Node;
- Type: constructs.Node
The tree node.
project
Required
public readonly project: Project;
- Type: projen.Project
task
Required
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. |
project
Required
- Type: projen.Project
options
Optional
- 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
bins
Required
- 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
.
deps
Required
- 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.
deps
Required
- 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.
deps
Required
- 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.
engine
Required
- Type: string
The engine (e.g. node
).
version
Required
- Type: string
The semantic version requirement (e.g. ^10
).
addField
public addField(name: string, value: any): void
Directly set fields in package.json
.
name
Required
- Type: string
field name.
value
Required
- Type: any
field value.
addKeywords
public addKeywords(keywords: ...string[]): void
Adds keywords to package.json (deduplicated).
keywords
Required
- 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.
resolutions
Required
- 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.
deps
Required
- 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.
version
Required
- Type: string
Package version.
hasScript
hasScript
public hasScript(name: string): boolean
Indicates if a script by the given name is defined.
name
Required
- Type: string
The name of the script.
removeScript
public removeScript(name: string): void
Removes an npm script (always successful).
name
Required
- Type: string
The name of the script.
setScript
public setScript(name: string, command: string): void
Add a npm package.json script.
name
Required
- Type: string
The script name.
command
Required
- Type: string
The command to execute.
tryResolveDependencyVersion
public tryResolveDependencyVersion(dependencyName: string): string
Attempt to resolve the currently installed version for a given dependency.
dependencyName
Required
- 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.
x
Required
- Type: any
Any object.
isComponent
import { javascript } from 'projen'
javascript.NodePackage.isComponent(x: any)
Test whether the given construct is a component.
x
Required
- 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.