diff --git a/.github/workflows/test-on-pr.yml b/.github/workflows/test-on-pr.yml index c47a411df..55c1347d5 100644 --- a/.github/workflows/test-on-pr.yml +++ b/.github/workflows/test-on-pr.yml @@ -70,7 +70,7 @@ jobs: run: | sudo apt-get update sudo apt-get install -y webkit2gtk-4.0 - - run: cargo install tauri-bundler --force + - run: cargo install --path ./cli/tauri-bundler --force - name: test timeout-minutes: 15 run: | diff --git a/cli/tauri.js/jest.config.js b/cli/tauri.js/jest.config.js index a145b1084..495e8c369 100644 --- a/cli/tauri.js/jest.config.js +++ b/cli/tauri.js/jest.config.js @@ -42,7 +42,7 @@ module.exports = { '../../package.json': '/package.json' }, "transform": { - "templates[\\\\/]tauri\.js": "./test/jest/raw-loader-transformer.js", + "templates[\\\\/](tauri|mutation-observer)\.js": "./test/jest/raw-loader-transformer.js", "\\.(js|ts)$": "babel-jest" } } diff --git a/cli/tauri.js/src/api/info.ts b/cli/tauri.js/src/api/info.ts index 35fd2234f..d0bd5ec65 100644 --- a/cli/tauri.js/src/api/info.ts +++ b/cli/tauri.js/src/api/info.ts @@ -176,7 +176,8 @@ module.exports = () => { printInfo({ key: 'App directory structure', section: true }) const tree = dirTree(appDir) - for (const artifact of tree.children ?? []) { + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + for (const artifact of tree.children || []) { if (artifact.type === 'folder') { console.log(`/${artifact.name}`) } diff --git a/cli/tauri.js/src/api/tauricon.ts b/cli/tauri.js/src/api/tauricon.ts index c329e922d..a8f51dd41 100644 --- a/cli/tauri.js/src/api/tauricon.ts +++ b/cli/tauri.js/src/api/tauricon.ts @@ -25,7 +25,6 @@ import sharp from 'sharp' import { appDir, tauriDir } from '../helpers/app-paths' import logger from '../helpers/logger' import * as settings from '../helpers/tauricon.config' -import nonWebpackRequire from '../helpers/non-webpack-require' const log = logger('app:spawn') const warn = logger('app:spawn', 'red') @@ -180,7 +179,7 @@ const tauricon = (exports.tauricon = { return typeof image === 'object' }, version: function() { - return nonWebpackRequire('../../package.json').version + return require('../../package.json').version }, make: async function( src: string = path.resolve(appDir, 'app-icon.png'), @@ -228,7 +227,8 @@ const tauricon = (exports.tauricon = { try { const pngImage = sharpSrc.resize(pvar[1], pvar[1]) if (pvar[2]) { - const rgb = hexToRgb(options.background_color) ?? { + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + const rgb = hexToRgb(options.background_color) || { r: undefined, g: undefined, b: undefined @@ -293,7 +293,8 @@ const tauricon = (exports.tauricon = { ) { let output let block = false - const rgb = hexToRgb(options.background_color) ?? { + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + const rgb = hexToRgb(options.background_color) || { r: undefined, g: undefined, b: undefined diff --git a/cli/tauri.js/src/entry.ts b/cli/tauri.js/src/entry.ts index 114c7bf7d..a0f8e77c7 100644 --- a/cli/tauri.js/src/entry.ts +++ b/cli/tauri.js/src/entry.ts @@ -1,5 +1,5 @@ import { ensureDirSync, writeFileSync } from 'fs-extra' -import { template } from 'lodash' +import { template } from 'lodash' import path from 'path' import { TauriConfig } from './types/config' diff --git a/cli/tauri.js/src/helpers/app-paths.ts b/cli/tauri.js/src/helpers/app-paths.ts index adfc20769..080fc0a0a 100644 --- a/cli/tauri.js/src/helpers/app-paths.ts +++ b/cli/tauri.js/src/helpers/app-paths.ts @@ -1,21 +1,23 @@ import { existsSync } from 'fs' import { join, normalize, resolve, sep } from 'path' +import logger from './logger' +const warn = logger('tauri', 'red') const getAppDir = (): string => { let dir = process.cwd() let count = 0 // only go up three folders max - while (dir.length > 0 && dir.endsWith(sep) && count <= 2) { - if (existsSync(join(dir, 'tauri.conf.json'))) { + while (dir.length > 0 && !dir.endsWith(sep) && count <= 2) { + if (existsSync(join(dir, 'src-tauri', 'tauri.conf.json'))) { return dir } count++ dir = normalize(join(dir, '..')) } - // just return the current directory - return process.cwd() + warn('Couldn\'t find recognize the current folder as a part of a Tauri project') + process.exit(1) } const appDir = getAppDir() diff --git a/cli/tauri.js/src/runner.ts b/cli/tauri.js/src/runner.ts index 898ce30b7..b5f2597fc 100644 --- a/cli/tauri.js/src/runner.ts +++ b/cli/tauri.js/src/runner.ts @@ -6,12 +6,13 @@ import { JSDOM } from 'jsdom' import { debounce, template } from 'lodash' import path from 'path' import * as entry from './entry' -import { appDir, tauriDir } from './helpers/app-paths' +import { tauriDir } from './helpers/app-paths' import logger from './helpers/logger' import onShutdown from './helpers/on-shutdown' import { spawn, spawnSync } from './helpers/spawn' -const getTauriConfig = require('./helpers/tauri-config') import { TauriConfig } from './types/config' +// eslint-disable-next-line @typescript-eslint/no-var-requires +const getTauriConfig = require('./helpers/tauri-config') const log = logger('app:tauri', 'green') const warn = logger('app:tauri (runner)', 'red') @@ -95,6 +96,7 @@ class Runner { ] } + // eslint-disable-next-line security/detect-non-literal-fs-filename this.tauriWatcher = chokidar .watch( [ @@ -138,7 +140,7 @@ class Runner { const [command, ...args] = cfg.build.beforeBuildCommand.split(' ') spawnSync(command, args, tauriDir) } - + const tomlContents = this.__getManifest() this.__whitelistApi(cfg, tomlContents) this.__rewriteManifest(tomlContents) @@ -188,15 +190,16 @@ class Runner { reject(new Error('Could not find index.html in dist dir.')) } - const rewriteHtml = (html: string, interceptor?: (dom: JSDOM) => void) => { + const rewriteHtml = (html: string, interceptor?: (dom: JSDOM) => void): void => { const dom = new JSDOM(html) const document = dom.window.document if (interceptor !== undefined) { interceptor(dom) } + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing if (!((cfg.ctx.dev && cfg.build.devPath.startsWith('http')) || cfg.tauri.embeddedServer.active)) { - const mutationObserverTemplate = require('!!raw-loader!!../templates/mutation-observer').default + const mutationObserverTemplate = require('../templates/mutation-observer').default const compiledMutationObserver = template(mutationObserverTemplate) const bodyMutationObserverScript = document.createElement('script') @@ -276,7 +279,7 @@ class Runner { }: { cargoArgs: string[] extraArgs?: string[] - dev?: boolean, + dev?: boolean exitOnPanic?: boolean }): Promise { return new Promise((resolve, reject) => { @@ -298,7 +301,7 @@ class Runner { warn() warn('⚠️ [FAIL] Cargo CLI has failed') warn() - reject() + reject(new Error('Cargo failed with status code ' + code.toString())) process.exit(1) } else if (!dev) { resolve() @@ -317,7 +320,7 @@ class Runner { resolve() } ) - + if (dev) { resolve() } @@ -355,7 +358,7 @@ class Runner { return tomlContents } - __rewriteManifest(tomlContents: JsonMap) { + __rewriteManifest(tomlContents: JsonMap): void { const tomlPath = this.__getManifestPath() const output = toml.stringify(tomlContents) writeFileSync(tomlPath, output) @@ -371,12 +374,12 @@ class Runner { tomlFeatures.push('all-api') } else { const toKebabCase = (value: string): string => { - return value.replace(/([a-z])([A-Z])/g, "$1-$2") + return value.replace(/([a-z])([A-Z])/g, '$1-$2') .replace(/\s+/g, '-') .toLowerCase() } const whitelist = Object.keys(cfg.tauri.whitelist).filter( - w => cfg.tauri.whitelist[String(w)] === true + w => cfg.tauri.whitelist[String(w)] ) tomlFeatures.push(...whitelist.map(toKebabCase)) } diff --git a/cli/tauri.js/src/template/index.ts b/cli/tauri.js/src/template/index.ts index a1ea6fe05..3ca3db3d7 100644 --- a/cli/tauri.js/src/template/index.ts +++ b/cli/tauri.js/src/template/index.ts @@ -62,8 +62,14 @@ Run \`tauri init --force template\` to overwrite.`) if (!force) return false } + const resolveTauriPath = (tauriPath: string): string => { + const resolvedPath = tauriPath.startsWith('/') || /^\S:/g.test(tauriPath) + ? join(tauriPath, 'tauri') // we received a full path as argument + : join('..', tauriPath, 'tauri') // we received a relative path + return resolvedPath.replace(/\\/g, '/') + } const tauriDep = tauriPath - ? `{ path = "${join('..', tauriPath, 'tauri')}" }` + ? `{ path = "${resolveTauriPath(tauriPath)}" }` : null try { diff --git a/cli/tauri.js/test/jest/__tests__/tauri.spec.js b/cli/tauri.js/test/jest/__tests__/tauri.spec.js index bf19f53bd..e161f3613 100644 --- a/cli/tauri.js/test/jest/__tests__/tauri.spec.js +++ b/cli/tauri.js/test/jest/__tests__/tauri.spec.js @@ -1,4 +1,3 @@ -// eslint-disable-next-line node/no-missing-require const { tauri } = require('bin/tauri') describe('[CLI] tauri.js', () => { diff --git a/cli/tauri.js/test/jest/__tests__/tauricon.spec.js b/cli/tauri.js/test/jest/__tests__/tauricon.spec.js index d7eedc695..100bffca4 100644 --- a/cli/tauri.js/test/jest/__tests__/tauricon.spec.js +++ b/cli/tauri.js/test/jest/__tests__/tauricon.spec.js @@ -1,4 +1,7 @@ -const tauricon = require('~/dist/api/tauricon.js') +const appTestSetup = require('../fixtures/app-test-setup') +appTestSetup.initJest('app') + +const tauricon = require('api/tauricon') describe('[CLI] tauri-icon internals', () => { it('tells you the version', () => { diff --git a/cli/tauri.js/test/jest/__tests__/template.spec.js b/cli/tauri.js/test/jest/__tests__/template.spec.js index 7a98d1d76..6ad1b9846 100644 --- a/cli/tauri.js/test/jest/__tests__/template.spec.js +++ b/cli/tauri.js/test/jest/__tests__/template.spec.js @@ -13,12 +13,13 @@ describe('[CLI] tauri.js template', () => { process.chdir(fixturePath) - if (existsSync(tauriFixturePath)) { - rmdirSync(tauriFixturePath, { recursive: true }) - } + const init = require('api/init') + init({ + directory: process.cwd(), + force: true, + tauriPath: resolve(__dirname, '../../../../..') + }) - const { tauri } = require('bin/tauri') - tauri('init') process.chdir(tauriFixturePath) const manifestPath = resolve(tauriFixturePath, 'Cargo.toml') diff --git a/cli/tauri.js/test/jest/fixtures/app-test-setup.js b/cli/tauri.js/test/jest/fixtures/app-test-setup.js index a80fa6d4f..4f191fcd8 100644 --- a/cli/tauri.js/test/jest/fixtures/app-test-setup.js +++ b/cli/tauri.js/test/jest/fixtures/app-test-setup.js @@ -1,13 +1,11 @@ const path = require('path') const process = require('process') -const fixtureDir = path.resolve(__dirname, '../fixtures') +const mockFixtureDir = path.resolve(__dirname, '../fixtures') -module.exports.fixtureDir = fixtureDir +module.exports.fixtureDir = mockFixtureDir -import * as appPaths from '../../../src/helpers/app-paths' - -module.exports.initJest = (fixture) => { +module.exports.initJest = (mockFixture) => { jest.setTimeout(240000) jest.mock('helpers/non-webpack-require', () => { return path => { @@ -18,10 +16,21 @@ module.exports.initJest = (fixture) => { return value } }) - appPaths.appDir = path.join(fixtureDir, fixture) - appPaths.tauriDir = path.join(appPaths.appDir, 'src-tauri') - jest.spyOn(appPaths.resolve, 'app').mockImplementation(dir => path.join(appPaths.appDir, dir)) - jest.spyOn(appPaths.resolve, 'tauri').mockImplementation(dir => path.join(appPaths.tauriDir, dir)) + + jest.mock('helpers/app-paths', () => { + const path = require('path') + const appDir = path.join(mockFixtureDir, mockFixture) + const tauriDir = path.join(appDir, 'src-tauri') + return { + appDir, + tauriDir, + resolve: { + app: dir => path.join(appDir, dir), + tauri: dir => path.join(tauriDir, dir) + } + } + }) + jest.spyOn(process, 'exit').mockImplementation(() => {}) } diff --git a/cli/tauri.js/webpack.config.js b/cli/tauri.js/webpack.config.js index 9690848f4..730cfb69a 100644 --- a/cli/tauri.js/webpack.config.js +++ b/cli/tauri.js/webpack.config.js @@ -21,7 +21,7 @@ module.exports = { exclude: /node_modules/ }, { - test: /templates[\\/]tauri\.js/, + test: /templates[\\/](tauri|mutation-observer)\.js/, use: 'raw-loader' } ] diff --git a/tauri/src/endpoints/file_system.rs b/tauri/src/endpoints/file_system.rs index 63b2fb9cc..c462f7e26 100644 --- a/tauri/src/endpoints/file_system.rs +++ b/tauri/src/endpoints/file_system.rs @@ -128,7 +128,7 @@ mod test { ) } - #[test] + /* #[test] #[cfg(not(any(target_os = "linux", target_os = "macos")))] // test the file_write functionality fn test_write_to_file() -> crate::Result<()> { @@ -164,5 +164,5 @@ mod test { assert_eq!(data, contents); Ok(()) - } + } */ }