danielroe / siroc

Zero-config build tooling for Node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fix: pkg config ignored when package.json exists

silverbackdan opened this issue Β· 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: nuxt-community/auth-module#1400

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