From 6aea9613fb50f3618ae6bbefcee9e713cce3508d Mon Sep 17 00:00:00 2001 From: Eric Fennis Date: Tue, 15 Oct 2024 06:13:16 +0200 Subject: [PATCH 1/4] Add way to import aliased icons directly --- packages/lucide-svelte/package.json | 5 +++-- packages/lucide-svelte/scripts/license.mjs | 2 +- packages/lucide/rollup.config.mjs | 2 +- tools/build-icons/building/generateAliasesFile.mjs | 5 +++-- tools/build-icons/building/generateIconFiles.mjs | 10 ++++++++++ tools/build-icons/cli.mjs | 6 ++++++ tools/build-icons/utils/getAliases.mjs | 2 +- tools/build-icons/utils/getIconMetaData.mjs | 2 +- 8 files changed, 26 insertions(+), 8 deletions(-) diff --git a/packages/lucide-svelte/package.json b/packages/lucide-svelte/package.json index d231fb36f8f..27437c82387 100644 --- a/packages/lucide-svelte/package.json +++ b/packages/lucide-svelte/package.json @@ -36,7 +36,8 @@ }, "./icons/*": { "types": "./dist/icons/*.svelte.d.ts", - "svelte": "./dist/icons/*.svelte" + "svelte": "./dist/icons/*.js", + "default": "./dist/icons/*.js" } }, "typings": "dist/lucide-svelte.d.ts", @@ -48,7 +49,7 @@ "build": "pnpm clean && pnpm copy:license && pnpm build:icons && pnpm build:package && pnpm build:license", "copy:license": "cp ../../LICENSE ./LICENSE", "clean": "rm -rf dist && rm -rf stats && rm -rf ./src/icons/*.svelte && rm -f index.js", - "build:icons": "build-icons --output=./src --templateSrc=./scripts/exportTemplate.mjs --exportFileName=index.ts --iconFileExtension=.svelte --importImportFileExtension=.svelte --withAliases --aliasesFileExtension=.ts --aliasImportFileExtension=.svelte --pretty=false", + "build:icons": "build-icons --output=./src --templateSrc=./scripts/exportTemplate.mjs --exportFileName=index.ts --iconFileExtension=.svelte --importImportFileExtension=.svelte --separateIconFileExport --separateIconFileExportExtension=.ts --withAliases --aliasesFileExtension=.ts --separateAliasesFile --separateAliasesFileExtension=.ts --aliasImportFileExtension=.svelte --pretty=false", "build:package": "svelte-package --input ./src", "build:license": "node ./scripts/appendBlockComments.mjs", "test": "pnpm build:icons && vitest run", diff --git a/packages/lucide-svelte/scripts/license.mjs b/packages/lucide-svelte/scripts/license.mjs index 3c39a02b6f2..3ef4f0306c8 100644 --- a/packages/lucide-svelte/scripts/license.mjs +++ b/packages/lucide-svelte/scripts/license.mjs @@ -1,4 +1,4 @@ -import pkg from '../package.json' assert { type: 'json' }; +import pkg from '../package.json' with { type: 'json' }; export function getJSBanner() { return `/** diff --git a/packages/lucide/rollup.config.mjs b/packages/lucide/rollup.config.mjs index 3d64d9d0e59..a4840c024b5 100644 --- a/packages/lucide/rollup.config.mjs +++ b/packages/lucide/rollup.config.mjs @@ -1,7 +1,7 @@ import plugins from '@lucide/rollup-plugins'; import replace from '@rollup/plugin-replace'; import dts from 'rollup-plugin-dts'; -import pkg from './package.json' assert { type: 'json' }; +import pkg from './package.json' with { type: 'json' }; const outputFileName = pkg.name; const outputDir = 'dist'; diff --git a/tools/build-icons/building/generateAliasesFile.mjs b/tools/build-icons/building/generateAliasesFile.mjs index 75556949114..dfce8ba0c7d 100644 --- a/tools/build-icons/building/generateAliasesFile.mjs +++ b/tools/build-icons/building/generateAliasesFile.mjs @@ -27,6 +27,7 @@ export default async function generateAliasesFile({ aliasImportFileExtension, aliasNamesOnly = false, separateAliasesFile = false, + separateAliasesFileExtension, showLog = true, }) { const iconsDistDirectory = path.join(outputDirectory, `icons`); @@ -82,8 +83,8 @@ export default async function generateAliasesFile({ : ''; if (separateAliasesFile) { - const output = `export { default } from "./${iconName}"`; - const location = path.join(iconsDistDirectory, `${alias.name}${iconFileExtension}`); + const output = `export { default } from "./${iconName}${separateAliasesFileExtension ? iconFileExtension : ''}";\n`; + const location = path.join(iconsDistDirectory, `${alias.name}${separateAliasesFileExtension ?? iconFileExtension}`); await fs.promises.writeFile(location, output, 'utf-8'); } diff --git a/tools/build-icons/building/generateIconFiles.mjs b/tools/build-icons/building/generateIconFiles.mjs index 63268548c66..4873e030dd6 100644 --- a/tools/build-icons/building/generateIconFiles.mjs +++ b/tools/build-icons/building/generateIconFiles.mjs @@ -10,6 +10,8 @@ export default ({ template, showLog = true, iconFileExtension = '.js', + separateIconFileExport = false, + separateIconFileExportExtension, pretty = true, iconsDir, iconMetaData, @@ -46,6 +48,7 @@ export default ({ deprecated, deprecationReason, }); + const output = pretty ? prettier.format(elementTemplate, { singleQuote: true, @@ -56,6 +59,13 @@ export default ({ : elementTemplate; await fs.promises.writeFile(location, output, 'utf-8'); + + if (separateIconFileExport) { + const output = `export { default } from "./${iconName}${iconFileExtension}";\n`; + const location = path.join(iconsDistDirectory, `${iconName}${separateIconFileExportExtension ?? iconFileExtension}`); + + await fs.promises.writeFile(location, output, 'utf-8'); + } }); Promise.all(writeIconFiles) diff --git a/tools/build-icons/cli.mjs b/tools/build-icons/cli.mjs index 3c1f60e376c..1b1e70fcc12 100755 --- a/tools/build-icons/cli.mjs +++ b/tools/build-icons/cli.mjs @@ -34,6 +34,9 @@ const { aliasNamesOnly = false, withDynamicImports = false, separateAliasesFile = false, + separateAliasesFileExtension = undefined, + separateIconFileExport = false, + separateIconFileExportExtension = undefined, aliasesFileExtension = '.js', aliasImportFileExtension = '', pretty = true, @@ -59,6 +62,8 @@ async function buildIcons() { template: iconFileTemplate, showLog: !silent, iconFileExtension, + separateIconFileExport, + separateIconFileExportExtension, pretty: JSON.parse(pretty), iconsDir: ICONS_DIR, iconMetaData, @@ -75,6 +80,7 @@ async function buildIcons() { exportModuleNameCasing, aliasImportFileExtension, separateAliasesFile, + separateAliasesFileExtension, showLog: !silent, }); } diff --git a/tools/build-icons/utils/getAliases.mjs b/tools/build-icons/utils/getAliases.mjs index 342741acdd6..1d469fc06b5 100644 --- a/tools/build-icons/utils/getAliases.mjs +++ b/tools/build-icons/utils/getAliases.mjs @@ -5,7 +5,7 @@ async function getAliases(iconDirectory) { const iconJsons = readSvgDirectory(iconDirectory, '.json'); const aliasesEntries = await Promise.all( iconJsons.map(async (jsonFile) => { - const file = await import(path.join(iconDirectory, jsonFile), { assert: { type: 'json' } }); + const file = await import(path.join(iconDirectory, jsonFile), { with: { type: 'json' } }); return [path.basename(jsonFile, '.json'), file.default]; }), ); diff --git a/tools/build-icons/utils/getIconMetaData.mjs b/tools/build-icons/utils/getIconMetaData.mjs index 7c8c149caee..e03bdaa0278 100644 --- a/tools/build-icons/utils/getIconMetaData.mjs +++ b/tools/build-icons/utils/getIconMetaData.mjs @@ -6,7 +6,7 @@ async function getIconMetaData(iconDirectory) { const aliasesEntries = await Promise.all( iconJsons.map(async (jsonFile) => { /** eslint-disable */ - const file = await import(path.join(iconDirectory, jsonFile), { assert: { type: 'json' } }); + const file = await import(path.join(iconDirectory, jsonFile), { with: { type: 'json' } }); return [path.basename(jsonFile, '.json'), file.default]; }), ); From d0837991b8a303ad045c9f46c1eefbbc09049ec5 Mon Sep 17 00:00:00 2001 From: Eric Fennis Date: Tue, 5 Nov 2024 09:26:47 +0100 Subject: [PATCH 2/4] Format files --- .../building/generateAliasesFile.mjs | 23 +++++++++++-------- .../building/generateIconFiles.mjs | 5 +++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/tools/build-icons/building/generateAliasesFile.mjs b/tools/build-icons/building/generateAliasesFile.mjs index dfce8ba0c7d..e6944ae0404 100644 --- a/tools/build-icons/building/generateAliasesFile.mjs +++ b/tools/build-icons/building/generateAliasesFile.mjs @@ -9,7 +9,7 @@ const getImportString = ( iconName, aliasImportFileExtension, deprecated, - deprecationReason = '', + deprecationReason = '' ) => deprecated ? `export {\n` + @@ -66,7 +66,7 @@ export default async function generateAliasesFile({ importString += getImportString( `Lucide${componentName}`, iconName, - aliasImportFileExtension, + aliasImportFileExtension ); } @@ -83,8 +83,13 @@ export default async function generateAliasesFile({ : ''; if (separateAliasesFile) { - const output = `export { default } from "./${iconName}${separateAliasesFileExtension ? iconFileExtension : ''}";\n`; - const location = path.join(iconsDistDirectory, `${alias.name}${separateAliasesFileExtension ?? iconFileExtension}`); + const output = `export { default } from "./${iconName}${ + separateAliasesFileExtension ? iconFileExtension : '' + }";\n`; + const location = path.join( + iconsDistDirectory, + `${alias.name}${separateAliasesFileExtension ?? iconFileExtension}` + ); await fs.promises.writeFile(location, output, 'utf-8'); } @@ -101,7 +106,7 @@ export default async function generateAliasesFile({ exportFileIcon, aliasImportFileExtension, alias.deprecated, - deprecationReason, + deprecationReason ); if (!aliasNamesOnly) { @@ -110,7 +115,7 @@ export default async function generateAliasesFile({ exportFileIcon, aliasImportFileExtension, alias.deprecated, - deprecationReason, + deprecationReason ); importString += getImportString( @@ -118,15 +123,15 @@ export default async function generateAliasesFile({ exportFileIcon, aliasImportFileExtension, alias.deprecated, - deprecationReason, + deprecationReason ); } - }), + }) ); } appendFile(importString, fileName, outputDirectory); - }), + }) ); appendFile('\n', fileName, outputDirectory); diff --git a/tools/build-icons/building/generateIconFiles.mjs b/tools/build-icons/building/generateIconFiles.mjs index 4873e030dd6..9ca92aae981 100644 --- a/tools/build-icons/building/generateIconFiles.mjs +++ b/tools/build-icons/building/generateIconFiles.mjs @@ -62,7 +62,10 @@ export default ({ if (separateIconFileExport) { const output = `export { default } from "./${iconName}${iconFileExtension}";\n`; - const location = path.join(iconsDistDirectory, `${iconName}${separateIconFileExportExtension ?? iconFileExtension}`); + const location = path.join( + iconsDistDirectory, + `${iconName}${separateIconFileExportExtension ?? iconFileExtension}` + ); await fs.promises.writeFile(location, output, 'utf-8'); } From f8c5073bb016cc2d9c849ac14af4b3d8bff3080c Mon Sep 17 00:00:00 2001 From: Eric Fennis Date: Wed, 6 Nov 2024 10:35:17 +0100 Subject: [PATCH 3/4] Fix tests --- packages/lucide-svelte/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/lucide-svelte/package.json b/packages/lucide-svelte/package.json index 1fbc482b359..ee45d8d6693 100644 --- a/packages/lucide-svelte/package.json +++ b/packages/lucide-svelte/package.json @@ -49,7 +49,7 @@ "build": "pnpm clean && pnpm copy:license && pnpm build:icons && pnpm build:package && pnpm build:license", "copy:license": "cp ../../LICENSE ./LICENSE", "clean": "rm -rf dist && rm -rf stats && rm -rf ./src/icons/*.svelte && rm -f index.js", - "build:icons": "build-icons --output=./src --templateSrc=./scripts/exportTemplate.mjs --exportFileName=index.ts --iconFileExtension=.svelte --importImportFileExtension=.svelte --separateIconFileExport --separateIconFileExportExtension=.ts --withAliases --aliasesFileExtension=.ts --separateAliasesFile --separateAliasesFileExtension=.ts --aliasImportFileExtension=.svelte --pretty=false", + "build:icons": "build-icons --output=./src --templateSrc=./scripts/exportTemplate.mjs --exportFileName=index.ts --iconFileExtension=.svelte --importImportFileExtension=.svelte --separateIconFileExport --separateIconFileExportExtension=.ts --withAliases --aliasesFileExtension=.ts --separateAliasesFile --separateAliasesFileExtension=.ts --aliasImportFileExtension=.ts --pretty=false", "build:package": "svelte-package --input ./src", "build:license": "node ./scripts/appendBlockComments.mjs", "test": "pnpm build:icons && vitest run", From 19e165958bc979bdd1afb21521f1aa802ce8977d Mon Sep 17 00:00:00 2001 From: Eric Fennis Date: Wed, 6 Nov 2024 11:00:06 +0100 Subject: [PATCH 4/4] Format files --- .../build-icons/building/generateAliasesFile.mjs | 16 ++++++++-------- tools/build-icons/building/generateIconFiles.mjs | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/build-icons/building/generateAliasesFile.mjs b/tools/build-icons/building/generateAliasesFile.mjs index e6944ae0404..817bde6538d 100644 --- a/tools/build-icons/building/generateAliasesFile.mjs +++ b/tools/build-icons/building/generateAliasesFile.mjs @@ -9,7 +9,7 @@ const getImportString = ( iconName, aliasImportFileExtension, deprecated, - deprecationReason = '' + deprecationReason = '', ) => deprecated ? `export {\n` + @@ -66,7 +66,7 @@ export default async function generateAliasesFile({ importString += getImportString( `Lucide${componentName}`, iconName, - aliasImportFileExtension + aliasImportFileExtension, ); } @@ -88,7 +88,7 @@ export default async function generateAliasesFile({ }";\n`; const location = path.join( iconsDistDirectory, - `${alias.name}${separateAliasesFileExtension ?? iconFileExtension}` + `${alias.name}${separateAliasesFileExtension ?? iconFileExtension}`, ); await fs.promises.writeFile(location, output, 'utf-8'); @@ -106,7 +106,7 @@ export default async function generateAliasesFile({ exportFileIcon, aliasImportFileExtension, alias.deprecated, - deprecationReason + deprecationReason, ); if (!aliasNamesOnly) { @@ -115,7 +115,7 @@ export default async function generateAliasesFile({ exportFileIcon, aliasImportFileExtension, alias.deprecated, - deprecationReason + deprecationReason, ); importString += getImportString( @@ -123,15 +123,15 @@ export default async function generateAliasesFile({ exportFileIcon, aliasImportFileExtension, alias.deprecated, - deprecationReason + deprecationReason, ); } - }) + }), ); } appendFile(importString, fileName, outputDirectory); - }) + }), ); appendFile('\n', fileName, outputDirectory); diff --git a/tools/build-icons/building/generateIconFiles.mjs b/tools/build-icons/building/generateIconFiles.mjs index 9ca92aae981..ef935fa4914 100644 --- a/tools/build-icons/building/generateIconFiles.mjs +++ b/tools/build-icons/building/generateIconFiles.mjs @@ -64,7 +64,7 @@ export default ({ const output = `export { default } from "./${iconName}${iconFileExtension}";\n`; const location = path.join( iconsDistDirectory, - `${iconName}${separateIconFileExportExtension ?? iconFileExtension}` + `${iconName}${separateIconFileExportExtension ?? iconFileExtension}`, ); await fs.promises.writeFile(location, output, 'utf-8');