ecij 0.1.1 → 0.2.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 +15 -2
- package/dist/index.d.ts +14 -0
- package/dist/index.js +27 -19
- package/index.d.ts +1 -1
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -99,6 +99,20 @@ The `ecij()` plugin accepts an optional configuration object:
|
|
|
99
99
|
|
|
100
100
|
```ts
|
|
101
101
|
export interface Configuration {
|
|
102
|
+
/**
|
|
103
|
+
* Include patterns for files to process.
|
|
104
|
+
* Can be a string, RegExp, or array of strings/RegExp.
|
|
105
|
+
* @default /\.[cm]?[jt]sx?$/
|
|
106
|
+
*/
|
|
107
|
+
include?: string | RegExp | ReadonlyArray<string | RegExp>;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Exclude patterns for files to skip.
|
|
111
|
+
* Can be a string, RegExp, or array of strings/RegExp.
|
|
112
|
+
* @default [/\/node_modules\//, /\.d\.ts$/]
|
|
113
|
+
*/
|
|
114
|
+
exclude?: string | RegExp | ReadonlyArray<string | RegExp>;
|
|
115
|
+
|
|
102
116
|
/**
|
|
103
117
|
* Prefix for generated CSS class names.
|
|
104
118
|
* Should not be empty, as generated hashes may start with a digit, resulting in invalid CSS class names.
|
|
@@ -119,8 +133,7 @@ ecij({
|
|
|
119
133
|
## TODO
|
|
120
134
|
|
|
121
135
|
- Tests
|
|
122
|
-
- Support `include`/`exclude` configuration
|
|
123
136
|
- Scope handling
|
|
124
|
-
- Validate that the `css` used refers to
|
|
137
|
+
- Validate that the `css` used refers to the ecij export
|
|
125
138
|
- Full import/export handling (default/namespace import/export)
|
|
126
139
|
- Sourcemaps
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,18 @@ import { Plugin } from "rolldown";
|
|
|
2
2
|
|
|
3
3
|
//#region src/index.d.ts
|
|
4
4
|
interface Configuration {
|
|
5
|
+
/**
|
|
6
|
+
* Include patterns for files to process.
|
|
7
|
+
* Can be a string, RegExp, or array of strings/RegExp.
|
|
8
|
+
* @default /\.[cm]?[jt]sx?$/
|
|
9
|
+
*/
|
|
10
|
+
include?: string | RegExp | ReadonlyArray<string | RegExp>;
|
|
11
|
+
/**
|
|
12
|
+
* Exclude patterns for files to skip.
|
|
13
|
+
* Can be a string, RegExp, or array of strings/RegExp.
|
|
14
|
+
* @default [/\/node_modules\//, /\.d\.ts$/]
|
|
15
|
+
*/
|
|
16
|
+
exclude?: string | RegExp | ReadonlyArray<string | RegExp>;
|
|
5
17
|
/**
|
|
6
18
|
* Prefix for generated CSS class names.
|
|
7
19
|
* Should not be empty, as generated hashes may start with a digit, resulting in invalid CSS class names.
|
|
@@ -10,6 +22,8 @@ interface Configuration {
|
|
|
10
22
|
classPrefix?: string;
|
|
11
23
|
}
|
|
12
24
|
declare function ecij({
|
|
25
|
+
include,
|
|
26
|
+
exclude,
|
|
13
27
|
classPrefix
|
|
14
28
|
}?: Configuration): Plugin;
|
|
15
29
|
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,12 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { relative } from "node:path";
|
|
3
3
|
import { cwd } from "node:process";
|
|
4
4
|
import { Visitor, parseSync } from "oxc-parser";
|
|
5
|
+
import { makeIdFiltersToMatchWithQuery } from "@rolldown/pluginutils";
|
|
5
6
|
|
|
6
7
|
//#region src/index.ts
|
|
7
|
-
const JS_TS_FILE_REGEX = /\.[
|
|
8
|
+
const JS_TS_FILE_REGEX = /\.[cm]?[jt]sx?$/;
|
|
9
|
+
const NODE_MODULES_REGEX = /\/node_modules\//;
|
|
10
|
+
const D_TS_FILE_REGEX = /\.d\.ts$/;
|
|
8
11
|
const PROJECT_ROOT = cwd();
|
|
9
12
|
function hashText(text) {
|
|
10
13
|
return createHash("md5").update(text).digest("hex").slice(0, 8);
|
|
@@ -21,7 +24,7 @@ function removeImport(code) {
|
|
|
21
24
|
function addCssImport(code, cssModuleId) {
|
|
22
25
|
return `import ${JSON.stringify(cssModuleId)};\n\n${code}`;
|
|
23
26
|
}
|
|
24
|
-
function ecij({ classPrefix = "css-" } = {}) {
|
|
27
|
+
function ecij({ include = JS_TS_FILE_REGEX, exclude = [NODE_MODULES_REGEX, D_TS_FILE_REGEX], classPrefix = "css-" } = {}) {
|
|
25
28
|
const extractedCssPerFile = /* @__PURE__ */ new Map();
|
|
26
29
|
const importedClassNameCache = /* @__PURE__ */ new Map();
|
|
27
30
|
/**
|
|
@@ -66,11 +69,11 @@ function ecij({ classPrefix = "css-" } = {}) {
|
|
|
66
69
|
if (node.init.type === "TaggedTemplateExpression") {
|
|
67
70
|
taggedTemplateExpressionFromVariableDeclarator.add(node.init);
|
|
68
71
|
handleTaggedTemplateExpression(localName, node.init);
|
|
69
|
-
} else if (node.init.type === "Literal" && typeof node.init.value === "string") {
|
|
72
|
+
} else if (node.init.type === "Literal" && (typeof node.init.value === "string" || typeof node.init.value === "number")) {
|
|
70
73
|
const exportedName$1 = localNameToExportedNameMap.get(localName);
|
|
71
74
|
if (exportedName$1 === void 0) return;
|
|
72
75
|
const cacheKey$1 = `${resolvedPath}:${exportedName$1}`;
|
|
73
|
-
importedClassNameCache.set(cacheKey$1, node.init.value);
|
|
76
|
+
importedClassNameCache.set(cacheKey$1, String(node.init.value));
|
|
74
77
|
}
|
|
75
78
|
},
|
|
76
79
|
TaggedTemplateExpression(node) {
|
|
@@ -127,7 +130,7 @@ function ecij({ classPrefix = "css-" } = {}) {
|
|
|
127
130
|
if (node.init.type === "TaggedTemplateExpression") {
|
|
128
131
|
taggedTemplateExpressionFromVariableDeclarator.add(node.init);
|
|
129
132
|
handleTaggedTemplateExpression(localName, node.init);
|
|
130
|
-
} else if (node.init.type === "Literal" && typeof node.init.value === "string") localClassNames.set(localName, node.init.value);
|
|
133
|
+
} else if (node.init.type === "Literal" && (typeof node.init.value === "string" || typeof node.init.value === "number")) localClassNames.set(localName, String(node.init.value));
|
|
131
134
|
},
|
|
132
135
|
TaggedTemplateExpression(node) {
|
|
133
136
|
if (taggedTemplateExpressionFromVariableDeclarator.has(node)) return;
|
|
@@ -212,21 +215,26 @@ function ecij({ classPrefix = "css-" } = {}) {
|
|
|
212
215
|
if (extractedCssPerFile.has(id)) return extractedCssPerFile.get(id);
|
|
213
216
|
return null;
|
|
214
217
|
},
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
finalCode =
|
|
218
|
+
transform: {
|
|
219
|
+
filter: { id: {
|
|
220
|
+
include: makeIdFiltersToMatchWithQuery(include),
|
|
221
|
+
exclude: makeIdFiltersToMatchWithQuery(exclude)
|
|
222
|
+
} },
|
|
223
|
+
async handler(code, id) {
|
|
224
|
+
const queryIndex = id.indexOf("?");
|
|
225
|
+
const cleanId = queryIndex === -1 ? id : id.slice(0, queryIndex);
|
|
226
|
+
if (!code.includes("ecij")) return null;
|
|
227
|
+
const { transformedCode, hasExtractions, cssContent, hasUnprocessedCssBlocks } = await extractCssFromCode(this, code, cleanId);
|
|
228
|
+
if (!hasExtractions) return null;
|
|
229
|
+
let finalCode = transformedCode;
|
|
230
|
+
if (cssContent !== "") {
|
|
231
|
+
const cssModuleId = `${cleanId}.${hashText(cssContent)}.css`;
|
|
232
|
+
extractedCssPerFile.set(cssModuleId, cssContent);
|
|
233
|
+
finalCode = addCssImport(finalCode, cssModuleId);
|
|
234
|
+
}
|
|
235
|
+
if (!hasUnprocessedCssBlocks) finalCode = removeImport(finalCode);
|
|
236
|
+
return finalCode;
|
|
227
237
|
}
|
|
228
|
-
if (!hasUnprocessedCssBlocks) finalCode = removeImport(finalCode);
|
|
229
|
-
return finalCode;
|
|
230
238
|
}
|
|
231
239
|
};
|
|
232
240
|
}
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ecij",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Rolldown and Vite plugin to Extract CSS-in-JS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"css-in-js"
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"author": "Nicolas Stepien",
|
|
18
18
|
"type": "module",
|
|
19
|
+
"sideEffects": false,
|
|
19
20
|
"exports": {
|
|
20
21
|
".": {
|
|
21
22
|
"types": "./index.d.ts",
|
|
@@ -38,13 +39,14 @@
|
|
|
38
39
|
"typecheck": "tsc"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"
|
|
42
|
+
"@rolldown/pluginutils": "^1.0.0-beta.50",
|
|
43
|
+
"oxc-parser": "^0.98.0"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
44
46
|
"@types/node": "^24.10.1",
|
|
45
47
|
"prettier": "^3.6.2",
|
|
46
48
|
"rolldown": "^1.0.0-beta.50",
|
|
47
|
-
"rolldown-plugin-dts": "^0.17.
|
|
49
|
+
"rolldown-plugin-dts": "^0.17.8",
|
|
48
50
|
"typescript": "^5.9.3"
|
|
49
51
|
}
|
|
50
52
|
}
|