Skip to content

Commit

Permalink
Merge pull request #437 from 07akioni/fix-dts-import
Browse files Browse the repository at this point in the history
Fix import .d.ts as dependency
  • Loading branch information
erikbarke authored Mar 1, 2021
2 parents 0fb19ea + 59c6401 commit b7e27ef
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions examples/angular2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"karma-typescript": "latest",
"karma-typescript-angular2-transform": "latest",
"rxjs": "^6.5.4",
"csstype": "^3.0.7",
"typescript": "latest"
}
}
2 changes: 2 additions & 0 deletions examples/angular2/src/app/hello.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Component } from "@angular/core";
// Testing a type only import
import { Properties } from 'csstype'

@Component({
selector: "app-hello",
Expand Down
2 changes: 1 addition & 1 deletion packages/karma-typescript/src/bundler/bundle-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class BundleItem {
}

public isScript(): boolean {
return (this.filename && /\.(js|jsx|mjs|ts|tsx)$/.test(this.filename))
return (this.filename && !this.isTypingsFile() && /\.(js|jsx|mjs|ts|tsx)$/.test(this.filename))
|| this.transformedScript;
}

Expand Down
22 changes: 14 additions & 8 deletions packages/karma-typescript/src/bundler/resolve/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,20 @@ export class Resolver {
return onFilenameResolved();
}

// This is probably a compiler path module (.d.ts)
if (bundleItem.isNpmModule() && bundleItem.isTypingsFile() &&
bundleItem.filename.indexOf(bundleItem.moduleName) === -1) {
const filepath = PathTool.fixWindowsPath(bundleItem.filename);
const matches = filepath.match(/\/node_modules\/(.*)\//);
if (matches && matches[1]) {
moduleName = matches[1];
this.log.debug("Resolved module name [%s] to [%s]", bundleItem.moduleName, moduleName);

if (bundleItem.isNpmModule() && bundleItem.isTypingsFile()) {
// This is probably a compiler path module (.d.ts)
if (bundleItem.filename.indexOf(bundleItem.moduleName) === -1) {
const filepath = PathTool.fixWindowsPath(bundleItem.filename);
const matches = filepath.match(/\/node_modules\/(.*)\//);
if (matches && matches[1]) {
moduleName = matches[1];
this.log.debug("Resolved module name [%s] to [%s]", bundleItem.moduleName, moduleName);
}
}
// This is probably a type only module import
else {
return onFilenameResolved()
}
}

Expand Down

0 comments on commit b7e27ef

Please sign in to comment.