Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rush-stack api-extractor #54

Open
youngkyo0504 opened this issue Jul 21, 2024 · 0 comments
Open

rush-stack api-extractor #54

youngkyo0504 opened this issue Jul 21, 2024 · 0 comments

Comments

@youngkyo0504
Copy link
Owner


title:
full_path: src/pages/.md

API Extractor

  • missing exports
    • exports를 하지 않은 타입을 자동으로 추출해주는 건가?
  • Accidental exports
    • 의도하지 않았는데 exports했을 때
  • Alpha/Beta graduation:
    • 잘모르겠음
  • d.ts rollup
    • 왜 bundle은 한 파일인데 ts는 한파일이 아닌가?
  • online document

Swatinem/rollup-plugin-dts: A rollup plugin to generate .d.ts rollup files for your typescript project 이것도 같은 역할을 함

import { existsSync } from 'fs'
import fs from 'fs/promises'
import path from 'path'

import { legacy, resolve } from 'resolve.exports'
import { rollup } from 'rollup'
import dts from 'rollup-plugin-dts'
import { externals } from 'rollup-plugin-node-externals'

import packageInfo from './package.json'

const externalDependenciesRegExrs = [
  ...Object.keys(packageInfo.dependencies),
  ...Object.keys(packageInfo.peerDependencies),
  // Next.js library css import 제약 https://nextjs.org/docs/messages/css-npm
  // @atelier/core의 style.css 등 CSS 디펜던시는 최종 번들에 포함
  // 나머지는 제외
  // https://jira.woowa.in/browse/WOOTELIER-469
].map((name) => new RegExp(`^${name}(/.*)?(?<!\\.css)$`))
console.log('시작')

async function build() {
  console.log('시작')
  const dtsEntryPath = path.join(process.cwd(), './dist/index.d.ts')
  console.log(dtsEntryPath)
  const outDir = path.dirname(dtsEntryPath)

  console.log('Bundling', dtsEntryPath)

  try {
    const bundle = await rollup({
      input: dtsEntryPath,
      external: (id) => {
        // jsx-runtime react 17 & 18 동시 지원 이슈
        // https://jira.woowa.in/browse/WOOTELIER-469
        if (id === 'react/jsx-runtime') return false
        return externalDependenciesRegExrs.some((regex) => regex.test(id))
      },
      plugins: [
        externals({
          packagePath: path.resolve('./package.json'),
          deps: true,
          devDeps: false,
          exclude: externalDependenciesRegExrs, // always bundle
          include: ['@jest/transform'], // don't bundle
        }),
        dts({
          compilerOptions: {
            incremental: false,
            noEmitOnError: false,
          },
          respectExternal: true,
        }),
      ],
    })

    console.log('번들 끝 ', bundle)

    // There is a chance that two `buildEntry`s  will run at the same time
    // and one will attempt to read while the other is writing. To fix that,
    // we'll defer the overwrite until all the bundles are ready
    return async () => {
      await bundle.write({
        dir: outDir,
        entryFileNames: '[name].ts',
        minifyInternalExports: false,
      })
    }
  } catch (e: any) {
    console.error('Error bundling', dtsEntryPath)
    console.error(e)
    throw e
  }
}

build().then((write) => write())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant