fix(tauri.js): init command properly building with manifests (#1374)

* fix(tauri.js): init command properly building with manifests

* fix: tests
This commit is contained in:
Lucas Fernandes Nogueira 2021-03-22 21:05:37 -03:00 committed by GitHub
parent af24034405
commit 2afb3f8ad5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 8 deletions

View File

@ -41,6 +41,7 @@ module.exports = {
},
transform: {
'templates[\\\\/]tauri.js': './test/jest/raw-loader-transformer.js',
'\\.toml$': 'jest-transform-toml',
'\\.(js|ts)$': 'babel-jest'
}
}

View File

@ -93,6 +93,7 @@
"eslint-plugin-security": "1.4.0",
"is-running": "2.1.0",
"jest": "26.6.3",
"jest-transform-toml": "^1.0.0",
"lint-staged": "10.5.4",
"lockfile-lint": "4.6.2",
"prettier": "2.2.1",

View File

@ -84,20 +84,21 @@ Run \`tauri init --force template\` to overwrite.`)
return resolvedPath.replace(/\\/g, '/')
}
const resolveCurrentTauriVersion = (crate: string): string => {
const manifestPath = `../../../../${crate}/Cargo.toml`
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-member-access, security/detect-non-literal-require
const tauriManifest = require(manifestPath) as CargoManifest
const version = tauriManifest.package.version
const resolveCurrentTauriVersion = (manifest: CargoManifest): string => {
const version = manifest.package.version
return version.substring(0, version.lastIndexOf('.'))
}
// eslint-disable-next-line @typescript-eslint/no-var-requires
const tauriManifest = require('../../../../tauri/Cargo.toml') as CargoManifest
// eslint-disable-next-line @typescript-eslint/no-var-requires
const tauriBuildManifest = require('../../../../core/tauri-build/Cargo.toml') as CargoManifest
const tauriDep = tauriPath
? `{ path = "${resolveTauriPath(tauriPath, 'tauri')}" }`
: `{ version = "${resolveCurrentTauriVersion('tauri')}" }`
: `{ version = "${resolveCurrentTauriVersion(tauriManifest)}" }`
const tauriBuildDep = tauriPath
? `{ path = "${resolveTauriPath(tauriPath, 'core/tauri-build')}" }`
: `{ version = "${resolveCurrentTauriVersion('core/tauri-build')}" }`
: `{ version = "${resolveCurrentTauriVersion(tauriBuildManifest)}" }`
removeSync(dir)
copyTemplates({

View File

@ -4891,6 +4891,13 @@ jest-snapshot@^26.6.2:
pretty-format "^26.6.2"
semver "^7.3.2"
jest-transform-toml@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/jest-transform-toml/-/jest-transform-toml-1.0.0.tgz#0a255066d4e59620ec3c3cc5a555321bb05f153d"
integrity sha1-CiVQZtTlliDsPDzFpVUyG7BfFT0=
dependencies:
toml-loader "^1.0.0"
jest-util@^26.6.2:
version "26.6.2"
resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-26.6.2.tgz#907535dbe4d5a6cb4c47ac9b926f6af29576cbc1"
@ -7392,7 +7399,7 @@ to-regex@^3.0.1, to-regex@^3.0.2:
regex-not "^1.0.2"
safe-regex "^1.1.0"
toml-loader@1.0.0:
toml-loader@1.0.0, toml-loader@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/toml-loader/-/toml-loader-1.0.0.tgz#05249b9294b623601148260caa480b22a653a19a"
integrity sha1-BSSbkpS2I2ARSCYMqkgLIqZToZo=