##// END OF EJS Templates
Added support for commonjs module format, all tests are pass.
cin -
r60:b23fe4a1683a default
parent child
Show More
@@ -0,0 +1,22
1 var rjs = require('requirejs');
2
3 rjs.config({
4 baseUrl: '.',
5 packages: [{
6 name: "@implab/core",
7 location: "build/dist"
8 },
9 {
10 name: "test",
11 location: "build/test"
12 },
13 {
14 name: "dojo",
15 location: "node_modules/dojo"
16 }
17 ],
18 nodeRequire: require
19 });
20
21
22 rjs(['test/plan']); No newline at end of file
@@ -0,0 +1,20
1 module.exports = {
2 foo: {
3 $type: "./Foo:Foo"
4 },
5
6 bar: {
7 $type: "./Bar:Bar",
8 params: {
9 db: {
10 provider: {
11 $dependency: "db"
12 }
13 },
14 foo: {
15 $type: "./Foo:Foo"
16 }
17 }
18 },
19 db: "db://localhost"
20 };
@@ -0,0 +1,11
1 {
2 "name": "@implab/core-test",
3 "version": "0.0.1-dev",
4 "main": "main.js",
5 "author": "Implab team",
6 "license": "BSD-2-Clause",
7 "repository": "https://bitbucket.org/implab/implabjs",
8 "publishConfig": {
9 "access": "public"
10 }
11 }
@@ -0,0 +1,5
1 import "./ActivatableTests";
2 import "./TraceSourceTests";
3 import "./CancellationTests";
4 import "./ObservableTests";
5 import "./ContainerTests";
@@ -0,0 +1,1
1 import "./plan";
@@ -0,0 +1,22
1 {
2 "extends": "../tsconfig",
3 "compilerOptions": {
4 "rootDir": "ts",
5 "baseUrl": ".",
6 "paths": {
7 "@implab/core/*": [
8 "../../build/dist/*"
9 ]
10 },
11 "types": [
12 "node"
13 ],
14 "rootDirs": [
15 "ts",
16 "../typings/test"
17 ]
18 },
19 "include" : [
20 "ts/**/*.ts"
21 ]
22 } No newline at end of file
@@ -46,10 +46,11 def createSoursetTasks = { String name,
46 into outDir
46 into outDir
47 }
47 }
48
48
49 def compileTypingsTask = task "compileTypings$setName"(dependsOn: beforeBuildTask, type: Exec) {
49 def compileTsTask = task "compileTs$setName"(dependsOn: beforeBuildTask, type: Exec) {
50 inputs.dir("$setDir/ts")
50 inputs.dir("$setDir/ts")
51 inputs.file("$srcDir/tsconfig.json")
51 inputs.file("$srcDir/tsconfig.json")
52 inputs.file("$setDir/tsconfig.json")
52 inputs.file("$setDir/tsconfig.json")
53 outputs.dir(destDir)
53 outputs.dir(declDir)
54 outputs.dir(declDir)
54
55
55 commandLine 'node_modules/.bin/tsc',
56 commandLine 'node_modules/.bin/tsc',
@@ -57,36 +58,20 def createSoursetTasks = { String name,
57 '-t', target,
58 '-t', target,
58 '-m', jsmodule,
59 '-m', jsmodule,
59 '-d',
60 '-d',
60 '--emitDeclarationOnly',
61 '--outDir', destDir,
61 '--declarationDir', declDir
62 '--declarationDir', declDir
62
63
63 if (lib)
64 if (lib)
64 args '--lib', lib
65 args '--lib', lib
65 }
66 }
66
67
67 def compileTsTask = task "compileTs$setName"(dependsOn: beforeBuildTask, type: Exec) {
68 inputs.dir("$setDir/ts")
69 inputs.file("$srcDir/tsconfig.json")
70 inputs.file("$setDir/tsconfig.json")
71 outputs.dir(destDir)
72
73 commandLine 'node_modules/.bin/tsc',
74 '-p', "$setDir/tsconfig.json",
75 '-t', target,
76 '-m', jsmodule,
77 '--outDir', destDir
78
79 if (lib)
80 args '--lib', lib
81 }
82
83 def copyTsOutputTask = task "copyTsOutput$setName"(dependsOn: compileTsTask, type: Copy) {
68 def copyTsOutputTask = task "copyTsOutput$setName"(dependsOn: compileTsTask, type: Copy) {
84 from compileTsTask
69 from destDir
85 into outDir
70 into outDir
86 }
71 }
87
72
88 def copyTypingsTask = task "copyTypings$setName"(dependsOn: compileTypingsTask, type: Copy) {
73 def copyTypingsTask = task "copyTypings$setName"(dependsOn: compileTsTask, type: Copy) {
89 from compileTypingsTask
74 from declDir
90 into outDir
75 into outDir
91 }
76 }
92
77
@@ -153,16 +138,18 sourceSets.each { createSoursetTasks(it,
153 testSets.each { createSoursetTasks(it, testDir) }
138 testSets.each { createSoursetTasks(it, testDir) }
154
139
155 compileTsAmd {
140 compileTsAmd {
156 dependsOn compileTypingsMain
141 dependsOn compileTsMain
157 }
142 }
158
143
159 compileTypingsAmd {
144 compileTsCjs {
160 dependsOn compileTypingsMain
145 dependsOn compileTsMain
161 }
146 }
162
147
163 task build(dependsOn: buildMain) {
148 task build(dependsOn: buildMain) {
164 if (jsmodule == "amd")
149 if (jsmodule == "amd")
165 dependsOn buildAmd
150 dependsOn buildAmd
151 if (jsmodule == "commonjs")
152 dependsOn buildCjs
166 }
153 }
167
154
168 compileTsTest {
155 compileTsTest {
@@ -170,11 +157,33 compileTsTest {
170 }
157 }
171
158
172 compileTsTestAmd {
159 compileTsTestAmd {
173 dependsOn compileTypingsTestAmd
160 dependsOn compileTsTest
161 }
162
163 compileTsTestCjs {
164 dependsOn compileTsTest
165 }
166
167 task _installLocalCjsDependency(dependsOn: [buildTestCjs, "_packageMeta"], type: Exec) {
168 inputs.file("$distDir/package.json")
169 outputs.upToDateWhen {
170 new File("$testDir/$packageName").exists()
174 }
171 }
175
172
176 task test(dependsOn: [buildTest, buildTestAmd], type: Exec) {
173 workingDir testDir
177 commandLine 'node', "$testDir/run-amd-tests.js"
174
175 commandLine 'npm', 'install', '--no-save', '--force', distDir
176 }
177
178 task test(dependsOn: [buildTest], type: Exec) {
179 if (jsmodule == "amd")
180 dependsOn buildTestAmd
181 if (jsmodule == "commonjs") {
182 dependsOn buildTestCjs
183 dependsOn _installLocalCjsDependency
184 }
185
186 commandLine 'node', "$testDir/run-tests.js"
178 }
187 }
179
188
180 task _packageMeta(type: Copy) {
189 task _packageMeta(type: Copy) {
@@ -90,7 +90,7
90 },
90 },
91 "duplexer": {
91 "duplexer": {
92 "version": "0.1.1",
92 "version": "0.1.1",
93 "resolved": "http://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz",
93 "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz",
94 "integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=",
94 "integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=",
95 "dev": true
95 "dev": true
96 },
96 },
@@ -144,7 +144,7
144 "dependencies": {
144 "dependencies": {
145 "tape": {
145 "tape": {
146 "version": "2.3.3",
146 "version": "2.3.3",
147 "resolved": "http://registry.npmjs.org/tape/-/tape-2.3.3.tgz",
147 "resolved": "https://registry.npmjs.org/tape/-/tape-2.3.3.tgz",
148 "integrity": "sha1-Lnzgox3wn41oUWZKcYQuDKUFevc=",
148 "integrity": "sha1-Lnzgox3wn41oUWZKcYQuDKUFevc=",
149 "dev": true,
149 "dev": true,
150 "requires": {
150 "requires": {
@@ -277,7 +277,7
277 },
277 },
278 "minimist": {
278 "minimist": {
279 "version": "0.0.5",
279 "version": "0.0.5",
280 "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.5.tgz",
280 "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.5.tgz",
281 "integrity": "sha1-16oye87PUY+RBqxrjwA/o7zqhWY=",
281 "integrity": "sha1-16oye87PUY+RBqxrjwA/o7zqhWY=",
282 "dev": true
282 "dev": true
283 },
283 },
@@ -316,7 +316,7
316 },
316 },
317 "readable-stream": {
317 "readable-stream": {
318 "version": "1.1.14",
318 "version": "1.1.14",
319 "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
319 "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
320 "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
320 "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
321 "dev": true,
321 "dev": true,
322 "requires": {
322 "requires": {
@@ -369,7 +369,7
369 },
369 },
370 "string_decoder": {
370 "string_decoder": {
371 "version": "0.10.31",
371 "version": "0.10.31",
372 "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
372 "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
373 "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
373 "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
374 "dev": true
374 "dev": true
375 },
375 },
@@ -432,7 +432,7
432 },
432 },
433 "through2": {
433 "through2": {
434 "version": "0.2.3",
434 "version": "0.2.3",
435 "resolved": "http://registry.npmjs.org/through2/-/through2-0.2.3.tgz",
435 "resolved": "https://registry.npmjs.org/through2/-/through2-0.2.3.tgz",
436 "integrity": "sha1-6zKE2k6jEbbMis42U3SKUqvyWj8=",
436 "integrity": "sha1-6zKE2k6jEbbMis42U3SKUqvyWj8=",
437 "dev": true,
437 "dev": true,
438 "requires": {
438 "requires": {
@@ -59,6 +59,12 class ModuleResolver {
59 }
59 }
60
60
61 export function makeResolver(moduleName: string, contextRequire: Require) {
61 export function makeResolver(moduleName: string, contextRequire: Require) {
62 trace.debug(
63 "makeResolver moduleName={0}, contextRequire={1}",
64 moduleName || "<nil>",
65 contextRequire ? typeof (contextRequire) : "<nil>"
66 );
67
62 const base = moduleName && moduleName.split("/").slice(0, -1).join("/");
68 const base = moduleName && moduleName.split("/").slice(0, -1).join("/");
63
69
64 const resolver = new ModuleResolver(contextRequire, base);
70 const resolver = new ModuleResolver(contextRequire, base);
@@ -91,7 +91,11 export class Configuration {
91 async loadConfiguration(moduleName: string, contextRequire?: any, ct = Cancellation.none) {
91 async loadConfiguration(moduleName: string, contextRequire?: any, ct = Cancellation.none) {
92 argumentNotEmptyString(moduleName, "moduleName");
92 argumentNotEmptyString(moduleName, "moduleName");
93
93
94 trace.log("loadConfiguration moduleName={0}", moduleName);
94 trace.log(
95 "loadConfiguration moduleName={0}, contextRequire={1}",
96 moduleName,
97 contextRequire ? typeof (contextRequire) : "<nil>"
98 );
95
99
96 this._configName = moduleName;
100 this._configName = moduleName;
97
101
@@ -79,7 +79,7 test("Container configure/resolve tests"
79 test("Load configuration from module", async t => {
79 test("Load configuration from module", async t => {
80 const container = new Container();
80 const container = new Container();
81
81
82 await container.configure("test/mock/config1");
82 await container.configure("./mock/config1", { contextRequire: require });
83 t.pass("The configuration should load");
83 t.pass("The configuration should load");
84
84
85 const f1 = container.resolve("foo");
85 const f1 = container.resolve("foo");
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now