mirror of
https://github.com/iconify/collections-json.git
synced 2024-11-21 20:15:12 +00:00
deps: add pathe
dependency
chore: use `pathe` instead `upath`
This commit is contained in:
parent
80d1506eeb
commit
7e84c7d78a
@ -30,10 +30,12 @@
|
||||
"scripts": {
|
||||
"build": "rimraf dist && tsup src/index.ts --format cjs,esm --dts",
|
||||
"test-esm": "jest --clearCache && cross-env NODE_OPTIONS=--experimental-vm-modules npx jest --config=jest.esm.config.ts",
|
||||
"test-cjs": "yarn build && jest --clearCache && jest --config=jest.cjs.config.ts"
|
||||
"test-cjs": "yarn build && jest --clearCache && jest --config=jest.cjs.config.ts",
|
||||
"test-locate-esm": "jest --clearCache && cross-env NODE_OPTIONS=--experimental-vm-modules npx jest --config=jest.esm.config.ts src/locate.esm.test.ts -i",
|
||||
"test-locate-cjs": "yarn build && jest --clearCache && jest --config=jest.cjs.config.ts src/locate.cjs.test.ts -i"
|
||||
},
|
||||
"dependencies": {
|
||||
"upath": "^2.0.1"
|
||||
"pathe": "^0.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@antfu/eslint-config": "^0.9.0",
|
||||
|
32
src/index.ts
32
src/index.ts
@ -10,9 +10,7 @@
|
||||
*/
|
||||
import { PathLike, promises as fs } from 'fs'
|
||||
import { fileURLToPath } from 'url'
|
||||
import Upath from 'upath'
|
||||
|
||||
const { dirname, resolve } = Upath
|
||||
import { dirname, join } from 'pathe'
|
||||
|
||||
/**
|
||||
* Icon dimensions.
|
||||
@ -392,9 +390,29 @@ export type IconifyMetaDataCollection = {
|
||||
[prefix: string]: IconifyMetaData
|
||||
}
|
||||
|
||||
const _dirname = typeof __dirname !== 'undefined' ? __dirname : dirname(fileURLToPath(import.meta.url))
|
||||
const _dirname = typeof __dirname !== 'undefined'
|
||||
? __dirname
|
||||
: dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
const dir = resolve(_dirname, '..')
|
||||
const dir = join(_dirname, '/..')
|
||||
|
||||
// todo@userquin: cleanup
|
||||
// console.log(`_dirname: ${_dirname}`)
|
||||
// if (typeof __dirname === 'undefined') {
|
||||
// if (false/* process.platform === 'win32' */) {
|
||||
// console.log(`_dirname3: ${dirname(import.meta.url)}`)
|
||||
// console.log(`_dirname3: ${join(dirname(import.meta.url), '/..')}`)
|
||||
// console.log(`_dirname3: ${resolve(join(dirname(import.meta.url), '/..'))}`)
|
||||
// }
|
||||
// else {
|
||||
// console.log(`_dirname2: ${dirname(fileURLToPath(import.meta.url))}`)
|
||||
// console.log(`_dirname2: ${join(fileURLToPath(dirname(import.meta.url)), '/..')}`)
|
||||
// console.log(`_dirname2: ${normalize(join(dirname(fileURLToPath(import.meta.url)), '/..'))}`)
|
||||
// }
|
||||
// }
|
||||
// console.log(`Normalized _dirname: ${normalize(_dirname)}`)
|
||||
// console.log(`Resolve _dirname: ${resolve(_dirname, '..')}`)
|
||||
// console.log(`Normalized _dirname: ${dir}`)
|
||||
|
||||
/**
|
||||
* Locate JSON file
|
||||
@ -402,7 +420,7 @@ const dir = resolve(_dirname, '..')
|
||||
* @param {string} name Collection name
|
||||
* @returns {string} Path to collection json file
|
||||
*/
|
||||
export const locate = (name: string): PathLike => `${dir}/json/${name}.json`
|
||||
export const locate = (name: string): PathLike => join(dir, `./json/${name}.json`)
|
||||
|
||||
/**
|
||||
* Loads a collection.
|
||||
@ -430,5 +448,5 @@ export const lookupCollection = async(name: string): Promise<IconifyJSON> => {
|
||||
* @return {Promise<IconifyMetaDataCollection>}
|
||||
*/
|
||||
export const lookupCollections = async(): Promise<IconifyMetaDataCollection> => {
|
||||
return JSON.parse(await fs.readFile(`${dir}/collections.json`, 'utf8'))
|
||||
return JSON.parse(await fs.readFile('./collections.json', 'utf8'))
|
||||
}
|
||||
|
@ -1,12 +1,10 @@
|
||||
import { resolve } from 'path'
|
||||
import { PathLike } from 'fs'
|
||||
|
||||
const cwd = process.cwd()
|
||||
import { resolve } from 'pathe'
|
||||
|
||||
export const locateTest = (locate: (name: string) => PathLike) => {
|
||||
test('mdi resolves the json collection', () => {
|
||||
const received = locate('mdi') as string
|
||||
const expected = resolve(cwd, 'json', 'mdi.json').replace(/\\/g, '/')
|
||||
const expected = resolve('./json/mdi.json').replace(/\\/g, '/')
|
||||
expect(received).toBe(expected)
|
||||
})
|
||||
}
|
||||
|
10
yarn.lock
10
yarn.lock
@ -3438,6 +3438,11 @@ path-type@^4.0.0:
|
||||
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
|
||||
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==
|
||||
|
||||
pathe@^0.0.2:
|
||||
version "0.0.2"
|
||||
resolved "https://registry.yarnpkg.com/pathe/-/pathe-0.0.2.tgz#d690780e578a8127e1d65828387609c153afc309"
|
||||
integrity sha512-mmK20YtPb4yXHlaPuOD/uPIpRu7iIK45GA/GiRSlNpIdfWDG5aEQmFT1HHtBmJB+t/6DvFOtOsEipsPA8Bx2cw==
|
||||
|
||||
picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.2.3:
|
||||
version "2.3.0"
|
||||
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.0.tgz#f1f061de8f6a4bf022892e2d128234fb98302972"
|
||||
@ -4195,11 +4200,6 @@ universalify@^0.1.2:
|
||||
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66"
|
||||
integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==
|
||||
|
||||
upath@^2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/upath/-/upath-2.0.1.tgz#50c73dea68d6f6b990f51d279ce6081665d61a8b"
|
||||
integrity sha512-1uEe95xksV1O0CYKXo8vQvN1JEbtJp7lb7C5U9HMsIp6IVwntkH/oNUzyVNQSd4S1sYk2FpSSW44FqMc8qee5w==
|
||||
|
||||
uri-js@^4.2.2:
|
||||
version "4.4.1"
|
||||
resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e"
|
||||
|
Loading…
Reference in New Issue
Block a user