generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix: switch from `npx` to `npm run`, closes #367 * fix command options if runner doesnt use npm run * don't append `--` if there are no args * further explain projectPath usage * Update README.md
- Loading branch information
1 parent
ef7395a
commit a778402
Showing
7 changed files
with
101 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'action': patch | ||
--- | ||
|
||
The action will now use `npm run tauri` instead of `npx tauri` to prevent issues in npm workspaces. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { execCommand, hasDependency, usesPnpm, usesYarn } from './utils'; | ||
|
||
class Runner { | ||
// Could be "npm", "yarn", "pnpm", "cargo", "path/to/tauri-cli/binary" or "tauri" | ||
bin: string; | ||
// could be ["tauri"], ["run", "tauri"], ["some package.json script"], ["run", "some package.json script"] or [] | ||
tauriScript: string[]; | ||
// vue-cli-plugin-tauri uses `tauri:build` instead of `tauri build` | ||
vueCli: boolean; | ||
|
||
constructor(bin: string, tauriScript?: string[], vueCli?: boolean) { | ||
this.bin = bin; | ||
this.tauriScript = tauriScript || []; | ||
this.vueCli = !!vueCli; | ||
} | ||
|
||
async execTauriCommand( | ||
command: string[], | ||
commandOptions: string[], | ||
cwd?: string | ||
): Promise<void> { | ||
const args: string[] = []; | ||
|
||
if (this.bin === 'npm' && this.tauriScript[0] !== 'run') { | ||
args.push('run'); | ||
} | ||
|
||
if (!(this.vueCli && command[0] === 'tauri:build')) { | ||
args.push(...this.tauriScript); | ||
} | ||
|
||
args.push(...command); | ||
|
||
if (this.bin === 'npm' && commandOptions.length) { | ||
args.push('--'); | ||
} | ||
|
||
args.push(...commandOptions); | ||
|
||
return execCommand(this.bin, args, { cwd }); | ||
} | ||
} | ||
|
||
async function getRunner( | ||
root: string, | ||
tauriScript: string | null | ||
): Promise<Runner> { | ||
if (tauriScript) { | ||
// FIXME: This will also split file paths with spaces. | ||
const [runnerCommand, ...runnerArgs] = tauriScript.split(' '); | ||
return new Runner(runnerCommand, runnerArgs); | ||
} | ||
|
||
const vueCli = hasDependency('vue-cli-plugin-tauri', root); | ||
if (hasDependency('@tauri-apps/cli', root) || vueCli) { | ||
if (usesYarn(root)) return new Runner('yarn', ['tauri'], vueCli); | ||
if (usesPnpm(root)) return new Runner('pnpm', ['tauri'], vueCli); | ||
return new Runner('npm', ['run', 'tauri'], vueCli); | ||
} | ||
|
||
await execCommand('npm', ['install', '-g', '@tauri-apps/cli'], { | ||
cwd: undefined, | ||
}); | ||
|
||
return new Runner('tauri'); | ||
} | ||
|
||
export { Runner, getRunner }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters