Skip to content

Commit

Permalink
🗂️ types(none): improve typechecking (#2396)
Browse files Browse the repository at this point in the history
- types: set strict mode for @roots/blade-loader
- types: set strict mode for @roots/bud-babel
- types: set strict mode for @roots/bud-build

## Type of change

**PATCH: backwards compatible change**
  • Loading branch information
kellymears committed Aug 5, 2023
1 parent 0945f3c commit f133de1
Show file tree
Hide file tree
Showing 125 changed files with 930 additions and 773 deletions.
40 changes: 39 additions & 1 deletion config/vitest/alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,49 @@ export default {
...packages.reduce((aliases, packageRoot) => {
const signifier = relative(path(), packageRoot)
aliases[signifier] = join(packageRoot, `src`)
aliases[join(signifier, `*`)] = join(packageRoot, `src`, `*`)
return aliases
}, {}),
'@roots/blade-loader': path(`sources/@roots/blade-loader/src/plugin.ts`),
'@roots/browserslist-config': path(`sources/@roots/browserslist-config`),
'@roots/bud': path(`sources/@roots/bud/src`),
'@roots/bud-api': path(`sources/@roots/bud-api/src`),
'@roots/bud-babel': path(`sources/@roots/bud-babel/src`),
'@roots/bud-build': path(`sources/@roots/bud-build/src`),
'@roots/bud-cache': path(`sources/@roots/bud-cache/src`),
'@roots/bud-client': path(`sources/@roots/bud-client/src`),
'@roots/bud-compiler': path(`sources/@roots/bud-compiler/src`),
'@roots/bud-compress': path(`sources/@roots/bud-compress/src`),
'@roots/bud-criticalcss': path(`sources/@roots/bud-criticalcss/src`),
'@roots/bud-dashboard': path(`sources/@roots/bud-dashboard/src`),
'@roots/bud-emotion': path(`sources/@roots/bud-emotion/src`),
'@roots/bud-entrypoints': path(`sources/@roots/bud-entrypoints/src`),
'@roots/bud-esbuild': path(`sources/@roots/bud-esbuild/src`),
'@roots/bud-eslint': path(`sources/@roots/bud-eslint/src`),
'@roots/bud-extensions': path(`sources/@roots/bud-extensions/src`),
'@roots/bud-framework': path(`sources/@roots/bud-framework/src`),
'@roots/bud-hooks': path(`sources/@roots/bud-hooks/src`),
'@roots/bud-imagemin': path(`sources/@roots/bud-imagemin/src`),
'@roots/bud-mdx': path(`sources/@roots/bud-mdx/src`),
'@roots/bud-minify': path(`sources/@roots/bud-minify/src`),
'@roots/bud-postcss': path(`sources/@roots/bud-postcss/src`),
'@roots/bud-preset-recommend': path(`sources/@roots/bud-preset-recommend/src`),
'@roots/bud-preset-wordpress': path(`sources/@roots/bud-preset-wordpress/src`),
'@roots/bud-prettier': path(`sources/@roots/bud-prettier/src`),
'@roots/bud-purgecss': path(`sources/@roots/bud-purgecss/src`),
'@roots/bud-react': path(`sources/@roots/bud-react/src`),
'@roots/bud-sass': path(`sources/@roots/bud-sass/src`),
'@roots/bud-server': path(`sources/@roots/bud-server/src`),
'@roots/bud-solid': path(`sources/@roots/bud-solid/src`),
'@roots/bud-stylelint': path(`sources/@roots/bud-stylelint/src`),
'@roots/bud-support': path(`sources/@roots/bud-support/src`),
'@roots/bud-swc': path(`sources/@roots/bud-swc/src`),
'@roots/bud-tailwindcss': path(`sources/@roots/bud-tailwindcss/src`),
'@roots/bud-tailwindcss-theme-json': path(`sources/@roots/bud-tailwindcss-theme-json/src`),
'@roots/bud-typescript': path(`sources/@roots/bud-typescript/src`),
'@roots/bud-vue': path(`sources/@roots/bud-vue/src`),
'@roots/bud-wordpress-dependencies': path(`sources/@roots/bud-wordpress-dependencies/src`),
'@roots/filesystem/src/vendor/sdk': path(
`sources/@roots/filesystem/vendor/sdk`,
),
'@roots/sage': path(`sources/@roots/sage/src`),
}
20 changes: 4 additions & 16 deletions sources/@roots/blade-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,10 @@
],
"type": "module",
"exports": {
".": {
"import": "./lib/plugin.js",
"default": "./lib/plugin.js"
},
"./plugin": {
"import": "./lib/plugin.js",
"default": "./lib/plugin.js"
},
"./module-loader": {
"require": "./lib/module-loader.cjs",
"default": "./lib/module-loader.cjs"
},
"./asset-loader": {
"require": "./lib/asset-loader.cjs",
"default": "./lib/asset-loader.cjs"
}
".": "./lib/plugin.js",
"./plugin": "./lib/plugin.js",
"./module-loader": "./lib/module-loader.cjs",
"./asset-loader": "./lib/asset-loader.cjs"
},
"types": "./lib/plugin.d.ts",
"main": "./lib/plugin.js",
Expand Down
8 changes: 1 addition & 7 deletions sources/@roots/blade-loader/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@
"compilerOptions": {
"rootDir": "./src",
"outDir": "./lib",
"paths": {
"@roots/blade-loader": ["./src/plugin.ts"],
"@roots/blade-loader/asset-loader": ["./src/asset-loader.cts"],
"@roots/blade-loader/module-loader": ["./src/module-loader.cts"],
"@roots/blade-loader/plugin": ["./src/plugin.ts"]
},
"strict": true,
"verbatimModuleSyntax": false
},
"include": ["./src"],
"exclude": ["./lib", "./node_modules", "**/*.test.ts"]
}
120 changes: 112 additions & 8 deletions sources/@roots/bud-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,140 @@
"type": "module",
"exports": {
".": "./lib/index.js",
"./api": "./lib/api/index.js",
"./methods": "./lib/methods/index.js",
"./methods/*": "./lib/methods/*/index.js"
"./methods/alias": "./lib/methods/alias/index.js",
"./methods/assets": "./lib/methods/assets/index.js",
"./methods/bundle": "./lib/methods/bundle/index.js",
"./methods/compilePaths": "./lib/methods/compilePaths/index.js",
"./methods/config": "./lib/methods/config/index.js",
"./methods/copyDir": "./lib/methods/copyDir/index.js",
"./methods/copyFile": "./lib/methods/copyFile/index.js",
"./methods/define": "./lib/methods/define/index.js",
"./methods/devtool": "./lib/methods/devtool/index.js",
"./methods/entry": "./lib/methods/entry/index.js",
"./methods/experiments": "./lib/methods/experiments/index.js",
"./methods/externals": "./lib/methods/externals/index.js",
"./methods/hash": "./lib/methods/hash/index.js",
"./methods/html": "./lib/methods/html/index.js",
"./methods/minimize": "./lib/methods/minimize/index.js",
"./methods/persist": "./lib/methods/persist/index.js",
"./methods/provide": "./lib/methods/provide/index.js",
"./methods/proxy": "./lib/methods/proxy/index.js",
"./methods/runtime": "./lib/methods/runtime/index.js",
"./methods/serve": "./lib/methods/serve/index.js",
"./methods/setProxyUrl": "./lib/methods/setProxyUrl/index.js",
"./methods/setPublicProxyUrl": "./lib/methods/setPublicProxyUrl/index.js",
"./methods/setPublicUrl": "./lib/methods/setPublicUrl/index.js",
"./methods/setUrl": "./lib/methods/setUrl/index.js",
"./methods/splitChunks": "./lib/methods/splitChunks/index.js",
"./methods/use": "./lib/methods/use/index.js",
"./methods/watch": "./lib/methods/watch/index.js",
"./service": "./lib/service/index.js"
},
"typesVersions": {
"*": {
".": [
"./lib/index.d.ts"
],
"api": [
"./lib/api/index.d.ts"
],
"methods": [
"./lib/methods/index.d.ts"
],
"methods/*": [
"./lib/methods/*/index.d.ts"
"methods/alias": [
"./lib/methods/alias/index.d.ts"
],
"methods/assets": [
"./lib/methods/assets/index.d.ts"
],
"methods/bundle": [
"./lib/methods/bundle/index.d.ts"
],
"methods/compilePaths": [
"./lib/methods/compilePaths/index.d.ts"
],
"methods/config": [
"./lib/methods/config/index.d.ts"
],
"methods/copyDir": [
"./lib/methods/copyDir/index.d.ts"
],
"methods/copyFile": [
"./lib/methods/copyFile/index.d.ts"
],
"methods/define": [
"./lib/methods/define/index.d.ts"
],
"methods/devtool": [
"./lib/methods/devtool/index.d.ts"
],
"methods/entry": [
"./lib/methods/entry/index.d.ts"
],
"methods/experiments": [
"./lib/methods/experiments/index.d.ts"
],
"methods/externals": [
"./lib/methods/externals/index.d.ts"
],
"methods/hash": [
"./lib/methods/hash/index.d.ts"
],
"methods/html": [
"./lib/methods/html/index.d.ts"
],
"methods/minimize": [
"./lib/methods/minimize/index.d.ts"
],
"methods/persist": [
"./lib/methods/persist/index.d.ts"
],
"methods/provide": [
"./lib/methods/provide/index.d.ts"
],
"methods/proxy": [
"./lib/methods/proxy/index.d.ts"
],
"methods/runtime": [
"./lib/methods/runtime/index.d.ts"
],
"methods/serve": [
"./lib/methods/serve/index.d.ts"
],
"methods/setProxyUrl": [
"./lib/methods/setProxyUrl/index.d.ts"
],
"methods/setPublicProxyUrl": [
"./lib/methods/setPublicProxyUrl/index.d.ts"
],
"methods/setPublicUrl": [
"./lib/methods/setPublicUrl/index.d.ts"
],
"methods/setUrl": [
"./lib/methods/setUrl/index.d.ts"
],
"methods/splitChunks": [
"./lib/methods/splitChunks/index.d.ts"
],
"methods/use": [
"./lib/methods/use/index.d.ts"
],
"methods/watch": [
"./lib/methods/watch/index.d.ts"
],
"service": [
"./lib/service/index.d.ts"
]
}
},
"types": "./lib/index.d.ts",
"module": "./lib/index.js",
"devDependencies": {
"@roots/bud-minify": "workspace:*",
"@skypack/package-check": "0.2.2",
"@types/node": "18.16.19"
},
"dependencies": {
"@roots/bud-extensions": "workspace:*",
"@roots/bud-framework": "workspace:*",
"@roots/bud-minify": "workspace:*",
"@roots/bud-support": "workspace:*",
"@roots/container": "workspace:*",
"chalk": "5.3.0",
Expand Down
69 changes: 40 additions & 29 deletions sources/@roots/bud-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,35 @@
* @see https://github.com/roots/bud
*/

import type {Api as Service} from './api/service.js'
import type * as Alias from './methods/alias/index.js'
import type * as Assets from './methods/assets/index.js'
import type * as Bundle from './methods/bundle/index.js'
import type * as CompilePaths from './methods/compilePaths/index.js'
import type * as Config from './methods/config/index.js'
import type * as CopyDir from './methods/copyDir/index.js'
import type * as CopyFile from './methods/copyFile/index.js'
import type * as Define from './methods/define/index.js'
import type * as Devtool from './methods/devtool/index.js'
import type * as Entry from './methods/entry/index.js'
import type * as Experiments from './methods/experiments/index.js'
import type * as Externals from './methods/externals/index.js'
import type * as Hash from './methods/hash/index.js'
import type * as Html from './methods/html/index.js'
import type * as Minimize from './methods/minimize/index.js'
import type * as Persist from './methods/persist/index.js'
import type * as Provide from './methods/provide/index.js'
import type * as Proxy from './methods/proxy/index.js'
import type * as Runtime from './methods/runtime/index.js'
import type * as Serve from './methods/serve/index.js'
import type * as SetProxyUrl from './methods/setProxyUrl/index.js'
import type * as SetPublicProxyUrl from './methods/setPublicProxyUrl/index.js'
import type * as SetPublicUrl from './methods/setPublicUrl/index.js'
import type * as SetUrl from './methods/setUrl/index.js'
import type * as SplitChunks from './methods/splitChunks/index.js'
import type * as Use from './methods/use/index.js'
import type * as Watch from './methods/watch/index.js'
import type * as Alias from '@roots/bud-api/methods/alias'
import type * as Assets from '@roots/bud-api/methods/assets'
import type * as Bundle from '@roots/bud-api/methods/bundle'
import type * as CompilePaths from '@roots/bud-api/methods/compilePaths'
import type * as Config from '@roots/bud-api/methods/config'
import type * as CopyDir from '@roots/bud-api/methods/copyDir'
import type * as CopyFile from '@roots/bud-api/methods/copyFile'
import type * as Define from '@roots/bud-api/methods/define'
import type * as Devtool from '@roots/bud-api/methods/devtool'
import type * as Entry from '@roots/bud-api/methods/entry'
import type * as Experiments from '@roots/bud-api/methods/experiments'
import type * as Externals from '@roots/bud-api/methods/externals'
import type * as Hash from '@roots/bud-api/methods/hash'
import type * as Html from '@roots/bud-api/methods/html'
import type * as Minimize from '@roots/bud-api/methods/minimize'
import type * as Persist from '@roots/bud-api/methods/persist'
import type * as Provide from '@roots/bud-api/methods/provide'
import type * as Proxy from '@roots/bud-api/methods/proxy'
import type * as Runtime from '@roots/bud-api/methods/runtime'
import type * as Serve from '@roots/bud-api/methods/serve'
import type * as SetProxyUrl from '@roots/bud-api/methods/setProxyUrl'
import type * as SetPublicProxyUrl from '@roots/bud-api/methods/setPublicProxyUrl'
import type * as SetPublicUrl from '@roots/bud-api/methods/setPublicUrl'
import type * as SetUrl from '@roots/bud-api/methods/setUrl'
import type * as SplitChunks from '@roots/bud-api/methods/splitChunks'
import type * as Use from '@roots/bud-api/methods/use'
import type * as Watch from '@roots/bud-api/methods/watch'

import {default as Service} from '@roots/bud-api/service'

declare module '@roots/bud-framework' {
interface Bud {
Expand Down Expand Up @@ -171,6 +172,11 @@ declare module '@roots/bud-framework' {
*/
html(...params: Html.Parameters): Bud

/**
* @roots/bud-minify
*/
minify: import('@roots/bud-minify').default

/**
* ## bud.minimize
*
Expand Down Expand Up @@ -298,6 +304,11 @@ declare module '@roots/bud-framework' {
}

type Api = Service

interface Services {
api: Service
extensions: import('@roots/bud-extensions').default
}
}

export {Api as default} from './api/service.js'
export {Service as default}
2 changes: 1 addition & 1 deletion sources/@roots/bud-api/src/methods/assets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const assets: assets = async function assets(

app.extensions
.get(`@roots/bud-extensions/copy-webpack-plugin`)
.set(`patterns`, (patterns = []) => [
?.set(`patterns`, (patterns = []) => [
...patterns,
...arrayedRequest.map(valueMapper),
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as methods from '../methods/index.js'
/**
* Bud.API {@link ServiceContainer}
*/
export class Api extends ServiceContainer implements BudApi {
class Api extends ServiceContainer implements BudApi {
/**
* {@link BudApi.label}
*/
Expand All @@ -23,3 +23,5 @@ export class Api extends ServiceContainer implements BudApi {
)
}
}

export {Api as default}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {factory} from '@repo/test-kit'
import {type Bud, factory} from '@repo/test-kit'
import {assets} from '@roots/bud-api/methods/assets'
import {beforeEach, describe, expect, it} from 'vitest'

describe(`bud.assets`, () => {
let bud
let bud: Bud
let assetsFn: typeof assets

beforeEach(async () => {
Expand Down
13 changes: 9 additions & 4 deletions sources/@roots/bud-api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
{
"extends": "../../../config/tsconfig.json",
"compilerOptions": {
"strict": true,
"rootDir": "./src",
"outDir": "./lib",
"paths": {
"@roots/bud-api": ["./src/index.ts"],
"@roots/bud-api/methods": ["./src/methods/index.ts"],
"@roots/bud-api/methods/*": ["./src/methods/*/index.ts"],
"@roots/bud-api/service": ["./src/service/index.ts"],
},
"rootDir": "./src",
"strict": true,
"types": ["node", "@roots/bud-framework", "@roots/bud-extensions", "@roots/bud-minify"]
},
"include": ["./src/**/*.ts"],
"exclude": ["./src/**/*.test.ts"],
"include": ["./src"],
"references": [
{"path": "../bud-build/tsconfig.json"},
{"path": "../bud-extensions/tsconfig.json"},
Expand Down
Loading

0 comments on commit f133de1

Please sign in to comment.