Skip to content

Commit 3c17b86

Browse files
authored
Use synckit (#134)
* Use synckit * test for other os * fix for win
1 parent 3f0575a commit 3c17b86

File tree

6 files changed

+32
-57
lines changed

6 files changed

+32
-57
lines changed

.github/workflows/NodeCI.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,20 @@ jobs:
1919
- name: Lint
2020
run: npm run lint
2121
test:
22-
runs-on: ubuntu-latest
2322
strategy:
2423
matrix:
25-
node-version: [12.x, 14.x, 16.x, 17.x]
24+
node-version: [12.x, 14.x, 16.x, 17.x, 18.x]
25+
os: [ubuntu-latest]
26+
include:
27+
- node: 18.x
28+
os: windows-latest
29+
- node: 18.x
30+
os: macos-latest
31+
- node: 12.x
32+
os: windows-latest
33+
- node: 12.x
34+
os: macos-latest
35+
runs-on: ${{ matrix.os }}
2636
steps:
2737
- uses: actions/checkout@v3
2838
- name: Use Node.js ${{ matrix.node-version }}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"json-schema-migrate": "^2.0.0",
6363
"jsonc-eslint-parser": "^2.0.0",
6464
"minimatch": "^5.0.0",
65+
"synckit": "^0.7.1",
6566
"toml-eslint-parser": "^0.4.0",
6667
"tunnel-agent": "^0.6.0",
6768
"yaml-eslint-parser": "^0.5.0"

src/utils/http-client/cli.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/utils/http-client/sync-http.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { RequestOptions } from "https"
2-
import { spawnSync } from "child_process"
3-
import path from "path"
2+
import { createSyncFn } from "synckit"
3+
4+
const getSync = createSyncFn(require.resolve("./worker"))
45

56
/**
67
* Synchronously GET Method
@@ -10,30 +11,5 @@ export function syncGet(
1011
options?: RequestOptions,
1112
httpModulePath?: string,
1213
): string {
13-
const httpScriptPath = require.resolve("./cli")
14-
const execPath = process.execPath
15-
const optionsJSON = JSON.stringify(options ?? {})
16-
const cliArgs = [
17-
httpScriptPath,
18-
url,
19-
optionsJSON,
20-
JSON.stringify({ httpModulePath }),
21-
]
22-
if (path.extname(httpScriptPath) === ".ts") {
23-
cliArgs.unshift("--require", "ts-node/register/transpile-only")
24-
}
25-
const result = spawnSync(execPath, cliArgs, {
26-
windowsHide: true,
27-
maxBuffer: Infinity,
28-
})
29-
30-
if (result.error) {
31-
throw result.error
32-
}
33-
if (result.status !== 0) {
34-
throw new Error(
35-
`Failed:\n${result.stdout.toString()}\n${result.stderr.toString()}`,
36-
)
37-
}
38-
return result.stdout.toString("utf8")
14+
return getSync(url, options, httpModulePath)
3915
}

src/utils/http-client/worker.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { RequestOptions } from "https"
2+
import { runAsWorker } from "synckit"
3+
import { get } from "./http"
4+
5+
runAsWorker(
6+
async (url: string, options?: RequestOptions, httpModulePath?: string) => {
7+
return get(url, options, httpModulePath)
8+
},
9+
)

tests/src/utils/ast/js.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ const FIXTURES_ROOT = path.join(__dirname, "../../../fixtures/utils/ast/js")
1212
describe("AST for JS.", () => {
1313
for (const filename of listupInput(FIXTURES_ROOT)) {
1414
it(filename.slice(FIXTURES_ROOT.length), () => {
15-
const input = fs.readFileSync(filename, "utf8")
15+
const input = fs
16+
.readFileSync(filename, "utf8")
17+
.replace(/\r\n/gu, "\n")
1618
const outputFile = filename.replace(/input.js$/, "output.json")
1719

1820
const linter = new Linter()
@@ -53,7 +55,9 @@ describe("AST for JS.", () => {
5355
)
5456
}
5557

56-
const output = JSON.parse(fs.readFileSync(outputFile, "utf8"))
58+
const output = JSON.parse(
59+
fs.readFileSync(outputFile, "utf8").replace(/\r\n/gu, "\n"),
60+
)
5761

5862
assert.deepStrictEqual(result, output)
5963
})

0 commit comments

Comments
 (0)