Skip to content

Commit

Permalink
Merge pull request #1829 from greg-md/fix-build-assets
Browse files Browse the repository at this point in the history
fix(): copy all assets on build
  • Loading branch information
kamilmysliwiec committed Dec 27, 2022
2 parents d9ab4ff + fee2571 commit b956164
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
1 change: 0 additions & 1 deletion actions/build.action.ts
Expand Up @@ -152,7 +152,6 @@ export class BuildAction extends AbstractAction {
);
} else {
this.compiler.run(configuration, pathToTsconfig, appName, onSuccess);
this.assetsManager.closeWatchers();
}
}

Expand Down
26 changes: 5 additions & 21 deletions lib/compiler/assets-manager.ts
Expand Up @@ -13,27 +13,9 @@ import { getValueOrDefault } from './helpers/get-value-or-default';
export class AssetsManager {
private watchAssetsKeyValue: { [key: string]: boolean } = {};
private watchers: chokidar.FSWatcher[] = [];
private actionInProgress = false;

/**
* Using on `nest build` to close file watch or the build process will not end
* Interval like process
* If no action has been taken recently close watchers
* If action has been taken recently flag and try again
*/
public closeWatchers() {
// Consider adjusting this for larger files
const timeoutMs = 500;
const closeFn = () => {
if (this.actionInProgress) {
this.actionInProgress = false;
setTimeout(closeFn, timeoutMs);
} else {
this.watchers.forEach((watcher) => watcher.close());
}
};

setTimeout(closeFn, timeoutMs);
this.watchers.forEach((watcher) => watcher.close());
}

public copyAssets(
Expand Down Expand Up @@ -96,6 +78,10 @@ export class AssetsManager {
.on('change', (path: string) => this.actionOnFile({ ...option, path, action: 'change' }))
.on('unlink', (path: string) => this.actionOnFile({ ...option, path, action: 'unlink' }));

if (!isWatchEnabled) {
watcher.on('ready', () => watcher.close());
}

this.watchers.push(watcher);
}
} catch (err) {
Expand All @@ -115,8 +101,6 @@ export class AssetsManager {
}
// Set path value to true for watching the first time
this.watchAssetsKeyValue[path] = true;
// Set action to true to avoid watches getting cutoff
this.actionInProgress = true;

const dest = copyPathResolve(
path,
Expand Down

0 comments on commit b956164

Please sign in to comment.