Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#9457: move knip to repository root #9505

Merged
merged 8 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ jobs:
cache: npm
- run: npm ci
# Detect dead code with enforced rules
- run: npm run dead-code --workspace=applications/browser-extension
- run: npm run dead-code -- --workspace=applications/browser-extension
# Detect dead code that is only used by tests
- run: npm run dead-code:prod --workspace=applications/browser-extension
# Also run the remaining "warn" rules
- run: npm run dead-code:base --workspace=applications/browser-extension -- --no-exit-code
- run: npm run dead-code:base -- --workspace=applications/browser-extension --no-exit-code

# https://pre-commit.com/#usage-in-continuous-integration
prettier:
Expand Down
143 changes: 0 additions & 143 deletions applications/browser-extension/knip.mjs

This file was deleted.

8 changes: 1 addition & 7 deletions applications/browser-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
"build:typescript": "tsc --noEmit",
"generate:headers": "npm run test -- src/development/headers.test.ts --no-silent",
"storybook": "storybook dev -p 6006 -s public",
"build-storybook": "storybook build",
"dead-code": "npm run dead-code:base -- --include files,duplicates,dependencies,classMembers,binaries,enumMembers,nsTypes,exports,nsExports",
"dead-code:base_BROKEN_DUE_TO_NOT_BEING_RUN_IN_ROOT": "knip --config knip.mjs --tags=-knip",
"dead-code:base": "echo 'skipping knip until fixed in next changeset. See: https://knip.dev/guides/handling-issues#missing-binaries'",
"dead-code:prod": "npm run dead-code -- --production"
"build-storybook": "storybook build"
},
"engine-strict": true,
"engines": {
Expand Down Expand Up @@ -274,7 +270,6 @@
"jest-webextension-mock": "^3.9.0",
"jsdom": "^25.0.1",
"jsdom-testing-mocks": "^1.13.1",
"knip": "^5.36.2",
"mini-css-extract-plugin": "^2.6.1",
"mockdate": "^3.0.5",
"msw": "^1.3.5",
Expand All @@ -283,7 +278,6 @@
"node-polyfill-webpack-plugin": "^4.0.0",
"otpauth": "^9.3.4",
"path-browserify": "^1.0.1",
"prettier": "3.1.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See discussion: #9503

"react-beautiful-dnd-next": "^11.0.5",
"react-refresh-typescript": "^2.0.9",
"react-select-event": "^5.3.0",
Expand Down
4 changes: 3 additions & 1 deletion applications/browser-extension/webpack.sharedConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ const path = require("node:path");
const JSON5 = require("json5");
const { merge } = require("webpack-merge");

const tsconfig = JSON5.parse(fs.readFileSync("./tsconfig.json", "utf8"));
const tsconfig = JSON5.parse(
fs.readFileSync(path.resolve(__dirname, "./tsconfig.json"), "utf8"),
);

const isProd = process.argv.includes("production");
const isHMR = Boolean(process.env.HMR);
Expand Down
165 changes: 165 additions & 0 deletions knip.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* Copyright (C) 2024 PixieBrix, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import configFactory from "@pixiebrix/extension/webpack.config.mjs";

const config = configFactory(process.env, {});

/**
* https://knip.dev/overview/configuration#customize
* @type {import("knip").KnipConfig}
*
* Production mode: https://knip.dev/features/production-mode
*/
const knipConfig = {
$schema: "https://unpkg.com/knip@5/schema.json",

workspaces: {
"applications/browser-extension": {
entry: [
// ! suffix files are included in production mode
...Object.values(config.entry).map((x) =>
`${x}.{ts,tsx,js,jsx}!`.replace("./", ""),
),
// App messenger and common storage
"src/background/messenger/external/api.ts!",
"src/store/browserExtensionIdStorage.ts!",

// Loaded via .eslintrc
"eslint-local-rules/*",

// Include in default run only
"end-to-end-tests/fixtures/*.ts",
"end-to-end-tests/setup/*.setup.ts",
"end-to-end-tests/utils.ts",

// Imported via .html files and manifest.json
"static/*",

// Scripting/config entry points that are not being picked up
"src/testUtils/FixJsdomEnvironment.js",
"scripts/*.{mjs,ts}",
"src/telemetry/lexicon.ts",

"webpack.sharedConfig.js",
".storybook/main.js",
],
project: [
// Include in production mode and default run
"src/**/*.ts!",

/**
* Exclude from production runs (`!` prefix and suffix)
* @see https://knip.dev/guides/configuring-project-files#production-mode
*/
"!end-to-end-tests/**!",
"!src/__mocks__/**!",
"!src/**/testHelpers.{ts,tsx}!",
"!src/testUtils/**!",
"!src/telemetry/lexicon.ts!",
"!src/development/hooks/**!",
"!src/vendors/reactPerformanceTesting/**!",
"!scripts/**!",
"!webpack.sharedConfig.js!",
"!.storybook/main.js!",
],
// https://knip.dev/guides/handling-issues#mocks-and-other-implicit-imports
ignore: [
// Test Mocks
"**/__mocks__/**",
// Development/debugging helpers
"src/development/hooks/**",
// Including end-to-end tests for dependency check but not dead code
"end-to-end-tests/**",

// https://knip.dev/reference/jsdoc-tsdoc-tags/#tags-cli
// Instead of adding files to this list, prefer adding a @knip JSDoc comment with explanation, like:

// /** @knip We want to use this later */
// export const someValue = 0;

// Prefer adding `@internal` JSDoc comment if only used by tests, factories, etc.
// `@internal` only ignores during production runs so it will still flag unused exports during full runs
],
ignoreDependencies: [
// TODO: These are used by production files, shouldn't need to ignore them?
// Most appear to be dynamic imports, maybe there's a plugin we need
"@fortawesome/free-brands-svg-icons",
"@fortawesome/free-regular-svg-icons",
"@szhsin/react-menu",
"ace-builds",
"bootstrap-icons",
"fit-textarea",
"holderjs",
"jquery",
"jszip",
"lodash-es",
"react-ace",
"react-autosuggest",
"react-hot-toast",
"react-hotkeys",
"react-image-crop",
"react-outside-click-handler",
"react-router-dom",
"react-select-virtualized",
"react-spinners",
"react-virtualized-auto-sizer",
"react-window",
"simple-icons",

// PeerDependency of react-select-virtualized
"react-virtualized",

// Browser environment types
"@types/chrome",
"@types/dom-navigation",
// Provides require.context, etc.
"@types/webpack-env",
// Used by src/contrib/google/sheets/core/types.ts
"@types/gapi.client",
"@types/gapi.client.drive-v3",
"@types/gapi.client.oauth2-v2",
"@types/gapi.client.sheets-v4",

// Referenced in scss files
"bootstrap",
"compass-mixins",
// Not getting detected by webpack plugin for .storybook/main.js
"style-loader",
"@storybook/react-webpack5",

// Used but not detected
"@types/holderjs",
"@types/react-autosuggest",
"@types/react-outside-click-handler",
"@types/react-virtualized-auto-sizer",
"@types/react-window",
"@tiptap/pm",
"@tiptap/starter-kit",
"@tiptap/react",
"@tiptap/extension-underline",
],
// False positive for PackageInstance.featureFlag
ignoreMembers: ["featureFlag"],
},
},
};

// Echo settings to console to make CI results easier to understand/debug
console.log(JSON.stringify(knipConfig, null, 2));

export default knipConfig;
Loading