@teacss/bun 0.10.11 → 0.10.13

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 CHANGED
@@ -2,10 +2,10 @@ import { type ShellOptions } from "@teacss/engine";
2
2
  import type { BuildConfig, BuildOutput, BunPlugin } from "bun";
3
3
  export type { ShellOptions } from "@teacss/engine";
4
4
  /**
5
- * `import "virtual:teacss.css"` (or `"teacss.css"`) becomes the generated stylesheet; every other
6
- * module goes through `project.transform`, and in a CSS file whose top level has `@teacss;` the generated
7
- * stylesheet then takes that rule's place. `minify` defaults to false, as teacss-ts's Bun plugin emits the
8
- * stylesheet unminified.
5
+ * `import "virtual:teacss.css"` (or `"teacss.css"`) becomes the generated stylesheet; a CSS file goes through
6
+ * `project.transform`, and when its top level has `@teacss;` the generated stylesheet then takes that rule's
7
+ * place; every other module goes through `transformSource`. `minify` defaults to false, as teacss-ts's Bun
8
+ * plugin emits the stylesheet unminified.
9
9
  */
10
10
  export declare function teacss(options?: ShellOptions): BunPlugin;
11
11
  export interface WatchOptions {
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { existsSync, watch as watchDirectory } from "node:fs";
1
+ import { existsSync, readFileSync, watch as watchDirectory } from "node:fs";
2
2
  import { mkdir, readFile, writeFile } from "node:fs/promises";
3
3
  import { dirname, join, resolve, sep } from "node:path";
4
- import { createProject, extractBundledFonts, replaceEntry } from "@teacss/engine";
4
+ import { createProject, extractBundledFonts, isCssId, replaceEntry } from "@teacss/engine";
5
5
  const PLUGIN = "teacss";
6
6
  const VIRTUAL_ENTRY = /^(?:virtual:)?teacss\.css$/;
7
7
  const MODULE = /\.(?:[cm]?[jt]sx?|html)$/;
@@ -10,27 +10,43 @@ const NODE_MODULES = `${sep}node_modules${sep}`;
10
10
  // teacss-ts `rewriteBundledAssets` writes each bundled font as `teacss-fonts/teacss-<sha256>.woff2` beside the CSS.
11
11
  const FONT_URL_PREFIX = "./teacss-fonts/teacss-";
12
12
  const FONT_URL = /^\.\/teacss-fonts\/teacss-[a-f0-9]{64}\.woff2$/;
13
+ /**
14
+ * The tokens of each `@source` module that `transformSource` rewrites: a `:css:` group becomes a class whose
15
+ * definition the engine now holds, the same rewrite `onLoad` returns to Bun. Bun may ask for the stylesheet
16
+ * before it loads the module, so the stylesheet cannot wait for `onLoad`. A module `transformSource` leaves as
17
+ * it is has the tokens `extractFilesUnion` read from its file.
18
+ */
19
+ function compiledClasses(project, unreadable) {
20
+ const { engine } = project;
21
+ const tokens = [];
22
+ for (const file of project.info.sourceFiles) {
23
+ if (isCssId(file) || unreadable.has(file))
24
+ continue;
25
+ const transformed = engine.transformSource(file, readFileSync(file, "utf8"));
26
+ if (transformed)
27
+ tokens.push(...engine.updateModule(file, transformed.code).tokens);
28
+ }
29
+ return tokens;
30
+ }
13
31
  /**
14
32
  * The tokens of every `@source` file read once and of `inline.content.inline`. `warned` holds the
15
- * unmatched-token warnings already printed by earlier builds of the same plugin.
33
+ * unreadable-directory and unmatched-token warnings already printed by earlier builds of the same plugin.
16
34
  */
17
35
  function generateCss(project, minify, warned) {
36
+ const warnOnce = (message) => {
37
+ if (warned.has(message))
38
+ return;
39
+ warned.add(message);
40
+ console.warn(`[@teacss/bun] ${message}`);
41
+ };
18
42
  const union = project.engine.extractFilesUnion(project.info.sourceFiles);
19
43
  for (const path of project.info.unreadableDirectories)
20
- console.warn(`[@teacss/bun] cannot read ${path} (E_IO)`);
44
+ warnOnce(`cannot read ${path} (E_IO)`);
21
45
  for (const { path, error } of union.failed)
22
46
  console.warn(`[@teacss/bun] cannot read ${path} (${error})`);
23
- const tokens = [...new Set([...union.tokens, ...project.inlineTokens()])];
47
+ const tokens = [...new Set([...union.tokens, ...project.inlineTokens(), ...compiledClasses(project, new Set(union.failed.map(({ path }) => path)))])];
24
48
  const result = project.engine.generate({ kind: "tokens", tokens }, { minify, css: true });
25
- project.reportUnmatched(result, {
26
- tokens,
27
- warn: (message) => {
28
- if (warned.has(message))
29
- return;
30
- warned.add(message);
31
- console.warn(`[@teacss/bun] ${message}`);
32
- },
33
- });
49
+ project.reportUnmatched(result, { tokens, warn: warnOnce });
34
50
  return result.css;
35
51
  }
36
52
  function externalizeFonts(css, fonts) {
@@ -60,10 +76,10 @@ function projectRoot(options, config) {
60
76
  return resolve(options.root ?? config.root ?? process.cwd());
61
77
  }
62
78
  /**
63
- * `import "virtual:teacss.css"` (or `"teacss.css"`) becomes the generated stylesheet; every other
64
- * module goes through `project.transform`, and in a CSS file whose top level has `@teacss;` the generated
65
- * stylesheet then takes that rule's place. `minify` defaults to false, as teacss-ts's Bun plugin emits the
66
- * stylesheet unminified.
79
+ * `import "virtual:teacss.css"` (or `"teacss.css"`) becomes the generated stylesheet; a CSS file goes through
80
+ * `project.transform`, and when its top level has `@teacss;` the generated stylesheet then takes that rule's
81
+ * place; every other module goes through `transformSource`. `minify` defaults to false, as teacss-ts's Bun
82
+ * plugin emits the stylesheet unminified.
67
83
  */
68
84
  export function teacss(options = {}) {
69
85
  // `watch()` runs every build through this one plugin; each build gets a fresh project, so that no module or
@@ -88,8 +104,9 @@ export function teacss(options = {}) {
88
104
  const code = await readFile(args.path, "utf8");
89
105
  if (args.path.includes(NODE_MODULES) && !code.includes("@teacss-include"))
90
106
  return;
91
- const result = project.transform(args.path, code);
92
- return result.changed ? { contents: result.code, loader: args.loader } : undefined;
107
+ // The stylesheet reads the `@source` files itself, so the module's tokens are not registered with the engine.
108
+ const transformed = project.engine.transformSource(args.path, code);
109
+ return transformed ? { contents: transformed.code, loader: args.loader } : undefined;
93
110
  });
94
111
  build.onEnd(async (result) => {
95
112
  project.dispose();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teacss/bun",
3
- "version": "0.10.11",
3
+ "version": "0.10.13",
4
4
  "description": "Bun.build plugin for TeaCSS: virtual:teacss.css and the entry's @teacss become the CSS the Rust engine generates",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -31,7 +31,7 @@
31
31
  "node": ">=26"
32
32
  },
33
33
  "dependencies": {
34
- "@teacss/engine": "0.10.11"
34
+ "@teacss/engine": "0.10.13"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/bun": "1.4.3",
@@ -40,7 +40,7 @@
40
40
  "scripts": {
41
41
  "build:ts": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json",
42
42
  "build": "npm run build:ts",
43
- "test": "bun test",
43
+ "test": "npm run check:types && bun test",
44
44
  "check:types": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json --noEmit"
45
45
  },
46
46
  "publishConfig": {