Skip to content

Commit e4d9d0b

Browse files
committed
feat: migrate to ESM. Make passing a TypeScript program optional
1 parent ef1d257 commit e4d9d0b

39 files changed

+2484
-2300
lines changed

README.md

+58-66
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,7 @@ const compilerOptions = getDefaultCompilerOptions();
144144
const compilerHost = createCompilerHost(compilerOptions);
145145

146146
// Create a Typescript program
147-
const program = createProgram(
148-
["my-file-1.ts", "my-file-2.ts"],
149-
compilerOptions,
150-
compilerHost
151-
);
147+
const program = createProgram(["my-file-1.ts", "my-file-2.ts"], compilerOptions, compilerHost);
152148

153149
// Transform the SourceFiles within the program, and pass them through the 'di' transformer
154150
program.emit(undefined, undefined, undefined, undefined, di({program}));
@@ -168,7 +164,7 @@ You can also do it programmatically. Here's an example using CommonJS:
168164
const {di} = require("@wessberg/rollup-plugin-ts");
169165

170166
require("ts-node").register({
171-
transformers: program => di({program})
167+
transformers: program => di({program})
172168
});
173169
```
174170

@@ -180,11 +176,7 @@ const compilerOptions = getDefaultCompilerOptions();
180176
const compilerHost = createCompilerHost(compilerOptions);
181177

182178
// Create a Typescript program
183-
const program = createProgram(
184-
["my-file-1.ts", "my-file-2.ts"],
185-
compilerOptions,
186-
compilerHost
187-
);
179+
const program = createProgram(["my-file-1.ts", "my-file-2.ts"], compilerOptions, compilerHost);
188180

189181
// Transform the SourceFiles within the program, and pass them through the 'di' transformer
190182
program.emit(undefined, undefined, undefined, undefined, di({program}));
@@ -229,15 +221,15 @@ import ts from "@wessberg/rollup-plugin-ts";
229221
import {di} from "@wessberg/di-compiler";
230222

231223
export default {
232-
input: "...",
233-
output: [
234-
/* ... */
235-
],
236-
plugins: [
237-
ts({
238-
transformers: [di]
239-
})
240-
]
224+
input: "...",
225+
output: [
226+
/* ... */
227+
],
228+
plugins: [
229+
ts({
230+
transformers: [di]
231+
})
232+
]
241233
};
242234
```
243235

@@ -248,15 +240,15 @@ import ts from "rollup-plugin-typescript2";
248240
import {di} from "@wessberg/di-compiler";
249241

250242
export default {
251-
input: "...",
252-
output: [
253-
/* ... */
254-
],
255-
plugins: [
256-
ts({
257-
transformers: [service => di({program: service.getProgram()})]
258-
})
259-
]
243+
input: "...",
244+
output: [
245+
/* ... */
246+
],
247+
plugins: [
248+
ts({
249+
transformers: [service => di({program: service.getProgram()})]
250+
})
251+
]
260252
};
261253
```
262254

@@ -272,21 +264,21 @@ There are two popular TypeScript loaders for Webpack that support Custom Transfo
272264
```typescript
273265
import {di} from "@wessberg/di-compiler";
274266
const config = {
275-
// ...
276-
module: {
277-
rules: [
278-
{
279-
// Match .mjs, .js, .jsx, and .tsx files
280-
test: /(\.mjs)|(\.[jt]sx?)$/,
281-
loader: "awesome-typescript-loader",
282-
options: {
283-
// ...
284-
getCustomTransformers: program => di({program})
285-
}
286-
}
287-
]
288-
}
289-
// ...
267+
// ...
268+
module: {
269+
rules: [
270+
{
271+
// Match .mjs, .js, .jsx, and .tsx files
272+
test: /(\.mjs)|(\.[jt]sx?)$/,
273+
loader: "awesome-typescript-loader",
274+
options: {
275+
// ...
276+
getCustomTransformers: program => di({program})
277+
}
278+
}
279+
]
280+
}
281+
// ...
290282
};
291283
```
292284

@@ -295,21 +287,21 @@ const config = {
295287
```typescript
296288
import {di} from "@wessberg/di";
297289
const config = {
298-
// ...
299-
module: {
300-
rules: [
301-
{
302-
// Match .mjs, .js, .jsx, and .tsx files
303-
test: /(\.mjs)|(\.[jt]sx?)$/,
304-
loader: "ts-loader",
305-
options: {
306-
// ...
307-
getCustomTransformers: program => di({program})
308-
}
309-
}
310-
]
311-
}
312-
// ...
290+
// ...
291+
module: {
292+
rules: [
293+
{
294+
// Match .mjs, .js, .jsx, and .tsx files
295+
test: /(\.mjs)|(\.[jt]sx?)$/,
296+
loader: "ts-loader",
297+
options: {
298+
// ...
299+
getCustomTransformers: program => di({program})
300+
}
301+
}
302+
]
303+
}
304+
// ...
313305
};
314306
```
315307

@@ -320,9 +312,9 @@ with the `require` property in the `ava` configuration:
320312

321313
```json5
322314
{
323-
// Other options...
324-
extensions: ["ts"],
325-
require: ["@wessberg/di-compiler/register"]
315+
// Other options...
316+
extensions: ["ts"],
317+
require: ["@wessberg/di-compiler/register"]
326318
}
327319
```
328320

@@ -367,8 +359,8 @@ For example, an expression such as:
367359

368360
```typescript
369361
import {DIContainer} from "@wessberg/di";
370-
import {MyInterface} from "./my-interface";
371-
import {MyImplementation} from "./my-implementation";
362+
import {MyInterface} from "./my-interface.js";
363+
import {MyImplementation} from "./my-implementation.js";
372364

373365
const container = new DIContainer();
374366
container.registerSingleton<MyInterface, MyImplementation>();
@@ -379,8 +371,8 @@ Will be compiled into:
379371
```javascript
380372
// ...
381373
container.registerSingleton(undefined, {
382-
identifier: `MyInterface`,
383-
implementation: MyImplementation
374+
identifier: `MyInterface`,
375+
implementation: MyImplementation
384376
});
385377
```
386378

package.json

+67-58
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"build": "pnpm run prebuild && pnpm run rollup",
1515
"prewatch": "pnpm run clean",
1616
"watch": "pnpm run prewatch && pnpm run rollup -- --watch",
17-
"rollup": "rollup -c rollup.config.js",
17+
"rollup": "rollup -c rollup.config.mjs",
1818
"preversion": "pnpm run lint && pnpm run build",
1919
"version": "pnpm run preversion && pnpm run generate:all && git add .",
2020
"release": "np --no-cleanup --no-yarn",
@@ -51,49 +51,52 @@
5151
],
5252
"license": "MIT",
5353
"devDependencies": {
54-
"@types/node": "^17.0.35",
55-
"@types/prettier": "^2.6.1",
56-
"@types/semver": "^7.3.9",
57-
"@typescript-eslint/eslint-plugin": "^5.26.0",
58-
"@typescript-eslint/parser": "^5.26.0",
59-
"@wessberg/ts-config": "^2.0.2",
60-
"rollup-plugin-ts": "^2.0.7",
54+
"@types/node": "^18.0.6",
55+
"@types/prettier": "^2.6.3",
56+
"@types/semver": "^7.3.10",
57+
58+
"@typescript-eslint/eslint-plugin": "^5.30.7",
59+
"@typescript-eslint/parser": "^5.30.7",
60+
"@wessberg/ts-config": "^2.0.4",
61+
"@wessberg/prettier-config": "^1.0.0",
62+
"rollup-plugin-ts": "^3.0.2",
6163
"semver": "^7.3.7",
6264
"ava": "3.15.0",
63-
"eslint": "^8.16.0",
65+
"eslint": "^8.20.0",
6466
"eslint-config-prettier": "^8.5.0",
6567
"eslint-plugin-import": "^2.26.0",
66-
"eslint-plugin-jsdoc": "^39.3.1",
68+
"eslint-plugin-jsdoc": "^39.3.3",
6769
"husky": "^8.0.1",
68-
"np": "^7.6.1",
69-
"pnpm": "^7.1.5",
70-
"prettier": "^2.6.2",
70+
"np": "^7.6.2",
71+
"pnpm": "^7.6.0",
72+
"prettier": "^2.7.1",
7173
"pretty-quick": "^3.1.3",
7274
"rimraf": "^3.0.2",
73-
"rollup": "^2.74.1",
74-
"sandhog": "^1.0.43",
75+
"rollup": "^2.77.0",
76+
"sandhog": "^2.0.2",
7577
"standard-changelog": "^2.0.27",
76-
"crosspath": "^1.0.0",
77-
"ts-node": "^10.8.0",
78-
"npm-check-updates": "^13.0.3",
79-
"typescript": "^4.6.4",
80-
"typescript-3-4-1": "npm:typescript@3.4.1",
81-
"typescript-3-5-1": "npm:typescript@3.5.1",
82-
"typescript-3-6-2": "npm:typescript@3.6.2",
83-
"typescript-3-7-2": "npm:typescript@3.7.2",
84-
"typescript-3-8-3": "npm:typescript@3.8.3",
85-
"typescript-3-9-2": "npm:typescript@3.9.2",
86-
"typescript-4-0-3": "npm:typescript@4.0.3",
87-
"typescript-4-1-2": "npm:typescript@4.1.2",
88-
"typescript-4-2-4": "npm:typescript@4.2.4",
89-
"typescript-4-3-5": "npm:typescript@4.3.5",
90-
"typescript-4-4-2": "npm:typescript@4.4.2",
91-
"typescript-4-5-3": "npm:typescript@4.5.3",
92-
"tslib": "^2.4.0"
78+
"crosspath": "^2.0.0",
79+
"ts-node": "^10.9.1",
80+
"npm-check-updates": "^15.3.4",
81+
"typescript": "^4.7.4",
82+
"typescript-3-4-1": "npm:typescript@3.4.1",
83+
"typescript-3-5-1": "npm:typescript@3.5.1",
84+
"typescript-3-6-2": "npm:typescript@3.6.2",
85+
"typescript-3-7-2": "npm:typescript@3.7.2",
86+
"typescript-3-8-3": "npm:typescript@3.8.3",
87+
"typescript-3-9-2": "npm:typescript@3.9.2",
88+
"typescript-4-0-3": "npm:typescript@4.0.3",
89+
"typescript-4-1-2": "npm:typescript@4.1.2",
90+
"typescript-4-2-4": "npm:typescript@4.2.4",
91+
"typescript-4-3-5": "npm:typescript@4.3.5",
92+
"typescript-4-4-2": "npm:typescript@4.4.2",
93+
"typescript-4-5-4": "npm:typescript@4.5.4",
94+
"typescript-4-6-4": "npm:typescript@4.6.4"
9395
},
9496
"dependencies": {
95-
"ts-evaluator": "^0.2.0",
96-
"compatfactory": "^0.0.13"
97+
"helpertypes": "^0.0.18",
98+
"ts-evaluator": "^1.0.3",
99+
"compatfactory": "^1.0.1"
97100
},
98101
"peerDependencies": {
99102
"typescript": ">=3.x || >= 4.x"
@@ -105,29 +108,35 @@
105108
"bugs": {
106109
"url": "https://github.com/wessberg/di-compiler/issues"
107110
},
108-
"main": "./dist/cjs/index.js",
109-
"module": "./dist/esm/index.js",
110-
"browser": "./dist/esm/index.js",
111-
"types": "./dist/esm/index.d.ts",
112-
"typings": "./dist/esm/index.d.ts",
113-
"es2015": "./dist/esm/index.js",
111+
"exports": {
112+
"import": "./dist/esm/index.js",
113+
"require": "./dist/cjs/index.cjs"
114+
},
115+
"type": "module",
116+
"types": "./dist/esm/index.d.ts",
117+
"main": "./dist/cjs/index.cjs",
118+
"module": "./dist/esm/index.js",
114119
"engines": {
115-
"node": ">=8.0.0"
116-
},
117-
"ava": {
118-
"files": [
119-
"test/**/**.test.ts"
120-
],
121-
"verbose": true,
122-
"timeout": "40s",
123-
"extensions": [
124-
"ts"
125-
],
126-
"environmentVariables": {
127-
"NODE_OPTIONS": "--max_old_space_size=4096"
128-
},
129-
"require": [
130-
"ts-node/register/transpile-only"
131-
]
132-
}
120+
"node": ">=14.19.0"
121+
},
122+
"prettier": "@wessberg/prettier-config",
123+
"ava": {
124+
"files": [
125+
"test/**/container.test.ts"
126+
],
127+
"verbose": true,
128+
"timeout": "400s",
129+
"nonSemVerExperiments": {
130+
"configurableModuleFormat": true
131+
},
132+
"extensions": {
133+
"ts": "module"
134+
},
135+
"nodeArguments": [
136+
"--loader=ts-node/esm"
137+
],
138+
"environmentVariables": {
139+
"FORCE_COLOR": "3"
140+
}
141+
}
133142
}

0 commit comments

Comments
 (0)