Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(css): use postcss #7

Merged
merged 8 commits into from
Jul 2, 2024

Conversation

AugustinMauroy
Copy link
Member

  • Allow nested selector
  • remove deprecation warn

@@ -60,6 +60,7 @@ describe('css-module loader', { concurrency: true }, () => {
Qux: 'Qux',
Zed: 'Zed',
img: 'img',
nested: 'nested',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could have something like this to represent the nested :

{
    "Foo": "Foo",
    "Bar": "Bar",
    "Qux": "Qux",
    "Zed": "Zed",
    "img": "img",
    "nested": {
        "something": "something"
    }
}

but it would change the spec

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an additive change (nesting wasn't supported before), so that's fine. I think your proposal in the comment (something.nested) is better as it avoids a risk of collision 🙂

I think the README would need to be updated (and if so, before cutting a release). I can do subsequently if you don't want to handle in this PR, but I can't til I'm back from Helsinki next week (same for cutting the release).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to experiment with the loader with react typescript and tailwind to find out which is the best behaviour to have.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here example of dum component:

import { useState } from 'react';
import styles from './basic.module.css';
import type { FC } from 'react';

const Basic: FC = () => {
    const [show, setShow] = useState(false);

    return (
        <div className={styles.container}>
            <button
                className={styles.button}
                onClick={() => setShow(!show)}
            >Toggle</button>
            {show && <p>Content</p>}
        </div>
    );
};

export default Basic;

here the test suite:

import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { render, screen, act } from "@testing-library/react";
import Basic from "./basic.tsx";

describe("Basic", () => {
    it("should render", () => {
        const { container } = render(<Basic />);
        assert.ok(container);
        container.remove();
    });

    it("should toggle content", () => {
        const { unmount } = render(<Basic />);
        const button = screen.getByRole("button");
        const content = screen.queryByText("Content");

        assert.ok(button);
        assert.strictEqual(content, null);

        act(() => {
            button.click();
        });

        assert.ok(screen.queryByText("Content"));
        unmount();
    });

    it("should have correct class names", () => {
        render(<Basic />);
        const container = screen.getByRole("button").parentElement;

        if (!container) {
            throw new Error("Container not found");
        }

        assert.strictEqual(container.className, "container");
        
        const button = container.querySelector("button");

        if (!button) {
            throw new Error("Button not found");
        }

        assert.strictEqual(button.className, "button");
    });
});

This is currently failing. That's why I think having nested keys in a js object seems more appropriate.

I'm well aware that nobody in their right mind would do such a test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With lasted commit this test pass

css-module.mjs Outdated Show resolved Hide resolved
@@ -60,6 +60,7 @@ describe('css-module loader', { concurrency: true }, () => {
Qux: 'Qux',
Zed: 'Zed',
img: 'img',
nested: 'nested',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an additive change (nesting wasn't supported before), so that's fine. I think your proposal in the comment (something.nested) is better as it avoids a risk of collision 🙂

I think the README would need to be updated (and if so, before cutting a release). I can do subsequently if you don't want to handle in this PR, but I can't til I'm back from Helsinki next week (same for cutting the release).

AugustinMauroy and others added 3 commits June 27, 2024 10:21
Co-authored-by: Jacob Smith <3012099+JakobJingleheimer@users.noreply.github.com>
Co-authored-by: Jacob Smith <3012099+JakobJingleheimer@users.noreply.github.com>
Copy link
Member

@JakobJingleheimer JakobJingleheimer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

w00t! thank you!

@JakobJingleheimer JakobJingleheimer merged commit 2e75e83 into nodejs-loaders:main Jul 2, 2024
3 checks passed
JakobJingleheimer added a commit that referenced this pull request Jul 2, 2024
@JakobJingleheimer JakobJingleheimer added the enhancement New feature or request label Jul 2, 2024
@AugustinMauroy AugustinMauroy deleted the experiment branch July 2, 2024 19:14
JakobJingleheimer added a commit that referenced this pull request Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants