Skip to content

Commit

Permalink
feat(wip): pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlindquist committed Sep 1, 2024
1 parent 63a1f32 commit d33b3bc
Show file tree
Hide file tree
Showing 17 changed files with 362 additions and 438 deletions.
44 changes: 25 additions & 19 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ jobs:
shell: bash
env:
KIT: ${{ env.kit_path }}
KNODE: ${{ env.knode_path }}
run: |
npm run build-kit
Expand All @@ -56,7 +55,6 @@ jobs:
npm run test
env:
KIT: ${{ env.kit_path }}
KNODE: ${{ env.knode_path }}


test-mac-and-ubuntu:
Expand All @@ -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"
Expand Down Expand Up @@ -126,7 +128,6 @@ jobs:
npm run test
env:
KIT: ${{ env.kit_path }}
KNODE: ${{ env.knode_path }}

release:
runs-on: macos-latest
Expand All @@ -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"
Expand Down
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion build/build-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion root/bin/kit
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion root/bin/kit.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion root/script
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
2 changes: 0 additions & 2 deletions src/api/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
kitPath,
kenvPath,
wait,
knodePath,
getLogFromScriptPath,
createPathResolver
} from "../core/utils.js"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/cli/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/core/constants.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 1 addition & 2 deletions src/core/resolvers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
home,
kitPath,
kenvPath,
kitDotEnvPath,
knodePath
kitDotEnvPath
} from "./resolvers"

// Helper function to set up environment variables
Expand Down
5 changes: 0 additions & 5 deletions src/core/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
6 changes: 2 additions & 4 deletions src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand Down Expand Up @@ -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"
Expand Down
75 changes: 32 additions & 43 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,51 @@ 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"
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
Expand Down
Loading

0 comments on commit d33b3bc

Please sign in to comment.