@sanity/tsdown-config 0.7.2 → 0.8.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/README.md CHANGED
@@ -11,3 +11,28 @@ import {defineConfig} from '@sanity/tsdown-config'
11
11
 
12
12
  export default defineConfig({tsconfig: 'tsconfig.dist.json'})
13
13
  ```
14
+
15
+ ## styled-components
16
+
17
+ If your package uses `styled-components`, enable the same `styledComponents` transform that `@sanity/pkg-utils` has:
18
+
19
+ ```ts
20
+ import {defineConfig} from '@sanity/tsdown-config'
21
+
22
+ export default defineConfig({
23
+ tsconfig: 'tsconfig.dist.json',
24
+ styledComponents: true,
25
+ })
26
+ ```
27
+
28
+ It adds `displayName` (better debugging) and `componentId` (avoids SSR hydration mismatches) to your styled components, and minifies the CSS in tagged template literals.
29
+ Unlike `@sanity/pkg-utils` it doesn't require installing `babel-plugin-styled-components`, as it uses [oxc's native port](https://oxc.rs/docs/guide/usage/transformer/plugins.html#styled-components) of the babel plugin.
30
+
31
+ Pass an object to customize the transform, using the same options as [`babel-plugin-styled-components`](https://styled-components.com/docs/tooling#babel-plugin):
32
+
33
+ ```ts
34
+ export default defineConfig({
35
+ tsconfig: 'tsconfig.dist.json',
36
+ styledComponents: {namespace: 'my-package'},
37
+ })
38
+ ```
package/dist/index.d.mts CHANGED
@@ -1,5 +1,31 @@
1
1
  import { UserConfig } from "tsdown";
2
2
  /**
3
+ * Options for the `styled-components` transform, the same options as `babel-plugin-styled-components`.
4
+ * @public
5
+ */
6
+ interface StyledComponentsOptions {
7
+ /** @defaultValue true */
8
+ displayName?: boolean;
9
+ /**
10
+ * @defaultValue []
11
+ * @example ["\@xstyled/styled-components", "\@xstyled/styled-components/*"]
12
+ */
13
+ topLevelImportPaths?: string[];
14
+ /** @defaultValue true */
15
+ ssr?: boolean;
16
+ /** @defaultValue false */
17
+ fileName?: boolean;
18
+ /** @defaultValue ["index"] */
19
+ meaninglessFileNames?: string[];
20
+ /** @defaultValue true */
21
+ minify?: boolean;
22
+ /** @defaultValue false */
23
+ transpileTemplateLiterals?: boolean;
24
+ namespace?: string;
25
+ /** @defaultValue true */
26
+ pure?: boolean;
27
+ }
28
+ /**
3
29
  * @public
4
30
  */
5
31
  interface PackageOptions extends Pick<UserConfig, "tsconfig" | "entry" | "format"> {
@@ -7,10 +33,18 @@ interface PackageOptions extends Pick<UserConfig, "tsconfig" | "entry" | "format
7
33
  * @defaultValue 'neutral'
8
34
  */
9
35
  platform?: UserConfig["platform"];
36
+ /**
37
+ * Applies the `styled-components` transform (`displayName`, `componentId`, CSS minification, etc)
38
+ * with the same defaults as the `babel: {styledComponents: true}` option in `@sanity/pkg-utils`.
39
+ * Unlike `@sanity/pkg-utils` it doesn't use `babel-plugin-styled-components`, but oxc's native port of it,
40
+ * so there's no need to install babel dependencies.
41
+ * @defaultValue false
42
+ */
43
+ styledComponents?: boolean | StyledComponentsOptions;
10
44
  }
11
45
  /**
12
46
  * @public
13
47
  */
14
48
  declare function defineConfig(options?: PackageOptions): UserConfig;
15
- export { PackageOptions, defineConfig };
49
+ export { PackageOptions, StyledComponentsOptions, defineConfig };
16
50
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;AAKA;;UAAiB,cAAA,SAAuB,IAAA,CAAK,UAAA;;;;EAI3C,QAAA,GAAW,UAAA;AAAA;;;;iBAMG,YAAA,CAAa,OAAA,GAAS,cAAA,GAAsB,UAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;AAMA;;;UAAiB,uBAAA;;EAEf,WAAA;;;;;EAKA,mBAAA;;EAEA,GAAA;EAWA;EATA,QAAA;EAeF;EAbE,oBAAA;;EAEA,MAAA;;EAEA,yBAAA;EACA,SAAA;EAQsC;EANtC,IAAA;AAAA;;;;UAMe,cAAA,SAAuB,IAAA,CAAK,UAAA;;;AAYd;EAR7B,QAAA,GAAW,UAAA;EAcG;;;;;;;EANd,gBAAA,aAA6B,uBAAA;AAAA;;;;iBAMf,YAAA,CAAa,OAAA,GAAS,cAAA,GAAsB,UAAA"}
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import { defineConfig as defineConfig$1 } from "tsdown";
3
3
  * @public
4
4
  */
5
5
  function defineConfig(options = {}) {
6
- let { entry } = options;
6
+ let { entry } = options, tsconfig = options.tsconfig ?? "tsconfig.json", platform = options.platform ?? "neutral", styledComponents = options.styledComponents ?? !1, report = { gzip: !1 };
7
7
  return defineConfig$1({
8
8
  entry,
9
9
  exports: {
@@ -14,28 +14,24 @@ function defineConfig(options = {}) {
14
14
  hash: !1,
15
15
  inputOptions: {
16
16
  preserveEntrySignatures: "strict",
17
- experimental: { attachDebugInfo: "none" }
17
+ experimental: { attachDebugInfo: "none" },
18
+ ...styledComponents !== !1 && { transform: { plugins: { styledComponents: {
19
+ fileName: !1,
20
+ transpileTemplateLiterals: !1,
21
+ pure: !0,
22
+ cssProp: !1,
23
+ ...typeof styledComponents == "object" ? styledComponents : {}
24
+ } } } }
18
25
  },
19
26
  outputOptions: { hoistTransitiveImports: !1 },
20
- platform: options.platform ?? "neutral",
27
+ platform,
21
28
  publint: !0,
22
- report: { gzip: !1 },
23
- tsconfig: options.tsconfig ?? "tsconfig.json",
29
+ report,
30
+ tsconfig,
24
31
  minify: {
25
32
  compress: !0,
26
33
  codegen: !1,
27
34
  mangle: !1
28
- },
29
- treeshake: {
30
- annotations: !0,
31
- propertyReadSideEffects: !1,
32
- moduleSideEffects: [{
33
- test: /\.css$/,
34
- sideEffects: !0
35
- }, {
36
- external: !0,
37
- sideEffects: !1
38
- }]
39
35
  }
40
36
  });
41
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["defineTsdownConfig"],"sources":["../src/index.ts"],"sourcesContent":["import {defineConfig as defineTsdownConfig, type UserConfig} from 'tsdown'\n\n/**\n * @public\n */\nexport interface PackageOptions extends Pick<UserConfig, 'tsconfig' | 'entry' | 'format'> {\n /**\n * @defaultValue 'neutral'\n */\n platform?: UserConfig['platform']\n}\n\n/**\n * @public\n */\nexport function defineConfig(options: PackageOptions = {}): UserConfig {\n const {entry} = options\n const tsconfig = options.tsconfig ?? 'tsconfig.json'\n const platform = options.platform ?? 'neutral'\n const report = {gzip: false} as const satisfies UserConfig['report']\n const publint = true\n const hash = false\n const format = options.format ?? 'esm'\n const inputOptions = {\n preserveEntrySignatures: 'strict',\n experimental: {attachDebugInfo: 'none'},\n } as const satisfies UserConfig['inputOptions']\n const outputOptions = {\n hoistTransitiveImports: false,\n } as const satisfies UserConfig['outputOptions']\n const exports = {\n enabled: 'local-only',\n // @TODO use @sanity/parse-package-json to determine if devExports should be `true` or `source`\n devExports: true,\n } as const satisfies UserConfig['exports']\n\n return defineTsdownConfig({\n entry,\n exports,\n format,\n hash,\n inputOptions,\n outputOptions,\n platform,\n publint,\n report,\n tsconfig,\n minify: {compress: true, codegen: false, mangle: false},\n treeshake: {\n annotations: true,\n propertyReadSideEffects: false,\n moduleSideEffects: [\n // If the module ends with `.css` it is considered to be a side effect, even if the module is marked as no side effect,\n {test: /\\.css$/, sideEffects: true},\n // This is the equivalent of `moduleSideEffects: 'no-external'`, and included here so it works the same as before the CSS exemption were added.\n {external: true, sideEffects: false},\n ],\n },\n })\n}\n"],"mappings":";;;;AAeA,SAAgB,aAAa,UAA0B,CAAC,GAAe;CACrE,IAAM,EAAC,UAAS;CAoBhB,OAAOA,eAAmB;EACxB;EACA,SAAA;GAPA,SAAS;GAET,YAAY;EAKN;EACN,QAjBa,QAAQ,UAAU;EAkB/B,MAAA;EACA,cAAA;GAjBA,yBAAyB;GACzB,cAAc,EAAC,iBAAiB,OAAM;EAgB3B;EACX,eAAA,EAdA,wBAAwB,GAcZ;EACZ,UAzBe,QAAQ,YAAY;EA0BnC,SAAA;EACA,QAAA,EA1Bc,MAAM,GA0Bf;EACL,UA7Be,QAAQ,YAAY;EA8BnC,QAAQ;GAAC,UAAU;GAAM,SAAS;GAAO,QAAQ;EAAK;EACtD,WAAW;GACT,aAAa;GACb,yBAAyB;GACzB,mBAAmB,CAEjB;IAAC,MAAM;IAAU,aAAa;GAAI,GAElC;IAAC,UAAU;IAAM,aAAa;GAAK,CACrC;EACF;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"index.mjs","names":["defineTsdownConfig"],"sources":["../src/index.ts"],"sourcesContent":["import {defineConfig as defineTsdownConfig, type UserConfig} from 'tsdown'\n\n/**\n * Options for the `styled-components` transform, the same options as `babel-plugin-styled-components`.\n * @public\n */\nexport interface StyledComponentsOptions {\n /** @defaultValue true */\n displayName?: boolean\n /**\n * @defaultValue []\n * @example [\"\\@xstyled/styled-components\", \"\\@xstyled/styled-components/*\"]\n */\n topLevelImportPaths?: string[]\n /** @defaultValue true */\n ssr?: boolean\n /** @defaultValue false */\n fileName?: boolean\n /** @defaultValue [\"index\"] */\n meaninglessFileNames?: string[]\n /** @defaultValue true */\n minify?: boolean\n /** @defaultValue false */\n transpileTemplateLiterals?: boolean\n namespace?: string\n /** @defaultValue true */\n pure?: boolean\n}\n\n/**\n * @public\n */\nexport interface PackageOptions extends Pick<UserConfig, 'tsconfig' | 'entry' | 'format'> {\n /**\n * @defaultValue 'neutral'\n */\n platform?: UserConfig['platform']\n /**\n * Applies the `styled-components` transform (`displayName`, `componentId`, CSS minification, etc)\n * with the same defaults as the `babel: {styledComponents: true}` option in `@sanity/pkg-utils`.\n * Unlike `@sanity/pkg-utils` it doesn't use `babel-plugin-styled-components`, but oxc's native port of it,\n * so there's no need to install babel dependencies.\n * @defaultValue false\n */\n styledComponents?: boolean | StyledComponentsOptions\n}\n\n/**\n * @public\n */\nexport function defineConfig(options: PackageOptions = {}): UserConfig {\n const {entry} = options\n const tsconfig = options.tsconfig ?? 'tsconfig.json'\n const platform = options.platform ?? 'neutral'\n const styledComponents = options.styledComponents ?? false\n const report = {gzip: false} as const satisfies UserConfig['report']\n const publint = true\n const hash = false\n const format = options.format ?? 'esm'\n const inputOptions = {\n preserveEntrySignatures: 'strict',\n experimental: {attachDebugInfo: 'none'},\n ...(styledComponents !== false && {\n transform: {\n plugins: {\n styledComponents: {\n // The same defaults as `babel: {styledComponents: true}` in `@sanity/pkg-utils`:\n // `fileName` is unnecessary, as the way we use styled-components in Sanity is usually by wrapping\n // `@sanity/ui` primitives, not declaring new ones like \"const Button = styled.button``\"\n fileName: false,\n // Native template literals take less space than this transpilation, and unlike\n // `babel-plugin-styled-components`, oxc doesn't add a `@__PURE__` annotation to the\n // transpiled call expression either, so enabling it wouldn't improve tree-shaking\n transpileTemplateLiterals: false,\n // Helps dead code elimination and tree-shaking, although oxc only annotates plain call\n // expressions so far, not tagged template expressions (https://github.com/rollup/rollup/issues/4035)\n pure: true,\n // Disabled, as tsdown tends to be used for npm publishing, while other tooling,\n // like `sanity dev`, `next dev`, etc are used for testing\n cssProp: false,\n ...(typeof styledComponents === 'object' ? styledComponents : {}),\n },\n },\n },\n }),\n } as const satisfies UserConfig['inputOptions']\n const outputOptions = {\n hoistTransitiveImports: false,\n } as const satisfies UserConfig['outputOptions']\n const exports = {\n enabled: 'local-only',\n // @TODO use @sanity/parse-package-json to determine if devExports should be `true` or `source`\n devExports: true,\n } as const satisfies UserConfig['exports']\n\n return defineTsdownConfig({\n entry,\n exports,\n format,\n hash,\n inputOptions,\n outputOptions,\n platform,\n publint,\n report,\n tsconfig,\n minify: {compress: true, codegen: false, mangle: false},\n // Rely on tsdown's/rolldown's default tree-shaking (`moduleSideEffects: true`) rather than\n // customizing it. Previously this set the equivalent of `moduleSideEffects: 'no-external'`\n // (with a `.css` exemption), which stripped intentional side-effect-only imports of external\n // packages (e.g. `import 'react-time-ago/locale/en'`) from the output. The default preserves\n // those imports while still honoring `package.json` `sideEffects` fields for bundled modules.\n })\n}\n"],"mappings":";;;;AAkDA,SAAgB,aAAa,UAA0B,CAAC,GAAe;CACrE,IAAM,EAAC,UAAS,SACV,WAAW,QAAQ,YAAY,iBAC/B,WAAW,QAAQ,YAAY,WAC/B,mBAAmB,QAAQ,oBAAoB,IAC/C,SAAS,EAAC,MAAM,GAAK;CAwC3B,OAAOA,eAAmB;EACxB;EACA,SAAA;GAPA,SAAS;GAET,YAAY;EAKN;EACN,QAxCa,QAAQ,UAAU;EAyC/B,MAAA;EACA,cAAA;GAxCA,yBAAyB;GACzB,cAAc,EAAC,iBAAiB,OAAM;GACtC,GAAI,qBAAqB,MAAS,EAChC,WAAW,EACT,SAAS,EACP,kBAAkB;IAIhB,UAAU;IAIV,2BAA2B;IAG3B,MAAM;IAGN,SAAS;IACT,GAAI,OAAO,oBAAqB,WAAW,mBAAmB,CAAC;GACjE,EACF,EACF,EACF;EAgBW;EACX,eAAA,EAdA,wBAAwB,GAcZ;EACZ;EACA;EACA;EACA;EACA,QAAQ;GAAC,UAAU;GAAM,SAAS;GAAO,QAAQ;EAAK;CAMxD,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/tsdown-config",
3
- "version": "0.7.2",
3
+ "version": "0.8.0",
4
4
  "description": "Shared configuration for tsdown",
5
5
  "keywords": [
6
6
  "sanity-io",
@@ -30,24 +30,21 @@
30
30
  ".": "./dist/index.mjs",
31
31
  "./package.json": "./package.json"
32
32
  },
33
- "main": "./dist/index.mjs",
34
- "module": "./dist/index.mjs",
35
33
  "types": "./dist/index.d.mts",
36
34
  "files": [
37
35
  "dist"
38
36
  ],
39
37
  "dependencies": {
40
- "publint": "^0.3.21",
41
- "@sanity/parse-package-json": "^2.1.7"
38
+ "publint": "^0.3.21"
42
39
  },
43
40
  "devDependencies": {
44
41
  "@typescript/native-preview": "7.0.0-dev.20260421.2",
45
42
  "tinyexec": "^1.2.4",
46
- "tsdown": "^0.22.2",
43
+ "tsdown": "^0.22.3",
47
44
  "typescript": "6.0.3",
48
- "vitest": "^4.1.8",
49
- "@sanity/pkg-utils": "^10.5.3",
50
- "@sanity/tsconfig": "^2.1.0"
45
+ "vitest": "^4.1.9",
46
+ "@sanity/tsconfig": "^2.1.0",
47
+ "@sanity/pkg-utils": "^10.9.0"
51
48
  },
52
49
  "peerDependencies": {
53
50
  "tsdown": "0.22.x",