Skip to content

Commit

Permalink
Merge branch 'master' into issue/#1779
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfirst authored Jul 16, 2019
2 parents c7f45a2 + d5d11af commit dc8fb1a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [unreleased]

- [#1779](https://github.com/teambit/bit/issues/1779) update bit-javascript to prioritize custom-resolve settings
- avoid generating duplicate `require` statements within dependency links files of ES6
- generate an index.d.ts file for node_modules links generated for custom-resolve-modules of typescript components
- [#1808](https://github.com/teambit/bit/issues/1808) support adding dist-path-template as a package-json value, which gets replaced with the calculated dist path upon import
- update execa to v2.0.3
- [#1792](https://github.com/teambit/bit/issues/1792) don't generate entry-point files for nested dependencies when their `package.json` is written
Expand Down
30 changes: 30 additions & 0 deletions e2e/flows/es6.e2e.3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { expect } from 'chai';
import Helper from '../e2e-helper';

describe('es6 components', function () {
this.timeout(0);
const helper = new Helper();
after(() => {
helper.destroyEnv();
});
describe('component that requires multiple variables from another component', () => {
before(() => {
helper.setNewLocalAndRemoteScopes();
helper.createFile('utils', 'index.js', 'export function isType() {}; export function isString() {};');
helper.createFile('bar', 'foo.js', 'import { isType, isString } from "../utils";');
helper.addComponent('utils/index.js');
helper.addComponentBarFoo();
helper.tagAllComponents();
helper.exportAllComponents();
helper.reInitLocalScope();
helper.addRemoteScope();
helper.importComponent('bar/foo');
});
it('the generated dependency link should not have duplicates', () => {
const dependencyLink = helper.readFile('components/bar/foo/utils/index.js');
const requireStatement = `require('@bit/${helper.remoteScope}.index');`;
const numOfOccurrences = dependencyLink.split(requireStatement).length - 1;
expect(numOfOccurrences).to.equal(1);
});
});
});
7 changes: 7 additions & 0 deletions e2e/typescript/typescript.e2e.3.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,13 @@ export class List extends React.Component {
const result = helper.runCmd('node app.js');
expect(result.trim()).to.equal('got is-type and got is-string and got foo');
});
it('should create index.d.ts file along with the index.js file inside the node_modules/custom-resolve', () => {
const expectedPath = path.join(
helper.localScopePath,
'components/bar/foo/node_modules/@/utils/is-string/index.d.ts'
);
expect(expectedPath).to.be.a.file();
});
});
describe('using bundler compiler that generates a dist file with a different name than the source', () => {
before(() => {
Expand Down
14 changes: 14 additions & 0 deletions src/links/dependency-file-link-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ export default class DependencyFileLinkGenerator {
this.linkFiles.push(linkFileInNodeModules);
}

if (getExt(this.relativePathInDependency) === 'ts') {
// this is needed for when building Angular components inside a capsule, so we don't care
// about the case when dist is outside the components
const linkFileTs = this.prepareLinkFile({
linkPath: this.getLinkPathForCustomResolve(relativeDistExtInDependency).replace('.js', '.d.ts'),
relativePathInDependency: relativePathInDependency.replace('.js', '.ts'),
depRootDir: isCustomResolvedWithDistInside ? depRootDirDist : depRootDir
});
if (this.createNpmLinkFiles && linkFile.linkContent) {
linkFileTs.postInstallLink = true;
}
this.linkFiles.push(linkFileTs);
}

return this.linkFiles;
}

Expand Down
7 changes: 4 additions & 3 deletions src/links/link-content.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
import normalize from 'normalize-path';
import R from 'ramda';
import fileTypesPlugins from '../plugins/file-types-plugins';
import { getWithoutExt, getExt } from '../utils';
import logger from '../logger/logger';
Expand Down Expand Up @@ -147,8 +148,8 @@ function tsTemplateWithImportSpecifiers(importSpecifiers) {
}

function es6TemplateWithImportSpecifiers(importSpecifiers) {
return importSpecifiers
.map((importSpecifier) => {
return R.uniq(
importSpecifiers.map((importSpecifier) => {
if (!importSpecifier.linkFile) {
// when no link-file is involved, use the standard non-es6 syntax (a privilege that doesn't exist for TS)
return LINKS_CONTENT_TEMPLATES.js;
Expand All @@ -169,5 +170,5 @@ function es6TemplateWithImportSpecifiers(importSpecifiers) {
: `${linkVariable}.${importSpecifier.mainFile.name}`;
return `${linkRequire}\n${exportPart} = ${pathPart};`;
})
.join('\n');
).join('\n');
}

0 comments on commit dc8fb1a

Please sign in to comment.