( outDirs: Set<string>, emptyOutDir: boolean | null, environment: Environment, )
| 45 | } |
| 46 | |
| 47 | function prepareOutDir( |
| 48 | outDirs: Set<string>, |
| 49 | emptyOutDir: boolean | null, |
| 50 | environment: Environment, |
| 51 | ) { |
| 52 | const { publicDir } = environment.config |
| 53 | const outDirsArray = [...outDirs] |
| 54 | for (const outDir of outDirs) { |
| 55 | // When run inside Vite Task, `emptyDir` below reads the entries of |
| 56 | // `outDir`. Without this, those reads would be recorded as build inputs |
| 57 | // and mix with the writes that follow, tripping Vite Task's read-write |
| 58 | // overlap check. |
| 59 | ignoreInput(outDir) |
| 60 | if (emptyOutDir !== false && fs.existsSync(outDir)) { |
| 61 | // skip those other outDirs which are nested in current outDir |
| 62 | const skipDirs = outDirsArray |
| 63 | .map((dir) => { |
| 64 | const relative = path.relative(outDir, dir) |
| 65 | if ( |
| 66 | relative && |
| 67 | !relative.startsWith('..') && |
| 68 | !path.isAbsolute(relative) |
| 69 | ) { |
| 70 | return relative |
| 71 | } |
| 72 | return '' |
| 73 | }) |
| 74 | .filter(Boolean) |
| 75 | emptyDir(outDir, [...skipDirs, '.git']) |
| 76 | } |
| 77 | if ( |
| 78 | environment.config.build.copyPublicDir && |
| 79 | publicDir && |
| 80 | fs.existsSync(publicDir) |
| 81 | ) { |
| 82 | if (!areSeparateFolders(outDir, publicDir)) { |
| 83 | environment.logger.warn( |
| 84 | colors.yellow( |
| 85 | `\n${colors.bold( |
| 86 | `(!)`, |
| 87 | )} The public directory feature may not work correctly. outDir ${colors.white( |
| 88 | colors.dim(outDir), |
| 89 | )} and publicDir ${colors.white( |
| 90 | colors.dim(publicDir), |
| 91 | )} are not separate folders.\n`, |
| 92 | ), |
| 93 | ) |
| 94 | } |
| 95 | copyDir(publicDir, outDir) |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | function areSeparateFolders(a: string, b: string) { |
| 101 | const na = normalizePath(a) |
no test coverage detected