Skip to content

Commit 86a0b75

Browse files
authored
refactor: reduce size (#271)
1 parent e2db5d4 commit 86a0b75

File tree

4 files changed

+17
-26
lines changed

4 files changed

+17
-26
lines changed

src/index.js

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// @ts-check
2-
const { resolve } = require('node:path')
2+
let { resolve } = require('node:path')
33

4-
const config = require('lilconfig')
4+
let { lilconfig } = require('lilconfig')
55

6-
const loadOptions = require('./options.js')
7-
const loadPlugins = require('./plugins.js')
8-
const req = require('./req.js')
6+
let loadOptions = require('./options.js')
7+
let loadPlugins = require('./plugins.js')
8+
let req = require('./req.js')
99

10-
const interopRequireDefault = obj =>
10+
let interopRequireDefault = obj =>
1111
obj && obj.__esModule ? obj : { default: obj }
1212

1313
/**
@@ -28,9 +28,7 @@ async function processResult(ctx, result) {
2828
projectConfig = { ...projectConfig, ...ctx }
2929
}
3030

31-
if (!projectConfig.plugins) {
32-
projectConfig.plugins = []
33-
}
31+
if (!projectConfig.plugins) projectConfig.plugins = []
3432

3533
let res = {
3634
file,
@@ -61,9 +59,7 @@ function createContext(ctx) {
6159
...ctx
6260
}
6361

64-
if (!ctx.env) {
65-
process.env.NODE_ENV = 'development'
66-
}
62+
if (!ctx.env) process.env.NODE_ENV = 'development'
6763

6864
return ctx
6965
}
@@ -89,7 +85,7 @@ async function yamlLoader(_, content) {
8985
}
9086

9187
/** @return {import('lilconfig').Options} */
92-
const withLoaders = (options = {}) => {
88+
let withLoaders = (options = {}) => {
9389
let moduleName = 'postcss'
9490

9591
return {
@@ -150,13 +146,10 @@ function rc(ctx, path, options) {
150146
*/
151147
path = path ? resolve(path) : process.cwd()
152148

153-
return config
154-
.lilconfig('postcss', withLoaders(options))
149+
return lilconfig('postcss', withLoaders(options))
155150
.search(path)
156151
.then(result => {
157-
if (!result) {
158-
throw new Error(`No PostCSS Config found in: ${path}`)
159-
}
152+
if (!result) throw new Error(`No PostCSS Config found in: ${path}`)
160153
return processResult(ctx, result)
161154
})
162155
}

src/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @ts-check
2-
const req = require('./req.js')
2+
let req = require('./req.js')
33

44
/**
55
* Load Options

src/plugins.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @ts-check
2-
const req = require('./req.js')
2+
let req = require('./req.js')
33

44
/**
55
* Plugin Loader
@@ -59,9 +59,7 @@ async function plugins(config, file) {
5959

6060
if (list.length && list.length > 0) {
6161
list.forEach((plugin, i) => {
62-
if (plugin.default) {
63-
plugin = plugin.default
64-
}
62+
if (plugin.default) plugin = plugin.default
6563

6664
if (plugin.postcss === true) {
6765
plugin = plugin()

src/req.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// @ts-check
2-
const { createRequire } = require('node:module')
3-
const { pathToFileURL } = require('node:url')
2+
let { createRequire } = require('node:module')
3+
let { pathToFileURL } = require('node:url')
44

5-
const TS_EXT_RE = /\.[mc]?ts$/
5+
let TS_EXT_RE = /\.[mc]?ts$/
66

77
let tsx
88

0 commit comments

Comments
 (0)