Skip to content

Commit 641b5fc

Browse files
committedJul 8, 2024
Improve Angular plugin a bit + add fixture/test (#717)
1 parent f0f9f5a commit 641b5fc

File tree

9 files changed

+150
-0
lines changed

9 files changed

+150
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"version": 1,
3+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
4+
"projects": {
5+
"app": {
6+
"root": "./",
7+
"sourceRoot": "src",
8+
"projectType": "application",
9+
"prefix": "app",
10+
"architect": {
11+
"build-esbuild": {
12+
"builder": "@angular-builders/custom-esbuild:application",
13+
"options": {
14+
"browser": "./src/browser.ts",
15+
"index": "./src/index.html",
16+
"outputPath": "./www",
17+
"tsConfig": "./tsconfig.app.json",
18+
"inlineStyleLanguage": "scss",
19+
"crossOrigin": "anonymous"
20+
}
21+
},
22+
"build": {
23+
"builder": "@angular-devkit/build-angular:application",
24+
"options": {
25+
"outputPath": "dist/blorp",
26+
"index": "src/index.html",
27+
"browser": "src/main.ts",
28+
"polyfills": ["zone.js"],
29+
"tsConfig": "tsconfig.app.json",
30+
"assets": [
31+
{
32+
"glob": "**/*",
33+
"input": "public"
34+
}
35+
],
36+
"styles": ["src/styles.css"],
37+
"scripts": [],
38+
"server": "src/main.server.ts",
39+
"prerender": true,
40+
"ssr": {
41+
"entry": "src/server.ts"
42+
}
43+
},
44+
"configurations": {
45+
"production": {
46+
"budgets": [
47+
{
48+
"type": "initial",
49+
"maximumWarning": "500kB",
50+
"maximumError": "1MB"
51+
},
52+
{
53+
"type": "anyComponentStyle",
54+
"maximumWarning": "2kB",
55+
"maximumError": "4kB"
56+
}
57+
],
58+
"outputHashing": "all"
59+
},
60+
"development": {
61+
"optimization": false,
62+
"extractLicenses": false,
63+
"sourceMap": true
64+
}
65+
},
66+
"defaultConfiguration": "production"
67+
},
68+
"serve": {
69+
"builder": "@angular-devkit/build-angular:dev-server",
70+
"configurations": {
71+
"production": {
72+
"buildTarget": "blorp:build:production"
73+
},
74+
"development": {
75+
"buildTarget": "blorp:build:development"
76+
}
77+
},
78+
"defaultConfiguration": "development"
79+
},
80+
"extract-i18n": {
81+
"builder": "@angular-devkit/build-angular:extract-i18n"
82+
},
83+
"test": {
84+
"builder": "@angular-devkit/build-angular:karma",
85+
"options": {
86+
"polyfills": ["zone.js", "zone.js/testing"],
87+
"tsConfig": "tsconfig.spec.json",
88+
"assets": [
89+
{
90+
"glob": "**/*",
91+
"input": "public"
92+
}
93+
],
94+
"styles": ["src/styles.css"],
95+
"scripts": []
96+
}
97+
}
98+
}
99+
}
100+
}
101+
}

‎packages/knip/fixtures/plugins/angular2/node_modules/@angular/cli/index.js

Whitespace-only changes.

‎packages/knip/fixtures/plugins/angular2/node_modules/@angular/cli/package.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@fixtures/angular2",
3+
"scripts": {
4+
"ng": "ng"
5+
},
6+
"devDependencies": {
7+
"@angular/cli": "*",
8+
"@angular/ssr": "*",
9+
"@angular-builders/custom-esbuild": "*",
10+
"@angular-devkit/build-angular": "*"
11+
}
12+
}

‎packages/knip/fixtures/plugins/angular2/src/browser.ts

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import { CommonEngine } from '@angular/ssr';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

‎packages/knip/src/plugins/angular/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ const resolveConfig: ResolveConfig<AngularCLIWorkspaceConfiguration> = async (co
3333
if ('main' in opts && typeof opts.main === 'string') {
3434
dependencies.add(toProductionEntryPattern(join(cwd, opts.main)));
3535
}
36+
if ('browser' in opts && typeof opts.browser === 'string') {
37+
dependencies.add(toProductionEntryPattern(join(cwd, opts.browser)));
38+
}
39+
if ('ssr' in opts && opts.ssr && typeof opts.ssr === 'object') {
40+
if ('entry' in opts.ssr && typeof opts.ssr.entry === 'string') {
41+
dependencies.add(toProductionEntryPattern(join(cwd, opts.ssr.entry)));
42+
}
43+
}
3644
}
3745
}
3846
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { test } from 'bun:test';
2+
import assert from 'node:assert/strict';
3+
import { main } from '../../src/index.js';
4+
import { resolve } from '../../src/util/path.js';
5+
import baseArguments from '../helpers/baseArguments.js';
6+
import baseCounters from '../helpers/baseCounters.js';
7+
8+
const cwd = resolve('fixtures/plugins/angular2');
9+
10+
test('Find dependencies with the Angular plugin (2)', async () => {
11+
const { counters } = await main({
12+
...baseArguments,
13+
cwd,
14+
});
15+
16+
assert.deepEqual(counters, {
17+
...baseCounters,
18+
processed: 2,
19+
total: 2,
20+
});
21+
});

0 commit comments

Comments
 (0)
Please sign in to comment.