Skip to content

Commit

Permalink
fix: watch too many file error (#1550)
Browse files Browse the repository at this point in the history
* fix: watch too many file error

* chore: delete print

* chore: delete log

* release: @umijs/mako@0.8.8-rc.1

* fix: conflict
  • Loading branch information
Jinbao1001 authored Sep 13, 2024
1 parent 672ee42 commit 76eac6c
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 16 deletions.
1 change: 0 additions & 1 deletion crates/mako/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ impl DevServer {
eprintln!("Error rebuilding: {:?}", e);
}
}
watcher.refresh_watch()?;
}
Ok(())
}
Expand Down
15 changes: 0 additions & 15 deletions crates/mako/src/dev/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,6 @@ impl<'a> Watcher<'a> {
Ok(())
}

pub fn refresh_watch(&mut self) -> anyhow::Result<()> {
let t_refresh_watch = Instant::now();
self.watch()?;
let t_refresh_watch_duration = t_refresh_watch.elapsed();
debug!(
"{}",
format!(
"✓ refresh watch in {}",
format!("{}ms", t_refresh_watch_duration.as_millis()).bold()
)
.green()
);
Ok(())
}

fn get_ignore_list(&self, with_output_dir: bool) -> Vec<PathBuf> {
let mut ignore_list = vec![".git", "node_modules", ".DS_Store", ".node"];
if with_output_dir {
Expand Down
88 changes: 88 additions & 0 deletions scripts/test-hmr.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,94 @@ ReactDOM.createRoot(document.getElementById("root")!).render(<App />);
);
});

runTest(
'link npm packages: import a not exit file then add it without main entry',
async () => {
await commonTest(
async () => {
write(
normalizeFiles({
'/src/index.tsx': `
import React from 'react';
import ReactDOM from "react-dom/client";
import { foo } from "mako-test-package-link/lib1";
function App() {
return <div>{foo}<section>{Math.random()}</section></div>;
}
ReactDOM.createRoot(document.getElementById("root")!).render(<App />);
`,
}),
);
writePackage(
'mako-test-package-link',
normalizeFiles({
'package.json': `
{
"name": "mako-test-package-link",
"version": "1.0.0",
"exports": {
"./lib1": {
"import": "./lib1/index.js"
},
"./lib2": {
"import": "./lib2/index.js"
}
}
}
`,

'lib1/index.js': `
const foo = 'foo';
export { foo };
`,
}),
);
execSync(
'cd ./tmp/packages/mako-test-package-link && pnpm link --global',
);
execSync('pnpm link --global mako-test-package-link');
},
(lastResult) => {
assert.equal(lastResult.html, '<div>foo</div>', 'Initial render');
},
async () => {
// add import to added file
write(
normalizeFiles({
'/src/index.tsx': `
import React from 'react';
import ReactDOM from "react-dom/client";
import { foo } from "mako-test-package-link/lib1";
import { bar } from "mako-test-package-link/lib2";
function App() {
return <div>{foo}{bar}<section>{Math.random()}</section></div>;
}
ReactDOM.createRoot(document.getElementById("root")!).render(<App />);
`,
}),
);
await delay(DELAY_TIME);
// add files
writePackage(
'mako-test-package-link',
normalizeFiles({
'lib2/index.js': `
const bar = 'bar';
export { bar };
`,
}),
);
},
(thisResult) => {
assert.equal(thisResult.html, '<div>foobar</div>', 'Second render');
},
true,
);
},
);

runTest('change async import to import', async () => {
write(
normalizeFiles({
Expand Down

0 comments on commit 76eac6c

Please sign in to comment.