Skip to content

Commit 93ce91e

Browse files
authored
docs(spec): v0.1.5
1 parent 2228b63 commit 93ce91e

File tree

1 file changed

+58
-22
lines changed

1 file changed

+58
-22
lines changed

README.md

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

3-
> version 0.1.3
3+
> version 0.1.5
44
55
- [`std.module.format`](#-stdmoduleformat-)
66
* [Overview](#overview)
@@ -43,21 +43,74 @@ Establishing the best way to support cjs and esm and how to structure project to
4343

4444
**disable** the following compiler options:
4545

46-
`esModuleInterop`: `false`
47-
`allowSyntheticDefaultImports`: `false`
48-
46+
> `tsconfig.json`
47+
```jsonc
48+
"esModuleInterop": false,
49+
"allowSyntheticDefaultImports": false
50+
```
4951

5052
The two flags `esModuleInterop` and `allowSyntheticDefaultImports` enable interoperation between ES Modules and CommonJS, AMD, and UMD modules for emit from TypeScript and type resolution by TypeScript respectively.
5153

5254
Unfortunately these options are viral: **enabling them in a package requires all downstream consumers to enable them as well** . The TLDR is due to the way CommonJS and ES Modules interoperate with bundlers (Webpack, Parcel, etc.).
5355

5456
### Solution
5557

56-
set both `allowSyntheticDefaultImports` and `esModuleInterop` to `false`.
58+
>**Warning**
59+
> setting both `allowSyntheticDefaultImports` and `esModuleInterop` to `false` may break your build.
5760
5861
Consumers can now opt into these semantics, it also does not require them to do so.
5962
Consumers **can always safely use alternative import syntaxes (including falling back to require() and import()),** or can enable these flags and opt into this behavior themselves.
6063

64+
#### Other Compiler Options Affecting the Build Result
65+
66+
- `extends`
67+
- `importsNotUsedAsValues`
68+
- `preserveValueImports`
69+
- `jsxFactory`
70+
- `jsxFragmentFactory`
71+
72+
#### Suggested `tsconfig` values
73+
74+
```jsonc
75+
"useDefineForClassFields": true,
76+
```
77+
```jsonc
78+
"isolatedModules": true,
79+
```
80+
81+
> [source, vitejs developer guide: vitejs.dev/guide/features.html#typescript-compiler-options](https://vitejs.dev/guide/features.html#typescript-compiler-options)
82+
83+
## Side by Side Compare
84+
85+
### node:assert
86+
87+
>**Note**
88+
>[See the NodeJs Assertion Documentation for more information](https://nodejs.org/api/assert.html#assert)
89+
90+
#### Modern
91+
92+
```typescript
93+
import { strict as assert } from 'node:assert'; // ESM
94+
const assert = require('node:assert').strict; // CJS
95+
```
96+
97+
```typescript
98+
import assert from 'node:assert/strict'; // ESM
99+
const assert = require('node:assert/strict'); // CJS
100+
```
101+
102+
```typescript
103+
import { strict as assert } from 'node:assert'; // ESM
104+
const assert = require('node:assert/strict'); // CJS
105+
```
106+
107+
#### Legacy
108+
109+
```typescript
110+
import assert from 'node:assert'; // ESM
111+
const assert = require('node:assert'); // CJS
112+
```
113+
61114
## TLDR
62115

63116
```javascript
@@ -136,23 +189,6 @@ export type { T }
136189
```
137190
> [source, typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
138191
139-
#### Other Compiler Options Affecting the Build Result
140-
- `extends`
141-
- `importsNotUsedAsValues`
142-
- `preserveValueImports`
143-
- `jsxFactory`
144-
- `jsxFragmentFactory`
145-
146-
#### Suggested `tsconfig` values
147-
```json
148-
["useDefineForClassFields": true]
149-
```
150-
```json
151-
["isolatedModules": true]
152-
```
153-
154-
> [source, vitejs developer guide: vitejs.dev/guide/features.html#typescript-compiler-options](https://vitejs.dev/guide/features.html#typescript-compiler-options)
155-
156192
## Avoid Default Exports and Prefer Named Exports
157193
158194
### Context

0 commit comments

Comments
 (0)