@mochi-css/next 4.0.1 → 4.0.2
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 +31 -43
- package/dist/index.mjs +32 -44
- package/package.json +2 -2
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,36 @@ 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
|
+
}
|
|
48
|
+
function createBuilder(resolved, roots) {
|
|
49
|
+
const context = new __mochi_css_config.FullContext(resolved.onDiagnostic ?? (() => {}));
|
|
50
|
+
for (const plugin of resolved.plugins) plugin.onLoad?.(context);
|
|
51
|
+
return new __mochi_css_builder.Builder({
|
|
52
|
+
roots,
|
|
53
|
+
stages: [...context.stages.getAll()],
|
|
54
|
+
bundler: new __mochi_css_builder.RolldownBundler(),
|
|
55
|
+
runner: new __mochi_css_builder.VmRunner(),
|
|
56
|
+
splitCss: resolved.splitCss,
|
|
57
|
+
filePreProcess: ({ content, filePath }) => context.filePreProcess.transform(content, { filePath }),
|
|
58
|
+
sourceTransforms: [...context.sourceTransforms.getAll()],
|
|
59
|
+
emitHooks: [...context.emitHooks.getAll()],
|
|
60
|
+
cleanup: () => {
|
|
61
|
+
context.cleanup.runAll();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
43
65
|
let watcherStarted = false;
|
|
44
66
|
/**
|
|
45
67
|
* Sets up a file watcher that rebuilds Mochi CSS whenever source files change.
|
|
@@ -54,30 +76,13 @@ async function startCssWatcher(tmpDir) {
|
|
|
54
76
|
const resolved = await (0, __mochi_css_config.resolveConfig)(await (0, __mochi_css_config.loadConfig)(), void 0, {});
|
|
55
77
|
const effectiveTmpDir = resolved.tmpDir ? path.default.resolve(cwd, resolved.tmpDir) : tmpDir;
|
|
56
78
|
const debug = resolved.debug ?? false;
|
|
57
|
-
const absoluteRoots =
|
|
58
|
-
...root,
|
|
59
|
-
path: path.default.resolve(cwd, root.path)
|
|
60
|
-
});
|
|
79
|
+
const absoluteRoots = resolveAbsoluteRoots(cwd, resolved.roots);
|
|
61
80
|
if (debug) console.log(`[mochi-css] watcher: roots=${JSON.stringify(absoluteRoots)}, tmpDir=${effectiveTmpDir}`);
|
|
62
81
|
if (absoluteRoots.length === 0) {
|
|
63
82
|
console.warn("[mochi-css] watcher: no roots configured — add `roots` to mochi.config.ts");
|
|
64
83
|
return;
|
|
65
84
|
}
|
|
66
|
-
const
|
|
67
|
-
for (const plugin of resolved.plugins) plugin.onLoad?.(context);
|
|
68
|
-
const builder = new __mochi_css_builder.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
|
-
});
|
|
85
|
+
const builder = createBuilder(resolved, absoluteRoots);
|
|
81
86
|
let rebuildTimer;
|
|
82
87
|
let rebuildGuard = Promise.resolve();
|
|
83
88
|
const scheduleRebuild = () => {
|
|
@@ -91,7 +96,7 @@ async function startCssWatcher(tmpDir) {
|
|
|
91
96
|
}, 50);
|
|
92
97
|
};
|
|
93
98
|
scheduleRebuild();
|
|
94
|
-
const rootDirs = absoluteRoots.map((root) => typeof root === "string" ? root : root.path);
|
|
99
|
+
const rootDirs = absoluteRoots.map((root) => __mochi_css_builder.path.toSystemPath(typeof root === "string" ? root : root.path));
|
|
95
100
|
for (const dir of rootDirs) {
|
|
96
101
|
if (!fs.default.existsSync(dir)) {
|
|
97
102
|
console.warn(`[mochi-css] watcher: root not found: ${dir}`);
|
|
@@ -112,29 +117,12 @@ async function buildCssOnce(tmpDir) {
|
|
|
112
117
|
const cwd = process.cwd();
|
|
113
118
|
const resolved = await (0, __mochi_css_config.resolveConfig)(await (0, __mochi_css_config.loadConfig)(), void 0, {});
|
|
114
119
|
const effectiveTmpDir = resolved.tmpDir ? path.default.resolve(cwd, resolved.tmpDir) : tmpDir;
|
|
115
|
-
const absoluteRoots =
|
|
116
|
-
...root,
|
|
117
|
-
path: path.default.resolve(cwd, root.path)
|
|
118
|
-
});
|
|
120
|
+
const absoluteRoots = resolveAbsoluteRoots(cwd, resolved.roots);
|
|
119
121
|
if (absoluteRoots.length === 0) {
|
|
120
122
|
console.warn("[mochi-css] buildCssOnce: no roots configured — add `roots` to mochi.config.ts");
|
|
121
123
|
return;
|
|
122
124
|
}
|
|
123
|
-
|
|
124
|
-
for (const plugin of resolved.plugins) plugin.onLoad?.(context);
|
|
125
|
-
await writeCssFiles(await new __mochi_css_builder.Builder({
|
|
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);
|
|
125
|
+
await writeCssFiles(await createBuilder(resolved, absoluteRoots).collectMochiCss(), effectiveTmpDir);
|
|
138
126
|
}
|
|
139
127
|
|
|
140
128
|
//#endregion
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import { FullContext, loadConfig, resolveConfig } from "@mochi-css/config";
|
|
5
|
-
import { Builder, RolldownBundler, VmRunner, fileHash } from "@mochi-css/builder";
|
|
5
|
+
import { Builder, RolldownBundler, VmRunner, 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,36 @@ 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
|
+
}
|
|
48
|
+
function createBuilder(resolved, roots) {
|
|
49
|
+
const context = new FullContext(resolved.onDiagnostic ?? (() => {}));
|
|
50
|
+
for (const plugin of resolved.plugins) plugin.onLoad?.(context);
|
|
51
|
+
return new Builder({
|
|
52
|
+
roots,
|
|
53
|
+
stages: [...context.stages.getAll()],
|
|
54
|
+
bundler: new RolldownBundler(),
|
|
55
|
+
runner: new VmRunner(),
|
|
56
|
+
splitCss: resolved.splitCss,
|
|
57
|
+
filePreProcess: ({ content, filePath }) => context.filePreProcess.transform(content, { filePath }),
|
|
58
|
+
sourceTransforms: [...context.sourceTransforms.getAll()],
|
|
59
|
+
emitHooks: [...context.emitHooks.getAll()],
|
|
60
|
+
cleanup: () => {
|
|
61
|
+
context.cleanup.runAll();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
43
65
|
let watcherStarted = false;
|
|
44
66
|
/**
|
|
45
67
|
* Sets up a file watcher that rebuilds Mochi CSS whenever source files change.
|
|
@@ -54,30 +76,13 @@ async function startCssWatcher(tmpDir) {
|
|
|
54
76
|
const resolved = await resolveConfig(await loadConfig(), void 0, {});
|
|
55
77
|
const effectiveTmpDir = resolved.tmpDir ? path.resolve(cwd, resolved.tmpDir) : tmpDir;
|
|
56
78
|
const debug = resolved.debug ?? false;
|
|
57
|
-
const absoluteRoots =
|
|
58
|
-
...root,
|
|
59
|
-
path: path.resolve(cwd, root.path)
|
|
60
|
-
});
|
|
79
|
+
const absoluteRoots = resolveAbsoluteRoots(cwd, resolved.roots);
|
|
61
80
|
if (debug) console.log(`[mochi-css] watcher: roots=${JSON.stringify(absoluteRoots)}, tmpDir=${effectiveTmpDir}`);
|
|
62
81
|
if (absoluteRoots.length === 0) {
|
|
63
82
|
console.warn("[mochi-css] watcher: no roots configured — add `roots` to mochi.config.ts");
|
|
64
83
|
return;
|
|
65
84
|
}
|
|
66
|
-
const
|
|
67
|
-
for (const plugin of resolved.plugins) plugin.onLoad?.(context);
|
|
68
|
-
const builder = new 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
|
-
});
|
|
85
|
+
const builder = createBuilder(resolved, absoluteRoots);
|
|
81
86
|
let rebuildTimer;
|
|
82
87
|
let rebuildGuard = Promise.resolve();
|
|
83
88
|
const scheduleRebuild = () => {
|
|
@@ -91,7 +96,7 @@ async function startCssWatcher(tmpDir) {
|
|
|
91
96
|
}, 50);
|
|
92
97
|
};
|
|
93
98
|
scheduleRebuild();
|
|
94
|
-
const rootDirs = absoluteRoots.map((root) => typeof root === "string" ? root : root.path);
|
|
99
|
+
const rootDirs = absoluteRoots.map((root) => path$1.toSystemPath(typeof root === "string" ? root : root.path));
|
|
95
100
|
for (const dir of rootDirs) {
|
|
96
101
|
if (!fs.existsSync(dir)) {
|
|
97
102
|
console.warn(`[mochi-css] watcher: root not found: ${dir}`);
|
|
@@ -112,29 +117,12 @@ async function buildCssOnce(tmpDir) {
|
|
|
112
117
|
const cwd = process.cwd();
|
|
113
118
|
const resolved = await resolveConfig(await loadConfig(), void 0, {});
|
|
114
119
|
const effectiveTmpDir = resolved.tmpDir ? path.resolve(cwd, resolved.tmpDir) : tmpDir;
|
|
115
|
-
const absoluteRoots =
|
|
116
|
-
...root,
|
|
117
|
-
path: path.resolve(cwd, root.path)
|
|
118
|
-
});
|
|
120
|
+
const absoluteRoots = resolveAbsoluteRoots(cwd, resolved.roots);
|
|
119
121
|
if (absoluteRoots.length === 0) {
|
|
120
122
|
console.warn("[mochi-css] buildCssOnce: no roots configured — add `roots` to mochi.config.ts");
|
|
121
123
|
return;
|
|
122
124
|
}
|
|
123
|
-
|
|
124
|
-
for (const plugin of resolved.plugins) plugin.onLoad?.(context);
|
|
125
|
-
await writeCssFiles(await new Builder({
|
|
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);
|
|
125
|
+
await writeCssFiles(await createBuilder(resolved, absoluteRoots).collectMochiCss(), effectiveTmpDir);
|
|
138
126
|
}
|
|
139
127
|
|
|
140
128
|
//#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.0.
|
|
4
|
+
"version": "4.0.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"coverage": "vitest run --coverage"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@mochi-css/builder": "^4.0.
|
|
40
|
+
"@mochi-css/builder": "^4.0.1",
|
|
41
41
|
"@mochi-css/config": "^4.0.0",
|
|
42
42
|
"diff": "^8.0.3"
|
|
43
43
|
},
|