@willbooster/wb 13.27.0 → 13.28.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/dotenv.js +39 -0
- package/dist/index.js +31 -32
- package/package.json +2 -1
package/bin/dotenv.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import childProcess from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
|
|
4
5
|
import { config } from 'dotenv';
|
|
@@ -15,7 +16,22 @@ export function runDotenvCommand(args) {
|
|
|
15
16
|
|
|
16
17
|
const cwd = path.resolve(process.cwd());
|
|
17
18
|
readAndApplyEnvironmentVariables(cwd);
|
|
19
|
+
const berryBinFolderPath = process.env.BERRY_BIN_FOLDER;
|
|
18
20
|
removeNpmAndYarnEnvironmentVariables(process.env);
|
|
21
|
+
// Stripping yarn's environment also removes its temporary bin folder — the ONLY place
|
|
22
|
+
// yarn Berry exposes dependency executables — so restore the project's own
|
|
23
|
+
// node_modules/.bin directories (nearest first) to keep bare binary names resolvable.
|
|
24
|
+
// Plug'n'Play installs create no node_modules at all; the temporary bin folder is then the
|
|
25
|
+
// sole source of dependency executables, so restore it instead. Mirrors
|
|
26
|
+
// src/commands/dotenv.ts + src/utils/binPath.ts for this startup fast path.
|
|
27
|
+
// The temporary folder is deliberately NOT restored when .bin directories exist: it also
|
|
28
|
+
// contains node/yarn shims, and a leaked node shim would violate wb's real-Node guarantee
|
|
29
|
+
// for tools like wrangler/vinext. Child `yarn` invocations stay resolvable through the
|
|
30
|
+
// launcher on the base PATH (mise/corepack), which every supported environment has —
|
|
31
|
+
// nothing could have started `yarn run`/`wb dotenv` without it.
|
|
32
|
+
if (!prependNodeModulesBinToPath(cwd, process.env) && berryBinFolderPath) {
|
|
33
|
+
process.env.PATH = process.env.PATH ? `${berryBinFolderPath}:${process.env.PATH}` : berryBinFolderPath;
|
|
34
|
+
}
|
|
19
35
|
|
|
20
36
|
const child = childProcess.spawn(command[0], command.slice(1), {
|
|
21
37
|
cwd,
|
|
@@ -89,6 +105,29 @@ function removeNpmAndYarnEnvironmentVariables(envVars) {
|
|
|
89
105
|
}
|
|
90
106
|
}
|
|
91
107
|
|
|
108
|
+
function prependNodeModulesBinToPath(dirPath, env) {
|
|
109
|
+
const binPaths = [];
|
|
110
|
+
let currentPath = path.resolve(dirPath);
|
|
111
|
+
for (;;) {
|
|
112
|
+
const binPath = path.join(currentPath, 'node_modules', '.bin');
|
|
113
|
+
if (fs.existsSync(binPath)) {
|
|
114
|
+
binPaths.push(binPath);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (fs.existsSync(path.join(currentPath, '.git'))) {
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
const parentPath = path.dirname(currentPath);
|
|
121
|
+
if (currentPath === parentPath) {
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
currentPath = parentPath;
|
|
125
|
+
}
|
|
126
|
+
if (binPaths.length === 0) return false;
|
|
127
|
+
env.PATH = env.PATH ? `${binPaths.join(':')}:${env.PATH}` : binPaths.join(':');
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
|
|
92
131
|
function parseDotenvArgs(args) {
|
|
93
132
|
const separatorIndex = args.indexOf('--');
|
|
94
133
|
return { command: separatorIndex === -1 ? args : args.slice(separatorIndex + 1) };
|