@jsenv/core 27.0.0-alpha.55 → 27.0.0-alpha.58
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.
|
@@ -26,17 +26,15 @@ import {
|
|
|
26
26
|
registerDirectoryLifecycle,
|
|
27
27
|
} from "@jsenv/filesystem"
|
|
28
28
|
import { createLogger } from "@jsenv/logger"
|
|
29
|
-
import { Abort } from "@jsenv/abort"
|
|
30
29
|
|
|
31
30
|
import { initReloadableProcess } from "@jsenv/utils/process_reload/process_reload.js"
|
|
32
31
|
import { createTaskLog } from "@jsenv/utils/logs/task_log.js"
|
|
33
|
-
import { executeCommand } from "@jsenv/utils/command/command.js"
|
|
34
32
|
|
|
35
33
|
export const startBuildServer = async ({
|
|
36
34
|
signal = new AbortController().signal,
|
|
37
35
|
handleSIGINT = true,
|
|
38
36
|
logLevel,
|
|
39
|
-
|
|
37
|
+
serverLogLevel = "warn",
|
|
40
38
|
protocol = "http",
|
|
41
39
|
http2,
|
|
42
40
|
certificate,
|
|
@@ -53,14 +51,7 @@ export const startBuildServer = async ({
|
|
|
53
51
|
},
|
|
54
52
|
buildServerMainFile,
|
|
55
53
|
buildServerAutoreload = false,
|
|
56
|
-
clientFiles = {
|
|
57
|
-
"./**": true,
|
|
58
|
-
"./**/.*/": false, // any folder starting with a dot is ignored (includes .git,.jsenv for instance)
|
|
59
|
-
"./dist/": false,
|
|
60
|
-
"./**/node_modules/": false,
|
|
61
|
-
},
|
|
62
54
|
cooldownBetweenFileEvents,
|
|
63
|
-
buildCommand,
|
|
64
55
|
mainBuildFileUrl = "/index.html",
|
|
65
56
|
}) => {
|
|
66
57
|
const logger = createLogger({ logLevel })
|
|
@@ -123,32 +114,6 @@ export const startBuildServer = async ({
|
|
|
123
114
|
}
|
|
124
115
|
signal = reloadableProcess.signal
|
|
125
116
|
|
|
126
|
-
let buildPromise
|
|
127
|
-
let buildAbortController
|
|
128
|
-
const runBuild = async () => {
|
|
129
|
-
buildAbortController = new AbortController()
|
|
130
|
-
const buildOperation = Abort.startOperation()
|
|
131
|
-
buildOperation.addAbortSignal(signal)
|
|
132
|
-
buildOperation.addAbortSignal(buildAbortController.signal)
|
|
133
|
-
const buildTask = createTaskLog(logger, `execute build command`)
|
|
134
|
-
buildPromise = executeCommand(buildCommand, {
|
|
135
|
-
cwd: rootDirectoryUrl,
|
|
136
|
-
logLevel: buildCommandLogLevel,
|
|
137
|
-
signal: buildOperation.signal,
|
|
138
|
-
})
|
|
139
|
-
try {
|
|
140
|
-
await buildPromise
|
|
141
|
-
buildTask.done()
|
|
142
|
-
} catch (e) {
|
|
143
|
-
if (e.code === "ABORT_ERR") {
|
|
144
|
-
buildTask.fail(`execute build command aborted`)
|
|
145
|
-
} else {
|
|
146
|
-
buildTask.fail()
|
|
147
|
-
throw e
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
117
|
const startServerTask = createTaskLog(logger, "start build server")
|
|
153
118
|
const server = await startServer({
|
|
154
119
|
signal,
|
|
@@ -156,7 +121,7 @@ export const startBuildServer = async ({
|
|
|
156
121
|
stopOnSIGINT: false,
|
|
157
122
|
stopOnInternalError: false,
|
|
158
123
|
keepProcessAlive: true,
|
|
159
|
-
logLevel,
|
|
124
|
+
logLevel: serverLogLevel,
|
|
160
125
|
startLog: false,
|
|
161
126
|
|
|
162
127
|
protocol,
|
|
@@ -183,8 +148,7 @@ export const startBuildServer = async ({
|
|
|
183
148
|
}),
|
|
184
149
|
},
|
|
185
150
|
sendErrorDetails: true,
|
|
186
|
-
requestToResponse:
|
|
187
|
-
await buildPromise
|
|
151
|
+
requestToResponse: (request) => {
|
|
188
152
|
const urlIsVersioned = new URL(
|
|
189
153
|
request.ressource,
|
|
190
154
|
request.origin,
|
|
@@ -217,37 +181,9 @@ export const startBuildServer = async ({
|
|
|
217
181
|
})
|
|
218
182
|
logger.info(``)
|
|
219
183
|
|
|
220
|
-
runBuild()
|
|
221
|
-
const clientFileChangeCallback = ({ relativeUrl, event }) => {
|
|
222
|
-
const url = new URL(relativeUrl, rootDirectoryUrl).href
|
|
223
|
-
buildAbortController.abort()
|
|
224
|
-
// setTimeout is to ensure the abortController.abort() above
|
|
225
|
-
// is properly taken into account so that logs about abort comes first
|
|
226
|
-
// then logs about re-running the build happens
|
|
227
|
-
setTimeout(() => {
|
|
228
|
-
logger.info(`${url.slice(rootDirectoryUrl.length)} ${event} -> rebuild`)
|
|
229
|
-
runBuild()
|
|
230
|
-
})
|
|
231
|
-
}
|
|
232
|
-
const stopWatchingClientFiles = registerDirectoryLifecycle(rootDirectoryUrl, {
|
|
233
|
-
watchPatterns: clientFiles,
|
|
234
|
-
cooldownBetweenFileEvents,
|
|
235
|
-
keepProcessAlive: false,
|
|
236
|
-
recursive: true,
|
|
237
|
-
added: ({ relativeUrl }) => {
|
|
238
|
-
clientFileChangeCallback({ relativeUrl, event: "added" })
|
|
239
|
-
},
|
|
240
|
-
updated: ({ relativeUrl }) => {
|
|
241
|
-
clientFileChangeCallback({ relativeUrl, event: "modified" })
|
|
242
|
-
},
|
|
243
|
-
removed: ({ relativeUrl }) => {
|
|
244
|
-
clientFileChangeCallback({ relativeUrl, event: "removed" })
|
|
245
|
-
},
|
|
246
|
-
})
|
|
247
184
|
return {
|
|
248
185
|
origin: server.origin,
|
|
249
186
|
stop: () => {
|
|
250
|
-
stopWatchingClientFiles()
|
|
251
187
|
server.stop()
|
|
252
188
|
},
|
|
253
189
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ensureEmptyDirectory } from "@jsenv/filesystem"
|
|
2
2
|
|
|
3
3
|
export const loadUrlGraph = async ({
|
|
4
|
+
operation,
|
|
4
5
|
urlGraph,
|
|
5
6
|
kitchen,
|
|
6
7
|
startLoading,
|
|
@@ -69,6 +70,7 @@ export const loadUrlGraph = async ({
|
|
|
69
70
|
)
|
|
70
71
|
|
|
71
72
|
const waitAll = async () => {
|
|
73
|
+
operation.throwIfAborted()
|
|
72
74
|
if (promises.length === 0) {
|
|
73
75
|
return
|
|
74
76
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isFileSystemPath,
|
|
3
3
|
normalizeStructuredMetaMap,
|
|
4
|
+
urlIsInsideOf,
|
|
4
5
|
urlToMeta,
|
|
5
6
|
} from "@jsenv/filesystem"
|
|
6
7
|
import { createDetailedMessage } from "@jsenv/logger"
|
|
@@ -8,6 +9,12 @@ import { createDetailedMessage } from "@jsenv/logger"
|
|
|
8
9
|
import { applyRollupPlugins } from "@jsenv/utils/js_ast/apply_rollup_plugins.js"
|
|
9
10
|
import { sourcemapConverter } from "@jsenv/utils/sourcemap/sourcemap_converter.js"
|
|
10
11
|
import { fileUrlConverter } from "@jsenv/core/src/omega/file_url_converter.js"
|
|
12
|
+
import { babelHelperNameFromUrl } from "@jsenv/babel-plugins"
|
|
13
|
+
|
|
14
|
+
const jsenvBabelPluginDirectoryUrl = new URL(
|
|
15
|
+
"../../transpilation/babel/",
|
|
16
|
+
import.meta.url,
|
|
17
|
+
).href
|
|
11
18
|
|
|
12
19
|
export const bundleJsModule = async ({
|
|
13
20
|
jsModuleUrlInfos,
|
|
@@ -216,6 +223,23 @@ const rollupPluginJsenv = ({
|
|
|
216
223
|
const name = nameFromUrlInfo || `${chunkInfo.name}.js`
|
|
217
224
|
return insideJs ? `js/${name}` : `${name}`
|
|
218
225
|
},
|
|
226
|
+
manualChunks: (id) => {
|
|
227
|
+
const fileUrl = fileUrlConverter.asFileUrl(id)
|
|
228
|
+
if (
|
|
229
|
+
fileUrl.endsWith(
|
|
230
|
+
"babel-plugin-transform-async-to-promises/helpers.mjs",
|
|
231
|
+
)
|
|
232
|
+
) {
|
|
233
|
+
return "babel_helpers"
|
|
234
|
+
}
|
|
235
|
+
if (babelHelperNameFromUrl(fileUrl)) {
|
|
236
|
+
return "babel_helpers"
|
|
237
|
+
}
|
|
238
|
+
if (urlIsInsideOf(fileUrl, jsenvBabelPluginDirectoryUrl)) {
|
|
239
|
+
return "babel_helpers"
|
|
240
|
+
}
|
|
241
|
+
return null
|
|
242
|
+
},
|
|
219
243
|
// https://rollupjs.org/guide/en/#outputpaths
|
|
220
244
|
// paths: (id) => {
|
|
221
245
|
// return id
|
|
@@ -785,22 +785,88 @@
|
|
|
785
785
|
(function () {
|
|
786
786
|
// worker or service worker
|
|
787
787
|
if (typeof WorkerGlobalScope === 'function' && self instanceof WorkerGlobalScope) {
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
788
|
+
/*
|
|
789
|
+
* SystemJs loads X files before executing the worker/service worker main file
|
|
790
|
+
* It mean events dispatched during this phase could be missed
|
|
791
|
+
* A warning like the one below is displayed in chrome devtools:
|
|
792
|
+
* "Event handler of 'install' event must be added on the initial evaluation of worker script"
|
|
793
|
+
* To fix that code below listen for these events early and redispatch them later
|
|
794
|
+
* once the worker file is executed (the listeners are installed)
|
|
795
|
+
*/
|
|
796
|
+
var firstRegisterCallbacks = []
|
|
797
|
+
var isServiceWorker = typeof self.skipWaiting === 'function'
|
|
798
|
+
if (isServiceWorker) {
|
|
799
|
+
// for service worker there is more events to listen
|
|
800
|
+
// and, to get rid of the warning, we override self.addEventListener
|
|
801
|
+
var eventsToCatch = ['message', 'install', 'activate', 'fetch']
|
|
802
|
+
var eventCallbackProxies = {}
|
|
803
|
+
var firstRegisterPromise = new Promise((resolve) => {
|
|
804
|
+
firstRegisterCallbacks.push(resolve)
|
|
805
|
+
})
|
|
806
|
+
eventsToCatch.forEach(function(eventName) {
|
|
807
|
+
var eventsToDispatch = []
|
|
808
|
+
var eventCallback = function (event) {
|
|
809
|
+
const eventCallbackProxy = eventCallbackProxies[event.type]
|
|
810
|
+
if (eventCallbackProxy) {
|
|
811
|
+
eventCallbackProxy(event)
|
|
812
|
+
}
|
|
813
|
+
else {
|
|
814
|
+
eventsToDispatch.push(event)
|
|
815
|
+
event.waitUntil(firstRegisterPromise)
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
self.addEventListener(eventName, eventCallback)
|
|
819
|
+
firstRegisterCallbacks.push(function() {
|
|
820
|
+
if (eventsToDispatch.length) {
|
|
821
|
+
const eventCallbackProxy = eventCallbackProxies[eventsToDispatch[0].type]
|
|
822
|
+
if (eventCallbackProxy) {
|
|
823
|
+
eventsToDispatch.forEach(function (event) {
|
|
824
|
+
eventCallbackProxy(event)
|
|
825
|
+
})
|
|
826
|
+
}
|
|
827
|
+
eventsToDispatch.length = 0
|
|
828
|
+
}
|
|
829
|
+
})
|
|
830
|
+
})
|
|
831
|
+
|
|
832
|
+
var addEventListener = self.addEventListener
|
|
833
|
+
self.addEventListener = function (eventName, callback, options) {
|
|
834
|
+
if (eventsToCatch.indexOf(eventName) > -1) {
|
|
835
|
+
eventCallbackProxies[eventName] = callback
|
|
836
|
+
return
|
|
837
|
+
}
|
|
838
|
+
return addEventListener.call(self, eventName, callback, options)
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
else {
|
|
842
|
+
var eventsToCatch = ['message']
|
|
843
|
+
eventsToCatch.forEach(function (eventName) {
|
|
844
|
+
var eventQueue = []
|
|
845
|
+
var eventCallback = (event) => {
|
|
846
|
+
eventQueue.push(event)
|
|
847
|
+
}
|
|
848
|
+
self.addEventListener(eventName, eventCallback)
|
|
849
|
+
firstRegisterCallbacks.push(function() {
|
|
850
|
+
self.removeEventListener(eventName, eventCallback)
|
|
851
|
+
eventQueue.forEach(function (event) {
|
|
852
|
+
self.dispatchEvent(event)
|
|
853
|
+
})
|
|
854
|
+
eventQueue.length = 0
|
|
855
|
+
})
|
|
856
|
+
})
|
|
792
857
|
}
|
|
793
|
-
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
// auto import first register
|
|
794
861
|
var register = System.register;
|
|
795
862
|
System.register = function(deps, declare) {
|
|
796
863
|
System.register = register;
|
|
797
864
|
System.registerRegistry[self.location.href] = [deps, declare];
|
|
798
865
|
return System.import(self.location.href).then((result) => {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
self.dispatchEvent(messageEvent)
|
|
866
|
+
firstRegisterCallbacks.forEach(firstRegisterCallback => {
|
|
867
|
+
firstRegisterCallback()
|
|
802
868
|
})
|
|
803
|
-
|
|
869
|
+
firstRegisterCallbacks.length = 0
|
|
804
870
|
return result
|
|
805
871
|
})
|
|
806
872
|
}
|