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
This commit is contained in:
Colum Ferry 2025-02-28 11:07:34 +00:00 committed by GitHub
parent e8647df08a
commit 30f5a52d96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -55,6 +55,7 @@
"npm-package-arg": "11.0.1",
"npm-run-path": "^4.0.1",
"ora": "5.3.0",
"picocolors": "^1.1.0",
"picomatch": "4.0.2",
"semver": "^7.5.3",
"source-map-support": "0.5.19",

View File

@ -12,8 +12,9 @@ import * as path from 'node:path';
import ignore from 'ignore';
import { globSync } from 'tinyglobby';
import { AssetGlob } from './assets';
import { logger } from '@nx/devkit';
import { logger, workspaceRoot } from '@nx/devkit';
import { ChangedFile, daemonClient } from 'nx/src/daemon/client/client';
import { dim } from 'picocolors';
export type FileEventType = 'create' | 'update' | 'delete';
@ -52,6 +53,9 @@ export const defaultFileEventHandler = (events: FileEvent[]) => {
} else {
logger.error(`Unknown file event: ${event.type}`);
}
const eventDir = path.dirname(event.src);
const relativeDest = path.relative(eventDir, event.dest);
logger.log(`\n${dim(relativeDest)}`);
});
};
@ -166,7 +170,9 @@ export class CopyAssetsHandler {
async processWatchEvents(events: ChangedFile[]): Promise<void> {
const fileEvents: FileEvent[] = [];
for (const event of events) {
const pathFromRoot = path.relative(this.rootDir, event.path);
const pathFromRoot = event.path.startsWith(this.rootDir)
? path.relative(this.rootDir, event.path)
: event.path;
for (const ag of this.assetGlobs) {
if (
picomatch(ag.pattern)(pathFromRoot) &&