Skip to content

Commit

Permalink
Allow exports map entries to point at .ts source files (#48563)
Browse files Browse the repository at this point in the history
* Probably works

* Add tests

* Update baselines for module option rename
  • Loading branch information
weswigham committed Jun 15, 2022
1 parent ba38fe1 commit ccd8b1d
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 0 deletions.
@@ -0,0 +1,34 @@
tests/cases/conformance/node/index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations.
tests/cases/conformance/node/index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary.


==== tests/cases/conformance/node/index.ts (2 errors) ====
// esm format file
import { Thing } from "inner/other";
~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations.
export const a = (await import("inner")).x();
~
!!! error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary.
import {a as a2} from "package";
==== tests/cases/conformance/node/node_modules/inner/index.ts (0 errors) ====
// esm format file
export { x } from "./other.js";
==== tests/cases/conformance/node/node_modules/inner/other.ts (0 errors) ====
// esm format file
export interface Thing {}
export const x: () => Thing = null as any;
==== tests/cases/conformance/node/package.json (0 errors) ====
{
"name": "package",
"private": true,
"type": "module",
"exports": "./index.ts"
}
==== tests/cases/conformance/node/node_modules/inner/package.json (0 errors) ====
{
"name": "inner",
"private": true,
"type": "module",
"exports": "./index.ts"
}
@@ -0,0 +1,44 @@
//// [tests/cases/conformance/node/nodeModulesExportsSourceTs.ts] ////

//// [index.ts]
// esm format file
import { Thing } from "inner/other";
export const a = (await import("inner")).x();
import {a as a2} from "package";
//// [index.ts]
// esm format file
export { x } from "./other.js";
//// [other.ts]
// esm format file
export interface Thing {}
export const x: () => Thing = null as any;
//// [package.json]
{
"name": "package",
"private": true,
"type": "module",
"exports": "./index.ts"
}
//// [package.json]
{
"name": "inner",
"private": true,
"type": "module",
"exports": "./index.ts"
}

//// [other.js]
export const x = null;
//// [index.js]
// esm format file
export { x } from "./other.js";
//// [index.js]
export const a = (await import("inner")).x();


//// [other.d.ts]
export interface Thing {
}
export declare const x: () => Thing;
//// [index.d.ts]
export { x } from "./other.js";
@@ -0,0 +1,29 @@
=== tests/cases/conformance/node/index.ts ===
// esm format file
import { Thing } from "inner/other";
>Thing : Symbol(Thing, Decl(index.ts, 1, 8))

export const a = (await import("inner")).x();
>a : Symbol(a, Decl(index.ts, 2, 12))
>(await import("inner")).x : Symbol(x, Decl(index.ts, 1, 8))
>"inner" : Symbol("tests/cases/conformance/node/node_modules/inner/index", Decl(index.ts, 0, 0))
>x : Symbol(x, Decl(index.ts, 1, 8))

import {a as a2} from "package";
>a : Symbol(a, Decl(index.ts, 2, 12))
>a2 : Symbol(a2, Decl(index.ts, 3, 8))

=== tests/cases/conformance/node/node_modules/inner/index.ts ===
// esm format file
export { x } from "./other.js";
>x : Symbol(x, Decl(index.ts, 1, 8))

=== tests/cases/conformance/node/node_modules/inner/other.ts ===
// esm format file
export interface Thing {}
>Thing : Symbol(Thing, Decl(other.ts, 0, 0))

export const x: () => Thing = null as any;
>x : Symbol(x, Decl(other.ts, 2, 12))
>Thing : Symbol(Thing, Decl(other.ts, 0, 0))

@@ -0,0 +1,32 @@
=== tests/cases/conformance/node/index.ts ===
// esm format file
import { Thing } from "inner/other";
>Thing : any

export const a = (await import("inner")).x();
>a : import("tests/cases/conformance/node/node_modules/inner/other").Thing
>(await import("inner")).x() : import("tests/cases/conformance/node/node_modules/inner/other").Thing
>(await import("inner")).x : () => import("tests/cases/conformance/node/node_modules/inner/other").Thing
>(await import("inner")) : typeof import("tests/cases/conformance/node/node_modules/inner/index")
>await import("inner") : typeof import("tests/cases/conformance/node/node_modules/inner/index")
>import("inner") : Promise<typeof import("tests/cases/conformance/node/node_modules/inner/index")>
>"inner" : "inner"
>x : () => import("tests/cases/conformance/node/node_modules/inner/other").Thing

import {a as a2} from "package";
>a : import("tests/cases/conformance/node/node_modules/inner/other").Thing
>a2 : import("tests/cases/conformance/node/node_modules/inner/other").Thing

=== tests/cases/conformance/node/node_modules/inner/index.ts ===
// esm format file
export { x } from "./other.js";
>x : () => import("tests/cases/conformance/node/node_modules/inner/other").Thing

=== tests/cases/conformance/node/node_modules/inner/other.ts ===
// esm format file
export interface Thing {}
export const x: () => Thing = null as any;
>x : () => Thing
>null as any : any
>null : null

@@ -0,0 +1,34 @@
tests/cases/conformance/node/index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations.
tests/cases/conformance/node/index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary.


==== tests/cases/conformance/node/index.ts (2 errors) ====
// esm format file
import { Thing } from "inner/other";
~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations.
export const a = (await import("inner")).x();
~
!!! error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary.
import {a as a2} from "package";
==== tests/cases/conformance/node/node_modules/inner/index.ts (0 errors) ====
// esm format file
export { x } from "./other.js";
==== tests/cases/conformance/node/node_modules/inner/other.ts (0 errors) ====
// esm format file
export interface Thing {}
export const x: () => Thing = null as any;
==== tests/cases/conformance/node/package.json (0 errors) ====
{
"name": "package",
"private": true,
"type": "module",
"exports": "./index.ts"
}
==== tests/cases/conformance/node/node_modules/inner/package.json (0 errors) ====
{
"name": "inner",
"private": true,
"type": "module",
"exports": "./index.ts"
}
@@ -0,0 +1,44 @@
//// [tests/cases/conformance/node/nodeModulesExportsSourceTs.ts] ////

//// [index.ts]
// esm format file
import { Thing } from "inner/other";
export const a = (await import("inner")).x();
import {a as a2} from "package";
//// [index.ts]
// esm format file
export { x } from "./other.js";
//// [other.ts]
// esm format file
export interface Thing {}
export const x: () => Thing = null as any;
//// [package.json]
{
"name": "package",
"private": true,
"type": "module",
"exports": "./index.ts"
}
//// [package.json]
{
"name": "inner",
"private": true,
"type": "module",
"exports": "./index.ts"
}

//// [other.js]
export const x = null;
//// [index.js]
// esm format file
export { x } from "./other.js";
//// [index.js]
export const a = (await import("inner")).x();


//// [other.d.ts]
export interface Thing {
}
export declare const x: () => Thing;
//// [index.d.ts]
export { x } from "./other.js";
@@ -0,0 +1,29 @@
=== tests/cases/conformance/node/index.ts ===
// esm format file
import { Thing } from "inner/other";
>Thing : Symbol(Thing, Decl(index.ts, 1, 8))

export const a = (await import("inner")).x();
>a : Symbol(a, Decl(index.ts, 2, 12))
>(await import("inner")).x : Symbol(x, Decl(index.ts, 1, 8))
>"inner" : Symbol("tests/cases/conformance/node/node_modules/inner/index", Decl(index.ts, 0, 0))
>x : Symbol(x, Decl(index.ts, 1, 8))

import {a as a2} from "package";
>a : Symbol(a, Decl(index.ts, 2, 12))
>a2 : Symbol(a2, Decl(index.ts, 3, 8))

=== tests/cases/conformance/node/node_modules/inner/index.ts ===
// esm format file
export { x } from "./other.js";
>x : Symbol(x, Decl(index.ts, 1, 8))

=== tests/cases/conformance/node/node_modules/inner/other.ts ===
// esm format file
export interface Thing {}
>Thing : Symbol(Thing, Decl(other.ts, 0, 0))

export const x: () => Thing = null as any;
>x : Symbol(x, Decl(other.ts, 2, 12))
>Thing : Symbol(Thing, Decl(other.ts, 0, 0))

@@ -0,0 +1,32 @@
=== tests/cases/conformance/node/index.ts ===
// esm format file
import { Thing } from "inner/other";
>Thing : any

export const a = (await import("inner")).x();
>a : import("tests/cases/conformance/node/node_modules/inner/other").Thing
>(await import("inner")).x() : import("tests/cases/conformance/node/node_modules/inner/other").Thing
>(await import("inner")).x : () => import("tests/cases/conformance/node/node_modules/inner/other").Thing
>(await import("inner")) : typeof import("tests/cases/conformance/node/node_modules/inner/index")
>await import("inner") : typeof import("tests/cases/conformance/node/node_modules/inner/index")
>import("inner") : Promise<typeof import("tests/cases/conformance/node/node_modules/inner/index")>
>"inner" : "inner"
>x : () => import("tests/cases/conformance/node/node_modules/inner/other").Thing

import {a as a2} from "package";
>a : import("tests/cases/conformance/node/node_modules/inner/other").Thing
>a2 : import("tests/cases/conformance/node/node_modules/inner/other").Thing

=== tests/cases/conformance/node/node_modules/inner/index.ts ===
// esm format file
export { x } from "./other.js";
>x : () => import("tests/cases/conformance/node/node_modules/inner/other").Thing

=== tests/cases/conformance/node/node_modules/inner/other.ts ===
// esm format file
export interface Thing {}
export const x: () => Thing = null as any;
>x : () => Thing
>null as any : any
>null : null

28 changes: 28 additions & 0 deletions tests/cases/conformance/node/nodeModulesExportsSourceTs.ts
@@ -0,0 +1,28 @@
// @module: node16,nodenext
// @declaration: true
// @filename: index.ts
// esm format file
import { Thing } from "inner/other";
export const a = (await import("inner")).x();
import {a as a2} from "package";
// @filename: node_modules/inner/index.ts
// esm format file
export { x } from "./other.js";
// @filename: node_modules/inner/other.ts
// esm format file
export interface Thing {}
export const x: () => Thing = null as any;
// @filename: package.json
{
"name": "package",
"private": true,
"type": "module",
"exports": "./index.ts"
}
// @filename: node_modules/inner/package.json
{
"name": "inner",
"private": true,
"type": "module",
"exports": "./index.ts"
}

0 comments on commit ccd8b1d

Please sign in to comment.