Skip to content

Commit f708ff8

Browse files
authored
fix(CTA): #1569, manually set tauri script for compatability with older npm (#1572)
1 parent 938fb62 commit f708ff8

4 files changed

Lines changed: 45 additions & 8 deletions

File tree

.changes/fix-cta-set-script.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-tauri-app": patch
3+
---
4+
5+
Manually set `tauri` script instead of using `npm set-script` for compatabilty with older npm versions

tooling/create-tauri-app/bin/create-tauri-app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {
1414
install,
1515
checkPackageManager,
1616
shell,
17+
addTauriScript,
1718
} = require("../dist/");
1819

1920
/**
@@ -208,9 +209,8 @@ async function runInit(argv, config = {}) {
208209
});
209210

210211
console.log("===== running tauri init =====");
211-
await shell("npm", ["set-script", "tauri", "tauri"], {
212-
cwd: appDirectory,
213-
});
212+
addTauriScript(appDirectory);
213+
214214
const binary = !argv.b ? packageManager : resolve(appDirectory, argv.b);
215215
const runTauriArgs =
216216
packageManager === "npm" && !argv.b
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
2+
// SPDX-License-Identifier: Apache-2.0
3+
// SPDX-License-Identifier: MIT
4+
5+
import { readFileSync, writeFileSync } from "fs";
6+
import { join } from "path";
7+
8+
export async function addTauriScript(appDirectory: string) {
9+
const pkgPath = join(appDirectory, "package.json");
10+
const pkgString = readFileSync(pkgPath, "utf8");
11+
const pkg = JSON.parse(pkgString) as {
12+
scripts: {
13+
tauri: string;
14+
};
15+
};
16+
17+
let outputPkg = {
18+
...pkg,
19+
scripts: {
20+
...pkg.scripts,
21+
tauri: "tauri",
22+
},
23+
};
24+
25+
writeFileSync(pkgPath, JSON.stringify(outputPkg, undefined, 2));
26+
}

tooling/create-tauri-app/src/index.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { vite } from "./recipes/vite";
1010

1111
export { shell } from "./shell";
1212
export { install, checkPackageManager } from "./dependency-manager";
13+
export { addTauriScript } from "./helpers/add-tauri-script";
1314
import { PackageManager } from "./dependency-manager";
1415

1516
export interface Recipe {
@@ -46,12 +47,17 @@ export interface Recipe {
4647

4748
export const allRecipes: Recipe[] = [vanillajs, reactjs, reactts, vite, vuecli];
4849

49-
export const recipeNames: Array<[string, string]> = allRecipes.map(r => [r.shortName, r.descriptiveName]);
50+
export const recipeNames: Array<[string, string]> = allRecipes.map((r) => [
51+
r.shortName,
52+
r.descriptiveName,
53+
]);
5054

51-
export const recipeByShortName = (name: string) => allRecipes.find(r => r.shortName === name);
55+
export const recipeByShortName = (name: string) =>
56+
allRecipes.find((r) => r.shortName === name);
5257

53-
export const recipeByDescriptiveName = (name: string) => allRecipes.find(r => r.descriptiveName === name);
58+
export const recipeByDescriptiveName = (name: string) =>
59+
allRecipes.find((r) => r.descriptiveName === name);
5460

55-
export const recipeShortNames = allRecipes.map(r => r.shortName);
61+
export const recipeShortNames = allRecipes.map((r) => r.shortName);
5662

57-
export const recipeDescriptiveNames = allRecipes.map(r => r.descriptiveName);
63+
export const recipeDescriptiveNames = allRecipes.map((r) => r.descriptiveName);

0 commit comments

Comments
 (0)