Skip to content

Commit

Permalink
feat(workspace): Harden Projen component types
Browse files Browse the repository at this point in the history
First-pass to make Projen types hardened by making root properties
read-only.

Related to #834.
  • Loading branch information
langri-sha committed Jul 20, 2024
1 parent e281134 commit 3458f49
Show file tree
Hide file tree
Showing 26 changed files with 139 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat(workspace): Harden Projen component types",
"packageName": "@langri-sha/projen-babel",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat(workspace): Harden Projen component types",
"packageName": "@langri-sha/projen-beachball",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat(workspace): Harden Projen component types",
"packageName": "@langri-sha/projen-codeowners",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat(workspace): Harden Projen component types",
"packageName": "@langri-sha/projen-editorconfig",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat(workspace): Harden Projen component types",
"packageName": "@langri-sha/projen-eslint",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat(workspace): Harden Projen component types",
"packageName": "@langri-sha/projen-jest-config",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat(workspace): Harden Projen component types",
"packageName": "@langri-sha/projen-lint-staged",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat(workspace): Harden Projen component types",
"packageName": "@langri-sha/projen-lint-synthesized",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat(workspace): Harden Projen component types",
"packageName": "@langri-sha/projen-pnpm-workspace",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat(workspace): Harden Projen component types",
"packageName": "@langri-sha/projen-prettier",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat(workspace): Harden Projen component types",
"packageName": "@langri-sha/projen-project",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat(workspace): Harden Projen component types",
"packageName": "@langri-sha/projen-readme",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat(workspace): Harden Projen component types",
"packageName": "@langri-sha/projen-typescript-config",
"email": "[email protected]",
"dependentChangeType": "patch"
}
6 changes: 3 additions & 3 deletions packages/projen-babel/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ export interface BabelOptions {
*
* @default 'babel.config.js'
*/
filename?: string
readonly filename?: string

/**
* Whether to output a config function, and the code to be executed.
*/
configApiFunction?: string
readonly configApiFunction?: string

/**
* Options for transforming Babel.
*/
options?: TransformOptions
readonly options?: TransformOptions
}

export class Babel extends FileBase {
Expand Down
4 changes: 2 additions & 2 deletions packages/projen-beachball/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { Project, TextFile } from 'projen'
* Options for configuring Beachball.
*/
export interface BeachballOptions {
filename?: string
config?: BeachballConfig
readonly filename?: string
readonly config?: BeachballConfig
}

export class Beachball extends TextFile {
Expand Down
2 changes: 1 addition & 1 deletion packages/projen-codeowners/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Component, type Project, TextFile } from 'projen'
* Codeowners options.
*/
export interface CodeownersOptions {
[pattern: string]: string | string[]
readonly [pattern: string]: string | string[]
}

/**
Expand Down
21 changes: 13 additions & 8 deletions packages/projen-editorconfig/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,48 @@ import { Component, IniFile, type Project } from 'projen'
* EditorConfig options.
*/
export interface EditorConfigOptions {
[pattern: string]: {
readonly [pattern: string]: {
/**
* Enforce either spaces or tabs for indentation.
*/
indent_style?: 'tab' | 'space'
readonly indent_style?: 'tab' | 'space'

/**
* The number of spaces per indent level OR the string "tab" to use the editor's tab settings.
*/
indent_size?: number | 'tab'
readonly indent_size?: number | 'tab'

/**
* The number of spaces a tab represents (overrides the editor's setting if indent_style is 'tab').
*/
tab_width?: number
readonly tab_width?: number

/**
* Specifies the line ending format (LF, CRLF, or CR).
*/
end_of_line?: 'lf' | 'crlf' | 'cr'
readonly end_of_line?: 'lf' | 'crlf' | 'cr'

/**
* Specifies the encoding of the file.
*/

charset?: 'latin1' | 'utf-8' | 'utf-8-bom' | 'utf-16be' | 'utf-16le'
readonly charset?:
| 'latin1'
| 'utf-8'
| 'utf-8-bom'
| 'utf-16be'
| 'utf-16le'

/**
* Trims any whitespace at the end of lines.
* @default true
*/
trim_trailing_whitespace?: boolean
readonly trim_trailing_whitespace?: boolean

/**
* Ensures a single newline at the end of the file.
*/
insert_final_newline?: boolean
readonly insert_final_newline?: boolean
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/projen-eslint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ export interface ESLintOptions {
*
* @default 'eslint.config.js'
*/
filename?: string
readonly filename?: string

/**
* Name of the ESLint configuration package to extend from.
*/
extends?: string
readonly extends?: string

/**
* Ignore patterns.
*/
ignorePatterns?: string[]
readonly ignorePatterns?: string[]

/**
* Prettier configuration object.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
config?: any[]
readonly config?: any[]
}

export class ESLint extends FileBase {
Expand Down
6 changes: 3 additions & 3 deletions packages/projen-jest-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ export interface JestConfigOptions {
*
* @default 'jest.config.ts'
*/
filename?: string
readonly filename?: string

/**
* Name of a Jest configuration package to extend from.
*/
extends?: string
readonly extends?: string

/**
* Jest configuration object.
*/
config?: Config
readonly config?: Config
}

export class JestConfig extends FileBase {
Expand Down
6 changes: 3 additions & 3 deletions packages/projen-lint-staged/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ export interface LintStagedOptions {
*
* @default 'lint-staged.config.js'
*/
filename?: string
readonly filename?: string

/**
* Name of the `lint-staged` configuration package to extend from.
*/
extends?: string
readonly extends?: string

/**
* `lint-staged` configuration.
*/
config?: Config
readonly config?: Config
}

export class LintStaged extends FileBase {
Expand Down
2 changes: 1 addition & 1 deletion packages/projen-lint-synthesized/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Component, Project } from 'projen'
const debug = createDebug('projen-lint-synthesized')

export interface LintSynthesizedOptions {
[pattern: string]: string | ((files: string[]) => string)
readonly [pattern: string]: string | ((files: string[]) => string)
}

/**
Expand Down
13 changes: 9 additions & 4 deletions packages/projen-pnpm-workspace/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export interface PnpmWorkspaceOptions {
*
* @default 'pnpm-workspace.yaml'
*/
filename?: string
readonly filename?: string

/**
* List of package paths.
*/
packages?: string[]
readonly packages?: string[]
}

export class PnpmWorkspace extends YamlFile {
Expand Down Expand Up @@ -70,8 +70,9 @@ export class PnpmWorkspace extends YamlFile {
return
}

const parsed: Required<Exclude<PnpmWorkspaceOptions, 'filename'>> =
YAML.parse(yaml)
const parsed: Writable<
Required<Exclude<PnpmWorkspaceOptions, 'filename'>>
> = YAML.parse(yaml)

parsed.packages = [...new Set(parsed.packages)]
parsed.packages.sort()
Expand All @@ -91,3 +92,7 @@ export class PnpmWorkspace extends YamlFile {
}
}
}

type Writable<T> = {
-readonly [K in keyof T]: T[K]
}
8 changes: 4 additions & 4 deletions packages/projen-prettier/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ export interface PrettierOptions {
*
* @default 'prettier.config.js'
*/
filename?: string
readonly filename?: string

/**
* Name of the Prettier configuration package to extend from.
*/
extends?: string
readonly extends?: string

/**
* Ignore patterns.
*/
ignorePatterns?: string[]
readonly ignorePatterns?: string[]

/**
* Prettier configuration object.
*/
config?: Config
readonly config?: Config
}

export class Prettier extends FileBase {
Expand Down
4 changes: 2 additions & 2 deletions packages/projen-project/src/lib/node-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { Project, javascript } from 'projen'
* Options for configuring Node.js packages.
*/
export interface NodePackageOptions extends javascript.NodePackageOptions {
peerDependenciesMeta?: Record<string, { optional?: boolean }>
type?: 'commonjs' | 'module'
readonly peerDependenciesMeta?: Record<string, { optional?: boolean }>
readonly type?: 'commonjs' | 'module'
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/projen-readme/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Project, SampleFile } from 'projen'
* Initial `README` for new packages.
*/
export interface ReadmeFileOptions {
filename?: string
readonly filename?: string
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/projen-typescript-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type { JSONSchemaForTheTypeScriptCompilerSConfigurationFile } from '@sche
import { IResolver, JsonFile, Project } from 'projen'

export interface TypeScriptConfigOptions {
fileName?: string
readonly fileName?: string

config?: JSONSchemaForTheTypeScriptCompilerSConfigurationFile & {
readonly config?: JSONSchemaForTheTypeScriptCompilerSConfigurationFile & {
/**
* Referenced projects. Requires TypeScript version 3.0 or later.
*/
Expand Down

0 comments on commit 3458f49

Please sign in to comment.