Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore files inside node_modules when removing declarations files #54

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/test/tmp
/test/build
!/test/src/typings/*.d.ts
!/test/src/node_modules/*.d.ts
/test/src/**/*.d.ts
/test/src/**/*.js
/test/src/**/*.js.map
Expand Down
9 changes: 5 additions & 4 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const identifierExp = /^\w+(?:[\.-]\w+)*$/;
const fileExp = /^([\./].*|.:.*)$/;
const privateExp = /^[ \t]*(?:static )?private (?:static )?/;
const publicExp = /^([ \t]*)(static |)(public |)(static |)(.*)/;
const nodeModulesExp = /\/node_modules\//;

export interface Options {
main: string;
Expand Down Expand Up @@ -374,11 +375,11 @@ export function bundle(options: Options): BundleResult {
if (removeSource) {
trace('\n### remove source typings ###');

sourceTypings.forEach(p => {
sourceTypings.forEach((filePath: string) => {
// safety check, only delete .d.ts files, leave our outFile intact for now
if (p !== outFile && dtsExp.test(p) && fs.statSync(p).isFile()) {
trace(' - %s', p);
fs.unlinkSync(p);
if (filePath !== outFile && dtsExp.test(filePath) && !nodeModulesExp.test(filePath) && fs.statSync(filePath).isFile()) {
trace(' - %s', filePath);
fs.unlinkSync(filePath);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@types/detect-indent": "0.1.30",
"@types/glob": "5.0.30",
"@types/mkdirp": "0.3.29",
"@types/node": "8.0.0",
"@types/node": "8.0.14",
"commander": "^2.9.0",
"detect-indent": "^0.2.0",
"glob": "^6.0.4",
Expand Down
3 changes: 3 additions & 0 deletions test/expected/default/foo-mx.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Dependencies for this module:
// ../../src/typings/external.d.ts
// ../../src/node_modules/modules.d.ts

declare module 'foo-mx' {
import exp = require('foo-mx/lib/exported-sub');
import mod1 = require('external1');
import nodeModule = require('node_module');
export import Foo = require('foo-mx/Foo');
export function run(foo?: Foo): Foo;
export function flep(): exp.ExternalContainer;
export function bar(): mod1.SomeType;
export function baz(): nodeModule.SomeType;
}

declare module 'foo-mx/lib/exported-sub' {
Expand Down
3 changes: 3 additions & 0 deletions test/expected/excludeExp/foo-mx.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Dependencies for this module:
// ../../src/typings/external.d.ts
// ../../src/node_modules/modules.d.ts

declare module 'foo-mx' {
import exp = require('foo-mx/lib/exported-sub');
import mod1 = require('external1');
import nodeModule = require('node_module');
export import Foo = require('foo-mx/Foo');
export function run(foo?: Foo): Foo;
export function flep(): exp.ExternalContainer;
export function bar(): mod1.SomeType;
export function baz(): nodeModule.SomeType;
}

declare module 'foo-mx/Foo' {
Expand Down
3 changes: 3 additions & 0 deletions test/expected/excludeFunc/foo-mx.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Dependencies for this module:
// ../../src/typings/external.d.ts
// ../../src/node_modules/modules.d.ts

declare module 'foo-mx' {
import exp = require('foo-mx/lib/exported-sub');
import mod1 = require('external1');
import nodeModule = require('node_module');
export import Foo = require('foo-mx/Foo');
export function run(foo?: Foo): Foo;
export function flep(): exp.ExternalContainer;
export function bar(): mod1.SomeType;
export function baz(): nodeModule.SomeType;
}

declare module 'foo-mx/Foo' {
Expand Down
8 changes: 8 additions & 0 deletions test/expected/externals/foo-mx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
declare module 'foo-mx' {
import exp = require('foo-mx/lib/exported-sub');
import mod1 = require('foo-mx/index//external1');
import nodeModule = require('foo-mx/index//node_module');
export import Foo = require('foo-mx/Foo');
export function run(foo?: Foo): Foo;
export function flep(): exp.ExternalContainer;
export function bar(): mod1.SomeType;
export function baz(): nodeModule.SomeType;
}

declare module 'foo-mx/index//external1' {
Expand All @@ -20,6 +22,12 @@ declare module 'foo-mx/index//external2' {
}
}

declare module 'foo-mx/index//node_module' {
export class SomeType {
foo(): void;
}
}

declare module 'foo-mx/lib/exported-sub' {
import Foo = require('foo-mx/Foo');
import mod2 = require('foo-mx/index//external2');
Expand Down
8 changes: 8 additions & 0 deletions test/expected/includeExclude/foo-mx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
declare module 'foo-mx' {
import exp = require('foo-mx/lib/exported-sub');
import mod1 = require('foo-mx/index//external1');
import nodeModule = require('foo-mx/index//node_module');
export import Foo = require('foo-mx/Foo');
export function run(foo?: Foo): Foo;
export function flep(): exp.ExternalContainer;
export function bar(): mod1.SomeType;
export function baz(): nodeModule.SomeType;
}

declare module 'foo-mx/index//external1' {
Expand All @@ -20,6 +22,12 @@ declare module 'foo-mx/index//external2' {
}
}

declare module 'foo-mx/index//node_module' {
export class SomeType {
foo(): void;
}
}

declare module 'foo-mx/Foo' {
class Foo {
foo: string;
Expand Down
3 changes: 3 additions & 0 deletions test/expected/out/fizz/buzz.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Dependencies for this module:
// ../../src/typings/external.d.ts
// ../../src/node_modules/modules.d.ts

declare module 'foo-mx' {
import exp = require('foo-mx/lib/exported-sub');
import mod1 = require('external1');
import nodeModule = require('node_module');
export import Foo = require('foo-mx/Foo');
export function run(foo?: Foo): Foo;
export function flep(): exp.ExternalContainer;
export function bar(): mod1.SomeType;
export function baz(): nodeModule.SomeType;
}

declare module 'foo-mx/lib/exported-sub' {
Expand Down
3 changes: 3 additions & 0 deletions test/expected/remove/foo-mx.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Dependencies for this module:
// ../../src/typings/external.d.ts
// ../../src/node_modules/modules.d.ts

declare module 'foo-mx' {
import exp = require('foo-mx/lib/exported-sub');
import mod1 = require('external1');
import nodeModule = require('node_module');
export import Foo = require('foo-mx/Foo');
export function run(foo?: Foo): Foo;
export function flep(): exp.ExternalContainer;
export function bar(): mod1.SomeType;
export function baz(): nodeModule.SomeType;
}

declare module 'foo-mx/lib/exported-sub' {
Expand Down
3 changes: 3 additions & 0 deletions test/expected/seprinnew/bar-mx.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Dependencies for this module: //$
// ../../src/typings/external.d.ts //$
// ../../src/node_modules/modules.d.ts //$
//$
declare module 'bar-mx' { //$
import exp = require('--bar-mx#lib#exported-sub'); //$
import mod1 = require('external1'); //$
import nodeModule = require('node_module'); //$
export import Foo = require('--bar-mx#Foo'); //$
export function run(foo?: Foo): Foo; //$
export function flep(): exp.ExternalContainer; //$
export function bar(): mod1.SomeType; //$
export function baz(): nodeModule.SomeType; //$
} //$
//$
declare module '--bar-mx#lib#exported-sub' { //$
Expand Down
7 changes: 7 additions & 0 deletions test/src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/// <reference path="./../typings/external.d.ts" />
/// <reference path="./../node_modules/modules.d.ts" />

import int = require('./lib/only-internal');
import exp = require('./lib/exported-sub');
import mod1 = require('external1');
import nodeModule = require('node_module');

export import Foo = require('./Foo');
/*
Expand All @@ -23,3 +25,8 @@ export function flep(): exp.ExternalContainer {
export function bar(): mod1.SomeType {
return new mod1.SomeType();
}

// baz some of that
export function baz(): nodeModule.SomeType {
return new nodeModule.SomeType();
}
5 changes: 5 additions & 0 deletions test/src/node_modules/modules.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.