Skip to content

Commit c56c505

Browse files
authored
Merge pull request #637 from TobyAndToby/copilot/fix-635
Fix omitVersions config parsing and documentation
2 parents bc4c78a + 3301d42 commit c56c505

File tree

16 files changed

+158
-9
lines changed

16 files changed

+158
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ E.g. `.glf.json`, `.glfrc.yml`, `.generatelicensefile.jsonc`, `.config/glf.js`,
8989
"exclude": ["your-package", "[email protected]", "/.*prettier.*/i"],
9090

9191
// Omit the version number in the output file
92-
"omitVersion": false
92+
"omitVersions": false
9393
}
9494
```
9595

e2e/config-file/test/cli/append/append.e2e.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { output as outputFileName } from "./config.js";
66
const execAsync = promisify(exec);
77

88
describe("cli", () => {
9-
beforeEach(async () => {});
109

1110
it("should match snapshot when content is appended", async () => {
1211
const configPath = "./test/cli/append/config.js";

e2e/config-file/test/cli/exclude/exclude.e2e.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { output as outputFileName } from "./config.js";
66
const execAsync = promisify(exec);
77

88
describe("cli", () => {
9-
beforeEach(async () => {});
109

1110
it("should match snapshot when content is excluded", async () => {
1211
const configPath = "./test/cli/exclude/config.js";

e2e/config-file/test/cli/inputs-output/inputs-output.e2e.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { output as outputFileName } from "./config.js";
66
const execAsync = promisify(exec);
77

88
describe("cli", () => {
9-
beforeEach(async () => {});
109

1110
it("should match snapshot when inputs and outputs are provided via config file", async () => {
1211
const configPath = "./test/cli/inputs-output/config.js";
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`cli should omit versions when omitVersions is true in config 1`] = `
4+
"This file was generated with the generate-license-file npm package!
5+
https://www.npmjs.com/package/generate-license-file
6+
7+
The following npm package may be included in this product:
8+
9+
- dep-four
10+
11+
This package contains the following license:
12+
13+
# Dep Four
14+
15+
This license file is spelt \`LICENCE\`.
16+
This license should be found.
17+
18+
-----------
19+
20+
The following npm package may be included in this product:
21+
22+
- dep-one
23+
24+
This package contains the following license:
25+
26+
# Dep One
27+
28+
This license file is spelt \`LICENSE.md\`.
29+
This license should be found.
30+
31+
-----------
32+
33+
The following npm package may be included in this product:
34+
35+
- dep-three
36+
37+
This package contains the following license:
38+
39+
# Dep Three
40+
41+
This license file is spelt \`LICENSE\`.
42+
This license should be found.
43+
44+
-----------
45+
46+
The following npm packages may be included in this product:
47+
48+
- dep-two
49+
- dep-two-duplicate
50+
51+
These packages each contain the following license:
52+
53+
# Dep Two
54+
55+
This license file is spelt \`LICENCE.md\`.
56+
This license should be found.
57+
58+
-----------
59+
60+
The following npm package may be included in this product:
61+
62+
- dep-five
63+
64+
This package contains the following license:
65+
66+
MIT
67+
68+
-----------
69+
70+
This file was generated with the generate-license-file npm package!
71+
https://www.npmjs.com/package/generate-license-file
72+
"
73+
`;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
inputs: ["./package.json"],
3+
output: "omit-versions-config-output.txt",
4+
5+
// Test that versions are omitted from the output file.
6+
omitVersions: true,
7+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { exec } from "child_process";
2+
import fs from "fs/promises";
3+
import { promisify } from "util";
4+
import { output as outputFileName } from "./config.js";
5+
6+
const execAsync = promisify(exec);
7+
8+
describe("cli", () => {
9+
10+
it("should omit versions when omitVersions is true in config", async () => {
11+
const configPath = "./test/cli/omit-versions/config.js";
12+
13+
await execAsync(`npx generate-license-file -c ${configPath}`);
14+
15+
const result = await fs.readFile(outputFileName, "utf8");
16+
17+
// Check that the output doesn't contain version numbers
18+
// Should not contain patterns like "@1.0.0" or "[email protected]"
19+
expect(result).not.toMatch(/@\d+\.\d+\.\d+/);
20+
21+
// Should contain package names without versions
22+
expect(result).toMatch(/dep-one/);
23+
expect(result).toMatchSnapshot();
24+
25+
await fs.unlink(outputFileName);
26+
});
27+
});

e2e/config-file/test/cli/replacement/replacement.e2e.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { output as outputFileName } from "./config.js";
66
const execAsync = promisify(exec);
77

88
describe("cli", () => {
9-
beforeEach(async () => {});
109

1110
it("should match snapshot when a package is replaced", async () => {
1211
const configPath = "./test/cli/replacement/config.js";

src/packages/generate-license-file/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ E.g. `.glf.json`, `.glfrc.yml`, `.generatelicensefile.jsonc`, `.config/glf.js`,
8989
"exclude": ["your-package", "[email protected]", "/.*prettier.*/i"],
9090

9191
// Omit the version number in the output file
92-
"omitVersion": false
92+
"omitVersions": false
9393
}
9494
```
9595

src/packages/generate-license-file/src/lib/cli/config/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const configSchema = z
1919
replace: z.record(z.string().nonempty(), z.string().nonempty()).optional(),
2020
exclude: z.string().nonempty().array().optional(),
2121
append: z.string().nonempty().array().optional(),
22+
omitVersions: z.boolean().optional(),
2223
})
2324
.optional();
2425

0 commit comments

Comments
 (0)