@jsenv/plugin-bundling 1.0.4 → 1.1.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": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,13 +24,13 @@
24
24
  "test": "node --conditions=development ./scripts/test.mjs"
25
25
  },
26
26
  "dependencies": {
27
- "@jsenv/ast": "1.4.10",
28
27
  "@jsenv/babel-plugins": "1.1.2",
29
28
  "@jsenv/log": "3.3.3",
30
29
  "@jsenv/url-meta": "7.0.2",
31
30
  "@jsenv/urls": "1.2.8",
32
31
  "@jsenv/sourcemap": "1.0.8",
33
32
  "acorn-import-assertions": "1.8.0",
33
+ "lightningcss": "1.18.0",
34
34
  "rollup": "3.9.1"
35
35
  },
36
36
  "peerDependencies": {
@@ -0,0 +1,56 @@
1
+ import { fileURLToPath, pathToFileURL } from "node:url"
2
+
3
+ // Do not use until https://github.com/parcel-bundler/parcel-css/issues/181
4
+ export const bundleCss = async ({ cssUrlInfos, context }) => {
5
+ const bundledCssUrlInfos = {}
6
+ const { bundleAsync } = await import("lightningcss")
7
+ const targets = runtimeCompatToTargets(context.runtimeCompat)
8
+ for (const cssUrlInfo of cssUrlInfos) {
9
+ const { code, map } = await bundleAsync({
10
+ filename: fileURLToPath(cssUrlInfo.originalUrl),
11
+ targets,
12
+ minify: false,
13
+ resolver: {
14
+ read: (specifier) => {
15
+ const fileUrlObject = pathToFileURL(specifier)
16
+ const fileUrl = String(fileUrlObject)
17
+ const urlInfo = context.urlGraph.getUrlInfo(fileUrl)
18
+ return urlInfo.content
19
+ },
20
+ resolve(specifier, from) {
21
+ const fileUrlObject = new URL(specifier, pathToFileURL(from))
22
+ const filePath = fileURLToPath(fileUrlObject)
23
+ return filePath
24
+ },
25
+ },
26
+ })
27
+ bundledCssUrlInfos[cssUrlInfo.url] = {
28
+ data: {
29
+ bundlerName: "lightningcss",
30
+ },
31
+ contentType: "text/css",
32
+ content: String(code),
33
+ sourcemap: map,
34
+ }
35
+ }
36
+ return bundledCssUrlInfos
37
+ }
38
+
39
+ const runtimeCompatToTargets = (runtimeCompat) => {
40
+ const targets = {}
41
+ ;["chrome", "firefox", "ie", "opera", "safari"].forEach((runtimeName) => {
42
+ const version = runtimeCompat[runtimeName]
43
+ if (version) {
44
+ targets[runtimeName] = versionToBits(version)
45
+ }
46
+ })
47
+ return targets
48
+ }
49
+
50
+ const versionToBits = (version) => {
51
+ const [major, minor = 0, patch = 0] = version
52
+ .split("-")[0]
53
+ .split(".")
54
+ .map((v) => parseInt(v, 10))
55
+ return (major << 16) | (minor << 8) | patch
56
+ }
@@ -11,7 +11,6 @@ import { applyPostCss, postCssPluginUrlVisitor } from "@jsenv/ast"
11
11
 
12
12
  import { sortByDependencies } from "./sort_by_dependencies.js"
13
13
 
14
- // Do not use until https://github.com/parcel-bundler/parcel-css/issues/181
15
14
  export const bundleCss = async ({ cssUrlInfos, context }) => {
16
15
  const bundledCssUrlInfos = {}
17
16
  const cssBundleInfos = await performCssBundling({
@@ -21,7 +20,7 @@ export const bundleCss = async ({ cssUrlInfos, context }) => {
21
20
  cssUrlInfos.forEach((cssUrlInfo) => {
22
21
  bundledCssUrlInfos[cssUrlInfo.url] = {
23
22
  data: {
24
- bundlerName: "parcel",
23
+ bundlerName: "postcss",
25
24
  },
26
25
  contentType: "text/css",
27
26
  content: cssBundleInfos[cssUrlInfo.url].bundleContent,
@@ -1,4 +1,4 @@
1
- import { bundleCss } from "./css/bundle_css.js"
1
+ import { bundleCss } from "./css/css_bundling_lightning_css.js"
2
2
  import { bundleJsClassicWorkers } from "./js_classic_workers/bundle_js_classic_workers.js"
3
3
  import { bundleJsModules } from "./js_module/bundle_js_modules.js"
4
4