Skip to content

Commit

Permalink
docs(spec): v0.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
sambacha authored Jul 3, 2022
1 parent 2228b63 commit 93ce91e
Showing 1 changed file with 58 additions and 22 deletions.
80 changes: 58 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `std.module.format`

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

**disable** the following compiler options:

`esModuleInterop`: `false`
`allowSyntheticDefaultImports`: `false`

> `tsconfig.json`
```jsonc
"esModuleInterop": false,
"allowSyntheticDefaultImports": false
```

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.

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.).

### Solution

set both `allowSyntheticDefaultImports` and `esModuleInterop` to `false`.
>**Warning**
> setting both `allowSyntheticDefaultImports` and `esModuleInterop` to `false` may break your build.
Consumers can now opt into these semantics, it also does not require them to do so.
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.

#### Other Compiler Options Affecting the Build Result

- `extends`
- `importsNotUsedAsValues`
- `preserveValueImports`
- `jsxFactory`
- `jsxFragmentFactory`

#### Suggested `tsconfig` values

```jsonc
"useDefineForClassFields": true,
```
```jsonc
"isolatedModules": true,
```

> [source, vitejs developer guide: vitejs.dev/guide/features.html#typescript-compiler-options](https://vitejs.dev/guide/features.html#typescript-compiler-options)
## Side by Side Compare

### node:assert

>**Note**
>[See the NodeJs Assertion Documentation for more information](https://nodejs.org/api/assert.html#assert)
#### Modern

```typescript
import { strict as assert } from 'node:assert'; // ESM
const assert = require('node:assert').strict; // CJS
```

```typescript
import assert from 'node:assert/strict'; // ESM
const assert = require('node:assert/strict'); // CJS
```

```typescript
import { strict as assert } from 'node:assert'; // ESM
const assert = require('node:assert/strict'); // CJS
```

#### Legacy

```typescript
import assert from 'node:assert'; // ESM
const assert = require('node:assert'); // CJS
```

## TLDR

```javascript
Expand Down Expand Up @@ -136,23 +189,6 @@ export type { T }
```
> [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)
#### Other Compiler Options Affecting the Build Result
- `extends`
- `importsNotUsedAsValues`
- `preserveValueImports`
- `jsxFactory`
- `jsxFragmentFactory`
#### Suggested `tsconfig` values
```json
["useDefineForClassFields": true]
```
```json
["isolatedModules": true]
```
> [source, vitejs developer guide: vitejs.dev/guide/features.html#typescript-compiler-options](https://vitejs.dev/guide/features.html#typescript-compiler-options)
## Avoid Default Exports and Prefer Named Exports
### Context
Expand Down

0 comments on commit 93ce91e

Please sign in to comment.