Skip to content

Commit

Permalink
fix: convert file URL to path (#123)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
eduardoboucas and kodiakhq[bot] authored Sep 14, 2022
1 parent d75af0d commit ff78c96
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions node/package_json.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import { readFileSync } from 'fs'
import { dirname, join } from 'path'
import { join } from 'path'
import { fileURLToPath } from 'url'

import { findUpSync } from 'find-up'
import { findUpSync, pathExistsSync } from 'find-up'

const getPackagePath = () => {
const packageJSONPath = findUpSync('package.json', { cwd: import.meta.url })
const packagePath = findUpSync(
(directory: string) => {
if (pathExistsSync(join(directory, 'package.json'))) {
return directory
}
},
{ cwd: fileURLToPath(import.meta.url), type: 'directory' },
)

// We should never get here, but let's show a somewhat useful error message.
if (packageJSONPath === undefined) {
if (packagePath === undefined) {
throw new Error(
'Could not find `package.json` for `@netlify/edge-bundler`. Please try running `npm install` to reinstall your dependencies.',
)
}

return dirname(packageJSONPath)
return packagePath
}

const getPackageVersion = () => {
Expand Down

0 comments on commit ff78c96

Please sign in to comment.