esm-styles 0.2.6 → 0.2.7

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.
Files changed (2) hide show
  1. package/dist/lib/build.js +24 -11
  2. package/package.json +1 -1
package/dist/lib/build.js CHANGED
@@ -22,6 +22,12 @@ export async function build(configPath = 'esm-styles.config.js') {
22
22
  const suffix = config.sourceFilesSuffix || '.styles.mjs';
23
23
  const floors = config.floors || [];
24
24
  const mainCssFile = config.mainCssFile || 'styles.css';
25
+ // Helper function to generate CSS comment header
26
+ const generateCssComment = (sourceName) => {
27
+ const normalizedBasePath = (config.basePath || '.').replace(/^\.\//, '');
28
+ const sourceFilePath = path.join(normalizedBasePath, config.sourcePath || '', `${sourceName}${suffix}`);
29
+ return `/* This CSS was automatically generated from ${sourceFilePath}, do not edit directly */\n`;
30
+ };
25
31
  // Merge media shorthands
26
32
  const mediaShorthands = getMediaShorthands(config);
27
33
  // Ensure output directory exists
@@ -35,7 +41,8 @@ export async function build(configPath = 'esm-styles.config.js') {
35
41
  const varsObj = (await import(fileUrl)).default;
36
42
  const cssVars = getCssVariables(varsObj);
37
43
  const rootSelector = config.globalRootSelector || ':root';
38
- const wrappedCss = `${rootSelector} {\n${cssVars}\n}`;
44
+ const comment = generateCssComment(config.globalVariables);
45
+ const wrappedCss = `${comment}${rootSelector} {\n${cssVars}\n}`;
39
46
  await fs.writeFile(outputFile, wrappedCss, 'utf8');
40
47
  cssFiles.push({ type: 'global', file: 'global.css' });
41
48
  }
@@ -73,7 +80,8 @@ export async function build(configPath = 'esm-styles.config.js') {
73
80
  fullSelector = `${rootSelector} ${selector}`;
74
81
  }
75
82
  }
76
- const block = `${fullSelector} {\n${cssVars}\n}`;
83
+ const comment = generateCssComment(setName);
84
+ const block = `${comment}${fullSelector} {\n${cssVars}\n}`;
77
85
  await fs.writeFile(outputFile, block, 'utf8');
78
86
  cssFiles.push({
79
87
  type: 'media',
@@ -178,13 +186,14 @@ export async function build(configPath = 'esm-styles.config.js') {
178
186
  ...mediaShorthands,
179
187
  globalRootSelector: config.globalRootSelector,
180
188
  });
181
- let wrappedCss = css;
189
+ const comment = generateCssComment(source);
190
+ let wrappedCss = `${comment}${css}`;
182
191
  if (layer) {
183
192
  // add layer to order in any case, even if the floor is not imported
184
193
  if (!uniqueLayers.includes(layer)) {
185
194
  uniqueLayers.push(layer);
186
195
  }
187
- wrappedCss = `@layer ${layer} {\n${css}\n}`;
196
+ wrappedCss = `${comment}@layer ${layer} {\n${css}\n}`;
188
197
  }
189
198
  await fs.writeFile(outputFile, wrappedCss, 'utf8');
190
199
  floorFiles.push({ file: `${source}.css`, layer, source });
@@ -215,13 +224,17 @@ export async function build(configPath = 'esm-styles.config.js') {
215
224
  }
216
225
  const importedFloorFiles = floorFiles.filter(isImportedFloor);
217
226
  const floorImports = importedFloorFiles.map(importStatement).join('\n');
218
- const mainCss = [
219
- uniqueLayers.length ? `@layer ${uniqueLayers.join(', ')};` : '',
220
- floorImports,
221
- varImports,
222
- ]
223
- .filter(Boolean)
224
- .join('\n') + '\n';
227
+ const normalizedBasePath = (config.basePath || '.').replace(/^\.\//, '');
228
+ const mainCssComment = `/* This CSS was automatically generated as the main styles file from ${normalizedBasePath}, do not edit directly */\n`;
229
+ const mainCss = mainCssComment +
230
+ [
231
+ uniqueLayers.length ? `@layer ${uniqueLayers.join(', ')};` : '',
232
+ floorImports,
233
+ varImports,
234
+ ]
235
+ .filter(Boolean)
236
+ .join('\n') +
237
+ '\n';
225
238
  await fs.writeFile(mainCssPath, mainCss, 'utf8');
226
239
  }
227
240
  // Helper for file URL import
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esm-styles",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "A library for working with ESM styles",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",