Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

fix: TypeScript file detection #34

Draft
wants to merge 13 commits into
base: develop
Choose a base branch
from
Draft
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@ jobs:
if: ${{ matrix.os == 'ubuntu-latest' }}
run: pnpm type-check

- name: Build
run: pnpm build

- name: Test
run: pnpm test
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"build": "pkgroll --target node12.20 --minify",
"lint": "eslint .",
"type-check": "tsc --noEmit",
"test": "pnpm build && tsx tests/index.ts",
"test": "tsx tests/index.ts",
"prepack": "pnpm build && clean-pkg-json"
},
"dependencies": {
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import type { TransformOptions } from 'esbuild';

const isPathPattern = /^\.{0,2}\//;
const isTsFilePatten = /\.[cm]?tsx?$/;
const nodeModulesPath = `${path.sep}node_modules${path.sep}`;

const tsconfig = (
Expand Down Expand Up @@ -123,7 +122,7 @@

// Add support for "node:" protocol
const resolveFilename = Module._resolveFilename;
Module._resolveFilename = function (request, parent, isMain, options) {

Check warning on line 125 in src/index.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Unexpected unnamed function
// Added in v12.20.0
// https://nodejs.org/api/esm.html#esm_node_imports
if (!supportsNodePrefix && request.startsWith('node:')) {
Expand Down Expand Up @@ -185,7 +184,7 @@

if (
parent?.filename
&& isTsFilePatten.test(parent.filename)
&& fileMatcher?.(parent.filename)
&& tsPath
) {
try {
Expand Down
4 changes: 3 additions & 1 deletion tests/utils/node-with-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export async function createNode(
nodeVersion: string,
fixturePath: string,
) {
const node = await getNode(nodeVersion);
const node = await getNode(nodeVersion, {
arch: 'x64',
});

return {
version: node.version,
Expand Down
Loading