fimo-vite 2.4.1 → 2.5.0-staging.2
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/dist/plugins/data-id.js +21 -3
- package/package.json +4 -4
package/dist/plugins/data-id.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createFilter } from '@rollup/pluginutils';
|
|
2
|
+
import { FIMO_EDITING_ATTRIBUTES, resolveFimoEditingMetadata } from 'fimo/preview';
|
|
2
3
|
import { getLineColumn } from 'fimo/vite/data-id';
|
|
3
4
|
import { parseSync } from 'oxc-parser';
|
|
4
5
|
export default function dataIdPlugin() {
|
|
@@ -10,7 +11,11 @@ export default function dataIdPlugin() {
|
|
|
10
11
|
config = resolvedConfig;
|
|
11
12
|
},
|
|
12
13
|
async transform(code, id) {
|
|
13
|
-
|
|
14
|
+
const configured = config?.define?.['process.env.FIMO_EDITING_METADATA'];
|
|
15
|
+
const editing = configured === undefined
|
|
16
|
+
? resolveFimoEditingMetadata(config?.command === 'serve' && !config.isProduction ? 'development' : undefined, process.env.FIMO_EDITING_METADATA)
|
|
17
|
+
: configured === JSON.stringify('true');
|
|
18
|
+
if (!editing && !code.includes('data-fimo-')) {
|
|
14
19
|
return null;
|
|
15
20
|
}
|
|
16
21
|
const filter = createFilter(/\.(jsx|tsx)$/);
|
|
@@ -28,12 +33,22 @@ export default function dataIdPlugin() {
|
|
|
28
33
|
if (!node || typeof node !== 'object') {
|
|
29
34
|
return;
|
|
30
35
|
}
|
|
36
|
+
if (!editing && node.type === 'JSXAttribute' && FIMO_EDITING_ATTRIBUTES.has(node.name?.name)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
31
39
|
if (node.type === 'JSXOpeningElement') {
|
|
32
40
|
const attributes = node.attributes || [];
|
|
41
|
+
if (!editing) {
|
|
42
|
+
for (const attr of attributes) {
|
|
43
|
+
if (attr.type === 'JSXAttribute' && FIMO_EDITING_ATTRIBUTES.has(attr.name?.name)) {
|
|
44
|
+
insertions.push({ offset: attr.start, end: attr.end, value: '' });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
33
48
|
const hasId = attributes.some((attr) => attr.type === 'JSXAttribute' &&
|
|
34
49
|
attr.name?.type === 'JSXIdentifier' &&
|
|
35
50
|
attr.name?.name === 'data-fimo-id');
|
|
36
|
-
if (!hasId && node.start != null) {
|
|
51
|
+
if (editing && !hasId && node.start != null) {
|
|
37
52
|
const line = getLineColumn(code, node.start);
|
|
38
53
|
const relativePath = id.replace(process.cwd() + '/', '');
|
|
39
54
|
const fimoId = `${relativePath}#${line.line}-${line.column}`;
|
|
@@ -66,7 +81,10 @@ export default function dataIdPlugin() {
|
|
|
66
81
|
insertions.sort((a, b) => b.offset - a.offset);
|
|
67
82
|
let transformed = code;
|
|
68
83
|
for (const insertion of insertions) {
|
|
69
|
-
transformed =
|
|
84
|
+
transformed =
|
|
85
|
+
transformed.slice(0, insertion.offset) +
|
|
86
|
+
insertion.value +
|
|
87
|
+
transformed.slice(insertion.end ?? insertion.offset);
|
|
70
88
|
}
|
|
71
89
|
return {
|
|
72
90
|
code: transformed,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fimo-vite",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0-staging.2",
|
|
4
4
|
"description": "Framework-neutral Fimo Vite plugin. Pairs with the fimo package at the same version.",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/",
|
|
@@ -31,15 +31,15 @@
|
|
|
31
31
|
"oxc-parser": "^0.118.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@fimo/tsconfig": "2.
|
|
34
|
+
"@fimo/tsconfig": "2.5.0-staging.2",
|
|
35
35
|
"@types/node": "22.18.6",
|
|
36
|
-
"fimo": "2.
|
|
36
|
+
"fimo": "2.5.0-staging.2",
|
|
37
37
|
"typescript": "7.0.2",
|
|
38
38
|
"vite": "8.2.2",
|
|
39
39
|
"vitest": "5.0.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"fimo": "
|
|
42
|
+
"fimo": "2.5.0-staging.2",
|
|
43
43
|
"vite": "^7.0.0 || ^8.0.0"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|