@plumeria/turbopack-loader 18.2.33 → 18.3.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.
Files changed (2) hide show
  1. package/README.md +109 -0
  2. package/package.json +10 -3
package/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # @plumeria/turbopack-loader
2
+
3
+ The loader that compiles Plumeria styles in a Next.js build, under Turbopack and webpack alike.
4
+
5
+ It reads each module, resolves `css.create` statically, rewrites the styling prop into a `className` string, and removes the `@plumeria/core` import along with the style declarations. The rules it extracts are collected into a stylesheet, and an import of that stylesheet is appended to the module, so the CSS reaches the app through the same graph the components do.
6
+
7
+ ```tsx
8
+ // in
9
+ const styles = css.create({ box: { padding: 16, color: 'red' } });
10
+ export const A = () => <div classStyle={styles.box} />;
11
+
12
+ // out
13
+ export const A = () => <div className={"xqqbxt1d xq96bg3w"} />;
14
+ import "../../node_modules/@plumeria/turbopack-loader/zero-virtual.css";
15
+ ```
16
+
17
+ Nothing of the library survives into the output, so a React Server Component keeps its styles with no `'use client'` boundary to add.
18
+
19
+ ## Setup
20
+
21
+ You do not configure this loader yourself. [`@plumeria/next-plugin`](https://www.npmjs.com/package/@plumeria/next-plugin) installs it and wires it into both bundlers:
22
+
23
+ ```bash
24
+ npm i -D @plumeria/next-plugin
25
+ ```
26
+
27
+ ```ts
28
+ // next.config.ts
29
+ import { withPlumeria } from '@plumeria/next-plugin';
30
+
31
+ export default withPlumeria({});
32
+ ```
33
+
34
+ ## Options
35
+
36
+ `withPlumeria` passes its second argument through as the loader's options:
37
+
38
+ ```ts
39
+ export default withPlumeria({}, {
40
+ include: ['./app/**/*.{ts,tsx}'],
41
+ exclude: ['**/node_modules/**'],
42
+ styleProp: 'sx',
43
+ });
44
+ ```
45
+
46
+ - `include` — the files to compile. The default is `['**/*.{js,jsx,ts,tsx}']`.
47
+ - `exclude` — the files to leave alone. The default is `['**/node_modules/**', '**/dist/**', '**/.next/**']`.
48
+ - `styleProp` — the JSX prop that carries styles. The default is `'classStyle'`.
49
+
50
+ The prop name here and the one declared in `plumeria.d.ts` have to match. If they disagree, the prop type-checks but is never compiled away.
51
+
52
+ ## The stylesheet
53
+
54
+ Rules are written to `zero-virtual.css` inside this package, and each compiled module imports it by relative path. In development the file grows as modules are compiled; a production build fills it in one pass before any module is processed, which is what [`@plumeria/compiler`](https://www.npmjs.com/package/@plumeria/compiler) is installed for. Writes are taken under a lock, so concurrent builds do not lose rules.
55
+
56
+ If styles are missing from a page, the module was not compiled — check that its path is matched by `include` and not by `exclude`.
57
+
58
+ ## Testing
59
+
60
+ A loader is a function that reads four properties off `this`, so it can be called on its own, with no bundler and no DOM in between. A Next.js project tests the loader its own build runs:
61
+
62
+ ```js
63
+ // compile.test.js
64
+ const loader = require('@plumeria/turbopack-loader');
65
+ const fn = loader.default ?? loader; // built as CommonJS with an ESM default
66
+
67
+ const compile = (source) =>
68
+ new Promise((resolve, reject) => {
69
+ fn.call(
70
+ {
71
+ resourcePath: `${__dirname}/fixture.tsx`,
72
+ async: () => (err, content) => (err ? reject(err) : resolve(content)),
73
+ addDependency: () => {},
74
+ clearDependencies: () => {},
75
+ },
76
+ source,
77
+ );
78
+ });
79
+
80
+ test('a media query does not collide with the base rule', async () => {
81
+ const code = await compile(`
82
+ import * as css from '@plumeria/core';
83
+ const styles = css.create({
84
+ box: { color: 'red', '@media (min-width: 640px)': { color: 'blue' } },
85
+ });
86
+ export const A = () => <div classStyle={styles.box} />;
87
+ `);
88
+
89
+ const classes = code.match(/className=\{"([^"]*)"\}/)[1].split(' ');
90
+ expect(new Set(classes).size).toBe(classes.length);
91
+ });
92
+ ```
93
+
94
+ It is plain asynchronous JavaScript, so Jest, Vitest and `node:test` all run it as it stands. Add this package to your `devDependencies` before requiring it: it arrives as a dependency of the plugin either way, but a strict package manager such as pnpm does not put a transitive dependency where your own code can reach it.
95
+
96
+ The rewritten code comes back through `async`. The stylesheet is written only under `NODE_ENV=development`, so a test run reads the class names and leaves the file alone; set the variable when the stylesheet is what you came for.
97
+
98
+ Read the class names out of the returned code rather than hard-coding them. An atomic class name is one property–value pair, hashed, so a list spelled out in a test breaks the next time a property is added to the style.
99
+
100
+ See [Testing](https://plumeria.dev/docs/testing) for the layer this belongs to, and the two it does not cover.
101
+
102
+ ## API Stability
103
+
104
+ **Stability: Frozen** — the signature will not change; behaviour may still be corrected.
105
+ See [API Stability](https://github.com/zss-in-js/plumeria#api-stability).
106
+
107
+ ## License
108
+
109
+ Plumeria is [MIT licensed](https://github.com/zss-in-js/plumeria/blob/main/LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/turbopack-loader",
3
- "version": "18.2.33",
3
+ "version": "18.3.0",
4
4
  "description": "Plumeria Turbopack-loader",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -17,13 +17,20 @@
17
17
  "sideEffects": false,
18
18
  "main": "dist/index.js",
19
19
  "types": "dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "default": "./dist/index.js"
24
+ },
25
+ "./zero-virtual.css": "./zero-virtual.css"
26
+ },
20
27
  "files": [
21
28
  "dist/",
22
29
  "zero-virtual.css"
23
30
  ],
24
31
  "dependencies": {
25
- "@plumeria/compiler": "^18.2.33",
26
- "@plumeria/utils": "^18.2.33"
32
+ "@plumeria/compiler": "^18.3.0",
33
+ "@plumeria/utils": "^18.3.0"
27
34
  },
28
35
  "devDependencies": {
29
36
  "@swc/core": "1.15.47",