Skip to content

Commit 037e455

Browse files
committed
Fix for conflicts where directory and file have same name
1 parent b87e617 commit 037e455

File tree

9 files changed

+95
-46
lines changed

9 files changed

+95
-46
lines changed

Gruntfile.js

+6-11
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@ module.exports = function (grunt) {
22
'use strict';
33

44
grunt.loadNpmTasks('grunt-ts');
5-
grunt.loadNpmTasks('grunt-dtsm');
65
grunt.loadNpmTasks('grunt-mocha-test');
76
grunt.loadNpmTasks('grunt-contrib-clean');
87

98
grunt.initConfig({
109
pkg: grunt.file.readJSON('package.json'),
11-
dtsm: {
12-
client: {
13-
options: {
14-
confog: './dtsm.json'
15-
}
16-
}
17-
},
1810
clean: {
1911
cruft: {
2012
option: {
@@ -45,7 +37,6 @@ module.exports = function (grunt) {
4537
main: {
4638
src: [
4739
'./lib/index.ts',
48-
'./typings/bundle.d.ts'
4940
],
5041
options: {
5142
"target": "es5",
@@ -72,6 +63,10 @@ module.exports = function (grunt) {
7263
testCommonJs: {
7364
src: ['test/src/commonjs/index.ts'],
7465
outDir: 'test/build/commonjs'
66+
},
67+
testConflicts: {
68+
src: ['test/src/conflicts/dirname/index.ts'],
69+
outDir: 'test/build/conflicts/dirname'
7570
}
7671
},
7772
mochaTest: {
@@ -88,15 +83,15 @@ module.exports = function (grunt) {
8883
grunt.registerTask('prep', [
8984
'clean:tmp',
9085
'clean:test',
91-
'clean:cruft',
92-
'dtsm'
86+
'clean:cruft'
9387
]);
9488

9589
grunt.registerTask('test', [
9690
'prep',
9791
'ts:test',
9892
'ts:testEs6',
9993
'ts:testCommonJs',
94+
'ts:testConflicts',
10095
'run'
10196
]);
10297

dtsm.json

-29
This file was deleted.

lib/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ export function bundle(options: Options): BundleResult {
539539
return name.replace(/\.\./g, '--').replace(/[\\\/]/g, separator);
540540
}
541541

542-
function mergeModulesLines(lines) {
542+
function mergeModulesLines(lines: any) {
543543
var i = (outputAsModuleFolder ? '' : indent);
544544
return (lines.length === 0 ? '' : i + lines.join(newline + i)) + newline;
545545
}
@@ -625,7 +625,7 @@ export function bundle(options: Options): BundleResult {
625625
}
626626
};
627627

628-
code.split(/\r?\n/g).forEach(line => {
628+
code.split(/\r?\n/g).forEach((line: any) => {
629629
let match: string[];
630630

631631
// block comment end
@@ -714,7 +714,7 @@ export function bundle(options: Options): BundleResult {
714714

715715
let full = path.resolve(path.dirname(file), impPath);
716716
// If full is not an existing file, then let's assume the extension .d.ts
717-
if(!fs.existsSync(full)) {
717+
if(!fs.existsSync(full) || fs.existsSync(full + '.d.ts')) {
718718
full += '.d.ts';
719719
}
720720
trace(' - import relative %s (%s)', moduleName, full);

package.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
},
3939
"main": "./index.js",
4040
"dependencies": {
41+
"@types/detect-indent": "0.1.30",
42+
"@types/glob": "5.0.30",
43+
"@types/mkdirp": "0.3.29",
44+
"@types/node": "8.0.0",
4145
"commander": "^2.9.0",
4246
"detect-indent": "^0.2.0",
4347
"glob": "^6.0.4",
@@ -49,12 +53,12 @@
4953
"grunt": "^0.4.5",
5054
"grunt-contrib-clean": "^0.5.0",
5155
"grunt-contrib-jshint": "^0.10.0",
52-
"grunt-dtsm": "^0.2.9",
56+
"grunt-dtsm": "1.0.0",
5357
"grunt-mocha-test": "^0.11.0",
54-
"grunt-ts": "^1.11.2",
58+
"grunt-ts": "^6.0.0-beta.16",
5559
"jshint-path-reporter": "^0.1.3",
5660
"mocha-unfunk-reporter": "^0.4.0",
5761
"ncp": "^0.5.1",
58-
"typescript": "^1.5.3"
62+
"typescript": "^2.3.4"
5963
}
6064
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
declare module 'foo-mx' {
3+
export * from 'foo-mx/file1';
4+
export * from 'foo-mx/file1/file2';
5+
}
6+
7+
declare module 'foo-mx/file1' {
8+
export class Foo1 {
9+
property1: number;
10+
constructor();
11+
}
12+
}
13+
14+
declare module 'foo-mx/file1/file2' {
15+
export class Foo2 {
16+
property2: string;
17+
constructor();
18+
}
19+
}
20+

test/src/conflicts/dirname/file1.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export class Foo1 {
2+
public property1: number;
3+
constructor() { }
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export class Foo2 {
2+
public property2: string;
3+
constructor() { }
4+
}

test/src/conflicts/dirname/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './file1';
2+
export * from './file1/file2';

test/test.js

+49
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,55 @@ describe('dts bundle', function () {
334334

335335
//testit('includeExclude_cli', function (actDir, expDir) { }); // No exclude options available from CLI.
336336

337+
(function testit(name, assertion, run) {
338+
var buildDir = path.resolve(__dirname, 'build', 'conflicts', 'dirname');
339+
var call = function (done) {
340+
var testDir = path.join(tmpDir, name);
341+
var expDir = path.join(expectDir, name);
342+
343+
mkdirp.sync(testDir);
344+
345+
ncp.ncp(buildDir, testDir, function (err) {
346+
if (err) {
347+
done(err);
348+
return;
349+
}
350+
assertion(testDir, expDir);
351+
done();
352+
});
353+
};
354+
355+
var label = 'bundle ' + name;
356+
357+
if (run === 'skip') {
358+
it.skip(label, call);
359+
}
360+
else if (run === 'only') {
361+
it.only(label, call);
362+
}
363+
else {
364+
it(label, call);
365+
}
366+
})('conflicts_dirname', function (actDir, expDir) {
367+
var result = dts.bundle({
368+
name: 'foo-mx',
369+
main: path.join(actDir, 'index.d.ts'),
370+
newline: '\n',
371+
verbose: true,
372+
headerPath: "none"
373+
});
374+
var name = 'foo-mx.d.ts';
375+
var actualFile = path.join(actDir, name);
376+
assert.isTrue(result.emitted, "not emit " + actualFile);
377+
var expectedFile = path.join(expDir, name);
378+
assertFiles(actDir, [
379+
name,
380+
'index.d.ts',
381+
'file1.d.ts',
382+
'file1/file2.d.ts',
383+
]);
384+
assert.strictEqual(getFile(actualFile), getFile(expectedFile));
385+
});
337386

338387
(function testit(name, assertion, run) {
339388
var buildDir = path.resolve(__dirname, 'build', 'es6');

0 commit comments

Comments
 (0)