Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/chilled-paths-keep-x.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"changed-modules-go": patch
"changed-roots": patch
---

fix: only strip a literal "./" prefix when normalizing paths

The prefix-stripping regex had an unescaped dot, so it matched any single character followed
by a slash. A module under a single-character top-level directory, such as `x/config`, was
reported as `config`, and consumers received a module directory no directory holds.
2 changes: 1 addition & 1 deletion actions/changed-modules-go/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions actions/changed-modules-go/src/__tests__/path-ops.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ describe("matchModule", () => {
const result = matchModule("scripts/build.js", moduleDirectories);
expect(result).toBe("scripts");
});

// A single-character top-level directory used to be stripped along with the "./" prefix,
// so "x/config/go.mod" matched a module named "config" that no directory holds.
test("should keep a single-character top-level directory", () => {
const moduleDirectories = ["x/config"];
const result = matchModule("x/config/go.mod", moduleDirectories);
expect(result).toBe("x/config");
});

test('should still strip a leading "./" prefix', () => {
const moduleDirectories = ["x/config"];
const result = matchModule("./x/config/go.mod", moduleDirectories);
expect(result).toBe("x/config");
});

test('should normalize a module directory given with a "./" prefix', () => {
const moduleDirectories = ["./x/config"];
const result = matchModules(["x/config/go.mod"], moduleDirectories);
expect(result).toEqual([["x/config/go.mod", "x/config"]]);
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion actions/changed-modules-go/src/path-ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function normalizePath(p: string): string {
if (s === "." || s === "./") return ".";

// strip leading ./ and extra slashes
s = s.replace(/^.\//, "").replace(/\/+$/, "");
s = s.replace(/^\.\//, "").replace(/\/+$/, "");
return s;
}

Expand Down
2 changes: 1 addition & 1 deletion actions/changed-roots/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions actions/changed-roots/src/__tests__/path-ops.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ describe("matchModule", () => {
const result = matchModule("scripts/build.js", moduleDirectories);
expect(result).toBe("scripts");
});

// A single-character top-level directory used to be stripped along with the "./" prefix,
// so "x/config/go.mod" matched a module named "config" that no directory holds.
test("should keep a single-character top-level directory", () => {
const moduleDirectories = ["x/config"];
const result = matchModule("x/config/go.mod", moduleDirectories);
expect(result).toBe("x/config");
});

test('should still strip a leading "./" prefix', () => {
const moduleDirectories = ["x/config"];
const result = matchModule("./x/config/go.mod", moduleDirectories);
expect(result).toBe("x/config");
});

test('should normalize a module directory given with a "./" prefix', () => {
const moduleDirectories = ["./x/config"];
const result = matchModules(["x/config/go.mod"], moduleDirectories);
expect(result).toEqual([["x/config/go.mod", "x/config"]]);
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion actions/changed-roots/src/path-ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function normalizePath(p: string): string {
if (s === "." || s === "./") return ".";

// strip leading ./ and extra slashes
s = s.replace(/^.\//, "").replace(/\/+$/, "");
s = s.replace(/^\.\//, "").replace(/\/+$/, "");
return s;
}

Expand Down
Loading