I have a large Typescript project that gets Concatenated in to a single JS file for deployment. What is the correct way to ensure that the files are given in the correct order for concatenation? There are far too many files to try and maintain it by hand.
If a class in file A is dependent on a class in file B, then the ordering of the classes in the resultant concatenated file is important. If file B appears later than file A then at runtime the class cannot be resolved.
This must surely be a common problem and there should be a simple solution to it. One caveat is that I use namespaces and not modules. I'm not sure if using modules across the project would resolve this issue at all.
Here is a quick example TestClassA.ts
namespace Test {
'use strict';
import TestClassB = Test.TestClassB;
export class TestClassA {
private test: TestClassB;
constructor() {
this.test = new TestClassB();
}
}
}
TestClassB.ts
namespace Test {
'use strict';
export class TestClassB {
private value: string;
constructor() {
this.value = 'test';
}
}
}
TestClass.spec.ts
'use strict';
describe('test', (): void => {
it ('should create an object', (): void => {
let a: Test.TestClassA = new Test.TestClassA();
expect(a).toBeDefined();
});
});
In the Karma.config file specify the files as
files: [
'src/**/*.js',
'test/**/*.spec.js'
],
the test will fail with the exception TestClassB is not a constructor.
If instead I specify the Karma.config files as files: ['src/TestClassB.ts','src/TestClassA.ts','test/**/*.spec.ts']
Then the test will pass.
But doing this for a project with hundreds of files becomes unmaintainable.