@ref0/workspace 0.4.0 → 0.6.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/README.md +9 -7
- package/dist/bin.mjs +2 -1
- package/dist/docs-budget.mjs +77 -18
- package/dist/package-exports.mjs +89 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,8 +57,9 @@ entry point's source:
|
|
|
57
57
|
|
|
58
58
|
- `docs-budget`: the docs agents load, each within its budget: every skill's description, the
|
|
59
59
|
repo's own `SKILL.md`s, `AGENTS.md`s, the root's `RULES.md`, and `GLOSSARY.md`. It reads the
|
|
60
|
-
Markdown Git tracks.
|
|
61
|
-
|
|
60
|
+
Markdown Git tracks. A `SKILL.md` fails past 6 KB and warns past 5 KB, each naming its largest
|
|
61
|
+
sections to move to `references/`. Upstream copies are the skills the root's `skills-lock.json`
|
|
62
|
+
names, and each skill with an `.agents/skills/<name>-UPSTREAM.md`.
|
|
62
63
|
- `symbols find <words...>` and `symbols check <base> [<head>]` or `symbols check --all`: what the
|
|
63
64
|
repo already has, and a change that copies it, as [Symbols](#symbols) says.
|
|
64
65
|
- `types`: the types of every project the root `tsconfig.json` reaches, and Effect's rules, with
|
|
@@ -70,7 +71,8 @@ entry point's source:
|
|
|
70
71
|
- `package-exports [--packages <glob>]... [--condition <name>]`: each package's `exports` names
|
|
71
72
|
files it tracks or its `vite.config.ts`'s `pack` builds, and each entry point that builds gives
|
|
72
73
|
its source under the condition first. `--packages` is `packages/*` and `--condition`
|
|
73
|
-
`@ref0/source` unless given.
|
|
74
|
+
`@ref0/source` unless given. The `package-exports` skill reviews the rest: what each runtime
|
|
75
|
+
resolves, side effects and each entry point's bundle.
|
|
74
76
|
|
|
75
77
|
`types` and `type-coverage` run the repo's own `@effect/tsgo`, `tsrs` and `typescript`, its
|
|
76
78
|
optional peers, resolved from its root, at the versions its catalog pins.
|
|
@@ -162,9 +164,9 @@ done
|
|
|
162
164
|
|
|
163
165
|
## Releasing
|
|
164
166
|
|
|
165
|
-
From [ref-0/home](https://github.com/ref-0/home)
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
publishes it.
|
|
167
|
+
From [ref-0/home](https://github.com/ref-0/home)'s release pull request, "Release: <next>", which
|
|
168
|
+
`release.yml` keeps open once a change to what this package publishes passes CI. It raises the next
|
|
169
|
+
minor, or the next patch while it has the `release:patch` label. Merging it, which only the user
|
|
170
|
+
does, tags the merge `workspace-v<version>` and publishes it, once CI passes the merge.
|
|
169
171
|
|
|
170
172
|
Apache-2.0, but for the copied plugins, which keep their MIT licences.
|
package/dist/bin.mjs
CHANGED
|
@@ -54,7 +54,8 @@ const plain = (about, run) => ({
|
|
|
54
54
|
});
|
|
55
55
|
const checks = /* @__PURE__ */ new Map([
|
|
56
56
|
["docs-budget", plain("the docs agents load, each within its budget", (at) => {
|
|
57
|
-
const { docs, problems } = docsBudget(at);
|
|
57
|
+
const { docs, problems, warnings } = docsBudget(at);
|
|
58
|
+
for (const line of warnings) console.error(`warning: ${line}`);
|
|
58
59
|
for (const line of problems) console.error(line);
|
|
59
60
|
if (problems.length > 0) return 1;
|
|
60
61
|
console.error(`docs-budget: ${docs.length} Markdown files within budget`);
|
package/dist/docs-budget.mjs
CHANGED
|
@@ -16,24 +16,70 @@ import { join } from "node:path";
|
|
|
16
16
|
*
|
|
17
17
|
* - Every skill's description, upstream copies too: at most 320 characters. An upkeep run that
|
|
18
18
|
* updates a copy can bring its source's longer description back, and fails here until it's cut.
|
|
19
|
-
* - The repo's own `SKILL.md`: at most
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* - The repo's own `SKILL.md`: at most 6 KB, with a warning past 5 KB, so each change has room to
|
|
20
|
+
* move a section to `references/` instead of trimming words to fit. Both name the largest
|
|
21
|
+
* sections. Upstream copies, those the root's `skills-lock.json` names, Cloudflare's `cf-*` and
|
|
22
|
+
* any skill with a `<name>-UPSTREAM.md` beside its folder, are left as their source wrote them.
|
|
22
23
|
* - Root `AGENTS.md`: at most 12 KB. Any other `AGENTS.md`: at most 8 KB. Root `RULES.md`, the rules
|
|
23
24
|
* every repo's `AGENTS.md` imports, so they load beside each one: at most 8 KB.
|
|
24
25
|
* - `GLOSSARY.md`: no tables, since `vp fmt` pads each cell to its column's widest, and no entry
|
|
25
26
|
* over 400 characters.
|
|
26
|
-
* - None of these keeps history, such as "Changed 15 Oct 2026": `git log`
|
|
27
|
+
* - None of these keeps history, such as "Changed 15 Oct 2026" or "ruled out on 19 Nov 2026": `git log`
|
|
28
|
+
* holds it. A full date outside code counts.
|
|
27
29
|
*/
|
|
30
|
+
const bytes = (text) => Buffer.byteLength(text, "utf8");
|
|
31
|
+
const kb = (size) => `${(size / 1e3).toFixed(1)} KB`;
|
|
28
32
|
const budgets = {
|
|
29
33
|
description: 320,
|
|
30
|
-
skill:
|
|
34
|
+
skill: 6e3,
|
|
35
|
+
skillWarning: 5e3,
|
|
31
36
|
rootAgents: 12e3,
|
|
32
37
|
agents: 8e3,
|
|
33
38
|
rules: 8e3,
|
|
34
39
|
glossaryEntry: 400
|
|
35
40
|
};
|
|
36
|
-
const history = /\b
|
|
41
|
+
const history = /\b\d{1,2} (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z]* \d{4}\b/;
|
|
42
|
+
/** `text` without fenced blocks or inline code, where a date is an example, not history. */
|
|
43
|
+
const prose = (text) => text.replace(/^(```|~~~)[^\n]*\n[\s\S]*?^\1[^\n]*$/gm, "").replace(/`[^`\n]*`/g, "");
|
|
44
|
+
/**
|
|
45
|
+
* The `## ` sections of a Markdown doc, largest first, each with its heading and its size in bytes,
|
|
46
|
+
* subsections included. Headings inside fenced blocks don't count.
|
|
47
|
+
*/
|
|
48
|
+
const sections = (text) => {
|
|
49
|
+
const found = [];
|
|
50
|
+
let fence;
|
|
51
|
+
for (const line of text.split("\n")) {
|
|
52
|
+
const marker = /^(```|~~~)/.exec(line)?.[1];
|
|
53
|
+
if (marker !== void 0) fence = fence === void 0 ? marker : fence === marker ? void 0 : fence;
|
|
54
|
+
if (fence === void 0 && line.startsWith("## ")) found.push({
|
|
55
|
+
heading: line.slice(3),
|
|
56
|
+
size: 0
|
|
57
|
+
});
|
|
58
|
+
const last = found.at(-1);
|
|
59
|
+
if (last !== void 0) last.size += bytes(line) + 1;
|
|
60
|
+
}
|
|
61
|
+
return found.toSorted((a, b) => b.size - a.size);
|
|
62
|
+
};
|
|
63
|
+
/** The largest sections of `text`, for a message: at most three, each with its size. */
|
|
64
|
+
const largest = (text) => sections(text).slice(0, 3).map(({ heading, size }) => `"${heading}" ${kb(size)}`).join(", ");
|
|
65
|
+
/** A reference's file name for a section: its heading's first words in kebab case, no step number. */
|
|
66
|
+
const referenceName = (heading) => {
|
|
67
|
+
return `${heading.replace(/^\d+\.\s*/, "").toLowerCase().split(/[^a-z0-9]+/).filter((word) => word !== "").slice(0, 4).join("-") || "detail"}.md`;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* What to do about a `SKILL.md` at `path` past a line: move a section only one step or case needs,
|
|
71
|
+
* word for word, to a reference beside it, and leave a pointer. Never trim words.
|
|
72
|
+
*/
|
|
73
|
+
const move = (path, text) => {
|
|
74
|
+
const [first] = sections(text);
|
|
75
|
+
const references = `${path.slice(0, -8)}references/`;
|
|
76
|
+
const named = first === void 0 ? "" : ` (for "${first.heading}", ${referenceName(first.heading)})`;
|
|
77
|
+
return [
|
|
78
|
+
`Largest sections: ${largest(text) || "none"}.`,
|
|
79
|
+
`Move a section only one step or case needs, word for word, to ${references}<topic>.md${named} or an existing reference on its topic, and leave one line in its place: "When <condition>, read [<topic>](references/<file>.md)."`,
|
|
80
|
+
"Don't reword to fit. The create-skill skill's references/thinning.md says how."
|
|
81
|
+
].join(" ");
|
|
82
|
+
};
|
|
37
83
|
/**
|
|
38
84
|
* A `SKILL.md`'s frontmatter description, as one line: plain, quoted, or a folded `>-` block.
|
|
39
85
|
* `undefined` when it has none.
|
|
@@ -48,8 +94,6 @@ const description = (text) => {
|
|
|
48
94
|
const folded = (end === -1 ? rest : rest.slice(0, end)).map((line) => line.trim());
|
|
49
95
|
return (/^[>|]-?$/.test(first) ? folded.join(" ") : first).replace(/^(["'])([\s\S]*)\1$/, "$2");
|
|
50
96
|
};
|
|
51
|
-
const bytes = (text) => Buffer.byteLength(text, "utf8");
|
|
52
|
-
const kb = (size) => `${(size / 1e3).toFixed(1)} KB`;
|
|
53
97
|
/** What the docs break, one line each, with what to do about it. */
|
|
54
98
|
const problems = (docs, upstream) => {
|
|
55
99
|
const found = [];
|
|
@@ -60,12 +104,12 @@ const problems = (docs, upstream) => {
|
|
|
60
104
|
const glossary = path === "GLOSSARY.md";
|
|
61
105
|
if (skill === void 0 && !agents && !rules && !glossary) continue;
|
|
62
106
|
const ours = skill === void 0 || !(upstream.has(skill) || skill.startsWith("cf-"));
|
|
63
|
-
const said = history.exec(text)?.[0];
|
|
107
|
+
const said = history.exec(prose(text))?.[0];
|
|
64
108
|
if (ours && said !== void 0) found.push(`${path}: "${said}" is history; leave it to git log and say what holds now.`);
|
|
65
109
|
if (skill !== void 0) {
|
|
66
110
|
const about = description(text) ?? "";
|
|
67
111
|
if (about.length > budgets.description) found.push(`${path}: its description is ${about.length} characters, over ${budgets.description}. Say what it does, when to use it and which sibling to use instead; cut the method.`);
|
|
68
|
-
if (ours && bytes(text) > budgets.skill) found.push(`${path}: ${kb(bytes(text))}, over ${kb(budgets.skill)}.
|
|
112
|
+
if (ours && bytes(text) > budgets.skill) found.push(`${path}: ${kb(bytes(text))}, over ${kb(budgets.skill)}. ${move(path, text)}`);
|
|
69
113
|
}
|
|
70
114
|
if (agents || rules) {
|
|
71
115
|
const limit = rules ? budgets.rules : path === "AGENTS.md" ? budgets.rootAgents : budgets.agents;
|
|
@@ -84,14 +128,27 @@ const problems = (docs, upstream) => {
|
|
|
84
128
|
return found;
|
|
85
129
|
};
|
|
86
130
|
/**
|
|
87
|
-
* The
|
|
88
|
-
*
|
|
131
|
+
* The repo's own `SKILL.md`s past the warning line but within budget, one line each: they pass,
|
|
132
|
+
* and the next addition should move a section out.
|
|
133
|
+
*/
|
|
134
|
+
const warnings = (docs, upstream) => docs.flatMap(({ path, text }) => {
|
|
135
|
+
const skill = /^\.agents\/skills\/([^/]+)\/SKILL\.md$/.exec(path)?.[1];
|
|
136
|
+
if (skill === void 0 || upstream.has(skill) || skill.startsWith("cf-")) return [];
|
|
137
|
+
const size = bytes(text);
|
|
138
|
+
if (size <= budgets.skillWarning || size > budgets.skill) return [];
|
|
139
|
+
return [`${path}: ${kb(size)}, past the ${kb(budgets.skillWarning)} warning line. ${move(path, text)}`];
|
|
140
|
+
});
|
|
141
|
+
/**
|
|
142
|
+
* The upstream copies, by folder name: the skills the skills CLI installed, from the lock at
|
|
143
|
+
* `root`, and each skill with a tracked `.agents/skills/<name>-UPSTREAM.md`, its provenance, among
|
|
144
|
+
* `docs`.
|
|
89
145
|
*/
|
|
90
|
-
const upstreamSkills = (root) => {
|
|
146
|
+
const upstreamSkills = (root, docs = []) => {
|
|
147
|
+
const copied = docs.flatMap(({ path }) => /^\.agents\/skills\/([^/]+)-UPSTREAM\.md$/.exec(path)?.[1] ?? []).filter((name) => docs.some(({ path }) => path === `.agents/skills/${name}/SKILL.md`));
|
|
91
148
|
const path = join(root, "skills-lock.json");
|
|
92
|
-
if (!existsSync(path)) return
|
|
149
|
+
if (!existsSync(path)) return new Set(copied);
|
|
93
150
|
const lock = JSON.parse(readFileSync(path, "utf8"));
|
|
94
|
-
return new Set(Object.keys(lock.skills));
|
|
151
|
+
return /* @__PURE__ */ new Set([...Object.keys(lock.skills), ...copied]);
|
|
95
152
|
};
|
|
96
153
|
/** The Markdown the checkout at `root` tracks, each by its path from the root, with its text. */
|
|
97
154
|
const trackedDocs = (root) => execFileSync("git", [
|
|
@@ -106,17 +163,19 @@ const trackedDocs = (root) => execFileSync("git", [
|
|
|
106
163
|
path,
|
|
107
164
|
text: readFileSync(join(root, path), "utf8")
|
|
108
165
|
}));
|
|
109
|
-
/** The checkout `from` is in: its root, its tracked docs, and what
|
|
166
|
+
/** The checkout `from` is in: its root, its tracked docs, what they break and what nears a line. */
|
|
110
167
|
const docsBudget = (from) => {
|
|
111
168
|
const root = execFileSync("git", ["rev-parse", "--show-toplevel"], {
|
|
112
169
|
cwd: from,
|
|
113
170
|
encoding: "utf8"
|
|
114
171
|
}).trim();
|
|
115
172
|
const docs = trackedDocs(root);
|
|
173
|
+
const upstream = upstreamSkills(root, docs);
|
|
116
174
|
return {
|
|
117
175
|
root,
|
|
118
176
|
docs,
|
|
119
|
-
problems: problems(docs,
|
|
177
|
+
problems: problems(docs, upstream),
|
|
178
|
+
warnings: warnings(docs, upstream)
|
|
120
179
|
};
|
|
121
180
|
};
|
|
122
|
-
export { budgets, description, docsBudget, problems, trackedDocs, upstreamSkills };
|
|
181
|
+
export { budgets, description, docsBudget, problems, sections, trackedDocs, upstreamSkills, warnings };
|
package/dist/package-exports.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { execFileSync } from "node:child_process";
|
|
|
2
2
|
import { existsSync, globSync, readFileSync } from "node:fs";
|
|
3
3
|
import { join, posix } from "node:path";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
|
-
import { Schema } from "effect";
|
|
5
|
+
import { Predicate, Schema } from "effect";
|
|
6
6
|
// src/package-exports.ts
|
|
7
7
|
/**
|
|
8
8
|
* Fails when a workspace package's `exports` names a file nothing has or builds, or a generated
|
|
@@ -16,14 +16,19 @@ import { Schema } from "effect";
|
|
|
16
16
|
*
|
|
17
17
|
* - It has an `exports` field, so no other package reaches a file it doesn't list. One nothing
|
|
18
18
|
* imports, such as a CLI's, is empty.
|
|
19
|
-
* - Each target, condition by condition, names a tracked file, or a
|
|
20
|
-
* entries builds
|
|
21
|
-
* target matches at least one
|
|
19
|
+
* - Each target, condition by condition, names a tracked file, or a built file one of its pack
|
|
20
|
+
* entries builds (`<outDir>/<entry>.mjs`, and `<outDir>/<entry>.d.mts` when it packs types) or
|
|
21
|
+
* its `pack.copy` copies there from tracked source files. A `*` target matches at least one
|
|
22
|
+
* tracked file.
|
|
22
23
|
* - No target names a `*.gen.ts` file, which a tool writes and git ignores.
|
|
23
|
-
* - A package that packs builds each entry point that has a `types` condition from a pack entry
|
|
24
|
+
* - A package that packs builds each entry point that has a `types` condition from a pack entry or
|
|
25
|
+
* `pack.copy`, except a tracked `.d.ts`/`.d.mts`/`.d.cts` declaration file in workspace `exports`
|
|
26
|
+
* when `publishConfig.exports` supplies the published map.
|
|
24
27
|
* - Each entry point in `exports` with a `types` or `import` target gives its source, a tracked
|
|
25
28
|
* file, under the source condition first, `--condition`, `@ref0/source` unless it's given, so
|
|
26
|
-
* the workspace reads source and only the published package reads what's built.
|
|
29
|
+
* the workspace reads source and only the published package reads what's built. When
|
|
30
|
+
* `publishConfig.exports` supplies the published map, a workspace `exports` entry whose `types`
|
|
31
|
+
* and `import` targets are already tracked source files needs no source condition ahead of them.
|
|
27
32
|
* `publishConfig.exports`, what the published package exports, has none.
|
|
28
33
|
*
|
|
29
34
|
* Under 1 s.
|
|
@@ -36,10 +41,25 @@ const Manifest = Schema.Struct({
|
|
|
36
41
|
exports: Schema.optionalKey(Exports),
|
|
37
42
|
publishConfig: Schema.optionalKey(Schema.Struct({ exports: Schema.optionalKey(Exports) }))
|
|
38
43
|
});
|
|
39
|
-
|
|
44
|
+
const DynamicFn = Schema.declare((value) => Predicate.isFunction(value));
|
|
45
|
+
/** One static asset copy entry in `vp pack`'s `copy` list. */
|
|
46
|
+
const CopyObject = Schema.Struct({
|
|
47
|
+
from: Schema.Union([Schema.String, Schema.Array(Schema.String)]),
|
|
48
|
+
to: Schema.optionalKey(Schema.String),
|
|
49
|
+
flatten: Schema.optionalKey(Schema.Boolean),
|
|
50
|
+
rename: Schema.optionalKey(Schema.Union([Schema.String, DynamicFn]))
|
|
51
|
+
});
|
|
52
|
+
const CopyItem = Schema.Union([Schema.String, CopyObject]);
|
|
53
|
+
/** What the check reads of one `vp pack` build: its entries, output dir, types, and copied files. */
|
|
40
54
|
const PackBuild = Schema.Struct({
|
|
41
55
|
entry: Schema.Union([Schema.Array(Schema.String), Schema.Record(Schema.String, Schema.String)]),
|
|
42
|
-
|
|
56
|
+
outDir: Schema.optionalKey(Schema.String),
|
|
57
|
+
dts: Schema.optionalKey(Schema.Union([Schema.Boolean, Schema.Struct({})])),
|
|
58
|
+
copy: Schema.optionalKey(Schema.Union([
|
|
59
|
+
CopyItem,
|
|
60
|
+
Schema.Array(CopyItem),
|
|
61
|
+
DynamicFn
|
|
62
|
+
]))
|
|
43
63
|
});
|
|
44
64
|
/** A `vite.config.ts` module, as far as its `pack`. */
|
|
45
65
|
const ConfigModule = Schema.Struct({ default: Schema.Struct({ pack: Schema.optionalKey(Schema.Union([PackBuild, Schema.Array(PackBuild)])) }) });
|
|
@@ -48,6 +68,8 @@ const decodeConfigModule = Schema.decodeUnknownSync(ConfigModule);
|
|
|
48
68
|
const isPaths = Schema.is(Schema.Array(Schema.String));
|
|
49
69
|
const isBuilds = Schema.is(Schema.Array(PackBuild));
|
|
50
70
|
const isPath = Schema.is(Schema.String);
|
|
71
|
+
const isCopyItems = Schema.is(Schema.Array(CopyItem));
|
|
72
|
+
const declarationFile = /\.d\.[cm]?ts$/;
|
|
51
73
|
/** The folder every path in `paths` is in, as `vp pack` names entries below it. */
|
|
52
74
|
const commonFolder = (paths) => {
|
|
53
75
|
const [first = [], ...rest] = paths.map((path) => posix.dirname(path).split("/"));
|
|
@@ -61,8 +83,44 @@ const entryNames = ({ entry }) => {
|
|
|
61
83
|
const folder = commonFolder(entry);
|
|
62
84
|
return entry.map((path) => posix.relative(folder, path).replace(/\.[cm]?[jt]sx?$/, ""));
|
|
63
85
|
};
|
|
64
|
-
/**
|
|
65
|
-
const
|
|
86
|
+
/** Converts a simple glob (`*`, `**`, `?`) into a RegExp over POSIX paths. */
|
|
87
|
+
const globToRegExp = (pattern) => {
|
|
88
|
+
const escaped = pattern.replaceAll(/[.+^${}()|[\]\\]/g, "\\$&").replaceAll("**/", "(?:.+/)?").replaceAll("**", ".*").replaceAll("*", "[^/]*").replaceAll("?", "[^/]");
|
|
89
|
+
return new RegExp(`^${escaped}$`);
|
|
90
|
+
};
|
|
91
|
+
/** Resolves `from` (explicit path or glob) against `context.tracked` when context is given. */
|
|
92
|
+
const resolvedCopySources = (source, context) => {
|
|
93
|
+
const normalized = posix.normalize(source);
|
|
94
|
+
const isGlob = /[*?[\]{}]/.test(normalized);
|
|
95
|
+
if (context === void 0) return isGlob ? [] : [normalized];
|
|
96
|
+
if (!isGlob) {
|
|
97
|
+
const repoPath = posix.join(context.directory, normalized);
|
|
98
|
+
return context.tracked.has(repoPath) ? [normalized] : [];
|
|
99
|
+
}
|
|
100
|
+
const pattern = globToRegExp(posix.join(context.directory, normalized));
|
|
101
|
+
return [...context.tracked].flatMap((file) => pattern.test(file) ? [posix.relative(context.directory, file)] : []);
|
|
102
|
+
};
|
|
103
|
+
/** Each file one `pack.copy` entry writes into `outDir`, matching tsdown's `resolveCopyEntry`. */
|
|
104
|
+
const copiedByItem = (item, outDir, context) => {
|
|
105
|
+
const froms = isPath(item) ? [item] : isPaths(item.from) ? item.from : [item.from];
|
|
106
|
+
const to = isPath(item) ? outDir : posix.normalize(item.to ?? outDir);
|
|
107
|
+
const flatten = isPath(item) ? true : item.flatten ?? true;
|
|
108
|
+
const rename = isPath(item) ? void 0 : item.rename;
|
|
109
|
+
if (rename !== void 0 && !isPath(rename)) return [];
|
|
110
|
+
return froms.flatMap((source) => resolvedCopySources(source, context).map((resolved) => {
|
|
111
|
+
const base = posix.basename(resolved);
|
|
112
|
+
const dir = posix.dirname(resolved);
|
|
113
|
+
const destFolder = flatten || dir === "." ? to : posix.join(to, ...dir.split("/").slice(1));
|
|
114
|
+
return posix.join(destFolder, rename ?? base);
|
|
115
|
+
}));
|
|
116
|
+
};
|
|
117
|
+
/** The output files a package's pack builds or copies, by path from the package's folder. */
|
|
118
|
+
const builtFiles = (pack, context) => new Set(pack.flatMap((build) => {
|
|
119
|
+
const outDir = posix.normalize(build.outDir ?? "dist");
|
|
120
|
+
const entries = entryNames(build).flatMap((name) => build.dts === void 0 || build.dts === false ? [posix.join(outDir, `${name}.mjs`)] : [posix.join(outDir, `${name}.mjs`), posix.join(outDir, `${name}.d.mts`)]);
|
|
121
|
+
const copies = build.copy === void 0 || Predicate.isFunction(build.copy) ? [] : (isCopyItems(build.copy) ? build.copy : [build.copy]).flatMap((item) => copiedByItem(item, outDir, context));
|
|
122
|
+
return [...entries, ...copies];
|
|
123
|
+
}));
|
|
66
124
|
/** Each `[condition, path]` of a target; a plain path has no condition. */
|
|
67
125
|
const paths = (target) => isPath(target) ? [[void 0, target]] : Object.entries(target);
|
|
68
126
|
/** Whether `pattern`, a target with at most one `*`, matches any of `files`. */
|
|
@@ -81,8 +139,17 @@ const problems = (packages, tracked, condition = defaultCondition) => {
|
|
|
81
139
|
const found = [];
|
|
82
140
|
for (const { directory, manifest, pack } of packages) {
|
|
83
141
|
const at = `${directory}/package.json`;
|
|
84
|
-
const built = new Set([...builtFiles(pack
|
|
142
|
+
const built = new Set([...builtFiles(pack, {
|
|
143
|
+
directory,
|
|
144
|
+
tracked
|
|
145
|
+
})].map((path) => posix.join(directory, path)));
|
|
146
|
+
const outDirs = new Set(pack.length === 0 ? ["dist"] : pack.map((build) => posix.normalize(build.outDir ?? "dist")));
|
|
147
|
+
const isOutputPath = (targetPath) => {
|
|
148
|
+
const normalized = posix.normalize(targetPath);
|
|
149
|
+
return [...outDirs].some((dir) => normalized === dir || normalized.startsWith(`${dir}/`));
|
|
150
|
+
};
|
|
85
151
|
const files = /* @__PURE__ */ new Set([...tracked, ...built]);
|
|
152
|
+
const hasPublishExports = manifest.publishConfig?.exports !== void 0;
|
|
86
153
|
if (manifest.exports === void 0) {
|
|
87
154
|
found.push(`${at}: has no exports, so any of its files can be imported. List its entry points, or write "exports": {} if nothing imports it.`);
|
|
88
155
|
continue;
|
|
@@ -102,13 +169,19 @@ const problems = (packages, tracked, condition = defaultCondition) => {
|
|
|
102
169
|
continue;
|
|
103
170
|
}
|
|
104
171
|
if (matches(file, files)) continue;
|
|
105
|
-
found.push(path
|
|
172
|
+
found.push(isOutputPath(path) ? `${at}: ${where} names ${path}, which no pack entry builds. Add its entry to pack in vite.config.ts, or point it at a file that's there.` : `${at}: ${where} names ${path}, which isn't tracked. Point it at a file that's there.`);
|
|
106
173
|
}
|
|
107
174
|
const types = isPath(target) ? void 0 : target["types"];
|
|
108
|
-
const packed = isPath(target) ? [] : ["types", "import"].filter((key) =>
|
|
175
|
+
const packed = isPath(target) ? [] : ["types", "import"].filter((key) => {
|
|
176
|
+
const targetPath = target[key];
|
|
177
|
+
if (targetPath === void 0) return false;
|
|
178
|
+
if (!hasPublishExports) return true;
|
|
179
|
+
return isOutputPath(targetPath) || built.has(posix.join(directory, targetPath));
|
|
180
|
+
});
|
|
109
181
|
const first = isPath(target) ? void 0 : Object.keys(target)[0];
|
|
110
182
|
if (field === "exports" && packed.length > 0 && first !== condition) found.push(`${at}: ${name} has ${packed.join(" and ")} but not its source under "${condition}" first. Add "${condition}": its source file, ahead of ${packed.join(" and ")}.`);
|
|
111
|
-
|
|
183
|
+
const workspaceDeclaration = field === "exports" && hasPublishExports && types !== void 0 && declarationFile.test(types) && tracked.has(posix.join(directory, types));
|
|
184
|
+
if (pack.length > 0 && types !== void 0 && !built.has(posix.join(directory, types)) && !workspaceDeclaration) found.push(`${at}: ${name} has types at ${types}, which no pack entry builds. Add "${entry}"'s source to pack's entry in vite.config.ts.`);
|
|
112
185
|
}
|
|
113
186
|
}
|
|
114
187
|
return found;
|
|
@@ -138,12 +211,7 @@ const packageExports = async (root, { packages, condition }) => {
|
|
|
138
211
|
console.error(`package-exports: no package.json in ${packages.join(" or ")}. Name the packages' folders with --packages.`);
|
|
139
212
|
return 1;
|
|
140
213
|
}
|
|
141
|
-
const tracked = new Set(execFileSync("git", [
|
|
142
|
-
"ls-files",
|
|
143
|
-
"-z",
|
|
144
|
-
"--",
|
|
145
|
-
...folders
|
|
146
|
-
], {
|
|
214
|
+
const tracked = new Set(execFileSync("git", ["ls-files", "-z"], {
|
|
147
215
|
cwd: root,
|
|
148
216
|
encoding: "utf8",
|
|
149
217
|
maxBuffer: 67108864
|
|
@@ -154,4 +222,4 @@ const packageExports = async (root, { packages, condition }) => {
|
|
|
154
222
|
console.error(`package-exports: the exports of ${folders.length} packages hold`);
|
|
155
223
|
return 0;
|
|
156
224
|
};
|
|
157
|
-
export { builtFiles, defaultCondition, packageExports, packageFolders, problems };
|
|
225
|
+
export { builtFiles, defaultCondition, packageExports, packageFolders, problems, readPackages };
|