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

[bug] App compilation starts before beforeDevCommand complete. #4740

Closed
aleph1 opened this issue Jul 22, 2022 · 4 comments · Fixed by #4834
Closed

[bug] App compilation starts before beforeDevCommand complete. #4740

aleph1 opened this issue Jul 22, 2022 · 4 comments · Fixed by #4834
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@aleph1
Copy link

aleph1 commented Jul 22, 2022

Describe the bug

Unlike the beforeBuildCommand, the beforeDevCommand does not seem to wait for the command to finish executing before compiling the application.

Reproduction

In tauri.conf.json, set the following settings:

"beforeBuildCommand": "sleep 5 && npm run build",
"beforeDevCommand": "sleep 5 && npm run dev",

In package.json add the followings scripts:

"build": "node scripts/build.js",
"dev": "node scripts/build.js",

In scripts/build.js add the following code:

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

console.log('js build script start');

sleep(5000).then(()=>{
	console.log('js build script end');
});

Execute the command npm run tauri build, the log output will be in the expected order:

Running beforeBuildCommand sleep 5 && npm run build
js build script start
js build script end
Finished release [optimized] target(s) in 0.21s
Bundling…

Execute the command npm run tauri dev, and the log output will not be in the expected order:

Running BeforeDevCommand (sleep 5 && npm run dev)
Info Watching [deleted path]
Compiling app v0.1.0 [deleted path]
Finished dev [unoptimized + debuginfo] target(s) in 2.39s

Neither the sleep 5 or the sleep call in the JS function are respected and the console.log calls from scripts/build.js is never logged.

Expected behavior

The beforeDevCommand should function like the beforeBuildCommand with compiling only occurring after the command(s) are complete. This is especially crucial in cases where assets are optimized and copied to a separate "dev" directory, as Tauri is bundling the previous versions of the assets from the "dev" directory.

I can workaround this by having npm run build be something like node scripts/build.mjs && npm run tauri dev but it seems counterintuitive and nullifies the use of Tauri's beforeDevCommand functionality.

Platform and versions

Environment
  › OS: Mac OS 11.6.3 X64
  › Node.js: 14.15.1
  › npm: 6.14.8
  › pnpm: Not installed!
  › yarn: 3.1.1
  › rustup: 1.25.1
  › rustc: 1.62.0
  › cargo: 1.62.0
  › Rust toolchain: stable-aarch64-apple-darwin 

Packages
  › @tauri-apps/cli [NPM]: 1.0.4
  › @tauri-apps/api [NPM]: 1.0.2
  › tauri [RUST]: 1.0.4,
  › tauri-build [RUST]: 1.0.4,
  › tao [RUST]: 0.12.1,
  › wry [RUST]: 0.19.0,

App
  › build-type: bundle
  › CSP: unset
  › distDir: ../dist
  › devPath: ../dev
  › bundler: Rollup

App directory structure
  ├─ dist
  ├─ node_modules
  ├─ scripts
  ├─ src-tauri
  ├─ dev
  └─ src

Stack trace

No response

Additional context

No response

@aleph1 aleph1 added status: needs triage This issue needs to triage, applied to new issues type: bug labels Jul 22, 2022
@lucasfernog
Copy link
Member

lucasfernog commented Jul 22, 2022

Yeah we do that because usually a beforeDevCommand starts the dev server. We could add an option to wait for it to finish.

@aleph1
Copy link
Author

aleph1 commented Jul 22, 2022

That would be much appreciated!

@liesauer
Copy link
Contributor

has this fix be published? i have this issue too. i am using the tauri 1.0.5.

image

@FabianLars
Copy link
Member

No, this will be part of 1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants