next-yak 0.0.35 → 0.0.39
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/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/loaders/cssloader.cjs +649 -0
- package/dist/loaders/cssloader.cjs.map +1 -0
- package/dist/loaders/cssloader.d.cts +3 -0
- package/dist/loaders/cssloader.d.ts +3 -0
- package/dist/loaders/cssloader.js +616 -0
- package/dist/loaders/cssloader.js.map +1 -0
- package/dist/loaders/tsloader.cjs +844 -0
- package/dist/loaders/tsloader.cjs.map +1 -0
- package/dist/loaders/tsloader.d.cts +6 -0
- package/dist/loaders/tsloader.d.ts +6 -0
- package/dist/loaders/tsloader.js +820 -0
- package/dist/loaders/tsloader.js.map +1 -0
- package/{withYak → dist/withYak}/index.cjs +14 -7
- package/dist/withYak/index.cjs.map +1 -0
- package/{withYak → dist/withYak}/index.d.cts +2 -2
- package/dist/withYak/index.d.ts +37 -0
- package/dist/withYak/index.js +68 -0
- package/dist/withYak/index.js.map +1 -0
- package/loaders/__tests__/classifier.test.ts +99 -93
- package/loaders/__tests__/cssloader.test.ts +1 -1
- package/loaders/__tests__/getCssName.test.ts +1 -1
- package/loaders/__tests__/tsloader.test.ts +1 -1
- package/loaders/{babel-yak-plugin.cjs → babel-yak-plugin.ts} +69 -68
- package/loaders/{cssloader.cjs → cssloader.ts} +73 -97
- package/loaders/lib/{appendCssUnitToExpressionValue.cjs → appendCssUnitToExpressionValue.ts} +7 -10
- package/loaders/lib/{getConstantValues.cjs → getConstantValues.ts} +10 -17
- package/loaders/lib/{getCssName.cjs → getCssName.ts} +19 -31
- package/loaders/lib/{getStyledComponentName.cjs → getStyledComponentName.ts} +7 -10
- package/loaders/lib/{getYakImports.cjs → getYakImports.ts} +4 -10
- package/loaders/lib/{hash.cjs → hash.ts} +3 -5
- package/loaders/lib/{localIdent.cjs → localIdent.ts} +5 -7
- package/loaders/lib/{quasiClassifier.cjs → quasiClassifier.ts} +7 -16
- package/loaders/lib/{replaceQuasiExpressionTokens.cjs → replaceQuasiExpressionTokens.ts} +27 -26
- package/loaders/lib/{stripCssComments.cjs → stripCssComments.ts} +3 -9
- package/loaders/{tsloader.cjs → tsloader.ts} +11 -15
- package/package.json +12 -21
- package/runtime/__tests__/attrs.test.tsx +4 -14
- package/runtime/__tests__/styled.test.tsx +25 -6
- package/runtime/styled.tsx +5 -5
- package/withYak/index.ts +43 -34
- package/withYak/index.cjs.map +0 -1
package/withYak/index.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { NextConfig } from "../../example/node_modules/next/dist/server/config.js";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import {
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { dirname } from "node:path";
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
const currentDir =
|
|
9
|
+
typeof __dirname !== "undefined"
|
|
10
|
+
? __dirname
|
|
11
|
+
: dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
|
|
13
|
+
export type YakConfigOptions = { contextPath?: string };
|
|
7
14
|
|
|
8
15
|
const addYak = (yakOptions: YakConfigOptions, nextConfig: NextConfig) => {
|
|
9
16
|
const previousConfig = nextConfig.webpack;
|
|
@@ -13,7 +20,7 @@ const addYak = (yakOptions: YakConfigOptions, nextConfig: NextConfig) => {
|
|
|
13
20
|
}
|
|
14
21
|
webpackConfig.module.rules.push({
|
|
15
22
|
test: /\.tsx?$/,
|
|
16
|
-
loader:
|
|
23
|
+
loader: path.join(currentDir, "../loaders/tsloader.cjs"),
|
|
17
24
|
options: yakOptions,
|
|
18
25
|
issuerLayer: {
|
|
19
26
|
// prevent recursions when calling this.importModule
|
|
@@ -23,15 +30,18 @@ const addYak = (yakOptions: YakConfigOptions, nextConfig: NextConfig) => {
|
|
|
23
30
|
});
|
|
24
31
|
webpackConfig.module.rules.push({
|
|
25
32
|
test: /\.yak\.module\.css$/,
|
|
26
|
-
loader:
|
|
33
|
+
loader: path.join(currentDir, "../loaders/cssloader.cjs"),
|
|
27
34
|
options: yakOptions,
|
|
28
35
|
});
|
|
29
36
|
|
|
30
|
-
// With the following alias the internal next-yak code
|
|
37
|
+
// With the following alias the internal next-yak code
|
|
31
38
|
// is able to import a context which works for server components
|
|
32
|
-
const yakContext = resolveYakContext(
|
|
39
|
+
const yakContext = resolveYakContext(
|
|
40
|
+
yakOptions.contextPath,
|
|
41
|
+
webpackConfig.context
|
|
42
|
+
);
|
|
33
43
|
if (yakContext) {
|
|
34
|
-
webpackConfig.resolve.alias[
|
|
44
|
+
webpackConfig.resolve.alias["next-yak/context/baseContext"] = yakContext;
|
|
35
45
|
}
|
|
36
46
|
|
|
37
47
|
return webpackConfig;
|
|
@@ -43,8 +53,10 @@ const addYak = (yakOptions: YakConfigOptions, nextConfig: NextConfig) => {
|
|
|
43
53
|
* Try to resolve yak
|
|
44
54
|
*/
|
|
45
55
|
function resolveYakContext(contextPath: string | undefined, cwd: string) {
|
|
46
|
-
const yakContext = contextPath
|
|
47
|
-
|
|
56
|
+
const yakContext = contextPath
|
|
57
|
+
? path.resolve(cwd, contextPath)
|
|
58
|
+
: path.resolve(cwd, "yak.context");
|
|
59
|
+
const extensions = ["", ".ts", ".tsx", ".js", ".jsx"];
|
|
48
60
|
for (const extension in extensions) {
|
|
49
61
|
const fileName = yakContext + extensions[extension];
|
|
50
62
|
if (existsSync(fileName)) {
|
|
@@ -59,7 +71,7 @@ function resolveYakContext(contextPath: string | undefined, cwd: string) {
|
|
|
59
71
|
// Wrapper to allow sync, async, and function configuration of Next.js
|
|
60
72
|
/**
|
|
61
73
|
* Add Yak to your Next.js app
|
|
62
|
-
*
|
|
74
|
+
*
|
|
63
75
|
* @usage
|
|
64
76
|
*
|
|
65
77
|
* ```ts
|
|
@@ -70,7 +82,7 @@ function resolveYakContext(contextPath: string | undefined, cwd: string) {
|
|
|
70
82
|
* };
|
|
71
83
|
* module.exports = withYak(nextConfig);
|
|
72
84
|
* ```
|
|
73
|
-
*
|
|
85
|
+
*
|
|
74
86
|
* With a custom yakConfig
|
|
75
87
|
*
|
|
76
88
|
* ```ts
|
|
@@ -86,29 +98,26 @@ function resolveYakContext(contextPath: string | undefined, cwd: string) {
|
|
|
86
98
|
* ```
|
|
87
99
|
*/
|
|
88
100
|
export const withYak: {
|
|
89
|
-
<
|
|
90
|
-
|
|
91
|
-
Record<string, any>
|
|
92
|
-
|
|
|
93
|
-
((...args: any[]) => Record<string, any
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
101
|
+
<
|
|
102
|
+
T extends
|
|
103
|
+
| Record<string, any>
|
|
104
|
+
| ((...args: any[]) => Record<string, any>)
|
|
105
|
+
| ((...args: any[]) => Promise<Record<string, any>>),
|
|
106
|
+
>(
|
|
107
|
+
yakOptions: YakConfigOptions,
|
|
108
|
+
nextConfig: T
|
|
109
|
+
): T;
|
|
98
110
|
// no yakConfig
|
|
99
|
-
<
|
|
100
|
-
|
|
101
|
-
Record<string, any>
|
|
102
|
-
|
|
|
103
|
-
((...args: any[]) => Record<string, any
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
} = (
|
|
109
|
-
maybeYakOptions,
|
|
110
|
-
nextConfig
|
|
111
|
-
) => {
|
|
111
|
+
<
|
|
112
|
+
T extends
|
|
113
|
+
| Record<string, any>
|
|
114
|
+
| ((...args: any[]) => Record<string, any>)
|
|
115
|
+
| ((...args: any[]) => Promise<Record<string, any>>),
|
|
116
|
+
>(
|
|
117
|
+
nextConfig: T,
|
|
118
|
+
_?: undefined
|
|
119
|
+
): T;
|
|
120
|
+
} = (maybeYakOptions, nextConfig) => {
|
|
112
121
|
if (nextConfig === undefined) {
|
|
113
122
|
return withYak({}, maybeYakOptions);
|
|
114
123
|
}
|
package/withYak/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"sourcesContent":["/// <reference types=\"node\" />\nimport { NextConfig } from \"../../example/node_modules/next/dist/server/config.js\";\nimport path from \"path\";\nimport { existsSync } from \"fs\";\n\nexport type YakConfigOptions = { contextPath?: string }\n\nconst addYak = (yakOptions: YakConfigOptions, nextConfig: NextConfig) => {\n const previousConfig = nextConfig.webpack;\n nextConfig.webpack = (webpackConfig, options) => {\n if (previousConfig) {\n webpackConfig = previousConfig(webpackConfig, options);\n }\n webpackConfig.module.rules.push({\n test: /\\.tsx?$/,\n loader: require.resolve(\"../loaders/tsloader.cjs\"),\n options: yakOptions,\n issuerLayer: {\n // prevent recursions when calling this.importModule\n // in the tsloader\n not: [\"yak-importModule\"],\n },\n });\n webpackConfig.module.rules.push({\n test: /\\.yak\\.module\\.css$/,\n loader: require.resolve(\"../loaders/cssloader.cjs\"),\n options: yakOptions,\n });\n\n // With the following alias the internal next-yak code \n // is able to import a context which works for server components\n const yakContext = resolveYakContext(yakOptions.contextPath, webpackConfig.context);\n if (yakContext) {\n webpackConfig.resolve.alias['next-yak/context/baseContext'] = yakContext;\n }\n\n return webpackConfig;\n };\n return nextConfig;\n};\n\n/**\n * Try to resolve yak\n */\nfunction resolveYakContext(contextPath: string | undefined, cwd: string) {\n const yakContext = contextPath ? path.resolve(cwd, contextPath) : path.resolve(cwd, \"yak.context\");\n const extensions = [\"\", \".ts\", \".tsx\", \".js\", \".jsx\", ];\n for (const extension in extensions) {\n const fileName = yakContext + extensions[extension];\n if (existsSync(fileName)) {\n return fileName;\n }\n }\n if (contextPath) {\n throw new Error(`Could not find yak context file at ${yakContext}`);\n }\n}\n\n// Wrapper to allow sync, async, and function configuration of Next.js\n/**\n * Add Yak to your Next.js app\n * \n * @usage\n *\n * ```ts\n * // next.config.js\n * const { withYak } = require(\"next-yak/withYak\");\n * const nextConfig = {\n * // your next config here\n * };\n * module.exports = withYak(nextConfig);\n * ```\n * \n * With a custom yakConfig\n *\n * ```ts\n * // next.config.js\n * const { withYak } = require(\"next-yak/withYak\");\n * const nextConfig = {\n * // your next config here\n * };\n * const yakConfig = {\n * // your yak config\n * };\n * module.exports = withYak(yakConfig, nextConfig);\n * ```\n */\nexport const withYak: {\n <T extends \n (\n Record<string, any>\n |\n ((...args: any[]) => Record<string, any>)\n |\n ((...args: any[]) => Promise<Record<string, any>>)\n )\n >(yakOptions: YakConfigOptions, nextConfig: T): T;\n // no yakConfig\n <T extends \n (\n Record<string, any>\n |\n ((...args: any[]) => Record<string, any>)\n |\n ((...args: any[]) => Promise<Record<string, any>>)\n )\n >(nextConfig: T, _?: undefined): T;\n} = (\n maybeYakOptions,\n nextConfig\n) => {\n if (nextConfig === undefined) {\n return withYak({}, maybeYakOptions);\n }\n // If the second parameter is present the first parameter must be a YakConfigOptions\n const yakOptions = maybeYakOptions as YakConfigOptions;\n if (typeof nextConfig === \"function\") {\n /**\n * A NextConfig can be a sync or async function\n * https://nextjs.org/docs/pages/api-reference/next-config-js\n * @param {any[]} args\n */\n return (...args) => {\n /** Dynamic Next Configs can be async or sync */\n const config = nextConfig(...args) as NextConfig | Promise<NextConfig>;\n return config instanceof Promise\n ? config.then((config) => addYak(yakOptions, config))\n : addYak(yakOptions, config);\n };\n }\n return addYak(yakOptions, nextConfig);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kBAAiB;AACjB,gBAA2B;AAI3B,IAAM,SAAS,CAAC,YAA8B,eAA2B;AACvE,QAAM,iBAAiB,WAAW;AAClC,aAAW,UAAU,CAAC,eAAe,YAAY;AAC/C,QAAI,gBAAgB;AAClB,sBAAgB,eAAe,eAAe,OAAO;AAAA,IACvD;AACA,kBAAc,OAAO,MAAM,KAAK;AAAA,MAC9B,MAAM;AAAA,MACN,QAAQ,gBAAgB,yBAAyB;AAAA,MACjD,SAAS;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