diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bd9e82676..e53b664a49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Features - Add Menu `iconOnly`, MenuItem `iconOnly` and `icon` props @miroslavstastny ([#73](https://github.com/stardust-ui/react/pull/73)) +- Fix `MenuItem` broken styles @miroslavstastny ([#94](https://github.com/stardust-ui/react/pull/94)) +- Fix wrong typings generated for dist @kuzhelov ([#99](https://github.com/stardust-ui/react/pull/99)) ## [v0.2.7](https://github.com/stardust-ui/react/tree/v0.2.7) (2018-08-13) diff --git a/build/gulp/plugins/gulp-use-relative-import-paths.ts b/build/gulp/plugins/gulp-use-relative-import-paths.ts new file mode 100644 index 0000000000..6bedbf6a96 --- /dev/null +++ b/build/gulp/plugins/gulp-use-relative-import-paths.ts @@ -0,0 +1,68 @@ +import * as path from 'path' +const g = require('gulp-load-plugins')() + +type BasePathProvider = { + base: (relativePath: string) => string +} + +type Config = { + forImportStartsWith: string + paths: BasePathProvider +} + +type Transform = (from: From) => To + +const replace = (line: string, what: RegExp, how: Transform) => { + let replacedLine = line + + let match = what.exec(line) + while (match != null) { + const replacement = how(match) + replacedLine = replacedLine.replace(match[0], replacement) + match = what.exec(line) + } + + return replacedLine +} + +const replaceInlinedImportPaths = (content: string, how: Transform) => { + const InlinedImportRegexp = /import\(['"]([^.].*?)['"]\)/g + + return content + .split('\n') + .map(line => + replace(line, InlinedImportRegexp, match => { + const originalImportStatement = match[0] + const originalImportPath = match[1] + + if (!originalImportPath) { + return originalImportStatement + } + + const modifiedImportPath = how(originalImportPath) + return originalImportStatement.replace(originalImportPath, modifiedImportPath) + }), + ) + .join('\n') +} + +export default ({ forImportStartsWith, paths }: Config) => + g.transform('utf8', (content, file) => { + const originalSrcFilePath = file.path + + const contentWithReplacement = replaceInlinedImportPaths(content, importPath => { + if (forImportStartsWith && !importPath.startsWith(forImportStartsWith)) { + return importPath + } + + const absoluteSrcImportPath = paths.base(importPath) + const relativeImportPath = path.relative( + path.dirname(originalSrcFilePath), + absoluteSrcImportPath, + ) + + return relativeImportPath.startsWith('.') ? relativeImportPath : `./${relativeImportPath}` + }) + + return contentWithReplacement + }) diff --git a/build/gulp/tasks/dist.ts b/build/gulp/tasks/dist.ts index b78eea4534..2c73f5a34f 100644 --- a/build/gulp/tasks/dist.ts +++ b/build/gulp/tasks/dist.ts @@ -8,6 +8,7 @@ import config from '../../../config' const { paths } = config const g = require('gulp-load-plugins')() const { log, PluginError } = g.util +import gulpUseRelativeImportPaths from '../plugins/gulp-use-relative-import-paths' // ---------------------------------------- // Clean @@ -29,7 +30,9 @@ task('build:dist:commonjs', () => { const types = src(paths.base('types/**')) return merge2([ - dts.pipe(dest(paths.dist('commonjs'))), + dts + .pipe(gulpUseRelativeImportPaths({ forImportStartsWith: 'src', paths })) + .pipe(dest(paths.dist('commonjs'))), js.pipe(dest(paths.dist('commonjs'))), types.pipe(dest(paths.dist('types'))), ]) @@ -44,7 +47,9 @@ task('build:dist:es', () => { const types = src(paths.base('types/**')) return merge2([ - dts.pipe(dest(paths.dist('es'))), + dts + .pipe(gulpUseRelativeImportPaths({ forImportStartsWith: 'src', paths })) + .pipe(dest(paths.dist('es'))), js.pipe(dest(paths.dist('es'))), types.pipe(dest(paths.dist('types'))), ]) diff --git a/package.json b/package.json index 0306c33b75..e275dc148f 100644 --- a/package.json +++ b/package.json @@ -116,6 +116,7 @@ "gulp-plumber": "^1.2.0", "gulp-rename": "^1.3.0", "gulp-replace": "^1.0.0", + "gulp-transform": "^3.0.5", "gulp-typescript": "^5.0.0-alpha.1", "gulp-util": "^3.0.8", "html-webpack-plugin": "^2.30.1", diff --git a/src/components/Provider/ProviderConsumer.tsx b/src/components/Provider/ProviderConsumer.tsx index 5d1e4b3625..e0204bb131 100644 --- a/src/components/Provider/ProviderConsumer.tsx +++ b/src/components/Provider/ProviderConsumer.tsx @@ -2,20 +2,16 @@ import * as PropTypes from 'prop-types' import * as React from 'react' import { FelaTheme } from 'react-fela' -// TODO: TypeScript incorrectly compiles typings defined in component files -// TODO: see: https://github.com/stardust-ui/react/issues/87#issuecomment-412657622 -// -// import { IThemePrepared } from '../../../types/theme' -// -// export interface IProviderConsumerProps { -// render: (theme: IThemePrepared) => React.ReactNode -// } +import { IThemePrepared } from '../../../types/theme' + +export interface IProviderConsumerProps { + render: (theme: IThemePrepared) => React.ReactNode +} /** * The Provider's Consumer is for accessing the theme. */ -// TODO: restore provider consumer interface once above bug is fixed -const ProviderConsumer: React.SFC = props => +const ProviderConsumer: React.SFC = props => ProviderConsumer.propTypes = { /** diff --git a/yarn.lock b/yarn.lock index 2478820b8d..ef32f816b8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -56,6 +56,15 @@ dependencies: "@types/node" "*" +"@types/gulp-util@*": + version "3.0.34" + resolved "https://registry.yarnpkg.com/@types/gulp-util/-/gulp-util-3.0.34.tgz#d1291ebf706d93f46eb8df11344bbfd96247697e" + dependencies: + "@types/node" "*" + "@types/through2" "*" + "@types/vinyl" "*" + chalk "^2.2.0" + "@types/history@*": version "4.6.2" resolved "https://registry.yarnpkg.com/@types/history/-/history-4.6.2.tgz#12cfaba693ba20f114ed5765467ff25fdf67ddb0" @@ -92,6 +101,18 @@ dependencies: csstype "^2.2.0" +"@types/through2@*": + version "2.0.33" + resolved "https://registry.yarnpkg.com/@types/through2/-/through2-2.0.33.tgz#1ff2e88a100dfb5b140e7bb98791f1194400d131" + dependencies: + "@types/node" "*" + +"@types/vinyl@*": + version "2.0.2" + resolved "https://registry.yarnpkg.com/@types/vinyl/-/vinyl-2.0.2.tgz#4f3b8dae8f5828d3800ef709b0cff488ee852de3" + dependencies: + "@types/node" "*" + abab@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.4.tgz#5faad9c2c07f60dd76770f71cf025b62a63cfd4e" @@ -1064,7 +1085,7 @@ chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3: strip-ansi "^3.0.0" supports-color "^2.0.0" -chalk@^2.0.0, chalk@^2.0.1, chalk@^2.3.0, chalk@^2.3.1: +chalk@^2.0.0, chalk@^2.0.1, chalk@^2.2.0, chalk@^2.3.0, chalk@^2.3.1: version "2.4.1" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e" dependencies: @@ -3114,6 +3135,15 @@ gulp-replace@^1.0.0: readable-stream "^2.0.1" replacestream "^4.0.0" +gulp-transform@^3.0.5: + version "3.0.5" + resolved "https://registry.yarnpkg.com/gulp-transform/-/gulp-transform-3.0.5.tgz#6972674a77dc30672d6b7746a173ef0506fe37b2" + dependencies: + "@types/gulp-util" "*" + "@types/node" "*" + gulp-util "^3.0.8" + tslib "^1.7.1" + gulp-typescript@^5.0.0-alpha.1: version "5.0.0-alpha.3" resolved "https://registry.yarnpkg.com/gulp-typescript/-/gulp-typescript-5.0.0-alpha.3.tgz#c49a306cbbb8c97f5fe8a79208671b6642ef9861"