import type * as d from '../../declarations' ; import { basename } from 'path' ; import { isString , unique } from '@utils' ; import { isOutputTargetDocsJson , isOutputTargetStats , isOutputTargetDocsVscode } from '../output-targets/output-utils' ; export const filesChanged = ( buildCtx ) => { return unique ( [ ... buildCtx . filesUpdated , ... buildCtx . filesAdded , ... buildCtx . filesDeleted ] ) . sort ( ) ; } ; export const scriptsAdded = ( buildCtx ) => { return buildCtx . filesAdded . filter ( ( f ) => { return SCRIPT_EXT . some ( ( ext ) => f . endsWith ( ext . toLowerCase ( ) ) ) ; } ) . map ( ( f ) => basename ( f ) ) ; } ; export const scriptsDeleted = ( buildCtx ) => { return buildCtx . filesDeleted . filter ( ( f ) => { return SCRIPT_EXT . some ( ( ext ) => f . endsWith ( ext . toLowerCase ( ) ) ) ; } ) . map ( ( f ) => basename ( f ) ) ; } ; export const hasScriptChanges = ( buildCtx ) => { return buildCtx . filesChanged . some ( ( f ) => { const ext = getExt ( f ) ; return SCRIPT_EXT . includes ( ext ) ; } ) ; } ; export const hasStyleChanges = ( buildCtx ) => { return buildCtx . filesChanged . some ( ( f ) => { const ext = getExt ( f ) ; return STYLE_EXT . includes ( ext ) ; } ) ; } ; const getExt = ( filePath ) => filePath . split ( '.' ) . pop ( ) . toLowerCase ( ) ; const SCRIPT_EXT = [ 'ts' , 'tsx' , 'js' , 'jsx' ] ; export const isScriptExt = ( ext ) => SCRIPT_EXT . includes ( ext ) ; const STYLE_EXT = [ 'css' , 'scss' , 'sass' , 'pcss' , 'styl' , 'stylus' , 'less' ] ; export const isStyleExt = ( ext ) => STYLE_EXT . includes ( ext ) ; export const hasHtmlChanges = ( config , buildCtx ) => { const anyHtmlChanged = buildCtx . filesChanged . some ( ( f ) => f . toLowerCase ( ) . endsWith ( '.html' ) ) ; if ( anyHtmlChanged ) { return true ; } const srcIndexHtmlChanged = buildCtx . filesChanged . some ( ( fileChanged ) => { return fileChanged === config . srcIndexHtml ; } ) ; return srcIndexHtmlChanged ; } ; export const updateCacheFromRebuild = ( compilerCtx , buildCtx ) => { buildCtx . filesChanged . forEach ( ( filePath ) => { compilerCtx . fs . clearFileCache ( filePath ) ; } ) ; buildCtx . dirsAdded . forEach ( ( dirAdded ) => { compilerCtx . fs . clearDirCache ( dirAdded ) ; } ) ; buildCtx . dirsDeleted . forEach ( ( dirDeleted ) => { compilerCtx . fs . clearDirCache ( dirDeleted ) ; } ) ; } ; export const isWatchIgnorePath = ( config , path ) => { if ( isString ( path ) ) { const isWatchIgnore = ( config . watchIgnoredRegex as RegExp [ ] ) . some ( ( reg ) => reg . test ( path ) ) ; if ( isWatchIgnore ) { return true ; } const outputTargets = config . outputTargets ; const ignoreFiles = [ ... outputTargets . filter ( isOutputTargetDocsJson ) . map ( ( o ) => o . file ) , ... outputTargets . filter ( isOutputTargetDocsJson ) . map ( ( o ) => o . typesFile ) , ... outputTargets . filter ( isOutputTargetStats ) . map ( ( o ) => o . file ) , ... outputTargets . filter ( isOutputTargetDocsVscode ) . map ( ( o ) => o . file ) , ] ; if ( ignoreFiles . includes ( path ) ) { return true ; } } return false ; } ;