next-yak 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -98,15 +98,15 @@ next-yak provide class name helpers. This allows using [tailwind](https://tailwi
98
98
  ```tsx
99
99
  import { styled, css, atoms } from "next-yak";
100
100
 
101
- const SpinningTitle = styled.h1<{ isAnimated: boolean; children: React.ReactNode }>`
102
- ${atoms("tw-text-lg md:tw-text-xl tw-bg-red-500")}
103
- ${({ isAnimated }) => isAnimated && css`animation: spin 1s linear infinite`)}
101
+ const Button = styled.button<{ $primary?: boolean }>`
102
+ ${atoms("text-teal-600", "text-base", "rounded-md")}
103
+ ${props => props.$primary && atoms("shadow-md")}
104
104
  `;
105
105
 
106
106
  const App = () => (
107
- <SpinningTitle isAnimated={true}>
107
+ <Button primary>
108
108
  Hello World
109
- </SpinningTitle>
109
+ </Button>
110
110
  );
111
111
  ```
112
112
 
@@ -115,7 +115,8 @@ const App = () => (
115
115
  This is a proof of concept. There are a lot of things that need to be done before this can be used in production:
116
116
 
117
117
  - [ ] improve js parsing - right now it not reusing babel..
118
- - [ ] config hot module reloading
118
+ - [ ] sourcemaps
119
+ - [ ] replace config apporach with a solution similar to vanilla-extracts `.styles.ts` files
119
120
 
120
121
  ## Prior art
121
122
 
@@ -2,7 +2,6 @@
2
2
  const babel = require("@babel/core");
3
3
  const quasiClassifier = require("./lib/quasiClassifier.cjs");
4
4
  const replaceQuasiExpressionTokens = require("./lib/replaceQuasiExpressionTokens.cjs");
5
- const loadConfigOnce = require("./lib/loadConfigOnce.cjs");
6
5
  const murmurhash2_32_gc = require("./lib/hash.cjs");
7
6
  const { relative, resolve } = require("path");
8
7
 
@@ -15,9 +14,9 @@ module.exports = async function cssLoader(source) {
15
14
  // Config for replacing tokens in css template literals
16
15
  // can be based on a typescript file
17
16
  const options = this.getOptions();
18
- const config = options.configPath ? await loadConfigOnce(
19
- async () => await this.importModule(resolve(this.rootContext, options.configPath))
20
- ) : {};
17
+ const config = options.configPath ? await this.importModule(resolve(this.rootContext, options.configPath), {
18
+ layer: "yak-importModule",
19
+ }) : {};
21
20
  const replaces = config.replaces || {};
22
21
 
23
22
  // parse source with babel
@@ -3,7 +3,6 @@ const path = require("path");
3
3
  const babel = require("@babel/core");
4
4
  const quasiClassifier = require("./lib/quasiClassifier.cjs");
5
5
  const replaceQuasiExpressionTokens = require("./lib/replaceQuasiExpressionTokens.cjs");
6
- const loadConfigOnce = require("./lib/loadConfigOnce.cjs");
7
6
  const murmurhash2_32_gc = require("./lib/hash.cjs");
8
7
  const { relative, resolve } = require("path");
9
8
 
@@ -22,9 +21,9 @@ module.exports = async function tsloader(source) {
22
21
  // Config for replacing tokens in css template literals
23
22
  // can be based on a typescript file
24
23
  const options = this.getOptions();
25
- const config = options.configPath ? await loadConfigOnce(
26
- async () => await this.importModule(resolve(this.rootContext, options.configPath))
27
- ) : {};
24
+ const config = options.configPath ? await this.importModule(resolve(this.rootContext, options.configPath), {
25
+ layer: "yak-importModule",
26
+ }) : {};
28
27
  const replaces = config.replaces || {};
29
28
 
30
29
  /** @type {string | null} */
@@ -17,6 +17,11 @@ const addYak = (yakOptions, nextConfig) => {
17
17
  test: /\.tsx?$/,
18
18
  loader: require.resolve("./tsloader.cjs"),
19
19
  options: yakOptions,
20
+ issuerLayer: {
21
+ // prevent recursions when calling this.importModule
22
+ // in the tsloader
23
+ not: ["yak-importModule"],
24
+ },
20
25
  });
21
26
  webpackConfig.module.rules.push({
22
27
  test: /\.yak\.module\.css$/,
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "next-yak",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
5
7
  "exports": {
6
8
  ".": "./dist/index.js",
7
9
  "./withYak": "./loaders/withYak.cjs"
@@ -1,17 +0,0 @@
1
- /// @ts-check
2
-
3
- /**
4
- * @type {Promise<{ replaces?: Record<string, Record<string, string>> }>}
5
- */
6
- let cache;
7
- module.exports = function loadConfigOnce(loader) {
8
- const config = cache || loader().catch((e) => {
9
- console.error("Failed to load yak config:", e);
10
- return {};
11
- })
12
-
13
- if (!cache) {
14
- cache = config;
15
- }
16
- return config;
17
- };