diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c941f67ba..e279d6f9c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,11 +3,11 @@ name: CI on: workflow_dispatch: push: - branches: [master] + branches: [ master ] paths-ignore: - '**/*.md' pull_request: - types: [opened, synchronize] + types: [ opened, synchronize ] paths-ignore: - '**/*.md' @@ -48,7 +48,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ ubuntu-latest ] + os: [ windows-latest ] runs-on: ${{ matrix.os }} if: ${{ !startsWith(github.event.head_commit.message, 'release:') && !startsWith(github.event.head_commit.message, 'ci:') && !startsWith(github.event.head_commit.message, 'docs:') }} steps: @@ -60,7 +60,7 @@ jobs: uses: ./.github/actions/rustup with: clippy: true - save-cache: true + save-cache: true shared-key: mako-build-${{ matrix.os }}-${{ steps.week_mark.outputs.EXPIRES_WEEK_MARK }}-${{ hashFiles('./Cargo.lock') }} - name: Install pnpm uses: pnpm/action-setup@v4 @@ -82,7 +82,7 @@ jobs: ./packages/mako/*.node ./packages/mako/binding.* ./packages/mako/dist - if-no-files-found: error + if-no-files-found: error test_e2e: name: E2E needs: build @@ -90,8 +90,8 @@ jobs: fail-fast: false matrix: script: [ "test:e2e", "test:hmr", "test:umi" ] - os: [ ubuntu-latest ] - runs-on: ${{ matrix.os }} + os: [ windows-latest ] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - name: Install pnpm @@ -106,17 +106,18 @@ jobs: - run: | pnpm i pnpm playwright install chromium - + - name: Download bindings uses: actions/download-artifact@v4 with: - name: bindings-${{ matrix.os }} + name: bindings-${{ matrix.os }} path: packages/mako/ - name: LS run: ls -l ./packages/mako - name: Test E2E + shell: pwsh run: pnpm ${{ matrix.script }} - + lint: name: Clippy runs-on: ubuntu-latest @@ -131,7 +132,7 @@ jobs: with: clippy: true shared-key: x86-cargo-test-ubuntu-latest-${{ steps.week_mark.outputs.EXPIRES_WEEK_MARK }}-${{ hashFiles('./Cargo.lock') }} - + - name: Clippy run: cargo clippy --locked -- -D warnings diff --git a/crates/mako/src/ast/file.rs b/crates/mako/src/ast/file.rs index a3bac0cf1..953a56dbe 100644 --- a/crates/mako/src/ast/file.rs +++ b/crates/mako/src/ast/file.rs @@ -334,9 +334,13 @@ type Params = Vec<(String, String)>; type Fragment = Option; pub fn parse_path(path: &str) -> Result<(PathName, Search, Params, Fragment)> { + #[cfg(windows)] + let path: String = format!("file://{}", path); + #[cfg(not(windows))] + let path: String = path.to_owned(); let base = "http://a.com/"; let base_url = Url::parse(base)?; - let full_url = base_url.join(path)?; + let full_url = base_url.join(&path)?; let path = full_url.path().to_string(); let fragment = full_url.fragment().map(|s| s.to_string()); let search = full_url.query().unwrap_or("").to_string(); diff --git a/crates/mako/src/generate/group_chunk.rs b/crates/mako/src/generate/group_chunk.rs index d58dc999d..bda8ecd6a 100644 --- a/crates/mako/src/generate/group_chunk.rs +++ b/crates/mako/src/generate/group_chunk.rs @@ -29,6 +29,7 @@ impl Compiler { let mut entry_chunk_name = "index"; for (key, value) in &self.context.config.entry { + println!("{}", &value.to_string_lossy()); // hmr entry id has query '?hmr' if parse_path(&value.to_string_lossy()).unwrap().0 == parse_path(&entry.id).unwrap().0 diff --git a/packages/mako/binding.d.ts b/packages/mako/binding.d.ts index 479963cfd..a9989c8a2 100644 --- a/packages/mako/binding.d.ts +++ b/packages/mako/binding.d.ts @@ -3,10 +3,6 @@ /* auto-generated by NAPI-RS */ -export interface TransformOutput { - code: string; - map?: string; -} export interface JsHooks { name?: string; load?: ( diff --git a/scripts/path.mjs b/scripts/path.mjs new file mode 100644 index 000000000..78f31ac7d --- /dev/null +++ b/scripts/path.mjs @@ -0,0 +1,14 @@ +import path from 'path'; + +function winPath(path) { + const isExtendedLengthPath = /^\\\\\?\\/.test(path); + if (isExtendedLengthPath) { + return path; + } + + return path.replace(/\\/g, '/'); +} + +export function winJoin(...args) { + return winPath(path.join(...args)); +} diff --git a/scripts/test-e2e.mjs b/scripts/test-e2e.mjs index 2402abd13..b32e4bfe7 100644 --- a/scripts/test-e2e.mjs +++ b/scripts/test-e2e.mjs @@ -1,5 +1,6 @@ import test from 'node:test'; import 'zx/globals'; +import { winJoin } from './path.mjs'; // node version 小于 20 时退出 const nodeVersion = process.versions.node.split('.')[0]; @@ -9,7 +10,7 @@ if (nodeVersion < 20) { } const root = process.cwd(); -const fixtures = path.join(root, argv.fixtures || 'e2e/fixtures'); +const fixtures = winJoin(root, argv.fixtures || 'e2e/fixtures'); let onlyDir = argv.only ? argv.only : null; const dirs = fs.readdirSync(fixtures).filter((dir) => { if (dir.endsWith('-only')) { @@ -17,17 +18,17 @@ const dirs = fs.readdirSync(fixtures).filter((dir) => { } return ( !dir.startsWith('.') && - fs.statSync(path.join(fixtures, dir)).isDirectory() && - fs.existsSync(path.join(fixtures, dir, 'expect.js')) + fs.statSync(winJoin(fixtures, dir)).isDirectory() && + fs.existsSync(winJoin(fixtures, dir, 'expect.js')) ); }); for (const dir of onlyDir ? [onlyDir] : dirs) { const testFn = dir.includes('failed') && !argv.only ? test.skip : test; await testFn(dir, async () => { - const cwd = path.join(fixtures, dir); + const cwd = winJoin(fixtures, dir); if (argv.umi) { - if (!fs.existsSync(path.join(cwd, 'node_modules'))) { + if (!fs.existsSync(winJoin(cwd, 'node_modules'))) { await $`cd ${cwd} && mkdir node_modules`; } // run umi build @@ -40,11 +41,11 @@ for (const dir of onlyDir ? [onlyDir] : dirs) { } else { try { // run mako build - await $`${path.join(root, 'scripts', 'mako.js')} ${cwd}`; + await $`node ${winJoin(root, 'scripts', 'mako.js')} ${cwd}`; } catch (e) { const isErrorCase = dir.split('.').includes('error'); if (isErrorCase) { - const mod = await import(path.join(fixtures, dir, 'expect.js')); + const mod = await import(winJoin(fixtures, dir, 'expect.js')); mod.default(e); return; } else { @@ -53,7 +54,7 @@ for (const dir of onlyDir ? [onlyDir] : dirs) { } } // run expect.js - const mod = await import(path.join(fixtures, dir, 'expect.js')); + const mod = await import(winJoin(fixtures, dir, 'expect.js')); if (mod && typeof mod.default === 'function') { await mod.default(); } diff --git a/scripts/test-hmr.mjs b/scripts/test-hmr.mjs index f3c3c16bb..0886d1b46 100644 --- a/scripts/test-hmr.mjs +++ b/scripts/test-hmr.mjs @@ -4,12 +4,13 @@ import getPort, { clearLockedPorts } from 'get-port'; import { chromium, devices } from 'playwright'; import waitPort from 'wait-port'; import 'zx/globals'; +import { winJoin } from './path.mjs'; function skip() {} const root = process.cwd(); -const tmp = path.join(root, 'tmp', 'hmr'); -const tmpPackages = path.join(root, 'tmp', 'packages'); +const tmp = winJoin(root, 'tmp', 'hmr'); +const tmpPackages = winJoin(root, 'tmp', 'packages'); if (!fs.existsSync(tmp)) { fs.mkdirSync(tmp, { recursive: true }); } @@ -1096,7 +1097,7 @@ ReactDOM.createRoot(document.getElementById("root")!).render(<>
{ assert.equal(lastResult.html, '
App
', 'Initial render'); }, async () => { - const gitPath = path.join(tmp, '.git'); + const gitPath = winJoin(tmp, '.git'); if (fs.existsSync(gitPath)) { await $`rm -rf ${gitPath}`; } @@ -1151,7 +1152,7 @@ ReactDOM.createRoot(document.getElementById("root")!).render(<>
{Ma assert.equal(lastResult.html, '
A b
', 'Initial render'); }, async () => { - const gitPath = path.join(tmp, '.git'); + const gitPath = winJoin(tmp, '.git'); if (fs.existsSync(gitPath)) { await $`rm -rf ${gitPath}`; } @@ -1692,7 +1693,7 @@ function normalizeFiles(files, makoConfig = {}) { function write(files) { for (const [file, content] of Object.entries(files)) { - const p = path.join(tmp, file); + const p = winJoin(tmp, file); fs.mkdirSync(path.dirname(p), { recursive: true }); fs.writeFileSync(p, content, 'utf-8'); } @@ -1700,14 +1701,14 @@ function write(files) { function writePackage(packageName, files) { for (const [file, content] of Object.entries(files)) { - const p = path.join(tmpPackages, packageName, file); + const p = winJoin(tmpPackages, packageName, file); fs.mkdirSync(path.dirname(p), { recursive: true }); fs.writeFileSync(p, content, 'utf-8'); } } function remove(file) { - const p = path.join(tmp, file); + const p = winJoin(tmp, file); fs.unlinkSync(p); } @@ -1719,7 +1720,7 @@ async function startMakoDevServer() { assert(port === MAKO_DEV_PORT, `port ${MAKO_DEV_PORT} is not available`); isFirstCase = false; } - const p = $`${path.join( + const p = $`node ${winJoin( root, 'scripts', 'mako.js',