@sanity/pkg-utils 6.12.2 → 6.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/pkg-utils",
3
- "version": "6.12.2",
3
+ "version": "6.13.0",
4
4
  "description": "Simple utilities for modern npm packages.",
5
5
  "keywords": [
6
6
  "sanity-io",
@@ -84,8 +84,8 @@
84
84
  "browserslist": "^4.24.3",
85
85
  "cac": "^6.7.14",
86
86
  "chalk": "^4.1.2",
87
- "chokidar": "^4.0.2",
88
- "esbuild": "^0.24.0",
87
+ "chokidar": "^4.0.3",
88
+ "esbuild": "^0.24.2",
89
89
  "esbuild-register": "^3.6.0",
90
90
  "find-config": "^1.0.0",
91
91
  "get-latest-version": "^5.1.0",
@@ -101,7 +101,7 @@
101
101
  "prompts": "^2.4.2",
102
102
  "recast": "0.23.9",
103
103
  "rimraf": "^4.4.1",
104
- "rollup": "^4.28.1",
104
+ "rollup": "^4.29.1",
105
105
  "rollup-plugin-esbuild": "^6.1.1",
106
106
  "rxjs": "^7.8.1",
107
107
  "treeify": "^1.1.0",
@@ -140,13 +140,13 @@
140
140
  "lint-staged": "^15.0.2",
141
141
  "npm-run-all2": "^7.0.2",
142
142
  "outdent": "^0.8.0",
143
- "rollup-plugin-visualizer": "^5.12.0",
143
+ "rollup-plugin-visualizer": "^5.13.1",
144
144
  "semver": "^7.6.0",
145
145
  "ts-node": "^10.9.2",
146
146
  "typescript": "5.7.2",
147
147
  "vitest": "^2.1.8",
148
148
  "vitest-github-actions-reporter": "^0.11.1",
149
- "@sanity/pkg-utils": "6.12.2"
149
+ "@sanity/pkg-utils": "6.13.0"
150
150
  },
151
151
  "peerDependencies": {
152
152
  "babel-plugin-react-compiler": "*",
@@ -170,6 +170,31 @@ export interface PkgConfigOptions {
170
170
  plugins?: BabelPluginItem[] | null | undefined
171
171
  /** @alpha */
172
172
  reactCompiler?: boolean
173
+ /** @alpha */
174
+ styledComponents?:
175
+ | boolean
176
+ | {
177
+ /** @defaultValue true */
178
+ displayName?: boolean
179
+ /**
180
+ * @defaultValue []
181
+ * @example ["@xstyled/styled-components", "@xstyled/styled-components/*"]
182
+ */
183
+ topLevelImportPaths?: string[]
184
+ /** @defaultValue true */
185
+ ssr?: boolean
186
+ /** @defaultValue fale */
187
+ fileName?: boolean
188
+ /** @defaultValue ["index"] */
189
+ meaninglessFileNames?: string[]
190
+ /** @defaultValue true */
191
+ minify?: boolean
192
+ /** @defaultValue false */
193
+ transpileTemplateLiterals?: boolean
194
+ namespace?: string
195
+ /** @defaultValue true */
196
+ pure?: boolean
197
+ }
173
198
  }
174
199
  /**
175
200
  * Configure the React Compiler.
@@ -1,5 +1,6 @@
1
1
  import path from 'node:path'
2
2
 
3
+ import type {PluginItem} from '@babel/core'
3
4
  import {optimizeLodashImports} from '@optimize-lodash/rollup-plugin'
4
5
  import alias from '@rollup/plugin-alias'
5
6
  import {babel, getBabelOutputPlugin} from '@rollup/plugin-babel'
@@ -96,13 +97,35 @@ export function resolveRollupConfig(
96
97
  }),
97
98
  commonjs(),
98
99
  json(),
99
- (isReactCompiler || config?.babel?.reactCompiler) &&
100
+ (isReactCompiler || config?.babel?.reactCompiler || config?.babel?.styledComponents) &&
100
101
  babel({
101
102
  babelrc: false,
102
103
  presets: ['@babel/preset-typescript'],
103
104
  babelHelpers: 'bundled',
104
105
  extensions: ['.ts', '.tsx', '.js', '.jsx'],
105
- plugins: [['babel-plugin-react-compiler', config?.reactCompilerOptions || {}]],
106
+ plugins: [
107
+ // The styled-components plugin needs to run before the react-compiler plugin, in case the css prop is used
108
+ config?.babel?.styledComponents && [
109
+ 'babel-plugin-styled-components',
110
+ {
111
+ // Unnecessary, as the way we use styled-components in Sanity is usually by wrapping `@sanity/ui` primitives, not declaring new ones like "const Button = styled.button``"
112
+ fileName: false,
113
+ // Native template literals take less space than this transpilation
114
+ transpileTemplateLiterals: false,
115
+ // Massively helps dead code elimination and tree-shaking
116
+ pure: true,
117
+ // disabled, as pkg-utils tends to be used for npm publishing, while other tooling, like `sanity dev`, `next dev`, etc are used for testing
118
+ cssProp: false,
119
+ ...(typeof config.babel.styledComponents === 'object'
120
+ ? config.babel.styledComponents
121
+ : {}),
122
+ },
123
+ ],
124
+ (isReactCompiler || config?.babel?.reactCompiler) && [
125
+ 'babel-plugin-react-compiler',
126
+ config?.reactCompilerOptions || {},
127
+ ],
128
+ ].filter(Boolean) as PluginItem[],
106
129
  }),
107
130
  esbuild({
108
131
  jsx: config?.jsx ?? 'automatic',
@@ -131,7 +154,8 @@ export function resolveRollupConfig(
131
154
  }),
132
155
  minify &&
133
156
  terser({
134
- compress: {directives: false},
157
+ compress: {directives: false, passes: 10},
158
+ ecma: 2020,
135
159
  output: {
136
160
  comments: (_node, comment) => {
137
161
  const text = comment.value
@@ -145,6 +169,7 @@ export function resolveRollupConfig(
145
169
 
146
170
  return false
147
171
  },
172
+ preserve_annotations: true,
148
173
  },
149
174
  }),
150
175
  ].filter(Boolean) as Plugin[]