Skip to content

Commit

Permalink
chore: use vite as a build toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Jul 12, 2022
1 parent ced9c25 commit 30e1c39
Show file tree
Hide file tree
Showing 26 changed files with 1,361 additions and 7,559 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI
on:
push:
branches: [main]
pull_request:
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Use Node
uses: actions/setup-node@v3
with:
node-version: lts/*

- name: Install deps
uses: bahmutov/npm-install@v1

- name: Lint
run: yarn run lint

- name: Test
run: yarn test

- name: Build
run: yarn run build
29 changes: 0 additions & 29 deletions .github/workflows/main.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .github/workflows/pr.yml

This file was deleted.

53 changes: 15 additions & 38 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
"author": "rot1024",
"version": "1.2.0",
"license": "MIT",
"type": "module",
"source": "./src/index.ts",
"main": "./dist/quickjs-emscripten-sync.cjs",
"module": "./dist/quickjs-emscripten-sync.module.js",
"exports": "./dist/quickjs-emscripten-sync.modern.js",
"main": "./dist/quickjs-emscripten-sync.umd.js",
"module": "./dist/quickjs-emscripten-sync.es.js",
"unpkg": "./dist/quickjs-emscripten-sync.umd.js",
"types": "./dist/index.d.ts",
"sideEffects": false,
"exports": {
".": {
"import": "./dist/quickjs-emscripten-sync.es.js",
"require": "./dist/quickjs-emscripten-sync.umd.js"
}
},
"files": [
"dist",
"src"
Expand All @@ -19,57 +23,30 @@
"node": ">=10"
},
"scripts": {
"start": "microbundle watch --tsconfig tsconfig.build.json",
"build": "microbundle --tsconfig tsconfig.build.json",
"test": "jest",
"lint": "tsc && eslint --ext '.ts,.tsx,.js' .",
"size": "size-limit",
"analyze": "size-limit --why"
"build": "tsc && vite build",
"test": "vitest",
"lint": "eslint ."
},
"peerDependencies": {
"quickjs-emscripten": "*"
},
"jest": {
"preset": "ts-jest"
},
"prettier": {
"printWidth": 80,
"semi": true,
"singleQuote": false,
"trailingComma": "es5"
},
"size-limit": [
{
"path": "dist/quickjs-emscripten-sync.cjs",
"limit": "10 KB"
},
{
"path": "dist/quickjs-emscripten-sync.umd.js",
"limit": "10 KB"
},
{
"path": "dist/quickjs-emscripten-sync.module.js",
"limit": "10 KB"
},
{
"path": "dist/quickjs-emscripten-sync.modern.js",
"limit": "10 KB"
}
],
"devDependencies": {
"@size-limit/preset-small-lib": "^5.0.3",
"@types/jest": "^27.0.1",
"@typescript-eslint/eslint-plugin": "^4.31.1",
"@typescript-eslint/parser": "^4.31.1",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.2.0",
"microbundle": "^0.13.3",
"prettier": "^2.4.0",
"quickjs-emscripten": "^0.13.0",
"size-limit": "^5.0.3",
"ts-jest": "^27.0.5",
"typescript": "^4.4.3"
"typescript": "^4.4.3",
"vite": "^2.9.14",
"vite-plugin-dts": "^1.2.1",
"vitest": "^0.18.0"
}
}
2 changes: 2 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { getQuickJS } from "quickjs-emscripten";
import { describe, expect, test } from "vitest";

import { Arena } from ".";

describe("readme", () => {
Expand Down
15 changes: 8 additions & 7 deletions src/marshal/function.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { getQuickJS, QuickJSHandle } from "quickjs-emscripten";
import { json, eq, call } from "../vmutil";
import marshalFunction from "./function";
import { expect, test, vi } from "vitest";

test("normal func", async () => {
const vm = (await getQuickJS()).createVm();

const marshal = jest.fn((v) => json(vm, v));
const unmarshal = jest.fn((v) =>
const marshal = vi.fn((v) => json(vm, v));
const unmarshal = vi.fn((v) =>
eq(vm, v, vm.global) ? undefined : vm.dump(v)
);
const preMarshal = jest.fn((_, a) => a);
const innerfn = jest.fn((..._args: any[]) => "hoge");
const preMarshal = vi.fn((_, a) => a);
const innerfn = vi.fn((..._args: any[]) => "hoge");
const fn = (...args: any[]) => innerfn(...args);

const handle = marshalFunction(vm, fn, marshal, unmarshal, preMarshal);
Expand Down Expand Up @@ -40,7 +41,7 @@ test("normal func", async () => {

test("func which has properties", async () => {
const vm = (await getQuickJS()).createVm();
const marshal = jest.fn((v) => json(vm, v));
const marshal = vi.fn((v) => json(vm, v));

const fn = () => {};
fn.hoge = "foo";
Expand Down Expand Up @@ -118,7 +119,7 @@ test("preApply", async () => {
};
const unmarshal = (v: QuickJSHandle) =>
vm.typeof(v) === "object" ? that : vm.dump(v);
const preApply = jest.fn(
const preApply = vi.fn(
(a: Function, b: any, c: any[]) => a.apply(b, c) + "!"
);
const that = {};
Expand Down Expand Up @@ -152,7 +153,7 @@ test("preApply", async () => {

test("undefined", async () => {
const vm = (await getQuickJS()).createVm();
const f = jest.fn();
const f = vi.fn();

expect(marshalFunction(vm, undefined, f, f, f)).toBe(undefined);
expect(marshalFunction(vm, null, f, f, f)).toBe(undefined);
Expand Down
9 changes: 6 additions & 3 deletions src/marshal/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { getQuickJS } from "quickjs-emscripten";
import { expect, test, vi } from "vitest";

import VMMap from "../vmmap";
import { instanceOf, call } from "../vmutil";
import marshal from ".";
Expand Down Expand Up @@ -117,6 +119,7 @@ test("class", async () => {
}
}

expect(A.name).toBe("_A"); // class A's name is _A in vitest
const handle = marshal(A);
if (!map) throw new Error("map is undefined");

Expand All @@ -134,7 +137,7 @@ test("class", async () => {

expect(vm.typeof(handle)).toBe("function");
expect(vm.dump(vm.getProp(handle, "length"))).toBe(1);
expect(vm.dump(vm.getProp(handle, "name"))).toBe("A");
expect(vm.dump(vm.getProp(handle, "name"))).toBe("_A");
const staticA = vm.getProp(handle, "a");
expect(instanceOf(vm, staticA, handle)).toBe(true);
expect(vm.dump(vm.getProp(staticA, "a"))).toBe(100);
Expand Down Expand Up @@ -172,7 +175,7 @@ test("class", async () => {
});

test("marshalable", async () => {
const isMarshalable = jest.fn((a: any) => a !== globalThis);
const isMarshalable = vi.fn((a: any) => a !== globalThis);
const { vm, marshal, dispose } = await setup({
isMarshalable,
});
Expand All @@ -187,7 +190,7 @@ test("marshalable", async () => {
});

test("marshalable json", async () => {
const isMarshalable = jest.fn<"json", [any]>(() => "json");
const isMarshalable = vi.fn(() => "json" as const);
const { vm, marshal, dispose } = await setup({
isMarshalable,
});
Expand Down
8 changes: 5 additions & 3 deletions src/marshal/json.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { getQuickJS } from "quickjs-emscripten";
import { expect, test, vi } from "vitest";

import marshalJSON from "./json";

test("empty object", async () => {
Expand All @@ -8,7 +10,7 @@ test("empty object", async () => {
);

const obj = {};
const preMarshal = jest.fn((_, a) => a);
const preMarshal = vi.fn((_, a) => a);

const handle = marshalJSON(vm, obj, preMarshal);
if (!handle) throw new Error("handle is undefined");
Expand Down Expand Up @@ -36,7 +38,7 @@ test("normal object", async () => {
const entries = vm.unwrapResult(vm.evalCode(`Object.entries`));

const obj = { a: 100, b: "hoge" };
const preMarshal = jest.fn((_, a) => a);
const preMarshal = vi.fn((_, a) => a);

const handle = marshalJSON(vm, obj, preMarshal);
if (!handle) throw new Error("handle is undefined");
Expand Down Expand Up @@ -70,7 +72,7 @@ test("array", async () => {
const isArray = vm.unwrapResult(vm.evalCode(`Array.isArray`));

const array = [1, "aa"];
const preMarshal = jest.fn((_, a) => a);
const preMarshal = vi.fn((_, a) => a);

const handle = marshalJSON(vm, array, preMarshal);
if (!handle) throw new Error("handle is undefined");
Expand Down
16 changes: 9 additions & 7 deletions src/marshal/object.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { getQuickJS } from "quickjs-emscripten";
import { expect, test, vi } from "vitest";

import { call } from "../vmutil";
import marshalObject from "./object";

Expand All @@ -9,8 +11,8 @@ test("empty object", async () => {
);

const obj = {};
const marshal = jest.fn();
const preMarshal = jest.fn((_, a) => a);
const marshal = vi.fn();
const preMarshal = vi.fn((_, a) => a);

const handle = marshalObject(vm, obj, marshal, preMarshal);
if (!handle) throw new Error("handle is undefined");
Expand Down Expand Up @@ -39,14 +41,14 @@ test("normal object", async () => {
const entries = vm.unwrapResult(vm.evalCode(`Object.entries`));

const obj = { a: 100, b: "hoge" };
const marshal = jest.fn((v) =>
const marshal = vi.fn((v) =>
typeof v === "number"
? vm.newNumber(v)
: typeof v === "string"
? vm.newString(v)
: vm.null
);
const preMarshal = jest.fn((_, a) => a);
const preMarshal = vi.fn((_, a) => a);

const handle = marshalObject(vm, obj, marshal, preMarshal);
if (!handle) throw new Error("handle is undefined");
Expand Down Expand Up @@ -81,14 +83,14 @@ test("array", async () => {
const isArray = vm.unwrapResult(vm.evalCode(`Array.isArray`));

const array = [1, "aa"];
const marshal = jest.fn((v) =>
const marshal = vi.fn((v) =>
typeof v === "number"
? vm.newNumber(v)
: typeof v === "string"
? vm.newString(v)
: vm.null
);
const preMarshal = jest.fn((_, a) => a);
const preMarshal = vi.fn((_, a) => a);

const handle = marshalObject(vm, array, marshal, preMarshal);
if (!handle) throw new Error("handle is undefined");
Expand Down Expand Up @@ -123,7 +125,7 @@ test("prototype", async () => {
const proto = { a: 100 };
const protoHandle = vm.newObject();
vm.setProp(protoHandle, "a", vm.newNumber(100));
const preMarshal = jest.fn((_, a) => a);
const preMarshal = vi.fn((_, a) => a);

const obj = Object.create(proto);
obj.b = "hoge";
Expand Down
2 changes: 2 additions & 0 deletions src/marshal/primitive.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { getQuickJS } from "quickjs-emscripten";
import { expect, test } from "vitest";

import { eq } from "../vmutil";
import marshalPrimitive from "./primitive";

Expand Down
Loading

0 comments on commit 30e1c39

Please sign in to comment.