danielroe / siroc

Zero-config build tooling for Node
MIT License
152 stars 4 forks source link

fix: pkg config ignored when package.json exists #225

Open silverbackdan opened 2 years ago

silverbackdan commented 2 years ago

๐Ÿ› The bug I have a package.json file but was looking to override it for the siroc build. I tried copying the entire file, changing just the "typings" property but siroc still appears to use the original

๐Ÿ› ๏ธ To reproduce Use a ts config like:

import { defineSirocConfig } from 'siroc'

export default defineSirocConfig({
  pkg: {
    types: "./dist/index.d.ts",
    typings: "./dist/index.d.ts",
  }
})

or

import { defineSirocConfig } from 'siroc'

export default defineSirocConfig({
  pkg: require('./package.siroc.json')
})

๐ŸŒˆ Expected behaviour Ideally I'd like to override individual parameters without having to define a completely new package.json - however it would be acceptable to be able to have any way to override these options.

โ„น๏ธ Additional context Originally, I just wanted to disable siroc from creating the index.d.ts definitions. This file already exists and siroc is overwriting it. There is then another command run to create a type definition in a ./dist directory, which the main ./index.d.ts imports. So.. I either wanted to disable it, as I have another command which will create it, or be able to set the location of the definitions file to the dist folder, which my next script can then override.

For now, I've added types property in my package.json alongside the typings property.

Related: https://github.com/nuxt-community/auth-module/pull/1400

danielroe commented 2 years ago

A couple of options:

  1. We've been working on porting the convenience features of siroc to https://github.com/unjs/unbuild - which does allow more granular configuration. That may be a better option for you in this case.
  2. You can use siroc hooks to interact with the generated rollup config:
import { defineSirocConfig } from 'siroc'
export default defineSirocConfig({
  hooks: {
    'build:extendRollup'(pkg, { rollupConfig }) {
      const declaration = rollupConfig.findIndex(i => i.output.file?.endsWith('.d.ts'))
      rollupConfig.splice(declaration, 1)
    },
  },
})