@jsenv/plugin-bundling 1.1.2 → 1.2.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/plugin-bundling",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"test": "node --conditions=development ./scripts/test.mjs"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@jsenv/babel-plugins": "1.1.
|
|
27
|
+
"@jsenv/babel-plugins": "1.1.4",
|
|
28
28
|
"@jsenv/log": "3.3.3",
|
|
29
29
|
"@jsenv/url-meta": "7.0.2",
|
|
30
30
|
"@jsenv/urls": "1.2.8",
|
|
@@ -3,8 +3,11 @@ import { pathToFileURL } from "node:url"
|
|
|
3
3
|
import { URL_META } from "@jsenv/url-meta"
|
|
4
4
|
import { isFileSystemPath } from "@jsenv/urls"
|
|
5
5
|
import { createDetailedMessage } from "@jsenv/log"
|
|
6
|
-
import {
|
|
6
|
+
import { babelHelperClientDirectoryUrl } from "@jsenv/babel-plugins"
|
|
7
7
|
import { sourcemapConverter } from "@jsenv/sourcemap"
|
|
8
|
+
import { newStylesheetClientFileUrl } from "@jsenv/core/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js"
|
|
9
|
+
import { globalThisClientFileUrl } from "@jsenv/core/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js"
|
|
10
|
+
import { regeneratorRuntimeClientFileUrl } from "@jsenv/core/src/plugins/transpilation/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js"
|
|
8
11
|
|
|
9
12
|
import { fileUrlConverter } from "./file_url_converter.js"
|
|
10
13
|
|
|
@@ -24,7 +27,9 @@ export const bundleJsModules = async ({
|
|
|
24
27
|
sourcemaps,
|
|
25
28
|
} = context
|
|
26
29
|
const {
|
|
30
|
+
vendorsChunk = true,
|
|
27
31
|
babelHelpersChunk = true,
|
|
32
|
+
customChunks = {},
|
|
28
33
|
include,
|
|
29
34
|
preserveDynamicImport = false,
|
|
30
35
|
strictExports = false,
|
|
@@ -34,6 +39,54 @@ export const bundleJsModules = async ({
|
|
|
34
39
|
rollupPlugins = [],
|
|
35
40
|
} = options
|
|
36
41
|
|
|
42
|
+
const chunksAssociations = {
|
|
43
|
+
...(vendorsChunk
|
|
44
|
+
? {
|
|
45
|
+
vendors: {
|
|
46
|
+
"./**/node_modules/": true,
|
|
47
|
+
[newStylesheetClientFileUrl]: true,
|
|
48
|
+
[globalThisClientFileUrl]: true,
|
|
49
|
+
[regeneratorRuntimeClientFileUrl]: true,
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
: {}),
|
|
53
|
+
...(babelHelpersChunk
|
|
54
|
+
? {
|
|
55
|
+
babel_helpers: {
|
|
56
|
+
[babelHelperClientDirectoryUrl]: true,
|
|
57
|
+
[newStylesheetClientFileUrl]: true,
|
|
58
|
+
[globalThisClientFileUrl]: true,
|
|
59
|
+
[regeneratorRuntimeClientFileUrl]: true,
|
|
60
|
+
"./**/babel-plugin-transform-async-to-promises/helpers.mjs": true,
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
: {}),
|
|
64
|
+
...customChunks,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let manualChunks
|
|
68
|
+
if (
|
|
69
|
+
typeof customChunks === "object" &&
|
|
70
|
+
Object.keys(chunksAssociations).length
|
|
71
|
+
) {
|
|
72
|
+
const associations = URL_META.resolveAssociations(
|
|
73
|
+
chunksAssociations,
|
|
74
|
+
rootDirectoryUrl,
|
|
75
|
+
)
|
|
76
|
+
manualChunks = (id) => {
|
|
77
|
+
if (rollupOutput.manualChunks) {
|
|
78
|
+
const manualChunkName = rollupOutput.manualChunks(id)
|
|
79
|
+
if (manualChunkName) {
|
|
80
|
+
return manualChunkName
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const url = fileUrlConverter.asFileUrl(id)
|
|
84
|
+
const meta = URL_META.applyAssociations({ url, associations })
|
|
85
|
+
const chunkName = Object.keys(meta).find((key) => meta[key])
|
|
86
|
+
return chunkName || null
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
37
90
|
const resultRef = { current: null }
|
|
38
91
|
try {
|
|
39
92
|
await applyRollupPlugins({
|
|
@@ -52,7 +105,6 @@ export const bundleJsModules = async ({
|
|
|
52
105
|
runtimeCompat,
|
|
53
106
|
sourcemaps,
|
|
54
107
|
include,
|
|
55
|
-
babelHelpersChunk,
|
|
56
108
|
preserveDynamicImport,
|
|
57
109
|
strictExports,
|
|
58
110
|
resultRef,
|
|
@@ -65,8 +117,8 @@ export const bundleJsModules = async ({
|
|
|
65
117
|
return
|
|
66
118
|
}
|
|
67
119
|
if (warning.code === "THIS_IS_UNDEFINED") {
|
|
68
|
-
const
|
|
69
|
-
if (
|
|
120
|
+
const fileUrl = pathToFileURL(warning.id).href
|
|
121
|
+
if (fileUrl === globalThisClientFileUrl) {
|
|
70
122
|
return
|
|
71
123
|
}
|
|
72
124
|
}
|
|
@@ -92,6 +144,7 @@ export const bundleJsModules = async ({
|
|
|
92
144
|
symbols: context.isSupportedOnCurrentClients("symbols"),
|
|
93
145
|
},
|
|
94
146
|
...rollupOutput,
|
|
147
|
+
manualChunks,
|
|
95
148
|
},
|
|
96
149
|
})
|
|
97
150
|
return resultRef.current.jsModuleBundleUrlInfos
|
|
@@ -116,7 +169,6 @@ const rollupPluginJsenv = ({
|
|
|
116
169
|
sourcemaps,
|
|
117
170
|
|
|
118
171
|
include,
|
|
119
|
-
babelHelpersChunk,
|
|
120
172
|
preserveDynamicImport,
|
|
121
173
|
strictExports,
|
|
122
174
|
|
|
@@ -257,26 +309,6 @@ const rollupPluginJsenv = ({
|
|
|
257
309
|
const name = nameFromUrlInfo || `${chunkInfo.name}.js`
|
|
258
310
|
return insideJs ? `${assetsDirectory}js/${name}` : `${name}`
|
|
259
311
|
},
|
|
260
|
-
manualChunks: (id) => {
|
|
261
|
-
if (babelHelpersChunk) {
|
|
262
|
-
const fileUrl = fileUrlConverter.asFileUrl(id)
|
|
263
|
-
if (
|
|
264
|
-
fileUrl.endsWith(
|
|
265
|
-
"babel-plugin-transform-async-to-promises/helpers.mjs",
|
|
266
|
-
)
|
|
267
|
-
) {
|
|
268
|
-
return "babel_helpers"
|
|
269
|
-
}
|
|
270
|
-
if (babelHelperNameFromUrl(fileUrl)) {
|
|
271
|
-
return "babel_helpers"
|
|
272
|
-
}
|
|
273
|
-
const urlInfo = urlGraph.getUrlInfo(fileUrl)
|
|
274
|
-
if (urlInfo && urlInfo.data.isBabelClientFile) {
|
|
275
|
-
return "babel_helpers"
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return null
|
|
279
|
-
},
|
|
280
312
|
// https://rollupjs.org/guide/en/#outputpaths
|
|
281
313
|
// paths: (id) => {
|
|
282
314
|
// return id
|