diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fb697f6 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +* text=auto eol=lf +*.cmd text=auto eol=crlf +*.bat text=auto eol=crlf +*.ps1 text=auto eol=crlf diff --git a/packages/mp/scripts/build.mjs b/packages/mp/scripts/build.mjs index b5ef4a1..94f8b2c 100644 --- a/packages/mp/scripts/build.mjs +++ b/packages/mp/scripts/build.mjs @@ -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"); @@ -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)), ); } diff --git a/packages/mp/src/package-exports.test.ts b/packages/mp/src/package-exports.test.ts index db91ee5..898e455 100644 --- a/packages/mp/src/package-exports.test.ts +++ b/packages/mp/src/package-exports.test.ts @@ -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", ); @@ -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);