@jsenv/plugin-transpilation 1.4.93 → 1.4.95

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-transpilation",
3
- "version": "1.4.93",
3
+ "version": "1.4.95",
4
4
  "description": "TODO",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -51,8 +51,8 @@
51
51
  "@babel/plugin-transform-template-literals": "7.25.9",
52
52
  "@babel/plugin-transform-typeof-symbol": "7.25.9",
53
53
  "@babel/plugin-transform-unicode-regex": "7.25.9",
54
- "@jsenv/ast": "6.5.0",
55
- "@jsenv/js-module-fallback": "1.3.57",
54
+ "@jsenv/ast": "6.5.2",
55
+ "@jsenv/js-module-fallback": "1.3.59",
56
56
  "@jsenv/runtime-compat": "1.3.1",
57
57
  "babel-plugin-transform-async-to-promises": "0.8.18",
58
58
  "construct-style-sheets-polyfill": "3.1.0",
@@ -15,7 +15,7 @@ import { JS_QUOTES } from "@jsenv/utils/src/string/js_quotes.js";
15
15
 
16
16
  export const jsenvPluginImportAttributes = ({
17
17
  json = "auto",
18
- css = "auto",
18
+ css = true,
19
19
  text = "auto",
20
20
  }) => {
21
21
  const transpilations = { json, css, text };
@@ -25,7 +25,11 @@ export const jsenvPluginImportAttributes = ({
25
25
  reference.filenameHint = `${urlToFilename(reference.url)}.js`;
26
26
  }
27
27
  };
28
- const turnIntoJsModuleProxy = (reference, type) => {
28
+ const turnIntoJsModuleProxy = (
29
+ reference,
30
+ type,
31
+ { injectSearchParamForSideEffectImports },
32
+ ) => {
29
33
  reference.mutation = (magicSource) => {
30
34
  if (reference.subtype === "import_dynamic") {
31
35
  const { importTypeAttributeNode } = reference.astInfo;
@@ -52,12 +56,19 @@ export const jsenvPluginImportAttributes = ({
52
56
  };
53
57
  const newUrl = injectQueryParams(reference.url, {
54
58
  [`as_${type}_module`]: "",
59
+ ...(injectSearchParamForSideEffectImports && reference.isSideEffectImport
60
+ ? { side_effect: "" }
61
+ : {}),
55
62
  });
56
63
  markAsJsModuleProxy(reference, type);
57
64
  return newUrl;
58
65
  };
59
66
 
60
- const createImportTypePlugin = ({ type, createUrlContent }) => {
67
+ const createImportTypePlugin = ({
68
+ type,
69
+ createUrlContent,
70
+ injectSearchParamForSideEffectImports,
71
+ }) => {
61
72
  return {
62
73
  name: `jsenv:import_type_${type}`,
63
74
  appliesDuring: "*",
@@ -95,7 +106,9 @@ export const jsenvPluginImportAttributes = ({
95
106
  return null;
96
107
  }
97
108
  if (reference.importAttributes.type === type) {
98
- return turnIntoJsModuleProxy(reference, type);
109
+ return turnIntoJsModuleProxy(reference, type, {
110
+ injectSearchParamForSideEffectImports,
111
+ });
99
112
  }
100
113
  return null;
101
114
  },
@@ -144,6 +157,7 @@ export const jsenvPluginImportAttributes = ({
144
157
 
145
158
  const asCssModule = createImportTypePlugin({
146
159
  type: "css",
160
+ injectSearchParamForSideEffectImports: true,
147
161
  createUrlContent: (cssUrlInfo) => {
148
162
  const cssText = JS_QUOTES.escapeSpecialChars(cssUrlInfo.content, {
149
163
  // If template string is choosen and runtime do not support template literals
@@ -161,15 +175,38 @@ export const jsenvPluginImportAttributes = ({
161
175
  } else {
162
176
  inlineContentCall = `new __InlineContent__(${cssText}, { type: "text/css" })`;
163
177
  }
164
- return {
165
- content: `
166
- import ${JSON.stringify(cssUrlInfo.context.inlineContentClientFileUrl)};
178
+
179
+ let autoInject = cssUrlInfo.searchParams.has("side_effect");
180
+ let cssModuleAutoInjectCode = ``;
181
+ if (autoInject) {
182
+ if (cssUrlInfo.context.dev) {
183
+ cssModuleAutoInjectCode = `
184
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, stylesheet];
185
+
186
+ if (import.meta.hot) {
187
+ import.meta.hot.dispose(() => {
188
+ document.adoptedStyleSheets = document.adoptedStyleSheets.filter(
189
+ (s) => s !== stylesheet,
190
+ );
191
+ });
192
+ };
193
+ `;
194
+ } else {
195
+ cssModuleAutoInjectCode = `
196
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, stylesheet];
197
+ `;
198
+ }
199
+ }
200
+ let cssModuleContent = `import ${JSON.stringify(cssUrlInfo.context.inlineContentClientFileUrl)};
167
201
 
168
202
  const inlineContent = ${inlineContentCall};
169
203
  const stylesheet = new CSSStyleSheet();
170
204
  stylesheet.replaceSync(inlineContent.text);
205
+ ${cssModuleAutoInjectCode}
206
+ export default stylesheet;`;
171
207
 
172
- export default stylesheet;`,
208
+ return {
209
+ content: cssModuleContent,
173
210
  contentType: "text/javascript",
174
211
  type: "js_module",
175
212
  originalUrl: cssUrlInfo.originalUrl,