Skip to content

Commit a979b98

Browse files
committed
Refactor to remove some dependencies
1 parent ef3e150 commit a979b98

File tree

6 files changed

+39
-35
lines changed

6 files changed

+39
-35
lines changed

crawl/sponsors.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import fs from 'node:fs/promises'
4141
import path from 'node:path'
4242
import process from 'node:process'
43-
import chalk from 'chalk'
4443
import dotenv from 'dotenv'
4544

4645
dotenv.config()
@@ -121,8 +120,7 @@ const members = json.data.collective.members.nodes
121120

122121
if (!info) {
123122
console.error(
124-
chalk.red('✖') +
125-
' @%s is an unknown sponsor, please define whether it’s spam or not in `sponsors.txt`',
123+
'✖ @%s is an unknown sponsor, please define whether it’s spam or not in `sponsors.txt`',
126124
oc
127125
)
128126
}

generate/asset.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import process from 'node:process'
99
import {glob} from 'glob'
1010
import sharp from 'sharp'
1111
import pAll from 'p-all'
12-
import {mkdirp} from 'vfile-mkdirp'
1312
import {VFile} from 'vfile'
1413
import {read, write} from 'to-vfile'
1514
import {reporter} from 'vfile-reporter'
@@ -65,7 +64,8 @@ const tasks = [
6564
'build',
6665
...file.dirname.split(path.sep).slice(1)
6766
].join(path.sep)
68-
await mkdirp(file)
67+
assert(file.dirname)
68+
await fs.mkdir(file.dirname, {recursive: true})
6969
await write(file)
7070
file.stored = true
7171
console.error(reporter(file))
@@ -75,7 +75,8 @@ const tasks = [
7575
file.dirname = ['build', ...file.dirname.split(path.sep).slice(1)].join(
7676
path.sep
7777
)
78-
await mkdirp(file)
78+
assert(file.dirname)
79+
await fs.mkdir(file.dirname, {recursive: true})
7980
await fs.copyFile(file.history[0], file.path)
8081
file.stored = true
8182
console.error(reporter(file))

generate/index.js

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @import {Root} from 'hast'
3-
* @import {DataMap, VFile} from 'vfile'
3+
* @import {DataMap} from 'vfile'
44
* @import {Human} from '../data/humans.js'
55
* @import {Release} from '../data/releases.js'
66
* @import {Person as Sponsor} from '../data/sponsors.js'
@@ -32,8 +32,9 @@ import yaml from 'yaml'
3232
import {glob} from 'glob'
3333
import {matter} from 'vfile-matter'
3434
import all from 'p-all'
35-
import {toVFile, read, readSync, write} from 'to-vfile'
35+
import {read, write} from 'to-vfile'
3636
import {reporter} from 'vfile-reporter'
37+
import {VFile} from 'vfile'
3738
import {humans} from '../data/humans.js'
3839
import {releases as dataReleases} from '../data/releases.js'
3940
import {sponsors} from '../data/sponsors.js'
@@ -79,27 +80,29 @@ await expandReleases(dataReleases)
7980

8081
const input = await glob('doc/learn/**/*.md')
8182

82-
const entries = input.map(function (input) {
83-
const file = readSync(input)
84-
matter(file)
85-
const slug = path.basename(input, path.extname(input))
86-
let meta = file.data.meta
87-
88-
if (!meta) {
89-
meta = {}
90-
file.data.meta = meta
91-
}
92-
93-
assert(file.data.matter)
94-
const {group, tags} = file.data.matter || {}
95-
assert(typeof group === 'string')
96-
meta.type = 'article'
97-
meta.tags = [group]
98-
if (tags) meta.tags.push(...tags)
99-
meta.pathname = ['', 'learn', group, slug, ''].join('/')
100-
101-
return file
102-
})
83+
const entries = await Promise.all(
84+
input.map(async function (input) {
85+
const file = await read(input)
86+
matter(file)
87+
const slug = path.basename(input, path.extname(input))
88+
let meta = file.data.meta
89+
90+
if (!meta) {
91+
meta = {}
92+
file.data.meta = meta
93+
}
94+
95+
assert(file.data.matter)
96+
const {group, tags} = file.data.matter || {}
97+
assert(typeof group === 'string')
98+
meta.type = 'article'
99+
meta.tags = [group]
100+
if (tags) meta.tags.push(...tags)
101+
meta.pathname = ['', 'learn', group, slug, ''].join('/')
102+
103+
return file
104+
})
105+
)
103106

104107
const sections = [
105108
{
@@ -313,7 +316,7 @@ all(promises, {concurrency: 50})
313316
*/
314317
function page(render, meta) {
315318
tasks.push(function () {
316-
return {tree: render(), file: toVFile({data: {meta}})}
319+
return {tree: render(), file: new VFile({data: {meta}})}
317320
})
318321
}
319322

generate/pipeline/main.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*/
55

66
import assert from 'node:assert/strict'
7+
import fs from 'node:fs/promises'
78
import path from 'node:path'
8-
import {mkdirp} from 'vfile-mkdirp'
99
import {unified} from 'unified'
1010
import rehypePresetMinify from 'rehype-preset-minify'
1111
import rehypeDocument from 'rehype-document'
@@ -103,6 +103,7 @@ function mkdir() {
103103
* @returns {Promise<undefined>}
104104
*/
105105
async function transformer(_, file) {
106-
await mkdirp(file)
106+
assert(file.dirname)
107+
await fs.mkdir(file.dirname, {recursive: true})
107108
}
108109
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"#": "note: `lz-string` is included because `@typescript/vfs` (through `twoslash`) types use it w/o marking it as a dep",
23
"author": "Titus Wormer <[email protected]> (https://wooorm.com)",
34
"bugs": "https://github.com/unifiedjs/unifiedjs.github.io/issues",
45
"contributors": [
@@ -14,7 +15,6 @@
1415
"@types/random-useragent": "^0.3.0",
1516
"@wooorm/starry-night": "^3.0.0",
1617
"bytes": "^3.0.0",
17-
"chalk": "^5.0.0",
1818
"cssnano": "^7.0.0",
1919
"cssnano-preset-advanced": "^7.0.0",
2020
"d3-scale": "^4.0.0",
@@ -35,6 +35,7 @@
3535
"html-url-attributes": "^3.0.0",
3636
"humanize-url": "^3.0.0",
3737
"javascript-time-ago": "^2.0.0",
38+
"lz-string": "^1.0.0",
3839
"p-all": "^5.0.0",
3940
"pick-random": "^4.0.0",
4041
"pluralize": "^8.0.0",
@@ -89,8 +90,8 @@
8990
"typescript": "^5.0.0",
9091
"unified": "^11.0.0",
9192
"unist-util-visit": "^5.0.0",
93+
"vfile": "^6.0.0",
9294
"vfile-matter": "^5.0.0",
93-
"vfile-mkdirp": "^3.0.0",
9495
"vfile-rename": "^3.0.0",
9596
"vfile-reporter": "^8.0.0",
9697
"xo": "^0.59.0",

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- lint disable first-heading-level -->
1+
<!-- lint ignore first-heading-level -->
22

33
# [`unifiedjs.com`][site]
44

0 commit comments

Comments
 (0)