vite-plugin-lucide-preprocess 1.0.2 → 1.0.4

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 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[]} The list of imported icon
5
+ * @return {[string[], string[]]} A list containing a list of imported icons,
6
+ * and a list of TypeScript types
5
7
  */
6
- export function rawModulesToModulesList(rawModules: string): string[];
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`)
@@ -11,6 +13,10 @@ export function rawModulesToModulesList(rawModules: string): string[];
11
13
  * @return {string} The dashed icon component name
12
14
  */
13
15
  export function iconCompToDashed(component: string): string;
14
- export const importsMatcher: RegExp;
16
+ /**
17
+ * The Vite plugin that preprocesses imports to optimize Lucide icons
18
+ * @return {import("vite").Plugin}
19
+ */
15
20
  export function plugin(): import("vite").Plugin;
21
+ export const importsMatcher: RegExp;
16
22
  //# sourceMappingURL=plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,oDAHsB,MAAM,GAChB,MAAM,EAAE,CAOnB;AAED;;;;;GAKG;AACH,4CAHqB,MAAM,GACf,MAAM,CAWjB;AAED,oCAAiG;AAM1F,0BAFK,OAAO,MAAM,EAAE,MAAM,CAgC/B"}
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,CAejB;AAID;;;GAGG;AACH,0BAFY,OAAO,MAAM,EAAE,MAAM,CAwChC;AA5CD,oCAAiG"}
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[]} The list of imported icon
6
+ * @return {[string[], string[]]} A list containing a list of imported icons,
7
+ * and a list of TypeScript types
6
8
  */
7
- export function rawModulesToModulesList(rawModules) {
8
- return rawModules
9
+ export function rawModulesToLists(rawModules) {
10
+ const raw = rawModules
9
11
  .split(",")
10
12
  .map(m => m.trim())
11
- .filter(m => !!m && !m.startsWith("type"));
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,41 +24,54 @@ 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}`)
24
32
  // exception for ClockNN
25
- .replace(/clock-(\d)-(\d)/, (_, a, b) => `clock-${a}${b}`));
33
+ .replace(/clock-(\d)-(\d)/, (_, a, b) => `clock-${a}${b}`)
34
+ // remove the "Icon" suffix
35
+ .replace(/-icon$/, ""));
26
36
  }
27
37
  export const importsMatcher = /^(\s*)import\s+\{([^}]*)}\s+from\s+(["'])lucide-(.*?)["'](.*)$/gm;
28
38
  /**
29
39
  * The Vite plugin that preprocesses imports to optimize Lucide icons
30
40
  * @return {import("vite").Plugin}
31
41
  */
32
- export const plugin = () => ({
33
- name: "vite-plugin-lucide-preprocess",
34
- enforce: "pre",
35
- transform: (code, path) => {
36
- if (ignoredPaths.some(p => path.includes(p))) {
37
- return;
42
+ export function plugin() {
43
+ return {
44
+ name: "vite-plugin-lucide-preprocess",
45
+ enforce: "pre",
46
+ transform: (code, path) => {
47
+ if (ignoredPaths.some(p => path.includes(p)))
48
+ return;
49
+ return {
50
+ code: code.replace(importsMatcher,
51
+ /**
52
+ * @param _ The whole matched string
53
+ * @param initialSpacing {string} The spacing before the matched import statement
54
+ * @param modulesStr {string} The imported icons as a raw string
55
+ * @param quote {string} The quote used in the import statement (either ' or ")
56
+ * @param framework {string} The framework the icons are imported for
57
+ * @param lineEnding {string} The end of the line of the matched import statement (often a semicolon)
58
+ * @return The optimized import statement(s)
59
+ */
60
+ (_, initialSpacing, modulesStr, quote, framework, lineEnding) => {
61
+ const [modules, types] = rawModulesToLists(modulesStr);
62
+ const moduleImports = modules
63
+ .map(m => `${initialSpacing}import ${m} from ${quote}lucide-${framework}/icons/${iconCompToDashed(m)}${quote}${lineEnding.trimEnd()}`)
64
+ .join(initialSpacing.includes("\n") ? "" : "\n");
65
+ const typesImport = `${initialSpacing}import type { ${types.join(", ")} } from ${quote}lucide-${framework}${quote}${lineEnding.trimEnd()}`;
66
+ return [
67
+ types.length ? typesImport : undefined,
68
+ modules.length ? moduleImports : undefined
69
+ ]
70
+ .filter(Boolean)
71
+ .join(initialSpacing.includes("\n") ? "" : "\n");
72
+ })
73
+ };
38
74
  }
39
- return {
40
- code: code.replace(importsMatcher,
41
- /**
42
- * @param _ The whole matched string
43
- * @param initialSpacing {string} The spacing before the matched import statement
44
- * @param modulesStr {string} The imported icons as a raw string
45
- * @param quote {string} The quote used in the import statement (either ' or ")
46
- * @param framework {string} The framework the icons are imported for
47
- * @param lineEnding {string} The end of the line of the matched import statement (often a semicolon)
48
- * @return The optimized import statement(s)
49
- */
50
- (_, initialSpacing, modulesStr, quote, framework, lineEnding) => {
51
- return rawModulesToModulesList(modulesStr)
52
- .map(m => `${initialSpacing}import ${m} from ${quote}lucide-${framework}/icons/${iconCompToDashed(m)}${quote}${lineEnding.trimEnd()}`)
53
- .join("\n");
54
- })
55
- };
56
- }
57
- });
75
+ };
76
+ }
58
77
  //# sourceMappingURL=plugin.js.map
@@ -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;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,UAAU;IACjD,OAAO,UAAU;SACf,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,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAS;IACzC,OAAO,CACN,SAAS;SACP,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;QACtF,oBAAoB;SACnB,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,wBAAwB;SACvB,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,E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,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-lucide-preprocess",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "author": {
5
5
  "url": "https://github.com/WarningImHack3r",
6
6
  "name": "WarningImHack3r"
@@ -31,11 +31,11 @@
31
31
  "vite": "^5"
32
32
  },
33
33
  "devDependencies": {
34
- "lucide-svelte": "^0.427.0",
34
+ "lucide-svelte": "^0.428.0",
35
35
  "prettier": "^3.3.3",
36
- "publint": "^0.2.9",
36
+ "publint": "^0.2.10",
37
37
  "typescript": "^5.5.4",
38
- "vite": "^5.4.0",
38
+ "vite": "^5.4.1",
39
39
  "vitest": "^2.0.5"
40
40
  },
41
41
  "main": "./dist/index.js",