@shortwind/next 0.1.0-beta.0
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.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +16 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +56 -0
- package/dist/loader.js.map +1 -0
- package/package.json +30 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type ShortwindNextOptions = {
|
|
2
|
+
recipesDir?: string;
|
|
3
|
+
cwd?: string;
|
|
4
|
+
};
|
|
5
|
+
type WebpackConfig = {
|
|
6
|
+
module?: {
|
|
7
|
+
rules?: unknown[];
|
|
8
|
+
};
|
|
9
|
+
[k: string]: unknown;
|
|
10
|
+
};
|
|
11
|
+
type WebpackContext = {
|
|
12
|
+
dev: boolean;
|
|
13
|
+
isServer: boolean;
|
|
14
|
+
};
|
|
15
|
+
type TurbopackRule = {
|
|
16
|
+
loaders: Array<{
|
|
17
|
+
loader: string;
|
|
18
|
+
options?: unknown;
|
|
19
|
+
}>;
|
|
20
|
+
[k: string]: unknown;
|
|
21
|
+
};
|
|
22
|
+
type TurbopackConfig = {
|
|
23
|
+
rules?: Record<string, TurbopackRule>;
|
|
24
|
+
[k: string]: unknown;
|
|
25
|
+
};
|
|
26
|
+
type NextConfig = {
|
|
27
|
+
webpack?: (config: WebpackConfig, ctx: WebpackContext) => WebpackConfig;
|
|
28
|
+
turbopack?: TurbopackConfig;
|
|
29
|
+
experimental?: Record<string, unknown>;
|
|
30
|
+
[k: string]: unknown;
|
|
31
|
+
};
|
|
32
|
+
export declare function withShortwind(options?: ShortwindNextOptions): (nextConfig?: NextConfig) => NextConfig;
|
|
33
|
+
export { default as shortwindLoader } from "./loader.js";
|
|
34
|
+
export type { ShortwindLoaderOptions } from "./loader.js";
|
|
35
|
+
//# sourceMappingURL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AAO,IAAI,eAAe,EAAE,MAAM,aAAa,CAAC;AACzD,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { clearRegistryCache } from "./loader.js";
|
|
4
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
5
|
+
// Resolves to the compiled ESM sibling. If we ever ship a dual CJS/ESM build,
|
|
6
|
+
// the loader file name must remain stable for webpack/turbopack to resolve it.
|
|
7
|
+
const LOADER_PATH = path.join(here, "loader.js");
|
|
8
|
+
const SOURCE_TEST = /\.(?:tsx?|jsx?|mdx?)$/;
|
|
9
|
+
export function withShortwind(options = {}) {
|
|
10
|
+
const cwd = options.cwd ?? process.cwd();
|
|
11
|
+
const recipesDir = options.recipesDir ?? path.join(cwd, "recipes");
|
|
12
|
+
return (nextConfig = {}) => {
|
|
13
|
+
const loaderOptions = { recipesDir };
|
|
14
|
+
const previousWebpack = nextConfig.webpack;
|
|
15
|
+
const wrapped = {
|
|
16
|
+
...nextConfig,
|
|
17
|
+
webpack(config, ctx) {
|
|
18
|
+
const next = previousWebpack ? previousWebpack(config, ctx) : config;
|
|
19
|
+
next.module ??= {};
|
|
20
|
+
next.module.rules ??= [];
|
|
21
|
+
const rule = {
|
|
22
|
+
test: SOURCE_TEST,
|
|
23
|
+
exclude: /node_modules/,
|
|
24
|
+
use: [{ loader: LOADER_PATH, options: loaderOptions }],
|
|
25
|
+
enforce: "pre",
|
|
26
|
+
};
|
|
27
|
+
next.module.rules.unshift(rule);
|
|
28
|
+
if (ctx.dev)
|
|
29
|
+
clearRegistryCache();
|
|
30
|
+
return next;
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
const turbo = nextConfig.turbopack ?? {};
|
|
34
|
+
const rules = { ...(turbo.rules ?? {}) };
|
|
35
|
+
rules["*.{tsx,ts,jsx,js,mdx,md}"] = {
|
|
36
|
+
loaders: [{ loader: LOADER_PATH, options: loaderOptions }],
|
|
37
|
+
};
|
|
38
|
+
wrapped.turbopack = { ...turbo, rules };
|
|
39
|
+
return wrapped;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export { default as shortwindLoader } from "./loader.js";
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAkCjD,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC1D,8EAA8E;AAC9E,+EAA+E;AAC/E,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AAEjD,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAE5C,MAAM,UAAU,aAAa,CAC3B,UAAgC,EAAE;IAElC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACzC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAEnE,OAAO,CAAC,aAAyB,EAAE,EAAE,EAAE;QACrC,MAAM,aAAa,GAAG,EAAE,UAAU,EAAE,CAAC;QACrC,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,CAAC;QAE3C,MAAM,OAAO,GAAe;YAC1B,GAAG,UAAU;YACb,OAAO,CAAC,MAAM,EAAE,GAAG;gBACjB,MAAM,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;gBACrE,IAAI,CAAC,MAAM,KAAK,EAAE,CAAC;gBACnB,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,EAAE,CAAC;gBACzB,MAAM,IAAI,GAAG;oBACX,IAAI,EAAE,WAAW;oBACjB,OAAO,EAAE,cAAc;oBACvB,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;oBACtD,OAAO,EAAE,KAAc;iBACxB,CAAC;gBACF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBAChC,IAAI,GAAG,CAAC,GAAG;oBAAE,kBAAkB,EAAE,CAAC;gBAClC,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC;QAEF,MAAM,KAAK,GAAoB,UAAU,CAAC,SAAS,IAAI,EAAE,CAAC;QAC1D,MAAM,KAAK,GAAkC,EAAE,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;QACxE,KAAK,CAAC,0BAA0B,CAAC,GAAG;YAClC,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;SAC3D,CAAC;QACF,OAAO,CAAC,SAAS,GAAG,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,CAAC;QAExC,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type TransformOptions } from "@shortwind/tailwind";
|
|
2
|
+
export type ShortwindLoaderOptions = {
|
|
3
|
+
recipesDir: string;
|
|
4
|
+
mode?: TransformOptions["mode"];
|
|
5
|
+
};
|
|
6
|
+
export declare function clearRegistryCache(): void;
|
|
7
|
+
type LoaderContext = {
|
|
8
|
+
getOptions: () => ShortwindLoaderOptions;
|
|
9
|
+
resourcePath: string;
|
|
10
|
+
addDependency?: (file: string) => void;
|
|
11
|
+
addContextDependency?: (dir: string) => void;
|
|
12
|
+
emitError?: (err: Error) => void;
|
|
13
|
+
};
|
|
14
|
+
export default function shortwindLoader(this: LoaderContext, source: string): string;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,qBAAqB,CAAC;AAG7B,MAAM,MAAM,sBAAsB,GAAG;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;CACjC,CAAC;AAqCF,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED,KAAK,aAAa,GAAG;IACnB,UAAU,EAAE,MAAM,sBAAsB,CAAC;IACzC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,oBAAoB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAmBnF"}
|
package/dist/loader.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { loadRegistryFromDir, transformContent, } from "@shortwind/tailwind";
|
|
4
|
+
const registryCache = new Map();
|
|
5
|
+
function recipesSignature(recipesDir) {
|
|
6
|
+
if (!existsSync(recipesDir))
|
|
7
|
+
return { signature: "", files: [] };
|
|
8
|
+
const files = readdirSync(recipesDir)
|
|
9
|
+
.filter((f) => f.endsWith(".css"))
|
|
10
|
+
.sort()
|
|
11
|
+
.map((f) => path.join(recipesDir, f));
|
|
12
|
+
const parts = [];
|
|
13
|
+
for (const full of files) {
|
|
14
|
+
const st = statSync(full);
|
|
15
|
+
parts.push(`${full}:${st.size}:${st.mtimeMs}`);
|
|
16
|
+
}
|
|
17
|
+
return { signature: parts.join("|"), files };
|
|
18
|
+
}
|
|
19
|
+
function getRegistry(recipesDir) {
|
|
20
|
+
const { signature, files } = recipesSignature(recipesDir);
|
|
21
|
+
const cached = registryCache.get(recipesDir);
|
|
22
|
+
if (cached && cached.signature === signature)
|
|
23
|
+
return cached;
|
|
24
|
+
const entry = {
|
|
25
|
+
registry: loadRegistryFromDir(recipesDir),
|
|
26
|
+
files,
|
|
27
|
+
signature,
|
|
28
|
+
};
|
|
29
|
+
registryCache.set(recipesDir, entry);
|
|
30
|
+
return entry;
|
|
31
|
+
}
|
|
32
|
+
export function clearRegistryCache() {
|
|
33
|
+
registryCache.clear();
|
|
34
|
+
}
|
|
35
|
+
export default function shortwindLoader(source) {
|
|
36
|
+
const options = this.getOptions();
|
|
37
|
+
if (this.addContextDependency)
|
|
38
|
+
this.addContextDependency(options.recipesDir);
|
|
39
|
+
let entry;
|
|
40
|
+
try {
|
|
41
|
+
entry = getRegistry(options.recipesDir);
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
const wrapped = err instanceof Error ? err : new Error(`shortwind: failed to load registry: ${String(err)}`);
|
|
45
|
+
if (this.emitError)
|
|
46
|
+
this.emitError(wrapped);
|
|
47
|
+
return source;
|
|
48
|
+
}
|
|
49
|
+
if (this.addDependency) {
|
|
50
|
+
for (const file of entry.files)
|
|
51
|
+
this.addDependency(file);
|
|
52
|
+
}
|
|
53
|
+
const mode = options.mode ?? (this.resourcePath.endsWith(".html") ? "html" : "jsx");
|
|
54
|
+
return transformContent(source, entry.registry, { mode });
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,mBAAmB,EACnB,gBAAgB,GAEjB,MAAM,qBAAqB,CAAC;AAc7B,MAAM,aAAa,GAAG,IAAI,GAAG,EAAsB,CAAC;AAEpD,SAAS,gBAAgB,CAAC,UAAkB;IAC1C,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC;QAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IACjE,MAAM,KAAK,GAAG,WAAW,CAAC,UAAU,CAAC;SAClC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;SACjC,IAAI,EAAE;SACN,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;IACxC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC1B,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC;AAC/C,CAAC;AAED,SAAS,W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AAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAC3D,CAAC;IACD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACpF,OAAO,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AAC5D,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shortwind/next",
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"description": "Next.js plugin for Shortwind. Webpack and Turbopack.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"next": ">=14.0.0"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@shortwind/core": "0.1.0-beta.0",
|
|
16
|
+
"@shortwind/tailwind": "0.1.0-beta.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^25.7.0"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public",
|
|
23
|
+
"tag": "beta"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"test": "vitest run"
|
|
29
|
+
}
|
|
30
|
+
}
|