Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

--moduleResolution bundler (formerly known as hybrid) #51669

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 65 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
e9f0a1a
WIP
andrewbranch Jul 28, 2022
5f9cf9d
Add extension error back unless noEmit is set
andrewbranch Jul 29, 2022
2421cf5
Add non-relative tests
andrewbranch Jul 29, 2022
660026e
Add error for importing from declaration file
andrewbranch Jul 29, 2022
2daa136
Merge branch 'main' into module-resolution/minimal
andrewbranch Sep 14, 2022
f49a368
Update unit test
andrewbranch Sep 14, 2022
af03675
Add explicit flag for importing from .ts extensions
andrewbranch Sep 14, 2022
496ef99
Add module specifier resolution changes
andrewbranch Sep 15, 2022
458c125
Add auto-import tests
andrewbranch Sep 19, 2022
7d64928
Disallow relative imports into node_modules
andrewbranch Sep 26, 2022
0249e0a
Ensure auto-imports don’t suggest ./node_modules;
andrewbranch Sep 26, 2022
6242ee3
Test a non-portable declaration emit issue
andrewbranch Sep 26, 2022
6cc0e18
Test auto-importing TSX file
andrewbranch Sep 26, 2022
240533a
Update path completions
andrewbranch Sep 26, 2022
eb9a4bb
Merge branch 'main' into module-resolution/minimal
andrewbranch Sep 26, 2022
619843e
Fix lint due to merge
andrewbranch Sep 27, 2022
2ceb4bc
Remove minimal-specific stuff
andrewbranch Oct 13, 2022
aad7fe7
Remove minimal tests
andrewbranch Oct 13, 2022
7fd3e72
Update unit tests
andrewbranch Oct 13, 2022
7cca6f3
Merge branch 'main' into module-resolution/ts-extensions
andrewbranch Oct 14, 2022
ea12012
Merge branch 'main' into module-resolution/ts-extensions
andrewbranch Oct 25, 2022
8655cf9
Merge branch 'main' into module-resolution/ts-extensions
andrewbranch Nov 7, 2022
86dd5da
Add options
andrewbranch Oct 20, 2022
8846f31
Add customConditions option
andrewbranch Oct 21, 2022
9bc0f07
Add first tests
andrewbranch Oct 24, 2022
4545afb
CJS constructs are not allowed
andrewbranch Oct 24, 2022
e82e61d
Add another test
andrewbranch Oct 24, 2022
038783d
Fix extension adding/replacing priority
andrewbranch Oct 25, 2022
c55c454
Merge branch 'main' into module-resolution/ts-extensions
andrewbranch Nov 8, 2022
870d807
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Nov 8, 2022
6e1989e
Merge branch 'main' into module-resolution/ts-extensions
andrewbranch Nov 15, 2022
a482180
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Nov 15, 2022
89bcd01
Update test to reflect the choice not to block on unrecognized extens…
andrewbranch Nov 16, 2022
6074661
Add auto-imports and string completions tests
andrewbranch Nov 17, 2022
fa188b1
Revamp string completions ending preferences
andrewbranch Nov 18, 2022
9e03db2
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Nov 18, 2022
c4320a2
Comment test
andrewbranch Nov 18, 2022
f04f1b5
Auto-imports of declaration files cannot use .ts extension
andrewbranch Nov 18, 2022
29039de
Have declaration file auto imports default to extensionless instead
andrewbranch Nov 18, 2022
c6b963b
Merge branch 'main' into module-resolution/ts-extensions
andrewbranch Nov 18, 2022
e83ca2a
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Nov 18, 2022
f98730a
Add test for custom conditions
andrewbranch Nov 18, 2022
5a01dd6
Fix indentation
andrewbranch Nov 18, 2022
4dd6d01
Add baseline showing resolvePackageJsonImports/Exports compatibility
andrewbranch Nov 18, 2022
7225671
Merge branch 'main' into module-resolution/ts-extensions
andrewbranch Nov 28, 2022
81b9e70
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Nov 28, 2022
f6fa5f3
Fix test and prevent CJS require from resolving
andrewbranch Nov 28, 2022
aeb23be
Update unit test baselines
andrewbranch Nov 28, 2022
3b1d554
Merge branch 'main' into module-resolution/ts-extensions
andrewbranch Dec 5, 2022
e0c0375
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Dec 5, 2022
f9414aa
Fix bad merge conflict resolution
andrewbranch Dec 5, 2022
dadc1a8
Make resolvedUsingTsExtension optional
andrewbranch Dec 5, 2022
5909643
Merge branch 'main' into module-resolution/ts-extensions
andrewbranch Dec 5, 2022
5089aab
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Dec 5, 2022
a88b8ad
Update missed baselines
andrewbranch Dec 6, 2022
c3575de
Merge branch 'main' into module-resolution/ts-extensions
andrewbranch Dec 6, 2022
224bb10
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Dec 6, 2022
b2e283c
Revert now-unnecessary API implementation changes
andrewbranch Dec 6, 2022
30afa86
Clean up
andrewbranch Dec 9, 2022
c4ba4a5
Merge branch 'main' into module-resolution/ts-extensions
andrewbranch Dec 9, 2022
0baca5b
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Dec 9, 2022
6e763d9
Update baselines to es5 emit
andrewbranch Dec 9, 2022
4e73a46
Merge branch 'main' into module-resolution/ts-extensions
andrewbranch Dec 13, 2022
22fbb44
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Dec 13, 2022
d4a3b3c
Rename to `bundler`
andrewbranch Dec 13, 2022
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
Prev Previous commit
Next Next commit
Add explicit flag for importing from .ts extensions
  • Loading branch information
andrewbranch committed Sep 14, 2022
commit af03675a085d6b799b8b7ce7e8f6f4baf4008ea9
4 changes: 2 additions & 2 deletions 4 src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3620,9 +3620,9 @@ namespace ts {
getSuggestedImportSource(Debug.checkDefined(tryExtractTSExtension(moduleReference))));
}
}
else if (resolvedModule.resolvedUsingTsExtension && !shouldAllowTsExtension(compilerOptions)) {
else if (resolvedModule.resolvedUsingTsExtension && !shouldAllowImportingTsExtension(compilerOptions, currentSourceFile.fileName)) {
const tsExtension = Debug.checkDefined(tryExtractTSExtension(moduleReference));
errorOnTSExtensionImport(tsExtension);
error(errorNode, Diagnostics.An_import_path_can_only_end_with_a_0_extension_when_allowImportingTsExtensions_is_enabled, tsExtension);
}

if (sourceFile.symbol) {
Expand Down
8 changes: 8 additions & 0 deletions 8 src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,14 @@ namespace ts {
category: Diagnostics.Modules,
description: Diagnostics.List_of_file_name_suffixes_to_search_when_resolving_a_module,
},
{
name: "allowImportingTsExtensions",
type: "boolean",
affectsModuleResolution: true,
category: Diagnostics.Modules,
description: Diagnostics.Allow_imports_to_include_TypeScript_file_extensions_Requires_moduleResolution_minimal_and_either_noEmit_or_emitDeclarationOnly_to_be_set,
defaultValueDescription: false,
},

// Source Maps
{
Expand Down
16 changes: 12 additions & 4 deletions 16 src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4229,6 +4229,14 @@
"category": "Error",
"code": 5095
},
"Option 'allowImportingTsExtensions' can only be used when 'moduleResolution' is set to 'minimal' and either 'noEmit' or 'emitDeclarationOnly' is set.": {
"category": "Error",
"code": 5096
},
"An import path can only end with a '{0}' extension when 'allowImportingTsExtensions' is enabled.": {
"category": "Error",
"code": 5097
},

"Generates a sourcemap for each corresponding '.d.ts' file.": {
"category": "Message",
Expand Down Expand Up @@ -4451,10 +4459,6 @@
"category": "Message",
"code": 6066
},
"Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6).": {
"category": "Message",
"code": 6069
},
"Initializes a TypeScript project and creates a tsconfig.json file.": {
"category": "Message",
"code": 6070
Expand Down Expand Up @@ -5418,6 +5422,10 @@
"category": "Message",
"code": 6401
},
"Allow imports to include TypeScript file extensions. Requires '--moduleResolution minimal' and either '--noEmit' or '--emitDeclarationOnly' to be set.": {
"category": "Message",
"code": 6402
},

"The expected type comes from property '{0}' which is declared here on type '{1}'": {
"category": "Message",
Expand Down
8 changes: 6 additions & 2 deletions 8 src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2716,8 +2716,12 @@ namespace ts {
return getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Minimal;
}

export function shouldAllowTsExtension(compilerOptions: CompilerOptions) {
return shouldResolveTsExtension(compilerOptions) && !!compilerOptions.noEmit;
// Program errors validate that `noEmit` or `emitDeclarationOnly` is also set,
// so this function doesn't check them to avoid propagating errors.
export function shouldAllowImportingTsExtension(compilerOptions: CompilerOptions, fromFileName?: string) {
return shouldResolveTsExtension(compilerOptions) && (
!!compilerOptions.allowImportingTsExtensions ||
fromFileName && isDeclarationFileName(fromFileName));
}

/**
Expand Down
4 changes: 4 additions & 0 deletions 4 src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3657,6 +3657,10 @@ namespace ts {
createOptionValueDiagnostic("importsNotUsedAsValues", Diagnostics.Option_preserveValueImports_can_only_be_used_when_module_is_set_to_es2015_or_later);
}

if (options.allowImportingTsExtensions && !(getEmitModuleResolutionKind(options) === ModuleResolutionKind.Minimal && (options.noEmit || options.emitDeclarationOnly))) {
createOptionValueDiagnostic("allowImportingTsExtensions", Diagnostics.Option_allowImportingTsExtensions_can_only_be_used_when_moduleResolution_is_set_to_minimal_and_either_noEmit_or_emitDeclarationOnly_is_set);
}

// If the emit is enabled make sure that every output file is unique and not overwriting any of the input files
if (!options.noEmit && !options.suppressOutputPathCheck) {
const emitHost = getEmitHost();
Expand Down
1 change: 1 addition & 0 deletions 1 src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6543,6 +6543,7 @@ namespace ts {

export interface CompilerOptions {
/*@internal*/ all?: boolean;
allowImportingTsExtensions?: boolean;
allowJs?: boolean;
/*@internal*/ allowNonTsExtensions?: boolean;
allowSyntheticDefaultImports?: boolean;
Expand Down
1 change: 1 addition & 0 deletions 1 src/testRunner/compilerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ namespace Harness {
"module",
"moduleResolution",
"moduleDetection",
"allowImportingTsExtensions",
"target",
"jsx",
"noEmit",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"compilerOptions": {
"moduleResolution": "minimal",
"noEmit": true,
"allowImportingTsExtensions": true,
"baseUrl": ".",
"paths": {
"*": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
error TS5056: Cannot write file 'dist/c.js' because it would be overwritten by multiple input files.
error TS6231: Could not resolve the path '/project/e' with the extensions: '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'.
The file is in the program because:
Root file specified for compilation
error TS6504: File '/project/b.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
The file is in the program because:
Root file specified for compilation
/project/main.ts(1,16): error TS2307: Cannot find module './a' or its corresponding type declarations.
/project/main.ts(3,16): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.
/project/main.ts(5,16): error TS2307: Cannot find module './b' or its corresponding type declarations.
/project/main.ts(7,16): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.
/project/main.ts(8,16): error TS2845: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './b.js' instead?
/project/main.ts(11,16): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.
/project/main.ts(12,16): error TS5097: An import path can only end with a '.tsx' extension when 'allowImportingTsExtensions' is enabled.
/project/main.ts(12,16): error TS6142: Module './c.tsx' was resolved to '/project/c.tsx', but '--jsx' is not set.
/project/main.ts(14,16): error TS2307: Cannot find module './d' or its corresponding type declarations.
/project/main.ts(15,16): error TS2307: Cannot find module './d/index' or its corresponding type declarations.
/project/main.ts(16,16): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.
/project/main.ts(18,16): error TS2307: Cannot find module './e' or its corresponding type declarations.
/project/types.d.ts(2,16): error TS2691: An import path cannot end with a '.d.ts' extension. Consider importing './a.js' instead.
/project/types.d.ts(3,21): error TS2691: An import path cannot end with a '.d.ts' extension. Consider importing './a.js' instead.


!!! error TS5056: Cannot write file 'dist/c.js' because it would be overwritten by multiple input files.
!!! error TS6231: Could not resolve the path '/project/e' with the extensions: '.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'.
!!! error TS6231: The file is in the program because:
!!! error TS6231: Root file specified for compilation
!!! error TS6504: File '/project/b.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
!!! error TS6504: The file is in the program because:
!!! error TS6504: Root file specified for compilation
==== /project/a.ts (0 errors) ====
export {};

==== /project/b.ts (0 errors) ====
export {};

==== /project/b.js (0 errors) ====
export {};

==== /project/b.d.ts (0 errors) ====
export {};

==== /project/c.ts (0 errors) ====
export {};

==== /project/c.tsx (0 errors) ====
export {};

==== /project/d/index.ts (0 errors) ====
export {};

==== /project/e (0 errors) ====
export {};

==== /project/main.ts (12 errors) ====
import {} from "./a";
~~~~~
!!! error TS2307: Cannot find module './a' or its corresponding type declarations.
import {} from "./a.js";
import {} from "./a.ts";
~~~~~~~~
!!! error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.

import {} from "./b";
~~~~~
!!! error TS2307: Cannot find module './b' or its corresponding type declarations.
import {} from "./b.js";
import {} from "./b.ts";
~~~~~~~~
!!! error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.
import {} from "./b.d.ts";
~~~~~~~~~~
!!! error TS2845: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './b.js' instead?
import type {} from "./b.d.ts";

import {} from "./c.ts";
~~~~~~~~
!!! error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.
import {} from "./c.tsx";
~~~~~~~~~
!!! error TS5097: An import path can only end with a '.tsx' extension when 'allowImportingTsExtensions' is enabled.
~~~~~~~~~
!!! error TS6142: Module './c.tsx' was resolved to '/project/c.tsx', but '--jsx' is not set.

import {} from "./d";
~~~~~
!!! error TS2307: Cannot find module './d' or its corresponding type declarations.
import {} from "./d/index";
~~~~~~~~~~~
!!! error TS2307: Cannot find module './d/index' or its corresponding type declarations.
import {} from "./d/index.ts";
~~~~~~~~~~~~~~
!!! error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.

import {} from "./e";
~~~~~
!!! error TS2307: Cannot find module './e' or its corresponding type declarations.

==== /project/types.d.ts (2 errors) ====
import {} from "./a.ts";
import {} from "./a.d.ts";
~~~~~~~~~~
!!! error TS2691: An import path cannot end with a '.d.ts' extension. Consider importing './a.js' instead.
import type {} from "./a.d.ts";
~~~~~~~~~~
!!! error TS2691: An import path cannot end with a '.d.ts' extension. Consider importing './a.js' instead.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//// [tests/cases/conformance/moduleResolution/minimal_relative.ts] ////

//// [a.ts]
export {};

//// [b.ts]
export {};

//// [b.js]
export {};

//// [b.d.ts]
export {};

//// [c.ts]
export {};

//// [c.tsx]
export {};

//// [index.ts]
export {};

//// [e]
export {};

//// [main.ts]
import {} from "./a";
import {} from "./a.js";
import {} from "./a.ts";

import {} from "./b";
import {} from "./b.js";
import {} from "./b.ts";
import {} from "./b.d.ts";
import type {} from "./b.d.ts";

import {} from "./c.ts";
import {} from "./c.tsx";

import {} from "./d";
import {} from "./d/index";
import {} from "./d/index.ts";

import {} from "./e";

//// [types.d.ts]
import {} from "./a.ts";
import {} from "./a.d.ts";
import type {} from "./a.d.ts";


//// [a.js]
"use strict";
exports.__esModule = true;
//// [b.js]
"use strict";
exports.__esModule = true;
//// [index.js]
"use strict";
exports.__esModule = true;
//// [main.js]
"use strict";
exports.__esModule = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
=== /project/a.ts ===
export {};
No type information for this code.
No type information for this code.=== /project/b.ts ===
export {};
No type information for this code.
No type information for this code.=== /project/b.d.ts ===
export {};
No type information for this code.
No type information for this code.=== /project/c.ts ===
export {};
No type information for this code.
No type information for this code.=== /project/c.tsx ===
export {};
No type information for this code.
No type information for this code.=== /project/d/index.ts ===
export {};
No type information for this code.
No type information for this code.=== /project/main.ts ===
import {} from "./a";
No type information for this code.import {} from "./a.js";
No type information for this code.import {} from "./a.ts";
No type information for this code.
No type information for this code.import {} from "./b";
No type information for this code.import {} from "./b.js";
No type information for this code.import {} from "./b.ts";
No type information for this code.import {} from "./b.d.ts";
No type information for this code.import type {} from "./b.d.ts";
No type information for this code.
No type information for this code.import {} from "./c.ts";
No type information for this code.import {} from "./c.tsx";
No type information for this code.
No type information for this code.import {} from "./d";
No type information for this code.import {} from "./d/index";
No type information for this code.import {} from "./d/index.ts";
No type information for this code.
No type information for this code.import {} from "./e";
No type information for this code.
No type information for this code.=== /project/types.d.ts ===
import {} from "./a.ts";
No type information for this code.import {} from "./a.d.ts";
No type information for this code.import type {} from "./a.d.ts";
No type information for this code.
No type information for this code.
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.