vite-plugin-lucide-preprocess 1.4.11 → 1.5.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 +1 -1
- package/dist/plugin.d.ts +2 -2
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +31 -8
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,7 +65,7 @@ More information about the auto-updater can be found in WarningImHack3r/vite-plu
|
|
|
65
65
|
Install the plugin with your package manager of choice:
|
|
66
66
|
|
|
67
67
|
```bash
|
|
68
|
-
pnpm i
|
|
68
|
+
pnpm i vite-plugin-lucide-preprocess
|
|
69
69
|
```
|
|
70
70
|
|
|
71
71
|
Then, add it to your `vite.config.js`/`.ts`:
|
package/dist/plugin.d.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* Converts a raw string of imported icons to a list of module names,
|
|
4
4
|
* and a list of TypeScript types
|
|
5
5
|
* @param rawModules {string} The raw string of imported icons
|
|
6
|
-
* @return {[Module[],
|
|
6
|
+
* @return {[Module[], Module[]]} A list containing a list of imported icons,
|
|
7
7
|
* and a list of TypeScript types
|
|
8
8
|
*/
|
|
9
|
-
export function rawModulesToLists(rawModules: string): [Module[],
|
|
9
|
+
export function rawModulesToLists(rawModules: string): [Module[], Module[]];
|
|
10
10
|
/**
|
|
11
11
|
* Converts a PascalCase icon component name to a dashed string
|
|
12
12
|
* (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":"
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.js"],"names":[],"mappings":"AAMA,6DAA6D;AAE7D;;;;;;GAMG;AACH,8CAJsB,MAAM,GAChB,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAsB/B;AAED;;;;;GAKG;AACH,4CAHqB,MAAM,GACf,MAAM,CAgBjB;AAED;;;;;GAKG;AACH,+CAJqB,MAAM,WACR,OAAO,GACd,MAAM,CAYjB;AAkBD;;;;GAIG;AACH,iCAHmB,OAAO,GACd,OAAO,MAAM,EAAE,MAAM,CAuEhC;AA1FD,oCACyF;qBAvE3E;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import renamedReplacementsModules from "./renamedReplacements.js";
|
|
2
2
|
import MagicString from "magic-string";
|
|
3
3
|
const ignoredPaths = ["/node_modules/", "/.svelte-kit/"];
|
|
4
|
+
const TYPE_PREFIX = "type ";
|
|
4
5
|
/** @typedef {{ name: string; importName: string }} Module */
|
|
5
6
|
/**
|
|
6
7
|
* Converts a raw string of imported icons to a list of module names,
|
|
7
8
|
* and a list of TypeScript types
|
|
8
9
|
* @param rawModules {string} The raw string of imported icons
|
|
9
|
-
* @return {[Module[],
|
|
10
|
+
* @return {[Module[], Module[]]} A list containing a list of imported icons,
|
|
10
11
|
* and a list of TypeScript types
|
|
11
12
|
*/
|
|
12
13
|
export function rawModulesToLists(rawModules) {
|
|
@@ -16,12 +17,17 @@ export function rawModulesToLists(rawModules) {
|
|
|
16
17
|
.filter(m => !!m);
|
|
17
18
|
return [
|
|
18
19
|
raw
|
|
19
|
-
.filter(m => !m.startsWith(
|
|
20
|
+
.filter(m => !m.startsWith(TYPE_PREFIX))
|
|
20
21
|
.map(m => {
|
|
21
22
|
const [original, newName] = m.split(" as ");
|
|
22
|
-
return { name: newName ?? original, importName: original };
|
|
23
|
+
return { name: (newName ?? original).trim(), importName: original.trim() };
|
|
23
24
|
}),
|
|
24
|
-
raw
|
|
25
|
+
raw
|
|
26
|
+
.filter(m => m.startsWith(TYPE_PREFIX))
|
|
27
|
+
.map(m => {
|
|
28
|
+
const [original, newName] = m.slice(TYPE_PREFIX.length).split(" as ");
|
|
29
|
+
return { name: (newName ?? original).trim(), importName: original.trim() };
|
|
30
|
+
})
|
|
25
31
|
];
|
|
26
32
|
}
|
|
27
33
|
/**
|
|
@@ -94,20 +100,37 @@ export function plugin(options = defaultOptions) {
|
|
|
94
100
|
* @param initialSpacing {string} The spacing before the matched import statement
|
|
95
101
|
* @param modulesStr {string} The imported icons as a raw string
|
|
96
102
|
* @param quote {string} The quote used in the import statement (either ' or ")
|
|
97
|
-
* @param importStyle {string} The method the icons are imported with
|
|
103
|
+
* @param importStyle {string} The method the icons are imported with (either "@lucide/" or "lucide-")
|
|
98
104
|
* @param framework {string} The framework the icons are imported for
|
|
99
105
|
* @param lineEnding {string} The end of the line of the matched import statement (often a semicolon)
|
|
100
106
|
* @return The optimized import statement(s)
|
|
101
107
|
*/
|
|
102
108
|
(_, initialSpacing, modulesStr, quote, importStyle, framework, lineEnding) => {
|
|
103
109
|
const [modules, types] = rawModulesToLists(modulesStr);
|
|
104
|
-
const
|
|
110
|
+
const [preserved, icons] = modules
|
|
111
|
+
.filter(({ importName }) => importName[0])
|
|
112
|
+
.reduce((acc, module) => {
|
|
113
|
+
if (module.importName[0] === module.importName[0].toLowerCase())
|
|
114
|
+
acc[0].push(module); // starts with lowercase = not an icon
|
|
115
|
+
else
|
|
116
|
+
acc[1].push(module); // doesn't start with lowercase = icon
|
|
117
|
+
return acc;
|
|
118
|
+
}, [/** @type {typeof modules} */ ([]), /** @type {typeof modules} */ ([])]);
|
|
119
|
+
const preservedStr = preserved
|
|
120
|
+
.map(({ name, importName }) => name === importName ? name : `${importName} as ${name}`)
|
|
121
|
+
.join(", ");
|
|
122
|
+
const preservedImports = `${initialSpacing}import { ${preservedStr} } from ${quote}${importStyle}${framework}${quote}${lineEnding.trimEnd()}`;
|
|
123
|
+
const moduleImports = icons
|
|
105
124
|
.map(m => `${initialSpacing}import ${m.name} from ${quote}${importStyle}${framework}${frameworkImportPath(framework, mergedOptions)}${iconCompToDashed(m.importName)}${quote}${lineEnding.trimEnd()}`)
|
|
106
125
|
.join(initialSpacing.includes("\n") ? "" : "\n");
|
|
107
|
-
const
|
|
126
|
+
const typesStr = types
|
|
127
|
+
.map(({ name, importName }) => name === importName ? name : `${importName} as ${name}`)
|
|
128
|
+
.join(", ");
|
|
129
|
+
const typesImport = `${initialSpacing}import type { ${typesStr} } from ${quote}${importStyle}${framework}${quote}${lineEnding.trimEnd()}`;
|
|
108
130
|
return [
|
|
131
|
+
preserved.length ? preservedImports : undefined,
|
|
109
132
|
types.length ? typesImport : undefined,
|
|
110
|
-
|
|
133
|
+
icons.length ? moduleImports : undefined
|
|
111
134
|
]
|
|
112
135
|
.filter(Boolean)
|
|
113
136
|
.join(initialSpacing.includes("\n") ? "" : "\n");
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.js"],"names":[],"mappings":"AAAA,OAAO,0BAA0B,MAAM,0BAA0B,CAAC;AAClE,OAAO,WAAW,MAAM,cAAc,CAAC;AAEvC,MAAM,YAAY,GAAG,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.js"],"names":[],"mappings":"AAAA,OAAO,0BAA0B,MAAM,0BAA0B,CAAC;AAClE,OAAO,WAAW,MAAM,cAAc,CAAC;AAEvC,MAAM,YAAY,GAAG,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;AACzD,MAAM,WAAW,GAAG,OAAO,CAAC;AAE5B,6DAA6D;AAE7D;;;;;;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,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