Skip to content

Commit

Permalink
chore: react/utils build setting update (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssi02014 authored Jan 25, 2025
1 parent 0b511eb commit 8f28e1b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 42 deletions.
40 changes: 23 additions & 17 deletions packages/react/build.utils.mjs
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
const PATH_PREFIX_MAP = {
_internal: '_internal',
utils: 'utils',
components: 'components',
hooks: 'hooks',
};

const getEntryFileNames = (name, format, path) => {
const cleanName = name.replace(`${path}-`, '');
return `${path}/${cleanName}/index.${format}`;
};

export const getFormatEntryFileNames = (chunkInfo, format) => {
const prefixMap = {
_internal: '_internal',
utils: 'utils',
components: 'components',
hooks: 'hooks',
};

for (const [key, value] of Object.entries(prefixMap)) {
if (chunkInfo.name === `${key}-index`) {
const { name } = chunkInfo;

for (const [key, value] of Object.entries(PATH_PREFIX_MAP)) {
// 각 모듈의 index
if (name === `${key}-index`) {
return `${key}/index.${format}`;
}

if (chunkInfo.name.startsWith(value)) {
return getEntryFileNames(chunkInfo.name, format, key);
// 기본 모듈
if (name.startsWith(value)) {
return getEntryFileNames(name, format, key);
}
}

return `[name].${format}`; // 기본 파일 이름
// root index
return `[name].${format}`;
};

export const getSubEntryMap = (keys, path) => {
const getEntryExtension = path === 'components' ? 'tsx' : 'ts';

return keys.reduce((acc, entry) => {
acc[`${path}-${entry}`] = `./src/${path}/${
entry === 'index'
? 'index.ts'
: `${entry}/index.${path === 'components' ? 'tsx' : 'ts'}`
}`;
const entryPath =
entry === 'index' ? 'index.ts' : `${entry}/index.${getEntryExtension}`;

acc[`${path}-${entry}`] = `./src/${path}/${entryPath}`;
return acc;
}, {});
};
54 changes: 29 additions & 25 deletions packages/utils/build.utils.mjs
Original file line number Diff line number Diff line change
@@ -1,44 +1,48 @@
const PATH_PREFIX_MAP = {
array: 'array',
clipboard: 'clipboard',
common: 'common',
date: 'date',
device: 'device',
file: 'file',
formatter: 'formatter',
math: 'math',
object: 'object',
regex: 'regex',
storage: 'storage',
string: 'string',
style: 'style',
validator: 'validator',
};

const getEntryFileNames = (name, format, path) => {
const cleanName = name.replace(`${path}-`, '');
return `${path}/${cleanName}/index.${format}`;
};

export const getFormatEntryFileNames = (chunkInfo, format) => {
const prefixMap = {
array: 'array',
clipboard: 'clipboard',
common: 'common',
date: 'date',
device: 'device',
file: 'file',
formatter: 'formatter',
math: 'math',
object: 'object',
regex: 'regex',
storage: 'storage',
string: 'string',
style: 'style',
validator: 'validator',
};
const { name } = chunkInfo;

for (const [key, value] of Object.entries(prefixMap)) {
if (chunkInfo.name === `${key}-index`) {
for (const [key, value] of Object.entries(PATH_PREFIX_MAP)) {
// 각 모듈의 index
if (name === `${key}-index`) {
return `${key}/index.${format}`;
}

if (chunkInfo.name.startsWith(value)) {
return getEntryFileNames(chunkInfo.name, format, key);
// 기본 모듈
if (name.startsWith(value)) {
return getEntryFileNames(name, format, key);
}
}

return `[name].${format}`; // 기본 파일 이름
// root index
return `[name].${format}`;
};

export const getSubEntryMap = (keys, path) => {
return keys.reduce((acc, entry) => {
acc[`${path}-${entry}`] = `./src/${path}/${
entry === 'index' ? 'index.ts' : `${entry}/index.ts`
}`;
const entryPath = entry === 'index' ? 'index.ts' : `${entry}/index.ts`;

acc[`${path}-${entry}`] = `./src/${path}/${entryPath}`;
return acc;
}, {});
};

0 comments on commit 8f28e1b

Please sign in to comment.