Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use pathe #1632

Merged
merged 6 commits into from Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion alias.ts
@@ -1,4 +1,4 @@
import { resolve } from 'path'
import { resolve } from 'pathe'

const r = (p: string) => resolve(__dirname, p)

Expand Down
2 changes: 1 addition & 1 deletion bench/build.mjs
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
import { performance } from 'perf_hooks'
import { join } from 'path'
import { join } from 'pathe'
import fs from 'fs-extra'
import { build } from 'vite'
import { dir, targets } from './meta.mjs'
Expand Down
2 changes: 1 addition & 1 deletion bench/gen.mjs
@@ -1,5 +1,5 @@
import { existsSync, promises as fs } from 'fs'
import { join } from 'path'
import { join } from 'pathe'
import { dir } from './meta.mjs'

const sizes = [
Expand Down
2 changes: 1 addition & 1 deletion bench/meta.mjs
@@ -1,5 +1,5 @@
import { fileURLToPath } from 'url'
import { dirname, resolve } from 'path'
import { dirname, resolve } from 'pathe'
import { getPackageInfo } from 'local-pkg'
import fs from 'fs-extra'

Expand Down
2 changes: 1 addition & 1 deletion bench/run.mjs
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
import { execSync } from 'child_process'
import { join } from 'path'
import { join } from 'pathe'
import fs from 'fs-extra'
import { escapeSelector } from '@unocss/core'
import { dir, getVersions, targets } from './meta.mjs'
Expand Down
2 changes: 1 addition & 1 deletion interactive/scripts/prepare.ts
@@ -1,4 +1,4 @@
import { basename, dirname, parse } from 'path'
import { basename, dirname, parse } from 'pathe'
import fs from 'fs-extra'
import fg from 'fast-glob'
import YAML from 'js-yaml'
Expand Down
1 change: 1 addition & 0 deletions packages/config/package.json
Expand Up @@ -38,6 +38,7 @@
},
"dependencies": {
"@unocss/core": "workspace:*",
"pathe": "^0.3.7",
"unconfig": "^0.3.6"
}
}
2 changes: 1 addition & 1 deletion packages/config/src/index.ts
@@ -1,5 +1,5 @@
import { dirname, resolve } from 'path'
import fs from 'fs'
import { dirname, resolve } from 'pathe'
import type { UserConfig } from '@unocss/core'
import type { LoadConfigResult, LoadConfigSource } from 'unconfig'
import { createConfigLoader as createLoader } from 'unconfig'
Expand Down
2 changes: 1 addition & 1 deletion packages/inspector/node/index.ts
@@ -1,5 +1,5 @@
import { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
import { dirname, resolve } from 'pathe'
import sirv from 'sirv'
import type { Plugin, ViteDevServer } from 'vite'
import type { UnocssPluginContext } from '@unocss/core'
Expand Down
1 change: 1 addition & 0 deletions packages/inspector/package.json
Expand Up @@ -42,6 +42,7 @@
},
"dependencies": {
"gzip-size": "^6.0.0",
"pathe": "^0.3.7",
"sirv": "^2.0.2"
}
}
1 change: 1 addition & 0 deletions packages/nuxt/package.json
Expand Up @@ -53,6 +53,7 @@
"@unocss/reset": "workspace:*",
"@unocss/vite": "workspace:*",
"@unocss/webpack": "workspace:*",
"pathe": "^0.3.7",
"unocss": "workspace:*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/index.ts
@@ -1,5 +1,5 @@
import { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
import { dirname, resolve } from 'pathe'
import { addComponentsDir, addPluginTemplate, defineNuxtModule, extendWebpackConfig } from '@nuxt/kit'
import WebpackPlugin from '@unocss/webpack'
import VitePlugin from '@unocss/vite'
Expand Down
3 changes: 2 additions & 1 deletion packages/preset-uno/package.json
Expand Up @@ -56,6 +56,7 @@
"dependencies": {
"@unocss/core": "workspace:*",
"@unocss/preset-mini": "workspace:*",
"@unocss/preset-wind": "workspace:*"
"@unocss/preset-wind": "workspace:*",
"pathe": "^0.3.7"
}
}
3 changes: 2 additions & 1 deletion packages/preset-web-fonts/package.json
Expand Up @@ -42,6 +42,7 @@
},
"dependencies": {
"@unocss/core": "workspace:*",
"ohmyfetch": "^0.4.18"
"ohmyfetch": "^0.4.18",
"pathe": "^0.3.7"
}
}
3 changes: 2 additions & 1 deletion packages/preset-wind/package.json
Expand Up @@ -40,6 +40,7 @@
},
"dependencies": {
"@unocss/core": "workspace:*",
"@unocss/preset-mini": "workspace:*"
"@unocss/preset-mini": "workspace:*",
"pathe": "^0.3.7"
}
}
3 changes: 2 additions & 1 deletion packages/vite/package.json
Expand Up @@ -53,7 +53,8 @@
"@unocss/inspector": "workspace:*",
"@unocss/scope": "workspace:*",
"@unocss/transformer-directives": "workspace:*",
"magic-string": "^0.26.3"
"magic-string": "^0.26.3",
"pathe": "^0.3.7"
},
"devDependencies": {
"@unocss/shared-integration": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/devtool.ts
@@ -1,6 +1,6 @@
import fs from 'fs'
import { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
import { dirname, resolve } from 'pathe'
import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'
import type { IncomingMessage } from 'connect'
import type { UnocssPluginContext } from '@unocss/core'
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/modes/global/build.ts
@@ -1,4 +1,4 @@
import { resolve } from 'path'
import { resolve } from 'pathe'
import type { Plugin, ResolvedConfig } from 'vite'
import type { GenerateResult, UnocssPluginContext } from '@unocss/core'
import {
Expand Down
1 change: 1 addition & 0 deletions packages/vscode/package.json
Expand Up @@ -75,6 +75,7 @@
"@unocss/preset-uno": "workspace:*",
"esno": "^0.16.3",
"jiti": "^1.15.0",
"pathe": "^0.3.7",
"prettier": "^2.7.1",
"tsup": "^6.2.3",
"unconfig": "^0.3.6"
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode/scripts/publish.ts
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
import { dirname, join } from 'path'
import { fileURLToPath } from 'url'
import { dirname, join } from 'pathe'
import fs from 'fs-extra'
import { execa } from 'execa'

Expand Down
6 changes: 3 additions & 3 deletions packages/vscode/src/annotation.ts
@@ -1,4 +1,4 @@
import path from 'path'
import { dirname, relative } from 'pathe'
import type { DecorationOptions, ExtensionContext, StatusBarItem } from 'vscode'
import { DecorationRangeBehavior, MarkdownString, Range, window, workspace } from 'vscode'
import { INCLUDE_COMMENT_IDE, getMatchedPositionsFromCode, isCssId } from './integration'
Expand Down Expand Up @@ -27,15 +27,15 @@ export async function registerAnnotations(

workspace.onDidSaveTextDocument(async (doc) => {
const id = doc.uri.fsPath
const dir = path.dirname(id)
const dir = dirname(id)

if (contextLoader.contextsMap.has(dir)) {
const ctx = contextLoader.contextsMap.get(dir)!
if (!ctx.getConfigFileList().includes(id))
return
try {
await ctx.reloadConfig()
log.appendLine(`🛠 Config reloaded by ${path.relative(cwd, doc.uri.fsPath)}`)
log.appendLine(`🛠 Config reloaded by ${relative(cwd, doc.uri.fsPath)}`)
}
catch (e) {
log.appendLine('⚠️ Error on loading config')
Expand Down
8 changes: 4 additions & 4 deletions packages/vscode/src/contextLoader.ts
@@ -1,6 +1,6 @@
import { readdir } from 'fs/promises'
import path from 'path'
import fs from 'fs'
import { dirname } from 'pathe'
import type { UnocssPluginContext, UserConfig, UserConfigDefaults } from '@unocss/core'
import { notNull } from '@unocss/core'
import { sourceObjectFields, sourcePluginFactory } from 'unconfig/presets'
Expand Down Expand Up @@ -134,7 +134,7 @@ export class ContextLoader {
if (!sources.length)
return null

const baseDir = path.dirname(sources[0])
const baseDir = dirname(sources[0])
if (baseDir !== dir) {
// exists on upper level, skip
this.contextsMap.set(dir, null)
Expand Down Expand Up @@ -197,7 +197,7 @@ export class ContextLoader {

// try finding a config from disk
if (fs.existsSync(file)) {
let dir = path.dirname(file)
let dir = dirname(file)
while (isSubdir(this.cwd, dir)) {
if (await this.configExists(dir)) {
const context = await this.loadContextInDirectory(dir)
Expand All @@ -207,7 +207,7 @@ export class ContextLoader {
}
}

const newDir = path.dirname(dir)
const newDir = dirname(dir)
if (newDir === dir)
break
dir = newDir
Expand Down
4 changes: 2 additions & 2 deletions packages/vscode/src/index.ts
@@ -1,4 +1,4 @@
import path from 'path'
import { resolve } from 'pathe'
import type { ExtensionContext } from 'vscode'
import { StatusBarAlignment, commands, window, workspace } from 'vscode'
import { version } from '../package.json'
Expand All @@ -24,7 +24,7 @@ export async function activate(ext: ExtensionContext) {
}

const root = config.get<string>('root')
const cwd = root ? path.resolve(projectPath, root) : projectPath
const cwd = root ? resolve(projectPath, root) : projectPath

const contextLoader = new ContextLoader(cwd)

Expand Down
6 changes: 3 additions & 3 deletions packages/vscode/src/utils.ts
@@ -1,4 +1,4 @@
import path from 'path'
import { isAbsolute, relative } from 'pathe'
import type { GenerateResult, UnoGenerator } from '@unocss/core'
import prettier from 'prettier/standalone'
import parserCSS from 'prettier/parser-postcss'
Expand Down Expand Up @@ -94,6 +94,6 @@ export function getColorsMap(uno: UnoGenerator, result: GenerateResult) {
}

export function isSubdir(parent: string, child: string) {
const relative = path.relative(parent, child)
return relative && !relative.startsWith('..') && !path.isAbsolute(relative)
const relativePath = relative(parent, child)
return relativePath && !relativePath.startsWith('..') && !isAbsolute(relativePath)
}
1 change: 1 addition & 0 deletions packages/webpack/package.json
Expand Up @@ -45,6 +45,7 @@
"@unocss/config": "workspace:*",
"@unocss/core": "workspace:*",
"magic-string": "^0.26.3",
"pathe": "^0.3.7",
"unplugin": "^0.9.5",
"webpack-sources": "^3.2.3"
},
Expand Down
24 changes: 22 additions & 2 deletions pnpm-lock.yaml

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