Skip to content

Commit

Permalink
Take 'import * as' directive into account to compute where to insert …
Browse files Browse the repository at this point in the history
…import statement for style file
  • Loading branch information
dimitribarbot committed Nov 1, 2023
1 parent 87d82c1 commit e95d433
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 1 addition & 2 deletions src/lib/imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/lib/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit e95d433

Please sign in to comment.