Skip to content

Fix generating module specifiers verbatim from exports #1087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
2 changes: 1 addition & 1 deletion internal/modulespecifiers/specifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ func tryGetModuleNameAsNodeModule(
return "" // File is under this package.json, but is not publicly exported - there's no way to name it via `node_modules` resolution
}
if verbatimFromExports {
return moduleFileName
return moduleFileToTry
}
//}
if len(packageRootPath) > 0 {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ export const c = makeC();
import { C } from "pkg";
export declare function makeC(): C;
//// [index.d.ts]
export declare const c: any;
export declare const c: import("pkg").C;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ export declare const e: typeof import("inner/mjs");
export declare const a: Promise<typeof import("./index.cts")>;
export declare const b: Promise<typeof import("package/mjs", { with: { "resolution-mode": "import" } })>;
export declare const c: Promise<typeof import("package", { with: { "resolution-mode": "import" } })>;
export declare const f: Promise<typeof import("inner", { with: { "resolution-mode": "import" } })>;
export declare const f: Promise<typeof import("inner")>;
//// [other2.d.cts]
// cjs format file, no TLA
export declare const d: Promise<typeof import("inner/cjs", { with: { "resolution-mode": "import" } })>;
export declare const d: Promise<typeof import("inner/cjs")>;
export declare const e: Promise<typeof import("inner/mjs", { with: { "resolution-mode": "import" } })>;
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@
- cjsMain: true;
- default: typeof import("inner");
-}>;
+export declare const f: Promise<typeof import("inner", { with: { "resolution-mode": "import" } })>;
+export declare const f: Promise<typeof import("inner")>;
//// [other2.d.cts]
-export declare const d: Promise<{
- cjsNonmain: true;
- default: typeof import("inner/cjs");
-}>;
+// cjs format file, no TLA
+export declare const d: Promise<typeof import("inner/cjs", { with: { "resolution-mode": "import" } })>;
+export declare const d: Promise<typeof import("inner/cjs")>;
export declare const e: Promise<typeof import("inner/mjs", { with: { "resolution-mode": "import" } })>;
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ export const c = import("package");
>"package" : "package"

export const f = import("inner");
>f : Promise<typeof import("./node_modules/inner")>
>import("inner") : Promise<typeof import("./node_modules/inner")>
>f : Promise<typeof import("inner")>
>import("inner") : Promise<typeof import("inner")>
>"inner" : "inner"

=== other2.cts ===
// cjs format file, no TLA
export const d = import("inner/cjs");
>d : Promise<typeof import("./node_modules/inner/index.d.cts")>
>import("inner/cjs") : Promise<typeof import("./node_modules/inner/index.d.cts")>
>d : Promise<typeof import("inner/cjs")>
>import("inner/cjs") : Promise<typeof import("inner/cjs")>
>"inner/cjs" : "inner/cjs"

export const e = import("inner/mjs");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,17 @@
export const f = import("inner");
->f : Promise<{ cjsMain: true; default: typeof import("node_modules/inner/index"); }>
->import("inner") : Promise<{ cjsMain: true; default: typeof import("node_modules/inner/index"); }>
+>f : Promise<typeof import("./node_modules/inner")>
+>import("inner") : Promise<typeof import("./node_modules/inner")>
+>f : Promise<typeof import("inner")>
+>import("inner") : Promise<typeof import("inner")>
>"inner" : "inner"

=== other2.cts ===
// cjs format file, no TLA
export const d = import("inner/cjs");
->d : Promise<{ cjsNonmain: true; default: typeof import("node_modules/inner/index"); }>
->import("inner/cjs") : Promise<{ cjsNonmain: true; default: typeof import("node_modules/inner/index"); }>
+>d : Promise<typeof import("./node_modules/inner/index.d.cts")>
+>import("inner/cjs") : Promise<typeof import("./node_modules/inner/index.d.cts")>
+>d : Promise<typeof import("inner/cjs")>
+>import("inner/cjs") : Promise<typeof import("inner/cjs")>
>"inner/cjs" : "inner/cjs"

export const e = import("inner/mjs");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ export declare const b: Promise<typeof import("package/mjs", { with: { "resoluti
export declare const c: Promise<typeof import("package", { with: { "resolution-mode": "import" } })>;
export declare const f: Promise<{
cjsMain: true;
default: typeof import("inner", { with: { "resolution-mode": "import" } });
default: typeof import("inner");
}>;
//// [other2.d.cts]
// cjs format file, no TLA
export declare const d: Promise<{
cjsNonmain: true;
default: typeof import("inner/cjs", { with: { "resolution-mode": "import" } });
default: typeof import("inner/cjs");
}>;
export declare const e: Promise<typeof import("inner/mjs", { with: { "resolution-mode": "import" } })>;
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,11 @@
}>;
export declare const b: Promise<typeof import("package/mjs", { with: { "resolution-mode": "import" } })>;
export declare const c: Promise<typeof import("package", { with: { "resolution-mode": "import" } })>;
export declare const f: Promise<{
cjsMain: true;
- default: typeof import("inner");
+ default: typeof import("inner", { with: { "resolution-mode": "import" } });
@@= skipped -16, +18 lines =@@
default: typeof import("inner");
}>;
//// [other2.d.cts]
+// cjs format file, no TLA
export declare const d: Promise<{
cjsNonmain: true;
- default: typeof import("inner/cjs");
+ default: typeof import("inner/cjs", { with: { "resolution-mode": "import" } });
}>;
export declare const e: Promise<typeof import("inner/mjs", { with: { "resolution-mode": "import" } })>;
default: typeof import("inner/cjs");
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ export const c = import("package");
>"package" : "package"

export const f = import("inner");
>f : Promise<{ cjsMain: true; default: typeof import("./node_modules/inner"); }>
>import("inner") : Promise<{ cjsMain: true; default: typeof import("./node_modules/inner"); }>
>f : Promise<{ cjsMain: true; default: typeof import("inner"); }>
>import("inner") : Promise<{ cjsMain: true; default: typeof import("inner"); }>
>"inner" : "inner"

=== other2.cts ===
// cjs format file, no TLA
export const d = import("inner/cjs");
>d : Promise<{ cjsNonmain: true; default: typeof import("./node_modules/inner/index.d.cts"); }>
>import("inner/cjs") : Promise<{ cjsNonmain: true; default: typeof import("./node_modules/inner/index.d.cts"); }>
>d : Promise<{ cjsNonmain: true; default: typeof import("inner/cjs"); }>
>import("inner/cjs") : Promise<{ cjsNonmain: true; default: typeof import("inner/cjs"); }>
>"inner/cjs" : "inner/cjs"

export const e = import("inner/mjs");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,17 @@
export const f = import("inner");
->f : Promise<{ cjsMain: true; default: typeof import("node_modules/inner/index"); }>
->import("inner") : Promise<{ cjsMain: true; default: typeof import("node_modules/inner/index"); }>
+>f : Promise<{ cjsMain: true; default: typeof import("./node_modules/inner"); }>
+>import("inner") : Promise<{ cjsMain: true; default: typeof import("./node_modules/inner"); }>
+>f : Promise<{ cjsMain: true; default: typeof import("inner"); }>
+>import("inner") : Promise<{ cjsMain: true; default: typeof import("inner"); }>
>"inner" : "inner"

=== other2.cts ===
// cjs format file, no TLA
export const d = import("inner/cjs");
->d : Promise<{ cjsNonmain: true; default: typeof import("node_modules/inner/index"); }>
->import("inner/cjs") : Promise<{ cjsNonmain: true; default: typeof import("node_modules/inner/index"); }>
+>d : Promise<{ cjsNonmain: true; default: typeof import("./node_modules/inner/index.d.cts"); }>
+>import("inner/cjs") : Promise<{ cjsNonmain: true; default: typeof import("./node_modules/inner/index.d.cts"); }>
+>d : Promise<{ cjsNonmain: true; default: typeof import("inner/cjs"); }>
+>import("inner/cjs") : Promise<{ cjsNonmain: true; default: typeof import("inner/cjs"); }>
>"inner/cjs" : "inner/cjs"

export const e = import("inner/mjs");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
index.ts(2,23): error TS2307: Cannot find module 'inner/other.js' or its corresponding type declarations.
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.


==== index.ts (2 errors) ====
==== index.ts (1 errors) ====
// esm format file
import { Thing } from "inner/other.js"; // should fail
~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'inner/other.js' 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.
==== node_modules/inner/index.d.ts (0 errors) ====
// esm format file
export { x } from "./other.js";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ export const a = (await import("inner")).x();


//// [index.d.ts]
export declare const a: any;
export declare const a: import("inner/other").Thing;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { Thing } from "inner/other.js"; // should fail
>Thing : any

export const a = (await import("inner")).x();
>a : import("./node_modules/inner/other.js").Thing
>(await import("inner")).x() : import("./node_modules/inner/other.js").Thing
>(await import("inner")).x : () => import("./node_modules/inner/other.js").Thing
>a : import("inner/other").Thing
>(await import("inner")).x() : import("inner/other").Thing
>(await import("inner")).x : () => import("inner/other").Thing
>(await import("inner")) : typeof import("inner")
>await import("inner") : typeof import("inner")
>import("inner") : Promise<typeof import("inner")>
>"inner" : "inner"
>x : () => import("./node_modules/inner/other.js").Thing
>x : () => import("inner/other").Thing

=== node_modules/inner/index.d.ts ===
// esm format file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
->(await import("inner")) : typeof import("node_modules/inner/index")
->await import("inner") : typeof import("node_modules/inner/index")
->import("inner") : Promise<typeof import("node_modules/inner/index")>
+>a : import("./node_modules/inner/other.js").Thing
+>(await import("inner")).x() : import("./node_modules/inner/other.js").Thing
+>(await import("inner")).x : () => import("./node_modules/inner/other.js").Thing
+>a : import("inner/other").Thing
+>(await import("inner")).x() : import("inner/other").Thing
+>(await import("inner")).x : () => import("inner/other").Thing
+>(await import("inner")) : typeof import("inner")
+>await import("inner") : typeof import("inner")
+>import("inner") : Promise<typeof import("inner")>
>"inner" : "inner"
->x : () => import("node_modules/inner/other").Thing
+>x : () => import("./node_modules/inner/other.js").Thing
+>x : () => import("inner/other").Thing

=== node_modules/inner/index.d.ts ===
// esm format file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
index.ts(2,23): error TS2307: Cannot find module 'inner/other.js' or its corresponding type declarations.
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.


==== index.ts (2 errors) ====
==== index.ts (1 errors) ====
// esm format file
import { Thing } from "inner/other.js"; // should fail
~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'inner/other.js' 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.
==== node_modules/inner/index.d.ts (0 errors) ====
// esm format file
export { x } from "./other.js";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ exports.a = (await import("inner")).x();


//// [index.d.ts]
export declare const a: any;
export declare const a: import("inner/other").Thing;
Loading