sanity-codegen icon indicating copy to clipboard operation
sanity-codegen copied to clipboard

Add ignore packages option

Open ricokahler opened this issue 4 years ago • 1 comments

From #59, it seems like the best option is to allow the ability to no-op packages while executing schema extraction.

The config might look like this:

import { SanityCodegenConfig } from 'sanity-codegen';

const config: SanityCodegenConfig = {
  // 👇 this will prevent errors from importing this package during schema extraction
  ignorePackages: ['sanity-plugin-tabs'],
  // ...
};


export default config;

This issue is a todo item for myself.

ricokahler avatar Jan 22 '21 19:01 ricokahler

One issue with this approach is that if you're no-oping a package that's used in generation of a type, you can't then use any functions from that package. eg, with orderable-document-list:

import { orderRankField } from '@sanity/orderable-document-list';

export const projectDoc = {
  // ...
  fields: [
    name,
    orderRankField({ type: 'project' }),
  ],
} as const;

Which then results in the Cannot convert object to primitive value thrown from validatePropertyName because the sanityTypeName is indeed a function, and it can't be called to resolve it because it's no-op 😢

mfanuzzi avatar Sep 13 '22 01:09 mfanuzzi