Skip to content

Commit 7fb18ae

Browse files
committed
fix: use latest dataset for building entity files
1 parent d9d9437 commit 7fb18ae

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

bin/build-entity-json-files.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ const _ = require('lodash')
22
const fs = require('fs')
33
const path = require('path')
44
const JSON5 = require('json5')
5-
const {importMergedData} = require('./shared/merge-entity-origin-data')
5+
const {
6+
importMergedData,
7+
getEntityDatasetsMostRecentFirst,
8+
} = require('./shared/merge-entity-origin-data')
69

710
const DIST_DIR = path.join(__dirname, '../dist')
811
const DATA_DIR = path.join(__dirname, '../data')
@@ -16,7 +19,7 @@ function cleanStatsFromEntity(entity) {
1619
const sourceEntities = JSON5.parse(fs.readFileSync(`${DATA_DIR}/entities.json5`, 'utf8'))
1720
fs.writeFileSync(`${DIST_DIR}/entities.json`, JSON.stringify(sourceEntities))
1821

19-
const httpArchiveData = importMergedData('2019-04-01-entity-scripting.json')
22+
const httpArchiveData = importMergedData(getEntityDatasetsMostRecentFirst()[0])
2023
const {getEntity} = require('../lib/index.js') // IMPORTANT: require this after entities have been written
2124
const entityExecutionStats = _(httpArchiveData)
2225
.groupBy(({domain}) => {

bin/shared/merge-entity-origin-data.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ function importDataset(filename) {
1414
}
1515

1616
module.exports = {
17+
importDataset,
18+
getEntityDatasetsMostRecentFirst() {
19+
return fs
20+
.readdirSync(DATA_FOLDER)
21+
.filter(f => f.includes('entity-scripting'))
22+
.sort()
23+
.reverse()
24+
},
1725
importMergedData(entityFilename) {
1826
const originFilename = entityFilename.replace('entity-scripting', 'origin-scripting')
1927

lib/index.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('getEntity', () => {
3636
it('works for direct domain usage', () => {
3737
expect(getEntity('https://js.connect.facebook.net/lib.js')).toMatchInlineSnapshot(`
3838
Object {
39-
"averageExecutionTime": 142.24502022559832,
39+
"averageExecutionTime": 161.0291502603836,
4040
"categories": Array [
4141
"social",
4242
],
@@ -60,16 +60,16 @@ Object {
6060
],
6161
"homepage": "https://www.facebook.com",
6262
"name": "Facebook",
63-
"totalExecutionTime": 288666212,
64-
"totalOccurrences": 2029359,
63+
"totalExecutionTime": 578108820,
64+
"totalOccurrences": 3590088,
6565
}
6666
`)
6767
})
6868

6969
it('works for inferred domain usage', () => {
7070
expect(getEntity('https://unknown.typekit.net/fonts.css')).toMatchInlineSnapshot(`
7171
Object {
72-
"averageExecutionTime": 91.44604519774012,
72+
"averageExecutionTime": 93.6581576026637,
7373
"categories": Array [
7474
"cdn",
7575
],
@@ -84,8 +84,8 @@ Object {
8484
],
8585
"homepage": "https://fonts.adobe.com/",
8686
"name": "Adobe TypeKit",
87-
"totalExecutionTime": 971157,
88-
"totalOccurrences": 10620,
87+
"totalExecutionTime": 1940878,
88+
"totalOccurrences": 20723,
8989
}
9090
`)
9191
})

0 commit comments

Comments
 (0)