@jsenv/core 23.8.2 → 23.8.7
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 +46 -39
- package/dist/jsenv_browser_system.js.map +14 -14
- package/dist/jsenv_compile_proxy.js.map +6 -6
- package/dist/jsenv_exploring_index.js.map +5 -5
- package/dist/jsenv_exploring_redirector.js.map +12 -12
- package/dist/jsenv_toolbar.js.map +7 -7
- package/dist/jsenv_toolbar_injector.js.map +5 -5
- package/helpers/babel/.eslintrc.cjs +24 -24
- package/helpers/babel/AsyncGenerator/AsyncGenerator.js +81 -81
- package/helpers/babel/AwaitValue/AwaitValue.js +3 -3
- package/helpers/babel/applyDecoratorDescriptor/applyDecoratorDescriptor.js +33 -33
- package/helpers/babel/arrayLikeToArray/arrayLikeToArray.js +7 -7
- package/helpers/babel/arrayWithHoles/arrayWithHoles.js +4 -4
- package/helpers/babel/arrayWithoutHoles/arrayWithoutHoles.js +6 -6
- package/helpers/babel/assertThisInitialized/assertThisInitialized.js +7 -7
- package/helpers/babel/asyncGeneratorDelegate/asyncGeneratorDelegate.js +40 -40
- package/helpers/babel/asyncIterator/asyncIterator.js +12 -12
- package/helpers/babel/asyncToGenerator/asyncToGenerator.js +34 -34
- package/helpers/babel/awaitAsyncGenerator/awaitAsyncGenerator.js +5 -5
- package/helpers/babel/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +20 -20
- package/helpers/babel/classApplyDescriptorGet/classApplyDescriptorGet.js +6 -6
- package/helpers/babel/classApplyDescriptorSet/classApplyDescriptorSet.js +13 -13
- package/helpers/babel/classCallCheck/classCallCheck.js +5 -5
- package/helpers/babel/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +5 -5
- package/helpers/babel/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +6 -6
- package/helpers/babel/classExtractFieldDescriptor/classExtractFieldDescriptor.js +7 -7
- package/helpers/babel/classNameTDZError/classNameTDZError.js +4 -4
- package/helpers/babel/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +7 -7
- package/helpers/babel/classPrivateFieldGet/classPrivateFieldGet.js +7 -7
- package/helpers/babel/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +6 -6
- package/helpers/babel/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +5 -5
- package/helpers/babel/classPrivateFieldSet/classPrivateFieldSet.js +8 -8
- package/helpers/babel/classPrivateMethodGet/classPrivateMethodGet.js +6 -6
- package/helpers/babel/classPrivateMethodSet/classPrivateMethodSet.js +3 -3
- package/helpers/babel/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +9 -9
- package/helpers/babel/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +15 -15
- package/helpers/babel/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +6 -6
- package/helpers/babel/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +3 -3
- package/helpers/babel/construct/construct.js +16 -16
- package/helpers/babel/createClass/createClass.js +15 -15
- package/helpers/babel/createForOfIteratorHelper/createForOfIteratorHelper.js +60 -60
- package/helpers/babel/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +23 -23
- package/helpers/babel/createRawReactElement/createRawReactElement.js +50 -50
- package/helpers/babel/createSuper/createSuper.js +22 -22
- package/helpers/babel/decorate/decorate.js +403 -403
- package/helpers/babel/defaults/defaults.js +11 -11
- package/helpers/babel/defineEnumerableProperties/defineEnumerableProperties.js +23 -23
- package/helpers/babel/defineProperty/defineProperty.js +18 -18
- package/helpers/babel/extends/extends.js +14 -14
- package/helpers/babel/get/get.js +13 -13
- package/helpers/babel/getPrototypeOf/getPrototypeOf.js +4 -4
- package/helpers/babel/inherits/inherits.js +15 -15
- package/helpers/babel/inheritsLoose/inheritsLoose.js +7 -7
- package/helpers/babel/initializerDefineProperty/initializerDefineProperty.js +10 -10
- package/helpers/babel/initializerWarningHelper/initializerWarningHelper.js +6 -6
- package/helpers/babel/instanceof/instanceof.js +6 -6
- package/helpers/babel/interopRequireDefault/interopRequireDefault.js +3 -3
- package/helpers/babel/interopRequireWildcard/interopRequireWildcard.js +37 -37
- package/helpers/babel/isNativeFunction/isNativeFunction.js +4 -4
- package/helpers/babel/isNativeReflectConstruct/isNativeReflectConstruct.js +21 -21
- package/helpers/babel/iterableToArray/iterableToArray.js +7 -7
- package/helpers/babel/iterableToArrayLimit/iterableToArrayLimit.js +36 -36
- package/helpers/babel/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +10 -10
- package/helpers/babel/jsx/jsx.js +45 -45
- package/helpers/babel/maybeArrayLike/maybeArrayLike.js +10 -10
- package/helpers/babel/newArrowCheck/newArrowCheck.js +5 -5
- package/helpers/babel/nonIterableRest/nonIterableRest.js +5 -5
- package/helpers/babel/nonIterableSpread/nonIterableSpread.js +5 -5
- package/helpers/babel/objectDestructuringEmpty/objectDestructuringEmpty.js +3 -3
- package/helpers/babel/objectSpread/objectSpread.js +23 -23
- package/helpers/babel/objectSpread2/objectSpread2.js +33 -33
- package/helpers/babel/objectWithoutProperties/objectWithoutProperties.js +19 -19
- package/helpers/babel/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +13 -13
- package/helpers/babel/possibleConstructorReturn/possibleConstructorReturn.js +10 -10
- package/helpers/babel/readOnlyError/readOnlyError.js +4 -4
- package/helpers/babel/readme.md +9 -9
- package/helpers/babel/set/set.js +44 -44
- package/helpers/babel/setPrototypeOf/setPrototypeOf.js +6 -6
- package/helpers/babel/skipFirstGeneratorNext/skipFirstGeneratorNext.js +8 -8
- package/helpers/babel/slicedToArray/slicedToArray.js +10 -10
- package/helpers/babel/slicedToArrayLoose/slicedToArrayLoose.js +13 -13
- package/helpers/babel/superPropBase/superPropBase.js +10 -10
- package/helpers/babel/taggedTemplateLiteral/taggedTemplateLiteral.js +10 -10
- package/helpers/babel/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +7 -7
- package/helpers/babel/tdz/tdz.js +4 -4
- package/helpers/babel/temporalRef/temporalRef.js +6 -6
- package/helpers/babel/temporalUndefined/temporalUndefined.js +3 -3
- package/helpers/babel/toArray/toArray.js +10 -10
- package/helpers/babel/toConsumableArray/toConsumableArray.js +10 -10
- package/helpers/babel/toPrimitive/toPrimitive.js +10 -10
- package/helpers/babel/toPropertyKey/toPropertyKey.js +6 -6
- package/helpers/babel/typeof/typeof.js +14 -14
- package/helpers/babel/unsupportedIterableToArray/unsupportedIterableToArray.js +12 -12
- package/helpers/babel/wrapAsyncGenerator/wrapAsyncGenerator.js +8 -8
- package/helpers/babel/wrapNativeSuper/wrapNativeSuper.js +30 -30
- package/helpers/babel/wrapRegExp/wrapRegExp.js +63 -63
- package/helpers/babel/writeOnlyError/writeOnlyError.js +4 -4
- package/helpers/regenerator-runtime/regenerator-runtime.js +748 -748
- package/{LICENSE → license} +21 -21
- 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 +203 -199
- package/src/internal/building/buildUsingRollup.js +2 -10
- package/src/internal/compiling/babel_plugin_import_assertions.js +121 -121
- package/src/internal/compiling/babel_plugin_import_metadata.js +22 -22
- package/src/internal/compiling/babel_plugin_import_visitor.js +84 -84
- package/src/internal/compiling/compile-directory/getOrGenerateCompiledFile.js +268 -268
- package/src/internal/compiling/compile-directory/updateMeta.js +154 -154
- package/src/internal/compiling/compile-directory/validateCache.js +265 -265
- package/src/internal/compiling/compileFile.js +233 -224
- package/src/internal/compiling/compileHtml.js +550 -550
- package/src/internal/compiling/createCompiledFileService.js +291 -291
- package/src/internal/compiling/html_source_file_service.js +403 -404
- package/src/internal/compiling/js-compilation-service/jsenvTransform.js +272 -270
- package/src/internal/compiling/jsenvCompilerForHtml.js +374 -308
- package/src/internal/compiling/jsenvCompilerForJavaScript.js +2 -0
- package/src/internal/compiling/startCompileServer.js +1086 -1048
- package/src/internal/compiling/transformResultToCompilationResult.js +220 -220
- package/src/internal/executing/coverage/babel_plugin_instrument.js +90 -90
- package/src/internal/executing/coverage/reportToCoverage.js +193 -187
- package/src/internal/executing/executePlan.js +183 -183
- package/src/internal/executing/launchAndExecute.js +458 -458
- package/src/internal/generateGroupMap/featuresCompatMap.js +29 -0
- package/src/internal/generateGroupMap/jsenvBabelPluginCompatMap.js +1 -8
- package/src/internal/runtime/createBrowserRuntime/scanBrowserRuntimeFeatures.js +246 -246
- package/src/internal/runtime/createNodeRuntime/scanNodeRuntimeFeatures.js +112 -112
- package/src/internal/runtime/s.js +727 -727
- package/src/internal/toolbar/jsenv-logo.svg +144 -144
- package/src/internal/toolbar/toolbar.main.css +196 -196
- package/src/internal/toolbar/toolbar.main.js +227 -227
- package/src/internal/url_conversion.js +317 -317
- package/src/startExploring.js +309 -309
package/{LICENSE → license}
RENAMED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2019 jsenv
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 jsenv
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "23.8.
|
|
3
|
+
"version": "23.8.7",
|
|
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.1.0",
|
|
71
71
|
"@jsenv/log": "1.4.0",
|
|
72
72
|
"@jsenv/logger": "4.0.1",
|
|
73
|
-
"@jsenv/server": "10.0.
|
|
73
|
+
"@jsenv/server": "10.0.11",
|
|
74
74
|
"@jsenv/uneval": "1.6.0",
|
|
75
75
|
"@jsenv/workers": "1.2.0",
|
|
76
76
|
"@rollup/plugin-commonjs": "21.0.0",
|
package/src/buildProject.js
CHANGED
|
@@ -1,300 +1,300 @@
|
|
|
1
|
-
import { createLogger, createDetailedMessage } from "@jsenv/logger"
|
|
2
|
-
import { resolveDirectoryUrl } from "@jsenv/filesystem"
|
|
3
|
-
import { Abort, raceProcessTeardownEvents } from "@jsenv/abort"
|
|
4
|
-
|
|
5
|
-
import { COMPILE_ID_BEST } from "./internal/CONSTANTS.js"
|
|
6
|
-
import {
|
|
7
|
-
assertProjectDirectoryUrl,
|
|
8
|
-
assertProjectDirectoryExists,
|
|
9
|
-
} from "./internal/argUtils.js"
|
|
10
|
-
import { startCompileServer } from "./internal/compiling/startCompileServer.js"
|
|
11
|
-
import { buildUsingRollup } from "./internal/building/buildUsingRollup.js"
|
|
12
|
-
import {
|
|
13
|
-
jsenvBrowserRuntimeSupport,
|
|
14
|
-
jsenvNodeRuntimeSupport,
|
|
15
|
-
} from "./internal/generateGroupMap/jsenvRuntimeSupport.js"
|
|
16
|
-
|
|
17
|
-
export const buildProject = async ({
|
|
18
|
-
signal = new AbortController().signal,
|
|
19
|
-
handleSIGINT = true,
|
|
20
|
-
logLevel = "info",
|
|
21
|
-
compileServerLogLevel = "warn",
|
|
22
|
-
logger,
|
|
23
|
-
|
|
24
|
-
projectDirectoryUrl,
|
|
25
|
-
entryPointMap,
|
|
26
|
-
buildDirectoryRelativeUrl,
|
|
27
|
-
buildDirectoryClean = false,
|
|
28
|
-
assetManifestFile = false,
|
|
29
|
-
assetManifestFileRelativeUrl = "asset-manifest.json",
|
|
30
|
-
sourcemapExcludeSources = false,
|
|
31
|
-
writeOnFileSystem = true,
|
|
32
|
-
|
|
33
|
-
format,
|
|
34
|
-
systemJsUrl,
|
|
35
|
-
globalName,
|
|
36
|
-
globals = {},
|
|
37
|
-
babelPluginMap,
|
|
38
|
-
customCompilers,
|
|
39
|
-
runtimeSupport = format === "global" ||
|
|
40
|
-
format === "systemjs" ||
|
|
41
|
-
format === "esmodule"
|
|
42
|
-
? jsenvBrowserRuntimeSupport
|
|
43
|
-
: jsenvNodeRuntimeSupport,
|
|
44
|
-
transformTopLevelAwait = true,
|
|
45
|
-
|
|
46
|
-
urlMappings = {},
|
|
47
|
-
importResolutionMethod = format === "commonjs" ? "node" : "importmap",
|
|
48
|
-
importMapFileRelativeUrl,
|
|
49
|
-
importDefaultExtension,
|
|
50
|
-
externalImportSpecifiers = [],
|
|
51
|
-
externalImportUrlPatterns = format === "commonjs"
|
|
52
|
-
? {
|
|
53
|
-
"node_modules/": true,
|
|
54
|
-
}
|
|
55
|
-
: {},
|
|
56
|
-
importPaths = {},
|
|
57
|
-
|
|
58
|
-
urlVersioning = format === "systemjs" ||
|
|
59
|
-
format === "esmodule" ||
|
|
60
|
-
format === "global",
|
|
61
|
-
lineBreakNormalization = process.platform === "win32",
|
|
62
|
-
// when jsConcatenation is disabled rollup becomes almost useless
|
|
63
|
-
// except it can still do tree shaking
|
|
64
|
-
jsConcatenation = true,
|
|
65
|
-
// useImportMapToMaximizeCacheReuse is enabled by default when entry point is an HTML file
|
|
66
|
-
// otherwise it's disabled. It can still be explicitely enabled for non HTML entry file
|
|
67
|
-
// in that case the returned buildImportMap must be injected into an html file
|
|
68
|
-
useImportMapToMaximizeCacheReuse,
|
|
69
|
-
preserveEntrySignatures,
|
|
70
|
-
|
|
71
|
-
minify = process.env.NODE_ENV === "production",
|
|
72
|
-
// https://github.com/kangax/html-minifier#options-quick-reference
|
|
73
|
-
minifyHtmlOptions = { collapseWhitespace: true },
|
|
74
|
-
// https://github.com/terser/terser#minify-options
|
|
75
|
-
minifyJsOptions,
|
|
76
|
-
// https://github.com/cssnano/cssnano/tree/master/packages/cssnano-preset-default
|
|
77
|
-
minifyCssOptions,
|
|
78
|
-
|
|
79
|
-
serviceWorkers = {},
|
|
80
|
-
serviceWorkerFinalizer,
|
|
81
|
-
|
|
82
|
-
env = {},
|
|
83
|
-
compileServerProtocol,
|
|
84
|
-
compileServerPrivateKey,
|
|
85
|
-
compileServerCertificate,
|
|
86
|
-
compileServerIp,
|
|
87
|
-
compileServerPort,
|
|
88
|
-
jsenvDirectoryRelativeUrl,
|
|
89
|
-
jsenvDirectoryClean,
|
|
90
|
-
|
|
91
|
-
// when true .jsenv/build directory is generated
|
|
92
|
-
// with all intermediated files used to produce the final build files.
|
|
93
|
-
// it might improve buildProject speed for subsequent build generation
|
|
94
|
-
// but this is to be proven and not absolutely required
|
|
95
|
-
// When false intermediates files are transformed and served in memory
|
|
96
|
-
// by the compile server
|
|
97
|
-
// must be true by default otherwise rollup cannot find sourcemap files
|
|
98
|
-
// when asking them to the compile server
|
|
99
|
-
// (to fix that sourcemap could be inlined)
|
|
100
|
-
filesystemCache = true,
|
|
101
|
-
}) => {
|
|
102
|
-
logger = logger || createLogger({ logLevel })
|
|
103
|
-
if (!["esmodule", "systemjs", "commonjs", "global"].includes(format)) {
|
|
104
|
-
throw new TypeError(
|
|
105
|
-
`unexpected format: ${format}. Must be "esmodule", "systemjs", "commonjs" or "global".`,
|
|
106
|
-
)
|
|
107
|
-
}
|
|
108
|
-
if (typeof runtimeSupport !== "object" || runtimeSupport === null) {
|
|
109
|
-
throw new TypeError(
|
|
110
|
-
`runtimeSupport must be an object, got ${runtimeSupport}`,
|
|
111
|
-
)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
projectDirectoryUrl = assertProjectDirectoryUrl({ projectDirectoryUrl })
|
|
115
|
-
await assertProjectDirectoryExists({ projectDirectoryUrl })
|
|
116
|
-
|
|
117
|
-
assertEntryPointMap({ entryPointMap })
|
|
118
|
-
|
|
119
|
-
if (Object.keys(entryPointMap).length === 0) {
|
|
120
|
-
logger.error(`entryPointMap is an empty object`)
|
|
121
|
-
return {
|
|
122
|
-
rollupBuilds: {},
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
assertBuildDirectoryRelativeUrl({ buildDirectoryRelativeUrl })
|
|
127
|
-
const buildDirectoryUrl = resolveDirectoryUrl(
|
|
128
|
-
buildDirectoryRelativeUrl,
|
|
129
|
-
projectDirectoryUrl,
|
|
130
|
-
)
|
|
131
|
-
assertBuildDirectoryInsideProject({
|
|
132
|
-
buildDirectoryUrl,
|
|
133
|
-
projectDirectoryUrl,
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
const buildOperation = Abort.startOperation()
|
|
137
|
-
buildOperation.addAbortSignal(signal)
|
|
138
|
-
|
|
139
|
-
if (handleSIGINT) {
|
|
140
|
-
buildOperation.addAbortSource((abort) => {
|
|
141
|
-
return raceProcessTeardownEvents(
|
|
142
|
-
{
|
|
143
|
-
SIGINT: true,
|
|
144
|
-
},
|
|
145
|
-
abort,
|
|
146
|
-
)
|
|
147
|
-
})
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const compileServer = await startCompileServer({
|
|
151
|
-
signal: buildOperation.signal,
|
|
152
|
-
compileServerLogLevel,
|
|
153
|
-
|
|
154
|
-
projectDirectoryUrl,
|
|
155
|
-
jsenvDirectoryRelativeUrl,
|
|
156
|
-
jsenvDirectoryClean,
|
|
157
|
-
// build compiled files are written into a different directory
|
|
158
|
-
// than exploring-server. This is because here we compile for rollup
|
|
159
|
-
// that is expecting esmodule format, not systemjs
|
|
160
|
-
// + some more differences like import.meta.dev
|
|
161
|
-
outDirectoryName: "build",
|
|
162
|
-
importDefaultExtension,
|
|
163
|
-
moduleOutFormat: "esmodule", // rollup will transform into systemjs
|
|
164
|
-
importMetaFormat: format, // but ensure import.meta are correctly transformed into the right format
|
|
165
|
-
|
|
166
|
-
compileServerProtocol,
|
|
167
|
-
compileServerPrivateKey,
|
|
168
|
-
compileServerCertificate,
|
|
169
|
-
compileServerIp,
|
|
170
|
-
compileServerPort,
|
|
171
|
-
env,
|
|
172
|
-
babelPluginMap,
|
|
173
|
-
transformTopLevelAwait,
|
|
174
|
-
customCompilers,
|
|
175
|
-
runtimeSupport,
|
|
176
|
-
|
|
177
|
-
compileServerCanReadFromFileSystem: filesystemCache,
|
|
178
|
-
compileServerCanWriteOnFilesystem: filesystemCache,
|
|
179
|
-
// keep source html untouched
|
|
180
|
-
// here we don't need to inline importmap
|
|
181
|
-
// nor to inject jsenv script
|
|
182
|
-
transformHtmlSourceFiles: false,
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
buildOperation.addEndCallback(async () => {
|
|
186
|
-
await compileServer.stop(`build cleanup`)
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
const { outDirectoryRelativeUrl, origin: compileServerOrigin } = compileServer
|
|
190
|
-
|
|
191
|
-
try {
|
|
192
|
-
const result = await buildUsingRollup({
|
|
193
|
-
buildOperation,
|
|
194
|
-
logger,
|
|
195
|
-
|
|
196
|
-
entryPointMap,
|
|
197
|
-
projectDirectoryUrl,
|
|
198
|
-
compileServerOrigin,
|
|
199
|
-
compileDirectoryRelativeUrl: `${outDirectoryRelativeUrl}${COMPILE_ID_BEST}/`,
|
|
200
|
-
buildDirectoryUrl,
|
|
201
|
-
buildDirectoryClean,
|
|
202
|
-
assetManifestFile,
|
|
203
|
-
assetManifestFileRelativeUrl,
|
|
204
|
-
|
|
205
|
-
urlMappings,
|
|
206
|
-
importResolutionMethod,
|
|
207
|
-
importMapFileRelativeUrl,
|
|
208
|
-
importDefaultExtension,
|
|
209
|
-
externalImportSpecifiers,
|
|
210
|
-
externalImportUrlPatterns,
|
|
211
|
-
importPaths,
|
|
212
|
-
|
|
213
|
-
format,
|
|
214
|
-
systemJsUrl,
|
|
215
|
-
globalName,
|
|
216
|
-
globals,
|
|
217
|
-
babelPluginMap,
|
|
218
|
-
transformTopLevelAwait,
|
|
219
|
-
runtimeSupport,
|
|
220
|
-
|
|
221
|
-
urlVersioning,
|
|
222
|
-
lineBreakNormalization,
|
|
223
|
-
useImportMapToMaximizeCacheReuse,
|
|
224
|
-
preserveEntrySignatures,
|
|
225
|
-
jsConcatenation,
|
|
226
|
-
|
|
227
|
-
minify,
|
|
228
|
-
minifyHtmlOptions,
|
|
229
|
-
minifyJsOptions,
|
|
230
|
-
minifyCssOptions,
|
|
231
|
-
|
|
232
|
-
serviceWorkers,
|
|
233
|
-
serviceWorkerFinalizer,
|
|
234
|
-
|
|
235
|
-
writeOnFileSystem,
|
|
236
|
-
sourcemapExcludeSources,
|
|
237
|
-
})
|
|
238
|
-
|
|
239
|
-
return result
|
|
240
|
-
} catch (e) {
|
|
241
|
-
if (Abort.isAbortError(e)) {
|
|
242
|
-
logger.info("build aborted")
|
|
243
|
-
return null
|
|
244
|
-
}
|
|
245
|
-
throw e
|
|
246
|
-
} finally {
|
|
247
|
-
await buildOperation.end()
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
const assertEntryPointMap = ({ entryPointMap }) => {
|
|
252
|
-
if (typeof entryPointMap !== "object") {
|
|
253
|
-
throw new TypeError(`entryPointMap must be an object, got ${entryPointMap}`)
|
|
254
|
-
}
|
|
255
|
-
const keys = Object.keys(entryPointMap)
|
|
256
|
-
keys.forEach((key) => {
|
|
257
|
-
if (!key.startsWith("./")) {
|
|
258
|
-
throw new TypeError(
|
|
259
|
-
`unexpected key in entryPointMap, all keys must start with ./ but found ${key}`,
|
|
260
|
-
)
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const value = entryPointMap[key]
|
|
264
|
-
if (typeof value !== "string") {
|
|
265
|
-
throw new TypeError(
|
|
266
|
-
`unexpected value in entryPointMap, all values must be strings found ${value} for key ${key}`,
|
|
267
|
-
)
|
|
268
|
-
}
|
|
269
|
-
if (!value.startsWith("./")) {
|
|
270
|
-
throw new TypeError(
|
|
271
|
-
`unexpected value in entryPointMap, all values must starts with ./ but found ${value} for key ${key}`,
|
|
272
|
-
)
|
|
273
|
-
}
|
|
274
|
-
})
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
const assertBuildDirectoryRelativeUrl = ({ buildDirectoryRelativeUrl }) => {
|
|
278
|
-
if (typeof buildDirectoryRelativeUrl !== "string") {
|
|
279
|
-
throw new TypeError(
|
|
280
|
-
`buildDirectoryRelativeUrl must be a string, received ${buildDirectoryRelativeUrl}`,
|
|
281
|
-
)
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
const assertBuildDirectoryInsideProject = ({
|
|
286
|
-
buildDirectoryUrl,
|
|
287
|
-
projectDirectoryUrl,
|
|
288
|
-
}) => {
|
|
289
|
-
if (!buildDirectoryUrl.startsWith(projectDirectoryUrl)) {
|
|
290
|
-
throw new Error(
|
|
291
|
-
createDetailedMessage(
|
|
292
|
-
`build directory must be inside project directory`,
|
|
293
|
-
{
|
|
294
|
-
["build directory url"]: buildDirectoryUrl,
|
|
295
|
-
["project directory url"]: projectDirectoryUrl,
|
|
296
|
-
},
|
|
297
|
-
),
|
|
298
|
-
)
|
|
299
|
-
}
|
|
300
|
-
}
|
|
1
|
+
import { createLogger, createDetailedMessage } from "@jsenv/logger"
|
|
2
|
+
import { resolveDirectoryUrl } from "@jsenv/filesystem"
|
|
3
|
+
import { Abort, raceProcessTeardownEvents } from "@jsenv/abort"
|
|
4
|
+
|
|
5
|
+
import { COMPILE_ID_BEST } from "./internal/CONSTANTS.js"
|
|
6
|
+
import {
|
|
7
|
+
assertProjectDirectoryUrl,
|
|
8
|
+
assertProjectDirectoryExists,
|
|
9
|
+
} from "./internal/argUtils.js"
|
|
10
|
+
import { startCompileServer } from "./internal/compiling/startCompileServer.js"
|
|
11
|
+
import { buildUsingRollup } from "./internal/building/buildUsingRollup.js"
|
|
12
|
+
import {
|
|
13
|
+
jsenvBrowserRuntimeSupport,
|
|
14
|
+
jsenvNodeRuntimeSupport,
|
|
15
|
+
} from "./internal/generateGroupMap/jsenvRuntimeSupport.js"
|
|
16
|
+
|
|
17
|
+
export const buildProject = async ({
|
|
18
|
+
signal = new AbortController().signal,
|
|
19
|
+
handleSIGINT = true,
|
|
20
|
+
logLevel = "info",
|
|
21
|
+
compileServerLogLevel = "warn",
|
|
22
|
+
logger,
|
|
23
|
+
|
|
24
|
+
projectDirectoryUrl,
|
|
25
|
+
entryPointMap,
|
|
26
|
+
buildDirectoryRelativeUrl,
|
|
27
|
+
buildDirectoryClean = false,
|
|
28
|
+
assetManifestFile = false,
|
|
29
|
+
assetManifestFileRelativeUrl = "asset-manifest.json",
|
|
30
|
+
sourcemapExcludeSources = false,
|
|
31
|
+
writeOnFileSystem = true,
|
|
32
|
+
|
|
33
|
+
format,
|
|
34
|
+
systemJsUrl,
|
|
35
|
+
globalName,
|
|
36
|
+
globals = {},
|
|
37
|
+
babelPluginMap,
|
|
38
|
+
customCompilers,
|
|
39
|
+
runtimeSupport = format === "global" ||
|
|
40
|
+
format === "systemjs" ||
|
|
41
|
+
format === "esmodule"
|
|
42
|
+
? jsenvBrowserRuntimeSupport
|
|
43
|
+
: jsenvNodeRuntimeSupport,
|
|
44
|
+
transformTopLevelAwait = true,
|
|
45
|
+
|
|
46
|
+
urlMappings = {},
|
|
47
|
+
importResolutionMethod = format === "commonjs" ? "node" : "importmap",
|
|
48
|
+
importMapFileRelativeUrl,
|
|
49
|
+
importDefaultExtension,
|
|
50
|
+
externalImportSpecifiers = [],
|
|
51
|
+
externalImportUrlPatterns = format === "commonjs"
|
|
52
|
+
? {
|
|
53
|
+
"node_modules/": true,
|
|
54
|
+
}
|
|
55
|
+
: {},
|
|
56
|
+
importPaths = {},
|
|
57
|
+
|
|
58
|
+
urlVersioning = format === "systemjs" ||
|
|
59
|
+
format === "esmodule" ||
|
|
60
|
+
format === "global",
|
|
61
|
+
lineBreakNormalization = process.platform === "win32",
|
|
62
|
+
// when jsConcatenation is disabled rollup becomes almost useless
|
|
63
|
+
// except it can still do tree shaking
|
|
64
|
+
jsConcatenation = true,
|
|
65
|
+
// useImportMapToMaximizeCacheReuse is enabled by default when entry point is an HTML file
|
|
66
|
+
// otherwise it's disabled. It can still be explicitely enabled for non HTML entry file
|
|
67
|
+
// in that case the returned buildImportMap must be injected into an html file
|
|
68
|
+
useImportMapToMaximizeCacheReuse,
|
|
69
|
+
preserveEntrySignatures,
|
|
70
|
+
|
|
71
|
+
minify = process.env.NODE_ENV === "production",
|
|
72
|
+
// https://github.com/kangax/html-minifier#options-quick-reference
|
|
73
|
+
minifyHtmlOptions = { collapseWhitespace: true },
|
|
74
|
+
// https://github.com/terser/terser#minify-options
|
|
75
|
+
minifyJsOptions,
|
|
76
|
+
// https://github.com/cssnano/cssnano/tree/master/packages/cssnano-preset-default
|
|
77
|
+
minifyCssOptions,
|
|
78
|
+
|
|
79
|
+
serviceWorkers = {},
|
|
80
|
+
serviceWorkerFinalizer,
|
|
81
|
+
|
|
82
|
+
env = {},
|
|
83
|
+
compileServerProtocol,
|
|
84
|
+
compileServerPrivateKey,
|
|
85
|
+
compileServerCertificate,
|
|
86
|
+
compileServerIp,
|
|
87
|
+
compileServerPort,
|
|
88
|
+
jsenvDirectoryRelativeUrl,
|
|
89
|
+
jsenvDirectoryClean,
|
|
90
|
+
|
|
91
|
+
// when true .jsenv/build directory is generated
|
|
92
|
+
// with all intermediated files used to produce the final build files.
|
|
93
|
+
// it might improve buildProject speed for subsequent build generation
|
|
94
|
+
// but this is to be proven and not absolutely required
|
|
95
|
+
// When false intermediates files are transformed and served in memory
|
|
96
|
+
// by the compile server
|
|
97
|
+
// must be true by default otherwise rollup cannot find sourcemap files
|
|
98
|
+
// when asking them to the compile server
|
|
99
|
+
// (to fix that sourcemap could be inlined)
|
|
100
|
+
filesystemCache = true,
|
|
101
|
+
}) => {
|
|
102
|
+
logger = logger || createLogger({ logLevel })
|
|
103
|
+
if (!["esmodule", "systemjs", "commonjs", "global"].includes(format)) {
|
|
104
|
+
throw new TypeError(
|
|
105
|
+
`unexpected format: ${format}. Must be "esmodule", "systemjs", "commonjs" or "global".`,
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
if (typeof runtimeSupport !== "object" || runtimeSupport === null) {
|
|
109
|
+
throw new TypeError(
|
|
110
|
+
`runtimeSupport must be an object, got ${runtimeSupport}`,
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
projectDirectoryUrl = assertProjectDirectoryUrl({ projectDirectoryUrl })
|
|
115
|
+
await assertProjectDirectoryExists({ projectDirectoryUrl })
|
|
116
|
+
|
|
117
|
+
assertEntryPointMap({ entryPointMap })
|
|
118
|
+
|
|
119
|
+
if (Object.keys(entryPointMap).length === 0) {
|
|
120
|
+
logger.error(`entryPointMap is an empty object`)
|
|
121
|
+
return {
|
|
122
|
+
rollupBuilds: {},
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
assertBuildDirectoryRelativeUrl({ buildDirectoryRelativeUrl })
|
|
127
|
+
const buildDirectoryUrl = resolveDirectoryUrl(
|
|
128
|
+
buildDirectoryRelativeUrl,
|
|
129
|
+
projectDirectoryUrl,
|
|
130
|
+
)
|
|
131
|
+
assertBuildDirectoryInsideProject({
|
|
132
|
+
buildDirectoryUrl,
|
|
133
|
+
projectDirectoryUrl,
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
const buildOperation = Abort.startOperation()
|
|
137
|
+
buildOperation.addAbortSignal(signal)
|
|
138
|
+
|
|
139
|
+
if (handleSIGINT) {
|
|
140
|
+
buildOperation.addAbortSource((abort) => {
|
|
141
|
+
return raceProcessTeardownEvents(
|
|
142
|
+
{
|
|
143
|
+
SIGINT: true,
|
|
144
|
+
},
|
|
145
|
+
abort,
|
|
146
|
+
)
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const compileServer = await startCompileServer({
|
|
151
|
+
signal: buildOperation.signal,
|
|
152
|
+
compileServerLogLevel,
|
|
153
|
+
|
|
154
|
+
projectDirectoryUrl,
|
|
155
|
+
jsenvDirectoryRelativeUrl,
|
|
156
|
+
jsenvDirectoryClean,
|
|
157
|
+
// build compiled files are written into a different directory
|
|
158
|
+
// than exploring-server. This is because here we compile for rollup
|
|
159
|
+
// that is expecting esmodule format, not systemjs
|
|
160
|
+
// + some more differences like import.meta.dev
|
|
161
|
+
outDirectoryName: "build",
|
|
162
|
+
importDefaultExtension,
|
|
163
|
+
moduleOutFormat: "esmodule", // rollup will transform into systemjs
|
|
164
|
+
importMetaFormat: format, // but ensure import.meta are correctly transformed into the right format
|
|
165
|
+
|
|
166
|
+
compileServerProtocol,
|
|
167
|
+
compileServerPrivateKey,
|
|
168
|
+
compileServerCertificate,
|
|
169
|
+
compileServerIp,
|
|
170
|
+
compileServerPort,
|
|
171
|
+
env,
|
|
172
|
+
babelPluginMap,
|
|
173
|
+
transformTopLevelAwait,
|
|
174
|
+
customCompilers,
|
|
175
|
+
runtimeSupport,
|
|
176
|
+
|
|
177
|
+
compileServerCanReadFromFileSystem: filesystemCache,
|
|
178
|
+
compileServerCanWriteOnFilesystem: filesystemCache,
|
|
179
|
+
// keep source html untouched
|
|
180
|
+
// here we don't need to inline importmap
|
|
181
|
+
// nor to inject jsenv script
|
|
182
|
+
transformHtmlSourceFiles: false,
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
buildOperation.addEndCallback(async () => {
|
|
186
|
+
await compileServer.stop(`build cleanup`)
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
const { outDirectoryRelativeUrl, origin: compileServerOrigin } = compileServer
|
|
190
|
+
|
|
191
|
+
try {
|
|
192
|
+
const result = await buildUsingRollup({
|
|
193
|
+
buildOperation,
|
|
194
|
+
logger,
|
|
195
|
+
|
|
196
|
+
entryPointMap,
|
|
197
|
+
projectDirectoryUrl,
|
|
198
|
+
compileServerOrigin,
|
|
199
|
+
compileDirectoryRelativeUrl: `${outDirectoryRelativeUrl}${COMPILE_ID_BEST}/`,
|
|
200
|
+
buildDirectoryUrl,
|
|
201
|
+
buildDirectoryClean,
|
|
202
|
+
assetManifestFile,
|
|
203
|
+
assetManifestFileRelativeUrl,
|
|
204
|
+
|
|
205
|
+
urlMappings,
|
|
206
|
+
importResolutionMethod,
|
|
207
|
+
importMapFileRelativeUrl,
|
|
208
|
+
importDefaultExtension,
|
|
209
|
+
externalImportSpecifiers,
|
|
210
|
+
externalImportUrlPatterns,
|
|
211
|
+
importPaths,
|
|
212
|
+
|
|
213
|
+
format,
|
|
214
|
+
systemJsUrl,
|
|
215
|
+
globalName,
|
|
216
|
+
globals,
|
|
217
|
+
babelPluginMap,
|
|
218
|
+
transformTopLevelAwait,
|
|
219
|
+
runtimeSupport,
|
|
220
|
+
|
|
221
|
+
urlVersioning,
|
|
222
|
+
lineBreakNormalization,
|
|
223
|
+
useImportMapToMaximizeCacheReuse,
|
|
224
|
+
preserveEntrySignatures,
|
|
225
|
+
jsConcatenation,
|
|
226
|
+
|
|
227
|
+
minify,
|
|
228
|
+
minifyHtmlOptions,
|
|
229
|
+
minifyJsOptions,
|
|
230
|
+
minifyCssOptions,
|
|
231
|
+
|
|
232
|
+
serviceWorkers,
|
|
233
|
+
serviceWorkerFinalizer,
|
|
234
|
+
|
|
235
|
+
writeOnFileSystem,
|
|
236
|
+
sourcemapExcludeSources,
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
return result
|
|
240
|
+
} catch (e) {
|
|
241
|
+
if (Abort.isAbortError(e)) {
|
|
242
|
+
logger.info("build aborted")
|
|
243
|
+
return null
|
|
244
|
+
}
|
|
245
|
+
throw e
|
|
246
|
+
} finally {
|
|
247
|
+
await buildOperation.end()
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const assertEntryPointMap = ({ entryPointMap }) => {
|
|
252
|
+
if (typeof entryPointMap !== "object") {
|
|
253
|
+
throw new TypeError(`entryPointMap must be an object, got ${entryPointMap}`)
|
|
254
|
+
}
|
|
255
|
+
const keys = Object.keys(entryPointMap)
|
|
256
|
+
keys.forEach((key) => {
|
|
257
|
+
if (!key.startsWith("./")) {
|
|
258
|
+
throw new TypeError(
|
|
259
|
+
`unexpected key in entryPointMap, all keys must start with ./ but found ${key}`,
|
|
260
|
+
)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const value = entryPointMap[key]
|
|
264
|
+
if (typeof value !== "string") {
|
|
265
|
+
throw new TypeError(
|
|
266
|
+
`unexpected value in entryPointMap, all values must be strings found ${value} for key ${key}`,
|
|
267
|
+
)
|
|
268
|
+
}
|
|
269
|
+
if (!value.startsWith("./")) {
|
|
270
|
+
throw new TypeError(
|
|
271
|
+
`unexpected value in entryPointMap, all values must starts with ./ but found ${value} for key ${key}`,
|
|
272
|
+
)
|
|
273
|
+
}
|
|
274
|
+
})
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const assertBuildDirectoryRelativeUrl = ({ buildDirectoryRelativeUrl }) => {
|
|
278
|
+
if (typeof buildDirectoryRelativeUrl !== "string") {
|
|
279
|
+
throw new TypeError(
|
|
280
|
+
`buildDirectoryRelativeUrl must be a string, received ${buildDirectoryRelativeUrl}`,
|
|
281
|
+
)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const assertBuildDirectoryInsideProject = ({
|
|
286
|
+
buildDirectoryUrl,
|
|
287
|
+
projectDirectoryUrl,
|
|
288
|
+
}) => {
|
|
289
|
+
if (!buildDirectoryUrl.startsWith(projectDirectoryUrl)) {
|
|
290
|
+
throw new Error(
|
|
291
|
+
createDetailedMessage(
|
|
292
|
+
`build directory must be inside project directory`,
|
|
293
|
+
{
|
|
294
|
+
["build directory url"]: buildDirectoryUrl,
|
|
295
|
+
["project directory url"]: projectDirectoryUrl,
|
|
296
|
+
},
|
|
297
|
+
),
|
|
298
|
+
)
|
|
299
|
+
}
|
|
300
|
+
}
|