Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

spec-change

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spec-change - npm Package Compare versions

Comparing version 1.6.3 to 1.7.0

13

bin/spec-change.js

@@ -14,2 +14,3 @@ #!/usr/bin/env node

'--time': Boolean,
'--allowjs': Boolean,
// aliases

@@ -19,2 +20,5 @@ '-f': '--folder',

'-t': '--time',
'--allow-js': '--allowjs',
'--allowJs': '--allowjs',
'--allowJS': '--allowjs',
})

@@ -37,4 +41,11 @@

const time = args['--time']
const deps = getDependsInFolder({ folder, fileMask, saveDepsFilename, time })
const allowJs = args['--allowjs'] || false
const deps = getDependsInFolder({
folder,
fileMask,
saveDepsFilename,
time,
allowJs,
})
const depsStringified = JSON.stringify(deps, null, 2)
console.log(depsStringified + '\n')

4

package.json
{
"name": "spec-change",
"version": "1.6.3",
"version": "1.7.0",
"description": "Computes specs to re-run when files change",

@@ -27,2 +27,4 @@ "main": "src/index.js",

"execa-wrap": "^1.4.0",
"filing-cabinet": "^3.3.0",
"precinct": "^9.0.1",
"prettier": "^2.8.1",

@@ -29,0 +31,0 @@ "semantic-release": "^20.1.0"

@@ -55,2 +55,8 @@ # spec-change

If you have JS and TS files in the same project, you should use the flag `--allowjs` to make sure TS imports from JS files are detected.
```
$ npx spec-change --folder "path to folder" --allowjs
```
### NPM module

@@ -57,0 +63,0 @@

@@ -0,1 +1,2 @@

// https://github.com/dependents/node-dependency-tree
const dependencyTree = require('dependency-tree')

@@ -33,7 +34,17 @@ const path = require('path')

*/
function getFileDependencies(filename, directory) {
const tree = dependencyTree({
function getFileDependencies(filename, directory, allowJs) {
const treeOptions = {
filename,
directory,
})
}
if (allowJs) {
treeOptions.tsConfig = {
compilerOptions: {
// JS files can import TS files
// and vice versa
allowJs: true,
},
}
}
const tree = dependencyTree(treeOptions)

@@ -50,5 +61,5 @@ // convert absolute paths into relative

*/
function getFlatFileDependencies(filename, directory) {
function getFlatFileDependencies(filename, directory, allowJs) {
const firstFileRelative = path.relative(directory, filename)
const tree = getFileDependencies(filename, directory)
const tree = getFileDependencies(filename, directory, allowJs)
const set = new Set()

@@ -78,3 +89,3 @@

*/
function getFlatFilesDependencies(filenames, directory) {
function getFlatFilesDependencies(filenames, directory, allowJs) {
la(Array.isArray(filenames), 'expected a list of filenames', filenames)

@@ -86,3 +97,3 @@ la(typeof directory === 'string', 'expected a directory', directory)

const name = path.relative(directory, filename)
const dependsOn = getFlatFileDependencies(filename, directory)
const dependsOn = getFlatFileDependencies(filename, directory, allowJs)
result[name] = dependsOn

@@ -100,8 +111,9 @@ })

* @param {string} directory The absolute path to the common directory
* @param {boolean} allowJs Allow JS and TS specs to import each other
* @see https://github.com/bahmutov/spec-change
*/
function getDependentFiles(filenames, directory) {
function getDependentFiles(filenames, directory, allowJs) {
la(Array.isArray(filenames), 'expected a list of filenames', filenames)
la(typeof directory === 'string', 'expected a directory', directory)
const flatDeps = getFlatFilesDependencies(filenames, directory)
const flatDeps = getFlatFilesDependencies(filenames, directory, allowJs)

@@ -145,3 +157,3 @@ const allImportedFilesSet = new Set()

function getDependsInFolder(options) {
const { folder, saveDepsFilename } = options
const { folder, saveDepsFilename, allowJs } = options
const fileMask = options.fileMask || '**/*.{js,ts}'

@@ -153,3 +165,3 @@

debug('absolute folder: %s', folder)
debug('file mask: %s', fileMask)
debug('file mask: %s allow JS %o', fileMask, allowJs)
const started = +new Date()

@@ -162,3 +174,3 @@ const files = globby.sync(fileMask, {

const deps = getDependentFiles(files, folder)
const deps = getDependentFiles(files, folder, allowJs)

@@ -165,0 +177,0 @@ if (saveDepsFilename) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc