Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: watch too many file error #1550

Merged
merged 7 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading