Skip to content

Commit

Permalink
feat(providence): update version of oxc; cleanup; include .ts(x) and …
Browse files Browse the repository at this point in the history
…jsx by default
  • Loading branch information
tlouisse committed Jan 15, 2025
1 parent 35e6605 commit 71992cc
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 169 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-pugs-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'providence-analytics': patch
---

update version of oxc; cleanup; include .ts(x) and jsx by default
10 changes: 5 additions & 5 deletions docs/fundamentals/node-tools/providence-analytics/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ It does this via the [oxc parser](https://oxc.rs/docs/guide/usage/parser.html),
Providence expects an analyzer name that tells it what type of analysis to run:

```bash
npx providence analyze <analyzer-name>
npx providence-analytics analyze <analyzer-name>
```

By default Providence ships these analyzers:
Expand All @@ -42,7 +42,7 @@ By default Providence ships these analyzers:
Let's say we run `find-imports`:

```bash
npx providence analyze find-imports
npx providence-analytics analyze find-imports
```

Now it retrieves all relevant data about es module imports.
Expand All @@ -68,14 +68,14 @@ For a "find" analyzer, there is one project involved (the target project).
We can specify it like this (we override the default current working directory):

```bash
npx providence analyze find-imports -t /importing/project
npx providence-analytics analyze find-imports -t /importing/project
```

For a "match" analyzer, there is also a reference project.
Here we match the exports of the reference project (-r) against the imports of the target project (-t).

```bash
npx providence analyze match-imports -t /importing/project -r /exporting/project
npx providence-analytics analyze match-imports -t /importing/project -r /exporting/project
```

## Utils
Expand All @@ -91,5 +91,5 @@ For a better understanding, check out the utils folders (tests and code).
For more options, see:

```bash
npx providence --help
npx providence-analytics --help
```
31 changes: 28 additions & 3 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions packages-node/providence-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"test:node:unit": "mocha './{test-node,src}/**/*.test.js'"
},
"dependencies": {
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-node-resolve": "^16.0.0",
"commander": "^2.20.3",
"oxc-parser": "^0.39.0",
"oxc-parser": "^0.46.0",
"parse5": "^7.2.1",
"semver": "^7.6.3"
},
Expand Down
3 changes: 1 addition & 2 deletions packages-node/providence-analytics/src/cli/cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'path';

import commander from 'commander';
import path from 'path';

import { InputDataService } from '../program/core/InputDataService.js';
import { getCurrentDir } from '../program/utils/get-current-dir.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,37 +234,10 @@ export default class FindClassesAnalyzer extends Analyzer {
/** @type {AnalyzerAst} */
static requiredAst = 'oxc';

/**
* Will find all public members (properties (incl. getter/setters)/functions) of a class and
* will make a distinction between private, public and protected methods
* @param {Partial<FindClassesConfig>} customConfig
*/
async execute(customConfig) {
const cfg = customConfig;

/**
* Prepare
*/
const analyzerResult = await this._prepare(cfg);
if (analyzerResult) {
return analyzerResult;
}

/**
* Traverse
*/
/** @type {FindClassesAnalyzerOutput} */
const queryOutput = await this._traverse(async (ast, { relativePath }) => {
const projectPath = cfg.targetProjectPath;
const fullPath = path.resolve(projectPath, relativePath);
const transformedEntry = await findMembersPerAstEntry(ast, fullPath, projectPath);
return { result: transformedEntry };
});
// _flattenedFormsPostProcessor();

/**
* Finalize
*/
return this._finalize(queryOutput, cfg);
static async analyzeFile(oxcAst, context) {
const projectPath = context.analyzerCfg.targetProjectPath;
const fullPath = path.resolve(projectPath, context.relativePath);
const transformedEntry = await findMembersPerAstEntry(oxcAst, fullPath, projectPath);
return { result: transformedEntry };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { trackDownIdentifierFromScope } from '../utils/track-down-identifier.js'
import { Analyzer } from '../core/Analyzer.js';

/**
* @typedef {import('../../../types/index.js').FindCustomelementsConfig} FindCustomelementsConfig
* @typedef {import('../../../types/index.js').AnalyzerAst} AnalyzerAst
* @typedef {import('../../../types/index.js').AnalyzerName} AnalyzerName
* @typedef {import('@babel/types').File} File
*/
Expand Down Expand Up @@ -100,38 +100,21 @@ export default class FindCustomelementsAnalyzer extends Analyzer {
/** @type {AnalyzerAst} */
static requiredAst = 'oxc';

/**
* Finds export specifiers and sources
* @param {FindCustomelementsConfig} customConfig
*/
async execute(customConfig = {}) {
const cfg = {
get config() {
return {
targetProjectPath: null,
...customConfig,
...this._customConfig,
};
}

/**
* Prepare
*/
const cachedAnalyzerResult = await this._prepare(cfg);
if (cachedAnalyzerResult) {
return cachedAnalyzerResult;
}

/**
* Traverse
*/
const projectPath = cfg.targetProjectPath;
const queryOutput = await this._traverse(async (ast, context) => {
let transformedEntry = findCustomElementsPerAstFile(ast);
transformedEntry = await trackdownRoot(transformedEntry, context.relativePath, projectPath);
transformedEntry = cleanup(transformedEntry);
return { result: transformedEntry };
});

/**
* Finalize
*/
return this._finalize(queryOutput, cfg);
static async analyzeFile(oxcAst, context) {
let transformedEntry = findCustomElementsPerAstFile(oxcAst);
transformedEntry = await trackdownRoot(
transformedEntry,
context.relativePath,
context.projectData.project.path,
);
transformedEntry = cleanup(transformedEntry);
return { result: transformedEntry };
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-shadow, no-param-reassign */
import path from 'path';

// import { transformIntoIterableFindExportsOutput } from './helpers/transform-into-iterable-find-exports-output.js';
import { getReferencedDeclaration } from '../utils/get-source-code-fragment-of-declaration.js';
import { normalizeSourcePaths } from './helpers/normalize-source-paths.js';
import { trackDownIdentifier } from '../utils/track-down-identifier.js';
Expand Down Expand Up @@ -274,4 +275,10 @@ export default class FindExportsAnalyzer extends Analyzer {

return { result: transformedFile };
}

static async analyzeProject(...args) {
const totalResult = await super.analyzeProject(...args);
// return transformIntoIterableFindExportsOutput({ queryOutput: totalResult });
return totalResult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,9 @@ import { Analyzer } from '../core/Analyzer.js';

/**
* Intends to work for oxc, swc, and babel asts
* @param {SwcNode} s
*/
function getSpecifierValue(s) {
// for (const exportedorImportedName of [...exportedNames, ...importedNames]) {
// for (const valueName of valueNames) {
// const result = s[exportedorImportedName][valueName];
// if (result) return result;
// }
// }
// return undefined;

return (
// These are regular import values and must be checked first
s.imported?.value ||
Expand Down Expand Up @@ -164,57 +157,35 @@ export default class FindImportsSwcAnalyzer extends Analyzer {
static requiredAst = /** @type {AnalyzerAst} */ ('oxc');

/**
* Finds import specifiers and sources
* @param {FindImportsConfig} customConfig
* @typedef FindImportsConfig
* @property {boolean} [keepInternalSources=false] by default, relative paths like '../x.js' are
* filtered out. This option keeps them.
* means that 'external-dep/file' will be resolved to 'external-dep/file.js' will both be stored
* as the latter
*/
async execute(customConfig = {}) {
/**
* @typedef FindImportsConfig
* @property {boolean} [keepInternalSources=false] by default, relative paths like '../x.js' are
* filtered out. This option keeps them.
* means that 'external-dep/file' will be resolved to 'external-dep/file.js' will both be stored
* as the latter
*/
const cfg = {
get config() {
return {
targetProjectPath: null,
// post process file
keepInternalSources: false,
...customConfig,
...this._customConfig,
};
}

/**
* Prepare
*/
const cachedAnalyzerResult = await this._prepare(cfg);
if (cachedAnalyzerResult) {
return cachedAnalyzerResult;
}
static async analyzeFile(oxcAst, context) {
let transformedFile = findImportsPerAstFile(oxcAst);
// Post processing based on configuration...
transformedFile = await normalizeSourcePaths(
transformedFile,
context.relativePath,
context.analyzerCfg.targetProjectPath,
);

/**
* Traverse
*/
const queryOutput = await this._traverse(async (oxcAst, context) => {
if (!context.analyzerCfg.keepInternalSources) {
// @ts-expect-error
let transformedFile = findImportsPerAstFile(oxcAst);
// Post processing based on configuration...
transformedFile = await normalizeSourcePaths(
transformedFile,
context.relativePath,
// @ts-expect-error
cfg.targetProjectPath,
);

if (!cfg.keepInternalSources) {
// @ts-expect-error
transformedFile = transformedFile.filter(entry => !isRelativeSourcePath(entry.source));
}

return { result: transformedFile };
});
transformedFile = transformedFile.filter(entry => !isRelativeSourcePath(entry.source));
}

/**
* Finalize
*/
return this._finalize(queryOutput, cfg);
return { result: transformedFile };
}
}
Loading

0 comments on commit 71992cc

Please sign in to comment.