Skip to content

Commit

Permalink
💚 chore: fix CI Build
Browse files Browse the repository at this point in the history
  • Loading branch information
futjesus committed Nov 14, 2024
1 parent 54af7e6 commit a30764e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 16 deletions.
14 changes: 11 additions & 3 deletions lib/components/Autocomplete/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
useRef,
} from 'react';

import { useTheme } from '../../contexts';

import { useAutocomplete } from './hooks';
import { List } from './components/List';
import { AutocompleteProps } from './Autocomplete.types';
Expand All @@ -32,6 +34,8 @@ const Autocomplete = forwardRef<HTMLInputElement, AutocompleteProps>(
const wrapperRef = useRef<ElementRef<'div'>>(null);
const inputRef = useRef<ElementRef<'input'>>(null);
const id = useId();
const { theme: contextTheme } = useTheme();
const inheritTheme = theme ?? contextTheme;

useImperativeHandle(ref, () => inputRef.current!, [inputRef]);

Expand All @@ -48,7 +52,7 @@ const Autocomplete = forwardRef<HTMLInputElement, AutocompleteProps>(
<label
htmlFor={name ?? id}
className={labelVariants({
theme,
theme: inheritTheme,
variant,
className: labelClassName,
})}
Expand All @@ -64,7 +68,11 @@ const Autocomplete = forwardRef<HTMLInputElement, AutocompleteProps>(
name={name}
role="combobox"
autoComplete={autoComplete}
className={autocompleteVariants({ theme, variant, className })}
className={autocompleteVariants({
theme: inheritTheme,
variant,
className,
})}
onChange={autocomplete.handleChange}
value={autocomplete.value}
placeholder={placeholder}
Expand All @@ -80,7 +88,7 @@ const Autocomplete = forwardRef<HTMLInputElement, AutocompleteProps>(
placeholder={placeHolderEmptyValues}
placeholderClassName={placeHolderEmptyValuesClassName}
variant={variant}
theme={theme}
theme={inheritTheme}
onClick={autocomplete.handleSelectValue}
/>
</div>
Expand Down
11 changes: 2 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
"files": [
"dist"
],
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/index.js",
"default": "./dist/index.cjs"
}
},
"author": {
"name": "Jesús Manuel Fuentes Trejo",
"email": "me@futjesus.dev",
Expand Down Expand Up @@ -43,17 +36,17 @@
],
"homepage": "https://konstructio.github.io/konstruct-ui",
"scripts": {
"build": "tsc --p ./tsconfig.build.json && tsup",
"build": "tsc --p ./tsconfig.build.json && tsup && cp ./package.json ./dist/package.json && cp ./scripts/generate-exports.js ./dist/generate-exports.js && node ./dist/generate-exports.js",
"build:storybook": "storybook build -o storybook-static && cp -r public/* storybook-static",
"check:exports": "attw --pack . --ignore-rules=cjs-resolves-to-esm",
"check:prettier": "prettier lib --check --config ./.prettierrc",
"check:types": "tsc -p tsconfig.json",
"ci": "npm run build && npm run check:prettier && npm run check:exports && npm run test",
"ci:release": "changeset version && changeset publish",
"deps:update": "npx npm-check-updates --interactive --format group",
"dev": "vite",
"format:prettier": "prettier lib --write './**/*.{js,jsx,ts,tsx}' --config ./.prettierrc",
"lint": "eslint lib --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"local:release": "changeset version && changeset publish",
"prepare": "husky",
"prepublishOnly": "npm run ci",
"preview": "vite preview",
Expand Down
50 changes: 50 additions & 0 deletions scripts/generate-exports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const packageJsonPath = path.resolve(__dirname, './package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));

const distDir = path.resolve(__dirname, '../dist');

const exports = {
'./package.json': './package.json',
'.': {
import: './dist/index.js',
default: './dist/index.cjs',
},
};

function addExports(dir, basePath = '.') {
fs.readdirSync(dir).forEach((file) => {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);

if (stat.isDirectory()) {
addExports(filePath, `${basePath}/${file}`);
} else {
const match = file.match(/^(.*)\.(js|cjs)$/);
if (match) {
const componentName = match[1];
exports[`${basePath}/${componentName}`] = {
import: `./dist/${componentName}.js`,
default: `./dist/${componentName}.cjs`,
};
}
}
});
}

addExports(distDir);

packageJson.exports = exports;
fs.writeFileSync(
packageJsonPath,
JSON.stringify(packageJson, null, 2),
'utf-8',
);

console.log('Campo `exports` actualizado en package.json');
10 changes: 6 additions & 4 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { defineConfig } from 'tsup';
import { resolve } from 'node:path';

export default defineConfig({
entryPoints: [
resolve(__dirname, 'lib/index.ts'),
resolve(__dirname, 'lib/styles.ts'),
entry: [
'!lib/**/*.test.(tsx|ts)',
'!lib/**/*.stories.(tsx|ts)',
'./lib/**/*.(tsx|ts)',
],
format: ['cjs', 'esm'],
dts: true,
outDir: 'dist',
clean: true,
bundle: false,
splitting: true,
});

0 comments on commit a30764e

Please sign in to comment.