Skip to content

Commit

Permalink
fixed exports (#968)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmkn authored May 28, 2023
1 parent 11c93f7 commit 1312c40
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 71 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
// "[email protected]",
"[email protected]",
// "[email protected]",
"./build/tests/sampleLintFile.js"
// "./build/tests/sampleLintFile.js"
"./tests/data/lint_data/exportTest.js"
],
//"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": [
Expand Down
21 changes: 21 additions & 0 deletions DEVELOP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Develop

## Setting up the dev environment
```
git clone https://github.com/tmkn/packageanalyzer.git
yarn install
yarn build
```
See [Core Concepts](https://packageanalyzer-docs.vercel.app/docs/core_concepts/provider) for a quick tour around the code

### Watch mode
`yarn dev`
### Build
`yarn build`
## Tests
### Run tests
`yarn test`
### Code Coverage
`yarn test:coverage`
### Watch tests
`yarn test:watch`
47 changes: 3 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,57 +15,16 @@ Stats are fun!

Please see the [Documentation](http://packageanalyzer-docs.vercel.app/) for a more in depth introduction.

## Prints various statistics:
* Number of transitive dependencies
* Number of distinct dependencies
* Most referred package
* Package with most direct dependencies
* Package with most versions
* Licenses

## Install
```
yarn add @tmkn/packageanalyzer
```

## Usage
The package analyzer is both a CLI and a framework.

As such it provides the following CLI options (non exhaustive!):
### Analyze latest version of a package
`pkga analyze --package typescript`
### Analyze specific version of a package
`pkga analyze --package [email protected]`
### Analyze local folder
`pkga analyze --folder path/to/folder/with/package.json`
### Print dependency tree
`pkga tree --package typescript`
### Print licenses
`pkga license --package typescript`
### Run custom report
`pkga report --config path/to/custom/report.js`

Please see [Using custom reports](https://packageanalyzer-docs.vercel.app/docs/guides/custom_reports) on how to use the package analyzer programatically.

## Setting up the dev environment
```
git clone https://github.com/tmkn/packageanalyzer.git
yarn install
yarn build
```
See [Core Concepts](https://packageanalyzer-docs.vercel.app/docs/core_concepts/provider) for a quick tour around the code
Please see the [CLI documentation](https://packageanalyzer-docs.vercel.app/docs/cli/) on usage.

### Watch mode
`yarn dev`
### Build
`yarn build`
## Tests
### Run tests
`yarn test`
### Code Coverage
`yarn test:coverage`
### Watch tests
`yarn test:watch`
## Develop
Please see [here](./DEVELOP.md) how to setup the dev environment

## Roadmap
* Stabilize API
Expand Down
3 changes: 3 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ steps:
- script: yarn lint:web
displayName: 'Check web version for NodeJS code'

- script: yarn test:exports
displayName: 'Test exports'

- script: |
yarn test
displayName: 'Run tests'
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "@tmkn/packageanalyzer",
"version": "0.9.13",
"version": "0.9.14",
"description": "A tool to analyze a Node.js project/package",
"main": "./build/src/index.js",
"types": "./build/src/index.d.ts",
"exports": {
".": "./build/src/index.js",
"./web": "./build/src/index.web.js"
},
"typesVersions": {
Expand All @@ -28,6 +29,7 @@
"test:coverage": "jest --coverage",
"test:update": "jest --updateSnapshot",
"test:clean": "node build/tests/clean.js",
"test:exports": "node ./build/src/cli.js lint --package react ./tests/exportTest.js",
"prettier": "prettier --write \"{src,tests,utility}/**/{*.ts,*.js}\" webpack.web.config.js",
"pa": "node build/src/cli.js",
"preview": "npm pack && tar -xvzf *.tgz && rm -rf package *.tgz",
Expand All @@ -47,7 +49,8 @@
"package",
"analyzer",
"dependency",
"tree"
"tree",
"lint"
],
"bugs": {
"url": "https://github.com/tmkn/packageanalyzer/issues"
Expand Down
1 change: 1 addition & 0 deletions src/cli/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export abstract class CliCommand<T extends AbstractReport<any>> extends Command
const stderrFormatter: IFormatter = new Formatter(this.context.stderr);

stderrFormatter.writeLine(e);
this.exitCode = 1;
}

return this.exitCode;
Expand Down
17 changes: 6 additions & 11 deletions src/reports/LintReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,12 @@ export class LintReport extends AbstractReport<ILintParams> {
private _loadLintFile(lintFile: string): unknown {
let lintFileData: unknown;

try {
const importPath: string = path.isAbsolute(lintFile)
? lintFile
: path.join(process.cwd(), lintFile);

// todo better way to load lint file, if an exception is thrown here it will always show up as couldn't find lint file
const data = require(importPath);
lintFileData = data;
} catch (e) {
throw new Error(`Couldn't find lint file: ${lintFile}`);
}
const importPath: string = path.isAbsolute(lintFile)
? lintFile
: path.join(process.cwd(), lintFile);

const data = require(importPath);
lintFileData = data;

return lintFileData;
}
Expand Down
9 changes: 0 additions & 9 deletions tests/cli/__snapshots__/lintCommand.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,6 @@ exports[`Lint Command Error Handling fails on missing --package and --folder: st

exports[`Lint Command Error Handling fails on missing --package and --folder: stdout 1`] = `[]`;

exports[`Lint Command Error Handling fails on missing lint file: stderr 1`] = `
[
"Error: Couldn't find lint file: ./tests/mocks/lint/missing.js",
"",
]
`;

exports[`Lint Command Error Handling fails on missing lint file: stdout 1`] = `[]`;

exports[`Lint Command Error Handling shows error message for invalid check return value: stderr 1`] = `[]`;

exports[`Lint Command Error Handling shows error message for invalid check return value: stdout 1`] = `
Expand Down
10 changes: 6 additions & 4 deletions tests/cli/lintCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ describe(`Lint Command`, () => {
`./tests/mocks/lint/missing.js`
]) as LintCommand;

expect.assertions(2);
expect.assertions(3);
const { mockContext, stdout, stderr } = createMockContext();
command.context = mockContext;

await command.execute();

expect(stdout.lines).toMatchSnapshot(`stdout`);
expect(stderr.lines).toMatchSnapshot(`stderr`);
expect(stdout.lines.length).toBe(0);
expect(stderr.lines.length).toBe(2);
expect(stderr.lines[0]).toContain(`Error:`);
});

test(`fails on invalid lint file format`, async () => {
Expand All @@ -44,14 +45,15 @@ describe(`Lint Command`, () => {
path.join(process.cwd(), `tests`, `sampleReport.js`)
]) as LintCommand;

expect.assertions(2);
expect.assertions(3);
const { mockContext, stdout, stderr } = createMockContext();
command.context = mockContext;

await command.execute();

expect(stdout.lines.length).toBe(0);
expect(stderr.lines.length).toBe(2);
expect(stderr.lines[0]).toContain(`Error:`);
});

test(`fails on missing --package and --folder`, async () => {
Expand Down
7 changes: 7 additions & 0 deletions tests/exportTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { ValidateKey } = require("@tmkn/packageanalyzer");

const validateKey = new ValidateKey();

module.exports = {
rules: []
};

0 comments on commit 1312c40

Please sign in to comment.