1
1
import type { Denops } from "@denops/core" ;
2
- import * as fs from "@std/fs" ;
3
- import * as path from "@std/path" ;
2
+ import { exists } from "@std/fs/exists" ;
3
+ import { basename } from "@std/path/basename" ;
4
+ import { fromFileUrl } from "@std/path/from-file-url" ;
5
+ import { join } from "@std/path/join" ;
4
6
import { execute } from "./execute.ts" ;
5
7
6
8
const loaded = new Set < URL > ( ) ;
@@ -101,12 +103,12 @@ export async function load(
101
103
102
104
async function ensureLocalFile ( url : URL ) : Promise < string > {
103
105
if ( url . protocol === "file:" ) {
104
- return path . fromFileUrl ( url ) ;
106
+ return fromFileUrl ( url ) ;
105
107
}
106
108
const cacheDir = await getOrCreateCacheDir ( ) ;
107
109
const filename = await getLocalFilename ( url ) ;
108
- const filepath = path . join ( cacheDir , filename ) ;
109
- if ( await fs . exists ( filepath ) ) {
110
+ const filepath = join ( cacheDir , filename ) ;
111
+ if ( await exists ( filepath ) ) {
110
112
return filepath ;
111
113
}
112
114
const response = await fetch ( url ) ;
@@ -131,8 +133,7 @@ async function getLocalFilename(url: URL): Promise<string> {
131
133
const h = Array . from ( new Uint8Array ( buf ) )
132
134
. map ( ( b ) => b . toString ( 16 ) . padStart ( 2 , "0" ) )
133
135
. join ( "" ) ;
134
- const basename = path . basename ( url . pathname ) ;
135
- return `${ h } -${ basename } ` ;
136
+ return `${ h } -${ basename ( url . pathname ) } ` ;
136
137
}
137
138
138
139
async function getOrCreateCacheDir ( ) : Promise < string > {
@@ -148,13 +149,13 @@ function getCacheDirUnix(): string {
148
149
if ( ! root ) {
149
150
throw new Error ( "`HOME` environment variable is not defined." ) ;
150
151
}
151
- return path . join ( root , ".cache" , "denops_std" , "load" ) ;
152
+ return join ( root , ".cache" , "denops_std" , "load" ) ;
152
153
}
153
154
154
155
function getCacheDirWindows ( ) : string {
155
156
const root = Deno . env . get ( "LOCALAPPDATA" ) ;
156
157
if ( ! root ) {
157
158
throw new Error ( "`LOCALAPPDATA` environment variable is not defined." ) ;
158
159
}
159
- return path . join ( root , "denops_std" , "load" ) ;
160
+ return join ( root , "denops_std" , "load" ) ;
160
161
}
0 commit comments