@jsenv/plugin-bundling 2.2.1 → 2.3.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-bundling",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,11 +26,11 @@
26
26
  "dependencies": {
27
27
  "@jsenv/log": "3.4.0",
28
28
  "@jsenv/url-meta": "8.1.0",
29
- "@jsenv/urls": "2.0.0",
30
- "@jsenv/sourcemap": "1.0.10",
29
+ "@jsenv/urls": "2.1.0",
30
+ "@jsenv/sourcemap": "1.1.0",
31
31
  "acorn-import-assertions": "1.9.0",
32
- "lightningcss": "1.21.0",
33
- "rollup": "3.24.0"
32
+ "lightningcss": "1.21.5",
33
+ "rollup": "3.26.2"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@jsenv/core": "*"
@@ -2,10 +2,10 @@ import { fileURLToPath, pathToFileURL } from "node:url";
2
2
  import { fileUrlConverter } from "../file_url_converter.js";
3
3
 
4
4
  // Do not use until https://github.com/parcel-bundler/parcel-css/issues/181
5
- export const bundleCss = async ({ cssUrlInfos, context }) => {
5
+ export const bundleCss = async (cssUrlInfos) => {
6
6
  const bundledCssUrlInfos = {};
7
7
  const { bundleAsync } = await import("lightningcss");
8
- const targets = runtimeCompatToTargets(context.runtimeCompat);
8
+ const targets = runtimeCompatToTargets(cssUrlInfos[0].context.runtimeCompat);
9
9
  for (const cssUrlInfo of cssUrlInfos) {
10
10
  const filename = fileUrlConverter.asFilePath(cssUrlInfo.originalUrl);
11
11
  const { code, map } = await bundleAsync({
@@ -16,7 +16,7 @@ export const bundleCss = async ({ cssUrlInfos, context }) => {
16
16
  read: (specifier) => {
17
17
  const fileUrlObject = fileUrlConverter.asFileUrl(specifier);
18
18
  const fileUrl = String(fileUrlObject);
19
- const urlInfo = context.urlGraph.getUrlInfo(fileUrl);
19
+ const urlInfo = cssUrlInfo.graph.getUrlInfo(fileUrl);
20
20
  return urlInfo.content;
21
21
  },
22
22
  resolve(specifier, from) {
@@ -5,29 +5,35 @@ import { sourcemapConverter } from "@jsenv/sourcemap";
5
5
 
6
6
  import { fileUrlConverter } from "../file_url_converter.js";
7
7
 
8
- export const bundleJsModules = async ({
8
+ export const bundleJsModules = async (
9
9
  jsModuleUrlInfos,
10
- context,
11
- include,
12
- chunks = {},
13
- strictExports = false,
14
- preserveDynamicImport = false,
15
- augmentDynamicImportUrlSearchParams = () => {},
16
- rollup,
17
- rollupInput = {},
18
- rollupOutput = {},
19
- rollupPlugins = [],
20
- }) => {
10
+ {
11
+ buildDirectoryUrl,
12
+ include,
13
+ chunks = {},
14
+ strictExports = false,
15
+ preserveDynamicImport = false,
16
+ augmentDynamicImportUrlSearchParams = () => {},
17
+ rollup,
18
+ rollupInput = {},
19
+ rollupOutput = {},
20
+ rollupPlugins = [],
21
+ },
22
+ ) => {
21
23
  const {
22
24
  signal,
23
25
  logger,
24
26
  rootDirectoryUrl,
25
- buildDirectoryUrl,
26
27
  assetsDirectory,
27
- urlGraph,
28
28
  runtimeCompat,
29
29
  sourcemaps,
30
- } = context;
30
+ minification,
31
+ isSupportedOnCurrentClients,
32
+ } = jsModuleUrlInfos[0].context;
33
+ const graph = jsModuleUrlInfos[0].graph;
34
+ if (buildDirectoryUrl === undefined) {
35
+ buildDirectoryUrl = jsModuleUrlInfos[0].context.buildDirectoryUrl;
36
+ }
31
37
 
32
38
  let manualChunks;
33
39
  if (Object.keys(chunks).length) {
@@ -64,7 +70,7 @@ export const bundleJsModules = async ({
64
70
  rootDirectoryUrl,
65
71
  buildDirectoryUrl,
66
72
  assetsDirectory,
67
- urlGraph,
73
+ graph,
68
74
  jsModuleUrlInfos,
69
75
 
70
76
  runtimeCompat,
@@ -91,17 +97,16 @@ export const bundleJsModules = async ({
91
97
  ...rollupInput,
92
98
  },
93
99
  rollupOutput: {
94
- compact: context.minification,
95
- minifyInternalExports: context.minification,
100
+ compact: minification,
101
+ minifyInternalExports: minification,
96
102
  generatedCode: {
97
- arrowFunctions: context.isSupportedOnCurrentClients("arrow_function"),
98
- constBindings: context.isSupportedOnCurrentClients("const_bindings"),
99
- objectShorthand: context.isSupportedOnCurrentClients(
103
+ arrowFunctions: isSupportedOnCurrentClients("arrow_function"),
104
+ constBindings: isSupportedOnCurrentClients("const_bindings"),
105
+ objectShorthand: isSupportedOnCurrentClients(
100
106
  "object_properties_shorthand",
101
107
  ),
102
- reservedNamesAsProps:
103
- context.isSupportedOnCurrentClients("reserved_words"),
104
- symbols: context.isSupportedOnCurrentClients("symbols"),
108
+ reservedNamesAsProps: isSupportedOnCurrentClients("reserved_words"),
109
+ symbols: isSupportedOnCurrentClients("symbols"),
105
110
  },
106
111
  ...rollupOutput,
107
112
  manualChunks,
@@ -124,7 +129,7 @@ const rollupPluginJsenv = ({
124
129
  rootDirectoryUrl,
125
130
  buildDirectoryUrl,
126
131
  assetsDirectory,
127
- urlGraph,
132
+ graph,
128
133
  jsModuleUrlInfos,
129
134
  sourcemaps,
130
135
 
@@ -181,7 +186,7 @@ const rollupPluginJsenv = ({
181
186
  : null,
182
187
  preserveSignature: strictExports
183
188
  ? "strict"
184
- : jsModuleUrlInfo.dependents.size < 2
189
+ : jsModuleUrlInfo.referenceFromOthersSet.size < 2
185
190
  ? "allow-extension"
186
191
  : "strict",
187
192
  });
@@ -324,7 +329,7 @@ const rollupPluginJsenv = ({
324
329
  if (!importCanBeBundled(url)) {
325
330
  return { id: url, external: true };
326
331
  }
327
- const urlInfo = urlGraph.getUrlInfo(url);
332
+ const urlInfo = graph.getUrlInfo(url);
328
333
  if (!urlInfo) {
329
334
  // happen when excluded by referenceAnalysis.include
330
335
  return { id: url, external: true };
@@ -337,7 +342,7 @@ const rollupPluginJsenv = ({
337
342
  },
338
343
  async load(rollupId) {
339
344
  const fileUrl = fileUrlConverter.asFileUrl(rollupId);
340
- const urlInfo = urlGraph.getUrlInfo(fileUrl);
345
+ const urlInfo = graph.getUrlInfo(fileUrl);
341
346
  return {
342
347
  code: urlInfo.content,
343
348
  map:
@@ -10,31 +10,21 @@ export const jsenvPluginBundling = ({
10
10
  const bundle = {};
11
11
 
12
12
  if (css) {
13
- bundle.css = (cssUrlInfos, context) => {
14
- return bundleCss({
15
- cssUrlInfos,
16
- context,
17
- });
13
+ bundle.css = (cssUrlInfos) => {
14
+ return bundleCss(cssUrlInfos);
18
15
  };
19
16
  }
20
17
  if (js_classic) {
21
- bundle.js_classic = (jsClassicUrlInfos, context) => {
22
- return bundleJsClassic({
23
- jsClassicUrlInfos,
24
- context,
25
- });
18
+ bundle.js_classic = (jsClassicUrlInfos) => {
19
+ return bundleJsClassic(jsClassicUrlInfos);
26
20
  };
27
21
  }
28
22
  if (js_module) {
29
23
  if (js_module === true) {
30
24
  js_module = {};
31
25
  }
32
- bundle.js_module = (jsModuleUrlInfos, context) => {
33
- return bundleJsModules({
34
- jsModuleUrlInfos,
35
- context,
36
- ...js_module,
37
- });
26
+ bundle.js_module = (jsModuleUrlInfos) => {
27
+ return bundleJsModules(jsModuleUrlInfos, js_module);
38
28
  };
39
29
  }
40
30