Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* text=auto eol=lf
*.cmd text=auto eol=crlf
*.bat text=auto eol=crlf
*.ps1 text=auto eol=crlf
9 changes: 5 additions & 4 deletions packages/mp/scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ execFileSync(
// 3. Compile var.css + mobile-tokens.css -> mp-tokens.wxss / mp-tokens.css
const compilerUrl = pathToFileURL(join(distDir, "compiler", "wxss-tokens.js")).href;
const { compileWxssTokens } = await import(compilerUrl);
const varCss = readFileSync(join(coreRoot, "src", "var.css"), "utf8");
const mobileTokensCss = readFileSync(join(coreRoot, "src", "mobile-tokens.css"), "utf8");
const readUtf8Lf = (filePath) => readFileSync(filePath, "utf8").replace(/\r\n/g, "\n");
const varCss = readUtf8Lf(join(coreRoot, "src", "var.css"));
const mobileTokensCss = readUtf8Lf(join(coreRoot, "src", "mobile-tokens.css"));
const compiled = compileWxssTokens(varCss, mobileTokensCss);

writeFileSync(join(stylesDir, "mp-tokens.wxss"), compiled.wxss, "utf8");
Expand All @@ -52,13 +53,13 @@ writeFileSync(join(distDir, "mp-tokens.wxss"), compiled.wxss, "utf8");
writeFileSync(join(distDir, "mp-tokens.css"), compiled.css, "utf8");

// 4. Emit mp-base.{css,wxss}, mp-components.{css,wxss}, and combined mp-styles.{css,wxss}
const baseCss = readFileSync(join(stylesDir, "mp-base.css"), "utf8");
const baseCss = readUtf8Lf(join(stylesDir, "mp-base.css"));
const baseWxss = baseCss.replace(
/\.mw-mp-root\s*,[\s\S]*?\.mw-mp-root \*::after\s*\{([\s\S]*?)\}\n\n/,
".mw-mp-root {$1}\n\n",
);
function readCssWithImports(filePath) {
return readFileSync(filePath, "utf8").replace(/^@import\s+["'](.+?)["'];?\s*$/gm, (_match, request) =>
return readUtf8Lf(filePath).replace(/^@import\s+["'](.+?)["'];?\s*$/gm, (_match, request) =>
readCssWithImports(join(dirname(filePath), request)),
);
}
Expand Down
14 changes: 8 additions & 6 deletions packages/mp/src/package-exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ const coreRoot = join(pkgRoot, "..", "core");
const stylesDir = join(pkgRoot, "src", "styles");
const pkgJson = JSON.parse(readFileSync(join(pkgRoot, "package.json"), "utf8"));

const readUtf8Lf = (filePath: string): string => readFileSync(filePath, "utf8").replace(/\r\n/g, "\n");

function readCssWithImports(filePath: string): string {
return readFileSync(filePath, "utf8").replace(/^@import\s+["'](.+?)["'];?\s*$/gm, (_match, request: string) =>
return readUtf8Lf(filePath).replace(/^@import\s+["'](.+?)["'];?\s*$/gm, (_match, request: string) =>
readCssWithImports(join(dirname(filePath), request)),
);
}

function buildExpectedStylesWxss(): { tokensWxss: string; stylesWxss: string } {
const varCss = readFileSync(join(coreRoot, "src", "var.css"), "utf8");
const mobileTokensCss = readFileSync(join(coreRoot, "src", "mobile-tokens.css"), "utf8");
const varCss = readUtf8Lf(join(coreRoot, "src", "var.css"));
const mobileTokensCss = readUtf8Lf(join(coreRoot, "src", "mobile-tokens.css"));
const compiled = compileWxssTokens(varCss, mobileTokensCss);
const baseWxss = readFileSync(join(stylesDir, "mp-base.css"), "utf8").replace(
const baseWxss = readUtf8Lf(join(stylesDir, "mp-base.css")).replace(
/\.mw-mp-root\s*,[\s\S]*?\.mw-mp-root \*::after\s*\{([\s\S]*?)\}\n\n/,
".mw-mp-root {$1}\n\n",
);
Expand All @@ -43,9 +45,9 @@ describe("@mango-write/ui-mp package exports & built styles", () => {

it("keeps source WXSS artifacts fresh, free of illegal wcsc selectors, and compilable by wcsc", () => {
const expected = buildExpectedStylesWxss();
const srcTokensWxss = readFileSync(join(stylesDir, "mp-tokens.wxss"), "utf8");
const srcTokensWxss = readUtf8Lf(join(stylesDir, "mp-tokens.wxss"));
const srcStylesWxssPath = join(stylesDir, "mp-styles.wxss");
const srcStylesWxss = readFileSync(srcStylesWxssPath, "utf8");
const srcStylesWxss = readUtf8Lf(srcStylesWxssPath);

expect(srcTokensWxss).toBe(expected.tokensWxss);
expect(srcStylesWxss).toBe(expected.stylesWxss);
Expand Down
Loading