From 4152c3439246b2ca85016562a9aa1075c2f5c616 Mon Sep 17 00:00:00 2001 From: starnayuta <58112571+starnayuta@users.noreply.github.com> Date: Sat, 3 Feb 2024 18:39:58 +0900 Subject: [PATCH] fix: not working on Windows 10 (#21) * BREAKING CHANGE: Changed from running eslint via node to npm. * test: add os matrix * Revert "BREAKING CHANGE: Changed from running eslint via node to npm." This reverts commit 8718c8baa6c493eccd4476caa975314deb5325f0. * fix: not working on Windows 10 * test: change ' to " * test: fix for macOS/linux * revert style --- .github/workflows/test.yml | 7 ++++--- eslint-cjs-to-esm.js | 10 +++++++--- package.json | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3a39e0f..b6f5891 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,11 +4,12 @@ permissions: contents: read jobs: test: - name: "Test on Node.js ${{ matrix.node-version }}" - runs-on: ubuntu-latest + name: Test(Node ${{ matrix.node }} on ${{ matrix.os }}) + runs-on: ${{ matrix.os }} strategy: matrix: - node-version: [ 18,20 ] + os: [ubuntu-latest, windows-latest] + node: [ 18, 20 ] steps: - name: checkout uses: actions/checkout@v4 diff --git a/eslint-cjs-to-esm.js b/eslint-cjs-to-esm.js index 730f909..46b9123 100644 --- a/eslint-cjs-to-esm.js +++ b/eslint-cjs-to-esm.js @@ -3,7 +3,9 @@ import { execa } from "execa"; import { createRequire } from "node:module"; const require = createRequire(import.meta.url); -const eslintBin = require.resolve(".bin/eslint"); +const isWindows = /^win/.test(process.platform); +const eslintBinBasePath = ".bin/eslint"; +const eslintBin = require.resolve(isWindows ? `${eslintBinBasePath}.cmd` : eslintBinBasePath); import url from "node:url"; import path from "node:path"; @@ -23,8 +25,10 @@ try { if (process.env.DEBUG === "eslint-cjs-to-esm") { console.debug({ args, eslintBin, builtinConfig }); } - const { stdout, stderr } = await execa("node", [ - eslintBin, + const command = isWindows ? eslintBin : "node"; + const platformArguments = isWindows ? [] : [eslintBin]; + const { stdout, stderr } = await execa(command, [ + ...platformArguments, "--config", builtinConfig, ...args], { diff --git a/package.json b/package.json index 18aa6bf..bf7eac0 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ ".eslintrc.cjs" ], "scripts": { - "test": "expected-exit-status 1 --stdout '/\\d+ problems/' --command 'node eslint-cjs-to-esm.js \"./test-fixtures/*\"'" + "test": "expected-exit-status 1 --stdout \"/\\d+ problems/\" --command \"node eslint-cjs-to-esm.js \"\"./test-fixtures/*.ts\"\"\"" }, "devDependencies": { "expected-exit-status": "^3.1.0"