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

revert: deprecate pathe #1654

Merged
merged 2 commits into from
Sep 28, 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'pathe'
import { resolve } from 'path'

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

Expand Down
2 changes: 1 addition & 1 deletion bench/build.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
import { performance } from 'perf_hooks'
import { join } from 'pathe'
import { join } from 'path'
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { existsSync, promises as fs } from 'fs'
import { join } from 'pathe'
import { join } from 'path'
import { dir } from './meta.mjs'

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

Expand Down
2 changes: 1 addition & 1 deletion bench/run.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
import { execSync } from 'child_process'
import { join } from 'pathe'
import { join } from 'path'
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { basename, dirname, parse } from 'pathe'
import { basename, dirname, parse } from 'path'
import fs from 'fs-extra'
import fg from 'fast-glob'
import YAML from 'js-yaml'
Expand Down
1 change: 0 additions & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
},
"dependencies": {
"@unocss/core": "workspace:*",
"pathe": "^0.3.7",
"unconfig": "^0.3.6"
}
}
2 changes: 1 addition & 1 deletion packages/config/src/index.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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: 0 additions & 1 deletion packages/inspector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
},
"dependencies": {
"gzip-size": "^6.0.0",
"pathe": "^0.3.7",
"sirv": "^2.0.2"
}
}
1 change: 0 additions & 1 deletion packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"@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
Original file line number Diff line number Diff line change
@@ -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: 1 addition & 2 deletions packages/preset-uno/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"dependencies": {
"@unocss/core": "workspace:*",
"@unocss/preset-mini": "workspace:*",
"@unocss/preset-wind": "workspace:*",
"pathe": "^0.3.7"
"@unocss/preset-wind": "workspace:*"
}
}
3 changes: 1 addition & 2 deletions packages/preset-web-fonts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
},
"dependencies": {
"@unocss/core": "workspace:*",
"ohmyfetch": "^0.4.18",
"pathe": "^0.3.7"
"ohmyfetch": "^0.4.18"
}
}
3 changes: 1 addition & 2 deletions packages/preset-wind/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
},
"dependencies": {
"@unocss/core": "workspace:*",
"@unocss/preset-mini": "workspace:*",
"pathe": "^0.3.7"
"@unocss/preset-mini": "workspace:*"
}
}
3 changes: 1 addition & 2 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@
"@unocss/inspector": "workspace:*",
"@unocss/scope": "workspace:*",
"@unocss/transformer-directives": "workspace:*",
"magic-string": "^0.26.3",
"pathe": "^0.3.7"
"magic-string": "^0.26.3"
},
"devDependencies": {
"@unocss/shared-integration": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/devtool.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'pathe'
import { resolve } from 'path'
import type { Plugin, ResolvedConfig } from 'vite'
import type { GenerateResult, UnocssPluginContext } from '@unocss/core'
import {
Expand Down
1 change: 0 additions & 1 deletion packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"@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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dirname, relative } from 'pathe'
import path from 'path'
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 = dirname(id)
const dir = path.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 ${relative(cwd, doc.uri.fsPath)}`)
log.appendLine(`🛠 Config reloaded by ${path.relative(cwd, doc.uri.fsPath)}`)
}
catch (e) {
log.appendLine('⚠️ Error on loading config')
Expand Down
11 changes: 5 additions & 6 deletions packages/vscode/src/contextLoader.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
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'
import presetUno from '@unocss/preset-uno'
import { normalizePath } from 'vite'
import { resolveOptions as resolveNuxtOptions } from '../../nuxt/src/options'
import { createNanoEvents } from '../../core/src/utils/events'
import { createContext, isCssId } from './integration'
Expand Down Expand Up @@ -135,8 +134,8 @@ export class ContextLoader {
if (!sources.length)
return null

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

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

const newDir = dirname(dir)
const newDir = path.dirname(dir)
if (newDir === dir)
break
dir = newDir
Expand Down
4 changes: 2 additions & 2 deletions packages/vscode/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'pathe'
import path from 'path'
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 ? resolve(projectPath, root) : projectPath
const cwd = root ? path.resolve(projectPath, root) : projectPath

const contextLoader = new ContextLoader(cwd)

Expand Down
6 changes: 3 additions & 3 deletions packages/vscode/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isAbsolute, relative } from 'pathe'
import path from 'path'
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 relativePath = relative(parent, child)
return relativePath && !relativePath.startsWith('..') && !isAbsolute(relativePath)
const relative = path.relative(parent, child)
return relative && !relative.startsWith('..') && !path.isAbsolute(relative)
}
1 change: 0 additions & 1 deletion packages/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"@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