@jsenv/core 23.7.0 → 23.7.1
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/dist/jsenv_browser_system.js.map +1 -1
- package/dist/jsenv_compile_proxy.js.map +1 -1
- package/dist/jsenv_exploring_redirector.js.map +1 -1
- package/dist/jsenv_toolbar.js.map +1 -1
- package/package.json +2 -2
- package/src/buildProject.js +300 -300
- package/src/execute.js +184 -184
- package/src/internal/browser-launcher/jsenv-browser-system.js +199 -199
- package/src/internal/compiling/createCompiledFileService.js +290 -290
- package/src/internal/compiling/startCompileServer.js +1052 -1052
- package/src/internal/executing/executePlan.js +183 -183
- package/src/internal/executing/launchAndExecute.js +458 -458
- package/src/internal/runtime/createBrowserRuntime/scanBrowserRuntimeFeatures.js +246 -246
- package/src/internal/runtime/createNodeRuntime/scanNodeRuntimeFeatures.js +112 -112
- package/src/internal/url_conversion.js +317 -317
- package/src/launchNode.js +210 -210
- package/src/startExploring.js +309 -309
package/src/startExploring.js
CHANGED
|
@@ -1,309 +1,309 @@
|
|
|
1
|
-
import {
|
|
2
|
-
normalizeStructuredMetaMap,
|
|
3
|
-
collectFiles,
|
|
4
|
-
urlToRelativeUrl,
|
|
5
|
-
} from "@jsenv/filesystem"
|
|
6
|
-
|
|
7
|
-
import { jsenvCoreDirectoryUrl } from "./internal/jsenvCoreDirectoryUrl.js"
|
|
8
|
-
import {
|
|
9
|
-
assertProjectDirectoryUrl,
|
|
10
|
-
assertProjectDirectoryExists,
|
|
11
|
-
} from "./internal/argUtils.js"
|
|
12
|
-
import {
|
|
13
|
-
startCompileServer,
|
|
14
|
-
computeOutDirectoryRelativeUrl,
|
|
15
|
-
} from "./internal/compiling/startCompileServer.js"
|
|
16
|
-
import { jsenvExplorableConfig } from "./jsenvExplorableConfig.js"
|
|
17
|
-
import {
|
|
18
|
-
sourcemapMainFileInfo,
|
|
19
|
-
sourcemapMappingFileInfo,
|
|
20
|
-
jsenvExploringRedirectorHtmlFileInfo,
|
|
21
|
-
jsenvExploringRedirectorJsFileInfo,
|
|
22
|
-
jsenvExploringIndexHtmlFileInfo,
|
|
23
|
-
jsenvExploringIndexJsFileInfo,
|
|
24
|
-
jsenvToolbarJsFileInfo,
|
|
25
|
-
} from "./internal/jsenvInternalFiles.js"
|
|
26
|
-
import { jsenvRuntimeSupportDuringDev } from "./jsenvRuntimeSupportDuringDev.js"
|
|
27
|
-
|
|
28
|
-
export const startExploring = async ({
|
|
29
|
-
signal = new AbortController().signal,
|
|
30
|
-
handleSIGINT = true,
|
|
31
|
-
|
|
32
|
-
explorableConfig = jsenvExplorableConfig,
|
|
33
|
-
projectDirectoryUrl,
|
|
34
|
-
jsenvDirectoryRelativeUrl,
|
|
35
|
-
outDirectoryName = "dev",
|
|
36
|
-
jsenvToolbar = true,
|
|
37
|
-
livereloading = true,
|
|
38
|
-
inlineImportMapIntoHTML = true,
|
|
39
|
-
keepProcessAlive = true,
|
|
40
|
-
|
|
41
|
-
babelPluginMap,
|
|
42
|
-
runtimeSupportDuringDev = jsenvRuntimeSupportDuringDev,
|
|
43
|
-
compileServerLogLevel,
|
|
44
|
-
compileServerCanReadFromFilesystem,
|
|
45
|
-
compileServerCanWriteOnFilesystem,
|
|
46
|
-
compileServerPort,
|
|
47
|
-
compileServerProtocol,
|
|
48
|
-
compileServerHttp2,
|
|
49
|
-
compileServerCertificate,
|
|
50
|
-
compileServerPrivateKey,
|
|
51
|
-
sourcemapMethod,
|
|
52
|
-
customCompilers,
|
|
53
|
-
livereloadWatchConfig,
|
|
54
|
-
jsenvDirectoryClean,
|
|
55
|
-
}) => {
|
|
56
|
-
projectDirectoryUrl = assertProjectDirectoryUrl({ projectDirectoryUrl })
|
|
57
|
-
await assertProjectDirectoryExists({ projectDirectoryUrl })
|
|
58
|
-
|
|
59
|
-
const outDirectoryRelativeUrl = computeOutDirectoryRelativeUrl({
|
|
60
|
-
projectDirectoryUrl,
|
|
61
|
-
jsenvDirectoryRelativeUrl,
|
|
62
|
-
outDirectoryName,
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
const redirectFiles = createRedirectFilesService({
|
|
66
|
-
projectDirectoryUrl,
|
|
67
|
-
outDirectoryRelativeUrl,
|
|
68
|
-
})
|
|
69
|
-
const serveExploringData = createExploringDataService({
|
|
70
|
-
projectDirectoryUrl,
|
|
71
|
-
outDirectoryRelativeUrl,
|
|
72
|
-
explorableConfig,
|
|
73
|
-
livereloading,
|
|
74
|
-
})
|
|
75
|
-
const serveExplorableListAsJson = createExplorableListAsJsonService({
|
|
76
|
-
projectDirectoryUrl,
|
|
77
|
-
outDirectoryRelativeUrl,
|
|
78
|
-
explorableConfig,
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
const compileServer = await startCompileServer({
|
|
82
|
-
signal,
|
|
83
|
-
handleSIGINT,
|
|
84
|
-
keepProcessAlive,
|
|
85
|
-
|
|
86
|
-
projectDirectoryUrl,
|
|
87
|
-
livereloadSSE: livereloading,
|
|
88
|
-
jsenvToolbarInjection: jsenvToolbar,
|
|
89
|
-
customServices: {
|
|
90
|
-
"service:exploring-redirect": (request) => redirectFiles(request),
|
|
91
|
-
"service:exploring-data": (request) => serveExploringData(request),
|
|
92
|
-
"service:explorables": (request) => serveExplorableListAsJson(request),
|
|
93
|
-
},
|
|
94
|
-
customCompilers,
|
|
95
|
-
jsenvDirectoryRelativeUrl,
|
|
96
|
-
outDirectoryName,
|
|
97
|
-
inlineImportMapIntoHTML,
|
|
98
|
-
|
|
99
|
-
compileServerLogLevel,
|
|
100
|
-
compileServerCanReadFromFilesystem,
|
|
101
|
-
compileServerCanWriteOnFilesystem,
|
|
102
|
-
compileServerPort,
|
|
103
|
-
compileServerProtocol,
|
|
104
|
-
compileServerHttp2,
|
|
105
|
-
compileServerCertificate,
|
|
106
|
-
compileServerPrivateKey,
|
|
107
|
-
sourcemapMethod,
|
|
108
|
-
babelPluginMap,
|
|
109
|
-
runtimeSupport: runtimeSupportDuringDev,
|
|
110
|
-
livereloadWatchConfig,
|
|
111
|
-
jsenvDirectoryClean,
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
return compileServer
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const createRedirectFilesService = ({ projectDirectoryUrl }) => {
|
|
118
|
-
const jsenvExploringRedirectorHtmlRelativeUrlForProject = urlToRelativeUrl(
|
|
119
|
-
jsenvExploringRedirectorHtmlFileInfo.url,
|
|
120
|
-
projectDirectoryUrl,
|
|
121
|
-
)
|
|
122
|
-
const jsenvExploringRedirectorJsBuildRelativeUrlForProject = urlToRelativeUrl(
|
|
123
|
-
jsenvExploringRedirectorJsFileInfo.jsenvBuildUrl,
|
|
124
|
-
projectDirectoryUrl,
|
|
125
|
-
)
|
|
126
|
-
const jsenvExploringJsBuildRelativeUrlForProject = urlToRelativeUrl(
|
|
127
|
-
jsenvExploringIndexJsFileInfo.jsenvBuildUrl,
|
|
128
|
-
projectDirectoryUrl,
|
|
129
|
-
)
|
|
130
|
-
const jsenvToolbarJsBuildRelativeUrlForProject = urlToRelativeUrl(
|
|
131
|
-
jsenvToolbarJsFileInfo.jsenvBuildUrl,
|
|
132
|
-
projectDirectoryUrl,
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
// unfortunately browser resolves sourcemap to url before redirection (not after).
|
|
136
|
-
// It means browser tries to load source map from "/.jsenv/jsenv-toolbar.js.map"
|
|
137
|
-
// we could also inline sourcemap but it's not yet possible
|
|
138
|
-
// inside buildProject
|
|
139
|
-
const jsenvExploringIndexSourcemapInfo = {
|
|
140
|
-
pathForBrowser: `/.jsenv/jsenv_exploring_index.js.map`,
|
|
141
|
-
pathForServer: `/${jsenvExploringJsBuildRelativeUrlForProject}.map`,
|
|
142
|
-
}
|
|
143
|
-
const jsenvToolbarSourcemapInfo = {
|
|
144
|
-
pathForBrowser: `/.jsenv/jsenv_toolbar.js.map`,
|
|
145
|
-
pathForServer: `/${jsenvToolbarJsBuildRelativeUrlForProject}.map`,
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return (request) => {
|
|
149
|
-
// exploring redirection
|
|
150
|
-
if (request.ressource === "/") {
|
|
151
|
-
const jsenvExploringRedirectorHtmlServerUrl = `${request.origin}/${jsenvExploringRedirectorHtmlRelativeUrlForProject}`
|
|
152
|
-
return {
|
|
153
|
-
status: 307,
|
|
154
|
-
headers: {
|
|
155
|
-
location: jsenvExploringRedirectorHtmlServerUrl,
|
|
156
|
-
},
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (request.ressource === "/.jsenv/exploring.redirector.js") {
|
|
160
|
-
const jsenvExploringRedirectorBuildServerUrl = `${request.origin}/${jsenvExploringRedirectorJsBuildRelativeUrlForProject}`
|
|
161
|
-
return {
|
|
162
|
-
status: 307,
|
|
163
|
-
headers: {
|
|
164
|
-
location: jsenvExploringRedirectorBuildServerUrl,
|
|
165
|
-
},
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// exploring index
|
|
170
|
-
if (request.ressource === "/.jsenv/exploring.index.js") {
|
|
171
|
-
const jsenvExploringJsBuildServerUrl = `${request.origin}/${jsenvExploringJsBuildRelativeUrlForProject}`
|
|
172
|
-
return {
|
|
173
|
-
status: 307,
|
|
174
|
-
headers: {
|
|
175
|
-
location: jsenvExploringJsBuildServerUrl,
|
|
176
|
-
},
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (request.ressource === jsenvExploringIndexSourcemapInfo.pathForBrowser) {
|
|
180
|
-
return {
|
|
181
|
-
status: 307,
|
|
182
|
-
headers: {
|
|
183
|
-
location: `${request.origin}${jsenvExploringIndexSourcemapInfo.pathForServer}`,
|
|
184
|
-
},
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// toolbar
|
|
189
|
-
if (request.ressource === "/.jsenv/toolbar.main.js") {
|
|
190
|
-
const jsenvToolbarJsBuildServerUrl = `${request.origin}/${jsenvToolbarJsBuildRelativeUrlForProject}`
|
|
191
|
-
return {
|
|
192
|
-
status: 307,
|
|
193
|
-
headers: {
|
|
194
|
-
location: jsenvToolbarJsBuildServerUrl,
|
|
195
|
-
},
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
if (request.ressource === jsenvToolbarSourcemapInfo.pathForBrowser) {
|
|
199
|
-
return {
|
|
200
|
-
status: 307,
|
|
201
|
-
headers: {
|
|
202
|
-
location: `${request.origin}${jsenvToolbarSourcemapInfo.pathForServer}`,
|
|
203
|
-
},
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return null
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const createExploringDataService = ({
|
|
212
|
-
projectDirectoryUrl,
|
|
213
|
-
outDirectoryRelativeUrl,
|
|
214
|
-
explorableConfig,
|
|
215
|
-
livereloading,
|
|
216
|
-
}) => {
|
|
217
|
-
return (request) => {
|
|
218
|
-
if (
|
|
219
|
-
request.ressource === "/.jsenv/exploring.json" &&
|
|
220
|
-
request.method === "GET"
|
|
221
|
-
) {
|
|
222
|
-
const data = {
|
|
223
|
-
projectDirectoryUrl,
|
|
224
|
-
outDirectoryRelativeUrl,
|
|
225
|
-
jsenvDirectoryRelativeUrl: urlToRelativeUrl(
|
|
226
|
-
jsenvCoreDirectoryUrl,
|
|
227
|
-
projectDirectoryUrl,
|
|
228
|
-
),
|
|
229
|
-
exploringHtmlFileRelativeUrl: urlToRelativeUrl(
|
|
230
|
-
jsenvExploringIndexHtmlFileInfo.url,
|
|
231
|
-
projectDirectoryUrl,
|
|
232
|
-
),
|
|
233
|
-
sourcemapMainFileRelativeUrl: urlToRelativeUrl(
|
|
234
|
-
sourcemapMainFileInfo.url,
|
|
235
|
-
jsenvCoreDirectoryUrl,
|
|
236
|
-
),
|
|
237
|
-
sourcemapMappingFileRelativeUrl: urlToRelativeUrl(
|
|
238
|
-
sourcemapMappingFileInfo.url,
|
|
239
|
-
jsenvCoreDirectoryUrl,
|
|
240
|
-
),
|
|
241
|
-
explorableConfig,
|
|
242
|
-
livereloading,
|
|
243
|
-
}
|
|
244
|
-
const json = JSON.stringify(data)
|
|
245
|
-
return {
|
|
246
|
-
status: 200,
|
|
247
|
-
headers: {
|
|
248
|
-
"cache-control": "no-store",
|
|
249
|
-
"content-type": "application/json",
|
|
250
|
-
"content-length": Buffer.byteLength(json),
|
|
251
|
-
},
|
|
252
|
-
body: json,
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return null
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
const createExplorableListAsJsonService = ({
|
|
260
|
-
projectDirectoryUrl,
|
|
261
|
-
outDirectoryRelativeUrl,
|
|
262
|
-
explorableConfig,
|
|
263
|
-
}) => {
|
|
264
|
-
return async (request) => {
|
|
265
|
-
if (
|
|
266
|
-
request.ressource === "/.jsenv/explorables.json" &&
|
|
267
|
-
request.method === "GET"
|
|
268
|
-
) {
|
|
269
|
-
const structuredMetaMapRelativeForExplorable = {}
|
|
270
|
-
Object.keys(explorableConfig).forEach((explorableGroup) => {
|
|
271
|
-
const explorableGroupConfig = explorableConfig[explorableGroup]
|
|
272
|
-
structuredMetaMapRelativeForExplorable[explorableGroup] = {
|
|
273
|
-
"**/.jsenv/": false, // temporary (in theory) to avoid visting .jsenv directory in jsenv itself
|
|
274
|
-
...explorableGroupConfig,
|
|
275
|
-
[outDirectoryRelativeUrl]: false,
|
|
276
|
-
}
|
|
277
|
-
})
|
|
278
|
-
const structuredMetaMapForExplorable = normalizeStructuredMetaMap(
|
|
279
|
-
structuredMetaMapRelativeForExplorable,
|
|
280
|
-
projectDirectoryUrl,
|
|
281
|
-
)
|
|
282
|
-
const matchingFileResultArray = await collectFiles({
|
|
283
|
-
directoryUrl: projectDirectoryUrl,
|
|
284
|
-
structuredMetaMap: structuredMetaMapForExplorable,
|
|
285
|
-
predicate: (meta) =>
|
|
286
|
-
Object.keys(meta).some((explorableGroup) =>
|
|
287
|
-
Boolean(meta[explorableGroup]),
|
|
288
|
-
),
|
|
289
|
-
})
|
|
290
|
-
const explorableFiles = matchingFileResultArray.map(
|
|
291
|
-
({ relativeUrl, meta }) => ({
|
|
292
|
-
relativeUrl,
|
|
293
|
-
meta,
|
|
294
|
-
}),
|
|
295
|
-
)
|
|
296
|
-
const json = JSON.stringify(explorableFiles)
|
|
297
|
-
return {
|
|
298
|
-
status: 200,
|
|
299
|
-
headers: {
|
|
300
|
-
"cache-control": "no-store",
|
|
301
|
-
"content-type": "application/json",
|
|
302
|
-
"content-length": Buffer.byteLength(json),
|
|
303
|
-
},
|
|
304
|
-
body: json,
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
return null
|
|
308
|
-
}
|
|
309
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
normalizeStructuredMetaMap,
|
|
3
|
+
collectFiles,
|
|
4
|
+
urlToRelativeUrl,
|
|
5
|
+
} from "@jsenv/filesystem"
|
|
6
|
+
|
|
7
|
+
import { jsenvCoreDirectoryUrl } from "./internal/jsenvCoreDirectoryUrl.js"
|
|
8
|
+
import {
|
|
9
|
+
assertProjectDirectoryUrl,
|
|
10
|
+
assertProjectDirectoryExists,
|
|
11
|
+
} from "./internal/argUtils.js"
|
|
12
|
+
import {
|
|
13
|
+
startCompileServer,
|
|
14
|
+
computeOutDirectoryRelativeUrl,
|
|
15
|
+
} from "./internal/compiling/startCompileServer.js"
|
|
16
|
+
import { jsenvExplorableConfig } from "./jsenvExplorableConfig.js"
|
|
17
|
+
import {
|
|
18
|
+
sourcemapMainFileInfo,
|
|
19
|
+
sourcemapMappingFileInfo,
|
|
20
|
+
jsenvExploringRedirectorHtmlFileInfo,
|
|
21
|
+
jsenvExploringRedirectorJsFileInfo,
|
|
22
|
+
jsenvExploringIndexHtmlFileInfo,
|
|
23
|
+
jsenvExploringIndexJsFileInfo,
|
|
24
|
+
jsenvToolbarJsFileInfo,
|
|
25
|
+
} from "./internal/jsenvInternalFiles.js"
|
|
26
|
+
import { jsenvRuntimeSupportDuringDev } from "./jsenvRuntimeSupportDuringDev.js"
|
|
27
|
+
|
|
28
|
+
export const startExploring = async ({
|
|
29
|
+
signal = new AbortController().signal,
|
|
30
|
+
handleSIGINT = true,
|
|
31
|
+
|
|
32
|
+
explorableConfig = jsenvExplorableConfig,
|
|
33
|
+
projectDirectoryUrl,
|
|
34
|
+
jsenvDirectoryRelativeUrl,
|
|
35
|
+
outDirectoryName = "dev",
|
|
36
|
+
jsenvToolbar = true,
|
|
37
|
+
livereloading = true,
|
|
38
|
+
inlineImportMapIntoHTML = true,
|
|
39
|
+
keepProcessAlive = true,
|
|
40
|
+
|
|
41
|
+
babelPluginMap,
|
|
42
|
+
runtimeSupportDuringDev = jsenvRuntimeSupportDuringDev,
|
|
43
|
+
compileServerLogLevel,
|
|
44
|
+
compileServerCanReadFromFilesystem,
|
|
45
|
+
compileServerCanWriteOnFilesystem,
|
|
46
|
+
compileServerPort,
|
|
47
|
+
compileServerProtocol,
|
|
48
|
+
compileServerHttp2,
|
|
49
|
+
compileServerCertificate,
|
|
50
|
+
compileServerPrivateKey,
|
|
51
|
+
sourcemapMethod,
|
|
52
|
+
customCompilers,
|
|
53
|
+
livereloadWatchConfig,
|
|
54
|
+
jsenvDirectoryClean,
|
|
55
|
+
}) => {
|
|
56
|
+
projectDirectoryUrl = assertProjectDirectoryUrl({ projectDirectoryUrl })
|
|
57
|
+
await assertProjectDirectoryExists({ projectDirectoryUrl })
|
|
58
|
+
|
|
59
|
+
const outDirectoryRelativeUrl = computeOutDirectoryRelativeUrl({
|
|
60
|
+
projectDirectoryUrl,
|
|
61
|
+
jsenvDirectoryRelativeUrl,
|
|
62
|
+
outDirectoryName,
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const redirectFiles = createRedirectFilesService({
|
|
66
|
+
projectDirectoryUrl,
|
|
67
|
+
outDirectoryRelativeUrl,
|
|
68
|
+
})
|
|
69
|
+
const serveExploringData = createExploringDataService({
|
|
70
|
+
projectDirectoryUrl,
|
|
71
|
+
outDirectoryRelativeUrl,
|
|
72
|
+
explorableConfig,
|
|
73
|
+
livereloading,
|
|
74
|
+
})
|
|
75
|
+
const serveExplorableListAsJson = createExplorableListAsJsonService({
|
|
76
|
+
projectDirectoryUrl,
|
|
77
|
+
outDirectoryRelativeUrl,
|
|
78
|
+
explorableConfig,
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
const compileServer = await startCompileServer({
|
|
82
|
+
signal,
|
|
83
|
+
handleSIGINT,
|
|
84
|
+
keepProcessAlive,
|
|
85
|
+
|
|
86
|
+
projectDirectoryUrl,
|
|
87
|
+
livereloadSSE: livereloading,
|
|
88
|
+
jsenvToolbarInjection: jsenvToolbar,
|
|
89
|
+
customServices: {
|
|
90
|
+
"service:exploring-redirect": (request) => redirectFiles(request),
|
|
91
|
+
"service:exploring-data": (request) => serveExploringData(request),
|
|
92
|
+
"service:explorables": (request) => serveExplorableListAsJson(request),
|
|
93
|
+
},
|
|
94
|
+
customCompilers,
|
|
95
|
+
jsenvDirectoryRelativeUrl,
|
|
96
|
+
outDirectoryName,
|
|
97
|
+
inlineImportMapIntoHTML,
|
|
98
|
+
|
|
99
|
+
compileServerLogLevel,
|
|
100
|
+
compileServerCanReadFromFilesystem,
|
|
101
|
+
compileServerCanWriteOnFilesystem,
|
|
102
|
+
compileServerPort,
|
|
103
|
+
compileServerProtocol,
|
|
104
|
+
compileServerHttp2,
|
|
105
|
+
compileServerCertificate,
|
|
106
|
+
compileServerPrivateKey,
|
|
107
|
+
sourcemapMethod,
|
|
108
|
+
babelPluginMap,
|
|
109
|
+
runtimeSupport: runtimeSupportDuringDev,
|
|
110
|
+
livereloadWatchConfig,
|
|
111
|
+
jsenvDirectoryClean,
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
return compileServer
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const createRedirectFilesService = ({ projectDirectoryUrl }) => {
|
|
118
|
+
const jsenvExploringRedirectorHtmlRelativeUrlForProject = urlToRelativeUrl(
|
|
119
|
+
jsenvExploringRedirectorHtmlFileInfo.url,
|
|
120
|
+
projectDirectoryUrl,
|
|
121
|
+
)
|
|
122
|
+
const jsenvExploringRedirectorJsBuildRelativeUrlForProject = urlToRelativeUrl(
|
|
123
|
+
jsenvExploringRedirectorJsFileInfo.jsenvBuildUrl,
|
|
124
|
+
projectDirectoryUrl,
|
|
125
|
+
)
|
|
126
|
+
const jsenvExploringJsBuildRelativeUrlForProject = urlToRelativeUrl(
|
|
127
|
+
jsenvExploringIndexJsFileInfo.jsenvBuildUrl,
|
|
128
|
+
projectDirectoryUrl,
|
|
129
|
+
)
|
|
130
|
+
const jsenvToolbarJsBuildRelativeUrlForProject = urlToRelativeUrl(
|
|
131
|
+
jsenvToolbarJsFileInfo.jsenvBuildUrl,
|
|
132
|
+
projectDirectoryUrl,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
// unfortunately browser resolves sourcemap to url before redirection (not after).
|
|
136
|
+
// It means browser tries to load source map from "/.jsenv/jsenv-toolbar.js.map"
|
|
137
|
+
// we could also inline sourcemap but it's not yet possible
|
|
138
|
+
// inside buildProject
|
|
139
|
+
const jsenvExploringIndexSourcemapInfo = {
|
|
140
|
+
pathForBrowser: `/.jsenv/jsenv_exploring_index.js.map`,
|
|
141
|
+
pathForServer: `/${jsenvExploringJsBuildRelativeUrlForProject}.map`,
|
|
142
|
+
}
|
|
143
|
+
const jsenvToolbarSourcemapInfo = {
|
|
144
|
+
pathForBrowser: `/.jsenv/jsenv_toolbar.js.map`,
|
|
145
|
+
pathForServer: `/${jsenvToolbarJsBuildRelativeUrlForProject}.map`,
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return (request) => {
|
|
149
|
+
// exploring redirection
|
|
150
|
+
if (request.ressource === "/") {
|
|
151
|
+
const jsenvExploringRedirectorHtmlServerUrl = `${request.origin}/${jsenvExploringRedirectorHtmlRelativeUrlForProject}`
|
|
152
|
+
return {
|
|
153
|
+
status: 307,
|
|
154
|
+
headers: {
|
|
155
|
+
location: jsenvExploringRedirectorHtmlServerUrl,
|
|
156
|
+
},
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (request.ressource === "/.jsenv/exploring.redirector.js") {
|
|
160
|
+
const jsenvExploringRedirectorBuildServerUrl = `${request.origin}/${jsenvExploringRedirectorJsBuildRelativeUrlForProject}`
|
|
161
|
+
return {
|
|
162
|
+
status: 307,
|
|
163
|
+
headers: {
|
|
164
|
+
location: jsenvExploringRedirectorBuildServerUrl,
|
|
165
|
+
},
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// exploring index
|
|
170
|
+
if (request.ressource === "/.jsenv/exploring.index.js") {
|
|
171
|
+
const jsenvExploringJsBuildServerUrl = `${request.origin}/${jsenvExploringJsBuildRelativeUrlForProject}`
|
|
172
|
+
return {
|
|
173
|
+
status: 307,
|
|
174
|
+
headers: {
|
|
175
|
+
location: jsenvExploringJsBuildServerUrl,
|
|
176
|
+
},
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (request.ressource === jsenvExploringIndexSourcemapInfo.pathForBrowser) {
|
|
180
|
+
return {
|
|
181
|
+
status: 307,
|
|
182
|
+
headers: {
|
|
183
|
+
location: `${request.origin}${jsenvExploringIndexSourcemapInfo.pathForServer}`,
|
|
184
|
+
},
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// toolbar
|
|
189
|
+
if (request.ressource === "/.jsenv/toolbar.main.js") {
|
|
190
|
+
const jsenvToolbarJsBuildServerUrl = `${request.origin}/${jsenvToolbarJsBuildRelativeUrlForProject}`
|
|
191
|
+
return {
|
|
192
|
+
status: 307,
|
|
193
|
+
headers: {
|
|
194
|
+
location: jsenvToolbarJsBuildServerUrl,
|
|
195
|
+
},
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (request.ressource === jsenvToolbarSourcemapInfo.pathForBrowser) {
|
|
199
|
+
return {
|
|
200
|
+
status: 307,
|
|
201
|
+
headers: {
|
|
202
|
+
location: `${request.origin}${jsenvToolbarSourcemapInfo.pathForServer}`,
|
|
203
|
+
},
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return null
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const createExploringDataService = ({
|
|
212
|
+
projectDirectoryUrl,
|
|
213
|
+
outDirectoryRelativeUrl,
|
|
214
|
+
explorableConfig,
|
|
215
|
+
livereloading,
|
|
216
|
+
}) => {
|
|
217
|
+
return (request) => {
|
|
218
|
+
if (
|
|
219
|
+
request.ressource === "/.jsenv/exploring.json" &&
|
|
220
|
+
request.method === "GET"
|
|
221
|
+
) {
|
|
222
|
+
const data = {
|
|
223
|
+
projectDirectoryUrl,
|
|
224
|
+
outDirectoryRelativeUrl,
|
|
225
|
+
jsenvDirectoryRelativeUrl: urlToRelativeUrl(
|
|
226
|
+
jsenvCoreDirectoryUrl,
|
|
227
|
+
projectDirectoryUrl,
|
|
228
|
+
),
|
|
229
|
+
exploringHtmlFileRelativeUrl: urlToRelativeUrl(
|
|
230
|
+
jsenvExploringIndexHtmlFileInfo.url,
|
|
231
|
+
projectDirectoryUrl,
|
|
232
|
+
),
|
|
233
|
+
sourcemapMainFileRelativeUrl: urlToRelativeUrl(
|
|
234
|
+
sourcemapMainFileInfo.url,
|
|
235
|
+
jsenvCoreDirectoryUrl,
|
|
236
|
+
),
|
|
237
|
+
sourcemapMappingFileRelativeUrl: urlToRelativeUrl(
|
|
238
|
+
sourcemapMappingFileInfo.url,
|
|
239
|
+
jsenvCoreDirectoryUrl,
|
|
240
|
+
),
|
|
241
|
+
explorableConfig,
|
|
242
|
+
livereloading,
|
|
243
|
+
}
|
|
244
|
+
const json = JSON.stringify(data)
|
|
245
|
+
return {
|
|
246
|
+
status: 200,
|
|
247
|
+
headers: {
|
|
248
|
+
"cache-control": "no-store",
|
|
249
|
+
"content-type": "application/json",
|
|
250
|
+
"content-length": Buffer.byteLength(json),
|
|
251
|
+
},
|
|
252
|
+
body: json,
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return null
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const createExplorableListAsJsonService = ({
|
|
260
|
+
projectDirectoryUrl,
|
|
261
|
+
outDirectoryRelativeUrl,
|
|
262
|
+
explorableConfig,
|
|
263
|
+
}) => {
|
|
264
|
+
return async (request) => {
|
|
265
|
+
if (
|
|
266
|
+
request.ressource === "/.jsenv/explorables.json" &&
|
|
267
|
+
request.method === "GET"
|
|
268
|
+
) {
|
|
269
|
+
const structuredMetaMapRelativeForExplorable = {}
|
|
270
|
+
Object.keys(explorableConfig).forEach((explorableGroup) => {
|
|
271
|
+
const explorableGroupConfig = explorableConfig[explorableGroup]
|
|
272
|
+
structuredMetaMapRelativeForExplorable[explorableGroup] = {
|
|
273
|
+
"**/.jsenv/": false, // temporary (in theory) to avoid visting .jsenv directory in jsenv itself
|
|
274
|
+
...explorableGroupConfig,
|
|
275
|
+
[outDirectoryRelativeUrl]: false,
|
|
276
|
+
}
|
|
277
|
+
})
|
|
278
|
+
const structuredMetaMapForExplorable = normalizeStructuredMetaMap(
|
|
279
|
+
structuredMetaMapRelativeForExplorable,
|
|
280
|
+
projectDirectoryUrl,
|
|
281
|
+
)
|
|
282
|
+
const matchingFileResultArray = await collectFiles({
|
|
283
|
+
directoryUrl: projectDirectoryUrl,
|
|
284
|
+
structuredMetaMap: structuredMetaMapForExplorable,
|
|
285
|
+
predicate: (meta) =>
|
|
286
|
+
Object.keys(meta).some((explorableGroup) =>
|
|
287
|
+
Boolean(meta[explorableGroup]),
|
|
288
|
+
),
|
|
289
|
+
})
|
|
290
|
+
const explorableFiles = matchingFileResultArray.map(
|
|
291
|
+
({ relativeUrl, meta }) => ({
|
|
292
|
+
relativeUrl,
|
|
293
|
+
meta,
|
|
294
|
+
}),
|
|
295
|
+
)
|
|
296
|
+
const json = JSON.stringify(explorableFiles)
|
|
297
|
+
return {
|
|
298
|
+
status: 200,
|
|
299
|
+
headers: {
|
|
300
|
+
"cache-control": "no-store",
|
|
301
|
+
"content-type": "application/json",
|
|
302
|
+
"content-length": Buffer.byteLength(json),
|
|
303
|
+
},
|
|
304
|
+
body: json,
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return null
|
|
308
|
+
}
|
|
309
|
+
}
|