siroc icon indicating copy to clipboard operation
siroc copied to clipboard

fix: pkg config ignored when package.json exists

Open silverbackdan opened this issue 2 years ago • 1 comments

🐛 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

silverbackdan avatar Dec 29 '21 12:12 silverbackdan

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)
    },
  },
})

danielroe avatar Jan 07 '22 21:01 danielroe