Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lucide-svelte): Aliased imports for direct imports #2584

Merged
merged 7 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/lucide-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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=.ts --pretty=false",
"build:package": "svelte-package --input ./src",
"build:license": "node ./scripts/appendBlockComments.mjs",
"test": "pnpm build:icons && vitest run",
Expand Down
2 changes: 1 addition & 1 deletion packages/lucide-svelte/scripts/license.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pkg from '../package.json' assert { type: 'json' };
import pkg from '../package.json' with { type: 'json' };

export function getJSBanner() {
return `/**
Expand Down
2 changes: 1 addition & 1 deletion packages/lucide/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
10 changes: 8 additions & 2 deletions tools/build-icons/building/aliases/generateAliasesFiles.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default async function generateAliasesFiles({
aliasImportFileExtension,
aliasNamesOnly = false,
separateAliasesFile = false,
separateAliasesFileExtension,
showLog = true,
}) {
const iconsDistDirectory = path.join(outputDirectory, `icons`);
Expand Down Expand Up @@ -96,8 +97,13 @@ export default async function generateAliasesFiles({
: '';

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');
}
Expand Down
13 changes: 13 additions & 0 deletions tools/build-icons/building/generateIconFiles.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export default ({
template,
showLog = true,
iconFileExtension = '.js',
separateIconFileExport = false,
separateIconFileExportExtension,
pretty = true,
iconsDir,
iconMetaData,
Expand Down Expand Up @@ -46,6 +48,7 @@ export default ({
deprecated,
deprecationReason,
});

const output = pretty
? prettier.format(elementTemplate, {
singleQuote: true,
Expand All @@ -56,6 +59,16 @@ 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)
Expand Down
6 changes: 6 additions & 0 deletions tools/build-icons/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const {
aliasNamesOnly = false,
withDynamicImports = false,
separateAliasesFile = false,
separateAliasesFileExtension = undefined,
separateIconFileExport = false,
separateIconFileExportExtension = undefined,
aliasesFileExtension = '.js',
aliasImportFileExtension = '',
pretty = true,
Expand All @@ -59,6 +62,8 @@ async function buildIcons() {
template: iconFileTemplate,
showLog: !silent,
iconFileExtension,
separateIconFileExport,
separateIconFileExportExtension,
pretty: JSON.parse(pretty),
iconsDir: ICONS_DIR,
iconMetaData,
Expand All @@ -75,6 +80,7 @@ async function buildIcons() {
exportModuleNameCasing,
aliasImportFileExtension,
separateAliasesFile,
separateAliasesFileExtension,
showLog: !silent,
});
}
Expand Down
2 changes: 1 addition & 1 deletion tools/build-icons/utils/getAliases.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}),
);
Expand Down
2 changes: 1 addition & 1 deletion tools/build-icons/utils/getIconMetaData.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}),
);
Expand Down
Loading