-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial version of angular plugin (closes #138)
- Loading branch information
Showing
14 changed files
with
2,474 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
{ | ||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json", | ||
"version": 1, | ||
"newProjectRoot": "projects", | ||
"projects": { | ||
"knip-angular-example": { | ||
"projectType": "application", | ||
"schematics": { | ||
"@schematics/angular:component": { | ||
"style": "scss" | ||
} | ||
}, | ||
"root": "", | ||
"sourceRoot": "src", | ||
"prefix": "app", | ||
"architect": { | ||
"build": { | ||
"builder": "@angular-devkit/build-angular:browser", | ||
"options": { | ||
"outputPath": "dist/knip-angular-example", | ||
"index": "src/index.html", | ||
"main": "src/main.ts", | ||
"polyfills": [ | ||
"zone.js" | ||
], | ||
"tsConfig": "tsconfig.app.json", | ||
"inlineStyleLanguage": "scss", | ||
"assets": [ | ||
"src/favicon.ico", | ||
"src/assets" | ||
], | ||
"styles": [ | ||
"src/styles.scss" | ||
], | ||
"scripts": [] | ||
}, | ||
"configurations": { | ||
"production": { | ||
"budgets": [ | ||
{ | ||
"type": "initial", | ||
"maximumWarning": "500kb", | ||
"maximumError": "1mb" | ||
}, | ||
{ | ||
"type": "anyComponentStyle", | ||
"maximumWarning": "2kb", | ||
"maximumError": "4kb" | ||
} | ||
], | ||
"outputHashing": "all" | ||
}, | ||
"development": { | ||
"buildOptimizer": false, | ||
"optimization": false, | ||
"vendorChunk": true, | ||
"extractLicenses": false, | ||
"sourceMap": true, | ||
"namedChunks": true | ||
} | ||
}, | ||
"defaultConfiguration": "production" | ||
}, | ||
"serve": { | ||
"builder": "@angular-devkit/build-angular:dev-server", | ||
"configurations": { | ||
"production": { | ||
"browserTarget": "knip-angular-example:build:production" | ||
}, | ||
"development": { | ||
"browserTarget": "knip-angular-example:build:development" | ||
} | ||
}, | ||
"defaultConfiguration": "development" | ||
}, | ||
"extract-i18n": { | ||
"builder": "@angular-devkit/build-angular:extract-i18n", | ||
"options": { | ||
"browserTarget": "knip-angular-example:build" | ||
} | ||
}, | ||
"test": { | ||
"builder": "@angular-devkit/build-angular:karma", | ||
"options": { | ||
"polyfills": [ | ||
"zone.js", | ||
"zone.js/testing" | ||
], | ||
"tsConfig": "tsconfig.spec.json", | ||
"inlineStyleLanguage": "scss", | ||
"assets": [ | ||
"src/favicon.ico", | ||
"src/assets" | ||
], | ||
"styles": [ | ||
"src/styles.scss" | ||
], | ||
"scripts": [] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "@fixtures/angular", | ||
"version": "*", | ||
"scripts": { | ||
"ng": "ng", | ||
"start": "ng serve", | ||
"build": "ng build", | ||
"watch": "ng build --watch --configuration development", | ||
"test": "ng test" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"types": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "./", | ||
"lib": ["ES2022", "dom"] | ||
}, | ||
"angularCompilerOptions": { | ||
"enableI18nLegacyMessageIdFormat": false, | ||
"strictInjectionParameters": true, | ||
"strictInputAccessModifiers": true, | ||
"strictTemplates": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"types": ["jasmine"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Angular | ||
|
||
## Enabled | ||
|
||
This plugin is enabled when any of the following package names and/or regular expressions has a match in `dependencies` | ||
or `devDependencies`: | ||
|
||
- `@angular/cli` | ||
|
||
## Default configuration | ||
|
||
```json | ||
{ | ||
"angular": { | ||
"config": ["angular.json"] | ||
} | ||
} | ||
``` | ||
|
||
Also see [Knip plugins][1] for more information about plugins. | ||
|
||
[1]: https://github.com/webpro/knip/blob/main/README.md#plugins |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { join } from '../../util/path.js'; | ||
import { timerify } from '../../util/Performance.js'; | ||
import { hasDependency, load } from '../../util/plugin.js'; | ||
import { findTypeScriptDependencies } from '../typescript/index.js'; | ||
import type { AngularCLIWorkspaceConfiguration } from './types.js'; | ||
import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js'; | ||
|
||
// link to docs | ||
|
||
export const NAME = 'Angular'; | ||
|
||
/** @public */ | ||
export const ENABLERS = ['@angular/cli']; | ||
|
||
export const isEnabled: IsPluginEnabledCallback = ({ dependencies }) => hasDependency(dependencies, ENABLERS); | ||
|
||
export const CONFIG_FILE_PATTERNS = ['angular.json']; | ||
|
||
const findPluginDependencies: GenericPluginCallback = async (configFilePath, opts) => { | ||
const { cwd } = opts; | ||
const config: AngularCLIWorkspaceConfiguration = await load(configFilePath); | ||
if (!config.projects) return []; | ||
|
||
const dependencies = new Set<string>(); | ||
|
||
for (const project of Object.values(config.projects)) { | ||
if (!project.architect) return []; | ||
for (const target of Object.values(project.architect)) { | ||
const { options } = target; | ||
const [packageName] = typeof target.builder === 'string' ? target.builder.split(':') : []; | ||
if (typeof packageName === 'string') dependencies.add(packageName); | ||
if (options) { | ||
if ('main' in options && typeof options?.main === 'string') { | ||
dependencies.add(join(cwd, options.main)); | ||
} | ||
if ('tsConfig' in options && typeof options.tsConfig === 'string') { | ||
const tsConfigDependencies = await findTypeScriptDependencies(join(cwd, options.tsConfig), opts); | ||
tsConfigDependencies.forEach(dependency => dependencies.add(dependency)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return Array.from(dependencies); | ||
}; | ||
|
||
export const findDependencies = timerify(findPluginDependencies); |
Oops, something went wrong.