From 6c3284e1c3d883a3db7250a7afa6077fcee8bc2e Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 16 Mar 2022 09:50:12 +0200 Subject: [PATCH] Retrieve list of files to build from package.json exports in utils --- packages/utils/build.config.ts | 65 ++++++++++++---------------------- 1 file changed, 23 insertions(+), 42 deletions(-) diff --git a/packages/utils/build.config.ts b/packages/utils/build.config.ts index f3e99b2..6d81d11 100644 --- a/packages/utils/build.config.ts +++ b/packages/utils/build.config.ts @@ -1,50 +1,31 @@ -import { defineBuildConfig } from 'unbuild' +import { BuildEntry, defineBuildConfig } from 'unbuild'; +import packageJSON from './package.json'; + +const entries: BuildEntry[] = []; +const exportsList = packageJSON['exports']; +const match = './lib/'; + +Object.keys(exportsList).forEach((key) => { + if (key.slice(0, match.length) !== match) { + return; + } + + const importValue = exportsList[key]['import']; + if (importValue === key + '.mjs') { + const name = key.slice(match.length); + entries.push({ + input: 'src/' + name, + name, + }); + } +}); export default defineBuildConfig({ outDir: './lib', - entries: [ - { input: 'src/colors/types', name: 'colors/types' }, - { input: 'src/colors/keywords', name: 'colors/keywords' }, - { input: 'src/colors/index', name: 'colors/index' }, - { input: 'src/customisations/bool', name: 'customisations/bool' }, - { input: 'src/customisations/compare', name: 'customisations/compare' }, - { input: 'src/customisations/index', name: 'customisations/index' }, - { input: 'src/customisations/rotate', name: 'customisations/rotate' }, - { input: 'src/customisations/shorthand', name: 'customisations/shorthand' }, - { input: 'src/icon/index', name: 'icon/index' }, - { input: 'src/icon/merge', name: 'icon/merge' }, - { input: 'src/icon/name', name: 'icon/name' }, - { input: 'src/icon-set/convert-info', name: 'icon-set/convert-info' }, - { input: 'src/icon-set/expand', name: 'icon-set/expand' }, - { input: 'src/icon-set/get-icon', name: 'icon-set/get-icon' }, - { input: 'src/icon-set/get-icons', name: 'icon-set/get-icons' }, - { input: 'src/icon-set/minify', name: 'icon-set/minify' }, - { input: 'src/icon-set/parse', name: 'icon-set/parse' }, - { input: 'src/icon-set/validate', name: 'icon-set/validate' }, - { input: 'src/loader/custom', name: 'loader/custom' }, - { input: 'src/loader/fs', name: 'loader/fs' }, - { input: 'src/loader/install-pkg', name: 'loader/install-pkg' }, - { input: 'src/loader/loader', name: 'loader/loader' }, - { input: 'src/loader/modern', name: 'loader/modern' }, - { input: 'src/loader/node-loader', name: 'loader/node-loader' }, - { input: 'src/loader/node-loaders', name: 'loader/node-loaders' }, - { input: 'src/loader/types', name: 'loader/types' }, - { input: 'src/loader/utils', name: 'loader/utils' }, - { input: 'src/loader/warn', name: 'loader/warn' }, - { input: 'src/misc/strings', name: 'misc/strings' }, - { input: 'src/svg/build', name: 'svg/build' }, - { input: 'src/svg/encode-svg-for-css', name: 'svg/encode-svg-for-css' }, - { input: 'src/svg/id', name: 'svg/id' }, - { input: 'src/svg/size', name: 'svg/size' }, - { input: 'src/index', name: 'index' }, - ], + entries, clean: true, declaration: true, - externals: [ - 'local-pkg', - 'fs', - ], rollup: { emitCJS: true, }, -}) +});