Skip to content

Commit

Permalink
Update repo (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
lydell authored Feb 10, 2024
1 parent 43b47c8 commit 8437d33
Show file tree
Hide file tree
Showing 20 changed files with 2,312 additions and 7,279 deletions.
19 changes: 7 additions & 12 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
"use strict";

module.exports = {
root: true,
extends: [
"eslint:recommended",
"plugin:jest/recommended",
"plugin:jest/style",
],
plugins: ["jest"],
extends: ["eslint:recommended", "plugin:vitest/recommended"],
plugins: ["vitest"],
parserOptions: {
ecmaVersion: 2016,
sourceType: "module",
ecmaVersion: 2020,
},
env: {
es6: true,
node: true,
"jest/globals": true,
},
rules: {
"arrow-body-style": "error",
Expand All @@ -32,7 +26,8 @@ module.exports = {
"prefer-template": "error",
eqeqeq: ["error", "always", { null: "ignore" }],
strict: "error",
"jest/no-conditional-expect": "off",
"jest/valid-title": "off",
"vitest/no-disabled-tests": "error",
"vitest/no-focused-tests": "error",
"vitest/valid-title": "off",
},
};
28 changes: 11 additions & 17 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,28 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node-version: [18.x]
node-version: [20.x]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "${{ matrix.node-version }}"

- name: Cache node_modules
id: cache-node_modules
uses: actions/cache@v3
- id: cache-node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ matrix.os }}-${{ matrix.node-version }}-${{ hashFiles('package.json', 'package-lock.json') }}

- name: npm ci
if: steps.cache-node_modules.outputs.cache-hit != 'true'
run: npm ci
- if: steps.cache-node_modules.outputs.cache-hit != 'true'
run: npm ci --no-audit

- name: Build
run: npm run build
- run: npm run build

- name: tsd
run: npx --no-install tsd
- run: npx tsd

- name: ESLint
run: npx --no-install eslint --report-unused-disable-directives .
- run: npx eslint --report-unused-disable-directives .

- name: Prettier
run: npx --no-install prettier --check .
- run: npx prettier --check .
25 changes: 10 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,26 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: [14.x, 16.x, 18.x]
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "${{ matrix.node-version }}"

- name: Cache node_modules
id: cache-node_modules
uses: actions/cache@v3
- id: cache-node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ matrix.os }}-${{ matrix.node-version }}-${{ hashFiles('package.json', 'package-lock.json') }}

- name: npm ci
if: steps.cache-node_modules.outputs.cache-hit != 'true'
run: npm ci
- if: steps.cache-node_modules.outputs.cache-hit != 'true'
run: npm ci --no-audit

- name: Build
run: npm run build
- run: npm run build

- name: Jest
run: npx --no-install jest --coverage
- run: npx vitest

- name: Benchmark
run: node benchmark.js
- run: node benchmark.js
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ _Spec: [JSX Specification]_
```ts
export default function jsTokens(
input: string,
options: { jsx: true }
options: { jsx: true },
): Iterable<Token | JSXToken>;
export declare type JSXToken =
Expand Down
22 changes: 10 additions & 12 deletions benchmark.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"use strict";

const babelParser = require("@babel/parser");
const fastGlob = require("fast-glob");
const fs = require("fs");
const jsTokens = require("./build/index");
import * as babelParser from "@babel/parser";
import fastGlob from "fast-glob";
import * as fs from "fs";
import jsTokens from "./build/index.js";

const usage = `
Usage: node benchmark.js [TOKENIZER] [NUM_FILES]
Expand Down Expand Up @@ -66,11 +64,11 @@ function read() {
.filter(
([, content]) =>
/\S/.test(content) &&
(content.trim().includes("\n") || content.length > 100)
(content.trim().includes("\n") || content.length > 100),
)
.sort(
([fileA, contentA], [fileB, contentB]) =>
contentA.length - contentB.length || fileA.localeCompare(fileB)
contentA.length - contentB.length || fileA.localeCompare(fileB),
)
.map(([file, content]) => `/*${file.replace(/\*\//g, "* /")}*/ ${content}`);
}
Expand All @@ -85,8 +83,8 @@ function median(array) {
return half === 0
? 0
: Number.isInteger(half)
? (sorted[half - 1] + sorted[half]) / 2
: sorted[Math.floor(half)];
? (sorted[half - 1] + sorted[half]) / 2
: sorted[Math.floor(half)];
}

function common(array) {
Expand All @@ -111,8 +109,8 @@ function fileSize(string) {
return byteLength < KiB
? `${byteLength} B`
: byteLength < MiB
? `${(byteLength / KiB).toFixed(1)} KiB`
: `${(byteLength / MiB).toFixed(1)} MiB`;
? `${(byteLength / KiB).toFixed(1)} KiB`
: `${(byteLength / MiB).toFixed(1)} MiB`;
}

function run(argv) {
Expand Down
13 changes: 6 additions & 7 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"use strict";
import * as coffee from "coffeescript";
import * as fs from "fs";
import * as path from "path";
import * as url from "url";

const coffee = require("coffeescript");
const fs = require("fs");
const path = require("path");

const DIR = __dirname;
const DIR = path.dirname(url.fileURLToPath(import.meta.url));
const BUILD = path.join(DIR, "build");

const READ_MORE = "**[➡️ Full readme](https://github.com/lydell/js-tokens/)**";
Expand Down Expand Up @@ -37,7 +36,7 @@ for (const { src, dest = src, transform } of FILES_TO_COPY) {
if (transform) {
fs.writeFileSync(
path.join(BUILD, dest),
transform(fs.readFileSync(path.join(DIR, src), "utf8"))
transform(fs.readFileSync(path.join(DIR, src), "utf8")),
);
} else {
fs.copyFileSync(path.join(DIR, src), path.join(BUILD, dest));
Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export declare type JSXToken =

declare function jsTokens(
input: string,
options: { jsx: true }
options: { jsx: true },
): Iterable<Token | JSXToken>;

declare function jsTokens(
input: string,
options?: { jsx?: boolean }
options?: { jsx?: boolean },
): Iterable<Token>;

// @ts-expect-error TypeScript complains about _both_ exporting types _and_ using `export =` but it seems to work fine in practice.
Expand Down
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const jsxTokens: Array<string> = Array.from(
expectError(token.closed);
return token.value;
}
}
},
);

expectType<Array<string>>(jsxTokens);
12 changes: 0 additions & 12 deletions jest.config.js

This file was deleted.

Loading

0 comments on commit 8437d33

Please sign in to comment.