@savvy-web/silk-effects 7.5.3 → 8.0.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.
@@ -1,4 +1,4 @@
1
- import changelogFunctions from "../changelog/index.js";
1
+ import { makeChangelogFunctions } from "../changelog/index.js";
2
2
 
3
3
  //#region src/changesets/api/changelog.ts
4
4
  /**
@@ -103,10 +103,13 @@ var Changelog = class {
103
103
  * @param versionType - The semantic version bump type (`"major"`, `"minor"`, or `"patch"`)
104
104
  * @param options - Configuration object; must include `repo` in `"owner/repo"` format.
105
105
  * Pass `null` to use defaults (no GitHub link resolution).
106
+ * @param logMode - How a failed GitHub lookup is reported (`"stderr"` when omitted);
107
+ * the host reads its own environment and passes `"github"` / `"silent"` — this
108
+ * engine never does. See `ChangesetLogMode`.
106
109
  * @returns A promise resolving to the formatted markdown string
107
110
  */
108
- static async formatReleaseLine(changeset, versionType, options) {
109
- return changelogFunctions.getReleaseLine(changeset, versionType, options);
111
+ static async formatReleaseLine(changeset, versionType, options, logMode) {
112
+ return makeChangelogFunctions(logMode === void 0 ? {} : { logMode }).getReleaseLine(changeset, versionType, options);
110
113
  }
111
114
  /**
112
115
  * Format dependency update release lines into a markdown table.
@@ -121,11 +124,13 @@ var Changelog = class {
121
124
  * old/new versions and package metadata
122
125
  * @param options - Configuration object; must include `repo` in `"owner/repo"` format.
123
126
  * Pass `null` to use defaults.
127
+ * @param logMode - How a failed GitHub lookup is reported (`"stderr"` when omitted);
128
+ * see {@link Changelog.formatReleaseLine}.
124
129
  * @returns A promise resolving to the formatted markdown string containing
125
130
  * the dependency update table
126
131
  */
127
- static async formatDependencyReleaseLine(changesets, dependenciesUpdated, options) {
128
- return changelogFunctions.getDependencyReleaseLine(changesets, dependenciesUpdated, options);
132
+ static async formatDependencyReleaseLine(changesets, dependenciesUpdated, options, logMode) {
133
+ return makeChangelogFunctions(logMode === void 0 ? {} : { logMode }).getDependencyReleaseLine(changesets, dependenciesUpdated, options);
129
134
  }
130
135
  };
131
136
 
@@ -1,10 +1,10 @@
1
1
  import { resolveCommitType } from "../categories/index.js";
2
2
  import { GitHubService } from "../services/github.js";
3
+ import { logWarning } from "../utils/logger.js";
3
4
  import { parseMarkdown, stringifyMarkdown } from "../utils/remark-pipeline.js";
4
5
  import { GitHubInfoSchema } from "../schemas/github.js";
5
6
  import { parseCommitMessage } from "../utils/commit-parser.js";
6
7
  import { parseIssueReferences } from "../utils/issue-refs.js";
7
- import { logWarning } from "../utils/logger.js";
8
8
  import { parseChangesetSections } from "../utils/section-parser.js";
9
9
  import { formatChangelogEntry, formatPRAndUserAttribution } from "./formatting.js";
10
10
  import { Effect, Schema } from "effect";
@@ -177,10 +177,7 @@ function getReleaseLine(changeset, versionType, options) {
177
177
  if (changeset.commit) commitInfo = yield* (yield* GitHubService).getInfo({
178
178
  commit: changeset.commit,
179
179
  repo: options.repo
180
- }).pipe(Effect.flatMap((raw) => Schema.decodeUnknownEffect(GitHubInfoSchema)(raw).pipe(Effect.map(() => raw), Effect.catch(() => Effect.succeed(raw)))), Effect.catch((error) => {
181
- logWarning("Could not fetch GitHub info for commit:", changeset.commit ?? "", String(error));
182
- return Effect.succeed(null);
183
- }));
180
+ }).pipe(Effect.flatMap((raw) => Schema.decodeUnknownEffect(GitHubInfoSchema)(raw).pipe(Effect.map(() => raw), Effect.catch(() => Effect.succeed(raw)))), Effect.catch((error) => logWarning("Could not fetch GitHub info for commit:", changeset.commit ?? "", String(error)).pipe(Effect.as(null))));
184
181
  const parsed = parseChangesetSections(changeset.summary);
185
182
  const firstLine = changeset.summary.split("\n")[0];
186
183
  const commitMsg = parseCommitMessage(firstLine);
@@ -1,5 +1,6 @@
1
1
  import { validateChangesetOptions } from "../schemas/options.js";
2
2
  import { GitHubService } from "../services/github.js";
3
+ import { ChangesetLogMode } from "../utils/logger.js";
3
4
  import { getDependencyReleaseLine } from "./getDependencyReleaseLine.js";
4
5
  import { getReleaseLine } from "./getReleaseLine.js";
5
6
  import { Effect } from "effect";
@@ -67,31 +68,50 @@ import { Effect } from "effect";
67
68
  */
68
69
  const MainLayer = GitHubService.layer;
69
70
  /**
70
- * Changesets API `ChangelogFunctions` implementation.
71
+ * Build a Changesets `ChangelogFunctions` implementation bound to a warning
72
+ * mode.
71
73
  *
72
- * This object satisfies the `ChangelogFunctions` contract from
73
- * `\@changesets/types`. Each method validates options, runs the
74
- * corresponding Effect program with the merged service layer, and
75
- * returns a `Promise<string>`.
74
+ * @remarks
75
+ * This module is engine code and reads no environment; the host that installs
76
+ * the functions (the `\@savvy-web/changelog` package under the changesets CLI)
77
+ * decides the mode from its own `process.env` and passes it here. Each method
78
+ * validates options, runs the corresponding Effect program with the merged
79
+ * service layer and the chosen {@link ChangesetLogMode}, and returns a
80
+ * `Promise<string>`.
76
81
  *
77
- * @internal
82
+ * @param options - The warning mode to provide
83
+ * @returns A `ChangelogFunctions` object for `.changeset/config.json`
84
+ *
85
+ * @public
78
86
  */
79
- const changelogFunctions = {
80
- getReleaseLine: async (changeset, versionType, options) => {
81
- const program = Effect.gen(function* () {
87
+ function makeChangelogFunctions(options = {}) {
88
+ const run = (program) => {
89
+ const provided = program.pipe(Effect.provide(MainLayer));
90
+ return Effect.runPromise(options.logMode === void 0 ? provided : provided.pipe(Effect.provideService(ChangesetLogMode, options.logMode)));
91
+ };
92
+ return {
93
+ getReleaseLine: async (changeset, versionType, options) => run(Effect.gen(function* () {
82
94
  const opts = yield* validateChangesetOptions(options);
83
95
  return yield* getReleaseLine(changeset, versionType, opts);
84
- });
85
- return Effect.runPromise(program.pipe(Effect.provide(MainLayer)));
86
- },
87
- getDependencyReleaseLine: async (changesets, dependenciesUpdated, options) => {
88
- const program = Effect.gen(function* () {
96
+ })),
97
+ getDependencyReleaseLine: async (changesets, dependenciesUpdated, options) => run(Effect.gen(function* () {
89
98
  const opts = yield* validateChangesetOptions(options);
90
99
  return yield* getDependencyReleaseLine(changesets, dependenciesUpdated, opts);
91
- });
92
- return Effect.runPromise(program.pipe(Effect.provide(MainLayer)));
93
- }
94
- };
100
+ }))
101
+ };
102
+ }
103
+ /**
104
+ * Changesets API `ChangelogFunctions` implementation with the default warning
105
+ * mode (`"stderr"`).
106
+ *
107
+ * @remarks
108
+ * Equivalent to `makeChangelogFunctions()`. A host that runs under GitHub
109
+ * Actions or a test runner should call {@link makeChangelogFunctions} with the
110
+ * mode it detects instead.
111
+ *
112
+ * @internal
113
+ */
114
+ const changelogFunctions = makeChangelogFunctions();
95
115
 
96
116
  //#endregion
97
- export { changelogFunctions as default };
117
+ export { changelogFunctions as default, makeChangelogFunctions };
@@ -5,11 +5,12 @@ import { JsonPathSchema, LegacyVersionFileConfigSchema, LegacyVersionFilesSchema
5
5
  import { GlobSchema, PackageScopeSchema, PackagesRecordSchema } from "./schemas/package-scope.js";
6
6
  import { ChangesetOptionsSchema, RepoSchema } from "./schemas/options.js";
7
7
  import { GitHubService, makeGitHubTest } from "./services/github.js";
8
+ import { ChangesetLogMode } from "./utils/logger.js";
8
9
  import { NonEmptyString, PositiveInteger } from "./schemas/primitives.js";
9
10
  import { DependencyActionSchema, DependencyTableRowSchema, DependencyTableSchema, DependencyTableTypeSchema, VERSION_RE, VersionOrEmptySchema } from "./schemas/dependency-table.js";
10
11
  import { serializeDependencyTableToMarkdown } from "./utils/dependency-table.js";
11
12
  import { GitHubInfoSchema, IssueNumberSchema, UrlOrMarkdownLinkSchema, UsernameSchema } from "./schemas/github.js";
12
- import changelogFunctions from "./changelog/index.js";
13
+ import changelogFunctions, { makeChangelogFunctions } from "./changelog/index.js";
13
14
  import { Changelog } from "./api/changelog.js";
14
15
  import { DependencyTable } from "./api/dependency-table.js";
15
16
  import { ContentStructureRule } from "./remark/rules/content-structure.js";
@@ -66,6 +67,7 @@ var changesets_exports = /* @__PURE__ */ __exportAll({
66
67
  ChangelogTransformer: () => ChangelogTransformer,
67
68
  ChangesetIOError: () => ChangesetIOError,
68
69
  ChangesetLinter: () => ChangesetLinter,
70
+ ChangesetLogMode: () => ChangesetLogMode,
69
71
  ChangesetOptionsSchema: () => ChangesetOptionsSchema,
70
72
  ChangesetPreviewSchema: () => ChangesetPreviewSchema,
71
73
  ChangesetSchema: () => ChangesetSchema,
@@ -152,6 +154,7 @@ var changesets_exports = /* @__PURE__ */ __exportAll({
152
154
  isPureDependencyChangeset: () => isPureDependencyChangeset,
153
155
  listPublishablePackageNames: () => listPublishablePackageNames,
154
156
  makeBranchAnalyzerTest: () => makeBranchAnalyzerTest,
157
+ makeChangelogFunctions: () => makeChangelogFunctions,
155
158
  makeConfigInspectorTest: () => makeConfigInspectorTest,
156
159
  makeDepsRegenDefault: () => makeDepsRegenDefault,
157
160
  makeGitHubTest: () => makeGitHubTest,
@@ -162,4 +165,4 @@ var changesets_exports = /* @__PURE__ */ __exportAll({
162
165
  });
163
166
 
164
167
  //#endregion
165
- export { AggregateDependencyTablesPlugin, AppliedReleaseEntrySchema, AppliedReleaseSchema, BranchAnalysisSchema, BranchAnalyzer, BranchFileEntrySchema, BumpTypeSchema, Categories, Changelog, ChangelogService, ChangelogTransformer, ChangesetIOError, ChangesetLinter, ChangesetOptionsSchema, ChangesetPreviewSchema, ChangesetSchema, ChangesetSummarySchema, ChangesetValidationError, ClassificationReasonSchema, ClassificationSchema, CoexistingChangesetSchema, CommitHashSchema, ConfigInspector, ConfigurationError, ContentStructureRule, ContributorFootnotesPlugin, DeduplicateItemsPlugin, DependencyActionSchema, DependencyTable, DependencyTableFormatRule, DependencyTableRowSchema, DependencyTableSchema, DependencyTableTypeSchema, DependencyTypeSchema, DependencyUpdateSchema, DepsRegen, DepsRegenDefault, FileStatusSchema, GitError, GitHubApiError, GitHubInfoSchema, GitHubService, GlobSchema, HeadingHierarchyRule, InspectedConfigSchema, IssueLinkRefsPlugin, IssueNumberSchema, JsonPathSchema, LegacyVersionFileConfigSchema, LegacyVersionFilesSchema, MaintenanceNotePlugin, MaintenanceReasonSchema, MaintenanceTriggerSchema, MarkdownParseError, ContentStructureRule$1 as MarkdownlintContentStructureRule, DependencyTableFormatRule$1 as MarkdownlintDependencyTableFormatRule, HeadingHierarchyRule$1 as MarkdownlintHeadingHierarchyRule, RequiredSectionsRule$1 as MarkdownlintRequiredSectionsRule, UncategorizedContentRule$1 as MarkdownlintUncategorizedContentRule, MergeSectionsPlugin, NonEmptyString, NormalizeFormatPlugin, PackageScopeSchema, PackagesRecordSchema, PendingChangesetSchema, PositiveInteger, PreviewReleaseSchema, RegenDiffRowSchema, RegenPlanSchema, RegenResultSchema, ReleasePlanError, ReleasePlanner, ReorderSectionsPlugin, RepoSchema, RequiredSectionsRule, ResolvedPackageScopeSchema, ResolvedVersionFileSchema, SectionCategorySchema, SilkChangesetPreset, SilkChangesetTransformPreset, SilkChangesetsRules, UncategorizedContentRule, UrlOrMarkdownLinkSchema, UsernameSchema, VERSION_RE, VersionFileConfigSchema, VersionFileError, VersionFileUpdateRecordSchema, VersionFiles, VersionFilesSchema, VersionOrEmptySchema, VersionTypeSchema, changelogFunctions, changesets_exports, computeWorkspaceDependencyDiffs, deriveMaintenanceReason, gitMergeBase, isPureDependencyChangeset, listPublishablePackageNames, makeBranchAnalyzerTest, makeConfigInspectorTest, makeDepsRegenDefault, makeGitHubTest, makeReleasePlannerTest, parseChangesetPackages, serializeDependencyTableToMarkdown, vanillaChangelogFunctions };
168
+ export { AggregateDependencyTablesPlugin, AppliedReleaseEntrySchema, AppliedReleaseSchema, BranchAnalysisSchema, BranchAnalyzer, BranchFileEntrySchema, BumpTypeSchema, Categories, Changelog, ChangelogService, ChangelogTransformer, ChangesetIOError, ChangesetLinter, ChangesetLogMode, ChangesetOptionsSchema, ChangesetPreviewSchema, ChangesetSchema, ChangesetSummarySchema, ChangesetValidationError, ClassificationReasonSchema, ClassificationSchema, CoexistingChangesetSchema, CommitHashSchema, ConfigInspector, ConfigurationError, ContentStructureRule, ContributorFootnotesPlugin, DeduplicateItemsPlugin, DependencyActionSchema, DependencyTable, DependencyTableFormatRule, DependencyTableRowSchema, DependencyTableSchema, DependencyTableTypeSchema, DependencyTypeSchema, DependencyUpdateSchema, DepsRegen, DepsRegenDefault, FileStatusSchema, GitError, GitHubApiError, GitHubInfoSchema, GitHubService, GlobSchema, HeadingHierarchyRule, InspectedConfigSchema, IssueLinkRefsPlugin, IssueNumberSchema, JsonPathSchema, LegacyVersionFileConfigSchema, LegacyVersionFilesSchema, MaintenanceNotePlugin, MaintenanceReasonSchema, MaintenanceTriggerSchema, MarkdownParseError, ContentStructureRule$1 as MarkdownlintContentStructureRule, DependencyTableFormatRule$1 as MarkdownlintDependencyTableFormatRule, HeadingHierarchyRule$1 as MarkdownlintHeadingHierarchyRule, RequiredSectionsRule$1 as MarkdownlintRequiredSectionsRule, UncategorizedContentRule$1 as MarkdownlintUncategorizedContentRule, MergeSectionsPlugin, NonEmptyString, NormalizeFormatPlugin, PackageScopeSchema, PackagesRecordSchema, PendingChangesetSchema, PositiveInteger, PreviewReleaseSchema, RegenDiffRowSchema, RegenPlanSchema, RegenResultSchema, ReleasePlanError, ReleasePlanner, ReorderSectionsPlugin, RepoSchema, RequiredSectionsRule, ResolvedPackageScopeSchema, ResolvedVersionFileSchema, SectionCategorySchema, SilkChangesetPreset, SilkChangesetTransformPreset, SilkChangesetsRules, UncategorizedContentRule, UrlOrMarkdownLinkSchema, UsernameSchema, VERSION_RE, VersionFileConfigSchema, VersionFileError, VersionFileUpdateRecordSchema, VersionFiles, VersionFilesSchema, VersionOrEmptySchema, VersionTypeSchema, changelogFunctions, changesets_exports, computeWorkspaceDependencyDiffs, deriveMaintenanceReason, gitMergeBase, isPureDependencyChangeset, listPublishablePackageNames, makeBranchAnalyzerTest, makeChangelogFunctions, makeConfigInspectorTest, makeDepsRegenDefault, makeGitHubTest, makeReleasePlannerTest, parseChangesetPackages, serializeDependencyTableToMarkdown, vanillaChangelogFunctions };
@@ -1,37 +1,64 @@
1
+ import { Context, Effect } from "effect";
2
+
1
3
  //#region src/changesets/utils/logger.ts
2
4
  /**
3
- * Log a warning message.
5
+ * Warning output for changelog generation, parameterised by a
6
+ * {@link ChangesetLogMode} reference instead of an ambient environment read.
4
7
  *
5
8
  * @remarks
6
- * Detection order:
7
- * 1. If `process.env.VITEST` is set, the message is silently discarded.
8
- * 2. If `process.env.GITHUB_ACTIONS === "true"`, the message is emitted
9
- * as a `::warning::` annotation.
10
- * 3. Otherwise, `console.warn` is used.
9
+ * This module is engine code shared by every front end, so it must not read
10
+ * `process` a `process.env` read here would bake one host's environment
11
+ * into every other. The mode is a `Context.Reference` with a default of
12
+ * `"stderr"`; a front end that knows it runs under GitHub Actions or a test
13
+ * runner provides `"github"` or `"silent"` from its own `process.env` read.
11
14
  *
12
- * @param message - The warning message
13
- * @param args - Additional arguments (concatenated with a space in CI mode)
15
+ * @packageDocumentation
16
+ */
17
+ /**
18
+ * The reference that selects the {@link ChangesetLogModeValue}.
19
+ *
20
+ * @remarks
21
+ * Defaults to `"stderr"` when no front end provides it, so a program that
22
+ * never touches the reference still reports. Provide with
23
+ * `Layer.succeed(ChangesetLogMode, "github")` or
24
+ * `Effect.provideService(ChangesetLogMode, "silent")`.
14
25
  *
15
26
  * @example
16
27
  * ```typescript
17
- * import { logWarning } from "../utils/logger.js";
28
+ * import { Effect } from "effect";
29
+ * import { Changesets } from "\@savvy-web/silk-effects";
18
30
  *
19
- * logWarning("Duplicate dependency entry", "effect@3.19.0");
20
- * // In CI: "::warning::Duplicate dependency entry effect@3.19.0"
21
- * // Locally: console.warn("Duplicate dependency entry", "effect@3.19.0")
31
+ * const mode = process.env.GITHUB_ACTIONS === "true" ? "github" : "stderr";
32
+ * program.pipe(Effect.provideService(Changesets.ChangesetLogMode, mode));
22
33
  * ```
23
34
  *
35
+ * @public
36
+ */
37
+ const ChangesetLogMode = Context.Reference("@savvy-web/silk-effects/Changesets/ChangesetLogMode", { defaultValue: () => "stderr" });
38
+ /**
39
+ * Log a warning message according to the {@link ChangesetLogMode} in context.
40
+ *
41
+ * @param message - The warning message
42
+ * @param args - Additional arguments (concatenated with a space in `"github"` mode)
43
+ * @returns An `Effect` that never fails
44
+ *
24
45
  * @internal
25
46
  */
26
47
  function logWarning(message, ...args) {
27
- /* v8 ignore start — environment-specific */
28
- if (typeof process !== "undefined" && process.env.VITEST) return;
29
- if (typeof process !== "undefined" && process.env.GITHUB_ACTIONS === "true") {
30
- const text = args.length > 0 ? `${message} ${args.join(" ")}` : message;
31
- console.warn(`::warning::${text}`);
32
- } else console.warn(message, ...args);
33
- /* v8 ignore stop */
48
+ return Effect.gen(function* () {
49
+ switch (yield* ChangesetLogMode) {
50
+ case "silent": return;
51
+ case "github": {
52
+ const text = args.length > 0 ? `${message} ${args.join(" ")}` : message;
53
+ console.warn(`::warning::${text}`);
54
+ return;
55
+ }
56
+ case "stderr":
57
+ console.warn(message, ...args);
58
+ return;
59
+ }
60
+ });
34
61
  }
35
62
 
36
63
  //#endregion
37
- export { logWarning };
64
+ export { ChangesetLogMode, logWarning };