Skip to content

Commit

Permalink
fix: resolve path on node
Browse files Browse the repository at this point in the history
  • Loading branch information
nobkd committed Dec 19, 2024
1 parent fcff463 commit bca9a16
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/nuekit/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { sep } from 'node:path'
import { pathToFileURL } from 'node:url'

import { log, colors, getVersion, getEngine } from './util.js'
import { esMain, log, colors, getVersion, getEngine } from './util.js'


// [-npe] --> [-n, -p, -e]
Expand Down Expand Up @@ -125,7 +125,7 @@ async function runCommand(args) {
}

// Only run main when called as real CLI
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
if (esMain(import.meta)) {

const args = getArgs(process.argv)

Expand Down
7 changes: 6 additions & 1 deletion packages/nuekit/src/util.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
/* misc stuff. think shame.css */

import { promises as fs } from 'node:fs'
import { sep, parse, normalize, join, isAbsolute, dirname } from 'node:path'
import { sep, parse, normalize, join, isAbsolute, dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'


export const srcdir = dirname(fileURLToPath(import.meta.url))

export const openUrl = process.platform == 'darwin' ? 'open' : process.platform == 'win32' ? 'start' : 'xdg-open'

export function esMain(meta) {
if (!meta || !process.argv[1]) return false
return fileURLToPath(meta.resolve(process.argv[1])) === fileURLToPath(meta.url)
}

// read from package.json
export async function getVersion() {
const path = join(srcdir, '../package.json')
Expand Down

0 comments on commit bca9a16

Please sign in to comment.