chore: switch to bun as package manager and test runner
Some checks failed
ci/woodpecker/pr/checks Pipeline failed

This commit is contained in:
Johannes Loher 2023-07-22 02:49:47 +02:00
parent 16f1adc475
commit 91b222a14e
Signed by: saluu
GPG key ID: 7CB0A9FB553DA045
23 changed files with 97 additions and 5245 deletions

2
.gitignore vendored
View file

@ -28,5 +28,3 @@ junit.xml
# foundry
/client
/common
.pnpm-store/

View file

@ -8,4 +8,3 @@
/.vscode/
client
common
pnpm-lock.yaml

View file

@ -5,10 +5,7 @@
$schema: https://raw.githubusercontent.com/woodpecker-ci/woodpecker/master/pipeline/schema/schema.json
variables:
- &node_image node:lts
- &enable_pnpm
- corepack enable
- corepack prepare pnpm@latest --activate
- &bun_image oven/bun:latest
when:
- event: push
@ -19,34 +16,29 @@ when:
steps:
install:
image: *node_image
image: *bun_image
commands:
- <<: *enable_pnpm
- pnpm install --frozen-lockfile
- bun install --frozen-lockfile
lint:
group: check
image: *node_image
image: *bun_image
commands:
- <<: *enable_pnpm
- pnpm lint
- bun run lint
formatcheck:
group: check
image: *node_image
image: *bun_image
commands:
- <<: *enable_pnpm
- pnpm format:check
- bun run format:check
typecheck:
group: check
image: *node_image
image: *bun_image
commands:
- <<: *enable_pnpm
- pnpm typecheck
- bun run typecheck
test:
group: check
image: *node_image
image: *bun_image
commands:
- <<: *enable_pnpm
- pnpm test
- bun run test
reuse:
group: check
image: fsfe/reuse:latest
@ -54,17 +46,17 @@ steps:
- reuse lint
commitlint:
group: check
image: *node_image
image: *bun_image
commands:
- <<: *enable_pnpm
- apt-get update
- apt-get install git -y
- git fetch origin ${CI_COMMIT_TARGET_BRANCH}
- pnpm exec commitlint --from origin/${CI_COMMIT_TARGET_BRANCH}
- bunx commitlint --from origin/${CI_COMMIT_TARGET_BRANCH}
when:
event: pull_request
build:
group: build
image: *node_image
image: *bun_image
commands:
- export APPDATA=$(pwd)
- <<: *enable_pnpm
- pnpm build
- bun run build

View file

@ -5,10 +5,7 @@
$schema: https://raw.githubusercontent.com/woodpecker-ci/woodpecker/master/pipeline/schema/schema.json
variables:
- &node_image node:lts
- &enable_pnpm
- corepack enable
- corepack prepare pnpm@latest --activate
- &bun_image oven/bun:latest
- &is_latest_channel
evaluate: CI_COMMIT_TAG matches "^[0-9]+\\\\.[0-9]+\\\\.[0-9]+$"
- &is_beta_channel
@ -33,18 +30,16 @@ depends_on:
steps:
install:
image: *node_image
image: *bun_image
commands:
- <<: *enable_pnpm
- pnpm install --frozen-lockfile
- bun install --frozen-lockfile
build:
image: *node_image
image: *bun_image
environment:
NODE_ENV: production
commands:
- export APPDATA=$(pwd)
- <<: *enable_pnpm
- pnpm build
- bun run build
package:
group: prepare-release
image: alpine:latest
@ -55,10 +50,9 @@ steps:
- zip -r ${CI_REPO_NAME}.zip ${CI_REPO_NAME}/*
changelog:
group: prepare-release
image: *node_image
image: *bun_image
commands:
- <<: *enable_pnpm
- pnpm changelog
- bun run changelog
choose-latest-channel:
group: prepare-release
image: alpine:latest

View file

@ -5,10 +5,7 @@
$schema: https://raw.githubusercontent.com/woodpecker-ci/woodpecker/master/pipeline/schema/schema.json
variables:
- &node_image node:lts
- &enable_pnpm
- corepack enable
- corepack prepare pnpm@latest --activate
- &bun_image oven/bun:latest
when:
event: manual
@ -19,22 +16,20 @@ depends_on:
steps:
install:
image: *node_image
image: *bun_image
commands:
- <<: *enable_pnpm
- pnpm install --frozen-lockfile
- bun install --frozen-lockfile
release:
image: *node_image
image: *bun_image
commands:
- <<: *enable_pnpm
- apt-get update
- apt-get install --yes jq
- export REPOSITORY_URL=$(echo "${CI_REPO_CLONE_URL}" | sed -e "s|://|://$${FORGE_TOKEN_NAME}:$${FORGE_TOKEN}@|g")
- git remote set-url origin $${REPOSITORY_URL}
- git config user.name woodpecker[bot]
- git config user.email woodpecker[bot]@${CI_SYSTEM_HOST}
- pnpm bump-version --release=${RELEASE_TYPE}
- pnpm exec prettier --write package.json system.json
- bun run bump-version --release=${RELEASE_TYPE}
- bunx prettier --write package.json system.json
- export RELEASE_VERSION=$(jq -r '.version' < package.json)
- git --no-pager diff
- git add package.json system.json

View file

@ -32,21 +32,12 @@ https://git.f3l.de/api/packages/dungeonslayers/generic/ds4/latest/system.json
### Prerequisites
In order to build this system, recent versions of `node` and `pnpm` are
required. Most likely using `npm` or `yarn` also works but only `pnpm` is
officially supported. We recommend using the latest lts version of `node`. If
you use `nvm` to manage your `node` versions, you can simply run
```
nvm install
```
in the project's root directory.
In order to build this system, a recent version of `bun` isr equired.
You also need to install the project's dependencies. To do so, run
```
pnpm install
bun install
```
### Building
@ -54,13 +45,13 @@ pnpm install
You can build the project by running
```
pnpm build
bun run build
```
Alternatively, you can run
```
pnpm watch
bun run watch
```
to watch for changes and automatically build as necessary.
@ -83,7 +74,7 @@ On platforms other than Linux you need to adjust the path accordingly.
Then run
```
pnpm link-package
bun run link-package
```
### Running the tests
@ -91,7 +82,7 @@ pnpm link-package
You can run the tests with the following command:
```
pnpm test
bun run test
```
## Contributing

BIN
bun.lockb Executable file

Binary file not shown.

6
bunfig.toml Normal file
View file

@ -0,0 +1,6 @@
# SPDX-FileCopyrightText: 2023 Johannes Loher
#
# SPDX-License-Identifier: MIT
[test]
preload = "./spec/setup.ts"

View file

@ -47,18 +47,16 @@
"clean": "run-p clean:files clean:link",
"clean:files": "rimraf dist",
"clean:link": "node ./tools/link-package.js --clean",
"lint": "pnpm eslint",
"lint:fix": "pnpm eslint --fix",
"lint": "bun eslint",
"lint:fix": "bun eslint --fix",
"eslint": "eslint --ext .ts,.js,.cjs,.mjs .",
"format": "pnpm prettier --write",
"format:check": "pnpm prettier --check",
"prettier": "prettier \"./**/*.(ts|js|cjs|mjs|json|scss|yml|yaml)\"",
"test": "run-p test:vitest test:typecheck",
"test:vitest": "vitest run",
"format": "bun prettier --write",
"format:check": "bun prettier --check",
"prettier": "prettier './**/*.(ts|js|cjs|mjs|json|scss|yml|yaml)'",
"test": "run-p test:bun test:typecheck",
"test:bun": "bun test",
"test:typecheck": "tsc --noEmit --project spec/tsconfig.json",
"test:watch": "vitest",
"test:ci": "run-p test:ci:vitest test:typecheck",
"test:ci:vitest": "vitest run --reporter=default --reporter=junit --outputFile=junit.xml",
"test:watch": "bun test --watch",
"typecheck": "tsc --noEmit",
"typecheck:watch": "tsc --noEmit --watch",
"bump-version": "node ./tools/bump-version.js",
@ -76,6 +74,7 @@
"@types/node": "18.16.19",
"@typescript-eslint/eslint-plugin": "6.1.0",
"@typescript-eslint/parser": "6.1.0",
"bun-types": "0.7.0",
"conventional-changelog-cli": "3.0.0",
"conventional-changelog-conventionalcommits": "6.1.0",
"eslint": "8.45.0",
@ -92,8 +91,6 @@
"tslib": "2.6.0",
"typescript": "5.1.6",
"vite": "4.4.6",
"vitest": "0.33.0",
"yargs": "17.7.2"
},
"packageManager": "pnpm@8.6.9"
}
}

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,7 @@
//
// SPDX-License-Identifier: MIT
import { describe, expect, it } from "vitest";
import { describe, expect, it } from "bun:test";
import { evaluateCheck } from "../../src/dice/check-evaluation";

View file

@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: MIT
import { describe, expect, it } from "vitest";
import { describe, expect, it } from "bun:test";
import { calculateSpellPrice } from "../../../../src/documents/item/spell/calculate-spell-price";
@ -205,17 +205,15 @@ describe("calculateSpellPrice", () => {
{ cooldownDuration: "d20d", factor: 3 },
];
describe.each(cooldownDurations)(
"with cooldown duration set to $cooldownDuration",
({ cooldownDuration, factor }) => {
cooldownDurations.forEach(({ cooldownDuration, factor }) => {
describe(`with cooldown duration set to ${cooldownDuration}`, () => {
const dataWithCooldownDuration = {
...defaultData,
cooldownDuration,
};
it.each(buildCombinedTestCases())(
`returns ${factor} × $expected if the minimum leves are $description`,
({ minimumLevels, expected }) => {
buildCombinedTestCases().forEach(({ minimumLevels, expected, description }) => {
it(`returns ${factor} × ${expected} if the minimum leves are ${description}`, () => {
// given
const data: DS4SpellDataSourceData = {
...dataWithCooldownDuration,
@ -227,8 +225,8 @@ describe("calculateSpellPrice", () => {
// then
expect(spellPrice).toBe(expected !== null ? expected * factor : expected);
},
);
},
);
});
});
});
});
});

View file

@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: MIT
import { describe, expect, it } from "vitest";
import { describe, expect, it } from "bun:test";
import { defaultEvaluator, Evaluator, mathEvaluator } from "../../src/expression-evaluation/evaluator";
@ -26,7 +26,7 @@ describe("Evaluator", () => {
const evaluate = () => defaultEvaluator.evaluate(expression);
// then
expect(evaluate).toThrowError("'function' is not an allowed identifier.");
expect(evaluate).toThrow("'function' is not an allowed identifier.");
});
it("fails to evaluate expressions that contain invalid tokens", () => {
@ -37,7 +37,7 @@ describe("Evaluator", () => {
const evaluate = () => defaultEvaluator.evaluate(expression);
// then
expect(evaluate).toThrowError("Invalid or unexpected token (1)");
expect(evaluate).toThrow("Invalid or unexpected token (1)");
});
it("fails to evaluate expressions that contain arrow functions", () => {
@ -48,7 +48,7 @@ describe("Evaluator", () => {
const evaluate = () => defaultEvaluator.evaluate(expression);
// then
expect(evaluate).toThrowError("Invalid or unexpected token (4)");
expect(evaluate).toThrow("Invalid or unexpected token (4)");
});
it("makes the given context available", () => {
@ -84,7 +84,7 @@ describe("Evaluator", () => {
const evaluate = () => mathEvaluator.evaluate(expression);
// then
expect(evaluate).toThrowError("'constructor' is not an allowed identifier.");
expect(evaluate).toThrow("'constructor' is not an allowed identifier.");
});
});
});

View file

@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: MIT
import { describe, expect, it } from "vitest";
import { describe, expect, it } from "bun:test";
import { Lexer } from "../../src/expression-evaluation/lexer";
@ -574,7 +574,7 @@ describe("Lexer", () => {
},
];
it.each([
[
...singleOperatorTestCases,
...singleNumberTestCases,
...invalidNumberTestCases,
@ -584,7 +584,8 @@ describe("Lexer", () => {
...invalidStringTestCases,
...whiteSpaceTestCases,
...complicatedTermTestCases,
])("lexes $input correctly", ({ input, expected }) => {
].forEach(({ input, expected }) => {
it(`lexes ${input} correctly`, () => {
// when
const result = consume(new Lexer(input));
@ -592,6 +593,7 @@ describe("Lexer", () => {
expect(result).toEqual(expected);
});
});
});
function consume<T>(iterable: Iterable<T>): T[] {
const result: T[] = [];

View file

@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: MIT
import { describe, expect, it } from "vitest";
import { describe, expect, it } from "bun:test";
import { literals, safeOperators } from "../../src/expression-evaluation/grammar";
import { Validator } from "../../src/expression-evaluation/validator";
@ -31,7 +31,7 @@ describe("Validator", () => {
const validate = () => validator.validate(input);
// then
expect(validate).toThrowError("'true' is not an allowed identifier");
expect(validate).toThrow("'true' is not an allowed identifier");
});
it("allows multiple identifiers according to the given predicate", () => {
@ -70,7 +70,7 @@ describe("Validator", () => {
const validate = () => validator.validate(input);
// then
expect(validate).toThrowError("'undefined' is not an allowed identifier.");
expect(validate).toThrow("'undefined' is not an allowed identifier.");
});
it("disallows invalid invalid tokens", () => {
@ -82,7 +82,7 @@ describe("Validator", () => {
const validate = () => validator.validate(input);
// then
expect(validate).toThrowError("Invalid or unexpected token (0)");
expect(validate).toThrow("Invalid or unexpected token (0)");
});
it("allows a complicated valid expression", () => {
@ -108,7 +108,7 @@ describe("Validator", () => {
const validate = () => validator.validate(input);
// then
expect(validate).toThrowError("'constructor' is not an allowed identifier.");
expect(validate).toThrow("'constructor' is not an allowed identifier.");
});
it("disallows arrow functions", () => {
@ -120,6 +120,6 @@ describe("Validator", () => {
const validate = () => validator.validate(input);
// then
expect(validate).toThrowError("Invalid or unexpected token (3)");
expect(validate).toThrow("Invalid or unexpected token (3)");
});
});

View file

@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: MIT
import { describe, expect, it } from "vitest";
import { describe, expect, it } from "bun:test";
import de from "../../lang/de.json";
import en from "../../lang/en.json";

View file

@ -4,6 +4,8 @@
import en from "../lang/en.json";
console.log(Bun.version);
function setupPrimitives() {
Object.defineProperties(Number, {
isNumeric: {

View file

@ -1,4 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["bun-types", "@types/jquery", "handlebars"],
"skipLibCheck": true
},
"include": ["../src", "./"]
}

View file

@ -2,6 +2,8 @@
//
// SPDX-License-Identifier: MIT
/// <reference lib="dom" />
import "../scss/ds4.scss";
import { registerForHooks } from "./hooks/hooks";

View file

@ -7,7 +7,7 @@
pack() {
packs=$(ls -D ./packs)
for pack in $packs; do
pnpm exec fvtt package pack --compendiumName=$pack --inputDirectory=./packs/$pack --outputDirectory=./dist/packs
bunx fvtt package pack --compendiumName=$pack --inputDirectory=./packs/$pack --outputDirectory=./dist/packs
done
}
@ -15,7 +15,7 @@ unpack() {
packs=$(ls -D ./dist/packs)
rm -rf ./packs/*
for pack in $packs; do
pnpm exec fvtt package unpack --compendiumName=$pack --inputDirectory=./dist/packs --outputDirectory=./packs/$pack
bunx fvtt package unpack --compendiumName=$pack --inputDirectory=./dist/packs --outputDirectory=./packs/$pack
done
}

View file

@ -1,11 +1,12 @@
{
"compilerOptions": {
"outDir": "dist",
"target": "ES2021",
"lib": ["ES2021", "DOM"],
"target": "ESNext",
"lib": ["ESNext"],
"module": "ESNext",
"types": ["@types/jquery", "handlebars"],
"esModuleInterop": true,
"moduleResolution": "node",
"moduleResolution": "bundler",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noUncheckedIndexedAccess": true,

View file

@ -1,11 +0,0 @@
// SPDX-FileCopyrightText: 2022 Johannes Loher
//
// SPDX-License-Identifier: MIT
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
setupFiles: ["./spec/setup.ts"],
},
});