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

Update all dependencies #251

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/mighty-lobsters-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"next-yak": patch
"yak-swc": patch
---

Updated all dependencies
2 changes: 1 addition & 1 deletion packages/benchmarks/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
2 changes: 1 addition & 1 deletion packages/example/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
35 changes: 18 additions & 17 deletions packages/example/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
/// <reference types="vitest" />
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react"
import react from "@vitejs/plugin-react";
import { defineConfig, mergeConfig } from "vitest/config";

// https://vitejs.dev/config/
export default defineConfig({
plugins:
[
react()
],
test: {
globals: true,
environment: "jsdom",
export default mergeConfig(
{
plugins: [react()],
},
defineConfig({
test: {
globals: true,
environment: "jsdom",

// This is only necessary because we use Vitest and Jest (to see verify that both work)
// and they should use different snapshot names
resolveSnapshotPath: (testPath, snapshotExtension) =>
testPath.replace('__tests__', '__tests__/__vite_snapshots__') + snapshotExtension,
}
});
// This is only necessary because we use Vitest and Jest (to see verify that both work)
// and they should use different snapshot names
resolveSnapshotPath: (testPath, snapshotExtension) =>
testPath.replace("__tests__", "__tests__/__vite_snapshots__") +
snapshotExtension,
},
}),
);
32 changes: 27 additions & 5 deletions packages/next-yak/loaders/css-loader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { LoaderContext } from "webpack";
import { resolveCrossFileConstant } from "./lib/resolveCrossFileSelectors.js";
import { relative } from "path";
import type { LoaderContext } from "webpack";
import type { YakConfigOptions } from "../withYak/index.js";
import { resolveCrossFileConstant } from "./lib/resolveCrossFileSelectors.js";

/**
* Transform typescript to css
Expand All @@ -22,6 +22,11 @@ export default async function cssExtractLoader(
if (err) {
return callback(err);
}
if (!source) {
return callback(
new Error(`Source code for ${this.resourcePath} is empty`),
);
}
const { experiments } = this.getOptions();
const debugLog = createDebugLogger(this, experiments?.debug);

Expand All @@ -36,8 +41,22 @@ export default async function cssExtractLoader(
});
}

function extractCss(code: string): string {
const codeParts = code.split("/*YAK Extracted CSS:\n");
function extractCss(code: string | Buffer<ArrayBufferLike>): string {
let codeString: string;

if (typeof code === "string") {
codeString = code;
} else if (code instanceof Buffer) {
codeString = code.toString("utf-8");
} else if (code instanceof ArrayBuffer) {
codeString = new TextDecoder("utf-8").decode(code);
} else {
throw new Error(
"Invalid input type: code must be string, Buffer, or ArrayBuffer",
);
}

const codeParts = codeString.split("/*YAK Extracted CSS:\n");
let result = "";
for (let i = 1; i < codeParts.length; i++) {
const codeUntilEnd = codeParts[i].split("*/")[0];
Expand All @@ -59,7 +78,10 @@ function createDebugLogger(
return () => {};
}
const debugType = debugOptions === true ? "ts" : debugOptions.type;
return (messageType: "ts" | "css" | "css resolved", message: string) => {
return (
messageType: "ts" | "css" | "css resolved",
message: string | Buffer<ArrayBufferLike> | undefined,
) => {
if (messageType === debugType || debugType === "all") {
console.log(
"🐮 Yak",
Expand Down
18 changes: 15 additions & 3 deletions packages/next-yak/loaders/lib/resolveCrossFileSelectors.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from "path";
import babel from "@babel/core";
import path from "path";
// @ts-expect-error - this is used by babel directly so we ignore that it is not typed
import babelPlugin from "@babel/plugin-syntax-typescript";
import type { Compilation, LoaderContext } from "webpack";
import { getCssModuleLocalIdent } from "next/dist/build/webpack/config/blocks/css/loaders/getCssModuleLocalIdent.js";
import type { Compilation, LoaderContext } from "webpack";

const yakCssImportRegex =
// Make mixin and selector non optional once we dropped support for the babel plugin
Expand Down Expand Up @@ -227,7 +227,19 @@ async function parseFile(
const tranformedSource = new Promise<string>((resolve, reject) => {
loader.loadModule(filePath, (err, source) => {
if (err) return reject(err);
resolve(source || "");
let sourceString: string;
if (typeof source === "string") {
sourceString = source;
} else if (source instanceof Buffer) {
sourceString = source.toString("utf-8");
} else if (source instanceof ArrayBuffer) {
sourceString = new TextDecoder("utf-8").decode(source);
} else {
throw new Error(
"Invalid input type: code must be string, Buffer, or ArrayBuffer",
);
}
resolve(sourceString || "");
});
});

Expand Down
32 changes: 16 additions & 16 deletions packages/yak-swc/Cargo.lock

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

4 changes: 2 additions & 2 deletions packages/yak-swc/css_in_js_parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ keywords = ["css", "parser", "css-in-js"]
categories = ["parser-implementations", "web-programming"]

[dependencies]
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.119"
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.134"
serde_repr = "0.1"

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions packages/yak-swc/relative_posix_path/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ categories = ["filesystem", "os::unix-apis", "os::windows-apis"]

[dependencies]
lazy_static = "1.4.0"
pathdiff = "0.2.1"
regex = "1.10.3"
pathdiff = "0.2.3"
regex = "1.10.3"
12 changes: 6 additions & 6 deletions packages/yak-swc/yak_swc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
lazy_static = "1.4.0"
serde = "1.0.203"
serde_json = "1.0.120"
swc_core = { version = "5.0.1", features = ["ecma_plugin_transform"] }
serde = "1.0.217"
serde_json = "1.0.134"
swc_core = { version = "5.0.4", features = ["ecma_plugin_transform"] }
css_in_js_parser = { path = "../css_in_js_parser" }
relative_posix_path = { path = "../relative_posix_path" }
itertools = "0.13.0"
percent-encoding = "2.3.1"
rustc-hash = "2.0.0"
rustc-hash = "2.1.0"

[dev-dependencies]
divan = "0.1.14"
divan = "0.1.17"
regex = "1.10.3"
swc = "5.0.1"
swc = "5.0.2"
swc_ecma_transforms_testing = "5.0.0"
swc_ecma_parser = "5.0.0"
testing = "5.0.0"
Expand Down
Loading
Loading