@jsenv/plugin-bundling 1.2.0 → 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.2.0",
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.3",
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 { babelHelperNameFromUrl } from "@jsenv/babel-plugins"
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 urlInfo = urlGraph.getUrlInfo(pathToFileURL(warning.id).href)
69
- if (urlInfo && urlInfo.data.isBabelClientFile) {
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
 
@@ -227,8 +279,6 @@ const rollupPluginJsenv = ({
227
279
  },
228
280
  outputOptions: (outputOptions) => {
229
281
  // const sourcemapFile = buildDirectoryUrl
230
- const { manualChunks } = outputOptions
231
-
232
282
  Object.assign(outputOptions, {
233
283
  format,
234
284
  dir: fileUrlConverter.asFilePath(buildDirectoryUrl),
@@ -259,32 +309,6 @@ const rollupPluginJsenv = ({
259
309
  const name = nameFromUrlInfo || `${chunkInfo.name}.js`
260
310
  return insideJs ? `${assetsDirectory}js/${name}` : `${name}`
261
311
  },
262
- manualChunks: (id) => {
263
- if (manualChunks) {
264
- const chunkId = manualChunks(id)
265
- if (chunkId) {
266
- return chunkId
267
- }
268
- }
269
- if (babelHelpersChunk) {
270
- const fileUrl = fileUrlConverter.asFileUrl(id)
271
- if (
272
- fileUrl.endsWith(
273
- "babel-plugin-transform-async-to-promises/helpers.mjs",
274
- )
275
- ) {
276
- return "babel_helpers"
277
- }
278
- if (babelHelperNameFromUrl(fileUrl)) {
279
- return "babel_helpers"
280
- }
281
- const urlInfo = urlGraph.getUrlInfo(fileUrl)
282
- if (urlInfo && urlInfo.data.isBabelClientFile) {
283
- return "babel_helpers"
284
- }
285
- }
286
- return null
287
- },
288
312
  // https://rollupjs.org/guide/en/#outputpaths
289
313
  // paths: (id) => {
290
314
  // return id