ecij 0.3.0 → 0.4.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/README.md +0 -1
- package/dist/index.js +14 -14
- package/index.d.ts +1 -4
- package/package.json +17 -21
package/README.md
CHANGED
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 {
|
|
5
|
-
import {
|
|
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?$/;
|
|
@@ -103,19 +103,19 @@ function ecij({ include = JS_TS_FILE_REGEX, exclude = [NODE_MODULES_REGEX, D_TS_
|
|
|
103
103
|
const resolvedId = await context.resolve(source, filePath);
|
|
104
104
|
if (resolvedId != null) {
|
|
105
105
|
const { id } = resolvedId;
|
|
106
|
-
const { declarations
|
|
106
|
+
const { declarations, exportNameToValueMap } = await parseFile(context, id);
|
|
107
107
|
if (exportNameToValueMap.has(imported)) {
|
|
108
|
-
if (declarations
|
|
108
|
+
if (declarations.length !== 0) modulesWithSideEffects.add(id);
|
|
109
109
|
return exportNameToValueMap.get(imported);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
function addProcessedDeclaration(declaration, cssContent
|
|
114
|
+
function addProcessedDeclaration(declaration, cssContent) {
|
|
115
115
|
const { className, node } = declaration;
|
|
116
116
|
cssExtractions.push({
|
|
117
117
|
className,
|
|
118
|
-
cssContent: cssContent
|
|
118
|
+
cssContent: cssContent.trim(),
|
|
119
119
|
sourcePosition: node.start
|
|
120
120
|
});
|
|
121
121
|
replacements.push({
|
|
@@ -126,16 +126,16 @@ function ecij({ include = JS_TS_FILE_REGEX, exclude = [NODE_MODULES_REGEX, D_TS_
|
|
|
126
126
|
}
|
|
127
127
|
for (const declaration of declarations) {
|
|
128
128
|
if (declaration.hasInterpolations) continue;
|
|
129
|
-
const cssContent
|
|
130
|
-
addProcessedDeclaration(declaration, cssContent
|
|
129
|
+
const cssContent = declaration.node.quasi.quasis[0].value.raw;
|
|
130
|
+
addProcessedDeclaration(declaration, cssContent);
|
|
131
131
|
}
|
|
132
132
|
for (const declaration of declarations) {
|
|
133
133
|
if (!declaration.hasInterpolations) continue;
|
|
134
134
|
const { quasis, expressions } = declaration.node.quasi;
|
|
135
|
-
let cssContent
|
|
135
|
+
let cssContent = "";
|
|
136
136
|
let allResolved = true;
|
|
137
137
|
for (let i = 0; i < quasis.length; i++) {
|
|
138
|
-
cssContent
|
|
138
|
+
cssContent += quasis[i].value.raw;
|
|
139
139
|
if (i < expressions.length) {
|
|
140
140
|
const expression = expressions[i];
|
|
141
141
|
if (expression.type !== "Identifier") {
|
|
@@ -148,10 +148,10 @@ function ecij({ include = JS_TS_FILE_REGEX, exclude = [NODE_MODULES_REGEX, D_TS_
|
|
|
148
148
|
allResolved = false;
|
|
149
149
|
break;
|
|
150
150
|
}
|
|
151
|
-
cssContent
|
|
151
|
+
cssContent += resolvedValue;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
if (allResolved) addProcessedDeclaration(declaration, cssContent
|
|
154
|
+
if (allResolved) addProcessedDeclaration(declaration, cssContent);
|
|
155
155
|
}
|
|
156
156
|
if (replacements.length === 0) return {
|
|
157
157
|
transformedCode: code,
|
|
@@ -164,7 +164,7 @@ function ecij({ include = JS_TS_FILE_REGEX, exclude = [NODE_MODULES_REGEX, D_TS_
|
|
|
164
164
|
for (const { start, end, className } of replacements) transformedCode = `${transformedCode.slice(0, start)}'${className}'${transformedCode.slice(end)}`;
|
|
165
165
|
cssExtractions.sort((a, b) => a.sourcePosition - b.sourcePosition);
|
|
166
166
|
const cssBlocks = [];
|
|
167
|
-
for (const { className, cssContent
|
|
167
|
+
for (const { className, cssContent } of cssExtractions) if (cssContent !== "") cssBlocks.push(`.${className} {\n ${cssContent}\n}`);
|
|
168
168
|
const cssContent = cssBlocks.join("\n\n");
|
|
169
169
|
return {
|
|
170
170
|
transformedCode,
|
|
@@ -203,7 +203,7 @@ function ecij({ include = JS_TS_FILE_REGEX, exclude = [NODE_MODULES_REGEX, D_TS_
|
|
|
203
203
|
const cssModuleId = `${cleanId}.${hashText(cssContent)}.css`;
|
|
204
204
|
extractedCssPerFile.set(cssModuleId, cssContent);
|
|
205
205
|
const importStatements = [];
|
|
206
|
-
for (const id
|
|
206
|
+
for (const id of modulesWithSideEffects) importStatements.push(`import ${JSON.stringify(id)};\n`);
|
|
207
207
|
importStatements.push(`import ${JSON.stringify(cssModuleId)}\n;`);
|
|
208
208
|
return `${importStatements.join("")}${transformedCode}`;
|
|
209
209
|
}
|
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
|
+
"version": "0.4.0",
|
|
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
|
-
"
|
|
17
|
-
|
|
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": "
|
|
38
|
-
"format: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": "^
|
|
49
|
-
"@vitest/coverage-v8": "^4.0.
|
|
50
|
-
"
|
|
51
|
-
"rolldown": "
|
|
52
|
-
"rolldown-plugin-dts": "^0.
|
|
44
|
+
"@types/node": "^25.3.2",
|
|
45
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
46
|
+
"oxfmt": "^0.35.0",
|
|
47
|
+
"rolldown": "1.0.0-rc.5",
|
|
48
|
+
"rolldown-plugin-dts": "^0.22.2",
|
|
53
49
|
"typescript": "^5.9.3",
|
|
54
|
-
"vite": "
|
|
55
|
-
"vitest": "^4.0.
|
|
50
|
+
"vite": "^8.0.0-beta.16",
|
|
51
|
+
"vitest": "^4.0.18"
|
|
56
52
|
},
|
|
57
53
|
"overrides": {
|
|
58
54
|
"vite": "$vite"
|