Skip to content

Commit

Permalink
Merge pull request #1242 from iuioiua/deprecation-guide
Browse files Browse the repository at this point in the history
docs: point to new "Deno 1.x to 2.x Migration Guide"
  • Loading branch information
kwhinnery authored Feb 7, 2024
2 parents b06f713 + 882ab0f commit 7bba1a9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 163 deletions.
209 changes: 47 additions & 162 deletions docs/rules/no_deprecated_deno_api.md
Original file line number Diff line number Diff line change
@@ -1,170 +1,55 @@
Warns the usage of the deprecated Deno APIs
Warns the usage of the deprecated - Deno APIs

The following APIs in the `Deno` namespace are now marked as deprecated and will
be removed from the namespace in Deno 2.0.

**IO APIs**
The following APIs will be removed from the `Deno.*` namespace but have newer
APIs to migrate to. See the
[Deno 1.x to 2.x Migration Guide](https://docs.deno.com/runtime/manual/advanced/migrate_deprecations)
for migration instructions.

- `Deno.Buffer`
- `Deno.copy`
- `Deno.iter`
- `Deno.iterSync`
- `Deno.readAll`
- `Deno.readAllSync`
- `Deno.writeAll`
- `Deno.writeAllSync`

Most of these APIs have been moved to [`std/io`](https://deno.land/std/io) of
the Deno Standard Library. For more detail, see
[the tracking issue](https://github.com/denoland/deno/issues/9795).

**Sub Process API**

- `Deno.run`

`Deno.run` was deprecated in favor of `Deno.Command`. See
[deno#9435](https://github.com/denoland/deno/discussions/9435) for more details.

**Custom Inspector API**

- `Deno.Closer`
- `Deno.close()`
- `Deno.Conn.rid`
- `Deno.copy()`
- `Deno.customInspect`

`Deno.customInspect` was deprecated in favor of
`Symbol.for("Deno.customInspect")`. Replace the usages with this symbol
expression. See [deno#9294](https://github.com/denoland/deno/issues/9294) for
more details.

**File system API**

- `Deno.File`

`Deno.File` was deprecated in favor of `Deno.FsFile`. Replace the usages with
new class name.

### Invalid:

```typescript
// buffer
const a = new Deno.Buffer();

// read all
const b = await Deno.readAll(reader);
const c = Deno.readAllSync(reader);

// write all
await Deno.writeAll(writer, data);
Deno.writeAllSync(writer, data);

// iter
for await (const x of Deno.iter(xs)) {}
for (const y of Deno.iterSync(ys)) {}

// copy
await Deno.copy(reader, writer);

// custom inspector
class A {
[Deno.customInspect]() {
return "This is A";
}
}

// file
function foo(file: Deno.File) {
// ...
}
```

### Valid:

```typescript
// buffer
import { Buffer } from "https://deno.land/std/io/buffer.ts";
const a = new Buffer();

// read all
import { readAll, readAllSync } from "https://deno.land/std/io/read_all.ts";
const b = await readAll(reader);
const c = readAllSync(reader);

// write all
import { writeAll, writeAllSync } from "https://deno.land/std/io/write_all.ts";
await writeAll(writer, data);
writeAllSync(writer, data);

// iter
// reader is `ReadableStream`
for await (const chunk of reader) {
// do something
}

// copy
// reader is `ReadableStream` and writer is `WritableStream`
await reader.pipeTo(writer);

// custom inspector
class A {
[Symbol.for("Deno.customInspect")]() {
return "This is A";
}
}

// file
function foo(file: Deno.FsFile) {
// ...
}
```

- `Deno.isatty`

`Deno.isatty` was deprecated in favor of `Deno.stdin.isTerminal()`,
`Deno.stdout.isTerminal()` and `Deno.stderr.isTerminal()`.

### Invalid:

```typescript
Deno.isatty(Deno.stdin.rid);
Deno.isatty(Deno.stdout.rid);
Deno.isatty(Deno.stderr.rid);
```

### Valid:

```typescript
Deno.stdin.isTerminal();
Deno.stdout.isTerminal();
Deno.stderr.isTerminal();
```

- `Deno.close`

`Deno.close` was deprecated in favor of `.close()` method available on relevant
objects.

### Invalid:

```typescript
const file = await Deno.open("foo.txt");
Deno.close(file.rid);
```

### Valid:

```typescript
const file = await Deno.open("foo.txt");
file.close();
```
- `Deno.fstatSync()`
- `Deno.fstat()`
- `Deno.FsWatcher.rid`
- `Deno.ftruncateSync()`
- `Deno.ftruncate()`
- `Deno.futimeSync()`
- `Deno.futime()`
- `Deno.isatty()`
- `Deno.Listener.rid`
- `Deno.ListenTlsOptions.certFile`
- `Deno.ListenTlsOptions.keyFile`
- `Deno.readAllSync()`
- `Deno.readAll()`
- `Deno.Reader`
- `Deno.ReaderSync`
- `Deno.readSync()`
- `Deno.read()`
- `Deno.run()`
- `Deno.seekSync()`
- `Deno.seek()`
- `Deno.serveHttp()`
- `Deno.Server`
- `Deno.shutdown`
- `Deno.stderr.rid`
- `Deno.stdin.rid`
- `Deno.stdout.rid`
- `Deno.TlsConn.rid`
- `Deno.UnixConn.rid`
- `Deno.writeAllSync()`
- `Deno.writeAll()`
- `Deno.Writer`
- `Deno.WriterSync`
- `Deno.writeSync()`
- `Deno.write()`
- `new Deno.FsFile()`

The following APIs will be removed from the `Deno.*` namespace without
replacement.

- `Deno.resources()`

Deno.resources() was deprecated. There are no replacements for this API.

- `Deno.metrics()`

Deno.metrics() was deprecated. There are no replacements for this API.

**HTTP server API**

- `Deno.serveHttp`

`Deno.serveHttp` was deprecated in favor of `Deno.serve`.
2 changes: 1 addition & 1 deletion www/static/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
},
{
"code": "no-deprecated-deno-api",
"docs": "Warns the usage of the deprecated Deno APIs\n\nThe following APIs in the `Deno` namespace are now marked as deprecated and will\nbe removed from the namespace in Deno 2.0.\n\n**IO APIs**\n\n- `Deno.Buffer`\n- `Deno.copy`\n- `Deno.iter`\n- `Deno.iterSync`\n- `Deno.readAll`\n- `Deno.readAllSync`\n- `Deno.writeAll`\n- `Deno.writeAllSync`\n\nMost of these APIs have been moved to [`std/io`](https://deno.land/std/io) of\nthe Deno Standard Library. For more detail, see\n[the tracking issue](https://github.com/denoland/deno/issues/9795).\n\n**Sub Process API**\n\n- `Deno.run`\n\n`Deno.run` was deprecated in favor of `Deno.Command`. See\n[deno#9435](https://github.com/denoland/deno/discussions/9435) for more details.\n\n**Custom Inspector API**\n\n- `Deno.customInspect`\n\n`Deno.customInspect` was deprecated in favor of\n`Symbol.for(\"Deno.customInspect\")`. Replace the usages with this symbol\nexpression. See [deno#9294](https://github.com/denoland/deno/issues/9294) for\nmore details.\n\n**File system API**\n\n- `Deno.File`\n\n`Deno.File` was deprecated in favor of `Deno.FsFile`. Replace the usages with\nnew class name.\n\n### Invalid:\n\n```typescript\n// buffer\nconst a = new Deno.Buffer();\n\n// read all\nconst b = await Deno.readAll(reader);\nconst c = Deno.readAllSync(reader);\n\n// write all\nawait Deno.writeAll(writer, data);\nDeno.writeAllSync(writer, data);\n\n// iter\nfor await (const x of Deno.iter(xs)) {}\nfor (const y of Deno.iterSync(ys)) {}\n\n// copy\nawait Deno.copy(reader, writer);\n\n// custom inspector\nclass A {\n [Deno.customInspect]() {\n return \"This is A\";\n }\n}\n\n// file\nfunction foo(file: Deno.File) {\n // ...\n}\n```\n\n### Valid:\n\n```typescript\n// buffer\nimport { Buffer } from \"https://deno.land/std/io/buffer.ts\";\nconst a = new Buffer();\n\n// read all\nimport { readAll, readAllSync } from \"https://deno.land/std/io/read_all.ts\";\nconst b = await readAll(reader);\nconst c = readAllSync(reader);\n\n// write all\nimport { writeAll, writeAllSync } from \"https://deno.land/std/io/write_all.ts\";\nawait writeAll(writer, data);\nwriteAllSync(writer, data);\n\n// iter\n// reader is `ReadableStream`\nfor await (const chunk of reader) {\n // do something\n}\n\n// copy\n// reader is `ReadableStream` and writer is `WritableStream`\nawait reader.pipeTo(writer);\n\n// custom inspector\nclass A {\n [Symbol.for(\"Deno.customInspect\")]() {\n return \"This is A\";\n }\n}\n\n// file\nfunction foo(file: Deno.FsFile) {\n // ...\n}\n```\n\n- `Deno.isatty`\n\n`Deno.isatty` was deprecated in favor of `Deno.stdin.isTerminal()`,\n`Deno.stdout.isTerminal()` and `Deno.stderr.isTerminal()`.\n\n### Invalid:\n\n```typescript\nDeno.isatty(Deno.stdin.rid);\nDeno.isatty(Deno.stdout.rid);\nDeno.isatty(Deno.stderr.rid);\n```\n\n### Valid:\n\n```typescript\nDeno.stdin.isTerminal();\nDeno.stdout.isTerminal();\nDeno.stderr.isTerminal();\n```\n\n- `Deno.close`\n\n`Deno.close` was deprecated in favor of `.close()` method available on relevant\nobjects.\n\n### Invalid:\n\n```typescript\nconst file = await Deno.open(\"foo.txt\");\nDeno.close(file.rid);\n```\n\n### Valid:\n\n```typescript\nconst file = await Deno.open(\"foo.txt\");\nfile.close();\n```\n\n- `Deno.resources()`\n\nDeno.resources() was deprecated. There are no replacements for this API.\n\n- `Deno.metrics()`\n\nDeno.metrics() was deprecated. There are no replacements for this API.\n\n**HTTP server API**\n\n- `Deno.serveHttp`\n\n`Deno.serveHttp` was deprecated in favor of `Deno.serve`.\n",
"docs": "Warns the usage of the deprecated - Deno APIs\n\nThe following APIs will be removed from the `Deno.*` namespace but have newer\nAPIs to migrate to. See the\n[Deno 1.x to 2.x Migration Guide](https://docs.deno.com/runtime/manual/advanced/migrate_deprecations)\nfor migration instructions.\n\n- `Deno.Buffer`\n- `Deno.Closer`\n- `Deno.close()`\n- `Deno.Conn.rid`\n- `Deno.copy()`\n- `Deno.customInspect`\n- `Deno.File`\n- `Deno.fstatSync()`\n- `Deno.fstat()`\n- `Deno.FsWatcher.rid`\n- `Deno.ftruncateSync()`\n- `Deno.ftruncate()`\n- `Deno.futimeSync()`\n- `Deno.futime()`\n- `Deno.isatty()`\n- `Deno.Listener.rid`\n- `Deno.ListenTlsOptions.certFile`\n- `Deno.ListenTlsOptions.keyFile`\n- `Deno.readAllSync()`\n- `Deno.readAll()`\n- `Deno.Reader`\n- `Deno.ReaderSync`\n- `Deno.readSync()`\n- `Deno.read()`\n- `Deno.run()`\n- `Deno.seekSync()`\n- `Deno.seek()`\n- `Deno.serveHttp()`\n- `Deno.Server`\n- `Deno.shutdown`\n- `Deno.stderr.rid`\n- `Deno.stdin.rid`\n- `Deno.stdout.rid`\n- `Deno.TlsConn.rid`\n- `Deno.UnixConn.rid`\n- `Deno.writeAllSync()`\n- `Deno.writeAll()`\n- `Deno.Writer`\n- `Deno.WriterSync`\n- `Deno.writeSync()`\n- `Deno.write()`\n- `new Deno.FsFile()`\n\nThe following APIs will be removed from the `Deno.*` namespace without\nreplacement.\n\n- `Deno.resources()`\n- `Deno.metrics()`\n",
"tags": [
"recommended"
]
Expand Down

0 comments on commit 7bba1a9

Please sign in to comment.