pear-electron 1.4.2 → 1.4.4

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/package.json +2 -2
  2. package/runtime.js +11 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pear-electron",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "description": "Pear User-Interface Library for Electron",
5
5
  "main": "index.js",
6
6
  "bin": "bin.js",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "pear": {
21
21
  "name": "pear-electron",
22
- "bootstrap": "pear://0.2621.yceb7sjhgfzsnza7oc38hy3oxu9dhnywi3mzxdm9ubc48kjnxqgo",
22
+ "bootstrap": "pear://0.2623.yceb7sjhgfzsnza7oc38hy3oxu9dhnywi3mzxdm9ubc48kjnxqgo",
23
23
  "stage": {
24
24
  "skipWarmup": "true",
25
25
  "only": [
package/runtime.js CHANGED
@@ -99,9 +99,9 @@ class PearElectron {
99
99
 
100
100
  const cwd = os.cwd()
101
101
  let dir = cwd
102
- let base = null
103
102
  if (key === null) {
104
- base = project(pathname, pathname, cwd)
103
+ const initial = normalize(pathname)
104
+ const base = project(initial, initial)
105
105
  dir = base.dir
106
106
  if (dir.length > 1 && dir.endsWith('/')) dir = dir.slice(0, -1)
107
107
  if (isPath) {
@@ -172,22 +172,24 @@ class PearElectron {
172
172
  }
173
173
  }
174
174
 
175
- function project (dir, origin, cwd) {
175
+ function project (dir, initial) {
176
176
  try {
177
177
  if (JSON.parse(fs.readFileSync(path.join(dir, 'package.json'))).pear) {
178
- return { dir, origin, entrypoint: isWindows ? path.normalize(origin.slice(1)).slice(dir.length) : origin.slice(dir.length) }
178
+ return { dir, entrypoint: initial.slice(dir.length) }
179
179
  }
180
180
  } catch (err) {
181
181
  if (err.code !== 'ENOENT' && err.code !== 'EISDIR' && err.code !== 'ENOTDIR') throw err
182
182
  }
183
183
  const parent = path.dirname(dir)
184
184
  if (parent === dir) {
185
- const normalizedOrigin = !isWindows ? origin : path.normalize(origin.slice(1))
186
- const cwdIsOrigin = path.relative(cwd, normalizedOrigin).length === 0
187
- const condition = cwdIsOrigin ? `at "${cwd}"` : normalizedOrigin.includes(cwd) ? `from "${normalizedOrigin}" up to "${cwd}"` : `at "${normalizedOrigin}"`
188
- throw ERR_INVALID_PROJECT_DIR(`A valid package.json file with pear field must exist ${condition}`)
185
+ throw ERR_INVALID_PROJECT_DIR(`A valid package.json file with pear field must exist (checked from "${initial}" to "${dir}")`)
189
186
  }
190
- return project(parent, origin, cwd)
187
+ return project(parent, initial)
188
+ }
189
+
190
+ function normalize (pathname) {
191
+ if (isWindows) return path.normalize(pathname.slice(1))
192
+ return pathname
191
193
  }
192
194
 
193
195
  module.exports = PearElectron