@produtype/core 0.27.0 → 0.28.0

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.
@@ -144,6 +144,15 @@ function isTestOrExamplePath(file) {
144
144
  // as a marketplace taking a cut. A field set to null is evidence of absence.
145
145
  return /(^|\/)(__tests__|__mocks__|mocks?|tests?|test-data|fixtures|frontend-example)(\/|$)/i.test(file)
146
146
  || /(^|\/)test[-_][^/]+\.(ts|tsx|js|jsx|mjs|cjs|py)$/i.test(file)
147
+ /**
148
+ * The other half of the convention.
149
+ *
150
+ * `test_settings.py` was recognised and `settings_tests.py` was not, so a Django
151
+ * project's test configuration was read as production and its `STRIPE_SECRET_KEY =
152
+ * "sk_test_fake"` raised a critical — the severity that bars a report from the top
153
+ * band — against a line written to be fake.
154
+ */
155
+ || /[-_]tests?\.(ts|tsx|js|jsx|mjs|cjs|py)$/i.test(file)
147
156
  || /\.(test|spec)\.(ts|tsx|js|jsx|mjs|cjs|py)$/i.test(file);
148
157
  }
149
158
  /**
@@ -4,9 +4,6 @@ export interface ScanOptions {
4
4
  patterns?: string[];
5
5
  ignore?: string[];
6
6
  }
7
- /**
8
- * Scan files relative to a root project path. Returns paths relative to cwd.
9
- */
10
7
  export declare function scanFiles(opts: ScanOptions): Promise<string[]>;
11
8
  /**
12
9
  * Quick check: does at least one path matching glob exist?
@@ -49,6 +49,20 @@ exports.DEFAULT_IGNORE = [
49
49
  '**/coverage/**',
50
50
  '**/venv/**',
51
51
  '**/.venv/**',
52
+ /**
53
+ * Where Python puts what you installed, whatever the surrounding directory is called.
54
+ *
55
+ * `venv/` and `.venv/` were ignored by name, and a repository whose virtualenv was
56
+ * called `venv52/` had 7331 of its 8438 source files read as its own: botocore, boto3,
57
+ * the whole of pip's output. It produced a critical — `SECRET_KEY =
58
+ * 'AWS_SECRET_ACCESS_KEY'`, which is botocore naming an environment variable — against
59
+ * a project that had not written it.
60
+ *
61
+ * This is `node_modules` for Python, and like `node_modules` it cannot be anything
62
+ * else. The name of the virtualenv is a guess; `site-packages` is a fact.
63
+ */
64
+ '**/site-packages/**',
65
+ '**/dist-packages/**',
52
66
  '**/__pycache__/**',
53
67
  '**/.next/**',
54
68
  '**/.turbo/**',
@@ -124,6 +138,24 @@ exports.DEFAULT_IGNORE = [
124
138
  /**
125
139
  * Scan files relative to a root project path. Returns paths relative to cwd.
126
140
  */
141
+ /**
142
+ * The file Python writes at the root of a virtualenv, and the only reliable way to
143
+ * recognise one.
144
+ *
145
+ * A virtualenv can be called anything: `venv52`, `env-3.11`, `.direnv`. Its scripts live
146
+ * in `bin/` and its packages in `lib/pythonX/site-packages/`, but the marker at the root
147
+ * is always this. Finding it means everything beside it was installed rather than
148
+ * written.
149
+ */
150
+ const VIRTUALENV_MARKER = 'pyvenv.cfg';
151
+ function withoutVirtualenvs(files) {
152
+ const roots = files
153
+ .filter((file) => file === VIRTUALENV_MARKER || file.endsWith(`/${VIRTUALENV_MARKER}`))
154
+ .map((file) => file.slice(0, file.length - VIRTUALENV_MARKER.length));
155
+ if (roots.length === 0)
156
+ return files;
157
+ return files.filter((file) => !roots.some((root) => root !== '' && file.startsWith(root)));
158
+ }
127
159
  async function scanFiles(opts) {
128
160
  const patterns = opts.patterns ?? ['**/*'];
129
161
  const ignore = [...exports.DEFAULT_IGNORE, ...(opts.ignore ?? [])];
@@ -135,7 +167,7 @@ async function scanFiles(opts) {
135
167
  ignore,
136
168
  suppressErrors: true,
137
169
  });
138
- return entries.map((e) => e.split(path.sep).join('/'));
170
+ return withoutVirtualenvs(entries.map((e) => e.split(path.sep).join('/')));
139
171
  }
140
172
  /**
141
173
  * Quick check: does at least one path matching glob exist?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@produtype/core",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "description": "Deterministic CLI and library that analyzes a web application repository and reports how far it is from production-ready for the kind of product it is meant to be.",
5
5
  "license": "MIT",
6
6
  "bin": {