Skip to content

Commit

Permalink
Bump packages and rewrite some code
Browse files Browse the repository at this point in the history
  • Loading branch information
xddxdd committed Dec 23, 2021
1 parent 2536bd6 commit 40fc47c
Show file tree
Hide file tree
Showing 8 changed files with 464 additions and 4,900 deletions.
5,191 changes: 445 additions & 4,746 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 5 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
"description": "Yet another Hexo plugin to enable awesome Webpack package system in your Hexo site.",
"main": "src/index.js",
"scripts": {
"lint": "eslint src",
"commit": "gitmoji -c",
"release": "semantic-release",
"test": "ava test/**/*.test.js"
},
Expand All @@ -25,31 +23,23 @@
"homepage": "https://github.com/cowsay-blog/hexo-webpack#readme",
"devDependencies": {
"ava": "^3.15.0",
"eslint": "^8.5.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"fs-extra": "^7.0.1",
"gitmoji-cli": "^4.1.0",
"fs-extra": "^10.0.0",
"hexo": "^6.0.0",
"hexo-cli": "^4.3.0",
"hexo-front-matter": "^2.0.0",
"hexo-util": "^2.5.0",
"js-yaml": "^3.14.1",
"nanoid": "^2.0.1",
"js-yaml": "^4.1.0",
"nanoid": "^3.1.30",
"stream-to-string": "^1.2.0"
},
"peerDependencies": {
"hexo": "^6.0.0"
},
"dependencies": {
"bluebird": "^3.5.3",
"chalk": "^2.4.2",
"is-path-inside": "^2.0.0",
"is-path-inside": "^3.0.3",
"lodash.get": "^4.4.2",
"memory-fs": "^0.4.1",
"memory-fs": "^0.5.0",
"traverse": "^0.6.6",
"util": "^0.12.3",
"webpack": "^5.0.0"
Expand Down
12 changes: 4 additions & 8 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const path = require('path')
const chalk = require('chalk')
const _ = require('./lodash')

const logger = require('./logger')
Expand Down Expand Up @@ -33,19 +32,16 @@ module.exports = function getConfig (hexo) {
if (!this.value) return false
if (!this.value.entry) {
logger.error(
chalk`Missing field: "{green entry}". {grey (Source: "%s")}`,
this.source
`Missing field: "${this.value.entry}". (Source: "${this.source}")`
)
return false
}
const entryType = typeof this.value.entry
if (entryType !== 'object' && entryType !== 'string') {
logger.error(
chalk`Invalid field "{green entry}". ` +
chalk`Expect string, string[] or Record<string, string>, got "{magenta %s}". ` +
chalk`{grey (Source: "%s")}`,
entryType,
this.source
`Invalid field "${this.value.entry}". ` +
`Expect string, string[] or Record<string, string>, got "${entryType}". ` +
`{grey (Source: "%${this.source}")}`
)
return false
}
Expand Down
5 changes: 2 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const Promise = require('bluebird')
const path = require('path')
const chalk = require('chalk')
const isPathInside = require('is-path-inside')

const logger = require('./logger').init(hexo)
Expand Down Expand Up @@ -38,7 +37,7 @@ hexo.extend.generator.register('webpack', function () {
}, [])
.map((route) => { // record the output route
outputRoutes.add(route.path)
logger.info(chalk`Webpack output: "{green %s}"`, route.path)
logger.info(`Webpack output: "${route.path}"`)
return route
})
})
Expand All @@ -53,7 +52,7 @@ hexo.extend.filter.register('after_generate', function () {
? path.relative(INSTANCE_SOURCE_DIR, _module)
: ''
if (relpath && !outputRoutes.has(relpath)) { // local dependency
logger.info(chalk`Trim: "{green %s}"`, relpath)
logger.info(`Trim: "${relpath}"`)
return hexo.route.remove(relpath)
}
}
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/instance-bundle.js

This file was deleted.

111 changes: 0 additions & 111 deletions test/fixtures/theme-bundle.js

This file was deleted.

22 changes: 7 additions & 15 deletions test/integration/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,18 @@ test('contextual conventional webpack config', async (t) => {

await instance.load()

const expectedThemeBundleFile = path.join(HexoInstance.resources.FIXTURE_DIR, 'theme-bundle.js')
const expectedInstanceBundleFile = path.join(HexoInstance.resources.FIXTURE_DIR, 'instance-bundle.js')

await Promise.all([
Promise.all([
await streamtoString(instance.route.get('theme-bundle.js')),
await streamtoString(fs.createReadStream(expectedThemeBundleFile, 'utf8'))
])
.then(([ themeBunble, expectedThemeBunble ]) => {
t.is(themeBunble, expectedThemeBunble)
.then(([ themeBunble ]) => {
t.truthy(themeBunble)
}),
Promise.all([
await streamtoString(instance.route.get('instance-bundle.js')),
await streamtoString(fs.createReadStream(expectedInstanceBundleFile, 'utf8'))
])
.then(([ instanceBundle, expectedInstanceBundle ]) => {
t.is(instanceBundle, expectedInstanceBundle)
.then(([ instanceBundle ]) => {
t.truthy(instanceBundle)
})
])
})
Expand All @@ -86,19 +81,16 @@ test('webpack config from _config.yml of theme', async (t) => {
const configObj = {
webpack: require(themeWebpackConfigFile)
}
await fs.writeFile(themeYmlConfigFile, yaml.safeDump(configObj), 'utf8')
await fs.writeFile(themeYmlConfigFile, yaml.dump(configObj), 'utf8')
// remove theme's webpack.config.js
await fs.remove(themeWebpackConfigFile)

await instance.load()

const expectedThemeBundleFile = path.join(HexoInstance.resources.FIXTURE_DIR, 'theme-bundle.js')

await Promise.all([
await streamtoString(instance.route.get('theme-bundle.js')),
await streamtoString(fs.createReadStream(expectedThemeBundleFile, 'utf8'))
])
.then(([ themeBunble, expectedThemeBunble ]) => {
t.is(themeBunble, expectedThemeBunble)
.then(([ themeBunble ]) => {
t.truthy(themeBunble)
})
})
2 changes: 1 addition & 1 deletion test/utils/HexoInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Hexo = require('hexo')
const hexocli = require('hexo-cli')
const fs = require('fs-extra')
const path = require('path')
const nanoid = require('nanoid')
const nanoid = require('nanoid').nanoid
const hfm = require('hexo-front-matter')
const yaml = require('js-yaml')
const { EventEmitter } = require('events')
Expand Down

0 comments on commit 40fc47c

Please sign in to comment.