pear-build 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +24 -3
  2. package/package.json +3 -2
package/index.js CHANGED
@@ -3,6 +3,7 @@ const path = require('path')
3
3
  const fs = require('fs')
4
4
  const { EventEmitter } = require('events')
5
5
  const Localdrive = require('localdrive')
6
+ const { ERR_NOT_FOUND, ERR_INVALID_INPUT, ERR_INVALID_APP_NAME } = require('pear-errors')
6
7
 
7
8
  class Build extends EventEmitter {
8
9
  constructor(opts) {
@@ -12,9 +13,26 @@ class Build extends EventEmitter {
12
13
  }
13
14
 
14
15
  async run(opts) {
16
+ if (!opts.package) throw ERR_INVALID_INPUT('package.json path must be specified.')
15
17
  const pkgPath = path.resolve(opts.package)
16
- const pkgFile = await fs.promises.readFile(pkgPath, 'utf-8')
17
- const pkg = JSON.parse(pkgFile)
18
+
19
+ const pkgFile = await fs.promises.readFile(pkgPath, 'utf8').catch((err) => {
20
+ if (err.code === 'ENOENT') {
21
+ throw ERR_NOT_FOUND('package.json not found', { path: pkgPath, cause: err })
22
+ }
23
+ if (err.code === 'EISDIR') {
24
+ throw ERR_INVALID_INPUT('package.json must be a file', { path: pkgPath, cause: err })
25
+ }
26
+ throw err
27
+ })
28
+
29
+ let pkg
30
+ try {
31
+ pkg = JSON.parse(pkgFile)
32
+ } catch (err) {
33
+ throw ERR_INVALID_INPUT('package.json is not a valid JSON', { path: pkgPath })
34
+ }
35
+
18
36
  const { target = path.resolve(pkg.name + '-' + pkg.version) } = opts
19
37
  const darwinArm64App = opts.darwinArm64App
20
38
  ? ['darwin-arm64', path.resolve(opts.darwinArm64App)]
@@ -67,7 +85,10 @@ class Build extends EventEmitter {
67
85
  const promises = []
68
86
  for (const [arch, app] of apps) {
69
87
  if (path.basename(app, path.extname(app)) !== appName) {
70
- throw new Error(`expected directory ${appName} but got ${path.basename(app)} for ${arch}`)
88
+ throw ERR_INVALID_APP_NAME(
89
+ `expected directory ${appName} but got ${path.basename(app)} for ${arch}`,
90
+ { arch, app }
91
+ )
71
92
  }
72
93
  const archApp = path.join(byArch, arch, 'app')
73
94
  await fs.promises.mkdir(archApp, { recursive: true })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pear-build",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "main": "index.js",
5
5
  "type": "commonjs",
6
6
  "bin": {
@@ -56,7 +56,8 @@
56
56
  "bare-fs": "^4.5.3",
57
57
  "bare-path": "^3.0.0",
58
58
  "localdrive": "^2.2.0",
59
- "paparam": "^1.10.0"
59
+ "paparam": "^1.10.0",
60
+ "pear-errors": "^1.0.1"
60
61
  },
61
62
  "devDependencies": {
62
63
  "brittle": "^4.0.0",