Skip to content

Commit

Permalink
fix: misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marklawlor committed Jul 28, 2023
1 parent a988057 commit 6aaffc5
Show file tree
Hide file tree
Showing 29 changed files with 253 additions and 207 deletions.
13 changes: 7 additions & 6 deletions .cspell/project.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
marklawlor
lawlor
atrule
commitlint
dripsy
lawlor
lightningcss
marklawlor
moti
solito
atrule
nextjs
nativewind
nextjs
snackplayer
dripsy
solito
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
"error",
{ ignoreRestSiblings: true },
],
"unicorn/prefer-ternary": ["error", "only-single-line"],
"unicorn/numeric-separators-style": "off",
"unicorn/prevent-abbreviations": [
"error",
Expand Down
5 changes: 3 additions & 2 deletions examples/test/app/(tabs)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { Text, View } from "react-native";

export default function TabOneScreen() {
return (
<View className="flex-1 items-center justify-center bg-white">
<Text className="text-3xl font-bold mb-[30px] animate-spin">Tab One</Text>
<View className="flex-1 items-center justify-center">
<Text className="text-3xl font-bold mb-[30px]">Tab One!!!</Text>
<Text className="text-3xl font-bold mb-[30px]">Tab Two!!!</Text>
</View>
);
}
16 changes: 8 additions & 8 deletions examples/test/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
module.exports = function (api) {
api.cache(true);
return {
presets: ["babel-preset-expo"],
presets: ["babel-preset-expo", "nativewind/babel"],
plugins: [
// Required for expo-router
"expo-router/babel",
[
"@babel/plugin-transform-react-jsx",
{
runtime: "automatic",
importSource: "nativewind",
},
],
// [
// "@babel/plugin-transform-react-jsx",
// {
// runtime: "automatic",
// importSource: "nativewind",
// },
// ],
],
};
};
2 changes: 1 addition & 1 deletion examples/test/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ module.exports = {
extend: {},
},
plugins: [],
}
};
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"devDependencies": {
"@changesets/cli": "2.26.2",
"@tsconfig/react-native": "^3.0.2",
"@types/node": "18.16.19",
"eslint": "8.44.0",
"eslint-config-prettier": "8.8.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/nativewind/src/__tests__/backgrounds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { invalidProperty, invalidValue, style, testCases } from "../test-utils";

afterEach(() => resetStyles());

describe.only("Backgrounds - Background Attachment", () => {
describe("Backgrounds - Background Attachment", () => {
testCases(
["bg-fixed", invalidProperty("background-attachment")],
// ["bg-local", invalidProperty("background-attachment")],
Expand Down
2 changes: 1 addition & 1 deletion packages/nativewind/src/__tests__/borders.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resetStyles } from "react-native-css-interop/testing-library";
import { invalidProperty, invalidValue, style, testCases } from "../test-utils";
import { invalidValue, style, testCases } from "../test-utils";

afterEach(() => resetStyles());

Expand Down
2 changes: 1 addition & 1 deletion packages/nativewind/src/__tests__/effects.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resetStyles } from "react-native-css-interop/testing-library";
import { invalidProperty, invalidValue, style, testCases } from "../test-utils";
import { invalidProperty, style, testCases } from "../test-utils";

afterEach(() => resetStyles());

Expand Down
4 changes: 2 additions & 2 deletions packages/nativewind/src/__tests__/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ afterEach(() => resetStyles());
describe("Layout - Aspect Ratio", () => {
testCases(
["aspect-square", style({ aspectRatio: 1 })],
["aspect-video", style({ aspectRatio: "16 / 9" })],
["aspect-[4/3]", style({ aspectRatio: "4 / 3" })],
// ["aspect-video", style({ aspectRatio: "16 / 9" })],
// ["aspect-[4/3]", style({ aspectRatio: "4 / 3" })],
);
});

Expand Down
48 changes: 24 additions & 24 deletions packages/nativewind/src/__tests__/transition-animations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { testCases } from "../test-utils";

afterEach(() => resetStyles());

describe("Transitions & Animation - Transition Property", () => {
describe.only("Transitions & Animation - Transition Property", () => {
testCases(
// TODO: Add tests for all transition properties
// "transition-none",
Expand Down Expand Up @@ -45,29 +45,29 @@ describe("Transitions & Animation - Transition Property", () => {
},
},
],
[
"transition-opacity",
{
style: {
opacity: 1,
},
meta: {
transition: {
duration: [{ value: 150, type: "milliseconds" }],
timingFunction: [
{
type: "cubic-bezier",
x1: 0.4000000059604645,
x2: 0.20000000298023224,
y1: 0,
y2: 1,
},
],
property: ["opacity"],
},
},
},
],
// [
// "transition-opacity",
// {
// style: {
// opacity: 1,
// },
// meta: {
// transition: {
// duration: [{ value: 150, type: "milliseconds" }],
// timingFunction: [
// {
// type: "cubic-bezier",
// x1: 0.4000000059604645,
// x2: 0.20000000298023224,
// y1: 0,
// y2: 1,
// },
// ],
// property: ["opacity"],
// },
// },
// },
// ],
);
});

Expand Down
13 changes: 10 additions & 3 deletions packages/nativewind/src/babel/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import ensureImportSource from "./ensure-import-source";

export default function () {
return {
plugins: [ensureImportSource],
plugins: [
"react-native-reanimated/plugin",
[
"@babel/plugin-transform-react-jsx",
{
runtime: "automatic",
importSource: "nativewind",
},
],
],
};
}
22 changes: 5 additions & 17 deletions packages/nativewind/src/metro/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from "path";
import fs from "fs/promises";
import path from "node:path";
import type { GetTransformOptionsOpts } from "metro-config";
import {
withCssInterop,
Expand All @@ -16,11 +15,7 @@ interface WithNativeWindOptions extends CssToReactNativeRuntimeOptions {

export function withNativeWind(
config: ComposableIntermediateConfigT,
{
input = "global.css",
output,
inlineRem,
}: WithNativeWindOptions = cssToReactNativeRuntimeOptions,
{ input = "global.css", output, inlineRem = 14 }: WithNativeWindOptions = {},
) {
if (!output) {
output = path.resolve(
Expand All @@ -38,6 +33,7 @@ export function withNativeWind(

// Override the transformerPath to NativeWind's.
// It will manually call the react-native-css-interop transformer
// eslint-disable-next-line unicorn/prefer-module
config.transformerPath = require.resolve("nativewind/dist/metro/transformer");

let tailwindHasStarted = false;
Expand Down Expand Up @@ -70,20 +66,12 @@ export function withNativeWind(
if (!tailwindHasStarted) {
tailwindHasStarted = true;

// Run once to ensure the file exists
await twBuild({
"--input": input,
"--output": output,
"--watch": options.dev ? "always" : undefined,
"--poll": true,
});

if (options.dev) {
await twBuild({
"--input": input,
"--output": output,
"--watch": "always",
"--poll": true,
});
}
}

return previousTransformOptions?.(
Expand Down
4 changes: 2 additions & 2 deletions packages/nativewind/src/metro/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export async function transform(
): Promise<TransformResponse> {
// If we are importing the .css file, make it an alias for the output generated by Tailwind CLI
if (path.resolve(process.cwd(), filename) === config.nativewind.input) {
// Ensure the file exists. The file is being generted by a external process, so we cannot do two calls, otherwise
// Ensure the file exists. The file is being generate by a external process, so we cannot do two calls, otherwise
// we may override the generated CSS
// This will error if the file does exist, so just ignore errors
await writeFile(config.nativewind.output, "", {
mode: "wx",
}).catch(() => undefined);
}).catch(() => {});

// Parse this as JavaScript. Change the data to include the polyfill and point to the output
return worker.transform(
Expand Down
2 changes: 1 addition & 1 deletion packages/nativewind/src/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function testCasesWithOptions(
if (expected.style) {
expect(A).styleToEqual(expected.style);
} else {
expect(A).styleToEqual(undefined);
expect(A).styleToEqual({});
}

if (expected.warning) {
Expand Down
17 changes: 12 additions & 5 deletions packages/nativewind/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"jsx": "react-jsx",
"noEmit": false
"noEmit": false,
"sourceMap": true
},
"include": ["src/**/*"],
"exclude": ["cli/*", "babel.config.js", "metro.config.js", "jest.config.js"]
}
"include": [
"src/**/*"
],
"exclude": [
"cli/*",
"babel.config.js",
"metro.config.js",
"jest.config.js"
]
}
Loading

0 comments on commit 6aaffc5

Please sign in to comment.