eslint-plugin-better-stylelint 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +33 -3
- package/dist/worker.js +2 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
1
2
|
import { execFileSync } from "node:child_process";
|
|
2
3
|
import { createHash } from "node:crypto";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import os from "node:os";
|
|
3
6
|
import path from "node:path";
|
|
4
7
|
import process from "node:process";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
9
|
//#region src/core.ts
|
|
7
10
|
const MAX_CACHE_ENTRIES = 100;
|
|
8
11
|
const CORE_TS_PATTERN = /core\.ts$/u;
|
|
9
12
|
const CORE_JS_PATTERN = /core\.js$/u;
|
|
13
|
+
const WORKER_BOOTSTRAP_PREFIX = "icebreaker-stylelint-worker-";
|
|
10
14
|
const resultCache = /* @__PURE__ */ new Map();
|
|
11
15
|
const configCacheIds = /* @__PURE__ */ new WeakMap();
|
|
12
16
|
let nextConfigCacheId = 0;
|
|
17
|
+
const require = createRequire(import.meta.url);
|
|
13
18
|
const UNSUPPORTED_EXEC_ARGV_FLAGS = new Set([
|
|
14
19
|
"--eval",
|
|
15
20
|
"-e",
|
|
@@ -101,16 +106,41 @@ function getWorkerExecArgv() {
|
|
|
101
106
|
}
|
|
102
107
|
return workerExecArgv;
|
|
103
108
|
}
|
|
109
|
+
function resolveWorkerCommand(workerPath) {
|
|
110
|
+
if (workerPath.endsWith(".ts")) {
|
|
111
|
+
const workerEntry = pathToFileURL(workerPath).href;
|
|
112
|
+
const tsxLoaderEntry = pathToFileURL(require.resolve("tsx/esm")).href;
|
|
113
|
+
const bootstrapPath = path.join(os.tmpdir(), `${WORKER_BOOTSTRAP_PREFIX}${createHash("sha1").update(workerEntry).digest("hex")}.mjs`);
|
|
114
|
+
if (!fs.existsSync(bootstrapPath)) fs.writeFileSync(bootstrapPath, `import ${JSON.stringify(workerEntry)}\n`, "utf8");
|
|
115
|
+
return {
|
|
116
|
+
command: process.execPath,
|
|
117
|
+
args: [
|
|
118
|
+
...getWorkerExecArgv(),
|
|
119
|
+
"--import",
|
|
120
|
+
tsxLoaderEntry,
|
|
121
|
+
bootstrapPath
|
|
122
|
+
]
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
command: process.execPath,
|
|
127
|
+
args: [...getWorkerExecArgv(), workerPath]
|
|
128
|
+
};
|
|
129
|
+
}
|
|
104
130
|
function getRunStylelintWorker() {
|
|
105
131
|
return (code, filename, options) => {
|
|
106
|
-
const
|
|
107
|
-
const output = execFileSync(
|
|
132
|
+
const worker = resolveWorkerCommand(resolveWorkerPath());
|
|
133
|
+
const output = execFileSync(worker.command, worker.args, {
|
|
108
134
|
input: JSON.stringify({
|
|
109
135
|
code,
|
|
110
136
|
filename,
|
|
111
137
|
options
|
|
112
138
|
}),
|
|
113
139
|
encoding: "utf8",
|
|
140
|
+
env: {
|
|
141
|
+
...process.env,
|
|
142
|
+
ICEBREAKER_STYLELINT_WORKER: "1"
|
|
143
|
+
},
|
|
114
144
|
stdio: [
|
|
115
145
|
"pipe",
|
|
116
146
|
"pipe",
|
package/dist/worker.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
+
import fs from "node:fs";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import process from "node:process";
|
|
4
5
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
|
-
import fs from "node:fs";
|
|
6
6
|
//#region src/worker.ts
|
|
7
7
|
function normalizeWarning(warning) {
|
|
8
8
|
return {
|
|
@@ -71,7 +71,7 @@ async function main() {
|
|
|
71
71
|
const response = await runStylelint(request.code, request.filename, request.options);
|
|
72
72
|
process.stdout.write(JSON.stringify(response));
|
|
73
73
|
}
|
|
74
|
-
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) main().catch((error) => {
|
|
74
|
+
if (process.env["ICEBREAKER_STYLELINT_WORKER"] === "1" || process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) main().catch((error) => {
|
|
75
75
|
const message = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
76
76
|
process.stderr.write(`${message}\n`);
|
|
77
77
|
process.exitCode = 1;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-better-stylelint",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.3",
|
|
5
5
|
"description": "Bridge Stylelint diagnostics into ESLint for style files and Vue SFCs",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"stylelint": "^17.
|
|
47
|
+
"stylelint": "^17.6.0"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public",
|