Skip to content

Commit 30f5a52

Browse files
authored
fix(vite): copy assets plugin not copying files in watch mode #30141 (#30208)
## Current Behavior Copy assets plugin for Vite is not copying files in watch mode when those files are changed. This is due to the path being incorrect after calculation. There is also no indication to the user that the copy completed at all. ## Expected Behavior Fix path calculation to allow copy to occur correctly Output the relative dest of the file after copy completed. ## Related Issue(s) Fixes #30141
1 parent e8647df commit 30f5a52

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/js/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"npm-package-arg": "11.0.1",
5656
"npm-run-path": "^4.0.1",
5757
"ora": "5.3.0",
58+
"picocolors": "^1.1.0",
5859
"picomatch": "4.0.2",
5960
"semver": "^7.5.3",
6061
"source-map-support": "0.5.19",

packages/js/src/utils/assets/copy-assets-handler.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import * as path from 'node:path';
1212
import ignore from 'ignore';
1313
import { globSync } from 'tinyglobby';
1414
import { AssetGlob } from './assets';
15-
import { logger } from '@nx/devkit';
15+
import { logger, workspaceRoot } from '@nx/devkit';
1616
import { ChangedFile, daemonClient } from 'nx/src/daemon/client/client';
17+
import { dim } from 'picocolors';
1718

1819
export type FileEventType = 'create' | 'update' | 'delete';
1920

@@ -52,6 +53,9 @@ export const defaultFileEventHandler = (events: FileEvent[]) => {
5253
} else {
5354
logger.error(`Unknown file event: ${event.type}`);
5455
}
56+
const eventDir = path.dirname(event.src);
57+
const relativeDest = path.relative(eventDir, event.dest);
58+
logger.log(`\n${dim(relativeDest)}`);
5559
});
5660
};
5761

@@ -166,7 +170,9 @@ export class CopyAssetsHandler {
166170
async processWatchEvents(events: ChangedFile[]): Promise<void> {
167171
const fileEvents: FileEvent[] = [];
168172
for (const event of events) {
169-
const pathFromRoot = path.relative(this.rootDir, event.path);
173+
const pathFromRoot = event.path.startsWith(this.rootDir)
174+
? path.relative(this.rootDir, event.path)
175+
: event.path;
170176
for (const ag of this.assetGlobs) {
171177
if (
172178
picomatch(ag.pattern)(pathFromRoot) &&

0 commit comments

Comments
 (0)