Skip to content

Commit 4ace621

Browse files
committed
fix: extract the copy destination and sort matches explicitly
1 parent 1f6e4ad commit 4ace621

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/parser-includes.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class ParserIncludes {
150150
const mergedInputs = {...(value.inputs ?? {}), ...globalInputs};
151151
const includeDir = `${cwd}/${stateDir}/includes/${gitData.remote.host}/${value["project"]}/${value["ref"] || "HEAD"}`;
152152
const normalizedFile = fileValue.replace(/^\/+/, "");
153-
const matches = globbySync(normalizedFile, {cwd: includeDir, absolute: true}).sort();
153+
const matches = globbySync(normalizedFile, {cwd: includeDir, absolute: true}).sort((a, b) => a.localeCompare(b));
154154
const filePaths = matches.length > 0 ? matches : [`${includeDir}/${normalizedFile}`];
155155
for (const filePath of filePaths) {
156156
const fileDoc = await Parser.loadYaml(filePath, {inputs: mergedInputs}, expandVariables, writeStreams);
@@ -378,7 +378,8 @@ export class ParserIncludes {
378378

379379
if (remote.schema.startsWith("http")) {
380380
const ext = "tmp-" + Math.random();
381-
await fs.mkdirp(path.dirname(`${cwd}/${target}/${normalizedFile}`));
381+
const destDir = path.dirname(`${cwd}/${target}/${normalizedFile}`);
382+
await fs.mkdirp(destDir);
382383
tmpDir = `${cwd}/${target}.${ext}`;
383384

384385
const isCommitSha = /^[0-9a-f]{40}$/i.test(ref);
@@ -391,7 +392,7 @@ export class ParserIncludes {
391392
`git sparse-checkout set --no-cone ${normalizedFile}`,
392393
isCommitSha ? "git checkout FETCH_HEAD" : "git checkout",
393394
`cd ${cwd}/${stateDir}`,
394-
`cp ${tmpDir}/${normalizedFile} ${path.dirname(`${cwd}/${target}/${normalizedFile}`)}/`,
395+
`cp ${tmpDir}/${normalizedFile} ${destDir}/`,
395396
], cwd);
396397
} else {
397398
await fs.mkdirp(`${cwd}/${target}`);

0 commit comments

Comments
 (0)