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

Add depcheck for CI step to check for unused dependencies #1677

Merged
merged 25 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
71b7808
add depcheck ci
anshgoyalevil Aug 14, 2023
fa1ed49
add depcheck ci
anshgoyalevil Aug 14, 2023
db36aaa
add depcheck ci
anshgoyalevil Aug 14, 2023
745614f
add depcheck ci
anshgoyalevil Aug 14, 2023
073304b
fix lint
anshgoyalevil Aug 14, 2023
ec8ac31
Bump @testing-library/jest-dom from 5.17.0 to 6.0.0 (#1679)
dependabot[bot] Aug 14, 2023
c2c29b7
Release 1.32.0 (#1676)
pavolloffay Aug 14, 2023
f2be9a9
Recognize uninstrumented services via both `producer` and `client` sp…
Wck-iipi Aug 14, 2023
5758f9d
Remove unused packages (#1675)
anshgoyalevil Aug 15, 2023
5e8b149
Bump eslint from 8.46.0 to 8.47.0 (#1678)
dependabot[bot] Aug 15, 2023
27827f9
generate depcheckrc automatically
anshgoyalevil Aug 15, 2023
fef043d
Bump the typescript-eslint group with 2 updates (#1686)
dependabot[bot] Aug 15, 2023
f068fe8
Remove unused type defs and packages (#1682)
anshgoyalevil Aug 15, 2023
d272d41
modify generatedepcheckrc
anshgoyalevil Aug 15, 2023
d60678c
[plexus] Remove unused deps and add missing deps (#1688)
anshgoyalevil Aug 15, 2023
3b2b286
add depcheck for plexus
anshgoyalevil Aug 15, 2023
a6d4086
fix lint errors
anshgoyalevil Aug 15, 2023
61dabd9
Update .github/workflows/unit-tests.yml
anshgoyalevil Aug 15, 2023
3d23799
sepration of concerns
anshgoyalevil Aug 15, 2023
d4d6709
fix script
anshgoyalevil Aug 15, 2023
b106ef4
fix script
anshgoyalevil Aug 15, 2023
ab0cf35
change permissions
anshgoyalevil Aug 15, 2023
456e8c7
add more robust implementation
anshgoyalevil Aug 16, 2023
29e1cbc
Merge branch 'main' into add-depcheck
anshgoyalevil Aug 16, 2023
34dea32
remove console statements
anshgoyalevil Aug 16, 2023
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: 4 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ jobs:
cache: yarn
node-version: '16'
- run: yarn install --frozen-lockfile
- name: Run depcheck
run: |
yarn global add depcheck
yarn run depcheck
- run: yarn lint
- run: yarn build
- run: yarn coverage
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"build": "lerna run build",
"check-license": "./scripts/check-license.sh",
"coverage": "lerna run coverage",
"depcheck": "./scripts/run-depcheck.sh",
"eslint": "eslint --cache 'scripts/*.{js,jsx,ts,tsx}' 'packages/*/src/**/*.{js,jsx,ts,tsx}' 'packages/*/*.{js,jsx,ts,tsx}'",
"fmt": "yarn prettier",
"lint": "npm-run-all -ln --parallel prettier-lint tsc-lint eslint check-license",
Expand Down
3 changes: 3 additions & 0 deletions packages/jaeger-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@
"react-ga": "^3.3.1",
"react-helmet": "^6.1.0",
"react-icons": "2.2.7",
"react-is": "^18.2.0",
"react-redux": "^5.0.6",
"react-router-dom": "4.3.1",
"react-router-redux": "5.0.0-alpha.8",
"react-select": "1.3.0",
"react-virtualized": "9.21.0",
"react-virtualized-select": "^3.1.0",
"react-vis": "^1.7.2",
"react-vis-force": "^0.3.1",
Expand Down
7 changes: 5 additions & 2 deletions packages/jaeger-ui/test/babel-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@

const babelJest = require('babel-jest').default;

module.exports = babelJest.createTransformer({
const babelConfiguration = {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
['@babel/preset-react', { development: !process.env.CI }],
'@babel/preset-typescript',
],
plugins: ['babel-plugin-inline-react-svg'],
});
}

module.exports = babelJest.createTransformer(babelConfiguration);
module.exports.babelConfiguration = babelConfiguration;
47 changes: 47 additions & 0 deletions scripts/generateDepcheckrcJaegerUI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2023 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/* eslint-disable import/no-extraneous-dependencies */
const fs = require('fs');
const path = require('path');
const { babelConfiguration } = require('../packages/jaeger-ui/test/babel-transform');

const packageNames = [
...babelConfiguration.presets.flatMap(preset => {
if (Array.isArray(preset)) {
return [preset[0]];
}
return [preset];
}),
...babelConfiguration.plugins,
];

const otherPackages = ['jest-environment-jsdom'];

// Use the selected targetPackage for generating depcheckrcContent
const depcheckrcContent = {
ignores: [...packageNames, ...otherPackages],
'ignore-dirs': ['build'],
};

// Use the argument provided to the script as the output file path
const outputFile = process.argv[2];

if (!outputFile) {
process.exit(1);
}

const depcheckrcPath = path.resolve(__dirname, outputFile);

fs.writeFileSync(depcheckrcPath, JSON.stringify(depcheckrcContent, null, 2));
57 changes: 57 additions & 0 deletions scripts/generateDepcheckrcPlexus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) 2023 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/* eslint-disable import/no-extraneous-dependencies */
const fs = require('fs');
const path = require('path');
const getBabelConfig = require('../packages/plexus/babel.config');

const babelConfiguration = getBabelConfig({
env: () => {
'development';
},
});

const packageNames = [
...babelConfiguration.presets.flatMap(preset => {
if (Array.isArray(preset)) {
return [preset[0]];
}
return [preset];
}),
...babelConfiguration.plugins.flatMap(plugin => {
if (Array.isArray(plugin)) {
return [plugin[0]];
}
return [plugin];
}),
];

const otherPackages = ['rimraf', 'webpack-cli'];

// Use the selected targetPackage for generating depcheckrcContent
const depcheckrcContent = {
ignores: [...packageNames, ...otherPackages],
};

// Use the argument provided to the script as the output file path
const outputFile = process.argv[2];

if (!outputFile) {
process.exit(1);
}

const depcheckrcPath = path.resolve(__dirname, outputFile);

fs.writeFileSync(depcheckrcPath, JSON.stringify(depcheckrcContent, null, 2));
12 changes: 12 additions & 0 deletions scripts/run-depcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
set -ex

# Create a temporary depcheckrc file for 'jaeger-ui'
tempfile_jaeger=$(mktemp /tmp/depcheckrc.XXXXXX.json)
node scripts/generateDepcheckrcJaegerUI.js "$tempfile_jaeger"
Copy link
Member

Choose a reason for hiding this comment

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

you could've done this more "unixy" by writing to stdout from the Node script and redirecting here to the temp file. This way there would be fewer dependencies between the steps, the Node script is easier to debug, and it would be simpler (no writing to files).

Copy link
Member Author

Choose a reason for hiding this comment

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

I was earlier thinking of the same to redirect the output using > operator in Unix.
Would create a sister PR to rectify the same.

depcheck packages/jaeger-ui --config "$tempfile_jaeger"

# Create a temporary depcheckrc file for 'plexus'
tempfile_plexus=$(mktemp /tmp/depcheckrc.XXXXXX.json)
node scripts/generateDepcheckrcPlexus.js "$tempfile_plexus"
depcheck packages/plexus --config "$tempfile_plexus"
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10641,7 +10641,7 @@ react-router@^4.2.0, react-router@^4.3.1:
prop-types "^15.6.1"
warning "^4.0.1"

react-select@^1.0.0-rc.2:
react-select@1.3.0, react-select@^1.0.0-rc.2:
version "1.3.0"
resolved "https://registry.yarnpkg.com/react-select/-/react-select-1.3.0.tgz#1828ad5bf7f3e42a835c7e2d8cb13b5c20714876"
dependencies:
Expand Down Expand Up @@ -10701,7 +10701,7 @@ react-virtualized-select@^3.1.0:
react-select "^1.0.0-rc.2"
react-virtualized "^9.0.0"

react-virtualized@^9.0.0:
react-virtualized@9.21.0, react-virtualized@^9.0.0:
version "9.21.0"
resolved "https://registry.yarnpkg.com/react-virtualized/-/react-virtualized-9.21.0.tgz#8267c40ffb48db35b242a36dea85edcf280a6506"
dependencies:
Expand Down