@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
|
@@ -1,220 +1,220 @@
|
|
|
1
|
-
import {
|
|
2
|
-
resolveUrl,
|
|
3
|
-
urlToRelativeUrl,
|
|
4
|
-
readFile,
|
|
5
|
-
ensureWindowsDriveLetter,
|
|
6
|
-
} from "@jsenv/filesystem"
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
replaceBackSlashesWithSlashes,
|
|
10
|
-
startsWithWindowsDriveLetter,
|
|
11
|
-
windowsFilePathToUrl,
|
|
12
|
-
} from "../filePathUtils.js"
|
|
13
|
-
import {
|
|
14
|
-
setJavaScriptSourceMappingUrl,
|
|
15
|
-
setCssSourceMappingUrl,
|
|
16
|
-
sourcemapToBase64Url,
|
|
17
|
-
} from "../sourceMappingURLUtils.js"
|
|
18
|
-
import { generateCompiledFileAssetUrl } from "./compile-directory/compile-asset.js"
|
|
19
|
-
import { testFilePresence } from "./compile-directory/fs-optimized-for-cache.js"
|
|
20
|
-
|
|
21
|
-
const isWindows = process.platform === "win32"
|
|
22
|
-
|
|
23
|
-
export const transformResultToCompilationResult = async (
|
|
24
|
-
{ contentType, code, map, metadata = {} },
|
|
25
|
-
{
|
|
26
|
-
projectDirectoryUrl,
|
|
27
|
-
originalFileContent,
|
|
28
|
-
originalFileUrl,
|
|
29
|
-
compiledFileUrl,
|
|
30
|
-
sourcemapFileUrl,
|
|
31
|
-
sourcemapEnabled = true,
|
|
32
|
-
// removing sourcesContent from map decrease the sourceMap
|
|
33
|
-
// it also means client have to fetch source from server (additional http request)
|
|
34
|
-
// some client ignore sourcesContent property such as vscode-chrome-debugger
|
|
35
|
-
// Because it's the most complex scenario and we want to ensure client is always able
|
|
36
|
-
// to find source from the sourcemap, we remove map.sourcesContent by default to test this.
|
|
37
|
-
sourcemapExcludeSources = true,
|
|
38
|
-
sourcemapMethod = "comment", // "comment", "inline"
|
|
39
|
-
},
|
|
40
|
-
) => {
|
|
41
|
-
if (typeof contentType !== "string") {
|
|
42
|
-
throw new TypeError(`contentType must be a string, got ${contentType}`)
|
|
43
|
-
}
|
|
44
|
-
if (typeof projectDirectoryUrl !== "string") {
|
|
45
|
-
throw new TypeError(
|
|
46
|
-
`projectDirectoryUrl must be a string, got ${projectDirectoryUrl}`,
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
if (typeof originalFileContent !== "string") {
|
|
50
|
-
throw new TypeError(
|
|
51
|
-
`originalFileContent must be a string, got ${originalFileContent}`,
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
if (typeof originalFileUrl !== "string") {
|
|
55
|
-
throw new TypeError(
|
|
56
|
-
`originalFileUrl must be a string, got ${originalFileUrl}`,
|
|
57
|
-
)
|
|
58
|
-
}
|
|
59
|
-
if (typeof compiledFileUrl !== "string") {
|
|
60
|
-
throw new TypeError(
|
|
61
|
-
`compiledFileUrl must be a string, got ${compiledFileUrl}`,
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
if (typeof sourcemapFileUrl !== "string") {
|
|
65
|
-
throw new TypeError(
|
|
66
|
-
`sourcemapFileUrl must be a string, got ${sourcemapFileUrl}`,
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const sources = []
|
|
71
|
-
const sourcesContent = []
|
|
72
|
-
const assets = []
|
|
73
|
-
const assetsContent = []
|
|
74
|
-
|
|
75
|
-
let output = code
|
|
76
|
-
if (sourcemapEnabled && map) {
|
|
77
|
-
if (map.sources.length === 0) {
|
|
78
|
-
// may happen in some cases where babel returns a wrong sourcemap
|
|
79
|
-
// there is at least one case where it happens
|
|
80
|
-
// a file with only import './whatever.js' inside
|
|
81
|
-
sources.push(originalFileUrl)
|
|
82
|
-
sourcesContent.push(originalFileContent)
|
|
83
|
-
} else {
|
|
84
|
-
map.sources.forEach((source, index) => {
|
|
85
|
-
const sourceFileUrl = resolveSourceFile({
|
|
86
|
-
source,
|
|
87
|
-
sourcemapFileUrl,
|
|
88
|
-
originalFileUrl,
|
|
89
|
-
compiledFileUrl,
|
|
90
|
-
projectDirectoryUrl,
|
|
91
|
-
})
|
|
92
|
-
if (sourceFileUrl) {
|
|
93
|
-
map.sources[index] = urlToRelativeUrl(sourceFileUrl, sourcemapFileUrl)
|
|
94
|
-
sources[index] = sourceFileUrl
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
if (sources.length === 0) {
|
|
99
|
-
// happens when sourcemap is generated by webpack and looks like
|
|
100
|
-
// webpack://Package./src/file.js
|
|
101
|
-
// in that case we'll don't know how to find the source file
|
|
102
|
-
sources.push(originalFileUrl)
|
|
103
|
-
sourcesContent.push(originalFileContent)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
await Promise.all(
|
|
107
|
-
sources.map(async (sourceUrl, index) => {
|
|
108
|
-
const contentFromSourcemap = map.sourcesContent
|
|
109
|
-
? map.sourcesContent[index]
|
|
110
|
-
: null
|
|
111
|
-
if (contentFromSourcemap) {
|
|
112
|
-
sourcesContent[index] = contentFromSourcemap
|
|
113
|
-
} else {
|
|
114
|
-
const contentFromFile = await readFile(sourceUrl)
|
|
115
|
-
sourcesContent[index] = contentFromFile
|
|
116
|
-
}
|
|
117
|
-
}),
|
|
118
|
-
)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (sourcemapExcludeSources) {
|
|
122
|
-
delete map.sourcesContent
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// we don't need sourceRoot because our path are relative or absolute to the current location
|
|
126
|
-
// we could comment this line because it is not set by babel because not passed during transform
|
|
127
|
-
delete map.sourceRoot
|
|
128
|
-
|
|
129
|
-
const setSourceMappingUrl =
|
|
130
|
-
contentType === "application/javascript"
|
|
131
|
-
? setJavaScriptSourceMappingUrl
|
|
132
|
-
: setCssSourceMappingUrl
|
|
133
|
-
|
|
134
|
-
if (sourcemapMethod === "inline") {
|
|
135
|
-
output = setSourceMappingUrl(output, sourcemapToBase64Url(map))
|
|
136
|
-
} else if (sourcemapMethod === "comment") {
|
|
137
|
-
const sourcemapFileRelativePathForModule = urlToRelativeUrl(
|
|
138
|
-
sourcemapFileUrl,
|
|
139
|
-
compiledFileUrl,
|
|
140
|
-
)
|
|
141
|
-
output = setSourceMappingUrl(output, sourcemapFileRelativePathForModule)
|
|
142
|
-
assets.push(sourcemapFileUrl)
|
|
143
|
-
assetsContent.push(stringifyMap(map))
|
|
144
|
-
}
|
|
145
|
-
} else {
|
|
146
|
-
sources.push(originalFileUrl)
|
|
147
|
-
sourcesContent.push(originalFileContent)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const { coverage } = metadata
|
|
151
|
-
if (coverage) {
|
|
152
|
-
const coverageAssetFileUrl = generateCompiledFileAssetUrl(
|
|
153
|
-
compiledFileUrl,
|
|
154
|
-
"coverage.json",
|
|
155
|
-
)
|
|
156
|
-
assets.push(coverageAssetFileUrl)
|
|
157
|
-
assetsContent.push(stringifyCoverage(coverage))
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const { dependencies = [] } = metadata
|
|
161
|
-
|
|
162
|
-
return {
|
|
163
|
-
contentType,
|
|
164
|
-
compiledSource: output,
|
|
165
|
-
sourcemap: map,
|
|
166
|
-
sources,
|
|
167
|
-
sourcesContent,
|
|
168
|
-
assets,
|
|
169
|
-
assetsContent,
|
|
170
|
-
dependencies,
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const resolveSourceFile = ({
|
|
175
|
-
source,
|
|
176
|
-
sourcemapFileUrl,
|
|
177
|
-
originalFileUrl,
|
|
178
|
-
compiledFileUrl,
|
|
179
|
-
projectDirectoryUrl,
|
|
180
|
-
}) => {
|
|
181
|
-
const sourceFileUrl = resolveSourceUrl({ source, sourcemapFileUrl })
|
|
182
|
-
|
|
183
|
-
if (!sourceFileUrl.startsWith(projectDirectoryUrl)) {
|
|
184
|
-
// do not track dependency outside project
|
|
185
|
-
// it means cache stays valid for those external sources
|
|
186
|
-
return null
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const fileFound = testFilePresence(sourceFileUrl)
|
|
190
|
-
if (fileFound) {
|
|
191
|
-
return sourceFileUrl
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// prefer original source file
|
|
195
|
-
const relativeUrl = urlToRelativeUrl(sourceFileUrl, compiledFileUrl)
|
|
196
|
-
const originalSourceUrl = resolveUrl(relativeUrl, originalFileUrl)
|
|
197
|
-
return originalSourceUrl
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const resolveSourceUrl = ({ source, sourcemapFileUrl }) => {
|
|
201
|
-
if (isWindows) {
|
|
202
|
-
// we can receive:
|
|
203
|
-
// - "C:/Directory/file.js" path from babel
|
|
204
|
-
// - relative path like "directory\file.js" (-> we replace \ with slash)
|
|
205
|
-
if (startsWithWindowsDriveLetter(source)) {
|
|
206
|
-
return windowsFilePathToUrl(source)
|
|
207
|
-
}
|
|
208
|
-
const url = resolveUrl(
|
|
209
|
-
replaceBackSlashesWithSlashes(source),
|
|
210
|
-
sourcemapFileUrl,
|
|
211
|
-
)
|
|
212
|
-
return ensureWindowsDriveLetter(url, sourcemapFileUrl)
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return resolveUrl(source, sourcemapFileUrl)
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const stringifyMap = (object) => JSON.stringify(object, null, " ")
|
|
219
|
-
|
|
220
|
-
const stringifyCoverage = (object) => JSON.stringify(object, null, " ")
|
|
1
|
+
import {
|
|
2
|
+
resolveUrl,
|
|
3
|
+
urlToRelativeUrl,
|
|
4
|
+
readFile,
|
|
5
|
+
ensureWindowsDriveLetter,
|
|
6
|
+
} from "@jsenv/filesystem"
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
replaceBackSlashesWithSlashes,
|
|
10
|
+
startsWithWindowsDriveLetter,
|
|
11
|
+
windowsFilePathToUrl,
|
|
12
|
+
} from "../filePathUtils.js"
|
|
13
|
+
import {
|
|
14
|
+
setJavaScriptSourceMappingUrl,
|
|
15
|
+
setCssSourceMappingUrl,
|
|
16
|
+
sourcemapToBase64Url,
|
|
17
|
+
} from "../sourceMappingURLUtils.js"
|
|
18
|
+
import { generateCompiledFileAssetUrl } from "./compile-directory/compile-asset.js"
|
|
19
|
+
import { testFilePresence } from "./compile-directory/fs-optimized-for-cache.js"
|
|
20
|
+
|
|
21
|
+
const isWindows = process.platform === "win32"
|
|
22
|
+
|
|
23
|
+
export const transformResultToCompilationResult = async (
|
|
24
|
+
{ contentType, code, map, metadata = {} },
|
|
25
|
+
{
|
|
26
|
+
projectDirectoryUrl,
|
|
27
|
+
originalFileContent,
|
|
28
|
+
originalFileUrl,
|
|
29
|
+
compiledFileUrl,
|
|
30
|
+
sourcemapFileUrl,
|
|
31
|
+
sourcemapEnabled = true,
|
|
32
|
+
// removing sourcesContent from map decrease the sourceMap
|
|
33
|
+
// it also means client have to fetch source from server (additional http request)
|
|
34
|
+
// some client ignore sourcesContent property such as vscode-chrome-debugger
|
|
35
|
+
// Because it's the most complex scenario and we want to ensure client is always able
|
|
36
|
+
// to find source from the sourcemap, we remove map.sourcesContent by default to test this.
|
|
37
|
+
sourcemapExcludeSources = true,
|
|
38
|
+
sourcemapMethod = "comment", // "comment", "inline"
|
|
39
|
+
},
|
|
40
|
+
) => {
|
|
41
|
+
if (typeof contentType !== "string") {
|
|
42
|
+
throw new TypeError(`contentType must be a string, got ${contentType}`)
|
|
43
|
+
}
|
|
44
|
+
if (typeof projectDirectoryUrl !== "string") {
|
|
45
|
+
throw new TypeError(
|
|
46
|
+
`projectDirectoryUrl must be a string, got ${projectDirectoryUrl}`,
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
if (typeof originalFileContent !== "string") {
|
|
50
|
+
throw new TypeError(
|
|
51
|
+
`originalFileContent must be a string, got ${originalFileContent}`,
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
if (typeof originalFileUrl !== "string") {
|
|
55
|
+
throw new TypeError(
|
|
56
|
+
`originalFileUrl must be a string, got ${originalFileUrl}`,
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
if (typeof compiledFileUrl !== "string") {
|
|
60
|
+
throw new TypeError(
|
|
61
|
+
`compiledFileUrl must be a string, got ${compiledFileUrl}`,
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
if (typeof sourcemapFileUrl !== "string") {
|
|
65
|
+
throw new TypeError(
|
|
66
|
+
`sourcemapFileUrl must be a string, got ${sourcemapFileUrl}`,
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const sources = []
|
|
71
|
+
const sourcesContent = []
|
|
72
|
+
const assets = []
|
|
73
|
+
const assetsContent = []
|
|
74
|
+
|
|
75
|
+
let output = code
|
|
76
|
+
if (sourcemapEnabled && map) {
|
|
77
|
+
if (map.sources.length === 0) {
|
|
78
|
+
// may happen in some cases where babel returns a wrong sourcemap
|
|
79
|
+
// there is at least one case where it happens
|
|
80
|
+
// a file with only import './whatever.js' inside
|
|
81
|
+
sources.push(originalFileUrl)
|
|
82
|
+
sourcesContent.push(originalFileContent)
|
|
83
|
+
} else {
|
|
84
|
+
map.sources.forEach((source, index) => {
|
|
85
|
+
const sourceFileUrl = resolveSourceFile({
|
|
86
|
+
source,
|
|
87
|
+
sourcemapFileUrl,
|
|
88
|
+
originalFileUrl,
|
|
89
|
+
compiledFileUrl,
|
|
90
|
+
projectDirectoryUrl,
|
|
91
|
+
})
|
|
92
|
+
if (sourceFileUrl) {
|
|
93
|
+
map.sources[index] = urlToRelativeUrl(sourceFileUrl, sourcemapFileUrl)
|
|
94
|
+
sources[index] = sourceFileUrl
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
if (sources.length === 0) {
|
|
99
|
+
// happens when sourcemap is generated by webpack and looks like
|
|
100
|
+
// webpack://Package./src/file.js
|
|
101
|
+
// in that case we'll don't know how to find the source file
|
|
102
|
+
sources.push(originalFileUrl)
|
|
103
|
+
sourcesContent.push(originalFileContent)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
await Promise.all(
|
|
107
|
+
sources.map(async (sourceUrl, index) => {
|
|
108
|
+
const contentFromSourcemap = map.sourcesContent
|
|
109
|
+
? map.sourcesContent[index]
|
|
110
|
+
: null
|
|
111
|
+
if (contentFromSourcemap) {
|
|
112
|
+
sourcesContent[index] = contentFromSourcemap
|
|
113
|
+
} else {
|
|
114
|
+
const contentFromFile = await readFile(sourceUrl)
|
|
115
|
+
sourcesContent[index] = contentFromFile
|
|
116
|
+
}
|
|
117
|
+
}),
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (sourcemapExcludeSources) {
|
|
122
|
+
delete map.sourcesContent
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// we don't need sourceRoot because our path are relative or absolute to the current location
|
|
126
|
+
// we could comment this line because it is not set by babel because not passed during transform
|
|
127
|
+
delete map.sourceRoot
|
|
128
|
+
|
|
129
|
+
const setSourceMappingUrl =
|
|
130
|
+
contentType === "application/javascript"
|
|
131
|
+
? setJavaScriptSourceMappingUrl
|
|
132
|
+
: setCssSourceMappingUrl
|
|
133
|
+
|
|
134
|
+
if (sourcemapMethod === "inline") {
|
|
135
|
+
output = setSourceMappingUrl(output, sourcemapToBase64Url(map))
|
|
136
|
+
} else if (sourcemapMethod === "comment") {
|
|
137
|
+
const sourcemapFileRelativePathForModule = urlToRelativeUrl(
|
|
138
|
+
sourcemapFileUrl,
|
|
139
|
+
compiledFileUrl,
|
|
140
|
+
)
|
|
141
|
+
output = setSourceMappingUrl(output, sourcemapFileRelativePathForModule)
|
|
142
|
+
assets.push(sourcemapFileUrl)
|
|
143
|
+
assetsContent.push(stringifyMap(map))
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
sources.push(originalFileUrl)
|
|
147
|
+
sourcesContent.push(originalFileContent)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const { coverage } = metadata
|
|
151
|
+
if (coverage) {
|
|
152
|
+
const coverageAssetFileUrl = generateCompiledFileAssetUrl(
|
|
153
|
+
compiledFileUrl,
|
|
154
|
+
"coverage.json",
|
|
155
|
+
)
|
|
156
|
+
assets.push(coverageAssetFileUrl)
|
|
157
|
+
assetsContent.push(stringifyCoverage(coverage))
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const { dependencies = [] } = metadata
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
contentType,
|
|
164
|
+
compiledSource: output,
|
|
165
|
+
sourcemap: map,
|
|
166
|
+
sources,
|
|
167
|
+
sourcesContent,
|
|
168
|
+
assets,
|
|
169
|
+
assetsContent,
|
|
170
|
+
dependencies,
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const resolveSourceFile = ({
|
|
175
|
+
source,
|
|
176
|
+
sourcemapFileUrl,
|
|
177
|
+
originalFileUrl,
|
|
178
|
+
compiledFileUrl,
|
|
179
|
+
projectDirectoryUrl,
|
|
180
|
+
}) => {
|
|
181
|
+
const sourceFileUrl = resolveSourceUrl({ source, sourcemapFileUrl })
|
|
182
|
+
|
|
183
|
+
if (!sourceFileUrl.startsWith(projectDirectoryUrl)) {
|
|
184
|
+
// do not track dependency outside project
|
|
185
|
+
// it means cache stays valid for those external sources
|
|
186
|
+
return null
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const fileFound = testFilePresence(sourceFileUrl)
|
|
190
|
+
if (fileFound) {
|
|
191
|
+
return sourceFileUrl
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// prefer original source file
|
|
195
|
+
const relativeUrl = urlToRelativeUrl(sourceFileUrl, compiledFileUrl)
|
|
196
|
+
const originalSourceUrl = resolveUrl(relativeUrl, originalFileUrl)
|
|
197
|
+
return originalSourceUrl
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const resolveSourceUrl = ({ source, sourcemapFileUrl }) => {
|
|
201
|
+
if (isWindows) {
|
|
202
|
+
// we can receive:
|
|
203
|
+
// - "C:/Directory/file.js" path from babel
|
|
204
|
+
// - relative path like "directory\file.js" (-> we replace \ with slash)
|
|
205
|
+
if (startsWithWindowsDriveLetter(source)) {
|
|
206
|
+
return windowsFilePathToUrl(source)
|
|
207
|
+
}
|
|
208
|
+
const url = resolveUrl(
|
|
209
|
+
replaceBackSlashesWithSlashes(source),
|
|
210
|
+
sourcemapFileUrl,
|
|
211
|
+
)
|
|
212
|
+
return ensureWindowsDriveLetter(url, sourcemapFileUrl)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return resolveUrl(source, sourcemapFileUrl)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const stringifyMap = (object) => JSON.stringify(object, null, " ")
|
|
219
|
+
|
|
220
|
+
const stringifyCoverage = (object) => JSON.stringify(object, null, " ")
|
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
import {
|
|
2
|
-
resolveUrl,
|
|
3
|
-
normalizeStructuredMetaMap,
|
|
4
|
-
urlToMeta,
|
|
5
|
-
} from "@jsenv/filesystem"
|
|
6
|
-
|
|
7
|
-
import { require } from "../../require.js"
|
|
8
|
-
|
|
9
|
-
// https://github.com/istanbuljs/babel-plugin-istanbul/blob/321740f7b25d803f881466ea819d870f7ed6a254/src/index.js
|
|
10
|
-
|
|
11
|
-
export const babelPluginInstrument = (api, options) => {
|
|
12
|
-
const { programVisitor } = require("istanbul-lib-instrument")
|
|
13
|
-
|
|
14
|
-
const { types } = api
|
|
15
|
-
const {
|
|
16
|
-
useInlineSourceMaps = false,
|
|
17
|
-
projectDirectoryUrl,
|
|
18
|
-
coverageConfig = { "./**/*": true },
|
|
19
|
-
} = options
|
|
20
|
-
|
|
21
|
-
const structuredMetaMapForCover = normalizeStructuredMetaMap(
|
|
22
|
-
{
|
|
23
|
-
cover: coverageConfig,
|
|
24
|
-
},
|
|
25
|
-
projectDirectoryUrl,
|
|
26
|
-
)
|
|
27
|
-
const shouldInstrument = (relativeUrl) => {
|
|
28
|
-
return urlToMeta({
|
|
29
|
-
url: resolveUrl(relativeUrl, projectDirectoryUrl),
|
|
30
|
-
structuredMetaMap: structuredMetaMapForCover,
|
|
31
|
-
}).cover
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
name: "transform-instrument",
|
|
36
|
-
visitor: {
|
|
37
|
-
Program: {
|
|
38
|
-
enter(path) {
|
|
39
|
-
const { file } = this
|
|
40
|
-
const { opts } = file
|
|
41
|
-
|
|
42
|
-
const relativeUrl = optionsToRelativeUrl(opts)
|
|
43
|
-
if (!relativeUrl) {
|
|
44
|
-
console.warn("file without relativeUrl", relativeUrl)
|
|
45
|
-
return
|
|
46
|
-
}
|
|
47
|
-
if (!shouldInstrument(relativeUrl)) return
|
|
48
|
-
|
|
49
|
-
this.__dv__ = null
|
|
50
|
-
|
|
51
|
-
let inputSourceMap
|
|
52
|
-
|
|
53
|
-
if (useInlineSourceMaps) {
|
|
54
|
-
// https://github.com/istanbuljs/babel-plugin-istanbul/commit/a9e15643d249a2985e4387e4308022053b2cd0ad#diff-1fdf421c05c1140f6d71444ea2b27638R65
|
|
55
|
-
inputSourceMap =
|
|
56
|
-
opts.inputSourceMap || file.inputMap
|
|
57
|
-
? file.inputMap.sourcemap
|
|
58
|
-
: null
|
|
59
|
-
} else {
|
|
60
|
-
inputSourceMap = opts.inputSourceMap
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
this.__dv__ = programVisitor(
|
|
64
|
-
types,
|
|
65
|
-
opts.filenameRelative || opts.filename,
|
|
66
|
-
{
|
|
67
|
-
coverageVariable: "__coverage__",
|
|
68
|
-
inputSourceMap,
|
|
69
|
-
},
|
|
70
|
-
)
|
|
71
|
-
this.__dv__.enter(path)
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
exit(path) {
|
|
75
|
-
if (!this.__dv__) {
|
|
76
|
-
return
|
|
77
|
-
}
|
|
78
|
-
const object = this.__dv__.exit(path)
|
|
79
|
-
// object got two properties: fileCoverage and sourceMappingURL
|
|
80
|
-
this.file.metadata.coverage = object.fileCoverage
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const optionsToRelativeUrl = ({ filenameRelative }) => {
|
|
88
|
-
if (filenameRelative) return filenameRelative
|
|
89
|
-
return ""
|
|
90
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
resolveUrl,
|
|
3
|
+
normalizeStructuredMetaMap,
|
|
4
|
+
urlToMeta,
|
|
5
|
+
} from "@jsenv/filesystem"
|
|
6
|
+
|
|
7
|
+
import { require } from "../../require.js"
|
|
8
|
+
|
|
9
|
+
// https://github.com/istanbuljs/babel-plugin-istanbul/blob/321740f7b25d803f881466ea819d870f7ed6a254/src/index.js
|
|
10
|
+
|
|
11
|
+
export const babelPluginInstrument = (api, options) => {
|
|
12
|
+
const { programVisitor } = require("istanbul-lib-instrument")
|
|
13
|
+
|
|
14
|
+
const { types } = api
|
|
15
|
+
const {
|
|
16
|
+
useInlineSourceMaps = false,
|
|
17
|
+
projectDirectoryUrl,
|
|
18
|
+
coverageConfig = { "./**/*": true },
|
|
19
|
+
} = options
|
|
20
|
+
|
|
21
|
+
const structuredMetaMapForCover = normalizeStructuredMetaMap(
|
|
22
|
+
{
|
|
23
|
+
cover: coverageConfig,
|
|
24
|
+
},
|
|
25
|
+
projectDirectoryUrl,
|
|
26
|
+
)
|
|
27
|
+
const shouldInstrument = (relativeUrl) => {
|
|
28
|
+
return urlToMeta({
|
|
29
|
+
url: resolveUrl(relativeUrl, projectDirectoryUrl),
|
|
30
|
+
structuredMetaMap: structuredMetaMapForCover,
|
|
31
|
+
}).cover
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
name: "transform-instrument",
|
|
36
|
+
visitor: {
|
|
37
|
+
Program: {
|
|
38
|
+
enter(path) {
|
|
39
|
+
const { file } = this
|
|
40
|
+
const { opts } = file
|
|
41
|
+
|
|
42
|
+
const relativeUrl = optionsToRelativeUrl(opts)
|
|
43
|
+
if (!relativeUrl) {
|
|
44
|
+
console.warn("file without relativeUrl", relativeUrl)
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
if (!shouldInstrument(relativeUrl)) return
|
|
48
|
+
|
|
49
|
+
this.__dv__ = null
|
|
50
|
+
|
|
51
|
+
let inputSourceMap
|
|
52
|
+
|
|
53
|
+
if (useInlineSourceMaps) {
|
|
54
|
+
// https://github.com/istanbuljs/babel-plugin-istanbul/commit/a9e15643d249a2985e4387e4308022053b2cd0ad#diff-1fdf421c05c1140f6d71444ea2b27638R65
|
|
55
|
+
inputSourceMap =
|
|
56
|
+
opts.inputSourceMap || file.inputMap
|
|
57
|
+
? file.inputMap.sourcemap
|
|
58
|
+
: null
|
|
59
|
+
} else {
|
|
60
|
+
inputSourceMap = opts.inputSourceMap
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
this.__dv__ = programVisitor(
|
|
64
|
+
types,
|
|
65
|
+
opts.filenameRelative || opts.filename,
|
|
66
|
+
{
|
|
67
|
+
coverageVariable: "__coverage__",
|
|
68
|
+
inputSourceMap,
|
|
69
|
+
},
|
|
70
|
+
)
|
|
71
|
+
this.__dv__.enter(path)
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
exit(path) {
|
|
75
|
+
if (!this.__dv__) {
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
const object = this.__dv__.exit(path)
|
|
79
|
+
// object got two properties: fileCoverage and sourceMappingURL
|
|
80
|
+
this.file.metadata.coverage = object.fileCoverage
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const optionsToRelativeUrl = ({ filenameRelative }) => {
|
|
88
|
+
if (filenameRelative) return filenameRelative
|
|
89
|
+
return ""
|
|
90
|
+
}
|