ecij 0.3.0 → 0.4.1

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/README.md CHANGED
@@ -172,6 +172,5 @@ npm test -- -u
172
172
 
173
173
  - Log CSS extraction failures
174
174
  - Scope handling
175
- - Validate that the `css` used refers to the ecij export
176
175
  - Full import/export handling (default/namespace import/export)
177
176
  - Sourcemaps
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { relative } from "node:path";
3
3
  import { cwd } from "node:process";
4
- import { Visitor, parseSync } from "oxc-parser";
5
- import { makeIdFiltersToMatchWithQuery } from "@rolldown/pluginutils";
4
+ import { makeIdFiltersToMatchWithQuery } from "rolldown/filter";
5
+ import { Visitor, parseSync } from "rolldown/utils";
6
6
 
7
7
  //#region src/index.ts
8
8
  const JS_TS_FILE_REGEX = /\.[cm]?[jt]sx?$/;
@@ -14,6 +14,7 @@ function hashText(text) {
14
14
  }
15
15
  function ecij({ include = JS_TS_FILE_REGEX, exclude = [NODE_MODULES_REGEX, D_TS_FILE_REGEX], classPrefix = "css-" } = {}) {
16
16
  const parsedFileInfoCache = /* @__PURE__ */ new Map();
17
+ const stylesheetImportPerFile = /* @__PURE__ */ new Map();
17
18
  const extractedCssPerFile = /* @__PURE__ */ new Map();
18
19
  /**
19
20
  * Parses a file and extracts all relevant information in a single pass
@@ -95,27 +96,28 @@ function ecij({ include = JS_TS_FILE_REGEX, exclude = [NODE_MODULES_REGEX, D_TS_
95
96
  const { declarations, localIdentifiers, importedIdentifiers } = await parseFile(context, filePath, code);
96
97
  const cssExtractions = [];
97
98
  const replacements = [];
98
- const modulesWithSideEffects = /* @__PURE__ */ new Set();
99
+ const stylesheetDependencies = /* @__PURE__ */ new Set();
99
100
  async function resolveValue(identifierName) {
100
101
  if (localIdentifiers.has(identifierName)) return localIdentifiers.get(identifierName);
101
102
  if (importedIdentifiers.has(identifierName)) {
102
103
  const { source, imported } = importedIdentifiers.get(identifierName);
103
104
  const resolvedId = await context.resolve(source, filePath);
104
105
  if (resolvedId != null) {
106
+ await context.load(resolvedId);
105
107
  const { id } = resolvedId;
106
- const { declarations: declarations$1, exportNameToValueMap } = await parseFile(context, id);
108
+ const { exportNameToValueMap } = await parseFile(context, id);
107
109
  if (exportNameToValueMap.has(imported)) {
108
- if (declarations$1.length !== 0) modulesWithSideEffects.add(id);
110
+ if (stylesheetImportPerFile.has(id)) stylesheetDependencies.add(stylesheetImportPerFile.get(id));
109
111
  return exportNameToValueMap.get(imported);
110
112
  }
111
113
  }
112
114
  }
113
115
  }
114
- function addProcessedDeclaration(declaration, cssContent$1) {
116
+ function addProcessedDeclaration(declaration, cssContent) {
115
117
  const { className, node } = declaration;
116
118
  cssExtractions.push({
117
119
  className,
118
- cssContent: cssContent$1.trim(),
120
+ cssContent: cssContent.trim(),
119
121
  sourcePosition: node.start
120
122
  });
121
123
  replacements.push({
@@ -126,16 +128,16 @@ function ecij({ include = JS_TS_FILE_REGEX, exclude = [NODE_MODULES_REGEX, D_TS_
126
128
  }
127
129
  for (const declaration of declarations) {
128
130
  if (declaration.hasInterpolations) continue;
129
- const cssContent$1 = declaration.node.quasi.quasis[0].value.raw;
130
- addProcessedDeclaration(declaration, cssContent$1);
131
+ const cssContent = declaration.node.quasi.quasis[0].value.raw;
132
+ addProcessedDeclaration(declaration, cssContent);
131
133
  }
132
134
  for (const declaration of declarations) {
133
135
  if (!declaration.hasInterpolations) continue;
134
136
  const { quasis, expressions } = declaration.node.quasi;
135
- let cssContent$1 = "";
137
+ let cssContent = "";
136
138
  let allResolved = true;
137
139
  for (let i = 0; i < quasis.length; i++) {
138
- cssContent$1 += quasis[i].value.raw;
140
+ cssContent += quasis[i].value.raw;
139
141
  if (i < expressions.length) {
140
142
  const expression = expressions[i];
141
143
  if (expression.type !== "Identifier") {
@@ -148,35 +150,36 @@ function ecij({ include = JS_TS_FILE_REGEX, exclude = [NODE_MODULES_REGEX, D_TS_
148
150
  allResolved = false;
149
151
  break;
150
152
  }
151
- cssContent$1 += resolvedValue;
153
+ cssContent += resolvedValue;
152
154
  }
153
155
  }
154
- if (allResolved) addProcessedDeclaration(declaration, cssContent$1);
156
+ if (allResolved) addProcessedDeclaration(declaration, cssContent);
155
157
  }
156
158
  if (replacements.length === 0) return {
157
159
  transformedCode: code,
158
160
  hasExtractions: false,
159
161
  cssContent: "",
160
- modulesWithSideEffects
162
+ stylesheetDependencies
161
163
  };
162
164
  replacements.sort((a, b) => b.start - a.start);
163
165
  let transformedCode = code;
164
166
  for (const { start, end, className } of replacements) transformedCode = `${transformedCode.slice(0, start)}'${className}'${transformedCode.slice(end)}`;
165
167
  cssExtractions.sort((a, b) => a.sourcePosition - b.sourcePosition);
166
168
  const cssBlocks = [];
167
- for (const { className, cssContent: cssContent$1 } of cssExtractions) if (cssContent$1 !== "") cssBlocks.push(`.${className} {\n ${cssContent$1}\n}`);
169
+ for (const { className, cssContent } of cssExtractions) if (cssContent !== "") cssBlocks.push(`.${className} {\n ${cssContent}\n}`);
168
170
  const cssContent = cssBlocks.join("\n\n");
169
171
  return {
170
172
  transformedCode,
171
173
  hasExtractions: true,
172
174
  cssContent,
173
- modulesWithSideEffects
175
+ stylesheetDependencies
174
176
  };
175
177
  }
176
178
  return {
177
179
  name: "ecij",
178
180
  buildEnd() {
179
181
  parsedFileInfoCache.clear();
182
+ stylesheetImportPerFile.clear();
180
183
  extractedCssPerFile.clear();
181
184
  },
182
185
  resolveId(id) {
@@ -197,14 +200,15 @@ function ecij({ include = JS_TS_FILE_REGEX, exclude = [NODE_MODULES_REGEX, D_TS_
197
200
  if (!code.includes("ecij")) return null;
198
201
  const queryIndex = id.indexOf("?");
199
202
  const cleanId = queryIndex === -1 ? id : id.slice(0, queryIndex);
200
- const { transformedCode, hasExtractions, cssContent, modulesWithSideEffects } = await extractCssFromCode(this, code, cleanId);
203
+ const { transformedCode, hasExtractions, cssContent, stylesheetDependencies } = await extractCssFromCode(this, code, cleanId);
201
204
  if (!hasExtractions) return null;
202
205
  if (cssContent === "") return transformedCode;
203
206
  const cssModuleId = `${cleanId}.${hashText(cssContent)}.css`;
204
207
  extractedCssPerFile.set(cssModuleId, cssContent);
208
+ stylesheetImportPerFile.set(id, cssModuleId);
205
209
  const importStatements = [];
206
- for (const id$1 of modulesWithSideEffects) importStatements.push(`import ${JSON.stringify(id$1)};\n`);
207
- importStatements.push(`import ${JSON.stringify(cssModuleId)}\n;`);
210
+ for (const id of stylesheetDependencies) importStatements.push(`import ${JSON.stringify(id)};\n`);
211
+ importStatements.push(`import ${JSON.stringify(cssModuleId)};\n`);
208
212
  return `${importStatements.join("")}${transformedCode}`;
209
213
  }
210
214
  }
package/index.d.ts CHANGED
@@ -14,7 +14,4 @@
14
14
  * const myClass = 'css-a1b2c3d4';
15
15
  * ```
16
16
  */
17
- export function css(
18
- strings: TemplateStringsArray,
19
- ...expressions: Array<string | number>
20
- ): string;
17
+ export function css(strings: TemplateStringsArray, ...expressions: Array<string | number>): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ecij",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Rolldown and Vite plugin to Extract CSS-in-JS",
5
5
  "keywords": [
6
6
  "css-in-js"
@@ -9,14 +9,19 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/nstepien/ecij/issues"
11
11
  },
12
+ "license": "MIT",
13
+ "author": "Nicolas Stepien",
12
14
  "repository": {
13
15
  "type": "git",
14
16
  "url": "git+https://github.com/nstepien/ecij.git"
15
17
  },
16
- "license": "MIT",
17
- "author": "Nicolas Stepien",
18
+ "files": [
19
+ "dist",
20
+ "index.d.ts"
21
+ ],
18
22
  "type": "module",
19
23
  "sideEffects": false,
24
+ "main": "index.js",
20
25
  "exports": {
21
26
  ".": {
22
27
  "types": "./index.d.ts",
@@ -27,32 +32,23 @@
27
32
  "default": "./dist/index.js"
28
33
  }
29
34
  },
30
- "main": "index.js",
31
- "files": [
32
- "dist",
33
- "index.d.ts"
34
- ],
35
35
  "scripts": {
36
36
  "build": "rolldown -c",
37
- "format": "prettier --write .",
38
- "format:check": "prettier --check .",
37
+ "format": "oxfmt",
38
+ "format:check": "oxfmt --check",
39
39
  "typecheck": "tsc --build",
40
40
  "test": "vitest run",
41
41
  "test:coverage": "vitest run --coverage"
42
42
  },
43
- "dependencies": {
44
- "@rolldown/pluginutils": "^1.0.0-beta.53",
45
- "oxc-parser": "^0.102.0"
46
- },
47
43
  "devDependencies": {
48
- "@types/node": "^24.10.1",
49
- "@vitest/coverage-v8": "^4.0.15",
50
- "prettier": "^3.7.4",
51
- "rolldown": "^1.0.0-beta.53",
52
- "rolldown-plugin-dts": "^0.18.3",
44
+ "@types/node": "^25.3.2",
45
+ "@vitest/coverage-v8": "^4.0.18",
46
+ "oxfmt": "^0.35.0",
47
+ "rolldown": "^1.0.0-rc.6",
48
+ "rolldown-plugin-dts": "^0.22.2",
53
49
  "typescript": "^5.9.3",
54
- "vite": "npm:rolldown-vite@^7.2.10",
55
- "vitest": "^4.0.15"
50
+ "vite": "^8.0.0-beta.16",
51
+ "vitest": "^4.0.18"
56
52
  },
57
53
  "overrides": {
58
54
  "vite": "$vite"