packaton 0.0.13 → 0.0.15
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.
- package/package.json +1 -1
- package/src/plugins-prod/HtmlCompiler.js +14 -3
- package/src/router.js +12 -1
package/package.json
CHANGED
|
@@ -69,12 +69,20 @@ export class HtmlCompiler {
|
|
|
69
69
|
.map(([, body]) => body)
|
|
70
70
|
.join('\n'))
|
|
71
71
|
|
|
72
|
+
this.scriptsModuleJs = await this.#minifyJS(scripts
|
|
73
|
+
.filter(([type]) => type === 'module')
|
|
74
|
+
.map(([, body]) => body)
|
|
75
|
+
.join('\n'))
|
|
76
|
+
|
|
72
77
|
this.scriptsNonJs = scripts
|
|
73
|
-
.filter(([type]) => type !== 'application/javascript')
|
|
78
|
+
.filter(([type]) => type !== 'application/javascript' && type !== 'module')
|
|
74
79
|
|
|
75
80
|
if (this.scriptsJs)
|
|
76
|
-
this.html = this.html.replace('</body>',
|
|
81
|
+
this.html = this.html.replace('</body>', `\n<script>${this.scriptsJs}</script></body>`)
|
|
77
82
|
|
|
83
|
+
if (this.scriptsModuleJs)
|
|
84
|
+
this.html = this.html.replace('</body>', `\n<script type="module">${this.scriptsModuleJs}</script></body>`)
|
|
85
|
+
|
|
78
86
|
for (const [type, body] of this.scriptsNonJs)
|
|
79
87
|
this.html = this.html.replace('</body>', `\n<script type="${type}">${body}</script></body>`)
|
|
80
88
|
}
|
|
@@ -86,6 +94,9 @@ export class HtmlCompiler {
|
|
|
86
94
|
const jsScriptHash = this.scriptsJs
|
|
87
95
|
? `'${this.hash256(this.scriptsJs)}'`
|
|
88
96
|
: '' // TODO maybe self?
|
|
97
|
+
const jsModuleHash = this.scriptsModuleJs
|
|
98
|
+
? `'${this.hash256(this.scriptsModuleJs)}'`
|
|
99
|
+
: '' // TODO maybe self?
|
|
89
100
|
const nonJsScriptHashes = this.scriptsNonJs
|
|
90
101
|
.map(([, body]) => `'${this.hash256(body)}'`).join(' ')
|
|
91
102
|
const externalScriptHashes = this.externalScripts.map(url => `${new URL(url).origin}`).join(' ')
|
|
@@ -93,7 +104,7 @@ export class HtmlCompiler {
|
|
|
93
104
|
`default-src 'self'`,
|
|
94
105
|
`img-src 'self' data:`, // data: is for Safari's video player icons and for CSS bg images
|
|
95
106
|
`style-src ${cssHash}`,
|
|
96
|
-
`script-src ${nonJsScriptHashes} ${jsScriptHash} ${externalScriptHashes}`,
|
|
107
|
+
`script-src-elem ${nonJsScriptHashes} ${jsScriptHash} ${jsModuleHash} ${externalScriptHashes} 'self'`,
|
|
97
108
|
`frame-ancestors 'none'`
|
|
98
109
|
].join('; ')
|
|
99
110
|
}
|
package/src/router.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
2
|
import { readFile } from 'node:fs/promises'
|
|
3
|
+
import { randomUUID } from 'node:crypto'
|
|
3
4
|
|
|
4
5
|
import { docs } from './app.js'
|
|
5
6
|
import { mimeFor } from './utils/mimes.js'
|
|
@@ -7,6 +8,8 @@ import { devClientWatcher } from './plugins-dev/WatcherDevClient.js'
|
|
|
7
8
|
import { sendError, sendJSON, servePartialContent, serveAsset } from './utils/http-response.js'
|
|
8
9
|
|
|
9
10
|
|
|
11
|
+
const devtoolsWorkspaceId = randomUUID()
|
|
12
|
+
|
|
10
13
|
const WATCHER_DEV = '/plugins-dev/watcherDev.js'
|
|
11
14
|
|
|
12
15
|
const API = {
|
|
@@ -21,7 +24,15 @@ export function router({ srcPath, ignore, mode }) {
|
|
|
21
24
|
return async function (req, response) {
|
|
22
25
|
let url = new URL(req.url, 'http://_').pathname
|
|
23
26
|
try {
|
|
24
|
-
if (url ===
|
|
27
|
+
if (url === '/.well-known/appspecific/com.chrome.devtools.json')
|
|
28
|
+
sendJSON(response, {
|
|
29
|
+
workspace: {
|
|
30
|
+
root: srcPath,
|
|
31
|
+
uuid: devtoolsWorkspaceId
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
else if (url === API.watchDev)
|
|
25
36
|
longPollDevHotReload(req, response)
|
|
26
37
|
|
|
27
38
|
else if (url === WATCHER_DEV)
|