diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 868ebbc1..a1060ed5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,7 +43,6 @@ jobs: shell: bash env: KIT: ${{ env.kit_path }} - KNODE: ${{ env.knode_path }} run: | npm run build-kit @@ -56,7 +55,6 @@ jobs: npm run test env: KIT: ${{ env.kit_path }} - KNODE: ${{ env.knode_path }} test-mac-and-ubuntu: @@ -78,26 +76,30 @@ jobs: - name: Checkout kit uses: actions/checkout@master - - name: Install Node - run: | - mkdir -p ./.knode - ./build/install-node.sh -v 20.16.0 -P ./.knode -y + - uses: pnpm/action-setup@v4 + name: Install pnpm + with: + version: 9.9.0 + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'pnpm' - name: Build Kit run: | - PATH="./.knode/bin:$PATH" npm i && PATH="./.knode/bin:$PATH" npm dedupe - PATH="./.knode/bin:$PATH" KIT=./.kit node ./build/build-ci.js + pnpm i + pnpm run build-kit - name: Set env vars run: | echo "wd_path=$PWD" >> $GITHUB_ENV echo "kit_path=$PWD/.kit" >> $GITHUB_ENV - echo "knode_path=$PWD/.knode" >> $GITHUB_ENV echo "release_channel=${{ env.GITHUB_REF_SLUG_URL }}" >> $GITHUB_ENV - name: Add node and kit to PATH run: | - echo "${{ env.knode_path }}/bin" >> $GITHUB_PATH echo "${{ env.kit_path }}/bin" >> $GITHUB_PATH echo "---" echo "$GITHUB_PATH" @@ -126,7 +128,6 @@ jobs: npm run test env: KIT: ${{ env.kit_path }} - KNODE: ${{ env.knode_path }} release: runs-on: macos-latest @@ -145,26 +146,31 @@ jobs: - name: Checkout kit uses: actions/checkout@master - - name: Install Node - run: | - mkdir -p ./.knode - ./build/install-node.sh -v 20.16.0 -P ./.knode -y + - uses: pnpm/action-setup@v4 + name: Install pnpm + with: + version: 9.9.0 + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'pnpm' + - name: Build Kit run: | - PATH="./.knode/bin:$PATH" npm i && PATH="./.knode/bin:$PATH" npm dedupe - PATH="./.knode/bin:$PATH" KIT=./.kit node ./build/build-ci.js + pnpm i + pnpm run build-kit - name: Set env vars run: | echo "wd_path=$PWD" >> $GITHUB_ENV echo "kit_path=$PWD/.kit" >> $GITHUB_ENV - echo "knode_path=$PWD/.knode" >> $GITHUB_ENV echo "release_channel=${{ env.GITHUB_REF_SLUG_URL }}" >> $GITHUB_ENV - name: Add node and kit to PATH run: | - echo "${{ env.knode_path }}/bin" >> $GITHUB_PATH echo "${{ env.kit_path }}/bin" >> $GITHUB_PATH echo "---" echo "$GITHUB_PATH" diff --git a/README.md b/README.md index 9b448bb1..0e4158a0 100644 --- a/README.md +++ b/README.md @@ -33,18 +33,6 @@ Requirements: npm -### Using node 20.16.0 from ~/.knode - -Installing `Kit.app` already installed node 20.16.0 to ~/.knode. You'll want to use this node version for all build/run steps: - -`PATH=~/.knode/bin:$PATH` - -This will use 20.16.0's node/npm when working with Kit. (Alternatively, you can use nvm/n/whatever, but I don't) - -- Use `volta` to manage node versions. - 1. Install [volta](https://volta.sh/) - 2. Volta will automatically switch node version to 20.16.0 when working with kit. - ### Clone Kit SDK Clone: diff --git a/build/build-ci.sh b/build/build-ci.sh index e11c4c8a..150903bd 100755 --- a/build/build-ci.sh +++ b/build/build-ci.sh @@ -2,7 +2,6 @@ set -e export WD=$(cd "$(dirname ${BASH_SOURCE[0]})"/.. &>/dev/null && pwd) export KIT="$WD/.kit" -export KNODE="$WD/.knode" export PATH="$KNODE:$PATH" cd $WD diff --git a/root/bin/kit b/root/bin/kit index e65c0c90..11faff37 100755 --- a/root/bin/kit +++ b/root/bin/kit @@ -13,7 +13,7 @@ KIT=$(cd "$(dirname $(readlink -f ${BASH_SOURCE[0]}))/.." &>/dev/null && pwd) pwd )" -KIT_NODE="${KIT_NODE:=$KIT/../.knode/bin/node}" +KIT_NODE="${KIT_NODE:=$KIT/../.kenv/bin/pnpm node}" # Default to system node if KIT_NODE doesn't exist [ ! -f $KIT_NODE ] && KIT_NODE=$(which node) diff --git a/root/bin/kit.bat b/root/bin/kit.bat index 7e6828b8..98ab3b81 100644 --- a/root/bin/kit.bat +++ b/root/bin/kit.bat @@ -16,7 +16,7 @@ if %errorlevel%==0 ( REM Set the default KIT_NODE variable to the custom node binary if not defined KIT_NODE ( - set "KIT_NODE=%KIT%/../.knode/bin/node" + set "KIT_NODE=%KIT%/../.kenv/bin/pnpm node" ) REM Check if the custom node binary exists, if not, use the system's node binary diff --git a/root/script b/root/script index b67d73f9..ec0ad0f5 100755 --- a/root/script +++ b/root/script @@ -2,7 +2,7 @@ # ../../ of this script KIT=$(cd "$(dirname ${BASH_SOURCE[0]})" &> /dev/null && pwd) -KIT_NODE="${KIT_NODE:=$KIT/../.knode/bin/node}" +KIT_NODE="${KIT_NODE:=$KIT/../.kenv/bin/pnpm node}" NODE_NO_WARNINGS=1 \ "$KIT_NODE" \ diff --git a/src/api/global.ts b/src/api/global.ts index 1d75a88e..3091caab 100644 --- a/src/api/global.ts +++ b/src/api/global.ts @@ -7,7 +7,6 @@ import { kitPath, kenvPath, wait, - knodePath, getLogFromScriptPath, createPathResolver } from "../core/utils.js" @@ -79,7 +78,6 @@ assignPropsTo(process.env, global.env) global.wait = wait global.kitPath = kitPath global.kenvPath = kenvPath -global.knodePath = knodePath global.isBin = isBin global.isDir = isDir global.createPathResolver = createPathResolver diff --git a/src/cli/lib/utils.ts b/src/cli/lib/utils.ts index 00d57d24..9226670e 100644 --- a/src/cli/lib/utils.ts +++ b/src/cli/lib/utils.ts @@ -1,6 +1,6 @@ -import path from "path" +import path from "node:path" import shelljs from "shelljs" -import { kitPath, knodePath, home } from "../../core/utils.js" +import { kitPath, home } from "../../core/utils.js" import { compile } from "@johnlindquist/globals" import { ensureDir, diff --git a/src/core/constants.ts b/src/core/constants.ts index 6c07cc15..72d71324 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -1,5 +1,5 @@ -import { home, kenvPath, kitPath, knodePath } from "./resolvers.js" -import { isMac, isWin } from "./is.js" +import { home, kenvPath, kitPath } from "./resolvers.js" +import { isMac } from "./is.js" export let cmd = isMac ? "cmd" : "ctrl" export let returnOrEnter = isMac ? "return" : "enter" diff --git a/src/core/resolvers.test.ts b/src/core/resolvers.test.ts index d69e99fc..89b34696 100644 --- a/src/core/resolvers.test.ts +++ b/src/core/resolvers.test.ts @@ -6,8 +6,7 @@ import { home, kitPath, kenvPath, - kitDotEnvPath, - knodePath + kitDotEnvPath } from "./resolvers" // Helper function to set up environment variables diff --git a/src/core/resolvers.ts b/src/core/resolvers.ts index ef0ab6c9..4a338bbb 100644 --- a/src/core/resolvers.ts +++ b/src/core/resolvers.ts @@ -39,8 +39,3 @@ export let kitDotEnvPath = () => { getEnvOrDefault(process.env.KIT_DOTENV_PATH, kenvPath(".env")) )() } - -export let knodePath = (...parts: string[]) => { - const knodeDir = getEnvOrDefault(process.env.KNODE, home(".knode")) - return createPathResolver(knodeDir)(...parts.filter(Boolean)) -} diff --git a/src/core/utils.ts b/src/core/utils.ts index a7655dc1..140813cd 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -9,7 +9,6 @@ import type { Scriptlet, Snippet } from "../types/core" -import { platform } from "node:os" import { lstatSync, realpathSync } from "node:fs" import { lstat, readdir } from "node:fs/promises" import { execSync } from "node:child_process" @@ -26,7 +25,7 @@ import tsPlugin from "acorn-typescript" import type { Stamp } from "./db" import { pathToFileURL } from "node:url" import { parseScript } from "./parser.js" -import { kitPath, kenvPath, knodePath } from "./resolvers.js" +import { kitPath, kenvPath } from "./resolvers.js" import { cmd } from "./constants.js" import { isBin, isJsh, isDir, isWin, isMac } from "./is.js" @@ -1411,8 +1410,7 @@ export { home, kitPath, kenvPath, - kitDotEnvPath, - knodePath + kitDotEnvPath } from "./resolvers.js" export { isBin, isFile, isJsh, isDir, isLinux, isMac, isWin } from "./is.js" diff --git a/src/index.ts b/src/index.ts index 8b19f34a..5820b20e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,29 +2,22 @@ import { homedir } from "os" import path from "path" import { URL, fileURLToPath } from "url" -let kitRun = async ( - command?: string, - ..._args: string[] -) => { - process.env.KIT = - process.env.KIT || - path.dirname(fileURLToPath(new URL(import.meta.url))) - - process.env.KNODE = - process.env.KNODE || path.resolve(homedir(), ".knode") - - await import("./api/global.js") - await import("./api/kit.js") - await import("./api/lib.js") - await import("./target/terminal.js") - - if (command) { - return await global.run(command, ..._args) - } +let kitRun = async (command?: string, ..._args: string[]) => { + process.env.KIT = + process.env.KIT || path.dirname(fileURLToPath(new URL(import.meta.url))) + + await import("./api/global.js") + await import("./api/kit.js") + await import("./api/lib.js") + await import("./target/terminal.js") + + if (command) { + return await global.run(command, ..._args) + } } if (!process?.env?.KIT_TARGET) { - await kitRun() + await kitRun() } export * from "./api/kit.js" @@ -32,32 +25,28 @@ export * from "./core/utils.js" let dirs = ["cli", "main"] -let kitGet = ( - _target: any, - key: string, - _receiver: any -) => { - if ((global as any)[key] && !dirs.includes(key)) { - return (global as any)[key] - } - - try { - return new Proxy( - {}, - { - get: async (_target, module: string, _receiver) => { - let modulePath = `../${key}/${module}.js?${global.uuid()}` - return await import(modulePath) - }, - } - ) - } catch (error) { - console.warn(error) - } +let kitGet = (_target: any, key: string, _receiver: any) => { + if ((global as any)[key] && !dirs.includes(key)) { + return (global as any)[key] + } + + try { + return new Proxy( + {}, + { + get: async (_target, module: string, _receiver) => { + let modulePath = `../${key}/${module}.js?${global.uuid()}` + return await import(modulePath) + } + } + ) + } catch (error) { + console.warn(error) + } } let kitDefault = new Proxy(kitRun, { - get: kitGet, + get: kitGet }) global.kit = kitDefault diff --git a/src/platform/darwin.ts b/src/platform/darwin.ts index 6f13426c..df063096 100644 --- a/src/platform/darwin.ts +++ b/src/platform/darwin.ts @@ -1,65 +1,58 @@ import { - KIT_FIRST_PATH, - KIT_DEFAULT_PATH, - getMainScriptPath, - isInDir, - cmd, - escapeShortcut, + KIT_FIRST_PATH, + KIT_DEFAULT_PATH, + getMainScriptPath, + isInDir, + cmd, + escapeShortcut } from "../core/utils.js" import { refreshScripts } from "../core/db.js" -global.applescript = async ( - script, - options = { silent: true } -) => { - let applescriptPath = kenvTmpPath("latest.scpt") - await writeFile(applescriptPath, script) - - let p = new Promise((res, rej) => { - let stdout = `` - let stderr = `` - let child = spawn( - `/usr/bin/osascript`, - [applescriptPath], - options - ) - - child.stdout.on("data", data => { - stdout += data.toString().trim() - }) - child.stderr.on("data", data => { - stderr += data.toString().trim() - }) - - child.on("exit", () => { - res(stdout) - }) - - child.on("error", () => { - rej(stderr) - }) - }) - - return p +global.applescript = async (script, options = { silent: true }) => { + let applescriptPath = kenvTmpPath("latest.scpt") + await writeFile(applescriptPath, script) + + let p = new Promise((res, rej) => { + let stdout = `` + let stderr = `` + let child = spawn(`/usr/bin/osascript`, [applescriptPath], options) + + child.stdout.on("data", (data) => { + stdout += data.toString().trim() + }) + child.stderr.on("data", (data) => { + stderr += data.toString().trim() + }) + + child.on("exit", () => { + res(stdout) + }) + + child.on("error", () => { + rej(stderr) + }) + }) + + return p } -global.terminal = async script => { - let formattedScript = script.replace(/'|"/g, '\\"') +global.terminal = async (script) => { + let formattedScript = script.replace(/'|"/g, '\\"') - let command = `tell application "Terminal" + let command = `tell application "Terminal" if not application "Terminal" is running then launch activate do script "${formattedScript}" end tell ` - return await global.applescript(command) + return await global.applescript(command) } -global.iterm = async command => { - command = `"${command.replace(/"/g, '\\"')}"` - let script = ` +global.iterm = async (command) => { + command = `"${command.replace(/"/g, '\\"')}"` + let script = ` tell application "iTerm" activate if application "iTerm" is running then @@ -76,15 +69,15 @@ global.iterm = async command => { end tell `.trim() - return await global.applescript(script) + return await global.applescript(script) } //TODO: refactor this work around if electron ever gets native osascript support // https://github.com/vercel/hyper/issues/3410 // https://github.com/electron/electron/issues/4418 -global.hyper = async command => { - command = `"${command.replace(/"/g, '\\"')}"` - let script = ` +global.hyper = async (command) => { + command = `"${command.replace(/"/g, '\\"')}"` + let script = ` tell application "Hyper" activate if application "Hyper" is running then @@ -101,108 +94,104 @@ global.hyper = async command => { end tell end tell `.trim() - return await global.applescript(script) + return await global.applescript(script) } -let terminalEditor = editor => async file => { - //TODO: Other terminals? - let supportedTerminalMap = { - terminal: global.terminal, - iterm: global.iterm, - hyper: global.hyper, - } - - let possibleTerminals = () => - Object.entries(supportedTerminalMap) - .filter(async ([name, value]) => { - return fileSearch(name, { - onlyin: "/", - kind: "application", - }) - }) - .map(([name, value]) => ({ name, value: name })) - - let KIT_TERMINAL = await global.env("KIT_TERMINAL", { - placeholder: `Which Terminal do you use with ${editor}?`, - choices: possibleTerminals(), - }) - - return supportedTerminalMap[KIT_TERMINAL]( - `${editor} ${file}` - ) +let terminalEditor = (editor) => async (file) => { + //TODO: Other terminals? + let supportedTerminalMap = { + terminal: global.terminal, + iterm: global.iterm, + hyper: global.hyper + } + + let possibleTerminals = () => + Object.entries(supportedTerminalMap) + .filter(async ([name, value]) => { + return fileSearch(name, { + onlyin: "/", + kind: "application" + }) + }) + .map(([name, value]) => ({ name, value: name })) + + let KIT_TERMINAL = await global.env("KIT_TERMINAL", { + placeholder: `Which Terminal do you use with ${editor}?`, + choices: possibleTerminals() + }) + + return supportedTerminalMap[KIT_TERMINAL](`${editor} ${file}`) } let execConfig = () => { - return { - shell: true, - env: { - HOME: home(), - PATH: KIT_FIRST_PATH, - }, - } + return { + shell: true, + env: { + HOME: home(), + PATH: KIT_FIRST_PATH + } + } } let macEditors = [ - "atom", - "code", - "cursor", - "cursor-nightly", - "emacs", - "nano", - "ne", - "nvim", - "sublime", - "webstorm", - "vim", - "zed", + "atom", + "code", + "cursor", + "cursor-nightly", + "emacs", + "nano", + "ne", + "nvim", + "sublime", + "webstorm", + "vim", + "zed" ] let safeReaddir = async (path: string) => { - try { - return await readdir(path) - } catch (e) { - return [] - } + try { + return await readdir(path) + } catch (e) { + return [] + } } global.selectKitEditor = async (reset = false) => { - let globalBins = [] - let binPaths = KIT_DEFAULT_PATH.split(":") - for await (let binPath of binPaths) { - let bins = await safeReaddir(binPath) - for (let bin of bins) { - let value = path.resolve(binPath, bin) - globalBins.push({ - name: bin, - description: value, - value, - }) - } - } - - let possibleEditors = () => { - let filteredMacEditors = macEditors - .map(editor => - globalBins.find(({ name }) => name === editor) - ) - .filter(Boolean) - - filteredMacEditors.push({ - name: "kit", - description: "built-in Script Kit editor", - value: "kit", - }) - - return filteredMacEditors - } - return await global.env("KIT_EDITOR", { - description: `Select a code editor for Script Kit`, - name: " ", - reset, - resize: false, - height: PROMPT.HEIGHT.XL, - placeholder: "Which code editor do you use?", - preview: md(` + let globalBins = [] + let binPaths = KIT_DEFAULT_PATH.split(":") + for await (let binPath of binPaths) { + let bins = await safeReaddir(binPath) + for (let bin of bins) { + let value = path.resolve(binPath, bin) + globalBins.push({ + name: bin, + description: value, + value + }) + } + } + + let possibleEditors = () => { + let filteredMacEditors = macEditors + .map((editor) => globalBins.find(({ name }) => name === editor)) + .filter(Boolean) + + filteredMacEditors.push({ + name: "kit", + description: "built-in Script Kit editor", + value: "kit" + }) + + return filteredMacEditors + } + return await global.env("KIT_EDITOR", { + description: `Select a code editor for Script Kit`, + name: " ", + reset, + resize: false, + height: PROMPT.HEIGHT.XL, + placeholder: "Which code editor do you use?", + preview: md(` > You can change your editor later in .env ## Don't see your editor? @@ -220,7 +209,7 @@ If you edited your ~/.zshrc (or similar) for a custom command then sync your PAT Run the following in your terminal: ~~~bash -~/.knode/bin/node ~/.kit/cli/sync-path.js ~/.kenv/.env +~/.kenv/pnpm node ~/.kit/cli/sync-path.js ~/.kenv/.env ~~~ ## Still not working? @@ -232,158 +221,149 @@ If you need additional help, we're happy to answer questions: - [GitHub Discussions](https://github.com/johnlindquist/kit/discussions/categories/q-a) `), - choices: [ - ...possibleEditors(), - { - name: "None. Always copy path to clipboard", - value: "copy", - }, - ], - }) + choices: [ + ...possibleEditors(), + { + name: "None. Always copy path to clipboard", + value: "copy" + } + ] + }) } let execAndLogCommand = async ( - command: string, - config: Parameters[1] + command: string, + config: Parameters[1] ) => { - global.log(`${process.pid}: > ${command}`) - return exec(command, config) + global.log(`${process.pid}: > ${command}`) + return exec(command, config) } let atom = async (file: string, dir: string) => { - let command = `${global.env.KIT_EDITOR} '${file}' ${ - dir ? ` '${dir}'` : `` - }` - await execAndLogCommand(command, execConfig()) + let command = `${global.env.KIT_EDITOR} '${file}' ${dir ? ` '${dir}'` : ``}` + await execAndLogCommand(command, execConfig()) } let code = async (file, dir, line = 0, col = 0) => { - let codeArgs = ["--goto", `'${file}:${line}:${col}'`] - if (dir) - codeArgs = [...codeArgs, "--folder-uri", `'${dir}'`] - let command = `${global.env.KIT_EDITOR} ${codeArgs.join( - " " - )}` + let codeArgs = ["--goto", `'${file}:${line}:${col}'`] + if (dir) codeArgs = [...codeArgs, "--folder-uri", `'${dir}'`] + let command = `${global.env.KIT_EDITOR} ${codeArgs.join(" ")}` - let config = execConfig() + let config = execConfig() - await execAndLogCommand(command, config) + await execAndLogCommand(command, config) } let webstorm = async (file, dir, line = 0) => { - let command = `open -na "WebStorm.app" --args --line ${line} ${file}` + let command = `open -na "WebStorm.app" --args --line ${line} ${file}` - let config = execConfig() + let config = execConfig() - await execAndLogCommand(command, config) + await execAndLogCommand(command, config) } let vim = terminalEditor("vim") let nvim = terminalEditor("nvim") let nano = terminalEditor("nano") let fullySupportedEditors = { - code, - cursor: code, - ["cursor-nightly"]: code, - zed: atom, - vim, - nvim, - nano, - atom, - webstorm, + code, + cursor: code, + ["cursor-nightly"]: code, + zed: atom, + vim, + nvim, + nano, + atom, + webstorm } global.edit = async (f, dir, line = 0, col = 0) => { - // console.log(`📝 Edit ${f}`) - let file = path.resolve( - f?.startsWith("~") ? f.replace(/^~/, home()) : f - ) - if (global.flag?.edit === false) return - - let KIT_EDITOR = await global.selectKitEditor(false) - - if (KIT_EDITOR === "kit") { - let language = global.extname(file).replace(/^\./, "") - let contents = (await readFile(file, "utf8")) || "" - let extraLibs = await global.getExtraLibs() - - let openMain = false - let onEscape = async (input, state) => { - openMain = - state?.history[0]?.filePath === getMainScriptPath() - if (input) submit(input) - } - let onAbandon = async (input, state) => { - if (input) submit(input) - } - - contents = await editor({ - value: contents, - description: file, - language, - extraLibs, - onAbandon, - shortcuts: [ - { - name: "Close", - key: `${cmd}+w`, - onPress: async (input, state) => { - exit() - }, - bar: "right", - }, - { - name: "Save and Close", - key: "escape", - onPress: onEscape, - bar: "right", - }, - ], - }) - - await writeFile(file, contents) - if (openMain) { - await refreshScripts() - - await mainScript() - } - } else { - await hide() - - let execEditor = async (file: string) => { - let editCommand = `"${KIT_EDITOR}" "${file}"` - let config = execConfig() - let { exitCode, stdout, stderr } = - await execAndLogCommand(editCommand, config) - - global.log( - `${ - process.pid - }: Edit command exited with ${exitCode}. ${ - exitCode === 0 ? "✅" : "❌" - }` - ) - - if (exitCode !== 0) { - global.log(`Stdout: ${stdout}`) - global.log(`Stderr: ${stderr}`) - } - } - let editorFn = - fullySupportedEditors[path.basename(KIT_EDITOR)] || - execEditor - - try { - await editorFn(file, dir, line, col) - } catch {} - } + // console.log(`📝 Edit ${f}`) + let file = path.resolve(f?.startsWith("~") ? f.replace(/^~/, home()) : f) + if (global.flag?.edit === false) return + + let KIT_EDITOR = await global.selectKitEditor(false) + + if (KIT_EDITOR === "kit") { + let language = global.extname(file).replace(/^\./, "") + let contents = (await readFile(file, "utf8")) || "" + let extraLibs = await global.getExtraLibs() + + let openMain = false + let onEscape = async (input, state) => { + openMain = state?.history[0]?.filePath === getMainScriptPath() + if (input) submit(input) + } + let onAbandon = async (input, state) => { + if (input) submit(input) + } + + contents = await editor({ + value: contents, + description: file, + language, + extraLibs, + onAbandon, + shortcuts: [ + { + name: "Close", + key: `${cmd}+w`, + onPress: async (input, state) => { + exit() + }, + bar: "right" + }, + { + name: "Save and Close", + key: "escape", + onPress: onEscape, + bar: "right" + } + ] + }) + + await writeFile(file, contents) + if (openMain) { + await refreshScripts() + + await mainScript() + } + } else { + await hide() + + let execEditor = async (file: string) => { + let editCommand = `"${KIT_EDITOR}" "${file}"` + let config = execConfig() + let { exitCode, stdout, stderr } = await execAndLogCommand( + editCommand, + config + ) + + global.log( + `${process.pid}: Edit command exited with ${exitCode}. ${ + exitCode === 0 ? "✅" : "❌" + }` + ) + + if (exitCode !== 0) { + global.log(`Stdout: ${stdout}`) + global.log(`Stderr: ${stderr}`) + } + } + let editorFn = + fullySupportedEditors[path.basename(KIT_EDITOR)] || execEditor + + try { + await editorFn(file, dir, line, col) + } catch {} + } } global.openLog = () => { - let logPath = global.kitScript - .replace("scripts", "logs") - .replace(new RegExp(`\${kitMode()}$`), "log") + let logPath = global.kitScript + .replace("scripts", "logs") + .replace(new RegExp(`\${kitMode()}$`), "log") - console.log(`📂 Open log ${logPath}`) + console.log(`📂 Open log ${logPath}`) - global.edit(logPath) + global.edit(logPath) } diff --git a/src/setup/setup.test.js b/src/setup/setup.test.js index 82e57766..9a31a872 100644 --- a/src/setup/setup.test.js +++ b/src/setup/setup.test.js @@ -5,104 +5,77 @@ import { pathToFileURL } from "node:url" /** @type {import("../core/utils")} */ let { isFile, KIT_FIRST_PATH } = await import( - pathToFileURL(kitPath("core", "utils.js")).href + pathToFileURL(kitPath("core", "utils.js")).href ) let KIT = kitPath() let KENV = kenvTestPath -let KNODE = - process.env.KNODE || path.resolve(os.homedir(), ".knode") let kenvSetupMockPath = (...parts) => { - return path.resolve(KENV, ...parts) + return path.resolve(KENV, ...parts) } /** @type {import("child_process").SpawnSyncOptions} */ const options = { - cwd: KIT, - encoding: "utf-8", - env: { - KIT, - KENV, - KNODE, - PATH: KIT_FIRST_PATH, - }, + cwd: KIT, + encoding: "utf-8", + env: { + KIT, + KENV, + KNODE, + PATH: KIT_FIRST_PATH + } } -ava.before(`Run setup script`, t => { - const setupResult = spawnSync( - `./script`, - [`./setup/setup.js`], - options - ) +ava.before(`Run setup script`, (t) => { + const setupResult = spawnSync(`./script`, [`./setup/setup.js`], options) }) -ava.serial("env was created", async t => { - let envPath = kenvSetupMockPath(".env") - t.log({envPath}) - let checkEnv = await isFile(envPath) - let contents = await readFile( - envPath, - "utf-8" - ) - - t.true(checkEnv, `env was created`) - t.false( - contents.includes("{{"), - `Check if .env was compiled` - ) +ava.serial("env was created", async (t) => { + let envPath = kenvSetupMockPath(".env") + t.log({ envPath }) + let checkEnv = await isFile(envPath) + let contents = await readFile(envPath, "utf-8") + + t.true(checkEnv, `env was created`) + t.false(contents.includes("{{"), `Check if .env was compiled`) }) -ava.serial("kenv linked to kit", async t => { - let pkg = await readJson( - kenvSetupMockPath("package.json") - ) +ava.serial("kenv linked to kit", async (t) => { + let pkg = await readJson(kenvSetupMockPath("package.json")) - t.assert( - pkg.devDependencies?.["@johnlindquist/kit"], - "file:../.kit", - `kenv linked to kit` - ) + t.assert( + pkg.devDependencies?.["@johnlindquist/kit"], + "file:../.kit", + `kenv linked to kit` + ) }) -ava.serial("kenv degit", async t => { - let files = await readdir(kenvSetupMockPath()) +ava.serial("kenv degit", async (t) => { + let files = await readdir(kenvSetupMockPath()) - t.false( - files.includes(".git"), - ".git was removed from kenv" - ) + t.false(files.includes(".git"), ".git was removed from kenv") }) -ava.serial("chmod", async t => { - if (process.platform === 'win32') { - t.pass('Skipping chmod test on Windows'); - return; - } - - let { access } = await import("node:fs/promises") - let { constants } = await import("node:fs") - - let bins = [ - "scripts", - "kar", - "bin k", - "bin kit", - "bin sk", - ] - - for (let b of bins) { - let binPath = kitPath(...b.split(" ")) - t.log(binPath) - let result = await access(binPath, constants.X_OK) - t.true(isUndefined(result), "bins can be executed") - } +ava.serial("chmod", async (t) => { + if (process.platform === "win32") { + t.pass("Skipping chmod test on Windows") + return + } + + let { access } = await import("node:fs/promises") + let { constants } = await import("node:fs") + + let bins = ["scripts", "kar", "bin k", "bin kit", "bin sk"] + + for (let b of bins) { + let binPath = kitPath(...b.split(" ")) + t.log(binPath) + let result = await access(binPath, constants.X_OK) + t.true(isUndefined(result), "bins can be executed") + } }) -ava.serial("example script exists", async t => { - t.truthy( - await pathExists( - kenvPath("scripts", "browse-scriptkit.js") - ) - ) +ava.serial("example script exists", async (t) => { + t.truthy(await pathExists(kenvPath("scripts", "browse-scriptkit.js"))) }) diff --git a/test-sdk/config.js b/test-sdk/config.js index 3817daaa..7f1721ac 100644 --- a/test-sdk/config.js +++ b/test-sdk/config.js @@ -4,8 +4,6 @@ import { pathToFileURL } from "node:url" process.env.KIT = process.env.KIT || path.resolve(os.homedir(), ".kit") -process.env.KNODE = process.env.KNODE || path.resolve(os.homedir(), ".knode") - let importKit = async (...parts) => { let partsPath = path.resolve(process.env.KIT, ...parts) await import(pathToFileURL(partsPath).href) diff --git a/test-sdk/main.test.js b/test-sdk/main.test.js index 6f490dd5..1dc0ba14 100644 --- a/test-sdk/main.test.js +++ b/test-sdk/main.test.js @@ -7,8 +7,6 @@ process.env.NODE_NO_WARNINGS = 1 process.env.KIT = process.env.KIT || path.resolve(os.homedir(), ".kit") -process.env.KNODE = process.env.KNODE || path.resolve(homedir(), ".knode") - ava.serial("app-prompt.js", async (t) => { let script = "mock-script-with-arg" let scriptPath = kenvPath("scripts", `${script}.js`) @@ -301,12 +299,14 @@ ava.serial("Run both JS and TS scripts", async (t) => { let newJSCommandResult = await exec(`kit new ${jsCommand} main --no-edit`, { env: { ...process.env, + EXEC_PATH: process.execPath, KIT_MODE: "js" } }) let newTSCommandResult = await exec(`kit new ${tsCommand} main --no-edit`, { env: { ...process.env, + KIT_EXEC_PATH: process.execPath, KIT_MODE: "ts" } }) @@ -333,6 +333,7 @@ ava.serial("Run kit from package.json", async (t) => { await exec(`kit new ${command} main --no-edit`, { env: { ...process.env, + EXEC_PATH: process.execPath, KIT_MODE: "js" } })