Skip to content

Commit

Permalink
feat(bundler-vite): fix build error on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
xierenyuan committed Jul 4, 2023
1 parent f3668f5 commit a7bfda6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
49 changes: 49 additions & 0 deletions packages/bundler-vite/src/plugins/deleteOutputFiles.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import deleteOutputFiles from './deleteOutputFiles';

test('test windows', async () => {
const files = [
'a\\b\\c',
'd\\e\\f',
'node_modules\\.tmp\\.bundler-vite-entry\\umi.html',
];
const beforeDelete = jest.fn();
const plugin = deleteOutputFiles(files, beforeDelete) as any;
const output = {
'a/b/c': {
fileName: 'a/b/c',
},
'd/e/f': {
fileName: 'd/e/f',
},
'node_modules/.tmp/.bundler-vite-entry/umi.html': {
fileName: 'node_modules/.tmp/.bundler-vite-entry/umi.html',
},
};
plugin.generateBundle?.({}, output);
expect(beforeDelete).toBeCalledTimes(3);
expect(output).toEqual({});
});

test('test mac', async () => {
const files = [
'a/b/c',
'd/e/f',
'node_modules/.tmp/.bundler-vite-entry/umi.html',
];
const beforeDelete = jest.fn();
const plugin = deleteOutputFiles(files, beforeDelete) as any;
const output = {
'a/b/c': {
fileName: 'a/b/c',
},
'd/e/f': {
fileName: 'd/e/f',
},
'node_modules/.tmp/.bundler-vite-entry/umi.html': {
fileName: 'node_modules/.tmp/.bundler-vite-entry/umi.html',
},
};
plugin.generateBundle?.({}, output);
expect(beforeDelete).toBeCalledTimes(3);
expect(output).toEqual({});
});
2 changes: 2 additions & 0 deletions packages/bundler-vite/src/plugins/deleteOutputFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export default function deleteOutputFiles(
name: 'bundler-vite:delete-output-files',
generateBundle(_, output) {
Object.keys(output).forEach((name) => {
// vite use '/' in windows
files = files.map((file) => file.replace(/\\/g, '/'));
if (files.includes(output[name].fileName)) {
beforeDelete(output[name]);
delete output[name];
Expand Down

0 comments on commit a7bfda6

Please sign in to comment.