@savvy-web/tsdown-plugins 2.11.1 → 2.11.3

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,7 +1,13 @@
1
- import { readdirSync, rmSync } from "node:fs";
2
- import { join } from "node:path";
1
+ import { rmSync } from "node:fs";
2
+ import { join, resolve } from "node:path";
3
+ import { Result } from "effect";
4
+ import { GlobPattern, GlobPatternOptions } from "@effected/glob";
5
+ import { descendSync } from "@effected/walker";
6
+ import { nodeWalkerSyncOps } from "@effected/walker/node-sync";
3
7
 
4
8
  // src/build/strip-maps.ts
9
+ /** `.d.ts.map` / `.d.cts.map` at any depth, dot-directories included. */
10
+ const STRIPPABLE_MAPS = Result.getOrThrow(GlobPattern.compileResult("**/*.d.{ts,cts}.map", GlobPatternOptions.make({ dot: true })));
5
11
  /**
6
12
  * Remove declaration source-map files (`.d.ts.map` / `.d.cts.map`) from a built `pkg`
7
13
  * directory, returning the removed paths.
@@ -18,23 +24,16 @@ import { join } from "node:path";
18
24
  * @public
19
25
  */
20
26
  function removeDeclarationMaps(pkgDir) {
21
- const removed = [];
22
- let entries;
23
- try {
24
- entries = readdirSync(pkgDir, { withFileTypes: true });
25
- } catch {
26
- return removed;
27
- }
28
- for (const entry of entries) {
29
- if (entry.name === "node_modules") continue;
30
- const full = join(pkgDir, entry.name);
31
- if (entry.isDirectory()) removed.push(...removeDeclarationMaps(full));
32
- else if (entry.name.endsWith(".d.ts.map") || entry.name.endsWith(".d.cts.map")) {
33
- rmSync(full, { force: true });
34
- removed.push(full);
35
- }
36
- }
37
- return removed;
27
+ return Result.getOrThrow(descendSync(STRIPPABLE_MAPS, {
28
+ cwd: resolve(pkgDir),
29
+ prune: ["node_modules"],
30
+ onUnreadable: "skip",
31
+ ...nodeWalkerSyncOps
32
+ })).map((rel) => {
33
+ const full = join(pkgDir, rel);
34
+ rmSync(full, { force: true });
35
+ return full;
36
+ });
38
37
  }
39
38
 
40
39
  export { removeDeclarationMaps };
@@ -1,18 +1,25 @@
1
1
  import { ConfigValidationError } from "../errors.js";
2
2
  import { findRelativeSpecifiers } from "../dts/relative-imports.js";
3
- import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, statSync } from "node:fs";
4
- import { dirname, join, relative } from "node:path";
3
+ import { copyFileSync, existsSync, mkdirSync, readFileSync, statSync } from "node:fs";
4
+ import { dirname, join, resolve } from "node:path";
5
+ import { Result } from "effect";
6
+ import { GlobPattern, GlobPatternOptions } from "@effected/glob";
7
+ import { descendSync } from "@effected/walker";
8
+ import { nodeWalkerSyncOps } from "@effected/walker/node-sync";
5
9
 
6
10
  // src/build/sync-public.ts
7
- /** Recursively collect every file path under `dir`, relative to `base`. */
8
- function listFilesRel(dir, base = dir) {
9
- const out = [];
10
- for (const entry of readdirSync(dir, { withFileTypes: true })) {
11
- const abs = join(dir, entry.name);
12
- if (entry.isDirectory()) out.push(...listFilesRel(abs, base));
13
- else out.push(relative(base, abs));
14
- }
15
- return out;
11
+ /** Every file at any depth, dotfiles included. */
12
+ const EVERY_FILE = Result.getOrThrow(GlobPattern.compileResult("**", GlobPatternOptions.make({ dot: true })));
13
+ /**
14
+ * Every file path under `dir`, relative to it (POSIX separators, sorted). Nothing is pruned, so a
15
+ * `public/.well-known/` or `public/node_modules/` asset still copies; symlinked directories are not entered.
16
+ */
17
+ function listFilesRel(dir) {
18
+ return Result.getOrThrow(descendSync(EVERY_FILE, {
19
+ cwd: resolve(dir),
20
+ prune: [],
21
+ ...nodeWalkerSyncOps
22
+ }));
16
23
  }
17
24
  /** True when both files exist with identical size and bytes. Size is checked first so the byte read is skipped for the common changed case. */
18
25
  function sameBytes(a, b) {
package/index.d.ts CHANGED
@@ -2023,6 +2023,10 @@ declare const EnvironmentDetector_base: Context.ServiceClass<EnvironmentDetector
2023
2023
  }>;
2024
2024
  /** @public */
2025
2025
  export declare class EnvironmentDetector extends EnvironmentDetector_base {
2026
+ /**
2027
+ * Detects from `@effected/env`'s `CurrentRuntimeEnv`, read through the ambient `ConfigProvider` (the process
2028
+ * environment by default) once, when the layer is built.
2029
+ */
2026
2030
  static readonly layer: Layer.Layer<EnvironmentDetector>;
2027
2031
  }
2028
2032
  /** @public */
@@ -1,8 +1,14 @@
1
- import { readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
2
- import { join } from "node:path";
1
+ import { readFileSync, writeFileSync } from "node:fs";
2
+ import { join, resolve } from "node:path";
3
+ import { Result } from "effect";
4
+ import { GlobPattern, GlobPatternOptions } from "@effected/glob";
5
+ import { descendSync } from "@effected/walker";
6
+ import { nodeWalkerSyncOps } from "@effected/walker/node-sync";
3
7
  import { decode, encode } from "@jridgewell/sourcemap-codec";
4
8
 
5
9
  // src/meta/scrub-declaration-maps.ts
10
+ /** Every declaration map, at any depth, dot-directories included. */
11
+ const DECLARATION_MAPS = Result.getOrThrow(GlobPattern.compileResult("**/*.d.{ts,cts,mts}.map", GlobPatternOptions.make({ dot: true })));
6
12
  /**
7
13
  * Drop every source-less segment (a generated position with no original position) from a
8
14
  * declaration map, in place. Returns the number of segments removed.
@@ -42,18 +48,15 @@ function scrubSourcelessMappings(mapPath) {
42
48
  * @internal
43
49
  */
44
50
  function scrubDeclarationMapsUnder(dir) {
51
+ const maps = Result.getOrThrow(descendSync(DECLARATION_MAPS, {
52
+ cwd: resolve(dir),
53
+ prune: [],
54
+ followSymlinks: true,
55
+ onUnreadable: "skip",
56
+ ...nodeWalkerSyncOps
57
+ }));
45
58
  let removed = 0;
46
- let entries;
47
- try {
48
- entries = readdirSync(dir);
49
- } catch {
50
- return 0;
51
- }
52
- for (const name of entries) {
53
- const p = join(dir, name);
54
- if (statSync(p).isDirectory()) removed += scrubDeclarationMapsUnder(p);
55
- else if (/\.d\.[cm]?ts\.map$/.test(name)) removed += scrubSourcelessMappings(p);
56
- }
59
+ for (const rel of maps) removed += scrubSourcelessMappings(join(dir, rel));
57
60
  return removed;
58
61
  }
59
62
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@savvy-web/tsdown-plugins",
3
- "version": "2.11.1",
3
+ "version": "2.11.3",
4
4
  "private": false,
5
5
  "description": "Interface-only tsdown/rolldown plugin pack powering @savvy-web/bundler",
6
6
  "homepage": "https://github.com/savvy-web/systems/tree/main/packages/tsdown-plugins",
@@ -30,24 +30,24 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@changesets/get-release-plan": "^5.0.2",
33
- "@effect/platform-node": "^4.0.6",
34
- "@effected/glob": "^0.14.0",
35
- "@effected/images": "^0.6.1",
36
- "@effected/jsonc": "^0.20.0",
37
- "@effected/npm": "^0.27.0",
38
- "@effected/package-json": "^0.26.0",
39
- "@effected/semver": "^0.18.0",
40
- "@effected/tsconfig-json": "^0.17.3",
41
- "@effected/walker": "^0.20.1",
42
- "@effected/workspaces": "^0.39.0",
33
+ "@effect/platform-node": "^4.0.7",
34
+ "@effected/env": "^0.7.0",
35
+ "@effected/glob": "^0.16.0",
36
+ "@effected/images": "^0.7.0",
37
+ "@effected/jsonc": "^0.21.0",
38
+ "@effected/npm": "^0.28.0",
39
+ "@effected/package-json": "^0.27.0",
40
+ "@effected/semver": "^0.19.0",
41
+ "@effected/tsconfig-json": "^0.18.0",
42
+ "@effected/walker": "^0.22.0",
43
+ "@effected/workspaces": "^0.40.0",
43
44
  "@jridgewell/sourcemap-codec": "^1.6.0",
44
45
  "@microsoft/api-extractor": "^7.59.4",
45
46
  "@microsoft/tsdoc": "~0.17.1",
46
47
  "@microsoft/tsdoc-config": "~0.18.3",
47
48
  "@tsdoctor/manifest": "^0.2.10",
48
- "effect": "^4.0.6",
49
+ "effect": "^4.0.7",
49
50
  "picocolors": "^1.1.1",
50
- "std-env": "^4.3.0",
51
51
  "tsdown": "^0.23.2",
52
52
  "typescript": "7.1.0-beta"
53
53
  }
@@ -1,16 +1,26 @@
1
- import { Context, Effect, Layer } from "effect";
2
- import { isAgent, isCI } from "std-env";
1
+ import { Context, Effect, Layer, Option } from "effect";
2
+ import { CurrentRuntimeEnv } from "@effected/env";
3
3
 
4
4
  // src/report/services/EnvironmentDetector.ts
5
- const isGitHub = () => process.env.GITHUB_ACTIONS === "true" || process.env.GITHUB_ACTIONS === "1";
5
+ /**
6
+ * Classify a runtime snapshot: an agent wins over CI, GitHub Actions is told apart from every other CI, and the
7
+ * human terminal is the default.
8
+ */
9
+ const classify = (env) => {
10
+ if (Option.isSome(env.agent)) return "agent-shell";
11
+ if (Option.isSome(env.ci)) return env.ci.value === "github-actions" ? "ci-github" : "ci-generic";
12
+ return "terminal";
13
+ };
6
14
  /** @public */
7
15
  var EnvironmentDetector = class extends Context.Service()("@savvy-web/tsdown-plugins/EnvironmentDetector") {
8
- static layer = Layer.succeed(this, { detect: () => Effect.sync(() => {
9
- if (isAgent) return "agent-shell";
10
- if (isGitHub()) return "ci-github";
11
- if (isCI) return "ci-generic";
12
- return "terminal";
13
- }) });
16
+ /**
17
+ * Detects from `@effected/env`'s `CurrentRuntimeEnv`, read through the ambient `ConfigProvider` (the process
18
+ * environment by default) once, when the layer is built.
19
+ */
20
+ static layer = Layer.effect(this, Effect.map(CurrentRuntimeEnv, (env) => {
21
+ const environment = classify(env);
22
+ return { detect: () => Effect.succeed(environment) };
23
+ })).pipe(Layer.provide(CurrentRuntimeEnv.layer));
14
24
  };
15
25
 
16
26
  export { EnvironmentDetector };
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.59.4"
8
+ "packageVersion": "7.60.0"
9
9
  }
10
10
  ]
11
11
  }