Skip to content

Commit

Permalink
fix(assets): Fix assets copying on Windows
Browse files Browse the repository at this point in the history
Fix issue where Nest CLI fails to copy assets files on Windows due to path format
  • Loading branch information
CustomEntity committed Mar 24, 2024
1 parent 185169a commit 2421a59
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/compiler/assets-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as chokidar from 'chokidar';
import * as chokidar from 'chokidar';
import { statSync } from 'fs';
import { sync } from 'glob';
import { dirname, join, sep } from 'path';
Expand Down Expand Up @@ -60,18 +60,18 @@ export class AssetsManager {
sourceRoot = join(process.cwd(), sourceRoot);

const filesToCopy = assets.map<AssetEntry>((item) => {
if (typeof item === 'string') {
return {
glob: join(sourceRoot, item),
outDir,
};
}
let includePath = typeof item === 'string' ? item : item.include!;
let excludePath = typeof item !== 'string' && item.exclude ? item.exclude : undefined;

includePath = join(sourceRoot, includePath).replace(/\\/g, '/');
excludePath = excludePath ? join(sourceRoot, excludePath).replace(/\\/g, '/') : undefined;

return {
outDir: item.outDir || outDir,
glob: join(sourceRoot, item.include!),
exclude: item.exclude ? join(sourceRoot, item.exclude) : undefined,
flat: item.flat, // deprecated field
watchAssets: item.watchAssets,
outDir: typeof item !== 'string' ? item.outDir || outDir : outDir,
glob: includePath,
exclude: excludePath,
flat: typeof item !== 'string' ? item.flat : undefined, // deprecated field
watchAssets: typeof item !== 'string' ? item.watchAssets : undefined,
};
});

Expand Down Expand Up @@ -104,6 +104,7 @@ export class AssetsManager {
const files = sync(item.glob, { ignore: item.exclude }).filter(
(matched) => statSync(matched).isFile(),
);

for (const path of files) {
this.actionOnFile({ ...option, path, action: 'change' });
}
Expand Down

0 comments on commit 2421a59

Please sign in to comment.