Skip to content

Commit

Permalink
fix(angular): fix assets copying in ng-packagr-lite executor (#14355)
Browse files Browse the repository at this point in the history
(cherry picked from commit 3e9f4bf)
  • Loading branch information
leosvelperez authored and FrozenPandaz committed Jan 17, 2023
1 parent 1c21e0c commit 9f60773
Showing 1 changed file with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,34 +122,31 @@ async function copyAssets(

const assets: AssetEntry[] = [];

for (const item of ngPackage.assets) {
const asset: Partial<AssetEntry> = {};
if (typeof item == 'object') {
asset.glob = item.glob;
asset.input = path.join(ngPackage.src, item.input);
asset.output = path.join(ngPackage.dest, item.output);
asset.ignore = item.ignore;
for (const assetPath of ngPackage.assets) {
let asset: AssetEntry;
if (typeof assetPath === 'object') {
asset = { ...assetPath };
} else {
const assetPath = item; // might be a glob
const assetFullPath = path.join(ngPackage.src, assetPath);
const [isDir, isFile] = await stat(assetFullPath)
const [isDir, isFile] = await stat(path.join(ngPackage.src, assetPath))
.then((stats) => [stats.isDirectory(), stats.isFile()])
.catch(() => [false, false]);
if (isDir) {
asset.glob = '**/*';
asset.input = assetFullPath;
asset.output = path.join(ngPackage.dest, assetPath);
asset = { glob: '**/*', input: assetPath, output: assetPath };
} else if (isFile) {
asset.glob = path.basename(assetFullPath); // filenames are their own glob
asset.input = path.dirname(assetFullPath);
asset.output = path.dirname(path.join(ngPackage.dest, assetPath));
// filenames are their own glob
asset = {
glob: path.basename(assetPath),
input: path.dirname(assetPath),
output: path.dirname(assetPath),
};
} else {
asset.glob = assetPath;
asset.input = ngPackage.src;
asset.output = ngPackage.dest;
asset = { glob: assetPath, input: '/', output: '/' };
}
}

asset.input = path.join(ngPackage.src, asset.input);
asset.output = path.join(ngPackage.dest, asset.output);

const isAncestorPath = (target: string, datum: string) =>
path.relative(datum, target).startsWith('..');
if (isAncestorPath(asset.input, ngPackage.src)) {
Expand All @@ -163,7 +160,7 @@ async function copyAssets(
);
}

assets.push(asset as AssetEntry);
assets.push(asset);
}

for (const asset of assets) {
Expand Down

0 comments on commit 9f60773

Please sign in to comment.