Skip to content

Commit b807c5e

Browse files
committed
v1.0.0: Add JS/TS configuration exports; switch Babel plugins
⚠️ BREAKING CHANGES (if using lint rules): - Transition from deprecated `@babel/plugin-syntax-import-assertions` to the new `@babel/plugin-syntax-import-attributes` and enable option `deprecatedAssertSyntax` for backward compatibility with import assertions. Since this is a peer dependency, consumers must switch plugins to match. 🌎 External changes: - Export JavaScript configuration as `configuration/javascript`. - Export TypeScript configuration as `configuration/typescript` now that microsoft/TypeScript#48665 has been fixed. - Update README with instructions on how to consume Babel, ESLint, JavaScript, rollup.js, and TypeScript configurations. 🏠 Internal changes: - Clean up `package.json` scripts and remove `engines` field. 🧹 Chores: - Upgrade dependencies.
1 parent d0a0b05 commit b807c5e

File tree

4 files changed

+1303
-1260
lines changed

4 files changed

+1303
-1260
lines changed

README.md

Lines changed: 95 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,112 @@
11
# Overview
22

3-
`bitumen` is a collection of utility classes, types, and opinionated configurations for Babel, ESLint, rollup.js, and TypeScript.
3+
`bitumen` is a collection of classes, types, utilities, and opinionated configuration for Babel, ESLint, rollup.js, and TypeScript.
44

55
# Supported Environments
66

7-
- Client-side use: Last two versions of Chrome, Edge, Firefox, or Safari
8-
- Server-side use: Node.js v14+
7+
- Client side: Last two versions of Chrome, Edge, Firefox (+ ESR), and Safari
8+
- Server side: Maintained versions of Node.js
99

10-
# Installation
10+
# Usage
11+
12+
## Configuration
13+
14+
### Babel
1115

12-
💡 Install the package as a runtime dependency.
16+
#### Option 1: 📍 `package.json`
1317

14-
```shell
15-
$ npm install bitumen
18+
```json
19+
{
20+
"babel": {
21+
"extends": "bitumen/configuration/babel"
22+
}
23+
}
1624
```
1725

18-
# Usage
26+
#### Option 2: 📍 `babel.config.cjs`
27+
28+
```js
29+
const base = require('bitumen/configuration/babel');
30+
31+
module.exports = {
32+
...base,
33+
// custom configuration and overrides
34+
};
35+
```
36+
37+
### ESLint
38+
39+
📍 `.eslintrc.cjs`
40+
41+
```js
42+
const base = require('bitumen/configuration/eslint');
43+
const react = require('bitumen/configuration/eslint-react');
44+
45+
module.exports = {
46+
...base,
47+
...react,
48+
// custom configuration and overrides
49+
};
50+
```
51+
52+
### rollup.js
53+
54+
📍 `rollup.config.js`
55+
56+
```js
57+
import configure from 'bitumen/configuration/rollup';
58+
59+
import packageJson from './package.json';
60+
61+
export default configure(packageJson);
62+
```
63+
64+
`configure()` returns a configuration object which:
65+
- Reads entry points from `package.json`'s `exports` field (no conditionals, null targets, or patterns).
66+
- Writes distributable output to `DIST_PATH`, mirroring the directory structure of `BUILD_PATH`.
67+
- Writes CommonJS modules to `.cjs` files and ES modules to `.js` files.
68+
- Excludes Jest directories `__mocks__`, `__tests__` from the output.
69+
- Copies Sass stylesheets (`.scss`) from `SRC_PATH` to `DIST_PATH`.
70+
- Copies TypeScript type declarations (`.d.ts`) from `BUILD_PATH` to `DIST_PATH`, giving them a `.d.ts` extension for ECMAScript and a `.d.cts` extension for CommonJS.
71+
72+
The following environment variables must be set at runtime:
73+
74+
- `BUILD_PATH`: Where Babel and `tsc` write their `.js` and `.d.ts` files.
75+
- `DIST_PATH`: Where rollup.js is to write its distributable output.
76+
- `FORMAT`: Type of modules to output; either _'es'_ (ES) or _'cjs'_ (CommonJS).
77+
- `SRC_PATH`: Where the original source code is located.
78+
79+
### TypeScript
80+
81+
📍 `jsconfig.json`
82+
83+
```json
84+
{
85+
"extends": "bitumen/configuration/javascript"
86+
}
87+
```
88+
89+
📍 `tsconfig.json`
90+
91+
```json
92+
{
93+
"extends": "bitumen/configuration/typescript",
94+
// `exclude`, `files`, and `include` paths must be set locally;
95+
// see https://github.com/microsoft/TypeScript/issues/45050
96+
"include": ["./src/"]
97+
}
98+
```
99+
100+
## Library
19101

20102
`bitumen` exposes named exports from the following entry points:
21103

22104
- `collections`
23-
- `configuration`
24105
- `mixins`
25106
- `types`
26107
- `utils`
27108

28-
For example, to implement the `SortedSet` class from the `collections` entry point:
109+
For example, to implement `SortedSet` from `collections`:
29110
```js
30111
import {SortedSet} from 'bitumen/collections';
31112

@@ -34,12 +115,9 @@ const set = new SortedSet();
34115

35116
# Type Declarations
36117

37-
TypeScript type declarations are included to aid in writing type-safe code—even in JavaScript projects. 🚀
118+
For proper module and type resolution, use the following project settings:
38119

39-
## Importing in Visual Studio Code
40-
41-
### JavaScript Projects
42-
📍 `jsconfig.json` (create as needed)
120+
📍 `jsconfig.json`
43121
```jsonc
44122
{
45123
"compilerOptions": {
@@ -50,7 +128,6 @@ TypeScript type declarations are included to aid in writing type-safe code—eve
50128
}
51129
```
52130

53-
### TypeScript Projects
54131
📍 `tsconfig.json`
55132
```jsonc
56133
{
@@ -59,3 +136,5 @@ TypeScript type declarations are included to aid in writing type-safe code—eve
59136
}
60137
}
61138
```
139+
140+
💡 `bitumen`'s [JavaScript and TypeScript configurations](#typescript) are already set up this way.

babel.config.cjs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
module.exports = {
77
plugins: [
8-
'@babel/plugin-syntax-import-assertions'
9-
].concat(
10-
process.env.ENV == 'jest' ? [['replace-import-extension', {extMapping: {'.js': '', '.jsx': ''}}]] : []
11-
),
8+
['@babel/plugin-syntax-import-attributes', {deprecatedAssertSyntax: true}],
9+
process.env.ENV == 'jest' && ['replace-import-extension', {extMapping: {'.js': '', '.jsx': ''}}]
10+
].filter(Boolean),
1211
presets: [
1312
['@babel/preset-env', {
1413
corejs: 3,
@@ -23,7 +22,7 @@ module.exports = {
2322
useBuiltIns: 'usage'
2423
}],
2524
['@babel/preset-typescript', {
26-
allowDeclareFields: true // will be enabled by default in Babel 8
25+
allowDeclareFields: true // TODO: will be enabled by default in Babel 8
2726
}]
2827
]
2928
};

0 commit comments

Comments
 (0)