Skip to content

Commit

Permalink
feat: migrate to ESM. Make passing a TypeScript program optional
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed Jul 22, 2022
1 parent ef1d257 commit e4d9d0b
Show file tree
Hide file tree
Showing 39 changed files with 2,484 additions and 2,300 deletions.
124 changes: 58 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,7 @@ const compilerOptions = getDefaultCompilerOptions();
const compilerHost = createCompilerHost(compilerOptions);

// Create a Typescript program
const program = createProgram(
["my-file-1.ts", "my-file-2.ts"],
compilerOptions,
compilerHost
);
const program = createProgram(["my-file-1.ts", "my-file-2.ts"], compilerOptions, compilerHost);

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

require("ts-node").register({
transformers: program => di({program})
transformers: program => di({program})
});
```

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

// Create a Typescript program
const program = createProgram(
["my-file-1.ts", "my-file-2.ts"],
compilerOptions,
compilerHost
);
const program = createProgram(["my-file-1.ts", "my-file-2.ts"], compilerOptions, compilerHost);

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

export default {
input: "...",
output: [
/* ... */
],
plugins: [
ts({
transformers: [di]
})
]
input: "...",
output: [
/* ... */
],
plugins: [
ts({
transformers: [di]
})
]
};
```

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

export default {
input: "...",
output: [
/* ... */
],
plugins: [
ts({
transformers: [service => di({program: service.getProgram()})]
})
]
input: "...",
output: [
/* ... */
],
plugins: [
ts({
transformers: [service => di({program: service.getProgram()})]
})
]
};
```

Expand All @@ -272,21 +264,21 @@ There are two popular TypeScript loaders for Webpack that support Custom Transfo
```typescript
import {di} from "@wessberg/di-compiler";
const config = {
// ...
module: {
rules: [
{
// Match .mjs, .js, .jsx, and .tsx files
test: /(\.mjs)|(\.[jt]sx?)$/,
loader: "awesome-typescript-loader",
options: {
// ...
getCustomTransformers: program => di({program})
}
}
]
}
// ...
// ...
module: {
rules: [
{
// Match .mjs, .js, .jsx, and .tsx files
test: /(\.mjs)|(\.[jt]sx?)$/,
loader: "awesome-typescript-loader",
options: {
// ...
getCustomTransformers: program => di({program})
}
}
]
}
// ...
};
```

Expand All @@ -295,21 +287,21 @@ const config = {
```typescript
import {di} from "@wessberg/di";
const config = {
// ...
module: {
rules: [
{
// Match .mjs, .js, .jsx, and .tsx files
test: /(\.mjs)|(\.[jt]sx?)$/,
loader: "ts-loader",
options: {
// ...
getCustomTransformers: program => di({program})
}
}
]
}
// ...
// ...
module: {
rules: [
{
// Match .mjs, .js, .jsx, and .tsx files
test: /(\.mjs)|(\.[jt]sx?)$/,
loader: "ts-loader",
options: {
// ...
getCustomTransformers: program => di({program})
}
}
]
}
// ...
};
```

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

```json5
{
// Other options...
extensions: ["ts"],
require: ["@wessberg/di-compiler/register"]
// Other options...
extensions: ["ts"],
require: ["@wessberg/di-compiler/register"]
}
```

Expand Down Expand Up @@ -367,8 +359,8 @@ For example, an expression such as:

```typescript
import {DIContainer} from "@wessberg/di";
import {MyInterface} from "./my-interface";
import {MyImplementation} from "./my-implementation";
import {MyInterface} from "./my-interface.js";
import {MyImplementation} from "./my-implementation.js";

const container = new DIContainer();
container.registerSingleton<MyInterface, MyImplementation>();
Expand All @@ -379,8 +371,8 @@ Will be compiled into:
```javascript
// ...
container.registerSingleton(undefined, {
identifier: `MyInterface`,
implementation: MyImplementation
identifier: `MyInterface`,
implementation: MyImplementation
});
```

Expand Down
125 changes: 67 additions & 58 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"build": "pnpm run prebuild && pnpm run rollup",
"prewatch": "pnpm run clean",
"watch": "pnpm run prewatch && pnpm run rollup -- --watch",
"rollup": "rollup -c rollup.config.js",
"rollup": "rollup -c rollup.config.mjs",
"preversion": "pnpm run lint && pnpm run build",
"version": "pnpm run preversion && pnpm run generate:all && git add .",
"release": "np --no-cleanup --no-yarn",
Expand Down Expand Up @@ -51,49 +51,52 @@
],
"license": "MIT",
"devDependencies": {
"@types/node": "^17.0.35",
"@types/prettier": "^2.6.1",
"@types/semver": "^7.3.9",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^5.26.0",
"@wessberg/ts-config": "^2.0.2",
"rollup-plugin-ts": "^2.0.7",
"@types/node": "^18.0.6",
"@types/prettier": "^2.6.3",
"@types/semver": "^7.3.10",

"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"@wessberg/ts-config": "^2.0.4",
"@wessberg/prettier-config": "^1.0.0",
"rollup-plugin-ts": "^3.0.2",
"semver": "^7.3.7",
"ava": "3.15.0",
"eslint": "^8.16.0",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsdoc": "^39.3.1",
"eslint-plugin-jsdoc": "^39.3.3",
"husky": "^8.0.1",
"np": "^7.6.1",
"pnpm": "^7.1.5",
"prettier": "^2.6.2",
"np": "^7.6.2",
"pnpm": "^7.6.0",
"prettier": "^2.7.1",
"pretty-quick": "^3.1.3",
"rimraf": "^3.0.2",
"rollup": "^2.74.1",
"sandhog": "^1.0.43",
"rollup": "^2.77.0",
"sandhog": "^2.0.2",
"standard-changelog": "^2.0.27",
"crosspath": "^1.0.0",
"ts-node": "^10.8.0",
"npm-check-updates": "^13.0.3",
"typescript": "^4.6.4",
"typescript-3-4-1": "npm:typescript@3.4.1",
"typescript-3-5-1": "npm:typescript@3.5.1",
"typescript-3-6-2": "npm:typescript@3.6.2",
"typescript-3-7-2": "npm:typescript@3.7.2",
"typescript-3-8-3": "npm:typescript@3.8.3",
"typescript-3-9-2": "npm:typescript@3.9.2",
"typescript-4-0-3": "npm:typescript@4.0.3",
"typescript-4-1-2": "npm:typescript@4.1.2",
"typescript-4-2-4": "npm:typescript@4.2.4",
"typescript-4-3-5": "npm:typescript@4.3.5",
"typescript-4-4-2": "npm:typescript@4.4.2",
"typescript-4-5-3": "npm:typescript@4.5.3",
"tslib": "^2.4.0"
"crosspath": "^2.0.0",
"ts-node": "^10.9.1",
"npm-check-updates": "^15.3.4",
"typescript": "^4.7.4",
"typescript-3-4-1": "npm:typescript@3.4.1",
"typescript-3-5-1": "npm:typescript@3.5.1",
"typescript-3-6-2": "npm:typescript@3.6.2",
"typescript-3-7-2": "npm:typescript@3.7.2",
"typescript-3-8-3": "npm:typescript@3.8.3",
"typescript-3-9-2": "npm:typescript@3.9.2",
"typescript-4-0-3": "npm:typescript@4.0.3",
"typescript-4-1-2": "npm:typescript@4.1.2",
"typescript-4-2-4": "npm:typescript@4.2.4",
"typescript-4-3-5": "npm:typescript@4.3.5",
"typescript-4-4-2": "npm:typescript@4.4.2",
"typescript-4-5-4": "npm:typescript@4.5.4",
"typescript-4-6-4": "npm:typescript@4.6.4"
},
"dependencies": {
"ts-evaluator": "^0.2.0",
"compatfactory": "^0.0.13"
"helpertypes": "^0.0.18",
"ts-evaluator": "^1.0.3",
"compatfactory": "^1.0.1"
},
"peerDependencies": {
"typescript": ">=3.x || >= 4.x"
Expand All @@ -105,29 +108,35 @@
"bugs": {
"url": "https://github.com/wessberg/di-compiler/issues"
},
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"browser": "./dist/esm/index.js",
"types": "./dist/esm/index.d.ts",
"typings": "./dist/esm/index.d.ts",
"es2015": "./dist/esm/index.js",
"exports": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.cjs"
},
"type": "module",
"types": "./dist/esm/index.d.ts",
"main": "./dist/cjs/index.cjs",
"module": "./dist/esm/index.js",
"engines": {
"node": ">=8.0.0"
},
"ava": {
"files": [
"test/**/**.test.ts"
],
"verbose": true,
"timeout": "40s",
"extensions": [
"ts"
],
"environmentVariables": {
"NODE_OPTIONS": "--max_old_space_size=4096"
},
"require": [
"ts-node/register/transpile-only"
]
}
"node": ">=14.19.0"
},
"prettier": "@wessberg/prettier-config",
"ava": {
"files": [
"test/**/container.test.ts"
],
"verbose": true,
"timeout": "400s",
"nonSemVerExperiments": {
"configurableModuleFormat": true
},
"extensions": {
"ts": "module"
},
"nodeArguments": [
"--loader=ts-node/esm"
],
"environmentVariables": {
"FORCE_COLOR": "3"
}
}
}
Loading

0 comments on commit e4d9d0b

Please sign in to comment.