Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: shebangs #3922

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cli/js/unit_test_runner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env -S deno run --reload --allow-run
#!/bin/sh
":" //; exec /usr/bin/env deno run --reload --allow-run "$0" "$@"
.charAt(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't parse this.. what is happening here?

Copy link
Contributor Author

@brandonkal brandonkal Feb 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The first line tells unix to parse as a shell script line by line.
  2. The : command which is quoted to be valid JavaScript is the "Do nothing beyond expanding arguments and performing redirections." Its only argument is // which is a valid path.
  3. Then we start a new shell statement after the ; inside the JavaScript comment.
  4. exec replaces the shell process with deno passing the desired deno arguments, the script file "$0" and any arguments the user provides "$@"
  5. The .charAt(0); line is required so that Prettier doesn't insert a semicolon after the ":" JavaScript statement. So instead JavaScript executes ":".charAt(0); which is basically a no-op.

// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import "./unit_tests.ts";
import {
Expand Down
4 changes: 3 additions & 1 deletion std/examples/catj.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env -S deno --allow-read
#!/bin/sh
":" //; exec /usr/bin/env deno run --allow-read "$0" "$@"
.charAt(0);
// Ported from: https://github.com/soheilpro/catj
// Copyright (c) 2014 Soheil Rashidi
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
Expand Down
4 changes: 3 additions & 1 deletion std/examples/gist.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env -S deno --allow-net --allow-env
#!/bin/sh
":" //; exec /usr/bin/env deno run --allow-net --allow-env "$0" "$@"
.charAt(0);
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { parse } from "https://deno.land/std/flags/mod.ts";

Expand Down
4 changes: 3 additions & 1 deletion std/http/file_server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env -S deno --allow-net
#!/bin/sh
":" //; exec /usr/bin/env deno run --allow-net "$0" "$@"
.charAt(0);
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

// This program serves files in the current directory over HTTP.
Expand Down
4 changes: 3 additions & 1 deletion std/testing/runner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env -S deno -A
#!/bin/sh
":" //; exec /usr/bin/env deno run -A "$0" "$@"
.charAt(0);
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { parse } from "../flags/mod.ts";
import { ExpandGlobOptions, expandGlob } from "../fs/mod.ts";
Expand Down
4 changes: 3 additions & 1 deletion std/uuid/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env -S deno run
#!/bin/sh
":" //; exec /usr/bin/env deno run "$0" "$@"
.charAt(0);
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { runIfMain } from "../testing/mod.ts";

Expand Down