MCPcopy Index your code
hub / github.com/cargo-lambda/cargo-lambda-cdk / getManifestPath

Function getManifestPath

src/cargo.ts:37–89  ·  view source on GitHub ↗
(project: CargoProject)

Source from the content-addressed store, hash-verified

35}
36
37export function getManifestPath(project: CargoProject): string {
38 const defaultManifestPath = project.manifestPath || 'Cargo.toml';
39 let manifestPath = defaultManifestPath;
40
41 // Determine what type of URL this is and download (git repo) locally
42 if (project.gitRemote && isValidGitUrl(project.gitRemote)) {
43 const gitReference = project.gitReference || 'HEAD';
44
45 // i.e: 3ed81b4751e8f09bfa39fe743ee143df60304db5 HEAD
46 let latestCommit = exec('git', ['ls-remote', project.gitRemote, gitReference]).stdout.toString().split(/(\s+)/)[0];
47 const localPath = join(tmpdir(), latestCommit);
48
49 if (project.gitForceClone) {
50 rmSync(localPath, { recursive: true, force: true });
51 }
52
53 if (!existsSync(localPath)) {
54 mkdirSync(localPath, { recursive: true });
55
56 const args = ['clone'];
57 if (gitReference === 'HEAD') {
58 args.push('--depth', '1');
59 }
60
61 args.push(project.gitRemote, localPath);
62 exec('git', args);
63
64 if (gitReference !== 'HEAD') {
65 exec('git', ['checkout', gitReference], { cwd: localPath });
66 }
67 }
68
69 // Append Cargo.toml to the path
70 manifestPath = join(localPath, defaultManifestPath);
71 }
72
73 let manifestPathResult;
74 let parsedManifestPath = parse(manifestPath);
75
76 if (parsedManifestPath.base && parsedManifestPath.ext && parsedManifestPath.base === 'Cargo.toml') {
77 manifestPathResult = manifestPath;
78 } else if (parsedManifestPath.base && parsedManifestPath.ext && parsedManifestPath.base != 'Cargo.toml') {
79 throw new Error('manifestPath is specifying a file that is not Cargo.toml');
80 } else {
81 manifestPathResult = join(manifestPath, 'Cargo.toml');
82 }
83
84 if (!existsSync(manifestPathResult)) {
85 throw new Error(`'${manifestPathResult}' is not a path to a Cargo.toml file, use the option \`manifestPath\` to specify the location of the Cargo.toml file`);
86 }
87
88 return manifestPathResult;
89}
90
91function isValidGitUrl(url: string): boolean {
92 const httpsRegex = /^https:\/\/[\w.-]+(:\d+)?\/[\w.-]+\/[\w.-]+(\.git)?$/;

Callers 4

cargo.test.tsFile · 0.90
getTestManifestPathFunction · 0.90
constructorMethod · 0.90
constructorMethod · 0.90

Calls 2

execFunction · 0.90
isValidGitUrlFunction · 0.85

Tested by 1

getTestManifestPathFunction · 0.72