Skip to content

Commit

Permalink
Scaffold LunaTrace NPM CLI tool
Browse files Browse the repository at this point in the history
This is built around Arborist and will be the place where we eventually are able to generate "patches" for an arbitrary change.

My goal with this was to just create a basic command, in this case `show-tree`, which wraps Arborist and provides a basic "test case"
for us to verify that the library works.

There is a basic fixture that I committed here -- an arbitrary NPM project from my machine -- that we can use for testing.

In the future, I hope to add in the commands to actually modify the tree to "update" a package to a given version.
  • Loading branch information
freeqaz committed Feb 1, 2023
1 parent c3221e5 commit 7808084
Show file tree
Hide file tree
Showing 34 changed files with 3,514 additions and 665 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module.exports = {
'lunatrace/bsl/common/tsconfig.json',
'lunatrace/bsl/logger/tsconfig.json',
'lunatrace/datadog-metrics-proxy/tsconfig.json',
'lunatrace/npm-package-cli/tsconfig.json',
'docs/tsconfig.json'
]
},
Expand Down
1 change: 1 addition & 0 deletions .idea/lunasec-monorepo.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"eslint-plugin-react": "^7.23.2",
"nodemon": "^2.0.7",
"pm2": "^4.0.1",
"prettier": "^2.2.1",
"prettier": "^2.5.0",
"ts-node": "^10.2.1",
"ts-node-dev": "^1.1.8",
"tslint-config-prettier": "^1.18.0",
Expand Down
8 changes: 4 additions & 4 deletions lunadefend/js/demo-apps/packages/react-front-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"graphql": "^15.0.0",
"graphql-tag": "^2.12.5",
"husky": "^6.0.0",
"prettier": "^2.2.1",
"prettier": "^2.5.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router-dom": "^5.3.0",
Expand All @@ -56,7 +56,7 @@
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/cypress": "^1.1.3",
"@types/jest": "^27.0.3",
"@types/jest": "^29.4.0",
"@types/node": "^14.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
Expand All @@ -66,11 +66,11 @@
"cypress": "9.1.0",
"cypress-file-upload": "^5.0.8",
"cypress-iframe": "^1.0.1",
"jest": "~28.1.0",
"jest": "^29.4.1",
"lerna": "^3.22.1",
"lint-staged": "^10.5.4",
"serve": "^11.3.0",
"ts-jest": "~28.0.3",
"ts-jest": "^29.0.5",
"tslint-config-prettier": "^1.18.0",
"typescript": "~4.5.3"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
},
"devDependencies": {
"@aws-cdk/assert": "1.147.0",
"@types/jest": "^26.0.10",
"@types/jest": "^29.4.0",
"@types/node": "^14.0.0",
"aws-cdk": "1.147.0",
"jest": "^26.4.2",
"ts-jest": "^26.2.0",
"ts-node": "^9.0.0",
"jest": "^29.4.1",
"ts-jest": "^29.0.5",
"ts-node": "^10.0.0",
"typescript": "~3.9.7"
},
"dependencies": {
Expand Down
6 changes: 3 additions & 3 deletions lunadefend/js/sdks/packages/browser-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"@types/jest": "^27.0.3",
"@types/jest": "^29.4.0",
"@types/node": "^14.0.0",
"jest": "^27.4.3",
"jest": "^29.4.1",
"jest-json-to-tap": "^2.1.0",
"ts-jest": "^27.0.7",
"ts-jest": "^29.0.5",
"ts-node": "^10.0.0",
"typescript": "~4.5.0"
},
Expand Down
2 changes: 1 addition & 1 deletion lunadefend/js/sdks/packages/react-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"prettier": "^2.1.1",
"react": "^17.0.0",
"react-dom": "^17.0.2",
"ts-node": "^9.0.0",
"ts-node": "^10.0.0",
"typedoc": "^0.22.10",
"typescript": "~4.5.2"
},
Expand Down
6 changes: 3 additions & 3 deletions lunadefend/js/sdks/packages/tokenizer-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
"devDependencies": {
"@openapitools/openapi-generator-cli": "^2.3.9",
"@types/express": "^4.17.11",
"@types/jest": "^26.0.24",
"@types/jest": "^29.4.0",
"@types/node": "^14.0.0",
"express": "~4.18.2",
"jest": "^27.0.4",
"jest": "^29.4.1",
"jest-json-to-tap": "^2.1.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-dropzone": "^11.4.2",
"ts-jest": "^27.0.7",
"ts-jest": "^29.0.5",
"ts-json-schema-generator": "^0.95.0",
"typescript": "~4.5.0"
},
Expand Down
6 changes: 3 additions & 3 deletions lunadefend/js/sdks/packages/vue-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"vue": "^3.0.0"
},
"devDependencies": {
"@types/jest": "^27.0.3",
"@types/jest": "^29.4.0",
"@types/node": "^14.0.0",
"@types/webpack-env": "^1.16.3",
"@typescript-eslint/eslint-plugin": "^5.6.0",
Expand All @@ -35,8 +35,8 @@
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-prettier-vue": "^3.1.0",
"eslint-plugin-vue": "^8.1.1",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"jest": "^29.4.1",
"prettier": "^2.5.0",
"typescript": "~4.5.2",
"vue-jest": "^5.0.0-0"
}
Expand Down
6 changes: 3 additions & 3 deletions lunatrace/bsl/backend-cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
},
"devDependencies": {
"@aws-sdk/types": "^3.162.0",
"@types/jest": "^26.0.10",
"@types/jest": "^29.4.0",
"@types/node": "^14.0.0",
"aws-cdk": "2.60.0",
"aws-cdk-lib": "2.60.0",
"aws-sdk": "^2.1209.0",
"constructs": "~10.1.221",
"jest": "^26.4.2",
"jest": "^29.4.1",
"source-map-support": "^0.5.16",
"ts-jest": "^26.2.0",
"ts-jest": "^29.0.5",
"ts-node": "^10.4.0",
"typescript": "~3.9.7"
},
Expand Down
6 changes: 3 additions & 3 deletions lunatrace/bsl/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"@types/eventsource": "^1.1.8",
"@types/express": "^4.17.13",
"@types/express-jwt": "^6.0.4",
"@types/jest": "^27.4.1",
"@types/jest": "^29.4.0",
"@types/js-yaml": "~4.0.5",
"@types/jsonwebtoken": "~8.5.8",
"@types/jwk-to-pem": "~2.0.1",
Expand All @@ -144,10 +144,10 @@
"eslint-plugin-react": "^7.23.2",
"generate-lockfile": "^0.0.11",
"graphqurl": "^1.0.1",
"jest": "^27.5.1",
"jest": "^29.4.1",
"pg-mem": "2.6.3",
"source-map-support": "^0.5.16",
"ts-jest": "^27.1.3",
"ts-jest": "^29.0.5",
"ts-node": "~10.9.1",
"ts-node-dev": "^2.0.0",
"typescript": "~4.7.4"
Expand Down
6 changes: 3 additions & 3 deletions lunatrace/bsl/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"vuln-vects": "~1.1.0"
},
"devDependencies": {
"@types/jest": "~27.4.1",
"@types/jest": "^29.4.0",
"@types/node": "^14.0.0",
"@types/stack-trace": "~0.0.29",
"generate-lockfile": "^0.0.11",
"jest": "^27.5.1",
"ts-jest": "^27.1.3",
"jest": "^29.4.1",
"ts-jest": "^29.0.5",
"ts-node": "^10.4.0",
"ts-node-dev": "^1.1.8",
"typescript": "~4.5.5"
Expand Down
2 changes: 1 addition & 1 deletion lunatrace/bsl/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"@testing-library/user-event": "^7.2.1",
"@types/debounce": "~1.2.1",
"@types/highlight.js": "~10.1.0",
"@types/jest": "^24.9.1",
"@types/jest": "^29.4.0",
"@types/jsonwebtoken": "^8.5.8",
"@types/minimatch": "~5.1.2",
"@types/node": "^14.0.0",
Expand Down
6 changes: 3 additions & 3 deletions lunatrace/bsl/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
"stackman": "^4.0.1"
},
"devDependencies": {
"@types/jest": "~27.4.1",
"@types/jest": "^29.4.0",
"@types/node": "^14.0.0",
"@types/stack-trace": "~0.0.29",
"generate-lockfile": "^0.0.11",
"jest": "^27.5.1",
"ts-jest": "^27.1.3",
"jest": "^29.4.1",
"ts-jest": "^29.0.5",
"ts-node": "^10.4.0",
"ts-node-dev": "^1.1.8",
"typescript": "~4.5.5"
Expand Down
21 changes: 21 additions & 0 deletions lunatrace/npm-package-cli/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Salesforce

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
66 changes: 66 additions & 0 deletions lunatrace/npm-package-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!--
~ Copyright by LunaSec (owned by Refinery Labs, Inc)
~
~ Licensed under the Creative Commons Attribution-ShareAlike 4.0 International
~ (the "License"); you may not use this file except in compliance with the
~ License. You may obtain a copy of the License at
~
~ https://creativecommons.org/licenses/by-sa/4.0/legalcode
~
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
lunatrace-npm-cli
=================

This is the LunaTrace CLI for NPM and Yarn. It is basically a wrapper around the "Arborist" NPM library.

<!-- toc -->
* [Usage](#usage)
* [Commands](#commands)
<!-- tocstop -->
# Usage
<!-- usage -->
```sh-session
$ npm install -g @lunasec/lunatrace-npm-cli
$ lunatrace-npm-cli COMMAND
running command...
$ lunatrace-npm-cli (--version)
lunatrace-npm-cli/0.0.0 darwin-x64 node-v16.13.1
$ lunatrace-npm-cli --help [COMMAND]
USAGE
$ lunatrace-npm-cli COMMAND
...
```
<!-- usagestop -->
# Commands
<!-- commands -->
* [`lunatrace-npm-cli show-tree /path/to/tree`](#show-tree)

## `show-tree`

Prints out the NPM dependency tree for the specified path.

```
USAGE
$ lunatrace-npm-cli show-tree [PROJECT_PATH]
ARGUMENTS
PROJECT_PATH Folder that should contain a package.json and package-lock.json
DESCRIPTION
Prints out the NPM dependency tree for the specified path.
EXAMPLES
$ lunatrace-npm-cli show-tree /path/to/tree
Package tree:
[email protected]
... big tree of data ...
```

### Built With

We are using `oclif` to build this CLI. It is a great tool to build CLIs with Node.js and TypeScript!

[![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
17 changes: 17 additions & 0 deletions lunatrace/npm-package-cli/bin/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node

const oclif = require('@oclif/core')

const path = require('path')
const project = path.join(__dirname, '..', 'tsconfig.json')

// In dev mode -> use ts-node and dev plugins
process.env.NODE_ENV = 'development'

require('ts-node').register({project})

// In dev mode, always show stack traces
oclif.settings.debug = true;

// Start the CLI
oclif.run().then(oclif.flush).catch(oclif.Errors.handle)
3 changes: 3 additions & 0 deletions lunatrace/npm-package-cli/bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\dev" %*
5 changes: 5 additions & 0 deletions lunatrace/npm-package-cli/bin/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

const oclif = require('@oclif/core')

oclif.run().then(require('@oclif/core/flush')).catch(require('@oclif/core/handle'))
3 changes: 3 additions & 0 deletions lunatrace/npm-package-cli/bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
35 changes: 35 additions & 0 deletions lunatrace/npm-package-cli/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2023 by LunaSec (owned by Refinery Labs, Inc)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
* Copyright by LunaSec (owned by Refinery Labs, Inc)
*
* Licensed under the Business Source License v1.1
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* https://github.com/lunasec-io/lunasec/blob/master/licenses/BSL-LunaTrace.txt
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
modulePathIgnorePatterns: ["dist", "bin"]
};
Loading

0 comments on commit 7808084

Please sign in to comment.