Skip to content

Commit 5bb44d5

Browse files
authored
v2023.01.15
1 parent d8dd645 commit 5bb44d5

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

README.md

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
# `std.module.format`
22

3-
> version 0.1.5
3+
> version 0.2.0:2023.01.15
44
55
- [`std.module.format`](#-stdmoduleformat-)
6-
* [Overview](#overview)
6+
* [`package.json` TLDR](#-packagejson--tldr)
7+
* [Problematic Settings](#problematic-settings)
8+
+ [Dont use `browser` field](#dont-use--browser--field)
9+
+ [dont use `preserveModules`](#dont-use--preservemodules-)
10+
+ [`moduleResolution` `NodeNext` only allows defined import paths](#-moduleresolution---nodenext--only-allows-defined-import-paths)
11+
- [correct manifest](#correct-manifest)
12+
* [`load-esm.{ts,mts}`](#-load-esm-ts-mts--)
13+
* [Motivation](#motivation)
14+
+ [Opt in compiler options](#opt-in-compiler-options)
15+
+ [Solution](#solution)
16+
- [Other Compiler Options Affecting the Build Result](#other-compiler-options-affecting-the-build-result)
17+
- [Suggested `tsconfig` values](#suggested--tsconfig--values)
18+
* [Side by Side Compare](#side-by-side-compare)
19+
+ [node:assert](#node-assert)
20+
- [Modern](#modern)
21+
- [Legacy](#legacy)
722
* [TLDR](#tldr)
23+
+ [Cheatsheet](#cheatsheet)
824
* [Avoid Default Exports and Prefer Named Exports](#avoid-default-exports-and-prefer-named-exports)
925
+ [Context](#context)
1026
+ [Summary](#summary)
@@ -32,9 +48,6 @@
3248
+ [parserOptions.moduleResolver](#parseroptionsmoduleresolver)
3349
* [License](#license)
3450

35-
<small><i><a href='#'>This is a work in progress</a></i></small>
36-
37-
3851
## `package.json` TLDR
3952

4053
```jsonc
@@ -52,7 +65,7 @@
5265
> **Warning** <br />
5366
> Use at your own discretion
5467
55-
### dont use `browser` field
68+
### Dont use `browser` field
5669
5770
webpack's resolve module algorithm picks a more specific field from `package.json` (and other bundlers too), so webpack chooses UMD module from `browser` field on the default and that breaks tree-shaking[^1]
5871
@@ -390,9 +403,9 @@ Node.js supports a new setting in package.json called type. "type" can be set to
390403
391404
Node.js supports two extensions to help with this: `.mjs` and `.cjs`. `.mjs` files are always ES modules, and `.cjs` files are always CommonJS modules, and there’s no way to override these.
392405
393-
In turn, TypeScript supports two new source file extensions: .mts and `.cts`. When TypeScript emits these to JavaScript files, it will emit them to `.mjs` and `.cjs` respectively.
406+
In turn, TypeScript supports two new source file extensions: `.mts` and `.cts`. When TypeScript emits these to JavaScript files, it will emit them to `.mjs` and `.cjs` respectively.
394407
395-
Furthermore, TypeScript also supports two new declaration file extensions: .d.mts and .d.cts. When TypeScript generates declaration files for `.mts` and `.cts`, their corresponding extensions will be `.d.mts` and `.d.cts`.
408+
Furthermore, TypeScript also supports two new declaration file extensions:` .d.mt`s and `.d.cts`. When TypeScript generates declaration files for `.mts` and `.cts`, their corresponding extensions will be `.d.mts` and `.d.cts`.
396409
397410
Using these extensions is entirely optional, but will often be useful even if you choose not to use them as part of your primary workflow.
398411
@@ -481,7 +494,7 @@ HighCharts.chart('container', { ... }); // Notice \`.default\`
481494
482495
> [esModuleInterop, https://www.typescriptlang.org/tsconfig#esModuleInterop](https://www.typescriptlang.org/tsconfig#esModuleInterop)
483496
484-
By default (with esModuleInterop false or not set) TypeScript treats CommonJS/AMD/UMD modules similar to ES6 modules. In doing this, there are two parts in particular which turned out to be flawed assumptions:
497+
By default (with `esModuleInterop` false or not set) TypeScript treats CommonJS/AMD/UMD modules similar to ES6 modules. In doing this, there are two parts in particular which turned out to be flawed assumptions:
485498
486499
a namespace import like `import * as moment from "moment"` acts the same as `const moment = require("moment")`
487500
@@ -609,7 +622,7 @@ const f: EmptyObject = {}; // NO ERROR - as expected
609622
610623
This is ***technically*** safe in this instance, [because under the hood the `{}` type is passed into an intersection type](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6fd37a55773b23e00a19418d9b5aad912087c982/types/react/index.d.ts#L501) (see the note at the end of this comment for why this is safe).
611624
612-
However, there is no way for us to statically analyse and know that this is a safe usage.
625+
However, there is no way for us to statically analyze and know that this is a safe usage.
613626
To work around this, consider reconfiguring the lint rule to match your repository's coding style.
614627
You can use the following config to allow it:
615628
@@ -790,23 +803,23 @@ The following are not valid module specifiers according to the above algorithm:
790803
791804
> [source, https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#customizing-module-resolution]
792805
793-
You can override the standard way the compiler resolves modules by implementing optional method: CompilerHost.resolveModuleNames:
806+
You can override the standard way the compiler resolves modules by implementing optional method: C`ompilerHost.resolveModuleNames`:
794807
795808
```typescript
796809
CompilerHost.resolveModuleNames(moduleNames: string[], containingFile: string): string[].
797810
```
798811
799-
The method is given a list of module names in a file, and is expected to return an array of size moduleNames.length, each element of the array stores either:
812+
The method is given a list of module names in a file, and is expected to return an array of size `moduleNames`.length, each element of the array stores either:
800813
801-
an instance of ResolvedModule with non-empty property resolvedFileName - resolution for corresponding name from moduleNames array or undefined if module name cannot be resolved.
814+
an instance of `ResolvedModule` with non-empty property `resolvedFileName` - resolution for corresponding name from moduleNames array or undefined if module name cannot be resolved.
802815
803-
You can invoke the standard module resolution process via calling resolveModuleName:
816+
You can invoke the standard module resolution process via calling `resolveModuleName`:
804817
805818
```typescript
806819
resolveModuleName(moduleName: string, containingFile: string, options: CompilerOptions, moduleResolutionHost: ModuleResolutionHost): ResolvedModuleNameWithFallbackLocations.
807820
```
808821
809-
This function returns an object that stores result of module resolution (value of resolvedModule property) as well as list of file names that were considered candidates before making current decision.
822+
This function returns an object that stores result of module resolution (value of `resolvedModule` property) as well as list of file names that were considered candidates before making current decision.
810823
811824
```typescript
812825
import * as ts from "typescript";
@@ -891,7 +904,7 @@ Default: `undefined`
891904
892905
This option allows you to provide a custom module resolution. The value should point to a JS file that default exports (`export default`, or `module.exports =`, or `export =`) a file with the following interface:
893906
894-
```
907+
```typescript
895908
interface ModuleResolver {
896909
version: 1;
897910
resolveModuleNames(
@@ -903,9 +916,9 @@ interface ModuleResolver {
903916
): (ts.ResolvedModule | undefined)[];
904917
}
905918
```
906-
Refer to the TypeScript Wiki for an example on how to write the resolveModuleNames function.
919+
Refer to the TypeScript Wiki for an example on how to write the `resolveModuleNames` function.
907920
908-
Note that if you pass custom programs via options.programs this option will not have any effect over them (you can simply add the custom resolution on them directly).
921+
Note that if you pass custom programs via `options.program`s this option will not have any effect over them (you can simply add the custom resolution on them directly).
909922
910923
## License
911924

0 commit comments

Comments
 (0)