diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index c66f3290..102f6aeb 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -25,8 +25,10 @@ jobs: node-version: 20 - name: Install dependencies run: npm install - - name: Compile sources - run: npm run compile + - name: Build bundle + run: npm run build:bundle + - name: Replace the entrypoint with a bundle + run: npm run build:bundle:replace - name: Benchmark (async) run: npm run bench:product:async - name: Benchmark (stream) @@ -58,8 +60,10 @@ jobs: node-version: 20 - name: Install dependencies run: npm install - - name: Compile sources - run: npm run compile + - name: Build bundle + run: npm run build:bundle + - name: Replace the entrypoint with a bundle + run: npm run build:bundle:replace - name: Benchmark (async) run: npm run bench:regression:async - name: Benchmark (stream) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1c8d590d..7348aa00 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,8 +36,10 @@ jobs: node-version: ${{ matrix.node_version }} - name: Install dependencies run: npm install - - name: Compile sources - run: npm run compile + - name: Build bundle + run: npm run build:bundle + - name: Replace the entrypoint with a bundle + run: npm run build:bundle:replace - name: Run Hygiene Checks run: npm run lint - name: Run unit tests diff --git a/.gitignore b/.gitignore index 76707907..e5208476 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ node_modules/ .tmp/ .benchmark/ out/ +build/ # Other files package-lock.json diff --git a/package.json b/package.json index 8f59a60d..0a01ac1a 100644 --- a/package.json +++ b/package.json @@ -11,13 +11,13 @@ "engines": { "node": ">=16.14.0" }, - "main": "out/index.js", - "typings": "out/index.d.ts", + "main": "build/index.js", + "typings": "build/index.d.ts", "files": [ - "out", - "!out/{benchmark,tests}", - "!out/**/*.map", - "!out/**/*.spec.*" + "build", + "!build/{benchmark,tests}", + "!build/**/*.map", + "!build/**/*.spec.*" ], "keywords": [ "glob", @@ -35,6 +35,7 @@ "@types/picomatch": "^2.3.0", "@types/sinon": "^10.0.15", "bencho": "^0.1.1", + "esbuild": "^0.19.5", "eslint": "^8.46.0", "eslint-config-mrmlnc": "^4.0.1", "execa": "^7.2.0", @@ -56,7 +57,7 @@ "micromatch": "^4.0.5" }, "scripts": { - "clean": "rimraf out", + "clean": "rimraf out build", "lint": "eslint \"src/**/*.ts\" --cache", "compile": "tsc", "test": "mocha \"out/**/*.spec.js\" -s 0", @@ -64,8 +65,14 @@ "test:e2e:sync": "mocha \"out/**/*.e2e.js\" -s 0 --grep \"\\(sync\\)\"", "test:e2e:async": "mocha \"out/**/*.e2e.js\" -s 0 --grep \"\\(async\\)\"", "test:e2e:stream": "mocha \"out/**/*.e2e.js\" -s 0 --grep \"\\(stream\\)\"", - "build": "npm run clean && npm run compile && npm run lint && npm test", - "watch": "npm run clean && npm run compile -- --sourceMap --watch", + "_build:compile": "npm run clean && npm run compile", + "build": "npm run _build:compile && npm run lint && npm test", + "watch": "npm run _build:compile -- --sourceMap --watch", + "_build:bundle:dts": "tsc --emitDeclarationOnly --outDir ./build", + "_build:bundle:ts": "esbuild --bundle ./src/index.ts --outfile=./build/index.js --platform=node --target=node16.14", + "_build:bundle": "npm run _build:bundle:dts && npm run _build:bundle:ts", + "build:bundle": "npm run _build:compile && npm run _build:bundle", + "build:bundle:replace": "npm run _build:bundle:ts -- --outfile=./out/index.js", "bench:async": "npm run bench:product:async && npm run bench:regression:async", "bench:stream": "npm run bench:product:stream && npm run bench:regression:stream", "bench:sync": "npm run bench:product:sync && npm run bench:regression:sync", diff --git a/src/utils/pattern.ts b/src/utils/pattern.ts index 9d789e79..00c69c40 100644 --- a/src/utils/pattern.ts +++ b/src/utils/pattern.ts @@ -1,6 +1,8 @@ import * as path from 'node:path'; -import * as globParent from 'glob-parent'; +// https://stackoverflow.com/a/39415662 +// eslint-disable-next-line @typescript-eslint/no-require-imports +import globParent = require('glob-parent'); import * as micromatch from 'micromatch'; import type { MicromatchOptions, Pattern, PatternRe } from '../types'; diff --git a/src/utils/stream.ts b/src/utils/stream.ts index cb05ef53..0bf3d3d6 100644 --- a/src/utils/stream.ts +++ b/src/utils/stream.ts @@ -1,4 +1,6 @@ -import * as merge2 from 'merge2'; +// https://stackoverflow.com/a/39415662 +// eslint-disable-next-line @typescript-eslint/no-require-imports +import merge2 = require('merge2'); import type { Readable } from 'node:stream';