Skip to content

Commit

Permalink
move from ascii encoding to utf8 (#14)
Browse files Browse the repository at this point in the history
* move `ascii` encoding to `utf8`

* update lockfile
  • Loading branch information
JensDll authored Nov 18, 2022
1 parent dbb5a77 commit c2a0f45
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 43 deletions.
7 changes: 4 additions & 3 deletions packages/shared/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import fs from 'fs'

import type {
ExtendedIconifyIcon,
IconifyDimenisons as IconifyDimensions,
Expand All @@ -20,9 +22,8 @@ export function toKebabCase(str: string): string {
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()
}

export function isPromise<T>(value: Awaitable<T>): value is Promise<T> {
// @ts-expect-error
return typeof value?.then === 'function'
export function readJson(path: string) {
return JSON.parse(fs.readFileSync(path, 'utf8'))
}

export function isUri(str: string | undefined): str is string {
Expand Down
8 changes: 4 additions & 4 deletions packages/tailwindcss-plugin-icons/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs'
import path from 'path'

import type { IconifyJSON } from '@iconify/types'
import { uriToFilename } from '@internal/shared'
import { readJson, uriToFilename } from '@internal/shared'

export class IconifyFileCache implements Map<string, IconifyJSON> {
readonly cacheDir: string
Expand Down Expand Up @@ -61,7 +61,7 @@ export class IconifyFileCache implements Map<string, IconifyJSON> {
return
}

return JSON.parse(fs.readFileSync(filePath, 'ascii'))
return readJson(filePath)
}

set(key: string, iconifyJson: IconifyJSON) {
Expand Down Expand Up @@ -94,15 +94,15 @@ export class IconifyFileCache implements Map<string, IconifyJSON> {
const files = fs.readdirSync(this.cacheDir)
for (const file of files) {
const filePath = path.resolve(this.cacheDir, file)
yield JSON.parse(fs.readFileSync(filePath, 'ascii'))
yield readJson(filePath)
}
}

*[Symbol.iterator](): IterableIterator<[string, IconifyJSON]> {
const files = fs.readdirSync(this.cacheDir)
for (const file of files) {
const filePath = path.resolve(this.cacheDir, file)
yield [file, JSON.parse(fs.readFileSync(filePath, 'ascii'))]
yield [file, readJson(filePath)]
}
}

Expand Down
7 changes: 4 additions & 3 deletions packages/tailwindcss-plugin-icons/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
isUri,
loadIconFromIconifyJson,
toKebabCase,
readJson,
type WithRequired
} from '@internal/shared'
import flattenColorPalette from 'tailwindcss/lib/util/flattenColorPalette'
Expand Down Expand Up @@ -61,7 +62,7 @@ function resolveIconSets(
callback(
kebabCaseIconSetName,
iconSetOptions as IconSetOptionsWithIcons,
JSON.parse(fs.readFileSync(jsonPath, 'ascii'))
readJson(jsonPath)
)
continue
} catch (e) {
Expand All @@ -79,7 +80,7 @@ function resolveIconSets(
callback(
kebabCaseIconSetName,
iconSetOptions as IconSetOptionsWithIcons,
JSON.parse(fs.readFileSync(jsonPath, 'ascii'))
readJson(jsonPath)
)
continue
} catch (e) {
Expand Down Expand Up @@ -134,7 +135,7 @@ function resolveIconSets(
callback(
kebabCaseIconSetName,
iconSetOptions as IconSetOptionsWithIcons,
JSON.parse(fs.readFileSync(resolvedLocation, 'ascii'))
readJson(resolvedLocation)
)

continue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"info": {
"name": "💯🔥"
},
"icons": {
"icon": {
"body": ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"info": {
"name": "💯🔥"
},
"icons": {
"icon": {
"body": ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"info": {
"name": "💯🔥"
},
"icons": {
"colored": {
"body": "<path d=\"1\" fill=\"#fff\"/>"
Expand Down
6 changes: 2 additions & 4 deletions packages/tailwindcss-plugin-icons/tests/cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import os from 'node:os'
import path from 'node:path'

import type { IconifyJSON } from '@iconify/types'
import { readJson } from '@internal/shared'
import fs from 'fs-extra'

import { IconifyFileCache } from '~tailwindcss-plugin-icons/cache'

const readFixture = (fixture: string) =>
[
fixture,
fs.readJSONSync(path.resolve(__dirname, '__fixtures__', fixture), 'ascii')
] as const
[fixture, readJson(path.resolve(__dirname, '__fixtures__', fixture))] as const

const readFixtures = (fixtures?: string[]) =>
(fixtures === undefined ? ['cache1.json', 'cache2.json'] : fixtures).map(
Expand Down
16 changes: 0 additions & 16 deletions playground/vue/README.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
plugins: {
'tailwindcss/nesting': {},
tailwindcss: {},
autoprefixer: {}
}
}
module.exports = {
plugins: {
'tailwindcss/nesting': {},
tailwindcss: {},
autoprefixer: {}
}
}
File renamed without changes.
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions scripts/rollup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import path from 'node:path'

import type { Alias, ResolverFunction } from '@rollup/plugin-alias'
import alias from '@rollup/plugin-alias'
import alias, { type Alias, type ResolverFunction } from '@rollup/plugin-alias'
import fs from 'fs-extra'

import { rootDir } from './utils'
Expand Down

0 comments on commit c2a0f45

Please sign in to comment.