Skip to content

Commit

Permalink
chore: auto update reflect metadata module
Browse files Browse the repository at this point in the history
updated entrypoint to auto import reflect metadata
updated docs
updated tsconfig with modern NodeJS module resolution
removed unused ancient builds
simplified CI
  • Loading branch information
notaphplover committed Nov 26, 2024
1 parent c68e60d commit e21b60d
Show file tree
Hide file tree
Showing 38 changed files with 54 additions and 142 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
node-version: [20.x, 22.x]
os: [ubuntu-latest, windows-latest]
ts-project: [src/tsconfig.json, src/tsconfig-es6.json]
ts-project: [src/tsconfig.json]
exclude:
- node-version: 22.x
os: ubuntu-latest
Expand Down
21 changes: 0 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,18 @@ pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
build

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
build
node_modules
bower_components
docs
bundled

typings
.typingsrc
dist
dts
lib
temp
es
es6
amd

type_definitions/inversify/*.js

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

### Changed
- Updated library to import `reflect-metadata`. Importing `reflect-metadata` before bootstraping a module in the userland is no longer required.

### Fixed
- Fixed container to properly resolve async `.toService` bindings.
Expand Down
21 changes: 6 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,18 @@ You can get the latest release and the type definitions using your preferred pac
> pnpm add inversify reflect-metadata
```

> **Hint!** If you want to use a more type-safe version of reflect-metadata, try [`@abraham/reflection`](https://www.npmjs.com/package/@abraham/reflection)
`reflect-metadata` will be automatically imported by inversify.

The InversifyJS type definitions are included in the inversify npm package.

> :warning: **Important!** InversifyJS requires TypeScript >= 4.4 and the `experimentalDecorators`, `emitDecoratorMetadata`, `types` and `lib`
compilation options in your `tsconfig.json` file.
> :warning: **Important!** InversifyJS requires TypeScript >= 4.4 and the `experimentalDecorators`, `emitDecoratorMetadata`, compilation options in your `tsconfig.json` file.
```json
{
"compilerOptions": {
"target": "es5",
"lib": ["es6"],
"types": ["reflect-metadata"],
"module": "commonjs",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
```

Expand All @@ -93,8 +87,6 @@ InversifyJS requires a modern JavaScript engine with support for:

If your environment doesn't support one of these you will need to import a shim or polyfill.

> :warning: **The `reflect-metadata` polyfill should be imported only once in your entire application** because the Reflect object is meant to be a global singleton. More details about this can be found [here](https://github.com/inversify/InversifyJS/issues/262#issuecomment-227593844).
Check out the [Environment support and polyfills](https://github.com/inversify/InversifyJS/blob/master/wiki/environment.md)
page in the wiki and the [Basic example](https://github.com/inversify/inversify-basic-example) to learn more.

Expand Down Expand Up @@ -152,7 +144,6 @@ When a class has a dependency on an interface we also need to use the `@inject`
// file entities.ts

import { injectable, inject } from "inversify";
import "reflect-metadata";
import { Weapon, ThrowableWeapon, Warrior } from "./interfaces";
import { TYPES } from "./types";

Expand Down
7 changes: 5 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"nyc": "17.1.0",
"prettier": "3.3.3",
"publish-please": "5.5.2",
"reflect-metadata": "0.2.2",
"rimraf": "6.0.1",
"sinon": "19.0.2",
"ts-loader": "9.5.1",
Expand All @@ -35,6 +34,9 @@
"webpack": "5.96.1",
"webpack-cli": "5.1.4"
},
"peerDependencies": {
"reflect-metadata": "~0.2.2"
},
"engines": {},
"homepage": "http://inversify.io",
"jsnext:main": "es/inversify.js",
Expand Down Expand Up @@ -63,12 +65,10 @@
"url": "https://github.com/inversify/InversifyJS.git"
},
"scripts": {
"build": "npm run build:lib && npm run build:amd && npm run build:es && npm run build:es6",
"build:amd": "tsc -p src/tsconfig-amd.json",
"build": "npm run build:lib && npm run build:es",
"build:es": "webpack && node ./scripts/writeEsmPackageJson.mjs ./es",
"build:es6": "tsc -p src/tsconfig-es6.json",
"build:lib": "tsc -p src/tsconfig.json",
"clean": "rimraf amd es es6 lib",
"clean": "rimraf es lib",
"format": "prettier --write ./src/*.ts ./src/**/*.ts ./test/*.ts ./test/**/*.ts",
"lint": "eslint ./src ./test",
"postupdate": "git diff-files --quiet package-lock.json || npm test",
Expand Down
2 changes: 2 additions & 0 deletions src/inversify.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'reflect-metadata';

import * as keys from './constants/metadata_keys';

export { LazyServiceIdentifier } from '@inversifyjs/common';
Expand Down
10 changes: 0 additions & 10 deletions src/tsconfig-amd.json

This file was deleted.

10 changes: 0 additions & 10 deletions src/tsconfig-es6.json

This file was deleted.

2 changes: 1 addition & 1 deletion test/annotation/inject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { inject } from '../../src/annotation/inject';
import { multiInject } from '../../src/annotation/multi_inject';
import * as ERROR_MSGS from '../../src/constants/error_msgs';
import * as METADATA_KEY from '../../src/constants/metadata_keys';
import { interfaces } from '../../src/interfaces/interfaces';
import type { interfaces } from '../../src/interfaces/interfaces';

class Katana {}
class Shuriken {}
Expand Down
2 changes: 1 addition & 1 deletion test/annotation/multi_inject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { decorate } from '../../src/annotation/decorator_utils';
import { multiInject } from '../../src/annotation/multi_inject';
import * as ERROR_MSGS from '../../src/constants/error_msgs';
import * as METADATA_KEY from '../../src/constants/metadata_keys';
import { interfaces } from '../../src/interfaces/interfaces';
import type { interfaces } from '../../src/interfaces/interfaces';

type Weapon = object;

Expand Down
2 changes: 1 addition & 1 deletion test/annotation/named.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { decorate } from '../../src/annotation/decorator_utils';
import { named } from '../../src/annotation/named';
import * as ERROR_MSGS from '../../src/constants/error_msgs';
import * as METADATA_KEY from '../../src/constants/metadata_keys';
import { interfaces } from '../../src/interfaces/interfaces';
import type { interfaces } from '../../src/interfaces/interfaces';

type Weapon = unknown;

Expand Down
2 changes: 1 addition & 1 deletion test/annotation/tagged.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { decorate } from '../../src/annotation/decorator_utils';
import { tagged } from '../../src/annotation/tagged';
import * as ERRORS_MSGS from '../../src/constants/error_msgs';
import * as METADATA_KEY from '../../src/constants/metadata_keys';
import { interfaces } from '../../src/interfaces/interfaces';
import type { interfaces } from '../../src/interfaces/interfaces';

type Weapon = unknown;

Expand Down
2 changes: 1 addition & 1 deletion test/annotation/target_name.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { decorate } from '../../src/annotation/decorator_utils';
import { injectable } from '../../src/annotation/injectable';
import { targetName } from '../../src/annotation/target_name';
import * as METADATA_KEY from '../../src/constants/metadata_keys';
import { interfaces } from '../../src/inversify';
import type { interfaces } from '../../src/inversify';
import { Metadata } from '../../src/planning/metadata';
import * as Stubs from '../utils/stubs';

Expand Down
2 changes: 1 addition & 1 deletion test/container/container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { BindingScopeEnum } from '../../src/constants/literal_types';
import { Container } from '../../src/container/container';
import { ContainerModule } from '../../src/container/container_module';
import { ModuleActivationStore } from '../../src/container/module_activation_store';
import { interfaces } from '../../src/interfaces/interfaces';
import type { interfaces } from '../../src/interfaces/interfaces';
import { getBindingDictionary } from '../../src/planning/planner';
import { getServiceIdentifierAsString } from '../../src/utils/serialization';

Expand Down
2 changes: 1 addition & 1 deletion test/container/container_module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
AsyncContainerModule,
ContainerModule,
} from '../../src/container/container_module';
import { interfaces } from '../../src/interfaces/interfaces';
import type { interfaces } from '../../src/interfaces/interfaces';

describe('ContainerModule', () => {
it('Should be able to set the registry of a container module', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/container/lookup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Binding } from '../../src/bindings/binding';
import * as ERROR_MSGS from '../../src/constants/error_msgs';
import { BindingScopeEnum } from '../../src/constants/literal_types';
import { Lookup } from '../../src/container/lookup';
import { interfaces } from '../../src/interfaces/interfaces';
import type { interfaces } from '../../src/interfaces/interfaces';

class ClonableValue<T> implements interfaces.Clonable<ClonableValue<T>> {
public readonly val: T;
Expand Down
2 changes: 1 addition & 1 deletion test/container/module_activation_store.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';

import { ModuleActivationStore } from '../../src/container/module_activation_store';
import { interfaces } from '../../src/inversify';
import type { interfaces } from '../../src/inversify';

describe('ModuleActivationStore', () => {
it('should remove handlers added by the module', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/features/metadata_reader.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';

import * as METADATA_KEY from '../../src/constants/metadata_keys';
import { interfaces } from '../../src/interfaces/interfaces';
import type { interfaces } from '../../src/interfaces/interfaces';
import {
Container,
inject,
Expand Down
2 changes: 1 addition & 1 deletion test/inversify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect } from 'chai';

import { DecoratorTarget } from '../src/annotation/decorator_utils';
import * as ERROR_MSGS from '../src/constants/error_msgs';
import { interfaces } from '../src/interfaces/interfaces';
import type { interfaces } from '../src/interfaces/interfaces';
import {
Container,
ContainerModule,
Expand Down
2 changes: 1 addition & 1 deletion test/middleware/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as sinon from 'sinon';
import { injectable } from '../../src/annotation/injectable';
import * as ERROR_MSGS from '../../src/constants/error_msgs';
import { Container } from '../../src/container/container';
import { interfaces } from '../../src/interfaces/interfaces';
import type { interfaces } from '../../src/interfaces/interfaces';

describe('Middleware', () => {
let sandbox: sinon.SinonSandbox;
Expand Down
2 changes: 1 addition & 1 deletion test/node/proxies.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';

import { interfaces } from '../../src/interfaces/interfaces';
import type { interfaces } from '../../src/interfaces/interfaces';
import { Container, inject, injectable } from '../../src/inversify';

describe('InversifyJS', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/planning/planner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { targetName } from '../../src/annotation/target_name';
import * as ERROR_MSGS from '../../src/constants/error_msgs';
import { TargetTypeEnum } from '../../src/constants/literal_types';
import { Container } from '../../src/container/container';
import { interfaces } from '../../src/interfaces/interfaces';
import type { interfaces } from '../../src/interfaces/interfaces';
import { named } from '../../src/inversify';
import { MetadataReader } from '../../src/planning/metadata_reader';
import { Plan } from '../../src/planning/plan';
Expand Down
2 changes: 1 addition & 1 deletion test/planning/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { expect } from 'chai';

import { TargetTypeEnum } from '../../src/constants/literal_types';
import { Container } from '../../src/container/container';
import { interfaces } from '../../src/interfaces/interfaces';
import type { interfaces } from '../../src/interfaces/interfaces';
import { Context } from '../../src/planning/context';
import { Request } from '../../src/planning/request';

Expand Down
2 changes: 1 addition & 1 deletion test/resolution/resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
TargetTypeEnum,
} from '../../src/constants/literal_types';
import { Container } from '../../src/container/container';
import { interfaces } from '../../src/interfaces/interfaces';
import type { interfaces } from '../../src/interfaces/interfaces';
import { MetadataReader } from '../../src/planning/metadata_reader';
import { getBindingDictionary, plan } from '../../src/planning/planner';
import { resolveInstance } from '../../src/resolution/instantiation';
Expand Down
2 changes: 1 addition & 1 deletion test/syntax/binding_in_when_on_syntax.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as sinon from 'sinon';
import { injectable } from '../../src/annotation/injectable';
import { Binding } from '../../src/bindings/binding';
import { BindingScopeEnum } from '../../src/constants/literal_types';
import { interfaces } from '../../src/interfaces/interfaces';
import type { interfaces } from '../../src/interfaces/interfaces';
import { BindingInWhenOnSyntax } from '../../src/syntax/binding_in_when_on_syntax';

describe('BindingInWhenOnSyntax', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/syntax/binding_on_syntax.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';

import { Binding } from '../../src/bindings/binding';
import { BindingScopeEnum } from '../../src/constants/literal_types';
import { interfaces } from '../../src/interfaces/interfaces';
import type { interfaces } from '../../src/interfaces/interfaces';
import { BindingOnSyntax } from '../../src/syntax/binding_on_syntax';

describe('BindingOnSyntax', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/syntax/binding_to_syntax.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
BindingScopeEnum,
BindingTypeEnum,
} from '../../src/constants/literal_types';
import { interfaces } from '../../src/interfaces/interfaces';
import type { interfaces } from '../../src/interfaces/interfaces';
import { BindingToSyntax } from '../../src/syntax/binding_to_syntax';

describe('BindingToSyntax', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/syntax/binding_when_on_syntax.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Sinon, * as sinon from 'sinon';
import { injectable } from '../../src/annotation/injectable';
import { Binding } from '../../src/bindings/binding';
import { BindingScopeEnum } from '../../src/constants/literal_types';
import { interfaces } from '../../src/interfaces/interfaces';
import type { interfaces } from '../../src/interfaces/interfaces';
import { BindingWhenOnSyntax } from '../../src/syntax/binding_when_on_syntax';

describe('BindingWhenOnSyntax', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/syntax/binding_when_syntax.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
TargetTypeEnum,
} from '../../src/constants/literal_types';
import { Container } from '../../src/container/container';
import { interfaces } from '../../src/interfaces/interfaces';
import type { interfaces } from '../../src/interfaces/interfaces';
import { Context } from '../../src/planning/context';
import { Request } from '../../src/planning/request';
import { BindingWhenSyntax } from '../../src/syntax/binding_when_syntax';
Expand Down
Loading

0 comments on commit e21b60d

Please sign in to comment.