vite-plugin-lucide-preprocess 1.0.2 → 1.0.3
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/plugin.d.ts +5 -3
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +23 -7
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
package/dist/plugin.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Converts a raw string of imported icons to a list of module names
|
|
2
|
+
* Converts a raw string of imported icons to a list of module names,
|
|
3
|
+
* and a list of TypeScript types
|
|
3
4
|
* @param rawModules {string} The raw string of imported icons
|
|
4
|
-
* @return {string[]}
|
|
5
|
+
* @return {[string[], string[]]} A list containing a list of imported icons,
|
|
6
|
+
* and a list of TypeScript types
|
|
5
7
|
*/
|
|
6
|
-
export function
|
|
8
|
+
export function rawModulesToLists(rawModules: string): [string[], string[]];
|
|
7
9
|
/**
|
|
8
10
|
* Converts a PascalCase icon component name to a dashed string
|
|
9
11
|
* (e.g. `IconComp` to `icon-comp`)
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.js"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.js"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,8CAJsB,MAAM,GAChB,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAY/B;AAED;;;;;GAKG;AACH,4CAHqB,MAAM,GACf,MAAM,CAajB;AAED,oCAAiG;AAM1F,0BAFK,OAAO,MAAM,EAAE,MAAM,CAwC/B"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
const ignoredPaths = ["/node_modules/", "/.svelte-kit/"];
|
|
2
2
|
/**
|
|
3
|
-
* Converts a raw string of imported icons to a list of module names
|
|
3
|
+
* Converts a raw string of imported icons to a list of module names,
|
|
4
|
+
* and a list of TypeScript types
|
|
4
5
|
* @param rawModules {string} The raw string of imported icons
|
|
5
|
-
* @return {string[]}
|
|
6
|
+
* @return {[string[], string[]]} A list containing a list of imported icons,
|
|
7
|
+
* and a list of TypeScript types
|
|
6
8
|
*/
|
|
7
|
-
export function
|
|
8
|
-
|
|
9
|
+
export function rawModulesToLists(rawModules) {
|
|
10
|
+
const raw = rawModules
|
|
9
11
|
.split(",")
|
|
10
12
|
.map(m => m.trim())
|
|
11
|
-
.filter(m => !!m
|
|
13
|
+
.filter(m => !!m);
|
|
14
|
+
return [
|
|
15
|
+
raw.filter(m => !m.startsWith("type ")),
|
|
16
|
+
raw.filter(m => m.startsWith("type ")).map(m => m.slice(5))
|
|
17
|
+
];
|
|
12
18
|
}
|
|
13
19
|
/**
|
|
14
20
|
* Converts a PascalCase icon component name to a dashed string
|
|
@@ -18,6 +24,8 @@ export function rawModulesToModulesList(rawModules) {
|
|
|
18
24
|
*/
|
|
19
25
|
export function iconCompToDashed(component) {
|
|
20
26
|
return (component
|
|
27
|
+
.split(" ")[0] // take only the first part if there's an alias
|
|
28
|
+
// transform "IconComp" to "icon-comp"
|
|
21
29
|
.replace(/[A-Z\d]/g, (match, offset) => (offset > 0 ? "-" : "") + match.toLowerCase())
|
|
22
30
|
// fix for NxN icons
|
|
23
31
|
.replace(/(\d)x-(\d)/, (_, a, b) => `${a}x${b}`)
|
|
@@ -48,9 +56,17 @@ export const plugin = () => ({
|
|
|
48
56
|
* @return The optimized import statement(s)
|
|
49
57
|
*/
|
|
50
58
|
(_, initialSpacing, modulesStr, quote, framework, lineEnding) => {
|
|
51
|
-
|
|
59
|
+
const [modules, types] = rawModulesToLists(modulesStr);
|
|
60
|
+
const moduleImports = modules
|
|
52
61
|
.map(m => `${initialSpacing}import ${m} from ${quote}lucide-${framework}/icons/${iconCompToDashed(m)}${quote}${lineEnding.trimEnd()}`)
|
|
53
|
-
.join("\n");
|
|
62
|
+
.join(initialSpacing.includes("\n") ? "" : "\n");
|
|
63
|
+
const typesImport = `${initialSpacing}import type { ${types.join(", ")} } from ${quote}lucide-${framework}${quote}${lineEnding.trimEnd()}`;
|
|
64
|
+
return [
|
|
65
|
+
types.length ? typesImport : undefined,
|
|
66
|
+
modules.length ? moduleImports : undefined
|
|
67
|
+
]
|
|
68
|
+
.filter(Boolean)
|
|
69
|
+
.join(initialSpacing.includes("\n") ? "" : "\n");
|
|
54
70
|
})
|
|
55
71
|
};
|
|
56
72
|
}
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.js"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;AAEzD
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.js"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;AAEzD;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAU;IAC3C,MAAM,GAAG,GAAG,UAAU;SACpB,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SAClB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnB,OAAO;QACN,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACvC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KAC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