diff --git a/Gruntfile.js b/Gruntfile.js index 5212b2e..73e3cc0 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -67,7 +67,11 @@ module.exports = function (grunt) { testConflicts: { src: ['test/src/conflicts/dirname/index.ts'], outDir: 'test/build/conflicts/dirname' - } + }, + testDotSlash: { + src: ['test/src/dot-slash/index.ts'], + outDir: 'test/build/dot-slash' + } }, mochaTest: { options: { @@ -92,6 +96,7 @@ module.exports = function (grunt) { 'ts:testEs6', 'ts:testCommonJs', 'ts:testConflicts', + 'ts:testDotSlash', 'run' ]); diff --git a/lib/index.ts b/lib/index.ts index 6e744c4..8446f34 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -183,7 +183,7 @@ export function bundle(options: Options): BundleResult { mainFileContent += generatedLine + "\n"; }); mainFile = path.resolve(baseDir, "dts-bundle.tmp." + exportName + ".d.ts"); - fs.writeFileSync(mainFile, mainFileContent, 'utf8'); + fs.writeFileSync(mainFile, mainFileContent, { encoding: 'utf8' }); } trace('\n### find typings ###'); @@ -424,7 +424,7 @@ export function bundle(options: Options): BundleResult { } } - fs.writeFileSync(outFile, content, 'utf8'); + fs.writeFileSync(outFile, content, { encoding: 'utf8' }); bundleResult.emitted = true; } else { warning(" XXX Not emit due to exist files not found.") diff --git a/test/expected/dot-slash/bundle.d.ts b/test/expected/dot-slash/bundle.d.ts new file mode 100644 index 0000000..7d271eb --- /dev/null +++ b/test/expected/dot-slash/bundle.d.ts @@ -0,0 +1,19 @@ + +declare module 'bundle' { + import { SomeOtherClass } from "bundle/SomeOtherClass"; + export interface IShouldBeThereOnlyOnce { + name: string; + } + export function getOther(): SomeOtherClass; +} + +declare module 'bundle/SomeOtherClass' { + import { IShouldBeThereOnlyOnce } from "bundle/"; + export class SomeOtherClass { + /** + * Extract metadata from the given audio file + */ + static saveTheWorld(once: IShouldBeThereOnlyOnce): Promise; + } +} + diff --git a/test/src/dot-slash/SomeOtherClass.ts b/test/src/dot-slash/SomeOtherClass.ts new file mode 100644 index 0000000..ca2f4b5 --- /dev/null +++ b/test/src/dot-slash/SomeOtherClass.ts @@ -0,0 +1,11 @@ +import {IShouldBeThereOnlyOnce} from "./"; + +export class SomeOtherClass { + + /** + * Extract metadata from the given audio file + */ + public static saveTheWorld(once: IShouldBeThereOnlyOnce): Promise { + return null; + } +} diff --git a/test/src/dot-slash/index.ts b/test/src/dot-slash/index.ts new file mode 100644 index 0000000..65fcf51 --- /dev/null +++ b/test/src/dot-slash/index.ts @@ -0,0 +1,13 @@ +'use strict'; + +import {SomeOtherClass} from "./SomeOtherClass"; + +const other: SomeOtherClass = new SomeOtherClass(); + +export interface IShouldBeThereOnlyOnce { + name: string, +} + +export function getOther(): SomeOtherClass { + return null; +} diff --git a/test/test.js b/test/test.js index 25f95dc..504dac0 100644 --- a/test/test.js +++ b/test/test.js @@ -532,4 +532,54 @@ describe('dts bundle', function () { ]); assert.strictEqual(getFile(actualFile), getFile(expectedFile)); }); + + (function testit(name, assertion, run) { + var buildDir = path.resolve(__dirname, 'build', name); + var call = function (done) { + var testDir = path.join(tmpDir, name); + var expDir = path.join(expectDir, name); + + mkdirp.sync(testDir); + + ncp.ncp(buildDir, testDir, function (err) { + if (err) { + done(err); + return; + } + assertion(testDir, expDir); + done(); + }); + }; + + var label = 'bundle ' + name; + + if (run === 'skip') { + it.skip(label, call); + } + else if (run === 'only') { + it.only(label, call); + } + else { + it(label, call); + } + })('dot-slash', function (actDir, expDir) { + var result = dts.bundle({ + name: 'bundle', + main: path.join(actDir, '../dot-slash', 'index.d.ts'), + newline: '\n', + verbose: true, + headerPath: "none" + }); + var name = 'bundle.d.ts'; + var actualFile = path.join(actDir, name); + assert.isTrue(result.emitted, "not emit " + actualFile); + var expectedFile = path.join(expDir, name); + assertFiles(actDir, [ + name, + 'index.d.ts', + 'SomeOtherClass.d.ts' + ]); + assert.strictEqual(getFile(actualFile), getFile(expectedFile)); + }) + });