Skip to content

Commit

Permalink
fix: use right location for Deno bundler (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Sep 14, 2022
1 parent 4bf8138 commit a8a9f5d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
9 changes: 4 additions & 5 deletions node/formats/eszip.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { join, resolve } from 'path'
import { fileURLToPath } from 'url'
import { join } from 'path'

import type { WriteStage2Options } from '../../shared/stage2.js'
import { DenoBridge } from '../bridge.js'
import type { Bundle } from '../bundle.js'
import { wrapBundleError } from '../bundle_error.js'
import { EdgeFunction } from '../edge_function.js'
import { ImportMap } from '../import_map.js'
import { getPackagePath } from '../package_json.js'
import { getFileHash } from '../utils/sha256.js'

interface BundleESZIPOptions {
Expand Down Expand Up @@ -55,9 +55,8 @@ const bundleESZIP = async ({
}

const getESZIPBundler = () => {
const url = new URL(import.meta.url)
const pathname = fileURLToPath(url)
const bundlerPath = resolve(pathname, '../../../deno/bundle.ts')
const packagePath = getPackagePath()
const bundlerPath = join(packagePath, 'deno', 'bundle.ts')

return bundlerPath
}
Expand Down
18 changes: 14 additions & 4 deletions node/package_json.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import { readFileSync } from 'fs'
import { dirname, join } from 'path'

import { findUpSync } from 'find-up'

const getPackageVersion = () => {
const getPackagePath = () => {
const packageJSONPath = findUpSync('package.json', { cwd: import.meta.url })

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

return dirname(packageJSONPath)
}

const getPackageVersion = () => {
const packagePath = getPackagePath()

try {
const packageJSON = readFileSync(packageJSONPath, 'utf8')
const packageJSON = readFileSync(join(packagePath, 'package.json'), 'utf8')
const { version } = JSON.parse(packageJSON)

return version as string
Expand All @@ -19,4 +29,4 @@ const getPackageVersion = () => {
}
}

export { getPackageVersion }
export { getPackagePath, getPackageVersion }

0 comments on commit a8a9f5d

Please sign in to comment.