From e95d433c00a92158eac5e6d155c3428f9fc287df Mon Sep 17 00:00:00 2001 From: dimitribarbot Date: Wed, 1 Nov 2023 11:12:49 +0100 Subject: [PATCH] Take 'import * as' directive into account to compute where to insert import statement for style file --- CHANGELOG.md | 9 ++++++++- package.json | 2 +- src/lib/imports.test.ts | 3 +-- src/lib/imports.ts | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9af70ad..228683b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Nothing yet! +## [0.4.7] - 2023-11-01 + +### Fixed + +- Take `import * as` directive into account to compute where to insert import statement for style file + ## [0.4.6] - 2023-11-01 ### Fixed @@ -58,7 +64,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add missing props to extracted components when expressions are used -[unreleased]: https://github.com/dimitribarbot/tailwind-styled-components-extractor/compare/v0.4.6...HEAD +[unreleased]: https://github.com/dimitribarbot/tailwind-styled-components-extractor/compare/v0.4.7...HEAD +[0.4.6]: https://github.com/dimitribarbot/tailwind-styled-components-extractor/compare/v0.4.6...v0.4.7 [0.4.6]: https://github.com/dimitribarbot/tailwind-styled-components-extractor/compare/v0.4.5...v0.4.6 [0.4.5]: https://github.com/dimitribarbot/tailwind-styled-components-extractor/compare/v0.4.4...v0.4.5 [0.4.4]: https://github.com/dimitribarbot/tailwind-styled-components-extractor/compare/v0.4.3...v0.4.4 diff --git a/package.json b/package.json index f506519..771485e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "tailwind-styled-components-extractor", "displayName": "Tailwind Styled-Components Extractor", - "version": "0.4.6", + "version": "0.4.7", "description": "Generate tailwind styled-components from JSX tags. A faster tailwind styled-component workflow.", "license": "MIT", "publisher": "dimitribarbot", diff --git a/src/lib/imports.test.ts b/src/lib/imports.test.ts index 8c32799..a9cb661 100644 --- a/src/lib/imports.test.ts +++ b/src/lib/imports.test.ts @@ -19,8 +19,7 @@ test("getImportInsertion no existing import with using directive", async () => { const code = ` "using client" -import { foo } from "./bar" -import { baz } from "./qux"`; +import * as React from "react"`; const insertion = getImportInsertion(code, "./styles", ["Abc", "Xyz"]); expect(insertion).toEqual({ diff --git a/src/lib/imports.ts b/src/lib/imports.ts index a85877e..3ce1a17 100644 --- a/src/lib/imports.ts +++ b/src/lib/imports.ts @@ -19,7 +19,7 @@ export const getImportInsertion = ( }; } - const importRegex = new RegExp(`(import {[^}]*?)[\\s\\n]+} from ".+"[;]?`); + const importRegex = new RegExp(`import .+ from ".+"[;]?`); const importAlreadyPresent = importRegex.exec(existingText); const insertionOffset = importAlreadyPresent?.index ?? 0;