diff --git a/src/core/AssetMap.ts b/src/core/AssetMap.ts index 7d84899..6d98a69 100644 --- a/src/core/AssetMap.ts +++ b/src/core/AssetMap.ts @@ -40,8 +40,13 @@ export class AssetMap extends ConfigProvider { } } + private getFile(depAsset: ParcelBundle): string { + const isRelative = depAsset.type === 'html' && !!depAsset.entryAsset?.relativeName; + return isRelative ? depAsset.entryAsset?.relativeName : path.basename(depAsset.name); + } + private iterativeDependencyResolver(depAsset: ParcelBundle): void { - const file = depAsset.entryAsset.relativeName || depAsset.name; + const file = this.getFile(depAsset); const extension = path.extname(file); const mapFile = extension === '.map'; const fileConfig = (this.config.rules as Structurizer[]).find(c => { @@ -62,10 +67,8 @@ export class AssetMap extends ConfigProvider { if (depAsset.childBundles.size) { const currentMap = this.assetsMap.get(currentPath); currentMap.dependents = []; - depAsset.childBundles.forEach(childBundle => { - currentMap.dependents.push( - this.generateCurrentPath(path.basename(childBundle.name)) - ); + depAsset.childBundles.forEach((childBundle: ParcelBundle) => { + currentMap.dependents.push(this.generateCurrentPath(this.getFile(childBundle))); this.iterativeDependencyResolver(childBundle); }); } @@ -87,7 +90,7 @@ export class AssetMap extends ConfigProvider { .split('/') .map(name => sanitize(name)) .join('/'), - file + fileConfig.flatten ? path.basename(file) : file ) : null; } diff --git a/src/core/FileManager.ts b/src/core/FileManager.ts index 4f57d41..a9c1227 100644 --- a/src/core/FileManager.ts +++ b/src/core/FileManager.ts @@ -2,6 +2,7 @@ import { readFile, writeFileSync } from 'fs'; import * as path from 'path'; import moveFile from 'move-file'; import chalk from 'chalk'; +import deleteEmpty from 'delete-empty'; import { ConfigProvider } from './providers/Config'; import { AssetsGraphMap, AssetGraph } from './AssetMap'; @@ -113,6 +114,8 @@ export class FileManager extends ConfigProvider { difference, fileLogs, }); + + deleteEmpty.sync(path.resolve(this.bundlerConfig.outDir)); } } }