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

Fixed export maps, types, and packaging for lucide-svelte #1707

Merged
merged 12 commits into from
Dec 24, 2023
Merged
1 change: 1 addition & 0 deletions packages/lucide-svelte/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
src/icons/*.svelte
.svelte-kit
27 changes: 11 additions & 16 deletions packages/lucide-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@
],
"author": "Eric Fennis",
"type": "module",
"main": "dist/esm/lucide-svelte.js",
"main": "dist/lucide-svelte.js",
"exports": {
".": {
"svelte": "./dist/svelte/lucide-svelte.js",
"types": "./dist/lucide-svelte.d.ts",
"default": "./dist/esm/lucide-svelte.js"
"svelte": "./dist/lucide-svelte.js",
"default": "./dist/lucide-svelte.js"
},
"./icons": {
"svelte": "./dist/svelte/icons/index.js",
"default": "./dist/esm/icons/index.js"
"types": "./dist/lucide-svelte.d.ts",
"svelte": "./dist/lucide-svelte.js"
},
"./icons/*": {
"svelte": "./dist/svelte/icons/*.svelte",
"default": "./dist/esm/icons/*.js"
"types": "./dist/icons/*.svelte.d.ts",
"svelte": "./dist/icons/*.svelte"
}
},
"typings": "dist/lucide-svelte.d.ts",
Expand All @@ -45,31 +45,26 @@
"dist"
],
"scripts": {
"build": "pnpm clean && pnpm copy:license && pnpm build:icons && pnpm build:bundles && pnpm build:strip && pnpm build:types",
"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:types": "node ./scripts/buildTypes.mjs",
"build:bundles": "rollup -c ./rollup.config.mjs",
"build:strip": "svelte-strip strip src/ dist/svelte",
"build:package": "svelte-package --input ./src",
"build:license": "node ./scripts/addLicense.mjs",
"test": "vitest run",
"version": "pnpm version --git-tag-version=false"
},
"devDependencies": {
"@lucide/build-icons": "workspace:*",
"@lucide/rollup-plugins": "workspace:*",
"@rollup/plugin-node-resolve": "^15.1.0",
"@sveltejs/package": "^2.2.3",
"@sveltejs/vite-plugin-svelte": "^2.4.2",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/svelte": "^4.0.2",
"@tsconfig/svelte": "^5.0.0",
"jsdom": "^20.0.3",
"rollup": "^3.25.3",
"rollup-plugin-svelte": "^7.1.6",
"svelte": "^4.0.1",
"svelte-check": "^3.4.4",
"svelte-preprocess": "^5.0.4",
"svelte-strip": "^2.0.0",
"typescript": "^5.1.6",
"vite": "^4.4.12",
"vitest": "^0.32.2"
Expand Down
84 changes: 0 additions & 84 deletions packages/lucide-svelte/rollup.config.mjs

This file was deleted.

52 changes: 52 additions & 0 deletions packages/lucide-svelte/scripts/addLicense.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { getCurrentDirPath } from '../../../scripts/helpers.mjs';
import { lstatSync } from 'fs';
import { readdir, readFile, writeFile } from 'fs/promises';
import path from 'path';
import pkg from '../package.json' assert { type: 'json' };

const BANNER = `${pkg.name} v${pkg.version} - ${pkg.license}`;
ericfennis marked this conversation as resolved.
Show resolved Hide resolved

const currentDir = getCurrentDirPath(import.meta.url);
const targetDirectory = path.join(currentDir, '../dist');

const files = await readdir(targetDirectory, {
recursive: true,
encoding: 'utf-8',
});

for (const file of files) {
const filepath = path.join(targetDirectory, file);
const filestat = lstatSync(filepath);

if (filestat.isFile() === false || filestat.isDirectory()) continue;

const contents = await readFile(filepath, { encoding: 'utf-8' });
const ext = path.extname(filepath);
let license;

if (/\.(js|mjs|cjs|ts)/.test(ext)) {
license = getJSBanner();
}

if (/\.svelte/.test(ext)) {
license = getSvelteBanner();
}

if (license) {
await writeFile(filepath, license + contents, { encoding: 'utf-8' });
}
}

function getJSBanner() {
return `/**
* ${BANNER}
*/
\n`;
}

function getSvelteBanner() {
return `<!--
${BANNER}
-->
\n`;
}
4 changes: 3 additions & 1 deletion packages/lucide-svelte/scripts/exportTemplate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ export default ({ iconName, children }) =>
`\
<script lang="ts">
import Icon from '../Icon.svelte';
import type { IconNode } from '../types';
import type { IconNode, IconProps } from '../types.js';

type $$Props = IconProps;

const iconNode: IconNode = ${JSON.stringify(children)};
</script>
Expand Down
8 changes: 4 additions & 4 deletions packages/lucide-svelte/src/lucide-svelte.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './icons';
export * as icons from './icons';
export * from './aliases';
export { default as defaultAttributes } from './defaultAttributes'
export * from './icons/index.js';
export * as icons from './icons/index.js';
export * from './aliases.js';
export { default as defaultAttributes } from './defaultAttributes.js';
16 changes: 12 additions & 4 deletions packages/lucide-svelte/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
/// <reference types="svelte" />
/// <reference types="svelte2tsx/svelte-jsx" />
import type { SVGAttributes, SvelteHTMLElements } from 'svelte/elements';

export type Attrs = svelte.JSX.SVGProps<SVGSVGElement>
export type IconNode = [elementName: keyof svelte.JSX.IntrinsicElements, attrs: Attrs][]
type SVGAttrs = SVGAttributes<SVGSVGElement>;

export type IconNode = [elementName: keyof SvelteHTMLElements, attrs: SVGAttrs][];

export interface IconProps extends SVGAttrs {
color?: string;
size?: number | string;
strokeWidth?: number | string;
absoluteStrokeWidth?: boolean;
class?: string;
}
Loading
Loading