Skip to content

Commit

Permalink
fix(*): hotfix typings for components
Browse files Browse the repository at this point in the history
  • Loading branch information
stepancar committed Dec 13, 2019
1 parent 7edbacf commit 8427628
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 7 additions & 4 deletions gulp-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ const defaultOptions = {
tsComponentsGlob: ['src/*/*.tsx', '!src/*/*.test.tsx', '!src/*/*-benchmark.tsx'],
jsGlob: ['src/**/*.{js,jsx}', '!src/**/*.test.{js,jsx}', '!src/**/*-benchmark.{js,jsx}'],
autoDtsGlob: [
'src/**/*.{js,jsx}', 'src/**/index.{js,jsx}', '!src/**/*.test.{js,jsx}', '!src/**/*-benchmark.{js,jsx}'
'src/**/*.{js,jsx}', '!src/**/index.{js,jsx}', '!src/**/*.test.{js,jsx}', '!src/**/*-benchmark.{js,jsx}'
],
tsGlob: ['src/**/*.{ts,tsx}', '!src/**/*.test.{ts,tsx}', '!src/**/*-benchmark.{ts,tsx}'],
cssGlob: ['src/**/*.css', '!src/vars/**/*.css', '!src/vars*.css'],
cssCopyGlob: ['src/**/vars/**/*.css', 'src/vars*.css'],
resourcesGlob: ['src/**/*.{png,gif,jpg,svg,ttf,woff,json}'],
publishFilesGlob: ['package.json', '*.md', 'LICENSE?(.md)']
publishFilesGlob: ['package.json', '*.md', 'LICENSE?(.md)'],
// все было сломано тут https://github.com/alfa-laboratory/library-utils/pull/95
// library utils не умеет хорошо генерить тайпинги по index.js файлов а реэксопрты в index.js файлах как правило работают чисто потому что повезло
useComponentDts: false
};

const errors = [];
Expand Down Expand Up @@ -78,7 +81,7 @@ function createTasks(packageName, options = {}) {

gulp.task('ts:packages',
() => gulp.src(options.tsComponentsGlob)
.pipe(componentPackage())
.pipe(componentPackage(options.useComponentDts))
.pipe(gulp.dest(options.publishDir))
.on('error', handleError)
);
Expand All @@ -89,7 +92,7 @@ function createTasks(packageName, options = {}) {
const components = gulp.src(options.componentsGlob);
const packages = components
.pipe(clone())
.pipe(componentPackage())
.pipe(componentPackage(options.useComponentDts))
.on('error', handleError);

const typingFiles = components
Expand Down
8 changes: 4 additions & 4 deletions gulp/component-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const Vinyl = require('vinyl');
* @param {*} file Gulp stream file instance
* @returns {String}
*/
function getComponentPackage(file) {
function getComponentPackage(file, useComponentDts) {
const dirname = path.dirname(file.path);
const componentName = path.parse(file.path).name;
const isIndexFileExist = fs.existsSync(path.join(dirname, 'index.js')) ||
fs.existsSync(path.join(dirname, 'index.ts'));

return JSON.stringify({
main: isIndexFileExist ? 'index.js' : `${componentName}.js`,
types: isIndexFileExist ? 'index.d.ts' : `${componentName}.d.ts`
types: isIndexFileExist && !useComponentDts ? 'index.d.ts' : `${componentName}.d.ts`
});
}

Expand All @@ -26,7 +26,7 @@ function getComponentPackage(file) {
*
* @returns {Function}
*/
function componentPackage() {
function componentPackage(useComponentDts) {
function transform(file, encoding, callback) {
if (file.isStream()) {
callback();
Expand All @@ -39,7 +39,7 @@ function componentPackage() {
cwd: file.cwd,
base: file.base,
path: path.join(dirname, 'package.json'),
contents: Buffer.from(getComponentPackage(file))
contents: Buffer.from(getComponentPackage(file, useComponentDts))
}));
}

Expand Down

0 comments on commit 8427628

Please sign in to comment.