@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.
- package/bin/postinstall.cjs +57 -55
- package/package.json +1 -1
package/bin/postinstall.cjs
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
// Ensures oxlint
|
|
4
|
-
//
|
|
5
|
-
// must be resolvable from
|
|
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
|
|
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
|
|
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
|
|
35
|
+
const lintDir = path.resolve(__dirname, '..');
|
|
25
36
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
49
|
+
if (fs.existsSync(bindingDestDir) && fs.readdirSync(bindingDestDir).some(f => f.endsWith('.node'))) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
37
52
|
|
|
38
|
-
|
|
39
|
-
|
|
53
|
+
const modulePkg = JSON.parse(fs.readFileSync(path.join(moduleDir, 'package.json'), 'utf8'));
|
|
54
|
+
const bindingVersion = modulePkg.optionalDependencies?.[bindingPackage];
|
|
40
55
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
71
|
-
|
|
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
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
installBinding('oxlint', 'oxlint', OXLINT_PLATFORM_TO_BINDING);
|
|
87
|
+
installBinding('oxfmt', 'oxfmt', OXFMT_PLATFORM_TO_BINDING);
|