@r_masseater/msch 0.32.0 → 0.35.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,581 +1,597 @@
1
- import { n as RepositoryFiles, t as NODE_MODULES } from "./repository-files-D_lFq7Bj.mjs";
1
+ import { n as RepositoryFiles, t as NODE_MODULES } from "./repository-files-R0NW0NE9.mjs";
2
2
  import { Array, Effect, Match, Option, Order, Predicate, Record, Schema, String as String$1, pipe } from "effect";
3
3
  import { parse, resolveConfigFromFile } from "vite-plus";
4
4
  import { readWorkspaceManifest } from "@pnpm/workspace.workspace-manifest-reader";
5
5
  import { findWorkspaceProjectsNoCheck } from "@pnpm/workspace.projects-reader";
6
- // src/entities/package/model/dependencies.ts
7
- const DependencyMap = Schema.optional(Schema.Record(Schema.String, Schema.String));
8
- const PackageManifest = Schema.Struct({
9
- name: Schema.optional(Schema.String),
10
- dependencies: DependencyMap,
11
- devDependencies: DependencyMap,
12
- peerDependencies: DependencyMap,
13
- exports: Schema.optional(Schema.Unknown),
14
- types: Schema.optional(Schema.String),
15
- typings: Schema.optional(Schema.String),
16
- main: Schema.optional(Schema.String)
6
+ import { readWantedLockfile } from "@pnpm/lockfile.fs";
7
+ // src/entities/workspace/model/config-literal.ts
8
+ const WRAPPERS = [
9
+ "TSAsExpression",
10
+ "TSSatisfiesExpression",
11
+ "ParenthesizedExpression"
12
+ ];
13
+ const KeySchema = Schema.Union([Schema.Struct({
14
+ type: Schema.Literal("Identifier"),
15
+ name: Schema.String
16
+ }), Schema.Struct({
17
+ type: Schema.Literal("Literal"),
18
+ value: Schema.String
19
+ })]);
20
+ const Quasi = Schema.Struct({ value: Schema.Struct({ cooked: Schema.String }) });
21
+ const PropertyNode = Schema.Struct({
22
+ type: Schema.Literal("Property"),
23
+ computed: Schema.Literal(false),
24
+ key: KeySchema,
25
+ value: Schema.Unknown
17
26
  });
18
- const MANIFEST_FILE = "package.json";
19
- const WORKSPACE_PROTOCOL = "workspace:";
20
- const ROOT_SUBPATH$1 = ".";
21
- const SUBPATH_PREFIX = "./";
22
- const WILDCARD = "*";
23
- const TYPES_CONDITION = "types";
24
- const TYPES_SCOPE = "@types/";
25
- const TYPES_SCOPE_SEPARATOR = "__";
26
- const CONDITION_DEPTH_LIMIT = 8;
27
- const ROOT_DEPTH = 0;
28
- const DEPTH_STEP = 1;
29
- const DECLARATIONS_SUFFIX = /\.d\.[cm]?ts$|\.[cm]?tsx?$/u;
30
- const SCRIPT_SUFFIX = /\.(?<module>[cm]?)js$/u;
31
- const readManifest = Effect.fn("readManifest")(function* readManifest(directory) {
32
- const files = yield* RepositoryFiles;
33
- const manifestText = yield* files.readFile(files.join(directory, MANIFEST_FILE));
34
- const text = yield* Effect.fromOption(manifestText);
35
- return yield* Schema.decodeEffect(Schema.fromJsonString(PackageManifest))(text);
36
- }, Effect.option);
37
- const conditionsOf = (held) => {
38
- if (!Predicate.isObject(held)) return [];
39
- return Record.toEntries(held);
40
- };
41
- const typesConditionIn = (held, depth) => {
42
- if (depth > CONDITION_DEPTH_LIMIT) return Option.none();
43
- const entries = conditionsOf(held);
44
- const declared = Array.findFirst(entries, ([condition, target]) => Option.liftPredicate(target, (candidate) => condition === TYPES_CONDITION && Predicate.isString(candidate))).pipe(Option.filter(Predicate.isString));
45
- return Option.orElse(declared, () => Array.findFirst(entries, ([, nested]) => typesConditionIn(nested, depth + DEPTH_STEP)));
46
- };
47
- const anyConditionIn = (held, depth) => {
48
- if (Predicate.isString(held)) return Option.some(held);
49
- if (depth > CONDITION_DEPTH_LIMIT) return Option.none();
50
- return Array.findFirst(conditionsOf(held), ([, nested]) => anyConditionIn(nested, depth + DEPTH_STEP));
51
- };
52
- const targetPathsOf = (target) => Array.getSomes([typesConditionIn(target, ROOT_DEPTH), anyConditionIn(target, ROOT_DEPTH)]);
53
- const subpathTargetsOf = (exportsField) => {
54
- if (Predicate.isString(exportsField)) return [{
55
- subpath: ROOT_SUBPATH$1,
56
- target: exportsField
57
- }];
58
- const entries = conditionsOf(exportsField);
59
- if (!pipe(entries, Array.some(([subpath]) => String$1.startsWith(ROOT_SUBPATH$1)(subpath)))) return Array.match(entries, {
60
- onEmpty: () => [],
61
- onNonEmpty: () => [{
62
- subpath: ROOT_SUBPATH$1,
63
- target: exportsField
64
- }]
65
- });
66
- return pipe(entries, Array.filter(([subpath]) => subpath === ROOT_SUBPATH$1 || String$1.startsWith(SUBPATH_PREFIX)(subpath)), Array.filter(([subpath]) => !String$1.includes(WILDCARD)(subpath)), Array.map(([subpath, target]) => ({
67
- subpath,
68
- target
69
- })));
70
- };
71
- const declarationsCandidateFor = (entryPath) => {
72
- if (DECLARATIONS_SUFFIX.test(entryPath)) return Option.some(entryPath);
73
- if (!SCRIPT_SUFFIX.test(entryPath)) return Option.none();
74
- return Option.some(String$1.replace(SCRIPT_SUFFIX, ".d.$<module>ts")(entryPath));
75
- };
76
- const firstDeclarationsAmong = Effect.fn("firstDeclarationsAmong")(function* firstDeclarations(directory, entryPaths) {
77
- const files = yield* RepositoryFiles;
78
- const candidates = Array.getSomes(pipe(entryPaths, Array.map((entryPath) => declarationsCandidateFor(entryPath))));
79
- const existing = yield* Effect.filter(pipe(candidates, Array.map((candidate) => files.join(directory, candidate))), (candidate) => files.exists(candidate));
80
- return yield* Option.match(Array.head(existing), {
81
- onNone: () => Effect.succeedNone,
82
- onSome: (candidate) => files.realPath(candidate).pipe(Effect.asSome)
83
- });
27
+ const WrappedNode = Schema.Struct({
28
+ type: Schema.Literals(WRAPPERS),
29
+ expression: Schema.Unknown
84
30
  });
85
- const importNameOf = (packageName) => {
86
- if (!String$1.startsWith(TYPES_SCOPE)(packageName)) return packageName;
87
- const unscoped = String$1.slice(7)(packageName);
88
- if (!String$1.includes(TYPES_SCOPE_SEPARATOR)(unscoped)) return unscoped;
89
- return `@${String$1.replace(TYPES_SCOPE_SEPARATOR, "/")(unscoped)}`;
90
- };
91
- const specifierFor = (packageName, subpath) => {
92
- const importName = importNameOf(packageName);
93
- if (subpath === ROOT_SUBPATH$1) return importName;
94
- return `${importName}/${String$1.slice(2)(subpath)}`;
95
- };
96
- const rootEntryPaths = (manifest) => Array.getSomes([
97
- Option.fromUndefinedOr(manifest.types),
98
- Option.fromUndefinedOr(manifest.typings),
99
- Option.fromUndefinedOr(manifest.main)
31
+ const ValueNode = Schema.Union([
32
+ Schema.Struct({
33
+ type: Schema.Literal("Literal"),
34
+ value: Schema.Union([
35
+ Schema.String,
36
+ Schema.Finite,
37
+ Schema.Boolean,
38
+ Schema.Null
39
+ ])
40
+ }),
41
+ Schema.Struct({
42
+ type: Schema.Literal("TemplateLiteral"),
43
+ expressions: Schema.Tuple([]),
44
+ quasis: Schema.Array(Quasi)
45
+ }),
46
+ Schema.Struct({
47
+ type: Schema.Literal("ArrayExpression"),
48
+ elements: Schema.Array(Schema.Unknown)
49
+ }),
50
+ Schema.Struct({
51
+ type: Schema.Literal("ObjectExpression"),
52
+ properties: Schema.Array(PropertyNode)
53
+ })
100
54
  ]);
101
- const subpathEntriesOf = Effect.fn("subpathEntriesOf")(function* subpathEntriesOf(packageName, directory, manifest) {
102
- const found = yield* Effect.forEach(subpathTargetsOf(manifest.exports), ({ subpath, target }) => firstDeclarationsAmong(directory, targetPathsOf(target)).pipe(Effect.map(Option.map((declarationsPath) => ({
103
- packageName,
104
- specifier: specifierFor(packageName, subpath),
105
- declarationsPath
106
- })))), { concurrency: 1 });
107
- return Array.getSomes(found);
108
- });
109
- const entriesOfDependency = Effect.fn("entriesOfDependency")(function* entriesOfDependency(packageName, directory) {
110
- const manifest = yield* readManifest(directory);
111
- if (Option.isNone(manifest)) return [];
112
- const subpathEntries = yield* subpathEntriesOf(packageName, directory, manifest.value);
113
- const rootSpecifier = specifierFor(packageName, ROOT_SUBPATH$1);
114
- if (pipe(subpathEntries, Array.some((entry) => entry.specifier === rootSpecifier))) return subpathEntries;
115
- return [...(yield* firstDeclarationsAmong(directory, rootEntryPaths(manifest.value))).pipe(Option.map((declarationsPath) => ({
116
- packageName,
117
- specifier: rootSpecifier,
118
- declarationsPath
119
- })), Option.toArray), ...subpathEntries];
120
- });
121
- const declaredDependencies = (manifest) => pipe(Record.toEntries({
122
- ...manifest.dependencies,
123
- ...manifest.devDependencies,
124
- ...manifest.peerDependencies
125
- }), Array.filter(([, range]) => !String$1.startsWith(WORKSPACE_PROTOCOL)(range)), Array.map(([packageName]) => packageName));
126
- const workspaceDependencies = (manifest) => pipe(Record.toEntries({
127
- ...manifest.dependencies,
128
- ...manifest.devDependencies
129
- }), Array.filter(([, range]) => String$1.startsWith(WORKSPACE_PROTOCOL)(range)), Array.map(([packageName]) => packageName));
130
- const entryOrder = Order.mapInput(Order.String, (entry) => entry.specifier);
131
- const dependencyEntries = Effect.fn("dependencyEntries")(function* dependencyEntries(packageDirectory) {
132
- const files = yield* RepositoryFiles;
133
- const manifest = yield* readManifest(packageDirectory);
134
- if (Option.isNone(manifest)) return [];
135
- const entries = yield* Effect.forEach(declaredDependencies(manifest.value), (packageName) => entriesOfDependency(packageName, files.join(packageDirectory, NODE_MODULES, packageName)), { concurrency: 1 });
136
- return Array.sort(Array.dedupeWith(entries.flat(), (left, right) => left.specifier === right.specifier), entryOrder);
137
- });
138
- // src/entities/package/model/public-entries.ts
139
- const SOURCE = /\.[cm]?tsx?$/u;
140
- const BUILT = /\.(?:d\.)?[cm]?[jt]s$/u;
141
- const DECLARATION = ".d.";
142
- const SEPARATOR$2 = "/";
143
- const ROOT_SUBPATH = ".";
144
- const BIN_LABEL = "bin";
145
- const targetsIn = (held) => {
146
- if (Predicate.isString(held)) return [held];
147
- if (!Predicate.isObject(held)) return [];
148
- return pipe(Record.values(held), Array.flatMap(targetsIn));
55
+ const decodeWrapped = Schema.decodeUnknownOption(WrappedNode);
56
+ const decodeValue = Schema.decodeUnknownOption(ValueNode);
57
+ const decodeProperty = Schema.decodeUnknownOption(Schema.Struct({
58
+ type: Schema.Literal("Property"),
59
+ key: KeySchema,
60
+ value: Schema.Unknown
61
+ }));
62
+ const decodeObject = Schema.decodeUnknownOption(Schema.Struct({
63
+ type: Schema.Literal("ObjectExpression"),
64
+ properties: Schema.Array(Schema.Unknown)
65
+ }));
66
+ const keyName = (key) => Match.value(key).pipe(Match.discriminatorsExhaustive("type")({
67
+ Identifier: (identifier) => identifier.name,
68
+ Literal: (literal) => literal.value
69
+ }));
70
+ const literalOf = (node) => {
71
+ const wrapped = decodeWrapped(node);
72
+ if (Option.isSome(wrapped)) return literalOf(wrapped.value.expression);
73
+ return pipe(decodeValue(node), Option.flatMap((value) => Match.value(value).pipe(Match.discriminatorsExhaustive("type")({
74
+ Literal: (scalar) => Option.some(scalar.value),
75
+ TemplateLiteral: (template) => Option.some(pipe(template.quasis, Array.map((quasi) => quasi.value.cooked), Array.join(""))),
76
+ ArrayExpression: (array) => pipe(array.elements, Array.map(literalOf), Option.all),
77
+ ObjectExpression: (object) => pipe(object.properties, Array.map((property) => pipe(literalOf(property.value), Option.map((literal) => [keyName(property.key), literal]))), Option.all, Option.map(Record.fromEntries))
78
+ }))));
149
79
  };
150
- const subpathsOf = (exportsField) => {
151
- if (!Predicate.isObject(exportsField)) return [[ROOT_SUBPATH, exportsField]];
152
- const entries = Record.toEntries(exportsField);
153
- if (pipe(entries, Array.some(([key]) => String$1.startsWith(ROOT_SUBPATH)(key)))) return entries;
154
- return [[ROOT_SUBPATH, exportsField]];
80
+ const propertyValue = (name) => (object) => pipe(decodeObject(object), Option.flatMap(({ properties }) => pipe(properties, Array.findFirst((property) => pipe(decodeProperty(property), Option.filter(({ key }) => keyName(key) === name), Option.map(({ value }) => value))))));
81
+ const childrenOf = (node) => {
82
+ if (Array.isArray(node)) return node;
83
+ if (Predicate.isReadonlyObject(node)) return Record.values(node);
84
+ return [];
155
85
  };
156
- const binsOf = (manifest) => {
157
- if (Predicate.isString(manifest.bin)) {
158
- const name = Option.getOrElse(Option.fromUndefinedOr(manifest.name), () => "");
159
- return [[`${BIN_LABEL} ${name}`, manifest.bin]];
160
- }
161
- if (!Predicate.isObject(manifest.bin)) return [];
162
- return pipe(Record.toEntries(manifest.bin), Array.map(([name, target]) => [`${BIN_LABEL} ${name}`, target]));
86
+ const nestedValues = (path) => (node) => {
87
+ const [outer, inner] = path;
88
+ return [...pipe(Option.some(node), Option.flatMap(propertyValue(outer)), Option.flatMap(propertyValue(inner)), Option.toArray), ...pipe(childrenOf(node), Array.flatMap(nestedValues(path)))];
163
89
  };
164
- const baseNameOf = (target) => pipe(String$1.split(target, SEPARATOR$2), Array.last, Option.getOrElse(() => target), String$1.replace(BUILT, ""));
165
- const sourceOf = ({ join, packEntries }) => (target) => {
166
- if (SOURCE.test(target) && !String$1.includes(DECLARATION)(target)) return Option.some(join(target));
167
- const name = baseNameOf(target);
168
- return pipe(packEntries, Array.findFirst((entry) => entry.name === name), Option.map((entry) => entry.source));
90
+ const StringNode = Schema.Union([Schema.Struct({
91
+ type: Schema.Literal("Literal"),
92
+ value: Schema.String,
93
+ start: Schema.Finite
94
+ }), Schema.Struct({
95
+ type: Schema.Literal("TemplateElement"),
96
+ value: Schema.Struct({ cooked: Schema.String }),
97
+ start: Schema.Finite
98
+ })]);
99
+ const decodeStringNode = Schema.decodeUnknownOption(StringNode);
100
+ const textOf = (node) => {
101
+ if (node.type === "Literal") return node.value;
102
+ return node.value.cooked;
169
103
  };
170
- const publicEntriesOf = (lookup) => pipe([...subpathsOf(lookup.manifest.exports), ...binsOf(lookup.manifest)], Array.flatMap(([label, held]) => pipe(targetsIn(held), Array.map(sourceOf(lookup)), Array.getSomes, Array.map((source) => ({
171
- label,
172
- source
173
- })))), Array.dedupeWith((left, right) => left.label === right.label && left.source === right.source));
174
- const EntryManifestFields = Schema.Struct({
175
- name: Schema.optional(Schema.String),
176
- exports: Schema.optional(Schema.Unknown),
177
- bin: Schema.optional(Schema.Unknown)
178
- });
179
- const EntryManifestJson = Schema.fromJsonString(EntryManifestFields);
180
- // src/entities/package/model/published.ts
104
+ const stringsIn = (node) => {
105
+ return [...pipe(decodeStringNode(node), Option.map((found) => ({
106
+ text: textOf(found),
107
+ start: found.start
108
+ })), Option.toArray), ...pipe(childrenOf(node), Array.flatMap(stringsIn))];
109
+ };
110
+ // src/entities/workspace/model/workspace-config-source.ts
111
+ const SINGLE = 1;
181
112
  const CONFIG_FILE$1 = "vite.config.ts";
182
- const SEPARATOR$1 = "/";
183
- const READ_CONCURRENCY$1 = 16;
184
- const SOURCE_EXTENSION = /\.[cm]?tsx?$/u;
185
- const UNIT_BYTES = [
186
- ["B", 1],
187
- ["kB", 1e3],
188
- ["MB", 1e6]
189
- ];
190
- const SizeText = Schema.TemplateLiteralParser([
191
- Schema.Finite,
192
- " ",
193
- Schema.Literals([
194
- "B",
195
- "kB",
196
- "MB"
197
- ])
198
- ]);
199
- const PackEntry = Schema.Union([
200
- Schema.String,
201
- Schema.Array(Schema.String),
202
- Schema.Record(Schema.String, Schema.String)
203
- ]);
204
- const PackSettings = Schema.Struct({ entry: Schema.optional(PackEntry) });
205
- const PackList = Schema.Union([PackSettings, Schema.Array(PackSettings)]);
206
- const isEntryList = Schema.is(Schema.Array(Schema.String));
207
- const WorkspaceConfig = Schema.Struct({
208
- msch: Schema.Struct({ publish: Schema.Struct({ installSize: SizeText }) }),
209
- pack: Schema.optional(PackList)
113
+ const taggedError$3 = Schema.TaggedError;
114
+ var WorkspaceSettingsInvalid = class extends taggedError$3()("WorkspaceSettingsInvalid", {
115
+ file: Schema.String,
116
+ message: Schema.String
117
+ }) {};
118
+ const settingsInvalid = (file) => (reason) => WorkspaceSettingsInvalid.make({
119
+ file,
120
+ message: `${file}: ${reason}`
210
121
  });
211
- const PublicManifest = Schema.Struct({ private: Schema.optional(Schema.Literal(false)) });
212
- const taggedError$2 = Schema.TaggedError;
213
- var WorkspaceConfigUnreadable = class extends taggedError$2()("WorkspaceConfigUnreadable", { file: Schema.String }) {};
214
- const bytesPer = (unit) => pipe(UNIT_BYTES, Array.findFirst(([name]) => name === unit), Option.map(([, bytes]) => bytes), Option.getOrElse(() => NaN));
215
- const nameOf = (source) => pipe(String$1.split(source, SEPARATOR$1), Array.last, Option.getOrElse(() => source), String$1.replace(SOURCE_EXTENSION, ""));
216
- const entriesOf = (entry) => {
217
- if (Predicate.isString(entry)) return [{
218
- name: nameOf(entry),
219
- source: entry
220
- }];
221
- if (isEntryList(entry)) return pipe(entry, Array.map((source) => ({
222
- name: nameOf(source),
223
- source
224
- })));
225
- return pipe(Record.toEntries(entry), Array.map(([name, source]) => ({
226
- name,
227
- source
228
- })));
229
- };
230
- const packEntriesOf = (pack) => pipe(Option.fromUndefinedOr(pack), Option.map(Array.ensure), Option.getOrElse(() => []), Array.flatMap((setting) => pipe(Option.fromUndefinedOr(setting.entry), Option.match({
231
- onNone: () => [],
232
- onSome: entriesOf
233
- }))));
234
- const settingsIn = Effect.fn("settingsIn")(function* settingsIn(file) {
122
+ const notLiteral = ([outer, inner]) => `${outer}.${inner} must be written with literal values, because the root vite.config.ts reads it without running this file. Name a set the root config defines in use instead of importing values.`;
123
+ const merged = (records) => pipe(records, Array.flatMap(Record.toEntries), Record.fromEntries);
124
+ const usedFrom = Effect.fn("usedFrom")(function* usedFrom(file, sets, used) {
125
+ const unknownSets = pipe(used, Array.filter((name) => !Record.has(sets, name)));
126
+ if (Array.isReadonlyArrayNonEmpty(unknownSets)) return yield* settingsInvalid(file)(`msch uses sets the root does not define: ${Array.join(unknownSets, ", ")}. Defined: ${Array.join(Record.keys(sets), ", ")}.`);
127
+ return pipe(used, Array.flatMap((name) => Option.toArray(Record.get(sets, name))));
128
+ });
129
+ const singleValue = Effect.fn("singleValue")(function* singleValue(source, path) {
130
+ const found = nestedValues(path)(source.program);
131
+ if (found.length > SINGLE) return yield* settingsInvalid(source.file)(`${Array.join(path, ".")} appears more than once.`);
132
+ return Array.head(found);
133
+ });
134
+ const literalSettings = ({ source, path, decode }) => Effect.gen(function* literalSettingsIn() {
135
+ const node = yield* singleValue(source, path);
136
+ if (Option.isNone(node)) return Option.none();
137
+ const literal = literalOf(node.value);
138
+ if (Option.isNone(literal)) return yield* settingsInvalid(source.file)(notLiteral(path));
139
+ const settings = yield* decode(literal.value).pipe(Effect.mapError((error) => settingsInvalid(source.file)(error.message)));
140
+ return Option.some(settings);
141
+ });
142
+ const programOf = Effect.fn("programOf")(function* programOf(file, text) {
143
+ const parsed = yield* Effect.promise(() => parse(file, text, { lang: "ts" }));
144
+ if (Array.isReadonlyArrayNonEmpty(parsed.errors)) return yield* settingsInvalid(file)("vite.config.ts does not parse.");
145
+ return parsed.program;
146
+ });
147
+ const workspaceConfigOf = Effect.fn("workspaceConfigOf")(function* workspaceConfigOf(root, directory) {
148
+ const files = yield* RepositoryFiles;
149
+ const file = files.join(root, directory, CONFIG_FILE$1);
150
+ const text = yield* files.readFile(file);
151
+ if (Option.isNone(text)) return Option.none();
152
+ const program = yield* programOf(file, text.value);
153
+ return Option.some({
154
+ file,
155
+ source: text.value,
156
+ program
157
+ });
158
+ });
159
+ // src/entities/workspace/model/workspace-tasks.ts
160
+ const VERIFY_TASK = ["tasks", "verify"];
161
+ const RUN_TASKS = ["run", "tasks"];
162
+ const NO_TASKS = { verify: [] };
163
+ const Tasks = Schema.Struct({ verify: Schema.Unknown });
164
+ const isVerified = Schema.is(Schema.Struct({ run: Schema.Struct({ tasks: Tasks }) }));
165
+ const definesTask = (path) => (program) => Array.isReadonlyArrayNonEmpty(nestedValues(path)(program));
166
+ const hasVerifyTask = Effect.fn("hasVerifyTask")(function* hasVerifyTask(file) {
235
167
  const config = yield* Effect.tryPromise({
236
168
  try: () => resolveConfigFromFile(file),
237
- catch: () => WorkspaceConfigUnreadable.make({ file })
169
+ catch: () => settingsInvalid(file)("vite.config.ts does not load.")
238
170
  }).pipe(Effect.option);
239
- return pipe(config, Option.flatMap(Schema.decodeUnknownOption(WorkspaceConfig)));
171
+ return Option.exists(config, isVerified);
240
172
  });
241
- const isPublicPackage = Effect.fn("isPublicPackage")(function* isPublicPackage(directory) {
173
+ const tasksOf = (manifest) => (program) => pipe(manifest, Option.flatMap((found) => Option.fromUndefinedOr(found.name)), Option.match({
174
+ onNone: () => NO_TASKS,
175
+ onSome: (name) => ({ verify: Array.filter([`${name}#verify`], () => definesTask(VERIFY_TASK)(program)) })
176
+ }));
177
+ // src/entities/workspace/model/run-tasks.ts
178
+ const TaskProperty = Schema.Struct({
179
+ type: Schema.Literal("Property"),
180
+ computed: Schema.Literal(false),
181
+ key: KeySchema,
182
+ value: Schema.Unknown,
183
+ start: Schema.Finite
184
+ });
185
+ const TaskObject = Schema.Struct({
186
+ type: Schema.Literal("ObjectExpression"),
187
+ properties: Schema.Array(Schema.Unknown)
188
+ });
189
+ const decodeTaskProperty = Schema.decodeUnknownOption(TaskProperty);
190
+ const decodeTaskObject = Schema.decodeUnknownOption(TaskObject);
191
+ const tasksIn = (program) => pipe(nestedValues(RUN_TASKS)(program), Array.flatMap((tasks) => pipe(decodeTaskObject(tasks), Option.map(({ properties }) => properties), Option.getOrElse(() => []))), Array.flatMap((property) => Option.toArray(decodeTaskProperty(property))));
192
+ const runTasksOf = Effect.fn("runTasksOf")(function* runTasksOf(root, directory) {
193
+ const config = yield* workspaceConfigOf(root, directory);
194
+ return pipe(config, Option.map(({ file, source, program }) => ({
195
+ file,
196
+ source,
197
+ tasks: tasksIn(program)
198
+ })));
199
+ });
200
+ // src/entities/workspace/model/workspace-unreadable.ts
201
+ const taggedError$2 = Schema.TaggedError;
202
+ var WorkspaceUnreadable = class extends taggedError$2()("WorkspaceUnreadable", {
203
+ root: Schema.String,
204
+ reason: Schema.String
205
+ }) {};
206
+ // src/entities/workspace/model/workspace-manifest.ts
207
+ /** @internal */
208
+ const workspaceManifest = (root) => Effect.tryPromise({
209
+ try: () => readWorkspaceManifest(root),
210
+ catch: (cause) => WorkspaceUnreadable.make({
211
+ root,
212
+ reason: String(cause)
213
+ })
214
+ }).pipe(Effect.map(Option.fromUndefinedOr), Effect.orElseSucceed(() => Option.none()));
215
+ // src/entities/workspace/model/workspace-projects.ts
216
+ const byDirectory = Order.mapInput(String$1.Order, ({ directory }) => directory);
217
+ const projectsMatching = (root, patterns) => Effect.tryPromise({
218
+ try: () => findWorkspaceProjectsNoCheck(root, { patterns: [...patterns] }),
219
+ catch: (cause) => WorkspaceUnreadable.make({
220
+ root,
221
+ reason: String(cause)
222
+ })
223
+ }).pipe(Effect.orElseSucceed(() => []));
224
+ /** @internal */
225
+ const workspaceProjects = Effect.fn("workspaceProjects")(function* workspaceProjects(root) {
242
226
  const files = yield* RepositoryFiles;
243
- const text = yield* files.readFile(files.join(directory, MANIFEST_FILE));
244
- return Option.exists(text, (found) => Option.isSome(Schema.decodeOption(Schema.fromJsonString(PublicManifest))(found)));
227
+ const manifest = yield* workspaceManifest(root);
228
+ const patterns = pipe(manifest, Option.flatMap(({ packages }) => Option.fromNullishOr(packages)), Option.getOrElse(() => []));
229
+ if (!Array.isReadonlyArrayNonEmpty(patterns)) return [];
230
+ const projects = yield* projectsMatching(root, patterns);
231
+ const found = pipe(projects, Array.map(({ rootDir, manifest: own }) => ({
232
+ directory: files.relative(root, rootDir),
233
+ packageName: Option.fromUndefinedOr(own.name),
234
+ published: own.private !== true,
235
+ keywords: Option.getOrElse(Option.fromUndefinedOr(own.keywords), () => []),
236
+ files: Option.fromUndefinedOr(own.files)
237
+ })), Array.filter(({ directory }) => String$1.isNonEmpty(directory)));
238
+ return Array.sort(found, byDirectory);
245
239
  });
246
- const workspaceOf = (directory, configFile, join) => ({ msch, pack }) => {
247
- const [amount, , unit] = msch.publish.installSize;
240
+ /** @internal */
241
+ const workspaceDirectories = Effect.fn("workspaceDirectories")(function* workspaceDirectories(root) {
242
+ const projects = yield* workspaceProjects(root);
243
+ return pipe(projects, Array.map(({ directory }) => directory));
244
+ });
245
+ // src/entities/workspace/model/workspace-patterns.ts
246
+ const SEPARATOR$2 = "/";
247
+ const NEGATION = "!";
248
+ const RELATIVE = "./";
249
+ const withoutRelative = (target) => {
250
+ if (String$1.startsWith(RELATIVE)(target)) return String$1.slice(2)(target);
251
+ return target;
252
+ };
253
+ const prefixed = (directory) => (pattern) => {
254
+ if (String$1.startsWith(NEGATION)(pattern)) return `${NEGATION}${directory}${SEPARATOR$2}${String$1.slice(1)(pattern)}`;
255
+ return `${directory}${SEPARATOR$2}${withoutRelative(pattern)}`;
256
+ };
257
+ // src/entities/workspace/model/workspace-names.ts
258
+ const ALTERNATIVE = "|";
259
+ const SCOPE = /^@[^/]+\//u;
260
+ const SPECIAL = /[$()*+.?[\\\]^{|}]/gu;
261
+ /** @internal */
262
+ const patternOf = (names) => {
263
+ const alternatives = pipe(names, Array.map(String$1.replaceAll(SPECIAL, String.raw`\$&`)));
264
+ return new RegExp(`(?<![\\p{L}\\p{N}_-])(?:${Array.join(alternatives, ALTERNATIVE)})(?![\\p{L}\\p{N}_-])`, "gu");
265
+ };
266
+ const namedIn = (basename) => ({ directory, packageName }) => {
267
+ const unscoped = pipe(packageName, Option.map(String$1.replace(SCOPE, "")));
248
268
  return {
249
269
  directory,
250
- configFile,
251
- installSize: `${amount} ${unit}`,
252
- installBudget: amount * bytesPer(unit),
253
- packEntries: pipe(packEntriesOf(pack), Array.map((entry) => ({
254
- name: entry.name,
255
- source: join(entry.source)
256
- })))
270
+ names: pipe([
271
+ Option.some(directory),
272
+ Option.some(basename(directory)),
273
+ packageName,
274
+ unscoped
275
+ ], Array.getSomes, Array.dedupe),
276
+ packageName
257
277
  };
258
278
  };
259
- const publishedIn = Effect.fn("publishedIn")(function* publishedIn(root, configName) {
260
- const files = yield* RepositoryFiles;
261
- const configFile = files.join(root, configName);
262
- const directory = files.dirname(configFile);
263
- if (!(yield* isPublicPackage(directory))) return Option.none();
264
- const settings = yield* settingsIn(configFile);
265
- return pipe(settings, Option.map(workspaceOf(directory, configFile, (source) => files.join(directory, source))));
266
- });
267
279
  /** @internal */
268
- const publishedWorkspaces = Effect.fn("publishedWorkspaces")(function* publishedWorkspaces(root) {
280
+ const namedWorkspaces = Effect.fn("namedWorkspaces")(function* namedWorkspaces(root) {
269
281
  const files = yield* RepositoryFiles;
270
- const names = yield* files.listedFiles(root);
271
- const configs = pipe(names, Array.filter((name) => files.basename(name) === CONFIG_FILE$1 && String$1.includes(SEPARATOR$1)(name)));
272
- const found = yield* Effect.forEach(configs, (name) => publishedIn(root, name), { concurrency: READ_CONCURRENCY$1 });
273
- return Array.getSomes(found);
282
+ const projects = yield* workspaceProjects(root);
283
+ return pipe(projects, Array.map(namedIn((directory) => files.basename(directory))));
274
284
  });
275
- // src/entities/workspace/model/config-literal.ts
276
- const WRAPPERS = [
277
- "TSAsExpression",
278
- "TSSatisfiesExpression",
279
- "ParenthesizedExpression"
280
- ];
281
- const KeySchema = Schema.Union([Schema.Struct({
282
- type: Schema.Literal("Identifier"),
283
- name: Schema.String
284
- }), Schema.Struct({
285
- type: Schema.Literal("Literal"),
286
- value: Schema.String
287
- })]);
288
- const Quasi = Schema.Struct({ value: Schema.Struct({ cooked: Schema.String }) });
289
- const PropertyNode = Schema.Struct({
290
- type: Schema.Literal("Property"),
291
- computed: Schema.Literal(false),
292
- key: KeySchema,
293
- value: Schema.Unknown
285
+ // src/entities/workspace/model/deploy-entries.ts
286
+ const MAIN_KEY = "main";
287
+ const READ_CONCURRENCY$1 = 16;
288
+ const SCRIPT = /\.[cm]?tsx?$/u;
289
+ const SKIPPED = /\.test\.|\.d\.[cm]?ts$/u;
290
+ const ALCHEMY_IMPORT = /from\s+["'](?:alchemy|@alchemy\.run)(?:\/[^"']*)?["']/u;
291
+ const MAIN_PROPERTY = /\bmain\s*:/u;
292
+ const decodeKey = Schema.decodeUnknownOption(KeySchema);
293
+ const isMainProperty = (node) => node["type"] === "Property" && pipe(decodeKey(node["key"]), Option.exists((key) => keyName(key) === MAIN_KEY));
294
+ const mainTargetsIn = (node) => {
295
+ if (Predicate.isReadonlyObject(node) && isMainProperty(node)) return pipe(stringsIn(node["value"]), Array.head, Option.map(({ text }) => text), Option.toArray);
296
+ return pipe(childrenOf(node), Array.flatMap(mainTargetsIn));
297
+ };
298
+ const declaredIn = Effect.fn("declaredIn")(function* declaredIn(root, file) {
299
+ const files = yield* RepositoryFiles;
300
+ const text = yield* files.readFile(files.join(root, file));
301
+ if (Option.isNone(text) || !ALCHEMY_IMPORT.test(text.value) || !MAIN_PROPERTY.test(text.value)) return [];
302
+ const parsed = yield* Effect.promise(() => parse(file, text.value, { lang: "ts" }));
303
+ return pipe(mainTargetsIn(parsed.program), Array.map((target) => files.join(files.dirname(file), target)));
294
304
  });
295
- const WrappedNode = Schema.Struct({
296
- type: Schema.Literals(WRAPPERS),
297
- expression: Schema.Unknown
305
+ const deployEntries = Effect.fn("deployEntries")(function* deployEntries(root) {
306
+ const listed = yield* (yield* RepositoryFiles).listedFiles(root);
307
+ const declaring = pipe(listed, Array.filter((file) => SCRIPT.test(file) && !SKIPPED.test(file)));
308
+ const found = yield* Effect.forEach(declaring, (file) => declaredIn(root, file), { concurrency: READ_CONCURRENCY$1 });
309
+ return pipe(Array.flatten(found), Array.filter((file) => Array.contains(listed, file)), Array.dedupe);
298
310
  });
299
- const ValueNode = Schema.Union([
300
- Schema.Struct({
301
- type: Schema.Literal("Literal"),
302
- value: Schema.Union([
303
- Schema.String,
304
- Schema.Finite,
305
- Schema.Boolean,
306
- Schema.Null
307
- ])
308
- }),
309
- Schema.Struct({
310
- type: Schema.Literal("TemplateLiteral"),
311
- expressions: Schema.Tuple([]),
312
- quasis: Schema.Array(Quasi)
313
- }),
314
- Schema.Struct({
315
- type: Schema.Literal("ArrayExpression"),
316
- elements: Schema.Array(Schema.Unknown)
317
- }),
318
- Schema.Struct({
319
- type: Schema.Literal("ObjectExpression"),
320
- properties: Schema.Array(PropertyNode)
311
+ // src/entities/workspace/model/lockfile-unreadable.ts
312
+ const taggedError$1 = Schema.TaggedError;
313
+ var LockfileUnreadable = class extends taggedError$1()("LockfileUnreadable", {
314
+ root: Schema.String,
315
+ reason: Schema.String
316
+ }) {};
317
+ // src/entities/workspace/model/locked-packages.ts
318
+ /** @internal */
319
+ const lockedPackages = (root) => Effect.tryPromise({
320
+ try: () => readWantedLockfile(root, { ignoreIncompatible: false }),
321
+ catch: (cause) => LockfileUnreadable.make({
322
+ root,
323
+ reason: String(cause)
321
324
  })
322
- ]);
323
- const decodeWrapped = Schema.decodeUnknownOption(WrappedNode);
324
- const decodeValue = Schema.decodeUnknownOption(ValueNode);
325
- const decodeProperty = Schema.decodeUnknownOption(Schema.Struct({
326
- type: Schema.Literal("Property"),
327
- key: KeySchema,
328
- value: Schema.Unknown
329
- }));
330
- const decodeObject = Schema.decodeUnknownOption(Schema.Struct({
331
- type: Schema.Literal("ObjectExpression"),
332
- properties: Schema.Array(Schema.Unknown)
333
- }));
334
- const keyName = (key) => Match.value(key).pipe(Match.discriminatorsExhaustive("type")({
335
- Identifier: (identifier) => identifier.name,
336
- Literal: (literal) => literal.value
337
- }));
338
- const literalOf = (node) => {
339
- const wrapped = decodeWrapped(node);
340
- if (Option.isSome(wrapped)) return literalOf(wrapped.value.expression);
341
- return pipe(decodeValue(node), Option.flatMap((value) => Match.value(value).pipe(Match.discriminatorsExhaustive("type")({
342
- Literal: (scalar) => Option.some(scalar.value),
343
- TemplateLiteral: (template) => Option.some(pipe(template.quasis, Array.map((quasi) => quasi.value.cooked), Array.join(""))),
344
- ArrayExpression: (array) => pipe(array.elements, Array.map(literalOf), Option.all),
345
- ObjectExpression: (object) => pipe(object.properties, Array.map((property) => pipe(literalOf(property.value), Option.map((literal) => [keyName(property.key), literal]))), Option.all, Option.map(Record.fromEntries))
346
- }))));
325
+ }).pipe(Effect.map((lockfile) => pipe(Option.fromNullishOr(lockfile), Option.flatMap(({ packages }) => Option.fromUndefinedOr(packages)), Option.map(Record.keys))));
326
+ // src/entities/package/model/dependencies.ts
327
+ const DependencyMap = Schema.optional(Schema.Record(Schema.String, Schema.String));
328
+ const PackageManifest = Schema.Struct({
329
+ name: Schema.optional(Schema.String),
330
+ dependencies: DependencyMap,
331
+ devDependencies: DependencyMap,
332
+ peerDependencies: DependencyMap,
333
+ exports: Schema.optional(Schema.Unknown),
334
+ types: Schema.optional(Schema.String),
335
+ typings: Schema.optional(Schema.String),
336
+ main: Schema.optional(Schema.String)
337
+ });
338
+ const MANIFEST_FILE = "package.json";
339
+ const WORKSPACE_PROTOCOL = "workspace:";
340
+ const ROOT_SUBPATH$1 = ".";
341
+ const SUBPATH_PREFIX = "./";
342
+ const WILDCARD = "*";
343
+ const TYPES_CONDITION = "types";
344
+ const TYPES_SCOPE = "@types/";
345
+ const TYPES_SCOPE_SEPARATOR = "__";
346
+ const CONDITION_DEPTH_LIMIT = 8;
347
+ const ROOT_DEPTH = 0;
348
+ const DEPTH_STEP = 1;
349
+ const DECLARATIONS_SUFFIX = /\.d\.[cm]?ts$|\.[cm]?tsx?$/u;
350
+ const SCRIPT_SUFFIX = /\.(?<module>[cm]?)js$/u;
351
+ const readManifest = Effect.fn("readManifest")(function* readManifest(directory) {
352
+ const files = yield* RepositoryFiles;
353
+ const manifestText = yield* files.readFile(files.join(directory, MANIFEST_FILE));
354
+ const text = yield* Effect.fromOption(manifestText);
355
+ return yield* Schema.decodeEffect(Schema.fromJsonString(PackageManifest))(text);
356
+ }, Effect.option);
357
+ const conditionsOf = (held) => {
358
+ if (!Predicate.isObject(held)) return [];
359
+ return Record.toEntries(held);
347
360
  };
348
- const propertyValue = (name) => (object) => pipe(decodeObject(object), Option.flatMap(({ properties }) => pipe(properties, Array.findFirst((property) => pipe(decodeProperty(property), Option.filter(({ key }) => keyName(key) === name), Option.map(({ value }) => value))))));
349
- const childrenOf = (node) => {
350
- if (Array.isArray(node)) return node;
351
- if (Predicate.isReadonlyObject(node)) return Record.values(node);
352
- return [];
361
+ const typesConditionIn = (held, depth) => {
362
+ if (depth > CONDITION_DEPTH_LIMIT) return Option.none();
363
+ const entries = conditionsOf(held);
364
+ const declared = Array.findFirst(entries, ([condition, target]) => Option.liftPredicate(target, (candidate) => condition === TYPES_CONDITION && Predicate.isString(candidate))).pipe(Option.filter(Predicate.isString));
365
+ return Option.orElse(declared, () => Array.findFirst(entries, ([, nested]) => typesConditionIn(nested, depth + DEPTH_STEP)));
353
366
  };
354
- const nestedValues = (path) => (node) => {
355
- const [outer, inner] = path;
356
- return [...pipe(Option.some(node), Option.flatMap(propertyValue(outer)), Option.flatMap(propertyValue(inner)), Option.toArray), ...pipe(childrenOf(node), Array.flatMap(nestedValues(path)))];
367
+ const anyConditionIn = (held, depth) => {
368
+ if (Predicate.isString(held)) return Option.some(held);
369
+ if (depth > CONDITION_DEPTH_LIMIT) return Option.none();
370
+ return Array.findFirst(conditionsOf(held), ([, nested]) => anyConditionIn(nested, depth + DEPTH_STEP));
357
371
  };
358
- const StringNode = Schema.Union([Schema.Struct({
359
- type: Schema.Literal("Literal"),
360
- value: Schema.String,
361
- start: Schema.Finite
362
- }), Schema.Struct({
363
- type: Schema.Literal("TemplateElement"),
364
- value: Schema.Struct({ cooked: Schema.String }),
365
- start: Schema.Finite
366
- })]);
367
- const decodeStringNode = Schema.decodeUnknownOption(StringNode);
368
- const textOf = (node) => {
369
- if (node.type === "Literal") return node.value;
370
- return node.value.cooked;
372
+ const targetPathsOf = (target) => Array.getSomes([typesConditionIn(target, ROOT_DEPTH), anyConditionIn(target, ROOT_DEPTH)]);
373
+ const subpathTargetsOf = (exportsField) => {
374
+ if (Predicate.isString(exportsField)) return [{
375
+ subpath: ROOT_SUBPATH$1,
376
+ target: exportsField
377
+ }];
378
+ const entries = conditionsOf(exportsField);
379
+ if (!pipe(entries, Array.some(([subpath]) => String$1.startsWith(ROOT_SUBPATH$1)(subpath)))) return Array.match(entries, {
380
+ onEmpty: () => [],
381
+ onNonEmpty: () => [{
382
+ subpath: ROOT_SUBPATH$1,
383
+ target: exportsField
384
+ }]
385
+ });
386
+ return pipe(entries, Array.filter(([subpath]) => subpath === ROOT_SUBPATH$1 || String$1.startsWith(SUBPATH_PREFIX)(subpath)), Array.filter(([subpath]) => !String$1.includes(WILDCARD)(subpath)), Array.map(([subpath, target]) => ({
387
+ subpath,
388
+ target
389
+ })));
371
390
  };
372
- const stringsIn = (node) => {
373
- return [...pipe(decodeStringNode(node), Option.map((found) => ({
374
- text: textOf(found),
375
- start: found.start
376
- })), Option.toArray), ...pipe(childrenOf(node), Array.flatMap(stringsIn))];
391
+ const declarationsCandidateFor = (entryPath) => {
392
+ if (DECLARATIONS_SUFFIX.test(entryPath)) return Option.some(entryPath);
393
+ if (!SCRIPT_SUFFIX.test(entryPath)) return Option.none();
394
+ return Option.some(String$1.replace(SCRIPT_SUFFIX, ".d.$<module>ts")(entryPath));
377
395
  };
378
- // src/entities/workspace/model/workspace-config-source.ts
379
- const SINGLE = 1;
380
- const CONFIG_FILE = "vite.config.ts";
381
- const taggedError$1 = Schema.TaggedError;
382
- var WorkspaceSettingsInvalid = class extends taggedError$1()("WorkspaceSettingsInvalid", {
383
- file: Schema.String,
384
- message: Schema.String
385
- }) {};
386
- const settingsInvalid = (file) => (reason) => WorkspaceSettingsInvalid.make({
387
- file,
388
- message: `${file}: ${reason}`
396
+ const firstDeclarationsAmong = Effect.fn("firstDeclarationsAmong")(function* firstDeclarations(directory, entryPaths) {
397
+ const files = yield* RepositoryFiles;
398
+ const candidates = Array.getSomes(pipe(entryPaths, Array.map((entryPath) => declarationsCandidateFor(entryPath))));
399
+ const existing = yield* Effect.filter(pipe(candidates, Array.map((candidate) => files.join(directory, candidate))), (candidate) => files.exists(candidate));
400
+ return yield* Option.match(Array.head(existing), {
401
+ onNone: () => Effect.succeedNone,
402
+ onSome: (candidate) => files.realPath(candidate).pipe(Effect.asSome)
403
+ });
389
404
  });
390
- const notLiteral = ([outer, inner]) => `${outer}.${inner} must be written with literal values, because the root vite.config.ts reads it without running this file. Name a set the root config defines in use instead of importing values.`;
391
- const merged = (records) => pipe(records, Array.flatMap(Record.toEntries), Record.fromEntries);
392
- const usedFrom = Effect.fn("usedFrom")(function* usedFrom(file, sets, used) {
393
- const unknownSets = pipe(used, Array.filter((name) => !Record.has(sets, name)));
394
- if (Array.isReadonlyArrayNonEmpty(unknownSets)) return yield* settingsInvalid(file)(`msch uses sets the root does not define: ${Array.join(unknownSets, ", ")}. Defined: ${Array.join(Record.keys(sets), ", ")}.`);
395
- return pipe(used, Array.flatMap((name) => Option.toArray(Record.get(sets, name))));
405
+ const importNameOf = (packageName) => {
406
+ if (!String$1.startsWith(TYPES_SCOPE)(packageName)) return packageName;
407
+ const unscoped = String$1.slice(7)(packageName);
408
+ if (!String$1.includes(TYPES_SCOPE_SEPARATOR)(unscoped)) return unscoped;
409
+ return `@${String$1.replace(TYPES_SCOPE_SEPARATOR, "/")(unscoped)}`;
410
+ };
411
+ const specifierFor = (packageName, subpath) => {
412
+ const importName = importNameOf(packageName);
413
+ if (subpath === ROOT_SUBPATH$1) return importName;
414
+ return `${importName}/${String$1.slice(2)(subpath)}`;
415
+ };
416
+ const rootEntryPaths = (manifest) => Array.getSomes([
417
+ Option.fromUndefinedOr(manifest.types),
418
+ Option.fromUndefinedOr(manifest.typings),
419
+ Option.fromUndefinedOr(manifest.main)
420
+ ]);
421
+ const subpathEntriesOf = Effect.fn("subpathEntriesOf")(function* subpathEntriesOf(packageName, directory, manifest) {
422
+ const found = yield* Effect.forEach(subpathTargetsOf(manifest.exports), ({ subpath, target }) => firstDeclarationsAmong(directory, targetPathsOf(target)).pipe(Effect.map(Option.map((declarationsPath) => ({
423
+ packageName,
424
+ specifier: specifierFor(packageName, subpath),
425
+ declarationsPath
426
+ })))), { concurrency: 1 });
427
+ return Array.getSomes(found);
396
428
  });
397
- const singleValue = Effect.fn("singleValue")(function* singleValue(source, path) {
398
- const found = nestedValues(path)(source.program);
399
- if (found.length > SINGLE) return yield* settingsInvalid(source.file)(`${Array.join(path, ".")} appears more than once.`);
400
- return Array.head(found);
429
+ const entriesOfDependency = Effect.fn("entriesOfDependency")(function* entriesOfDependency(packageName, directory) {
430
+ const manifest = yield* readManifest(directory);
431
+ if (Option.isNone(manifest)) return [];
432
+ const subpathEntries = yield* subpathEntriesOf(packageName, directory, manifest.value);
433
+ const rootSpecifier = specifierFor(packageName, ROOT_SUBPATH$1);
434
+ if (pipe(subpathEntries, Array.some((entry) => entry.specifier === rootSpecifier))) return subpathEntries;
435
+ return [...(yield* firstDeclarationsAmong(directory, rootEntryPaths(manifest.value))).pipe(Option.map((declarationsPath) => ({
436
+ packageName,
437
+ specifier: rootSpecifier,
438
+ declarationsPath
439
+ })), Option.toArray), ...subpathEntries];
401
440
  });
402
- const literalSettings = ({ source, path, decode }) => Effect.gen(function* literalSettingsIn() {
403
- const node = yield* singleValue(source, path);
404
- if (Option.isNone(node)) return Option.none();
405
- const literal = literalOf(node.value);
406
- if (Option.isNone(literal)) return yield* settingsInvalid(source.file)(notLiteral(path));
407
- const settings = yield* decode(literal.value).pipe(Effect.mapError((error) => settingsInvalid(source.file)(error.message)));
408
- return Option.some(settings);
441
+ const declaredDependencies = (manifest) => pipe(Record.toEntries({
442
+ ...manifest.dependencies,
443
+ ...manifest.devDependencies,
444
+ ...manifest.peerDependencies
445
+ }), Array.filter(([, range]) => !String$1.startsWith(WORKSPACE_PROTOCOL)(range)), Array.map(([packageName]) => packageName));
446
+ const workspaceDependencies = (manifest) => pipe(Record.toEntries({
447
+ ...manifest.dependencies,
448
+ ...manifest.devDependencies
449
+ }), Array.filter(([, range]) => String$1.startsWith(WORKSPACE_PROTOCOL)(range)), Array.map(([packageName]) => packageName));
450
+ const entryOrder = Order.mapInput(Order.String, (entry) => entry.specifier);
451
+ const dependencyEntries = Effect.fn("dependencyEntries")(function* dependencyEntries(packageDirectory) {
452
+ const files = yield* RepositoryFiles;
453
+ const manifest = yield* readManifest(packageDirectory);
454
+ if (Option.isNone(manifest)) return [];
455
+ const entries = yield* Effect.forEach(declaredDependencies(manifest.value), (packageName) => entriesOfDependency(packageName, files.join(packageDirectory, NODE_MODULES, packageName)), { concurrency: 1 });
456
+ return Array.sort(Array.dedupeWith(entries.flat(), (left, right) => left.specifier === right.specifier), entryOrder);
409
457
  });
410
- const programOf = Effect.fn("programOf")(function* programOf(file, text) {
411
- const parsed = yield* Effect.promise(() => parse(file, text, { lang: "ts" }));
412
- if (Array.isReadonlyArrayNonEmpty(parsed.errors)) return yield* settingsInvalid(file)("vite.config.ts does not parse.");
413
- return parsed.program;
458
+ // src/entities/package/model/public-entries.ts
459
+ const SOURCE = /\.[cm]?tsx?$/u;
460
+ const BUILT = /\.(?:d\.)?[cm]?[jt]s$/u;
461
+ const DECLARATION = ".d.";
462
+ const SEPARATOR$1 = "/";
463
+ const ROOT_SUBPATH = ".";
464
+ const BIN_LABEL = "bin";
465
+ const targetsIn = (held) => {
466
+ if (Predicate.isString(held)) return [held];
467
+ if (!Predicate.isObject(held)) return [];
468
+ return pipe(Record.values(held), Array.flatMap(targetsIn));
469
+ };
470
+ const subpathsOf = (exportsField) => {
471
+ if (!Predicate.isObject(exportsField)) return [[ROOT_SUBPATH, exportsField]];
472
+ const entries = Record.toEntries(exportsField);
473
+ if (pipe(entries, Array.some(([key]) => String$1.startsWith(ROOT_SUBPATH)(key)))) return entries;
474
+ return [[ROOT_SUBPATH, exportsField]];
475
+ };
476
+ const binsOf = (manifest) => {
477
+ if (Predicate.isString(manifest.bin)) {
478
+ const name = Option.getOrElse(Option.fromUndefinedOr(manifest.name), () => "");
479
+ return [[`${BIN_LABEL} ${name}`, manifest.bin]];
480
+ }
481
+ if (!Predicate.isObject(manifest.bin)) return [];
482
+ return pipe(Record.toEntries(manifest.bin), Array.map(([name, target]) => [`${BIN_LABEL} ${name}`, target]));
483
+ };
484
+ const baseNameOf = (target) => pipe(String$1.split(target, SEPARATOR$1), Array.last, Option.getOrElse(() => target), String$1.replace(BUILT, ""));
485
+ const sourceOf = ({ join, packEntries }) => (target) => {
486
+ if (SOURCE.test(target) && !String$1.includes(DECLARATION)(target)) return Option.some(join(target));
487
+ const name = baseNameOf(target);
488
+ return pipe(packEntries, Array.findFirst((entry) => entry.name === name), Option.map((entry) => entry.source));
489
+ };
490
+ const publicEntriesOf = (lookup) => pipe([...subpathsOf(lookup.manifest.exports), ...binsOf(lookup.manifest)], Array.flatMap(([label, held]) => pipe(targetsIn(held), Array.map(sourceOf(lookup)), Array.getSomes, Array.map((source) => ({
491
+ label,
492
+ source
493
+ })))), Array.dedupeWith((left, right) => left.label === right.label && left.source === right.source));
494
+ const EntryManifestFields = Schema.Struct({
495
+ name: Schema.optional(Schema.String),
496
+ exports: Schema.optional(Schema.Unknown),
497
+ bin: Schema.optional(Schema.Unknown)
414
498
  });
415
- const workspaceConfigOf = Effect.fn("workspaceConfigOf")(function* workspaceConfigOf(root, directory) {
416
- const files = yield* RepositoryFiles;
417
- const file = files.join(root, directory, CONFIG_FILE);
418
- const text = yield* files.readFile(file);
419
- if (Option.isNone(text)) return Option.none();
420
- const program = yield* programOf(file, text.value);
421
- return Option.some({
422
- file,
423
- source: text.value,
424
- program
425
- });
499
+ const EntryManifestJson = Schema.fromJsonString(EntryManifestFields);
500
+ // src/entities/package/model/published.ts
501
+ const CONFIG_FILE = "vite.config.ts";
502
+ const SEPARATOR = "/";
503
+ const READ_CONCURRENCY = 16;
504
+ const SOURCE_EXTENSION = /\.[cm]?tsx?$/u;
505
+ const UNIT_BYTES = [
506
+ ["B", 1],
507
+ ["kB", 1e3],
508
+ ["MB", 1e6]
509
+ ];
510
+ const SizeText = Schema.TemplateLiteralParser([
511
+ Schema.Finite,
512
+ " ",
513
+ Schema.Literals([
514
+ "B",
515
+ "kB",
516
+ "MB"
517
+ ])
518
+ ]);
519
+ const PackEntry = Schema.Union([
520
+ Schema.String,
521
+ Schema.Array(Schema.String),
522
+ Schema.Record(Schema.String, Schema.String)
523
+ ]);
524
+ const PackSettings = Schema.Struct({ entry: Schema.optional(PackEntry) });
525
+ const PackList = Schema.Union([PackSettings, Schema.Array(PackSettings)]);
526
+ const isEntryList = Schema.is(Schema.Array(Schema.String));
527
+ const WorkspaceConfig = Schema.Struct({
528
+ msch: Schema.Struct({ publish: Schema.Struct({ installSize: SizeText }) }),
529
+ pack: Schema.optional(PackList)
426
530
  });
427
- // src/entities/workspace/model/workspace-tasks.ts
428
- const VERIFY_TASK = ["tasks", "verify"];
429
- const RUN_TASKS = ["run", "tasks"];
430
- const NO_TASKS = { verify: [] };
431
- const Tasks = Schema.Struct({ verify: Schema.Unknown });
432
- const isVerified = Schema.is(Schema.Struct({ run: Schema.Struct({ tasks: Tasks }) }));
433
- const definesTask = (path) => (program) => Array.isReadonlyArrayNonEmpty(nestedValues(path)(program));
434
- const hasVerifyTask = Effect.fn("hasVerifyTask")(function* hasVerifyTask(file) {
531
+ const PublicManifest = Schema.Struct({ private: Schema.optional(Schema.Literal(false)) });
532
+ const taggedError = Schema.TaggedError;
533
+ var WorkspaceConfigUnreadable = class extends taggedError()("WorkspaceConfigUnreadable", { file: Schema.String }) {};
534
+ const bytesPer = (unit) => pipe(UNIT_BYTES, Array.findFirst(([name]) => name === unit), Option.map(([, bytes]) => bytes), Option.getOrElse(() => NaN));
535
+ const nameOf = (source) => pipe(String$1.split(source, SEPARATOR), Array.last, Option.getOrElse(() => source), String$1.replace(SOURCE_EXTENSION, ""));
536
+ const entriesOf = (entry) => {
537
+ if (Predicate.isString(entry)) return [{
538
+ name: nameOf(entry),
539
+ source: entry
540
+ }];
541
+ if (isEntryList(entry)) return pipe(entry, Array.map((source) => ({
542
+ name: nameOf(source),
543
+ source
544
+ })));
545
+ return pipe(Record.toEntries(entry), Array.map(([name, source]) => ({
546
+ name,
547
+ source
548
+ })));
549
+ };
550
+ const packEntriesOf = (pack) => pipe(Option.fromUndefinedOr(pack), Option.map(Array.ensure), Option.getOrElse(() => []), Array.flatMap((setting) => pipe(Option.fromUndefinedOr(setting.entry), Option.match({
551
+ onNone: () => [],
552
+ onSome: entriesOf
553
+ }))));
554
+ const settingsIn = Effect.fn("settingsIn")(function* settingsIn(file) {
435
555
  const config = yield* Effect.tryPromise({
436
556
  try: () => resolveConfigFromFile(file),
437
- catch: () => settingsInvalid(file)("vite.config.ts does not load.")
557
+ catch: () => WorkspaceConfigUnreadable.make({ file })
438
558
  }).pipe(Effect.option);
439
- return Option.exists(config, isVerified);
440
- });
441
- const tasksOf = (manifest) => (program) => pipe(manifest, Option.flatMap((found) => Option.fromUndefinedOr(found.name)), Option.match({
442
- onNone: () => NO_TASKS,
443
- onSome: (name) => ({ verify: Array.filter([`${name}#verify`], () => definesTask(VERIFY_TASK)(program)) })
444
- }));
445
- // src/entities/workspace/model/run-tasks.ts
446
- const TaskProperty = Schema.Struct({
447
- type: Schema.Literal("Property"),
448
- computed: Schema.Literal(false),
449
- key: KeySchema,
450
- value: Schema.Unknown,
451
- start: Schema.Finite
452
- });
453
- const TaskObject = Schema.Struct({
454
- type: Schema.Literal("ObjectExpression"),
455
- properties: Schema.Array(Schema.Unknown)
456
- });
457
- const decodeTaskProperty = Schema.decodeUnknownOption(TaskProperty);
458
- const decodeTaskObject = Schema.decodeUnknownOption(TaskObject);
459
- const tasksIn = (program) => pipe(nestedValues(RUN_TASKS)(program), Array.flatMap((tasks) => pipe(decodeTaskObject(tasks), Option.map(({ properties }) => properties), Option.getOrElse(() => []))), Array.flatMap((property) => Option.toArray(decodeTaskProperty(property))));
460
- const runTasksOf = Effect.fn("runTasksOf")(function* runTasksOf(root, directory) {
461
- const config = yield* workspaceConfigOf(root, directory);
462
- return pipe(config, Option.map(({ file, source, program }) => ({
463
- file,
464
- source,
465
- tasks: tasksIn(program)
466
- })));
559
+ return pipe(config, Option.flatMap(Schema.decodeUnknownOption(WorkspaceConfig)));
467
560
  });
468
- // src/entities/workspace/model/workspace-unreadable.ts
469
- const taggedError = Schema.TaggedError;
470
- var WorkspaceUnreadable = class extends taggedError()("WorkspaceUnreadable", {
471
- root: Schema.String,
472
- reason: Schema.String
473
- }) {};
474
- // src/entities/workspace/model/workspace-manifest.ts
475
- /** @internal */
476
- const workspaceManifest = (root) => Effect.tryPromise({
477
- try: () => readWorkspaceManifest(root),
478
- catch: (cause) => WorkspaceUnreadable.make({
479
- root,
480
- reason: String(cause)
481
- })
482
- }).pipe(Effect.map(Option.fromUndefinedOr), Effect.orElseSucceed(() => Option.none()));
483
- // src/entities/workspace/model/workspace-projects.ts
484
- const byDirectory = Order.mapInput(String$1.Order, ({ directory }) => directory);
485
- const projectsMatching = (root, patterns) => Effect.tryPromise({
486
- try: () => findWorkspaceProjectsNoCheck(root, { patterns: [...patterns] }),
487
- catch: (cause) => WorkspaceUnreadable.make({
488
- root,
489
- reason: String(cause)
490
- })
491
- }).pipe(Effect.orElseSucceed(() => []));
492
- /** @internal */
493
- const workspaceProjects = Effect.fn("workspaceProjects")(function* workspaceProjects(root) {
561
+ const isPublicPackage = Effect.fn("isPublicPackage")(function* isPublicPackage(directory) {
494
562
  const files = yield* RepositoryFiles;
495
- const manifest = yield* workspaceManifest(root);
496
- const patterns = pipe(manifest, Option.flatMap(({ packages }) => Option.fromNullishOr(packages)), Option.getOrElse(() => []));
497
- if (!Array.isReadonlyArrayNonEmpty(patterns)) return [];
498
- const projects = yield* projectsMatching(root, patterns);
499
- const found = pipe(projects, Array.map(({ rootDir, manifest: own }) => ({
500
- directory: files.relative(root, rootDir),
501
- packageName: Option.fromUndefinedOr(own.name),
502
- published: own.private !== true,
503
- keywords: Option.getOrElse(Option.fromUndefinedOr(own.keywords), () => []),
504
- files: Option.fromUndefinedOr(own.files)
505
- })), Array.filter(({ directory }) => String$1.isNonEmpty(directory)));
506
- return Array.sort(found, byDirectory);
507
- });
508
- /** @internal */
509
- const workspaceDirectories = Effect.fn("workspaceDirectories")(function* workspaceDirectories(root) {
510
- const projects = yield* workspaceProjects(root);
511
- return pipe(projects, Array.map(({ directory }) => directory));
563
+ const text = yield* files.readFile(files.join(directory, MANIFEST_FILE));
564
+ return Option.exists(text, (found) => Option.isSome(Schema.decodeOption(Schema.fromJsonString(PublicManifest))(found)));
512
565
  });
513
- // src/entities/workspace/model/workspace-patterns.ts
514
- const SEPARATOR = "/";
515
- const NEGATION = "!";
516
- const RELATIVE = "./";
517
- const withoutRelative = (target) => {
518
- if (String$1.startsWith(RELATIVE)(target)) return String$1.slice(2)(target);
519
- return target;
520
- };
521
- const prefixed = (directory) => (pattern) => {
522
- if (String$1.startsWith(NEGATION)(pattern)) return `${NEGATION}${directory}${SEPARATOR}${String$1.slice(1)(pattern)}`;
523
- return `${directory}${SEPARATOR}${withoutRelative(pattern)}`;
524
- };
525
- // src/entities/workspace/model/workspace-names.ts
526
- const ALTERNATIVE = "|";
527
- const SCOPE = /^@[^/]+\//u;
528
- const SPECIAL = /[$()*+.?[\\\]^{|}]/gu;
529
- /** @internal */
530
- const patternOf = (names) => {
531
- const alternatives = pipe(names, Array.map(String$1.replaceAll(SPECIAL, String.raw`\$&`)));
532
- return new RegExp(`(?<![\\p{L}\\p{N}_-])(?:${Array.join(alternatives, ALTERNATIVE)})(?![\\p{L}\\p{N}_-])`, "gu");
533
- };
534
- const namedIn = (basename) => ({ directory, packageName }) => {
535
- const unscoped = pipe(packageName, Option.map(String$1.replace(SCOPE, "")));
566
+ const workspaceOf = (directory, configFile, join) => ({ msch, pack }) => {
567
+ const [amount, , unit] = msch.publish.installSize;
536
568
  return {
537
569
  directory,
538
- names: pipe([
539
- Option.some(directory),
540
- Option.some(basename(directory)),
541
- packageName,
542
- unscoped
543
- ], Array.getSomes, Array.dedupe),
544
- packageName
570
+ configFile,
571
+ installSize: `${amount} ${unit}`,
572
+ installBudget: amount * bytesPer(unit),
573
+ packEntries: pipe(packEntriesOf(pack), Array.map((entry) => ({
574
+ name: entry.name,
575
+ source: join(entry.source)
576
+ })))
545
577
  };
546
578
  };
547
- /** @internal */
548
- const namedWorkspaces = Effect.fn("namedWorkspaces")(function* namedWorkspaces(root) {
579
+ const publishedIn = Effect.fn("publishedIn")(function* publishedIn(root, configName) {
549
580
  const files = yield* RepositoryFiles;
550
- const projects = yield* workspaceProjects(root);
551
- return pipe(projects, Array.map(namedIn((directory) => files.basename(directory))));
581
+ const configFile = files.join(root, configName);
582
+ const directory = files.dirname(configFile);
583
+ if (!(yield* isPublicPackage(directory))) return Option.none();
584
+ const settings = yield* settingsIn(configFile);
585
+ return pipe(settings, Option.map(workspaceOf(directory, configFile, (source) => files.join(directory, source))));
552
586
  });
553
- // src/entities/workspace/model/deploy-entries.ts
554
- const MAIN_KEY = "main";
555
- const READ_CONCURRENCY = 16;
556
- const SCRIPT = /\.[cm]?tsx?$/u;
557
- const SKIPPED = /\.test\.|\.d\.[cm]?ts$/u;
558
- const ALCHEMY_IMPORT = /from\s+["'](?:alchemy|@alchemy\.run)(?:\/[^"']*)?["']/u;
559
- const MAIN_PROPERTY = /\bmain\s*:/u;
560
- const decodeKey = Schema.decodeUnknownOption(KeySchema);
561
- const isMainProperty = (node) => node["type"] === "Property" && pipe(decodeKey(node["key"]), Option.exists((key) => keyName(key) === MAIN_KEY));
562
- const mainTargetsIn = (node) => {
563
- if (Predicate.isReadonlyObject(node) && isMainProperty(node)) return pipe(stringsIn(node["value"]), Array.head, Option.map(({ text }) => text), Option.toArray);
564
- return pipe(childrenOf(node), Array.flatMap(mainTargetsIn));
565
- };
566
- const declaredIn = Effect.fn("declaredIn")(function* declaredIn(root, file) {
587
+ /** @internal */
588
+ const publishedWorkspaces = Effect.fn("publishedWorkspaces")(function* publishedWorkspaces(root) {
567
589
  const files = yield* RepositoryFiles;
568
- const text = yield* files.readFile(files.join(root, file));
569
- if (Option.isNone(text) || !ALCHEMY_IMPORT.test(text.value) || !MAIN_PROPERTY.test(text.value)) return [];
570
- const parsed = yield* Effect.promise(() => parse(file, text.value, { lang: "ts" }));
571
- return pipe(mainTargetsIn(parsed.program), Array.map((target) => files.join(files.dirname(file), target)));
572
- });
573
- const deployEntries = Effect.fn("deployEntries")(function* deployEntries(root) {
574
- const listed = yield* (yield* RepositoryFiles).listedFiles(root);
575
- const declaring = pipe(listed, Array.filter((file) => SCRIPT.test(file) && !SKIPPED.test(file)));
576
- const found = yield* Effect.forEach(declaring, (file) => declaredIn(root, file), { concurrency: READ_CONCURRENCY });
577
- return pipe(Array.flatten(found), Array.filter((file) => Array.contains(listed, file)), Array.dedupe);
590
+ const names = yield* files.listedFiles(root);
591
+ const configs = pipe(names, Array.filter((name) => files.basename(name) === CONFIG_FILE && String$1.includes(SEPARATOR)(name)));
592
+ const found = yield* Effect.forEach(configs, (name) => publishedIn(root, name), { concurrency: READ_CONCURRENCY });
593
+ return Array.getSomes(found);
578
594
  });
579
- export { entriesOf as A, childrenOf as C, propertyValue as D, nestedValues as E, dependencyEntries as F, readManifest as I, workspaceDependencies as L, EntryManifestJson as M, publicEntriesOf as N, stringsIn as O, MANIFEST_FILE as P, KeySchema as S, literalOf as T, merged as _, withoutRelative as a, usedFrom as b, workspaceManifest as c, RUN_TASKS as d, VERIFY_TASK as f, literalSettings as g, tasksOf as h, prefixed as i, publishedWorkspaces as j, PackEntry as k, runTasksOf as l, hasVerifyTask as m, namedWorkspaces as n, workspaceDirectories as o, definesTask as p, patternOf as r, workspaceProjects as s, deployEntries as t, NO_TASKS as u, programOf as v, keyName as w, workspaceConfigOf as x, settingsInvalid as y };
595
+ export { usedFrom as A, definesTask as C, merged as D, literalSettings as E, literalOf as F, nestedValues as I, propertyValue as L, KeySchema as M, childrenOf as N, programOf as O, keyName as P, stringsIn as R, VERIFY_TASK as S, tasksOf as T, workspaceProjects as _, publicEntriesOf as a, NO_TASKS as b, readManifest as c, deployEntries as d, namedWorkspaces as f, workspaceDirectories as g, withoutRelative as h, EntryManifestJson as i, workspaceConfigOf as j, settingsInvalid as k, workspaceDependencies as l, prefixed as m, entriesOf as n, MANIFEST_FILE as o, patternOf as p, publishedWorkspaces as r, dependencyEntries as s, PackEntry as t, lockedPackages as u, workspaceManifest as v, hasVerifyTask as w, RUN_TASKS as x, runTasksOf as y };
580
596
 
581
- //# sourceMappingURL=workspace-BNAwy85Z.mjs.map
597
+ //# sourceMappingURL=package-DU5r3bvx.mjs.map