@layerzerolabs/build-utils-rust 0.2.113
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/.turbo/turbo-build.log +43 -0
- package/.turbo/turbo-lint.log +8 -0
- package/.turbo/turbo-test.log +58 -0
- package/README.md +111 -0
- package/dist/457ZJTJH.js +52 -0
- package/dist/457ZJTJH.js.map +1 -0
- package/dist/LQ26FJL3.js +112 -0
- package/dist/LQ26FJL3.js.map +1 -0
- package/dist/SPODHCGD.js +59 -0
- package/dist/SPODHCGD.js.map +1 -0
- package/dist/TOEFRNPD.js +83 -0
- package/dist/TOEFRNPD.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/WKRDI535.js +51 -0
- package/dist/WKRDI535.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +28 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -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 +46 -0
- package/src/cli.ts +33 -0
- package/src/index.ts +1 -0
- package/src/logger.ts +26 -0
- package/src/resolve/discover.ts +93 -0
- package/src/resolve/exclude.ts +52 -0
- package/src/resolve/index.ts +122 -0
- package/src/resolve/io.ts +69 -0
- package/src/resolve/rewrite.ts +210 -0
- package/tests/resolve/discover.test.ts +206 -0
- package/tests/resolve/fixtures/index.ts +6 -0
- package/tests/resolve/fixtures/minimal.toml +2 -0
- package/tests/resolve/fixtures/mixed-deps.toml +4 -0
- package/tests/resolve/fixtures/multi-path-deps.toml +9 -0
- package/tests/resolve/fixtures/multi-section-path-deps.toml +13 -0
- package/tests/resolve/fixtures/no-path-deps.toml +3 -0
- package/tests/resolve/fixtures/oapp-with-stale-deps.toml +5 -0
- package/tests/resolve/fixtures/patch-multi-registry.toml +22 -0
- package/tests/resolve/fixtures/program-with-deps.toml +5 -0
- package/tests/resolve/fixtures/program-with-macros.toml +6 -0
- package/tests/resolve/fixtures/program-workspace-member.toml +5 -0
- package/tests/resolve/fixtures/root-only-sections.toml +13 -0
- package/tests/resolve/fixtures/stellar-consumer.toml +8 -0
- package/tests/resolve/fixtures/stellar-member-inheriting.toml +10 -0
- package/tests/resolve/fixtures/stellar-workspace-root.toml +17 -0
- package/tests/resolve/fixtures/stellar-workspace-with-tests.toml +15 -0
- package/tests/resolve/fixtures/target-cfg-path-dep.toml +10 -0
- package/tests/resolve/fixtures/with-features.toml +2 -0
- package/tests/resolve/fixtures/workspace-at-end.toml +6 -0
- package/tests/resolve/fixtures/workspace-at-top.toml +10 -0
- package/tests/resolve/fixtures/workspace-middle.toml +10 -0
- package/tests/resolve/fixtures/workspace-with-default-members.toml +8 -0
- package/tests/resolve/fixtures/workspace-with-path-deps.toml +8 -0
- package/tests/resolve/index.test.ts +298 -0
- package/tests/resolve/rewrite.test.ts +420 -0
- package/tsconfig.json +21 -0
- package/tsup.config.ts +8 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/logger.ts"],"names":["logger","createConsoleLogger","LogLevel","INFO","setLogLevel","level","parseLogLevel","value","toLowerCase","TRACE","DEBUG","WARN","ERROR"],"mappings":";;;;AAKO,IAAIA,MAAAA,GAASC,mBAAAA,CAAoBC,QAAAA,CAASC,IAAI;AAE9C,IAAMC,WAAAA,2BAAeC,KAAAA,KAAAA;AACxBL,EAAAA,MAAAA,GAASC,oBAAoBI,KAAAA,CAAAA;AACjC,CAAA,EAF2B,aAAA;AAKpB,IAAMC,aAAAA,2BAAiBC,KAAAA,KAAAA;AAC1B,EAAA,QAAQA,KAAAA,EAAOC,aAAAA;IACX,KAAK,OAAA;AACD,MAAA,OAAON,QAAAA,CAASO,KAAAA;IACpB,KAAK,OAAA;AACD,MAAA,OAAOP,QAAAA,CAASQ,KAAAA;IACpB,KAAK,MAAA;AACD,MAAA,OAAOR,QAAAA,CAASS,IAAAA;IACpB,KAAK,OAAA;AACD,MAAA,OAAOT,QAAAA,CAASU,KAAAA;AACpB,IAAA;AACI,MAAA,OAAOV,QAAAA,CAASC,IAAAA;AACxB;AACJ,CAAA,EAb6B,eAAA","file":"UDDAJZY4.js","sourcesContent":["import { createConsoleLogger, LogLevel } from '@layerzerolabs/logger-node';\n\nexport type { Logger } from '@layerzerolabs/logger-node';\nexport { LogLevel } from '@layerzerolabs/logger-node';\n\nexport let logger = createConsoleLogger(LogLevel.INFO);\n\nexport const setLogLevel = (level: LogLevel): void => {\n logger = createConsoleLogger(level);\n};\n\n/** Parse a log-level string (CLI flag). Unknown values fall back to INFO. */\nexport const parseLogLevel = (value?: string): LogLevel => {\n switch (value?.toLowerCase()) {\n case 'trace':\n return LogLevel.TRACE;\n case 'debug':\n return LogLevel.DEBUG;\n case 'warn':\n return LogLevel.WARN;\n case 'error':\n return LogLevel.ERROR;\n default:\n return LogLevel.INFO;\n }\n};\n"]}
|
package/dist/VUOMXK5T.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"VUOMXK5T.js"}
|
package/dist/WKRDI535.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { __name } from './VUOMXK5T.js';
|
|
2
|
+
|
|
3
|
+
// src/resolve/exclude.ts
|
|
4
|
+
var COPY_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
5
|
+
".rs",
|
|
6
|
+
".toml",
|
|
7
|
+
".json"
|
|
8
|
+
]);
|
|
9
|
+
var EXCLUDE_DIR = /* @__PURE__ */ new Set([
|
|
10
|
+
// npm directories
|
|
11
|
+
"dependencies",
|
|
12
|
+
"node_modules",
|
|
13
|
+
"target",
|
|
14
|
+
".turbo",
|
|
15
|
+
// cargo directories
|
|
16
|
+
"examples",
|
|
17
|
+
"benches",
|
|
18
|
+
"fuzz",
|
|
19
|
+
".cargo",
|
|
20
|
+
// vcs / ci
|
|
21
|
+
".git",
|
|
22
|
+
".github",
|
|
23
|
+
// shared directories
|
|
24
|
+
"tests"
|
|
25
|
+
]);
|
|
26
|
+
var EXCLUDE_FILE = /* @__PURE__ */ new Set([
|
|
27
|
+
// npm
|
|
28
|
+
"package.json",
|
|
29
|
+
"pnpm-lock.yaml",
|
|
30
|
+
// turbo
|
|
31
|
+
"turbo-snapshot.lock.json",
|
|
32
|
+
"turbo.json",
|
|
33
|
+
// cargo/rust
|
|
34
|
+
"Cargo.lock",
|
|
35
|
+
"clippy.toml",
|
|
36
|
+
"deny.toml",
|
|
37
|
+
"rust-toolchain.toml",
|
|
38
|
+
"rustfmt.toml",
|
|
39
|
+
// solana
|
|
40
|
+
"Anchor.toml"
|
|
41
|
+
]);
|
|
42
|
+
var COPY_EXCLUDES = /* @__PURE__ */ new Set([
|
|
43
|
+
...EXCLUDE_DIR,
|
|
44
|
+
...EXCLUDE_FILE
|
|
45
|
+
]);
|
|
46
|
+
var removeExcludedFiles = /* @__PURE__ */ __name((entries) => entries.filter((entry) => !COPY_EXCLUDES.has(entry)), "removeExcludedFiles");
|
|
47
|
+
var hasExcludedSegment = /* @__PURE__ */ __name((relPath) => relPath.split(/[\\/]+/).some((segment) => EXCLUDE_DIR.has(segment)), "hasExcludedSegment");
|
|
48
|
+
|
|
49
|
+
export { COPY_EXTENSIONS, hasExcludedSegment, removeExcludedFiles };
|
|
50
|
+
//# sourceMappingURL=WKRDI535.js.map
|
|
51
|
+
//# sourceMappingURL=WKRDI535.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/resolve/exclude.ts"],"names":["COPY_EXTENSIONS","Set","EXCLUDE_DIR","EXCLUDE_FILE","COPY_EXCLUDES","removeExcludedFiles","entries","filter","entry","has","hasExcludedSegment","relPath","split","some","segment"],"mappings":";;;AACO,IAAMA,eAAAA,uBAAsBC,GAAAA,CAAI;AAAC,EAAA,KAAA;AAAO,EAAA,OAAA;AAAS,EAAA;AAAQ,CAAA;AAGhE,IAAMC,WAAAA,uBAAkBD,GAAAA,CAAI;;AAExB,EAAA,cAAA;AACA,EAAA,cAAA;AACA,EAAA,QAAA;AACA,EAAA,QAAA;;AAEA,EAAA,UAAA;AACA,EAAA,SAAA;AACA,EAAA,MAAA;AACA,EAAA,QAAA;;AAEA,EAAA,MAAA;AACA,EAAA,SAAA;;AAEA,EAAA;AACH,CAAA,CAAA;AAGD,IAAME,YAAAA,uBAAmBF,GAAAA,CAAI;;AAEzB,EAAA,cAAA;AACA,EAAA,gBAAA;;AAEA,EAAA,0BAAA;AACA,EAAA,YAAA;;AAEA,EAAA,YAAA;AACA,EAAA,aAAA;AACA,EAAA,WAAA;AACA,EAAA,qBAAA;AACA,EAAA,cAAA;;AAEA,EAAA;AACH,CAAA,CAAA;AAED,IAAMG,aAAAA,uBAAoBH,GAAAA,CAAI;AAAIC,EAAAA,GAAAA,WAAAA;AAAgBC,EAAAA,GAAAA;AAAa,CAAA,CAAA;AAGxD,IAAME,mBAAAA,mBAAsB,MAAA,CAAA,CAACC,OAAAA,KAChCA,OAAAA,CAAQC,MAAAA,CAAO,CAACC,KAAAA,KAAU,CAACJ,aAAAA,CAAcK,GAAAA,CAAID,KAAAA,CAAAA,CAAAA,EADd,qBAAA;AAO5B,IAAME,kBAAAA,mBAAqB,MAAA,CAAA,CAACC,OAAAA,KAC/BA,OAAAA,CAAQC,MAAM,QAAA,CAAA,CAAUC,IAAAA,CAAK,CAACC,OAAAA,KAAYZ,WAAAA,CAAYO,GAAAA,CAAIK,OAAAA,CAAAA,CAAAA,EAD5B,oBAAA","file":"WKRDI535.js","sourcesContent":["/** Files vendored into dependencies/ — everything else is skipped by type. */\nexport const COPY_EXTENSIONS = new Set(['.rs', '.toml', '.json']);\n\n/** Directories never descended into when copying or scanning. */\nconst EXCLUDE_DIR = new Set([\n // npm directories\n 'dependencies',\n 'node_modules',\n 'target',\n '.turbo',\n // cargo directories\n 'examples',\n 'benches',\n 'fuzz',\n '.cargo',\n // vcs / ci\n '.git',\n '.github',\n // shared directories\n 'tests',\n]);\n\n/** Files matching COPY_EXTENSIONS that must still be skipped — lockfiles, toolchain config, etc. */\nconst EXCLUDE_FILE = new Set([\n // npm\n 'package.json',\n 'pnpm-lock.yaml',\n // turbo\n 'turbo-snapshot.lock.json',\n 'turbo.json',\n // cargo/rust\n 'Cargo.lock',\n 'clippy.toml',\n 'deny.toml',\n 'rust-toolchain.toml',\n 'rustfmt.toml',\n // solana\n 'Anchor.toml',\n]);\n\nconst COPY_EXCLUDES = new Set([...EXCLUDE_DIR, ...EXCLUDE_FILE]);\n\n/** Filter excluded names from a directory listing. */\nexport const removeExcludedFiles = (entries: string[]): string[] =>\n entries.filter((entry) => !COPY_EXCLUDES.has(entry));\n\n/**\n * True if a resolved crate path contains an excluded segment.\n * Do not use on raw `path` dep values — those legitimately pass through node_modules.\n */\nexport const hasExcludedSegment = (relPath: string): boolean =>\n relPath.split(/[\\\\/]+/).some((segment) => EXCLUDE_DIR.has(segment));\n"]}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env tsx
|
|
2
|
+
import { resolveDependencies } from './TOEFRNPD.js';
|
|
3
|
+
import './LQ26FJL3.js';
|
|
4
|
+
import './457ZJTJH.js';
|
|
5
|
+
import './SPODHCGD.js';
|
|
6
|
+
import { logger, setLogLevel, parseLogLevel } from './UDDAJZY4.js';
|
|
7
|
+
import './WKRDI535.js';
|
|
8
|
+
import { __name } from './VUOMXK5T.js';
|
|
9
|
+
import { Command } from 'commander';
|
|
10
|
+
|
|
11
|
+
var main = /* @__PURE__ */ __name(async () => {
|
|
12
|
+
const program = new Command();
|
|
13
|
+
program.name("build-utils-rust").description("Build utilities for Rust/Cargo packages in LayerZero.");
|
|
14
|
+
program.command("resolve").description("Resolve @layerzerolabs Cargo dependencies from node_modules into a flat dependencies/ directory with rewritten path deps.").option("--cwd <path>", "pnpm package root (where node_modules/ lives). Default: cwd.").option("--cargo-dir <path>", "Cargo crate directory to resolve. Defaults to package root.").option("--log-level <level>", "trace | debug | info | warn | error. Default: info.").action(async (opts) => {
|
|
15
|
+
setLogLevel(parseLogLevel(opts.logLevel));
|
|
16
|
+
await resolveDependencies({
|
|
17
|
+
cwd: opts.cwd,
|
|
18
|
+
cargoDir: opts.cargoDir
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
await program.parseAsync(process.argv);
|
|
22
|
+
}, "main");
|
|
23
|
+
void main().catch((err) => {
|
|
24
|
+
logger.error("build-utils-rust failed", err);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=cli.js.map
|
|
28
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts"],"names":["main","program","Command","name","description","command","option","action","opts","setLogLevel","parseLogLevel","logLevel","resolveDependencies","cwd","cargoDir","parseAsync","process","argv","catch","err","logger","error","exit"],"mappings":";;;;;;;;;;AAMA,IAAMA,uBAAO,MAAA,CAAA,YAAA;AACT,EAAA,MAAMC,OAAAA,GAAU,IAAIC,OAAAA,EAAAA;AACpBD,EAAAA,OAAAA,CACKE,IAAAA,CAAK,kBAAA,CAAA,CACLC,WAAAA,CAAY,uDAAA,CAAA;AAEjBH,EAAAA,OAAAA,CACKI,OAAAA,CAAQ,SAAA,CAAA,CACRD,WAAAA,CACG,2HACI,CAAA,CAEPE,MAAAA,CAAO,gBAAgB,8DAAA,CAAA,CACvBA,OAAO,oBAAA,EAAsB,6DAAA,EAC7BA,MAAAA,CAAO,qBAAA,EAAuB,qDAAA,CAAA,CAC9BC,MAAAA,CAAO,OAAOC,IAAAA,KAAAA;AACXC,IAAAA,WAAAA,CAAYC,aAAAA,CAAcF,IAAAA,CAAKG,QAAQ,CAAA,CAAA;AACvC,IAAA,MAAMC,mBAAAA,CAAoB;AAAEC,MAAAA,GAAAA,EAAKL,IAAAA,CAAKK,GAAAA;AAAKC,MAAAA,QAAAA,EAAUN,IAAAA,CAAKM;KAAS,CAAA;EACvE,CAAA,CAAA;AAEJ,EAAA,MAAMb,OAAAA,CAAQc,UAAAA,CAAWC,OAAAA,CAAQC,IAAI,CAAA;AACzC,CAAA,EArBa,MAAA,CAAA;AAuBb,KAAKjB,IAAAA,EAAAA,CAAOkB,KAAAA,CAAM,CAACC,GAAAA,KAAAA;AACfC,EAAAA,MAAAA,CAAOC,KAAAA,CAAM,2BAA2BF,GAAAA,CAAAA;AACxCH,EAAAA,OAAAA,CAAQM,KAAK,CAAA,CAAA;AACjB,CAAA,CAAA","file":"cli.js","sourcesContent":["#!/usr/bin/env tsx\nimport { Command } from 'commander';\n\nimport { logger, parseLogLevel, setLogLevel } from './logger';\nimport { resolveDependencies } from './resolve';\n\nconst main = async (): Promise<void> => {\n const program = new Command();\n program\n .name('build-utils-rust')\n .description('Build utilities for Rust/Cargo packages in LayerZero.');\n\n program\n .command('resolve')\n .description(\n 'Resolve @layerzerolabs Cargo dependencies from node_modules into a flat ' +\n 'dependencies/ directory with rewritten path deps.',\n )\n .option('--cwd <path>', 'pnpm package root (where node_modules/ lives). Default: cwd.')\n .option('--cargo-dir <path>', 'Cargo crate directory to resolve. Defaults to package root.')\n .option('--log-level <level>', 'trace | debug | info | warn | error. Default: info.')\n .action(async (opts: { cwd?: string; cargoDir?: string; logLevel?: string }) => {\n setLogLevel(parseLogLevel(opts.logLevel));\n await resolveDependencies({ cwd: opts.cwd, cargoDir: opts.cargoDir });\n });\n\n await program.parseAsync(process.argv);\n};\n\nvoid main().catch((err: unknown) => {\n logger.error('build-utils-rust failed', err);\n process.exit(1);\n});\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { resolveDependencies } from './TOEFRNPD.js';
|
|
2
|
+
import './LQ26FJL3.js';
|
|
3
|
+
import './457ZJTJH.js';
|
|
4
|
+
import './SPODHCGD.js';
|
|
5
|
+
import './UDDAJZY4.js';
|
|
6
|
+
import './WKRDI535.js';
|
|
7
|
+
import './VUOMXK5T.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LogLevel } from '@layerzerolabs/logger-node';
|
|
2
|
+
export type { Logger } from '@layerzerolabs/logger-node';
|
|
3
|
+
export { LogLevel } from '@layerzerolabs/logger-node';
|
|
4
|
+
export declare let logger: import("@layerzerolabs/logger-node").Logger;
|
|
5
|
+
export declare const setLogLevel: (level: LogLevel) => void;
|
|
6
|
+
/** Parse a log-level string (CLI flag). Unknown values fall back to INFO. */
|
|
7
|
+
export declare const parseLogLevel: (value?: string) => LogLevel;
|
|
8
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAE3E,YAAY,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD,eAAO,IAAI,MAAM,6CAAqC,CAAC;AAEvD,eAAO,MAAM,WAAW,GAAI,OAAO,QAAQ,KAAG,IAE7C,CAAC;AAEF,6EAA6E;AAC7E,eAAO,MAAM,aAAa,GAAI,QAAQ,MAAM,KAAG,QAa9C,CAAC"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"logger.js"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Discovery — walk node_modules/@layerzerolabs/ to find all @layerzerolabs Cargo crates. */
|
|
2
|
+
import type { CollectedTree } from './io';
|
|
3
|
+
/** A discovered package paired with its collected source tree, ready to vendor. */
|
|
4
|
+
export interface VendorTarget {
|
|
5
|
+
/** npm package name (without scope) — the dependencies/ subdir. */
|
|
6
|
+
pkgName: string;
|
|
7
|
+
/** canonical source path (realpath through pnpm symlinks). */
|
|
8
|
+
npmPkgDir: string;
|
|
9
|
+
/** vendored location: dependencies/<pkgName>. */
|
|
10
|
+
depsPkgDir: string;
|
|
11
|
+
/** included file/dir tree (excluded subtrees already pruned). */
|
|
12
|
+
tree: CollectedTree;
|
|
13
|
+
}
|
|
14
|
+
/** Checks if the directory contains a Cargo.toml. */
|
|
15
|
+
export declare const isCrate: (dir: string) => Promise<boolean>;
|
|
16
|
+
/** True if the directory's Cargo.toml declares a `[workspace]` table. */
|
|
17
|
+
export declare const isWorkspaceRoot: (crateRoot: string) => Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Recursively discover all @layerzerolabs Cargo packages reachable from `dir`'s node_modules.
|
|
20
|
+
* Resolves pnpm symlinks to canonical paths; `visited` prevents re-walking shared deps.
|
|
21
|
+
*/
|
|
22
|
+
export declare const discoverPackages: (dir: string, discovered: Map<string, string>, visited: Set<string>) => Promise<void>;
|
|
23
|
+
//# sourceMappingURL=discover.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover.d.ts","sourceRoot":"","sources":["../../src/resolve/discover.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAO7F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAU1C,mFAAmF;AACnF,MAAM,WAAW,YAAY;IACzB,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC;IAChB,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,UAAU,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,IAAI,EAAE,aAAa,CAAC;CACvB;AAID,qDAAqD;AACrD,eAAO,MAAM,OAAO,GAAU,KAAK,MAAM,KAAG,OAAO,CAAC,OAAO,CAS1D,CAAC;AAEF,yEAAyE;AACzE,eAAO,MAAM,eAAe,GAAU,WAAW,MAAM,KAAG,OAAO,CAAC,OAAO,CAgBxE,CAAC;AAIF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GACzB,KAAK,MAAM,EACX,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,SAAS,GAAG,CAAC,MAAM,CAAC,KACrB,OAAO,CAAC,IAAI,CAoBd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"discover.js"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Files vendored into dependencies/ — everything else is skipped by type. */
|
|
2
|
+
export declare const COPY_EXTENSIONS: Set<string>;
|
|
3
|
+
/** Filter excluded names from a directory listing. */
|
|
4
|
+
export declare const removeExcludedFiles: (entries: string[]) => string[];
|
|
5
|
+
/**
|
|
6
|
+
* True if a resolved crate path contains an excluded segment.
|
|
7
|
+
* Do not use on raw `path` dep values — those legitimately pass through node_modules.
|
|
8
|
+
*/
|
|
9
|
+
export declare const hasExcludedSegment: (relPath: string) => boolean;
|
|
10
|
+
//# sourceMappingURL=exclude.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exclude.d.ts","sourceRoot":"","sources":["../../src/resolve/exclude.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,eAAO,MAAM,eAAe,aAAqC,CAAC;AAyClE,sDAAsD;AACtD,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,EAAE,KAAG,MAAM,EACN,CAAC;AAEzD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,KAAG,OACkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"exclude.js"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendor @layerzerolabs Cargo dependencies from node_modules into a flat
|
|
3
|
+
* dependencies/ directory with rewritten path deps, so a Rust package builds
|
|
4
|
+
* without the rest of the monorepo.
|
|
5
|
+
*/
|
|
6
|
+
import { type VendorTarget } from './discover';
|
|
7
|
+
/** Maps each crate's npm package source path to its vendored dependencies/ location. */
|
|
8
|
+
export declare const buildDependenciesPathMap: (targets: VendorTarget[]) => Map<string, string>;
|
|
9
|
+
/**
|
|
10
|
+
* Entry point: vendor every @layerzerolabs Cargo crate reachable through node_modules
|
|
11
|
+
* into dependencies/, with path deps rewritten to resolve locally.
|
|
12
|
+
*
|
|
13
|
+
* @param cwd pnpm package root (where node_modules/ lives). Default: process.cwd()
|
|
14
|
+
* @param cargoDir Cargo crate directory to vendor into. Default: packageRoot
|
|
15
|
+
*/
|
|
16
|
+
export declare const resolveDependencies: ({ cwd, cargoDir, }?: {
|
|
17
|
+
cwd?: string;
|
|
18
|
+
cargoDir?: string;
|
|
19
|
+
}) => Promise<void>;
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resolve/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,EAA6B,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAQ1E,wFAAwF;AACxF,eAAO,MAAM,wBAAwB,GAAI,SAAS,YAAY,EAAE,KAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAWpF,CAAC;AAoCF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAU,qBAGvC;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,KAAG,OAAO,CAAC,IAAI,CA6CzD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { buildDependenciesPathMap, resolveDependencies } from '../TOEFRNPD.js';
|
|
2
|
+
import '../LQ26FJL3.js';
|
|
3
|
+
import '../457ZJTJH.js';
|
|
4
|
+
import '../SPODHCGD.js';
|
|
5
|
+
import '../UDDAJZY4.js';
|
|
6
|
+
import '../WKRDI535.js';
|
|
7
|
+
import '../VUOMXK5T.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const tryRealpath: (path: string) => Promise<string | undefined>;
|
|
2
|
+
export declare const tryIsDirectory: (path: string) => Promise<boolean>;
|
|
3
|
+
export declare const tryReaddir: (dir: string) => Promise<string[]>;
|
|
4
|
+
export interface CollectedTree {
|
|
5
|
+
/** directories containing copyable content, relative to root (no empties) */
|
|
6
|
+
dirs: string[];
|
|
7
|
+
/** copyable files (COPY_EXTENSIONS), relative to root (excluded subtrees pruned) */
|
|
8
|
+
files: string[];
|
|
9
|
+
/** dirs that directly contain a Cargo.toml (crate roots), relative to root; '.' is the root */
|
|
10
|
+
manifestDirs: string[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Walk `root` once, applying exclusion per level and keeping only COPY_EXTENSIONS files.
|
|
14
|
+
* Also records `manifestDirs` (dirs holding a Cargo.toml) so consumers don't re-scan.
|
|
15
|
+
*/
|
|
16
|
+
export declare const collectFiles: (root: string, relativePath?: string) => Promise<CollectedTree>;
|
|
17
|
+
//# sourceMappingURL=io.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../../src/resolve/io.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,WAAW,GAAU,MAAM,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAM1E,CAAC;AAEF,eAAO,MAAM,cAAc,GAAU,MAAM,MAAM,KAAG,OAAO,CAAC,OAAO,CAMlE,CAAC;AAEF,eAAO,MAAM,UAAU,GAAU,KAAK,MAAM,KAAG,OAAO,CAAC,MAAM,EAAE,CAM9D,CAAC;AAEF,MAAM,WAAW,aAAa;IAC1B,6EAA6E;IAC7E,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,oFAAoF;IACpF,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,+FAA+F;IAC/F,YAAY,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAU,MAAM,MAAM,EAAE,qBAAiB,KAAG,OAAO,CAAC,aAAa,CAyBzF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"io.js"}
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
import { type CollectedTree } from './io';
|
|
6
|
+
/** Bundled resolution state passed through the rewrite pipeline. */
|
|
7
|
+
export interface RewriteContext {
|
|
8
|
+
pathMap: Map<string, string>;
|
|
9
|
+
discovered: Map<string, string>;
|
|
10
|
+
}
|
|
11
|
+
type Table = Record<string, unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* Drop literal `members` / `default-members` entries whose path contains an excluded
|
|
14
|
+
* directory segment (e.g. `tests/mock_vault`) — those dirs are never vendored, so the
|
|
15
|
+
* member would dangle and fail Cargo's workspace load. Globs (`tests/*`) are kept; Cargo
|
|
16
|
+
* re-expands them to a harmless empty match. Returns true if any member was removed.
|
|
17
|
+
*/
|
|
18
|
+
export declare const pruneExcludedLiteralMembers: (manifest: Table) => boolean;
|
|
19
|
+
/** Rebase every path dep in `manifest` into the flat dependencies/ layout. Returns true if any changed. */
|
|
20
|
+
export declare const rewritePathDeps: (manifest: Table, originalDir: string, manifestDir: string, ctx: RewriteContext, includeWorkspaceDeps: boolean) => Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Delete the `[workspace]` / `[patch.*]` / `[profile.*]` tables — invalid or ignored in a
|
|
23
|
+
* vendored dependency (only honored at the real workspace root). Returns true if any was removed.
|
|
24
|
+
*/
|
|
25
|
+
export declare const stripRootOnlyTables: (manifest: Table) => boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Rewrite one vendored Cargo.toml in place: rebase its path deps, then strip the root-only
|
|
28
|
+
* tables — or, for a preserved workspace root (`stripRootTables = false`), prune excluded
|
|
29
|
+
* members instead. Re-serialized only if something changed.
|
|
30
|
+
*
|
|
31
|
+
* @param originalDir source crate dir the manifest was copied from
|
|
32
|
+
* @param cargoTomlPath the vendored Cargo.toml to rewrite
|
|
33
|
+
*/
|
|
34
|
+
export declare const rewriteCargoToml: (originalDir: string, cargoTomlPath: string, ctx: RewriteContext, stripRootTables?: boolean) => Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Rewrite every Cargo.toml in a copied dependency tree. The root manifest keeps its
|
|
37
|
+
* root-only tables when it's a workspace (members inherit from them); all others strip them.
|
|
38
|
+
*/
|
|
39
|
+
export declare const rewriteCargoTomls: (srcRoot: string, destRoot: string, tree: CollectedTree, ctx: RewriteContext) => Promise<void>;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=rewrite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rewrite.d.ts","sourceRoot":"","sources":["../../src/resolve/rewrite.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EAAE,KAAK,aAAa,EAAe,MAAM,MAAM,CAAC;AAEvD,oEAAoE;AACpE,MAAM,WAAW,cAAc;IAC3B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,KAAK,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAmCrC;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,GAAI,UAAU,KAAK,KAAG,OAoB7D,CAAC;AAEF,2GAA2G;AAC3G,eAAO,MAAM,eAAe,GACxB,UAAU,KAAK,EACf,aAAa,MAAM,EACnB,aAAa,MAAM,EACnB,KAAK,cAAc,EACnB,sBAAsB,OAAO,KAC9B,OAAO,CAAC,OAAO,CAiBjB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAAI,UAAU,KAAK,KAAG,OASrD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,GACzB,aAAa,MAAM,EACnB,eAAe,MAAM,EACrB,KAAK,cAAc,EACnB,yBAAsB,KACvB,OAAO,CAAC,IAAI,CAmBd,CAAC;AAiCF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC1B,SAAS,MAAM,EACf,UAAU,MAAM,EAChB,MAAM,aAAa,EACnB,KAAK,cAAc,KACpB,OAAO,CAAC,IAAI,CAWd,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { pruneExcludedLiteralMembers, rewriteCargoToml, rewriteCargoTomls, rewritePathDeps, stripRootOnlyTables } from '../LQ26FJL3.js';
|
|
2
|
+
import '../457ZJTJH.js';
|
|
3
|
+
import '../SPODHCGD.js';
|
|
4
|
+
import '../UDDAJZY4.js';
|
|
5
|
+
import '../WKRDI535.js';
|
|
6
|
+
import '../VUOMXK5T.js';
|
|
7
|
+
//# sourceMappingURL=rewrite.js.map
|
|
8
|
+
//# sourceMappingURL=rewrite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"rewrite.js"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@layerzerolabs/build-utils-rust",
|
|
3
|
+
"version": "0.2.113",
|
|
4
|
+
"private": false,
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"bin": {
|
|
16
|
+
"build-utils-rust": "./src/cli.ts"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"commander": "13.1.0",
|
|
20
|
+
"smol-toml": "^1.7.0",
|
|
21
|
+
"@layerzerolabs/logger-node": "0.2.113"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^22.18.6",
|
|
25
|
+
"tsup": "^8.4.0",
|
|
26
|
+
"tsx": "^4.21.0",
|
|
27
|
+
"vitest": "^3.2.6",
|
|
28
|
+
"@layerzerolabs/tsup-configuration": "0.2.113",
|
|
29
|
+
"@layerzerolabs/typescript-configuration": "0.2.113"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "restricted",
|
|
33
|
+
"registry": "https://registry.npmjs.org/"
|
|
34
|
+
},
|
|
35
|
+
"externalRepoConfig": {
|
|
36
|
+
"targets": [
|
|
37
|
+
"audit-external"
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsup",
|
|
42
|
+
"clean": "rm -rf ./.turbo ./dist ./node_modules",
|
|
43
|
+
"lint": "eslint . --max-warnings 0 || (eslint . --fix --max-warnings 0 && false)",
|
|
44
|
+
"test": "vitest --run --pass-with-no-tests --typecheck"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env tsx
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
|
|
4
|
+
import { logger, parseLogLevel, setLogLevel } from './logger';
|
|
5
|
+
import { resolveDependencies } from './resolve';
|
|
6
|
+
|
|
7
|
+
const main = async (): Promise<void> => {
|
|
8
|
+
const program = new Command();
|
|
9
|
+
program
|
|
10
|
+
.name('build-utils-rust')
|
|
11
|
+
.description('Build utilities for Rust/Cargo packages in LayerZero.');
|
|
12
|
+
|
|
13
|
+
program
|
|
14
|
+
.command('resolve')
|
|
15
|
+
.description(
|
|
16
|
+
'Resolve @layerzerolabs Cargo dependencies from node_modules into a flat ' +
|
|
17
|
+
'dependencies/ directory with rewritten path deps.',
|
|
18
|
+
)
|
|
19
|
+
.option('--cwd <path>', 'pnpm package root (where node_modules/ lives). Default: cwd.')
|
|
20
|
+
.option('--cargo-dir <path>', 'Cargo crate directory to resolve. Defaults to package root.')
|
|
21
|
+
.option('--log-level <level>', 'trace | debug | info | warn | error. Default: info.')
|
|
22
|
+
.action(async (opts: { cwd?: string; cargoDir?: string; logLevel?: string }) => {
|
|
23
|
+
setLogLevel(parseLogLevel(opts.logLevel));
|
|
24
|
+
await resolveDependencies({ cwd: opts.cwd, cargoDir: opts.cargoDir });
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
await program.parseAsync(process.argv);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
void main().catch((err: unknown) => {
|
|
31
|
+
logger.error('build-utils-rust failed', err);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { resolveDependencies } from './resolve';
|
package/src/logger.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createConsoleLogger, LogLevel } from '@layerzerolabs/logger-node';
|
|
2
|
+
|
|
3
|
+
export type { Logger } from '@layerzerolabs/logger-node';
|
|
4
|
+
export { LogLevel } from '@layerzerolabs/logger-node';
|
|
5
|
+
|
|
6
|
+
export let logger = createConsoleLogger(LogLevel.INFO);
|
|
7
|
+
|
|
8
|
+
export const setLogLevel = (level: LogLevel): void => {
|
|
9
|
+
logger = createConsoleLogger(level);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/** Parse a log-level string (CLI flag). Unknown values fall back to INFO. */
|
|
13
|
+
export const parseLogLevel = (value?: string): LogLevel => {
|
|
14
|
+
switch (value?.toLowerCase()) {
|
|
15
|
+
case 'trace':
|
|
16
|
+
return LogLevel.TRACE;
|
|
17
|
+
case 'debug':
|
|
18
|
+
return LogLevel.DEBUG;
|
|
19
|
+
case 'warn':
|
|
20
|
+
return LogLevel.WARN;
|
|
21
|
+
case 'error':
|
|
22
|
+
return LogLevel.ERROR;
|
|
23
|
+
default:
|
|
24
|
+
return LogLevel.INFO;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/** Discovery — walk node_modules/@layerzerolabs/ to find all @layerzerolabs Cargo crates. */
|
|
2
|
+
|
|
3
|
+
import { access, readFile, stat } from 'fs/promises';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import { parse } from 'smol-toml';
|
|
6
|
+
|
|
7
|
+
import { logger } from '../logger';
|
|
8
|
+
import type { CollectedTree } from './io';
|
|
9
|
+
import { tryReaddir, tryRealpath } from './io';
|
|
10
|
+
|
|
11
|
+
// ─── Constants ───
|
|
12
|
+
|
|
13
|
+
/** Only packages under this npm scope are treated as Cargo dependencies. */
|
|
14
|
+
const LZ_SCOPE = '@layerzerolabs';
|
|
15
|
+
|
|
16
|
+
// ─── Types ───
|
|
17
|
+
|
|
18
|
+
/** A discovered package paired with its collected source tree, ready to vendor. */
|
|
19
|
+
export interface VendorTarget {
|
|
20
|
+
/** npm package name (without scope) — the dependencies/ subdir. */
|
|
21
|
+
pkgName: string;
|
|
22
|
+
/** canonical source path (realpath through pnpm symlinks). */
|
|
23
|
+
npmPkgDir: string;
|
|
24
|
+
/** vendored location: dependencies/<pkgName>. */
|
|
25
|
+
depsPkgDir: string;
|
|
26
|
+
/** included file/dir tree (excluded subtrees already pruned). */
|
|
27
|
+
tree: CollectedTree;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ─── Crate Helpers ───
|
|
31
|
+
|
|
32
|
+
/** Checks if the directory contains a Cargo.toml. */
|
|
33
|
+
export const isCrate = async (dir: string): Promise<boolean> => {
|
|
34
|
+
try {
|
|
35
|
+
const stats = await stat(dir);
|
|
36
|
+
if (!stats.isDirectory()) return false;
|
|
37
|
+
await access(join(dir, 'Cargo.toml'));
|
|
38
|
+
return true;
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** True if the directory's Cargo.toml declares a `[workspace]` table. */
|
|
45
|
+
export const isWorkspaceRoot = async (crateRoot: string): Promise<boolean> => {
|
|
46
|
+
const manifestPath = join(crateRoot, 'Cargo.toml');
|
|
47
|
+
let raw: string;
|
|
48
|
+
try {
|
|
49
|
+
raw = await readFile(manifestPath, 'utf-8');
|
|
50
|
+
} catch {
|
|
51
|
+
return false; // no readable Cargo.toml here — not a workspace root
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
return parse(raw).workspace != null;
|
|
55
|
+
} catch (err) {
|
|
56
|
+
// Warn rather than silently treat a malformed manifest as a non-workspace
|
|
57
|
+
// (which would strip its [workspace] table); the parser is stricter than Cargo.
|
|
58
|
+
logger.warn(`failed to parse ${manifestPath}; treating as non-workspace`, err);
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// ─── Main Functions ───
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Recursively discover all @layerzerolabs Cargo packages reachable from `dir`'s node_modules.
|
|
67
|
+
* Resolves pnpm symlinks to canonical paths; `visited` prevents re-walking shared deps.
|
|
68
|
+
*/
|
|
69
|
+
export const discoverPackages = async (
|
|
70
|
+
dir: string,
|
|
71
|
+
discovered: Map<string, string>,
|
|
72
|
+
visited: Set<string>,
|
|
73
|
+
): Promise<void> => {
|
|
74
|
+
const realDir = await tryRealpath(dir);
|
|
75
|
+
if (!realDir || visited.has(realDir)) return;
|
|
76
|
+
visited.add(realDir);
|
|
77
|
+
|
|
78
|
+
const nodeModulesDir = join(dir, 'node_modules', LZ_SCOPE);
|
|
79
|
+
|
|
80
|
+
for (const pkgName of await tryReaddir(nodeModulesDir)) {
|
|
81
|
+
// Resolve pnpm symlink to canonical path (deduplicates across dep chains)
|
|
82
|
+
const realPath = await tryRealpath(join(nodeModulesDir, pkgName));
|
|
83
|
+
const isValidCratePath = realPath && (await isCrate(realPath));
|
|
84
|
+
if (!isValidCratePath) continue;
|
|
85
|
+
|
|
86
|
+
if (!discovered.has(pkgName)) {
|
|
87
|
+
discovered.set(pkgName, realPath);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Walk this package's own node_modules for transitive Cargo deps
|
|
91
|
+
await discoverPackages(realPath, discovered, visited);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Files vendored into dependencies/ — everything else is skipped by type. */
|
|
2
|
+
export const COPY_EXTENSIONS = new Set(['.rs', '.toml', '.json']);
|
|
3
|
+
|
|
4
|
+
/** Directories never descended into when copying or scanning. */
|
|
5
|
+
const EXCLUDE_DIR = new Set([
|
|
6
|
+
// npm directories
|
|
7
|
+
'dependencies',
|
|
8
|
+
'node_modules',
|
|
9
|
+
'target',
|
|
10
|
+
'.turbo',
|
|
11
|
+
// cargo directories
|
|
12
|
+
'examples',
|
|
13
|
+
'benches',
|
|
14
|
+
'fuzz',
|
|
15
|
+
'.cargo',
|
|
16
|
+
// vcs / ci
|
|
17
|
+
'.git',
|
|
18
|
+
'.github',
|
|
19
|
+
// shared directories
|
|
20
|
+
'tests',
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
/** Files matching COPY_EXTENSIONS that must still be skipped — lockfiles, toolchain config, etc. */
|
|
24
|
+
const EXCLUDE_FILE = new Set([
|
|
25
|
+
// npm
|
|
26
|
+
'package.json',
|
|
27
|
+
'pnpm-lock.yaml',
|
|
28
|
+
// turbo
|
|
29
|
+
'turbo-snapshot.lock.json',
|
|
30
|
+
'turbo.json',
|
|
31
|
+
// cargo/rust
|
|
32
|
+
'Cargo.lock',
|
|
33
|
+
'clippy.toml',
|
|
34
|
+
'deny.toml',
|
|
35
|
+
'rust-toolchain.toml',
|
|
36
|
+
'rustfmt.toml',
|
|
37
|
+
// solana
|
|
38
|
+
'Anchor.toml',
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
const COPY_EXCLUDES = new Set([...EXCLUDE_DIR, ...EXCLUDE_FILE]);
|
|
42
|
+
|
|
43
|
+
/** Filter excluded names from a directory listing. */
|
|
44
|
+
export const removeExcludedFiles = (entries: string[]): string[] =>
|
|
45
|
+
entries.filter((entry) => !COPY_EXCLUDES.has(entry));
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* True if a resolved crate path contains an excluded segment.
|
|
49
|
+
* Do not use on raw `path` dep values — those legitimately pass through node_modules.
|
|
50
|
+
*/
|
|
51
|
+
export const hasExcludedSegment = (relPath: string): boolean =>
|
|
52
|
+
relPath.split(/[\\/]+/).some((segment) => EXCLUDE_DIR.has(segment));
|