Skip to content

Commit 107f7ca

Browse files
rsk2rickstaa
andauthored
Feature/grs 1955 change commonjs imports (#1995)
* GRS-1955: Using ES6 import/export in src files * GRS-1955: Using ES6 import/export in test files * GRS-1955: Using ES6 import/export in themes index.js * GRS-1955: Readding blank line at end of top-languages-card.js * feat: fix test es6 import errors This commit makes sure jest is set-up to support es6. It also fixes several test errors and sorts the imports. * test: update test node version This commit makes sure node 16 is used in the github actions. * refactor: run prettier Co-authored-by: rickstaa <[email protected]>
1 parent 4073512 commit 107f7ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+338
-475
lines changed

.github/workflows/generate-theme-doc.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: setup node
1717
uses: actions/setup-node@v1
1818
with:
19-
node-version: "12.x"
19+
node-version: "16.x"
2020

2121
- name: npm install, generate readme
2222
run: |

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup Node
1919
uses: actions/setup-node@v1
2020
with:
21-
node-version: "12.x"
21+
node-version: "16.x"
2222

2323
- name: Install & Test
2424
run: |

api/index.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
require("dotenv").config();
2-
const {
1+
import {
32
renderError,
43
parseBoolean,
54
parseArray,
65
clampValue,
76
CONSTANTS,
8-
} = require("../src/common/utils");
9-
const fetchStats = require("../src/fetchers/stats-fetcher");
10-
const renderStatsCard = require("../src/cards/stats-card");
11-
const blacklist = require("../src/common/blacklist");
12-
const { isLocaleAvailable } = require("../src/translations");
7+
} from "../src/common/utils";
8+
import fetchStats from "../src/fetchers/stats-fetcher";
9+
import renderStatsCard from "../src/cards/stats-card";
10+
import blacklist from "../src/common/blacklist";
11+
import { isLocaleAvailable } from "../src/translations";
12+
import * as dotenv from "dotenv";
1313

14-
module.exports = async (req, res) => {
14+
dotenv.config();
15+
16+
export default async (req, res) => {
1517
const {
1618
username,
1719
hide,

api/pin.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
require("dotenv").config();
2-
const {
1+
import {
32
renderError,
43
parseBoolean,
54
clampValue,
65
CONSTANTS,
7-
} = require("../src/common/utils");
8-
const fetchRepo = require("../src/fetchers/repo-fetcher");
9-
const renderRepoCard = require("../src/cards/repo-card");
10-
const blacklist = require("../src/common/blacklist");
11-
const { isLocaleAvailable } = require("../src/translations");
6+
} from "../src/common/utils";
7+
import fetchRepo from "../src/fetchers/repo-fetcher";
8+
import renderRepoCard from "../src/cards/repo-card";
9+
import blacklist from "../src/common/blacklist";
10+
import { isLocaleAvailable } from "../src/translations";
1211

13-
module.exports = async (req, res) => {
12+
export default async (req, res) => {
1413
const {
1514
username,
1615
repo,

api/top-langs.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
require("dotenv").config();
2-
const {
1+
import {
32
renderError,
43
clampValue,
54
parseBoolean,
65
parseArray,
76
CONSTANTS,
8-
} = require("../src/common/utils");
9-
const fetchTopLanguages = require("../src/fetchers/top-languages-fetcher");
10-
const renderTopLanguages = require("../src/cards/top-languages-card");
11-
const blacklist = require("../src/common/blacklist");
12-
const { isLocaleAvailable } = require("../src/translations");
7+
} from "../src/common/utils";
8+
import fetchTopLanguages from "../src/fetchers/top-languages-fetcher";
9+
import { renderTopLanguages } from "../src/cards/top-languages-card";
10+
import blacklist from "../src/common/blacklist";
11+
import { isLocaleAvailable } from "../src/translations";
12+
import * as dotenv from "dotenv";
1313

14-
module.exports = async (req, res) => {
14+
dotenv.config();
15+
16+
export default async (req, res) => {
1517
const {
1618
username,
1719
hide,

api/wakatime.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
require("dotenv").config();
2-
const {
1+
import {
32
renderError,
43
parseBoolean,
54
clampValue,
65
parseArray,
76
CONSTANTS,
8-
} = require("../src/common/utils");
9-
const { isLocaleAvailable } = require("../src/translations");
10-
const { fetchWakatimeStats } = require("../src/fetchers/wakatime-fetcher");
11-
const wakatimeCard = require("../src/cards/wakatime-card");
7+
} from "../src/common/utils";
8+
import { isLocaleAvailable } from "../src/translations";
9+
import fetchWakatimeStats from "../src/fetchers/wakatime-fetcher";
10+
import wakatimeCard from "../src/cards/wakatime-card";
11+
import * as dotenv from "dotenv";
1212

13-
module.exports = async (req, res) => {
13+
dotenv.config();
14+
15+
export default async (req, res) => {
1416
const {
1517
username,
1618
title_color,

jest.config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
module.exports = {
1+
export default {
22
clearMocks: true,
3+
transform: {},
4+
testEnvironment: "jsdom",
35
};

package.json

+9-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
"version": "1.0.0",
44
"description": "Dynamically generate stats for your github readmes",
55
"main": "index.js",
6+
"type": "module",
67
"scripts": {
7-
"test": "jest --coverage",
8-
"test:watch": "jest --watch",
8+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
9+
"test:watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch",
10+
"test:update:snapshot": "node --experimental-vm-modules node_modules/jest/bin/jest.js -u",
911
"theme-readme-gen": "node scripts/generate-theme-doc",
1012
"preview-theme": "node scripts/preview-theme",
1113
"generate-langs-json": "node scripts/generate-langs-json",
@@ -20,14 +22,15 @@
2022
"devDependencies": {
2123
"@actions/core": "^1.2.4",
2224
"@actions/github": "^4.0.0",
23-
"@testing-library/dom": "^7.20.0",
24-
"@testing-library/jest-dom": "^5.11.0",
25+
"@testing-library/dom": "^8.17.1",
26+
"@testing-library/jest-dom": "^5.16.5",
27+
"jest-environment-jsdom": "^29.0.3",
28+
"jest": "^29.0.3",
2529
"@uppercod/css-to-object": "^1.1.1",
2630
"axios-mock-adapter": "^1.18.1",
2731
"color-contrast-checker": "^2.1.0",
2832
"hjson": "^3.2.2",
2933
"husky": "^4.2.5",
30-
"jest": "^26.1.0",
3134
"js-yaml": "^4.1.0",
3235
"lodash.snakecase": "^4.1.1",
3336
"parse-diff": "^0.7.0",
@@ -38,6 +41,7 @@
3841
"dotenv": "^8.2.0",
3942
"emoji-name-map": "^1.2.8",
4043
"github-username-regex": "^1.0.0",
44+
"upgrade": "^1.1.0",
4145
"word-wrap": "^1.2.3"
4246
},
4347
"husky": {

scripts/generate-langs-json.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const fs = require("fs");
2-
const jsYaml = require("js-yaml");
3-
const axios = require("axios");
1+
import axios from "axios";
2+
import fs from "fs";
3+
import jsYaml from "js-yaml";
44

55
const LANGS_FILEPATH = "./src/common/languageColors.json";
66

scripts/generate-theme-doc.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const theme = require("../themes/index");
2-
const fs = require("fs");
1+
import fs from "fs";
2+
import { themes } from "../themes/index";
33

44
const TARGET_FILE = "./themes/README.md";
55
const REPO_CARD_LINKS_FLAG = "<!-- REPO_CARD_LINKS -->";
@@ -54,7 +54,7 @@ const createStatMdLink = (theme) => {
5454
};
5555

5656
const generateLinks = (fn) => {
57-
return Object.keys(theme)
57+
return Object.keys(themes)
5858
.map((name) => fn(name))
5959
.join("");
6060
};
@@ -65,7 +65,7 @@ const createTableItem = ({ link, label, isRepoCard }) => {
6565
};
6666
const generateTable = ({ isRepoCard }) => {
6767
const rows = [];
68-
const themes = Object.keys(theme).filter(
68+
const themes = Object.keys(themes).filter(
6969
(name) => name !== (!isRepoCard ? "default_repocard" : "default"),
7070
);
7171

scripts/preview-theme.js

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
const core = require("@actions/core");
2-
const github = require("@actions/github");
3-
const parse = require("parse-diff");
4-
const Hjson = require("hjson");
5-
const snakeCase = require("lodash.snakecase");
6-
const ColorContrastChecker = require("color-contrast-checker");
1+
import core from "@actions/core";
2+
import github from "@actions/github";
3+
import ColorContrastChecker from "color-contrast-checker";
4+
import * as dotenv from "dotenv";
5+
import Hjson from "hjson";
6+
import snakeCase from "lodash.snakecase";
7+
import parse from "parse-diff";
78

8-
require("dotenv").config();
9+
dotenv.config();
910

1011
const OWNER = "anuraghazra";
1112
const REPO = "github-readme-stats";
@@ -76,10 +77,10 @@ function getGrsLink(colors) {
7677
}
7778

7879
const themeContribGuidelines = `
79-
\rHi, thanks for the theme contribution, please read our theme [contribution guidelines](https://github.com/anuraghazra/github-readme-stats/blob/master/CONTRIBUTING.md#themes-contribution).
80+
\rHi, thanks for the theme contribution, please read our theme [contribution guidelines](https://github.com/anuraghazra/github-readme-stats/blob/master/CONTRIBUTING.md#themes-contribution).
8081
\rWe are currently only accepting color combinations from any VSCode theme or themes which have good color combination to minimize bloating the themes collection.
8182
82-
\r> Also note that if this theme is exclusively for your personal use, then instead of adding it to our theme collection you can use card [customization options](https://github.com/anuraghazra/github-readme-stats#customization)
83+
\r> Also note that if this theme is exclusively for your personal use, then instead of adding it to our theme collection you can use card [customization options](https://github.com/anuraghazra/github-readme-stats#customization)
8384
`;
8485

8586
async function run() {
@@ -128,7 +129,7 @@ async function run() {
128129
issue_number: pullRequestId,
129130
body: `
130131
\r**${COMMENT_TITLE}**
131-
132+
132133
\rCannot create theme preview
133134
134135
${themeContribGuidelines}
@@ -167,16 +168,16 @@ async function run() {
167168
owner: OWNER,
168169
repo: REPO,
169170
body: `
170-
\r**${COMMENT_TITLE}**
171-
171+
\r**${COMMENT_TITLE}**
172+
172173
\r${warnings.map((warning) => `- :warning: ${warning}\n`).join("")}
173174
174175
\ntitle_color: <code>#${titleColor}</code> | icon_color: <code>#${iconColor}</code> | text_color: <code>#${textColor}</code> | bg_color: <code>#${bgColor}</code>
175-
176+
176177
\r[Preview Link](${url})
177178
178179
\r[![](${url})](${url})
179-
180+
180181
${themeContribGuidelines}
181182
`,
182183
});

scripts/push-theme-readme.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ git checkout -b $BRANCH_NAME
1111
git add --all
1212
git commit --message "docs(theme): Auto update theme readme" || exit 0
1313
git remote add origin-$BRANCH_NAME https://${PERSONAL_TOKEN}@github.com/${GH_REPO}.git
14-
git push --force --quiet --set-upstream origin-$BRANCH_NAME $BRANCH_NAME
14+
git push --force --quiet --set-upstream origin-$BRANCH_NAME $BRANCH_NAME

src/calculateRank.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ function calculateRank({
5757
issues * ISSUES_OFFSET +
5858
stargazers * STARS_OFFSET +
5959
prs * PRS_OFFSET +
60-
followers * FOLLOWERS_OFFSET +
61-
totalRepos * REPO_OFFSET
60+
followers * FOLLOWERS_OFFSET +
61+
totalRepos * REPO_OFFSET
6262
) / 100;
6363

6464
const normalizedScore = normalcdf(score, TOTAL_VALUES, ALL_OFFSETS) * 100;
@@ -74,4 +74,5 @@ function calculateRank({
7474
return { level, score: normalizedScore };
7575
}
7676

77-
module.exports = calculateRank;
77+
export { calculateRank };
78+
export default calculateRank;

src/cards/repo-card.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// @ts-check
2-
const {
3-
kFormatter,
2+
import { Card } from "../common/Card";
3+
import { I18n } from "../common/I18n";
4+
import { icons } from "../common/icons";
5+
import {
46
encodeHTML,
5-
getCardColors,
67
flexLayout,
7-
wrapTextMultiline,
8+
getCardColors,
9+
kFormatter,
810
measureText,
911
parseEmojis,
10-
} = require("../common/utils");
11-
const I18n = require("../common/I18n");
12-
const Card = require("../common/Card");
13-
const icons = require("../common/icons");
14-
const { repoCardLocales } = require("../translations");
12+
wrapTextMultiline,
13+
} from "../common/utils";
14+
import { repoCardLocales } from "../translations";
1515

1616
/**
1717
* @param {string} label
@@ -185,4 +185,5 @@ const renderRepoCard = (repo, options = {}) => {
185185
`);
186186
};
187187

188-
module.exports = renderRepoCard;
188+
export { renderRepoCard };
189+
export default renderRepoCard;

src/cards/stats-card.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// @ts-check
2-
const I18n = require("../common/I18n");
3-
const Card = require("../common/Card");
4-
const icons = require("../common/icons");
5-
const { getStyles } = require("../getStyles");
6-
const { statCardLocales } = require("../translations");
7-
const {
8-
kFormatter,
9-
flexLayout,
2+
import { Card } from "../common/Card";
3+
import { I18n } from "../common/I18n";
4+
import { icons } from "../common/icons";
5+
import {
106
clampValue,
11-
measureText,
7+
flexLayout,
128
getCardColors,
13-
} = require("../common/utils");
9+
kFormatter,
10+
measureText,
11+
} from "../common/utils";
12+
import { getStyles } from "../getStyles";
13+
import { statCardLocales } from "../translations";
1414

1515
const createTextNode = ({
1616
icon,
@@ -300,4 +300,5 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
300300
`);
301301
};
302302

303-
module.exports = renderStatsCard;
303+
export { renderStatsCard };
304+
export default renderStatsCard;

src/cards/top-languages-card.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// @ts-check
2-
const Card = require("../common/Card");
3-
const I18n = require("../common/I18n");
4-
const { langCardLocales } = require("../translations");
5-
const { createProgressNode } = require("../common/createProgressNode");
6-
const {
2+
import { Card } from "../common/Card";
3+
import { createProgressNode } from "../common/createProgressNode";
4+
import { I18n } from "../common/I18n";
5+
import {
6+
chunkArray,
77
clampValue,
8-
getCardColors,
98
flexLayout,
9+
getCardColors,
1010
lowercaseTrim,
1111
measureText,
12-
chunkArray,
13-
} = require("../common/utils");
12+
} from "../common/utils";
13+
import { langCardLocales } from "../translations";
1414

1515
const DEFAULT_CARD_WIDTH = 300;
1616
const MIN_CARD_WIDTH = 230;
@@ -311,5 +311,4 @@ const renderTopLanguages = (topLangs, options = {}) => {
311311
`);
312312
};
313313

314-
module.exports = renderTopLanguages;
315-
module.exports.MIN_CARD_WIDTH = MIN_CARD_WIDTH;
314+
export { renderTopLanguages, MIN_CARD_WIDTH };

0 commit comments

Comments
 (0)