Skip to content

Commit 2510578

Browse files
authored
Update all the things (dependents#157)
* Drop Node.js < 14 support * Remove debug dependency * Fix tests on Windows * Switch to GitHub Actions CI * Add c8 for coverage * Update dependencies * Remove rewire and esm, update mocha and switch to ESM for tests
1 parent 6358873 commit 2510578

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+11718
-6304
lines changed

.c8rc.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"reporter": [
3+
"html",
4+
"lcovonly",
5+
"text"
6+
]
7+
}

.editorconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
indent_size = 2
9+
indent_style = space
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Enforce Unix newlines
2+
* text=auto eol=lf

.github/codeql/codeql-config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: "CodeQL config"
2+
paths-ignore:
3+
- "test/fixtures/**"

.github/dependabot.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: monthly

.github/workflows/ci.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
- "!dependabot/**"
8+
pull_request:
9+
workflow_dispatch:
10+
11+
env:
12+
FORCE_COLOR: 2
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
test:
19+
name: Node ${{ matrix.node }} on ${{ matrix.os }}
20+
runs-on: ${{ matrix.os }}
21+
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
os: [ubuntu-latest, windows-latest]
26+
node: [14, 16, 18, 20]
27+
28+
steps:
29+
- name: Clone repository
30+
uses: actions/checkout@v3
31+
with:
32+
persist-credentials: false
33+
34+
- name: Set up Node.js
35+
uses: actions/setup-node@v3
36+
with:
37+
node-version: ${{ matrix.node }}
38+
cache: npm
39+
40+
- name: Install npm dependencies
41+
run: npm ci
42+
43+
- name: Run unit tests
44+
run: npm run test:ci

.github/workflows/codeql.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- "!dependabot/**"
8+
pull_request:
9+
branches:
10+
- main
11+
- "!dependabot/**"
12+
schedule:
13+
- cron: "0 0 * * 0"
14+
workflow_dispatch:
15+
16+
jobs:
17+
analyze:
18+
name: Analyze
19+
runs-on: ubuntu-latest
20+
permissions:
21+
actions: read
22+
contents: read
23+
security-events: write
24+
25+
steps:
26+
- name: Clone repository
27+
uses: actions/checkout@v3
28+
with:
29+
persist-credentials: false
30+
31+
- name: Initialize CodeQL
32+
uses: github/codeql-action/init@v2
33+
with:
34+
config-file: ./.github/codeql/codeql-config.yml
35+
languages: "javascript"
36+
queries: +security-and-quality
37+
38+
- name: Autobuild
39+
uses: github/codeql-action/autobuild@v2
40+
41+
- name: Perform CodeQL Analysis
42+
uses: github/codeql-action/analyze@v2
43+
with:
44+
category: "/language:javascript"

.github/workflows/lint.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
- "!dependabot/**"
8+
pull_request:
9+
workflow_dispatch:
10+
11+
env:
12+
FORCE_COLOR: 2
13+
NODE: 18
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
lint:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Clone repository
24+
uses: actions/checkout@v3
25+
with:
26+
persist-credentials: false
27+
28+
- name: Set up Node.js
29+
uses: actions/setup-node@v3
30+
with:
31+
node-version: ${{ env.NODE }}
32+
cache: npm
33+
34+
- name: Install npm dependencies
35+
run: npm ci
36+
37+
- name: Lint
38+
run: npm run lint

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
/coverage/
2+
/node_modules/

.jscsrc

-3
This file was deleted.

.mocharc.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"check-leaks": false,
3+
"timeout": 10000,
4+
"throw-deprecation": true,
5+
"trace-deprecation": true,
6+
"trace-warnings": true,
7+
"use-strict": true
8+
}

.npmignore

-5
This file was deleted.

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lockfile-version=2

.travis.yml

-9
This file was deleted.

README.md

+23-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
1-
### dependency-tree [![npm](http://img.shields.io/npm/v/dependency-tree.svg)](https://npmjs.org/package/dependency-tree) [![npm](http://img.shields.io/npm/dm/dependency-tree.svg)](https://npmjs.org/package/dependency-tree)
1+
# dependency-tree
2+
3+
[![CI](https://img.shields.io/github/actions/workflow/status/dependents/node-dependency-tree/ci.yml?branch=main&label=CI&logo=github)](https://github.com/dependents/node-dependency-tree/actions/workflows/ci.yml?query=branch%3Amain)
4+
[![npm version](https://img.shields.io/npm/v/dependency-tree?logo=npm&logoColor=fff)](https://www.npmjs.com/package/dependency-tree)
5+
[![npm downloads](https://img.shields.io/npm/dm/dependency-tree)](https://www.npmjs.com/package/dependency-tree)
26

37
> Get the dependency tree of a module
48
5-
`npm install --save dependency-tree`
9+
```sh
10+
npm install dependency-tree
11+
```
612

7-
* Works for JS (AMD, CommonJS, ES6 modules), Typescript, and CSS preprocessors (CSS (PostCSS), Sass, Stylus, and Less); basically, any module type supported by [Precinct](https://github.com/mrjoelkemp/node-precinct).
13+
* Works for JS (AMD, CommonJS, ES6 modules), Typescript, and CSS preprocessors (CSS (PostCSS), Sass, Stylus, and Less); basically, any module type supported by [Precinct](https://github.com/dependents/node-precinct).
814
- For CommonJS modules, 3rd party dependencies (npm installed dependencies) are included in the tree by default
9-
- Dependency path resolutions are handled by [filing-cabinet](https://github.com/mrjoelkemp/node-filing-cabinet)
15+
- Dependency path resolutions are handled by [filing-cabinet](https://github.com/dependents/node-filing-cabinet)
1016
- Supports RequireJS and Webpack loaders
1117
* All core Node modules (assert, path, fs, etc) are removed from the dependency list by default
1218

13-
### Usage
19+
## Usage
1420

1521
```js
16-
var dependencyTree = require('dependency-tree');
22+
const dependencyTree = require('dependency-tree');
1723

1824
// Returns a dependency tree object for the given file
19-
var tree = dependencyTree({
25+
const tree = dependencyTree({
2026
filename: 'path/to/a/file',
2127
directory: 'path/to/all/files',
2228
requireConfig: 'path/to/requirejs/config', // optional
@@ -33,13 +39,13 @@ var tree = dependencyTree({
3339
// Returns a post-order traversal (list form) of the tree with duplicate sub-trees pruned.
3440
// This is useful for bundling source files, because the list gives the concatenation order.
3541
// Note: you can pass the same arguments as you would to dependencyTree()
36-
var list = dependencyTree.toList({
42+
const list = dependencyTree.toList({
3743
filename: 'path/to/a/file',
3844
directory: 'path/to/all/files'
3945
});
4046
```
4147

42-
#### Options
48+
### Options
4349

4450
* `requireConfig`: path to a requirejs config for AMD modules (allows for the result of aliased module paths)
4551
* `webpackConfig`: path to a webpack config for aliased modules
@@ -54,7 +60,7 @@ var list = dependencyTree.toList({
5460
- See [precinct's usage docs](https://github.com/dependents/node-precinct#usage) for the list of module types you can pass options to.
5561
* `noTypeDefinitions`: For TypeScript imports, whether to resolve to `*.js` instead of `*.d.ts`.
5662

57-
#### Format Details
63+
### Format Details
5864

5965
The object form is a mapping of the dependency tree to the filesystem –
6066
where every key is an absolute filepath and the value is another object/subtree.
@@ -79,7 +85,7 @@ Example:
7985
This structure was chosen to serve as a visual representation of the dependency tree
8086
for use in the [Dependents](https://github.com/mrjoelkemp/sublime-dependents) plugin.
8187

82-
##### CLI version
88+
### CLI version
8389

8490
* Assumes a global install: `npm install -g dependency-tree`
8591

@@ -91,9 +97,9 @@ Prints the dependency tree of the given filename as stringified json (by default
9197

9298
* You can alternatively print out the list form one element per line using the `--list-form` option.
9399

94-
### How does this work?
100+
## How does this work?
95101

96-
Dependency tree takes in a starting file, extracts its declared dependencies via [precinct](https://github.com/dependents/node-precinct/), resolves each of those dependencies to a file on the filesystem via [filing-cabinet](https://github.com/dependents/node-filing-cabinet), then recursively performs those steps until there are no more dependencies to process.
102+
Dependency tree takes in a starting file, extracts its declared dependencies via [precinct](https://github.com/dependents/node-precinct/), resolves each of those dependencies to a file on the filesystem via [filing-cabinet](https://github.com/dependents/node-filing-cabinet), then recursively performs those steps until there are no more dependencies to process.
97103

98104
In more detail, the starting file is passed to precinct to extract dependencies. Dependency-tree doesn't care about how to extract dependencies, so it delegates that work to precinct: which is a multi-language dependency extractor; we'll focus on JavaScript tree generation for this example. To do the extraction, precinct delegates the abstract-syntax-tree (AST) generation to the default parser for [node-source-walk](https://github.com/dependents/node-source-walk). Precinct uses the AST to determine what type of JS module the file is (Commonjs, AMD, or ES6) and then delegates to the "detective" that's appropriate for that module type. The "detective" contains the logic for how to extract dependencies based on the module syntax format; i.e., the way dependencies are declared in commonjs is different than in AMD (which has 4 ways of doing that, for example).
99105

@@ -105,13 +111,13 @@ So after the appropriate resolver finds the file on the filesystem, filing-cabin
105111

106112
At the end of traversing every file (in a depth-first fashion), we have a fully populated dependency tree. :dancers:
107113

108-
### FAQ
114+
## FAQ
109115

110-
#### Why aren't some some dependencies being detected?
116+
### Why aren't some some dependencies being detected?
111117

112118
If there are bugs in [precinct](https://github.com/dependents/node-precinct) or if the `requireConfig`/`webpackConfig`/`tsConfig` options are incomplete,
113119
some dependencies may not be resolved. The optional array passed to the `nonExistent` option will be populated with paths
114120
that could not be resolved. You can check this array to see where problems might exist.
115121

116-
You can also use the `DEBUG=*` env variable along with the cli version to see debugging information explaining where resolution went wrong.
117-
Example: `DEBUG=* dependency-tree -w path/to/webpack.config.json path/to/a/file`
122+
You can also use the `NODE_DEBUG=*` env variable along with the cli version to see debugging information explaining where resolution went wrong.
123+
Example: `NODE_DEBUG=* dependency-tree -w path/to/webpack.config.json path/to/a/file`

bin/cli.js

+16-13
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,39 @@
22

33
'use strict';
44

5-
const dependencyTree = require('../');
65
const program = require('commander');
6+
const dependencyTree = require('../index.js');
7+
const { name, description, version } = require('../package.json');
78

89
program
9-
.version(require('../package.json').version)
10+
.name(name)
11+
.description(description)
12+
.version(version)
1013
.usage('[options] <filename>')
1114
.option('-d, --directory <path>', 'location of files of supported filetypes')
1215
.option('-c, --require-config <path>', 'path to a requirejs config')
1316
.option('-w, --webpack-config <path>', 'path to a webpack config')
1417
.option('-t, --ts-config <path>', 'path to a typescript config')
1518
.option('--list-form', 'output the list form of the tree (one element per line)')
16-
.parse(process.argv);
17-
18-
let tree;
19+
.parse();
1920

21+
const cliOptions = program.opts();
2022
const options = {
2123
filename: program.args[0],
22-
root: program.directory,
23-
config: program.requireConfig,
24-
webpackConfig: program.webpackConfig,
25-
tsConfig: program.tsConfig
24+
root: cliOptions.directory,
25+
config: cliOptions.requireConfig,
26+
webpackConfig: cliOptions.webpackConfig,
27+
tsConfig: cliOptions.tsConfig
2628
};
2729

28-
if (program.listForm) {
30+
let tree;
31+
32+
if (cliOptions.listForm) {
2933
tree = dependencyTree.toList(options);
3034

31-
tree.forEach(function(node) {
35+
for (const node of tree) {
3236
console.log(node);
33-
});
34-
37+
}
3538
} else {
3639
tree = dependencyTree(options);
3740

0 commit comments

Comments
 (0)