@@ -5,6 +5,7 @@ const fs = isBare ? require('bare-fs') : require('fs')
5
5
const path = isBare ? require ( 'bare-path' ) : require ( 'path' )
6
6
const { pathToFileURL } = require ( 'url-file-url' )
7
7
const hypercoreid = require ( 'hypercore-id-encoding' )
8
+ const pearLink = require ( 'pear-link' )
8
9
const z32 = require ( 'z32' )
9
10
const crypto = require ( 'hypercore-crypto' )
10
11
const { PLATFORM_DIR , SWAP , RUNTIME } = require ( 'pear-api/constants' )
@@ -40,7 +41,7 @@ module.exports = class State {
40
41
static injestPackage ( state , pkg , overrides = { } ) {
41
42
state . manifest = pkg
42
43
state . main = pkg ?. main || 'index.html'
43
- state . options = pkg ?. pear || null
44
+ state . options = pkg ?. pear || { }
44
45
state . name = pkg ?. pear ?. name || pkg ?. name || null
45
46
state . links = pkg ?. pear ?. links || null
46
47
state . gui = pkg ?. pear ?. gui || null
@@ -148,7 +149,7 @@ module.exports = class State {
148
149
this . stage = stage
149
150
this . fragment = fragment
150
151
this . linkData = segment
151
- this . link = link ? ( link . startsWith ( protocol ) ? link : pathToFileURL ( link ) . toString ( ) ) : null
152
+ this . link = link ? ( link . startsWith ( protocol ) ? link : pearLink . normalize ( pathToFileURL ( link ) . toString ( ) ) ) : null
152
153
this . key = key
153
154
this . applink = key ? this . link . slice ( 0 , - ( ~ ~ ( pathname ?. length ) + ~ ~ ( hash ?. length ) ) ) : null
154
155
this . alias = alias
@@ -165,7 +166,8 @@ module.exports = class State {
165
166
this . env . NODE_ENV = this . env . NODE_ENV || 'production'
166
167
}
167
168
this . constructor . injestPackage ( this , pkg , { links } )
168
- const invalidStorage = this . key === null && this . storage !== null && this . storage . startsWith ( this . dir ) && this . storage . includes ( '/pear/pear/' ) === false
169
+ const invalidStorage = this . key === null && this . storage !== null
170
+ && this . storage . startsWith ( this . dir ) && this . storage . includes ( path . sep + 'pear' + path . sep + 'pear' + path . sep ) === false
169
171
if ( invalidStorage ) throw ERR_INVALID_APP_STORAGE ( 'Application Storage may not be inside the project directory. --store "' + this . storage + '" is invalid' )
170
172
const invalidName = / ^ [ @ / a - z 0 - 9 - _ ] + $ / . test ( this . name ) === false
171
173
if ( invalidName ) throw ERR_INVALID_APP_NAME ( 'The package.json name / pear.name field must be lowercase and one word, and may contain letters, numbers, hyphens (-), underscores (_), forward slashes (/) and asperands (@).' )
0 commit comments