find-cypress-specs 1.22.0 → 1.23.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.
Files changed (3) hide show
  1. package/README.md +11 -0
  2. package/bin/find.js +29 -2
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -61,6 +61,17 @@ $ npx find-cypress-specs --branch main --parent --trace-imports cypress
61
61
 
62
62
  **Note:** the argument is the subfolder name to limit the number of files to inspect when tracing the imports.
63
63
 
64
+ You can time how long tracing takes by adding option `--time-trace` to the command line arguments. You can also saved traced dependencies using `--cache-trace` argument. Next time the dependencies will be loaded from the file without recomputing. This is convenient on CI to avoid recomputing them. For example, if you need the number of affected files and their filenames
65
+
66
+ ```
67
+ # get the number of affected specs
68
+ $ npx find-cypress-specs --branch main --parent --trace-imports cypress --cache-trace --count
69
+ # quickly get the affected specs without recomputing the dependencies
70
+ $ npx find-cypress-specs --branch main --parent --trace-imports cypress --cache-trace
71
+ ```
72
+
73
+ The cached trace will be saved in file `deps.json`, you probably want to Git ignore it.
74
+
64
75
  ### number of changed files
65
76
 
66
77
  You can print just the number of changed specs
package/bin/find.js CHANGED
@@ -37,6 +37,9 @@ const args = arg({
37
37
  // to set two named outputs, one for number of changed specs
38
38
  // another for actual list of files
39
39
  '--set-gha-outputs': Boolean,
40
+ // save a JSON file with traced dependencies to save time
41
+ '--cache-trace': Boolean,
42
+ '--time-trace': Boolean,
40
43
  // aliases
41
44
  '-n': '--names',
42
45
  '--name': '--names',
@@ -141,8 +144,32 @@ if (args['--names'] || args['--tags']) {
141
144
  debug('comparing against the specs %o', specs)
142
145
  if (args['--trace-imports']) {
143
146
  debug('tracing dependent changes in folder %s', args['--trace-imports'])
144
- const absoluteFolder = path.join(process.cwd(), args['--trace-imports'])
145
- const deps = getDependsInFolder(absoluteFolder)
147
+
148
+ const saveDependenciesFile = 'deps.json'
149
+ let deps
150
+ if (args['--cache-trace']) {
151
+ if (fs.existsSync(saveDependenciesFile)) {
152
+ debug(
153
+ 'loading cached traced dependencies from file %s',
154
+ saveDependenciesFile,
155
+ )
156
+ deps = JSON.parse(fs.readFileSync(saveDependenciesFile, 'utf-8')).deps
157
+ }
158
+ }
159
+
160
+ if (!deps) {
161
+ const absoluteFolder = path.join(process.cwd(), args['--trace-imports'])
162
+ const depsOptions = { folder: absoluteFolder, time: args['--time-trace'] }
163
+ if (args['--cache-trace']) {
164
+ depsOptions.saveDepsFilename = saveDependenciesFile
165
+ debug(
166
+ 'will save found dependencies into the file %s',
167
+ saveDependenciesFile,
168
+ )
169
+ }
170
+ debug('tracing options %o', depsOptions)
171
+ deps = getDependsInFolder(depsOptions)
172
+ }
146
173
  debug('traced dependencies via imports and require')
147
174
  debug(deps)
148
175
  Object.entries(deps).forEach(([filename, fileDependents]) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "find-cypress-specs",
3
- "version": "1.22.0",
3
+ "version": "1.23.0",
4
4
  "description": "Find Cypress spec files using the config settings",
5
5
  "main": "src",
6
6
  "files": [
@@ -26,7 +26,7 @@
26
26
  "count-changed-specs": "node ./bin/find --branch main --count",
27
27
  "semantic-release": "semantic-release",
28
28
  "deps": "spec-change --folder . --mask 'cypress/**/*.{js,ts}'",
29
- "deps-changed": "DEBUG=find-cypress-specs node ./bin/find --branch main --parent --trace-imports cypress"
29
+ "deps-changed": "DEBUG=find-cypress-specs node ./bin/find --branch main --parent --trace-imports cypress --time-trace --cache-trace"
30
30
  },
31
31
  "repository": {
32
32
  "type": "git",
@@ -62,7 +62,7 @@
62
62
  "pluralize": "^8.0.0",
63
63
  "require-and-forget": "^1.0.0",
64
64
  "shelljs": "^0.8.5",
65
- "spec-change": "^1.4.0",
65
+ "spec-change": "^1.6.0",
66
66
  "ts-node": "^10.9.1"
67
67
  }
68
68
  }