From fc35c02a55dc953871969508f4ff0d441f07acd4 Mon Sep 17 00:00:00 2001 From: remojansen Date: Thu, 8 Sep 2016 00:11:44 +0100 Subject: [PATCH 1/7] Implemented #357 --- src/interfaces/interfaces.ts | 2 +- src/syntax/binding_to_syntax.ts | 4 ++-- test/bugs/bugs.test.ts | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/interfaces/interfaces.ts b/src/interfaces/interfaces.ts index aff382b46..444b5cb31 100644 --- a/src/interfaces/interfaces.ts +++ b/src/interfaces/interfaces.ts @@ -188,7 +188,7 @@ namespace interfaces { to(constructor: { new (...args: any[]): T; }): BindingInWhenOnSyntax; toSelf(): BindingInWhenOnSyntax; toConstantValue(value: T): BindingWhenOnSyntax; - toDynamicValue(func: (context: Context) => T): BindingWhenOnSyntax; + toDynamicValue(func: (context: Context) => T): BindingInWhenOnSyntax; toConstructor(constructor: Newable): BindingWhenOnSyntax; toFactory(factory: FactoryCreator): BindingWhenOnSyntax; toFunction(func: T): BindingWhenOnSyntax; diff --git a/src/syntax/binding_to_syntax.ts b/src/syntax/binding_to_syntax.ts index aa2201e7b..c4615d854 100644 --- a/src/syntax/binding_to_syntax.ts +++ b/src/syntax/binding_to_syntax.ts @@ -30,12 +30,12 @@ class BindingToSyntax implements interfaces.BindingToSyntax { return new BindingWhenOnSyntax(this._binding); } - public toDynamicValue(func: (context: interfaces.Context) => T): interfaces.BindingWhenOnSyntax { + public toDynamicValue(func: (context: interfaces.Context) => T): interfaces.BindingInWhenOnSyntax { this._binding.type = BindingType.DynamicValue; this._binding.cache = null; this._binding.dynamicValue = func; this._binding.implementationType = null; - return new BindingWhenOnSyntax(this._binding); + return new BindingInWhenOnSyntax(this._binding); } public toConstructor(constructor: interfaces.Newable): interfaces.BindingWhenOnSyntax { diff --git a/test/bugs/bugs.test.ts b/test/bugs/bugs.test.ts index 7d6993d81..63cae6fcd 100644 --- a/test/bugs/bugs.test.ts +++ b/test/bugs/bugs.test.ts @@ -206,4 +206,28 @@ describe("Bugs", () => { }); + it("Should be able to combine dynamic value with singleton scope", () => { + + let kernel = new Kernel(); + + kernel.bind("transient_random").toDynamicValue((context: interfaces.Context) => { + return Math.random(); + }).inTransientScope(); + + kernel.bind("singleton_random").toDynamicValue((context: interfaces.Context) => { + return Math.random(); + }).inSingletonScope(); + + let a = kernel.get("transient_random"); + let b = kernel.get("transient_random"); + + expect(a).not.to.eql(b); + + let c = kernel.get("singleton_random"); + let d = kernel.get("singleton_random"); + + expect(c).to.eql(d); + + }); + }); From 3fa26965a49a6ff1d3b09f58b7d42dac6cacf35f Mon Sep 17 00:00:00 2001 From: remojansen Date: Thu, 8 Sep 2016 00:53:42 +0100 Subject: [PATCH 2/7] [WIP] #330 --- gulpfile.js | 4 ---- package.json | 3 +-- src/annotation/inject.ts | 3 ++- src/annotation/multi_inject.ts | 3 ++- src/interfaces/globals.d.ts | 19 ------------------- src/interfaces/interfaces.ts | 4 ++-- src/kernel/key_value_pair.ts | 4 ++-- src/kernel/lookup.ts | 10 +++++----- src/planning/target.ts | 2 +- test/features/property_injection.test.ts | 2 ++ test/globals.d.ts | 4 ++++ test/inversify.test.ts | 2 ++ tsconfig.json | 3 +-- typings.json | 1 - 14 files changed, 24 insertions(+), 40 deletions(-) delete mode 100644 src/interfaces/globals.d.ts create mode 100644 test/globals.d.ts diff --git a/gulpfile.js b/gulpfile.js index acceb42c1..674f68f65 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -104,7 +104,6 @@ gulp.task("build-lib", function() { return gulp.src([ "typings/index.d.ts", "node_modules/reflect-metadata/reflect-metadata.d.ts", - "src/interfaces/globals.d.ts", "src/**/*.ts" ]) .pipe(tsc(tsLibProject)) @@ -122,7 +121,6 @@ gulp.task("build-es", function() { return gulp.src([ "typings/index.d.ts", "node_modules/reflect-metadata/reflect-metadata.d.ts", - "src/interfaces/globals.d.ts", "src/**/*.ts" ]) .pipe(tsc(tsEsProject)) @@ -143,7 +141,6 @@ gulp.task("build-src", function() { return gulp.src([ "typings/index.d.ts", "node_modules/reflect-metadata/reflect-metadata.d.ts", - "src/interfaces/globals.d.ts", "src/**/*.ts" ]) .pipe(tsc(tstProject)) @@ -159,7 +156,6 @@ gulp.task("build-test", function() { return gulp.src([ "typings/index.d.ts", "node_modules/reflect-metadata/reflect-metadata.d.ts", - "src/interfaces/globals.d.ts", "test/**/*.ts" ]) .pipe(tsc(tsTestProject)) diff --git a/package.json b/package.json index dafa7952b..3a435df43 100644 --- a/package.json +++ b/package.json @@ -68,8 +68,7 @@ "sinon": "^1.17.3", "tsify": "^1.0.3", "tslint": "^3.12.0", - "typedoc": ">=0.3.9", - "typescript": "^1.8.10", + "typescript": "^2.0.2", "typings": "^1.0.4", "vinyl-buffer": "^1.0.0", "vinyl-source-stream": "^1.1.0" diff --git a/src/annotation/inject.ts b/src/annotation/inject.ts index 3746e7d15..95042ab39 100644 --- a/src/annotation/inject.ts +++ b/src/annotation/inject.ts @@ -1,8 +1,9 @@ import Metadata from "../planning/metadata"; +import interfaces from "../interfaces/interfaces"; import { tagParameter, tagProperty } from "./decorator_utils"; import * as METADATA_KEY from "../constants/metadata_keys"; -function inject(serviceIdentifier: (string|Symbol)) { +function inject(serviceIdentifier: interfaces.ServiceIdentifier) { return function(target: any, targetKey: string, index?: number) { let metadata = new Metadata(METADATA_KEY.INJECT_TAG, serviceIdentifier); diff --git a/src/annotation/multi_inject.ts b/src/annotation/multi_inject.ts index 76b2f8060..36dc7278f 100644 --- a/src/annotation/multi_inject.ts +++ b/src/annotation/multi_inject.ts @@ -1,8 +1,9 @@ import Metadata from "../planning/metadata"; +import interfaces from "../interfaces/interfaces"; import { tagParameter, tagProperty } from "./decorator_utils"; import * as METADATA_KEY from "../constants/metadata_keys"; -function multiInject(serviceIdentifier: (string|Symbol)) { +function multiInject(serviceIdentifier: interfaces.ServiceIdentifier) { return function(target: any, targetKey: string, index?: number) { let metadata = new Metadata(METADATA_KEY.MULTI_INJECT_TAG, serviceIdentifier); diff --git a/src/interfaces/globals.d.ts b/src/interfaces/globals.d.ts deleted file mode 100644 index 7b3803eb1..000000000 --- a/src/interfaces/globals.d.ts +++ /dev/null @@ -1,19 +0,0 @@ - - -interface Symbol { - /** Returns a string representation of an object. */ - toString(): string; - - /** Returns the primitive value of the specified object. */ - valueOf(): Object; -} - -interface SymbolConstructor { - (description?: string|number): Symbol; -} - -declare var Symbol: SymbolConstructor; - -declare module "es6-symbol/implement" { - /* declares globals */ -} diff --git a/src/interfaces/interfaces.ts b/src/interfaces/interfaces.ts index 444b5cb31..025380ecd 100644 --- a/src/interfaces/interfaces.ts +++ b/src/interfaces/interfaces.ts @@ -4,7 +4,7 @@ namespace interfaces { new (...args: any[]): T; } - export type ServiceIdentifier = (string | Symbol | Newable); + export type ServiceIdentifier = (string | symbol | Newable); export interface Binding extends Clonable> { guid: string; @@ -112,7 +112,7 @@ namespace interfaces { metadata: Array; hasTag(key: string): boolean; isArray(): boolean; - matchesArray(name: string | Symbol | Newable): boolean; + matchesArray(name: interfaces.ServiceIdentifier): boolean; isNamed(): boolean; isTagged(): boolean; matchesNamedTag(name: string): boolean; diff --git a/src/kernel/key_value_pair.ts b/src/kernel/key_value_pair.ts index f76b42acb..3d70be330 100644 --- a/src/kernel/key_value_pair.ts +++ b/src/kernel/key_value_pair.ts @@ -3,11 +3,11 @@ import guid from "../utils/guid"; class KeyValuePair implements interfaces.KeyValuePair { - public serviceIdentifier: (string|Symbol|any); + public serviceIdentifier: interfaces.ServiceIdentifier; public value: Array; public guid: string; - public constructor(serviceIdentifier: (string|Symbol|any), value: T) { + public constructor(serviceIdentifier: interfaces.ServiceIdentifier, value: T) { this.serviceIdentifier = serviceIdentifier; this.value = new Array(); this.value.push(value); diff --git a/src/kernel/lookup.ts b/src/kernel/lookup.ts index c2562c9c8..c5fe167a9 100644 --- a/src/kernel/lookup.ts +++ b/src/kernel/lookup.ts @@ -12,7 +12,7 @@ class Lookup> implements interfaces.Lookup { } // adds a new KeyValuePair to _dictionary - public add(serviceIdentifier: (string|Symbol|any), value: T): void { + public add(serviceIdentifier: interfaces.ServiceIdentifier, value: T): void { if (serviceIdentifier === null || serviceIdentifier === undefined) { throw new Error(ERROR_MSGS.NULL_ARGUMENT); }; if (value === null || value === undefined) { throw new Error(ERROR_MSGS.NULL_ARGUMENT); }; @@ -26,7 +26,7 @@ class Lookup> implements interfaces.Lookup { } // gets the value of a KeyValuePair by its serviceIdentifier - public get(serviceIdentifier: (string|Symbol|any)): Array { + public get(serviceIdentifier: interfaces.ServiceIdentifier): Array { if (serviceIdentifier === null || serviceIdentifier === undefined) { throw new Error(ERROR_MSGS.NULL_ARGUMENT); } @@ -39,7 +39,7 @@ class Lookup> implements interfaces.Lookup { } // removes a KeyValuePair from _dictionary by its serviceIdentifier - public remove(serviceIdentifier: (string|Symbol|any)): void { + public remove(serviceIdentifier: interfaces.ServiceIdentifier): void { if (serviceIdentifier === null || serviceIdentifier === undefined) { throw new Error(ERROR_MSGS.NULL_ARGUMENT); } @@ -64,7 +64,7 @@ class Lookup> implements interfaces.Lookup { } // returns true if _dictionary contains serviceIdentifier - public hasKey(serviceIdentifier: (string|Symbol|any)): boolean { + public hasKey(serviceIdentifier: interfaces.ServiceIdentifier): boolean { if (serviceIdentifier === null || serviceIdentifier === undefined) { throw new Error(ERROR_MSGS.NULL_ARGUMENT); } @@ -92,7 +92,7 @@ class Lookup> implements interfaces.Lookup { } // finds the location of a KeyValuePair pair in _dictionary by its serviceIdentifier - private getIndexByKey(serviceIdentifier: (string|Symbol|any)): number { + private getIndexByKey(serviceIdentifier: interfaces.ServiceIdentifier): number { let index = -1; for (let i = 0; i < this._dictionary.length; i++) { let keyValuePair = this._dictionary[i]; diff --git a/src/planning/target.ts b/src/planning/target.ts index 83c93a7b7..3b0433f1d 100644 --- a/src/planning/target.ts +++ b/src/planning/target.ts @@ -56,7 +56,7 @@ class Target implements interfaces.Target { return this.hasTag(METADATA_KEY.MULTI_INJECT_TAG); } - public matchesArray(name: string|Symbol|any): boolean { + public matchesArray(name: interfaces.ServiceIdentifier): boolean { return this.matchesTag(METADATA_KEY.MULTI_INJECT_TAG)(name); } diff --git a/test/features/property_injection.test.ts b/test/features/property_injection.test.ts index e7338cdaa..8113e1380 100644 --- a/test/features/property_injection.test.ts +++ b/test/features/property_injection.test.ts @@ -1,3 +1,5 @@ +/// + import { expect } from "chai"; import "es6-symbol/implement"; import { diff --git a/test/globals.d.ts b/test/globals.d.ts new file mode 100644 index 000000000..936a1e559 --- /dev/null +++ b/test/globals.d.ts @@ -0,0 +1,4 @@ + +declare module "es6-symbol/implement" { + /* declares globals */ +} diff --git a/test/inversify.test.ts b/test/inversify.test.ts index 6088d2c04..349c41bf2 100644 --- a/test/inversify.test.ts +++ b/test/inversify.test.ts @@ -1,3 +1,5 @@ +/// + import interfaces from "../src/interfaces/interfaces"; import { expect } from "chai"; import "es6-symbol/implement"; diff --git a/tsconfig.json b/tsconfig.json index 8fb292630..b4c0d80b7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "target": "es5", + "lib": ["es6", "dom"], "module": "commonjs", "moduleResolution": "node", "isolatedModules": false, @@ -10,14 +11,12 @@ "declaration": false, "noImplicitAny": true, "removeComments": true, - "noLib": false, "preserveConstEnums": true, "suppressImplicitAnyIndexErrors": false }, "files": [ "./typings/index.d.ts", "./node_modules/reflect-metadata/reflect-metadata.d.ts", - "./src/interfaces/globals.d.ts", "./src/inversify.ts" ] } \ No newline at end of file diff --git a/typings.json b/typings.json index 39db6052e..a2091537d 100644 --- a/typings.json +++ b/typings.json @@ -1,7 +1,6 @@ { "name": "inversify", "globalDependencies": { - "bluebird": "registry:dt/bluebird#2.0.0+20160701023356", "chai": "registry:dt/chai#3.4.0+20160601211834", "harmony-proxy": "registry:dt/harmony-proxy#1.0.0+20160317120654", "mocha": "registry:dt/mocha#2.2.5+20160720003353", From 3690a17b8c209289ad59b061fc4af2e1d617687f Mon Sep 17 00:00:00 2001 From: remojansen Date: Thu, 8 Sep 2016 00:53:55 +0100 Subject: [PATCH 3/7] [WIP] #330 --- gulpfile.js | 71 +++-------------------------------------------------- 1 file changed, 3 insertions(+), 68 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 674f68f65..e335767c7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -18,7 +18,6 @@ var gulp = require("gulp"), uglify = require("gulp-uglify"), rename = require("gulp-rename"), runSequence = require("run-sequence"), - header = require("gulp-header"), mocha = require("gulp-mocha"), istanbul = require("gulp-istanbul"), karma = require("karma"); @@ -39,65 +38,8 @@ gulp.task("lint", function() { }); //****************************************************************************** -//* SOURCE +//* BUILD //****************************************************************************** -var banner = ["/**", - " * <%= pkg.name %> v.<%= pkg.version %> - <%= pkg.description %>", - " * Copyright (c) 2015 <%= pkg.author %>", - " * <%= pkg.license %> inversify.io/LICENSE", - " * <%= pkg.homepage %>", - " */", - ""].join("\n"); - -var pkg = require("./package.json"); - -gulp.task("build-bundle-src", function() { - - var mainTsFilePath = "src/inversify.ts"; - var outputFolder = "dist/"; - var outputFileName = "inversify.js"; - - var bundler = browserify({ - debug: true, - standalone : "inversify" - }); - - // TS compiler options are in tsconfig.json file - return bundler.add(mainTsFilePath) - .plugin(tsify, { typescript: require("typescript") }) - .bundle() - .pipe(source(outputFileName)) - .pipe(buffer()) - .pipe(sourcemaps.init({ loadMaps: true })) - .pipe(header(banner, { pkg : pkg } )) - .pipe(sourcemaps.write(".")) - .pipe(gulp.dest(outputFolder)); -}); - -gulp.task("build-bundle-compress-src", function() { - - var mainTsFilePath = "src/inversify.ts"; - var outputFolder = "dist/"; - var outputFileName = "inversify.min.js"; - - var bundler = browserify({ - debug: true, - standalone : "inversify" - }); - - // TS compiler options are in tsconfig.json file - return bundler.add(mainTsFilePath) - .plugin(tsify) - .bundle() - .pipe(source(outputFileName)) - .pipe(buffer()) - .pipe(sourcemaps.init({ loadMaps: true })) - .pipe(uglify()) - .pipe(header(banner, { pkg : pkg } )) - .pipe(sourcemaps.write(".")) - .pipe(gulp.dest(outputFolder)); -}); - var tsLibProject = tsc.createProject("tsconfig.json", { module : "commonjs", typescript: require("typescript") }); gulp.task("build-lib", function() { @@ -110,9 +52,7 @@ gulp.task("build-lib", function() { .on("error", function (err) { process.exit(1); }) - .js - .pipe(header(banner, { pkg : pkg } )) - .pipe(gulp.dest("lib/")); + .js.pipe(gulp.dest("lib/")); }); var tsEsProject = tsc.createProject("tsconfig.json", { module : "es2015", typescript: require("typescript") }); @@ -127,9 +67,7 @@ gulp.task("build-es", function() { .on("error", function (err) { process.exit(1); }) - .js - .pipe(header(banner, { pkg : pkg } )) - .pipe(gulp.dest("es/")); + .js.pipe(gulp.dest("es/")); }); //****************************************************************************** @@ -202,7 +140,6 @@ gulp.task("build-bundle-test", function() { .pipe(source(outputFileName)) .pipe(buffer()) .pipe(sourcemaps.init({ loadMaps: true })) - .pipe(header(banner, { pkg : pkg } )) .pipe(sourcemaps.write(".")) .pipe(gulp.dest(outputFolder)); }); @@ -238,8 +175,6 @@ if (process.env.APPVEYOR) { gulp.task("build", function(cb) { runSequence( "lint", - "build-bundle-src", // for nodejs - "build-bundle-compress-src", // for browsers ["build-src", "build-es", "build-lib"], // tests + build es and lib "build-test", cb); }); From 9dcacbb5122601adb60576e60373cb7a586c8a37 Mon Sep 17 00:00:00 2001 From: remojansen Date: Thu, 8 Sep 2016 01:12:24 +0100 Subject: [PATCH 4/7] Auto generate dts files --- .gitignore | 1 + gulpfile.js | 22 +++++++++++++++++++++- package.json | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f68017090..b83eda8c0 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ bundled typings .typingsrc dist +dts lib temp es diff --git a/gulpfile.js b/gulpfile.js index e335767c7..21b8b59f0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -70,6 +70,26 @@ gulp.task("build-es", function() { .js.pipe(gulp.dest("es/")); }); +var tsDtsProject = tsc.createProject("tsconfig.json", { + declaration: true, + noExternalResolve: false, + typescript: require("typescript") +}); + +gulp.task("build-dts", function() { + return gulp.src([ + "typings/index.d.ts", + "node_modules/reflect-metadata/reflect-metadata.d.ts", + "src/**/*.ts" + ]) + .pipe(tsc(tsDtsProject)) + .on("error", function (err) { + process.exit(1); + }) + .dts.pipe(gulp.dest("dts")); + +}); + //****************************************************************************** //* TESTS NODE //****************************************************************************** @@ -175,7 +195,7 @@ if (process.env.APPVEYOR) { gulp.task("build", function(cb) { runSequence( "lint", - ["build-src", "build-es", "build-lib"], // tests + build es and lib + ["build-src", "build-es", "build-lib", "build-dts"], // tests + build es and lib "build-test", cb); }); diff --git a/package.json b/package.json index 3a435df43..0419b5869 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "A powerful and lightweight inversion of control container for JavaScript and Node.js apps powered by TypeScript.", "main": "lib/inversify.js", "jsnext:main": "es/inversify.js", + "typings": "./dts/inversify.d.ts", "directories": { "test": "gulp" }, From 5ced5192f0607915e3ebae3367cba61293fcec4a Mon Sep 17 00:00:00 2001 From: remojansen Date: Thu, 8 Sep 2016 01:40:02 +0100 Subject: [PATCH 5/7] Updated docs --- README.md | 60 ++++++++++++++++++++------------------------- tsconfig.json | 2 -- wiki/environment.md | 16 ++++-------- 3 files changed, 31 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index c263b6bfe..51608412e 100644 --- a/README.md +++ b/README.md @@ -57,38 +57,39 @@ InversifyJS has been developed with 4 main goals: You can get the latest release and the type definitions using npm: ``` -npm install inversify@2.0.0-rc.13 reflect-metadata --save -npm install inversify-dts --save-dev +npm install inversify@2.0.0-rc.14 reflect-metadata --save ``` -You will also need the type definitions files for inversify and reflect-metadata. +The InversifyJS type definitions are included in the inversify npm package. +You will also need the type definitions files for `reflect-metadata`. +The `reflect-metadata` type definitions are included in its npm package. -The InversifyJS type definitions are included in the inversify-dts npm package: +InversifyJS requires the `experimentalDecorators`, `emitDecoratorMetadata` +and `lib` compilation options in your `tsconfig.json` file: -```ts -/// -``` - -The reflect-metadata type definitions are included in the npm package: - -```ts -/// ``` - -InversifyJS requires a modern JavaScript engine with support for the Promise, Reflect (with metadata) and Proxy objects. -If your environment don't support one of these you will need to import a shim or polyfill. If you are targeting ES5 you will get the following error: - -> TypeScript error: node_modules/inversify-dts/inversify/inversify.d.ts(108,13): Error TS2304: Cannot find name 'Promise'. - -You can solve this problem by installing type definitions for the Promise API. If you are working on node the node type definitions already include the required definitions. If you are working on a browser app you can use the bluebird type definitions and polyfill: - -``` -$ typings install --save --global dt~bluebird +{ + "compilerOptions": { + "target": "es5", + "lib": ["es6", "dom"], + "module": "commonjs", + "moduleResolution": "node", + "jsx": "react", + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "noImplicitAny": true + }, + "files": [ + "./node_modules/reflect-metadata/reflect-metadata.d.ts", + ] +} ``` - Check out the [Environment support and polyfills](https://github.com/inversify/InversifyJS/blob/master/wiki/environment.md) page in the wiki to learn more. +InversifyJS requires a modern JavaScript engine with support for the Promise, Reflect Metadats and Proxy objects. +If your environment don't support one of these you will need to import a shim or polyfill. -The relect-metadata polyfill can be importing as follows: +At the time of writing this guide (September 2016) it is necesary to +use the `relect-metadata` polyfill. This polyfill can be importing as follows: ```ts import "reflect-metadata"; @@ -96,16 +97,7 @@ import "reflect-metadata"; > **The `reflect-metadata` polyfill should be imported only once in your entire application** because the Reflect object is mean to be a global singleton. More details about this can be found [here](https://github.com/inversify/InversifyJS/issues/262#issuecomment-227593844). -InversifyJS requires the following TypeScript compilation options in your `tsconfig.json` file: - -``` -{ - "compilerOptions": { - "experimentalDecorators": true, - "emitDecoratorMetadata": true - } -} -``` +Check out the [Environment support and polyfills](https://github.com/inversify/InversifyJS/blob/master/wiki/environment.md) page in the wiki to learn more. ### The Basics (TypeScript) Let’s take a look to the basic usage and APIs of InversifyJS with TypeScript: diff --git a/tsconfig.json b/tsconfig.json index b4c0d80b7..f14e390d2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,11 +4,9 @@ "lib": ["es6", "dom"], "module": "commonjs", "moduleResolution": "node", - "isolatedModules": false, "jsx": "react", "experimentalDecorators": true, "emitDecoratorMetadata": true, - "declaration": false, "noImplicitAny": true, "removeComments": true, "preserveConstEnums": true, diff --git a/wiki/environment.md b/wiki/environment.md index 6400667ff..6819f18dd 100644 --- a/wiki/environment.md +++ b/wiki/environment.md @@ -21,19 +21,16 @@ import "reflect-metadata"; ``` This will create the Reflect object as a global. +> **The `reflect-metadata` polyfill should be imported only once in your entire application** because the Reflect object is mean to be a global singleton. More details about this can be found [here](https://github.com/inversify/InversifyJS/issues/262#issuecomment-227593844). + ## Promise Required only if you use want to [inject a provider](https://github.com/inversify/InversifyJS#injecting-a-provider-asynchronous-factory). -Use the [bluebird](https://www.npmjs.com/package/bluebird) as polyfill. -``` -$ npm install bluebird -$ typings install bluebird +Use the [bluebird](https://www.npmjs.com/package/bluebird) polyfill. ``` -After installing it add a reference to the `bluebird.d.ts` file: +$ npm install bluebird @types/bluebird ``` -/// -``` -Finally, import bluebird: +After installing you will be able to import bluebird: ``` import "bluebird"; ``` @@ -42,6 +39,3 @@ This will create the Promise object as a global. ## Proxy Required only if you want to [inject a proxy](https://github.com/inversify/InversifyJS#injecting-a-proxy). Use [harmony-proxy](https://www.npmjs.com/package/harmony-proxy) as polyfill. - -**Important** There is an issue with this feature at the moment. -You can track the progress [here](https://github.com/inversify/InversifyJS/issues/106). From 1339e23e69a231e634a0cb151b4244fb998b8590 Mon Sep 17 00:00:00 2001 From: remojansen Date: Thu, 8 Sep 2016 18:23:34 +0100 Subject: [PATCH 6/7] [WIP] trying to fix 'Cannot find global type Array' --- PULL_REQUEST_TEMPLATE.md | 2 -- tsconfig.json | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index ed0b8f0db..5d5e54371 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -29,8 +29,6 @@ - [ ] My code follows the code style of this project. - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. -- [ ] My change requires a change to the type definitions. -- [ ] I have updated the type definitions accordingly. - [ ] I have read the **CONTRIBUTING** document. - [ ] I have added tests to cover my changes. - [ ] All new and existing tests passed. diff --git a/tsconfig.json b/tsconfig.json index f14e390d2..7a29d5f71 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,8 @@ "noImplicitAny": true, "removeComments": true, "preserveConstEnums": true, - "suppressImplicitAnyIndexErrors": false + "suppressImplicitAnyIndexErrors": false, + "noResolve": false }, "files": [ "./typings/index.d.ts", From db68752e2077d288f1022b3aba60a2179d6c4ee9 Mon Sep 17 00:00:00 2001 From: remojansen Date: Fri, 9 Sep 2016 00:51:55 +0100 Subject: [PATCH 7/7] Removed tsify --- gulpfile.js | 11 ++++------- package.json | 1 - 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 21b8b59f0..6aa43ae8c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -9,7 +9,6 @@ require("harmonize")(); var gulp = require("gulp"), browserify = require("browserify"), - tsify = require("tsify"), source = require("vinyl-source-stream"), buffer = require("vinyl-buffer"), tslint = require("gulp-tslint"), @@ -142,9 +141,9 @@ gulp.task("istanbul:hook", function() { //****************************************************************************** //* TESTS BROWSER //****************************************************************************** -gulp.task("build-bundle-test", function() { +gulp.task("bundle-test", function() { - var mainTsFilePath = "test/inversify.test.ts"; + var mainJsFilePath = "test/inversify.test.js"; var outputFolder = "temp/"; var outputFileName = "bundle.test.js"; @@ -153,9 +152,7 @@ gulp.task("build-bundle-test", function() { standalone : "inversify" }); - // TS compiler options are in tsconfig.json file - return bundler.add(mainTsFilePath) - .plugin(tsify, { typescript: require("typescript") }) + return bundler.add(mainJsFilePath) .bundle() .pipe(source(outputFileName)) .pipe(buffer()) @@ -164,7 +161,7 @@ gulp.task("build-bundle-test", function() { .pipe(gulp.dest(outputFolder)); }); -gulp.task("karma", ["build-bundle-test"], function (done) { +gulp.task("karma", ["bundle-test"], function (done) { new karma.Server({ configFile: __dirname + "/karma.conf.js" }, function(code) { diff --git a/package.json b/package.json index 0419b5869..703b6eb52 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,6 @@ "reflect-metadata": "^0.1.3", "run-sequence": "^1.2.0", "sinon": "^1.17.3", - "tsify": "^1.0.3", "tslint": "^3.12.0", "typescript": "^2.0.2", "typings": "^1.0.4",