MCPcopy Create free account
hub / github.com/formkit/formkit / createBundle

Function createBundle

scripts/bundle.mjs:43–170  ·  view source on GitHub ↗
(pkg, plugin, showLogs = false)

Source from the content-addressed store, hash-verified

41 * @param {string} format the format to create (cjs, esm, umd, etc...)
42 */
43export async function createBundle(pkg, plugin, showLogs = false) {
44 const __filename = fileURLToPath(import.meta.url)
45 const __dirname = dirname(__filename)
46 const rootDir = resolve(__dirname, `../packages/${pkg}`)
47 const packages = readdirSync(resolve(__dirname, '../packages')).filter(
48 (p) => !p.startsWith('.')
49 )
50
51 const tsconfig = JSON.parse(
52 readFileSync(resolve(__dirname, '../tsconfig.json'), 'utf8')
53 )
54 if (!pkg) {
55 throw new Error('PKG env var is required to build.')
56 }
57
58 if (!packages.includes(pkg)) {
59 throw new Error(`${pkg} is not a valid package name.`)
60 }
61
62 function createEntry() {
63 const entry = resolve(rootDir, `src/${plugin ? plugin + '/' : ''}index.ts`)
64 return entry
65 }
66
67 function createOutdir() {
68 const entry = resolve(rootDir, 'dist' + (plugin ? '/' + plugin : ''))
69 return entry
70 }
71
72 function createFormats() {
73 if (pkg === 'vue') {
74 return ['iife', 'cjs', 'esm', 'esm']
75 }
76 return ['cjs', 'esm', 'esm']
77 }
78
79 let devBuild = false
80
81 const outDir = createOutdir()
82
83 const pureFunctions = ['createMessage']
84
85 if (pkg === 'inputs') {
86 pureFunctions.push(
87 ...readdirSync(resolve(__dirname, '../packages/inputs/src/sections')).map(
88 (fileName) => {
89 return fileName.replace(/\.ts$/, '')
90 }
91 )
92 )
93 }
94
95 const esbuildPlugins = [
96 makeAllPackagesExternalPlugin,
97 {
98 name: 'transform-pipe',
99 setup(ctx, ...args) {
100 const plugin = transformPipe.esbuild({

Callers 1

bundleFunction · 0.90

Calls 4

createOutdirFunction · 0.85
createFormatsFunction · 0.85
createEntryFunction · 0.85
warnFunction · 0.85

Tested by

no test coverage detected