@@ -17,15 +17,6 @@ import { isSubDirectory } from './path';
1717 */
1818export const DEFAULT_ASSET_IGNORE = [ '**/.gitkeep' , '**/.DS_Store' , '**/Thumbs.db' ] as const ;
1919
20- function resolveDestination ( output : string , filePath : string , flatten ?: boolean ) : string {
21- const destination = path . join ( output , flatten ? path . basename ( filePath ) : filePath ) ;
22- if ( destination === '..' || destination . startsWith ( `..${ path . sep } ` ) ) {
23- throw new Error ( 'An asset cannot be written to a location outside of the output path.' ) ;
24- }
25-
26- return destination ;
27- }
28-
2920export async function resolveAssets (
3021 entries : {
3122 glob : string ;
@@ -47,24 +38,19 @@ export async function resolveAssets(
4738 if ( ! entry . ignore ?. length && ! isDynamicPattern ( entry . glob ) ) {
4839 const src = path . join ( cwd , entry . glob ) ;
4940 if ( isSubDirectory ( cwd , src ) ) {
50- let stats ;
5141 try {
52- stats = await ( entry . followSymlinks ? stat ( src ) : lstat ( src ) ) ;
53- } catch {
54- // File does not exist or cannot be accessed.
55- return [ ] ;
56- }
42+ const stats = await ( entry . followSymlinks ? stat ( src ) : lstat ( src ) ) ;
43+ if ( stats . isFile ( ) ) {
44+ const filePath = entry . flatten ? path . basename ( entry . glob ) : entry . glob ;
5745
58- if ( stats . isFile ( ) ) {
59- return [
60- {
61- source : src ,
62- destination : resolveDestination ( entry . output , entry . glob , entry . flatten ) ,
63- } ,
64- ] ;
65- }
46+ return [ { source : src , destination : path . join ( entry . output , filePath ) } ] ;
47+ }
6648
67- if ( ! stats . isSymbolicLink ( ) ) {
49+ if ( ! stats . isSymbolicLink ( ) ) {
50+ return [ ] ;
51+ }
52+ } catch {
53+ // File does not exist or cannot be accessed.
6854 return [ ] ;
6955 }
7056 }
@@ -77,10 +63,17 @@ export async function resolveAssets(
7763 followSymbolicLinks : entry . followSymlinks ?? false ,
7864 } ) ;
7965
80- return files . map ( ( file ) => ( {
81- source : path . join ( cwd , file ) ,
82- destination : resolveDestination ( entry . output , file , entry . flatten ) ,
83- } ) ) ;
66+ return files . map ( ( file ) => {
67+ const destination = path . join ( entry . output , entry . flatten ? path . basename ( file ) : file ) ;
68+ if ( destination === '..' || destination . startsWith ( `..${ path . sep } ` ) ) {
69+ throw new Error ( 'An asset cannot be written to a location outside of the output path.' ) ;
70+ }
71+
72+ return {
73+ source : path . join ( cwd , file ) ,
74+ destination,
75+ } ;
76+ } ) ;
8477 } ) ;
8578
8679 return resolvedEntries . flat ( ) ;
0 commit comments