-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Added installed-check linter and Knip (#199)
* Added installed-check linter * Added a changeset file * Added knip
- Loading branch information
1 parent
0a3337a
commit 7805dbe
Showing
19 changed files
with
1,521 additions
and
278 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@workleap/tsup-configs": patch | ||
--- | ||
|
||
Add an export for the tsup configs default entry paths. |
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,186 @@ | ||
import type { KnipConfig } from "knip"; | ||
|
||
type KnipWorkspaceConfig = NonNullable<KnipConfig["workspaces"]>[string]; | ||
|
||
type KnipTransformer = (config: KnipWorkspaceConfig) => KnipWorkspaceConfig; | ||
|
||
function defineWorkspace({ ignore, ...config }: KnipWorkspaceConfig, transformers?: KnipTransformer[]): KnipWorkspaceConfig { | ||
let transformedConfig: KnipWorkspaceConfig = { | ||
...config, | ||
ignore: [ | ||
...(ignore as string[] ?? []), | ||
"node_modules/**", | ||
"dist/**" | ||
] | ||
}; | ||
|
||
if (transformers) { | ||
transformedConfig = transformers.reduce((acc, transformer) => transformer(acc), transformedConfig); | ||
} | ||
|
||
return transformedConfig; | ||
} | ||
|
||
const ignoreBrowserslist: KnipTransformer = ({ ignoreDependencies, ...config }) => { | ||
return { | ||
...config, | ||
ignoreDependencies: [ | ||
...(ignoreDependencies as string[] ?? []), | ||
// Browserlist isn't supported by plugins. | ||
"@workleap/browserslist-config" | ||
] | ||
}; | ||
}; | ||
|
||
const configurePostcss: KnipTransformer = config => { | ||
return { | ||
...config, | ||
postcss: { | ||
config: ["postcss.config.ts"] | ||
} | ||
}; | ||
}; | ||
|
||
const configureMsw: KnipTransformer = ({ entry, ignore, ...config }) => { | ||
return { | ||
...config, | ||
entry: [ | ||
...(entry as string[] ?? []), | ||
"src/mocks/browser.ts", | ||
"src/mocks/handlers.ts" | ||
], | ||
ignore: [ | ||
...(ignore as string[] ?? []), | ||
// MSW isn't supported by plugins. | ||
"public/mockServiceWorker.js" | ||
] | ||
}; | ||
}; | ||
|
||
const configureWebpack: KnipTransformer = ({ ignoreDependencies, ...config }) => { | ||
return { | ||
...config, | ||
webpack: { | ||
config: ["webpack.*.js"] | ||
}, | ||
ignoreDependencies: [ | ||
...(ignoreDependencies as string[] ?? []), | ||
"@svgr/webpack", | ||
"swc-loader", | ||
"css-loader", | ||
"postcss-loader", | ||
"style-loader", | ||
"mini-css-extract-plugin" | ||
].filter(Boolean) as string[] | ||
}; | ||
}; | ||
|
||
const configureTsup: KnipTransformer = config => { | ||
return { | ||
...config, | ||
tsup: { | ||
config: ["tsup.*.ts"] | ||
} | ||
}; | ||
}; | ||
|
||
const configurePackage: KnipTransformer = config => { | ||
return { | ||
...config, | ||
eslint: true | ||
}; | ||
}; | ||
|
||
const configureSample: KnipTransformer = ({ entry, ...config }) => { | ||
return { | ||
...config, | ||
entry: [ | ||
...(entry as string[] ?? []), | ||
"src/index.ts", | ||
"src/index.tsx" | ||
], | ||
eslint: true, | ||
stylelint: true | ||
}; | ||
}; | ||
|
||
const rootConfig = defineWorkspace({ | ||
ignoreDependencies: [ | ||
// Required for Stylelint (seems like a Knip bug) | ||
"prettier", | ||
// Installed once for all the workspace's projects | ||
"ts-node" | ||
] | ||
}); | ||
|
||
const packagesConfig: KnipWorkspaceConfig = defineWorkspace({}, [ | ||
configurePackage, | ||
configureTsup | ||
]); | ||
|
||
const swcConfig: KnipWorkspaceConfig = defineWorkspace({ | ||
ignoreDependencies: [ | ||
// Omitting the optional peer dependencies from the peerDependencies emits | ||
// runtime errors like "[ERROR] Could not resolve "browserslist"". | ||
"@swc/jest", | ||
"browserslist" | ||
] | ||
}, [ | ||
configurePackage, | ||
configureTsup | ||
]); | ||
|
||
const webpackConfig: KnipWorkspaceConfig = defineWorkspace({ | ||
ignoreDependencies: [ | ||
// Emits an referenced optionap peerDependencies warning but according to PNPM | ||
// documentation, to specify a version constraint, the optional dependency must be define. | ||
// See: https://pnpm.io/package_json#peerdependenciesmetaoptional. | ||
"webpack-dev-server" | ||
] | ||
}, [ | ||
configurePackage, | ||
configureTsup | ||
]); | ||
|
||
const sampleAppConfig = defineWorkspace({}, [ | ||
configureSample, | ||
ignoreBrowserslist, | ||
configurePostcss, | ||
configureWebpack, | ||
configureMsw | ||
]); | ||
|
||
const sampleComponentsConfig = defineWorkspace({}, [ | ||
configureSample, | ||
configureTsup | ||
]); | ||
|
||
const sampleUtilsConfig = defineWorkspace({}, [ | ||
configureSample, | ||
configureTsup | ||
]); | ||
|
||
const config: KnipConfig = { | ||
workspaces: { | ||
".": rootConfig, | ||
"packages/*": packagesConfig, | ||
"packages/swc-configs": swcConfig, | ||
"packages/webpack-configs": webpackConfig, | ||
"sample/app": sampleAppConfig, | ||
"sample/components": sampleComponentsConfig, | ||
"sample/utils": sampleUtilsConfig | ||
}, | ||
ignoreWorkspaces: [ | ||
// Until it's migrated to ESLint 9. | ||
"packages/eslint-plugin", | ||
// Until it supports ESM. | ||
"packages/stylelint-configs" | ||
], | ||
exclude: [ | ||
// It cause issues with config like Jest "projects". | ||
"unresolved" | ||
], | ||
ignoreExportsUsedInFile: true | ||
}; | ||
|
||
export default config; |
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
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 |
---|---|---|
@@ -1,21 +1,4 @@ | ||
import type { Config } from "@swc/core"; | ||
import { defineJestConfig } from "@workleap/swc-configs"; | ||
|
||
export const swcConfig = defineJestConfig(); | ||
|
||
export const config: Config = { | ||
jsc: { | ||
parser: { | ||
syntax: "typescript", | ||
tsx: true | ||
}, | ||
// The output environment that the code will be compiled for. | ||
target: "es2022", | ||
// Import shims from an external module rather than inlining them in bundle files to greatly reduce the bundles size. | ||
// Requires to add "@swc/helpers" as a project dependency | ||
externalHelpers: true | ||
}, | ||
module: { | ||
// The output module resolution system that the code will be compiled for. | ||
type: "es6", | ||
// Prevent SWC from exporting the `__esModule` property. | ||
strict: 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
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
Oops, something went wrong.