Skip to content

Commit 28a7335

Browse files
author
Thomas Draier
authored
TECH-233: Convert package to typescript (#237)
1 parent f9be5c3 commit 28a7335

File tree

227 files changed

+8675
-5684
lines changed

Some content is hidden

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

227 files changed

+8675
-5684
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ references:
1616
defaults: &defaults
1717
working_directory: ~/source
1818
docker:
19-
- image: circleci/node:latest
19+
- image: cimg/node:16.20
2020
resource_class: large
2121

2222
jobs:

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ node
22
node_modules
33
target
44
build
5+
dist
6+

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
'<rootDir>/jest.setup.js'
44
],
55
transform: {
6-
'^.+\\.jsx?$': 'babel-jest'
6+
'^.+\\.[tj]sx?$': 'babel-jest'
77
},
88
moduleNameMapper: {
99
'\\.(gif|ttf|woff|woff2|eot|eot|svg)$': '<rootDir>/__mocks__/fileMock.js'

package.json

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"clean": "rm -rf packages/**/build/",
77
"build": "lerna run build",
88
"publish": "lerna --concurrency 1 run publish-script",
9-
"lint": "eslint --ext js,jsx .",
10-
"lint:fix": "yarn lint --fix .",
11-
"test": "lerna --scope @jahia/test-framework run build && jest --coverage",
9+
"lint": "lerna run lint",
10+
"lint:fix": "lerna run lint:fix",
11+
"test": "lerna --scope @jahia/test-framework run build && lerna run test",
1212
"tdd": "jest --watch"
1313
},
1414
"husky": {
@@ -19,13 +19,16 @@
1919
},
2020
"license": "SEE LICENSE IN LICENSE.txt FILE",
2121
"devDependencies": {
22-
"@babel/cli": "^7.4.4",
23-
"@babel/core": "^7.4.5",
22+
"@babel/cli": "^7.21.5",
23+
"@babel/core": "^7.21.8",
24+
"@babel/eslint-parser": "^7.21.8",
2425
"@babel/helper-module-imports": "^7.0.0",
2526
"@babel/plugin-external-helpers": "^7.2.0",
2627
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
27-
"@babel/preset-env": "^7.4.3",
28+
"@babel/plugin-transform-runtime": "^7.21.4",
29+
"@babel/preset-env": "^7.21.5",
2830
"@babel/preset-react": "^7.0.0",
31+
"@babel/preset-typescript": "^7.21.5",
2932
"@storybook/addon-actions": "^6.5.12",
3033
"@storybook/addon-knobs": "^6.4.0",
3134
"@storybook/addons": "^6.5.12",
@@ -35,24 +38,30 @@
3538
"@storybook/source-loader": "^6.4.5",
3639
"@types/history": "^4.6.2",
3740
"@types/i18next": "^8.4.3",
38-
"@types/react": "^16.3.14",
41+
"@types/react": "^16",
42+
"@types/react-dom": "^16",
43+
"@typescript-eslint/eslint-plugin": "^5.59.2",
44+
"@typescript-eslint/parser": "^5.59.2",
3945
"auto": "^10.37.6",
4046
"babel-eslint": "^10.0.1",
41-
"babel-jest": "^24.7.1",
42-
"babel-loader": "^8.0.6",
47+
"babel-jest": "^29.5.0",
48+
"babel-loader": "^9.1.2",
4349
"babel-plugin-lodash": "^3.3.4",
50+
"babel-plugin-module-resolver": "^5.0.0",
4451
"babel-plugin-transform-dynamic-import-to-static": "^1.0.1",
52+
"babel-plugin-transform-rename-import": "^2.3.0",
53+
"babel-plugin-typescript-to-proptypes": "^2.1.0",
4554
"cross-env": "^5.1.6",
46-
"css-loader": "^6.7.1",
4755
"enzyme": "^3.11.0",
4856
"enzyme-adapter-react-16": "^1.12.1",
4957
"enzyme-to-json": "^3.3.5",
50-
"eslint": "^6.6.0",
51-
"eslint-config-xo": "^0.27.2",
52-
"eslint-config-xo-react": "^0.20.0",
53-
"eslint-plugin-jest": "^23.0.2",
54-
"eslint-plugin-react": "^7.16.0",
55-
"eslint-plugin-react-hooks": "^2.2.0",
58+
"eslint": "^8.39.0",
59+
"eslint-config-xo": "^0.43.1",
60+
"eslint-config-xo-react": "^0.27.0",
61+
"eslint-plugin-jest": "^27.2.1",
62+
"eslint-plugin-json": "^3.1.0",
63+
"eslint-plugin-react": "^7.32.2",
64+
"eslint-plugin-react-hooks": "^4.6.0",
5665
"husky": "^3.0.5",
5766
"jest": "^24.9.0",
5867
"lerna": "^5.5.4",
@@ -63,7 +72,7 @@
6372
"postcss-mixins": "^9.0.4",
6473
"react": "^16.12.0",
6574
"react-dom": "^16.12.0",
66-
"style-loader": "^3.3.1",
75+
"typescript": "^5.0.4",
6776
"uglify-js": "^3.4.9",
6877
"yarn": "^1.15.2"
6978
},
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: ['@babel/preset-env', '@babel/preset-react']
3+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
setupFilesAfterEnv: [
3+
'<rootDir>/../../jest.setup.js'
4+
],
5+
transform: {
6+
'^.+\\.[tj]sx?$': 'babel-jest'
7+
},
8+
moduleNameMapper: {
9+
'\\.(gif|ttf|woff|woff2|eot|eot|svg)$': '<rootDir>/__mocks__/fileMock.js'
10+
},
11+
modulePathIgnorePatterns: [
12+
'build/',
13+
'target/',
14+
'node'
15+
],
16+
testPathIgnorePatterns: [
17+
'build/',
18+
'node_modules/',
19+
'target/',
20+
'node'
21+
]
22+
};

packages/data-helper/package.json

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
{
2-
"name": "@jahia/data-helper",
3-
"version": "1.0.8",
4-
"scripts": {
5-
"babel:js": "jahia-babel-js",
6-
"babel:module": "jahia-babel-module",
7-
"react2dts": "jahia-react2dts",
8-
"publish-script": "jahia-publish",
9-
"prepare-build": "jahia-prepare-build",
10-
"build": "jahia-build",
11-
"build-umd": "jahia-build-umd"
12-
},
13-
"main": "js/index.js",
14-
"module": "esm/index.js",
15-
"typings": "esm/index.d.ts",
16-
"browser": "lib/react-apollo.umd.min.js",
17-
"sideEffects": false,
18-
"license": "SEE LICENSE IN ../../LICENSE.txt FILE",
19-
"dependencies": {
20-
"apollo-cache": "^1.3.4",
21-
"apollo-client": "^2.6.8",
22-
"apollo-utilities": "^1.3.3",
23-
"fast-deep-equal": "^3.1.1",
24-
"graphql": "^15.4.0",
25-
"graphql-tag": "^2.11.0",
26-
"lodash": "^4.17.13",
27-
"react-apollo": "^3.1.3"
28-
},
29-
"peerDependencies": {
30-
"react": "^16.12.0"
31-
}
2+
"name": "@jahia/data-helper",
3+
"version": "1.0.8",
4+
"scripts": {
5+
"babel:js": "jahia-babel-js",
6+
"babel:module": "jahia-babel-module",
7+
"react2dts": "jahia-react2dts",
8+
"publish-script": "jahia-publish",
9+
"prepare-build": "jahia-prepare-build",
10+
"build": "jahia-build",
11+
"build-umd": "jahia-build-umd",
12+
"lint": "eslint --ext js,jsx src",
13+
"lint:fix": "yarn lint --fix",
14+
"test": "jest --coverage"
15+
},
16+
"main": "js/index.js",
17+
"module": "esm/index.js",
18+
"typings": "esm/index.d.ts",
19+
"browser": "lib/react-apollo.umd.min.js",
20+
"sideEffects": false,
21+
"license": "SEE LICENSE IN ../../LICENSE.txt FILE",
22+
"dependencies": {
23+
"apollo-cache": "^1.3.4",
24+
"apollo-client": "^2.6.8",
25+
"apollo-utilities": "^1.3.3",
26+
"fast-deep-equal": "^3.1.1",
27+
"graphql": "^15.4.0",
28+
"graphql-tag": "^2.11.0",
29+
"lodash": "^4.17.13",
30+
"react-apollo": "^3.1.3"
31+
},
32+
"peerDependencies": {
33+
"react": "^16.12.0"
34+
}
3235
}

packages/data-helper/src/fragments/fragments.utils.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ function findFragmentsInSelectionSet(selectionSet) {
6363

6464
function replaceFragmentsInSelectionSet(selectionSet, fragments, def, document) {
6565
if (selectionSet && selectionSet.selections) {
66-
let newFragmentsSpreads = [];
67-
let removedFragmentSpreads = [];
66+
const newFragmentsSpreads = [];
67+
const removedFragmentSpreads = [];
6868
// Look for all existing fragment spreads in selection set
6969
selectionSet.selections.filter(sel => sel.kind === 'FragmentSpread').forEach(sel => {
7070
// Handle only named fragments
7171
if (sel.name.value) {
7272
// Check if spread exists in current doc - if not, we replace or remove it
73-
let existing = document.definitions.find(definition => definition.kind === 'FragmentDefinition' && definition.name.value === sel.name.value);
73+
const existing = document.definitions.find(definition => definition.kind === 'FragmentDefinition' && definition.name.value === sel.name.value);
7474

7575
if (!existing) {
7676
// First remove the spread, as it has no match in document
@@ -88,18 +88,18 @@ function replaceFragmentsInSelectionSet(selectionSet, fragments, def, document)
8888
newFragmentsSpreads.push(newSpread);
8989

9090
// Add the new fragment definition in document if it has not already been added
91-
let existing = document.definitions.find(definition => definition.kind === 'FragmentDefinition' && definition.name.value === frag.name.value);
91+
const existing = document.definitions.find(definition => definition.kind === 'FragmentDefinition' && definition.name.value === frag.name.value);
9292
if (!existing) {
9393
document.definitions.push(frag);
9494
}
9595
});
9696

9797
// Adds the associated variables to the query
98-
let allVariables = applyableFragments.reduce((result, n) => ({...result, ...n.variables}), {});
98+
const allVariables = applyableFragments.reduce((result, n) => ({...result, ...n.variables}), {});
9999
Object.entries(allVariables).forEach(([name, value]) => {
100-
let existing = def.variableDefinitions.find(def => def.variable.name.value === name);
100+
const existing = def.variableDefinitions.find(def => def.variable.name.value === name);
101101
if (!existing) {
102-
let type = parseType(value, {noLocation: true});
102+
const type = parseType(value, {noLocation: true});
103103
def.variableDefinitions.push({
104104
kind: 'VariableDefinition',
105105
variable: {
@@ -109,7 +109,7 @@ function replaceFragmentsInSelectionSet(selectionSet, fragments, def, document)
109109
value: name
110110
}
111111
},
112-
type: type
112+
type
113113
});
114114
}
115115
});

packages/data-helper/src/hooks/useContentPreview/useContentPreview.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ export const useContentPreview = ({
1212
fetchPolicy
1313
}) => {
1414
const variables = {
15-
path: path,
16-
templateType: templateType,
17-
view: view,
18-
contextConfiguration: contextConfiguration,
19-
language: language,
15+
path,
16+
templateType,
17+
view,
18+
contextConfiguration,
19+
language,
2020
workspace: workspace.toUpperCase(),
21-
requestAttributes: requestAttributes
21+
requestAttributes
2222
};
2323

2424
return useQuery(CONTENT_PREVIEW_QUERY, {

packages/data-helper/src/hooks/useContentPreview/useContentPreview.spec.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import {useContentPreview} from './index.js';
22

3-
jest.mock('react-apollo', () => {
4-
return {
5-
useQuery: jest.fn(() => ({
6-
data: {},
7-
loading: false,
8-
error: null
9-
}))
10-
};
11-
});
3+
jest.mock('react-apollo', () => ({
4+
useQuery: jest.fn(() => ({
5+
data: {},
6+
loading: false,
7+
error: null
8+
}))
9+
}));
1210

1311
import {useQuery} from 'react-apollo';
1412

0 commit comments

Comments
 (0)