@autofleet/lint 1.0.1-beta-c262fdfd.2 → 1.0.1-beta-c262fdfd.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.
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Ensures oxlint's native binding is installed where oxlint can find it.
4
+ // oxlint uses createRequire(import.meta.url) to load its binding, so the binding
5
+ // must be resolvable from oxlint's own package directory.
6
+ // npm does not install optionalDependencies of transitive packages, so we handle it here
7
+ // by directly extracting the binding tarball into oxlint's node_modules.
8
+
9
+ const { execFileSync } = require('node:child_process');
10
+ const fs = require('node:fs');
11
+ const path = require('node:path');
12
+
13
+ const PLATFORM_TO_BINDING = {
14
+ 'darwin-arm64': '@oxlint/binding-darwin-arm64',
15
+ 'darwin-x64': '@oxlint/binding-darwin-x64',
16
+ 'linux-x64': '@oxlint/binding-linux-x64-gnu',
17
+ 'linux-arm64': '@oxlint/binding-linux-arm64-gnu',
18
+ 'win32-x64': '@oxlint/binding-win32-x64-msvc',
19
+ 'win32-arm64': '@oxlint/binding-win32-arm64-msvc',
20
+ 'freebsd-x64': '@oxlint/binding-freebsd-x64',
21
+ };
22
+
23
+ const platform = `${process.platform}-${process.arch}`;
24
+ const bindingPackage = PLATFORM_TO_BINDING[platform];
25
+
26
+ if (!bindingPackage) {
27
+ console.warn(`@autofleet/lint postinstall: No known oxlint binding for platform ${platform}, skipping.`);
28
+ process.exit(0);
29
+ }
30
+
31
+ try {
32
+ const lintDir = path.resolve(__dirname, '..');
33
+
34
+ // Resolve oxlint from @autofleet/lint's own dependencies
35
+ const oxlintModulePath = require.resolve('oxlint', { paths: [lintDir] });
36
+ const oxlintDir = path.dirname(path.dirname(oxlintModulePath));
37
+
38
+ // Where the binding needs to live for oxlint's createRequire to find it
39
+ const bindingDestDir = path.join(oxlintDir, 'node_modules', bindingPackage);
40
+
41
+ // Check if already installed with a .node file present
42
+ if (fs.existsSync(bindingDestDir) && fs.readdirSync(bindingDestDir).some(f => f.endsWith('.node'))) {
43
+ process.exit(0);
44
+ }
45
+
46
+ // Get the required version from oxlint's own package.json
47
+ const oxlintPkg = JSON.parse(fs.readFileSync(path.join(oxlintDir, 'package.json'), 'utf8'));
48
+ const bindingVersion = oxlintPkg.optionalDependencies?.[bindingPackage];
49
+
50
+ if (!bindingVersion) {
51
+ console.warn(`@autofleet/lint postinstall: Could not determine binding version from oxlint package.json.`);
52
+ process.exit(0);
53
+ }
54
+
55
+ console.log(`@autofleet/lint postinstall: Installing ${bindingPackage}@${bindingVersion} for oxlint...`);
56
+
57
+ // Use npm pack to download the tarball, then extract it directly into oxlint's node_modules
58
+ // This bypasses npm's hoisting behavior
59
+ const tmpDir = fs.mkdtempSync(path.join(require('node:os').tmpdir(), 'oxlint-binding-'));
60
+ try {
61
+ execFileSync('npm', ['pack', `${bindingPackage}@${bindingVersion}`, '--pack-destination', tmpDir], {
62
+ stdio: 'pipe',
63
+ });
64
+
65
+ const tarballs = fs.readdirSync(tmpDir).filter(f => f.endsWith('.tgz'));
66
+ if (tarballs.length === 0) {
67
+ throw new Error('npm pack produced no tarball');
68
+ }
69
+
70
+ const tarball = path.join(tmpDir, tarballs[0]);
71
+ fs.mkdirSync(bindingDestDir, { recursive: true });
72
+
73
+ // Extract tarball — npm packs into a "package/" subdirectory inside the tgz
74
+ execFileSync('tar', ['-xzf', tarball, '-C', bindingDestDir, '--strip-components=1'], {
75
+ stdio: 'pipe',
76
+ });
77
+
78
+ console.log(`@autofleet/lint postinstall: Native binding installed successfully.`);
79
+ } finally {
80
+ fs.rmSync(tmpDir, { recursive: true, force: true });
81
+ }
82
+ } catch (err) {
83
+ console.warn(`@autofleet/lint postinstall: Could not install native binding: ${err.message}`);
84
+ console.warn(`If oxlint fails, add "oxlint": "^1.56.0" to your devDependencies as a workaround.`);
85
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/lint",
3
- "version": "1.0.1-beta-c262fdfd.2",
3
+ "version": "1.0.1-beta-c262fdfd.3",
4
4
  "description": "Shared Oxlint and Oxfmt configuration for Autofleet projects (Rust-powered, ultra-fast)",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -26,9 +26,6 @@
26
26
  "oxfmt": "^0.41.0",
27
27
  "oxlint": "^1.56.0"
28
28
  },
29
- "optionalDependencies": {
30
- "@oxlint/binding-darwin-arm64": "1.56.0"
31
- },
32
29
  "keywords": [
33
30
  "oxlint",
34
31
  "oxfmt",
@@ -41,6 +38,7 @@
41
38
  "fast"
42
39
  ],
43
40
  "scripts": {
44
- "build": "echo 'No build needed - config files only'"
41
+ "build": "echo 'No build needed - config files only'",
42
+ "postinstall": "node ./bin/postinstall.cjs"
45
43
  }
46
44
  }