@dbarrett24/tsdown-config 1.0.1

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.
@@ -0,0 +1,20 @@
1
+ import { UserConfig } from "tsdown";
2
+
3
+ //#region index.d.ts
4
+ declare const makeConfig: (entries: Record<string, string>, clientEntries?: Record<string, string>, optionOverrides?: Partial<UserConfig>) => UserConfig;
5
+ declare const defaultConfigObject: {
6
+ dts: true;
7
+ format: ("cjs" | "esm")[];
8
+ clean: true;
9
+ sourcemap: true;
10
+ deps: {
11
+ skipNodeModulesBundle: true;
12
+ neverBundle: RegExp[];
13
+ };
14
+ outputOptions: {
15
+ esModule: true;
16
+ };
17
+ };
18
+ //#endregion
19
+ export { defaultConfigObject, makeConfig };
20
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,149 @@
1
+ import { readWantedLockfile } from "@pnpm/lockfile-file";
2
+ import { merge } from "es-toolkit";
3
+ import fs from "fs";
4
+ import path from "path";
5
+ import { defineConfig } from "tsdown";
6
+ //#region index.ts
7
+ const formatEmittedPackageJson = (obj) => `${JSON.stringify(obj, null, 4)}\n`;
8
+ const makeConfig = (entries, clientEntries, optionOverrides) => {
9
+ return defineConfig(makeConfigObject(entries, clientEntries, optionOverrides));
10
+ };
11
+ const copyPackageJson = async () => {
12
+ const packageJSON = JSON.parse(fs.readFileSync("package.json").toString());
13
+ const newPackageJSON = {};
14
+ newPackageJSON.name = packageJSON.name;
15
+ newPackageJSON.dependencies = packageJSON.dependencies;
16
+ newPackageJSON.peerDependencies = packageJSON.peerDependencies ?? {};
17
+ newPackageJSON.sideEffects = packageJSON.sideEffects;
18
+ newPackageJSON.version = packageJSON.version;
19
+ if (packageJSON.repository) newPackageJSON.repository = packageJSON.repository;
20
+ if (packageJSON.publishConfig?.access) newPackageJSON.publishConfig = { access: packageJSON.publishConfig.access };
21
+ if (packageJSON.bin) {
22
+ const distBin = {};
23
+ for (const [name, srcPath] of Object.entries(packageJSON.bin)) distBin[name] = srcPath;
24
+ newPackageJSON.bin = distBin;
25
+ }
26
+ if (packageJSON.scripts?.postinstall) newPackageJSON.scripts = { postinstall: packageJSON.scripts.postinstall };
27
+ newPackageJSON.main = "./index.cjs";
28
+ newPackageJSON.module = "./index.mjs";
29
+ newPackageJSON.types = "./index.d.cts";
30
+ const exports = {
31
+ ".": {
32
+ import: {
33
+ types: "./index.d.mts",
34
+ default: "./index.mjs"
35
+ },
36
+ require: {
37
+ types: "./index.d.cts",
38
+ default: "./index.cjs"
39
+ }
40
+ },
41
+ "./*": {
42
+ import: {
43
+ types: "./*.d.mts",
44
+ default: "./*.mjs"
45
+ },
46
+ require: {
47
+ types: "./*.d.cts",
48
+ default: "./*.cjs"
49
+ }
50
+ }
51
+ };
52
+ const cssDir = path.join("dist", "css");
53
+ if (fs.existsSync(cssDir)) {
54
+ const cssFiles = fs.readdirSync(cssDir).filter((file) => file.endsWith(".css"));
55
+ if (cssFiles.length > 0) {
56
+ exports["./css/*"] = "./css/*";
57
+ exports["./css/*.css"] = "./css/*.css";
58
+ cssFiles.forEach((file) => {
59
+ const baseName = file.replace(".css", "");
60
+ exports[`./css/${baseName}`] = `./css/${file}`;
61
+ exports[`./css/${file}`] = `./css/${file}`;
62
+ });
63
+ }
64
+ }
65
+ newPackageJSON.exports = exports;
66
+ const packageName = process.cwd().split(path.sep).slice(-2).join("/");
67
+ const lockfile_package_list = (await readWantedLockfile("../..", { ignoreIncompatible: true }))?.importers?.[packageName];
68
+ const merged_deps = merge(lockfile_package_list?.dependencies ?? {}, lockfile_package_list?.devDependencies ?? {});
69
+ for (const item of Object.entries(newPackageJSON.peerDependencies)) {
70
+ const [dep, version] = item;
71
+ if (version.includes("workspace")) {
72
+ const package_path = merged_deps?.[dep].version.replace(/(?:link:|\/dist)/g, "") + "/package.json";
73
+ const packageJSON = JSON.parse(fs.readFileSync(package_path).toString());
74
+ newPackageJSON.peerDependencies[dep] = version.replace("workspace:*", packageJSON.version);
75
+ }
76
+ }
77
+ for (const item of Object.entries(newPackageJSON.dependencies ?? {})) {
78
+ const [dep, version] = item;
79
+ if (version.includes("workspace")) {
80
+ const package_path = merged_deps?.[dep].version.replace(/(?:link:|\/dist)/g, "") + "/package.json";
81
+ const packageJSON = JSON.parse(fs.readFileSync(package_path).toString());
82
+ newPackageJSON.dependencies[dep] = version.replace("workspace:*", packageJSON.version);
83
+ }
84
+ }
85
+ fs.writeFileSync("dist/package.json", formatEmittedPackageJson(newPackageJSON));
86
+ };
87
+ const prependUseClient = (fileNames) => {
88
+ fileNames.forEach((fileName) => {
89
+ for (const ext of [".mjs", ".cjs"]) {
90
+ const file = `dist/${fileName}${ext}`;
91
+ if (fs.existsSync(file)) fs.writeFileSync(file, "'use client';\n" + fs.readFileSync(file).toString());
92
+ }
93
+ });
94
+ };
95
+ const fillDuplicateDts = (allEntries) => {
96
+ const bySource = /* @__PURE__ */ new Map();
97
+ for (const [key, source] of Object.entries(allEntries)) {
98
+ const list = bySource.get(source);
99
+ if (list) list.push(key);
100
+ else bySource.set(source, [key]);
101
+ }
102
+ for (const ext of [".d.mts", ".d.cts"]) for (const keys of bySource.values()) {
103
+ if (keys.length < 2) continue;
104
+ const present = keys.map((k) => `dist/${k}${ext}`).find((p) => fs.existsSync(p));
105
+ if (!present) continue;
106
+ const contents = fs.readFileSync(present);
107
+ for (const key of keys) {
108
+ const target = `dist/${key}${ext}`;
109
+ if (!fs.existsSync(target)) {
110
+ fs.mkdirSync(path.dirname(target), { recursive: true });
111
+ fs.writeFileSync(target, contents);
112
+ }
113
+ }
114
+ }
115
+ };
116
+ const defaultConfigObject = {
117
+ dts: true,
118
+ format: ["cjs", "esm"],
119
+ clean: true,
120
+ sourcemap: true,
121
+ deps: {
122
+ skipNodeModulesBundle: true,
123
+ neverBundle: [/^@dbarrett24\//, /^@evolve\.ui\//]
124
+ },
125
+ outputOptions: { esModule: true }
126
+ };
127
+ const makeConfigObject = (entries, clientEntries = {}, optionOverrides = {}) => {
128
+ return {
129
+ ...defaultConfigObject,
130
+ entry: {
131
+ ...entries,
132
+ ...clientEntries
133
+ },
134
+ ...optionOverrides,
135
+ onSuccess: async (config, signal) => {
136
+ if (typeof optionOverrides.onSuccess === "function") await optionOverrides.onSuccess(config, signal);
137
+ await copyPackageJson();
138
+ fillDuplicateDts({
139
+ ...entries,
140
+ ...clientEntries
141
+ });
142
+ prependUseClient(Object.keys(clientEntries));
143
+ }
144
+ };
145
+ };
146
+ //#endregion
147
+ export { defaultConfigObject, makeConfig };
148
+
149
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@dbarrett24/tsdown-config",
3
+ "version": "1.0.1",
4
+ "description": "Shared tsdown configuration for building component libraries (publish-from-dist with generated wildcard exports)",
5
+ "type": "module",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist/index.js",
16
+ "dist/index.d.ts"
17
+ ],
18
+ "dependencies": {
19
+ "@pnpm/lockfile-file": "^8.1.2",
20
+ "@pnpm/logger": "^5.0.0",
21
+ "es-toolkit": "^1.26.1",
22
+ "tsdown": "^0.22.0",
23
+ "typescript": "^6.0.3"
24
+ },
25
+ "devDependencies": {
26
+ "concurrently": "^8.2.2",
27
+ "@dbarrett24/typescript-config": "1.0.1"
28
+ },
29
+ "peerDependencies": {
30
+ "tsdown": ">=0.15.0"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "keywords": [
36
+ "tsdown",
37
+ "config",
38
+ "build",
39
+ "typescript",
40
+ "monorepo"
41
+ ],
42
+ "author": "dbarrett24",
43
+ "license": "MIT",
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "git+https://github.com/dbarrett24/evolve-ui.git",
47
+ "directory": "shared-configs/tsdown-config"
48
+ },
49
+ "scripts": {
50
+ "build": "tsdown",
51
+ "dev": "tsdown --watch",
52
+ "lint": "concurrently --raw --kill-others-on-fail --names oxlint,oxfmt,tsc pnpm:lint-oxlint pnpm:lint-oxfmt pnpm:ts-check",
53
+ "lint-fix": "pnpm lint-oxlint-fix && pnpm lint-oxfmt-fix",
54
+ "lint-oxfmt": "oxfmt --config ../../.oxfmtrc.json --check \"*.ts\"",
55
+ "lint-oxfmt-fix": "oxfmt --config ../../.oxfmtrc.json --write \"*.ts\"",
56
+ "lint-oxlint": "oxlint index.ts tsdown.config.ts",
57
+ "lint-oxlint-fix": "oxlint --fix index.ts tsdown.config.ts",
58
+ "ts-check": "tsc --noEmit",
59
+ "test": "echo 'No tests for tsdown-config'"
60
+ }
61
+ }