@autofleet/lint 1.0.1-beta-c262fdfd.4 → 1.0.1

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 (2) hide show
  1. package/bin/postinstall.cjs +57 -55
  2. package/package.json +1 -1
@@ -1,16 +1,17 @@
1
1
  #!/usr/bin/env node
2
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.
3
+ // Ensures native bindings for oxlint and oxfmt are installed where each tool can find them.
4
+ // Both tools use createRequire(import.meta.url) to load bindings, so the bindings
5
+ // must be resolvable from each tool's own package directory.
6
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.
7
+ // by directly extracting the binding tarball into each tool's node_modules.
8
8
 
9
9
  const { execFileSync } = require('node:child_process');
10
10
  const fs = require('node:fs');
11
+ const os = require('node:os');
11
12
  const path = require('node:path');
12
13
 
13
- const PLATFORM_TO_BINDING = {
14
+ const OXLINT_PLATFORM_TO_BINDING = {
14
15
  'darwin-arm64': '@oxlint/binding-darwin-arm64',
15
16
  'darwin-x64': '@oxlint/binding-darwin-x64',
16
17
  'linux-x64': '@oxlint/binding-linux-x64-gnu',
@@ -20,66 +21,67 @@ const PLATFORM_TO_BINDING = {
20
21
  'freebsd-x64': '@oxlint/binding-freebsd-x64',
21
22
  };
22
23
 
24
+ const OXFMT_PLATFORM_TO_BINDING = {
25
+ 'darwin-arm64': '@oxfmt/binding-darwin-arm64',
26
+ 'darwin-x64': '@oxfmt/binding-darwin-x64',
27
+ 'linux-x64': '@oxfmt/binding-linux-x64-gnu',
28
+ 'linux-arm64': '@oxfmt/binding-linux-arm64-gnu',
29
+ 'win32-x64': '@oxfmt/binding-win32-x64-msvc',
30
+ 'win32-arm64': '@oxfmt/binding-win32-arm64-msvc',
31
+ 'freebsd-x64': '@oxfmt/binding-freebsd-x64',
32
+ };
33
+
23
34
  const platform = `${process.platform}-${process.arch}`;
24
- const bindingPackage = PLATFORM_TO_BINDING[platform];
35
+ const lintDir = path.resolve(__dirname, '..');
25
36
 
26
- if (!bindingPackage) {
27
- console.warn(`@autofleet/lint postinstall: No known oxlint binding for platform ${platform}, skipping.`);
28
- process.exit(0);
29
- }
37
+ const installBinding = (toolName, moduleName, platformMap) => {
38
+ const bindingPackage = platformMap[platform];
39
+ if (!bindingPackage) {
40
+ console.warn(`@autofleet/lint postinstall: No known ${toolName} binding for platform ${platform}, skipping.`);
41
+ return;
42
+ }
30
43
 
31
- try {
32
- const lintDir = path.resolve(__dirname, '..');
44
+ try {
45
+ const modulePath = require.resolve(moduleName, { paths: [lintDir] });
46
+ const moduleDir = path.dirname(path.dirname(modulePath));
47
+ const bindingDestDir = path.join(moduleDir, 'node_modules', bindingPackage);
33
48
 
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));
49
+ if (fs.existsSync(bindingDestDir) && fs.readdirSync(bindingDestDir).some(f => f.endsWith('.node'))) {
50
+ return;
51
+ }
37
52
 
38
- // Where the binding needs to live for oxlint's createRequire to find it
39
- const bindingDestDir = path.join(oxlintDir, 'node_modules', bindingPackage);
53
+ const modulePkg = JSON.parse(fs.readFileSync(path.join(moduleDir, 'package.json'), 'utf8'));
54
+ const bindingVersion = modulePkg.optionalDependencies?.[bindingPackage];
40
55
 
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
- }
56
+ if (!bindingVersion) {
57
+ console.warn(`@autofleet/lint postinstall: Could not determine binding version from ${toolName} package.json.`);
58
+ return;
59
+ }
45
60
 
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];
61
+ console.log(`@autofleet/lint postinstall: Installing ${bindingPackage}@${bindingVersion} for ${toolName}...`);
49
62
 
50
- if (!bindingVersion) {
51
- console.warn(`@autofleet/lint postinstall: Could not determine binding version from oxlint package.json.`);
52
- process.exit(0);
53
- }
63
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), `${toolName}-binding-`));
64
+ try {
65
+ execFileSync('npm', ['pack', `${bindingPackage}@${bindingVersion}`, '--pack-destination', tmpDir], {
66
+ stdio: 'pipe',
67
+ });
54
68
 
55
- console.log(`@autofleet/lint postinstall: Installing ${bindingPackage}@${bindingVersion} for oxlint...`);
69
+ const tarballs = fs.readdirSync(tmpDir).filter(f => f.endsWith('.tgz'));
70
+ if (tarballs.length === 0) { throw new Error('npm pack produced no tarball'); }
56
71
 
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
- });
72
+ const tarball = path.join(tmpDir, tarballs[0]);
73
+ fs.mkdirSync(bindingDestDir, { recursive: true });
74
+ execFileSync('tar', ['-xzf', tarball, '-C', bindingDestDir, '--strip-components=1'], { stdio: 'pipe' });
64
75
 
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');
76
+ console.log(`@autofleet/lint postinstall: ${toolName} native binding installed successfully.`);
77
+ } finally {
78
+ fs.rmSync(tmpDir, { recursive: true, force: true });
68
79
  }
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 });
80
+ } catch (err) {
81
+ console.warn(`@autofleet/lint postinstall: Could not install ${toolName} native binding: ${err.message}`);
82
+ console.warn(`If ${toolName} fails, add "${moduleName}" to your devDependencies as a workaround.`);
81
83
  }
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
- }
84
+ };
85
+
86
+ installBinding('oxlint', 'oxlint', OXLINT_PLATFORM_TO_BINDING);
87
+ installBinding('oxfmt', 'oxfmt', OXFMT_PLATFORM_TO_BINDING);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/lint",
3
- "version": "1.0.1-beta-c262fdfd.4",
3
+ "version": "1.0.1",
4
4
  "description": "Shared Oxlint and Oxfmt configuration for Autofleet projects (Rust-powered, ultra-fast)",
5
5
  "main": "index.js",
6
6
  "bin": {