memtrace 0.3.55 → 0.3.56
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/install.js +40 -6
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -33,6 +33,11 @@ function getBinaryPath() {
|
|
|
33
33
|
}
|
|
34
34
|
const ext = os.platform() === "win32" ? ".exe" : "";
|
|
35
35
|
const binaryName = `memtrace${ext}`;
|
|
36
|
+
try {
|
|
37
|
+
return require.resolve(`${pkg}/bin/${binaryName}`);
|
|
38
|
+
} catch {
|
|
39
|
+
selfHealPlatformPackage();
|
|
40
|
+
}
|
|
36
41
|
try {
|
|
37
42
|
return require.resolve(`${pkg}/bin/${binaryName}`);
|
|
38
43
|
} catch {
|
|
@@ -43,6 +48,27 @@ function getBinaryPath() {
|
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
|
|
51
|
+
function buildSelfHealInstallArgs(packageDir, versioned) {
|
|
52
|
+
return ["install", "--prefix", packageDir, "--no-save", "--include=optional", versioned];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function buildSelfHealEnv(env) {
|
|
56
|
+
const next = { ...env };
|
|
57
|
+
|
|
58
|
+
// During `npm install -g memtrace`, npm exposes global-mode config through
|
|
59
|
+
// the environment. A nested `npm install` can inherit that and install the
|
|
60
|
+
// platform package into the global prefix instead of this package directory.
|
|
61
|
+
delete next.npm_config_global;
|
|
62
|
+
delete next.NPM_CONFIG_GLOBAL;
|
|
63
|
+
next.npm_config_global = "false";
|
|
64
|
+
|
|
65
|
+
return next;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getPinnedPlatformVersion(packageJson, platformPackage) {
|
|
69
|
+
return packageJson.optionalDependencies?.[platformPackage] ?? packageJson.version;
|
|
70
|
+
}
|
|
71
|
+
|
|
46
72
|
// ── Optional-dep self-heal ───────────────────────────────────────────────────
|
|
47
73
|
//
|
|
48
74
|
// `optionalDependencies` is supposed to fan out platform binaries
|
|
@@ -57,15 +83,15 @@ function getBinaryPath() {
|
|
|
57
83
|
function selfHealPlatformPackage() {
|
|
58
84
|
const key = getPlatformKey();
|
|
59
85
|
const pkg = PLATFORM_MAP[key];
|
|
60
|
-
if (!pkg) return; // unsupported platform — getBinaryPath will surface it later
|
|
86
|
+
if (!pkg) return false; // unsupported platform — getBinaryPath will surface it later
|
|
61
87
|
try {
|
|
62
88
|
require.resolve(`${pkg}/package.json`);
|
|
63
|
-
return; // already installed via optionalDependencies
|
|
89
|
+
return true; // already installed via optionalDependencies
|
|
64
90
|
} catch (_) {
|
|
65
91
|
// not installed — fall through to install
|
|
66
92
|
}
|
|
67
93
|
const ourPkg = require("./package.json");
|
|
68
|
-
const versioned = `${pkg}@${ourPkg
|
|
94
|
+
const versioned = `${pkg}@${getPinnedPlatformVersion(ourPkg, pkg)}`;
|
|
69
95
|
console.log(
|
|
70
96
|
`memtrace: optional platform dep ${pkg} was not installed; ` +
|
|
71
97
|
`running 'npm install ${versioned}' to fetch it…`
|
|
@@ -78,11 +104,11 @@ function selfHealPlatformPackage() {
|
|
|
78
104
|
// `test/spawn-helper.test.js` for the full regression coverage.
|
|
79
105
|
const result = spawnSync(
|
|
80
106
|
platformBinary("npm", process.platform),
|
|
81
|
-
|
|
107
|
+
buildSelfHealInstallArgs(__dirname, versioned),
|
|
82
108
|
spawnOptionsForPlatform(process.platform, {
|
|
83
109
|
cwd: __dirname,
|
|
84
110
|
stdio: "inherit",
|
|
85
|
-
env: process.env,
|
|
111
|
+
env: buildSelfHealEnv(process.env),
|
|
86
112
|
})
|
|
87
113
|
);
|
|
88
114
|
if (result.status !== 0) {
|
|
@@ -90,7 +116,9 @@ function selfHealPlatformPackage() {
|
|
|
90
116
|
`memtrace: self-heal install of ${versioned} failed (exit ${result.status}). ` +
|
|
91
117
|
`Run manually: npm install -g memtrace --include=optional`
|
|
92
118
|
);
|
|
119
|
+
return false;
|
|
93
120
|
}
|
|
121
|
+
return true;
|
|
94
122
|
}
|
|
95
123
|
|
|
96
124
|
// ── Main postinstall ─────────────────────────────────────────────────────────
|
|
@@ -176,4 +204,10 @@ if (require.main === module) {
|
|
|
176
204
|
}
|
|
177
205
|
}
|
|
178
206
|
|
|
179
|
-
module.exports = {
|
|
207
|
+
module.exports = {
|
|
208
|
+
getBinaryPath,
|
|
209
|
+
selfHealPlatformPackage,
|
|
210
|
+
buildSelfHealEnv,
|
|
211
|
+
buildSelfHealInstallArgs,
|
|
212
|
+
getPinnedPlatformVersion,
|
|
213
|
+
};
|