@jsenv/core 23.8.18 → 23.10.0
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 +2 -2
- package/src/buildProject.js +2 -0
- package/src/internal/building/buildUsingRollup.js +4 -0
- package/src/internal/compiling/compile-directory/getOrGenerateCompiledFile.js +4 -37
- package/src/internal/compiling/compileFile.js +0 -2
- package/src/internal/compiling/createCompiledFileService.js +3 -4
- package/src/internal/compiling/startCompileServer.js +14 -2
- package/src/startExploring.js +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "23.
|
|
3
|
+
"version": "23.10.0",
|
|
4
4
|
"description": "Tool to develop, test and build js projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@jsenv/importmap": "1.2.0",
|
|
71
71
|
"@jsenv/log": "1.4.0",
|
|
72
72
|
"@jsenv/logger": "4.0.1",
|
|
73
|
-
"@jsenv/server": "
|
|
73
|
+
"@jsenv/server": "11.0.0",
|
|
74
74
|
"@jsenv/uneval": "1.6.0",
|
|
75
75
|
"@rollup/plugin-commonjs": "21.0.0",
|
|
76
76
|
"@rollup/plugin-json": "4.1.0",
|
package/src/buildProject.js
CHANGED
|
@@ -67,6 +67,7 @@ export const buildProject = async ({
|
|
|
67
67
|
// in that case the returned buildImportMap must be injected into an html file
|
|
68
68
|
useImportMapToMaximizeCacheReuse,
|
|
69
69
|
preserveEntrySignatures,
|
|
70
|
+
treeshake,
|
|
70
71
|
|
|
71
72
|
minify = process.env.NODE_ENV === "production",
|
|
72
73
|
// https://github.com/kangax/html-minifier#options-quick-reference
|
|
@@ -222,6 +223,7 @@ export const buildProject = async ({
|
|
|
222
223
|
lineBreakNormalization,
|
|
223
224
|
useImportMapToMaximizeCacheReuse,
|
|
224
225
|
preserveEntrySignatures,
|
|
226
|
+
treeshake,
|
|
225
227
|
jsConcatenation,
|
|
226
228
|
|
|
227
229
|
minify,
|
|
@@ -54,6 +54,7 @@ export const buildUsingRollup = async ({
|
|
|
54
54
|
jsConcatenation,
|
|
55
55
|
useImportMapToMaximizeCacheReuse,
|
|
56
56
|
preserveEntrySignatures,
|
|
57
|
+
treeshake,
|
|
57
58
|
|
|
58
59
|
minify,
|
|
59
60
|
minifyJsOptions,
|
|
@@ -141,6 +142,7 @@ export const buildUsingRollup = async ({
|
|
|
141
142
|
globalName,
|
|
142
143
|
sourcemapExcludeSources,
|
|
143
144
|
preserveEntrySignatures,
|
|
145
|
+
treeshake,
|
|
144
146
|
// jsConcatenation,
|
|
145
147
|
buildDirectoryUrl,
|
|
146
148
|
buildDirectoryClean,
|
|
@@ -259,6 +261,7 @@ const useRollup = async ({
|
|
|
259
261
|
globalName,
|
|
260
262
|
sourcemapExcludeSources,
|
|
261
263
|
preserveEntrySignatures,
|
|
264
|
+
treeshake,
|
|
262
265
|
// jsConcatenation,
|
|
263
266
|
buildDirectoryUrl,
|
|
264
267
|
asOriginalUrl,
|
|
@@ -316,6 +319,7 @@ const useRollup = async ({
|
|
|
316
319
|
// on fait cela car sinon rollup est pénible si on passe un entry point map de type html
|
|
317
320
|
input: [],
|
|
318
321
|
preserveEntrySignatures,
|
|
322
|
+
treeshake,
|
|
319
323
|
plugins: [jsenvRollupPlugin],
|
|
320
324
|
acornInjectPlugins: [importAssertions],
|
|
321
325
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { urlToFileSystemPath } from "@jsenv/filesystem"
|
|
1
|
+
import { urlToFileSystemPath, readFile } from "@jsenv/filesystem"
|
|
2
2
|
import { createDetailedMessage } from "@jsenv/logger"
|
|
3
3
|
import { timeStart, timeFunction } from "@jsenv/server"
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
import { validateCache } from "./validateCache.js"
|
|
6
6
|
import { getMetaJsonFileUrl } from "./compile-asset.js"
|
|
7
7
|
import { createLockRegistry } from "./createLockRegistry.js"
|
|
@@ -17,7 +17,6 @@ export const getOrGenerateCompiledFile = async ({
|
|
|
17
17
|
compileCacheStrategy,
|
|
18
18
|
compileCacheSourcesValidation,
|
|
19
19
|
compileCacheAssetsValidation,
|
|
20
|
-
fileContentFallback,
|
|
21
20
|
request,
|
|
22
21
|
compile,
|
|
23
22
|
}) => {
|
|
@@ -65,7 +64,6 @@ export const getOrGenerateCompiledFile = async ({
|
|
|
65
64
|
originalFileUrl,
|
|
66
65
|
compiledFileUrl,
|
|
67
66
|
compile,
|
|
68
|
-
fileContentFallback,
|
|
69
67
|
compileCacheStrategy,
|
|
70
68
|
compileCacheSourcesValidation,
|
|
71
69
|
compileCacheAssetsValidation,
|
|
@@ -94,7 +92,6 @@ const computeCompileReport = async ({
|
|
|
94
92
|
originalFileUrl,
|
|
95
93
|
compiledFileUrl,
|
|
96
94
|
compile,
|
|
97
|
-
fileContentFallback,
|
|
98
95
|
compileCacheStrategy,
|
|
99
96
|
compileCacheSourcesValidation,
|
|
100
97
|
compileCacheAssetsValidation,
|
|
@@ -136,7 +133,6 @@ const computeCompileReport = async ({
|
|
|
136
133
|
callCompile({
|
|
137
134
|
logger,
|
|
138
135
|
originalFileUrl,
|
|
139
|
-
fileContentFallback,
|
|
140
136
|
compile,
|
|
141
137
|
}),
|
|
142
138
|
)
|
|
@@ -174,22 +170,11 @@ const computeCompileReport = async ({
|
|
|
174
170
|
}
|
|
175
171
|
}
|
|
176
172
|
|
|
177
|
-
const callCompile = async ({
|
|
178
|
-
logger,
|
|
179
|
-
originalFileUrl,
|
|
180
|
-
fileContentFallback,
|
|
181
|
-
compile,
|
|
182
|
-
}) => {
|
|
173
|
+
const callCompile = async ({ logger, originalFileUrl, compile }) => {
|
|
183
174
|
logger.debug(`compile ${originalFileUrl}`)
|
|
184
175
|
|
|
185
|
-
const codeBeforeCompile =
|
|
186
|
-
compile.length === 0
|
|
187
|
-
? ""
|
|
188
|
-
: await getCodeToCompile({ originalFileUrl, fileContentFallback })
|
|
189
|
-
|
|
190
176
|
const compileReturnValue = await compile({
|
|
191
|
-
code:
|
|
192
|
-
map: undefined,
|
|
177
|
+
code: await readFile(originalFileUrl),
|
|
193
178
|
})
|
|
194
179
|
if (typeof compileReturnValue !== "object" || compileReturnValue === null) {
|
|
195
180
|
throw new TypeError(
|
|
@@ -229,24 +214,6 @@ const callCompile = async ({
|
|
|
229
214
|
}
|
|
230
215
|
}
|
|
231
216
|
|
|
232
|
-
const getCodeToCompile = async ({ originalFileUrl, fileContentFallback }) => {
|
|
233
|
-
let fileContent
|
|
234
|
-
if (fileContentFallback) {
|
|
235
|
-
try {
|
|
236
|
-
fileContent = await readFileContent(originalFileUrl)
|
|
237
|
-
} catch (e) {
|
|
238
|
-
if (e.code === "ENOENT") {
|
|
239
|
-
fileContent = await fileContentFallback()
|
|
240
|
-
} else {
|
|
241
|
-
throw e
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
} else {
|
|
245
|
-
fileContent = await readFileContent(originalFileUrl)
|
|
246
|
-
}
|
|
247
|
-
return fileContent
|
|
248
|
-
}
|
|
249
|
-
|
|
250
217
|
const startAsap = async (fn, { logger, compiledFileUrl }) => {
|
|
251
218
|
const metaJsonFileUrl = getMetaJsonFileUrl(compiledFileUrl)
|
|
252
219
|
const metaJsonFilePath = urlToFileSystemPath(metaJsonFileUrl)
|
|
@@ -16,7 +16,6 @@ export const compileFile = async ({
|
|
|
16
16
|
projectDirectoryUrl,
|
|
17
17
|
originalFileUrl,
|
|
18
18
|
compiledFileUrl,
|
|
19
|
-
fileContentFallback,
|
|
20
19
|
projectFileRequestedCallback = () => {},
|
|
21
20
|
request,
|
|
22
21
|
pushResponse,
|
|
@@ -44,7 +43,6 @@ export const compileFile = async ({
|
|
|
44
43
|
projectDirectoryUrl,
|
|
45
44
|
originalFileUrl,
|
|
46
45
|
compiledFileUrl,
|
|
47
|
-
fileContentFallback,
|
|
48
46
|
request,
|
|
49
47
|
compileCacheStrategy,
|
|
50
48
|
compileCacheSourcesValidation,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fetchFileSystem } from "@jsenv/server"
|
|
2
2
|
import {
|
|
3
3
|
resolveUrl,
|
|
4
4
|
resolveDirectoryUrl,
|
|
@@ -80,7 +80,7 @@ export const createCompiledFileService = ({
|
|
|
80
80
|
projectDirectoryUrl,
|
|
81
81
|
)
|
|
82
82
|
|
|
83
|
-
return (request, { pushResponse }) => {
|
|
83
|
+
return (request, { pushResponse, redirectRequest }) => {
|
|
84
84
|
const { origin, ressource } = request
|
|
85
85
|
// we use "ressourceToPathname" to remove eventual query param from the url
|
|
86
86
|
// Without this a pattern like "**/*.js" would not match "file.js?t=1"
|
|
@@ -167,12 +167,11 @@ export const createCompiledFileService = ({
|
|
|
167
167
|
projectFileRequestedCallback,
|
|
168
168
|
request,
|
|
169
169
|
pushResponse,
|
|
170
|
-
compile: ({ code
|
|
170
|
+
compile: ({ code }) => {
|
|
171
171
|
return compiler({
|
|
172
172
|
logger,
|
|
173
173
|
|
|
174
174
|
code,
|
|
175
|
-
map,
|
|
176
175
|
url: originalFileUrl,
|
|
177
176
|
compiledUrl: compiledFileUrl,
|
|
178
177
|
projectDirectoryUrl,
|
|
@@ -103,6 +103,7 @@ export const startCompileServer = async ({
|
|
|
103
103
|
},
|
|
104
104
|
livereloadLogLevel = "info",
|
|
105
105
|
customServices = {},
|
|
106
|
+
serverPlugins,
|
|
106
107
|
livereloadSSE = false,
|
|
107
108
|
transformHtmlSourceFiles = true,
|
|
108
109
|
jsenvToolbarInjection = false,
|
|
@@ -279,7 +280,7 @@ export const startCompileServer = async ({
|
|
|
279
280
|
jsenvDirectoryClean,
|
|
280
281
|
compileServerMetaFileInfo,
|
|
281
282
|
})
|
|
282
|
-
writeFile(
|
|
283
|
+
await writeFile(
|
|
283
284
|
compileServerMetaFileInfo.url,
|
|
284
285
|
JSON.stringify(compileServerMetaFileInfo.data, null, " "),
|
|
285
286
|
)
|
|
@@ -358,6 +359,7 @@ export const startCompileServer = async ({
|
|
|
358
359
|
ip: compileServerIp,
|
|
359
360
|
port: compileServerPort,
|
|
360
361
|
plugins: {
|
|
362
|
+
...serverPlugins,
|
|
361
363
|
...pluginCORS({
|
|
362
364
|
accessControlAllowRequestOrigin: true,
|
|
363
365
|
accessControlAllowRequestMethod: true,
|
|
@@ -470,10 +472,20 @@ const cleanOutDirectoryIfNeeded = async ({
|
|
|
470
472
|
let previousCompileServerMeta
|
|
471
473
|
try {
|
|
472
474
|
const source = await readFile(compileServerMetaFileInfo.url)
|
|
473
|
-
|
|
475
|
+
if (source === "") {
|
|
476
|
+
previousCompileServerMeta = null
|
|
477
|
+
logger.debug(
|
|
478
|
+
`compiler server meta file is empty ${compileServerMetaFileInfo.url}`,
|
|
479
|
+
)
|
|
480
|
+
} else {
|
|
481
|
+
previousCompileServerMeta = JSON.parse(source)
|
|
482
|
+
}
|
|
474
483
|
} catch (e) {
|
|
475
484
|
if (e.code === "ENOENT") {
|
|
476
485
|
previousCompileServerMeta = null
|
|
486
|
+
} else if (e.name === "SyntaxError") {
|
|
487
|
+
previousCompileServerMeta = null
|
|
488
|
+
logger.warn(`Syntax error while parsing ${compileServerMetaFileInfo.url}`)
|
|
477
489
|
} else {
|
|
478
490
|
throw e
|
|
479
491
|
}
|
package/src/startExploring.js
CHANGED
|
@@ -49,7 +49,9 @@ export const startExploring = async ({
|
|
|
49
49
|
compileServerCertificate,
|
|
50
50
|
compileServerPrivateKey,
|
|
51
51
|
sourcemapMethod,
|
|
52
|
+
customServices,
|
|
52
53
|
customCompilers,
|
|
54
|
+
serverPlugins,
|
|
53
55
|
livereloadWatchConfig,
|
|
54
56
|
jsenvDirectoryClean,
|
|
55
57
|
}) => {
|
|
@@ -87,11 +89,13 @@ export const startExploring = async ({
|
|
|
87
89
|
livereloadSSE: livereloading,
|
|
88
90
|
jsenvToolbarInjection: jsenvToolbar,
|
|
89
91
|
customServices: {
|
|
92
|
+
...customServices,
|
|
90
93
|
"service:exploring-redirect": (request) => redirectFiles(request),
|
|
91
94
|
"service:exploring-data": (request) => serveExploringData(request),
|
|
92
95
|
"service:explorables": (request) => serveExplorableListAsJson(request),
|
|
93
96
|
},
|
|
94
97
|
customCompilers,
|
|
98
|
+
serverPlugins,
|
|
95
99
|
jsenvDirectoryRelativeUrl,
|
|
96
100
|
outDirectoryName,
|
|
97
101
|
inlineImportMapIntoHTML,
|