@faable/faable 4.41.0 → 4.41.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.
@@ -32,6 +32,11 @@ const collect_manifest = async (workdir) => {
32
32
  ? split_z((await cmd(`git ls-files -co --exclude-standard -z`, { cwd: workdir }))
33
33
  .stdout)
34
34
  : await list_without_repo(workdir);
35
+ if (in_repo) {
36
+ const warning = committed_venv_warning(rel_paths);
37
+ if (warning)
38
+ log.warn(warning);
39
+ }
35
40
  if (rel_paths.length === 0) {
36
41
  throw new Error(in_repo
37
42
  ? "No files to upload (empty git tree?)"
@@ -85,8 +90,56 @@ const split_z = (out) => String(out)
85
90
  .filter((p) => p.length > 0);
86
91
  const shell_quote = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
87
92
  // Out of an upload even when no .gitignore says so — a plain folder has none,
88
- // and these are the files a repository would have ignored anyway.
89
- const NO_REPO_EXCLUDES = ["node_modules/", ".env", ".env.*", ".DS_Store"];
93
+ // and these are the files a repository would have ignored anyway. Python
94
+ // virtualenvs and bytecode: the buildpack recreates the venv (`uv venv`) and
95
+ // compiles its own bytecode, so uploading them only bloats the artifact
96
+ // (arch/abuse/keepalive-interno-free-24h.md). Not excluded on purpose: hidden
97
+ // paths in general (`.well-known/`, `.npmrc`, `.python-version` are content or
98
+ // build input) and `dist/`, `build/`, `out/` (a plain folder is often an
99
+ // already-built site uploaded as is).
100
+ const NO_REPO_EXCLUDES = [
101
+ "node_modules/",
102
+ ".env",
103
+ ".env.*",
104
+ ".DS_Store",
105
+ ".venv/",
106
+ "venv/",
107
+ "__pycache__/",
108
+ "*.pyc",
109
+ ".git/",
110
+ ];
111
+ const PYVENV_CFG = "pyvenv.cfg";
112
+ // A virtualenv under any other name (`env/`, `.python/`…) is still a
113
+ // virtualenv: it is the folder that holds a pyvenv.cfg. Matched on the listing
114
+ // instead of with a git pattern so that an `env/` of config files stays in.
115
+ const without_virtualenvs = (paths) => {
116
+ const venv_dirs = paths
117
+ .filter((p) => p.endsWith(`/${PYVENV_CFG}`))
118
+ .map((p) => p.slice(0, -PYVENV_CFG.length));
119
+ if (venv_dirs.length === 0)
120
+ return paths;
121
+ return paths.filter((p) => !venv_dirs.some((d) => p.startsWith(d)));
122
+ };
123
+ // More files than this under site-packages/ is an installed environment, not a
124
+ // vendored module or two.
125
+ const SITE_PACKAGES_WARN_THRESHOLD = 200;
126
+ /**
127
+ * In a repository git decides what is uploaded, a committed virtualenv
128
+ * included — but the build recreates it, so say so (and keep going).
129
+ */
130
+ const committed_venv_warning = (paths) => {
131
+ const cfg = paths.find((p) => p === PYVENV_CFG || p.endsWith(`/${PYVENV_CFG}`));
132
+ const site_packages = paths.filter((p) => `/${p}`.includes("/site-packages/")).length;
133
+ if (!cfg && site_packages <= SITE_PACKAGES_WARN_THRESHOLD)
134
+ return undefined;
135
+ const dir = cfg?.slice(0, -PYVENV_CFG.length);
136
+ const found = dir
137
+ ? `${dir} is a Python virtualenv`
138
+ : cfg
139
+ ? "the repository root is a Python virtualenv"
140
+ : `${site_packages} files under site-packages/ look like a Python virtualenv`;
141
+ return `⚠️ ${found} committed to the repository. The build recreates it, so it only makes the upload bigger: add ${dir || "it"} to .gitignore.`;
142
+ };
90
143
  /**
91
144
  * The files of a folder that is not a git repository. Git still lists them:
92
145
  * a temporary repository holds the index and the folder is its work tree, so
@@ -99,14 +152,14 @@ const list_without_repo = async (workdir) => {
99
152
  await cmd(`git init -q ${shell_quote(git_dir)}`).catch(() => {
100
153
  throw new Error("Deploys collect the source with git, and git is not available. Install git and try again.");
101
154
  });
102
- log.info(`📂 ${workdir} is not a git repository: uploading the folder (its .gitignore files apply; ${NO_REPO_EXCLUDES.join(", ")} stay out)`);
155
+ log.info(`📂 ${workdir} is not a git repository: uploading the folder (its .gitignore files apply; ${NO_REPO_EXCLUDES.join(", ")} and Python virtualenvs stay out)`);
103
156
  const excludes = NO_REPO_EXCLUDES.map((p) => `-x ${shell_quote(p)}`).join(" ");
104
157
  const out = await cmd(`git --git-dir=${shell_quote(path.join(git_dir, ".git"))} --work-tree=${shell_quote(workdir)} ls-files -o --exclude-standard ${excludes} -z`, { cwd: workdir });
105
- return split_z(out.stdout);
158
+ return without_virtualenvs(split_z(out.stdout));
106
159
  }
107
160
  finally {
108
161
  rmSync(git_dir, { recursive: true, force: true });
109
162
  }
110
163
  };
111
164
 
112
- export { NO_REPO_EXCLUDES, collect_manifest };
165
+ export { NO_REPO_EXCLUDES, collect_manifest, committed_venv_warning };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faable/faable",
3
- "version": "4.41.0",
3
+ "version": "4.41.1",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Marc Pomar <marc@faable.com>",