Skip to content

Commit 49de961

Browse files
authored
Merge pull request #263 from 4513ECHO/optimize_std_import
💪 Optimize imports from std
2 parents 8cd0dc0 + 8e5e471 commit 49de961

File tree

14 files changed

+35
-32
lines changed

14 files changed

+35
-32
lines changed

.scripts/gen-function/gen-function.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as path from "@std/path";
1+
import { fromFileUrl } from "@std/path/from-file-url";
22
import { parse } from "./parse.ts";
33
import { format } from "./format.ts";
44
import { DOCS_OVERRIDES } from "./override.ts";
@@ -103,5 +103,5 @@ await transform(resolvePath(vimManualModule), vimDefs);
103103
await transform(resolvePath(nvimManualModule), nvimDefs);
104104

105105
function resolvePath(p: string): string {
106-
return path.fromFileUrl(new URL(p, import.meta.url));
106+
return fromFileUrl(new URL(p, import.meta.url));
107107
}

.scripts/gen-option/gen-option.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as path from "@std/path";
1+
import { fromFileUrl } from "@std/path/from-file-url";
22
import { parse } from "./parse.ts";
33
import { format } from "./format.ts";
44
import { DOCS_OVERRIDES } from "./override.ts";
@@ -98,5 +98,5 @@ await transform(resolvePath(vimManualModule), vimDefs);
9898
await transform(resolvePath(nvimManualModule), nvimDefs);
9999

100100
function resolvePath(p: string): string {
101-
return path.fromFileUrl(new URL(p, import.meta.url));
101+
return fromFileUrl(new URL(p, import.meta.url));
102102
}

.scripts/transform.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { fromFileUrl, toFileUrl } from "@std/path";
1+
import { fromFileUrl } from "@std/path/from-file-url";
2+
import { toFileUrl } from "@std/path/to-file-url";
23

34
interface ModuleInformation {
45
sourcePath: string;

.scripts/utils.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as streams from "@std/streams";
1+
import { toText } from "@std/streams/to-text";
22

33
/**
44
* Downloads a text file and returns the contents.
@@ -9,8 +9,7 @@ export async function downloadString(url: string): Promise<string> {
99
if (response.status >= 400 || !response.body) {
1010
throw new Error(`Failed to read ${url}`);
1111
}
12-
//const reader = streams.readerFromStreamReader(response.body.getReader());
13-
return await streams.toText(response.body);
12+
return await toText(response.body);
1413
}
1514

1615
/**

buffer/buffer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Denops } from "@denops/core";
22
import { maybe } from "@core/unknownutil/maybe";
3-
import { ulid } from "@std/ulid";
3+
import { ulid } from "@std/ulid/ulid";
44
import * as autocmd from "../autocmd/mod.ts";
55
import * as batch from "../batch/mod.ts";
66
import * as fn from "../function/mod.ts";

bufname/bufname.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ const exprPattern = /^(.*?)(?:;(.*?))?(?:#(.*))?$/;
139139
*
140140
* ```typescript
141141
* import { assertEquals } from "jsr:@std/assert";
142-
* import * as path from "jsr:@std/path";
142+
* import { toFileUrl } from "jsr:@std/path/to-file-url";
143143
* import { format } from "jsr:@denops/std/bufname";
144144
*
145145
* // NOTE:
146146
* // Works only on Windows (Use path.win32.toFileUrl instead on other platforms)
147147
* assertEquals(
148148
* format({
149149
* scheme: "denops",
150-
* expr: path.toFileUrl("C:\\Users\John Titor\test.git").pathname,
150+
* expr:toFileUrl("C:\\Users\John Titor\test.git").pathname,
151151
* }),
152152
* "denops:///C:/Users/John%2520Titor/test.git",
153153
* );
@@ -233,7 +233,7 @@ export function format(
233233
*
234234
* ```typescript
235235
* import { assertEquals } from "jsr:@std/assert";
236-
* import * as path from "jsr:@std/path";
236+
* import { fromFileUrl } from "jsr:@std/path/from-file-url";
237237
* import { parse } from "jsr:@denops/std/bufname";
238238
*
239239
* const bufname = parse("denops:///C:/Users/John%2520Titor/test.git");
@@ -244,7 +244,7 @@ export function format(
244244
* // NOTE:
245245
* // Works only on Windows (Use path.win32.fromFileUrl instead on other platforms)
246246
* assertEquals(
247-
* path.fromFileUrl(`file://${bufname.expr}`),
247+
* fromFileUrl(`file://${bufname.expr}`),
248248
* "C:\\Users\\John Titor\\test.git",
249249
* );
250250
* ```

bufname/bufname_test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { assertEquals, assertThrows } from "@std/assert";
2-
import * as pathWin from "@std/path/windows";
2+
import { fromFileUrl } from "@std/path/windows/from-file-url";
3+
import { toFileUrl } from "@std/path/windows/to-file-url";
34
import { format, parse } from "./bufname.ts";
45

56
Deno.test("format throws exception when 'scheme' contains unusable characters", () => {
@@ -188,7 +189,7 @@ Deno.test("format pass example in README.md", () => {
188189
"denops:///Users/John Titor/test.git;foo=foo&bar=bar1&bar=bar2#README.md",
189190
);
190191

191-
const fileUrl = pathWin.toFileUrl("C:\\Users\\John Titor\\test.git");
192+
const fileUrl = toFileUrl("C:\\Users\\John Titor\\test.git");
192193
assertEquals(
193194
fileUrl.pathname,
194195
"/C:/Users/John%20Titor/test.git",
@@ -407,7 +408,7 @@ Deno.test("parse pass example in README.md", () => {
407408
},
408409
);
409410
assertEquals(
410-
pathWin.fromFileUrl(`file://${bufname.expr}`),
411+
fromFileUrl(`file://${bufname.expr}`),
411412
"C:\\Users\\John Titor\\test.git",
412413
);
413414
});

deno.jsonc

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"@std/path": "jsr:@std/path@^1.0.2",
5959
"@std/semver": "jsr:@std/semver@^1.0.0",
6060
"@std/streams": "jsr:@std/streams@^1.0.0",
61-
"@std/testing": "jsr:@std/testing@^1.0.0-rc.5",
61+
"@std/testing": "jsr:@std/testing@^1.0.1",
6262
"@std/ulid": "jsr:@std/ulid@^1.0.0",
6363
"encoding-japanese": "npm:encoding-japanese@^2.1.0",
6464
"jsr:@denops/std": "./mod.ts",

function/getreginfo.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Denops } from "../mod.ts";
2-
import { lessThan, parse } from "@std/semver";
3-
import { ulid } from "@std/ulid";
2+
import { lessThan } from "@std/semver/less-than";
3+
import { parse } from "@std/semver/parse";
4+
import { ulid } from "@std/ulid/ulid";
45
import { execute } from "../helper/mod.ts";
56

67
const cacheKey = "denops_std/function/getreginfo.ts@1";

helper/echo.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Denops } from "@denops/core";
2-
import { ulid } from "@std/ulid";
2+
import { ulid } from "@std/ulid/ulid";
33
import { execute } from "./execute.ts";
44

55
const cacheKey = "denops_std/helper/echo@1";

helper/expr_string.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { isRecord } from "@core/unknownutil/is/record";
3939
import { isString } from "@core/unknownutil/is/string";
4040
import { isSymbol } from "@core/unknownutil/is/symbol";
4141
import { isUndefined } from "@core/unknownutil/is/undefined";
42-
import { ulid } from "@std/ulid";
42+
import { ulid } from "@std/ulid/ulid";
4343
import { execute } from "./execute.ts";
4444

4545
const EXPR_STRING_MARK = "__denops_expr_string";

helper/input.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Denops } from "@denops/core";
22
import { assert } from "@core/unknownutil/assert";
33
import { isNumber } from "@core/unknownutil/is/number";
44
import { isString } from "@core/unknownutil/is/string";
5-
import { ulid } from "@std/ulid";
5+
import { ulid } from "@std/ulid/ulid";
66
import * as fn from "../function/mod.ts";
77
import * as lambda from "../lambda/mod.ts";
88
import { execute } from "./execute.ts";

helper/load.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
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";
46
import { execute } from "./execute.ts";
57

68
const loaded = new Set<URL>();
@@ -101,12 +103,12 @@ export async function load(
101103

102104
async function ensureLocalFile(url: URL): Promise<string> {
103105
if (url.protocol === "file:") {
104-
return path.fromFileUrl(url);
106+
return fromFileUrl(url);
105107
}
106108
const cacheDir = await getOrCreateCacheDir();
107109
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)) {
110112
return filepath;
111113
}
112114
const response = await fetch(url);
@@ -131,8 +133,7 @@ async function getLocalFilename(url: URL): Promise<string> {
131133
const h = Array.from(new Uint8Array(buf))
132134
.map((b) => b.toString(16).padStart(2, "0"))
133135
.join("");
134-
const basename = path.basename(url.pathname);
135-
return `${h}-${basename}`;
136+
return `${h}-${basename(url.pathname)}`;
136137
}
137138

138139
async function getOrCreateCacheDir(): Promise<string> {
@@ -148,13 +149,13 @@ function getCacheDirUnix(): string {
148149
if (!root) {
149150
throw new Error("`HOME` environment variable is not defined.");
150151
}
151-
return path.join(root, ".cache", "denops_std", "load");
152+
return join(root, ".cache", "denops_std", "load");
152153
}
153154

154155
function getCacheDirWindows(): string {
155156
const root = Deno.env.get("LOCALAPPDATA");
156157
if (!root) {
157158
throw new Error("`LOCALAPPDATA` environment variable is not defined.");
158159
}
159-
return path.join(root, "denops_std", "load");
160+
return join(root, "denops_std", "load");
160161
}

popup/nvim.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Denops } from "@denops/core";
2-
import { ulid } from "@std/ulid";
2+
import { ulid } from "@std/ulid/ulid";
33
import * as nvimFn from "../function/nvim/mod.ts";
44
import { execute } from "../helper/execute.ts";
55

0 commit comments

Comments
 (0)