Skip to content

Commit c33f960

Browse files
committed
convert to ES modules
- run https://github.com/nolanlawson/cjs-to-es6 - run convert_exports_default_object https://gist.github.com/maxlath/a8d1c03dfd3ccf3e1e0656ce35a4b62a - update eslint rules and run with --fix - replace CommonJS-dependent git-hooks with @vercel/git-hooks - keeping `cross-fetch`, as the active NodeJS LTS still has the native `fetch` behind an experimental flag
1 parent 38399ce commit c33f960

File tree

153 files changed

+3684
-3323
lines changed

Some content is hidden

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

153 files changed

+3684
-3323
lines changed

.eslintrc

-47
This file was deleted.

.eslintrc.cjs

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// This config file is used by eslint
2+
// See package.json scripts: lint*
3+
// Rules documentation: https://eslint.org/docs/rules/
4+
// Inspect the generated config:
5+
// eslint --print-config .eslintrc.cjs
6+
module.exports = {
7+
"root": true,
8+
"extends": [
9+
// See https://github.com/standard/eslint-config-standard/blob/master/.eslintrc.json
10+
"standard"
11+
],
12+
"env": {
13+
"browser": true,
14+
"commonjs": true,
15+
"es2022": true
16+
},
17+
"parserOptions": {
18+
"ecmaVersion": 2022,
19+
"ecmaFeatures": {
20+
"jsx": false
21+
}
22+
},
23+
"rules": {
24+
'array-bracket-spacing': [ 'error', 'always' ],
25+
'arrow-parens': [ 'error', 'as-needed' ],
26+
'comma-dangle': [ 'error', {
27+
arrays: 'always-multiline',
28+
objects: 'always-multiline',
29+
imports: 'always-multiline',
30+
exports: 'always-multiline',
31+
functions: 'never',
32+
} ],
33+
eqeqeq: [ 'error', 'smart' ],
34+
'implicit-arrow-linebreak': [ 'error', 'beside' ],
35+
'import/newline-after-import': 'error',
36+
'import/order': [
37+
'error',
38+
{
39+
pathGroups: [
40+
{ pattern: '#*/**', group: 'internal', position: 'before' },
41+
],
42+
groups: [ 'builtin', 'external', 'internal', 'parent', 'sibling' ],
43+
'newlines-between': 'never',
44+
alphabetize: { order: 'asc' },
45+
},
46+
],
47+
indent: [ 'error', 2, { MemberExpression: 'off' } ],
48+
'linebreak-style': [ 'error', 'unix' ],
49+
'no-ex-assign': [ 'off' ],
50+
'no-var': [ 'error' ],
51+
'nonblock-statement-body-position': [ 'error', 'beside' ],
52+
'object-curly-spacing': [ 'error', 'always' ],
53+
'object-shorthand': [ 'error', 'properties' ],
54+
'one-var': [ 'off' ],
55+
'prefer-arrow-callback': [ 'error' ],
56+
'prefer-const': [ 'error' ],
57+
},
58+
}
59+

config/default.js config/default.cjs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Log full objects
22
require('util').inspect.defaultOptions.depth = null
3-
require('module-alias/register')
43

54
module.exports = {
65
// initConfig

config/local.cjs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module.exports = {
2+
instance: 'http://localhost:8181',
3+
credentials: {
4+
oauth: {
5+
consumer_key: '7bc33647478f215844e82a1ca3e91fd7',
6+
consumer_secret: 'f3bec9695f04c98a7b437a9e58e396ff4abb93de',
7+
token: '40f64185a8108b127cc4f21d00175ad0',
8+
token_secret: '1757420b6a16b2d4a0fd34dee050eb6f603de787',
9+
}
10+
},
11+
12+
credentialsAlt: {
13+
username: 'WikibaseAdmin',
14+
password: 'WikibaseDockerAdminPass',
15+
// oauth: null
16+
// password: 'test_pwd@cq29uo9d4q1df56tq573bbd9ja97332g'
17+
},
18+
19+
secondUserCredentials: {
20+
username: 'Lnwev',
21+
password: 'vHuLL_AkPSdgoYL*LU1=Us-LlEwMLY5Y'
22+
},
23+
24+
// /!\ TESTS REQUIRING ENTITY DELETION WILL FAIL ON test.wikidata.org
25+
// AS IT REQUIRES EXTRA PRIVILEGES
26+
// instance: 'https://test.wikidata.org',
27+
// credentials: {
28+
// oauth: {
29+
// consumer_key: 'cd4cbe38901003712654f1a284da16b6',
30+
// consumer_secret: '913f78ff9d2c715613b71d012115f05acec3e173',
31+
// token: 'fe7eb84d59e964a39d3a023da6a04c0c',
32+
// token_secret: '0961e72de9478a08c63dde04c62c4d6b61092d00',
33+
// }
34+
// },
35+
// credentialsAlt: {
36+
// username: 'Maxlath_tests',
37+
// password: 'MJ188QwTnm=P;lVnPS_&g!s_&YbKGCDu',
38+
// },
39+
40+
// credentialsAlt: {
41+
// username: 'Maxlath',
42+
// password: 'RéeEuùà:Q;2MamMu0Xvu8Lé6K4rfXkjD',
43+
// },
44+
45+
// instance: 'https://www.wikidata.org',
46+
// sparqlEndpoint: 'https://query.wikidata.org',
47+
// maxlag: 20,
48+
}

jsconfig.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"compilerOptions": {
3-
"target": "es6",
4-
"module": "commonJS",
3+
"target": "es2022",
4+
"module": "esnext",
55
"moduleResolution": "node",
66
"baseUrl": ".",
77
"paths": {
8-
"lib/*": [
9-
"./lib/*"
8+
"#lib/*": [
9+
"./lib/*.js"
1010
],
11-
"root/*": [
12-
"*"
11+
"#tests/*": [
12+
"./tests/*.js"
1313
],
14-
"tests/*": [
15-
"./tests/*"
14+
"#root/*": [
15+
"./*"
1616
],
1717
}
1818
},

lib/alias/action.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const validate = require('../validate')
1+
import validate from '../validate.js'
22

3-
module.exports = action => params => {
3+
export default action => params => {
44
const { id, language, value } = params
55

66
validate.entity(id)

lib/alias/add.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
module.exports = require('./action')('add')
1+
import actionFactory from './action.js'
2+
3+
export default actionFactory('add')

lib/alias/remove.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
module.exports = require('./action')('remove')
1+
import actionFactory from './action.js'
2+
3+
export default actionFactory('remove')

lib/alias/set.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
module.exports = require('./action')('set')
1+
import actionFactory from './action.js'
2+
3+
export default actionFactory('set')

lib/badge/add.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const validate = require('../validate')
2-
const format = require('../entity/format')
3-
const { getEntitySitelinks } = require('../get_entity')
4-
const error_ = require('../error')
5-
const { uniq } = require('../utils')
1+
import format from '../entity/format.js'
2+
import error_ from '../error.js'
3+
import { getEntitySitelinks } from '../get_entity.js'
4+
import { uniq } from '../utils.js'
5+
import validate from '../validate.js'
66

7-
module.exports = async (params, config, API) => {
7+
export default async (params, config, API) => {
88
let { id, site, badges } = params
99
validate.entity(id)
1010
validate.site(site)
@@ -22,6 +22,6 @@ module.exports = async (params, config, API) => {
2222
id,
2323
site,
2424
title,
25-
badges: uniq(currentBadges.concat(badges))
25+
badges: uniq(currentBadges.concat(badges)),
2626
})
2727
}

lib/badge/remove.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Doc https://www.wikidata.org/w/api.php?action=help&modules=wbsetsitelink
2-
const validate = require('../validate')
3-
const format = require('../entity/format')
4-
const { getEntitySitelinks } = require('../get_entity')
5-
const error_ = require('../error')
6-
const { difference } = require('../utils')
72

8-
module.exports = async (params, config, API) => {
3+
import format from '../entity/format.js'
4+
import error_ from '../error.js'
5+
import { getEntitySitelinks } from '../get_entity.js'
6+
import { difference } from '../utils.js'
7+
import validate from '../validate.js'
8+
9+
export default async (params, config, API) => {
910
let { id, site, badges } = params
1011
validate.entity(id)
1112
validate.site(site)
@@ -23,6 +24,6 @@ module.exports = async (params, config, API) => {
2324
id,
2425
site,
2526
title,
26-
badges: difference(currentBadges, badges)
27+
badges: difference(currentBadges, badges),
2728
})
2829
}

lib/bundle_wrapper.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const error_ = require('./error')
2-
const fetchUsedPropertiesDatatypes = require('./properties/fetch_used_properties_datatypes')
3-
const validateAndEnrichConfig = require('./validate_and_enrich_config')
1+
import error_ from './error.js'
2+
import fetchUsedPropertiesDatatypes from './properties/fetch_used_properties_datatypes.js'
3+
import validateAndEnrichConfig from './validate_and_enrich_config.js'
44

5-
module.exports = (fn, generalConfig, API) => async (params, reqConfig) => {
5+
export default (fn, generalConfig, API) => async (params, reqConfig) => {
66
validateParams(params)
77
const config = validateAndEnrichConfig(generalConfig, reqConfig)
88
await fetchUsedPropertiesDatatypes(params, config)

lib/claim/builders.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
const { getNumericId } = require('wikibase-sdk')
2-
const getTimeObject = require('./get_time_object')
3-
const { parseQuantity } = require('./quantity')
1+
import { getNumericId } from 'wikibase-sdk'
2+
import getTimeObject from './get_time_object.js'
3+
import { parseQuantity } from './quantity.js'
44

55
// The difference in builders are due to the different expectations of the Wikibase API
66

7-
const singleClaimBuilders = {
7+
export const singleClaimBuilders = {
88
string: str => `"${str}"`,
99
entity: entityId => JSON.stringify(buildEntity(entityId)),
1010
time: value => JSON.stringify(getTimeObject(value)),
1111
// Property type specific builders
1212
monolingualtext: valueObj => JSON.stringify(valueObj),
1313
quantity: (amount, instance) => JSON.stringify(parseQuantity(amount, instance)),
14-
globecoordinate: obj => JSON.stringify(obj)
14+
globecoordinate: obj => JSON.stringify(obj),
1515
}
1616

17-
const entityEditBuilders = {
17+
export const entityEditBuilders = {
1818
string: (pid, value) => valueStatementBase(pid, 'string', value),
1919
entity: (pid, value) => {
2020
return valueStatementBase(pid, 'wikibase-entityid', buildEntity(value))
@@ -25,7 +25,7 @@ const entityEditBuilders = {
2525
time: (pid, value) => valueStatementBase(pid, 'time', getTimeObject(value)),
2626
quantity: (pid, value, instance) => valueStatementBase(pid, 'quantity', parseQuantity(value, instance)),
2727
globecoordinate: (pid, value) => valueStatementBase(pid, 'globecoordinate', value),
28-
specialSnaktype: (pid, snaktype) => statementBase(pid, snaktype)
28+
specialSnaktype: (pid, snaktype) => statementBase(pid, snaktype),
2929
}
3030

3131
const buildEntity = entityId => {
@@ -41,8 +41,8 @@ const statementBase = (pid, snaktype, value) => {
4141
type: 'statement',
4242
mainsnak: {
4343
property: pid,
44-
snaktype
45-
}
44+
snaktype,
45+
},
4646
}
4747
}
4848

@@ -51,5 +51,3 @@ const valueStatementBase = (pid, type, value) => {
5151
statement.mainsnak.datavalue = { type, value }
5252
return statement
5353
}
54-
55-
module.exports = { singleClaimBuilders, entityEditBuilders }

lib/claim/claim_parsers.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
const { claim: simplifyClaim } = require('wikibase-sdk').simplify
2-
const { hasSpecialSnaktype } = require('./special_snaktype')
1+
import { simplifyClaim } from 'wikibase-sdk'
2+
import { hasSpecialSnaktype } from './special_snaktype.js'
33

4-
module.exports = {
5-
matchClaim: value => claim => {
6-
if (typeof value === 'object') {
7-
if (hasSpecialSnaktype(value)) {
8-
if (claim.mainsnak.snaktype === value.snaktype) return true
9-
}
10-
value = value.value
4+
export const matchClaim = value => claim => {
5+
if (typeof value === 'object') {
6+
if (hasSpecialSnaktype(value)) {
7+
if (claim.mainsnak.snaktype === value.snaktype) return true
118
}
12-
return value === simplifyClaim(claim)
13-
},
14-
getGuid: claim => claim.id
9+
value = value.value
10+
}
11+
return value === simplifyClaim(claim)
1512
}
13+
14+
export const getGuid = claim => claim.id

lib/claim/create.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const error_ = require('../error')
1+
import error_ from '../error.js'
22

3-
module.exports = async (params, config, API) => {
3+
export default async (params, config, API) => {
44
const { id, property, value, qualifiers, references, rank, reconciliation } = params
55

66
if (!value) throw error_.new('missing value', 400, params)
@@ -22,7 +22,7 @@ module.exports = async (params, config, API) => {
2222
const data = {
2323
id,
2424
claims: {
25-
[property]: claim
25+
[property]: claim,
2626
},
2727
summary,
2828
baserevid: params.baserevid || config.baserevid,

lib/claim/find_snak.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const error_ = require('../error')
2-
const isMatchingSnak = require('./is_matching_snak')
1+
import error_ from '../error.js'
2+
import isMatchingSnak from './is_matching_snak.js'
33

4-
module.exports = (property, propSnaks, searchedValue) => {
4+
export default (property, propSnaks, searchedValue) => {
55
if (!propSnaks) return
66

77
const matchingSnaks = propSnaks.filter(snak => isMatchingSnak(snak, searchedValue))

lib/claim/format_claim_value.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const { parseQuantity } = require('./quantity')
2-
const { hasSpecialSnaktype } = require('./special_snaktype')
1+
import { parseQuantity } from './quantity.js'
2+
import { hasSpecialSnaktype } from './special_snaktype.js'
33

4-
module.exports = (datatype, value, instance) => {
4+
export default (datatype, value, instance) => {
55
if (hasSpecialSnaktype(value)) return value
66
// Try to recover data passed in a different type than the one expected:
77
// - Quantities should be of type number

0 commit comments

Comments
 (0)