dockerfile-ast
- Version 0.6.1
- Published
- 237 kB
- 2 dependencies
- MIT license
Install
npm i dockerfile-ast
yarn add dockerfile-ast
pnpm add dockerfile-ast
Overview
Parse a Dockerfile into an array of instructions and comments.
Index
Variables
Classes
Interfaces
Enums
Namespaces
Variables
variable DefaultVariables
const DefaultVariables: string[];
Classes
class Add
class Add extends JSONInstruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
method stopSearchingForFlags
stopSearchingForFlags: (argument: string) => boolean;
class Arg
class Arg extends PropertyInstruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
method getProperty
getProperty: () => Property | null;
Returns the variable defined by this ARG. This may be null if this ARG instruction is malformed and has no variable declaration.
class Argument
class Argument {}
class Cmd
class Cmd extends JSONInstruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
class Comment
class Comment extends Line {}
constructor
constructor(document: TextDocument, range: Range);
method getContent
getContent: () => string;
Returns the content of this comment. This excludes leading and trailing whitespace as well as the # symbol. If the comment only consists of whitespace, the empty string will be returned.
method getContentRange
getContentRange: () => Range | null;
Returns a range that includes the content of the comment excluding any leading and trailing whitespace as well as the # symbol. May return null if the comment only consists of whitespace characters.
method toString
toString: () => string;
class Copy
class Copy extends JSONInstruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
method getFromFlag
getFromFlag: () => Flag | null;
method getHeredocs
getHeredocs: () => Heredoc[];
Returns there here-documents that are defined in this RUN instruction.
This API is experimental and subject to change.
method stopSearchingForFlags
stopSearchingForFlags: (argument: string) => boolean;
class Entrypoint
class Entrypoint extends JSONInstruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
class Env
class Env extends PropertyInstruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
method getProperties
getProperties: () => Property[];
class Flag
class Flag {}
constructor
constructor( document: TextDocument, range: Range, name: string, nameRange: Range, value: string, valueRange: any);
method getName
getName: () => string;
Returns the name of this flag. The name does not include the -- prefix. Thus, for HEALTHCHECK's --interval flag, interval is the flag's name and not --interval.
this flag's name
method getNameRange
getNameRange: () => Range;
Returns the range that encompasses the flag's name
the range containing the flag's name
method getOption
getOption: (name: string) => FlagOption | null;
method getOptions
getOptions: () => FlagOption[];
method getRange
getRange: () => Range;
Returns the range that encompasses this entire flag. This includes the -- prefix in the beginning to the last character of the flag's value (if it has been defined).
the entire range of this flag
method getValue
getValue: () => string | null;
Returns the value that has been set to this flag. May be null if the flag is invalid and has no value set like a --start-period. If the flag is instead a --start-period= with an equals sign then the flag's value is the empty string.
this flag's value if it has been defined, null otherwise
method getValueRange
getValueRange: () => Range | null;
Returns the range that encompasses this flag's value. If no value has been set then null will be returned.
the range containing this flag's value, or null if the flag has no value defined
method hasOptions
hasOptions: () => boolean;
method toString
toString: () => string;
class From
class From extends ModifiableInstruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
method getBuildStage
getBuildStage: () => string | null;
method getBuildStageRange
getBuildStageRange: () => Range | null;
method getImage
getImage: () => string | null;
method getImageDigest
getImageDigest: () => string | null;
method getImageDigestRange
getImageDigestRange: () => Range | null;
Returns the range in the document that the digest of the base image encompasses.
the base image's digest's range in the document, or null if no digest has been specified
method getImageName
getImageName: () => string | null;
Returns the name of the image that will be used as the base image.
the base image's name, or null if unspecified
method getImageNameRange
getImageNameRange: () => Range | null;
Returns the range that covers the name of the image used by this instruction.
the range of the name of this instruction's argument, or null if no image has been specified
method getImageRange
getImageRange: () => Range | null;
Returns the range that covers the image argument of this instruction. This includes the tag or digest of the image if it has been specified by the instruction.
the range of the image argument, or null if no image has been specified
method getImageTag
getImageTag: () => string | null;
method getImageTagRange
getImageTagRange: () => Range | null;
Returns the range in the document that the tag of the base image encompasses.
the base image's tag's range in the document, or null if no tag has been specified
method getPlatformFlag
getPlatformFlag: () => Flag | null;
method getRegistry
getRegistry: () => string | null;
method getRegistryRange
getRegistryRange: () => Range | null;
method stopSearchingForFlags
protected stopSearchingForFlags: (argument: string) => boolean;
class Healthcheck
class Healthcheck extends ModifiableInstruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
method getSubcommand
getSubcommand: () => Argument | null;
method stopSearchingForFlags
protected stopSearchingForFlags: (argument: string) => boolean;
class Heredoc
class Heredoc {}
Heredoc represents a here-document that has been embedded in a Dockerfile.
This API is experimental and subject to change.
constructor
constructor( startRange: Range, name: string, nameRange: Range, contentRange: Range, endRange: Range);
method getContentRange
getContentRange: () => Range | null;
Returns the range of the content of this here-document. This may be null if the here-document has no content because: - the start range is the only thing that was declared - the end range was declared immediately and there is no content
This API is experimental and subject to change.
method getDelimiterRange
getDelimiterRange: () => Range | null;
Returns the range of the here-document's name on a line that represents the end of the here-document.
This API is experimental and subject to change.
method getName
getName: () => string;
Returns the name of the here-document.
This API is experimental and subject to change.
method getNameRange
getNameRange: () => Range;
Returns the range of this here-document's name that is declared at the beginning of the here-document with the operator. If the here-document is initialized with <<EOT then the name range would encompass the latter three "EOT" characters.
This API is experimental and subject to change.
method getStartRange
getStartRange: () => Range;
Returns the range of the start operator and the name. If the here-document is initialized with <<EOT then the start range would encompass all five characters.
This API is experimental and subject to change.
class Instruction
class Instruction extends Line {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
property dockerfile
protected readonly dockerfile: Dockerfile;
property escapeChar
protected readonly escapeChar: string;
method getArguments
getArguments: () => Argument[];
method getArgumentsContent
getArgumentsContent: () => string | null;
method getArgumentsRange
getArgumentsRange: () => Range | null;
method getArgumentsRanges
getArgumentsRanges: () => Range[];
method getExpandedArguments
getExpandedArguments: () => Argument[];
method getHeredocs
protected getHeredocs: () => Heredoc[];
method getInstruction
getInstruction: () => string;
method getInstructionRange
getInstructionRange: () => Range;
method getKeyword
getKeyword: () => string;
method getRangeContent
protected getRangeContent: (range: Range | null) => string | null;
method getRawArgumentsContent
getRawArgumentsContent: () => string | null;
method getVariables
getVariables: () => Variable[];
method toString
toString: () => string;
class JSONArgument
class JSONArgument extends Argument {}
constructor
constructor(value: string, range: Range, jsonRange: Range);
method getJSONRange
getJSONRange: () => Range;
method getJSONValue
getJSONValue: () => string;
class JSONInstruction
class JSONInstruction extends ModifiableInstruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
method getClosingBracket
getClosingBracket: () => Argument | null;
method getJSONStrings
getJSONStrings: () => JSONArgument[];
method getOpeningBracket
getOpeningBracket: () => Argument | null;
method stopSearchingForFlags
protected stopSearchingForFlags: (_value: string) => boolean;
class Label
class Label extends PropertyInstruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
method getProperties
getProperties: () => Property[];
method getVariables
getVariables: () => Variable[];
class Line
class Line {}
constructor
constructor(document: TextDocument, range: Range);
property document
protected readonly document: TextDocument;
method getRange
getRange: () => Range;
method getTextContent
getTextContent: () => string;
method isAfter
isAfter: (line: Line) => boolean;
method isBefore
isBefore: (line: number) => boolean;
class ModifiableInstruction
abstract class ModifiableInstruction extends Instruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
method getArguments
getArguments: () => Argument[];
method getFlags
getFlags: () => Flag[];
method stopSearchingForFlags
protected abstract stopSearchingForFlags: (value: string) => boolean;
class Onbuild
class Onbuild extends Instruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
method getTrigger
getTrigger: () => string | null;
method getTriggerInstruction
getTriggerInstruction: () => Instruction | null;
method getTriggerRange
getTriggerRange: () => Range | null;
method getTriggerWord
getTriggerWord: () => string | null;
class ParserDirective
class ParserDirective extends Line {}
constructor
constructor( document: TextDocument, range: Range, nameRange: Range, valueRange: Range);
method getDirective
getDirective: () => Directive | null;
method getName
getName: () => string;
method getNameRange
getNameRange: () => Range;
method getValue
getValue: () => string;
method getValueRange
getValueRange: () => Range;
method toString
toString: () => string;
class Property
class Property {}
constructor
constructor( document: TextDocument, escapeChar: string, arg: Argument, arg2?: Argument);
method getAssignmentOperator
getAssignmentOperator: () => string | null;
Retrieves the operator used for delimiting between the name and value of this property. This will either be the "=" character or null if a character was not used or if this property has no value defined.
method getAssignmentOperatorRange
getAssignmentOperatorRange: () => Range | null;
method getName
getName: () => string;
method getNameRange
getNameRange: () => Range;
method getRange
getRange: () => Range;
method getUnescapedValue
getUnescapedValue: () => string | null;
Returns the value of this property including any enclosing single or double quotes and relevant escape characters. Escaped newlines and its associated contiguous whitespace characters however will not be returned as they are deemed to be uninteresting to clients trying to return a Dockerfile.
the unescaped value of this property or null if this property has no associated value
method getValue
getValue: () => string | null;
method getValueRange
getValueRange: () => Range | null;
class PropertyInstruction
abstract class PropertyInstruction extends Instruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
method getProperties
getProperties: () => Property[];
method getPropertyArguments
getPropertyArguments: () => Argument[];
class Run
class Run extends JSONInstruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
method getHeredocs
getHeredocs: () => Heredoc[];
Returns there here-documents that are defined in this RUN instruction.
This API is experimental and subject to change.
method stopSearchingForFlags
stopSearchingForFlags: (argument: string) => boolean;
class Shell
class Shell extends JSONInstruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
class Stopsignal
class Stopsignal extends Instruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
class User
class User extends Instruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
class Variable
class Variable {}
constructor
constructor( name: string, nameRange: Range, range: Range, modifier: string, modifierRange: any, substitutionParameter: string, substitutionRange: any, defined: boolean, buildVariable: boolean, stringValue: string);
method getModifier
getModifier: () => string | null;
Returns the modifier character that has been set for specifying how this variable should be expanded and resolved. If this variable is ${variable:+value} then the modifier character is '+'. Will be the empty string if the variable is declared as ${variable:}. Otherwise, will be null if this variable will not use variable substitution at all (such as ${variable} or $variable).
this variable's modifier character, or the empty string if it does not have one, or null if this variable will not use variable substitution
method getModifierRange
getModifierRange: () => Range | null;
method getName
getName: () => string;
method getNameRange
getNameRange: () => Range;
method getRange
getRange: () => Range;
Returns the range of the entire variable. This includes the symbols for the declaration of the variable such as the $, {, and } symbols.
the range in the document that this variable encompasses in its entirety
method getSubstitutionParameter
getSubstitutionParameter: () => string | null;
Returns the parameter that will be used for substitution if this variable uses modifiers to define how its value should be resolved. If this variable is ${variable:+value} then the substitution value will be 'value'. Will be the empty string if the variable is declared as ${variable:+} or some other variant where the only thing that follows the modifier character (excluding considerations of escape characters and so on) is the variable's closing bracket. May be null if this variable does not have a modifier character defined (such as ${variable} or $variable).
this variable's substitution parameter, or the empty string if it does not have one, or null if there is not one defined
method getSubstitutionRange
getSubstitutionRange: () => Range | null;
method isBuildVariable
isBuildVariable: () => boolean;
method isDefined
isDefined: () => boolean;
Returns whether this variable has been defined or not.
true if this variable has been defined, false otherwise
method isEnvironmentVariable
isEnvironmentVariable: () => boolean;
method toString
toString: () => string;
class Volume
class Volume extends JSONInstruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
class Workdir
class Workdir extends Instruction {}
constructor
constructor( document: TextDocument, range: Range, dockerfile: Dockerfile, escapeChar: string, instruction: string, instructionRange: Range);
method getAbsolutePath
getAbsolutePath: () => string | null | undefined;
Returns the absolute path that this instruction resolves to. The function will inspect prior WORKDIR instructions in the current image or another build stage in the Dockerfile to try to determine this.
the absolute path of the working directory, or null if this instruction has no arguments, or undefined if it cannot be determined because only relative paths could be found
method getPath
getPath: () => string | null;
Returns the path that has been defined. Note that this path may be absolute or relative depending on what was written in the instruction.
the working directory's path, or null if this instruction has no arguments
Interfaces
interface Dockerfile
interface Dockerfile extends ImageTemplate {}
method getAvailableWorkingDirectories
getAvailableWorkingDirectories: (line: number) => string[];
method getComments
getComments: () => Comment[];
method getContainingImage
getContainingImage: (position: Position) => ImageTemplate | null;
Returns the set of instructions that include the given position.
Parameter position
the position to search in the set of instructions that the given position is in, or null if the position is invalid and is not contained within the Dockerfile
method getDirective
getDirective: () => ParserDirective | null;
Deprecated
As of 0.0.18, replaced by getDirectives(). If there is more than one parser directive defined in the Dockerfile, the first one will be returned.
method getDirectives
getDirectives: () => ParserDirective[];
Retrieves the list of parser directives that have been defined in this Dockerfile. It will be in the order it was defined in the file with the first line of the file being the first directive in the returned array.
the list of parser directives defined in this Dockerfile in the order they are defined 0.0.18
method getEscapeCharacter
getEscapeCharacter: () => string;
method getInitialARGs
getInitialARGs: () => Arg[];
method resolveVariable
resolveVariable: (variable: string, line: number) => string | null | undefined;
Resolves a variable with the given name at the specified line to its value. If null is returned, then the variable has been defined but no value was given. If undefined is returned, then a variable with the given name has not been defined yet as of the given line.
Parameter variable
the name of the variable to resolve
Parameter line
the line number that the variable is on, zero-based the value of the variable as defined by an ARG or ENV instruction, or null if no value has been specified, or undefined if a variable with the given name has not been defined or if the document does not contain the given line number
interface ImageTemplate
interface ImageTemplate {}
method contains
contains: (position: Position) => boolean;
method getARGs
getARGs: () => Arg[];
method getAvailableVariables
getAvailableVariables: (line: number) => string[];
Retrieves an array of variable names that are valid at the given line in the Dockerfile (zero-based). If the line is outside the range of the parsed Dockerfile, an empty array will be returned.
Parameter line
the interested line, zero-based the array of variables that may be used by an instruction at the specified line
method getCMDs
getCMDs: () => Cmd[];
method getComments
getComments: () => Comment[];
method getCOPYs
getCOPYs: () => Copy[];
method getENTRYPOINTs
getENTRYPOINTs: () => Entrypoint[];
method getENVs
getENVs: () => Env[];
method getFROMs
getFROMs: () => From[];
method getHEALTHCHECKs
getHEALTHCHECKs: () => Healthcheck[];
method getInstructions
getInstructions: () => Instruction[];
method getOnbuildTriggers
getOnbuildTriggers: () => Instruction[];
method getRange
getRange: () => Range | null;
Enums
enum Directive
enum Directive { escape = 'escape', syntax = 'syntax',}
enum Keyword
enum Keyword { ADD = 'ADD', ARG = 'ARG', CMD = 'CMD', COPY = 'COPY', ENTRYPOINT = 'ENTRYPOINT', ENV = 'ENV', EXPOSE = 'EXPOSE', FROM = 'FROM', HEALTHCHECK = 'HEALTHCHECK', LABEL = 'LABEL', MAINTAINER = 'MAINTAINER', ONBUILD = 'ONBUILD', RUN = 'RUN', SHELL = 'SHELL', STOPSIGNAL = 'STOPSIGNAL', USER = 'USER', VOLUME = 'VOLUME', WORKDIR = 'WORKDIR',}
member ADD
ADD = 'ADD'
member ARG
ARG = 'ARG'
member CMD
CMD = 'CMD'
member COPY
COPY = 'COPY'
member ENTRYPOINT
ENTRYPOINT = 'ENTRYPOINT'
member ENV
ENV = 'ENV'
member EXPOSE
EXPOSE = 'EXPOSE'
member FROM
FROM = 'FROM'
member HEALTHCHECK
HEALTHCHECK = 'HEALTHCHECK'
member LABEL
LABEL = 'LABEL'
member MAINTAINER
MAINTAINER = 'MAINTAINER'
member ONBUILD
ONBUILD = 'ONBUILD'
member RUN
RUN = 'RUN'
member SHELL
SHELL = 'SHELL'
member STOPSIGNAL
STOPSIGNAL = 'STOPSIGNAL'
member USER
USER = 'USER'
member VOLUME
VOLUME = 'VOLUME'
member WORKDIR
WORKDIR = 'WORKDIR'
Namespaces
namespace DockerfileParser
namespace DockerfileParser {}
function parse
parse: (content: string) => Dockerfile;
Package Files (30)
- lib/argument.d.ts
- lib/comment.d.ts
- lib/flag.d.ts
- lib/heredoc.d.ts
- lib/instruction.d.ts
- lib/instructions/add.d.ts
- lib/instructions/arg.d.ts
- lib/instructions/cmd.d.ts
- lib/instructions/copy.d.ts
- lib/instructions/entrypoint.d.ts
- lib/instructions/env.d.ts
- lib/instructions/from.d.ts
- lib/instructions/healthcheck.d.ts
- lib/instructions/label.d.ts
- lib/instructions/onbuild.d.ts
- lib/instructions/run.d.ts
- lib/instructions/shell.d.ts
- lib/instructions/stopsignal.d.ts
- lib/instructions/user.d.ts
- lib/instructions/volume.d.ts
- lib/instructions/workdir.d.ts
- lib/jsonArgument.d.ts
- lib/jsonInstruction.d.ts
- lib/line.d.ts
- lib/main.d.ts
- lib/modifiableInstruction.d.ts
- lib/parserDirective.d.ts
- lib/property.d.ts
- lib/propertyInstruction.d.ts
- lib/variable.d.ts
Dependencies (2)
Dev Dependencies (5)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/dockerfile-ast
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/dockerfile-ast)
- HTML<a href="https://www.jsdocs.io/package/dockerfile-ast"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 4224 ms. - Missing or incorrect documentation? Open an issue for this package.