Skip to content

Commit

Permalink
fix: error when same file destination in build mode (#1833)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZYSzys committed Dec 5, 2020
1 parent 00be02a commit 12afdd8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions snowpack/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ export async function command(commandOptions: CommandOptions) {

// 0. Find all source files.
for (const [mountedDir, mountEntry] of Object.entries(config.mount)) {
const finalDestLocMap = new Map<string, string>();
const allFiles = glob.sync(`**/*`, {
ignore: [...config.exclude, ...config.testOptions.files],
cwd: mountedDir,
Expand All @@ -444,6 +445,15 @@ export async function command(commandOptions: CommandOptions) {
const fileLoc = path.resolve(rawLocOnDisk); // this is necessary since glob.sync() returns paths with / on windows. path.resolve() will switch them to the native path separator.
const finalUrl = getUrlForFileMount({fileLoc, mountKey: mountedDir, mountEntry, config})!;
const finalDestLoc = path.join(buildDirectoryLoc, finalUrl);

const existedFileLoc = finalDestLocMap.get(finalDestLoc);
if (existedFileLoc) {
logger.error(`Error: These two files are built to the same path: ${finalDestLoc}`);
logger.error(existedFileLoc);
logger.error(fileLoc);
process.exit(1);
}

const outDir = path.dirname(finalDestLoc);
const buildPipelineFile = new FileBuilder({
fileURL: url.pathToFileURL(fileLoc),
Expand All @@ -453,6 +463,8 @@ export async function command(commandOptions: CommandOptions) {
lockfile,
});
buildPipelineFiles[fileLoc] = buildPipelineFile;

finalDestLocMap.set(finalDestLoc, fileLoc);
}
}

Expand Down

1 comment on commit 12afdd8

@vercel
Copy link

@vercel vercel bot commented on 12afdd8 Dec 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.