Skip to content
Closed
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
23 changes: 12 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -82,16 +82,16 @@ 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
strategy:
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
Expand All @@ -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
Expand All @@ -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

Expand Down
6 changes: 5 additions & 1 deletion crates/mako/src/ast/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,13 @@ type Params = Vec<(String, String)>;
type Fragment = Option<String>;

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();
Expand Down
1 change: 1 addition & 0 deletions crates/mako/src/generate/group_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions packages/mako/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

/* auto-generated by NAPI-RS */

export interface TransformOutput {
code: string;
map?: string;
}
export interface JsHooks {
name?: string;
load?: (
Expand Down
14 changes: 14 additions & 0 deletions scripts/path.mjs
Original file line number Diff line number Diff line change
@@ -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));
}
17 changes: 9 additions & 8 deletions scripts/test-e2e.mjs
Original file line number Diff line number Diff line change
@@ -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];
Expand All @@ -9,25 +10,25 @@ 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')) {
onlyDir = 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
Expand All @@ -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 {
Expand All @@ -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();
}
Expand Down
17 changes: 9 additions & 8 deletions scripts/test-hmr.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down Expand Up @@ -1096,7 +1097,7 @@ ReactDOM.createRoot(document.getElementById("root")!).render(<><App /><section>{
assert.equal(lastResult.html, '<div>App</div>', 'Initial render');
},
async () => {
const gitPath = path.join(tmp, '.git');
const gitPath = winJoin(tmp, '.git');
if (fs.existsSync(gitPath)) {
await $`rm -rf ${gitPath}`;
}
Expand Down Expand Up @@ -1151,7 +1152,7 @@ ReactDOM.createRoot(document.getElementById("root")!).render(<><A /><section>{Ma
assert.equal(lastResult.html, '<div>A b</div>', 'Initial render');
},
async () => {
const gitPath = path.join(tmp, '.git');
const gitPath = winJoin(tmp, '.git');
if (fs.existsSync(gitPath)) {
await $`rm -rf ${gitPath}`;
}
Expand Down Expand Up @@ -1692,22 +1693,22 @@ 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');
}
}

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);
}

Expand All @@ -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',
Expand Down