@storm-software/workspace-tools 1.270.2 → 1.271.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.
Files changed (287) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +1 -1
  3. package/dist/chunk-4QYM3VS4.mjs +282 -0
  4. package/dist/{chunk-ZP76EMBE.js → chunk-FYXWAGK3.js} +97 -27
  5. package/dist/chunk-MJMN2T4N.mjs +166 -0
  6. package/dist/chunk-RZVF4LHT.js +282 -0
  7. package/dist/executors.js +6 -6
  8. package/dist/executors.mjs +6 -6
  9. package/dist/index.d.mts +1 -1
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.js +6 -6
  12. package/dist/index.mjs +8 -8
  13. package/dist/src/executors/npm-publish/executor.js +3 -3
  14. package/dist/src/executors/npm-publish/executor.mjs +2 -2
  15. package/dist/src/generators/preset/files/LICENSE +201 -0
  16. package/dist/src/utils/index.d.mts +1 -1
  17. package/dist/src/utils/index.d.ts +1 -1
  18. package/dist/src/utils/index.js +2 -2
  19. package/dist/src/utils/index.mjs +3 -3
  20. package/dist/src/utils/pnpm-deps-update.d.mts +3 -3
  21. package/dist/src/utils/pnpm-deps-update.d.ts +3 -3
  22. package/dist/src/utils/pnpm-deps-update.js +2 -2
  23. package/dist/src/utils/pnpm-deps-update.mjs +3 -3
  24. package/docs/api/base/base-executor.schema.md +16 -0
  25. package/docs/api/base/base-generator.schema.md +15 -0
  26. package/docs/api/base/cargo-base-executor.schema.md +90 -0
  27. package/docs/api/base/typescript-build-executor.schema.md +126 -0
  28. package/docs/api/base/typescript-library-generator.schema.md +129 -0
  29. package/docs/api/executors/cargo-build/schema.md +89 -0
  30. package/docs/api/executors/cargo-check/schema.md +90 -0
  31. package/docs/api/executors/cargo-clippy/schema.md +99 -0
  32. package/docs/api/executors/cargo-doc/schema.md +130 -0
  33. package/docs/api/executors/cargo-format/schema.md +90 -0
  34. package/docs/api/executors/cargo-publish/schema.md +117 -0
  35. package/docs/api/executors/clean-package/schema.md +65 -0
  36. package/docs/api/executors/esbuild/schema.md +126 -0
  37. package/docs/api/executors/npm-publish/schema.md +64 -0
  38. package/docs/api/executors/size-limit/schema.md +25 -0
  39. package/docs/api/executors/typia/schema.md +46 -0
  40. package/docs/api/executors/unbuild/schema.md +222 -0
  41. package/docs/api/generators/browser-library/files/README.md +58 -0
  42. package/docs/api/generators/browser-library/schema.md +129 -0
  43. package/docs/api/generators/config-schema/schema.md +25 -0
  44. package/docs/api/generators/init/schema.md +15 -0
  45. package/docs/api/generators/neutral-library/files/README.md +58 -0
  46. package/docs/api/generators/neutral-library/schema.md +129 -0
  47. package/docs/api/generators/node-library/files/README.md +63 -0
  48. package/docs/api/generators/node-library/schema.md +129 -0
  49. package/docs/api/generators/preset/schema.md +110 -0
  50. package/docs/api/generators/release-version/schema.md +160 -0
  51. package/package.json +13 -35
  52. package/dist/chunk-CMH2A42G.js +0 -467
  53. package/dist/chunk-HMJTTE4A.mjs +0 -96
  54. package/dist/chunk-I54IKCIV.mjs +0 -467
  55. package/docs/executors/rollup.md +0 -88
  56. package/executors.ts +0 -23
  57. package/generators.ts +0 -14
  58. package/index.ts +0 -5
  59. package/project.json +0 -58
  60. package/src/base/base-executor.ts +0 -200
  61. package/src/base/base-executor.untyped.ts +0 -18
  62. package/src/base/base-generator.ts +0 -130
  63. package/src/base/base-generator.untyped.ts +0 -16
  64. package/src/base/cargo-base-executor.untyped.ts +0 -73
  65. package/src/base/index.ts +0 -8
  66. package/src/base/typescript-build-executor.untyped.ts +0 -153
  67. package/src/base/typescript-library-generator.ts +0 -415
  68. package/src/base/typescript-library-generator.untyped.ts +0 -106
  69. package/src/executors/cargo-build/executor.spec.ts +0 -18
  70. package/src/executors/cargo-build/executor.ts +0 -28
  71. package/src/executors/cargo-build/untyped.ts +0 -18
  72. package/src/executors/cargo-check/executor.spec.ts +0 -18
  73. package/src/executors/cargo-check/executor.ts +0 -27
  74. package/src/executors/cargo-check/untyped.ts +0 -11
  75. package/src/executors/cargo-clippy/executor.spec.ts +0 -18
  76. package/src/executors/cargo-clippy/executor.ts +0 -28
  77. package/src/executors/cargo-clippy/untyped.ts +0 -18
  78. package/src/executors/cargo-doc/executor.spec.ts +0 -18
  79. package/src/executors/cargo-doc/executor.ts +0 -39
  80. package/src/executors/cargo-doc/untyped.ts +0 -44
  81. package/src/executors/cargo-format/executor.spec.ts +0 -18
  82. package/src/executors/cargo-format/executor.ts +0 -28
  83. package/src/executors/cargo-format/untyped.ts +0 -11
  84. package/src/executors/cargo-publish/executor.spec.ts +0 -11
  85. package/src/executors/cargo-publish/executor.ts +0 -139
  86. package/src/executors/cargo-publish/untyped.ts +0 -33
  87. package/src/executors/clean-package/constants.ts +0 -99
  88. package/src/executors/clean-package/executor.spec.ts +0 -18
  89. package/src/executors/clean-package/executor.ts +0 -214
  90. package/src/executors/clean-package/types.ts +0 -6
  91. package/src/executors/clean-package/untyped.ts +0 -60
  92. package/src/executors/clean-package/utils.ts +0 -85
  93. package/src/executors/esbuild/executor.spec.ts +0 -11
  94. package/src/executors/esbuild/executor.ts +0 -67
  95. package/src/executors/esbuild/untyped.ts +0 -20
  96. package/src/executors/npm-publish/executor.spec.ts +0 -11
  97. package/src/executors/npm-publish/executor.ts +0 -680
  98. package/src/executors/npm-publish/untyped.ts +0 -56
  99. package/src/executors/size-limit/executor.spec.ts +0 -18
  100. package/src/executors/size-limit/executor.ts +0 -88
  101. package/src/executors/size-limit/untyped.ts +0 -22
  102. package/src/executors/typia/executor.ts +0 -54
  103. package/src/executors/typia/untyped.ts +0 -48
  104. package/src/executors/unbuild/executor.spec.ts +0 -11
  105. package/src/executors/unbuild/executor.ts +0 -136
  106. package/src/executors/unbuild/untyped.ts +0 -152
  107. package/src/generators/browser-library/generator.spec.ts +0 -20
  108. package/src/generators/browser-library/generator.ts +0 -109
  109. package/src/generators/browser-library/untyped.ts +0 -29
  110. package/src/generators/config-schema/generator.spec.ts +0 -20
  111. package/src/generators/config-schema/generator.ts +0 -90
  112. package/src/generators/config-schema/untyped.ts +0 -19
  113. package/src/generators/init/init.ts +0 -32
  114. package/src/generators/init/untyped.ts +0 -16
  115. package/src/generators/neutral-library/generator.spec.ts +0 -20
  116. package/src/generators/neutral-library/generator.ts +0 -81
  117. package/src/generators/neutral-library/untyped.ts +0 -29
  118. package/src/generators/node-library/generator.spec.ts +0 -20
  119. package/src/generators/node-library/generator.ts +0 -84
  120. package/src/generators/node-library/untyped.ts +0 -29
  121. package/src/generators/preset/files/.all-contributorsrc.template +0 -48
  122. package/src/generators/preset/files/.editorconfig +0 -454
  123. package/src/generators/preset/files/.env.template +0 -38
  124. package/src/generators/preset/files/.gitattributes +0 -52
  125. package/src/generators/preset/files/.github/.nvmrc +0 -1
  126. package/src/generators/preset/files/.github/CODEOWNERS +0 -3
  127. package/src/generators/preset/files/.github/CODE_OF_CONDUCT.md +0 -125
  128. package/src/generators/preset/files/.github/CONTRIBUTING.md.template +0 -15
  129. package/src/generators/preset/files/.github/FUNDING.yml +0 -3
  130. package/src/generators/preset/files/.github/ISSUE_TEMPLATE/bug-report.yml.template +0 -102
  131. package/src/generators/preset/files/.github/ISSUE_TEMPLATE/documentation.yml.template +0 -56
  132. package/src/generators/preset/files/.github/ISSUE_TEMPLATE/feature-request.yml.template +0 -60
  133. package/src/generators/preset/files/.github/PULL_REQUEST_TEMPLATE.md.template +0 -39
  134. package/src/generators/preset/files/.github/SECURITY.md +0 -9
  135. package/src/generators/preset/files/.github/codecov.yml +0 -29
  136. package/src/generators/preset/files/.github/dependabot.yml +0 -64
  137. package/src/generators/preset/files/.github/labels.yml +0 -84
  138. package/src/generators/preset/files/.github/renovate.json +0 -4
  139. package/src/generators/preset/files/.github/renovate.json.template +0 -63
  140. package/src/generators/preset/files/.github/stale.yml +0 -55
  141. package/src/generators/preset/files/.github/workflows/build-release.yml.template +0 -25
  142. package/src/generators/preset/files/.github/workflows/code-review.yml +0 -18
  143. package/src/generators/preset/files/.github/workflows/codeql.yml +0 -84
  144. package/src/generators/preset/files/.github/workflows/dependabot-update.yml +0 -32
  145. package/src/generators/preset/files/.github/workflows/git-guardian.yml +0 -23
  146. package/src/generators/preset/files/.github/workflows/greetings.yml +0 -31
  147. package/src/generators/preset/files/.github/workflows/labels.yml +0 -31
  148. package/src/generators/preset/files/.github/workflows/lock.yml +0 -26
  149. package/src/generators/preset/files/.log4brains.yml.template +0 -5
  150. package/src/generators/preset/files/.markdownlint.json +0 -155
  151. package/src/generators/preset/files/.verdaccio/config.yml.template +0 -40
  152. package/src/generators/preset/files/.vscode/README.md +0 -32
  153. package/src/generators/preset/files/.vscode/cspell.json +0 -3
  154. package/src/generators/preset/files/.vscode/extensions.json +0 -14
  155. package/src/generators/preset/files/.vscode/launch.json +0 -37
  156. package/src/generators/preset/files/.vscode/settings.json +0 -401
  157. package/src/generators/preset/files/.vscode/tasks.json +0 -4
  158. package/src/generators/preset/files/.whitesource +0 -14
  159. package/src/generators/preset/files/assets/diagrams/.gitkeep +0 -0
  160. package/src/generators/preset/files/assets/icons/dark/.gitkeep +0 -0
  161. package/src/generators/preset/files/assets/icons/light/.gitkeep +0 -0
  162. package/src/generators/preset/files/assets/logos/.gitkeep +0 -0
  163. package/src/generators/preset/files/docs/api-reference/.gitkeep +0 -0
  164. package/src/generators/preset/generator.spec.ts +0 -20
  165. package/src/generators/preset/generator.ts +0 -315
  166. package/src/generators/preset/untyped.ts +0 -88
  167. package/src/generators/release-version/generator.spec.ts +0 -20
  168. package/src/generators/release-version/generator.ts +0 -920
  169. package/src/generators/release-version/untyped.ts +0 -156
  170. package/src/plugins/rust/cargo-toml.ts +0 -434
  171. package/src/plugins/rust/index.ts +0 -1
  172. package/src/plugins/typescript/index.ts +0 -1
  173. package/src/plugins/typescript/project-config.ts +0 -564
  174. package/src/plugins/typescript/tsup.ts +0 -198
  175. package/src/types.ts +0 -130
  176. package/src/utils/apply-workspace-tokens.ts +0 -73
  177. package/src/utils/cargo.ts +0 -219
  178. package/src/utils/create-cli-options.ts +0 -23
  179. package/src/utils/get-project-configurations.ts +0 -27
  180. package/src/utils/index.ts +0 -12
  181. package/src/utils/lock-file.ts +0 -159
  182. package/src/utils/package-helpers.ts +0 -54
  183. package/src/utils/plugin-helpers.ts +0 -112
  184. package/src/utils/pnpm-deps-update.ts +0 -111
  185. package/src/utils/project-tags.ts +0 -162
  186. package/src/utils/toml.ts +0 -204
  187. package/src/utils/typia-transform.ts +0 -8
  188. package/src/utils/versions.ts +0 -19
  189. package/tsconfig.json +0 -30
  190. package/tsup.config.ts +0 -36
  191. /package/{src/generators/preset/files/LICENSE → LICENSE} +0 -0
  192. /package/{src → dist/src}/base/base-executor.schema.d.ts +0 -0
  193. /package/{src → dist/src}/base/base-executor.schema.json +0 -0
  194. /package/{src → dist/src}/base/base-executor.schema.md +0 -0
  195. /package/{src → dist/src}/base/base-generator.schema.d.ts +0 -0
  196. /package/{src → dist/src}/base/base-generator.schema.json +0 -0
  197. /package/{src → dist/src}/base/base-generator.schema.md +0 -0
  198. /package/{src → dist/src}/base/cargo-base-executor.schema.d.ts +0 -0
  199. /package/{src → dist/src}/base/cargo-base-executor.schema.json +0 -0
  200. /package/{src → dist/src}/base/cargo-base-executor.schema.md +0 -0
  201. /package/{src → dist/src}/base/typescript-build-executor.schema.d.ts +0 -0
  202. /package/{src → dist/src}/base/typescript-build-executor.schema.json +0 -0
  203. /package/{src → dist/src}/base/typescript-build-executor.schema.md +0 -0
  204. /package/{src → dist/src}/base/typescript-library-generator.schema.d.ts +0 -0
  205. /package/{src → dist/src}/base/typescript-library-generator.schema.json +0 -0
  206. /package/{src → dist/src}/base/typescript-library-generator.schema.md +0 -0
  207. /package/{src → dist/src}/executors/cargo-build/schema.d.ts +0 -0
  208. /package/{src → dist/src}/executors/cargo-build/schema.json +0 -0
  209. /package/{src → dist/src}/executors/cargo-build/schema.md +0 -0
  210. /package/{src → dist/src}/executors/cargo-check/schema.d.ts +0 -0
  211. /package/{src → dist/src}/executors/cargo-check/schema.json +0 -0
  212. /package/{src → dist/src}/executors/cargo-check/schema.md +0 -0
  213. /package/{src → dist/src}/executors/cargo-clippy/schema.d.ts +0 -0
  214. /package/{src → dist/src}/executors/cargo-clippy/schema.json +0 -0
  215. /package/{src → dist/src}/executors/cargo-clippy/schema.md +0 -0
  216. /package/{src → dist/src}/executors/cargo-doc/schema.d.ts +0 -0
  217. /package/{src → dist/src}/executors/cargo-doc/schema.json +0 -0
  218. /package/{src → dist/src}/executors/cargo-doc/schema.md +0 -0
  219. /package/{src → dist/src}/executors/cargo-format/schema.d.ts +0 -0
  220. /package/{src → dist/src}/executors/cargo-format/schema.json +0 -0
  221. /package/{src → dist/src}/executors/cargo-format/schema.md +0 -0
  222. /package/{src → dist/src}/executors/cargo-publish/schema.d.ts +0 -0
  223. /package/{src → dist/src}/executors/cargo-publish/schema.json +0 -0
  224. /package/{src → dist/src}/executors/cargo-publish/schema.md +0 -0
  225. /package/{src → dist/src}/executors/clean-package/schema.d.ts +0 -0
  226. /package/{src → dist/src}/executors/clean-package/schema.json +0 -0
  227. /package/{src → dist/src}/executors/clean-package/schema.md +0 -0
  228. /package/{src → dist/src}/executors/esbuild/schema.d.ts +0 -0
  229. /package/{src → dist/src}/executors/esbuild/schema.json +0 -0
  230. /package/{src → dist/src}/executors/esbuild/schema.md +0 -0
  231. /package/{src → dist/src}/executors/npm-publish/schema.d.ts +0 -0
  232. /package/{src → dist/src}/executors/npm-publish/schema.json +0 -0
  233. /package/{src → dist/src}/executors/npm-publish/schema.md +0 -0
  234. /package/{src → dist/src}/executors/size-limit/schema.d.ts +0 -0
  235. /package/{src → dist/src}/executors/size-limit/schema.json +0 -0
  236. /package/{src → dist/src}/executors/size-limit/schema.md +0 -0
  237. /package/{src → dist/src}/executors/typia/schema.d.ts +0 -0
  238. /package/{src → dist/src}/executors/typia/schema.json +0 -0
  239. /package/{src → dist/src}/executors/typia/schema.md +0 -0
  240. /package/{src → dist/src}/executors/unbuild/schema.d.ts +0 -0
  241. /package/{src → dist/src}/executors/unbuild/schema.json +0 -0
  242. /package/{src → dist/src}/executors/unbuild/schema.md +0 -0
  243. /package/{src → dist/src}/generators/browser-library/files/README.md +0 -0
  244. /package/{src → dist/src}/generators/browser-library/files/jest.config.ts +0 -0
  245. /package/{src → dist/src}/generators/browser-library/files/src/index.ts.template +0 -0
  246. /package/{src → dist/src}/generators/browser-library/files/tsconfig.spec.json +0 -0
  247. /package/{src → dist/src}/generators/browser-library/schema.d.ts +0 -0
  248. /package/{src → dist/src}/generators/browser-library/schema.json +0 -0
  249. /package/{src → dist/src}/generators/browser-library/schema.md +0 -0
  250. /package/{src → dist/src}/generators/config-schema/schema.d.ts +0 -0
  251. /package/{src → dist/src}/generators/config-schema/schema.json +0 -0
  252. /package/{src → dist/src}/generators/config-schema/schema.md +0 -0
  253. /package/{src → dist/src}/generators/init/schema.d.ts +0 -0
  254. /package/{src → dist/src}/generators/init/schema.json +0 -0
  255. /package/{src → dist/src}/generators/init/schema.md +0 -0
  256. /package/{src → dist/src}/generators/neutral-library/files/README.md +0 -0
  257. /package/{src → dist/src}/generators/neutral-library/files/jest.config.ts +0 -0
  258. /package/{src → dist/src}/generators/neutral-library/files/src/index.ts.template +0 -0
  259. /package/{src → dist/src}/generators/neutral-library/files/tsconfig.spec.json +0 -0
  260. /package/{src → dist/src}/generators/neutral-library/schema.d.ts +0 -0
  261. /package/{src → dist/src}/generators/neutral-library/schema.json +0 -0
  262. /package/{src → dist/src}/generators/neutral-library/schema.md +0 -0
  263. /package/{src → dist/src}/generators/node-library/files/README.md +0 -0
  264. /package/{src → dist/src}/generators/node-library/files/jest.config.ts +0 -0
  265. /package/{src → dist/src}/generators/node-library/files/src/index.ts.template +0 -0
  266. /package/{src → dist/src}/generators/node-library/files/tsconfig.spec.json +0 -0
  267. /package/{src → dist/src}/generators/node-library/schema.d.ts +0 -0
  268. /package/{src → dist/src}/generators/node-library/schema.json +0 -0
  269. /package/{src → dist/src}/generators/node-library/schema.md +0 -0
  270. /package/{src → dist/src}/generators/preset/files/README.md.template +0 -0
  271. /package/{src → dist/src}/generators/preset/files/docs/readme-templates/README.footer.md.template +0 -0
  272. /package/{src → dist/src}/generators/preset/files/docs/readme-templates/README.header.md.template +0 -0
  273. /package/{src → dist/src}/generators/preset/files/eslint.config.js.template +0 -0
  274. /package/{src → dist/src}/generators/preset/files/knip.json +0 -0
  275. /package/{src → dist/src}/generators/preset/files/lefthook.json +0 -0
  276. /package/{src → dist/src}/generators/preset/files/nx.json +0 -0
  277. /package/{src → dist/src}/generators/preset/files/pnpm-workspace.yaml +0 -0
  278. /package/{src → dist/src}/generators/preset/files/socket.yaml +0 -0
  279. /package/{src → dist/src}/generators/preset/files/storm.json.template +0 -0
  280. /package/{src → dist/src}/generators/preset/files/tsconfig.base.json.template +0 -0
  281. /package/{src → dist/src}/generators/preset/schema.d.ts +0 -0
  282. /package/{src → dist/src}/generators/preset/schema.json +0 -0
  283. /package/{src → dist/src}/generators/preset/schema.md +0 -0
  284. /package/{src → dist/src}/generators/release-version/schema.d.ts +0 -0
  285. /package/{src → dist/src}/generators/release-version/schema.json +0 -0
  286. /package/{src → dist/src}/generators/release-version/schema.md +0 -0
  287. /package/{src → dist/src}/plugins/typescript/untyped-schema.ts +0 -0
@@ -1,680 +0,0 @@
1
- import {
2
- detectPackageManager,
3
- readJsonFile,
4
- type ExecutorContext
5
- } from "@nx/devkit";
6
- import { joinPaths } from "@storm-software/config-tools/utilities/correct-paths";
7
- import columnify from "columnify";
8
- import { exec, execSync } from "node:child_process";
9
- import { existsSync } from "node:fs";
10
- import { relative } from "node:path";
11
- import { env as appendLocalEnv } from "npm-run-path";
12
- import { PackageJson } from "nx/src/utils/package-json";
13
- import { pnpmCatalogUpdate } from "../../utils/pnpm-deps-update";
14
- import type { NpmPublishExecutorSchema } from "./schema.d";
15
-
16
- export const LARGE_BUFFER = 1024 * 1000000;
17
-
18
- function processEnv(color: boolean) {
19
- const env = {
20
- ...process.env,
21
- ...appendLocalEnv()
22
- };
23
-
24
- if (color) {
25
- env.FORCE_COLOR = `${color}`;
26
- }
27
- return env;
28
- }
29
-
30
- export default async function npmPublishExecutorFn(
31
- options: NpmPublishExecutorSchema,
32
- context: ExecutorContext
33
- ) {
34
- const pm = detectPackageManager();
35
- /**
36
- * We need to check both the env var and the option because the executor may have been triggered
37
- * indirectly via dependsOn, in which case the env var will be set, but the option will not.
38
- */
39
- const isDryRun = process.env.NX_DRY_RUN === "true" || options.dryRun || false;
40
-
41
- const projectConfig =
42
- context.projectsConfigurations!.projects[context.projectName!]!;
43
-
44
- const packageRoot = joinPaths(
45
- context.root,
46
- options.packageRoot ?? projectConfig.root
47
- );
48
-
49
- const packageJsonPath = joinPaths(packageRoot, "package.json");
50
- const packageJson = readJsonFile(packageJsonPath);
51
- const packageName = packageJson.name;
52
-
53
- await pnpmCatalogUpdate(packageRoot, context.root);
54
-
55
- /**
56
- * Whether or not dynamically replacing local dependency protocols (such as "workspace:*") is supported during `nx release publish` is
57
- * dependent on the package manager the user is using.
58
- *
59
- * npm does not support the workspace protocol at all, and `npm publish` does not support dynamically updating locally linked packages
60
- * during its packing phase, so we give the user a clear error message informing them of that.
61
- *
62
- * - `pnpm publish` provides ideal support, it has the possibility of providing JSON output consistent with npm
63
- * - `bun publish`, provides very good support, including all the flags we need apart from the JSON output, so we just have to accept that
64
- * it will look and feel different and print what it gives us and perform one bit of string manipulation for the dry-run case.
65
- * - `yarn npm publish`, IS NOT YET SUPPORTED, and will be tricky because it does not support the majority of the flags we need. However, it
66
- * does support replacing local dependency protocols with the correct version during its packing phase.
67
- */
68
- // if (pm === "npm" || pm === "yarn") {
69
- // const depTypes = ["dependencies", "devDependencies", "peerDependencies"];
70
- // for (const depType of depTypes) {
71
- // const deps = packageJson[depType];
72
- // if (deps) {
73
- // for (const depName in deps) {
74
- // if (isLocallyLinkedPackageVersion(deps[depName])) {
75
- // if (pm === "npm") {
76
- // console.error(
77
- // `Error: Cannot publish package "${packageName}" because it contains a local dependency protocol in its "${depType}", and your package manager is npm.
78
-
79
- // Please update the local dependency on "${depName}" to be a valid semantic version (e.g. using \`nx release\`) before publishing, or switch to pnpm or bun as a package manager, which support dynamically replacing these protocols during publishing.`
80
- // );
81
- // } else if (pm === "yarn") {
82
- // console.error(
83
- // `Error: Cannot publish package "${packageName}" because it contains a local dependency protocol in its "${depType}", and your package manager is yarn.
84
-
85
- // Currently, yarn is not supported for this use case because its \`yarn npm publish\` command does not support the customization needed.
86
-
87
- // Please update the local dependency on "${depName}" to be a valid semantic version (e.g. using \`nx release\`) before publishing, or switch to pnpm or bun as a package manager, which support dynamically replacing these protocols during publishing.`
88
- // );
89
- // }
90
- // return {
91
- // success: false
92
- // };
93
- // }
94
- // }
95
- // }
96
- // }
97
- // }
98
-
99
- // If package and project name match, we can make log messages terser
100
- const packageTxt =
101
- packageName === context.projectName
102
- ? `package "${packageName}"`
103
- : `package "${packageName}" from project "${context.projectName}"`;
104
-
105
- if (packageJson.private === true) {
106
- console.warn(
107
- `Skipped ${packageTxt}, because it has \`"private": true\` in ${packageJsonPath}`
108
- );
109
- return {
110
- success: true
111
- };
112
- }
113
-
114
- const warnFn = (message: string) => {
115
- console.log(message);
116
- };
117
- const { registry, tag, registryConfigKey } = await parseRegistryOptions(
118
- context.root,
119
- {
120
- packageRoot,
121
- packageJson
122
- },
123
- {
124
- registry: options.registry,
125
- tag: options.tag
126
- },
127
- warnFn
128
- );
129
-
130
- const npmViewCommandSegments = [
131
- `npm view ${packageName} versions dist-tags --json --"${registryConfigKey}=${registry}"`
132
- ];
133
- const npmDistTagAddCommandSegments = [
134
- `npm dist-tag add ${packageName}@${packageJson.version} ${tag} --"${registryConfigKey}=${registry}"`
135
- ];
136
-
137
- /**
138
- * In a dry-run scenario, it is most likely that all commands are being run with dry-run, therefore
139
- * the most up to date/relevant version might not exist on disk for us to read and make the npm view
140
- * request with.
141
- *
142
- * Therefore, so as to not produce misleading output in dry around dist-tags being altered, we do not
143
- * perform the npm view step, and just show npm/pnpm publish's dry-run output.
144
- */
145
- if (!isDryRun && !options.firstRelease) {
146
- const currentVersion = packageJson.version;
147
- try {
148
- const result = execSync(npmViewCommandSegments.join(" "), {
149
- env: processEnv(true),
150
- cwd: context.root,
151
- stdio: ["ignore", "pipe", "pipe"],
152
- windowsHide: false
153
- });
154
-
155
- const resultJson = JSON.parse(result.toString());
156
- const distTags = resultJson["dist-tags"] || {};
157
- if (distTags[tag] === currentVersion) {
158
- console.warn(
159
- `Skipped ${packageTxt} because v${currentVersion} already exists in ${registry} with tag "${tag}"`
160
- );
161
- return {
162
- success: true
163
- };
164
- }
165
-
166
- // If only one version of a package exists in the registry, versions will be a string instead of an array.
167
- const versions = Array.isArray(resultJson.versions)
168
- ? resultJson.versions
169
- : [resultJson.versions];
170
-
171
- if (versions.includes(currentVersion)) {
172
- try {
173
- if (!isDryRun) {
174
- execSync(npmDistTagAddCommandSegments.join(" "), {
175
- env: processEnv(true),
176
- cwd: context.root,
177
- stdio: "ignore",
178
- windowsHide: false
179
- });
180
- console.log(
181
- `Added the dist-tag ${tag} to v${currentVersion} for registry ${registry}.\n`
182
- );
183
- } else {
184
- console.log(
185
- `Would add the dist-tag ${tag} to v${currentVersion} for registry ${registry}, but "[dry-run]" was set.\n`
186
- );
187
- }
188
- return {
189
- success: true
190
- };
191
- } catch (err) {
192
- try {
193
- const stdoutData = JSON.parse(err.stdout?.toString() || "{}");
194
-
195
- // If the error is that the package doesn't exist, then we can ignore it because we will be publishing it for the first time in the next step
196
- if (
197
- !(
198
- stdoutData.error?.code?.includes("E404") &&
199
- stdoutData.error?.summary?.includes("no such package available")
200
- ) &&
201
- !(
202
- err.stderr?.toString().includes("E404") &&
203
- err.stderr?.toString().includes("no such package available")
204
- )
205
- ) {
206
- console.error("npm dist-tag add error:");
207
- if (stdoutData.error.summary) {
208
- console.error(stdoutData.error.summary);
209
- }
210
- if (stdoutData.error.detail) {
211
- console.error(stdoutData.error.detail);
212
- }
213
-
214
- if (context.isVerbose) {
215
- console.error("npm dist-tag add stdout:");
216
- console.error(JSON.stringify(stdoutData, null, 2));
217
- }
218
- return {
219
- success: false
220
- };
221
- }
222
- } catch (err) {
223
- console.error(
224
- "Something unexpected went wrong when processing the npm dist-tag add output\n",
225
- err
226
- );
227
- return {
228
- success: false
229
- };
230
- }
231
- }
232
- }
233
- } catch (err) {
234
- const stdoutData = JSON.parse(err.stdout?.toString() || "{}");
235
- // If the error is that the package doesn't exist, then we can ignore it because we will be publishing it for the first time in the next step
236
- if (
237
- !(
238
- stdoutData.error?.code?.includes("E404") &&
239
- stdoutData.error?.summary?.toLowerCase().includes("not found")
240
- ) &&
241
- !(
242
- err.stderr?.toString().includes("E404") &&
243
- err.stderr?.toString().toLowerCase().includes("not found")
244
- )
245
- ) {
246
- console.error(
247
- `Something unexpected went wrong when checking for existing dist-tags.\n`,
248
- err
249
- );
250
- return {
251
- success: false
252
- };
253
- }
254
- }
255
- }
256
-
257
- if (options.firstRelease && context.isVerbose) {
258
- console.log("Skipped npm view because --first-release was set");
259
- }
260
-
261
- /**
262
- * NOTE: If this is ever changed away from running the command at the workspace root and pointing at the package root (e.g. back
263
- * to running from the package root directly), then special attention should be paid to the fact that npm/pnpm publish will nest its
264
- * JSON output under the name of the package in that case (and it would need to be handled below).
265
- */
266
- const publishCommandSegments = [
267
- pm === "bun"
268
- ? // Unlike npm, bun publish does not support a custom registryConfigKey option
269
- `bun publish --cwd="${packageRoot}" --json --registry="${registry}" --tag=${tag}`
270
- : pm === "pnpm"
271
- ? // Unlike npm, pnpm publish does not support a custom registryConfigKey option, and will error on uncommitted changes by default if --no-git-checks is not set
272
- `pnpm publish "${packageRoot}" --json --registry="${registry}" --tag=${tag} --no-git-checks`
273
- : `npm publish "${packageRoot}" --json --"${registryConfigKey}=${registry}" --tag=${tag}`
274
- ];
275
-
276
- if (options.otp) {
277
- publishCommandSegments.push(`--otp=${options.otp}`);
278
- }
279
-
280
- publishCommandSegments.push(`--access=public`);
281
-
282
- if (isDryRun) {
283
- publishCommandSegments.push(`--dry-run`);
284
- }
285
-
286
- try {
287
- const output = execSync(publishCommandSegments.join(" "), {
288
- maxBuffer: LARGE_BUFFER,
289
- env: processEnv(true),
290
- cwd: context.root,
291
- stdio: ["ignore", "pipe", "pipe"],
292
- windowsHide: false
293
- });
294
- // If in dry-run mode, the version on disk will not represent the version that would be published, so we scrub it from the output to avoid confusion.
295
- const dryRunVersionPlaceholder = "X.X.X-dry-run";
296
-
297
- const publishSummaryMessage = isDryRun
298
- ? `Would publish to ${registry} with tag "${tag}", but "[dry-run]" was set`
299
- : `Published to ${registry} with tag "${tag}"`;
300
-
301
- // bun publish does not support outputting JSON, so we need to modify and print the output string directly
302
- if (pm === "bun") {
303
- let outputStr = output.toString();
304
- if (isDryRun) {
305
- outputStr = outputStr.replace(
306
- new RegExp(`${packageJson.name}@${packageJson.version}`, "g"),
307
- `${packageJson.name}@${dryRunVersionPlaceholder}`
308
- );
309
- }
310
- console.log(outputStr);
311
- console.log(publishSummaryMessage);
312
- return {
313
- success: true
314
- };
315
- }
316
-
317
- /**
318
- * We cannot JSON.parse the output directly because if the user is using lifecycle scripts, npm/pnpm will mix its publish output with the JSON output all on stdout.
319
- * Additionally, we want to capture and show the lifecycle script outputs as beforeJsonData and afterJsonData and print them accordingly below.
320
- */
321
- const { beforeJsonData, jsonData, afterJsonData } =
322
- extractNpmPublishJsonData(output.toString());
323
- if (!jsonData) {
324
- console.error(
325
- `The ${pm} publish output data could not be extracted. Please report this issue on https://github.com/nrwl/nx`
326
- );
327
- return {
328
- success: false
329
- };
330
- }
331
-
332
- if (isDryRun) {
333
- for (const [key, val] of Object.entries(jsonData)) {
334
- if (typeof val !== "string") {
335
- continue;
336
- }
337
- jsonData[key] = val.replace(
338
- new RegExp(packageJson.version, "g"),
339
- dryRunVersionPlaceholder
340
- );
341
- }
342
- }
343
-
344
- if (
345
- typeof beforeJsonData === "string" &&
346
- beforeJsonData.trim().length > 0
347
- ) {
348
- console.log(beforeJsonData);
349
- }
350
-
351
- logTar(jsonData);
352
-
353
- if (typeof afterJsonData === "string" && afterJsonData.trim().length > 0) {
354
- console.log(afterJsonData);
355
- }
356
-
357
- // Print the summary message after the JSON data has been printed
358
- console.log(publishSummaryMessage);
359
-
360
- return {
361
- success: true
362
- };
363
- } catch (err) {
364
- try {
365
- // bun publish does not support outputting JSON, so we cannot perform any further processing
366
- if (pm === "bun") {
367
- console.error(`bun publish error:`);
368
- console.error(err.stderr?.toString() || "");
369
- console.error(err.stdout?.toString() || "");
370
- return {
371
- success: false
372
- };
373
- }
374
-
375
- const stdoutData = JSON.parse(err.stdout?.toString() || "{}");
376
-
377
- console.error(`${pm} publish error:`);
378
- if (stdoutData.error?.summary) {
379
- console.error(stdoutData.error.summary);
380
- }
381
- if (stdoutData.error?.detail) {
382
- console.error(stdoutData.error.detail);
383
- }
384
-
385
- if (context.isVerbose) {
386
- console.error(`${pm} publish stdout:`);
387
- console.error(JSON.stringify(stdoutData, null, 2));
388
- }
389
-
390
- if (!stdoutData.error) {
391
- throw err;
392
- }
393
-
394
- return {
395
- success: false
396
- };
397
- } catch (err) {
398
- console.error(
399
- `Something unexpected went wrong when processing the ${pm} publish output\n`,
400
- err
401
- );
402
- return {
403
- success: false
404
- };
405
- }
406
- }
407
- }
408
-
409
- async function parseRegistryOptions(
410
- cwd: string,
411
- pkg: {
412
- packageRoot: string;
413
- packageJson: PackageJson;
414
- },
415
- options: {
416
- registry?: string;
417
- tag?: string;
418
- },
419
- logWarnFn: (message: string) => void = console.warn
420
- ): Promise<{
421
- registry: string;
422
- tag: string;
423
- registryConfigKey: string;
424
- }> {
425
- const npmRcPath = joinPaths(pkg.packageRoot, ".npmrc");
426
- if (existsSync(npmRcPath)) {
427
- const relativeNpmRcPath = relative(cwd, npmRcPath);
428
- logWarnFn(
429
- `\nIgnoring .npmrc file detected in the package root: ${relativeNpmRcPath}. Nested .npmrc files are not supported by npm. Only the .npmrc file at the root of the workspace will be used. To customize the registry or tag for specific packages, see https://nx.dev/recipes/nx-release/configure-custom-registries\n`
430
- );
431
- }
432
-
433
- const scope = pkg.packageJson.name.startsWith("@")
434
- ? pkg.packageJson.name.split("/")[0]
435
- : "";
436
-
437
- // If the package is scoped, then the registry argument that will
438
- // correctly override the registry in the .npmrc file must be scoped.
439
- const registryConfigKey = scope ? `${scope}:registry` : "registry";
440
-
441
- const publishConfigRegistry =
442
- pkg.packageJson.publishConfig?.[registryConfigKey];
443
-
444
- // Even though it won't override the actual registry that's actually used,
445
- // the user might think otherwise, so we should still warn if the user has
446
- // set a 'registry' in 'publishConfig' for a scoped package.
447
- if (publishConfigRegistry || pkg.packageJson.publishConfig?.registry) {
448
- const relativePackageJsonPath = relative(
449
- cwd,
450
- joinPaths(pkg.packageRoot, "package.json")
451
- );
452
- if (options.registry) {
453
- logWarnFn(
454
- `\nRegistry detected in the 'publishConfig' of the package manifest: ${relativePackageJsonPath}. This will override your registry option set in the project configuration or passed via the --registry argument, which is why configuring the registry with 'publishConfig' is not recommended. For details, see https://nx.dev/recipes/nx-release/configure-custom-registries\n`
455
- );
456
- } else {
457
- logWarnFn(
458
- `\nRegistry detected in the 'publishConfig' of the package manifest: ${relativePackageJsonPath}. Configuring the registry in this way is not recommended because it prevents the registry from being overridden in project configuration or via the --registry argument. To customize the registry for specific packages, see https://nx.dev/recipes/nx-release/configure-custom-registries\n`
459
- );
460
- }
461
- }
462
-
463
- const registry =
464
- // `npm publish` will always use the publishConfig registry if it exists, even over the --registry arg
465
- publishConfigRegistry ||
466
- options.registry ||
467
- (await getNpmRegistry(cwd, scope));
468
- const tag = options.tag || (await getNpmTag(cwd));
469
- if (!registry || !tag) {
470
- throw new Error(
471
- `The registry and tag options are required. Please provide them in the project configuration or via the --registry and --tag arguments.`
472
- );
473
- }
474
-
475
- return { registry, tag, registryConfigKey };
476
- }
477
-
478
- /**
479
- * Returns the npm registry that is used for publishing.
480
- *
481
- * @param scope the scope of the package for which to determine the registry
482
- * @param cwd the directory where the npm config should be read from
483
- */
484
- async function getNpmRegistry(
485
- cwd: string,
486
- scope?: string
487
- ): Promise<string | undefined> {
488
- let registry: string | undefined;
489
-
490
- if (scope) {
491
- registry = await getNpmConfigValue(`${scope}:registry`, cwd);
492
- }
493
-
494
- if (!registry) {
495
- registry = await getNpmConfigValue("registry", cwd);
496
- }
497
-
498
- return registry;
499
- }
500
-
501
- /**
502
- * Returns the npm tag that is used for publishing.
503
- *
504
- * @param cwd the directory where the npm config should be read from
505
- */
506
- async function getNpmTag(cwd: string): Promise<string | undefined> {
507
- // npm does not support '@scope:tag' in the npm config, so we only need to check for 'tag'.
508
- return getNpmConfigValue("tag", cwd);
509
- }
510
-
511
- async function getNpmConfigValue(
512
- key: string,
513
- cwd: string
514
- ): Promise<string | undefined> {
515
- try {
516
- const result = await execAsync(`npm config get ${key}`, cwd);
517
- return result === "undefined" ? undefined : result;
518
- } catch (_) {
519
- return Promise.resolve(undefined);
520
- }
521
- }
522
-
523
- async function execAsync(command: string, cwd: string): Promise<string> {
524
- // Must be non-blocking async to allow spinner to render
525
- return new Promise<string>((resolve, reject) => {
526
- exec(command, { cwd, windowsHide: false }, (error, stdout, stderr) => {
527
- if (error) {
528
- return reject((stderr ? `${stderr}\n` : "") + error);
529
- }
530
- return resolve(stdout.trim());
531
- });
532
- });
533
- }
534
-
535
- const expectedNpmPublishJsonKeys = [
536
- "id",
537
- "name",
538
- "version",
539
- "size",
540
- "filename"
541
- ];
542
-
543
- function extractNpmPublishJsonData(str: string): {
544
- beforeJsonData: string;
545
- jsonData: Record<string, unknown> | null;
546
- afterJsonData: string;
547
- } {
548
- const jsonMatches = str.match(/{(?:[^{}]|{[^{}]*})*}/g);
549
- if (jsonMatches) {
550
- for (const match of jsonMatches) {
551
- // Cheap upfront check to see if the stringified JSON data has the expected keys as substrings
552
- if (!expectedNpmPublishJsonKeys.every(key => str.includes(key))) {
553
- continue;
554
- }
555
- // Full JSON parsing to identify the JSON object
556
- try {
557
- const parsedJson = JSON.parse(match);
558
- if (
559
- !expectedNpmPublishJsonKeys.every(
560
- key => parsedJson[key] !== undefined
561
- )
562
- ) {
563
- continue;
564
- }
565
- const jsonStartIndex = str.indexOf(match);
566
- return {
567
- beforeJsonData: str.slice(0, jsonStartIndex),
568
- jsonData: parsedJson,
569
- afterJsonData: str.slice(jsonStartIndex + match.length)
570
- };
571
- } catch {
572
- // Ignore parsing errors for unrelated JSON blocks
573
- }
574
- }
575
- }
576
-
577
- // No applicable jsonData detected, the whole contents is the beforeJsonData
578
- return {
579
- beforeJsonData: str,
580
- jsonData: null,
581
- afterJsonData: ""
582
- };
583
- }
584
-
585
- const formatBytes = (bytes, space = true) => {
586
- let spacer = "";
587
- if (space) {
588
- spacer = " ";
589
- }
590
-
591
- if (bytes < 1000) {
592
- // B
593
- return `${bytes}${spacer}B`;
594
- }
595
-
596
- if (bytes < 1000000) {
597
- // kB
598
- return `${(bytes / 1000).toFixed(1)}${spacer}kB`;
599
- }
600
-
601
- if (bytes < 1000000000) {
602
- // MB
603
- return `${(bytes / 1000000).toFixed(1)}${spacer}MB`;
604
- }
605
-
606
- // GB
607
- return `${(bytes / 1000000000).toFixed(1)}${spacer}GB`;
608
- };
609
-
610
- const logTar = (tarball, opts = {}) => {
611
- // @ts-expect-error Expected to be a tarball
612
- const { unicode = true } = opts;
613
- console.log("");
614
- console.log(
615
- `${unicode ? "📦 " : "package:"} ${tarball.name}@${tarball.version}`
616
- );
617
- console.log("=== Tarball Contents ===");
618
- if (tarball.files.length) {
619
- console.log("");
620
- const columnData = columnify(
621
- tarball.files
622
- .map(f => {
623
- const bytes = formatBytes(f.size, false);
624
- return /^node_modules\//.test(f.path)
625
- ? null
626
- : { path: f.path, size: `${bytes}` };
627
- })
628
- .filter(f => f),
629
- {
630
- include: ["size", "path"],
631
- showHeaders: false
632
- }
633
- );
634
- columnData.split("\n").forEach(line => {
635
- console.log(line);
636
- });
637
- }
638
- if (tarball.bundled.length) {
639
- console.log("=== Bundled Dependencies ===");
640
- tarball.bundled.forEach(name => console.log("", name));
641
- }
642
- console.log("=== Tarball Details ===");
643
- console.log(
644
- columnify(
645
- [
646
- { name: "name:", value: tarball.name },
647
- { name: "version:", value: tarball.version },
648
- tarball.filename && { name: "filename:", value: tarball.filename },
649
- { name: "package size:", value: formatBytes(tarball.size) },
650
- { name: "unpacked size:", value: formatBytes(tarball.unpackedSize) },
651
- { name: "shasum:", value: tarball.shasum },
652
- {
653
- name: "integrity:",
654
- value:
655
- tarball.integrity.toString().slice(0, 20) +
656
- "[...]" +
657
- tarball.integrity.toString().slice(80)
658
- },
659
- tarball.bundled.length && {
660
- name: "bundled deps:",
661
- value: tarball.bundled.length
662
- },
663
- tarball.bundled.length && {
664
- name: "bundled files:",
665
- value: tarball.entryCount - tarball.files.length
666
- },
667
- tarball.bundled.length && {
668
- name: "own files:",
669
- value: tarball.files.length
670
- },
671
- { name: "total files:", value: tarball.entryCount }
672
- ].filter(x => x),
673
- {
674
- include: ["name", "value"],
675
- showHeaders: false
676
- }
677
- )
678
- );
679
- console.log("", "");
680
- };