mirror of
https://github.com/denoland/deno.git
synced 2025-09-28 21:24:48 +00:00
lint: add max line length rules (denoland/deno_std#507)
Original: b04fda30c8
This commit is contained in:
parent
d6e92582cc
commit
c85b1c06a9
39 changed files with 262 additions and 129 deletions
|
@ -18,6 +18,19 @@
|
||||||
"@typescript-eslint/no-unused-vars": [
|
"@typescript-eslint/no-unused-vars": [
|
||||||
"error",
|
"error",
|
||||||
{ "argsIgnorePattern": "^_", "varsIgnorePattern": "_" }
|
{ "argsIgnorePattern": "^_", "varsIgnorePattern": "_" }
|
||||||
|
],
|
||||||
|
"max-len": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"code": 80,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"comments": 80,
|
||||||
|
"ignoreTrailingComments": false,
|
||||||
|
"ignoreUrls": true,
|
||||||
|
"ignoreStrings": false,
|
||||||
|
"ignoreTemplateLiterals": false,
|
||||||
|
"ignoreRegExpLiterals": false
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Ported and modified from: https://github.com/jshttp/mime-types and licensed as:
|
* Ported and modified from: https://github.com/jshttp/mime-types and
|
||||||
|
* licensed as:
|
||||||
*
|
*
|
||||||
* (The MIT License)
|
* (The MIT License)
|
||||||
*
|
*
|
||||||
|
@ -292,7 +293,8 @@ export class Tar {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a file to this tar archive
|
* Append a file to this tar archive
|
||||||
* @param fileName file name (e.g., test.txt; use slash for directory separators)
|
* @param fileName file name
|
||||||
|
* e.g., test.txt; use slash for directory separators
|
||||||
* @param opts options
|
* @param opts options
|
||||||
*/
|
*/
|
||||||
async append(fileName: string, opts: TarOptions): Promise<void> {
|
async append(fileName: string, opts: TarOptions): Promise<void> {
|
||||||
|
@ -314,7 +316,8 @@ export class Tar {
|
||||||
}
|
}
|
||||||
if (i < 0 || fileName.length > 100 || fileNamePrefix!.length > 155) {
|
if (i < 0 || fileName.length > 100 || fileNamePrefix!.length > 155) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"ustar format does not allow a long file name (length of [file name prefix] + / + [file name] must be shorter than 256 bytes)"
|
"ustar format does not allow a long file name (length of [file name" +
|
||||||
|
"prefix] + / + [file name] must be shorter than 256 bytes)"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,10 @@ test(async function createTarArchive(): Promise<void> {
|
||||||
const writer = new Deno.Buffer(),
|
const writer = new Deno.Buffer(),
|
||||||
wrote = await Deno.copy(writer, tar.getReader());
|
wrote = await Deno.copy(writer, tar.getReader());
|
||||||
|
|
||||||
// 3072 = 512 (header) + 512 (content) + 512 (header) + 512 (content) + 1024 (footer)
|
/**
|
||||||
|
* 3072 = 512 (header) + 512 (content) + 512 (header) + 512 (content)
|
||||||
|
* + 1024 (footer)
|
||||||
|
*/
|
||||||
assertEquals(wrote, 3072);
|
assertEquals(wrote, 3072);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,8 @@ declare global {
|
||||||
var __results: [string, string] | undefined;
|
var __results: [string, string] | undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* eslint-disable max-len */
|
||||||
/* eslint-enable @typescript-eslint/no-namespace */
|
/* eslint-enable @typescript-eslint/no-namespace */
|
||||||
|
|
||||||
const fixture = `
|
const fixture = `
|
||||||
define("data", [], { "baz": "qat" });
|
define("data", [], { "baz": "qat" });
|
||||||
define("modB", ["require", "exports", "data"], function(require, exports, data) {
|
define("modB", ["require", "exports", "data"], function(require, exports, data) {
|
||||||
|
@ -32,6 +32,7 @@ define("modA", ["require", "exports", "modB"], function(require, exports, modB)
|
||||||
globalThis.__results = [modB.foo, modB.baz];
|
globalThis.__results = [modB.foo, modB.baz];
|
||||||
});
|
});
|
||||||
`;
|
`;
|
||||||
|
/* eslint-enable max-len */
|
||||||
|
|
||||||
const fixtureQueue = ["data", "modB", "modA"];
|
const fixtureQueue = ["data", "modB", "modA"];
|
||||||
const fixtureModules = new Map<string, ModuleMetaData>();
|
const fixtureModules = new Map<string, ModuleMetaData>();
|
||||||
|
|
|
@ -21,11 +21,12 @@ export class ParseError extends Error {
|
||||||
/**
|
/**
|
||||||
* @property comma - Character which separates values. Default: ','
|
* @property comma - Character which separates values. Default: ','
|
||||||
* @property comment - Character to start a comment. Default: '#'
|
* @property comment - Character to start a comment. Default: '#'
|
||||||
* @property trimLeadingSpace - Flag to trim the leading space of the value. Default: 'false'
|
* @property trimLeadingSpace - Flag to trim the leading space of the value.
|
||||||
|
* Default: 'false'
|
||||||
* @property lazyQuotes - Allow unquoted quote in a quoted field or non double
|
* @property lazyQuotes - Allow unquoted quote in a quoted field or non double
|
||||||
* quoted quotes in quoted field Default: 'false'
|
* quoted quotes in quoted field Default: 'false'
|
||||||
* @property fieldsPerRecord - Enabling the check of fields for each row. If == 0
|
* @property fieldsPerRecord - Enabling the check of fields for each row.
|
||||||
* first row is used as referal for the number of fields.
|
* If == 0, first row is used as referal for the number of fields.
|
||||||
*/
|
*/
|
||||||
export interface ParseOptions {
|
export interface ParseOptions {
|
||||||
comma?: string;
|
comma?: string;
|
||||||
|
|
|
@ -129,7 +129,7 @@ const testCases = [
|
||||||
Name: "BadBareQuote",
|
Name: "BadBareQuote",
|
||||||
Input: `a "word","b"`,
|
Input: `a "word","b"`,
|
||||||
Error: ErrBareQuote
|
Error: ErrBareQuote
|
||||||
// Error: true //&ParseError{StartLine: 1, Line: 1, Column: 2, Err: ErrBareQuote},
|
// &ParseError{StartLine: 1, Line: 1, Column: 2, Err: ErrBareQuote}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "BadTrailingQuote",
|
Name: "BadTrailingQuote",
|
||||||
|
@ -151,7 +151,7 @@ const testCases = [
|
||||||
{
|
{
|
||||||
Name: "BadFieldCount1",
|
Name: "BadFieldCount1",
|
||||||
Input: `a,b,c`,
|
Input: `a,b,c`,
|
||||||
// Error: &ParseError{StartLine: 1, Line: 1, Err: ErrFieldCount},
|
// Error: &ParseError{StartLine: 1, Line: 1, Err: ErrFieldCount},
|
||||||
UseFieldsPerRecord: true,
|
UseFieldsPerRecord: true,
|
||||||
FieldsPerRecord: 2,
|
FieldsPerRecord: 2,
|
||||||
Error: ErrFieldCount
|
Error: ErrFieldCount
|
||||||
|
@ -298,7 +298,11 @@ x,,,
|
||||||
// {
|
// {
|
||||||
// Name: "MultiFieldCRCRLFCRCR",
|
// Name: "MultiFieldCRCRLFCRCR",
|
||||||
// Input: "field1,field2\r\r\n\r\rfield1,field2\r\r\n\r\r,",
|
// Input: "field1,field2\r\r\n\r\rfield1,field2\r\r\n\r\r,",
|
||||||
// Output: [["field1", "field2\r"], ["\r\rfield1", "field2\r"], ["\r\r", ""]]
|
// Output: [
|
||||||
|
// ["field1", "field2\r"],
|
||||||
|
// ["\r\rfield1", "field2\r"],
|
||||||
|
// ["\r\r", ""]
|
||||||
|
// ]
|
||||||
// },
|
// },
|
||||||
{
|
{
|
||||||
Name: "NonASCIICommaAndComment",
|
Name: "NonASCIICommaAndComment",
|
||||||
|
@ -339,13 +343,20 @@ x,,,
|
||||||
// Name: "MultipleCRLF",
|
// Name: "MultipleCRLF",
|
||||||
// Input: "\r\n\r\n\r\n\r\n"
|
// Input: "\r\n\r\n\r\n\r\n"
|
||||||
// },
|
// },
|
||||||
// {
|
/**
|
||||||
// // The implementation may read each line in several chunks if it doesn't fit entirely
|
* The implementation may read each line in several chunks if
|
||||||
// // in the read buffer, so we should test the code to handle that condition.
|
* it doesn't fit entirely.
|
||||||
// Name: "HugeLines",
|
* in the read buffer, so we should test the code to handle that condition.
|
||||||
// Input: strings.Repeat("#ignore\n", 10000) + strings.Repeat("@", 5000) + "," + strings.Repeat("*", 5000),
|
*/
|
||||||
// Output: [[strings.Repeat("@", 5000), strings.Repeat("*", 5000)]],
|
// {
|
||||||
// Comment: '#',
|
// Name: "HugeLines",
|
||||||
|
// Input:
|
||||||
|
// strings.Repeat("#ignore\n", 10000) +
|
||||||
|
// strings.Repeat("@", 5000) +
|
||||||
|
// "," +
|
||||||
|
// strings.Repeat("*", 5000),
|
||||||
|
// Output: [[strings.Repeat("@", 5000), strings.Repeat("*", 5000)]],
|
||||||
|
// Comment: "#"
|
||||||
// },
|
// },
|
||||||
{
|
{
|
||||||
Name: "QuoteWithTrailingCRLF",
|
Name: "QuoteWithTrailingCRLF",
|
||||||
|
|
|
@ -32,7 +32,8 @@ function fromHexChar(byte: number): [number, boolean] {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EncodedLen returns the length of an encoding of n source bytes. Specifically, it returns n * 2.
|
* EncodedLen returns the length of an encoding of n source bytes. Specifically,
|
||||||
|
* it returns n * 2.
|
||||||
* @param n
|
* @param n
|
||||||
*/
|
*/
|
||||||
export function encodedLen(n: number): number {
|
export function encodedLen(n: number): number {
|
||||||
|
@ -73,8 +74,10 @@ export function encodeToString(src: Uint8Array): string {
|
||||||
/**
|
/**
|
||||||
* Decode decodes `src` into `decodedLen(src.length)` bytes
|
* Decode decodes `src` into `decodedLen(src.length)` bytes
|
||||||
* returning the actual number of bytes written to `dst`.
|
* returning the actual number of bytes written to `dst`.
|
||||||
* Decode expects that `src` contains only hexadecimal characters and that `src` has even length.
|
* Decode expects that `src` contains only hexadecimal characters and that `src`
|
||||||
* If the input is malformed, Decode returns the number of bytes decoded before the error.
|
* has even length.
|
||||||
|
* If the input is malformed, Decode returns the number of bytes decoded before
|
||||||
|
* the error.
|
||||||
* @param dst
|
* @param dst
|
||||||
* @param src
|
* @param src
|
||||||
*/
|
*/
|
||||||
|
@ -110,7 +113,8 @@ export function decode(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DecodedLen returns the length of a decoding of `x` source bytes. Specifically, it returns `x / 2`.
|
* DecodedLen returns the length of a decoding of `x` source bytes.
|
||||||
|
* Specifically, it returns `x / 2`.
|
||||||
* @param x
|
* @param x
|
||||||
*/
|
*/
|
||||||
export function decodedLen(x: number): number {
|
export function decodedLen(x: number): number {
|
||||||
|
@ -119,14 +123,16 @@ export function decodedLen(x: number): number {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DecodeString returns the bytes represented by the hexadecimal string `s`.
|
* DecodeString returns the bytes represented by the hexadecimal string `s`.
|
||||||
* DecodeString expects that src contains only hexadecimal characters and that src has even length.
|
* DecodeString expects that src contains only hexadecimal characters and that
|
||||||
|
* src has even length.
|
||||||
* If the input is malformed, DecodeString will throws an error.
|
* If the input is malformed, DecodeString will throws an error.
|
||||||
* @param s the `string` need to decode to `Uint8Array`
|
* @param s the `string` need to decode to `Uint8Array`
|
||||||
*/
|
*/
|
||||||
export function decodeString(s: string): Uint8Array {
|
export function decodeString(s: string): Uint8Array {
|
||||||
const src = new TextEncoder().encode(s);
|
const src = new TextEncoder().encode(s);
|
||||||
// We can use the source slice itself as the destination
|
// We can use the source slice itself as the destination
|
||||||
// because the decode loop increments by one and then the 'seen' byte is not used anymore.
|
// because the decode loop increments by one and then the 'seen' byte is not
|
||||||
|
// used anymore.
|
||||||
const [n, err] = decode(src, src);
|
const [n, err] = decode(src, src);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
@ -507,8 +507,9 @@ class Dumper {
|
||||||
const min = dtPad(value.getUTCMinutes().toString());
|
const min = dtPad(value.getUTCMinutes().toString());
|
||||||
const s = dtPad(value.getUTCSeconds().toString());
|
const s = dtPad(value.getUTCSeconds().toString());
|
||||||
const ms = dtPad(value.getUTCMilliseconds().toString(), 3);
|
const ms = dtPad(value.getUTCMilliseconds().toString(), 3);
|
||||||
const fmtDate = `${value.getUTCFullYear()}-${m}-${d}T${h}:${min}:${s}.${ms}`;
|
// formated date
|
||||||
return `${this._declaration(title)}${fmtDate}`;
|
const fData = `${value.getUTCFullYear()}-${m}-${d}T${h}:${min}:${s}.${ms}`;
|
||||||
|
return `${this._declaration(title)}${fData}`;
|
||||||
}
|
}
|
||||||
_format(): string[] {
|
_format(): string[] {
|
||||||
const rDeclaration = /(.*)\s=/;
|
const rDeclaration = /(.*)\s=/;
|
||||||
|
|
|
@ -29,7 +29,8 @@ test({
|
||||||
str5: "The quick brown\nfox jumps over\nthe lazy dog.",
|
str5: "The quick brown\nfox jumps over\nthe lazy dog.",
|
||||||
str6: "The quick brown\nfox jumps over\nthe lazy dog.",
|
str6: "The quick brown\nfox jumps over\nthe lazy dog.",
|
||||||
lines:
|
lines:
|
||||||
"The first newline is\ntrimmed in raw strings.\n All other whitespace\n is preserved."
|
"The first newline is\ntrimmed in raw strings.\n All other " +
|
||||||
|
"whitespace\n is preserved."
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const actual = parseFile(path.join(testFilesDir, "string.toml"));
|
const actual = parseFile(path.join(testFilesDir, "string.toml"));
|
||||||
|
|
|
@ -21,7 +21,8 @@ async function main(): Promise<void> {
|
||||||
|
|
||||||
if (parsedArgs._.length === 0) {
|
if (parsedArgs._.length === 0) {
|
||||||
console.error(
|
console.error(
|
||||||
"Usage: gist.ts --allow-env --allow-net [-t|--title Example] some_file [next_file]"
|
"Usage: gist.ts --allow-env --allow-net [-t|--title Example] some_file " +
|
||||||
|
"[next_file]"
|
||||||
);
|
);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
17
fs/copy.ts
17
fs/copy.ts
|
@ -9,7 +9,8 @@ export interface CopyOptions {
|
||||||
*/
|
*/
|
||||||
overwrite?: boolean;
|
overwrite?: boolean;
|
||||||
/**
|
/**
|
||||||
* When `true`, will set last modification and access times to the ones of the original source files.
|
* When `true`, will set last modification and access times to the ones of the
|
||||||
|
* original source files.
|
||||||
* When `false`, timestamp behavior is OS-dependent.
|
* When `false`, timestamp behavior is OS-dependent.
|
||||||
* Default is `false`.
|
* Default is `false`.
|
||||||
*/
|
*/
|
||||||
|
@ -188,9 +189,10 @@ function copyDirSync(src: string, dest: string, options: CopyOptions): void {
|
||||||
/**
|
/**
|
||||||
* Copy a file or directory. The directory can have contents. Like `cp -r`.
|
* Copy a file or directory. The directory can have contents. Like `cp -r`.
|
||||||
* @param src the file/directory path.
|
* @param src the file/directory path.
|
||||||
* Note that if `src` is a directory it will copy everything inside of this directory,
|
* Note that if `src` is a directory it will copy everything inside
|
||||||
* not the entire directory itself
|
* of this directory, not the entire directory itself
|
||||||
* @param dest the destination path. Note that if `src` is a file, `dest` cannot be a directory
|
* @param dest the destination path. Note that if `src` is a file, `dest` cannot
|
||||||
|
* be a directory
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
export async function copy(
|
export async function copy(
|
||||||
|
@ -225,9 +227,10 @@ export async function copy(
|
||||||
/**
|
/**
|
||||||
* Copy a file or directory. The directory can have contents. Like `cp -r`.
|
* Copy a file or directory. The directory can have contents. Like `cp -r`.
|
||||||
* @param src the file/directory path.
|
* @param src the file/directory path.
|
||||||
* Note that if `src` is a directory it will copy everything inside of this directory,
|
* Note that if `src` is a directory it will copy everything inside
|
||||||
* not the entire directory itself
|
* of this directory, not the entire directory itself
|
||||||
* @param dest the destination path. Note that if `src` is a file, `dest` cannot be a directory
|
* @param dest the destination path. Note that if `src` is a file, `dest` cannot
|
||||||
|
* be a directory
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
export function copySync(
|
export function copySync(
|
||||||
|
|
|
@ -431,7 +431,8 @@ testCopySync(
|
||||||
);
|
);
|
||||||
|
|
||||||
testCopySync(
|
testCopySync(
|
||||||
"[fs] copy directory synchronously, and destination exist and not a directory",
|
"[fs] copy directory synchronously, and destination exist and not a " +
|
||||||
|
"directory",
|
||||||
(tempDir: string): void => {
|
(tempDir: string): void => {
|
||||||
const srcDir = path.join(tempDir, "parent_sync");
|
const srcDir = path.join(tempDir, "parent_sync");
|
||||||
const destDir = path.join(tempDir, "child.txt");
|
const destDir = path.join(tempDir, "child.txt");
|
||||||
|
|
|
@ -5,8 +5,10 @@ import { getFileInfoType } from "./utils.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that the file exists.
|
* Ensures that the file exists.
|
||||||
* If the file that is requested to be created is in directories that do not exist,
|
* If the file that is requested to be created is in directories that do not
|
||||||
* these directories are created. If the file already exists, it is NOT MODIFIED.
|
* exist.
|
||||||
|
* these directories are created. If the file already exists,
|
||||||
|
* it is NOTMODIFIED.
|
||||||
*/
|
*/
|
||||||
export async function ensureFile(filePath: string): Promise<void> {
|
export async function ensureFile(filePath: string): Promise<void> {
|
||||||
let pathExists = false;
|
let pathExists = false;
|
||||||
|
@ -33,8 +35,10 @@ export async function ensureFile(filePath: string): Promise<void> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that the file exists.
|
* Ensures that the file exists.
|
||||||
* If the file that is requested to be created is in directories that do not exist,
|
* If the file that is requested to be created is in directories that do not
|
||||||
* these directories are created. If the file already exists, it is NOT MODIFIED.
|
* exist,
|
||||||
|
* these directories are created. If the file already exists,
|
||||||
|
* it is NOT MODIFIED.
|
||||||
*/
|
*/
|
||||||
export function ensureFileSync(filePath: string): void {
|
export function ensureFileSync(filePath: string): void {
|
||||||
let pathExists = false;
|
let pathExists = false;
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
/** Test whether or not the given path exists by checking with the file system */
|
/**
|
||||||
|
* Test whether or not the given path exists by checking with the file system
|
||||||
|
*/
|
||||||
export async function exists(filePath: string): Promise<boolean> {
|
export async function exists(filePath: string): Promise<boolean> {
|
||||||
return Deno.lstat(filePath)
|
return Deno.lstat(filePath)
|
||||||
.then((): boolean => true)
|
.then((): boolean => true)
|
||||||
.catch((): boolean => false);
|
.catch((): boolean => false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Test whether or not the given path exists by checking with the file system */
|
/**
|
||||||
|
* Test whether or not the given path exists by checking with the file system
|
||||||
|
*/
|
||||||
export function existsSync(filePath: string): boolean {
|
export function existsSync(filePath: string): boolean {
|
||||||
try {
|
try {
|
||||||
Deno.lstatSync(filePath);
|
Deno.lstatSync(filePath);
|
||||||
|
|
|
@ -36,11 +36,13 @@ test(function existsDirectorySync(): void {
|
||||||
});
|
});
|
||||||
|
|
||||||
test(function existsLinkSync(): void {
|
test(function existsLinkSync(): void {
|
||||||
// TODO(axetroy): generate link file use Deno api instead of set a link file in repository
|
// TODO(axetroy): generate link file use Deno api instead of set a link file
|
||||||
|
// in repository
|
||||||
assertEquals(existsSync(path.join(testdataDir, "0-link.ts")), true);
|
assertEquals(existsSync(path.join(testdataDir, "0-link.ts")), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test(async function existsLink(): Promise<void> {
|
test(async function existsLink(): Promise<void> {
|
||||||
// TODO(axetroy): generate link file use Deno api instead of set a link file in repository
|
// TODO(axetroy): generate link file use Deno api instead of set a link file
|
||||||
|
// in repository
|
||||||
assertEquals(await exists(path.join(testdataDir, "0-link.ts")), true);
|
assertEquals(await exists(path.join(testdataDir, "0-link.ts")), true);
|
||||||
});
|
});
|
||||||
|
|
|
@ -47,6 +47,7 @@ export function glob(glob: string, options: GlobOptions = {}): RegExp {
|
||||||
/** Test whether the given string is a glob */
|
/** Test whether the given string is a glob */
|
||||||
export function isGlob(str: string): boolean {
|
export function isGlob(str: string): boolean {
|
||||||
const chars: Record<string, string> = { "{": "}", "(": ")", "[": "]" };
|
const chars: Record<string, string> = { "{": "}", "(": ")", "[": "]" };
|
||||||
|
/* eslint-disable-next-line max-len */
|
||||||
const regex = /\\(.)|(^!|\*|[\].+)]\?|\[[^\\\]]+\]|\{[^\\}]+\}|\(\?[:!=][^\\)]+\)|\([^|]+\|[^\\)]+\))/;
|
const regex = /\\(.)|(^!|\*|[\].+)]\?|\[[^\\\]]+\]|\{[^\\}]+\}|\(\?[:!=][^\\)]+\)|\([^|]+\|[^\\)]+\))/;
|
||||||
|
|
||||||
if (str === "") {
|
if (str === "") {
|
||||||
|
|
|
@ -76,7 +76,8 @@ export function globrex(
|
||||||
if (split) {
|
if (split) {
|
||||||
if (last) segment += str;
|
if (last) segment += str;
|
||||||
if (segment !== "") {
|
if (segment !== "") {
|
||||||
if (!flags.includes("g")) segment = `^${segment}$`; // change it 'includes'
|
// change it 'includes'
|
||||||
|
if (!flags.includes("g")) segment = `^${segment}$`;
|
||||||
path.segments.push(new RegExp(segment, flags));
|
path.segments.push(new RegExp(segment, flags));
|
||||||
}
|
}
|
||||||
segment = "";
|
segment = "";
|
||||||
|
@ -265,8 +266,10 @@ export function globrex(
|
||||||
// globstar is enabled, so determine if this is a globstar segment
|
// globstar is enabled, so determine if this is a globstar segment
|
||||||
let isGlobstar =
|
let isGlobstar =
|
||||||
starCount > 1 && // multiple "*"'s
|
starCount > 1 && // multiple "*"'s
|
||||||
(prevChar === "/" || prevChar === undefined) && // from the start of the segment
|
// from the start of the segment
|
||||||
(nextChar === "/" || nextChar === undefined); // to the end of the segment
|
(prevChar === "/" || prevChar === undefined) &&
|
||||||
|
// to the end of the segment
|
||||||
|
(nextChar === "/" || nextChar === undefined);
|
||||||
if (isGlobstar) {
|
if (isGlobstar) {
|
||||||
// it's a globstar, so match zero or more path segments
|
// it's a globstar, so match zero or more path segments
|
||||||
add(GLOBSTAR, { only: "regex" });
|
add(GLOBSTAR, { only: "regex" });
|
||||||
|
|
|
@ -31,7 +31,8 @@ export type PathType = "file" | "dir" | "symlink";
|
||||||
/**
|
/**
|
||||||
* Get a human readable file type string.
|
* Get a human readable file type string.
|
||||||
*
|
*
|
||||||
* @param fileInfo A FileInfo describes a file and is returned by `stat`, `lstat`
|
* @param fileInfo A FileInfo describes a file and is returned by `stat`,
|
||||||
|
* `lstat`
|
||||||
*/
|
*/
|
||||||
export function getFileInfoType(fileInfo: Deno.FileInfo): PathType | undefined {
|
export function getFileInfoType(fileInfo: Deno.FileInfo): PathType | undefined {
|
||||||
return fileInfo.isFile()
|
return fileInfo.isFile()
|
||||||
|
|
|
@ -97,9 +97,10 @@ export function getCookies(req: ServerRequest): Cookies {
|
||||||
* @param [cookie.domain] Specifies those hosts to which the cookie will be sent
|
* @param [cookie.domain] Specifies those hosts to which the cookie will be sent
|
||||||
* @param [cookie.path] Indicates a URL path that must exist in the request.
|
* @param [cookie.path] Indicates a URL path that must exist in the request.
|
||||||
* @param [cookie.secure] Indicates if the cookie is made using SSL & HTTPS.
|
* @param [cookie.secure] Indicates if the cookie is made using SSL & HTTPS.
|
||||||
* @param [cookie.httpOnly] Indicates that cookie is not accessible via Javascript
|
* @param [cookie.httpOnly] Indicates that cookie is not accessible via
|
||||||
* @param [cookie.sameSite] Allows servers to assert that a cookie ought not to be
|
* Javascript
|
||||||
* sent along with cross-site requests
|
* @param [cookie.sameSite] Allows servers to assert that a cookie ought not to
|
||||||
|
* be sent along with cross-site requests
|
||||||
* Example:
|
* Example:
|
||||||
*
|
*
|
||||||
* setCookie(response, { name: 'deno', value: 'runtime',
|
* setCookie(response, { name: 'deno', value: 'runtime',
|
||||||
|
|
|
@ -124,7 +124,8 @@ test({
|
||||||
});
|
});
|
||||||
assertEquals(
|
assertEquals(
|
||||||
res.headers.get("Set-Cookie"),
|
res.headers.get("Set-Cookie"),
|
||||||
"Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land; SameSite=Strict"
|
"Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land; " +
|
||||||
|
"SameSite=Strict"
|
||||||
);
|
);
|
||||||
|
|
||||||
res.headers = new Headers();
|
res.headers = new Headers();
|
||||||
|
@ -170,7 +171,8 @@ test({
|
||||||
});
|
});
|
||||||
assertEquals(
|
assertEquals(
|
||||||
res.headers.get("Set-Cookie"),
|
res.headers.get("Set-Cookie"),
|
||||||
"Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land; Path=/; unparsed=keyvalue; batman=Bruce"
|
"Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land; Path=/; " +
|
||||||
|
"unparsed=keyvalue; batman=Bruce"
|
||||||
);
|
);
|
||||||
|
|
||||||
res.headers = new Headers();
|
res.headers = new Headers();
|
||||||
|
@ -186,7 +188,8 @@ test({
|
||||||
});
|
});
|
||||||
assertEquals(
|
assertEquals(
|
||||||
res.headers.get("Set-Cookie"),
|
res.headers.get("Set-Cookie"),
|
||||||
"Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land; Path=/; Expires=Fri, 07 Jan 1983 15:32:00 GMT"
|
"Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land; Path=/; " +
|
||||||
|
"Expires=Fri, 07 Jan 1983 15:32:00 GMT"
|
||||||
);
|
);
|
||||||
|
|
||||||
res.headers = new Headers();
|
res.headers = new Headers();
|
||||||
|
|
|
@ -59,7 +59,8 @@ test(async function serveDirectory(): Promise<void> {
|
||||||
assert(page.includes("azure-pipelines.yml"));
|
assert(page.includes("azure-pipelines.yml"));
|
||||||
|
|
||||||
// `Deno.FileInfo` is not completely compatible with Windows yet
|
// `Deno.FileInfo` is not completely compatible with Windows yet
|
||||||
// TODO: `mode` should work correctly in the future. Correct this test case accordingly.
|
// TODO: `mode` should work correctly in the future.
|
||||||
|
// Correct this test case accordingly.
|
||||||
Deno.platform.os !== "win" &&
|
Deno.platform.os !== "win" &&
|
||||||
assert(/<td class="mode">\([a-zA-Z-]{10}\)<\/td>/.test(page));
|
assert(/<td class="mode">\([a-zA-Z-]{10}\)<\/td>/.test(page));
|
||||||
Deno.platform.os === "win" &&
|
Deno.platform.os === "win" &&
|
||||||
|
|
|
@ -359,17 +359,20 @@ test(async function testReadRequestError(): Promise<void> {
|
||||||
// See Issue 16490.
|
// See Issue 16490.
|
||||||
{
|
{
|
||||||
in:
|
in:
|
||||||
"POST / HTTP/1.1\r\nContent-Length: 10\r\nContent-Length: 0\r\n\r\nGopher hey\r\n",
|
"POST / HTTP/1.1\r\nContent-Length: 10\r\nContent-Length: 0\r\n\r\n" +
|
||||||
|
"Gopher hey\r\n",
|
||||||
err: "cannot contain multiple Content-Length headers"
|
err: "cannot contain multiple Content-Length headers"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
in:
|
in:
|
||||||
"POST / HTTP/1.1\r\nContent-Length: 10\r\nContent-Length: 6\r\n\r\nGopher\r\n",
|
"POST / HTTP/1.1\r\nContent-Length: 10\r\nContent-Length: 6\r\n\r\n" +
|
||||||
|
"Gopher\r\n",
|
||||||
err: "cannot contain multiple Content-Length headers"
|
err: "cannot contain multiple Content-Length headers"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
in:
|
in:
|
||||||
"PUT / HTTP/1.1\r\nContent-Length: 6 \r\nContent-Length: 6\r\nContent-Length:6\r\n\r\nGopher\r\n",
|
"PUT / HTTP/1.1\r\nContent-Length: 6 \r\nContent-Length: 6\r\n" +
|
||||||
|
"Content-Length:6\r\n\r\nGopher\r\n",
|
||||||
headers: [{ key: "Content-Length", value: "6" }]
|
headers: [{ key: "Content-Length", value: "6" }]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -388,7 +391,8 @@ test(async function testReadRequestError(): Promise<void> {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
in:
|
in:
|
||||||
"POST / HTTP/1.1\r\nContent-Length:0\r\ntransfer-encoding: chunked\r\n\r\n",
|
"POST / HTTP/1.1\r\nContent-Length:0\r\ntransfer-encoding: " +
|
||||||
|
"chunked\r\n\r\n",
|
||||||
headers: [],
|
headers: [],
|
||||||
err: "http: Transfer-Encoding and Content-Length cannot be send together"
|
err: "http: Transfer-Encoding and Content-Length cannot be send together"
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,8 @@ import { exists } from "../fs/exists.ts";
|
||||||
const encoder = new TextEncoder();
|
const encoder = new TextEncoder();
|
||||||
const decoder = new TextDecoder("utf-8");
|
const decoder = new TextDecoder("utf-8");
|
||||||
const isWindows = Deno.platform.os === "win";
|
const isWindows = Deno.platform.os === "win";
|
||||||
const driverLetterReg = /^[c-z]:/i; // Regular expression to test disk driver letter. eg "C:\\User\username\path\to"
|
// Regular expression to test disk driver letter. eg "C:\\User\username\path\to"
|
||||||
|
const driverLetterReg = /^[c-z]:/i;
|
||||||
|
|
||||||
enum Permission {
|
enum Permission {
|
||||||
Read,
|
Read,
|
||||||
|
@ -101,8 +102,10 @@ function checkIfExistsInPath(filePath: string): boolean {
|
||||||
|
|
||||||
for (const p of paths) {
|
for (const p of paths) {
|
||||||
const pathInEnv = path.normalize(p);
|
const pathInEnv = path.normalize(p);
|
||||||
// On Windows paths from env contain drive letter. (eg. C:\Users\username\.deno\bin)
|
// On Windows paths from env contain drive letter.
|
||||||
// But in the path of Deno, there is no drive letter. (eg \Users\username\.deno\bin)
|
// (eg. C:\Users\username\.deno\bin)
|
||||||
|
// But in the path of Deno, there is no drive letter.
|
||||||
|
// (eg \Users\username\.deno\bin)
|
||||||
if (isWindows) {
|
if (isWindows) {
|
||||||
if (driverLetterReg.test(pathInEnv)) {
|
if (driverLetterReg.test(pathInEnv)) {
|
||||||
fileAbsolutePath = HOMEDRIVE + "\\" + fileAbsolutePath;
|
fileAbsolutePath = HOMEDRIVE + "\\" + fileAbsolutePath;
|
||||||
|
@ -118,7 +121,8 @@ function checkIfExistsInPath(filePath: string): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getInstallerDir(): string {
|
function getInstallerDir(): string {
|
||||||
// In Windows's Powershell $HOME environmental variable maybe null, if so use $HOMEPATH instead.
|
// In Windows's Powershell $HOME environmental variable maybe null
|
||||||
|
// if so use $HOMEPATH instead.
|
||||||
let { HOME, HOMEPATH } = env();
|
let { HOME, HOMEPATH } = env();
|
||||||
|
|
||||||
const HOME_PATH = HOME || HOMEPATH;
|
const HOME_PATH = HOME || HOMEPATH;
|
||||||
|
@ -140,7 +144,8 @@ USAGE:
|
||||||
ARGS:
|
ARGS:
|
||||||
EXE_NAME Name for executable
|
EXE_NAME Name for executable
|
||||||
SCRIPT_URL Local or remote URL of script to install
|
SCRIPT_URL Local or remote URL of script to install
|
||||||
[FLAGS...] List of flags for script, both Deno permission and script specific flag can be used.
|
[FLAGS...] List of flags for script, both Deno permission and script specific
|
||||||
|
flag can be used.
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,10 +153,14 @@ async function generateExecutable(
|
||||||
filePath: string,
|
filePath: string,
|
||||||
commands: string[]
|
commands: string[]
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// On Windows if user is using Powershell .cmd extension is need to run the installed module.
|
// On Windows if user is using Powershell .cmd extension is need to run the
|
||||||
|
// installed module.
|
||||||
// Generate batch script to satisfy that.
|
// Generate batch script to satisfy that.
|
||||||
|
const templateHeader =
|
||||||
|
"This executable is generated by Deno. Please don't modify it unless you " +
|
||||||
|
"know what it means.";
|
||||||
if (isWindows) {
|
if (isWindows) {
|
||||||
const template = `% This executable is generated by Deno. Please don't modify it unless you know what it means. %
|
const template = `% ${templateHeader} %
|
||||||
@IF EXIST "%~dp0\deno.exe" (
|
@IF EXIST "%~dp0\deno.exe" (
|
||||||
"%~dp0\deno.exe" ${commands.slice(1).join(" ")} %*
|
"%~dp0\deno.exe" ${commands.slice(1).join(" ")} %*
|
||||||
) ELSE (
|
) ELSE (
|
||||||
|
@ -167,7 +176,7 @@ async function generateExecutable(
|
||||||
|
|
||||||
// generate Shell script
|
// generate Shell script
|
||||||
const template = `#/bin/sh
|
const template = `#/bin/sh
|
||||||
# This executable is generated by Deno. Please don't modify it unless you know what it means.
|
# ${templateHeader}
|
||||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")
|
||||||
|
|
||||||
case \`uname\` in
|
case \`uname\` in
|
||||||
|
@ -198,7 +207,9 @@ export async function install(
|
||||||
const filePath = path.join(installerDir, moduleName);
|
const filePath = path.join(installerDir, moduleName);
|
||||||
|
|
||||||
if (await exists(filePath)) {
|
if (await exists(filePath)) {
|
||||||
const msg = `⚠️ ${moduleName} is already installed, do you want to overwrite it?`;
|
const msg =
|
||||||
|
"⚠️ ${moduleName} is already installed, " +
|
||||||
|
"do you want to overwrite it?";
|
||||||
if (!(await yesNoPrompt(msg))) {
|
if (!(await yesNoPrompt(msg))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -245,7 +256,8 @@ export async function install(
|
||||||
if (!checkIfExistsInPath(installerDir)) {
|
if (!checkIfExistsInPath(installerDir)) {
|
||||||
console.log("\nℹ️ Add ~/.deno/bin to PATH");
|
console.log("\nℹ️ Add ~/.deno/bin to PATH");
|
||||||
console.log(
|
console.log(
|
||||||
" echo 'export PATH=\"$HOME/.deno/bin:$PATH\"' >> ~/.bashrc # change this to your shell"
|
" echo 'export PATH=\"$HOME/.deno/bin:$PATH\"' >> ~/.bashrc # change" +
|
||||||
|
" this to your shell"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,7 @@ installerTest(async function installBasic(): Promise<void> {
|
||||||
if (isWindows) {
|
if (isWindows) {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
await fs.readFileStr(filePath + ".cmd"),
|
await fs.readFileStr(filePath + ".cmd"),
|
||||||
|
/* eslint-disable max-len */
|
||||||
`% This executable is generated by Deno. Please don't modify it unless you know what it means. %
|
`% This executable is generated by Deno. Please don't modify it unless you know what it means. %
|
||||||
@IF EXIST "%~dp0\deno.exe" (
|
@IF EXIST "%~dp0\deno.exe" (
|
||||||
"%~dp0\deno.exe" run http://localhost:4500/http/file_server.ts %*
|
"%~dp0\deno.exe" run http://localhost:4500/http/file_server.ts %*
|
||||||
|
@ -77,11 +78,13 @@ installerTest(async function installBasic(): Promise<void> {
|
||||||
deno run http://localhost:4500/http/file_server.ts %*
|
deno run http://localhost:4500/http/file_server.ts %*
|
||||||
)
|
)
|
||||||
`
|
`
|
||||||
|
/* eslint-enable max-len */
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
await fs.readFileStr(filePath),
|
await fs.readFileStr(filePath),
|
||||||
|
/* eslint-disable max-len */
|
||||||
`#/bin/sh
|
`#/bin/sh
|
||||||
# This executable is generated by Deno. Please don't modify it unless you know what it means.
|
# This executable is generated by Deno. Please don't modify it unless you know what it means.
|
||||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")
|
||||||
|
@ -99,6 +102,7 @@ else
|
||||||
fi
|
fi
|
||||||
exit $ret
|
exit $ret
|
||||||
`
|
`
|
||||||
|
/* eslint-enable max-len */
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -115,6 +119,7 @@ installerTest(async function installWithFlags(): Promise<void> {
|
||||||
if (isWindows) {
|
if (isWindows) {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
await fs.readFileStr(filePath + ".cmd"),
|
await fs.readFileStr(filePath + ".cmd"),
|
||||||
|
/* eslint-disable max-len */
|
||||||
`% This executable is generated by Deno. Please don't modify it unless you know what it means. %
|
`% This executable is generated by Deno. Please don't modify it unless you know what it means. %
|
||||||
@IF EXIST "%~dp0\deno.exe" (
|
@IF EXIST "%~dp0\deno.exe" (
|
||||||
"%~dp0\deno.exe" run --allow-net --allow-read http://localhost:4500/http/file_server.ts --foobar %*
|
"%~dp0\deno.exe" run --allow-net --allow-read http://localhost:4500/http/file_server.ts --foobar %*
|
||||||
|
@ -124,11 +129,13 @@ installerTest(async function installWithFlags(): Promise<void> {
|
||||||
deno run --allow-net --allow-read http://localhost:4500/http/file_server.ts --foobar %*
|
deno run --allow-net --allow-read http://localhost:4500/http/file_server.ts --foobar %*
|
||||||
)
|
)
|
||||||
`
|
`
|
||||||
|
/* eslint-enable max-len */
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
await fs.readFileStr(filePath),
|
await fs.readFileStr(filePath),
|
||||||
|
/* eslint-disable max-len */
|
||||||
`#/bin/sh
|
`#/bin/sh
|
||||||
# This executable is generated by Deno. Please don't modify it unless you know what it means.
|
# This executable is generated by Deno. Please don't modify it unless you know what it means.
|
||||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")
|
||||||
|
@ -146,6 +153,7 @@ else
|
||||||
fi
|
fi
|
||||||
exit $ret
|
exit $ret
|
||||||
`
|
`
|
||||||
|
/* eslint-enable max-len */
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -207,8 +207,10 @@ export class BufReader implements Reader {
|
||||||
/** readString() reads until the first occurrence of delim in the input,
|
/** readString() reads until the first occurrence of delim in the input,
|
||||||
* returning a string containing the data up to and including the delimiter.
|
* returning a string containing the data up to and including the delimiter.
|
||||||
* If ReadString encounters an error before finding a delimiter,
|
* If ReadString encounters an error before finding a delimiter,
|
||||||
* it returns the data read before the error and the error itself (often io.EOF).
|
* it returns the data read before the error and the error itself
|
||||||
* ReadString returns err != nil if and only if the returned data does not end in
|
* (often io.EOF).
|
||||||
|
* ReadString returns err != nil if and only if the returned data does not end
|
||||||
|
* in
|
||||||
* delim.
|
* delim.
|
||||||
* For simple uses, a Scanner may be more convenient.
|
* For simple uses, a Scanner may be more convenient.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -143,7 +143,8 @@ test(async function bufioBufReader(): Promise<void> {
|
||||||
|
|
||||||
test(async function bufioBufferFull(): Promise<void> {
|
test(async function bufioBufferFull(): Promise<void> {
|
||||||
const longString =
|
const longString =
|
||||||
"And now, hello, world! It is the time for all good men to come to the aid of their party";
|
"And now, hello, world! It is the time for all good men to come to the" +
|
||||||
|
" aid of their party";
|
||||||
const buf = new BufReader(stringsReader(longString), MIN_READ_BUFFER_SIZE);
|
const buf = new BufReader(stringsReader(longString), MIN_READ_BUFFER_SIZE);
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
|
|
||||||
|
@ -165,7 +166,8 @@ const testInput = encoder.encode(
|
||||||
"012\n345\n678\n9ab\ncde\nfgh\nijk\nlmn\nopq\nrst\nuvw\nxy"
|
"012\n345\n678\n9ab\ncde\nfgh\nijk\nlmn\nopq\nrst\nuvw\nxy"
|
||||||
);
|
);
|
||||||
const testInputrn = encoder.encode(
|
const testInputrn = encoder.encode(
|
||||||
"012\r\n345\r\n678\r\n9ab\r\ncde\r\nfgh\r\nijk\r\nlmn\r\nopq\r\nrst\r\nuvw\r\nxy\r\n\n\r\n"
|
"012\r\n345\r\n678\r\n9ab\r\ncde\r\nfgh\r\nijk\r\nlmn\r\nopq\r\nrst\r\n" +
|
||||||
|
"uvw\r\nxy\r\n\n\r\n"
|
||||||
);
|
);
|
||||||
const testOutput = encoder.encode("0123456789abcdefghijklmnopqrstuvwxy");
|
const testOutput = encoder.encode("0123456789abcdefghijklmnopqrstuvwxy");
|
||||||
|
|
||||||
|
@ -281,13 +283,17 @@ test(async function bufioPeek(): Promise<void> {
|
||||||
const r = await buf.peek(1);
|
const r = await buf.peek(1);
|
||||||
assert(r === EOF);
|
assert(r === EOF);
|
||||||
/* TODO
|
/* TODO
|
||||||
// Test for issue 3022, not exposing a reader's error on a successful Peek.
|
Test for issue 3022, not exposing a reader's error on a successful Peek.
|
||||||
buf = NewReaderSize(dataAndEOFReader("abcd"), 32)
|
buf = NewReaderSize(dataAndEOFReader("abcd"), 32)
|
||||||
if s, err := buf.Peek(2); string(s) != "ab" || err != nil {
|
if s, err := buf.Peek(2); string(s) != "ab" || err != nil {
|
||||||
t.Errorf(`Peek(2) on "abcd", EOF = %q, %v; want "ab", nil`, string(s), err)
|
t.Errorf(`Peek(2) on "abcd", EOF = %q, %v; want "ab", nil`, string(s), err)
|
||||||
}
|
}
|
||||||
if s, err := buf.Peek(4); string(s) != "abcd" || err != nil {
|
if s, err := buf.Peek(4); string(s) != "abcd" || err != nil {
|
||||||
t.Errorf(`Peek(4) on "abcd", EOF = %q, %v; want "abcd", nil`, string(s), err)
|
t.Errorf(
|
||||||
|
`Peek(4) on "abcd", EOF = %q, %v; want "abcd", nil`,
|
||||||
|
string(s),
|
||||||
|
err
|
||||||
|
)
|
||||||
}
|
}
|
||||||
if n, err := buf.Read(p[0:5]); string(p[0:n]) != "abcd" || err != nil {
|
if n, err := buf.Read(p[0:5]); string(p[0:n]) != "abcd" || err != nil {
|
||||||
t.Fatalf("Read after peek = %q, %v; want abcd, EOF", p[0:n], err)
|
t.Fatalf("Read after peek = %q, %v; want abcd, EOF", p[0:n], err)
|
||||||
|
|
|
@ -4,7 +4,9 @@ type Reader = Deno.Reader;
|
||||||
type Writer = Deno.Writer;
|
type Writer = Deno.Writer;
|
||||||
import { assert } from "../testing/asserts.ts";
|
import { assert } from "../testing/asserts.ts";
|
||||||
|
|
||||||
/** copy N size at the most. If read size is lesser than N, then returns nread */
|
/** copy N size at the most.
|
||||||
|
* If read size is lesser than N, then returns nread
|
||||||
|
* */
|
||||||
export async function copyN(
|
export async function copyN(
|
||||||
dest: Writer,
|
dest: Writer,
|
||||||
r: Reader,
|
r: Reader,
|
||||||
|
|
|
@ -25,7 +25,9 @@ export function stringsReader(s: string): Reader {
|
||||||
return new Buffer(encode(s).buffer);
|
return new Buffer(encode(s).buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create or open a temporal file at specified directory with prefix and postfix */
|
/** Create or open a temporal file at specified directory with prefix and
|
||||||
|
* postfix
|
||||||
|
* */
|
||||||
export async function tempFile(
|
export async function tempFile(
|
||||||
dir: string,
|
dir: string,
|
||||||
opts: {
|
opts: {
|
||||||
|
|
|
@ -111,7 +111,8 @@ test(function multipartMultipartWriter2(): void {
|
||||||
(): MultipartWriter =>
|
(): MultipartWriter =>
|
||||||
new MultipartWriter(
|
new MultipartWriter(
|
||||||
w,
|
w,
|
||||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
|
||||||
|
"aaaaaaaa"
|
||||||
),
|
),
|
||||||
Error,
|
Error,
|
||||||
"invalid boundary length"
|
"invalid boundary length"
|
||||||
|
|
|
@ -10,7 +10,9 @@ export interface FormFile {
|
||||||
size: number;
|
size: number;
|
||||||
/** in-memory content of file. Either content or tempfile is set */
|
/** in-memory content of file. Either content or tempfile is set */
|
||||||
content?: Uint8Array;
|
content?: Uint8Array;
|
||||||
/** temporal file path. Set if file size is bigger than specified max-memory size at reading form */
|
/** temporal file path.
|
||||||
|
* Set if file size is bigger than specified max-memory size at reading form
|
||||||
|
* */
|
||||||
tempfile?: string;
|
tempfile?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,23 @@
|
||||||
/**
|
/**
|
||||||
* Copyright © James Long and contributors
|
* Copyright © James Long and contributors
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
// This script formats the given source files. If the files are omitted, it
|
// This script formats the given source files. If the files are omitted, it
|
||||||
|
@ -23,49 +35,47 @@ Formats the given files. If no arg is passed, then formats the all files.
|
||||||
Usage: deno prettier/main.ts [options] [files...]
|
Usage: deno prettier/main.ts [options] [files...]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-H, --help Show this help message and exit.
|
-H, --help Show this help message and exit.
|
||||||
--check Check if the source files are formatted.
|
--check Check if the source files are formatted.
|
||||||
--write Whether to write to the file, otherwise it will output to stdout, Defaults to false.
|
--write Whether to write to the file, otherwise
|
||||||
--ignore <path> Ignore the given path(s).
|
it will output to stdout, Defaults to
|
||||||
|
false.
|
||||||
|
--ignore <path> Ignore the given path(s).
|
||||||
|
|
||||||
JS/TS Styling Options:
|
JS/TS Styling Options:
|
||||||
--print-width <int> The line length where Prettier will try wrap.
|
--print-width <int> The line length where Prettier will try
|
||||||
Defaults to 80.
|
wrap. Defaults to 80.
|
||||||
--tab-width <int> Number of spaces per indentation level.
|
--tab-width <int> Number of spaces per indentation level.
|
||||||
Defaults to 2.
|
Defaults to 2.
|
||||||
--use-tabs Indent with tabs instead of spaces.
|
--use-tabs Indent with tabs instead of spaces.
|
||||||
Defaults to false.
|
Defaults to false.
|
||||||
--no-semi Do not print semicolons, except at the beginning of lines which may need them.
|
--no-semi Do not print semicolons, except at the
|
||||||
--single-quote Use single quotes instead of double quotes.
|
beginning of lines which may need them.
|
||||||
Defaults to false.
|
--single-quote Use single quotes instead of double
|
||||||
--trailing-comma <none|es5|all>
|
quotes. Defaults to false.
|
||||||
Print trailing commas wherever possible when multi-line.
|
--trailing-comma <none|es5|all> Print trailing commas wherever possible
|
||||||
Defaults to none.
|
when multi-line. Defaults to none.
|
||||||
--no-bracket-spacing Do not print spaces between brackets.
|
--no-bracket-spacing Do not print spaces between brackets.
|
||||||
--arrow-parens <avoid|always>
|
--arrow-parens <avoid|always> Include parentheses around a sole arrow
|
||||||
Include parentheses around a sole arrow function parameter.
|
function parameter. Defaults to avoid.
|
||||||
Defaults to avoid.
|
--end-of-line <auto|lf|crlf|cr> Which end of line characters to apply.
|
||||||
--end-of-line <auto|lf|crlf|cr>
|
Defaults to auto.
|
||||||
Which end of line characters to apply.
|
|
||||||
Defaults to auto.
|
|
||||||
|
|
||||||
Markdown Styling Options:
|
Markdown Styling Options:
|
||||||
--prose-wrap <always|never|preserve>
|
--prose-wrap <always|never|preserve> How to wrap prose. Defaults to preserve.
|
||||||
How to wrap prose.
|
|
||||||
Defaults to preserve.
|
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
deno run prettier/main.ts --write script1.ts script2.js
|
deno run prettier/main.ts --write script1.ts script2.js
|
||||||
Formats the files
|
Formats the files
|
||||||
|
|
||||||
deno run prettier/main.ts --check script1.ts script2.js
|
deno run prettier/main.ts --check script1.ts script2.js
|
||||||
Checks if the files are formatted
|
Checks if the files are formatted
|
||||||
|
|
||||||
deno run prettier/main.ts --write
|
deno run prettier/main.ts --write
|
||||||
Formats the all files in the repository
|
Formats the all files in the repository
|
||||||
|
|
||||||
deno run prettier/main.ts script1.ts
|
deno run prettier/main.ts script1.ts
|
||||||
Print the formatted code to stdout
|
Print the formatted code to stdout
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// Available parsers
|
// Available parsers
|
||||||
|
@ -230,7 +240,8 @@ async function formatSourceFiles(
|
||||||
/**
|
/**
|
||||||
* Get the files to format.
|
* Get the files to format.
|
||||||
* @param selectors The glob patterns to select the files.
|
* @param selectors The glob patterns to select the files.
|
||||||
* eg `cmd/*.ts` to select all the typescript files in cmd directory.
|
* eg `cmd/*.ts` to select all the typescript files in cmd
|
||||||
|
* directory.
|
||||||
* eg `cmd/run.ts` to select `cmd/run.ts` file as only.
|
* eg `cmd/run.ts` to select `cmd/run.ts` file as only.
|
||||||
* @param ignore The glob patterns to ignore files.
|
* @param ignore The glob patterns to ignore files.
|
||||||
* eg `*_test.ts` to ignore all the test file.
|
* eg `*_test.ts` to ignore all the test file.
|
||||||
|
|
|
@ -197,9 +197,9 @@ console.log([function foo() {}, function baz() {}, (a) => {}]);
|
||||||
await run([...cmd, "--prose-wrap", "always", "--write", file3]);
|
await run([...cmd, "--prose-wrap", "always", "--write", file3]);
|
||||||
assertEquals(
|
assertEquals(
|
||||||
normalizeSourceCode(await getSourceCode(file3)),
|
normalizeSourceCode(await getSourceCode(file3)),
|
||||||
`Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, " +
|
||||||
incididunt ut labore et dolore magna aliqua.
|
"sed do eiusmod tempor" +
|
||||||
`
|
"\nincididunt ut labore et dolore magna aliqua.\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
await run([...cmd, "--end-of-line", "crlf", "--write", file2]);
|
await run([...cmd, "--end-of-line", "crlf", "--write", file2]);
|
||||||
|
@ -227,7 +227,8 @@ test(async function testPrettierPrintToStdout(): Promise<void> {
|
||||||
const { stdout: formattedCode } = await run([...cmd, file1]);
|
const { stdout: formattedCode } = await run([...cmd, file1]);
|
||||||
// The source file will not change without `--write` flags.
|
// The source file will not change without `--write` flags.
|
||||||
assertEquals(await getSourceCode(file1), "console.log(0);" + EOL);
|
assertEquals(await getSourceCode(file1), "console.log(0);" + EOL);
|
||||||
// The output will be formatted code even it is the same as the source file's content.
|
// The output will be formatted code even it is the same as the source file's
|
||||||
|
// content.
|
||||||
assertEquals(formattedCode, "console.log(0);" + EOL);
|
assertEquals(formattedCode, "console.log(0);" + EOL);
|
||||||
|
|
||||||
emptyDir(tempDir);
|
emptyDir(tempDir);
|
||||||
|
|
|
@ -72,9 +72,14 @@ export default function diff<T>(A: T[], B: T[]): Array<DiffResult<T>> {
|
||||||
const delta = M - N;
|
const delta = M - N;
|
||||||
const size = M + N + 1;
|
const size = M + N + 1;
|
||||||
const fp = new Array(size).fill({ y: -1 });
|
const fp = new Array(size).fill({ y: -1 });
|
||||||
// INFO: This buffer is used to save memory and improve performance.
|
/**
|
||||||
// The first half is used to save route and last half is used to save diff type.
|
* INFO:
|
||||||
// This is because, when I kept new uint8array area to save type, performance worsened.
|
* This buffer is used to save memory and improve performance.
|
||||||
|
* The first half is used to save route and last half is used to save diff
|
||||||
|
* type.
|
||||||
|
* This is because, when I kept new uint8array area to save type,performance
|
||||||
|
* worsened.
|
||||||
|
*/
|
||||||
const routes = new Uint32Array((M * N + size + 1) * 2);
|
const routes = new Uint32Array((M * N + size + 1) * 2);
|
||||||
const diffTypesPtrOffset = routes.length / 2;
|
const diffTypesPtrOffset = routes.length / 2;
|
||||||
let ptr = 0;
|
let ptr = 0;
|
||||||
|
|
|
@ -72,7 +72,9 @@ const getConstructorName = (val: new (...args: any[]) => any): string =>
|
||||||
(typeof val.constructor === "function" && val.constructor.name) || "Object";
|
(typeof val.constructor === "function" && val.constructor.name) || "Object";
|
||||||
|
|
||||||
/* global window */
|
/* global window */
|
||||||
/** Is val is equal to global window object? Works even if it does not exist :) */
|
/** Is val is equal to global window object?
|
||||||
|
* Works even if it does not exist :)
|
||||||
|
* */
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const isWindow = (val: any): val is Window =>
|
const isWindow = (val: any): val is Window =>
|
||||||
typeof window !== "undefined" && val === window;
|
typeof window !== "undefined" && val === window;
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { test } from "./mod.ts";
|
||||||
import { assertEquals } from "../testing/asserts.ts";
|
import { assertEquals } from "../testing/asserts.ts";
|
||||||
import { format } from "./format.ts";
|
import { format } from "./format.ts";
|
||||||
|
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-explicit-any
|
||||||
function returnArguments(...args: any[]): IArguments {
|
function returnArguments(...args: any[]): IArguments {
|
||||||
return arguments;
|
return arguments;
|
||||||
|
@ -385,7 +386,8 @@ test({
|
||||||
val.prop = "value1";
|
val.prop = "value1";
|
||||||
assertEquals(
|
assertEquals(
|
||||||
format(val),
|
format(val),
|
||||||
'Object {\n "prop": "value1",\n Symbol(symbol1): "value2",\n Symbol(symbol2): "value3",\n}'
|
'Object {\n "prop": "value1",\n Symbol(symbol1): "value2",\n ' +
|
||||||
|
'Symbol(symbol2): "value3",\n}'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -607,7 +609,8 @@ test({
|
||||||
const val = { prop: { prop: { prop: "value" } } };
|
const val = { prop: { prop: { prop: "value" } } };
|
||||||
assertEquals(
|
assertEquals(
|
||||||
format(val),
|
format(val),
|
||||||
'Object {\n "prop": Object {\n "prop": Object {\n "prop": "value",\n },\n },\n}'
|
'Object {\n "prop": Object {\n "prop": Object {\n "prop": ' +
|
||||||
|
'"value",\n },\n },\n}'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -106,8 +106,10 @@ export class TextProtoReader {
|
||||||
//let key = canonicalMIMEHeaderKey(kv.subarray(0, endKey));
|
//let key = canonicalMIMEHeaderKey(kv.subarray(0, endKey));
|
||||||
let key = str(kv.subarray(0, endKey));
|
let key = str(kv.subarray(0, endKey));
|
||||||
|
|
||||||
// As per RFC 7230 field-name is a token, tokens consist of one or more chars.
|
// As per RFC 7230 field-name is a token,
|
||||||
// We could return a ProtocolError here, but better to be liberal in what we
|
// tokens consist of one or more chars.
|
||||||
|
// We could return a ProtocolError here,
|
||||||
|
// but better to be liberal in what we
|
||||||
// accept, so if we get an empty key, skip it.
|
// accept, so if we get an empty key, skip it.
|
||||||
if (key == "") {
|
if (key == "") {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -52,7 +52,8 @@ test({
|
||||||
name: "[textproto] Reader : MIME Header",
|
name: "[textproto] Reader : MIME Header",
|
||||||
async fn(): Promise<void> {
|
async fn(): Promise<void> {
|
||||||
const input =
|
const input =
|
||||||
"my-key: Value 1 \r\nLong-key: Even Longer Value\r\nmy-Key: Value 2\r\n\n";
|
"my-key: Value 1 \r\nLong-key: Even Longer Value\r\nmy-Key: " +
|
||||||
|
"Value 2\r\n\n";
|
||||||
const r = reader(input);
|
const r = reader(input);
|
||||||
const m = assertNotEOF(await r.readMIMEHeader());
|
const m = assertNotEOF(await r.readMIMEHeader());
|
||||||
assertEquals(m.get("My-Key"), "Value 1, Value 2");
|
assertEquals(m.get("My-Key"), "Value 1, Value 2");
|
||||||
|
|
|
@ -42,7 +42,8 @@ async function main(): Promise<void> {
|
||||||
} else {
|
} else {
|
||||||
await sock.send(line);
|
await sock.send(line);
|
||||||
}
|
}
|
||||||
// FIXME: Without this, sock.receive() won't resolved though it is readable...
|
// FIXME: Without this,
|
||||||
|
// sock.receive() won't resolved though it is readable...
|
||||||
await new Promise((resolve): void => setTimeout(resolve, 0));
|
await new Promise((resolve): void => setTimeout(resolve, 0));
|
||||||
}
|
}
|
||||||
await sock.close(1000);
|
await sock.close(1000);
|
||||||
|
|
|
@ -474,7 +474,10 @@ async function handshake(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Connect to given websocket endpoint url. Endpoint must be acceptable for URL */
|
/**
|
||||||
|
* Connect to given websocket endpoint url.
|
||||||
|
* Endpoint must be acceptable for URL.
|
||||||
|
*/
|
||||||
export async function connectWebSocket(
|
export async function connectWebSocket(
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
headers: Headers = new Headers()
|
headers: Headers = new Headers()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue