pear-electron 0.2.3 → 0.2.5

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 +1 -1
  2. package/preload.js +71 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pear-electron",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Pear User-Interface Library for Electron",
5
5
  "main": "index.js",
6
6
  "bin": "bin.js",
package/preload.js CHANGED
@@ -43,6 +43,76 @@ module.exports = (state) => {
43
43
  })
44
44
  }
45
45
 
46
+ const { warn } = console
47
+ console.warn = (msg, ...args) => {
48
+ // if (/Insecure Content-Security-Policy/.test(msg)) return.
49
+ warn.call(console, msg, ...args)
50
+ }
51
+
52
+ if (location.hostname === 'localhost' && location.port) {
53
+ const gunk = require('pear-api/gunk')
54
+ const runtime = require('script-linker/runtime')
55
+
56
+ // platform runtime:
57
+ const pltsl = runtime({
58
+ builtins: gunk.builtins,
59
+ map: gunk.platform.map,
60
+ mapImport: gunk.platform.mapImport,
61
+ symbol: gunk.platform.symbol,
62
+ protocol: gunk.platform.protocol,
63
+ getSync (url) {
64
+ const xhr = new XMLHttpRequest()
65
+ xhr.open('GET', url, false)
66
+ xhr.send(null)
67
+ return xhr.responseText
68
+ },
69
+ resolveSync (req, dirname, { isImport }) {
70
+ const xhr = new XMLHttpRequest()
71
+ const type = isImport ? 'esm' : 'cjs'
72
+ const url = `${dirname}/~${req}+platform-resolve+${type}`
73
+ xhr.open('GET', url, false)
74
+ xhr.send(null)
75
+ return xhr.responseText
76
+ }
77
+ })
78
+
79
+ // app runtime:
80
+ const appsl = runtime({
81
+ builtins: gunk.builtins,
82
+ map: gunk.app.map,
83
+ mapImport: gunk.app.mapImport,
84
+ symbol: gunk.app.symbol,
85
+ protocol: gunk.app.protocol,
86
+ getSync (url) {
87
+ const xhr = new XMLHttpRequest()
88
+ xhr.open('GET', url, false)
89
+ xhr.send(null)
90
+ return xhr.responseText
91
+ },
92
+ resolveSync (req, dirname, { isImport }) {
93
+ const xhr = new XMLHttpRequest()
94
+ const type = isImport ? 'esm' : 'cjs'
95
+ const url = `${dirname}/~${req}+resolve+${type}`
96
+ xhr.open('GET', url, false)
97
+ xhr.send(null)
98
+ if (xhr.status !== 200) throw new Error(`${xhr.status} ${xhr.responseText}`)
99
+ return xhr.responseText
100
+ }
101
+ })
102
+
103
+ async function warm () {
104
+ for await (const { batch, protocol } of Pear[Pear.constructor.UI].warming()) {
105
+ let sl = null
106
+ if (protocol === 'pear' || protocol === 'holepunch') sl = pltsl
107
+ if (protocol === 'app') sl = appsl
108
+ if (sl === null) continue
109
+ for (const { filename, source } of batch) sl.sources.set(filename, source)
110
+ }
111
+ }
112
+
113
+ if (Pear.config.isDecal === false) warm().catch(console.error)
114
+ }
115
+
46
116
  function descopeGlobals () {
47
117
  delete global.require
48
118
  delete global.module
@@ -50,21 +120,7 @@ module.exports = (state) => {
50
120
  delete global.__filename
51
121
  }
52
122
 
53
- const { warn } = console
54
- console.warn = (msg, ...args) => {
55
- if (/Insecure Content-Security-Policy/.test(msg)) return
56
- warn.call(console, msg, ...args)
57
- }
58
-
59
- if (Pear.config.options.gui?.preload) {
60
- const run = require('node-bare-bundle')
61
- const key = Pear.config.options.gui.preload
62
- Pear.get({ key, bundle: true }).then((preload) => {
63
- run(preload, { mount: '/', entrypoint: key })
64
- }, console.error).finally(descopeGlobals)
65
- } else {
66
- descopeGlobals()
67
- }
123
+ descopeGlobals()
68
124
 
69
125
  customElements.define('pear-ctrl', class extends HTMLElement {
70
126
  #onfocus = null