Skip to content
This repository was archived by the owner on Dec 4, 2022. It is now read-only.

Commit 6930960

Browse files
author
David First
committed
resolve teambit/bit#1925, fix Angular non-relative paths from decorators
1 parent 90c10d1 commit 6930960

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [unreleased]
99

10+
- [#1925](https://github.com/teambit/bit/issues/1925) fix Angular non-relative paths from decorators
11+
1012
## [2.1.1-dev.1] - 2019-08-12
1113

1214
- remove angular dependencies. use typescript compiler to parse Angular Decorators

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dependency-builder/detectives/detective-typescript/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* this file had been forked from https://github.com/pahen/detective-typescript
33
*/
44
import { getDependenciesFromMemberExpression, getDependenciesFromCallExpression } from '../parser-helper';
5+
import { isRelativeImport } from '../../../utils';
56

67
const Parser = require('@typescript-eslint/typescript-estree');
78
const Walker = require('node-source-walk');
@@ -24,6 +25,10 @@ module.exports = function (src, options = {}) {
2425
dependencies[dependency] = {};
2526
}
2627
};
28+
const addAngularLocalDependency = (dependency) => {
29+
const angularDep = isRelativeImport(dependency) ? dependency : `./${dependency}`;
30+
addDependency(angularDep);
31+
};
2732
const addImportSpecifier = (dependency, importSpecifier) => {
2833
if (dependencies[dependency].importSpecifiers) {
2934
dependencies[dependency].importSpecifiers.push(importSpecifier);
@@ -106,14 +111,14 @@ module.exports = function (src, options = {}) {
106111
angularComponent.forEach((prop) => {
107112
if (!prop.key || !prop.value) return;
108113
if (prop.key.name === 'templateUrl' && prop.value.type === 'Literal') {
109-
addDependency(prop.value.value);
114+
addAngularLocalDependency(prop.value.value);
110115
}
111116
if (prop.key.name === 'styleUrl' && prop.value.type === 'Literal') {
112-
addDependency(prop.value.value);
117+
addAngularLocalDependency(prop.value.value);
113118
}
114119
if (prop.key.name === 'styleUrls' && prop.value.type === 'ArrayExpression') {
115120
const literalsElements = prop.value.elements.filter(e => e.type === 'Literal');
116-
literalsElements.forEach(element => addDependency(element.value));
121+
literalsElements.forEach(element => addAngularLocalDependency(element.value));
117122
}
118123
});
119124
}

src/dependency-builder/detectives/detective-typescript/index.spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ describe('detective-typescript', () => {
136136
@Component({
137137
selector: 'main-component',
138138
templateUrl: './my-template.html',
139-
styleUrls: ['./my-style1.css', styleUrl, './my-style3.css']
139+
styleUrls: ['./my-style1.css', styleUrl, './my-style3.css', 'my-style4.css']
140140
})
141141
export class MainComponent {}`;
142142
const results = detective(componentDecorator); // eslint-disable-line
@@ -152,5 +152,8 @@ describe('detective-typescript', () => {
152152
it('should not recognize dynamic style (style path entered as a variable)', () => {
153153
expect(deps).to.not.include('./my-style2.css');
154154
});
155+
it('should change non-relative paths to be relative', () => {
156+
expect(deps).to.include('./my-style4.css');
157+
});
155158
});
156159
});

0 commit comments

Comments
 (0)