@astryxdesign/cli 0.7.11-canary.9b7ebc4 → 0.7.11-canary.a646669

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.
@@ -30,3 +30,4 @@ export function resolveCore(cwd: string): {
30
30
  components: string[];
31
31
  };
32
32
  export { CORE_PROVIDER_ID as CORE_PACKAGE } from "../../foundation/identity/providers.mjs";
33
+ export { planCopy, relativeSpecifierBetween, renderFile } from "./_moduleGraph.mjs";
@@ -9,7 +9,8 @@
9
9
  * for its "component not found" suggestions. Resolving core + listing lives
10
10
  * here once so neither leaf re-walks the filesystem. Throws AstryxError
11
11
  * (ERR_CORE_NOT_FOUND) when core can't be located. The copy receipt's `gh`
12
- * lookup is here too, on the shared search-path walk.
12
+ * lookup is here too, on the shared search-path walk, and so is the copy's
13
+ * module graph (_moduleGraph.mjs), which reads the owner package's source.
13
14
  */
14
15
 
15
16
  import {executablesOnSearchPath} from '../../foundation/env/search-path.mjs';
@@ -18,6 +19,8 @@ import {resolveComponentReplacements} from '../../foundation/discovery/component
18
19
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
19
20
  import {AstryxError} from '../error.mjs';
20
21
 
22
+ export {planCopy, relativeSpecifierBetween, renderFile} from './_moduleGraph.mjs';
23
+
21
24
  /**
22
25
  * Whether an executable `gh` is on `PATH` (with a `PATHEXT` extension on
23
26
  * Windows), found without running it. The copy receipt offers its
@@ -0,0 +1,162 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * A specifier that is either fixed (a public subpath) or computed from where
6
+ * two copied files land.
7
+ * @typedef {string | {from: string, to: string}} SpecifierChoice
8
+ *
9
+ * @typedef {object} PlannedEdit
10
+ * @property {number} start
11
+ * @property {number} end
12
+ * @property {(specifierOf: (choice: SpecifierChoice) => string) => string} render
13
+ *
14
+ * @typedef {object} CopyPlan
15
+ * @property {Map<string, {code: string, edits: PlannedEdit[]}>} files every
16
+ * file the copy holds (absolute source path), with the edits its imports need
17
+ * @property {Map<string, Set<string>>} dependsOn file -> carried files its
18
+ * computed specifiers point at
19
+ */
20
+ /**
21
+ * Follow a component's module graph from its entry files and decide what the
22
+ * copy holds. A module inside the component folder is copied. A module
23
+ * outside it is reached through the owner package's public exports when every
24
+ * name taken from it is public there; otherwise the module that defines the
25
+ * name is copied, and imported by relative path. Tests, stories and docs are
26
+ * never reached, so they are never copied.
27
+ *
28
+ * @param {object} options
29
+ * @param {string} options.packageDir the owner package root
30
+ * @param {string} options.srcRoot its source root
31
+ * @param {string} options.componentDir
32
+ * @param {string} options.ownerPackage
33
+ * @param {string[]} options.entries absolute entry files of the component
34
+ * @returns {CopyPlan}
35
+ */
36
+ export function planCopy({ packageDir, srcRoot, componentDir, ownerPackage, entries, }: {
37
+ packageDir: string;
38
+ srcRoot: string;
39
+ componentDir: string;
40
+ ownerPackage: string;
41
+ entries: string[];
42
+ }): CopyPlan;
43
+ /**
44
+ * The source of a planned file with its edits applied.
45
+ * @param {{code: string, edits: PlannedEdit[]}} planned
46
+ * @param {(choice: SpecifierChoice) => string} specifierOf
47
+ */
48
+ export function renderFile(planned: {
49
+ code: string;
50
+ edits: PlannedEdit[];
51
+ }, specifierOf: (choice: SpecifierChoice) => string): string;
52
+ /**
53
+ * The relative specifier from one written file to another.
54
+ * @param {string} fromDest
55
+ * @param {string} toDest
56
+ */
57
+ export function relativeSpecifierBetween(fromDest: string, toDest: string): string;
58
+ export type ImportSpecifier = {
59
+ /**
60
+ * the exported name (`default` for a default import)
61
+ */
62
+ imported: string;
63
+ local: string;
64
+ typeOnly: boolean;
65
+ };
66
+ export type ModuleReference = {
67
+ kind: "named" | "namespace" | "sideEffect" | "dynamic" | "reexportAll" | "reexportNamed";
68
+ /**
69
+ * the specifier as written
70
+ */
71
+ source: string;
72
+ /**
73
+ * statement (or, for `import()`, string literal) start
74
+ */
75
+ start: number;
76
+ end: number;
77
+ /**
78
+ * the whole statement is `import type` / `export type`
79
+ */
80
+ typeOnly: boolean;
81
+ specifiers: ImportSpecifier[];
82
+ /**
83
+ * the local name of `* as X`
84
+ */
85
+ namespace?: string | undefined;
86
+ };
87
+ export type ParsedModule = {
88
+ code: string;
89
+ references: ModuleReference[];
90
+ /**
91
+ * names the module declares and exports
92
+ */
93
+ declares: Set<string>;
94
+ };
95
+ /**
96
+ * `value` reads runtime exports only;
97
+ * `type` reads type-only exports too
98
+ */
99
+ export type ExportKind = "value" | "type";
100
+ /**
101
+ * every name a module exports, with where it is declared
102
+ */
103
+ export type OriginsOf = (file: string, kind: ExportKind) => Map<string, {
104
+ file: string;
105
+ name: string;
106
+ }>;
107
+ /**
108
+ * `file#name` of a declaration -> the subpaths that export it, and as what
109
+ */
110
+ export type ExportersByOrigin = Map<string, Array<{
111
+ subpath: string;
112
+ name: string;
113
+ }>>;
114
+ export type PublicSurface = {
115
+ /**
116
+ * the subpaths
117
+ * that export each declaration as a value, and as a value or a type
118
+ */
119
+ byOrigin: Record<ExportKind, ExportersByOrigin>;
120
+ /**
121
+ * source file -> the subpath that
122
+ * exports exactly that file
123
+ */
124
+ byFile: Map<string, string>;
125
+ exportsField: Record<string, unknown> | undefined;
126
+ };
127
+ /**
128
+ * A specifier that is either fixed (a public subpath) or computed from where
129
+ * two copied files land.
130
+ */
131
+ export type SpecifierChoice = string | {
132
+ from: string;
133
+ to: string;
134
+ };
135
+ /**
136
+ * A specifier that is either fixed (a public subpath) or computed from where
137
+ * two copied files land.
138
+ */
139
+ export type PlannedEdit = {
140
+ start: number;
141
+ end: number;
142
+ render: (specifierOf: (choice: SpecifierChoice) => string) => string;
143
+ };
144
+ /**
145
+ * A specifier that is either fixed (a public subpath) or computed from where
146
+ * two copied files land.
147
+ */
148
+ export type CopyPlan = {
149
+ /**
150
+ * every
151
+ * file the copy holds (absolute source path), with the edits its imports need
152
+ */
153
+ files: Map<string, {
154
+ code: string;
155
+ edits: PlannedEdit[];
156
+ }>;
157
+ /**
158
+ * file -> carried files its
159
+ * computed specifiers point at
160
+ */
161
+ dependsOn: Map<string, Set<string>>;
162
+ };