@dbarrett24/tsdown-config 1.0.1 → 1.0.2

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.
Files changed (2) hide show
  1. package/dist/index.js +33 -4
  2. package/package.json +6 -4
package/dist/index.js CHANGED
@@ -3,6 +3,35 @@ import { merge } from "es-toolkit";
3
3
  import fs from "fs";
4
4
  import path from "path";
5
5
  import { defineConfig } from "tsdown";
6
+ //#region workspace-specifier.ts
7
+ /**
8
+ * Resolution of pnpm workspace protocol specifiers for the emitted `dist/package.json`.
9
+ *
10
+ * Kept in its own dependency-free module so it can be unit-tested without loading tsdown or
11
+ * the pnpm lockfile reader. Its correctness is load-bearing at publish time: a specifier that
12
+ * survives into the emitted manifest publishes successfully and is uninstallable for every
13
+ * consumer, which is the most expensive failure this package can produce.
14
+ */
15
+ /**
16
+ * Convert a `workspace:` specifier into a publishable semver range.
17
+ *
18
+ * `workspace:*` pins the dependency exactly, which is right for packages that must move in
19
+ * lockstep. `workspace:^` and `workspace:~` publish as the matching range, which is what a
20
+ * package wants when consumers should be able to pick up the dependency's patch releases —
21
+ * without it, a fix published to the dependency is unreachable behind an exact pin.
22
+ *
23
+ * @param specifier the raw dependency value, e.g. `workspace:^`
24
+ * @param resolvedVersion the dependency's actual version, e.g. `1.2.3`
25
+ */
26
+ const resolveWorkspaceSpecifier = (specifier, resolvedVersion) => {
27
+ if (specifier === "workspace:*") return resolvedVersion;
28
+ if (specifier === "workspace:^") return `^${resolvedVersion}`;
29
+ if (specifier === "workspace:~") return `~${resolvedVersion}`;
30
+ return specifier.replace(/^workspace:/, "");
31
+ };
32
+ /** True when a dependency value uses the pnpm workspace protocol. */
33
+ const isWorkspaceSpecifier = (specifier) => specifier.startsWith("workspace:");
34
+ //#endregion
6
35
  //#region index.ts
7
36
  const formatEmittedPackageJson = (obj) => `${JSON.stringify(obj, null, 4)}\n`;
8
37
  const makeConfig = (entries, clientEntries, optionOverrides) => {
@@ -68,18 +97,18 @@ const copyPackageJson = async () => {
68
97
  const merged_deps = merge(lockfile_package_list?.dependencies ?? {}, lockfile_package_list?.devDependencies ?? {});
69
98
  for (const item of Object.entries(newPackageJSON.peerDependencies)) {
70
99
  const [dep, version] = item;
71
- if (version.includes("workspace")) {
100
+ if (isWorkspaceSpecifier(version)) {
72
101
  const package_path = merged_deps?.[dep].version.replace(/(?:link:|\/dist)/g, "") + "/package.json";
73
102
  const packageJSON = JSON.parse(fs.readFileSync(package_path).toString());
74
- newPackageJSON.peerDependencies[dep] = version.replace("workspace:*", packageJSON.version);
103
+ newPackageJSON.peerDependencies[dep] = resolveWorkspaceSpecifier(version, packageJSON.version);
75
104
  }
76
105
  }
77
106
  for (const item of Object.entries(newPackageJSON.dependencies ?? {})) {
78
107
  const [dep, version] = item;
79
- if (version.includes("workspace")) {
108
+ if (isWorkspaceSpecifier(version)) {
80
109
  const package_path = merged_deps?.[dep].version.replace(/(?:link:|\/dist)/g, "") + "/package.json";
81
110
  const packageJSON = JSON.parse(fs.readFileSync(package_path).toString());
82
- newPackageJSON.dependencies[dep] = version.replace("workspace:*", packageJSON.version);
111
+ newPackageJSON.dependencies[dep] = resolveWorkspaceSpecifier(version, packageJSON.version);
83
112
  }
84
113
  }
85
114
  fs.writeFileSync("dist/package.json", formatEmittedPackageJson(newPackageJSON));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbarrett24/tsdown-config",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Shared tsdown configuration for building component libraries (publish-from-dist with generated wildcard exports)",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
@@ -23,7 +23,9 @@
23
23
  "typescript": "^6.0.3"
24
24
  },
25
25
  "devDependencies": {
26
+ "@swc/jest": "^0.2.39",
26
27
  "concurrently": "^8.2.2",
28
+ "jest": "^30.3.0",
27
29
  "@dbarrett24/typescript-config": "1.0.1"
28
30
  },
29
31
  "peerDependencies": {
@@ -53,9 +55,9 @@
53
55
  "lint-fix": "pnpm lint-oxlint-fix && pnpm lint-oxfmt-fix",
54
56
  "lint-oxfmt": "oxfmt --config ../../.oxfmtrc.json --check \"*.ts\"",
55
57
  "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
+ "lint-oxlint": "oxlint index.ts tsdown.config.ts workspace-specifier.ts",
59
+ "lint-oxlint-fix": "oxlint --fix index.ts tsdown.config.ts workspace-specifier.ts",
58
60
  "ts-check": "tsc --noEmit",
59
- "test": "echo 'No tests for tsdown-config'"
61
+ "test": "jest --passWithNoTests"
60
62
  }
61
63
  }