oxlint 0.4.0 → 0.4.2

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.
@@ -0,0 +1,147 @@
1
+ #!/usr/bin/env node
2
+
3
+ const isMusl = () => {
4
+ let musl = false;
5
+ if (process.platform === "linux") {
6
+ musl = isMuslFromFilesystem();
7
+ if (musl === null) {
8
+ musl = isMuslFromReport();
9
+ }
10
+ if (musl === null) {
11
+ musl = isMuslFromChildProcess();
12
+ }
13
+ }
14
+ return musl;
15
+ };
16
+
17
+ const isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
18
+
19
+ const isMuslFromFilesystem = () => {
20
+ const { readFileSync } = require("fs");
21
+ try {
22
+ return readFileSync("/usr/bin/ldd", "utf-8").includes("musl");
23
+ } catch {
24
+ return null;
25
+ }
26
+ };
27
+
28
+ const isMuslFromReport = () => {
29
+ const report =
30
+ typeof process.report.getReport === "function"
31
+ ? process.report.getReport()
32
+ : null;
33
+ if (!report) {
34
+ return null;
35
+ }
36
+ if (report.header && report.header.glibcVersionRuntime) {
37
+ return false;
38
+ }
39
+ if (Array.isArray(report.sharedObjects)) {
40
+ if (report.sharedObjects.some(isFileMusl)) {
41
+ return true;
42
+ }
43
+ }
44
+ return false;
45
+ };
46
+
47
+ const isMuslFromChildProcess = () => {
48
+ try {
49
+ return require("child_process")
50
+ .execSync("ldd --version", { encoding: "utf8" })
51
+ .includes("musl");
52
+ } catch (e) {
53
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
54
+ return false;
55
+ }
56
+ };
57
+
58
+ const { platform, arch, env, version, release } = process;
59
+
60
+ const BIN_NAME = "oxc_language_server";
61
+
62
+ const PLATFORMS = {
63
+ win32: {
64
+ x64: {
65
+ musl: `@oxlint/win32-x64/${BIN_NAME}.exe`,
66
+ gnu: `@oxlint/win32-x64/${BIN_NAME}.exe`,
67
+ },
68
+ arm64: {
69
+ musl: `@oxlint/win32-arm64/${BIN_NAME}.exe`,
70
+ gnu: `@oxlint/win32-arm64/${BIN_NAME}.exe`,
71
+ },
72
+ },
73
+ darwin: {
74
+ x64: {
75
+ musl: `@oxlint/darwin-x64/${BIN_NAME}`,
76
+ gnu: `@oxlint/darwin-x64/${BIN_NAME}`,
77
+ },
78
+ arm64: {
79
+ musl: `@oxlint/darwin-arm64/${BIN_NAME}`,
80
+ gnu: `@oxlint/darwin-arm64/${BIN_NAME}`,
81
+ },
82
+ },
83
+ linux: {
84
+ x64: {
85
+ musl: `@oxlint/linux-x64-musl/${BIN_NAME}`,
86
+ gnu: `@oxlint/linux-x64-gnu/${BIN_NAME}`,
87
+ },
88
+ arm64: {
89
+ musl: `@oxlint/linux-arm64-musl/${BIN_NAME}`,
90
+ gnu: `@oxlint/linux-arm64-gnu/${BIN_NAME}`,
91
+ },
92
+ },
93
+ };
94
+
95
+ let binPath = PLATFORMS[platform]?.[arch]?.[isMusl() ? "musl" : "gnu"];
96
+
97
+ if (binPath) {
98
+ const result = require("child_process").spawnSync(
99
+ require.resolve(binPath),
100
+ process.argv.slice(2),
101
+ {
102
+ shell: false,
103
+ stdio: "inherit",
104
+ env: {
105
+ ...env,
106
+ JS_RUNTIME_VERSION: version,
107
+ JS_RUNTIME_NAME: release.name,
108
+ NODE_PACKAGE_MANAGER: detectPackageManager(),
109
+ },
110
+ }
111
+ );
112
+
113
+ if (result.error) {
114
+ throw result.error;
115
+ }
116
+
117
+ process.exitCode = result.status;
118
+ } else {
119
+ let target = `${platform}-${arch}`;
120
+ if (isMusl()) {
121
+ target = `${target}-musl`;
122
+ }
123
+ console.error(
124
+ `The oxc_language_server CLI package doesn't ship with prebuilt binaries for your platform (${target}) yet. ` +
125
+ "You can create an issue at https://github.com/oxc-project/oxc/issues for support."
126
+ );
127
+ process.exitCode = 1;
128
+ }
129
+
130
+ /**
131
+ * NPM, Yarn, and other package manager set the `npm_config_user_agent`. It has the following format:
132
+ *
133
+ * ```
134
+ * "npm/8.3.0 node/v16.13.2 win32 x64 workspaces/false
135
+ * ```
136
+ *
137
+ * @returns The package manager string (`npm/8.3.0`) or null if the user agent string isn't set.
138
+ */
139
+ function detectPackageManager() {
140
+ const userAgent = env.npm_config_user_agent;
141
+
142
+ if (userAgent == null) {
143
+ return null;
144
+ }
145
+
146
+ return userAgent.split(" ")[0];
147
+ }
package/bin/oxlint CHANGED
@@ -57,57 +57,40 @@ const isMuslFromChildProcess = () => {
57
57
 
58
58
  const { platform, arch, env, version, release } = process;
59
59
 
60
- let binPath;
60
+ const PLATFORMS = {
61
+ win32: {
62
+ x64: {
63
+ musl: "@oxlint/win32-x64/oxlint.exe",
64
+ gnu: "@oxlint/win32-x64/oxlint.exe",
65
+ },
66
+ arm64: {
67
+ musl: "@oxlint/win32-arm64/oxlint.exe",
68
+ gnu: "@oxlint/win32-arm64/oxlint.exe",
69
+ },
70
+ },
71
+ darwin: {
72
+ x64: {
73
+ musl: "@oxlint/darwin-x64/oxlint",
74
+ gnu: "@oxlint/darwin-x64/oxlint",
75
+ },
76
+ arm64: {
77
+ musl: "@oxlint/darwin-arm64/oxlint",
78
+ gnu: "@oxlint/darwin-arm64/oxlint",
79
+ },
80
+ },
81
+ linux: {
82
+ x64: {
83
+ musl: "@oxlint/linux-x64-musl/oxlint",
84
+ gnu: "@oxlint/linux-x64-gnu/oxlint",
85
+ },
86
+ arm64: {
87
+ musl: "@oxlint/linux-arm64-musl/oxlint",
88
+ gnu: "@oxlint/linux-arm64-gnu/oxlint",
89
+ },
90
+ },
91
+ };
61
92
 
62
- switch (platform) {
63
- case "win32": {
64
- switch (arch) {
65
- case "x64": {
66
- binPath = "@oxlint/win32-x64/oxlint.exe";
67
- break;
68
- }
69
- case "arm64": {
70
- binPath = "@oxlint/win32-arm64/oxlint.exe";
71
- break;
72
- }
73
- }
74
- break;
75
- }
76
- case "darwin": {
77
- switch (arch) {
78
- case "x64": {
79
- binPath = "@oxlint/darwin-x64/oxlint";
80
- break;
81
- }
82
- case "arm64": {
83
- binPath = "@oxlint/darwin-arm64/oxlint";
84
- break;
85
- }
86
- }
87
- break;
88
- }
89
- case "linux": {
90
- switch (arch) {
91
- case "x64": {
92
- if (isMusl()) {
93
- binPath = "@oxlint/linux-x64-musl/oxlint";
94
- } else {
95
- binPath = "@oxlint/linux-x64-gnu/oxlint";
96
- }
97
- break;
98
- }
99
- case "arm64": {
100
- if (isMusl()) {
101
- binPath = "@oxlint/linux-arm64-musl/oxlint";
102
- } else {
103
- binPath = "@oxlint/linux-arm64-gnu/oxlint";
104
- }
105
- break;
106
- }
107
- }
108
- break;
109
- }
110
- }
93
+ let binPath = PLATFORMS[platform]?.[arch]?.[isMusl() ? "musl" : "gnu"];
111
94
 
112
95
  if (binPath) {
113
96
  const result = require("child_process").spawnSync(
@@ -122,7 +105,7 @@ if (binPath) {
122
105
  JS_RUNTIME_NAME: release.name,
123
106
  NODE_PACKAGE_MANAGER: detectPackageManager(),
124
107
  },
125
- },
108
+ }
126
109
  );
127
110
 
128
111
  if (result.error) {
@@ -137,7 +120,7 @@ if (binPath) {
137
120
  }
138
121
  console.error(
139
122
  `The oxlint CLI package doesn't ship with prebuilt binaries for your platform (${target}) yet. ` +
140
- "You can create an issue at https://github.com/oxc-project/oxc/issues for support.",
123
+ "You can create an issue at https://github.com/oxc-project/oxc/issues for support."
141
124
  );
142
125
  process.exitCode = 1;
143
126
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema#",
3
3
  "title": "OxlintConfig",
4
- "description": "Oxlint Configuration File\n\nThis configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).\n\nUsage: `oxlint -c oxlintrc.json`\n\n::: danger NOTE\n\nOnly the `.json` format is supported.\n\n:::\n\nExample\n\n```json\n // oxlintrc.json\n {\n // Comments are supported.\n \"env\": {\n \"browser\": true\n },\n \"globals\": {\n \"foo\": \"readonly\",\n },\n \"settings\": {\n },\n \"rules\": {\n \"eqeqeq\": \"warn\",\n },\n }\n```",
4
+ "description": "Oxlint Configuration File\n\nThis configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).\n\nUsage: `oxlint -c oxlintrc.json`\n\n::: danger NOTE\n\nOnly the `.json` format is supported.\n\n:::\n\nExample\n\n`.oxlintrc.json`\n\n```json { \"env\": { \"browser\": true }, \"globals\": { \"foo\": \"readonly\" }, \"settings\": { }, \"rules\": { \"eqeqeq\": \"warn\" } } ```",
5
5
  "type": "object",
6
6
  "properties": {
7
7
  "env": {
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"oxlint","version":"0.4.0","description":"Linter for the JavaScript Oxidation Compiler","keywords":[],"author":"Boshen and oxc contributors","license":"MIT","homepage":"https://oxc-project.github.io","bugs":"https://github.com/oxc-project/oxc/issues","repository":{"type":"git","url":"https://github.com/oxc-project/oxc","directory":"npm/oxlint"},"bin":"bin/oxlint","funding":{"url":"https://github.com/sponsors/Boshen"},"engines":{"node":">=14.*"},"files":["bin/oxlint","configuration_schema.json","README.md"],"optionalDependencies":{"@oxlint/win32-x64":"0.4.0","@oxlint/win32-arm64":"0.4.0","@oxlint/linux-x64-gnu":"0.4.0","@oxlint/linux-arm64-gnu":"0.4.0","@oxlint/linux-x64-musl":"0.4.0","@oxlint/linux-arm64-musl":"0.4.0","@oxlint/darwin-x64":"0.4.0","@oxlint/darwin-arm64":"0.4.0"}}
1
+ {"name":"oxlint","version":"0.4.2","description":"Linter for the JavaScript Oxidation Compiler","keywords":[],"author":"Boshen and oxc contributors","license":"MIT","homepage":"https://oxc-project.github.io","bugs":"https://github.com/oxc-project/oxc/issues","repository":{"type":"git","url":"https://github.com/oxc-project/oxc","directory":"npm/oxlint"},"bin":"bin/oxlint","funding":{"url":"https://github.com/sponsors/Boshen"},"engines":{"node":">=14.*"},"files":["bin/oxlint","bin/oxc_language_server","configuration_schema.json","README.md"],"optionalDependencies":{"@oxlint/win32-x64":"0.4.2","@oxlint/win32-arm64":"0.4.2","@oxlint/linux-x64-gnu":"0.4.2","@oxlint/linux-arm64-gnu":"0.4.2","@oxlint/linux-x64-musl":"0.4.2","@oxlint/linux-arm64-musl":"0.4.2","@oxlint/darwin-x64":"0.4.2","@oxlint/darwin-arm64":"0.4.2"}}