Skip to content

Commit 14b39ac

Browse files
Alasdair Mercerneocotic
Alasdair Mercer
authored andcommitted
Replace lodash package with lodash-es for better ESM support
1 parent 54e54f9 commit 14b39ac

29 files changed

+127
-128
lines changed

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"glob": "^10.3.3",
4444
"hosted-git-info": "^7.0.0",
4545
"image-size": "^1.0.2",
46-
"lodash": "^4.17.21",
46+
"lodash-es": "^4.17.21",
4747
"mime": "^3.0.0",
4848
"mkdirp": "^3.0.1",
4949
"pkg-up": "^4.0.0",

src/color.mjs

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
/* istanbul ignore file */
2424

25-
import _ from 'lodash';
2625
import convert from 'color-convert';
26+
import { chain, trim } from 'lodash-es';
2727

2828
/**
2929
* Contains color information based on a specific value in a single color format and supports easy conversion to other
@@ -62,16 +62,16 @@ export class Color {
6262
* @public
6363
*/
6464
constructor(options) {
65-
const format = _.trim(options.format).toLowerCase();
65+
const format = trim(options.format).toLowerCase();
6666
if (!convert[format]) {
6767
throw new Error(`Unsupported color format: ${format}`);
6868
}
6969

7070
this.#format = format;
71-
this.#name = _.trim(options.name) || null;
72-
this.#value = options.value == null ? [] : _.chain(options.value)
71+
this.#name = trim(options.name) || null;
72+
this.#value = options.value == null ? [] : chain(options.value)
7373
.castArray()
74-
.map((v) => typeof v === 'string' ? _.trim(v) : v)
74+
.map((v) => typeof v === 'string' ? trim(v) : v)
7575
.value();
7676
}
7777

src/config/config.mjs

+11-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
/* istanbul ignore file */
2424

25-
import _ from 'lodash';
25+
import { castArray, cloneDeep, get, trim } from 'lodash-es';
2626
import { EOL } from 'node:os';
2727
import path from 'node:path';
2828

@@ -129,10 +129,10 @@ export class Config {
129129
this.#pkg = options.pkg || new Package();
130130
this.#repository = new Repo(repositoryService.getRepository(options.repository));
131131
this.#baseDir = path.dirname(this.#filePath);
132-
this.#email = _.trim(this.#data.email) || null;
133-
this.#homepage = _.trim(this.#data.homepage) || _.trim(this.#pkg.get('homepage')) || this.#repository.homepage;
134-
this.#name = _.trim(this.#data.name) || _.trim(this.#pkg.get('name')) || this.#repository.name;
135-
this.#title = _.trim(this.#data.title) || this.#name;
132+
this.#email = trim(this.#data.email) || null;
133+
this.#homepage = trim(this.#data.homepage) || trim(this.#pkg.get('homepage')) || this.#repository.homepage;
134+
this.#name = trim(this.#data.name) || trim(this.#pkg.get('name')) || this.#repository.name;
135+
this.#title = trim(this.#data.title) || this.#name;
136136
this.#lineSeparator = ((lineSeparator) => {
137137
switch (lineSeparator) {
138138
case 'crlf':
@@ -142,7 +142,7 @@ export class Config {
142142
default:
143143
return EOL;
144144
}
145-
})(_.trim(this.option('lineSeparator')).toLowerCase());
145+
})(trim(this.option('lineSeparator')).toLowerCase());
146146
}
147147

148148
/**
@@ -172,7 +172,7 @@ export class Config {
172172
* @public
173173
*/
174174
assetURL(paths) {
175-
paths = _.castArray(paths);
175+
paths = castArray(paths);
176176

177177
const assetURL = this.option('assets.url');
178178
let filePath = paths.map((p) => p.replace(/\\/g, '/')).join('/');
@@ -214,7 +214,7 @@ export class Config {
214214
* @public
215215
*/
216216
docURL(paths, fragment) {
217-
paths = _.castArray(paths);
217+
paths = castArray(paths);
218218

219219
const docURL = this.option('docs.url');
220220
let filePath = paths.map((p) => p.replace(/\\/g, '/')).join('/');
@@ -264,7 +264,7 @@ export class Config {
264264
* @public
265265
*/
266266
option(name, defaultValue) {
267-
return _.get(this.#data.options, name, defaultValue);
267+
return get(this.#data.options, name, defaultValue);
268268
}
269269

270270
/**
@@ -342,7 +342,7 @@ export class Config {
342342
throw new TypeError('"docs" configuration can only be an array');
343343
}
344344

345-
return _.cloneDeep(docs);
345+
return cloneDeep(docs);
346346
}
347347

348348
/**
@@ -490,7 +490,7 @@ export class Config {
490490
throw new TypeError('"tasks" configuration can only be an array');
491491
}
492492

493-
return _.cloneDeep(tasks);
493+
return cloneDeep(tasks);
494494
}
495495

496496
/**

src/config/context-parser.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
/* istanbul ignore file */
2424

25-
import _ from 'lodash';
2625
import Debug from 'debug';
26+
import { cloneDeep } from 'lodash-es';
2727
import { EventEmitter } from 'node:events';
2828
import pollock from 'pollock';
2929

@@ -97,7 +97,7 @@ export class ContextParser extends EventEmitter {
9797
return null;
9898
}
9999

100-
const data = _.cloneDeep(this.#dataSet[index]);
100+
const data = cloneDeep(this.#dataSet[index]);
101101
if (!data) {
102102
debug('No data found at index: %d', index);
103103

src/config/expression.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
/* istanbul ignore file */
2424

25-
import _ from 'lodash';
25+
import { template } from 'lodash-es';
2626

2727
/**
2828
* Compiles a raw expression string so that it can be evaluated, optionally using data passed in directly to it to
@@ -33,7 +33,7 @@ import _ from 'lodash';
3333
export class Expression {
3434

3535
/**
36-
* @type {TemplateExecutor}
36+
* @type {Function}
3737
* @private
3838
*/
3939
#compiled;
@@ -45,7 +45,7 @@ export class Expression {
4545
* @public
4646
*/
4747
constructor(str) {
48-
this.#compiled = _.template(str);
48+
this.#compiled = template(str);
4949
}
5050

5151
/**

src/config/package/package.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
/* istanbul ignore file */
2424

25-
import _ from 'lodash';
25+
import { cloneDeep, get } from 'lodash-es';
2626

2727
/**
2828
* Contains parsed package data that has been loaded from a single package file.
@@ -71,7 +71,7 @@ export class Package {
7171
* @public
7272
*/
7373
get(name, defaultValue) {
74-
return _.get(this.#data, name, defaultValue);
74+
return get(this.#data, name, defaultValue);
7575
}
7676

7777
/**
@@ -90,7 +90,7 @@ export class Package {
9090
* @public
9191
*/
9292
get data() {
93-
return this.#data ? _.cloneDeep(this.#data) : null;
93+
return this.#data ? cloneDeep(this.#data) : null;
9494
}
9595

9696
/**

src/config/repository/git/git-repository-provider.mjs

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
/* istanbul ignore file */
2424

25-
import _ from 'lodash';
2625
import chalk from 'chalk';
2726
import Debug from 'debug';
2827
import hostedGitInfo from 'hosted-git-info';
28+
import { chain, isEmpty, trim } from 'lodash-es';
2929
import { spawn } from 'node:child_process';
3030

3131
import { GitRepository } from './git-repository.mjs';
@@ -88,7 +88,7 @@ export class GitRepositoryProvider extends RepositoryProvider {
8888
debug('Resolving Git repository URL from directory: %s', chalk.blue(dirPath));
8989

9090
const remotes = await this.#getRemoteNames(dirPath);
91-
if (_.isEmpty(remotes)) {
91+
if (isEmpty(remotes)) {
9292
debug('No remotes found in Git repository at directory: %s', chalk.blue(dirPath));
9393

9494
return null;
@@ -157,7 +157,7 @@ export class GitRepositoryProvider extends RepositoryProvider {
157157
async #getBranchName(dirPath) {
158158
const output = await this.#execGit(dirPath, 'branch', '--show-current');
159159

160-
return _.trim(output) || null;
160+
return trim(output) || null;
161161
}
162162

163163
/**
@@ -168,9 +168,9 @@ export class GitRepositoryProvider extends RepositoryProvider {
168168
async #getRemoteNames(dirPath) {
169169
const output = await this.#execGit(dirPath, 'remote', 'show');
170170

171-
return _.chain(output)
171+
return chain(output)
172172
.split(/\n/)
173-
.map(_.trim)
173+
.map(trim)
174174
.compact()
175175
.value();
176176
}
@@ -184,7 +184,7 @@ export class GitRepositoryProvider extends RepositoryProvider {
184184
async #getRemoteURL(name, dirPath) {
185185
const output = await this.#execGit(dirPath, 'remote', 'get-url', name);
186186

187-
return _.trim(output) || null;
187+
return trim(output) || null;
188188
}
189189

190190
}

src/config/repository/repository-service.mjs

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
/* istanbul ignore file */
2424

25-
import _ from 'lodash';
2625
import chalk from 'chalk';
2726
import Debug from 'debug';
27+
import { get, trim } from 'lodash-es';
2828

2929
import { GitRepositoryProvider } from './git/git-repository-provider.mjs';
3030

@@ -257,10 +257,10 @@ export class RepositoryService {
257257
let type, url;
258258

259259
if (typeof info === 'string') {
260-
url = _.trim(info) || null;
260+
url = trim(info) || null;
261261
} else {
262-
type = _.trim(_.get(info, 'type')).toLowerCase() || null;
263-
url = _.trim(_.get(info, 'url')) || null;
262+
type = trim(get(info, 'type')).toLowerCase() || null;
263+
url = trim(get(info, 'url')) || null;
264264
}
265265

266266
return { type, url };

0 commit comments

Comments
 (0)