@layerzerolabs/build-utils-rust 1.2.68 → 1.2.70
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/bin/build-utils-rust.js +3 -0
- package/dist/2T2WFWNM.js +57 -0
- package/dist/2T2WFWNM.js.map +1 -0
- package/dist/N2QRCDCB.js +115 -0
- package/dist/N2QRCDCB.js.map +1 -0
- package/dist/N4NI6N3K.js +83 -0
- package/dist/N4NI6N3K.js.map +1 -0
- package/dist/UDDAJZY4.js +26 -0
- package/dist/UDDAJZY4.js.map +1 -0
- package/dist/VUOMXK5T.js +6 -0
- package/dist/VUOMXK5T.js.map +1 -0
- package/dist/ZQ7KHDAO.js +52 -0
- package/dist/ZQ7KHDAO.js.map +1 -0
- package/dist/ZS7IDLZZ.js +59 -0
- package/dist/ZS7IDLZZ.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +27 -0
- package/dist/cli.js.map +1 -0
- package/{src/index.ts → dist/index.d.ts} +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +4 -0
- package/dist/logger.js.map +1 -0
- package/dist/resolve/discover.d.ts +23 -0
- package/dist/resolve/discover.d.ts.map +1 -0
- package/dist/resolve/discover.js +7 -0
- package/dist/resolve/discover.js.map +1 -0
- package/dist/resolve/exclude.d.ts +10 -0
- package/dist/resolve/exclude.d.ts.map +1 -0
- package/dist/resolve/exclude.js +4 -0
- package/dist/resolve/exclude.js.map +1 -0
- package/dist/resolve/index.d.ts +20 -0
- package/dist/resolve/index.d.ts.map +1 -0
- package/dist/resolve/index.js +9 -0
- package/dist/resolve/index.js.map +1 -0
- package/dist/resolve/io.d.ts +17 -0
- package/dist/resolve/io.d.ts.map +1 -0
- package/dist/resolve/io.js +6 -0
- package/dist/resolve/io.js.map +1 -0
- package/dist/resolve/rewrite.d.ts +41 -0
- package/dist/resolve/rewrite.d.ts.map +1 -0
- package/dist/resolve/rewrite.js +8 -0
- package/dist/resolve/rewrite.js.map +1 -0
- package/package.json +9 -6
- package/src/cli.ts +0 -33
- package/src/logger.ts +0 -26
- package/src/resolve/discover.ts +0 -93
- package/src/resolve/exclude.ts +0 -58
- package/src/resolve/index.ts +0 -122
- package/src/resolve/io.ts +0 -69
- package/src/resolve/rewrite.ts +0 -231
- package/tests/resolve/discover.test.ts +0 -208
- package/tests/resolve/fixtures/index.ts +0 -6
- package/tests/resolve/fixtures/minimal.toml +0 -2
- package/tests/resolve/fixtures/mixed-deps.toml +0 -4
- package/tests/resolve/fixtures/multi-path-deps.toml +0 -9
- package/tests/resolve/fixtures/multi-section-path-deps.toml +0 -13
- package/tests/resolve/fixtures/no-path-deps.toml +0 -3
- package/tests/resolve/fixtures/oapp-with-stale-deps.toml +0 -5
- package/tests/resolve/fixtures/oft-core-with-stale-deep-deps.toml +0 -11
- package/tests/resolve/fixtures/patch-multi-registry.toml +0 -22
- package/tests/resolve/fixtures/program-with-deps.toml +0 -5
- package/tests/resolve/fixtures/program-with-macros.toml +0 -6
- package/tests/resolve/fixtures/program-workspace-member.toml +0 -5
- package/tests/resolve/fixtures/root-only-sections.toml +0 -13
- package/tests/resolve/fixtures/stellar-consumer.toml +0 -8
- package/tests/resolve/fixtures/stellar-member-inheriting.toml +0 -10
- package/tests/resolve/fixtures/stellar-workspace-root.toml +0 -17
- package/tests/resolve/fixtures/stellar-workspace-with-tests.toml +0 -15
- package/tests/resolve/fixtures/target-cfg-path-dep.toml +0 -10
- package/tests/resolve/fixtures/with-features.toml +0 -2
- package/tests/resolve/fixtures/workspace-at-end.toml +0 -6
- package/tests/resolve/fixtures/workspace-at-top.toml +0 -10
- package/tests/resolve/fixtures/workspace-middle.toml +0 -10
- package/tests/resolve/fixtures/workspace-with-default-members.toml +0 -8
- package/tests/resolve/fixtures/workspace-with-path-deps.toml +0 -8
- package/tests/resolve/index.test.ts +0 -468
- package/tests/resolve/rewrite.test.ts +0 -507
- package/tsconfig.json +0 -21
- package/tsup.config.ts +0 -8
package/src/resolve/rewrite.ts
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rewrite a vendored Cargo.toml's path deps into the flat dependencies/ layout,
|
|
3
|
-
* operating on the parsed TOML (via smol-toml) rather than text.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { readFile, writeFile } from 'fs/promises';
|
|
7
|
-
import { dirname, join, relative } from 'path';
|
|
8
|
-
import { parse, stringify } from 'smol-toml';
|
|
9
|
-
|
|
10
|
-
import { logger } from '../logger';
|
|
11
|
-
import { isWorkspaceRoot } from './discover';
|
|
12
|
-
import { hasExcludedSegment } from './exclude';
|
|
13
|
-
import { type CollectedTree, tryRealpath } from './io';
|
|
14
|
-
|
|
15
|
-
/** Bundled resolution state passed through the rewrite pipeline. */
|
|
16
|
-
export interface RewriteContext {
|
|
17
|
-
pathMap: Map<string, string>;
|
|
18
|
-
discovered: Map<string, string>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type Table = Record<string, unknown>;
|
|
22
|
-
|
|
23
|
-
/** A dependency spec that carries a `path` — an inline table like `{ path = "…" }`. */
|
|
24
|
-
type PathDepSpec = Table & { path: string };
|
|
25
|
-
|
|
26
|
-
const isTable = (value: unknown): value is Table =>
|
|
27
|
-
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
28
|
-
|
|
29
|
-
const DEP_TABLE_KEYS = ['dependencies', 'dev-dependencies', 'build-dependencies'] as const;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Dependency specs that declare a `path`, across every dependency table (plus
|
|
33
|
-
* `[workspace.dependencies]` when `includeWorkspaceDeps`). Specs are live references
|
|
34
|
-
* into `manifest`, so mutating `.path` updates it.
|
|
35
|
-
*/
|
|
36
|
-
const pathDepSpecs = (manifest: Table, includeWorkspaceDeps: boolean): PathDepSpec[] => {
|
|
37
|
-
// The root manifest and each [target.'cfg(...)'] table both hold DEP_TABLE_KEYS tables.
|
|
38
|
-
const containers = [
|
|
39
|
-
manifest,
|
|
40
|
-
...(isTable(manifest.target) ? Object.values(manifest.target).filter(isTable) : []),
|
|
41
|
-
];
|
|
42
|
-
|
|
43
|
-
const depTables = [
|
|
44
|
-
...containers.flatMap((container) => DEP_TABLE_KEYS.map((key) => container[key])),
|
|
45
|
-
...(includeWorkspaceDeps && isTable(manifest.workspace)
|
|
46
|
-
? [manifest.workspace.dependencies]
|
|
47
|
-
: []),
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
return depTables
|
|
51
|
-
.filter(isTable)
|
|
52
|
-
.flatMap((table) => Object.values(table))
|
|
53
|
-
.filter((spec): spec is PathDepSpec => isTable(spec) && typeof spec.path === 'string');
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Drop literal `members` / `default-members` entries whose path contains an excluded
|
|
58
|
-
* directory segment (e.g. `tests/mock_vault`) — those dirs are never vendored, so the
|
|
59
|
-
* member would dangle and fail Cargo's workspace load. Globs (`tests/*`) are kept; Cargo
|
|
60
|
-
* re-expands them to a harmless empty match. Returns true if any member was removed.
|
|
61
|
-
*/
|
|
62
|
-
export const pruneExcludedLiteralMembers = (manifest: Table): boolean => {
|
|
63
|
-
const workspace = manifest.workspace;
|
|
64
|
-
if (!isTable(workspace)) return false;
|
|
65
|
-
|
|
66
|
-
let changed = false;
|
|
67
|
-
for (const key of ['members', 'default-members'] as const) {
|
|
68
|
-
const members = workspace[key];
|
|
69
|
-
if (!Array.isArray(members)) continue;
|
|
70
|
-
|
|
71
|
-
// Keep everything except literal (non-glob) members inside an excluded dir.
|
|
72
|
-
const kept = members.filter(
|
|
73
|
-
(m) => typeof m !== 'string' || m.includes('*') || !hasExcludedSegment(m),
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
if (kept.length !== members.length) {
|
|
77
|
-
workspace[key] = kept;
|
|
78
|
-
changed = true;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return changed;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
/** Rebase every path dep in `manifest` into the flat dependencies/ layout. Returns true if any changed. */
|
|
85
|
-
export const rewritePathDeps = async (
|
|
86
|
-
manifest: Table,
|
|
87
|
-
originalDir: string,
|
|
88
|
-
manifestDir: string,
|
|
89
|
-
ctx: RewriteContext,
|
|
90
|
-
includeWorkspaceDeps: boolean,
|
|
91
|
-
): Promise<boolean> => {
|
|
92
|
-
let changed = false;
|
|
93
|
-
for (const spec of pathDepSpecs(manifest, includeWorkspaceDeps)) {
|
|
94
|
-
const target =
|
|
95
|
-
(await resolveViaRealpath(originalDir, spec.path, ctx.pathMap)) ??
|
|
96
|
-
resolveViaNameFallback(spec.path, ctx);
|
|
97
|
-
if (!target) continue;
|
|
98
|
-
|
|
99
|
-
const rewritten = relative(manifestDir, target);
|
|
100
|
-
if (rewritten === spec.path) continue;
|
|
101
|
-
|
|
102
|
-
logger.trace(`rewrite path dep ${spec.path} -> ${rewritten}`);
|
|
103
|
-
spec.path = rewritten;
|
|
104
|
-
changed = true;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return changed;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Delete the `[workspace]` / `[patch.*]` / `[profile.*]` tables — invalid or ignored in a
|
|
112
|
-
* vendored dependency (only honored at the real workspace root). Returns true if any was removed.
|
|
113
|
-
*/
|
|
114
|
-
export const stripRootOnlyTables = (manifest: Table): boolean => {
|
|
115
|
-
let changed = false;
|
|
116
|
-
for (const table of ['workspace', 'patch', 'profile'] as const) {
|
|
117
|
-
if (manifest[table] != null) {
|
|
118
|
-
delete manifest[table];
|
|
119
|
-
changed = true;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return changed;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Rewrite one vendored Cargo.toml in place: rebase its path deps, then strip the root-only
|
|
127
|
-
* tables — or, for a preserved workspace root (`stripRootTables = false`), prune excluded
|
|
128
|
-
* members instead. Re-serialized only if something changed.
|
|
129
|
-
*
|
|
130
|
-
* @param originalDir source crate dir the manifest was copied from
|
|
131
|
-
* @param cargoTomlPath the vendored Cargo.toml to rewrite
|
|
132
|
-
*/
|
|
133
|
-
export const rewriteCargoToml = async (
|
|
134
|
-
originalDir: string,
|
|
135
|
-
cargoTomlPath: string,
|
|
136
|
-
ctx: RewriteContext,
|
|
137
|
-
stripRootTables = true,
|
|
138
|
-
): Promise<void> => {
|
|
139
|
-
const manifest = parse(await readFile(cargoTomlPath, 'utf-8'));
|
|
140
|
-
|
|
141
|
-
const pathsChanged = await rewritePathDeps(
|
|
142
|
-
manifest,
|
|
143
|
-
originalDir,
|
|
144
|
-
dirname(cargoTomlPath),
|
|
145
|
-
ctx,
|
|
146
|
-
!stripRootTables,
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
const tablesChanged = stripRootTables
|
|
150
|
-
? stripRootOnlyTables(manifest)
|
|
151
|
-
: pruneExcludedLiteralMembers(manifest);
|
|
152
|
-
|
|
153
|
-
if (pathsChanged || tablesChanged) {
|
|
154
|
-
await writeFile(cargoTomlPath, stringify(manifest));
|
|
155
|
-
logger.debug(`rewrote ${cargoTomlPath}`);
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
/** Primary resolution: realpath the path through pnpm symlinks, then look it up in pathMap. */
|
|
160
|
-
const resolveViaRealpath = async (
|
|
161
|
-
originalDir: string,
|
|
162
|
-
pathValue: string,
|
|
163
|
-
pathMap: Map<string, string>,
|
|
164
|
-
): Promise<string | undefined> => {
|
|
165
|
-
const resolvedPath = await tryRealpath(join(originalDir, pathValue));
|
|
166
|
-
return resolvedPath ? pathMap.get(resolvedPath) : undefined;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Fallback: locate a discovered npm package stem in the path and preserve every
|
|
171
|
-
* suffix segment after it (e.g. protocol-stellar-v2/message-libs/simple-message-lib).
|
|
172
|
-
*
|
|
173
|
-
* When several discovered package names appear as path segments, pick the
|
|
174
|
-
* **rightmost** (deepest) match — insertion order must not win over specificity.
|
|
175
|
-
*/
|
|
176
|
-
const resolveViaNameFallback = (pathValue: string, ctx: RewriteContext): string | undefined => {
|
|
177
|
-
const segments = pathValue.split('/').filter(Boolean);
|
|
178
|
-
if (segments.length === 0) return undefined;
|
|
179
|
-
|
|
180
|
-
let best:
|
|
181
|
-
| {
|
|
182
|
-
pkgIndex: number;
|
|
183
|
-
vendoredBase: string;
|
|
184
|
-
suffixSegments: string[];
|
|
185
|
-
}
|
|
186
|
-
| undefined;
|
|
187
|
-
|
|
188
|
-
for (const [pkgName, realPath] of ctx.discovered) {
|
|
189
|
-
const pkgIndex = segments.indexOf(pkgName);
|
|
190
|
-
if (pkgIndex === -1) continue;
|
|
191
|
-
|
|
192
|
-
const vendoredBase = ctx.pathMap.get(realPath);
|
|
193
|
-
if (!vendoredBase) continue;
|
|
194
|
-
|
|
195
|
-
// Prefer the deepest stem. Equal index cannot happen for distinct names.
|
|
196
|
-
if (best != null && pkgIndex <= best.pkgIndex) continue;
|
|
197
|
-
|
|
198
|
-
best = {
|
|
199
|
-
pkgIndex,
|
|
200
|
-
vendoredBase,
|
|
201
|
-
suffixSegments: segments.slice(pkgIndex + 1),
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (!best) return undefined;
|
|
206
|
-
return best.suffixSegments.length === 0
|
|
207
|
-
? best.vendoredBase
|
|
208
|
-
: join(best.vendoredBase, ...best.suffixSegments);
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Rewrite every Cargo.toml in a copied dependency tree. The root manifest keeps its
|
|
213
|
-
* root-only tables when it's a workspace (members inherit from them); all others strip them.
|
|
214
|
-
*/
|
|
215
|
-
export const rewriteCargoTomls = async (
|
|
216
|
-
srcRoot: string,
|
|
217
|
-
destRoot: string,
|
|
218
|
-
tree: CollectedTree,
|
|
219
|
-
ctx: RewriteContext,
|
|
220
|
-
): Promise<void> => {
|
|
221
|
-
for (const manifestDir of tree.manifestDirs) {
|
|
222
|
-
const preserve = manifestDir === '.' && (await isWorkspaceRoot(destRoot));
|
|
223
|
-
|
|
224
|
-
await rewriteCargoToml(
|
|
225
|
-
join(srcRoot, manifestDir),
|
|
226
|
-
join(destRoot, manifestDir, 'Cargo.toml'),
|
|
227
|
-
ctx,
|
|
228
|
-
!preserve,
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
};
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from 'fs';
|
|
2
|
-
import os from 'os';
|
|
3
|
-
import { join } from 'path';
|
|
4
|
-
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
5
|
-
|
|
6
|
-
import { buildDependenciesPathMap } from '../../src/resolve';
|
|
7
|
-
import {
|
|
8
|
-
discoverPackages,
|
|
9
|
-
isCrate,
|
|
10
|
-
isWorkspaceRoot,
|
|
11
|
-
type VendorTarget,
|
|
12
|
-
} from '../../src/resolve/discover';
|
|
13
|
-
import { collectFiles } from '../../src/resolve/io';
|
|
14
|
-
|
|
15
|
-
// Unique per run so concurrent runs (other checkouts, worktrees) can't delete each other's fixtures.
|
|
16
|
-
// realpath'd because resolve/ looks paths up by their real path — macOS /var/folders is a symlink.
|
|
17
|
-
const TMP = realpathSync(mkdtempSync(join(os.tmpdir(), 'build-utils-discover-')));
|
|
18
|
-
|
|
19
|
-
const createFile = (path: string, content = '') => {
|
|
20
|
-
mkdirSync(join(path, '..'), { recursive: true });
|
|
21
|
-
writeFileSync(path, content);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const createCrate = (path: string, cargoContent = '[package]\nname = "test"') => {
|
|
25
|
-
mkdirSync(path, { recursive: true });
|
|
26
|
-
writeFileSync(join(path, 'Cargo.toml'), cargoContent);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
beforeEach(() => mkdirSync(TMP, { recursive: true }));
|
|
30
|
-
afterEach(() => rmSync(TMP, { recursive: true, force: true }));
|
|
31
|
-
|
|
32
|
-
describe('isCrate', () => {
|
|
33
|
-
it('returns true for directory with Cargo.toml', async () => {
|
|
34
|
-
createCrate(join(TMP, 'my-crate'));
|
|
35
|
-
expect(await isCrate(join(TMP, 'my-crate'))).toBe(true);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('returns false for directory without Cargo.toml', async () => {
|
|
39
|
-
mkdirSync(join(TMP, 'not-a-crate'), { recursive: true });
|
|
40
|
-
expect(await isCrate(join(TMP, 'not-a-crate'))).toBe(false);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('returns false for nonexistent path', async () => {
|
|
44
|
-
expect(await isCrate(join(TMP, 'nope'))).toBe(false);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('returns false for a file', async () => {
|
|
48
|
-
createFile(join(TMP, 'a-file'), 'hello');
|
|
49
|
-
expect(await isCrate(join(TMP, 'a-file'))).toBe(false);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe('discoverPackages', () => {
|
|
54
|
-
it('discovers @layerzerolabs packages with Cargo.toml from node_modules', async () => {
|
|
55
|
-
// Simulate: TMP/node_modules/@layerzerolabs/my-crate/Cargo.toml
|
|
56
|
-
const cratePath = join(TMP, 'node_modules', '@layerzerolabs', 'my-crate');
|
|
57
|
-
createCrate(cratePath);
|
|
58
|
-
|
|
59
|
-
const discovered = new Map<string, string>();
|
|
60
|
-
await discoverPackages(TMP, discovered, new Set());
|
|
61
|
-
|
|
62
|
-
expect(discovered.size).toBe(1);
|
|
63
|
-
expect(discovered.has('my-crate')).toBe(true);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('skips packages without Cargo.toml', async () => {
|
|
67
|
-
const pkgPath = join(TMP, 'node_modules', '@layerzerolabs', 'ts-only-pkg');
|
|
68
|
-
mkdirSync(pkgPath, { recursive: true });
|
|
69
|
-
writeFileSync(join(pkgPath, 'package.json'), '{}');
|
|
70
|
-
|
|
71
|
-
const discovered = new Map<string, string>();
|
|
72
|
-
await discoverPackages(TMP, discovered, new Set());
|
|
73
|
-
|
|
74
|
-
expect(discovered.size).toBe(0);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('discovers transitive deps by recursing into package node_modules', async () => {
|
|
78
|
-
// Root depends on pkg-a, pkg-a depends on pkg-b
|
|
79
|
-
const pkgA = join(TMP, 'node_modules', '@layerzerolabs', 'pkg-a');
|
|
80
|
-
const pkgB = join(pkgA, 'node_modules', '@layerzerolabs', 'pkg-b');
|
|
81
|
-
createCrate(pkgA);
|
|
82
|
-
createCrate(pkgB);
|
|
83
|
-
|
|
84
|
-
const discovered = new Map<string, string>();
|
|
85
|
-
await discoverPackages(TMP, discovered, new Set());
|
|
86
|
-
|
|
87
|
-
expect(discovered.size).toBe(2);
|
|
88
|
-
expect(discovered.has('pkg-a')).toBe(true);
|
|
89
|
-
expect(discovered.has('pkg-b')).toBe(true);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('deduplicates packages seen through multiple paths', async () => {
|
|
93
|
-
// Both pkg-a and pkg-b depend on shared (via symlinks in real pnpm,
|
|
94
|
-
// but here we just put it in both node_modules)
|
|
95
|
-
const pkgA = join(TMP, 'node_modules', '@layerzerolabs', 'pkg-a');
|
|
96
|
-
const shared = join(TMP, 'node_modules', '@layerzerolabs', 'shared');
|
|
97
|
-
const sharedViaA = join(pkgA, 'node_modules', '@layerzerolabs', 'shared');
|
|
98
|
-
createCrate(pkgA);
|
|
99
|
-
createCrate(shared);
|
|
100
|
-
createCrate(sharedViaA);
|
|
101
|
-
|
|
102
|
-
const discovered = new Map<string, string>();
|
|
103
|
-
await discoverPackages(TMP, discovered, new Set());
|
|
104
|
-
|
|
105
|
-
// "shared" discovered once from root, not duplicated from pkg-a's copy
|
|
106
|
-
expect(discovered.size).toBe(2); // pkg-a + shared
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
describe('isWorkspaceRoot', () => {
|
|
111
|
-
it('returns true when Cargo.toml has a [workspace] table', async () => {
|
|
112
|
-
createCrate(join(TMP, 'ws'), '[workspace]\nmembers = ["contracts/*"]');
|
|
113
|
-
expect(await isWorkspaceRoot(join(TMP, 'ws'))).toBe(true);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('returns true for a virtual manifest ([workspace] without [package])', async () => {
|
|
117
|
-
createCrate(join(TMP, 'virtual'), '[workspace]\nresolver = "2"\nmembers = ["a"]');
|
|
118
|
-
expect(await isWorkspaceRoot(join(TMP, 'virtual'))).toBe(true);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('returns false for a bare [package] (standalone single crate)', async () => {
|
|
122
|
-
createCrate(join(TMP, 'leaf'), '[package]\nname = "leaf"');
|
|
123
|
-
expect(await isWorkspaceRoot(join(TMP, 'leaf'))).toBe(false);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('returns false when there is no Cargo.toml', async () => {
|
|
127
|
-
mkdirSync(join(TMP, 'empty'), { recursive: true });
|
|
128
|
-
expect(await isWorkspaceRoot(join(TMP, 'empty'))).toBe(false);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe('buildDependenciesPathMap', () => {
|
|
133
|
-
// Build a VendorTarget by collecting the crate's tree (same input the pipeline feeds it).
|
|
134
|
-
const toTarget = async (
|
|
135
|
-
pkgName: string,
|
|
136
|
-
npmPkgDir: string,
|
|
137
|
-
depsDir: string,
|
|
138
|
-
): Promise<VendorTarget> => ({
|
|
139
|
-
pkgName,
|
|
140
|
-
npmPkgDir,
|
|
141
|
-
depsPkgDir: join(depsDir, pkgName),
|
|
142
|
-
tree: await collectFiles(npmPkgDir),
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('maps discovered packages to dependencies/ targets', async () => {
|
|
146
|
-
const depsDir = join(TMP, 'dependencies');
|
|
147
|
-
// A discovered package always has a root Cargo.toml (isCrate-verified), so its
|
|
148
|
-
// '.' manifest dir maps the package root to its dependencies/ target.
|
|
149
|
-
const rbac = join(TMP, 'rbac');
|
|
150
|
-
const oapp = join(TMP, 'oapp');
|
|
151
|
-
createCrate(rbac);
|
|
152
|
-
createCrate(oapp);
|
|
153
|
-
const targets = [
|
|
154
|
-
await toTarget('rbac-solana-contracts', rbac, depsDir),
|
|
155
|
-
await toTarget('oapp-solana-contracts', oapp, depsDir),
|
|
156
|
-
];
|
|
157
|
-
|
|
158
|
-
const pathMap = buildDependenciesPathMap(targets);
|
|
159
|
-
|
|
160
|
-
expect(pathMap.get(rbac)).toBe(join(depsDir, 'rbac-solana-contracts'));
|
|
161
|
-
expect(pathMap.get(oapp)).toBe(join(depsDir, 'oapp-solana-contracts'));
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('includes subdirectories with Cargo.toml (macros/)', async () => {
|
|
165
|
-
const depsDir = join(TMP, 'dependencies');
|
|
166
|
-
const crateDir = join(TMP, 'real-crate');
|
|
167
|
-
createCrate(crateDir);
|
|
168
|
-
createCrate(join(crateDir, 'macros'));
|
|
169
|
-
|
|
170
|
-
const pathMap = buildDependenciesPathMap([await toTarget('my-crate', crateDir, depsDir)]);
|
|
171
|
-
|
|
172
|
-
expect(pathMap.get(crateDir)).toBe(join(depsDir, 'my-crate'));
|
|
173
|
-
expect(pathMap.get(join(crateDir, 'macros'))).toBe(join(depsDir, 'my-crate', 'macros'));
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('skips excluded directories like node_modules and target', async () => {
|
|
177
|
-
const depsDir = join(TMP, 'dependencies');
|
|
178
|
-
const crateDir = join(TMP, 'real-crate');
|
|
179
|
-
createCrate(crateDir);
|
|
180
|
-
createCrate(join(crateDir, 'node_modules')); // should be excluded
|
|
181
|
-
createCrate(join(crateDir, 'target')); // should be excluded
|
|
182
|
-
|
|
183
|
-
const pathMap = buildDependenciesPathMap([await toTarget('my-crate', crateDir, depsDir)]);
|
|
184
|
-
|
|
185
|
-
expect(pathMap.size).toBe(1); // only the root, no subdirs
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('maps every crate dir (incl. deeply nested) to its dependencies/ target', async () => {
|
|
189
|
-
const depsDir = join(TMP, 'dependencies');
|
|
190
|
-
const crateDir = join(TMP, 'protocol-stellar-v2');
|
|
191
|
-
createCrate(crateDir, '[workspace]\nmembers = ["endpoint-v2", "message-libs/*"]');
|
|
192
|
-
createCrate(join(crateDir, 'endpoint-v2'));
|
|
193
|
-
createCrate(join(crateDir, 'message-libs', 'simple-message-lib'));
|
|
194
|
-
|
|
195
|
-
const pathMap = buildDependenciesPathMap([
|
|
196
|
-
await toTarget('protocol-stellar-v2', crateDir, depsDir),
|
|
197
|
-
]);
|
|
198
|
-
|
|
199
|
-
expect(pathMap.get(crateDir)).toBe(join(depsDir, 'protocol-stellar-v2'));
|
|
200
|
-
expect(pathMap.get(join(crateDir, 'endpoint-v2'))).toBe(
|
|
201
|
-
join(depsDir, 'protocol-stellar-v2', 'endpoint-v2'),
|
|
202
|
-
);
|
|
203
|
-
// the deep member — the case the old one-level scan missed
|
|
204
|
-
expect(pathMap.get(join(crateDir, 'message-libs', 'simple-message-lib'))).toBe(
|
|
205
|
-
join(depsDir, 'protocol-stellar-v2', 'message-libs', 'simple-message-lib'),
|
|
206
|
-
);
|
|
207
|
-
});
|
|
208
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "my-crate"
|
|
3
|
-
version = "0.1.0"
|
|
4
|
-
edition = "2021"
|
|
5
|
-
|
|
6
|
-
[dependencies]
|
|
7
|
-
anchor-lang = { version = "0.32.1" }
|
|
8
|
-
|
|
9
|
-
[dev-dependencies]
|
|
10
|
-
test-utils = { path = "dependencies/test-utils" }
|
|
11
|
-
|
|
12
|
-
[build-dependencies]
|
|
13
|
-
codegen = { path = "dependencies/codegen-utils" }
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "oft-core"
|
|
3
|
-
version = "0.0.1"
|
|
4
|
-
edition = "2021"
|
|
5
|
-
|
|
6
|
-
[dependencies]
|
|
7
|
-
endpoint-v2 = { path = "dependencies/protocol-stellar-v2/endpoint-v2" }
|
|
8
|
-
|
|
9
|
-
[dev-dependencies]
|
|
10
|
-
simple-message-lib = { path = "dependencies/protocol-stellar-v2/message-libs/simple-message-lib" }
|
|
11
|
-
message-lib-common = { path = "dependencies/protocol-stellar-v2/message-libs/message-lib-common" }
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "my-crate"
|
|
3
|
-
version = "0.1.0"
|
|
4
|
-
edition = "2021"
|
|
5
|
-
|
|
6
|
-
[dependencies]
|
|
7
|
-
anchor-lang = { version = "0.32.1" }
|
|
8
|
-
|
|
9
|
-
[patch.crates-io]
|
|
10
|
-
anchor-lang = { git = "https://github.com/example/anchor.git", rev = "deadbeef" }
|
|
11
|
-
|
|
12
|
-
[patch."https://github.com/solana-labs/solana.git"]
|
|
13
|
-
solana-program = { path = "../solana-program" }
|
|
14
|
-
|
|
15
|
-
[profile.dev]
|
|
16
|
-
opt-level = 1
|
|
17
|
-
|
|
18
|
-
[profile.dev.package."*"]
|
|
19
|
-
opt-level = 3
|
|
20
|
-
|
|
21
|
-
[profile.release]
|
|
22
|
-
overflow-checks = true
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "my-lib"
|
|
3
|
-
version = "0.1.0"
|
|
4
|
-
edition = "2021"
|
|
5
|
-
|
|
6
|
-
[dependencies]
|
|
7
|
-
anchor-lang = { version = "0.32.1" }
|
|
8
|
-
|
|
9
|
-
[patch.crates-io]
|
|
10
|
-
anchor-lang = { git = "https://github.com/example/anchor.git", rev = "deadbeef" }
|
|
11
|
-
|
|
12
|
-
[profile.release]
|
|
13
|
-
overflow-checks = true
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "console-oft"
|
|
3
|
-
|
|
4
|
-
# Like the Solana consumers, the manifest points straight at dependencies/ —
|
|
5
|
-
# the resolve tool only vendors crates there, it does not rewrite this file.
|
|
6
|
-
[dependencies]
|
|
7
|
-
endpoint-v2 = { path = "dependencies/protocol-stellar-v2/endpoint-v2" }
|
|
8
|
-
simple-message-lib = { path = "dependencies/protocol-stellar-v2/message-libs/simple-message-lib" }
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
[workspace]
|
|
2
|
-
resolver = "2"
|
|
3
|
-
members = ["endpoint-v2", "message-libs/*", "workers/*"]
|
|
4
|
-
|
|
5
|
-
[workspace.package]
|
|
6
|
-
edition = "2021"
|
|
7
|
-
version = "0.0.1"
|
|
8
|
-
license = "MIT"
|
|
9
|
-
|
|
10
|
-
[workspace.dependencies]
|
|
11
|
-
soroban-sdk = { version = "25.1.1" }
|
|
12
|
-
endpoint-v2 = { path = "endpoint-v2", default-features = false }
|
|
13
|
-
message-lib-common = { path = "message-libs/message-lib-common" }
|
|
14
|
-
simple-message-lib = { path = "message-libs/simple-message-lib" }
|
|
15
|
-
|
|
16
|
-
[profile.release]
|
|
17
|
-
opt-level = "z"
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
[workspace]
|
|
2
|
-
resolver = "2"
|
|
3
|
-
members = ["endpoint-v2", "tests/mock_vault"]
|
|
4
|
-
|
|
5
|
-
[workspace.package]
|
|
6
|
-
edition = "2021"
|
|
7
|
-
version = "0.0.1"
|
|
8
|
-
license = "MIT"
|
|
9
|
-
|
|
10
|
-
[workspace.dependencies]
|
|
11
|
-
soroban-sdk = { version = "25.1.1" }
|
|
12
|
-
endpoint-v2 = { path = "endpoint-v2", default-features = false }
|
|
13
|
-
|
|
14
|
-
[profile.release]
|
|
15
|
-
opt-level = "z"
|