@w5s/tsdown-config 1.0.0-alpha.5 → 1.0.0-alpha.6

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/dist/index.d.ts CHANGED
@@ -1,3 +1,37 @@
1
- export * from './defaultConfig.js';
2
- export * from './defineConfig.js';
3
- export * from './defineConfigWith.js';
1
+ import { DtsOptions, Format, InlineConfig, OutExtensionContext, OutExtensionFactory, OutExtensionObject, Sourcemap, TsdownPlugin, TsdownPluginOption, UserConfig, UserConfig as UserConfig$1, UserConfigExport, UserConfigFn } from "tsdown";
2
+
3
+ //#region src/defaultConfig.d.ts
4
+ declare const defaultConfig: UserConfig$1;
5
+ //#endregion
6
+ //#region src/defineConfig.d.ts
7
+ /**
8
+ * Define a tsdown configuration with the package default (entry, format, dts, package defines, etc.).
9
+ * Accepts either a config object or a function `(config, context) => config`.
10
+ *
11
+ * @param optionsOrFn
12
+ */
13
+ declare function defineConfig(optionsOrFn: UserConfig): UserConfig;
14
+ declare function defineConfig(optionsOrFn: UserConfigFn): UserConfigFn;
15
+ //#endregion
16
+ //#region src/defineConfigWith.d.ts
17
+ /**
18
+ * Returns a `defineConfig`-like function that uses a custom base config instead of the package default.
19
+ * Use this when you have a shared base (e.g. a library preset) and want to reuse it across multiple packages.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * // Helper for shared library preset
24
+ * export const defineConfig = defineConfigWith({ format: ['esm', 'cjs'] });
25
+ *
26
+ * // in tsdown.config.ts
27
+ * export default defineConfig({ entry: ['src/index.ts'] });
28
+ * ```
29
+ * @param baseConfig The base configuration to merge with the package default.
30
+ */
31
+ declare function defineConfigWith(baseConfig: UserConfig): {
32
+ (optionsOrFn: UserConfig): UserConfig;
33
+ (optionsOrFn: UserConfigFn): UserConfigFn;
34
+ };
35
+ //#endregion
36
+ export { type DtsOptions, type Format, type InlineConfig, type OutExtensionContext, type OutExtensionFactory, type OutExtensionObject, type Sourcemap, type TsdownPlugin, type TsdownPluginOption, type UserConfig, type UserConfigExport, type UserConfigFn, defaultConfig, defineConfig, defineConfigWith };
37
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,3 +1,84 @@
1
- export * from './defaultConfig.js';
2
- export * from './defineConfig.js';
3
- export * from './defineConfigWith.js';
1
+ import * as TsDown from "tsdown";
2
+ import { readFileSync } from "node:fs";
3
+ import path from "node:path";
4
+ //#region src/defaultConfig.ts
5
+ const defaultConfig = {
6
+ entry: [
7
+ "src/index.ts",
8
+ "!src/**/*.test.*",
9
+ "!src/**/*.spec.*",
10
+ "!**/__mocks__/**"
11
+ ],
12
+ sourcemap: true,
13
+ format: ["esm"],
14
+ dts: true,
15
+ tsconfig: "tsconfig.build.json",
16
+ outExtensions({ format }) {
17
+ return { js: format === "es" ? ".js" : ".cjs" };
18
+ }
19
+ };
20
+ //#endregion
21
+ //#region src/withPackageDefine.ts
22
+ function toInt(value) {
23
+ if (value == null) return void 0;
24
+ const parsed = Number.parseInt(value);
25
+ return Number.isNaN(parsed) ? void 0 : parsed;
26
+ }
27
+ function withPackageDefine(config) {
28
+ let packageJSON = void 0;
29
+ const cwd = config.cwd ?? process.cwd();
30
+ function getPackageJSON() {
31
+ if (packageJSON) return packageJSON;
32
+ try {
33
+ packageJSON = JSON.parse(readFileSync(path.join(cwd, "package.json"), "utf8"));
34
+ return packageJSON;
35
+ } catch {
36
+ return {};
37
+ }
38
+ }
39
+ function jsonSafeStringify(value) {
40
+ return JSON.stringify(value);
41
+ }
42
+ return {
43
+ ...config,
44
+ cwd,
45
+ define: {
46
+ __PACKAGE_NAME__: jsonSafeStringify(process.env["npm_package_name"] ?? getPackageJSON().name ?? ""),
47
+ __PACKAGE_VERSION__: jsonSafeStringify(process.env["npm_package_version"] ?? getPackageJSON().version ?? ""),
48
+ __PACKAGE_BUILD_NUMBER__: jsonSafeStringify(toInt(process.env["npm_package_build_number"]) ?? toInt(process.env["BUILD_NUMBER"]) ?? toInt(process.env["CI_BUILD_NUMBER"]) ?? Date.now()),
49
+ ...config.define
50
+ }
51
+ };
52
+ }
53
+ //#endregion
54
+ //#region src/defineConfig.ts
55
+ function defineConfig(optionsOrFn) {
56
+ return TsDown.defineConfig(typeof optionsOrFn === "function" ? (config, context) => optionsOrFn(withPackageDefine(TsDown.mergeConfig(defaultConfig, config)), context) : withPackageDefine(TsDown.mergeConfig(defaultConfig, optionsOrFn)));
57
+ }
58
+ //#endregion
59
+ //#region src/defineConfigWith.ts
60
+ function mergeConfig(base, extension) {
61
+ return TsDown.mergeConfig(base, extension);
62
+ }
63
+ /**
64
+ * Returns a `defineConfig`-like function that uses a custom base config instead of the package default.
65
+ * Use this when you have a shared base (e.g. a library preset) and want to reuse it across multiple packages.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * // Helper for shared library preset
70
+ * export const defineConfig = defineConfigWith({ format: ['esm', 'cjs'] });
71
+ *
72
+ * // in tsdown.config.ts
73
+ * export default defineConfig({ entry: ['src/index.ts'] });
74
+ * ```
75
+ * @param baseConfig The base configuration to merge with the package default.
76
+ */
77
+ function defineConfigWith(baseConfig) {
78
+ const resolvedBaseConfig = mergeConfig(defaultConfig, baseConfig);
79
+ return (optionsOrFn) => TsDown.defineConfig(typeof optionsOrFn === "function" ? (config, context) => withPackageDefine(optionsOrFn(resolvedBaseConfig, context)) : withPackageDefine(mergeConfig(resolvedBaseConfig, optionsOrFn)));
80
+ }
81
+ //#endregion
82
+ export { defaultConfig, defineConfig, defineConfigWith };
83
+
84
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/defaultConfig.ts","../src/withPackageDefine.ts","../src/defineConfig.ts","../src/defineConfigWith.ts"],"sourcesContent":["import type { UserConfig } from 'tsdown';\n\nexport const defaultConfig: UserConfig = {\n entry: ['src/index.ts', '!src/**/*.test.*', '!src/**/*.spec.*', '!**/__mocks__/**'],\n sourcemap: true,\n format: ['esm'],\n dts: true,\n // clean: true,\n // treeshake: 'recommended',\n // splitting: false,\n tsconfig: 'tsconfig.build.json',\n outExtensions({ format }) {\n return {\n js: format === 'es' ? '.js' : '.cjs',\n };\n },\n};\n","import type * as TsDown from 'tsdown';\nimport { readFileSync } from 'node:fs';\nimport path from 'node:path';\n\ninterface PackageJSON {\n name?: string;\n version?: string;\n}\n\nfunction toInt(value: string | undefined): number | undefined {\n if (value == null) return undefined;\n const parsed = Number.parseInt(value);\n return Number.isNaN(parsed) ? undefined : parsed;\n}\n\nexport function withPackageDefine<T extends TsDown.UserConfig | TsDown.InlineConfig>(config: T): T {\n let packageJSON: PackageJSON | undefined = undefined;\n const cwd = config.cwd ?? process.cwd();\n\n function getPackageJSON() {\n if (packageJSON) return packageJSON;\n try {\n packageJSON = JSON.parse(readFileSync(path.join(cwd, 'package.json'), 'utf8'));\n return packageJSON as unknown as PackageJSON;\n } catch {\n return {};\n }\n }\n\n // Ensure we do not stringify undefined values\n function jsonSafeStringify(value: string | number): string {\n return JSON.stringify(value);\n }\n\n return {\n ...config,\n cwd,\n define: {\n __PACKAGE_NAME__: jsonSafeStringify(process.env['npm_package_name'] ?? getPackageJSON().name ?? ''),\n __PACKAGE_VERSION__: jsonSafeStringify(process.env['npm_package_version'] ?? getPackageJSON().version ?? ''),\n __PACKAGE_BUILD_NUMBER__: jsonSafeStringify(\n toInt(process.env['npm_package_build_number']) ??\n toInt(process.env['BUILD_NUMBER']) ??\n toInt(process.env['CI_BUILD_NUMBER']) ??\n Date.now(),\n ),\n ...config.define,\n },\n };\n}\n","import * as TsDown from 'tsdown';\nimport type { UserConfig, UserConfigFn } from './types.js';\nimport { defaultConfig } from './defaultConfig.js';\nimport { withPackageDefine } from './withPackageDefine.js';\n\n/**\n * Define a tsdown configuration with the package default (entry, format, dts, package defines, etc.).\n * Accepts either a config object or a function `(config, context) => config`.\n *\n * @param optionsOrFn\n */\nexport function defineConfig(optionsOrFn: UserConfig): UserConfig;\nexport function defineConfig(optionsOrFn: UserConfigFn): UserConfigFn;\nexport function defineConfig(optionsOrFn: UserConfig | UserConfigFn): UserConfig | UserConfigFn {\n // @ts-ignore tsdown's overloads do not narrow cleanly after wrapping function configs.\n return TsDown.defineConfig(\n typeof optionsOrFn === 'function'\n ? (config, context) => optionsOrFn(withPackageDefine(TsDown.mergeConfig(defaultConfig, config)), context)\n : withPackageDefine(TsDown.mergeConfig(defaultConfig, optionsOrFn)),\n );\n}\n","import * as TsDown from 'tsdown';\nimport type { UserConfig, UserConfigFn } from './types.js';\nimport { defaultConfig } from './defaultConfig.js';\nimport { withPackageDefine } from './withPackageDefine.js';\n\nfunction mergeConfig(base: UserConfig, extension: UserConfig): UserConfig {\n return TsDown.mergeConfig(base, extension);\n}\n\n/**\n * Returns a `defineConfig`-like function that uses a custom base config instead of the package default.\n * Use this when you have a shared base (e.g. a library preset) and want to reuse it across multiple packages.\n *\n * @example\n * ```ts\n * // Helper for shared library preset\n * export const defineConfig = defineConfigWith({ format: ['esm', 'cjs'] });\n *\n * // in tsdown.config.ts\n * export default defineConfig({ entry: ['src/index.ts'] });\n * ```\n * @param baseConfig The base configuration to merge with the package default.\n */\nexport function defineConfigWith(baseConfig: UserConfig): {\n (optionsOrFn: UserConfig): UserConfig;\n (optionsOrFn: UserConfigFn): UserConfigFn;\n} {\n const resolvedBaseConfig = mergeConfig(defaultConfig, baseConfig);\n // @ts-ignore tsdown's overloads do not narrow cleanly after wrapping function configs.\n return (optionsOrFn) =>\n TsDown.defineConfig(\n typeof optionsOrFn === 'function'\n ? (config, context) =>\n withPackageDefine(optionsOrFn(resolvedBaseConfig, context) as UserConfig)\n : withPackageDefine(mergeConfig(resolvedBaseConfig, optionsOrFn)),\n ) as UserConfig | UserConfigFn;\n}\n"],"mappings":";;;;AAEA,MAAa,gBAA4B;CACvC,OAAO;EAAC;EAAgB;EAAoB;EAAoB;CAAkB;CAClF,WAAW;CACX,QAAQ,CAAC,KAAK;CACd,KAAK;CAIL,UAAU;CACV,cAAc,EAAE,UAAU;EACxB,OAAO,EACL,IAAI,WAAW,OAAO,QAAQ,OAChC;CACF;AACF;;;ACPA,SAAS,MAAM,OAA+C;CAC5D,IAAI,SAAS,MAAM,OAAO,KAAA;CAC1B,MAAM,SAAS,OAAO,SAAS,KAAK;CACpC,OAAO,OAAO,MAAM,MAAM,IAAI,KAAA,IAAY;AAC5C;AAEA,SAAgB,kBAAqE,QAAc;CACjG,IAAI,cAAuC,KAAA;CAC3C,MAAM,MAAM,OAAO,OAAO,QAAQ,IAAI;CAEtC,SAAS,iBAAiB;EACxB,IAAI,aAAa,OAAO;EACxB,IAAI;GACF,cAAc,KAAK,MAAM,aAAa,KAAK,KAAK,KAAK,cAAc,GAAG,MAAM,CAAC;GAC7E,OAAO;EACT,QAAQ;GACN,OAAO,CAAC;EACV;CACF;CAGA,SAAS,kBAAkB,OAAgC;EACzD,OAAO,KAAK,UAAU,KAAK;CAC7B;CAEA,OAAO;EACL,GAAG;EACH;EACA,QAAQ;GACN,kBAAkB,kBAAkB,QAAQ,IAAI,uBAAuB,eAAe,EAAE,QAAQ,EAAE;GAClG,qBAAqB,kBAAkB,QAAQ,IAAI,0BAA0B,eAAe,EAAE,WAAW,EAAE;GAC3G,0BAA0B,kBACxB,MAAM,QAAQ,IAAI,2BAA2B,KAC7C,MAAM,QAAQ,IAAI,eAAe,KACjC,MAAM,QAAQ,IAAI,kBAAkB,KACpC,KAAK,IAAI,CACX;GACA,GAAG,OAAO;EACZ;CACF;AACF;;;ACpCA,SAAgB,aAAa,aAAmE;CAE9F,OAAO,OAAO,aACZ,OAAO,gBAAgB,cAClB,QAAQ,YAAY,YAAY,kBAAkB,OAAO,YAAY,eAAe,MAAM,CAAC,GAAG,OAAO,IACtG,kBAAkB,OAAO,YAAY,eAAe,WAAW,CAAC,CACtE;AACF;;;ACfA,SAAS,YAAY,MAAkB,WAAmC;CACxE,OAAO,OAAO,YAAY,MAAM,SAAS;AAC3C;;;;;;;;;;;;;;;AAgBA,SAAgB,iBAAiB,YAG/B;CACA,MAAM,qBAAqB,YAAY,eAAe,UAAU;CAEhE,QAAQ,gBACN,OAAO,aACL,OAAO,gBAAgB,cAClB,QAAQ,YACP,kBAAkB,YAAY,oBAAoB,OAAO,CAAe,IAC1E,kBAAkB,YAAY,oBAAoB,WAAW,CAAC,CACpE;AACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@w5s/tsdown-config",
3
- "version": "1.0.0-alpha.5",
3
+ "version": "1.0.0-alpha.6",
4
4
  "description": "Shared tsdown configuration",
5
5
  "keywords": [
6
6
  "typescript",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
17
- "url": "git@github.com:w5s/project-config.git",
17
+ "url": "git+ssh@github.com:w5s/project-config.git",
18
18
  "directory": "packages/tsdown-config"
19
19
  },
20
20
  "license": "MIT",
@@ -36,17 +36,6 @@
36
36
  "!**/*.spec.*",
37
37
  "!**/__tests__/**"
38
38
  ],
39
- "tsdown": {
40
- "entry": [
41
- "src/index.ts"
42
- ],
43
- "sourcemap": true,
44
- "format": [
45
- "esm"
46
- ],
47
- "dts": true,
48
- "clean": true
49
- },
50
39
  "scripts": {
51
40
  "postpack": "clean-package restore"
52
41
  },
@@ -65,5 +54,5 @@
65
54
  "access": "public"
66
55
  },
67
56
  "sideEffect": false,
68
- "gitHead": "38cf5f5877af4c8a1c292b9b7039c5a11863fc00"
57
+ "gitHead": "ab7987a57772b2e7fb3ef7eb4cadb3cedd9cc9ae"
69
58
  }
@@ -1,4 +1,5 @@
1
1
  import * as TsDown from 'tsdown';
2
+ import type { UserConfig, UserConfigFn } from './types.js';
2
3
  import { defaultConfig } from './defaultConfig.js';
3
4
  import { withPackageDefine } from './withPackageDefine.js';
4
5
 
@@ -8,10 +9,10 @@ import { withPackageDefine } from './withPackageDefine.js';
8
9
  *
9
10
  * @param optionsOrFn
10
11
  */
11
- export function defineConfig(
12
- optionsOrFn: TsDown.UserConfig | TsDown.UserConfigFn,
13
- ): TsDown.UserConfig | TsDown.UserConfigFn {
14
- // @ts-ignore
12
+ export function defineConfig(optionsOrFn: UserConfig): UserConfig;
13
+ export function defineConfig(optionsOrFn: UserConfigFn): UserConfigFn;
14
+ export function defineConfig(optionsOrFn: UserConfig | UserConfigFn): UserConfig | UserConfigFn {
15
+ // @ts-ignore tsdown's overloads do not narrow cleanly after wrapping function configs.
15
16
  return TsDown.defineConfig(
16
17
  typeof optionsOrFn === 'function'
17
18
  ? (config, context) => optionsOrFn(withPackageDefine(TsDown.mergeConfig(defaultConfig, config)), context)
@@ -1,8 +1,9 @@
1
1
  import * as TsDown from 'tsdown';
2
+ import type { UserConfig, UserConfigFn } from './types.js';
2
3
  import { defaultConfig } from './defaultConfig.js';
3
4
  import { withPackageDefine } from './withPackageDefine.js';
4
5
 
5
- function mergeConfig(base: TsDown.UserConfig, extension: TsDown.UserConfig): TsDown.UserConfig {
6
+ function mergeConfig(base: UserConfig, extension: UserConfig): UserConfig {
6
7
  return TsDown.mergeConfig(base, extension);
7
8
  }
8
9
 
@@ -20,15 +21,17 @@ function mergeConfig(base: TsDown.UserConfig, extension: TsDown.UserConfig): TsD
20
21
  * ```
21
22
  * @param baseConfig The base configuration to merge with the package default.
22
23
  */
23
- export function defineConfigWith(baseConfig: TsDown.UserConfig): ((
24
- optionsOrFn: TsDown.UserConfig | TsDown.UserConfigFn,
25
- ) => TsDown.UserConfig | TsDown.UserConfigFn) {
24
+ export function defineConfigWith(baseConfig: UserConfig): {
25
+ (optionsOrFn: UserConfig): UserConfig;
26
+ (optionsOrFn: UserConfigFn): UserConfigFn;
27
+ } {
26
28
  const resolvedBaseConfig = mergeConfig(defaultConfig, baseConfig);
29
+ // @ts-ignore tsdown's overloads do not narrow cleanly after wrapping function configs.
27
30
  return (optionsOrFn) =>
28
31
  TsDown.defineConfig(
29
32
  typeof optionsOrFn === 'function'
30
33
  ? (config, context) =>
31
- withPackageDefine(optionsOrFn(resolvedBaseConfig, context) as TsDown.UserConfig)
34
+ withPackageDefine(optionsOrFn(resolvedBaseConfig, context) as UserConfig)
32
35
  : withPackageDefine(mergeConfig(resolvedBaseConfig, optionsOrFn)),
33
- ) as TsDown.UserConfig | TsDown.UserConfigFn;
36
+ ) as UserConfig | UserConfigFn;
34
37
  }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './defaultConfig.js';
2
2
  export * from './defineConfig.js';
3
3
  export * from './defineConfigWith.js';
4
+ export type * from './types.js';
package/src/types.ts ADDED
@@ -0,0 +1,14 @@
1
+ export type {
2
+ DtsOptions,
3
+ Format,
4
+ InlineConfig,
5
+ OutExtensionContext,
6
+ OutExtensionFactory,
7
+ OutExtensionObject,
8
+ Sourcemap,
9
+ TsdownPlugin,
10
+ TsdownPluginOption,
11
+ UserConfig,
12
+ UserConfigExport,
13
+ UserConfigFn,
14
+ } from 'tsdown';
@@ -1,2 +0,0 @@
1
- import type { UserConfig } from 'tsdown';
2
- export declare const defaultConfig: UserConfig;
@@ -1,15 +0,0 @@
1
- export const defaultConfig = {
2
- entry: ['src/index.ts', '!src/**/*.test.*', '!src/**/*.spec.*', '!**/__mocks__/**'],
3
- sourcemap: true,
4
- format: ['esm'],
5
- dts: true,
6
- // clean: true,
7
- // treeshake: 'recommended',
8
- // splitting: false,
9
- tsconfig: 'tsconfig.build.json',
10
- outExtensions({ format }) {
11
- return {
12
- js: format === 'es' ? '.js' : '.cjs',
13
- };
14
- },
15
- };
@@ -1,8 +0,0 @@
1
- import * as TsDown from 'tsdown';
2
- /**
3
- * Define a tsdown configuration with the package default (entry, format, dts, package defines, etc.).
4
- * Accepts either a config object or a function `(config, context) => config`.
5
- *
6
- * @param optionsOrFn
7
- */
8
- export declare function defineConfig(optionsOrFn: TsDown.UserConfig | TsDown.UserConfigFn): TsDown.UserConfig | TsDown.UserConfigFn;
@@ -1,15 +0,0 @@
1
- import * as TsDown from 'tsdown';
2
- import { defaultConfig } from './defaultConfig.js';
3
- import { withPackageDefine } from './withPackageDefine.js';
4
- /**
5
- * Define a tsdown configuration with the package default (entry, format, dts, package defines, etc.).
6
- * Accepts either a config object or a function `(config, context) => config`.
7
- *
8
- * @param optionsOrFn
9
- */
10
- export function defineConfig(optionsOrFn) {
11
- // @ts-ignore
12
- return TsDown.defineConfig(typeof optionsOrFn === 'function'
13
- ? (config, context) => optionsOrFn(withPackageDefine(TsDown.mergeConfig(defaultConfig, config)), context)
14
- : withPackageDefine(TsDown.mergeConfig(defaultConfig, optionsOrFn)));
15
- }
@@ -1,16 +0,0 @@
1
- import * as TsDown from 'tsdown';
2
- /**
3
- * Returns a `defineConfig`-like function that uses a custom base config instead of the package default.
4
- * Use this when you have a shared base (e.g. a library preset) and want to reuse it across multiple packages.
5
- *
6
- * @example
7
- * ```ts
8
- * // Helper for shared library preset
9
- * export const defineConfig = defineConfigWith({ format: ['esm', 'cjs'] });
10
- *
11
- * // in tsdown.config.ts
12
- * export default defineConfig({ entry: ['src/index.ts'] });
13
- * ```
14
- * @param baseConfig The base configuration to merge with the package default.
15
- */
16
- export declare function defineConfigWith(baseConfig: TsDown.UserConfig): ((optionsOrFn: TsDown.UserConfig | TsDown.UserConfigFn) => TsDown.UserConfig | TsDown.UserConfigFn);
@@ -1,26 +0,0 @@
1
- import * as TsDown from 'tsdown';
2
- import { defaultConfig } from './defaultConfig.js';
3
- import { withPackageDefine } from './withPackageDefine.js';
4
- function mergeConfig(base, extension) {
5
- return TsDown.mergeConfig(base, extension);
6
- }
7
- /**
8
- * Returns a `defineConfig`-like function that uses a custom base config instead of the package default.
9
- * Use this when you have a shared base (e.g. a library preset) and want to reuse it across multiple packages.
10
- *
11
- * @example
12
- * ```ts
13
- * // Helper for shared library preset
14
- * export const defineConfig = defineConfigWith({ format: ['esm', 'cjs'] });
15
- *
16
- * // in tsdown.config.ts
17
- * export default defineConfig({ entry: ['src/index.ts'] });
18
- * ```
19
- * @param baseConfig The base configuration to merge with the package default.
20
- */
21
- export function defineConfigWith(baseConfig) {
22
- const resolvedBaseConfig = mergeConfig(defaultConfig, baseConfig);
23
- return (optionsOrFn) => TsDown.defineConfig(typeof optionsOrFn === 'function'
24
- ? (config, context) => withPackageDefine(optionsOrFn(resolvedBaseConfig, context))
25
- : withPackageDefine(mergeConfig(resolvedBaseConfig, optionsOrFn)));
26
- }
@@ -1,2 +0,0 @@
1
- import type * as TsDown from 'tsdown';
2
- export declare function withPackageDefine<T extends TsDown.UserConfig | TsDown.InlineConfig>(config: T): T;
@@ -1,40 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import path from 'node:path';
3
- function toInt(value) {
4
- if (value == null)
5
- return undefined;
6
- const parsed = Number.parseInt(value);
7
- return Number.isNaN(parsed) ? undefined : parsed;
8
- }
9
- export function withPackageDefine(config) {
10
- let packageJSON = undefined;
11
- const cwd = config.cwd ?? process.cwd();
12
- function getPackageJSON() {
13
- if (packageJSON)
14
- return packageJSON;
15
- try {
16
- packageJSON = JSON.parse(readFileSync(path.join(cwd, 'package.json'), 'utf8'));
17
- return packageJSON;
18
- }
19
- catch {
20
- return {};
21
- }
22
- }
23
- // Ensure we do not stringify undefined values
24
- function jsonSafeStringify(value) {
25
- return JSON.stringify(value);
26
- }
27
- return {
28
- ...config,
29
- cwd,
30
- define: {
31
- __PACKAGE_NAME__: jsonSafeStringify(process.env['npm_package_name'] ?? getPackageJSON().name ?? ''),
32
- __PACKAGE_VERSION__: jsonSafeStringify(process.env['npm_package_version'] ?? getPackageJSON().version ?? ''),
33
- __PACKAGE_BUILD_NUMBER__: jsonSafeStringify(toInt(process.env['npm_package_build_number']) ??
34
- toInt(process.env['BUILD_NUMBER']) ??
35
- toInt(process.env['CI_BUILD_NUMBER']) ??
36
- Date.now()),
37
- ...config.define,
38
- },
39
- };
40
- }