Skip to content

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

@aleph1

Description

@aleph1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions