@jsenv/core 30.0.7 → 30.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/dist/main.js CHANGED
@@ -16,7 +16,7 @@ import { Readable, Stream, Writable } from "node:stream";
16
16
  import { Http2ServerResponse } from "node:http2";
17
17
  import { lookup } from "node:dns";
18
18
  import { SOURCEMAP, generateSourcemapFileUrl, composeTwoSourcemaps, generateSourcemapDataUrl, createMagicSource, getOriginalPosition } from "@jsenv/sourcemap";
19
- import { parseHtmlString, stringifyHtmlAst, getHtmlNodeAttribute, visitHtmlNodes, analyzeScriptNode, setHtmlNodeAttributes, parseSrcSet, getHtmlNodePosition, getHtmlNodeAttributePosition, applyPostCss, postCssPluginUrlVisitor, parseJsUrls, getHtmlNodeText, setHtmlNodeText, applyBabelPlugins, injectScriptNodeAsEarlyAsPossible, createHtmlNode, findHtmlNode, removeHtmlNode, removeHtmlNodeText, transpileWithParcel, injectJsImport, analyzeLinkNode, injectHtmlNode, insertHtmlNodeAfter } from "@jsenv/ast";
19
+ import { parseHtmlString, stringifyHtmlAst, getHtmlNodeAttribute, visitHtmlNodes, analyzeScriptNode, setHtmlNodeAttributes, parseSrcSet, getHtmlNodePosition, getHtmlNodeAttributePosition, applyPostCss, postCssPluginUrlVisitor, parseJsUrls, getHtmlNodeText, setHtmlNodeText, applyBabelPlugins, injectScriptNodeAsEarlyAsPossible, createHtmlNode, findHtmlNode, removeHtmlNode, removeHtmlNodeText, injectJsImport, analyzeLinkNode, injectHtmlNode, insertHtmlNodeAfter } from "@jsenv/ast";
20
20
  import { createRequire } from "node:module";
21
21
  import babelParser from "@babel/parser";
22
22
  import { bundleJsModules } from "@jsenv/plugin-bundling";
@@ -17750,17 +17750,16 @@ const babelPluginMetadataImportMetaScenarios = () => {
17750
17750
  };
17751
17751
  };
17752
17752
 
17753
- // https://github.com/parcel-bundler/parcel-css
17754
- const jsenvPluginCssParcel = () => {
17753
+ const jsenvPluginCssTranspilation = () => {
17755
17754
  return {
17756
- name: "jsenv:css_parcel",
17755
+ name: "jsenv:css_transpilation",
17757
17756
  appliesDuring: "*",
17758
17757
  transformUrlContent: {
17759
- css: (urlInfo, context) => {
17758
+ css: async (urlInfo, context) => {
17760
17759
  const {
17761
17760
  code,
17762
17761
  map
17763
- } = transpileWithParcel(urlInfo, context);
17762
+ } = await transpileCss(urlInfo, context);
17764
17763
  return {
17765
17764
  content: String(code),
17766
17765
  sourcemap: map
@@ -17769,6 +17768,44 @@ const jsenvPluginCssParcel = () => {
17769
17768
  }
17770
17769
  };
17771
17770
  };
17771
+ const transpileCss = async (urlInfo, context) => {
17772
+ // https://lightningcss.dev/docs.html
17773
+ const {
17774
+ transform
17775
+ } = await import("lightningcss");
17776
+ const targets = runtimeCompatToTargets(context.runtimeCompat);
17777
+ const {
17778
+ code,
17779
+ map
17780
+ } = transform({
17781
+ filename: fileURLToPath(urlInfo.originalUrl),
17782
+ code: Buffer.from(urlInfo.content),
17783
+ targets,
17784
+ minify: false,
17785
+ drafts: {
17786
+ nesting: true,
17787
+ customMedia: true
17788
+ }
17789
+ });
17790
+ return {
17791
+ code,
17792
+ map
17793
+ };
17794
+ };
17795
+ const runtimeCompatToTargets = runtimeCompat => {
17796
+ const targets = {};
17797
+ ["chrome", "firefox", "ie", "opera", "safari"].forEach(runtimeName => {
17798
+ const version = runtimeCompat[runtimeName];
17799
+ if (version) {
17800
+ targets[runtimeName] = versionToBits(version);
17801
+ }
17802
+ });
17803
+ return targets;
17804
+ };
17805
+ const versionToBits = version => {
17806
+ const [major, minor = 0, patch = 0] = version.split("-")[0].split(".").map(v => parseInt(v, 10));
17807
+ return major << 16 | minor << 8 | patch;
17808
+ };
17772
17809
 
17773
17810
  /*
17774
17811
  * Jsenv wont touch code where "specifier" or "type" is dynamic (see code below)
@@ -19206,7 +19243,7 @@ const jsenvPluginTranspilation = ({
19206
19243
  }), jsenvPluginAsJsModule(),
19207
19244
  // topLevelAwait must come after jsenvPluginAsJsClassic because it's related to the module format
19208
19245
  // so we want to wait to know the module format before transforming things related to top level await
19209
- ...(topLevelAwait ? [jsenvPluginTopLevelAwait()] : []), ...(css ? [jsenvPluginCssParcel()] : [])];
19246
+ ...(topLevelAwait ? [jsenvPluginTopLevelAwait()] : []), ...(css ? [jsenvPluginCssTranspilation()] : [])];
19210
19247
  };
19211
19248
 
19212
19249
  const jsenvPluginNodeRuntime = ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "30.0.7",
3
+ "version": "30.1.0",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -67,9 +67,9 @@
67
67
  "@c88/v8-coverage": "0.1.1",
68
68
  "@financial-times/polyfill-useragent-normaliser": "1.10.2",
69
69
  "@jsenv/abort": "4.2.4",
70
- "@jsenv/ast": "1.4.10",
70
+ "@jsenv/ast": "2.0.0",
71
71
  "@jsenv/babel-plugins": "1.1.2",
72
- "@jsenv/plugin-bundling": "1.0.4",
72
+ "@jsenv/plugin-bundling": "1.0.5",
73
73
  "@jsenv/filesystem": "4.1.9",
74
74
  "@jsenv/importmap": "1.2.1",
75
75
  "@jsenv/integrity": "0.0.1",
@@ -88,6 +88,7 @@
88
88
  "istanbul-lib-report": "3.0.0",
89
89
  "istanbul-reports": "3.1.5",
90
90
  "launch-editor": "2.6.0",
91
+ "lightningcss": "1.18.0",
91
92
  "pidtree": "0.6.0",
92
93
  "string-width": "5.1.2",
93
94
  "strip-ansi": "7.0.1",
@@ -0,0 +1,54 @@
1
+ import { fileURLToPath } from "node:url"
2
+
3
+ export const jsenvPluginCssTranspilation = () => {
4
+ return {
5
+ name: "jsenv:css_transpilation",
6
+ appliesDuring: "*",
7
+ transformUrlContent: {
8
+ css: async (urlInfo, context) => {
9
+ const { code, map } = await transpileCss(urlInfo, context)
10
+ return {
11
+ content: String(code),
12
+ sourcemap: map,
13
+ }
14
+ },
15
+ },
16
+ }
17
+ }
18
+
19
+ const transpileCss = async (urlInfo, context) => {
20
+ // https://lightningcss.dev/docs.html
21
+ const { transform } = await import("lightningcss")
22
+
23
+ const targets = runtimeCompatToTargets(context.runtimeCompat)
24
+ const { code, map } = transform({
25
+ filename: fileURLToPath(urlInfo.originalUrl),
26
+ code: Buffer.from(urlInfo.content),
27
+ targets,
28
+ minify: false,
29
+ drafts: {
30
+ nesting: true,
31
+ customMedia: true,
32
+ },
33
+ })
34
+ return { code, map }
35
+ }
36
+
37
+ const runtimeCompatToTargets = (runtimeCompat) => {
38
+ const targets = {}
39
+ ;["chrome", "firefox", "ie", "opera", "safari"].forEach((runtimeName) => {
40
+ const version = runtimeCompat[runtimeName]
41
+ if (version) {
42
+ targets[runtimeName] = versionToBits(version)
43
+ }
44
+ })
45
+ return targets
46
+ }
47
+
48
+ const versionToBits = (version) => {
49
+ const [major, minor = 0, patch = 0] = version
50
+ .split("-")[0]
51
+ .split(".")
52
+ .map((v) => parseInt(v, 10))
53
+ return (major << 16) | (minor << 8) | patch
54
+ }
@@ -7,7 +7,7 @@
7
7
  * of this plugin
8
8
  */
9
9
 
10
- import { jsenvPluginCssParcel } from "./css_parcel/jsenv_plugin_css_parcel.js"
10
+ import { jsenvPluginCssTranspilation } from "./css/jsenv_plugin_css_transpilation.js"
11
11
  import { jsenvPluginImportAssertions } from "./import_assertions/jsenv_plugin_import_assertions.js"
12
12
  import { jsenvPluginAsJsClassic } from "./as_js_classic/jsenv_plugin_as_js_classic.js"
13
13
  import { jsenvPluginAsJsModule } from "./as_js_module/jsenv_plugin_as_js_module.js"
@@ -52,6 +52,6 @@ export const jsenvPluginTranspilation = ({
52
52
  // topLevelAwait must come after jsenvPluginAsJsClassic because it's related to the module format
53
53
  // so we want to wait to know the module format before transforming things related to top level await
54
54
  ...(topLevelAwait ? [jsenvPluginTopLevelAwait(topLevelAwait)] : []),
55
- ...(css ? [jsenvPluginCssParcel()] : []),
55
+ ...(css ? [jsenvPluginCssTranspilation()] : []),
56
56
  ]
57
57
  }
@@ -1,18 +0,0 @@
1
- import { transpileWithParcel } from "@jsenv/ast"
2
-
3
- // https://github.com/parcel-bundler/parcel-css
4
- export const jsenvPluginCssParcel = () => {
5
- return {
6
- name: "jsenv:css_parcel",
7
- appliesDuring: "*",
8
- transformUrlContent: {
9
- css: (urlInfo, context) => {
10
- const { code, map } = transpileWithParcel(urlInfo, context)
11
- return {
12
- content: String(code),
13
- sourcemap: map,
14
- }
15
- },
16
- },
17
- }
18
- }