@jsenv/core 31.0.0 → 31.0.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/main.js +48 -22
- package/package.json +1 -1
- package/src/build/start_build_server.js +41 -18
- package/src/dev/file_service.js +2 -1
- package/src/dev/start_dev_server.js +3 -0
- package/src/kitchen/kitchen.js +11 -1
package/dist/main.js
CHANGED
|
@@ -9225,7 +9225,13 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
|
|
|
9225
9225
|
} = urlInfo;
|
|
9226
9226
|
if (generatedUrl && generatedUrl.startsWith("file:")) {
|
|
9227
9227
|
if (urlInfo.type === "directory") ; else if (urlInfo.content === null) ; else {
|
|
9228
|
-
|
|
9228
|
+
let contentIsInlined = urlInfo.isInline;
|
|
9229
|
+
if (contentIsInlined && context.supervisor && urlGraph.getUrlInfo(urlInfo.inlineUrlSite.url).type === "html") {
|
|
9230
|
+
contentIsInlined = false;
|
|
9231
|
+
}
|
|
9232
|
+
if (!contentIsInlined) {
|
|
9233
|
+
writeFileSync(new URL(generatedUrl), urlInfo.content);
|
|
9234
|
+
}
|
|
9229
9235
|
const {
|
|
9230
9236
|
sourcemapGeneratedUrl,
|
|
9231
9237
|
sourcemap
|
|
@@ -22256,6 +22262,7 @@ const createFileService = ({
|
|
|
22256
22262
|
logLevel,
|
|
22257
22263
|
serverStopCallbacks,
|
|
22258
22264
|
serverEventsDispatcher,
|
|
22265
|
+
contextCache,
|
|
22259
22266
|
rootDirectoryUrl,
|
|
22260
22267
|
runtimeCompat,
|
|
22261
22268
|
plugins,
|
|
@@ -22319,7 +22326,6 @@ const createFileService = ({
|
|
|
22319
22326
|
}
|
|
22320
22327
|
});
|
|
22321
22328
|
serverStopCallbacks.push(stopWatchingClientFiles);
|
|
22322
|
-
const contextCache = new Map();
|
|
22323
22329
|
const getOrCreateContext = request => {
|
|
22324
22330
|
const {
|
|
22325
22331
|
runtimeName,
|
|
@@ -22380,6 +22386,7 @@ const createFileService = ({
|
|
|
22380
22386
|
cacheControl,
|
|
22381
22387
|
ribbon
|
|
22382
22388
|
})],
|
|
22389
|
+
supervisor,
|
|
22383
22390
|
minification: false,
|
|
22384
22391
|
sourcemaps,
|
|
22385
22392
|
sourcemapsSourcesProtocol,
|
|
@@ -22849,6 +22856,7 @@ const startDevServer = async ({
|
|
|
22849
22856
|
serverStopCallbacks.push(() => {
|
|
22850
22857
|
serverEventsDispatcher.destroy();
|
|
22851
22858
|
});
|
|
22859
|
+
const contextCache = new Map();
|
|
22852
22860
|
const server = await startServer({
|
|
22853
22861
|
signal,
|
|
22854
22862
|
stopOnExit: false,
|
|
@@ -22877,6 +22885,7 @@ const startDevServer = async ({
|
|
|
22877
22885
|
logLevel,
|
|
22878
22886
|
serverStopCallbacks,
|
|
22879
22887
|
serverEventsDispatcher,
|
|
22888
|
+
contextCache,
|
|
22880
22889
|
rootDirectoryUrl,
|
|
22881
22890
|
runtimeCompat,
|
|
22882
22891
|
plugins,
|
|
@@ -22967,7 +22976,8 @@ const startDevServer = async ({
|
|
|
22967
22976
|
origin: server.origin,
|
|
22968
22977
|
stop: () => {
|
|
22969
22978
|
server.stop();
|
|
22970
|
-
}
|
|
22979
|
+
},
|
|
22980
|
+
contextCache
|
|
22971
22981
|
};
|
|
22972
22982
|
};
|
|
22973
22983
|
|
|
@@ -26153,30 +26163,46 @@ const startBuildServer = async ({
|
|
|
26153
26163
|
},
|
|
26154
26164
|
buildServerAutoreload = false,
|
|
26155
26165
|
buildServerMainFile = getCallerPosition().url,
|
|
26156
|
-
cooldownBetweenFileEvents
|
|
26166
|
+
cooldownBetweenFileEvents,
|
|
26167
|
+
...rest
|
|
26157
26168
|
}) => {
|
|
26158
|
-
|
|
26159
|
-
|
|
26160
|
-
|
|
26161
|
-
|
|
26162
|
-
|
|
26163
|
-
if (buildIndexPath) {
|
|
26164
|
-
if (typeof buildIndexPath !== "string") {
|
|
26165
|
-
throw new TypeError(`buildIndexPath must be a string, got ${buildIndexPath}`);
|
|
26169
|
+
// params validation
|
|
26170
|
+
{
|
|
26171
|
+
const unexpectedParamNames = Object.keys(rest);
|
|
26172
|
+
if (unexpectedParamNames.length > 0) {
|
|
26173
|
+
throw new TypeError(`${unexpectedParamNames.join(",")}: there is no such param`);
|
|
26166
26174
|
}
|
|
26167
|
-
|
|
26168
|
-
|
|
26169
|
-
|
|
26170
|
-
const buildIndexUrl = new URL(buildIndexPath, buildDirectoryUrl).href;
|
|
26171
|
-
if (!buildIndexUrl.startsWith(buildDirectoryUrl)) {
|
|
26172
|
-
throw new Error(`buildIndexPath must be relative, got ${buildIndexPath}`);
|
|
26173
|
-
}
|
|
26174
|
-
buildIndexPath = buildIndexUrl.slice(buildDirectoryUrl.length);
|
|
26175
|
+
const rootDirectoryUrlValidation = validateDirectoryUrl(rootDirectoryUrl);
|
|
26176
|
+
if (!rootDirectoryUrlValidation.valid) {
|
|
26177
|
+
throw new TypeError(`rootDirectoryUrl ${rootDirectoryUrlValidation.message}, got ${rootDirectoryUrl}`);
|
|
26175
26178
|
}
|
|
26176
|
-
|
|
26177
|
-
|
|
26179
|
+
rootDirectoryUrl = rootDirectoryUrlValidation.value;
|
|
26180
|
+
const buildDirectoryUrlValidation = validateDirectoryUrl(buildDirectoryUrl);
|
|
26181
|
+
if (!buildDirectoryUrlValidation.valid) {
|
|
26182
|
+
throw new TypeError(`buildDirectoryUrl ${buildDirectoryUrlValidation.message}, got ${buildDirectoryUrlValidation}`);
|
|
26183
|
+
}
|
|
26184
|
+
buildDirectoryUrl = buildDirectoryUrlValidation.value;
|
|
26185
|
+
if (buildIndexPath) {
|
|
26186
|
+
if (typeof buildIndexPath !== "string") {
|
|
26187
|
+
throw new TypeError(`buildIndexPath must be a string, got ${buildIndexPath}`);
|
|
26188
|
+
}
|
|
26189
|
+
if (buildIndexPath[0] === "/") {
|
|
26190
|
+
buildIndexPath = buildIndexPath.slice(1);
|
|
26191
|
+
} else {
|
|
26192
|
+
const buildIndexUrl = new URL(buildIndexPath, buildDirectoryUrl).href;
|
|
26193
|
+
if (!buildIndexUrl.startsWith(buildDirectoryUrl)) {
|
|
26194
|
+
throw new Error(`buildIndexPath must be relative, got ${buildIndexPath}`);
|
|
26195
|
+
}
|
|
26196
|
+
buildIndexPath = buildIndexUrl.slice(buildDirectoryUrl.length);
|
|
26197
|
+
}
|
|
26198
|
+
if (!existsSync(new URL(buildIndexPath, buildDirectoryUrl))) {
|
|
26199
|
+
buildIndexPath = null;
|
|
26200
|
+
}
|
|
26178
26201
|
}
|
|
26179
26202
|
}
|
|
26203
|
+
const logger = createLogger({
|
|
26204
|
+
logLevel
|
|
26205
|
+
});
|
|
26180
26206
|
const operation = Abort.startOperation();
|
|
26181
26207
|
operation.addAbortSignal(signal);
|
|
26182
26208
|
if (handleSIGINT) {
|
package/package.json
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
jsenvServiceErrorHandler,
|
|
24
24
|
} from "@jsenv/server"
|
|
25
25
|
import {
|
|
26
|
-
|
|
26
|
+
validateDirectoryUrl,
|
|
27
27
|
registerDirectoryLifecycle,
|
|
28
28
|
} from "@jsenv/filesystem"
|
|
29
29
|
import { Abort, raceProcessTeardownEvents } from "@jsenv/abort"
|
|
@@ -62,32 +62,55 @@ export const startBuildServer = async ({
|
|
|
62
62
|
buildServerAutoreload = false,
|
|
63
63
|
buildServerMainFile = getCallerPosition().url,
|
|
64
64
|
cooldownBetweenFileEvents,
|
|
65
|
+
...rest
|
|
65
66
|
}) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
// params validation
|
|
68
|
+
{
|
|
69
|
+
const unexpectedParamNames = Object.keys(rest)
|
|
70
|
+
if (unexpectedParamNames.length > 0) {
|
|
71
|
+
throw new TypeError(
|
|
72
|
+
`${unexpectedParamNames.join(",")}: there is no such param`,
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
const rootDirectoryUrlValidation = validateDirectoryUrl(rootDirectoryUrl)
|
|
76
|
+
if (!rootDirectoryUrlValidation.valid) {
|
|
77
|
+
throw new TypeError(
|
|
78
|
+
`rootDirectoryUrl ${rootDirectoryUrlValidation.message}, got ${rootDirectoryUrl}`,
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
rootDirectoryUrl = rootDirectoryUrlValidation.value
|
|
82
|
+
const buildDirectoryUrlValidation = validateDirectoryUrl(buildDirectoryUrl)
|
|
83
|
+
if (!buildDirectoryUrlValidation.valid) {
|
|
71
84
|
throw new TypeError(
|
|
72
|
-
`
|
|
85
|
+
`buildDirectoryUrl ${buildDirectoryUrlValidation.message}, got ${buildDirectoryUrlValidation}`,
|
|
73
86
|
)
|
|
74
87
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
`buildIndexPath must be relative, got ${buildIndexPath}`,
|
|
88
|
+
buildDirectoryUrl = buildDirectoryUrlValidation.value
|
|
89
|
+
|
|
90
|
+
if (buildIndexPath) {
|
|
91
|
+
if (typeof buildIndexPath !== "string") {
|
|
92
|
+
throw new TypeError(
|
|
93
|
+
`buildIndexPath must be a string, got ${buildIndexPath}`,
|
|
82
94
|
)
|
|
83
95
|
}
|
|
84
|
-
buildIndexPath
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
96
|
+
if (buildIndexPath[0] === "/") {
|
|
97
|
+
buildIndexPath = buildIndexPath.slice(1)
|
|
98
|
+
} else {
|
|
99
|
+
const buildIndexUrl = new URL(buildIndexPath, buildDirectoryUrl).href
|
|
100
|
+
if (!buildIndexUrl.startsWith(buildDirectoryUrl)) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
`buildIndexPath must be relative, got ${buildIndexPath}`,
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
buildIndexPath = buildIndexUrl.slice(buildDirectoryUrl.length)
|
|
106
|
+
}
|
|
107
|
+
if (!existsSync(new URL(buildIndexPath, buildDirectoryUrl))) {
|
|
108
|
+
buildIndexPath = null
|
|
109
|
+
}
|
|
88
110
|
}
|
|
89
111
|
}
|
|
90
112
|
|
|
113
|
+
const logger = createLogger({ logLevel })
|
|
91
114
|
const operation = Abort.startOperation()
|
|
92
115
|
operation.addAbortSignal(signal)
|
|
93
116
|
if (handleSIGINT) {
|
package/src/dev/file_service.js
CHANGED
|
@@ -20,6 +20,7 @@ export const createFileService = ({
|
|
|
20
20
|
logLevel,
|
|
21
21
|
serverStopCallbacks,
|
|
22
22
|
serverEventsDispatcher,
|
|
23
|
+
contextCache,
|
|
23
24
|
|
|
24
25
|
rootDirectoryUrl,
|
|
25
26
|
runtimeCompat,
|
|
@@ -82,7 +83,6 @@ export const createFileService = ({
|
|
|
82
83
|
})
|
|
83
84
|
serverStopCallbacks.push(stopWatchingClientFiles)
|
|
84
85
|
|
|
85
|
-
const contextCache = new Map()
|
|
86
86
|
const getOrCreateContext = (request) => {
|
|
87
87
|
const { runtimeName, runtimeVersion } = parseUserAgentHeader(
|
|
88
88
|
request.headers["user-agent"],
|
|
@@ -150,6 +150,7 @@ export const createFileService = ({
|
|
|
150
150
|
ribbon,
|
|
151
151
|
}),
|
|
152
152
|
],
|
|
153
|
+
supervisor,
|
|
153
154
|
minification: false,
|
|
154
155
|
sourcemaps,
|
|
155
156
|
sourcemapsSourcesProtocol,
|
|
@@ -173,6 +173,7 @@ export const startDevServer = async ({
|
|
|
173
173
|
serverStopCallbacks.push(() => {
|
|
174
174
|
serverEventsDispatcher.destroy()
|
|
175
175
|
})
|
|
176
|
+
const contextCache = new Map()
|
|
176
177
|
const server = await startServer({
|
|
177
178
|
signal,
|
|
178
179
|
stopOnExit: false,
|
|
@@ -208,6 +209,7 @@ export const startDevServer = async ({
|
|
|
208
209
|
logLevel,
|
|
209
210
|
serverStopCallbacks,
|
|
210
211
|
serverEventsDispatcher,
|
|
212
|
+
contextCache,
|
|
211
213
|
|
|
212
214
|
rootDirectoryUrl,
|
|
213
215
|
runtimeCompat,
|
|
@@ -304,5 +306,6 @@ export const startDevServer = async ({
|
|
|
304
306
|
stop: () => {
|
|
305
307
|
server.stop()
|
|
306
308
|
},
|
|
309
|
+
contextCache,
|
|
307
310
|
}
|
|
308
311
|
}
|
package/src/kitchen/kitchen.js
CHANGED
|
@@ -673,7 +673,17 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
|
|
|
673
673
|
// (error hapenning before urlInfo.content can be set, or 404 for instance)
|
|
674
674
|
// in that case we can't write anything
|
|
675
675
|
} else {
|
|
676
|
-
|
|
676
|
+
let contentIsInlined = urlInfo.isInline
|
|
677
|
+
if (
|
|
678
|
+
contentIsInlined &&
|
|
679
|
+
context.supervisor &&
|
|
680
|
+
urlGraph.getUrlInfo(urlInfo.inlineUrlSite.url).type === "html"
|
|
681
|
+
) {
|
|
682
|
+
contentIsInlined = false
|
|
683
|
+
}
|
|
684
|
+
if (!contentIsInlined) {
|
|
685
|
+
writeFileSync(new URL(generatedUrl), urlInfo.content)
|
|
686
|
+
}
|
|
677
687
|
const { sourcemapGeneratedUrl, sourcemap } = urlInfo
|
|
678
688
|
if (sourcemapGeneratedUrl && sourcemap) {
|
|
679
689
|
writeFileSync(
|