Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
feat: implement flatten and fix #31
Browse files Browse the repository at this point in the history
  • Loading branch information
samrith-s committed Mar 15, 2021
1 parent af5dedb commit cea6eea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/core/AssetMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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);
});
}
Expand All @@ -87,7 +90,7 @@ export class AssetMap extends ConfigProvider {
.split('/')
.map(name => sanitize(name))
.join('/'),
file
fileConfig.flatten ? path.basename(file) : file
)
: null;
}
Expand Down
3 changes: 3 additions & 0 deletions src/core/FileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -113,6 +114,8 @@ export class FileManager extends ConfigProvider {
difference,
fileLogs,
});

deleteEmpty.sync(path.resolve(this.bundlerConfig.outDir));
}
}
}

0 comments on commit cea6eea

Please sign in to comment.