@jsenv/core 38.4.19 → 39.0.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/js/ribbon.js CHANGED
@@ -37,26 +37,34 @@ const injectRibbon = ({ text }) => {
37
37
  user-select: none;
38
38
  }
39
39
  `;
40
-
41
40
  const html = /* html */ `<div id="jsenv_ribbon_container">
42
41
  <style>${css}</style>
43
42
  <div id="jsenv_ribbon">
44
43
  <div id="jsenv_ribbon_text">${text}</div>
45
44
  </div>
46
45
  </div>`;
47
-
48
- const node = document.createElement("div");
49
- node.innerHTML = html;
50
-
46
+ class JsenvRibbonHtmlElement extends HTMLElement {
47
+ constructor({ hidden }) {
48
+ super();
49
+ const root = this.attachShadow({ mode: "open" });
50
+ root.innerHTML = html;
51
+ if (hidden) {
52
+ root.style.display = "none";
53
+ }
54
+ }
55
+ }
56
+ if (customElements && !customElements.get("jsenv-ribbon")) {
57
+ customElements.define("jsenv-ribbon", JsenvRibbonHtmlElement);
58
+ }
51
59
  const toolbarStateInLocalStorage = localStorage.hasOwnProperty(
52
60
  "jsenv_toolbar",
53
61
  )
54
62
  ? JSON.parse(localStorage.getItem("jsenv_toolbar"))
55
63
  : {};
56
- if (toolbarStateInLocalStorage.ribbonDisplayed === false) {
57
- node.querySelector("#jsenv_ribbon_container").style.display = "none";
58
- }
59
- document.body.appendChild(node.firstChild);
64
+ const jsenvRibbonElement = new JsenvRibbonHtmlElement({
65
+ hidden: toolbarStateInLocalStorage.ribbonDisplayed === false,
66
+ });
67
+ document.body.appendChild(jsenvRibbonElement);
60
68
  };
61
69
 
62
70
  export { injectRibbon };
@@ -9141,15 +9141,15 @@ const JS_QUOTE_REPLACEMENTS = {
9141
9141
  * ```js
9142
9142
  * const file = "./style.css"
9143
9143
  * const type = "css"
9144
- * import(file, { assert: { type }})
9144
+ * import(file, { with: { type }})
9145
9145
  * ```
9146
9146
  * Jsenv could throw an error when it knows some browsers in runtimeCompat
9147
- * do not support import assertions
9147
+ * do not support import attributes
9148
9148
  * But for now (as it is simpler) we let the browser throw the error
9149
9149
  */
9150
9150
 
9151
9151
 
9152
- const jsenvPluginImportAssertions = ({
9152
+ const jsenvPluginImportAttributes = ({
9153
9153
  json = "auto",
9154
9154
  css = "auto",
9155
9155
  text = "auto",
@@ -9172,17 +9172,17 @@ const jsenvPluginImportAssertions = ({
9172
9172
  } else {
9173
9173
  const { importTypeAttributeNode } = reference.astInfo;
9174
9174
  const content = reference.ownerUrlInfo.content;
9175
- const assertKeyboardStart = content.indexOf(
9176
- "assert",
9177
- importTypeAttributeNode.start - " assert { ".length,
9175
+ const withKeywordStart = content.indexOf(
9176
+ "with",
9177
+ importTypeAttributeNode.start - " with { ".length,
9178
9178
  );
9179
- const assertKeywordEnd = content.indexOf(
9179
+ const withKeywordEnd = content.indexOf(
9180
9180
  "}",
9181
9181
  importTypeAttributeNode.end,
9182
9182
  );
9183
9183
  magicSource.remove({
9184
- start: assertKeyboardStart,
9185
- end: assertKeywordEnd + 1,
9184
+ start: withKeywordStart,
9185
+ end: withKeywordEnd + 1,
9186
9186
  });
9187
9187
  }
9188
9188
  };
@@ -10161,7 +10161,7 @@ const analyzeConstructableStyleSheetUsage = (urlInfo) => {
10161
10161
  // import('./' + moduleName)
10162
10162
  return false;
10163
10163
  }
10164
- if (hasImportTypeCssAssertion(node)) {
10164
+ if (hasImportTypeCssAttribute(node)) {
10165
10165
  return node;
10166
10166
  }
10167
10167
  if (hasCssModuleQueryParam(source)) {
@@ -10174,7 +10174,7 @@ const analyzeConstructableStyleSheetUsage = (urlInfo) => {
10174
10174
  if (hasCssModuleQueryParam(source)) {
10175
10175
  return source;
10176
10176
  }
10177
- if (hasImportTypeCssAssertion(node)) {
10177
+ if (hasImportTypeCssAttribute(node)) {
10178
10178
  return node;
10179
10179
  }
10180
10180
  return false;
@@ -10236,22 +10236,20 @@ const hasCssModuleQueryParam = (node) => {
10236
10236
  );
10237
10237
  };
10238
10238
 
10239
- const hasImportTypeCssAssertion = (node) => {
10240
- const importAssertionsDescriptor = getImportAssertionsDescriptor(
10241
- node.assertions,
10242
- );
10243
- return Boolean(importAssertionsDescriptor.type === "css");
10239
+ const hasImportTypeCssAttribute = (node) => {
10240
+ const importAttributes = getImportAttributes(node);
10241
+ return Boolean(importAttributes.type === "css");
10244
10242
  };
10245
10243
 
10246
- const getImportAssertionsDescriptor = (importAssertions) => {
10247
- const importAssertionsDescriptor = {};
10248
- if (importAssertions) {
10249
- importAssertions.forEach((importAssertion) => {
10250
- importAssertionsDescriptor[importAssertion.key.name] =
10251
- importAssertion.value.value;
10244
+ const getImportAttributes = (importNode) => {
10245
+ const importAttributes = {};
10246
+ if (importNode.attributes) {
10247
+ importNode.attributes.forEach((importAttributeNode) => {
10248
+ importAttributes[importAttributeNode.key.name] =
10249
+ importAttributeNode.value.value;
10252
10250
  });
10253
10251
  }
10254
- return importAssertionsDescriptor;
10252
+ return importAttributes;
10255
10253
  };
10256
10254
 
10257
10255
  const babelPluginNewStylesheetInjector = (
@@ -11111,7 +11109,7 @@ const jsenvPluginCssTranspilation = () => {
11111
11109
 
11112
11110
 
11113
11111
  const jsenvPluginTranspilation = ({
11114
- importAssertions = true,
11112
+ importAttributes = true,
11115
11113
  css = true, // TODO
11116
11114
  // build sets jsModuleFallback: false during first step of the build
11117
11115
  // and re-enable it in the second phase (when performing the bundling)
@@ -11119,8 +11117,8 @@ const jsenvPluginTranspilation = ({
11119
11117
  jsModuleFallback = true,
11120
11118
  babelHelpersAsImport = true,
11121
11119
  }) => {
11122
- if (importAssertions === true) {
11123
- importAssertions = {};
11120
+ if (importAttributes === true) {
11121
+ importAttributes = {};
11124
11122
  }
11125
11123
  if (jsModuleFallback === true) {
11126
11124
  jsModuleFallback = {};
@@ -11132,8 +11130,8 @@ const jsenvPluginTranspilation = ({
11132
11130
  }),
11133
11131
  jsenvPluginAsJsModule(),
11134
11132
  ...(jsModuleFallback ? [jsenvPluginJsModuleFallback()] : []),
11135
- ...(importAssertions
11136
- ? [jsenvPluginImportAssertions(importAssertions)]
11133
+ ...(importAttributes
11134
+ ? [jsenvPluginImportAttributes(importAttributes)]
11137
11135
  : []),
11138
11136
 
11139
11137
  ...(css ? [jsenvPluginCssTranspilation()] : []),
@@ -15928,7 +15926,8 @@ const jsenvPluginHtmlReferenceAnalysis = ({
15928
15926
  line,
15929
15927
  column,
15930
15928
  });
15931
- console.error(`Error while handling ${urlInfo.context.request ? urlInfo.context.request.url : urlInfo.url}:
15929
+ urlInfo.kitchen.context.logger
15930
+ .error(`Error while handling ${urlInfo.context.request ? urlInfo.context.request.url : urlInfo.url}:
15932
15931
  ${e.reasonCode}
15933
15932
  ${urlInfo.url}:${line}:${column}
15934
15933
  ${htmlErrorContentFrame}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "38.4.19",
3
+ "version": "39.0.0",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -64,17 +64,17 @@
64
64
  "dependencies": {
65
65
  "@financial-times/polyfill-useragent-normaliser": "1.10.2",
66
66
  "@jsenv/abort": "4.3.0",
67
- "@jsenv/ast": "6.0.7",
67
+ "@jsenv/ast": "6.1.0",
68
68
  "@jsenv/filesystem": "4.7.2",
69
69
  "@jsenv/humanize": "1.1.3",
70
70
  "@jsenv/importmap": "1.2.1",
71
71
  "@jsenv/integrity": "0.0.1",
72
- "@jsenv/js-module-fallback": "1.3.16",
72
+ "@jsenv/js-module-fallback": "1.3.17",
73
73
  "@jsenv/node-esm-resolution": "1.0.2",
74
74
  "@jsenv/plugin-bundling": "2.6.12",
75
75
  "@jsenv/plugin-minification": "1.5.4",
76
- "@jsenv/plugin-supervisor": "1.4.11",
77
- "@jsenv/plugin-transpilation": "1.3.16",
76
+ "@jsenv/plugin-supervisor": "1.4.12",
77
+ "@jsenv/plugin-transpilation": "1.4.0",
78
78
  "@jsenv/runtime-compat": "1.3.0",
79
79
  "@jsenv/server": "15.2.8",
80
80
  "@jsenv/sourcemap": "1.2.10",
@@ -84,7 +84,7 @@
84
84
  },
85
85
  "devDependencies": {
86
86
  "@babel/eslint-parser": "7.24.7",
87
- "@babel/plugin-syntax-import-assertions": "7.24.7",
87
+ "@babel/plugin-syntax-import-attributes": "7.24.7",
88
88
  "@babel/plugin-syntax-optional-chaining-assign": "7.24.7",
89
89
  "@jsenv/assert": "./packages/independent/assert/",
90
90
  "@jsenv/core": "./",
@@ -151,7 +151,8 @@ export const jsenvPluginHtmlReferenceAnalysis = ({
151
151
  line,
152
152
  column,
153
153
  });
154
- console.error(`Error while handling ${urlInfo.context.request ? urlInfo.context.request.url : urlInfo.url}:
154
+ urlInfo.kitchen.context.logger
155
+ .error(`Error while handling ${urlInfo.context.request ? urlInfo.context.request.url : urlInfo.url}:
155
156
  ${e.reasonCode}
156
157
  ${urlInfo.url}:${line}:${column}
157
158
  ${htmlErrorContentFrame}`);
@@ -37,24 +37,32 @@ export const injectRibbon = ({ text }) => {
37
37
  user-select: none;
38
38
  }
39
39
  `;
40
-
41
40
  const html = /* html */ `<div id="jsenv_ribbon_container">
42
41
  <style>${css}</style>
43
42
  <div id="jsenv_ribbon">
44
43
  <div id="jsenv_ribbon_text">${text}</div>
45
44
  </div>
46
45
  </div>`;
47
-
48
- const node = document.createElement("div");
49
- node.innerHTML = html;
50
-
46
+ class JsenvRibbonHtmlElement extends HTMLElement {
47
+ constructor({ hidden }) {
48
+ super();
49
+ const root = this.attachShadow({ mode: "open" });
50
+ root.innerHTML = html;
51
+ if (hidden) {
52
+ root.style.display = "none";
53
+ }
54
+ }
55
+ }
56
+ if (customElements && !customElements.get("jsenv-ribbon")) {
57
+ customElements.define("jsenv-ribbon", JsenvRibbonHtmlElement);
58
+ }
51
59
  const toolbarStateInLocalStorage = localStorage.hasOwnProperty(
52
60
  "jsenv_toolbar",
53
61
  )
54
62
  ? JSON.parse(localStorage.getItem("jsenv_toolbar"))
55
63
  : {};
56
- if (toolbarStateInLocalStorage.ribbonDisplayed === false) {
57
- node.querySelector("#jsenv_ribbon_container").style.display = "none";
58
- }
59
- document.body.appendChild(node.firstChild);
64
+ const jsenvRibbonElement = new JsenvRibbonHtmlElement({
65
+ hidden: toolbarStateInLocalStorage.ribbonDisplayed === false,
66
+ });
67
+ document.body.appendChild(jsenvRibbonElement);
60
68
  };