@mochi-css/next 4.0.1 → 6.0.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.js +17 -42
- package/dist/index.mjs +19 -44
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -18,11 +18,9 @@ async function writeIfChanged(filePath, content) {
|
|
|
18
18
|
async function writeCssFiles(css, tmpDir) {
|
|
19
19
|
await fs.default.promises.mkdir(tmpDir, { recursive: true });
|
|
20
20
|
const existingCssFiles = new Set((await fs.default.promises.readdir(tmpDir)).filter((f) => f.endsWith(".css") && f !== "global.css").map((f) => path.default.resolve(tmpDir, f)));
|
|
21
|
-
const normalizedSourcemods = {};
|
|
22
|
-
for (const [source, mod] of Object.entries(css.sourcemods ?? {})) normalizedSourcemods[source.replaceAll("\\", "/")] = mod;
|
|
23
21
|
const diskManifest = {
|
|
24
22
|
files: {},
|
|
25
|
-
sourcemods:
|
|
23
|
+
sourcemods: css.sourcemods
|
|
26
24
|
};
|
|
27
25
|
const writtenCssPaths = /* @__PURE__ */ new Set();
|
|
28
26
|
if (css.global) {
|
|
@@ -34,12 +32,19 @@ async function writeCssFiles(css, tmpDir) {
|
|
|
34
32
|
const hash = (0, __mochi_css_builder.fileHash)(source);
|
|
35
33
|
const cssPath = path.default.resolve(tmpDir, `${hash}.css`);
|
|
36
34
|
await writeIfChanged(cssPath, fileCss);
|
|
37
|
-
diskManifest.files[source
|
|
35
|
+
diskManifest.files[source] = cssPath;
|
|
38
36
|
writtenCssPaths.add(cssPath);
|
|
39
37
|
}
|
|
40
38
|
for (const existingPath of existingCssFiles) if (!writtenCssPaths.has(existingPath)) await fs.default.promises.unlink(existingPath);
|
|
41
39
|
await writeIfChanged(path.default.resolve(tmpDir, "manifest.json"), JSON.stringify(diskManifest));
|
|
42
40
|
}
|
|
41
|
+
function resolveAbsoluteRoots(cwd, roots) {
|
|
42
|
+
const posixCwd = __mochi_css_builder.path.fromSystemPath(cwd);
|
|
43
|
+
return roots.map((root) => typeof root === "string" ? __mochi_css_builder.path.resolve(posixCwd, root) : {
|
|
44
|
+
...root,
|
|
45
|
+
path: __mochi_css_builder.path.resolve(posixCwd, root.path)
|
|
46
|
+
});
|
|
47
|
+
}
|
|
43
48
|
let watcherStarted = false;
|
|
44
49
|
/**
|
|
45
50
|
* Sets up a file watcher that rebuilds Mochi CSS whenever source files change.
|
|
@@ -54,30 +59,15 @@ async function startCssWatcher(tmpDir) {
|
|
|
54
59
|
const resolved = await (0, __mochi_css_config.resolveConfig)(await (0, __mochi_css_config.loadConfig)(), void 0, {});
|
|
55
60
|
const effectiveTmpDir = resolved.tmpDir ? path.default.resolve(cwd, resolved.tmpDir) : tmpDir;
|
|
56
61
|
const debug = resolved.debug ?? false;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
if (debug) console.log(`[mochi-css] watcher: roots=${JSON.stringify(absoluteRoots)}, tmpDir=${effectiveTmpDir}`);
|
|
62
|
-
if (absoluteRoots.length === 0) {
|
|
62
|
+
resolved.roots = resolveAbsoluteRoots(cwd, resolved.roots);
|
|
63
|
+
if (debug) console.log(`[mochi-css] watcher: roots=${JSON.stringify(resolved.roots)}, tmpDir=${effectiveTmpDir}`);
|
|
64
|
+
if (resolved.roots.length === 0) {
|
|
63
65
|
console.warn("[mochi-css] watcher: no roots configured — add `roots` to mochi.config.ts");
|
|
64
66
|
return;
|
|
65
67
|
}
|
|
66
68
|
const context = new __mochi_css_config.FullContext(resolved.onDiagnostic ?? (() => {}));
|
|
67
69
|
for (const plugin of resolved.plugins) plugin.onLoad?.(context);
|
|
68
|
-
const builder =
|
|
69
|
-
roots: absoluteRoots,
|
|
70
|
-
stages: [...context.stages.getAll()],
|
|
71
|
-
bundler: new __mochi_css_builder.RolldownBundler(),
|
|
72
|
-
runner: new __mochi_css_builder.VmRunner(),
|
|
73
|
-
splitCss: resolved.splitCss,
|
|
74
|
-
filePreProcess: ({ content, filePath }) => context.filePreProcess.transform(content, { filePath }),
|
|
75
|
-
sourceTransforms: [...context.sourceTransforms.getAll()],
|
|
76
|
-
emitHooks: [...context.emitHooks.getAll()],
|
|
77
|
-
cleanup: () => {
|
|
78
|
-
context.cleanup.runAll();
|
|
79
|
-
}
|
|
80
|
-
});
|
|
70
|
+
const builder = (0, __mochi_css_config.createBuilder)(resolved, context);
|
|
81
71
|
let rebuildTimer;
|
|
82
72
|
let rebuildGuard = Promise.resolve();
|
|
83
73
|
const scheduleRebuild = () => {
|
|
@@ -91,7 +81,7 @@ async function startCssWatcher(tmpDir) {
|
|
|
91
81
|
}, 50);
|
|
92
82
|
};
|
|
93
83
|
scheduleRebuild();
|
|
94
|
-
const rootDirs =
|
|
84
|
+
const rootDirs = resolved.roots.map((root) => __mochi_css_builder.path.toSystemPath(typeof root === "string" ? root : root.path));
|
|
95
85
|
for (const dir of rootDirs) {
|
|
96
86
|
if (!fs.default.existsSync(dir)) {
|
|
97
87
|
console.warn(`[mochi-css] watcher: root not found: ${dir}`);
|
|
@@ -112,29 +102,14 @@ async function buildCssOnce(tmpDir) {
|
|
|
112
102
|
const cwd = process.cwd();
|
|
113
103
|
const resolved = await (0, __mochi_css_config.resolveConfig)(await (0, __mochi_css_config.loadConfig)(), void 0, {});
|
|
114
104
|
const effectiveTmpDir = resolved.tmpDir ? path.default.resolve(cwd, resolved.tmpDir) : tmpDir;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
path: path.default.resolve(cwd, root.path)
|
|
118
|
-
});
|
|
119
|
-
if (absoluteRoots.length === 0) {
|
|
105
|
+
resolved.roots = resolveAbsoluteRoots(cwd, resolved.roots);
|
|
106
|
+
if (resolved.roots.length === 0) {
|
|
120
107
|
console.warn("[mochi-css] buildCssOnce: no roots configured — add `roots` to mochi.config.ts");
|
|
121
108
|
return;
|
|
122
109
|
}
|
|
123
110
|
const context = new __mochi_css_config.FullContext(resolved.onDiagnostic ?? (() => {}));
|
|
124
111
|
for (const plugin of resolved.plugins) plugin.onLoad?.(context);
|
|
125
|
-
await writeCssFiles(await
|
|
126
|
-
roots: absoluteRoots,
|
|
127
|
-
stages: [...context.stages.getAll()],
|
|
128
|
-
bundler: new __mochi_css_builder.RolldownBundler(),
|
|
129
|
-
runner: new __mochi_css_builder.VmRunner(),
|
|
130
|
-
splitCss: resolved.splitCss,
|
|
131
|
-
filePreProcess: ({ content, filePath }) => context.filePreProcess.transform(content, { filePath }),
|
|
132
|
-
sourceTransforms: [...context.sourceTransforms.getAll()],
|
|
133
|
-
emitHooks: [...context.emitHooks.getAll()],
|
|
134
|
-
cleanup: () => {
|
|
135
|
-
context.cleanup.runAll();
|
|
136
|
-
}
|
|
137
|
-
}).collectMochiCss(), effectiveTmpDir);
|
|
112
|
+
await writeCssFiles(await (0, __mochi_css_config.createBuilder)(resolved, context).collectMochiCss(), effectiveTmpDir);
|
|
138
113
|
}
|
|
139
114
|
|
|
140
115
|
//#endregion
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import fs from "fs";
|
|
4
|
-
import { FullContext, loadConfig, resolveConfig } from "@mochi-css/config";
|
|
5
|
-
import {
|
|
4
|
+
import { FullContext, createBuilder, loadConfig, resolveConfig } from "@mochi-css/config";
|
|
5
|
+
import { fileHash, path as path$1 } from "@mochi-css/builder";
|
|
6
6
|
|
|
7
7
|
//#region rolldown:runtime
|
|
8
8
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
@@ -18,11 +18,9 @@ async function writeIfChanged(filePath, content) {
|
|
|
18
18
|
async function writeCssFiles(css, tmpDir) {
|
|
19
19
|
await fs.promises.mkdir(tmpDir, { recursive: true });
|
|
20
20
|
const existingCssFiles = new Set((await fs.promises.readdir(tmpDir)).filter((f) => f.endsWith(".css") && f !== "global.css").map((f) => path.resolve(tmpDir, f)));
|
|
21
|
-
const normalizedSourcemods = {};
|
|
22
|
-
for (const [source, mod] of Object.entries(css.sourcemods ?? {})) normalizedSourcemods[source.replaceAll("\\", "/")] = mod;
|
|
23
21
|
const diskManifest = {
|
|
24
22
|
files: {},
|
|
25
|
-
sourcemods:
|
|
23
|
+
sourcemods: css.sourcemods
|
|
26
24
|
};
|
|
27
25
|
const writtenCssPaths = /* @__PURE__ */ new Set();
|
|
28
26
|
if (css.global) {
|
|
@@ -34,12 +32,19 @@ async function writeCssFiles(css, tmpDir) {
|
|
|
34
32
|
const hash = fileHash(source);
|
|
35
33
|
const cssPath = path.resolve(tmpDir, `${hash}.css`);
|
|
36
34
|
await writeIfChanged(cssPath, fileCss);
|
|
37
|
-
diskManifest.files[source
|
|
35
|
+
diskManifest.files[source] = cssPath;
|
|
38
36
|
writtenCssPaths.add(cssPath);
|
|
39
37
|
}
|
|
40
38
|
for (const existingPath of existingCssFiles) if (!writtenCssPaths.has(existingPath)) await fs.promises.unlink(existingPath);
|
|
41
39
|
await writeIfChanged(path.resolve(tmpDir, "manifest.json"), JSON.stringify(diskManifest));
|
|
42
40
|
}
|
|
41
|
+
function resolveAbsoluteRoots(cwd, roots) {
|
|
42
|
+
const posixCwd = path$1.fromSystemPath(cwd);
|
|
43
|
+
return roots.map((root) => typeof root === "string" ? path$1.resolve(posixCwd, root) : {
|
|
44
|
+
...root,
|
|
45
|
+
path: path$1.resolve(posixCwd, root.path)
|
|
46
|
+
});
|
|
47
|
+
}
|
|
43
48
|
let watcherStarted = false;
|
|
44
49
|
/**
|
|
45
50
|
* Sets up a file watcher that rebuilds Mochi CSS whenever source files change.
|
|
@@ -54,30 +59,15 @@ async function startCssWatcher(tmpDir) {
|
|
|
54
59
|
const resolved = await resolveConfig(await loadConfig(), void 0, {});
|
|
55
60
|
const effectiveTmpDir = resolved.tmpDir ? path.resolve(cwd, resolved.tmpDir) : tmpDir;
|
|
56
61
|
const debug = resolved.debug ?? false;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
if (debug) console.log(`[mochi-css] watcher: roots=${JSON.stringify(absoluteRoots)}, tmpDir=${effectiveTmpDir}`);
|
|
62
|
-
if (absoluteRoots.length === 0) {
|
|
62
|
+
resolved.roots = resolveAbsoluteRoots(cwd, resolved.roots);
|
|
63
|
+
if (debug) console.log(`[mochi-css] watcher: roots=${JSON.stringify(resolved.roots)}, tmpDir=${effectiveTmpDir}`);
|
|
64
|
+
if (resolved.roots.length === 0) {
|
|
63
65
|
console.warn("[mochi-css] watcher: no roots configured — add `roots` to mochi.config.ts");
|
|
64
66
|
return;
|
|
65
67
|
}
|
|
66
68
|
const context = new FullContext(resolved.onDiagnostic ?? (() => {}));
|
|
67
69
|
for (const plugin of resolved.plugins) plugin.onLoad?.(context);
|
|
68
|
-
const builder =
|
|
69
|
-
roots: absoluteRoots,
|
|
70
|
-
stages: [...context.stages.getAll()],
|
|
71
|
-
bundler: new RolldownBundler(),
|
|
72
|
-
runner: new VmRunner(),
|
|
73
|
-
splitCss: resolved.splitCss,
|
|
74
|
-
filePreProcess: ({ content, filePath }) => context.filePreProcess.transform(content, { filePath }),
|
|
75
|
-
sourceTransforms: [...context.sourceTransforms.getAll()],
|
|
76
|
-
emitHooks: [...context.emitHooks.getAll()],
|
|
77
|
-
cleanup: () => {
|
|
78
|
-
context.cleanup.runAll();
|
|
79
|
-
}
|
|
80
|
-
});
|
|
70
|
+
const builder = createBuilder(resolved, context);
|
|
81
71
|
let rebuildTimer;
|
|
82
72
|
let rebuildGuard = Promise.resolve();
|
|
83
73
|
const scheduleRebuild = () => {
|
|
@@ -91,7 +81,7 @@ async function startCssWatcher(tmpDir) {
|
|
|
91
81
|
}, 50);
|
|
92
82
|
};
|
|
93
83
|
scheduleRebuild();
|
|
94
|
-
const rootDirs =
|
|
84
|
+
const rootDirs = resolved.roots.map((root) => path$1.toSystemPath(typeof root === "string" ? root : root.path));
|
|
95
85
|
for (const dir of rootDirs) {
|
|
96
86
|
if (!fs.existsSync(dir)) {
|
|
97
87
|
console.warn(`[mochi-css] watcher: root not found: ${dir}`);
|
|
@@ -112,29 +102,14 @@ async function buildCssOnce(tmpDir) {
|
|
|
112
102
|
const cwd = process.cwd();
|
|
113
103
|
const resolved = await resolveConfig(await loadConfig(), void 0, {});
|
|
114
104
|
const effectiveTmpDir = resolved.tmpDir ? path.resolve(cwd, resolved.tmpDir) : tmpDir;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
path: path.resolve(cwd, root.path)
|
|
118
|
-
});
|
|
119
|
-
if (absoluteRoots.length === 0) {
|
|
105
|
+
resolved.roots = resolveAbsoluteRoots(cwd, resolved.roots);
|
|
106
|
+
if (resolved.roots.length === 0) {
|
|
120
107
|
console.warn("[mochi-css] buildCssOnce: no roots configured — add `roots` to mochi.config.ts");
|
|
121
108
|
return;
|
|
122
109
|
}
|
|
123
110
|
const context = new FullContext(resolved.onDiagnostic ?? (() => {}));
|
|
124
111
|
for (const plugin of resolved.plugins) plugin.onLoad?.(context);
|
|
125
|
-
await writeCssFiles(await
|
|
126
|
-
roots: absoluteRoots,
|
|
127
|
-
stages: [...context.stages.getAll()],
|
|
128
|
-
bundler: new RolldownBundler(),
|
|
129
|
-
runner: new VmRunner(),
|
|
130
|
-
splitCss: resolved.splitCss,
|
|
131
|
-
filePreProcess: ({ content, filePath }) => context.filePreProcess.transform(content, { filePath }),
|
|
132
|
-
sourceTransforms: [...context.sourceTransforms.getAll()],
|
|
133
|
-
emitHooks: [...context.emitHooks.getAll()],
|
|
134
|
-
cleanup: () => {
|
|
135
|
-
context.cleanup.runAll();
|
|
136
|
-
}
|
|
137
|
-
}).collectMochiCss(), effectiveTmpDir);
|
|
112
|
+
await writeCssFiles(await createBuilder(resolved, context).collectMochiCss(), effectiveTmpDir);
|
|
138
113
|
}
|
|
139
114
|
|
|
140
115
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mochi-css/next",
|
|
3
3
|
"repository": "git@github.com:Niikelion/mochi-css.git",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "6.0.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"coverage": "vitest run --coverage"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@mochi-css/builder": "^
|
|
41
|
-
"@mochi-css/config": "^
|
|
40
|
+
"@mochi-css/builder": "^6.0.0",
|
|
41
|
+
"@mochi-css/config": "^6.0.0",
|
|
42
42
|
"diff": "^8.0.3"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|