@layerzerolabs/build-utils-rust 1.2.68 → 1.2.69

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.
Files changed (83) hide show
  1. package/bin/build-utils-rust.js +3 -0
  2. package/dist/2T2WFWNM.js +57 -0
  3. package/dist/2T2WFWNM.js.map +1 -0
  4. package/dist/N2QRCDCB.js +115 -0
  5. package/dist/N2QRCDCB.js.map +1 -0
  6. package/dist/N4NI6N3K.js +83 -0
  7. package/dist/N4NI6N3K.js.map +1 -0
  8. package/dist/UDDAJZY4.js +26 -0
  9. package/dist/UDDAJZY4.js.map +1 -0
  10. package/dist/VUOMXK5T.js +6 -0
  11. package/dist/VUOMXK5T.js.map +1 -0
  12. package/dist/ZQ7KHDAO.js +52 -0
  13. package/dist/ZQ7KHDAO.js.map +1 -0
  14. package/dist/ZS7IDLZZ.js +59 -0
  15. package/dist/ZS7IDLZZ.js.map +1 -0
  16. package/dist/cli.d.ts +2 -0
  17. package/dist/cli.d.ts.map +1 -0
  18. package/dist/cli.js +27 -0
  19. package/dist/cli.js.map +1 -0
  20. package/{src/index.ts → dist/index.d.ts} +1 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/logger.d.ts +8 -0
  24. package/dist/logger.d.ts.map +1 -0
  25. package/dist/logger.js +4 -0
  26. package/dist/logger.js.map +1 -0
  27. package/dist/resolve/discover.d.ts +23 -0
  28. package/dist/resolve/discover.d.ts.map +1 -0
  29. package/dist/resolve/discover.js +7 -0
  30. package/dist/resolve/discover.js.map +1 -0
  31. package/dist/resolve/exclude.d.ts +10 -0
  32. package/dist/resolve/exclude.d.ts.map +1 -0
  33. package/dist/resolve/exclude.js +4 -0
  34. package/dist/resolve/exclude.js.map +1 -0
  35. package/dist/resolve/index.d.ts +20 -0
  36. package/dist/resolve/index.d.ts.map +1 -0
  37. package/dist/resolve/index.js +9 -0
  38. package/dist/resolve/index.js.map +1 -0
  39. package/dist/resolve/io.d.ts +17 -0
  40. package/dist/resolve/io.d.ts.map +1 -0
  41. package/dist/resolve/io.js +6 -0
  42. package/dist/resolve/io.js.map +1 -0
  43. package/dist/resolve/rewrite.d.ts +41 -0
  44. package/dist/resolve/rewrite.d.ts.map +1 -0
  45. package/dist/resolve/rewrite.js +8 -0
  46. package/dist/resolve/rewrite.js.map +1 -0
  47. package/package.json +9 -6
  48. package/src/cli.ts +0 -33
  49. package/src/logger.ts +0 -26
  50. package/src/resolve/discover.ts +0 -93
  51. package/src/resolve/exclude.ts +0 -58
  52. package/src/resolve/index.ts +0 -122
  53. package/src/resolve/io.ts +0 -69
  54. package/src/resolve/rewrite.ts +0 -231
  55. package/tests/resolve/discover.test.ts +0 -208
  56. package/tests/resolve/fixtures/index.ts +0 -6
  57. package/tests/resolve/fixtures/minimal.toml +0 -2
  58. package/tests/resolve/fixtures/mixed-deps.toml +0 -4
  59. package/tests/resolve/fixtures/multi-path-deps.toml +0 -9
  60. package/tests/resolve/fixtures/multi-section-path-deps.toml +0 -13
  61. package/tests/resolve/fixtures/no-path-deps.toml +0 -3
  62. package/tests/resolve/fixtures/oapp-with-stale-deps.toml +0 -5
  63. package/tests/resolve/fixtures/oft-core-with-stale-deep-deps.toml +0 -11
  64. package/tests/resolve/fixtures/patch-multi-registry.toml +0 -22
  65. package/tests/resolve/fixtures/program-with-deps.toml +0 -5
  66. package/tests/resolve/fixtures/program-with-macros.toml +0 -6
  67. package/tests/resolve/fixtures/program-workspace-member.toml +0 -5
  68. package/tests/resolve/fixtures/root-only-sections.toml +0 -13
  69. package/tests/resolve/fixtures/stellar-consumer.toml +0 -8
  70. package/tests/resolve/fixtures/stellar-member-inheriting.toml +0 -10
  71. package/tests/resolve/fixtures/stellar-workspace-root.toml +0 -17
  72. package/tests/resolve/fixtures/stellar-workspace-with-tests.toml +0 -15
  73. package/tests/resolve/fixtures/target-cfg-path-dep.toml +0 -10
  74. package/tests/resolve/fixtures/with-features.toml +0 -2
  75. package/tests/resolve/fixtures/workspace-at-end.toml +0 -6
  76. package/tests/resolve/fixtures/workspace-at-top.toml +0 -10
  77. package/tests/resolve/fixtures/workspace-middle.toml +0 -10
  78. package/tests/resolve/fixtures/workspace-with-default-members.toml +0 -8
  79. package/tests/resolve/fixtures/workspace-with-path-deps.toml +0 -8
  80. package/tests/resolve/index.test.ts +0 -468
  81. package/tests/resolve/rewrite.test.ts +0 -507
  82. package/tsconfig.json +0 -21
  83. package/tsup.config.ts +0 -8
@@ -1,507 +0,0 @@
1
- import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'fs';
2
- import os from 'os';
3
- import { join } from 'path';
4
- import { parse } from 'smol-toml';
5
- import { afterEach, beforeEach, describe, expect, it } from 'vitest';
6
-
7
- import { collectFiles } from '../../src/resolve/io';
8
- import type { RewriteContext } from '../../src/resolve/rewrite';
9
- import { rewriteCargoToml, rewriteCargoTomls } from '../../src/resolve/rewrite';
10
- import { fixture } from './fixtures';
11
-
12
- // Unique per run so concurrent runs (other checkouts, worktrees) can't delete each other's fixtures.
13
- // realpath'd because resolve/ looks paths up by their real path — macOS /var/folders is a symlink.
14
- const TMP = realpathSync(mkdtempSync(join(os.tmpdir(), 'build-utils-rewrite-')));
15
-
16
- const writeToml = (path: string, content: string) => {
17
- mkdirSync(join(path, '..'), { recursive: true });
18
- writeFileSync(path, content);
19
- };
20
-
21
- const readToml = (path: string) => readFileSync(path, 'utf-8');
22
-
23
- /** Read + parse a written manifest — assertions check structure, not formatting. */
24
- const readParsed = (path: string): Record<string, unknown> => parse(readFileSync(path, 'utf-8'));
25
-
26
- /** The `path` value of a dependency in a given table, or undefined. */
27
- const depPath = (manifest: Record<string, unknown>, table: string, dep: string): unknown => {
28
- const deps = manifest[table] as Record<string, { path?: unknown }> | undefined;
29
- return deps?.[dep]?.path;
30
- };
31
-
32
- beforeEach(() => mkdirSync(TMP, { recursive: true }));
33
- afterEach(() => rmSync(TMP, { recursive: true, force: true }));
34
-
35
- describe('rewriteCargoToml', () => {
36
- it('rewrites path deps using name fallback when realpath fails', async () => {
37
- const depsDir = join(TMP, 'dependencies');
38
- const crateDir = join(TMP, 'programs', 'my-program');
39
- const cargoToml = join(crateDir, 'Cargo.toml');
40
-
41
- writeToml(cargoToml, fixture('mixed-deps.toml'));
42
-
43
- const ctx: RewriteContext = {
44
- pathMap: new Map([['/real/rbac', join(depsDir, 'rbac-solana-contracts')]]),
45
- discovered: new Map([['rbac-solana-contracts', '/real/rbac']]),
46
- };
47
-
48
- await rewriteCargoToml(crateDir, cargoToml, ctx);
49
- const result = readToml(cargoToml);
50
-
51
- expect(result).toContain('rbac = { path = "../../dependencies/rbac-solana-contracts" }');
52
- expect(result).toContain('anchor-lang = { version = "0.32.1" }');
53
- expect(result).toContain('num_enum = { version = "0.7" }');
54
- });
55
-
56
- it('rewrites macros subdir paths via parent name match', async () => {
57
- const depsDir = join(TMP, 'dependencies');
58
- const crateDir = join(TMP, 'programs', 'my-program');
59
- const cargoToml = join(crateDir, 'Cargo.toml');
60
-
61
- writeToml(cargoToml, fixture('program-with-macros.toml'));
62
-
63
- const ctx: RewriteContext = {
64
- pathMap: new Map([
65
- ['/real/rbac', join(depsDir, 'rbac-solana-contracts')],
66
- ['/real/rbac/macros', join(depsDir, 'rbac-solana-contracts', 'macros')],
67
- ]),
68
- discovered: new Map([['rbac-solana-contracts', '/real/rbac']]),
69
- };
70
-
71
- await rewriteCargoToml(crateDir, cargoToml, ctx);
72
- const result = readToml(cargoToml);
73
-
74
- expect(result).toContain(
75
- 'rbac-macros = { path = "../../dependencies/rbac-solana-contracts/macros" }',
76
- );
77
- });
78
-
79
- it('rewrites arbitrary-depth paths below a discovered package stem', async () => {
80
- const depsDir = join(TMP, 'dependencies');
81
- const crateDir = join(TMP, 'programs', 'oft-core');
82
- const cargoToml = join(crateDir, 'Cargo.toml');
83
-
84
- writeToml(cargoToml, fixture('oft-core-with-stale-deep-deps.toml'));
85
-
86
- const protocolRoot = join(depsDir, 'protocol-stellar-v2');
87
- const ctx: RewriteContext = {
88
- pathMap: new Map([
89
- ['/real/protocol', protocolRoot],
90
- ['/real/protocol/endpoint-v2', join(protocolRoot, 'endpoint-v2')],
91
- [
92
- '/real/protocol/message-libs/simple-message-lib',
93
- join(protocolRoot, 'message-libs', 'simple-message-lib'),
94
- ],
95
- [
96
- '/real/protocol/message-libs/message-lib-common',
97
- join(protocolRoot, 'message-libs', 'message-lib-common'),
98
- ],
99
- ]),
100
- discovered: new Map([['protocol-stellar-v2', '/real/protocol']]),
101
- };
102
-
103
- await rewriteCargoToml(crateDir, cargoToml, ctx);
104
- const manifest = readParsed(cargoToml);
105
-
106
- expect(depPath(manifest, 'dependencies', 'endpoint-v2')).toBe(
107
- join('..', '..', 'dependencies', 'protocol-stellar-v2', 'endpoint-v2'),
108
- );
109
- expect(depPath(manifest, 'dev-dependencies', 'simple-message-lib')).toBe(
110
- join(
111
- '..',
112
- '..',
113
- 'dependencies',
114
- 'protocol-stellar-v2',
115
- 'message-libs',
116
- 'simple-message-lib',
117
- ),
118
- );
119
- expect(depPath(manifest, 'dev-dependencies', 'message-lib-common')).toBe(
120
- join(
121
- '..',
122
- '..',
123
- 'dependencies',
124
- 'protocol-stellar-v2',
125
- 'message-libs',
126
- 'message-lib-common',
127
- ),
128
- );
129
- });
130
-
131
- it('prefers the deepest discovered package stem over Map insertion order', async () => {
132
- // Path contains both a shallow parent package name and a nested child package
133
- // name. Insertion order lists the parent first — first-match would wrongly
134
- // rewrite under the parent; most-specific must use the child stem.
135
- const depsDir = join(TMP, 'dependencies');
136
- const crateDir = join(TMP, 'programs', 'consumer');
137
- const cargoToml = join(crateDir, 'Cargo.toml');
138
-
139
- writeToml(
140
- cargoToml,
141
- '[dependencies]\nmacros = { path = "../../node_modules/parent-pkg/child-pkg/macros" }\n',
142
- );
143
-
144
- const ctx: RewriteContext = {
145
- pathMap: new Map([
146
- ['/real/parent', join(depsDir, 'parent-pkg')],
147
- ['/real/child', join(depsDir, 'child-pkg')],
148
- ]),
149
- // Parent inserted first — old first-match behavior would select it.
150
- discovered: new Map([
151
- ['parent-pkg', '/real/parent'],
152
- ['child-pkg', '/real/child'],
153
- ]),
154
- };
155
-
156
- await rewriteCargoToml(crateDir, cargoToml, ctx);
157
-
158
- expect(depPath(readParsed(cargoToml), 'dependencies', 'macros')).toBe(
159
- join('..', '..', 'dependencies', 'child-pkg', 'macros'),
160
- );
161
- });
162
-
163
- it('preserves features and other inline attrs', async () => {
164
- const depsDir = join(TMP, 'dependencies');
165
- const cargoToml = join(TMP, 'Cargo.toml');
166
-
167
- writeToml(cargoToml, fixture('with-features.toml'));
168
-
169
- const ctx: RewriteContext = {
170
- pathMap: new Map([['/real/rbac', join(depsDir, 'rbac-solana-contracts')]]),
171
- discovered: new Map([['rbac-solana-contracts', '/real/rbac']]),
172
- };
173
-
174
- await rewriteCargoToml(TMP, cargoToml, ctx);
175
- const result = readToml(cargoToml);
176
-
177
- expect(result).toContain('features = ["idl-build"]');
178
- expect(result).toContain('path = "dependencies/rbac-solana-contracts"');
179
- });
180
-
181
- it('does not modify file when no path deps match and no workspace', async () => {
182
- const cargoToml = join(TMP, 'Cargo.toml');
183
- const original = fixture('no-path-deps.toml');
184
-
185
- writeToml(cargoToml, original);
186
-
187
- const ctx: RewriteContext = {
188
- pathMap: new Map(),
189
- discovered: new Map(),
190
- };
191
-
192
- await rewriteCargoToml(TMP, cargoToml, ctx);
193
- expect(readToml(cargoToml)).toBe(original);
194
- });
195
-
196
- it('strips [workspace] table at top of file', async () => {
197
- const cargoToml = join(TMP, 'Cargo.toml');
198
- writeToml(cargoToml, fixture('workspace-at-top.toml'));
199
-
200
- const ctx: RewriteContext = { pathMap: new Map(), discovered: new Map() };
201
- await rewriteCargoToml(TMP, cargoToml, ctx);
202
- const manifest = readParsed(cargoToml);
203
-
204
- expect(manifest.workspace).toBeUndefined();
205
- expect(manifest.package).toMatchObject({ name: 'my-lib' });
206
- expect(manifest.dependencies).toHaveProperty('anchor-lang');
207
- });
208
-
209
- it('strips [workspace] sandwiched between other sections', async () => {
210
- const cargoToml = join(TMP, 'Cargo.toml');
211
- writeToml(cargoToml, fixture('workspace-middle.toml'));
212
-
213
- const ctx: RewriteContext = { pathMap: new Map(), discovered: new Map() };
214
- await rewriteCargoToml(TMP, cargoToml, ctx);
215
- const manifest = readParsed(cargoToml);
216
-
217
- expect(manifest.workspace).toBeUndefined();
218
- expect(manifest.package).toMatchObject({ name: 'my-lib' });
219
- expect(manifest.dependencies).toHaveProperty('anchor-lang');
220
- });
221
-
222
- it('strips [workspace] at end of file with no trailing section', async () => {
223
- const cargoToml = join(TMP, 'Cargo.toml');
224
- writeToml(cargoToml, fixture('workspace-at-end.toml'));
225
-
226
- const ctx: RewriteContext = { pathMap: new Map(), discovered: new Map() };
227
- await rewriteCargoToml(TMP, cargoToml, ctx);
228
- const result = readToml(cargoToml);
229
-
230
- expect(result).not.toContain('[workspace]');
231
- expect(result).not.toContain('members');
232
- expect(result).not.toContain('resolver');
233
- expect(result).toContain('[package]');
234
- expect(result).toContain('name = "my-lib"');
235
- });
236
-
237
- it('strips [workspace] and rewrites path deps in the same pass', async () => {
238
- const depsDir = join(TMP, 'dependencies');
239
- const cargoToml = join(TMP, 'Cargo.toml');
240
- writeToml(cargoToml, fixture('workspace-with-path-deps.toml'));
241
-
242
- const ctx: RewriteContext = {
243
- pathMap: new Map([['/real/rbac', join(depsDir, 'rbac-solana-contracts')]]),
244
- discovered: new Map([['rbac-solana-contracts', '/real/rbac']]),
245
- };
246
-
247
- await rewriteCargoToml(TMP, cargoToml, ctx);
248
- const result = readToml(cargoToml);
249
-
250
- expect(result).not.toContain('[workspace]');
251
- expect(result).toContain('path = "dependencies/rbac-solana-contracts"');
252
- expect(result).toContain('name = "oapp"');
253
- });
254
-
255
- it('strips root-only [patch.*] and [profile.*] tables from vendored manifests', async () => {
256
- const cargoToml = join(TMP, 'Cargo.toml');
257
- writeToml(cargoToml, fixture('root-only-sections.toml'));
258
-
259
- const ctx: RewriteContext = { pathMap: new Map(), discovered: new Map() };
260
- await rewriteCargoToml(TMP, cargoToml, ctx);
261
- const manifest = readParsed(cargoToml);
262
-
263
- expect(manifest.package).toBeDefined();
264
- expect(manifest.dependencies).toBeDefined();
265
- expect(manifest.patch).toBeUndefined();
266
- expect(manifest.profile).toBeUndefined();
267
- });
268
- });
269
-
270
- describe('rewriteCargoToml — path dep syntax variants', () => {
271
- it('rewrites table-syntax path deps ([dependencies.dep]\\npath = "...")', async () => {
272
- // Structural TOML parsing handles the table-header form too — the old
273
- // inline-table-only regex did not, so this is a fixed limitation.
274
- const cargoToml = join(TMP, 'Cargo.toml');
275
- writeToml(
276
- cargoToml,
277
- '[package]\nname = "x"\n\n[dependencies.rbac]\npath = "dependencies/rbac-solana-contracts"\n',
278
- );
279
-
280
- const ctx: RewriteContext = {
281
- pathMap: new Map([['/real/rbac', join(TMP, 'deps', 'rbac-solana-contracts')]]),
282
- discovered: new Map([['rbac-solana-contracts', '/real/rbac']]),
283
- };
284
-
285
- await rewriteCargoToml(TMP, cargoToml, ctx);
286
- expect(depPath(readParsed(cargoToml), 'dependencies', 'rbac')).toBe(
287
- join('deps', 'rbac-solana-contracts'),
288
- );
289
- });
290
-
291
- it('rewrites path deps in [dev-dependencies] and [build-dependencies]', async () => {
292
- const depsDir = join(TMP, 'dependencies');
293
- const cargoToml = join(TMP, 'Cargo.toml');
294
- writeToml(cargoToml, fixture('multi-section-path-deps.toml'));
295
-
296
- const ctx: RewriteContext = {
297
- pathMap: new Map([
298
- ['/real/test-utils', join(depsDir, 'test-utils')],
299
- ['/real/codegen-utils', join(depsDir, 'codegen-utils')],
300
- ]),
301
- discovered: new Map([
302
- ['test-utils', '/real/test-utils'],
303
- ['codegen-utils', '/real/codegen-utils'],
304
- ]),
305
- };
306
-
307
- await rewriteCargoToml(TMP, cargoToml, ctx);
308
- const result = readToml(cargoToml);
309
-
310
- expect(result).toContain('test-utils = { path = "dependencies/test-utils" }');
311
- expect(result).toContain('codegen = { path = "dependencies/codegen-utils" }');
312
- });
313
-
314
- it("rewrites path deps in [target.'cfg(...)'.dependencies]", async () => {
315
- const depsDir = join(TMP, 'dependencies');
316
- const cargoToml = join(TMP, 'Cargo.toml');
317
- writeToml(cargoToml, fixture('target-cfg-path-dep.toml'));
318
-
319
- const ctx: RewriteContext = {
320
- pathMap: new Map([['/real/wasm-utils', join(depsDir, 'wasm-utils')]]),
321
- discovered: new Map([['wasm-utils', '/real/wasm-utils']]),
322
- };
323
-
324
- await rewriteCargoToml(TMP, cargoToml, ctx);
325
- const result = readToml(cargoToml);
326
-
327
- expect(result).toContain('wasm-utils = { path = "dependencies/wasm-utils" }');
328
- });
329
-
330
- it('rewrites multiple path deps in one [dependencies] block in a single pass', async () => {
331
- const depsDir = join(TMP, 'dependencies');
332
- const cargoToml = join(TMP, 'Cargo.toml');
333
- writeToml(cargoToml, fixture('multi-path-deps.toml'));
334
-
335
- const ctx: RewriteContext = {
336
- pathMap: new Map([
337
- ['/real/pkg-a', join(depsDir, 'pkg-a')],
338
- ['/real/pkg-b', join(depsDir, 'pkg-b')],
339
- ['/real/pkg-c', join(depsDir, 'pkg-c')],
340
- ]),
341
- discovered: new Map([
342
- ['pkg-a', '/real/pkg-a'],
343
- ['pkg-b', '/real/pkg-b'],
344
- ['pkg-c', '/real/pkg-c'],
345
- ]),
346
- };
347
-
348
- await rewriteCargoToml(TMP, cargoToml, ctx);
349
- const result = readToml(cargoToml);
350
-
351
- expect(result).toContain('pkg-a = { path = "dependencies/pkg-a" }');
352
- expect(result).toContain('pkg-b = { path = "dependencies/pkg-b" }');
353
- expect(result).toContain('pkg-c = { path = "dependencies/pkg-c" }');
354
- });
355
- });
356
-
357
- describe('rewriteCargoToml — primary pathMap resolution (no fallback)', () => {
358
- it('rewrites via pathMap lookup when path resolves directly (no symlink needed)', async () => {
359
- // Create a real directory so realpath(join(TMP, 'src-crate')) succeeds.
360
- const srcCrateDir = join(TMP, 'src-crate');
361
- const depsDir = join(TMP, 'dependencies');
362
- mkdirSync(srcCrateDir, { recursive: true });
363
-
364
- // The consumer Cargo.toml lives at TMP root; its path dep points at src-crate/.
365
- const cargoToml = join(TMP, 'Cargo.toml');
366
- writeToml(cargoToml, '[dependencies]\nmy-pkg = { path = "src-crate" }');
367
-
368
- // pathMap uses the real (non-symlinked) path as the key — primary resolution
369
- const ctx: RewriteContext = {
370
- pathMap: new Map([[srcCrateDir, join(depsDir, 'my-pkg')]]),
371
- discovered: new Map([['my-pkg', srcCrateDir]]),
372
- };
373
-
374
- await rewriteCargoToml(TMP, cargoToml, ctx);
375
-
376
- expect(depPath(readParsed(cargoToml), 'dependencies', 'my-pkg')).toBe(
377
- join('dependencies', 'my-pkg'),
378
- );
379
- });
380
- });
381
-
382
- describe('rewriteCargoToml — root table stripping edge cases', () => {
383
- it('strips [patch."https://..."] and [profile.dev.package.*] sub-tables', async () => {
384
- const cargoToml = join(TMP, 'Cargo.toml');
385
- writeToml(cargoToml, fixture('patch-multi-registry.toml'));
386
-
387
- const ctx: RewriteContext = { pathMap: new Map(), discovered: new Map() };
388
- await rewriteCargoToml(TMP, cargoToml, ctx);
389
- const manifest = readParsed(cargoToml);
390
-
391
- expect(manifest.package).toBeDefined();
392
- expect(manifest.dependencies).toBeDefined();
393
- expect(manifest.patch).toBeUndefined();
394
- expect(manifest.profile).toBeUndefined();
395
- });
396
-
397
- it('strips [workspace] with no trailing newline at EOF', async () => {
398
- const cargoToml = join(TMP, 'Cargo.toml');
399
- // No trailing newline after [workspace] block
400
- writeToml(cargoToml, '[package]\nname = "x"\n\n[workspace]\nmembers = ["a"]');
401
-
402
- const ctx: RewriteContext = { pathMap: new Map(), discovered: new Map() };
403
- await rewriteCargoToml(TMP, cargoToml, ctx);
404
- const result = readToml(cargoToml);
405
-
406
- expect(result).not.toContain('[workspace]');
407
- expect(result).toContain('[package]');
408
- expect(result).toContain('name = "x"');
409
- });
410
- });
411
-
412
- describe('rewriteCargoToml — pruneExcludedLiteralMembers edge cases', () => {
413
- it('prunes excluded literal from default-members and members in same manifest', async () => {
414
- const cargoToml = join(TMP, 'Cargo.toml');
415
- writeToml(cargoToml, fixture('workspace-with-default-members.toml'));
416
-
417
- const ctx: RewriteContext = { pathMap: new Map(), discovered: new Map() };
418
- // stripRootTables=false → preserve workspace, prune excluded members
419
- await rewriteCargoToml(TMP, cargoToml, ctx, false);
420
- const result = readToml(cargoToml);
421
-
422
- expect(result).not.toContain('tests/mock');
423
- expect(result).toContain('contracts/*');
424
- expect(result).toContain('contracts/main');
425
- expect(result).toContain('[workspace]');
426
- });
427
-
428
- it('does NOT prune a glob member pattern even when it starts with an excluded segment', async () => {
429
- const cargoToml = join(TMP, 'Cargo.toml');
430
- // "tests/*" is a glob — not a resolved literal pointing into tests/, so it is kept.
431
- // Cargo will expand it at build time over the (already test-free) vendored tree,
432
- // resulting in an empty expansion — not an error.
433
- writeToml(cargoToml, '[workspace]\nmembers = ["contracts/*", "tests/*"]\n');
434
-
435
- const ctx: RewriteContext = { pathMap: new Map(), discovered: new Map() };
436
- await rewriteCargoToml(TMP, cargoToml, ctx, false);
437
- const result = readToml(cargoToml);
438
-
439
- expect(result).toContain('contracts/*');
440
- expect(result).toContain('tests/*');
441
- });
442
- });
443
-
444
- describe('rewriteCargoToml — preserved workspace root [workspace.dependencies] paths', () => {
445
- it('keeps [workspace.dependencies] paths intact — they are relative within the vendored workspace', async () => {
446
- // [workspace.dependencies] entries like `utils = { path = "contracts/utils" }` are
447
- // relative to the workspace root. Since the entire workspace is vendored intact at
448
- // dependencies/<pkg>/, those relative paths remain correct inside the copy.
449
- // The realpath of `join(originalDir, "contracts/utils")` won't resolve to a pathMap
450
- // key (it's an internal sub-path, not a separate npm package), so the path is left unchanged.
451
- const cargoToml = join(TMP, 'Cargo.toml');
452
- const original = [
453
- '[workspace]',
454
- 'resolver = "2"',
455
- 'members = ["contracts/utils"]',
456
- '',
457
- '[workspace.dependencies]',
458
- 'utils = { path = "contracts/utils" }',
459
- ].join('\n');
460
-
461
- writeToml(cargoToml, original);
462
-
463
- const ctx: RewriteContext = {
464
- pathMap: new Map([['/real/protocol', join(TMP, 'dependencies', 'protocol')]]),
465
- discovered: new Map([['protocol', '/real/protocol']]),
466
- };
467
-
468
- await rewriteCargoToml('/real/protocol', cargoToml, ctx, false);
469
- const result = readToml(cargoToml);
470
-
471
- expect(result).toContain('[workspace]');
472
- expect(result).toContain('[workspace.dependencies]');
473
- // Path unchanged — still relative within the vendored workspace tree
474
- expect(result).toContain('utils = { path = "contracts/utils" }');
475
- });
476
- });
477
-
478
- describe('rewriteCargoTomls', () => {
479
- it('rewrites root Cargo.toml and nested subdir Cargo.toml', async () => {
480
- const depsDir = join(TMP, 'deps');
481
- const crateDir = join(TMP, 'my-crate');
482
- const macrosDir = join(crateDir, 'macros');
483
-
484
- writeToml(
485
- join(crateDir, 'Cargo.toml'),
486
- '[dependencies]\ndep-a = { path = "dependencies/dep-a" }',
487
- );
488
- writeToml(
489
- join(macrosDir, 'Cargo.toml'),
490
- '[dependencies]\ndep-a = { path = "../dependencies/dep-a" }',
491
- );
492
-
493
- const ctx: RewriteContext = {
494
- pathMap: new Map([['/real/dep-a', join(depsDir, 'dep-a')]]),
495
- discovered: new Map([['dep-a', '/real/dep-a']]),
496
- };
497
-
498
- const tree = await collectFiles(crateDir);
499
- await rewriteCargoTomls(crateDir, crateDir, tree, ctx);
500
-
501
- const rootResult = readToml(join(crateDir, 'Cargo.toml'));
502
- const macrosResult = readToml(join(macrosDir, 'Cargo.toml'));
503
-
504
- expect(rootResult).toContain(`path = "${join('..', 'deps', 'dep-a')}"`);
505
- expect(macrosResult).toContain(`path = "${join('..', '..', 'deps', 'dep-a')}"`);
506
- });
507
- });
package/tsconfig.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "extends": "@layerzerolabs/typescript-configuration/tsconfig.base.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./dist",
6
- "lib": ["ESNext"],
7
- "strictPropertyInitialization": false,
8
- "noUnusedLocals": false,
9
- "noUnusedParameters": false,
10
- "jsx": "react-jsx"
11
- },
12
- "exclude": [
13
- "node_modules",
14
- "**/__mocks__/*",
15
- "**/__tests__/*",
16
- "**/*.spec.ts",
17
- "**/*.test.ts",
18
- "dist"
19
- ],
20
- "include": ["src/**/*"]
21
- }
package/tsup.config.ts DELETED
@@ -1,8 +0,0 @@
1
- import { defineConfig } from 'tsup';
2
-
3
- import { createPackageTsupConfig } from '@layerzerolabs/tsup-configuration';
4
-
5
- export default defineConfig(({ watch }) => ({
6
- ...createPackageTsupConfig(),
7
- clean: !watch,
8
- }));