From 7e84c7d78a3c32f365db1efb84388430a5d39c4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez=20Jim=C3=A9nez?= Date: Thu, 23 Sep 2021 12:44:44 +0200 Subject: [PATCH] deps: add `pathe` dependency chore: use `pathe` instead `upath` --- package.json | 6 ++++-- src/index.ts | 32 +++++++++++++++++++++++++------- src/locate.test.ts | 6 ++---- yarn.lock | 10 +++++----- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 8ba8eee..dae0012 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.ts b/src/index.ts index 20681d5..c3e3098 100644 --- a/src/index.ts +++ b/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 => { * @return {Promise} */ export const lookupCollections = async(): Promise => { - return JSON.parse(await fs.readFile(`${dir}/collections.json`, 'utf8')) + return JSON.parse(await fs.readFile('./collections.json', 'utf8')) } diff --git a/src/locate.test.ts b/src/locate.test.ts index f4f9c8f..9e1fd0d 100644 --- a/src/locate.test.ts +++ b/src/locate.test.ts @@ -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) }) } diff --git a/yarn.lock b/yarn.lock index faf1bc3..ba01751 100644 --- a/yarn.lock +++ b/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"