@effected/bundler 0.4.0 → 0.5.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.
- package/Bundler.js +30 -27
- package/catalog/resolve-catalogs.js +6 -13
- package/changesets/next-versions.js +16 -22
- package/dts/bundled-siblings.js +38 -42
- package/dts/resolved-tsconfig.js +44 -53
- package/entries/package-json-entries.js +2 -5
- package/index.d.ts +56 -28
- package/internal/exists.js +14 -0
- package/internal/native-realpath.js +15 -0
- package/manifest/emit-manifest.js +53 -28
- package/meta/api-extractor.js +42 -32
- package/meta/bundle-source.js +42 -58
- package/meta/generate.js +92 -101
- package/meta/og-image.js +29 -35
- package/meta/og-satori.js +10 -4
- package/meta/run-pass.js +44 -40
- package/meta/scrub-declaration-maps.js +16 -18
- package/meta/tsconfig-resolver.js +9 -16
- package/meta/tsdoc-config.js +6 -10
- package/package.json +19 -19
- package/passes/build-target-groups.js +97 -75
- package/passes/bundled-deps.js +62 -0
- package/passes/stamp-versions.js +121 -0
- package/passes/sync-public.js +52 -53
- package/passes/third-party-licenses.js +102 -0
- package/tsconfig/sync-options.js +0 -20
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { Result } from "effect";
|
|
2
|
-
import { readFileSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { join, resolve } from "node:path";
|
|
1
|
+
import { Effect, FileSystem, Path, Result } from "effect";
|
|
4
2
|
import { GlobPattern, GlobPatternOptions } from "@effected/glob";
|
|
5
|
-
import {
|
|
6
|
-
import { nodeWalkerSyncOps } from "@effected/walker/node-sync";
|
|
3
|
+
import { descend } from "@effected/walker";
|
|
7
4
|
import { decode, encode } from "@jridgewell/sourcemap-codec";
|
|
8
5
|
|
|
9
6
|
// src/meta/scrub-declaration-maps.ts
|
|
@@ -24,8 +21,9 @@ const DECLARATION_MAPS = Result.getOrThrow(GlobPattern.compileResult("**/*.d.{ts
|
|
|
24
21
|
*
|
|
25
22
|
* @internal
|
|
26
23
|
*/
|
|
27
|
-
|
|
28
|
-
const
|
|
24
|
+
const scrubSourcelessMappings = Effect.fnUntraced(function* (mapPath) {
|
|
25
|
+
const fs = yield* FileSystem.FileSystem;
|
|
26
|
+
const raw = JSON.parse(yield* fs.readFileString(mapPath));
|
|
29
27
|
const lines = decode(raw.mappings);
|
|
30
28
|
let removed = 0;
|
|
31
29
|
const scrubbed = lines.map((segments) => segments.filter((segment) => {
|
|
@@ -35,29 +33,29 @@ function scrubSourcelessMappings(mapPath) {
|
|
|
35
33
|
}
|
|
36
34
|
return true;
|
|
37
35
|
}));
|
|
38
|
-
if (removed > 0)
|
|
36
|
+
if (removed > 0) yield* fs.writeFileString(mapPath, `${JSON.stringify({
|
|
39
37
|
...raw,
|
|
40
38
|
mappings: encode(scrubbed)
|
|
41
|
-
})}\n
|
|
39
|
+
})}\n`);
|
|
42
40
|
return removed;
|
|
43
|
-
}
|
|
41
|
+
});
|
|
44
42
|
/**
|
|
45
43
|
* Scrub every `.d.ts.map`/`.d.cts.map`/`.d.mts.map` under `dir` (recursively). Returns the total
|
|
46
44
|
* number of segments removed. Missing dir -> 0.
|
|
47
45
|
*
|
|
48
46
|
* @internal
|
|
49
47
|
*/
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
48
|
+
const scrubDeclarationMapsUnder = Effect.fnUntraced(function* (dir) {
|
|
49
|
+
const path = yield* Path.Path;
|
|
50
|
+
const maps = yield* descend(DECLARATION_MAPS, {
|
|
51
|
+
cwd: path.resolve(dir),
|
|
53
52
|
prune: [],
|
|
54
53
|
followSymlinks: true,
|
|
55
|
-
onUnreadable: "skip"
|
|
56
|
-
|
|
57
|
-
}));
|
|
54
|
+
onUnreadable: "skip"
|
|
55
|
+
});
|
|
58
56
|
let removed = 0;
|
|
59
|
-
for (const rel of maps) removed += scrubSourcelessMappings(join(dir, rel));
|
|
57
|
+
for (const rel of maps) removed += yield* scrubSourcelessMappings(path.join(dir, rel));
|
|
60
58
|
return removed;
|
|
61
|
-
}
|
|
59
|
+
});
|
|
62
60
|
|
|
63
61
|
export { scrubDeclarationMapsUnder, scrubSourcelessMappings };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { PortableTsconfig, TsconfigLoaderSync } from "@effected/tsconfig-json";
|
|
1
|
+
import { existsLikeNode } from "../internal/exists.js";
|
|
2
|
+
import { Effect, Path } from "effect";
|
|
3
|
+
import { PortableTsconfig, TsconfigLoader } from "@effected/tsconfig-json";
|
|
5
4
|
|
|
6
5
|
// src/meta/tsconfig-resolver.ts
|
|
7
6
|
/**
|
|
@@ -16,7 +15,7 @@ const TSCONFIG_SCHEMA_URL = "https://json.schemastore.org/tsconfig";
|
|
|
16
15
|
* @remarks
|
|
17
16
|
* Resolves the package's own `<cwd>/tsconfig.json` (which extends the shared
|
|
18
17
|
* `@effected/plugin/tsconfig/ecma.json` base) via `@effected/tsconfig-json`'s
|
|
19
|
-
*
|
|
18
|
+
* `TsconfigLoader` (tsc-parity `extends` resolution) so the
|
|
20
19
|
* result carries the full effective options (target/module/strict/jsx/lib),
|
|
21
20
|
* then projects them through the kit's `PortableTsconfig.make` allow-list
|
|
22
21
|
* filter to a portable, compilerOptions-only shape with no absolute paths or
|
|
@@ -33,9 +32,9 @@ const TSCONFIG_SCHEMA_URL = "https://json.schemastore.org/tsconfig";
|
|
|
33
32
|
*
|
|
34
33
|
* @public
|
|
35
34
|
*/
|
|
36
|
-
|
|
37
|
-
const ownConfig =
|
|
38
|
-
const configPath =
|
|
35
|
+
const resolvePortableTsconfig = Effect.fnUntraced(function* (cwd, fallbackConfigPath) {
|
|
36
|
+
const ownConfig = (yield* Path.Path).join(cwd, "tsconfig.json");
|
|
37
|
+
const configPath = (yield* existsLikeNode(ownConfig)) ? ownConfig : fallbackConfigPath !== void 0 && (yield* existsLikeNode(fallbackConfigPath)) ? fallbackConfigPath : void 0;
|
|
39
38
|
if (configPath === void 0) return {
|
|
40
39
|
$schema: TSCONFIG_SCHEMA_URL,
|
|
41
40
|
compilerOptions: {
|
|
@@ -43,13 +42,7 @@ function resolvePortableTsconfig(cwd, fallbackConfigPath) {
|
|
|
43
42
|
noEmit: true
|
|
44
43
|
}
|
|
45
44
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return PortableTsconfig.make(resolved, { includeTypes: true });
|
|
49
|
-
} catch (error) {
|
|
50
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
51
|
-
throw new Error(`Cannot resolve portable tsconfig at ${configPath}: ${message}`, { cause: error });
|
|
52
|
-
}
|
|
53
|
-
}
|
|
45
|
+
return yield* TsconfigLoader.resolve(configPath).pipe(Effect.map((resolved) => PortableTsconfig.make(resolved, { includeTypes: true })), Effect.mapError((error) => new Error(`Cannot resolve portable tsconfig at ${configPath}: ${error instanceof Error ? error.message : String(error)}`, { cause: error })));
|
|
46
|
+
});
|
|
54
47
|
|
|
55
48
|
export { resolvePortableTsconfig };
|
package/meta/tsdoc-config.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import { Effect, FileSystem, Path } from "effect";
|
|
1
2
|
import { isDeepStrictEqual } from "node:util";
|
|
2
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
3
|
import { StandardTags } from "@microsoft/tsdoc";
|
|
5
4
|
|
|
6
5
|
// src/meta/tsdoc-config.ts
|
|
@@ -30,18 +29,15 @@ function buildTsdocConfig(tsdoc) {
|
|
|
30
29
|
return config;
|
|
31
30
|
}
|
|
32
31
|
/** Write tsdoc.json to `cwd`. Deterministic and idempotent: skips the write when the existing file is byte-equal to the computed config. Returns the path. */
|
|
33
|
-
|
|
34
|
-
const
|
|
32
|
+
const writeTsdocConfig = Effect.fnUntraced(function* (cwd, tsdoc) {
|
|
33
|
+
const fs = yield* FileSystem.FileSystem;
|
|
34
|
+
const path = (yield* Path.Path).join(cwd, "tsdoc.json");
|
|
35
35
|
const config = buildTsdocConfig({
|
|
36
36
|
suppressWarnings: tsdoc.suppressWarnings ?? [],
|
|
37
37
|
tagDefinitions: tsdoc.tagDefinitions ?? []
|
|
38
38
|
});
|
|
39
|
-
if (
|
|
40
|
-
const existing = JSON.parse(readFileSync(path, "utf-8"));
|
|
41
|
-
if (isDeepStrictEqual(existing, config)) return path;
|
|
42
|
-
} catch {}
|
|
43
|
-
writeFileSync(path, `${JSON.stringify(config, null, " ")}\n`, "utf-8");
|
|
39
|
+
if (!(yield* fs.readFileString(path).pipe(Effect.flatMap((text) => Effect.try(() => isDeepStrictEqual(JSON.parse(text), config))), Effect.orElseSucceed(() => false)))) yield* fs.writeFileString(path, `${JSON.stringify(config, null, " ")}\n`);
|
|
44
40
|
return path;
|
|
45
|
-
}
|
|
41
|
+
});
|
|
46
42
|
|
|
47
43
|
export { buildTsdocConfig, writeTsdocConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effected/bundler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The kit's build pipeline: effected.toml config, tsdown JS and declaration passes, API Extractor meta, SEA, GitHub Action bundles and build journals.",
|
|
6
6
|
"keywords": [
|
|
@@ -38,24 +38,24 @@
|
|
|
38
38
|
"./package.json": "./package.json"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@effect/platform-node": "4.1.
|
|
42
|
-
"@effected/changesets": "0.
|
|
43
|
-
"@effected/config-file": "
|
|
44
|
-
"@effected/env": "
|
|
45
|
-
"@effected/files": "
|
|
46
|
-
"@effected/glob": "
|
|
47
|
-
"@effected/images": "
|
|
48
|
-
"@effected/jsonc": "
|
|
49
|
-
"@effected/jsonl": "
|
|
50
|
-
"@effected/manifest": "
|
|
51
|
-
"@effected/npm": "
|
|
52
|
-
"@effected/package-json": "
|
|
53
|
-
"@effected/semver": "
|
|
54
|
-
"@effected/toml": "
|
|
55
|
-
"@effected/tsconfig-json": "
|
|
56
|
-
"@effected/walker": "
|
|
57
|
-
"@effected/workspaces": "
|
|
58
|
-
"@effected/yaml": "
|
|
41
|
+
"@effect/platform-node": "4.1.4",
|
|
42
|
+
"@effected/changesets": "0.5.0",
|
|
43
|
+
"@effected/config-file": "0.27.1",
|
|
44
|
+
"@effected/env": "0.12.0",
|
|
45
|
+
"@effected/files": "0.3.0",
|
|
46
|
+
"@effected/glob": "0.21.0",
|
|
47
|
+
"@effected/images": "0.10.0",
|
|
48
|
+
"@effected/jsonc": "0.25.0",
|
|
49
|
+
"@effected/jsonl": "0.19.0",
|
|
50
|
+
"@effected/manifest": "0.2.0",
|
|
51
|
+
"@effected/npm": "0.34.0",
|
|
52
|
+
"@effected/package-json": "0.32.1",
|
|
53
|
+
"@effected/semver": "0.24.0",
|
|
54
|
+
"@effected/toml": "0.20.0",
|
|
55
|
+
"@effected/tsconfig-json": "0.21.1",
|
|
56
|
+
"@effected/walker": "0.28.0",
|
|
57
|
+
"@effected/workspaces": "0.47.0",
|
|
58
|
+
"@effected/yaml": "0.30.0",
|
|
59
59
|
"@jridgewell/sourcemap-codec": "^1.6.0",
|
|
60
60
|
"@microsoft/api-extractor": "^7.60.1",
|
|
61
61
|
"@microsoft/tsdoc": "~0.17.1",
|
|
@@ -6,12 +6,14 @@ import { emitManifest } from "../manifest/emit-manifest.js";
|
|
|
6
6
|
import { buildMetricsPlugin } from "../report/metrics-plugin.js";
|
|
7
7
|
import { createTimer } from "../report/timer.js";
|
|
8
8
|
import { createTsdownLogger } from "../report/tsdown-logger.js";
|
|
9
|
+
import { bundlePatterns, bundledEverywhere } from "./bundled-deps.js";
|
|
9
10
|
import { cjsDefaultInterop } from "./cjs-default-interop.js";
|
|
10
11
|
import { nodeBuiltinDefaultInterop } from "./node-builtin-default-interop.js";
|
|
12
|
+
import { stampVersions } from "./stamp-versions.js";
|
|
11
13
|
import { copyAmbientDts, copyPublicDir } from "./sync-public.js";
|
|
12
14
|
import { deriveDeclarationsPassOptions, deriveDtsPassOptions, deriveTargetGroupOptions, outDirFor } from "./target-groups.js";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
+
import { THIRD_PARTY_LICENSES, renderThirdPartyLicenses, thirdPartyLicenses } from "./third-party-licenses.js";
|
|
16
|
+
import { Effect, FileSystem, Path } from "effect";
|
|
15
17
|
|
|
16
18
|
// src/passes/build-target-groups.ts
|
|
17
19
|
/**
|
|
@@ -21,7 +23,7 @@ import { dirname, isAbsolute, join } from "node:path";
|
|
|
21
23
|
*/
|
|
22
24
|
const STUB_BASE_ENTRY = "index";
|
|
23
25
|
/** The configured copy entries as tsdown takes them for one group, with each `to` anchored to that group's outDir. */
|
|
24
|
-
const copyEntriesFor = (entries, outDir) => entries.map((entry) => {
|
|
26
|
+
const copyEntriesFor = (entries, outDir, join) => entries.map((entry) => {
|
|
25
27
|
if (typeof entry === "string") return entry;
|
|
26
28
|
return {
|
|
27
29
|
from: entry.from,
|
|
@@ -50,22 +52,25 @@ const copyEntriesFor = (entries, outDir) => entries.map((entry) => {
|
|
|
50
52
|
* node_modules dependency to its own sibling file (mirroring its `node_modules/...` path),
|
|
51
53
|
* which `npm pack` then strips, breaking the "self-contained" promise `bundleNodeModules`
|
|
52
54
|
* already makes. Scoped to that flag alone; every other build's JS pass is unaffected.
|
|
55
|
+
*
|
|
56
|
+
* The bundler's own reads and writes (the manifest, the tsconfigs, the stubs, `public/`) go through `FileSystem` and
|
|
57
|
+
* `Path`; tsdown always works on the host disk. A tsdown rejection is a defect, carrying the thrown value.
|
|
53
58
|
* @public
|
|
54
59
|
*/
|
|
55
|
-
|
|
56
|
-
const
|
|
60
|
+
const buildTargetGroups = Effect.fnUntraced(function* (options) {
|
|
61
|
+
const fs = yield* FileSystem.FileSystem;
|
|
62
|
+
const path = yield* Path.Path;
|
|
63
|
+
const { dirname, isAbsolute, join } = path;
|
|
64
|
+
const build = options.build ?? (yield* Effect.promise(() => import("tsdown"))).build;
|
|
57
65
|
const publicDir = join(options.cwd, "public");
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
pkgForAmbient = JSON.parse(readFileSync(join(options.cwd, "package.json"), "utf-8"));
|
|
61
|
-
} catch {}
|
|
66
|
+
const pkgForAmbient = yield* fs.readFileString(join(options.cwd, "package.json")).pipe(Effect.flatMap((text) => Effect.try(() => JSON.parse(text))), Effect.orElseSucceed(() => ({})));
|
|
62
67
|
const ambient = extractAmbientDts(pkgForAmbient, {});
|
|
63
|
-
const dtsEmitTsconfigPath = writeDtsEmitTsconfig(options.tsconfigPath);
|
|
64
|
-
const bundledSiblings = options.emitDts === false ? [] :
|
|
68
|
+
const dtsEmitTsconfigPath = yield* writeDtsEmitTsconfig(options.tsconfigPath);
|
|
69
|
+
const bundledSiblings = options.emitDts === false ? [] : yield* resolveBundledSiblings(options.cwd, [...options.bundledPackages ?? [], ...(options.overrides ?? []).flatMap((override) => override.bundledPackages ?? [])]);
|
|
65
70
|
const emitTsconfigFor = (bundled) => {
|
|
66
71
|
const packages = new Set(bundled?.map(packageNameOf));
|
|
67
72
|
const siblings = bundledSiblings.filter((sibling) => packages.has(sibling.name));
|
|
68
|
-
return siblings.length > 0 ? writeDtsEmitTsconfig(options.tsconfigPath, { paths: siblingPaths(siblings) }) : dtsEmitTsconfigPath;
|
|
73
|
+
return siblings.length > 0 ? writeDtsEmitTsconfig(options.tsconfigPath, { paths: siblingPaths(siblings, path) }) : Effect.succeed(dtsEmitTsconfigPath);
|
|
69
74
|
};
|
|
70
75
|
const collector = options.collector;
|
|
71
76
|
const verbose = options.verbose ?? false;
|
|
@@ -75,16 +80,18 @@ async function buildTargetGroups(options) {
|
|
|
75
80
|
};
|
|
76
81
|
const metricsPlugins = (groupId, pass, suppressMixedExports = false) => collector === void 0 ? [] : [buildMetricsPlugin(collector, groupId, pass, verbose, suppressMixedExports)];
|
|
77
82
|
const timingChecks = { checks: { pluginTimings: verbose } };
|
|
78
|
-
const timed =
|
|
83
|
+
const timed = (groupId, pass, run) => Effect.suspend(() => {
|
|
79
84
|
options.onPass?.(pass);
|
|
80
85
|
const timer = createTimer();
|
|
81
|
-
|
|
82
|
-
await run();
|
|
83
|
-
} finally {
|
|
86
|
+
return run.pipe(Effect.asVoid, Effect.ensuring(Effect.sync(() => {
|
|
84
87
|
if (collector !== void 0) collector.recordPassTiming(groupId, pass, timer.elapsed());
|
|
85
|
-
}
|
|
86
|
-
};
|
|
88
|
+
})));
|
|
89
|
+
});
|
|
90
|
+
const tsdown = (config) => Effect.promise(() => build(config));
|
|
91
|
+
const stampPlugin = yield* stampVersions({ cwd: options.cwd });
|
|
92
|
+
const bundled = bundledEverywhere(options.bundle, options.overrides ?? []);
|
|
87
93
|
for (const group of options.groups) {
|
|
94
|
+
const licensesFound = /* @__PURE__ */ new Map();
|
|
88
95
|
if (collector !== void 0) collector.registerGroup(group.id, Object.keys(options.entry));
|
|
89
96
|
const partitions = [{
|
|
90
97
|
entry: options.entry,
|
|
@@ -109,7 +116,7 @@ async function buildTargetGroups(options) {
|
|
|
109
116
|
cwd: options.cwd,
|
|
110
117
|
version: options.version,
|
|
111
118
|
entry: part.entry,
|
|
112
|
-
tsconfigPath: emitTsconfigFor(partBundledPackages),
|
|
119
|
+
tsconfigPath: yield* emitTsconfigFor(partBundledPackages),
|
|
113
120
|
devManifest: options.devManifest,
|
|
114
121
|
...partExternals !== void 0 ? { externals: partExternals } : {},
|
|
115
122
|
...partBundleNodeModules !== void 0 ? { bundleNodeModules: partBundleNodeModules } : {},
|
|
@@ -134,7 +141,7 @@ async function buildTargetGroups(options) {
|
|
|
134
141
|
`!${srcDir}/**/*.{test,spec}.{ts,tsx,mts,cts}`,
|
|
135
142
|
`!${srcDir}/**/*.d.{ts,cts,mts}`
|
|
136
143
|
] : js.entry;
|
|
137
|
-
const manifestPlugin = isBase ? emitManifest({
|
|
144
|
+
const manifestPlugin = isBase ? yield* emitManifest({
|
|
138
145
|
targetGroup,
|
|
139
146
|
devManifest: options.devManifest,
|
|
140
147
|
drop: options.drop,
|
|
@@ -142,10 +149,16 @@ async function buildTargetGroups(options) {
|
|
|
142
149
|
sourceDir: options.cwd,
|
|
143
150
|
dual: options.dualExports ?? js.format.includes("cjs"),
|
|
144
151
|
emitDts: options.emitDts !== false,
|
|
152
|
+
bundled,
|
|
145
153
|
...options.subdirExports !== void 0 ? { subdirExports: options.subdirExports } : {},
|
|
146
154
|
...options.exeRewrite !== void 0 ? { exeRewrite: options.exeRewrite } : {}
|
|
147
155
|
}) : void 0;
|
|
148
|
-
|
|
156
|
+
const licensesPlugin = yield* thirdPartyLicenses({
|
|
157
|
+
cwd: options.cwd,
|
|
158
|
+
packageName: group.name,
|
|
159
|
+
found: licensesFound
|
|
160
|
+
});
|
|
161
|
+
yield* timed(group.id, "js", tsdown({
|
|
149
162
|
config: false,
|
|
150
163
|
cwd: options.cwd,
|
|
151
164
|
entry: jsEntry,
|
|
@@ -162,13 +175,15 @@ async function buildTargetGroups(options) {
|
|
|
162
175
|
...timingChecks,
|
|
163
176
|
...instrument(group.id),
|
|
164
177
|
...part.css !== void 0 ? { css: part.css } : {},
|
|
165
|
-
...isBase && options.copy?.length ? { copy: copyEntriesFor(options.copy, partOutDir) } : {},
|
|
178
|
+
...isBase && options.copy?.length ? { copy: copyEntriesFor(options.copy, partOutDir, join) } : {},
|
|
166
179
|
...partExternals?.length || partBundle?.length ? { deps: {
|
|
167
180
|
...partExternals?.length ? { neverBundle: partExternals } : {},
|
|
168
|
-
...partBundle?.length ? { alwaysBundle: partBundle } : {}
|
|
181
|
+
...partBundle?.length ? { alwaysBundle: bundlePatterns(partBundle) } : {}
|
|
169
182
|
} } : {},
|
|
170
183
|
...js.cjsDefault !== void 0 ? { cjsDefault: js.cjsDefault } : {},
|
|
171
184
|
plugins: [
|
|
185
|
+
stampPlugin,
|
|
186
|
+
licensesPlugin,
|
|
172
187
|
...manifestPlugin ? [manifestPlugin] : [],
|
|
173
188
|
...js.format.includes("cjs") ? [nodeBuiltinDefaultInterop(), cjsDefaultInterop()] : [],
|
|
174
189
|
...options.extraPlugins ?? [],
|
|
@@ -179,27 +194,21 @@ async function buildTargetGroups(options) {
|
|
|
179
194
|
if (options.emitDts === false || Object.keys(dts.entry).length === 0) continue;
|
|
180
195
|
const dtsDeps = dtsNeverBundle.length > 0 || dts.bundledPackages || partBundle?.length ? { deps: {
|
|
181
196
|
...dtsNeverBundle.length > 0 ? { neverBundle: dtsNeverBundle } : {},
|
|
182
|
-
...partBundle?.length ? { alwaysBundle: partBundle } : {},
|
|
197
|
+
...partBundle?.length ? { alwaysBundle: bundlePatterns(partBundle) } : {},
|
|
183
198
|
...dts.bundledPackages ? partBundleNodeModules ? { dts: { alwaysBundle: dts.bundledPackages } } : {
|
|
184
199
|
neverBundle: true,
|
|
185
200
|
dts: { alwaysBundle: dts.bundledPackages }
|
|
186
201
|
} : {}
|
|
187
202
|
} } : {};
|
|
188
203
|
const stubEntries = /* @__PURE__ */ new Map();
|
|
189
|
-
const readSource = (src) =>
|
|
190
|
-
try {
|
|
191
|
-
return readFileSync(isAbsolute(src) ? src : join(options.cwd, src), "utf-8");
|
|
192
|
-
} catch {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
};
|
|
204
|
+
const readSource = (src) => fs.readFileString(isAbsolute(src) ? src : join(options.cwd, src)).pipe(Effect.orElseSucceed(() => void 0));
|
|
196
205
|
const baseSrc = dts.entry[STUB_BASE_ENTRY];
|
|
197
206
|
if (baseSrc !== void 0 && Object.keys(dts.entry).length > 1) {
|
|
198
|
-
const baseSource = readSource(baseSrc);
|
|
207
|
+
const baseSource = yield* readSource(baseSrc);
|
|
199
208
|
const base = baseSource !== void 0 ? collectExportNames(baseSource) : void 0;
|
|
200
209
|
if (base?.complete === true) for (const [entryName, entrySource] of Object.entries(dts.entry)) {
|
|
201
210
|
if (entryName === STUB_BASE_ENTRY || entryName.includes("/")) continue;
|
|
202
|
-
const source = readSource(entrySource);
|
|
211
|
+
const source = yield* readSource(entrySource);
|
|
203
212
|
if (source === void 0) continue;
|
|
204
213
|
const analysis = analyzeReexportBarrel(source);
|
|
205
214
|
if (!analysis.isPureNamedReexportBarrel) continue;
|
|
@@ -211,7 +220,7 @@ async function buildTargetGroups(options) {
|
|
|
211
220
|
});
|
|
212
221
|
}
|
|
213
222
|
}
|
|
214
|
-
|
|
223
|
+
yield* timed(group.id, "dts", Effect.gen(function* () {
|
|
215
224
|
for (const [entryName, entrySource] of Object.entries(dts.entry)) {
|
|
216
225
|
const stub = stubEntries.get(entryName);
|
|
217
226
|
if (stub !== void 0) {
|
|
@@ -229,7 +238,7 @@ async function buildTargetGroups(options) {
|
|
|
229
238
|
typeNames: stub.typeNames,
|
|
230
239
|
baseSpecifier: variant.spec
|
|
231
240
|
});
|
|
232
|
-
|
|
241
|
+
yield* fs.writeFileString(join(partOutDir, variant.file), content);
|
|
233
242
|
collector?.recordEmitted(group.id, "dts", {
|
|
234
243
|
path: variant.file,
|
|
235
244
|
bytes: Buffer.byteLength(content)
|
|
@@ -237,7 +246,7 @@ async function buildTargetGroups(options) {
|
|
|
237
246
|
}
|
|
238
247
|
continue;
|
|
239
248
|
}
|
|
240
|
-
|
|
249
|
+
yield* tsdown({
|
|
241
250
|
config: false,
|
|
242
251
|
cwd: options.cwd,
|
|
243
252
|
entry: { [entryName]: entrySource },
|
|
@@ -260,53 +269,60 @@ async function buildTargetGroups(options) {
|
|
|
260
269
|
]
|
|
261
270
|
});
|
|
262
271
|
}
|
|
263
|
-
});
|
|
272
|
+
}));
|
|
264
273
|
if (js.isProd && options.emitDeclarations === true && Object.keys(decl.entry).length > 0) {
|
|
265
274
|
const partDeclDir = part.outSubdir !== void 0 ? join(decl.outDir, part.outSubdir) : decl.outDir;
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
...dtsNeverBundle.length > 0
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
275
|
+
yield* Effect.promise(async () => {
|
|
276
|
+
try {
|
|
277
|
+
await build({
|
|
278
|
+
config: false,
|
|
279
|
+
cwd: options.cwd,
|
|
280
|
+
entry: decl.entry,
|
|
281
|
+
outDir: partDeclDir,
|
|
282
|
+
format: decl.format,
|
|
283
|
+
platform: decl.platform,
|
|
284
|
+
sourcemap: decl.sourcemap,
|
|
285
|
+
unbundle: decl.unbundle,
|
|
286
|
+
clean: isBase,
|
|
287
|
+
fixedExtension: decl.fixedExtension,
|
|
288
|
+
dts: decl.dts,
|
|
289
|
+
define: decl.define,
|
|
290
|
+
...timingChecks,
|
|
291
|
+
logLevel: "silent",
|
|
292
|
+
...dtsNeverBundle.length > 0 || decl.bundledPackages || partBundle?.length ? { deps: {
|
|
293
|
+
...dtsNeverBundle.length > 0 ? { neverBundle: dtsNeverBundle } : {},
|
|
294
|
+
...partBundle?.length ? { alwaysBundle: bundlePatterns(partBundle) } : {},
|
|
295
|
+
...decl.bundledPackages ? partBundleNodeModules ? { dts: { alwaysBundle: decl.bundledPackages } } : {
|
|
296
|
+
neverBundle: true,
|
|
297
|
+
dts: { alwaysBundle: decl.bundledPackages }
|
|
298
|
+
} : {}
|
|
299
|
+
} } : {},
|
|
300
|
+
...options.extraPlugins !== void 0 ? { plugins: [...options.extraPlugins] } : {}
|
|
301
|
+
});
|
|
302
|
+
} catch (err) {
|
|
303
|
+
collector?.recordWarning(group.id, {
|
|
304
|
+
source: "tsdown",
|
|
305
|
+
level: "warn",
|
|
306
|
+
text: `Could not emit per-module declarations for API Extractor diagnostics: ${String(err)}`
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
});
|
|
299
310
|
}
|
|
300
311
|
}
|
|
301
312
|
const looseOutDir = outDirFor(options.cwd, group.id);
|
|
302
313
|
const isProdGroup = group.id !== "dev";
|
|
303
314
|
const looseDeps = {
|
|
304
315
|
...options.externals?.length ? { neverBundle: options.externals } : {},
|
|
305
|
-
...options.bundle?.length ? { alwaysBundle: options.bundle } : {}
|
|
316
|
+
...options.bundle?.length ? { alwaysBundle: bundlePatterns(options.bundle) } : {}
|
|
306
317
|
};
|
|
307
318
|
for (const lf of options.looseFiles ?? []) {
|
|
308
319
|
const hasCjs = lf.format === "cjs";
|
|
309
|
-
|
|
320
|
+
const looseLicenses = yield* thirdPartyLicenses({
|
|
321
|
+
cwd: options.cwd,
|
|
322
|
+
packageName: group.name,
|
|
323
|
+
found: licensesFound
|
|
324
|
+
});
|
|
325
|
+
yield* timed(group.id, "loose", tsdown({
|
|
310
326
|
config: false,
|
|
311
327
|
cwd: options.cwd,
|
|
312
328
|
entry: { [lf.entryName]: lf.source },
|
|
@@ -328,6 +344,8 @@ async function buildTargetGroups(options) {
|
|
|
328
344
|
...Object.keys(looseDeps).length > 0 ? { deps: looseDeps } : {},
|
|
329
345
|
...hasCjs ? { cjsDefault: true } : {},
|
|
330
346
|
plugins: [
|
|
347
|
+
stampPlugin,
|
|
348
|
+
looseLicenses,
|
|
331
349
|
...hasCjs ? [nodeBuiltinDefaultInterop(), cjsDefaultInterop()] : [],
|
|
332
350
|
...options.extraPlugins ?? [],
|
|
333
351
|
...metricsPlugins(group.id, "loose", hasCjs)
|
|
@@ -335,13 +353,17 @@ async function buildTargetGroups(options) {
|
|
|
335
353
|
}));
|
|
336
354
|
}
|
|
337
355
|
const groupOutDir = outDirFor(options.cwd, group.id);
|
|
338
|
-
|
|
339
|
-
|
|
356
|
+
if (licensesFound.size > 0) {
|
|
357
|
+
yield* fs.makeDirectory(groupOutDir, { recursive: true });
|
|
358
|
+
yield* fs.writeFileString(join(groupOutDir, THIRD_PARTY_LICENSES), renderThirdPartyLicenses(group.name, [...licensesFound.values()]));
|
|
359
|
+
}
|
|
360
|
+
yield* copyPublicDir(publicDir, groupOutDir);
|
|
361
|
+
if (ambient.length > 0) yield* copyAmbientDts({
|
|
340
362
|
ambient,
|
|
341
363
|
srcCwd: options.cwd,
|
|
342
364
|
outDir: groupOutDir
|
|
343
365
|
});
|
|
344
366
|
}
|
|
345
|
-
}
|
|
367
|
+
});
|
|
346
368
|
|
|
347
369
|
export { buildTargetGroups };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Result } from "effect";
|
|
2
|
+
import { GlobPattern } from "@effected/glob";
|
|
3
|
+
|
|
4
|
+
// src/passes/bundled-deps.ts
|
|
5
|
+
/** A bare package name, `name` or `@scope/name`, with no subpath and no glob syntax. */
|
|
6
|
+
const PACKAGE_NAME = /^(?:@[^/*?{}[\]!]+\/)?[^/@*?{}[\]!][^/*?{}[\]!]*$/;
|
|
7
|
+
/** Any character that makes an entry a glob rather than a literal specifier. */
|
|
8
|
+
const GLOB_SYNTAX = /[*?{}[\]!]/;
|
|
9
|
+
/**
|
|
10
|
+
* The patterns tsdown's `deps.alwaysBundle` is given for a `bundle` list.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* tsdown matches an import specifier against each entry exactly or as a glob, so `effect` alone would inline
|
|
14
|
+
* `import "effect"` and leave `import "effect/Schema"` external. A bare package name here means the package: it is
|
|
15
|
+
* widened to the name and every subpath under it. A glob is widened the same way, since its `*` stops at `/` and
|
|
16
|
+
* `@effected/*` would otherwise leave `import "@effected/cli/main"` external while {@link bundlesPackage} prunes
|
|
17
|
+
* `@effected/cli`; one already ending `/**`, or a negation, is passed as written. A subpath entry is passed as written.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
const bundlePatterns = (entries) => entries.flatMap((entry) => PACKAGE_NAME.test(entry) || GLOB_SYNTAX.test(entry) && !entry.startsWith("!") && !entry.endsWith("/**") ? [entry, `${entry}/**`] : [entry]);
|
|
22
|
+
/**
|
|
23
|
+
* Whether a `bundle` list inlines the package `name` as a whole: an entry naming it, or a glob matching it.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
const bundlesPackage = (name, entries) => entries.some((entry) => {
|
|
28
|
+
if (entry === name) return true;
|
|
29
|
+
if (PACKAGE_NAME.test(entry)) return false;
|
|
30
|
+
const compiled = GlobPattern.compileResult(entry);
|
|
31
|
+
return Result.isSuccess(compiled) && compiled.success.matches(name);
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Whether every partition of a build inlines the package `name`: the base `bundle` list and each override's.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* An override with no `bundle` of its own bundles nothing by force, so a package it imports stays a dependency.
|
|
38
|
+
* Only a package inlined everywhere can leave the emitted manifest.
|
|
39
|
+
*
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
const bundledEverywhere = (base, overrides) => (name) => bundlesPackage(name, base ?? []) && overrides.every((override) => override.bundle !== void 0 && bundlesPackage(name, override.bundle));
|
|
43
|
+
/**
|
|
44
|
+
* Removes from `dependencies` and `optionalDependencies` every package the build inlined, so an install never fetches
|
|
45
|
+
* what the published files already hold. `peerDependencies` are kept: a peer of an inlined package is the author's
|
|
46
|
+
* statement that the host provides it, such as the types a declaration file still imports.
|
|
47
|
+
*
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
const pruneBundled = (pkg, isBundled) => {
|
|
51
|
+
const out = { ...pkg };
|
|
52
|
+
for (const field of ["dependencies", "optionalDependencies"]) {
|
|
53
|
+
const deps = out[field];
|
|
54
|
+
if (typeof deps !== "object" || deps === null) continue;
|
|
55
|
+
const kept = Object.fromEntries(Object.entries(deps).filter(([name]) => !isBundled(name)));
|
|
56
|
+
if (Object.keys(kept).length === 0) delete out[field];
|
|
57
|
+
else out[field] = kept;
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { bundlePatterns, bundledEverywhere, bundlesPackage, pruneBundled };
|