@jsenv/core 41.4.26 → 41.4.27

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.
@@ -8360,6 +8360,12 @@ const jsenvPluginImportMetaCss = () => {
8360
8360
  return null;
8361
8361
  }
8362
8362
  if (urlInfo.context.build) {
8363
+ if (hasModuleScopeAssignment(urlInfo.contentAst)) {
8364
+ urlInfo.contentSideEffects.push({
8365
+ has: true,
8366
+ reason: "import.meta.css assigned at module scope",
8367
+ });
8368
+ }
8363
8369
  const packageName = urlInfo.packageName;
8364
8370
  const packageDirectoryUrl =
8365
8371
  urlInfo.packageDirectoryUrl || urlInfo.context.rootDirectoryUrl;
@@ -8403,6 +8409,28 @@ const jsenvPluginImportMetaCss = () => {
8403
8409
  };
8404
8410
  };
8405
8411
 
8412
+ // A stylesheet assigned at module scope is adopted when the module runs: that
8413
+ // assignment IS the module's side effect. It has to be told, because a
8414
+ // package.json "sideEffects" list is authoritative once it exists — a module
8415
+ // it does not name is dropped whole when it is imported for nothing else, and
8416
+ // its css silently leaves the build.
8417
+ const hasModuleScopeAssignment = (ast) => {
8418
+ for (const node of ast.body) {
8419
+ if (node.type !== "ExpressionStatement") {
8420
+ continue;
8421
+ }
8422
+ const { expression } = node;
8423
+ if (
8424
+ expression.type === "AssignmentExpression" &&
8425
+ expression.operator === "=" &&
8426
+ getImportMetaPropertyName(expression.left) === "css"
8427
+ ) {
8428
+ return true;
8429
+ }
8430
+ }
8431
+ return false;
8432
+ };
8433
+
8406
8434
  const babelPluginRewriteImportMetaCssAssignment = (
8407
8435
  { types: t },
8408
8436
  { relativeUrl },
@@ -6179,6 +6179,12 @@ const jsenvPluginImportMetaCss = () => {
6179
6179
  return null;
6180
6180
  }
6181
6181
  if (urlInfo.context.build) {
6182
+ if (hasModuleScopeAssignment(urlInfo.contentAst)) {
6183
+ urlInfo.contentSideEffects.push({
6184
+ has: true,
6185
+ reason: "import.meta.css assigned at module scope",
6186
+ });
6187
+ }
6182
6188
  const packageName = urlInfo.packageName;
6183
6189
  const packageDirectoryUrl =
6184
6190
  urlInfo.packageDirectoryUrl || urlInfo.context.rootDirectoryUrl;
@@ -6222,6 +6228,28 @@ const jsenvPluginImportMetaCss = () => {
6222
6228
  };
6223
6229
  };
6224
6230
 
6231
+ // A stylesheet assigned at module scope is adopted when the module runs: that
6232
+ // assignment IS the module's side effect. It has to be told, because a
6233
+ // package.json "sideEffects" list is authoritative once it exists — a module
6234
+ // it does not name is dropped whole when it is imported for nothing else, and
6235
+ // its css silently leaves the build.
6236
+ const hasModuleScopeAssignment = (ast) => {
6237
+ for (const node of ast.body) {
6238
+ if (node.type !== "ExpressionStatement") {
6239
+ continue;
6240
+ }
6241
+ const { expression } = node;
6242
+ if (
6243
+ expression.type === "AssignmentExpression" &&
6244
+ expression.operator === "=" &&
6245
+ getImportMetaPropertyName(expression.left) === "css"
6246
+ ) {
6247
+ return true;
6248
+ }
6249
+ }
6250
+ return false;
6251
+ };
6252
+
6225
6253
  const babelPluginRewriteImportMetaCssAssignment = (
6226
6254
  { types: t },
6227
6255
  { relativeUrl },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "41.4.26",
3
+ "version": "41.4.27",
4
4
  "type": "module",
5
5
  "description": "Tool to develop, test and build js projects",
6
6
  "repository": {
@@ -64,6 +64,12 @@ export const jsenvPluginImportMetaCss = () => {
64
64
  return null;
65
65
  }
66
66
  if (urlInfo.context.build) {
67
+ if (hasModuleScopeAssignment(urlInfo.contentAst)) {
68
+ urlInfo.contentSideEffects.push({
69
+ has: true,
70
+ reason: "import.meta.css assigned at module scope",
71
+ });
72
+ }
67
73
  const packageName = urlInfo.packageName;
68
74
  const packageDirectoryUrl =
69
75
  urlInfo.packageDirectoryUrl || urlInfo.context.rootDirectoryUrl;
@@ -107,6 +113,28 @@ export const jsenvPluginImportMetaCss = () => {
107
113
  };
108
114
  };
109
115
 
116
+ // A stylesheet assigned at module scope is adopted when the module runs: that
117
+ // assignment IS the module's side effect. It has to be told, because a
118
+ // package.json "sideEffects" list is authoritative once it exists — a module
119
+ // it does not name is dropped whole when it is imported for nothing else, and
120
+ // its css silently leaves the build.
121
+ const hasModuleScopeAssignment = (ast) => {
122
+ for (const node of ast.body) {
123
+ if (node.type !== "ExpressionStatement") {
124
+ continue;
125
+ }
126
+ const { expression } = node;
127
+ if (
128
+ expression.type === "AssignmentExpression" &&
129
+ expression.operator === "=" &&
130
+ getImportMetaPropertyName(expression.left) === "css"
131
+ ) {
132
+ return true;
133
+ }
134
+ }
135
+ return false;
136
+ };
137
+
110
138
  const babelPluginRewriteImportMetaCssAssignment = (
111
139
  { types: t },
112
140
  { relativeUrl },