diff --git a/runtime/manual/advanced/typescript/configuration.md b/runtime/manual/advanced/typescript/configuration.md index e32efb732..c14dd7e4f 100644 --- a/runtime/manual/advanced/typescript/configuration.md +++ b/runtime/manual/advanced/typescript/configuration.md @@ -89,7 +89,7 @@ this: "compilerOptions": { "allowJs": true, "esModuleInterop": true, - "experimentalDecorators": true, + "experimentalDecorators": false, "inlineSourceMap": true, "isolatedModules": true, "jsx": "react", diff --git a/runtime/manual/node/compatibility.mdx b/runtime/manual/node/compatibility.mdx index 5dfa6ce62..8edc2977b 100644 --- a/runtime/manual/node/compatibility.mdx +++ b/runtime/manual/node/compatibility.mdx @@ -415,9 +415,7 @@ which modules you need by </div> </summary> <p> - Missing <code>disconnect</code>, <code>message</code>,{" "} - <code>multipleResolves</code>, <code>rejectionHandled</code> and{" "} - <code>worker</code> events. + Missing <code>multipleResolves</code>, <code>worker</code> events. </p> <p> <a href="https://nodejs.org/api/process.html">Node.js docs</a> diff --git a/runtime/manual/runtime/import_meta_api.md b/runtime/manual/runtime/import_meta_api.md index 94054133c..35ebc706f 100644 --- a/runtime/manual/runtime/import_meta_api.md +++ b/runtime/manual/runtime/import_meta_api.md @@ -1,15 +1,115 @@ # `import.meta` API -Deno supports a number of methods on the +Deno supports a number of properties and methods on the [`import.meta`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta) API: -- `import.meta.url`: returns the URL of the current module. -- `import.meta.main`: returns whether the current module is the entry point to - your program. -- `import.meta.resolve`: resolve specifiers relative to the current module. +## `import.meta.url` -## `import.meta.resolve` Example +Returns the URL of the current module. + +```ts +// main.ts +console.log(import.meta.url); +``` + +```sh +$ deno run main.ts +file:///dev/main.ts + +$ deno run https:/example.com/main.ts +https://example.com/main.ts +``` + +## `import.meta.main` + +Returns whether the current module is the entry point to your program. + +```ts +// main.ts +import "./other.ts"; + +console.log(`Is ${import.meta.url} the main module?`, import.meta.main); + +// other.ts +console.log(`Is ${import.meta.url} the main module?`, import.meta.main); +``` + +```sh +$ deno run main.ts +Is file:///dev/other.ts the main module? false +Is file:///dev/main.ts the main module? true +``` + +## `import.meta.filename` + +_This property is only available for local modules (module that have +`file:///...` specifier) and returns `undefined` for remote modules._ + +Returns the fully resolved path to the current module. The value contains OS +specific path separators. + +```ts +// main.ts +console.log(import.meta.filename); +``` + +On Unix: + +```sh +$ deno run main.ts +/dev/main.ts + +$ deno run https://example.com/main.ts +undefined +``` + +On Windows: + +```sh +$ deno run main.ts +C:\dev\main.ts + +$ deno run https://example.com/main.ts +undefined +``` + +## `import.meta.dirname` + +_This property is only available for local modules (module that have +`file:///...` specifier) and returns `undefined` for remote modules._ + +Returns the fully resolved path to the directory containing the current module. +The value contains OS specific path separators. + +```ts +// main.ts +console.log(import.meta.dirname); +``` + +On Unix: + +```sh +$ deno run main.ts +/dev/ + +$ deno run https://example.com/main.ts +undefined +``` + +On Windows: + +```sh +$ deno run main.ts +C:\dev\ + +$ deno run https://example.com/main.ts +undefined +``` + +## `import.meta.resolve` + +Resolve specifiers relative to the current module. ```ts const worker = new Worker(import.meta.resolve("./worker.ts")); diff --git a/runtime/manual/runtime/program_lifecycle.md b/runtime/manual/runtime/program_lifecycle.md index 53ce3cb7b..7ff2e3330 100644 --- a/runtime/manual/runtime/program_lifecycle.md +++ b/runtime/manual/runtime/program_lifecycle.md @@ -14,6 +14,11 @@ Deno supports browser compatible lifecycle events: - [`unhandledrejection`](https://developer.mozilla.org/en-US/docs/Web/API/Window/unhandledrejection_event): fired when a promise that has no rejection handler is rejected, ie. a promise that has no `.catch()` handler or a second argument to `.then()`. +- [`rejectionhandled`](https://developer.mozilla.org/en-US/docs/Web/API/Window/rejectionhandled_event): + fired when a `.catch()` handler is added to a a promise that has already + rejected. This event is fired only if there's `unhandledrejection` listener + installed that prevents propagation of the event (which would result in the + program terminating with an error). You can use these events to provide setup and cleanup code in your program. diff --git a/runtime/manual/runtime/workers.md b/runtime/manual/runtime/workers.md index cf4df9384..4595da566 100644 --- a/runtime/manual/runtime/workers.md +++ b/runtime/manual/runtime/workers.md @@ -17,11 +17,11 @@ and this capability by default. ```ts // Good -new Worker(new URL("./worker.js", import.meta.url).href, { type: "module" }); +new Worker(import.meta.resolve("./worker.js"), { type: "module" }); // Bad -new Worker(new URL("./worker.js", import.meta.url).href); -new Worker(new URL("./worker.js", import.meta.url).href, { type: "classic" }); +new Worker(import.meta.resolve("./worker.js")); +new Worker(import.meta.resolve("./worker.js"), { type: "classic" }); new Worker("./worker.js", { type: "module" }); ``` @@ -55,7 +55,7 @@ For workers using local modules; `--allow-read` permission is required: **main.ts** ```ts -new Worker(new URL("./worker.ts", import.meta.url).href, { type: "module" }); +new Worker(import.meta.resolve("./worker.ts"), { type: "module" }); ``` **worker.ts** @@ -105,7 +105,7 @@ hello world **main.js** ```js -const worker = new Worker(new URL("./worker.js", import.meta.url).href, { +const worker = new Worker(import.meta.resolve("./worker.js"), { type: "module", }); @@ -158,7 +158,7 @@ the `deno.permissions` option in the worker API. the on/off option you can pass true/false respectively. ```ts - const worker = new Worker(new URL("./worker.js", import.meta.url).href, { + const worker = new Worker(import.meta.resolve("./worker.js"), { type: "module", deno: { permissions: { @@ -202,7 +202,7 @@ the `deno.permissions` option in the worker API. ```ts // This worker will inherit its parent permissions - const worker = new Worker(new URL("./worker.js", import.meta.url).href, { + const worker = new Worker(import.meta.resolve("./worker.js"), { type: "module", deno: { permissions: "inherit", @@ -212,7 +212,7 @@ the `deno.permissions` option in the worker API. ```ts // This worker will inherit only the net permissions of its parent - const worker = new Worker(new URL("./worker.js", import.meta.url).href, { + const worker = new Worker(import.meta.resolve("./worker.js"), { type: "module", deno: { permissions: { @@ -233,14 +233,14 @@ the `deno.permissions` option in the worker API. ```ts // This worker will inherit its parent permissions - const worker = new Worker(new URL("./worker.js", import.meta.url).href, { + const worker = new Worker(import.meta.resolve("./worker.js"), { type: "module", }); ``` ```ts // This worker will inherit all the permissions of its parent BUT net - const worker = new Worker(new URL("./worker.js", import.meta.url).href, { + const worker = new Worker(import.meta.resolve("./worker.js"), { type: "module", deno: { permissions: { @@ -255,7 +255,7 @@ the `deno.permissions` option in the worker API. ```ts // This worker will not have any permissions enabled - const worker = new Worker(new URL("./worker.js", import.meta.url).href, { + const worker = new Worker(import.meta.resolve("./worker.js"), { type: "module", deno: { permissions: "none", diff --git a/runtime/manual/tools/unstable_flags.md b/runtime/manual/tools/unstable_flags.md index 92fb9e7bb..c3610b1ac 100644 --- a/runtime/manual/tools/unstable_flags.md +++ b/runtime/manual/tools/unstable_flags.md @@ -223,17 +223,10 @@ Enable unstable file system APIs in the `Deno` namespace. These APIs include: - [`Deno.funlockSync`](https://deno.land/api?unstable=&s=Deno.funlockSync) - [`Deno.umask`](https://deno.land/api?unstable=&s=Deno.umask) -## `--unstable-http` - -Enable unstable HTTP APIs in the `Deno` namespace. These APIs include: - -- [`Deno.upgradeHttp`](https://deno.land/api?unstable=&s=Deno.upgradeHttp) - ## `--unstable-net` Enable unstable net APIs in the `Deno` namespace. These APIs include: -- [`Deno.ConnectTlsOptions`](https://deno.land/api?unstable=&s=Deno.ConnectTlsOptions) - [`Deno.DatagramConn`](https://deno.land/api?unstable=&s=Deno.DatagramConn) - Many more - for the latest list, check the "Show Unstable API" checkbox in the [API reference](https://deno.land/api?unstable=) @@ -262,5 +255,5 @@ access to these unstable features, you would run your script with: deno run --unstable your_script.ts ``` -No new features will be exposed using this method, and it will be removed in a -future release. +It is recommended that you use the granular unstable flags instead of this, the +`--unstable` flag is now depreacted and will be removed in Deno 2. diff --git a/runtime/tutorials/module_metadata.md b/runtime/tutorials/module_metadata.md index 62ea3f08c..2dfe75762 100644 --- a/runtime/tutorials/module_metadata.md +++ b/runtime/tutorials/module_metadata.md @@ -8,6 +8,14 @@ will let you know if the current module is the program entry point. - The string [import.meta.url](https://deno.land/api?s=ImportMeta#prop_url) will give you the URL of the current module. +- The string + [import.meta.filename](https://deno.land/api?s=ImportMeta#prop_filename) will + give you the fully resolved path to the current module. _For local modules + only_. +- The string + [import.meta.dirname](https://deno.land/api?s=ImportMeta#prop_dirname) will + give you the fully resolved path to the directory containing the current + module. _For local modules only_. - The [import.meta.resolve](https://deno.land/api?s=ImportMeta#prop_resolve) allows you to resolve specifier relative to the current module. This function takes into account an import map (if one was provided on startup).