Skip to content

Commit

Permalink
fix(copy): if dest is specified copy task is not relative
Browse files Browse the repository at this point in the history
fixes #1697
  • Loading branch information
manucorporat committed Jul 3, 2019
1 parent 2d1a0aa commit 4292f74
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
11 changes: 7 additions & 4 deletions src/compiler/config/validate-copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ export function validateCopy(copy: d.CopyTask[] | boolean, defaultCopy: d.CopyTa
if (!Array.isArray(copy)) {
copy = [];
}
return unique([
...copy,
...defaultCopy,
], task => task.src);
copy = copy.slice();
for (const task of defaultCopy) {
if (copy.every(t => t.src !== task.src)) {
copy.push(task);
}
}
return unique(copy, task => `${task.src}:${task.dest}:${task.relative}`);
}
6 changes: 4 additions & 2 deletions src/compiler/copy/assets-copy-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export function getComponentAssetsCopyTasks(config: d.Config, buildCtx: d.BuildC
copyTasks.push({
src: assetsMeta.absolutePath,
dest: config.sys.path.join(dest, assetsMeta.cmpRelativePath),
warn: false
warn: false,
relative: false,
});
});
} else if (!cmp.excludeFromCollection && !cmp.isCollectionDependency) {
Expand All @@ -32,7 +33,8 @@ export function getComponentAssetsCopyTasks(config: d.Config, buildCtx: d.BuildC
copyTasks.push({
src: assetsMeta.absolutePath,
dest: collectionDirDestination,
warn: false
warn: false,
relative: false,
});
});
}
Expand Down
19 changes: 14 additions & 5 deletions src/compiler/copy/copy-tasks-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export async function copyTasksWorker(copyTasks: Required<d.CopyTask>[], srcDir:
copyTasks = flatOne(await Promise.all(
copyTasks.map(task => processGlobs(task, srcDir))
));
copyTasks = unique(copyTasks, task => `${task.src}:::${task.dest}`);

copyTasks = unique(copyTasks, task => task.dest);

const allCopyTasks: d.CopyTask[] = [];

Expand Down Expand Up @@ -63,8 +64,11 @@ async function processGlobs(copyTask: Required<d.CopyTask>, srcDir: string): Pro
? await processGlobTask(copyTask, srcDir)
: [{
src: getSrcAbsPath(srcDir, copyTask.src),
dest: copyTask.dest,
warn: copyTask.warn
dest: copyTask.relative
? path.join(copyTask.dest, copyTask.src)
: copyTask.dest,
warn: copyTask.warn,
relative: copyTask.relative
}];
}

Expand All @@ -85,10 +89,15 @@ async function processGlobTask(copyTask: Required<d.CopyTask>, srcDir: string):


function createGlobCopyTask(copyTask: Required<d.CopyTask>, srcDir: string, globRelPath: string): Required<d.CopyTask> {
const dest = path.join(copyTask.dest, copyTask.relative
? globRelPath
: path.basename(globRelPath)
);
return {
src: path.join(srcDir, globRelPath),
dest: path.join(copyTask.dest, globRelPath),
warn: copyTask.warn
dest,
warn: copyTask.warn,
relative: copyTask.relative
};
}

Expand Down
5 changes: 1 addition & 4 deletions src/compiler/copy/local-copy-tasks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as d from '../../declarations';
import isGlob from 'is-glob';

export function getSrcAbsPath(config: d.Config, src: string) {
if (config.sys.path.isAbsolute(src)) {
Expand All @@ -23,7 +22,5 @@ export function getDestAbsPath(config: d.Config, src: string, destAbsPath: strin
throw new Error(`copy task, "dest" property must exist if "src" property is an absolute path: ${src}`);
}

return isGlob(src)
? destAbsPath
: config.sys.path.join(destAbsPath, src);
return destAbsPath;
}
1 change: 1 addition & 0 deletions src/compiler/output-targets/output-copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function transformToAbs(config: d.Config, copyTask: d.CopyTask, dest: string): R
return {
src: copyTask.src,
dest: getDestAbsPath(config, copyTask.src, dest, copyTask.dest),
relative: typeof copyTask.relative === 'boolean' ? copyTask.relative : copyTask.dest == null,
warn: copyTask.warn !== false
};
}
1 change: 1 addition & 0 deletions src/declarations/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface CopyTask {
src: string;
dest?: string;
warn?: boolean;
relative?: boolean;
}


Expand Down

0 comments on commit 4292f74

Please sign in to comment.