dts-generator icon indicating copy to clipboard operation
dts-generator copied to clipboard

Glob feature breaks excludes list

Open alexswan10k opened this issue 9 years ago • 5 comments

Commit 6bf53678d85623a49fe1581beeef4c194a7771f4 fixing #26 unfortunately broke the use of relative paths with the exclusion list. As globbing occurs from the working directory, you effectively find the relative path injected twice:

baseDir: ./SomePath/SomeSubPath
excludes: [SomeFile.ts]

becomes:

./SomePath/SomeSubPath/SomePath/SomeSubPath/SomeFile.ts

Fix is simple, glob sync operation simply needs to take a relative path.

(index.ts line 124)
glob.sync(filename, {cwd: baseDir}).forEach(.....

I would fix this myself and submit a pull request, but unfortunately there is not much chance of getting the CLA agreement past my organization.

alexswan10k avatar Oct 19 '15 10:10 alexswan10k

I am going to move this to 1.7.0, because I think if using the tsconfig.json works for you, then all the files will be resolved within there. I will think about how to better make excluding work better via the command line, but I would like to get 1.6.0 out there since it is causing a lot of grief to folks.

kitsonk avatar Nov 03 '15 12:11 kitsonk

Thanks for taking a look.

alexswan10k avatar Nov 03 '15 17:11 alexswan10k

Just my two cents: I have just run into this problem.

I have a project directory which includes a typings directory created and maintained with tsd. I do not want the tsd files from the typings directory to be included in my tsd file, but if I exclude them in tsconfig.json tsc will not compile, and if I try using the exclude option in dts-generator it excludes files based in the current working directory - not the baseDir I have provided.

My options for dts-generator look something like this:

{
    baseDir: 'AMDComponents',
    name: 'AMDComponents',
    project: 'AMDComponents',
    out: 'build/AMDComponents/AMDComponents.d.ts',
    exclude: ['node_modules/**/*.d.ts', 'typings/**/*.d.ts'],
    verbose: true
}

dts-generator tries to exclude the following files (I have a node_modules directory in the current working directory, but not in baseDir):

node_modules/typescript/lib/lib.core.d.ts
node_modules/typescript/lib/lib.core.es6.d.ts
node_modules/typescript/lib/lib.d.ts
node_modules/typescript/lib/lib.dom.d.ts
node_modules/typescript/lib/lib.es6.d.ts
node_modules/typescript/lib/lib.scriptHost.d.ts
node_modules/typescript/lib/lib.webworker.d.ts
node_modules/typescript/lib/typescript.d.ts
node_modules/typescript/lib/typescriptServices.d.ts

What I think should be the correct functionality (which works with the change suggested by @Metal10k) is for the following files to be excluded:

typings/knockout/knockout.d.ts
typings/tsd.d.ts

This means that my dts file includes the knockout typings, which I do not want.

I am happy to submit a pull request with @Metal10k's change if you like.

MortenHoustonLudvigsen avatar Nov 05 '15 16:11 MortenHoustonLudvigsen

Don't know if related, but I cannot get excludes working. If I run this:

require('dts-generator').default({
    name: 'aurelia-json',
    project: '.',
    files: [
      'src/schema.ts',
      'src/message-interceptor.ts'
    ],
    excludes: [ 'jspm_packages/**/*.d.ts' ],
    out: 'dist/aurelia-json.d.ts'
});

I get all definitions of modules in jspm_packages/**/*.d.ts bundled and not excluded.

heruan avatar Dec 21 '15 12:12 heruan

@heruan please use exclude instead of excludes which is in the readme document. @kitsonk but i find if i use baseDir, the code

excludesMap[filenameToMid(pathUtil.resolve(baseDir, globFileName))] = true;[line:134] will add the 'basedir' to exludeslists, and which would cause a bug in

if (excludesMap[filenameToMid(pathUtil.normalize(sourceFile.fileName))]) {[line:170] is this a bug or if i use this in the incorrect way?

taoqf avatar Feb 22 '16 02:02 taoqf