oxfmt 0.0.0

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.
Files changed (4) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +40 -0
  3. package/bin/oxfmt +149 -0
  4. package/package.json +29 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present VoidZero Inc. & Contributors
4
+ Copyright (c) 2023 Boshen
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ <p align="center">
2
+ <img alt="OXC Logo" src="https://raw.githubusercontent.com/oxc-project/oxc-assets/main/preview-universal.png" width="600">
3
+ </p>
4
+
5
+ <div align="center">
6
+
7
+ [![MIT licensed][license-badge]][license-url]
8
+ [![Build Status][ci-badge]][ci-url]
9
+ [![Code Coverage][code-coverage-badge]][code-coverage-url]
10
+ [![Sponsors][sponsors-badge]][sponsors-url]
11
+
12
+ [![Discord chat][discord-badge]][discord-url]
13
+ [![Playground][playground-badge]][playground-url]
14
+
15
+ [discord-badge]: https://img.shields.io/discord/1079625926024900739?logo=discord&label=Discord
16
+ [discord-url]: https://discord.gg/9uXCAwqQZW
17
+ [license-badge]: https://img.shields.io/badge/license-MIT-blue.svg
18
+ [license-url]: https://github.com/oxc-project/oxc/blob/main/LICENSE
19
+ [ci-badge]: https://github.com/oxc-project/oxc/actions/workflows/ci.yml/badge.svg?event=push&branch=main
20
+ [ci-url]: https://github.com/oxc-project/oxc/actions/workflows/ci.yml?query=event%3Apush+branch%3Amain
21
+ [npm-badge]: https://img.shields.io/npm/v/oxfmt/latest?color=brightgreen
22
+ [npm-url]: https://www.npmjs.com/package/oxfmt/v/latest
23
+ [code-size-badge]: https://img.shields.io/github/languages/code-size/oxc-project/oxc
24
+ [code-size-url]: https://github.com/oxc-project/oxc
25
+ [code-coverage-badge]: https://codecov.io/github/oxc-project/oxc/branch/main/graph/badge.svg
26
+ [code-coverage-url]: https://codecov.io/gh/oxc-project/oxc
27
+ [sponsors-badge]: https://img.shields.io/github/sponsors/Boshen
28
+ [sponsors-url]: https://github.com/sponsors/Boshen
29
+ [playground-badge]: https://img.shields.io/badge/Playground-blue?color=9BE4E0
30
+ [playground-url]: https://oxc-playground.netlify.app
31
+
32
+ </div>
33
+
34
+ # ⚓ Oxc
35
+
36
+ The Oxidation Compiler is creating a suite of high-performance tools for JavaScript and TypeScript.
37
+
38
+ ## Oxfmt
39
+
40
+ This is the formatter for oxc.
package/bin/oxfmt ADDED
@@ -0,0 +1,149 @@
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(_error) {
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 PLATFORMS = {
61
+ win32: {
62
+ x64: {
63
+ musl: "@oxfmt/win32-x64/oxfmt.exe",
64
+ gnu: "@oxfmt/win32-x64/oxfmt.exe",
65
+ },
66
+ arm64: {
67
+ musl: "@oxfmt/win32-arm64/oxfmt.exe",
68
+ gnu: "@oxfmt/win32-arm64/oxfmt.exe",
69
+ },
70
+ },
71
+ darwin: {
72
+ x64: {
73
+ musl: "@oxfmt/darwin-x64/oxfmt",
74
+ gnu: "@oxfmt/darwin-x64/oxfmt",
75
+ },
76
+ arm64: {
77
+ musl: "@oxfmt/darwin-arm64/oxfmt",
78
+ gnu: "@oxfmt/darwin-arm64/oxfmt",
79
+ },
80
+ },
81
+ linux: {
82
+ x64: {
83
+ musl: "@oxfmt/linux-x64-musl/oxfmt",
84
+ gnu: "@oxfmt/linux-x64-gnu/oxfmt",
85
+ },
86
+ arm64: {
87
+ musl: "@oxfmt/linux-arm64-musl/oxfmt",
88
+ gnu: "@oxfmt/linux-arm64-gnu/oxfmt",
89
+ },
90
+ },
91
+ };
92
+
93
+ let binPath = (
94
+ PLATFORMS &&
95
+ PLATFORMS[platform] &&
96
+ PLATFORMS[platform][arch] &&
97
+ PLATFORMS[platform][arch][isMusl() ? "musl" : "gnu"]
98
+ ) || null;
99
+
100
+ if (binPath) {
101
+ const result = require("child_process").spawnSync(
102
+ require.resolve(binPath),
103
+ process.argv.slice(2),
104
+ {
105
+ shell: false,
106
+ stdio: "inherit",
107
+ env: Object.assign({}, env, {
108
+ JS_RUNTIME_VERSION: version,
109
+ JS_RUNTIME_NAME: release.name,
110
+ NODE_PACKAGE_MANAGER: detectPackageManager(),
111
+ }),
112
+ }
113
+ );
114
+
115
+ if (result.error) {
116
+ throw result.error;
117
+ }
118
+
119
+ process.exitCode = result.status;
120
+ } else {
121
+ let target = `${platform}-${arch}`;
122
+ if (isMusl()) {
123
+ target = `${target}-musl`;
124
+ }
125
+ console.error(
126
+ `The oxfmt CLI package doesn't ship with prebuilt binaries for your platform (${target}) yet. ` +
127
+ "You can create an issue at https://github.com/oxc-project/oxc/issues for support."
128
+ );
129
+ process.exitCode = 1;
130
+ }
131
+
132
+ /**
133
+ * NPM, Yarn, and other package manager set the `npm_config_user_agent`. It has the following format:
134
+ *
135
+ * ```
136
+ * "npm/8.3.0 node/v16.13.2 win32 x64 workspaces/false
137
+ * ```
138
+ *
139
+ * @returns The package manager string (`npm/8.3.0`) or null if the user agent string isn't set.
140
+ */
141
+ function detectPackageManager() {
142
+ const userAgent = env.npm_config_user_agent;
143
+
144
+ if (userAgent == null) {
145
+ return null;
146
+ }
147
+
148
+ return userAgent.split(" ")[0];
149
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "oxfmt",
3
+ "version": "0.0.0",
4
+ "type": "commonjs",
5
+ "description": "Formatter for the JavaScript Oxidation Compiler",
6
+ "keywords": [],
7
+ "author": "Boshen and oxc contributors",
8
+ "license": "MIT",
9
+ "homepage": "https://oxc.rs",
10
+ "bugs": "https://github.com/oxc-project/oxc/issues",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/oxc-project/oxc",
14
+ "directory": "npm/oxfmt"
15
+ },
16
+ "bin": {
17
+ "oxfmt": "bin/oxfmt"
18
+ },
19
+ "funding": {
20
+ "url": "https://github.com/sponsors/Boshen"
21
+ },
22
+ "engines": {
23
+ "node": ">=8.*"
24
+ },
25
+ "files": [
26
+ "bin/oxfmt",
27
+ "README.md"
28
+ ]
29
+ }