aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Tiramify (A.K. Daniel) <94789999+TiranexDev@users.noreply.github.com> 2023-07-13 23:29:24 +0200
committerGravatar GitHub <noreply@github.com> 2023-07-13 14:29:24 -0700
commit044b09afc2a8ce315d7f54a37a14aabf7e013744 (patch)
treecb0d44a1aee2a2a17db401885875f6344a050cf7
parent9eb8eea2a81be6a20abb62544dc54a35ff4173a5 (diff)
downloadbun-044b09afc2a8ce315d7f54a37a14aabf7e013744.tar.gz
bun-044b09afc2a8ce315d7f54a37a14aabf7e013744.tar.zst
bun-044b09afc2a8ce315d7f54a37a14aabf7e013744.zip
Impl. fix (#3630)
-rw-r--r--src/cli/run_command.zig2
-rw-r--r--test/cli/run/run-process-env.test.ts19
-rw-r--r--test/harness.ts9
3 files changed, 26 insertions, 4 deletions
diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig
index 48bbd36d2..271d9ecba 100644
--- a/src/cli/run_command.zig
+++ b/src/cli/run_command.zig
@@ -978,7 +978,7 @@ pub const RunCommand = struct {
var ORIGINAL_PATH: string = "";
var this_bundler: bundler.Bundler = undefined;
var root_dir_info = try configureEnvForRun(ctx, &this_bundler, null, &ORIGINAL_PATH, log_errors, force_using_bun);
- this_bundler.env.map.putDefault("npm_lifecycle_event", script_name_to_search) catch unreachable;
+ this_bundler.env.map.put("npm_lifecycle_event", script_name_to_search) catch unreachable;
if (root_dir_info.enclosing_package_json) |package_json| {
if (package_json.scripts) |scripts| {
switch (script_name_to_search.len) {
diff --git a/test/cli/run/run-process-env.test.ts b/test/cli/run/run-process-env.test.ts
index 8d8eb0b07..1d7cb2c56 100644
--- a/test/cli/run/run-process-env.test.ts
+++ b/test/cli/run/run-process-env.test.ts
@@ -1,16 +1,31 @@
import { describe, expect, test } from "bun:test";
-import { bunRunAsScript, tempDirWithFiles } from "harness";
+import { bunExe, bunRunAsScript, tempDirWithFiles } from "harness";
describe("process.env", () => {
test("npm_lifecycle_event", () => {
const scriptName = "start:dev";
const dir = tempDirWithFiles("processenv", {
- "package.json": `{'scripts': {'${scriptName}': 'bun run index.ts'}}`,
+ "package.json": `{'scripts': {'${scriptName}': '${bunExe()} run index.ts'}}`,
"index.ts": "console.log(process.env.npm_lifecycle_event);",
});
const { stdout } = bunRunAsScript(dir, scriptName);
expect(stdout).toBe(scriptName);
});
+
+ // https://github.com/oven-sh/bun/issues/3589
+ test('npm_lifecycle_event should have the value of the last call', () => {
+ const dir = tempDirWithFiles("processenv_ls_call", {
+ "package.json": `{"scripts": { "first": "${bunExe()} run --cwd lsc second" } }`,
+ "lsc": {
+ "package.json": `{"scripts": { "second": "${bunExe()} run index.ts" } }`,
+ "index.ts": "console.log(process.env.npm_lifecycle_event);",
+ }
+ });
+
+
+ const { stdout } = bunRunAsScript(dir, "first");
+ expect(stdout).toBe("second");
+ });
});
diff --git a/test/harness.ts b/test/harness.ts
index 8b850bbfc..ab3ae5ca2 100644
--- a/test/harness.ts
+++ b/test/harness.ts
@@ -84,9 +84,16 @@ export function hideFromStackTrace(block: CallableFunction) {
});
}
-export function tempDirWithFiles(basename: string, files: Record<string, string>) {
+export function tempDirWithFiles(basename: string, files: Record<string, string | Record<string, string>>) {
const dir = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), basename + "_"));
for (const [name, contents] of Object.entries(files)) {
+ if (typeof contents === "object") {
+ fs.mkdirSync(path.join(dir, name));
+ for (const [_name, _contents] of Object.entries(contents)) {
+ fs.writeFileSync(path.join(dir, name, _name), _contents);
+ }
+ continue;
+ }
fs.writeFileSync(path.join(dir, name), contents);
}
return dir;