Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions types/node/v16/module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,22 +195,15 @@ declare module "module" {
static Module: typeof Module;
constructor(id: string, parent?: Module);
}
type ImportMetaDOMCompat = typeof globalThis extends { onmessage: any } ? {
resolve(specifier: string): string;
}
: {
resolve?(specifier: string, parent?: string | URL): Promise<string>;
};
global {
interface ImportMeta {
interface ImportMeta extends ImportMetaDOMCompat {
url: string;
/**
* @experimental
* This feature is only available with the `--experimental-import-meta-resolve`
* command flag enabled.
*
* Provides a module-relative resolution function scoped to each module, returning
* the URL string.
*
* @param specified The module specifier to resolve relative to `parent`.
* @param parent The absolute parent module URL to resolve from. If none
* is specified, the value of `import.meta.url` is used as the default.
*/
resolve?(specified: string, parent?: string | URL): Promise<string>;
}
}
export = Module;
Expand Down
1 change: 1 addition & 0 deletions types/node/v16/node-tests-dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./test/module-dom";
1 change: 1 addition & 0 deletions types/node/v16/node-tests-non-dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./test/module-non-dom";
9 changes: 9 additions & 0 deletions types/node/v16/test/module-dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Module = require("node:module");
import { URL } from "node:url";
// global
{
const importmeta: ImportMeta = {} as any; // Fake because we cannot really access the true `import.meta` with the current build target
importmeta.url; // $ExpectType string
importmeta.resolve!("local"); // $ExpectType Promise<string> || string
}

10 changes: 10 additions & 0 deletions types/node/v16/test/module-non-dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Module = require("node:module");
import { URL } from "node:url";
// global
{
const importmeta: ImportMeta = {} as any; // Fake because we cannot really access the true `import.meta` with the current build target
importmeta.url; // $ExpectType string
importmeta.resolve!("local"); // $ExpectType Promise<string>
importmeta.resolve!("local", "/parent"); // $ExpectType Promise<string>
importmeta.resolve!("local", new URL("https://parent.module")); // $ExpectType Promise<string>
}
7 changes: 0 additions & 7 deletions types/node/v16/test/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ const pl: Module.SourceMapPayload = smap.payload;
const entry: Module.SourceMapping = smap.findEntry(1, 1);

// global
{
const importmeta: ImportMeta = {} as any; // Fake because we cannot really access the true `import.meta` with the current build target
importmeta.url; // $ExpectType string
importmeta.resolve!("local", "/parent"); // $ExpectType Promise<string>
importmeta.resolve!("local", new URL("https://parent.module")); // $ExpectType Promise<string>
}

{
const resolve: Module.ResolveHook = async (specifier, context, nextResolve) => {
const { parentURL = null } = context;
Expand Down
3 changes: 2 additions & 1 deletion types/node/v16/tsconfig.dom.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"files": [
"index.d.ts",
"node-tests.ts"
"node-tests.ts",
"node-tests-dom.ts"
],
"compilerOptions": {
"module": "commonjs",
Expand Down
3 changes: 2 additions & 1 deletion types/node/v16/tsconfig.non-dom.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"files": [
"index.d.ts",
"node-tests.ts"
"node-tests.ts",
"node-tests-non-dom.ts"
],
"compilerOptions": {
"module": "commonjs",
Expand Down
21 changes: 7 additions & 14 deletions types/node/v18/module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,22 +272,15 @@ declare module "module" {
static register<Data = any>(specifier: string | URL, options?: RegisterOptions<Data>): void;
constructor(id: string, parent?: Module);
}
type ImportMetaDOMCompat = typeof globalThis extends { onmessage: any } ? {
resolve(specifier: string): string;
}
: {
resolve?(specifier: string, parent?: string | URL): Promise<string>;
};
global {
interface ImportMeta {
interface ImportMeta extends ImportMetaDOMCompat {
url: string;
/**
* @experimental
* This feature is only available with the `--experimental-import-meta-resolve`
* command flag enabled.
*
* Provides a module-relative resolution function scoped to each module, returning
* the URL string.
*
* @param specified The module specifier to resolve relative to `parent`.
* @param parent The absolute parent module URL to resolve from. If none
* is specified, the value of `import.meta.url` is used as the default.
*/
resolve?(specified: string, parent?: string | URL): Promise<string>;
}
}
export = Module;
Expand Down
1 change: 1 addition & 0 deletions types/node/v18/node-tests-dom.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./test/events-dom";
import "./test/globals-dom";
import "./test/perf_hooks-dom";
import "./test/module-dom";
1 change: 1 addition & 0 deletions types/node/v18/node-tests-non-dom.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./test/events-non-dom";
import "./test/globals-non-dom";
import "./test/perf_hooks-non-dom";
import "./test/module-non-dom";
8 changes: 8 additions & 0 deletions types/node/v18/test/module-dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Module = require("node:module");
import { URL } from "node:url";
// global
{
const importmeta: ImportMeta = {} as any; // Fake because we cannot really access the true `import.meta` with the current build target
importmeta.url; // $ExpectType string
importmeta.resolve!("local"); // $ExpectType Promise<string> || string
}
10 changes: 10 additions & 0 deletions types/node/v18/test/module-non-dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Module = require("node:module");
import { URL } from "node:url";
// global
{
const importmeta: ImportMeta = {} as any; // Fake because we cannot really access the true `import.meta` with the current build target
importmeta.url; // $ExpectType string
importmeta.resolve!("local"); // $ExpectType Promise<string>
importmeta.resolve!("local", "/parent"); // $ExpectType Promise<string>
importmeta.resolve!("local", new URL("https://parent.module")); // $ExpectType Promise<string>
}
7 changes: 0 additions & 7 deletions types/node/v18/test/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ const pl: Module.SourceMapPayload = smap.payload;
const entry: Module.SourceMapping = smap.findEntry(1, 1);

// global
{
const importmeta: ImportMeta = {} as any; // Fake because we cannot really access the true `import.meta` with the current build target
importmeta.url; // $ExpectType string
importmeta.resolve!("local", "/parent"); // $ExpectType Promise<string>
importmeta.resolve!("local", new URL("https://parent.module")); // $ExpectType Promise<string>
}

{
const resolve: Module.ResolveHook = async (specifier, context, nextResolve) => {
const { parentURL = null } = context;
Expand Down