Skip to content

Commit

Permalink
feat: exclude node_modules by default (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnauorriols authored Dec 11, 2023
1 parent 32da267 commit ad8328e
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 7 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,15 @@ jobs:
exclude: |
import_bomb1
import_bomb2
- name: Always exclude node_modules directory
uses: ./
with:
project: happy-rat-64
root: action/tests/always_exclude_node_modules
entrypoint: main.ts
- name: Always exclude nested node_modules directory
uses: ./
with:
project: happy-rat-64
root: action/tests
entrypoint: always_exclude_node_modules/main.ts
5 changes: 3 additions & 2 deletions action/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -4021,7 +4021,8 @@ async function walk(cwd, dir, files, options) {
const relative = path.slice(cwd.length);
// Do not test directories, because --include=foo/bar must include the directory foo
if (!file.isDirectory &&
!include(path.slice(cwd.length + 1), options.include, options.exclude)) {
// .slice(1) removes the leading slash
!include(relative.slice(1), options.include, options.exclude)) {
continue;
}
let entry;
Expand All @@ -4035,7 +4036,7 @@ async function walk(cwd, dir, files, options) {
};
files.set(gitSha1, path);
} else if (file.isDirectory) {
if (relative === "/.git") continue;
if (relative === "/.git" || relative.endsWith("/node_modules")) continue;
entry = {
kind: "directory",
entries: await walk(cwd, path, files, options)
Expand Down
3 changes: 3 additions & 0 deletions action/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
These test modules are deployed by the
[test GHA](../../.github/workflows/test.yml). Assertions are performed as
deployment errors.
17 changes: 17 additions & 0 deletions action/tests/always_exclude_node_modules/main.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.
4 changes: 2 additions & 2 deletions action/tests/include_exclude.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
try {
await Deno.lstat("import_bomb1");
await Deno.lstat(new URL(import.meta.resolve("./import_bomb1")));
throw new Error("BOOM!");
} catch (e) {
if (!(e instanceof Deno.errors.NotFound)) {
throw e;
}
}
try {
await Deno.lstat("import_bomb2");
await Deno.lstat(new URL(import.meta.resolve("./import_bomb2")));
throw new Error("BOOM!");
} catch (e) {
if (!(e instanceof Deno.errors.NotFound)) {
Expand Down
4 changes: 2 additions & 2 deletions deployctl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import logsSubcommand from "./src/subcommands/logs.ts";
import { MINIMUM_DENO_VERSION, VERSION } from "./src/version.ts";
import { fetchReleases, getConfigPaths } from "./src/utils/info.ts";
import configFile from "./src/config_file.ts";
import inferMissingConfig from "./src/config_inference.ts";
import inferConfig from "./src/config_inference.ts";
import { wait } from "./src/utils/spinner.ts";

const help = `deployctl ${VERSION}
Expand Down Expand Up @@ -81,7 +81,7 @@ const subcommand = args._.shift();
switch (subcommand) {
case "deploy":
await setDefaultsFromConfigFile(args);
await inferMissingConfig(args);
await inferConfig(args);
await deploySubcommand(args);
break;
case "upgrade":
Expand Down
9 changes: 8 additions & 1 deletion src/config_inference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const NONAMES = ["src", "lib", "code", "dist", "build", "shared", "public"];
interface InferredArgs {
project?: string;
entrypoint?: string;
exclude: string[];
include: string[];
}

/**
Expand Down Expand Up @@ -195,7 +197,7 @@ async function present(path: string): Promise<string | undefined> {
}
}

export default async function inferMissingConfig(
export default async function inferConfig(
args: InferredArgs & {
token?: string;
help?: boolean;
Expand All @@ -212,6 +214,7 @@ export default async function inferMissingConfig(
if (args.project === undefined) {
args.project = await inferProject(api, !!args["dry-run"]);
}

if (args.entrypoint === undefined) {
args.entrypoint = await inferEntrypoint();
if (args.entrypoint) {
Expand All @@ -223,4 +226,8 @@ export default async function inferMissingConfig(
);
}
}

if (!args.include.some((i) => i.includes("node_modules"))) {
args.exclude.push("**/node_modules");
}
}

0 comments on commit ad8328e

Please sign in to comment.