aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 5.62 kB
JavaScript
"use strict";var _a,_b,_c,_d;Object.defineProperty(exports,"__esModule",{value:!0}),exports.DockerIgnoreStrategy=exports.GitIgnoreStrategy=exports.GlobIgnoreStrategy=exports.IgnoreStrategy=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var path=()=>{var tmp=require("path");return path=()=>tmp,tmp},dockerignore_1=()=>{var tmp=require("@balena/dockerignore");return dockerignore_1=()=>tmp,tmp},ignore_1=()=>{var tmp=require("ignore");return ignore_1=()=>tmp,tmp},options_1=()=>{var tmp=require("./options");return options_1=()=>tmp,tmp},errors_1=()=>{var tmp=require("../errors");return errors_1=()=>tmp,tmp},minimatch=()=>{var tmp=require("minimatch");return minimatch=()=>tmp,tmp};class IgnoreStrategy{static glob(absoluteRootPath,patterns){return new GlobIgnoreStrategy(absoluteRootPath,patterns)}static git(absoluteRootPath,patterns){return new GitIgnoreStrategy(absoluteRootPath,patterns)}static docker(absoluteRootPath,patterns){return new DockerIgnoreStrategy(absoluteRootPath,patterns)}static fromCopyOptions(options,absoluteRootPath){try{jsiiDeprecationWarnings().aws_cdk_lib_CopyOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromCopyOptions),error}const ignoreMode=options.ignoreMode||options_1().IgnoreMode.GLOB,exclude=options.exclude||[];switch(ignoreMode){case options_1().IgnoreMode.GLOB:return this.glob(absoluteRootPath,exclude);case options_1().IgnoreMode.GIT:return this.git(absoluteRootPath,exclude);case options_1().IgnoreMode.DOCKER:return this.docker(absoluteRootPath,exclude)}}completelyIgnores(absoluteDirectoryPath){return this.ignores(absoluteDirectoryPath)}}exports.IgnoreStrategy=IgnoreStrategy,_a=JSII_RTTI_SYMBOL_1,IgnoreStrategy[_a]={fqn:"aws-cdk-lib.IgnoreStrategy",version:"2.219.0"};class GlobIgnoreStrategy extends IgnoreStrategy{constructor(absoluteRootPath,patterns){if(super(),!path().isAbsolute(absoluteRootPath))throw new(errors_1()).UnscopedValidationError("GlobIgnoreStrategy expects an absolute file path");this.absoluteRootPath=absoluteRootPath,this.patterns=patterns}add(pattern){this.patterns.push(pattern)}ignores(absoluteFilePath){if(!path().isAbsolute(absoluteFilePath))throw new(errors_1()).UnscopedValidationError("GlobIgnoreStrategy.ignores() expects an absolute path");let relativePath=path().relative(this.absoluteRootPath,absoluteFilePath),excludeOutput=!1;for(const pattern of this.patterns){const negate=pattern.startsWith("!"),match=minimatch()(relativePath,pattern,{matchBase:!0,flipNegate:!0});!negate&&match&&(excludeOutput=!0),negate&&match&&(excludeOutput=!1)}return excludeOutput}}exports.GlobIgnoreStrategy=GlobIgnoreStrategy,_b=JSII_RTTI_SYMBOL_1,GlobIgnoreStrategy[_b]={fqn:"aws-cdk-lib.GlobIgnoreStrategy",version:"2.219.0"};class GitIgnoreStrategy extends IgnoreStrategy{constructor(absoluteRootPath,patterns){if(super(),!path().isAbsolute(absoluteRootPath))throw new(errors_1()).UnscopedValidationError("GitIgnoreStrategy expects an absolute file path");this.absoluteRootPath=absoluteRootPath,this.ignore=(0,ignore_1().default)().add(patterns)}add(pattern){this.ignore.add(pattern)}ignores(absoluteFilePath){if(!path().isAbsolute(absoluteFilePath))throw new(errors_1()).UnscopedValidationError("GitIgnoreStrategy.ignores() expects an absolute path");let relativePath=path().relative(this.absoluteRootPath,absoluteFilePath);return this.ignore.ignores(relativePath)}completelyIgnores(absoluteDirectoryPath){if(!path().isAbsolute(absoluteDirectoryPath))throw new(errors_1()).UnscopedValidationError("GitIgnoreStrategy.completelyIgnores() expects an absolute path");const relativePath=path().relative(this.absoluteRootPath,absoluteDirectoryPath),relativePathWithSep=relativePath.endsWith(path().sep)?relativePath:relativePath+path().sep;return this.ignore.ignores(relativePathWithSep)}}exports.GitIgnoreStrategy=GitIgnoreStrategy,_c=JSII_RTTI_SYMBOL_1,GitIgnoreStrategy[_c]={fqn:"aws-cdk-lib.GitIgnoreStrategy",version:"2.219.0"};class DockerIgnoreStrategy extends IgnoreStrategy{constructor(absoluteRootPath,patterns){if(super(),this.negativeIgnoreRegex=/^\s*(\!|\/\!)(.*)/,!path().isAbsolute(absoluteRootPath))throw new(errors_1()).UnscopedValidationError("DockerIgnoreStrategy expects an absolute file path");this.absoluteRootPath=absoluteRootPath,this.completeIgnore=(0,dockerignore_1().default)(),this.ignore=(0,dockerignore_1().default)();for(const pattern of patterns)this.add(pattern)}completelyAdd(pattern){this.completeIgnore.add(pattern);const negativeMatch=pattern.match(this.negativeIgnoreRegex);if(negativeMatch!==null){let dirname=negativeMatch[2];for(;dirname=path().dirname(dirname),!(dirname==="/"||dirname===".");)this.completeIgnore.add(negativeMatch[1]+dirname)}}add(pattern){this.ignore.add(pattern),this.completelyAdd(pattern)}getRelativePath(absoluteFilePath){if(!path().isAbsolute(absoluteFilePath))throw new(errors_1()).UnscopedValidationError("DockerIgnoreStrategy.ignores() expects an absolute path");return path().relative(this.absoluteRootPath,absoluteFilePath)}ignores(absoluteFilePath){return this.ignore.ignores(this.getRelativePath(absoluteFilePath))}completelyIgnores(absoluteDirectoryPath){const relativePath=this.getRelativePath(absoluteDirectoryPath);return this.ignore.ignores(relativePath)&&this.completeIgnore.ignores(relativePath)}}exports.DockerIgnoreStrategy=DockerIgnoreStrategy,_d=JSII_RTTI_SYMBOL_1,DockerIgnoreStrategy[_d]={fqn:"aws-cdk-lib.DockerIgnoreStrategy",version:"2.219.0"};