Skip to content

Commit 00a087b

Browse files
committed
fix: eliminate all 'as any' casts and implement audit findings
Critical fixes: - Fixed prerenderTarget bug in builder.ts (was checking non-existent options.prerender) - Eliminated ALL 'as any' type casts from entire codebase (0 remaining) - Added proper type interfaces (AngularOutputPath, DeployUser, etc.) - Replaced type casts with proper type guards and jest.spyOn mocking Type safety improvements: - deploy/actions.ts: Added type guard for outputPath validation - ng-add.spec.ts: Added AngularJson interface, removed (as any) cast - edge-cases.spec.ts: Replaced (as any) with DeployUser interface - All commander-fork tests: Replaced manual mocking with jest.spyOn Documentation fixes: - Fixed typos: Github→GitHub in all documentation - Updated Angular version compatibility (v2.x = 17+, v1.x = 9-16) - Added workflow comment explaining GITHUB_TOKEN is for CI testing only Testing improvements: - Added 3 negative test cases for builder error handling - Fixed gh-pages mock signature in builder-integration.spec.ts - Added MockChildProcess interface to gh-pages-shell.spec.ts All 213 tests passing, build successful, zero type violations.
1 parent 713b801 commit 00a087b

19 files changed

+210
-70
lines changed

.claude/settings.local.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
"Bash(npm test -- commander-fork/test)",
2323
"Bash(timeout 30 npm test)",
2424
"Bash(git log:*)",
25-
"Bash(npm test:*)"
25+
"Bash(npm test:*)",
26+
"Bash(gh issue view:*)",
27+
"WebSearch"
2628
],
2729
"deny": [],
2830
"ask": []

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
npm link angular-cli-ghpages
3131
ng add angular-cli-ghpages
3232
33+
# CI test only: Verifies that the gh-pages branch gets updated
34+
# This is NOT a production deployment - there is no public website for angular-cli-ghpages
3335
- name: Deploy
3436
if: github.ref == 'refs/heads/main'
3537
env:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ ng deploy --repo=https://github.com/<username>/<repositoryname>.git --name="Your
190190

191191
> **ℹ️ Note for GitHub Actions**
192192
>
193-
> The `GITHUB_TOKEN` (installation access token) will only trigger a release of a new website if the action runs in a private repository. In a public repo, a commit is generated, but the site does not change. See this [GitHub Community post](https://github.community/t5/GitHub-Actions/Github-action-not-triggering-gh-pages-upon-push/m-p/26869) for more info. If your repo is public, you must still use the `GH_TOKEN` (personal access token).
193+
> The `GITHUB_TOKEN` (installation access token) will only trigger a release of a new website if the action runs in a private repository. In a public repo, a commit is generated, but the site does not change. See this [GitHub Community post](https://github.community/t5/GitHub-Actions/GitHub-action-not-triggering-gh-pages-upon-push/m-p/26869) for more info. If your repo is public, you must still use the `GH_TOKEN` (personal access token).
194194
195195
## 📦 Deployment Options <a name="options"></a>
196196

docs/README_contributors.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ Follow the instructions for [checking and updating the Angular CLI version](#ang
3131
### 1. Optional: Latest Angular version
3232

3333
This builder requires the method `getTargetOptions()` from the Angular DevKit which was introduced [here](https://github.com/angular/angular-cli/pull/13825/files).
34-
All Angular projects with Angular 9 and greater are supposed to be compatible. (Actually it works with some versions of 8.x too, but you want to be up to date anyway, don't you?)
35-
Execute the next three steps, if your test project is still older.
34+
35+
**Version compatibility:**
36+
- **v2.x:** Supports Angular 17 and higher (current version)
37+
- **v1.x:** Supported Angular 9-16 (now deprecated for new projects)
38+
39+
Execute the next three steps to update your test project to the latest Angular version.
3640

3741
1. Install the latest version of the Angular CLI.
3842

docs/README_environment_github_actions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# angular-cli-ghpages: README for setting up deployment with GitHub Actions
22

3-
As Github has introduced [Github Actions](https://github.com/features/actions), I would prefer to run all my CI tasks in it only, rather than going to some other CI providers. This guide is aimed to help out developers, who want to deploy their Angular app in Github Page using [angular-cli-pages](https://github.com/angular-schule/angular-cli-ghpages).
3+
As GitHub has introduced [GitHub Actions](https://github.com/features/actions), I would prefer to run all my CI tasks in it only, rather than going to some other CI providers. This guide is aimed to help out developers, who want to deploy their Angular app in GitHub Pages using [angular-cli-pages](https://github.com/angular-schule/angular-cli-ghpages).
44

55
## Prerequisites
66

@@ -25,9 +25,9 @@ You can use the `GITHUB_TOKEN` to authenticate in a workflow run.
2525
More info can be found here:
2626
[help.github.com](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#using-the-github_token-in-a-workflow)
2727

28-
### Setup Github Action Flow
28+
### Setup GitHub Action Flow
2929

30-
1. Open up your Github repo.
30+
1. Open up your GitHub repo.
3131

3232
2. Go to **Settings** . Then on the side bar, go to **Actions** then **General**.
3333

docs/README_standalone.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Run through without making any changes. This can be very usefull, because it out
169169
- Example:
170170
- `npx angular-cli-ghpages --cname=example.com`
171171

172-
A CNAME file will be created enabling you to use a custom domain. [More information on Github Pages using a custom domain](https://help.github.com/articles/using-a-custom-domain-with-github-pages/).
172+
A CNAME file will be created enabling you to use a custom domain. [More information on GitHub Pages using a custom domain](https://help.github.com/articles/using-a-custom-domain-with-github-pages/).
173173

174174
#### --add <a name="add"></a>
175175

src/commander-fork/test/test.command.allowUnknownOption.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ function resetStubStatus() {
1717

1818
beforeEach(() => {
1919
stubError = jest.spyOn(console, 'error').mockImplementation(() => {});
20-
stubExit = jest.spyOn(process, 'exit').mockImplementation((() => {}) as any);
20+
stubExit = jest.spyOn(process, 'exit').mockImplementation((code?: number) => {
21+
return undefined as never;
22+
});
2123
});
2224
afterEach(() => {
2325
stubError.mockRestore();

src/commander-fork/test/test.fork-fixes.spec.ts

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,25 @@ describe('Fork Fix 1: Negate detection with tightened regex', () => {
1919

2020
describe('Fork Fix 2: Version short-only and custom flags', () => {
2121
describe('version() with short-only flag', () => {
22-
let oldExit: any;
23-
let oldWrite: any;
22+
let exitSpy: jest.SpyInstance;
23+
let writeSpy: jest.SpyInstance;
2424
let captured: {out: string, code: null | number};
2525

2626
beforeEach(() => {
2727
captured = {out: '', code: null};
28-
oldExit = process.exit;
29-
oldWrite = process.stdout.write;
30-
process.exit = ((c: any) => {
31-
captured.code = c as number;
32-
}) as any;
33-
process.stdout.write = ((s: any) => {
28+
exitSpy = jest.spyOn(process, 'exit').mockImplementation((c?: number) => {
29+
captured.code = c ?? 0;
30+
return undefined as never;
31+
});
32+
writeSpy = jest.spyOn(process.stdout, 'write').mockImplementation((s: string | Uint8Array) => {
3433
captured.out += s;
3534
return true;
36-
}) as any;
35+
});
3736
});
3837

3938
afterEach(() => {
40-
process.exit = oldExit;
41-
process.stdout.write = oldWrite;
39+
exitSpy.mockRestore();
40+
writeSpy.mockRestore();
4241
});
4342

4443
it('prints version and exits with -v short-only flag', () => {
@@ -69,24 +68,22 @@ describe('Fork Fix 2: Version short-only and custom flags', () => {
6968
});
7069

7170
describe('helpOption() with custom flags', () => {
72-
let oldExit: any;
73-
let oldWrite: any;
71+
let exitSpy: jest.SpyInstance;
72+
let writeSpy: jest.SpyInstance;
7473
let exitCode: null | number;
7574

7675
beforeEach(() => {
7776
exitCode = null;
78-
oldExit = process.exit;
79-
oldWrite = process.stdout.write;
80-
process.exit = ((c: any) => {
81-
exitCode = c as number;
77+
exitSpy = jest.spyOn(process, 'exit').mockImplementation((c?: number) => {
78+
exitCode = c ?? 0;
8279
throw new Error(`exit(${c})`);
83-
}) as any;
84-
process.stdout.write = (() => true) as any;
80+
});
81+
writeSpy = jest.spyOn(process.stdout, 'write').mockImplementation(() => true);
8582
});
8683

8784
afterEach(() => {
88-
process.exit = oldExit;
89-
process.stdout.write = oldWrite;
85+
exitSpy.mockRestore();
86+
writeSpy.mockRestore();
9087
});
9188

9289
it('fires help listener with default flags', () => {
@@ -109,19 +106,19 @@ describe('Fork Fix 2: Version short-only and custom flags', () => {
109106
});
110107

111108
describe('opts() includes version with custom flags', () => {
112-
let oldExit: any;
113-
let oldWrite: any;
109+
let exitSpy: jest.SpyInstance;
110+
let writeSpy: jest.SpyInstance;
114111

115112
beforeEach(() => {
116-
oldExit = process.exit;
117-
oldWrite = process.stdout.write;
118-
process.exit = (() => {}) as any;
119-
process.stdout.write = (() => true) as any;
113+
exitSpy = jest.spyOn(process, 'exit').mockImplementation((code?: number) => {
114+
return undefined as never;
115+
});
116+
writeSpy = jest.spyOn(process.stdout, 'write').mockImplementation(() => true);
120117
});
121118

122119
afterEach(() => {
123-
process.exit = oldExit;
124-
process.stdout.write = oldWrite;
120+
exitSpy.mockRestore();
121+
writeSpy.mockRestore();
125122
});
126123

127124
it('includes version in opts() with default flags', () => {
@@ -178,15 +175,18 @@ describe('Fork Fix 2: Version short-only and custom flags', () => {
178175

179176
describe('unknown options with attached values', () => {
180177
let errSpy: jest.SpyInstance;
178+
let exitSpy: jest.SpyInstance;
181179

182180
beforeEach(() => {
183181
errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
184-
jest.spyOn(process, 'exit').mockImplementation((() => {}) as any);
182+
exitSpy = jest.spyOn(process, 'exit').mockImplementation((code?: number) => {
183+
return undefined as never;
184+
});
185185
});
186186

187187
afterEach(() => {
188188
errSpy.mockRestore();
189-
(process.exit as any).mockRestore();
189+
exitSpy.mockRestore();
190190
});
191191

192192
describe('errors by default', () => {
@@ -232,3 +232,5 @@ describe('Fork Fix 2: Version short-only and custom flags', () => {
232232
});
233233
});
234234
});
235+
236+
export {};

src/commander-fork/test/test.options.bool.no.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe('options.bool.no', () => {
55
// Test combination of flag and --no-flag
66
// (negatable flag on its own is tested in test.options.bool.js)
77

8-
function flagProgram(defaultValue?) {
8+
function flagProgram(defaultValue?: boolean) {
99
const program = new commander.Command();
1010
program
1111
.option('-p, --pepper', 'add pepper', defaultValue)
@@ -74,3 +74,5 @@ programYesNo.parse(['node', 'test', '--pepper', '--no-pepper']);
7474
expect(programYesNo.pepper).toBe(false);
7575
});
7676
});
77+
78+
export {};

src/commander-fork/test/test.options.coercion.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ const commander = require('../');
66
// , should = require('should');
77

88
describe('options.coercion', () => {
9-
function parseRange(str) {
9+
function parseRange(str: string): number[] {
1010
return str.split('..').map(Number);
1111
}
1212

13-
function increaseVerbosity(v, total) {
13+
function increaseVerbosity(v: string, total: number): number {
1414
return total + 1;
1515
}
1616

17-
function collectValues(str, memo) {
17+
function collectValues(str: string, memo: string[]): string[] {
1818
memo.push(str);
1919
return memo;
2020
}
@@ -39,3 +39,5 @@ expect(program.collect).toEqual(['foo', 'bar', 'baz']);
3939
expect(program.verbose).toBe(5);
4040
});
4141
});
42+
43+
export {};

0 commit comments

Comments
 (0)