116 Commits

Author SHA1 Message Date
Andrew Branch
31bf80ce6b
Fix path completions missing extensions for exports wildcards (#57312) 2024-02-07 15:02:35 -08:00
Andrew Branch
25a4f9e535
Deprioritize declaration emit paths from baseUrl containing node_modules (#57145) 2024-01-23 13:31:15 -08:00
Andrew Branch
6cb6fc94ae
Add --module preserve, support require in --moduleResolution bundler (#56785) 2024-01-19 12:03:24 -08:00
Emma Hamilton
fbcdb8cf4f
Add auto-import for the package.json imports field (#55015)
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
Co-authored-by: Andrew Branch <andrew@wheream.io>
2023-12-21 09:48:03 -08:00
Jake Bailey
1d7c0c977a
Try and deal with CodeQL reports on replace("*", ...) (#56607) 2023-12-05 13:58:56 -08:00
Sheetal Nandi
b6121e400c
Replace disk path operations to use fileNames instead of path (#56476)
Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
2023-11-27 22:21:29 -08:00
Andrew Branch
0ee2db33ca
Fix declaration emit in --moduleResolution bundler using wrong exports conditions (#56265) 2023-10-30 15:39:57 -07:00
Andrew Branch
248488aa06
Prefer local module specifier over relative node_modules ones in auto-import, even when it reaches into a monorepo package (#55969) 2023-10-03 14:10:06 -07:00
Sampo Kivistö
ec2bd4e252
perf: replace String and Array indexOf method calls with includes method call (#55482) 2023-08-25 11:27:55 -07:00
Jake Bailey
5e8c261b6a
dprint the codebase (#54820) 2023-08-16 14:26:38 -07:00
Andrew Branch
22a9ae9eed
Offer auto-imports from wildcard exports with AutoImportProvider (#54831) 2023-07-07 12:50:38 -05:00
Andrew Branch
f4d372aef4
Fix auto import path mapping when first pattern fails (#54868) 2023-07-03 15:02:13 -07:00
Jm
362703a213
Cover more cases for node module auto-import (#54024) 2023-05-09 09:46:55 -07:00
Andrew Branch
818c9806d4
Ensure paths-based resolution does not generate module specifiers with .. in the middle (#53957) 2023-04-21 15:04:16 -07:00
navya9singh
d3bbef390d
'Move to file' refactor (#53542) 2023-04-21 11:48:53 -07:00
Andrew Branch
287ee41cf2
Fix two module specifier ending preference detection issues (#53691) 2023-04-06 13:06:58 -07:00
Andrew Branch
7d8f6eec46
Add cache to auto-import package.json filter (#52422) 2023-02-06 11:33:04 -08:00
Andrew Branch
1da47255fa
Fix auto-imports of aliased packages with exports (#52538) 2023-02-01 09:49:38 -08:00
Andrew Branch
5e8bf480e4
Fix auto-imports with --moduleResolution bundler and customConditions (#52423) 2023-01-26 09:44:07 -08:00
Wesley Wigham
89e928e8b4
Add --allowArbitraryExtensions, a flag for allowing arbitrary extensions on import paths (#51435) 2023-01-09 17:12:42 -08:00
Andrew Branch
a5dde88dce
--moduleResolution bundler (formerly known as hybrid) (#51669)
* WIP

* Add extension error back unless noEmit is set

* Add non-relative tests

* Add error for importing from declaration file

* Update unit test

* Add explicit flag for importing from .ts extensions

* Add module specifier resolution changes

* Add auto-import tests

* Disallow relative imports into node_modules

* Ensure auto-imports don’t suggest ./node_modules;

* Test a non-portable declaration emit issue

* Test auto-importing TSX file

* Update path completions

* Fix lint due to merge

* Remove minimal-specific stuff

* Remove minimal tests

* Update unit tests

* Add options

* Add customConditions option

* Add first tests

* CJS constructs are not allowed

* Add another test

* Fix extension adding/replacing priority

* Update test to reflect the choice not to block on unrecognized extensions

* Add auto-imports and string completions tests

* Revamp string completions ending preferences

* Comment test

* Auto-imports of declaration files cannot use .ts extension

* Have declaration file auto imports default to extensionless instead

* Add test for custom conditions

* Fix indentation

* Add baseline showing resolvePackageJsonImports/Exports compatibility

* Fix test and prevent CJS require from resolving

* Update unit test baselines

* Fix bad merge conflict resolution

* Make resolvedUsingTsExtension optional

* Update missed baselines

* Revert now-unnecessary API implementation changes

* Clean up

* Update baselines to es5 emit

* Rename to `bundler`
2022-12-13 13:35:16 -08:00
Isabel Duan
ae9c671d59
(fix #50725, #50710) add file extensions in import statements (#51702)
* fixes #50725

* fixed 50710

* fixed broken test

* clean up

* variable rename

* rename variable to newFileBaseName
2022-12-06 09:28:10 -08:00
Jake Bailey
00dc0b6674
Flip imports to case insensitive sorting (#51579) 2022-11-17 15:35:28 -08:00
Jake Bailey
2d2a4343b8
Reformat imports to be one identifier per line (#51565) 2022-11-17 13:42:18 -08:00
Andrew Branch
89ce16ccfd
Fix auto-import when paths points to project reference redirect (#51492)
* Fix auto-import when `paths` points to project reference redirect

* Put paths specifiers to redirects in lower priority bucket
2022-11-15 14:19:15 -08:00
Jake Bailey
fbdf00ce12
Undo accidental style changes from Map/Set PR (#51529) 2022-11-14 14:52:00 -08:00
Sheetal Nandi
c5aea89230
Add alias ResolutionMode for ModuleKind.ESNext | ModuleKind.CommonJs | undefined (#51482)
* Add alias ResolutionMode for ModuleKind.ESNext | ModuleKind.CommonJs | undefined

* ResolutionMode | undefined = ResolutionMode

* More
2022-11-10 16:47:46 -08:00
Jake Bailey
9f64a3a58c
Remove ts.{Map,Set,ESMap,Iterator} and associated types (#51439) 2022-11-09 15:06:31 -08:00
Jake Bailey
d12116d8da Fix all internal JSDoc comments
If these are regular comments, then they won't appear in our d.ts files.
But, now we are relying on an external d.ts bundler to produce our final
merged, so they need to be present in the "input" d.ts files, meaning
they have to be JSDoc comments.

These comments only work today because all of our builds load their TS
files from scratch, so they see the actual source files and their
non-JSDoc comments.

The comments also need to be attached to a declaration, not floating,
otherwise they won't be used by api-extractor, so move them if needed.
2022-11-07 13:34:44 -08:00
Jake Bailey
07758c08ab Generated module conversion step - inlineImports
This step converts as many explicit accesses as possible in favor of direct imports from the modules in which things were declared. This restores the code (as much as possible) back to how it looked originally before the explicitify step, e.g. instead of "ts.Node" and "ts.Symbol", we have just "Node" and "Symbol".
2022-11-07 13:33:07 -08:00
Jake Bailey
b6c0538826 Generated module conversion step - stripNamespaces
This step converts each file into an exported module by hoisting the namespace bodies into the global scope and transferring internal markers down onto declarations as needed.

The namespaces are reconstructed as "barrel"-style modules, which are identical to the old namespace objects in structure. These reconstructed namespaces are then imported in the newly module-ified files, making existing expressions like "ts." valid.
2022-11-07 13:32:03 -08:00
Jake Bailey
9a0b85ce2a Generated module conversion step - explicitify
This step makes all implicit namespace accesses explicit, e.g. "Node" turns into "ts.Node".
2022-11-07 13:29:05 -08:00
Jake Bailey
94724a8c2e Generated module conversion step - unindent
This step makes further commits look clearer by unindenting all of the top level namespaces preemptively.
2022-11-07 13:28:13 -08:00
Andrew Branch
ef69116c41
Generate shortest rootDirs module specifier instead of first possible (#51244)
* Generate shortest rootDirs module specifier instead of first possible

* Simplify `min`
2022-10-21 16:05:58 -07:00
Sheetal Nandi
6b890f93c4
Handle more places where package direcroy is converted to canonical file path (#50740)
* Add test for node16 resolution with package json lookup making casing incorrect

* Handle more places where package direcroy is converted to canonical file path
2022-09-12 15:11:35 -07:00
Andrew Branch
c82c9a9744
Fix bugs in module specifier generation with paths/typesVersions (#49792)
* Write a test and a huge comment

* Finish fixing everything

* Clean up comment

* Remove obsolete comment

* Fix comment trailing off

* Optimize to hit the file system much less
2022-08-03 13:58:15 -07:00
Andrew Branch
f3f0a3f394
Fix module specifier generation crash from typesVersions (#49035) 2022-05-09 12:48:24 -07:00
Andrew Branch
2ffe6864b1
Respect importModuleSpecifierEnding inside node_modules packages (#48995)
* Respect importModuleSpecifierEnding inside node_modules packages

* Add tests for missing package.json
2022-05-06 12:58:12 -07:00
Daniel Rosenwasser
5f9c9a6ccf
Start Node ESM stable version at Node16 (#48879)
* Remove Node12, add Node16.

* Accepted baselines.

* Refactor checking for top-level await, give a better error message in CJS files.

* Accepted baselines.

* Stop erroring on JSON module imports in node ESM since they're no longer experimental.

* Accepted baselines.

* More refactoring, do the same checks for for-await loops.

* Accepted baselines.

* Adjust phrasing to permit for-await on CJS error.

* Accepted baselines.

* Accepted baselines.

* Fix lints.
2022-05-03 16:29:40 -07:00
Wesley Wigham
ea0db9e031
Add import assertions to type only imports and import types to force the resolution mode of the specifier (#47807)
* Add import assertions for type-only imports and import types to change resolver modes

* By popular request, only allow mode assertions on top-level type only imports

* Add specifier options parameter to specifier generation
2022-03-02 08:54:10 -08:00
Andrew Branch
4d298591db
Fix duplicate completions from two different copies of a node_modules package (#47584)
* Fix duplicate completions from two different copies of a node_modules package

* Fix logic for scoped packages

* Fix errors from merge

* Less gross way to reconcile these two conflicting PRs
2022-01-27 14:35:36 -08:00
Andrew Branch
d0b3ac376d
Better reuse of package.json cache, module resolution cache, and package.json auto import filter (#47388)
* Use package.json cache in module specifier generation

* Let AutoImportProviderProject reuse module resolution cache of host project

* Add missing module resolution cache access, add logging to getRootFileNames

* Reuse packageJsonImportFilter

* Only log when the project will be created, update API baseline

* Remove override that could mess up watches
2022-01-18 13:23:13 -08:00
Daniel Rosenwasser
461fb65623
Fix for crash for auto import completions with a rooted rootDirs entry (#47411)
* Add failing test case.

* Guard against undefined relative path.
2022-01-12 13:45:06 -08:00
Andrew Branch
0f1496f354
Process package.json exports with auto-import provider (#47092)
* Have auto-import provider pull in `exports`

* Revert filtering of node_modules relative paths, to do in separate PR

* Do @types and JS prioritization correctly

* Cache entrypoints on PackageJsonInfo

* Add one more test

* Delete unused function

* Fix other tests - dependencies need package.json files

* Do two passes of exports resolution

* Fix missed refactor

* Apply suggestions from code review

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>

* Uncomment rest of test

* Handle array targets

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2022-01-11 11:10:35 -08:00
Wesley Wigham
d53630fac3
Make specifier generation from export map information conditional on module resolution mode (#46670) 2021-11-03 13:10:44 -07:00
Wesley Wigham
a02a7ab8e9
Follow and respect export maps when generating module specifiers (#46159)
* Follow and respect export maps when generating module specifiers

* Type baseline updates from master merge
2021-10-01 13:54:07 -07:00
Andrew Branch
96f259ddcc
Minimal fix for auto-importing node_modules in node12/nodenext (#46148) 2021-09-30 13:42:06 -07:00
Wesley Wigham
586b0d5011
moduleResolution: node12 support (#45884)
* Initial support for module: node12

* Add allowJs and declaration emit enabled tests

* Fix typos

* cts, mts, cjs, mjs, etc extension support

* Fix watch of files whose intepretation changes due to a package.json update

* Minor PR feedback

* Adjust error message

* Initial import/export/self-name support

* Accept new error codes

* TypesVersions support in export/import map conditions

* Fix import suggestion and autoimport default extensions under new resolution modes

* Add tests for import maps non-relative name lookup feature

* Fix isDeclarationFileName for .d.mts and .d.cts

* Preserve new extensions when generating module specifiers

* Fix spurious implict any suggestion caused by file ordering bug and optimize import name format detection by relying on parents being set

* Fix a bunch of incremental bugs that dont repro under fourslash for some reason

* Accept updated baseline

* Always include extensions on completions for cjs/mjs style imports

* String completion relative import suggestions respect the mode of the import when choosing if they provide extensions

* Style feedback

* Change diagnostic case
2021-09-24 14:25:59 -07:00
Andrew Branch
328e888a9d
Resolve module specifiers for auto imports in completion list (in incomplete chunks) (#44713)
* Enable module specifiers for all auto imports

* Use isIncomplete

* isIncomplete continuation

* Lots of fixes

* Merged/transient symbol fixes, resolve all ambient module specifiers up front, pull as many as we want from cache

* Fix existing tests

* Start testing

* Add more tests

* Set cache attempt limit, update API baseline

* Fix a few tests

* Fix contextToken

* Split getModuleSpecifiers

* Unexport function

* Clean up importFixes

* Clean up completions

* Delete transient symbol assertion - fixing later
2021-06-25 17:26:53 -05:00
Jesse Trinity
753feb8707
importModuleSpecifierEnding changes .ts string completions to .js (#44602)
* don't add .ts extensions to imports

* Update src/services/stringCompletions.ts

Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>

* add other supported extension types

* add final newlines

* adress PR comment

* add unsupported extension test

Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
2021-06-21 14:43:33 -07:00