@reasonabletech/config-tsup 0.1.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 +98 -0
- package/dist/index.js +133 -0
- package/dist/index.js.map +1 -0
- package/dist/src/config.d.ts +125 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/docs/README.md +30 -0
- package/docs/api/api-reference.md +337 -0
- package/docs/guides/migration.md +47 -0
- package/docs/guides/usage-guide.md +96 -0
- package/package.json +76 -0
package/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# @reasonabletech/config-tsup
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@reasonabletech/config-tsup)
|
|
4
|
+
[](https://www.npmjs.com/package/@reasonabletech/config-tsup)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
|
|
8
|
+
`@reasonabletech/config-tsup` provides shared `tsup` configuration factories for library and tooling packages. The defaults produce ESM-only output with declaration files, targeting a neutral platform — override only the options that differ from those defaults.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pnpm add -D @reasonabletech/config-tsup tsup typescript
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Peer Dependencies
|
|
17
|
+
|
|
18
|
+
| Dependency | Version | Required |
|
|
19
|
+
| ---------- | --------- | -------- |
|
|
20
|
+
| tsup | >= 8.0 | Yes |
|
|
21
|
+
| typescript | >= 5.0 | Yes |
|
|
22
|
+
|
|
23
|
+
This package generates tsup configuration objects and requires tsup 8.0+ for ESM-first defaults and TypeScript 5.0+ for type checking.
|
|
24
|
+
|
|
25
|
+
## Exported API
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import {
|
|
29
|
+
createTsupConfig,
|
|
30
|
+
configPackageConfig,
|
|
31
|
+
nodeConfig,
|
|
32
|
+
reactConfig,
|
|
33
|
+
type EsbuildOptionsFunction,
|
|
34
|
+
type TsupConfigOptions,
|
|
35
|
+
} from "@reasonabletech/config-tsup";
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
### Default Library Configuration
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
// tsup.config.ts
|
|
44
|
+
import { createTsupConfig } from "@reasonabletech/config-tsup";
|
|
45
|
+
|
|
46
|
+
export default createTsupConfig();
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Customized Configuration
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
// tsup.config.ts
|
|
53
|
+
import { createTsupConfig } from "@reasonabletech/config-tsup";
|
|
54
|
+
|
|
55
|
+
export default createTsupConfig({
|
|
56
|
+
dts: true,
|
|
57
|
+
entry: { index: "src/index.ts" },
|
|
58
|
+
external: ["react"],
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Preset Configurations
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import {
|
|
66
|
+
configPackageConfig,
|
|
67
|
+
nodeConfig,
|
|
68
|
+
reactConfig,
|
|
69
|
+
} from "@reasonabletech/config-tsup";
|
|
70
|
+
|
|
71
|
+
export default reactConfig;
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Defaults
|
|
75
|
+
|
|
76
|
+
`createTsupConfig()` defaults to:
|
|
77
|
+
|
|
78
|
+
- `entry: { index: "src/index.ts" }`
|
|
79
|
+
- `format: ["esm"]`
|
|
80
|
+
- `platform: "neutral"`
|
|
81
|
+
- `target: "ES2023"`
|
|
82
|
+
- `sourcemap: true`
|
|
83
|
+
- `treeshake: true`
|
|
84
|
+
- `splitting: false`
|
|
85
|
+
- `clean: false`
|
|
86
|
+
|
|
87
|
+
If `tsconfig` is omitted, the factory uses `tsconfig.build.json` automatically when present.
|
|
88
|
+
|
|
89
|
+
## Changelog
|
|
90
|
+
|
|
91
|
+
See [CHANGELOG.md](./CHANGELOG.md) for release history.
|
|
92
|
+
|
|
93
|
+
This package follows [Semantic Versioning](https://semver.org/). Breaking changes are documented with migration guides when applicable.
|
|
94
|
+
|
|
95
|
+
## Additional References
|
|
96
|
+
|
|
97
|
+
- [Usage Guide](./docs/guides/usage-guide.md)
|
|
98
|
+
- [Package Docs](./docs/README.md)
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
// src/config.ts
|
|
5
|
+
function includeIfDefined(obj) {
|
|
6
|
+
const result = {};
|
|
7
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
8
|
+
if (value !== void 0) {
|
|
9
|
+
result[key] = value;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
function resolveDefaultBuildTsconfigPath() {
|
|
15
|
+
const buildTsconfigFileName = "tsconfig.build.json";
|
|
16
|
+
const packageJsonPath = process.env.npm_package_json;
|
|
17
|
+
if (packageJsonPath !== void 0) {
|
|
18
|
+
const packageDir = path.dirname(packageJsonPath);
|
|
19
|
+
const packageTsconfigPath = path.join(packageDir, buildTsconfigFileName);
|
|
20
|
+
if (existsSync(packageTsconfigPath)) {
|
|
21
|
+
return packageDir === process.cwd() ? buildTsconfigFileName : packageTsconfigPath;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const cwdTsconfigPath = path.join(process.cwd(), buildTsconfigFileName);
|
|
25
|
+
if (existsSync(cwdTsconfigPath)) {
|
|
26
|
+
return buildTsconfigFileName;
|
|
27
|
+
}
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
function createTsupConfig(options = {}) {
|
|
31
|
+
const {
|
|
32
|
+
entry = { index: "src/index.ts" },
|
|
33
|
+
format = ["esm"],
|
|
34
|
+
external,
|
|
35
|
+
noExternal,
|
|
36
|
+
dts = false,
|
|
37
|
+
bundle,
|
|
38
|
+
clean = false,
|
|
39
|
+
sourcemap = true,
|
|
40
|
+
treeshake = true,
|
|
41
|
+
splitting = false,
|
|
42
|
+
platform = "neutral",
|
|
43
|
+
target = "ES2023",
|
|
44
|
+
tsconfig,
|
|
45
|
+
esbuildPlugins = [],
|
|
46
|
+
esbuildOptions,
|
|
47
|
+
define,
|
|
48
|
+
onSuccess,
|
|
49
|
+
minify,
|
|
50
|
+
terserOptions,
|
|
51
|
+
metafile
|
|
52
|
+
} = options;
|
|
53
|
+
const defaultExternal = [
|
|
54
|
+
// Peer dependencies
|
|
55
|
+
"react",
|
|
56
|
+
"react-dom",
|
|
57
|
+
"next",
|
|
58
|
+
"next/headers",
|
|
59
|
+
"next/navigation",
|
|
60
|
+
"next/server",
|
|
61
|
+
"express",
|
|
62
|
+
"electron",
|
|
63
|
+
// Node.js built-ins
|
|
64
|
+
"fs",
|
|
65
|
+
"path",
|
|
66
|
+
"os",
|
|
67
|
+
"crypto",
|
|
68
|
+
"child_process",
|
|
69
|
+
"http",
|
|
70
|
+
"https",
|
|
71
|
+
"url",
|
|
72
|
+
"events",
|
|
73
|
+
"util",
|
|
74
|
+
"stream",
|
|
75
|
+
"buffer",
|
|
76
|
+
"querystring"
|
|
77
|
+
];
|
|
78
|
+
let finalExternal;
|
|
79
|
+
if (noExternal !== void 0) {
|
|
80
|
+
finalExternal = external !== void 0 ? [...external] : void 0;
|
|
81
|
+
} else {
|
|
82
|
+
finalExternal = external !== void 0 ? [...defaultExternal, ...external] : defaultExternal;
|
|
83
|
+
}
|
|
84
|
+
const resolvedTsconfig = tsconfig ?? resolveDefaultBuildTsconfigPath();
|
|
85
|
+
const config = {
|
|
86
|
+
dts,
|
|
87
|
+
splitting,
|
|
88
|
+
sourcemap,
|
|
89
|
+
clean,
|
|
90
|
+
treeshake,
|
|
91
|
+
platform,
|
|
92
|
+
target,
|
|
93
|
+
outExtension() {
|
|
94
|
+
return { js: `.js` };
|
|
95
|
+
},
|
|
96
|
+
...includeIfDefined({
|
|
97
|
+
entry,
|
|
98
|
+
format,
|
|
99
|
+
external: finalExternal,
|
|
100
|
+
noExternal,
|
|
101
|
+
bundle,
|
|
102
|
+
tsconfig: resolvedTsconfig,
|
|
103
|
+
esbuildPlugins,
|
|
104
|
+
esbuildOptions,
|
|
105
|
+
define,
|
|
106
|
+
onSuccess,
|
|
107
|
+
minify,
|
|
108
|
+
terserOptions,
|
|
109
|
+
metafile
|
|
110
|
+
})
|
|
111
|
+
};
|
|
112
|
+
return config;
|
|
113
|
+
}
|
|
114
|
+
var configPackageConfig = createTsupConfig({
|
|
115
|
+
external: ["tsup", "esbuild"]
|
|
116
|
+
});
|
|
117
|
+
var reactConfig = createTsupConfig({
|
|
118
|
+
external: ["@mui/icons-material"],
|
|
119
|
+
esbuildOptions(options) {
|
|
120
|
+
return {
|
|
121
|
+
...options,
|
|
122
|
+
jsx: "automatic"
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
var nodeConfig = createTsupConfig({
|
|
127
|
+
platform: "node",
|
|
128
|
+
external: ["dotenv"]
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
export { configPackageConfig, createTsupConfig, nodeConfig, reactConfig };
|
|
132
|
+
//# sourceMappingURL=index.js.map
|
|
133
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config.ts"],"names":[],"mappings":";;;;AAMA,SAAS,iBACP,GAAA,EACyB;AACzB,EAAA,MAAM,SAAkC,EAAC;AACzC,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,GAAG,CAAA,EAAG;AAC9C,IAAA,IAAI,UAAU,MAAA,EAAW;AACvB,MAAA,MAAA,CAAO,GAAG,CAAA,GAAI,KAAA;AAAA,IAChB;AAAA,EACF;AACA,EAAA,OAAO,MA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AAA,MACA,SAAA;AAAA,MACA,MAAA;AAAA,MACA,aAAA;AAAA,MACA;AAAA,KACD;AAAA,GACH;AAcA,EAAA,OAAO,MAAA;AACT;AAKO,IAAM,sBAAsB,gBAAA,CAAiB;AAAA,EAClD,QAAA,EAAU,CAAC,MAAA,EAAQ,SAAS;AAC9B,CAAC;AAKM,IAAM,cAAc,gBAAA,CAAiB;AAAA,EAC1C,QAAA,EAAU,CAAC,qBAAqB,CAAA;AAAA,EAEhC,eAAe,OAAA,EAAiC;AAC9C,IAAA,OAAO;AAAA,MACL,GAAG,OAAA;AAAA,MACH,GAAA,EAAK;AAAA,KACP;AAAA,EACF;AACF,CAAC;AAKM,IAAM,aAAa,gBAAA,CAAiB;AAAA,EACzC,QAAA,EAAU,MAAA;AAAA,EACV,QAAA,EAAU,CAAC,QAAQ;AACrB,CAAC","file":"index.js","sourcesContent":["import { type Options } from \"tsup\";\nimport type { BuildOptions } from \"esbuild\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\n\n// Local utility to avoid circular dependency with @reasonabletech/utils\nfunction includeIfDefined<T extends Record<string, unknown>>(\n obj: T,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n if (value !== undefined) {\n result[key] = value;\n }\n }\n return result;\n}\n\nfunction resolveDefaultBuildTsconfigPath(): string | undefined {\n const buildTsconfigFileName = \"tsconfig.build.json\";\n const packageJsonPath = process.env.npm_package_json;\n\n if (packageJsonPath !== undefined) {\n const packageDir = path.dirname(packageJsonPath);\n const packageTsconfigPath = path.join(packageDir, buildTsconfigFileName);\n if (existsSync(packageTsconfigPath)) {\n return packageDir === process.cwd()\n ? buildTsconfigFileName\n : packageTsconfigPath;\n }\n }\n\n const cwdTsconfigPath = path.join(process.cwd(), buildTsconfigFileName);\n if (existsSync(cwdTsconfigPath)) {\n return buildTsconfigFileName;\n }\n\n return undefined;\n}\n\n/**\n * Function signature for customizing tsup's `esbuildOptions`.\n */\nexport type EsbuildOptionsFunction = (\n options: Readonly<BuildOptions>,\n) => BuildOptions;\n\n/**\n * Configuration options for creating a tsup build configuration.\n */\nexport interface TsupConfigOptions {\n /**\n * Entry points for the build. Can be a string, array, or object.\n * Defaults to { index: \"src/index.ts\" }\n */\n readonly entry?:\n | Readonly<Record<string, string>>\n | string\n | readonly string[];\n\n /**\n * Output formats. Defaults to [\"esm\"].\n * ESM is the standard - other formats are strongly discouraged except with compelling justification.\n */\n readonly format?: ReadonlyArray<\"esm\" | \"cjs\" | \"iife\">;\n\n /**\n * External dependencies that should not be bundled.\n * If not provided, sensible defaults are used based on platform.\n * To override defaults completely, use noExternal: [/.*\\/] and provide exact externals.\n */\n readonly external?: readonly string[];\n\n /**\n * Dependencies that should always be bundled (opposite of external).\n * Use [/.*\\/] to bundle everything except what's in external array.\n */\n readonly noExternal?: ReadonlyArray<string | RegExp>;\n\n /**\n * Whether to generate TypeScript declaration files. Defaults to false.\n */\n readonly dts?: boolean;\n\n /**\n * Whether to generate source maps. Defaults to true.\n */\n readonly sourcemap?: boolean;\n\n /**\n * Whether to bundle dependencies. Defaults to true.\n */\n readonly bundle?: boolean;\n\n /**\n * Whether to clean the output directory before building. Defaults to false.\n *\n * Rationale: A non-clean default avoids deleting artifacts unexpectedly in\n * multi-step builds and keeps incremental local workflows predictable.\n * Packages that need cleaning can explicitly set clean=true.\n */\n readonly clean?: boolean;\n\n /**\n * Whether to enable tree shaking. Defaults to true.\n */\n readonly treeshake?: boolean;\n\n /**\n * Whether to enable code splitting. Defaults to false for better compatibility.\n */\n readonly splitting?: boolean;\n\n /**\n * Target platform. Defaults to \"neutral\" for libraries.\n */\n readonly platform?: \"node\" | \"browser\" | \"neutral\";\n\n /**\n * Target environment. Defaults to \"ES2023\" (Node.js 22 compatible).\n */\n readonly target?: string;\n\n /**\n * Path to TypeScript config file.\n */\n readonly tsconfig?: string;\n\n /**\n * Additional esbuild plugins.\n */\n readonly esbuildPlugins?: readonly unknown[];\n\n /**\n * Custom esbuild options function.\n */\n readonly esbuildOptions?: (options: Readonly<BuildOptions>) => BuildOptions;\n\n /**\n * Build-time environment variable definitions.\n */\n readonly define?: Readonly<Record<string, string>>;\n\n /**\n * Custom onSuccess callback.\n */\n readonly onSuccess?: () => void | Promise<void>;\n\n /**\n * Minification options.\n */\n readonly minify?: boolean | \"terser\";\n\n /**\n * Terser-specific options (when minify: \"terser\").\n */\n readonly terserOptions?: {\n readonly compress?: Record<string, unknown>;\n readonly mangle?: Record<string, unknown>;\n };\n\n /**\n * Whether to generate metafile for bundle analysis.\n */\n readonly metafile?: boolean;\n}\n\n/**\n * Base tsup configuration for packages in the ReasonableTech project.\n *\n * This configuration provides sensible defaults for most packages while allowing\n * for customization through options or by extending this configuration.\n * @param options Configuration options to customize the tsup build\n * @returns Configured tsup build settings\n */\nexport function createTsupConfig(\n options: TsupConfigOptions = {},\n): Options {\n const {\n entry = { index: \"src/index.ts\" },\n format = [\"esm\"],\n external,\n noExternal,\n dts = false,\n bundle,\n clean = false,\n sourcemap = true,\n treeshake = true,\n splitting = false,\n platform = \"neutral\",\n target = \"ES2023\",\n tsconfig,\n esbuildPlugins = [],\n esbuildOptions,\n define,\n onSuccess,\n minify,\n terserOptions,\n metafile,\n } = options;\n\n // Default externals - only used if user doesn't provide noExternal\n const defaultExternal = [\n // Peer dependencies\n \"react\",\n \"react-dom\",\n \"next\",\n \"next/headers\",\n \"next/navigation\",\n \"next/server\",\n \"express\",\n \"electron\",\n // Node.js built-ins\n \"fs\",\n \"path\",\n \"os\",\n \"crypto\",\n \"child_process\",\n \"http\",\n \"https\",\n \"url\",\n \"events\",\n \"util\",\n \"stream\",\n \"buffer\",\n \"querystring\",\n ];\n\n // Determine final external list\n let finalExternal: string[] | undefined;\n if (noExternal !== undefined) {\n // If noExternal is provided, only use the explicit external list\n finalExternal = external !== undefined ? [...external] : undefined;\n } else {\n // Default behavior: merge user external with defaults\n finalExternal =\n external !== undefined\n ? [...defaultExternal, ...external]\n : defaultExternal;\n }\n\n const resolvedTsconfig = tsconfig ?? resolveDefaultBuildTsconfigPath();\n\n const config: Options = {\n dts,\n splitting,\n sourcemap,\n clean,\n treeshake,\n platform,\n target,\n outExtension() {\n return { js: `.js` };\n },\n ...includeIfDefined({\n entry: entry as Options[\"entry\"],\n format: format as Options[\"format\"],\n external: finalExternal as Options[\"external\"],\n noExternal: noExternal as Options[\"noExternal\"],\n bundle,\n tsconfig: resolvedTsconfig,\n esbuildPlugins,\n esbuildOptions,\n define,\n onSuccess,\n minify,\n terserOptions,\n metafile,\n }),\n };\n // ...(tsconfig !== undefined ? { tsconfig } : {}),\n // ...(esbuildPlugins.length > 0\n // ? { esbuildPlugins: esbuildPlugins as Options[\"esbuildPlugins\"] }\n // : {}),\n // ...(esbuildOptions !== undefined\n // ? { esbuildOptions: esbuildOptions as Options[\"esbuildOptions\"] }\n // : {}),\n // ...(define !== undefined ? { define: define as Options[\"define\"] } : {}),\n // ...(onSuccess !== undefined\n // ? { onSuccess: onSuccess as Options[\"onSuccess\"] }\n // : {}),\n // };\n\n return config;\n}\n\n/**\n * Pre-configured tsup config for build/config packages.\n */\nexport const configPackageConfig = createTsupConfig({\n external: [\"tsup\", \"esbuild\"],\n});\n\n/**\n * Pre-configured tsup config for React component libraries.\n */\nexport const reactConfig = createTsupConfig({\n external: [\"@mui/icons-material\"],\n\n esbuildOptions(options: Readonly<BuildOptions>) {\n return {\n ...options,\n jsx: \"automatic\",\n };\n },\n});\n\n/**\n * Pre-configured tsup config for Node.js applications/CLIs.\n */\nexport const nodeConfig = createTsupConfig({\n platform: \"node\",\n external: [\"dotenv\"],\n});\n"]}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { type Options } from "tsup";
|
|
2
|
+
import type { BuildOptions } from "esbuild";
|
|
3
|
+
/**
|
|
4
|
+
* Function signature for customizing tsup's `esbuildOptions`.
|
|
5
|
+
*/
|
|
6
|
+
export type EsbuildOptionsFunction = (options: Readonly<BuildOptions>) => BuildOptions;
|
|
7
|
+
/**
|
|
8
|
+
* Configuration options for creating a tsup build configuration.
|
|
9
|
+
*/
|
|
10
|
+
export interface TsupConfigOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Entry points for the build. Can be a string, array, or object.
|
|
13
|
+
* Defaults to { index: "src/index.ts" }
|
|
14
|
+
*/
|
|
15
|
+
readonly entry?: Readonly<Record<string, string>> | string | readonly string[];
|
|
16
|
+
/**
|
|
17
|
+
* Output formats. Defaults to ["esm"].
|
|
18
|
+
* ESM is the standard - other formats are strongly discouraged except with compelling justification.
|
|
19
|
+
*/
|
|
20
|
+
readonly format?: ReadonlyArray<"esm" | "cjs" | "iife">;
|
|
21
|
+
/**
|
|
22
|
+
* External dependencies that should not be bundled.
|
|
23
|
+
* If not provided, sensible defaults are used based on platform.
|
|
24
|
+
* To override defaults completely, use noExternal: [/.*\/] and provide exact externals.
|
|
25
|
+
*/
|
|
26
|
+
readonly external?: readonly string[];
|
|
27
|
+
/**
|
|
28
|
+
* Dependencies that should always be bundled (opposite of external).
|
|
29
|
+
* Use [/.*\/] to bundle everything except what's in external array.
|
|
30
|
+
*/
|
|
31
|
+
readonly noExternal?: ReadonlyArray<string | RegExp>;
|
|
32
|
+
/**
|
|
33
|
+
* Whether to generate TypeScript declaration files. Defaults to false.
|
|
34
|
+
*/
|
|
35
|
+
readonly dts?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Whether to generate source maps. Defaults to true.
|
|
38
|
+
*/
|
|
39
|
+
readonly sourcemap?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Whether to bundle dependencies. Defaults to true.
|
|
42
|
+
*/
|
|
43
|
+
readonly bundle?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Whether to clean the output directory before building. Defaults to false.
|
|
46
|
+
*
|
|
47
|
+
* Rationale: A non-clean default avoids deleting artifacts unexpectedly in
|
|
48
|
+
* multi-step builds and keeps incremental local workflows predictable.
|
|
49
|
+
* Packages that need cleaning can explicitly set clean=true.
|
|
50
|
+
*/
|
|
51
|
+
readonly clean?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Whether to enable tree shaking. Defaults to true.
|
|
54
|
+
*/
|
|
55
|
+
readonly treeshake?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Whether to enable code splitting. Defaults to false for better compatibility.
|
|
58
|
+
*/
|
|
59
|
+
readonly splitting?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Target platform. Defaults to "neutral" for libraries.
|
|
62
|
+
*/
|
|
63
|
+
readonly platform?: "node" | "browser" | "neutral";
|
|
64
|
+
/**
|
|
65
|
+
* Target environment. Defaults to "ES2023" (Node.js 22 compatible).
|
|
66
|
+
*/
|
|
67
|
+
readonly target?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Path to TypeScript config file.
|
|
70
|
+
*/
|
|
71
|
+
readonly tsconfig?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Additional esbuild plugins.
|
|
74
|
+
*/
|
|
75
|
+
readonly esbuildPlugins?: readonly unknown[];
|
|
76
|
+
/**
|
|
77
|
+
* Custom esbuild options function.
|
|
78
|
+
*/
|
|
79
|
+
readonly esbuildOptions?: (options: Readonly<BuildOptions>) => BuildOptions;
|
|
80
|
+
/**
|
|
81
|
+
* Build-time environment variable definitions.
|
|
82
|
+
*/
|
|
83
|
+
readonly define?: Readonly<Record<string, string>>;
|
|
84
|
+
/**
|
|
85
|
+
* Custom onSuccess callback.
|
|
86
|
+
*/
|
|
87
|
+
readonly onSuccess?: () => void | Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Minification options.
|
|
90
|
+
*/
|
|
91
|
+
readonly minify?: boolean | "terser";
|
|
92
|
+
/**
|
|
93
|
+
* Terser-specific options (when minify: "terser").
|
|
94
|
+
*/
|
|
95
|
+
readonly terserOptions?: {
|
|
96
|
+
readonly compress?: Record<string, unknown>;
|
|
97
|
+
readonly mangle?: Record<string, unknown>;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Whether to generate metafile for bundle analysis.
|
|
101
|
+
*/
|
|
102
|
+
readonly metafile?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Base tsup configuration for packages in the ReasonableTech project.
|
|
106
|
+
*
|
|
107
|
+
* This configuration provides sensible defaults for most packages while allowing
|
|
108
|
+
* for customization through options or by extending this configuration.
|
|
109
|
+
* @param options Configuration options to customize the tsup build
|
|
110
|
+
* @returns Configured tsup build settings
|
|
111
|
+
*/
|
|
112
|
+
export declare function createTsupConfig(options?: TsupConfigOptions): Options;
|
|
113
|
+
/**
|
|
114
|
+
* Pre-configured tsup config for build/config packages.
|
|
115
|
+
*/
|
|
116
|
+
export declare const configPackageConfig: Options;
|
|
117
|
+
/**
|
|
118
|
+
* Pre-configured tsup config for React component libraries.
|
|
119
|
+
*/
|
|
120
|
+
export declare const reactConfig: Options;
|
|
121
|
+
/**
|
|
122
|
+
* Pre-configured tsup config for Node.js applications/CLIs.
|
|
123
|
+
*/
|
|
124
|
+
export declare const nodeConfig: Options;
|
|
125
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAuC5C;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,CACnC,OAAO,EAAE,QAAQ,CAAC,YAAY,CAAC,KAC5B,YAAY,CAAC;AAElB;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EACX,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAChC,MAAM,GACN,SAAS,MAAM,EAAE,CAAC;IAEtB;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,KAAK,GAA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CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IAErC;;OAEG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE;QACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC3C,CAAC;IAEF;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CA2GT;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,SAE9B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,WAAW,SAStB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,UAAU,SAGrB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAErB,YAAY,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @reasonabletech/config-tsup Documentation
|
|
2
|
+
|
|
3
|
+
Reference documentation for shared `tsup` configuration in the core-utils monorepo.
|
|
4
|
+
|
|
5
|
+
## Start Here
|
|
6
|
+
|
|
7
|
+
- [Usage Guide](./guides/usage-guide.md)
|
|
8
|
+
|
|
9
|
+
## API Reference
|
|
10
|
+
|
|
11
|
+
- [API Reference](./api/api-reference.md) — Factory functions, options, and preset configs
|
|
12
|
+
|
|
13
|
+
## Quick Example
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// tsup.config.ts
|
|
17
|
+
import { createTsupConfig } from "@reasonabletech/config-tsup";
|
|
18
|
+
|
|
19
|
+
export default createTsupConfig({
|
|
20
|
+
dts: true,
|
|
21
|
+
clean: true,
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Monorepo Context
|
|
26
|
+
|
|
27
|
+
- [Package README](../README.md)
|
|
28
|
+
- [Architecture](../../../docs/architecture.md) — How packages relate
|
|
29
|
+
- [Tooling](../../../docs/tooling.md) — Turbo, Changesets, tsup details
|
|
30
|
+
- [Contributing](../../../CONTRIBUTING.md)
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
# config-tsup API Reference
|
|
2
|
+
|
|
3
|
+
## Package Exports
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import {
|
|
7
|
+
createTsupConfig,
|
|
8
|
+
reactConfig,
|
|
9
|
+
nodeConfig,
|
|
10
|
+
configPackageConfig,
|
|
11
|
+
} from "@reasonabletech/config-tsup";
|
|
12
|
+
|
|
13
|
+
import type {
|
|
14
|
+
TsupConfigOptions,
|
|
15
|
+
EsbuildOptionsFunction,
|
|
16
|
+
} from "@reasonabletech/config-tsup";
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Factory Function
|
|
22
|
+
|
|
23
|
+
### `createTsupConfig(options?)`
|
|
24
|
+
|
|
25
|
+
Creates a customized tsup build configuration with sensible defaults for TypeScript libraries.
|
|
26
|
+
|
|
27
|
+
**Signature:**
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
function createTsupConfig(options?: TsupConfigOptions): Options;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Parameters:**
|
|
34
|
+
|
|
35
|
+
| Parameter | Type | Default | Description |
|
|
36
|
+
| --------- | ------------------ | ------- | ----------------------------- |
|
|
37
|
+
| `options` | `TsupConfigOptions` | `{}` | Configuration options object |
|
|
38
|
+
|
|
39
|
+
**Returns:** `Options` — A tsup configuration object
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Configuration Options
|
|
44
|
+
|
|
45
|
+
### `TsupConfigOptions`
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
interface TsupConfigOptions {
|
|
49
|
+
entry?: Record<string, string> | string | string[];
|
|
50
|
+
format?: Array<"esm" | "cjs" | "iife">;
|
|
51
|
+
external?: string[];
|
|
52
|
+
noExternal?: Array<string | RegExp>;
|
|
53
|
+
dts?: boolean;
|
|
54
|
+
sourcemap?: boolean;
|
|
55
|
+
bundle?: boolean;
|
|
56
|
+
clean?: boolean;
|
|
57
|
+
treeshake?: boolean;
|
|
58
|
+
splitting?: boolean;
|
|
59
|
+
platform?: "node" | "browser" | "neutral";
|
|
60
|
+
target?: string;
|
|
61
|
+
tsconfig?: string;
|
|
62
|
+
esbuildPlugins?: unknown[];
|
|
63
|
+
esbuildOptions?: EsbuildOptionsFunction;
|
|
64
|
+
define?: Record<string, string>;
|
|
65
|
+
onSuccess?: () => void | Promise<void>;
|
|
66
|
+
minify?: boolean | "terser";
|
|
67
|
+
terserOptions?: {
|
|
68
|
+
compress?: Record<string, unknown>;
|
|
69
|
+
mangle?: Record<string, unknown>;
|
|
70
|
+
};
|
|
71
|
+
metafile?: boolean;
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Option Details
|
|
76
|
+
|
|
77
|
+
| Option | Type | Default | Description |
|
|
78
|
+
| ----------------- | -------------------------------------- | ------------------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
79
|
+
| `entry` | `Record<string, string> \| string \| string[]` | `{ index: "src/index.ts" }` | Entry points for the build |
|
|
80
|
+
| `format` | `Array<"esm" \| "cjs" \| "iife">` | `["esm"]` | Output formats. ESM is standard; other formats are discouraged except with compelling justification |
|
|
81
|
+
| `external` | `string[]` | See below | Dependencies that should not be bundled |
|
|
82
|
+
| `noExternal` | `Array<string \| RegExp>` | `undefined` | Dependencies that should always be bundled. Use `[/.*/]` to bundle everything except explicit externals |
|
|
83
|
+
| `dts` | `boolean` | `false` | Generate TypeScript declaration files |
|
|
84
|
+
| `sourcemap` | `boolean` | `true` | Generate source maps |
|
|
85
|
+
| `bundle` | `boolean` | `undefined` (tsup default) | Bundle dependencies |
|
|
86
|
+
| `clean` | `boolean` | `false` | Clean output directory before building. Non-clean default avoids deleting artifacts in multi-step builds |
|
|
87
|
+
| `treeshake` | `boolean` | `true` | Enable tree shaking |
|
|
88
|
+
| `splitting` | `boolean` | `false` | Enable code splitting. Disabled by default for better compatibility |
|
|
89
|
+
| `platform` | `"node" \| "browser" \| "neutral"` | `"neutral"` | Target platform. "neutral" is best for libraries |
|
|
90
|
+
| `target` | `string` | `"ES2023"` | Target environment (Node.js 22 compatible) |
|
|
91
|
+
| `tsconfig` | `string` | Auto-detected | Path to TypeScript config file. Auto-resolves `tsconfig.build.json` if present |
|
|
92
|
+
| `esbuildPlugins` | `unknown[]` | `[]` | Additional esbuild plugins |
|
|
93
|
+
| `esbuildOptions` | `EsbuildOptionsFunction` | `undefined` | Custom esbuild options transformer |
|
|
94
|
+
| `define` | `Record<string, string>` | `undefined` | Build-time environment variable definitions |
|
|
95
|
+
| `onSuccess` | `() => void \| Promise<void>` | `undefined` | Callback executed after successful build |
|
|
96
|
+
| `minify` | `boolean \| "terser"` | `undefined` | Minification options |
|
|
97
|
+
| `terserOptions` | `object` | `undefined` | Terser-specific options (when `minify: "terser"`) |
|
|
98
|
+
| `metafile` | `boolean` | `undefined` | Generate metafile for bundle analysis |
|
|
99
|
+
|
|
100
|
+
### Default Externals
|
|
101
|
+
|
|
102
|
+
When `noExternal` is not provided, these dependencies are automatically externalized:
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const defaultExternal = [
|
|
106
|
+
// Peer dependencies
|
|
107
|
+
"react", "react-dom", "next", "next/headers", "next/navigation",
|
|
108
|
+
"next/server", "express", "electron",
|
|
109
|
+
// Node.js built-ins
|
|
110
|
+
"fs", "path", "os", "crypto", "child_process", "http", "https",
|
|
111
|
+
"url", "events", "util", "stream", "buffer", "querystring",
|
|
112
|
+
];
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Type Exports
|
|
118
|
+
|
|
119
|
+
### `EsbuildOptionsFunction`
|
|
120
|
+
|
|
121
|
+
Function signature for customizing tsup's `esbuildOptions`.
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
type EsbuildOptionsFunction = (options: Readonly<BuildOptions>) => BuildOptions;
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Preset Configurations
|
|
130
|
+
|
|
131
|
+
### `configPackageConfig`
|
|
132
|
+
|
|
133
|
+
Pre-configured config for build/config packages (like this one).
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
const configPackageConfig = createTsupConfig({
|
|
137
|
+
external: ["tsup", "esbuild"],
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Use for:** Packages that provide configuration (eslint configs, tsup configs, etc.)
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
### `reactConfig`
|
|
146
|
+
|
|
147
|
+
Pre-configured config for React component libraries.
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
const reactConfig = createTsupConfig({
|
|
151
|
+
external: ["@mui/icons-material"],
|
|
152
|
+
esbuildOptions(options) {
|
|
153
|
+
return {
|
|
154
|
+
...options,
|
|
155
|
+
jsx: "automatic",
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Includes:**
|
|
162
|
+
|
|
163
|
+
- Automatic JSX transform (no React import required)
|
|
164
|
+
- `@mui/icons-material` externalized
|
|
165
|
+
|
|
166
|
+
**Use for:** React UI component libraries
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
### `nodeConfig`
|
|
171
|
+
|
|
172
|
+
Pre-configured config for Node.js applications and CLIs.
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
const nodeConfig = createTsupConfig({
|
|
176
|
+
platform: "node",
|
|
177
|
+
external: ["dotenv"],
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
**Includes:**
|
|
182
|
+
|
|
183
|
+
- Platform set to `"node"`
|
|
184
|
+
- `dotenv` externalized
|
|
185
|
+
|
|
186
|
+
**Use for:** Node.js servers, CLIs, and backend utilities
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Usage Examples
|
|
191
|
+
|
|
192
|
+
### Basic Library
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
// tsup.config.ts
|
|
196
|
+
import { createTsupConfig } from "@reasonabletech/config-tsup";
|
|
197
|
+
|
|
198
|
+
export default createTsupConfig();
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Library with Declaration Files
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
// tsup.config.ts
|
|
205
|
+
import { createTsupConfig } from "@reasonabletech/config-tsup";
|
|
206
|
+
|
|
207
|
+
export default createTsupConfig({
|
|
208
|
+
dts: true,
|
|
209
|
+
clean: true,
|
|
210
|
+
});
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Multiple Entry Points
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
// tsup.config.ts
|
|
217
|
+
import { createTsupConfig } from "@reasonabletech/config-tsup";
|
|
218
|
+
|
|
219
|
+
export default createTsupConfig({
|
|
220
|
+
entry: {
|
|
221
|
+
index: "src/index.ts",
|
|
222
|
+
cli: "src/cli.ts",
|
|
223
|
+
utils: "src/utils/index.ts",
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### React Component Library
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
// tsup.config.ts
|
|
232
|
+
import { reactConfig } from "@reasonabletech/config-tsup";
|
|
233
|
+
|
|
234
|
+
export default reactConfig;
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Custom React Config with Overrides
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
// tsup.config.ts
|
|
241
|
+
import { createTsupConfig } from "@reasonabletech/config-tsup";
|
|
242
|
+
|
|
243
|
+
export default createTsupConfig({
|
|
244
|
+
external: ["@mui/icons-material", "framer-motion"],
|
|
245
|
+
esbuildOptions(options) {
|
|
246
|
+
return {
|
|
247
|
+
...options,
|
|
248
|
+
jsx: "automatic",
|
|
249
|
+
jsxImportSource: "@emotion/react",
|
|
250
|
+
};
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Node.js CLI Application
|
|
256
|
+
|
|
257
|
+
```typescript
|
|
258
|
+
// tsup.config.ts
|
|
259
|
+
import { createTsupConfig } from "@reasonabletech/config-tsup";
|
|
260
|
+
|
|
261
|
+
export default createTsupConfig({
|
|
262
|
+
entry: { cli: "src/cli.ts" },
|
|
263
|
+
platform: "node",
|
|
264
|
+
external: ["dotenv", "commander"],
|
|
265
|
+
minify: true,
|
|
266
|
+
});
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Bundle All Dependencies
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
// tsup.config.ts
|
|
273
|
+
import { createTsupConfig } from "@reasonabletech/config-tsup";
|
|
274
|
+
|
|
275
|
+
export default createTsupConfig({
|
|
276
|
+
noExternal: [/.*/],
|
|
277
|
+
external: ["react", "react-dom"], // Only externalize peer deps
|
|
278
|
+
});
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### Config Package
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
// tsup.config.ts
|
|
285
|
+
import { configPackageConfig } from "@reasonabletech/config-tsup";
|
|
286
|
+
|
|
287
|
+
export default configPackageConfig;
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### With Build-Time Definitions
|
|
291
|
+
|
|
292
|
+
```typescript
|
|
293
|
+
// tsup.config.ts
|
|
294
|
+
import { createTsupConfig } from "@reasonabletech/config-tsup";
|
|
295
|
+
|
|
296
|
+
export default createTsupConfig({
|
|
297
|
+
define: {
|
|
298
|
+
"process.env.PACKAGE_VERSION": JSON.stringify(process.env.npm_package_version),
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### Production Build with Minification
|
|
304
|
+
|
|
305
|
+
```typescript
|
|
306
|
+
// tsup.config.ts
|
|
307
|
+
import { createTsupConfig } from "@reasonabletech/config-tsup";
|
|
308
|
+
|
|
309
|
+
export default createTsupConfig({
|
|
310
|
+
minify: "terser",
|
|
311
|
+
terserOptions: {
|
|
312
|
+
compress: { drop_console: true },
|
|
313
|
+
},
|
|
314
|
+
clean: true,
|
|
315
|
+
metafile: true,
|
|
316
|
+
});
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## tsconfig Auto-Resolution
|
|
322
|
+
|
|
323
|
+
The `tsconfig` option auto-resolves in this order:
|
|
324
|
+
|
|
325
|
+
1. If `tsconfig` is explicitly provided, use it
|
|
326
|
+
2. Look for `tsconfig.build.json` in the package directory (via `npm_package_json`)
|
|
327
|
+
3. Look for `tsconfig.build.json` in the current working directory
|
|
328
|
+
4. Fall back to tsup's default behavior
|
|
329
|
+
|
|
330
|
+
This allows packages to use a separate `tsconfig.build.json` for builds while keeping `tsconfig.json` for IDE/editor use.
|
|
331
|
+
|
|
332
|
+
---
|
|
333
|
+
|
|
334
|
+
## Related Documentation
|
|
335
|
+
|
|
336
|
+
- [Usage Guide](../guides/usage-guide.md) — Setup and common patterns
|
|
337
|
+
- [Package README](../../README.md) — Quick start
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Migration Guide
|
|
2
|
+
|
|
3
|
+
This guide documents breaking changes and how to migrate between major versions of @reasonabletech/config-tsup.
|
|
4
|
+
|
|
5
|
+
## Current Version
|
|
6
|
+
|
|
7
|
+
The current major version is **0.x** (pre-1.0). The API is stabilizing but may have breaking changes before 1.0.
|
|
8
|
+
|
|
9
|
+
## Future Migration Notes
|
|
10
|
+
|
|
11
|
+
_No breaking changes documented yet. This section will be updated when breaking changes are released._
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Migration Template
|
|
16
|
+
|
|
17
|
+
When documenting a breaking change, use this structure:
|
|
18
|
+
|
|
19
|
+
### Migrating from X.x to Y.0
|
|
20
|
+
|
|
21
|
+
#### Breaking Changes
|
|
22
|
+
|
|
23
|
+
1. **Change description** - Brief explanation of what changed
|
|
24
|
+
|
|
25
|
+
**Before:**
|
|
26
|
+
```typescript
|
|
27
|
+
// Old usage
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**After:**
|
|
31
|
+
```typescript
|
|
32
|
+
// New usage
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
2. **Another change** - Description
|
|
36
|
+
|
|
37
|
+
#### Deprecations
|
|
38
|
+
|
|
39
|
+
- `oldFunction()` is deprecated in favor of `newFunction()`
|
|
40
|
+
|
|
41
|
+
#### New Features
|
|
42
|
+
|
|
43
|
+
- Feature description
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
_Last updated: [date]_
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# @reasonabletech/config-tsup Usage Guide
|
|
2
|
+
|
|
3
|
+
This guide covers canonical usage of `@reasonabletech/config-tsup` for greenfield package builds.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @reasonabletech/config-tsup tsup typescript
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// tsup.config.ts
|
|
15
|
+
import { createTsupConfig } from "@reasonabletech/config-tsup";
|
|
16
|
+
|
|
17
|
+
export default createTsupConfig();
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Exported API
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import {
|
|
24
|
+
createTsupConfig,
|
|
25
|
+
configPackageConfig,
|
|
26
|
+
nodeConfig,
|
|
27
|
+
reactConfig,
|
|
28
|
+
type EsbuildOptionsFunction,
|
|
29
|
+
type TsupConfigOptions,
|
|
30
|
+
} from "@reasonabletech/config-tsup";
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Common Configuration Patterns
|
|
34
|
+
|
|
35
|
+
### Library Build
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { createTsupConfig } from "@reasonabletech/config-tsup";
|
|
39
|
+
|
|
40
|
+
export default createTsupConfig({
|
|
41
|
+
dts: true,
|
|
42
|
+
entry: { index: "src/index.ts" },
|
|
43
|
+
format: ["esm"],
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### React Component Package
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { reactConfig } from "@reasonabletech/config-tsup";
|
|
51
|
+
|
|
52
|
+
export default reactConfig;
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Node Runtime Package
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { nodeConfig } from "@reasonabletech/config-tsup";
|
|
59
|
+
|
|
60
|
+
export default nodeConfig;
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Config/Tooling Package
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { configPackageConfig } from "@reasonabletech/config-tsup";
|
|
67
|
+
|
|
68
|
+
export default configPackageConfig;
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Defaults from `createTsupConfig()`
|
|
72
|
+
|
|
73
|
+
- `entry: { index: "src/index.ts" }`
|
|
74
|
+
- `format: ["esm"]`
|
|
75
|
+
- `platform: "neutral"`
|
|
76
|
+
- `target: "ES2023"`
|
|
77
|
+
- `sourcemap: true`
|
|
78
|
+
- `treeshake: true`
|
|
79
|
+
- `splitting: false`
|
|
80
|
+
- `clean: false`
|
|
81
|
+
|
|
82
|
+
When `tsconfig` is omitted, the factory uses `tsconfig.build.json` automatically if present.
|
|
83
|
+
|
|
84
|
+
## Troubleshooting
|
|
85
|
+
|
|
86
|
+
### Unexpected bundled dependencies
|
|
87
|
+
|
|
88
|
+
Use `external` and `noExternal` explicitly if your package has strict bundling requirements.
|
|
89
|
+
|
|
90
|
+
### Wrong TypeScript config used
|
|
91
|
+
|
|
92
|
+
Pass `tsconfig` directly to `createTsupConfig` if your package does not use `tsconfig.build.json`.
|
|
93
|
+
|
|
94
|
+
## Related Documentation
|
|
95
|
+
|
|
96
|
+
- [Package README](../../README.md)
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reasonabletech/config-tsup",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared tsup configuration for ReasonableTech packages",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"reasonabletech",
|
|
7
|
+
"config",
|
|
8
|
+
"typescript",
|
|
9
|
+
"tsup",
|
|
10
|
+
"bundler",
|
|
11
|
+
"build-config",
|
|
12
|
+
"esm",
|
|
13
|
+
"esbuild"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"module": "dist/index.js",
|
|
18
|
+
"types": "./dist/src/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/src/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"docs/**/*"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public",
|
|
31
|
+
"registry": "https://registry.npmjs.org/"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "25.3.1",
|
|
35
|
+
"@vitest/coverage-v8": "4.0.18",
|
|
36
|
+
"esbuild": "0.27.3",
|
|
37
|
+
"eslint": "10.0.2",
|
|
38
|
+
"tsup": "8.5.1",
|
|
39
|
+
"typescript": "5.9.3",
|
|
40
|
+
"vitest": "4.0.18",
|
|
41
|
+
"@reasonabletech/config-eslint": "0.1.0",
|
|
42
|
+
"@reasonabletech/config-typescript": "0.1.0"
|
|
43
|
+
},
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"author": "Reasonable Tech Company",
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "https://github.com/ReasonableTech/core-utils.git",
|
|
49
|
+
"directory": "packages/config-tsup"
|
|
50
|
+
},
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/ReasonableTech/core-utils/issues"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://github.com/ReasonableTech/core-utils/tree/main/packages/config-tsup",
|
|
55
|
+
"sideEffects": false,
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=22"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsup && tsc --emitDeclarationOnly -p tsconfig.build.json",
|
|
61
|
+
"clean": "rm -rf dist .turbo node_modules tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo",
|
|
62
|
+
"dev": "tsup --watch",
|
|
63
|
+
"docs:coverage": "tsx ../../../scripts/analysis/check-doc-coverage.ts --html",
|
|
64
|
+
"lint": "eslint . --fix",
|
|
65
|
+
"lint:check": "eslint .",
|
|
66
|
+
"test": "vitest run",
|
|
67
|
+
"test:coverage": "vitest run --coverage",
|
|
68
|
+
"test:e2e": "vitest run tests/e2e",
|
|
69
|
+
"test:integration": "vitest run tests/integration",
|
|
70
|
+
"test:ui": "vitest --ui",
|
|
71
|
+
"test:unit": "vitest run tests/unit",
|
|
72
|
+
"test:watch": "vitest --watch",
|
|
73
|
+
"typecheck": "tsc --noEmit",
|
|
74
|
+
"verify:release": "pnpm typecheck && pnpm lint:check && pnpm test && pnpm build"
|
|
75
|
+
}
|
|
76
|
+
}
|