Skip to content

Commit fe63e79

Browse files
committed
misc: adjust code for linters
1 parent 8a2496a commit fe63e79

File tree

8 files changed

+64
-54
lines changed

8 files changed

+64
-54
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
wasm-node
1+
pkg

.github/workflows/CI.yaml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ name: CI
33
env:
44
DEBUG: napi:*
55
APP_NAME: font-toolkit
6-
MACOSX_DEPLOYMENT_TARGET: '10.13'
6+
MACOSX_DEPLOYMENT_TARGET: "10.13"
77

8-
'on':
8+
"on":
99
push:
1010
branches:
1111
- main
1212
tags-ignore:
13-
- '**'
13+
- "**"
1414
# 忽略以下文件
1515
paths-ignore:
16-
- '**/*.md'
17-
- 'LICENSE'
18-
- '**/*.gitignore'
19-
- '.editorconfig'
20-
- 'docs/**'
21-
- 'example/*.png'
16+
- "**/*.md"
17+
- "LICENSE"
18+
- "**/*.gitignore"
19+
- ".editorconfig"
20+
- "docs/**"
21+
- "example/*.png"
2222

2323
pull_request: null
2424

@@ -28,7 +28,7 @@ jobs:
2828
strategy:
2929
fail-fast: false
3030
matrix:
31-
node: ['12', '14', '16']
31+
node: ["14", "16"]
3232
runs-on: ubuntu-latest
3333

3434
steps:
@@ -54,7 +54,7 @@ jobs:
5454
- name: Install wasm-pack
5555
uses: jetli/[email protected]
5656
with:
57-
version: 'latest'
57+
version: "latest"
5858

5959
- name: Install dependencies
6060
run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
@@ -69,5 +69,4 @@ jobs:
6969
uses: actions/upload-artifact@v2
7070
with:
7171
name: wasm32
72-
path: wasm-node/*.wasm
73-
72+
path: pkg/**/*.wasm

__test__/wasm.spec.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
1-
import { promises as fs } from 'fs'
2-
import { join } from 'path'
1+
import { promises as fs } from 'fs';
2+
import { dirname, join } from 'path';
3+
import { fileURLToPath } from 'url';
34

4-
import test from 'ava'
5+
import test from 'ava';
56

6-
import { FontKit } from '../wasm-node'
7+
import ToolKit from '../pkg/node/index.js';
8+
9+
const { FontKit } = ToolKit;
10+
const __dirname = dirname(fileURLToPath(import.meta.url));
711

812
// init wasm
9-
let fontData = null
13+
let fontData: Uint8Array | null = null;
1014

1115
test.before(async () => {
12-
fontData = await fs.readFile(join(__dirname, '../examples/OpenSans-Italic.ttf'))
13-
})
16+
fontData = await fs.readFile(join(__dirname, '../examples/OpenSans-Italic.ttf'));
17+
});
1418

1519
test('em box', (t) => {
16-
const fontkit = new FontKit()
17-
const key = fontkit.add_font_from_buffer(fontData)
18-
const font = fontkit.query(key)
20+
const fontkit = new FontKit();
21+
const key = fontkit.add_font_from_buffer(fontData!);
22+
const font = fontkit.query(key);
1923

20-
t.is(font.units_per_em, 2048)
21-
})
24+
t.not(font, undefined);
25+
t.is(font!.units_per_em, 2048);
26+
});
2227

2328
test('glyph path to_string()', (t) => {
24-
const fontkit = new FontKit()
25-
const key = fontkit.add_font_from_buffer(fontData)
26-
const font = fontkit.query(key)
29+
const fontkit = new FontKit();
30+
const key = fontkit.add_font_from_buffer(fontData!);
31+
const font = fontkit.query(key);
2732

2833
t.is(
29-
font.glyph_path('A').to_string(),
34+
font!.glyph_path('A')!.to_string(),
3035
'M 813 2324 L 317 2324 L 72 2789 L -117 2789 L 682 1327 L 856 1327 L 1040 2789 L 870 2789 L 813 2324 z M 795 2168 L 760 1869 Q 736 1690 731 1519 Q 694 1607 650.5 1694 Q 607 1781 401 2168 L 795 2168 z',
31-
)
32-
})
36+
);
37+
});

node.mjs renamed to node.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { fileURLToPath } from 'url';
66
import walkdir from 'walkdir';
77
import { WASI } from 'wasi';
88

9+
export * from 'pkg/node/index';
10+
911
const __dirname = dirname(fileURLToPath(import.meta.url));
1012

1113
const WASM_PATH = resolve(__dirname, 'pkg/wasi/fontkit.wasm');

package.json

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,47 @@
99
},
1010
"files": [
1111
"pkg",
12-
"node.mjs"
12+
"node.mjs",
13+
"Readme.md"
1314
],
1415
"author": "Zimon Dai <[email protected]>",
1516
"license": "MIT",
1617
"types": "./pkg/bundler/index.d.ts",
1718
"scripts": {
18-
"prepack": "cargo build --target wasm32-unknown-unknown --release && wasm-bindgen --target bundler --out-dir pkg/bundler --out-name index ./target/wasm32-unknown-unknown/release/fontkit.wasm",
19-
"build": "wasm-pack build --target bundler --out-name index --out-dir pkg/bundler --release",
19+
"prepack": "cargo build --target wasm32-unknown-unknown --release && wasm-bindgen --target nodejs --out-dir pkg/node --out-name index ./target/wasm32-unknown-unknown/release/fontkit.wasm",
20+
"build": "wasm-pack build --target nodejs --out-name index --out-dir pkg/node --release && wasm-pack build --target nodejs --out-name index --out-dir pkg/node --release && rm -rf pkg/node/package.json && rm -rf pkg/bundler/package.json",
2021
"build:wasi": "cargo build --release --target wasm32-wasi && mkdir -p pkg/wasi && cp target/wasm32-wasi/release/fontkit.wasm pkg/wasi/",
2122
"test": "ava",
2223
"format:rs": "cargo fmt",
2324
"format:source": "prettier --config ./package.json --write './**/*.{js,ts,mjs}'",
2425
"format:yaml": "prettier --parser yaml --write './**/*.{yml,yaml}'",
25-
"lint": "eslint . -c ./.eslintrc.yml './**/*.{ts,tsx,js}'",
26-
"lint:fix": "eslint . -c ./.eslintrc.yml './**/*.{ts,tsx,js}' --fix"
26+
"lint": "eslint -c ./.eslintrc.yml './**/*.{ts,tsx,js}'",
27+
"lint:fix": "eslint -c ./.eslintrc.yml './**/*.{ts,tsx,js}' --fix"
2728
},
2829
"repository": {
2930
"type": "git",
3031
"url": "[email protected]:alibaba/font-toolkit.git"
3132
},
3233
"devDependencies": {
33-
"@swc-node/register": "^1.4.2",
34+
"@types/node": "^17.0.41",
3435
"@typescript-eslint/eslint-plugin": "^5.15.0",
3536
"@typescript-eslint/parser": "^5.15.0",
36-
"ava": "^3.15.0",
37+
"ava": "^4.3.0",
3738
"eslint": "^8.11.0",
3839
"eslint-config-prettier": "^8.5.0",
3940
"eslint-plugin-import": "^2.25.4",
4041
"eslint-plugin-prettier": "^4.0.0",
4142
"eslint-plugin-sonarjs": "^0.12.0",
42-
"prettier": "^2.6.0"
43+
"prettier": "^2.6.0",
44+
"ts-node": "^10.8.1",
45+
"typescript": "^4.7.3"
4346
},
4447
"ava": {
45-
"require": [
46-
"@swc-node/register"
47-
],
48-
"extensions": [
49-
"ts"
48+
"extensions": {
49+
"ts": "module"
50+
},
51+
"nodeArguments": [
52+
"--loader=ts-node/esm"
5053
],
5154
"timeout": "2m",
5255
"environmentVariables": {
@@ -65,4 +68,4 @@
6568
"dependencies": {
6669
"walkdir": "^0.4.1"
6770
}
68-
}
71+
}

src/ras.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use pathfinder_content::stroke::{LineCap, LineJoin, OutlineStrokeToFill, StrokeS
66
use pathfinder_geometry::vector::Vector2F;
77
use ttf_parser::{OutlineBuilder, Rect};
88
use usvg::PathData;
9-
#[cfg(wasm)]
10-
use wasm_bindgen::prelude::*;
119

1210
impl Font {
1311
/// Output the outline instructions of a glyph

src/wasm.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::*;
22
use pathfinder_content::outline::Outline;
33
use pathfinder_geometry::transform2d::Transform2F;
44
use pathfinder_geometry::vector::Vector2F;
5-
use wasm_bindgen::prelude::*;
65

76
/// Interface for querying data in a Font
87
#[wasm_bindgen(js_name = "Font")]

tsconfig.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
"target": "ES2018",
44
"strict": true,
55
"moduleResolution": "node",
6-
"module": "CommonJS",
6+
"module": "ES2020",
77
"noUnusedLocals": true,
88
"noUnusedParameters": true,
99
"esModuleInterop": true,
10-
"allowSyntheticDefaultImports": true
10+
"allowSyntheticDefaultImports": true,
1111
},
12-
"include": ["."],
13-
"exclude": ["node_modules"]
14-
}
12+
"include": [
13+
"."
14+
],
15+
"exclude": [
16+
"node_modules"
17+
]
18+
}

0 commit comments

Comments
 (0)