0.2.1-0 • Published 1 year ago

export-collector v0.2.1-0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

:tada: export-collector

English | 简体中文

ESM export collector.

:rocket: Feature

Collect all export from a esm file. Based on NodeJS and swc, you may want to use it in scripts or hooks in module bundler.

Not support re-export from a alias path now. Like export * from '@core/index'.

:wrench: Usage

More details see the unit test in test folder.

Consumed in src/index.ts is:

// src/index.ts
export const one = 1
export const getThree = () => 3

export * from './func1' // export from another file.
export * from 'vue' // reExport from deps will be ignored.

in src/func1.ts is:

// src/func1.ts
function func1() {}
function funcRe() {}

export { func1, funcRe as fRe }

Generate autoImport function

The feature only support TS temporarily.

// scripts/build.ts
import { expGenerator } from 'export-collector'

await expGenerator('./src/index.ts', {
  include: ['custom'] // custom export name.
})

In src/index.ts:

// src/index.ts
export const one = 1
export const getThree = () => 3

export * from './func1'
export * from 'vue'

// --- Auto-Generated By Export-Collector ---

const exportList = ['one', 'getThree', 'func1', 'fRe', 'custom'] as const

export type AutoImportMap = { [K in typeof exportList[number]]: string }
export function autoImport(map?: Partial<AutoImportMap>): Record<string, (string | [string, string])[]> {
  return {
    'export-collector': exportList.map(v => map && map[v] ? [v, map[v]] as [string, string] : v),
  }
}

// --- Auto-Generated By Export-Collector ---

Just get export list

Use like :

import { expCollector } from 'export-collector'

const val = await expCollector('./src/index.ts') // base on root as default.

console.log(val)
// ['one', 'getThree', 'func1', 'fRe']

Or customize the base path.

// ...
const val = await expCollector(
  './index.ts',
  fileURLToPath(new URL('./src/index.ts', import.meta.url))
)
// the value will be same as above example.
0.1.1

1 year ago

0.2.1-0

1 year ago

0.1.0

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago