Skip to content

Commit bb8f35d

Browse files
Revert "fix(): copy all assets on build"
1 parent 4eb8384 commit bb8f35d

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

actions/build.action.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export class BuildAction extends AbstractAction {
152152
);
153153
} else {
154154
this.compiler.run(configuration, pathToTsconfig, appName, onSuccess);
155+
this.assetsManager.closeWatchers();
155156
}
156157
}
157158

lib/compiler/assets-manager.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,27 @@ import { getValueOrDefault } from './helpers/get-value-or-default';
1313
export class AssetsManager {
1414
private watchAssetsKeyValue: { [key: string]: boolean } = {};
1515
private watchers: chokidar.FSWatcher[] = [];
16+
private actionInProgress = false;
1617

18+
/**
19+
* Using on `nest build` to close file watch or the build process will not end
20+
* Interval like process
21+
* If no action has been taken recently close watchers
22+
* If action has been taken recently flag and try again
23+
*/
1724
public closeWatchers() {
18-
this.watchers.forEach((watcher) => watcher.close());
25+
// Consider adjusting this for larger files
26+
const timeoutMs = 500;
27+
const closeFn = () => {
28+
if (this.actionInProgress) {
29+
this.actionInProgress = false;
30+
setTimeout(closeFn, timeoutMs);
31+
} else {
32+
this.watchers.forEach((watcher) => watcher.close());
33+
}
34+
};
35+
36+
setTimeout(closeFn, timeoutMs);
1937
}
2038

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

81-
if (!isWatchEnabled) {
82-
watcher.on('ready', () => watcher.close());
83-
}
84-
8599
this.watchers.push(watcher);
86100
}
87101
} catch (err) {
@@ -101,6 +115,8 @@ export class AssetsManager {
101115
}
102116
// Set path value to true for watching the first time
103117
this.watchAssetsKeyValue[path] = true;
118+
// Set action to true to avoid watches getting cutoff
119+
this.actionInProgress = true;
104120

105121
const dest = copyPathResolve(
106122
path,

0 commit comments

Comments
 (0)