chore: move to swc + esm
This commit is contained in:
parent
60032a2df0
commit
0315b33acd
94 changed files with 2568 additions and 2312 deletions
|
|
@ -19,7 +19,7 @@ module.exports = {
|
|||
files: [
|
||||
'**/test-suites/**/*.js',
|
||||
'**/test/**/*.js',
|
||||
'**/test-node/**/*.js',
|
||||
'**/test-node/**/*.{j,mj}s',
|
||||
'**/demo/**/*.js',
|
||||
'**/docs/**/*.js',
|
||||
'**/*.config.js',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { OverlaysManager } from 'overlays';
|
||||
import { OverlaysManager , OverlaysManager as OverlaysManager2 } from 'overlays';
|
||||
import { singletonManager } from 'singleton-manager';
|
||||
import { OverlaysManager as OverlaysManager2 } from './node_modules/page-b/node_modules/overlays/index.js';
|
||||
|
||||
let compatibleManager1;
|
||||
let compatibleManager2;
|
||||
|
|
|
|||
66
package.json
66
package.json
|
|
@ -44,70 +44,64 @@
|
|||
"changeset": "^0.2.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.10.1",
|
||||
"@babel/core": "^7.21.3",
|
||||
"@bundled-es-modules/fetch-mock": "^6.5.2",
|
||||
"@changesets/cli": "^2.26.1",
|
||||
"@custom-elements-manifest/analyzer": "^0.5.7",
|
||||
"@open-wc/building-rollup": "^1.2.1",
|
||||
"@open-wc/eslint-config": "^7.0.0",
|
||||
"@open-wc/testing": "^3.1.2",
|
||||
"@open-wc/testing-helpers": "^2.1.2",
|
||||
"@custom-elements-manifest/analyzer": "^0.8.0",
|
||||
"@open-wc/building-rollup": "^1.10.0",
|
||||
"@open-wc/eslint-config": "^10.0.0",
|
||||
"@open-wc/testing": "^3.1.7",
|
||||
"@open-wc/testing-helpers": "^2.2.0",
|
||||
"@rocket/blog": "^0.4.0",
|
||||
"@rocket/cli": "^0.10.1",
|
||||
"@rocket/cli": "^0.10.2",
|
||||
"@rocket/launch": "^0.6.0",
|
||||
"@rocket/search": "^0.5.1",
|
||||
"@types/chai-as-promised": "^7.1.5",
|
||||
"@types/chai-dom": "^0.0.8",
|
||||
"@types/convert-source-map": "^1.5.1",
|
||||
"@types/fs-extra": "^9.0.7",
|
||||
"@types/convert-source-map": "^1.5.2",
|
||||
"@types/fs-extra": "^9.0.13",
|
||||
"@types/glob": "^7.1.3",
|
||||
"@types/istanbul-reports": "^3.0.0",
|
||||
"@types/mocha": "^10.0.0",
|
||||
"@types/prettier": "^2.2.1",
|
||||
"@web/dev-server": "^0.1.8",
|
||||
"@types/istanbul-reports": "^3.0.1",
|
||||
"@types/mocha": "^10.0.1",
|
||||
"@types/prettier": "^2.7.2",
|
||||
"@web/dev-server": "^0.1.37",
|
||||
"@web/dev-server-legacy": "^0.1.7",
|
||||
"@web/test-runner": "^0.13.7",
|
||||
"@web/test-runner-browserstack": "^0.5.0",
|
||||
"@web/test-runner-commands": "^0.6.1",
|
||||
"@web/test-runner-playwright": "^0.8.8",
|
||||
"@webcomponents/scoped-custom-element-registry": "^0.0.5",
|
||||
"@web/test-runner": "^0.15.2",
|
||||
"@web/test-runner-browserstack": "^0.5.1",
|
||||
"@web/test-runner-commands": "^0.6.5",
|
||||
"@web/test-runner-playwright": "^0.9.0",
|
||||
"@webcomponents/scoped-custom-element-registry": "^0.0.8",
|
||||
"@yarnpkg/lockfile": "^1.1.0",
|
||||
"babel-polyfill": "^6.26.0",
|
||||
"bundlesize": "^1.0.0-beta.2",
|
||||
"cem-plugin-vs-code-custom-data-generator": "^1.4.1",
|
||||
"chai": "^4.2.0",
|
||||
"chai-as-promised": "^7.1.1",
|
||||
"chalk": "^4.1.0",
|
||||
"concurrently": "^5.2.0",
|
||||
"cross-env": "^7.0.2",
|
||||
"es6-promisify": "^6.1.1",
|
||||
"eslint": "^8.26.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-lit": "^1.6.1",
|
||||
"eslint-plugin-lit-a11y": "^2.2.0",
|
||||
"eslint-plugin-wc": "^1.3.2",
|
||||
"globby": "^13.1.2",
|
||||
"eslint": "^8.37.0",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-lit": "^1.8.2",
|
||||
"eslint-plugin-lit-a11y": "^2.4.0",
|
||||
"eslint-plugin-wc": "^1.4.0",
|
||||
"globby": "^13.1.3",
|
||||
"husky": "^6.0.0",
|
||||
"lint-staged": "^10.0.0",
|
||||
"looks-same": "^7.2.3",
|
||||
"lint-staged": "^10.5.4",
|
||||
"looks-same": "^7.3.0",
|
||||
"markdownlint-cli": "^0.17.0",
|
||||
"mermaid": "^9.3.0",
|
||||
"minimist": "^1.2.6",
|
||||
"mkdirp-promise": "^5.0.1",
|
||||
"mocha": "^10.1.0",
|
||||
"mock-fs": "^5.1.2",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"nyc": "^15.0.0",
|
||||
"playwright": "^1.20.0",
|
||||
"playwright": "^1.32.1",
|
||||
"postinstall-postinstall": "^2.1.0",
|
||||
"prettier": "^2.0.5",
|
||||
"prettier-package-json": "^2.1.3",
|
||||
"remark-html": "^13.0.1",
|
||||
"rimraf": "^2.6.3",
|
||||
"rollup": "^2.0.0",
|
||||
"semver": "^7.5.2",
|
||||
"sinon": "^7.2.2",
|
||||
"rollup": "^2.79.1",
|
||||
"sinon": "^7.5.0",
|
||||
"ssl-root-cas": "^1.3.1",
|
||||
"typescript": "~4.8.4",
|
||||
"whatwg-fetch": "^3.0.0",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* @desc Can be called from a button click handler in order to let the end user download a file
|
||||
* Can be called from a button click handler in order to let the end user download a file
|
||||
* @param {string} filename like 'overview.csv'
|
||||
* @param {string} content for instance a csv file
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,15 +1,19 @@
|
|||
import fs from 'fs';
|
||||
import pathLib, { dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import pathLib from 'path';
|
||||
import { startDevServer } from '@web/dev-server';
|
||||
import { ReportService } from '../src/program/core/ReportService.js';
|
||||
import { providenceConfUtil } from '../src/program/utils/providence-conf-util.mjs';
|
||||
import { providenceConfUtil } from '../src/program/utils/providence-conf-util.js';
|
||||
import { getCurrentDir } from '../src/program/utils/get-current-dir.js';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
/**
|
||||
* @typedef {import('../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../types/index.js').GatherFilesConfig} GatherFilesConfig
|
||||
* @typedef {import('../types/index.js').AnalyzerName} AnalyzerName
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets all results found in cache folder with all results
|
||||
* @param {{ supportedAnalyzers: `match-${string}`[], resultsPath: string }} options
|
||||
* @param {{ supportedAnalyzers?: `match-${string}`[], resultsPath?: string }} options
|
||||
*/
|
||||
async function getCachedProvidenceResults({
|
||||
supportedAnalyzers = ['match-imports', 'match-subclasses'],
|
||||
|
|
@ -34,6 +38,7 @@ async function getCachedProvidenceResults({
|
|||
searchTargetDeps = content;
|
||||
} else {
|
||||
const analyzerName = fileName.split('_-_')[0];
|
||||
// @ts-ignore
|
||||
if (!supportedAnalyzers.includes(analyzerName)) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -48,7 +53,7 @@ async function getCachedProvidenceResults({
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {{ providenceConf: object; earchTargetDeps: object; resultFiles: string[]; }}
|
||||
* @param {{ providenceConf: object; providenceConfRaw:string; searchTargetDeps: object; resultFiles: string[]; }}
|
||||
*/
|
||||
function createMiddleWares({ providenceConf, providenceConfRaw, searchTargetDeps, resultFiles }) {
|
||||
/**
|
||||
|
|
@ -80,7 +85,10 @@ function createMiddleWares({ providenceConf, providenceConfRaw, searchTargetDeps
|
|||
return res;
|
||||
}
|
||||
|
||||
const pathFromServerRootToHere = `/${pathLib.relative(process.cwd(), __dirname)}`;
|
||||
const pathFromServerRootToHere = `/${pathLib.relative(
|
||||
process.cwd(),
|
||||
getCurrentDir(import.meta.url),
|
||||
)}`;
|
||||
|
||||
return [
|
||||
// eslint-disable-next-line consistent-return
|
||||
|
|
@ -143,7 +151,7 @@ export async function createDashboardServerConfig() {
|
|||
const moduleRoot = fromPackageRoot ? pathLib.resolve(process.cwd(), '../../') : process.cwd();
|
||||
|
||||
return {
|
||||
appIndex: pathLib.resolve(__dirname, 'index.html'),
|
||||
appIndex: pathLib.resolve(getCurrentDir(import.meta.url), 'index.html'),
|
||||
rootDir: moduleRoot,
|
||||
nodeResolve: true,
|
||||
moduleDirs: pathLib.resolve(moduleRoot, 'node_modules'),
|
||||
|
|
@ -158,6 +166,7 @@ export async function createDashboardServerConfig() {
|
|||
};
|
||||
}
|
||||
|
||||
/** @type {(value?: any) => void} */
|
||||
let resolveLoaded;
|
||||
export const serverInstanceLoaded = new Promise(resolve => {
|
||||
resolveLoaded = resolve;
|
||||
|
|
@ -10,26 +10,27 @@
|
|||
"url": "https://github.com/ing-bank/lion.git",
|
||||
"directory": "packages-node/providence-analytics"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./src/index.js",
|
||||
"./src/cli": "./src/cli/index.js",
|
||||
"./cli.js": "./src/cli/index.js",
|
||||
"./utils.js": "./src/program/utils/index.js",
|
||||
"./analyzers": "./src/program/analyzers/index.js",
|
||||
"./analyzers.js": "./src/program/analyzers/index.js",
|
||||
"./docs/*": "./docs/*"
|
||||
},
|
||||
"main": "./src/index.js",
|
||||
"bin": {
|
||||
"providence": "./src/cli/index.mjs"
|
||||
"providence": "./src/cli/index.js"
|
||||
},
|
||||
"files": [
|
||||
"dashboard/src",
|
||||
"src"
|
||||
],
|
||||
"scripts": {
|
||||
"dashboard": "node ./dashboard/server.mjs --run-server --serve-from-package-root",
|
||||
"dashboard": "node ./dashboard/server.js --run-server --serve-from-package-root",
|
||||
"postinstall": "npx patch-package",
|
||||
"match-lion-imports": "npm run providence -- analyze match-subclasses --search-target-collection @lion-targets --reference-collection @lion-references --measure-perf --add-system-paths",
|
||||
"providence": "node --max-old-space-size=8192 ./src/cli/index.mjs",
|
||||
"providence": "node --max-old-space-size=8192 ./src/cli/index.js",
|
||||
"publish-docs": "node ../../packages-node/publish-docs/src/cli.js --github-url https://github.com/ing-bank/lion/ --git-root-dir ../../",
|
||||
"prepublishOnly": "npm run publish-docs",
|
||||
"test:node": "npm run test:node:unit && npm run test:node:e2e",
|
||||
|
|
@ -37,32 +38,35 @@
|
|||
"test:node:unit": "mocha './test-node/**/*.test.{j,mj}s'"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.10.1",
|
||||
"@babel/parser": "^7.5.5",
|
||||
"@babel/plugin-proposal-class-properties": "^7.8.3",
|
||||
"@babel/core": "^7.21.3",
|
||||
"@babel/parser": "^7.21.3",
|
||||
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
||||
"@babel/plugin-syntax-export-default-from": "^7.18.6",
|
||||
"@babel/plugin-syntax-import-assertions": "^7.18.6",
|
||||
"@babel/register": "^7.5.5",
|
||||
"@babel/traverse": "^7.23.2",
|
||||
"@babel/types": "^7.9.0",
|
||||
"@rollup/plugin-node-resolve": "^15.0.0",
|
||||
"@web/dev-server": "^0.1.28",
|
||||
"anymatch": "^3.1.1",
|
||||
"chalk": "^4.1.0",
|
||||
"commander": "^2.20.0",
|
||||
"deepmerge": "^4.0.0",
|
||||
"glob": "^7.1.6",
|
||||
"inquirer": "^7.0.0",
|
||||
"@babel/plugin-syntax-import-assertions": "^7.20.0",
|
||||
"@babel/register": "^7.21.0",
|
||||
"@babel/traverse": "^7.21.3",
|
||||
"@babel/types": "^7.21.3",
|
||||
"@rollup/plugin-node-resolve": "^15.0.1",
|
||||
"@swc/core": "^1.3.42",
|
||||
"@web/dev-server": "^0.1.37",
|
||||
"anymatch": "^3.1.3",
|
||||
"commander": "^2.20.3",
|
||||
"glob": "^7.2.3",
|
||||
"inquirer": "^9.1.5",
|
||||
"is-negated-glob": "^1.0.0",
|
||||
"lit-element": "~2.4.0",
|
||||
"parse5": "^5.1.1",
|
||||
"parse5": "^7.1.2",
|
||||
"read-package-tree": "5.3.1",
|
||||
"semver": "^7.5.2",
|
||||
"typescript": "~4.8.4"
|
||||
"semver": "^7.3.8",
|
||||
"swc-to-babel": "^1.26.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@web/dev-server-core": "^0.3.19",
|
||||
"mock-require": "^3.0.3"
|
||||
"@types/chai": "^4.3.4",
|
||||
"@types/inquirer": "^9.0.3",
|
||||
"@types/mocha": "^10.0.1",
|
||||
"@web/dev-server-core": "^0.4.0",
|
||||
"mock-require": "^3.0.3",
|
||||
"mock-fs": "^5.2.0"
|
||||
},
|
||||
"keywords": [
|
||||
"analysis",
|
||||
|
|
@ -77,8 +81,5 @@
|
|||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"imports": {
|
||||
"#types": "./src/program/types"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ export default {
|
|||
majorVersion: 1,
|
||||
// These conditions will be run on overy filePath
|
||||
categories: {
|
||||
overlays: localFilePath => {
|
||||
overlays: (/** @type {string} */ localFilePath) => {
|
||||
const names = ['dialog', 'tooltip'];
|
||||
const fromPackages = names.some(p =>
|
||||
localFilePath.startsWith(`./packages/ui/components/${p}`),
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
/* eslint-disable no-shadow */
|
||||
const pathLib = require('path');
|
||||
const child_process = require('child_process'); // eslint-disable-line camelcase
|
||||
const glob = require('glob');
|
||||
const readPackageTree = require('../program/utils/read-package-tree-with-bower-support.js');
|
||||
const { LogService } = require('../program/core/LogService.js');
|
||||
const { toPosixPath } = require('../program/utils/to-posix-path.js');
|
||||
import pathLib from 'path';
|
||||
import child_process from 'child_process'; // eslint-disable-line camelcase
|
||||
import glob from 'glob';
|
||||
import readPackageTree from '../program/utils/read-package-tree-with-bower-support.js';
|
||||
import { LogService } from '../program/core/LogService.js';
|
||||
import { toPosixPath } from '../program/utils/to-posix-path.js';
|
||||
|
||||
/**
|
||||
* @param {any[]} arr
|
||||
* @returns {any[]}
|
||||
*/
|
||||
function flatten(arr) {
|
||||
export function flatten(arr) {
|
||||
return Array.prototype.concat.apply([], arr);
|
||||
}
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ function flatten(arr) {
|
|||
* @param {string} v
|
||||
* @returns {string[]}
|
||||
*/
|
||||
function csToArray(v) {
|
||||
export function csToArray(v) {
|
||||
return v.split(',').map(v => v.trim());
|
||||
}
|
||||
|
||||
|
|
@ -26,11 +26,16 @@ function csToArray(v) {
|
|||
* @param {string} v like 'js,html'
|
||||
* @returns {string[]} like ['.js', '.html']
|
||||
*/
|
||||
function extensionsFromCs(v) {
|
||||
export function extensionsFromCs(v) {
|
||||
return csToArray(v).map(v => `.${v}`);
|
||||
}
|
||||
|
||||
function setQueryMethod(m) {
|
||||
/**
|
||||
*
|
||||
* @param {*} m
|
||||
* @returns
|
||||
*/
|
||||
export function setQueryMethod(m) {
|
||||
const allowedMehods = ['grep', 'ast'];
|
||||
if (allowedMehods.includes(m)) {
|
||||
return m;
|
||||
|
|
@ -43,7 +48,7 @@ function setQueryMethod(m) {
|
|||
* @param {string} t
|
||||
* @returns {string[]|undefined}
|
||||
*/
|
||||
function pathsArrayFromCs(t, cwd = process.cwd()) {
|
||||
export function pathsArrayFromCs(t, cwd = process.cwd()) {
|
||||
if (!t) {
|
||||
return undefined;
|
||||
}
|
||||
|
|
@ -72,10 +77,10 @@ function pathsArrayFromCs(t, cwd = process.cwd()) {
|
|||
* @param {string} [cwd]
|
||||
* @returns {string[]|undefined}
|
||||
*/
|
||||
function pathsArrayFromCollectionName(
|
||||
export function pathsArrayFromCollectionName(
|
||||
name,
|
||||
collectionType = 'search-target',
|
||||
eCfg,
|
||||
eCfg = undefined,
|
||||
cwd = process.cwd(),
|
||||
) {
|
||||
let collection;
|
||||
|
|
@ -93,10 +98,10 @@ function pathsArrayFromCollectionName(
|
|||
/**
|
||||
* @param {string} processArgStr
|
||||
* @param {object} [opts]
|
||||
* @returns {Promise<{ code:string; number:string }>}
|
||||
* @returns {Promise<{ code:number; output:string }>}
|
||||
* @throws {Error}
|
||||
*/
|
||||
function spawnProcess(processArgStr, opts) {
|
||||
export function spawnProcess(processArgStr, opts) {
|
||||
const processArgs = processArgStr.split(' ');
|
||||
// eslint-disable-next-line camelcase
|
||||
const proc = child_process.spawn(processArgs[0], processArgs.slice(1), opts);
|
||||
|
|
@ -123,7 +128,7 @@ function spawnProcess(processArgStr, opts) {
|
|||
* @param {string} cwd
|
||||
* @returns {string[]}
|
||||
*/
|
||||
function targetDefault(cwd) {
|
||||
export function targetDefault(cwd) {
|
||||
return [toPosixPath(cwd)];
|
||||
}
|
||||
|
||||
|
|
@ -133,7 +138,11 @@ function targetDefault(cwd) {
|
|||
* @param {string} [matchPattern] base for RegExp
|
||||
* @param {('npm'|'bower')[]} [modes]
|
||||
*/
|
||||
async function appendProjectDependencyPaths(rootPaths, matchPattern, modes = ['npm', 'bower']) {
|
||||
export async function appendProjectDependencyPaths(
|
||||
rootPaths,
|
||||
matchPattern,
|
||||
modes = ['npm', 'bower'],
|
||||
) {
|
||||
let matchFn;
|
||||
if (matchPattern) {
|
||||
if (matchPattern.startsWith('/') && matchPattern.endsWith('/')) {
|
||||
|
|
@ -181,12 +190,13 @@ async function appendProjectDependencyPaths(rootPaths, matchPattern, modes = ['n
|
|||
* Relevant when '--target-dependencies' is supplied.
|
||||
* @param {string[]} searchTargetPaths
|
||||
*/
|
||||
async function installDeps(searchTargetPaths) {
|
||||
export async function installDeps(searchTargetPaths) {
|
||||
for (const targetPath of searchTargetPaths) {
|
||||
LogService.info(`Installing npm dependencies for ${pathLib.basename(targetPath)}`);
|
||||
try {
|
||||
await spawnProcess('npm i --no-progress', { cwd: targetPath });
|
||||
} catch (e) {
|
||||
// @ts-expect-error
|
||||
LogService.error(e);
|
||||
}
|
||||
|
||||
|
|
@ -194,12 +204,13 @@ async function installDeps(searchTargetPaths) {
|
|||
try {
|
||||
await spawnProcess(`bower i --production --force-latest`, { cwd: targetPath });
|
||||
} catch (e) {
|
||||
// @ts-expect-error
|
||||
LogService.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export const _cliHelpersModule = {
|
||||
csToArray,
|
||||
extensionsFromCs,
|
||||
setQueryMethod,
|
||||
|
|
|
|||
|
|
@ -1,25 +1,30 @@
|
|||
import child_process from 'child_process'; // eslint-disable-line camelcase
|
||||
import pathLib from 'path';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import commander from 'commander';
|
||||
import providenceModule from '../program/providence.js';
|
||||
import { LogService } from '../program/core/LogService.js';
|
||||
import { QueryService } from '../program/core/QueryService.js';
|
||||
import { InputDataService } from '../program/core/InputDataService.js';
|
||||
import promptModule from './prompt-analyzer-menu.js';
|
||||
import cliHelpers from './cli-helpers.js';
|
||||
import extendDocsModule from './launch-providence-with-extend-docs.js';
|
||||
import { toPosixPath } from '../program/utils/to-posix-path.js';
|
||||
import { getCurrentDir } from '../program/utils/get-current-dir.mjs';
|
||||
import { dashboardServer } from '../../dashboard/server.mjs';
|
||||
|
||||
const { version } = JSON.parse(
|
||||
fs.readFileSync(pathLib.resolve(getCurrentDir(import.meta.url), '../../package.json'), 'utf8'),
|
||||
);
|
||||
const { extensionsFromCs, setQueryMethod, targetDefault, installDeps } = cliHelpers;
|
||||
import { getCurrentDir } from '../program/utils/get-current-dir.js';
|
||||
import { dashboardServer } from '../../dashboard/server.js';
|
||||
import { _providenceModule } from '../program/providence.js';
|
||||
import { _cliHelpersModule } from './cli-helpers.js';
|
||||
import { _extendDocsModule } from './launch-providence-with-extend-docs.js';
|
||||
import { _promptAnalyzerMenuModule } from './prompt-analyzer-menu.js';
|
||||
|
||||
/**
|
||||
* @param {{cwd?:string; argv: string[]; providenceConf?: object}} cfg
|
||||
* @typedef {import('../../types/index.js').AnalyzerName} AnalyzerName
|
||||
* @typedef {import('../../types/index.js').ProvidenceCliConf} ProvidenceCliConf
|
||||
*/
|
||||
|
||||
const { version } = JSON.parse(
|
||||
fs.readFileSync(path.resolve(getCurrentDir(import.meta.url), '../../package.json'), 'utf8'),
|
||||
);
|
||||
const { extensionsFromCs, setQueryMethod, targetDefault, installDeps } = _cliHelpersModule;
|
||||
|
||||
/**
|
||||
* @param {{cwd?:string; argv?: string[]; providenceConf?: Partial<ProvidenceCliConf>}} cfg
|
||||
*/
|
||||
export async function cli({ cwd = process.cwd(), providenceConf, argv = process.argv }) {
|
||||
/** @type {(value: any) => void} */
|
||||
|
|
@ -44,6 +49,13 @@ export async function cli({ cwd = process.cwd(), providenceConf, argv = process.
|
|||
// TODO: change back to "InputDataService.getExternalConfig();" once full package ESM
|
||||
const externalConfig = providenceConf;
|
||||
|
||||
/**
|
||||
* @param {'search-query'|'feature-query'|'analyzer-query'} searchMode
|
||||
* @param {{regexString: string}} regexSearchOptions
|
||||
* @param {{queryString: string}} featureOptions
|
||||
* @param {{name:AnalyzerName; config:object;promptOptionalConfig:object}} analyzerOptions
|
||||
* @returns
|
||||
*/
|
||||
async function getQueryConfigAndMeta(
|
||||
/* eslint-disable no-shadow */
|
||||
searchMode,
|
||||
|
|
@ -66,11 +78,12 @@ export async function cli({ cwd = process.cwd(), providenceConf, argv = process.
|
|||
} else if (searchMode === 'analyzer-query') {
|
||||
let { name, config } = analyzerOptions;
|
||||
if (!name) {
|
||||
const answers = await promptModule.promptAnalyzerMenu();
|
||||
const answers = await _promptAnalyzerMenuModule.promptAnalyzerMenu();
|
||||
|
||||
name = answers.analyzerName;
|
||||
}
|
||||
if (!config) {
|
||||
const answers = await promptModule.promptAnalyzerConfigMenu(
|
||||
const answers = await _promptAnalyzerMenuModule.promptAnalyzerConfigMenu(
|
||||
name,
|
||||
analyzerOptions.promptOptionalConfig,
|
||||
);
|
||||
|
|
@ -79,7 +92,7 @@ export async function cli({ cwd = process.cwd(), providenceConf, argv = process.
|
|||
// Will get metaConfig from ./providence.conf.js
|
||||
const metaConfig = externalConfig ? externalConfig.metaConfig : {};
|
||||
config = { ...config, metaConfig };
|
||||
queryConfig = QueryService.getQueryConfigFromAnalyzer(name, config);
|
||||
queryConfig = await QueryService.getQueryConfigFromAnalyzer(name, config);
|
||||
queryMethod = 'ast';
|
||||
} else {
|
||||
LogService.error('Please define a feature, analyzer or search');
|
||||
|
|
@ -108,7 +121,7 @@ export async function cli({ cwd = process.cwd(), providenceConf, argv = process.
|
|||
*/
|
||||
let totalSearchTargets;
|
||||
if (commander.targetDependencies !== undefined) {
|
||||
totalSearchTargets = await cliHelpers.appendProjectDependencyPaths(
|
||||
totalSearchTargets = await _cliHelpersModule.appendProjectDependencyPaths(
|
||||
searchTargetPaths,
|
||||
commander.targetDependencies,
|
||||
);
|
||||
|
|
@ -121,7 +134,7 @@ export async function cli({ cwd = process.cwd(), providenceConf, argv = process.
|
|||
// we do not test against ourselves...
|
||||
// -
|
||||
|
||||
providenceModule.providence(queryConfig, {
|
||||
_providenceModule.providence(queryConfig, {
|
||||
gatherFilesConfig: {
|
||||
extensions: commander.extensions,
|
||||
allowlistMode: commander.allowlistMode,
|
||||
|
|
@ -141,11 +154,15 @@ export async function cli({ cwd = process.cwd(), providenceConf, argv = process.
|
|||
skipCheckMatchCompatibility: commander.skipCheckMatchCompatibility,
|
||||
measurePerformance: commander.measurePerf,
|
||||
addSystemPathsInResult: commander.addSystemPaths,
|
||||
fallbackToBabel: commander.fallbackToBabel,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{update:boolean; deps:boolean;createVersionHistory:boolean}} options
|
||||
*/
|
||||
async function manageSearchTargets(options) {
|
||||
const basePath = pathLib.join(__dirname, '../..');
|
||||
const basePath = path.join(__dirname, '../..');
|
||||
if (options.update) {
|
||||
LogService.info('git submodule update --init --recursive');
|
||||
|
||||
|
|
@ -175,7 +192,7 @@ export async function cli({ cwd = process.cwd(), providenceConf, argv = process.
|
|||
'-t, --search-target-paths [targets]',
|
||||
`path(s) to project(s) on which analysis/querying should take place. Requires
|
||||
a list of comma seperated values relative to project root`,
|
||||
v => cliHelpers.pathsArrayFromCs(v, cwd),
|
||||
v => _cliHelpersModule.pathsArrayFromCs(v, cwd),
|
||||
targetDefault(cwd),
|
||||
)
|
||||
.option(
|
||||
|
|
@ -183,29 +200,29 @@ export async function cli({ cwd = process.cwd(), providenceConf, argv = process.
|
|||
`path(s) to project(s) which serve as a reference (applicable for certain analyzers like
|
||||
'match-imports'). Requires a list of comma seperated values relative to
|
||||
project root (like 'node_modules/lion-based-ui, node_modules/lion-based-ui-labs').`,
|
||||
v => cliHelpers.pathsArrayFromCs(v, cwd),
|
||||
v => _cliHelpersModule.pathsArrayFromCs(v, cwd),
|
||||
InputDataService.referenceProjectPaths,
|
||||
)
|
||||
.option('-a, --allowlist [allowlist]', `allowlisted paths, like 'src/**/*, packages/**/*'`, v =>
|
||||
cliHelpers.csToArray(v),
|
||||
_cliHelpersModule.csToArray(v),
|
||||
)
|
||||
.option(
|
||||
'--allowlist-reference [allowlist-reference]',
|
||||
`allowed paths for reference, like 'src/**/*, packages/**/*'`,
|
||||
v => cliHelpers.csToArray(v),
|
||||
v => _cliHelpersModule.csToArray(v),
|
||||
)
|
||||
.option(
|
||||
'--search-target-collection [collection-name]',
|
||||
`path(s) to project(s) which serve as a reference (applicable for certain analyzers like
|
||||
'match-imports'). Should be a collection defined in providence.conf.js as paths relative to
|
||||
project root.`,
|
||||
v => cliHelpers.pathsArrayFromCollectionName(v, 'search-target', externalConfig),
|
||||
v => _cliHelpersModule.pathsArrayFromCollectionName(v, 'search-target', externalConfig),
|
||||
)
|
||||
.option(
|
||||
'--reference-collection [collection-name]',
|
||||
`path(s) to project(s) on which analysis/querying should take place. Should be a collection
|
||||
defined in providence.conf.js as paths relative to project root.`,
|
||||
v => cliHelpers.pathsArrayFromCollectionName(v, 'reference', externalConfig),
|
||||
v => _cliHelpersModule.pathsArrayFromCollectionName(v, 'reference', externalConfig),
|
||||
)
|
||||
.option('--write-log-file', `Writes all logs to 'providence.log' file`)
|
||||
.option(
|
||||
|
|
@ -236,7 +253,11 @@ export async function cli({ cwd = process.cwd(), providenceConf, argv = process.
|
|||
`skips semver checks, handy for forward compatible libs or libs below v1`,
|
||||
)
|
||||
.option('--measure-perf', 'Logs the completion time in seconds')
|
||||
.option('--add-system-paths', 'Adds system paths to results');
|
||||
.option('--add-system-paths', 'Adds system paths to results')
|
||||
.option(
|
||||
'--fallback-to-babel',
|
||||
'Uses babel instead of swc. This will be slower, but guaranteed to be 100% compatible with @babel/generate and @babel/traverse',
|
||||
);
|
||||
|
||||
commander
|
||||
.command('search <regex>')
|
||||
|
|
@ -302,7 +323,7 @@ export async function cli({ cwd = process.cwd(), providenceConf, argv = process.
|
|||
.option(
|
||||
'--output-folder [output-folder]',
|
||||
`This is the file path where the result file "providence-extend-docs-data.json" will be written to`,
|
||||
p => toPosixPath(pathLib.resolve(process.cwd(), p.trim())),
|
||||
p => toPosixPath(path.resolve(process.cwd(), p.trim())),
|
||||
process.cwd(),
|
||||
)
|
||||
.action(options => {
|
||||
|
|
@ -315,7 +336,7 @@ export async function cli({ cwd = process.cwd(), providenceConf, argv = process.
|
|||
process.exit(1);
|
||||
}
|
||||
const prefixCfg = { from: options.prefixFrom, to: options.prefixTo };
|
||||
extendDocsModule
|
||||
_extendDocsModule
|
||||
.launchProvidenceWithExtendDocs({
|
||||
referenceProjectPaths: commander.referencePaths,
|
||||
prefixCfg,
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env node
|
||||
import { cli } from './cli.mjs';
|
||||
import { providenceConfUtil } from '../program/utils/providence-conf-util.mjs';
|
||||
import { cli } from './cli.js';
|
||||
import { providenceConfUtil } from '../program/utils/providence-conf-util.js';
|
||||
|
||||
(async () => {
|
||||
// We need to provide config to cli, until whole package is rewritten as ESM.
|
||||
|
|
@ -1,16 +1,17 @@
|
|||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
const fs = require('fs');
|
||||
const pathLib = require('path');
|
||||
const { performance } = require('perf_hooks');
|
||||
const providenceModule = require('../program/providence.js');
|
||||
const { QueryService } = require('../program/core/QueryService.js');
|
||||
const { InputDataService } = require('../program/core/InputDataService.js');
|
||||
const { LogService } = require('../program/core/LogService.js');
|
||||
const { flatten } = require('./cli-helpers.js');
|
||||
import fs from 'fs';
|
||||
import pathLib from 'path';
|
||||
import { performance } from 'perf_hooks';
|
||||
import { _providenceModule } from '../program/providence.js';
|
||||
import { QueryService } from '../program/core/QueryService.js';
|
||||
import { InputDataService } from '../program/core/InputDataService.js';
|
||||
import { LogService } from '../program/core/LogService.js';
|
||||
import { flatten } from './cli-helpers.js';
|
||||
import MatchPathsAnalyzer from '../program/analyzers/match-paths.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../program/types').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../program/types').GatherFilesConfig} GatherFilesConfig
|
||||
* @typedef {import('../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../types/index.js').GatherFilesConfig} GatherFilesConfig
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -24,7 +25,7 @@ const { flatten } = require('./cli-helpers.js');
|
|||
* }} opts
|
||||
* @returns
|
||||
*/
|
||||
async function getExtendDocsResults({
|
||||
export async function getExtendDocsResults({
|
||||
referenceProjectPaths,
|
||||
prefixCfg,
|
||||
extensions,
|
||||
|
|
@ -34,8 +35,8 @@ async function getExtendDocsResults({
|
|||
}) {
|
||||
const monoPkgs = InputDataService.getMonoRepoPackages(cwd);
|
||||
|
||||
const results = await providenceModule.providence(
|
||||
QueryService.getQueryConfigFromAnalyzer('match-paths', { prefix: prefixCfg }),
|
||||
const results = await _providenceModule.providence(
|
||||
await QueryService.getQueryConfigFromAnalyzer(MatchPathsAnalyzer, { prefix: prefixCfg }),
|
||||
{
|
||||
gatherFilesConfig: {
|
||||
extensions: extensions || /** @type {GatherFilesConfig['extensions']} */ (['.js']),
|
||||
|
|
@ -98,7 +99,11 @@ async function getExtendDocsResults({
|
|||
return queryOutputs;
|
||||
}
|
||||
|
||||
async function launchProvidenceWithExtendDocs({
|
||||
/**
|
||||
*
|
||||
* @param {*} opts
|
||||
*/
|
||||
export async function launchProvidenceWithExtendDocs({
|
||||
referenceProjectPaths,
|
||||
prefixCfg,
|
||||
outputFolder,
|
||||
|
|
@ -134,7 +139,7 @@ async function launchProvidenceWithExtendDocs({
|
|||
LogService.info(`"extend-docs" completed in ${Math.round((t1 - t0) / 1000)} seconds`);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export const _extendDocsModule = {
|
||||
launchProvidenceWithExtendDocs,
|
||||
getExtendDocsResults,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,23 +1,31 @@
|
|||
const fs = require('fs');
|
||||
const pathLib = require('path');
|
||||
const inquirer = require('inquirer');
|
||||
const { default: traverse } = require('@babel/traverse');
|
||||
const { InputDataService } = require('../program/core/InputDataService.js');
|
||||
const { AstService } = require('../program/core/AstService.js');
|
||||
const { LogService } = require('../program/core/LogService.js');
|
||||
const JsdocCommentParser = require('../program/utils/jsdoc-comment-parser.js');
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import inquirer from 'inquirer';
|
||||
import traverse from '@babel/traverse';
|
||||
import { InputDataService } from '../program/core/InputDataService.js';
|
||||
import { AstService } from '../program/core/AstService.js';
|
||||
import { LogService } from '../program/core/LogService.js';
|
||||
import JsdocCommentParser from '../program/utils/jsdoc-comment-parser.js';
|
||||
import { getCurrentDir } from '../program/utils/get-current-dir.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../../types/index.js').TargetDepsObj} TargetDepsObj
|
||||
* @typedef {import('../../types/index.js').TargetOrRefCollectionsObj} TargetOrRefCollectionsObj
|
||||
* @typedef {import('../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../types/index.js').AnalyzerName} AnalyzerName
|
||||
*/
|
||||
|
||||
/**
|
||||
* Extracts name, defaultValue, optional, type, desc from JsdocCommentParser.parse method
|
||||
* result
|
||||
* @param {string[]} jsdoc
|
||||
* @returns {{ name:string, defaultValue:string, optional:boolean, type:string, desc:string }}
|
||||
* @param {{tagName:string;tagValue:string}[]} jsdoc
|
||||
* @returns {{ name:string, defaultValue:string, optional:boolean, type:string, desc:string }[]}
|
||||
*/
|
||||
function getPropsFromParsedJsDoc(jsdoc) {
|
||||
const jsdocProps = jsdoc.filter(p => p.tagName === '@property');
|
||||
const options = jsdocProps.map(({ tagValue }) => {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const [_, type, nameOptionalDefault, desc] = tagValue.match(/\{(.*)\}\s*([^\s]*)\s*(.*)/);
|
||||
const [_, type, nameOptionalDefault, desc] = tagValue.match(/\{(.*)\}\s*([^\s]*)\s*(.*)/) || [];
|
||||
let nameDefault = nameOptionalDefault;
|
||||
let optional = false;
|
||||
if (nameOptionalDefault.startsWith('[') && nameOptionalDefault.endsWith(']')) {
|
||||
|
|
@ -30,21 +38,26 @@ function getPropsFromParsedJsDoc(jsdoc) {
|
|||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {PathFromSystemRoot} file
|
||||
*/
|
||||
function getAnalyzerOptions(file) {
|
||||
const code = fs.readFileSync(file, 'utf8');
|
||||
const ast = AstService.getAst(code, 'babel', { filePath: file });
|
||||
const babelAst = AstService.getAst(code, 'swc-to-babel', { filePath: file });
|
||||
|
||||
let commentNode;
|
||||
traverse(ast, {
|
||||
traverse.default(babelAst, {
|
||||
// eslint-disable-next-line no-shadow
|
||||
VariableDeclaration(path) {
|
||||
if (!path.node.leadingComments) {
|
||||
VariableDeclaration(astPath) {
|
||||
const { node } = astPath;
|
||||
if (!node.leadingComments) {
|
||||
return;
|
||||
}
|
||||
const decls = path.node.declarations || [];
|
||||
decls.forEach(decl => {
|
||||
if (decl && decl.id && decl.id.name === 'cfg') {
|
||||
[commentNode] = path.node.leadingComments;
|
||||
node.declarations.forEach(decl => {
|
||||
// @ts-expect-error
|
||||
if (decl?.id?.name === 'cfg') {
|
||||
// eslint-disable-next-line prefer-destructuring
|
||||
commentNode = node.leadingComments?.[0];
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
@ -57,20 +70,33 @@ function getAnalyzerOptions(file) {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
function gatherAnalyzers(dir, getConfigOptions) {
|
||||
/**
|
||||
* @param {PathFromSystemRoot} dir
|
||||
* @param {boolean} [shouldGetOptions]
|
||||
*/
|
||||
function gatherAnalyzers(dir, shouldGetOptions) {
|
||||
return InputDataService.gatherFilesFromDir(dir, { depth: 0 }).map(file => {
|
||||
const analyzerObj = { file, name: pathLib.basename(file, '.js') };
|
||||
if (getConfigOptions) {
|
||||
const analyzerObj = { file, name: path.basename(file, '.js') };
|
||||
if (shouldGetOptions) {
|
||||
analyzerObj.options = getAnalyzerOptions(file);
|
||||
}
|
||||
return analyzerObj;
|
||||
});
|
||||
}
|
||||
|
||||
async function promptAnalyzerConfigMenu(
|
||||
/**
|
||||
*
|
||||
* @param {AnalyzerName} analyzerName
|
||||
* @param {*} promptOptionalConfig
|
||||
* @param {PathFromSystemRoot} [dir]
|
||||
* @returns
|
||||
*/
|
||||
export async function promptAnalyzerConfigMenu(
|
||||
analyzerName,
|
||||
promptOptionalConfig,
|
||||
dir = pathLib.resolve(__dirname, '../program/analyzers'),
|
||||
dir = /** @type {PathFromSystemRoot} */ (
|
||||
path.resolve(getCurrentDir(import.meta.url), '../program/analyzers')
|
||||
),
|
||||
) {
|
||||
const menuOptions = gatherAnalyzers(dir, true);
|
||||
const analyzer = menuOptions.find(o => o.name === analyzerName);
|
||||
|
|
@ -112,7 +138,11 @@ async function promptAnalyzerConfigMenu(
|
|||
};
|
||||
}
|
||||
|
||||
async function promptAnalyzerMenu(dir = pathLib.resolve(__dirname, '../program/analyzers')) {
|
||||
export async function promptAnalyzerMenu(
|
||||
dir = /** @type {PathFromSystemRoot} */ (
|
||||
path.resolve(getCurrentDir(import.meta.url), '../program/analyzers')
|
||||
),
|
||||
) {
|
||||
const menuOptions = gatherAnalyzers(dir);
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
|
|
@ -127,7 +157,7 @@ async function promptAnalyzerMenu(dir = pathLib.resolve(__dirname, '../program/a
|
|||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export const _promptAnalyzerMenuModule = {
|
||||
promptAnalyzerMenu,
|
||||
promptAnalyzerConfigMenu,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
const { providence } = require('./program/providence.js');
|
||||
const { QueryService } = require('./program/core/QueryService.js');
|
||||
const { LogService } = require('./program/core/LogService.js');
|
||||
const { InputDataService } = require('./program/core/InputDataService.js');
|
||||
const { AstService } = require('./program/core/AstService.js');
|
||||
|
||||
module.exports = { providence, QueryService, LogService, InputDataService, AstService };
|
||||
export { providence } from './program/providence.js';
|
||||
export { QueryService } from './program/core/QueryService.js';
|
||||
export { LogService } from './program/core/LogService.js';
|
||||
export { InputDataService } from './program/core/InputDataService.js';
|
||||
export { AstService } from './program/core/AstService.js';
|
||||
|
|
|
|||
|
|
@ -1,24 +1,27 @@
|
|||
/* eslint-disable no-shadow, no-param-reassign */
|
||||
const pathLib = require('path');
|
||||
const t = require('@babel/types');
|
||||
const { default: traverse } = require('@babel/traverse');
|
||||
const { Analyzer } = require('../core/Analyzer.js');
|
||||
const { trackDownIdentifierFromScope } = require('./helpers/track-down-identifier.js');
|
||||
import pathLib from 'path';
|
||||
import t from '@babel/types';
|
||||
import babelTraverse from '@babel/traverse';
|
||||
import { Analyzer } from '../core/Analyzer.js';
|
||||
import { trackDownIdentifierFromScope } from './helpers/track-down-identifier.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('@babel/types').File} File
|
||||
* @typedef {import('@babel/types').ClassMethod} ClassMethod
|
||||
* @typedef {import('../types/analyzers').FindClassesAnalyzerOutput} FindClassesAnalyzerOutput
|
||||
* @typedef {import('../types/analyzers').FindClassesAnalyzerOutputEntry} FindClassesAnalyzerOutputEntry
|
||||
* @typedef {import('../types/analyzers').FindClassesConfig} FindClassesConfig
|
||||
* @typedef {import('@babel/traverse').NodePath} NodePath
|
||||
* @typedef {import('../../../types/index.js').AnalyzerName} AnalyzerName
|
||||
* @typedef {import('../../../types/index.js').FindClassesAnalyzerResult} FindClassesAnalyzerResult
|
||||
* @typedef {import('../../../types/index.js').FindClassesAnalyzerOutputFile} FindClassesAnalyzerOutputFile
|
||||
* @typedef {import('../../../types/index.js').FindClassesAnalyzerEntry} FindClassesAnalyzerEntry
|
||||
* @typedef {import('../../../types/index.js').FindClassesConfig} FindClassesConfig
|
||||
*/
|
||||
|
||||
/**
|
||||
* Finds import specifiers and sources
|
||||
* @param {File} ast
|
||||
* @param {File} babelAst
|
||||
* @param {string} fullCurrentFilePath the file being currently processed
|
||||
*/
|
||||
async function findMembersPerAstEntry(ast, fullCurrentFilePath, projectPath) {
|
||||
async function findMembersPerAstEntry(babelAst, fullCurrentFilePath, projectPath) {
|
||||
// The transformed entry
|
||||
const classesFound = [];
|
||||
/**
|
||||
|
|
@ -82,18 +85,18 @@ async function findMembersPerAstEntry(ast, fullCurrentFilePath, projectPath) {
|
|||
|
||||
/**
|
||||
*
|
||||
* @param {*} path
|
||||
* @param {{isMixin?:boolean}} param1
|
||||
* @param {NodePath} astPath
|
||||
* @param {{isMixin?:boolean}} opts
|
||||
*/
|
||||
async function traverseClass(path, { isMixin = false } = {}) {
|
||||
async function traverseClass(astPath, { isMixin = false } = {}) {
|
||||
const classRes = {};
|
||||
classRes.name = path.node.id && path.node.id.name;
|
||||
classRes.name = astPath.node.id && astPath.node.id.name;
|
||||
classRes.isMixin = Boolean(isMixin);
|
||||
if (path.node.superClass) {
|
||||
if (astPath.node.superClass) {
|
||||
const superClasses = [];
|
||||
|
||||
// Add all Identifier names
|
||||
let parent = path.node.superClass;
|
||||
let parent = astPath.node.superClass;
|
||||
while (parent.type === 'CallExpression') {
|
||||
superClasses.push({ name: parent.callee.name, isMixin: true });
|
||||
// As long as we are a CallExpression, we will have a parent
|
||||
|
|
@ -103,15 +106,15 @@ async function findMembersPerAstEntry(ast, fullCurrentFilePath, projectPath) {
|
|||
superClasses.push({ name: parent.name, isMixin: false });
|
||||
|
||||
// For all found superclasses, track down their root location.
|
||||
// This will either result in a local, relative path in the project,
|
||||
// or an external path like '@lion/overlays'. In the latter case,
|
||||
// This will either result in a local, relative astPath in the project,
|
||||
// or an external astPath like '@lion/overlays'. In the latter case,
|
||||
// tracking down will halt and should be done when there is access to
|
||||
// the external repo... (similar to how 'match-imports' analyzer works)
|
||||
|
||||
for (const classObj of superClasses) {
|
||||
// Finds the file that holds the declaration of the import
|
||||
classObj.rootFile = await trackDownIdentifierFromScope(
|
||||
path,
|
||||
astPath,
|
||||
classObj.name,
|
||||
fullCurrentFilePath,
|
||||
projectPath,
|
||||
|
|
@ -127,18 +130,18 @@ async function findMembersPerAstEntry(ast, fullCurrentFilePath, projectPath) {
|
|||
methods: [],
|
||||
};
|
||||
|
||||
path.traverse({
|
||||
ClassMethod(path) {
|
||||
// if (isBlacklisted(path)) {
|
||||
astPath.traverse({
|
||||
ClassMethod(astPath) {
|
||||
// if (isBlacklisted(astPath)) {
|
||||
// return;
|
||||
// }
|
||||
if (isStaticProperties(path)) {
|
||||
if (isStaticProperties(astPath)) {
|
||||
let hasFoundTopLvlObjExpr = false;
|
||||
path.traverse({
|
||||
ObjectExpression(path) {
|
||||
astPath.traverse({
|
||||
ObjectExpression(astPath) {
|
||||
if (hasFoundTopLvlObjExpr) return;
|
||||
hasFoundTopLvlObjExpr = true;
|
||||
path.node.properties.forEach(objectProperty => {
|
||||
astPath.node.properties.forEach(objectProperty => {
|
||||
if (!t.isProperty(objectProperty)) {
|
||||
// we can also have a SpreadElement
|
||||
return;
|
||||
|
|
@ -156,19 +159,19 @@ async function findMembersPerAstEntry(ast, fullCurrentFilePath, projectPath) {
|
|||
}
|
||||
|
||||
const methodRes = {};
|
||||
const { name } = path.node.key;
|
||||
const { name } = astPath.node.key;
|
||||
methodRes.name = name;
|
||||
methodRes.accessType = computeAccessType(name);
|
||||
|
||||
if (path.node.kind === 'set' || path.node.kind === 'get') {
|
||||
if (path.node.static) {
|
||||
if (astPath.node.kind === 'set' || astPath.node.kind === 'get') {
|
||||
if (astPath.node.static) {
|
||||
methodRes.static = true;
|
||||
}
|
||||
methodRes.kind = [...(methodRes.kind || []), path.node.kind];
|
||||
methodRes.kind = [...(methodRes.kind || []), astPath.node.kind];
|
||||
// Merge getter/setters into one
|
||||
const found = classRes.members.props.find(p => p.name === name);
|
||||
if (found) {
|
||||
found.kind = [...(found.kind || []), path.node.kind];
|
||||
found.kind = [...(found.kind || []), astPath.node.kind];
|
||||
} else {
|
||||
classRes.members.props.push(methodRes);
|
||||
}
|
||||
|
|
@ -182,17 +185,18 @@ async function findMembersPerAstEntry(ast, fullCurrentFilePath, projectPath) {
|
|||
}
|
||||
|
||||
const classesToTraverse = [];
|
||||
traverse(ast, {
|
||||
ClassDeclaration(path) {
|
||||
classesToTraverse.push({ path, isMixin: false });
|
||||
|
||||
babelTraverse.default(babelAst, {
|
||||
ClassDeclaration(astPath) {
|
||||
classesToTraverse.push({ astPath, isMixin: false });
|
||||
},
|
||||
ClassExpression(path) {
|
||||
classesToTraverse.push({ path, isMixin: true });
|
||||
ClassExpression(astPath) {
|
||||
classesToTraverse.push({ astPath, isMixin: true });
|
||||
},
|
||||
});
|
||||
|
||||
for (const klass of classesToTraverse) {
|
||||
await traverseClass(klass.path, { isMixin: klass.isMixin });
|
||||
await traverseClass(klass.astPath, { isMixin: klass.isMixin });
|
||||
}
|
||||
|
||||
return classesFound;
|
||||
|
|
@ -218,24 +222,20 @@ async function findMembersPerAstEntry(ast, fullCurrentFilePath, projectPath) {
|
|||
// });
|
||||
// }
|
||||
|
||||
class FindClassesAnalyzer extends Analyzer {
|
||||
static get analyzerName() {
|
||||
return 'find-classes';
|
||||
}
|
||||
export default class FindClassesAnalyzer extends Analyzer {
|
||||
/** @type {AnalyzerName} */
|
||||
static analyzerName = 'find-classes';
|
||||
|
||||
/** @type {'babel'|'swc-to-babel'} */
|
||||
requiredAst = 'babel';
|
||||
|
||||
/**
|
||||
* @desc Will find all public members (properties (incl. getter/setters)/functions) of a class and
|
||||
* 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 {FindClassesConfig} customConfig
|
||||
* @param {Partial<FindClassesConfig>} customConfig
|
||||
*/
|
||||
async execute(customConfig = {}) {
|
||||
/** @type {FindClassesConfig} */
|
||||
const cfg = {
|
||||
gatherFilesConfig: {},
|
||||
targetProjectPath: null,
|
||||
metaConfig: null,
|
||||
...customConfig,
|
||||
};
|
||||
async execute(customConfig) {
|
||||
const cfg = customConfig;
|
||||
|
||||
/**
|
||||
* Prepare
|
||||
|
|
@ -263,5 +263,3 @@ class FindClassesAnalyzer extends Analyzer {
|
|||
return this._finalize(queryOutput, cfg);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FindClassesAnalyzer;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,14 @@
|
|||
const pathLib = require('path');
|
||||
const t = require('@babel/types');
|
||||
const { default: traverse } = require('@babel/traverse');
|
||||
const { Analyzer } = require('../core/Analyzer.js');
|
||||
const { trackDownIdentifierFromScope } = require('./helpers/track-down-identifier.js');
|
||||
import path from 'path';
|
||||
import t from '@babel/types';
|
||||
import babelTraverse from '@babel/traverse';
|
||||
import { Analyzer } from '../core/Analyzer.js';
|
||||
import { trackDownIdentifierFromScope } from './helpers/track-down-identifier.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('@babel/types').File} File
|
||||
* @typedef {import('../../../types/index.js').AnalyzerName} AnalyzerName
|
||||
* @typedef {import('../../../types/index.js').FindCustomelementsConfig} FindCustomelementsConfig
|
||||
*/
|
||||
|
||||
function cleanup(transformedEntry) {
|
||||
transformedEntry.forEach(definitionObj => {
|
||||
|
|
@ -15,11 +21,11 @@ function cleanup(transformedEntry) {
|
|||
}
|
||||
|
||||
async function trackdownRoot(transformedEntry, relativePath, projectPath) {
|
||||
const fullCurrentFilePath = pathLib.resolve(projectPath, relativePath);
|
||||
const fullCurrentFilePath = path.resolve(projectPath, relativePath);
|
||||
|
||||
for (const definitionObj of transformedEntry) {
|
||||
const rootFile = await trackDownIdentifierFromScope(
|
||||
definitionObj.__tmp.path,
|
||||
definitionObj.__tmp.astPath,
|
||||
definitionObj.constructorIdentifier,
|
||||
fullCurrentFilePath,
|
||||
projectPath,
|
||||
|
|
@ -31,19 +37,19 @@ async function trackdownRoot(transformedEntry, relativePath, projectPath) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @desc Finds import specifiers and sources
|
||||
* @param {BabelAst} ast
|
||||
* Finds import specifiers and sources
|
||||
* @param {File} babelAst
|
||||
*/
|
||||
function findCustomElementsPerAstEntry(ast) {
|
||||
function findCustomElementsPerAstFile(babelAst) {
|
||||
const definitions = [];
|
||||
traverse(ast, {
|
||||
CallExpression(path) {
|
||||
babelTraverse.default(babelAst, {
|
||||
CallExpression(astPath) {
|
||||
let found = false;
|
||||
// Doing it like this we detect 'customElements.define()',
|
||||
// but also 'window.customElements.define()'
|
||||
path.traverse({
|
||||
astPath.traverse({
|
||||
MemberExpression(memberPath) {
|
||||
if (memberPath.parentPath !== path) {
|
||||
if (memberPath.parentPath !== astPath) {
|
||||
return;
|
||||
}
|
||||
const { node } = memberPath;
|
||||
|
|
@ -64,29 +70,31 @@ function findCustomElementsPerAstEntry(ast) {
|
|||
let tagName;
|
||||
let constructorIdentifier;
|
||||
|
||||
if (t.isLiteral(path.node.arguments[0])) {
|
||||
tagName = path.node.arguments[0].value;
|
||||
if (t.isLiteral(astPath.node.arguments[0])) {
|
||||
tagName = astPath.node.arguments[0].value;
|
||||
} else {
|
||||
// No Literal found. For now, we only mark them as '[variable]'
|
||||
tagName = '[variable]';
|
||||
}
|
||||
if (path.node.arguments[1].type === 'Identifier') {
|
||||
constructorIdentifier = path.node.arguments[1].name;
|
||||
if (astPath.node.arguments[1].type === 'Identifier') {
|
||||
constructorIdentifier = astPath.node.arguments[1].name;
|
||||
} else {
|
||||
// We assume customElements.define('my-el', class extends HTMLElement {...})
|
||||
constructorIdentifier = '[inline]';
|
||||
}
|
||||
definitions.push({ tagName, constructorIdentifier, __tmp: { path } });
|
||||
definitions.push({ tagName, constructorIdentifier, __tmp: { astPath } });
|
||||
}
|
||||
},
|
||||
});
|
||||
return definitions;
|
||||
}
|
||||
|
||||
class FindCustomelementsAnalyzer extends Analyzer {
|
||||
static get analyzerName() {
|
||||
return 'find-customelements';
|
||||
}
|
||||
export default class FindCustomelementsAnalyzer extends Analyzer {
|
||||
/** @type {AnalyzerName} */
|
||||
static analyzerName = 'find-customelements';
|
||||
|
||||
/** @type {'babel'|'swc-to-babel'} */
|
||||
requiredAst = 'swc-to-babel';
|
||||
|
||||
/**
|
||||
* Finds export specifiers and sources
|
||||
|
|
@ -110,9 +118,9 @@ class FindCustomelementsAnalyzer extends Analyzer {
|
|||
* Traverse
|
||||
*/
|
||||
const projectPath = cfg.targetProjectPath;
|
||||
const queryOutput = await this._traverse(async (ast, { relativePath }) => {
|
||||
let transformedEntry = findCustomElementsPerAstEntry(ast);
|
||||
transformedEntry = await trackdownRoot(transformedEntry, relativePath, projectPath);
|
||||
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 };
|
||||
});
|
||||
|
|
@ -123,5 +131,3 @@ class FindCustomelementsAnalyzer extends Analyzer {
|
|||
return this._finalize(queryOutput, cfg);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FindCustomelementsAnalyzer;
|
||||
|
|
|
|||
|
|
@ -1,29 +1,33 @@
|
|||
/* eslint-disable no-shadow, no-param-reassign */
|
||||
const pathLib = require('path');
|
||||
const { default: traverse } = require('@babel/traverse');
|
||||
const { Analyzer } = require('../core/Analyzer.js');
|
||||
const { trackDownIdentifier } = require('./helpers/track-down-identifier.js');
|
||||
const { normalizeSourcePaths } = require('./helpers/normalize-source-paths.js');
|
||||
const { getReferencedDeclaration } = require('../utils/get-source-code-fragment-of-declaration.js');
|
||||
|
||||
const { LogService } = require('../core/LogService.js');
|
||||
import pathLib from 'path';
|
||||
import babelTraverse from '@babel/traverse';
|
||||
import { Analyzer } from '../core/Analyzer.js';
|
||||
import { trackDownIdentifier } from './helpers/track-down-identifier.js';
|
||||
import { normalizeSourcePaths } from './helpers/normalize-source-paths.js';
|
||||
import { getReferencedDeclaration } from '../utils/get-source-code-fragment-of-declaration.js';
|
||||
import { LogService } from '../core/LogService.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('@babel/types').File} File
|
||||
* @typedef {import('@babel/types').Node} Node
|
||||
* @typedef {import('../../../types/index.js').AnalyzerName} AnalyzerName
|
||||
* @typedef {import('../../../types/index.js').FindExportsAnalyzerResult} FindExportsAnalyzerResult
|
||||
* @typedef {import('../../../types/index.js').FindExportsAnalyzerEntry} FindExportsAnalyzerEntry
|
||||
* @typedef {import('../../../types/index.js').PathRelativeFromProjectRoot} PathRelativeFromProjectRoot
|
||||
* @typedef {import('./helpers/track-down-identifier.js').RootFile} RootFile
|
||||
* @typedef {object} RootFileMapEntry
|
||||
* @typedef {string} currentFileSpecifier this is the local name in the file we track from
|
||||
* @typedef {RootFile} rootFile contains file(filePath) and specifier
|
||||
* @typedef {RootFileMapEntry[]} RootFileMap
|
||||
*
|
||||
* @typedef {{ exportSpecifiers:string[]; localMap: object; source:string, __tmp: { path:string } }} FindExportsSpecifierObj
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {FindExportsSpecifierObj[]} transformedEntry
|
||||
* @param {FindExportsSpecifierObj[]} transformedFile
|
||||
*/
|
||||
async function trackdownRoot(transformedEntry, relativePath, projectPath) {
|
||||
async function trackdownRoot(transformedFile, relativePath, projectPath) {
|
||||
const fullCurrentFilePath = pathLib.resolve(projectPath, relativePath);
|
||||
for (const specObj of transformedEntry) {
|
||||
for (const specObj of transformedFile) {
|
||||
/** @type {RootFileMap} */
|
||||
const rootFileMap = [];
|
||||
if (specObj.exportSpecifiers[0] === '[file]') {
|
||||
|
|
@ -79,16 +83,16 @@ async function trackdownRoot(transformedEntry, relativePath, projectPath) {
|
|||
}
|
||||
specObj.rootFileMap = rootFileMap;
|
||||
}
|
||||
return transformedEntry;
|
||||
return transformedFile;
|
||||
}
|
||||
|
||||
function cleanup(transformedEntry) {
|
||||
transformedEntry.forEach(specObj => {
|
||||
function cleanup(transformedFile) {
|
||||
transformedFile.forEach(specObj => {
|
||||
if (specObj.__tmp) {
|
||||
delete specObj.__tmp;
|
||||
}
|
||||
});
|
||||
return transformedEntry;
|
||||
return transformedFile;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -110,7 +114,7 @@ function getExportSpecifiers(node) {
|
|||
let specifier;
|
||||
if (s.exported) {
|
||||
// { x as y }
|
||||
specifier = s.exported.name;
|
||||
specifier = s.exported.name === 'default' ? '[default]' : s.exported.name;
|
||||
} else {
|
||||
// { x }
|
||||
specifier = s.local.name;
|
||||
|
|
@ -142,22 +146,22 @@ const isImportingSpecifier = pathOrNode =>
|
|||
|
||||
/**
|
||||
* Finds import specifiers and sources for a given ast result
|
||||
* @param {File} ast
|
||||
* @param {File} babelAst
|
||||
* @param {FindExportsConfig} config
|
||||
*/
|
||||
function findExportsPerAstEntry(ast, { skipFileImports }) {
|
||||
LogService.debug(`Analyzer "find-exports": started findExportsPerAstEntry method`);
|
||||
function findExportsPerAstFile(babelAst, { skipFileImports }) {
|
||||
LogService.debug(`Analyzer "find-exports": started findExportsPerAstFile method`);
|
||||
|
||||
// Visit AST...
|
||||
|
||||
/** @type {FindExportsSpecifierObj} */
|
||||
const transformedEntry = [];
|
||||
/** @type {FindExportsSpecifierObj[]} */
|
||||
const transformedFile = [];
|
||||
// Unfortunately, we cannot have async functions in babel traverse.
|
||||
// Therefore, we store a temp reference to path that we use later for
|
||||
// async post processing (tracking down original export Identifier)
|
||||
let globalScopeBindings;
|
||||
|
||||
traverse(ast, {
|
||||
babelTraverse.default(babelAst, {
|
||||
Program: {
|
||||
enter(babelPath) {
|
||||
const body = babelPath.get('body');
|
||||
|
|
@ -174,7 +178,7 @@ function findExportsPerAstEntry(ast, { skipFileImports }) {
|
|||
if (path.node.assertions?.length) {
|
||||
entry.assertionType = path.node.assertions[0].value?.value;
|
||||
}
|
||||
transformedEntry.push(entry);
|
||||
transformedFile.push(entry);
|
||||
},
|
||||
ExportDefaultDeclaration(defaultExportPath) {
|
||||
const exportSpecifiers = ['[default]'];
|
||||
|
|
@ -190,26 +194,28 @@ function findExportsPerAstEntry(ast, { skipFileImports }) {
|
|||
source = importOrDeclPath.parentPath.node.source.value;
|
||||
}
|
||||
}
|
||||
transformedEntry.push({ exportSpecifiers, source, __tmp: { path: defaultExportPath } });
|
||||
transformedFile.push({ exportSpecifiers, source, __tmp: { path: defaultExportPath } });
|
||||
},
|
||||
});
|
||||
|
||||
if (!skipFileImports) {
|
||||
// Always add an entry for just the file 'relativePath'
|
||||
// (since this also can be imported directly from a search target project)
|
||||
transformedEntry.push({
|
||||
transformedFile.push({
|
||||
exportSpecifiers: ['[file]'],
|
||||
// source: relativePath,
|
||||
});
|
||||
}
|
||||
|
||||
return transformedEntry;
|
||||
return transformedFile;
|
||||
}
|
||||
|
||||
class FindExportsAnalyzer extends Analyzer {
|
||||
static get analyzerName() {
|
||||
return 'find-exports';
|
||||
}
|
||||
export default class FindExportsAnalyzer extends Analyzer {
|
||||
/** @type {AnalyzerName} */
|
||||
static analyzerName = 'find-exports';
|
||||
|
||||
/** @type {'babel'|'swc-to-babel'} */
|
||||
requiredAst = 'swc-to-babel';
|
||||
|
||||
/**
|
||||
* Finds export specifiers and sources
|
||||
|
|
@ -243,13 +249,13 @@ class FindExportsAnalyzer extends Analyzer {
|
|||
const projectPath = cfg.targetProjectPath;
|
||||
|
||||
const traverseEntryFn = async (ast, { relativePath }) => {
|
||||
let transformedEntry = findExportsPerAstEntry(ast, cfg);
|
||||
let transformedFile = findExportsPerAstFile(ast, cfg);
|
||||
|
||||
transformedEntry = await normalizeSourcePaths(transformedEntry, relativePath, projectPath);
|
||||
transformedEntry = await trackdownRoot(transformedEntry, relativePath, projectPath);
|
||||
transformedEntry = cleanup(transformedEntry);
|
||||
transformedFile = await normalizeSourcePaths(transformedFile, relativePath, projectPath);
|
||||
transformedFile = await trackdownRoot(transformedFile, relativePath, projectPath);
|
||||
transformedFile = cleanup(transformedFile);
|
||||
|
||||
return { result: transformedEntry };
|
||||
return { result: transformedFile };
|
||||
};
|
||||
|
||||
const queryOutput = await this._traverse({
|
||||
|
|
@ -264,5 +270,3 @@ class FindExportsAnalyzer extends Analyzer {
|
|||
return this._finalize(queryOutput, cfg);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FindExportsAnalyzer;
|
||||
|
|
|
|||
|
|
@ -1,17 +1,18 @@
|
|||
/* eslint-disable no-shadow, no-param-reassign */
|
||||
const { default: traverse } = require('@babel/traverse');
|
||||
const { isRelativeSourcePath } = require('../utils/relative-source-path.js');
|
||||
const { normalizeSourcePaths } = require('./helpers/normalize-source-paths.js');
|
||||
const { Analyzer } = require('../core/Analyzer.js');
|
||||
const { LogService } = require('../core/LogService.js');
|
||||
import babelTraverse from '@babel/traverse';
|
||||
import { isRelativeSourcePath } from '../utils/relative-source-path.js';
|
||||
import { normalizeSourcePaths } from './helpers/normalize-source-paths.js';
|
||||
import { Analyzer } from '../core/Analyzer.js';
|
||||
import { LogService } from '../core/LogService.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('@babel/types').File} File
|
||||
* @typedef {import('@babel/types').Node} Node *
|
||||
* @typedef {import('../types/core').AnalyzerName} AnalyzerName
|
||||
* @typedef {import('../types/analyzers').FindImportsAnalyzerResult} FindImportsAnalyzerResult
|
||||
* @typedef {import('../types/analyzers').FindImportsAnalyzerEntry} FindImportsAnalyzerEntry
|
||||
* @typedef {import('../types/core').PathRelativeFromProjectRoot} PathRelativeFromProjectRoot
|
||||
* @typedef {import('@babel/types').Node} Node
|
||||
* @typedef {import('../../../types/index.js').AnalyzerName} AnalyzerName
|
||||
* @typedef {import('../../../types/index.js').AnalyzerConfig} AnalyzerConfig
|
||||
* @typedef {import('../../../types/index.js').FindImportsAnalyzerResult} FindImportsAnalyzerResult
|
||||
* @typedef {import('../../../types/index.js').FindImportsAnalyzerEntry} FindImportsAnalyzerEntry
|
||||
* @typedef {import('../../../types/index.js').PathRelativeFromProjectRoot} PathRelativeFromProjectRoot
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -36,7 +37,11 @@ const /** @type {AnalyzerConfig} */ options = {
|
|||
*/
|
||||
function getImportOrReexportsSpecifiers(node) {
|
||||
return node.specifiers.map(s => {
|
||||
if (s.type === 'ImportDefaultSpecifier' || s.type === 'ExportDefaultSpecifier') {
|
||||
if (
|
||||
s.type === 'ImportDefaultSpecifier' ||
|
||||
s.type === 'ExportDefaultSpecifier' ||
|
||||
(s.type === 'ExportSpecifier' && s.exported?.name === 'default')
|
||||
) {
|
||||
return '[default]';
|
||||
}
|
||||
if (s.type === 'ImportNamespaceSpecifier' || s.type === 'ExportNamespaceSpecifier') {
|
||||
|
|
@ -54,41 +59,42 @@ function getImportOrReexportsSpecifiers(node) {
|
|||
|
||||
/**
|
||||
* Finds import specifiers and sources
|
||||
* @param {File} ast
|
||||
* @param {File} babelAst
|
||||
*/
|
||||
function findImportsPerAstEntry(ast) {
|
||||
LogService.debug(`Analyzer "find-imports": started findImportsPerAstEntry method`);
|
||||
function findImportsPerAstFile(babelAst, context) {
|
||||
LogService.debug(`Analyzer "find-imports": started findImportsPerAstFile method`);
|
||||
|
||||
// https://github.com/babel/babel/blob/672a58660f0b15691c44582f1f3fdcdac0fa0d2f/packages/babel-core/src/transformation/index.ts#L110
|
||||
// Visit AST...
|
||||
/** @type {Partial<FindImportsAnalyzerEntry>[]} */
|
||||
const transformedEntry = [];
|
||||
traverse(ast, {
|
||||
const transformedFile = [];
|
||||
babelTraverse.default(babelAst, {
|
||||
ImportDeclaration(path) {
|
||||
const importSpecifiers = getImportOrReexportsSpecifiers(path.node);
|
||||
if (!importSpecifiers.length) {
|
||||
importSpecifiers.push('[file]'); // apparently, there was just a file import
|
||||
}
|
||||
const source = path.node.source.value;
|
||||
const entry = { importSpecifiers, source };
|
||||
const entry = /** @type {Partial<FindImportsAnalyzerEntry>} */ ({ importSpecifiers, source });
|
||||
if (path.node.assertions?.length) {
|
||||
entry.assertionType = path.node.assertions[0].value?.value;
|
||||
}
|
||||
transformedEntry.push(entry);
|
||||
transformedFile.push(entry);
|
||||
},
|
||||
// Dynamic imports
|
||||
CallExpression(path) {
|
||||
if (path.node.callee && path.node.callee.type === 'Import') {
|
||||
// TODO: check for specifiers catched via obj destructuring?
|
||||
// TODO: also check for ['file']
|
||||
const importSpecifiers = ['[default]'];
|
||||
let source = path.node.arguments[0].value;
|
||||
if (!source) {
|
||||
// TODO: with advanced retrieval, we could possibly get the value
|
||||
source = '[variable]';
|
||||
}
|
||||
transformedEntry.push({ importSpecifiers, source });
|
||||
if (path.node.callee?.type !== 'Import') {
|
||||
return;
|
||||
}
|
||||
// TODO: check for specifiers catched via obj destructuring?
|
||||
// TODO: also check for ['file']
|
||||
const importSpecifiers = ['[default]'];
|
||||
let source = path.node.arguments[0].value;
|
||||
if (!source) {
|
||||
// TODO: with advanced retrieval, we could possibly get the value
|
||||
source = '[variable]';
|
||||
}
|
||||
transformedFile.push({ importSpecifiers, source });
|
||||
},
|
||||
ExportNamedDeclaration(path) {
|
||||
if (!path.node.source) {
|
||||
|
|
@ -96,11 +102,11 @@ function findImportsPerAstEntry(ast) {
|
|||
}
|
||||
const importSpecifiers = getImportOrReexportsSpecifiers(path.node);
|
||||
const source = path.node.source.value;
|
||||
const entry = { importSpecifiers, source };
|
||||
const entry = /** @type {Partial<FindImportsAnalyzerEntry>} */ ({ importSpecifiers, source });
|
||||
if (path.node.assertions?.length) {
|
||||
entry.assertionType = path.node.assertions[0].value?.value;
|
||||
}
|
||||
transformedEntry.push(entry);
|
||||
transformedFile.push(entry);
|
||||
},
|
||||
// ExportAllDeclaration(path) {
|
||||
// if (!path.node.source) {
|
||||
|
|
@ -108,18 +114,19 @@ function findImportsPerAstEntry(ast) {
|
|||
// }
|
||||
// const importSpecifiers = ['[*]'];
|
||||
// const source = path.node.source.value;
|
||||
// transformedEntry.push({ importSpecifiers, source });
|
||||
// transformedFile.push({ importSpecifiers, source });
|
||||
// },
|
||||
});
|
||||
|
||||
return transformedEntry;
|
||||
return transformedFile;
|
||||
}
|
||||
|
||||
class FindImportsAnalyzer extends Analyzer {
|
||||
export default class FindImportsAnalyzer extends Analyzer {
|
||||
/** @type {AnalyzerName} */
|
||||
static get analyzerName() {
|
||||
return 'find-imports';
|
||||
}
|
||||
static analyzerName = 'find-imports';
|
||||
|
||||
/** @type {'babel'|'swc-to-babel'} */
|
||||
requiredAst = 'swc-to-babel';
|
||||
|
||||
/**
|
||||
* Finds import specifiers and sources
|
||||
|
|
@ -143,28 +150,28 @@ class FindImportsAnalyzer extends Analyzer {
|
|||
/**
|
||||
* Prepare
|
||||
*/
|
||||
const analyzerResult = this._prepare(cfg);
|
||||
if (analyzerResult) {
|
||||
return analyzerResult;
|
||||
const cachedAnalyzerResult = this._prepare(cfg);
|
||||
if (cachedAnalyzerResult) {
|
||||
return cachedAnalyzerResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverse
|
||||
*/
|
||||
const queryOutput = await this._traverse(async (ast, { relativePath }) => {
|
||||
let transformedEntry = findImportsPerAstEntry(ast);
|
||||
const queryOutput = await this._traverse(async (ast, context) => {
|
||||
let transformedFile = findImportsPerAstFile(ast, context);
|
||||
// Post processing based on configuration...
|
||||
transformedEntry = await normalizeSourcePaths(
|
||||
transformedEntry,
|
||||
relativePath,
|
||||
transformedFile = await normalizeSourcePaths(
|
||||
transformedFile,
|
||||
context.relativePath,
|
||||
cfg.targetProjectPath,
|
||||
);
|
||||
|
||||
if (!cfg.keepInternalSources) {
|
||||
transformedEntry = options.onlyExternalSources(transformedEntry);
|
||||
transformedFile = options.onlyExternalSources(transformedFile);
|
||||
}
|
||||
|
||||
return { result: transformedEntry };
|
||||
return { result: transformedFile };
|
||||
});
|
||||
|
||||
// if (cfg.sortBySpecifier) {
|
||||
|
|
@ -180,5 +187,3 @@ class FindImportsAnalyzer extends Analyzer {
|
|||
return this._finalize(queryOutput, cfg);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FindImportsAnalyzer;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
const { isRelativeSourcePath } = require('../../utils/relative-source-path.js');
|
||||
const { LogService } = require('../../core/LogService.js');
|
||||
const { resolveImportPath } = require('../../utils/resolve-import-path.js');
|
||||
const { toPosixPath } = require('../../utils/to-posix-path.js');
|
||||
import { isRelativeSourcePath } from '../../utils/relative-source-path.js';
|
||||
import { LogService } from '../../core/LogService.js';
|
||||
import { resolveImportPath } from '../../utils/resolve-import-path.js';
|
||||
import { toPosixPath } from '../../utils/to-posix-path.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../../types/core').PathRelativeFromProjectRoot} PathRelativeFromProjectRoot
|
||||
* @typedef {import('../../types/core').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../types/core').SpecifierSource} SpecifierSource
|
||||
* @typedef {import('../../../../types/index.js').PathRelativeFromProjectRoot} PathRelativeFromProjectRoot
|
||||
* @typedef {import('../../../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../../../types/index.js').SpecifierSource} SpecifierSource
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -23,7 +23,7 @@ const { toPosixPath } = require('../../utils/to-posix-path.js');
|
|||
* @param {PathFromSystemRoot} config.importeeProjectPath '/path/to/reference/project'
|
||||
* @returns {Promise<PathRelativeFromProjectRoot|null>} './foo.js'
|
||||
*/
|
||||
async function fromImportToExportPerspective({ importee, importer, importeeProjectPath }) {
|
||||
export async function fromImportToExportPerspective({ importee, importer, importeeProjectPath }) {
|
||||
if (isRelativeSourcePath(importee)) {
|
||||
LogService.warn('[fromImportToExportPerspective] Please only provide external import paths');
|
||||
return null;
|
||||
|
|
@ -38,5 +38,3 @@ async function fromImportToExportPerspective({ importee, importer, importeeProje
|
|||
absolutePath.replace(new RegExp(`^${toPosixPath(importeeProjectPath)}/?(.*)$`), './$1')
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = { fromImportToExportPerspective };
|
||||
|
|
|
|||
|
|
@ -1,17 +1,16 @@
|
|||
/* eslint-disable no-param-reassign */
|
||||
const pathLib = require('path');
|
||||
const { isRelativeSourcePath } = require('../../utils/relative-source-path.js');
|
||||
const { resolveImportPath } = require('../../utils/resolve-import-path.js');
|
||||
const { toPosixPath } = require('../../utils/to-posix-path.js');
|
||||
import pathLib from 'path';
|
||||
import { isRelativeSourcePath } from '../../utils/relative-source-path.js';
|
||||
import { resolveImportPath } from '../../utils/resolve-import-path.js';
|
||||
import { toPosixPath } from '../../utils/to-posix-path.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../../types/core').PathRelative} PathRelative
|
||||
* @typedef {import('../../types/core').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../types/core').QueryOutput} QueryOutput
|
||||
* @typedef {import('../../../../types/index.js').PathRelative} PathRelative
|
||||
* @typedef {import('../../../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../../../types/index.js').QueryOutput} QueryOutput
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {PathFromSystemRoot} currentDirPath
|
||||
* @param {PathFromSystemRoot} resolvedPath
|
||||
* @returns {PathRelative}
|
||||
|
|
@ -38,7 +37,7 @@ function toLocalPath(currentDirPath, resolvedPath) {
|
|||
* @param {string} relativePath
|
||||
* @param {string} rootPath
|
||||
*/
|
||||
async function normalizeSourcePaths(queryOutput, relativePath, rootPath = process.cwd()) {
|
||||
export async function normalizeSourcePaths(queryOutput, relativePath, rootPath = process.cwd()) {
|
||||
const currentFilePath = /** @type {PathFromSystemRoot} */ (
|
||||
pathLib.resolve(rootPath, relativePath)
|
||||
);
|
||||
|
|
@ -65,5 +64,3 @@ async function normalizeSourcePaths(queryOutput, relativePath, rootPath = proces
|
|||
}
|
||||
return normalizedQueryOutput;
|
||||
}
|
||||
|
||||
module.exports = { normalizeSourcePaths };
|
||||
|
|
|
|||
|
|
@ -1,21 +1,19 @@
|
|||
const fs = require('fs');
|
||||
const pathLib = require('path');
|
||||
const { default: traverse } = require('@babel/traverse');
|
||||
const {
|
||||
isRelativeSourcePath,
|
||||
toRelativeSourcePath,
|
||||
} = require('../../utils/relative-source-path.js');
|
||||
const { InputDataService } = require('../../core/InputDataService.js');
|
||||
const { resolveImportPath } = require('../../utils/resolve-import-path.js');
|
||||
const { AstService } = require('../../core/AstService.js');
|
||||
const { LogService } = require('../../core/LogService.js');
|
||||
const { memoize } = require('../../utils/memoize.js');
|
||||
import fs from 'fs';
|
||||
import pathLib from 'path';
|
||||
import babelTraverse from '@babel/traverse';
|
||||
import { isRelativeSourcePath, toRelativeSourcePath } from '../../utils/relative-source-path.js';
|
||||
import { InputDataService } from '../../core/InputDataService.js';
|
||||
import { resolveImportPath } from '../../utils/resolve-import-path.js';
|
||||
import { AstService } from '../../core/AstService.js';
|
||||
import { LogService } from '../../core/LogService.js';
|
||||
import { memoize } from '../../utils/memoize.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../../types/core').RootFile} RootFile
|
||||
* @typedef {import('../../types/core').SpecifierSource} SpecifierSource
|
||||
* @typedef {import('../../types/core').IdentifierName} IdentifierName
|
||||
* @typedef {import('../../types/core').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../../../types/index.js').RootFile} RootFile
|
||||
* @typedef {import('../../../../types/index.js').SpecifierSource} SpecifierSource
|
||||
* @typedef {import('../../../../types/index.js').IdentifierName} IdentifierName
|
||||
* @typedef {import('../../../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('@babel/traverse').NodePath} NodePath
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -42,7 +40,7 @@ function isExternalProject(source, projectName) {
|
|||
* Other than with import, no binding is created for MyClass by Babel(?)
|
||||
* This means 'path.scope.getBinding('MyClass')' returns undefined
|
||||
* and we have to find a different way to retrieve this value.
|
||||
* @param {object} astPath Babel ast traversal path
|
||||
* @param {NodePath} astPath Babel ast traversal path
|
||||
* @param {IdentifierName} identifierName the name that should be tracked (and that exists inside scope of astPath)
|
||||
*/
|
||||
function getBindingAndSourceReexports(astPath, identifierName) {
|
||||
|
|
@ -60,10 +58,12 @@ function getBindingAndSourceReexports(astPath, identifierName) {
|
|||
ExportSpecifier(path) {
|
||||
// eslint-disable-next-line arrow-body-style
|
||||
const found =
|
||||
// @ts-expect-error
|
||||
path.node.exported.name === identifierName || path.node.local.name === identifierName;
|
||||
if (found) {
|
||||
bindingPath = path;
|
||||
bindingType = 'ExportSpecifier';
|
||||
// @ts-expect-error
|
||||
source = path.parentPath.node.source ? path.parentPath.node.source.value : '[current]';
|
||||
path.stop();
|
||||
}
|
||||
|
|
@ -78,21 +78,22 @@ function getBindingAndSourceReexports(astPath, identifierName) {
|
|||
* We might be an import that was locally renamed.
|
||||
* Since we are traversing, we are interested in the imported name. Or in case of a re-export,
|
||||
* the local name.
|
||||
* @param {object} astPath Babel ast traversal path
|
||||
* @param {NodePath} astPath Babel ast traversal path
|
||||
* @param {string} identifierName the name that should be tracked (and that exists inside scope of astPath)
|
||||
* @returns {{ source:string, importedIdentifierName:string }}
|
||||
*/
|
||||
function getImportSourceFromAst(astPath, identifierName) {
|
||||
export function getImportSourceFromAst(astPath, identifierName) {
|
||||
let source;
|
||||
let importedIdentifierName;
|
||||
|
||||
const binding = astPath.scope.getBinding(identifierName);
|
||||
let bindingType = binding && binding.path.type;
|
||||
let bindingPath = binding && binding.path;
|
||||
let bindingType = binding?.path.type;
|
||||
let bindingPath = binding?.path;
|
||||
const matchingTypes = ['ImportSpecifier', 'ImportDefaultSpecifier', 'ExportSpecifier'];
|
||||
|
||||
if (binding && matchingTypes.includes(bindingType)) {
|
||||
source = binding.path.parentPath.node.source.value;
|
||||
if (bindingType && matchingTypes.includes(bindingType)) {
|
||||
// @ts-expect-error
|
||||
source = binding?.path?.parentPath?.node?.source?.value;
|
||||
} else {
|
||||
// no binding
|
||||
[source, bindingType, bindingPath] = getBindingAndSourceReexports(astPath, identifierName);
|
||||
|
|
@ -102,15 +103,19 @@ function getImportSourceFromAst(astPath, identifierName) {
|
|||
if (shouldLookForDefaultExport) {
|
||||
importedIdentifierName = '[default]';
|
||||
} else if (source) {
|
||||
// @ts-expect-error
|
||||
const { node } = bindingPath;
|
||||
importedIdentifierName = (node.imported && node.imported.name) || node.local.name;
|
||||
}
|
||||
return { source, importedIdentifierName };
|
||||
}
|
||||
|
||||
/** @type {(source:SpecifierSource,identifierName:IdentifierName,currentFilePath:PathFromSystemRoot,rootPath:PathFromSystemRoot, depth?:number) => Promise<RootFile>} */
|
||||
let trackDownIdentifier;
|
||||
/**
|
||||
* @typedef {(source:SpecifierSource,identifierName:IdentifierName,currentFilePath:PathFromSystemRoot,rootPath:PathFromSystemRoot,projectName?: string,depth?:number) => Promise<RootFile>} TrackDownIdentifierFn
|
||||
*/
|
||||
|
||||
/**
|
||||
* Follows the full path of an Identifier until its declaration ('root file') is found.
|
||||
* @example
|
||||
*```js
|
||||
* // 1. Starting point
|
||||
|
|
@ -126,14 +131,19 @@ let trackDownIdentifier;
|
|||
* export class RefComp extends LitElement {...}
|
||||
*```
|
||||
*
|
||||
* @param {SpecifierSource} source an importSpecifier source, like 'ref-proj' or '../file'
|
||||
* @param {IdentifierName} identifierName imported reference/Identifier name, like 'MyComp'
|
||||
* @param {PathFromSystemRoot} currentFilePath file path, like '/path/to/target-proj/my-comp-import.js'
|
||||
* @param {PathFromSystemRoot} rootPath dir path, like '/path/to/target-proj'
|
||||
* @param {string} [projectName] like 'target-proj' or '@lion/input'
|
||||
* @returns {Promise<RootFile>} file: path of file containing the binding (exported declaration),
|
||||
* -param {SpecifierSource} source an importSpecifier source, like 'ref-proj' or '../file'
|
||||
* -param {IdentifierName} identifierName imported reference/Identifier name, like 'MyComp'
|
||||
* -param {PathFromSystemRoot} currentFilePath file path, like '/path/to/target-proj/my-comp-import.js'
|
||||
* -param {PathFromSystemRoot} rootPath dir path, like '/path/to/target-proj'
|
||||
* -param {string} [projectName] like 'target-proj' or '@lion/input'
|
||||
* -returns {Promise<RootFile>} file: path of file containing the binding (exported declaration),
|
||||
* like '/path/to/ref-proj/src/RefComp.js'
|
||||
*/
|
||||
/** @type {TrackDownIdentifierFn} */
|
||||
// eslint-disable-next-line import/no-mutable-exports
|
||||
export let trackDownIdentifier;
|
||||
|
||||
/** @type {TrackDownIdentifierFn} */
|
||||
async function trackDownIdentifierFn(
|
||||
source,
|
||||
identifierName,
|
||||
|
|
@ -150,7 +160,7 @@ async function trackDownIdentifierFn(
|
|||
projectName = InputDataService.getPackageJson(rootPath)?.name;
|
||||
}
|
||||
|
||||
if (isExternalProject(source, projectName)) {
|
||||
if (projectName && isExternalProject(source, projectName)) {
|
||||
// So, it is an external ref like '@lion/core' or '@open-wc/scoped-elements/index.js'
|
||||
// At this moment in time, we don't know if we have file system access to this particular
|
||||
// project. Therefore, we limit ourselves to tracking down local references.
|
||||
|
|
@ -162,9 +172,6 @@ async function trackDownIdentifierFn(
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {PathFromSystemRoot}
|
||||
*/
|
||||
const resolvedSourcePath = await resolveImportPath(source, currentFilePath);
|
||||
|
||||
LogService.debug(`[trackDownIdentifier] ${resolvedSourcePath}`);
|
||||
|
|
@ -177,14 +184,15 @@ async function trackDownIdentifierFn(
|
|||
};
|
||||
}
|
||||
const code = fs.readFileSync(resolvedSourcePath, 'utf8');
|
||||
const ast = AstService.getAst(code, 'babel', { filePath: resolvedSourcePath });
|
||||
const babelAst = AstService.getAst(code, 'swc-to-babel', { filePath: resolvedSourcePath });
|
||||
|
||||
const shouldLookForDefaultExport = identifierName === '[default]';
|
||||
|
||||
let reexportMatch = false; // named specifier declaration
|
||||
let exportMatch;
|
||||
let pendingTrackDownPromise;
|
||||
|
||||
traverse(ast, {
|
||||
babelTraverse.default(babelAst, {
|
||||
ExportDefaultDeclaration(path) {
|
||||
if (!shouldLookForDefaultExport) {
|
||||
return;
|
||||
|
|
@ -288,10 +296,10 @@ async function trackDownIdentifierFn(
|
|||
trackDownIdentifier = memoize(trackDownIdentifierFn);
|
||||
|
||||
/**
|
||||
* @param {BabelPath} astPath
|
||||
* @param {NodePath} astPath
|
||||
* @param {string} identifierNameInScope
|
||||
* @param {string} fullCurrentFilePath
|
||||
* @param {string} projectPath
|
||||
* @param {PathFromSystemRoot} fullCurrentFilePath
|
||||
* @param {PathFromSystemRoot} projectPath
|
||||
* @param {string} [projectName]
|
||||
*/
|
||||
async function trackDownIdentifierFromScopeFn(
|
||||
|
|
@ -320,10 +328,4 @@ async function trackDownIdentifierFromScopeFn(
|
|||
return rootFile;
|
||||
}
|
||||
|
||||
const trackDownIdentifierFromScope = memoize(trackDownIdentifierFromScopeFn);
|
||||
|
||||
module.exports = {
|
||||
trackDownIdentifier,
|
||||
getImportSourceFromAst,
|
||||
trackDownIdentifierFromScope,
|
||||
};
|
||||
export const trackDownIdentifierFromScope = memoize(trackDownIdentifierFromScopeFn);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* @typedef {import('../../types/analyzers').FindExportsAnalyzerResult} FindExportsAnalyzerResult
|
||||
* @typedef {import('../../../../types/index.js').FindExportsAnalyzerResult} FindExportsAnalyzerResult
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
*
|
||||
* @param {FindExportsAnalyzerResult} exportsAnalyzerResult
|
||||
*/
|
||||
function transformIntoIterableFindExportsOutput(exportsAnalyzerResult) {
|
||||
export function transformIntoIterableFindExportsOutput(exportsAnalyzerResult) {
|
||||
/** @type {IterableFindExportsAnalyzerEntry[]} */
|
||||
const iterableEntries = [];
|
||||
|
||||
|
|
@ -62,6 +62,3 @@ function transformIntoIterableFindExportsOutput(exportsAnalyzerResult) {
|
|||
}
|
||||
return iterableEntries;
|
||||
}
|
||||
module.exports = {
|
||||
transformIntoIterableFindExportsOutput,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* @typedef {import('../../types/analyzers').FindImportsAnalyzerResult} FindImportsAnalyzerResult
|
||||
* @typedef {import('../../../../types/index.js').FindImportsAnalyzerResult} FindImportsAnalyzerResult
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -32,7 +32,7 @@
|
|||
*
|
||||
* @param {FindImportsAnalyzerResult} importsAnalyzerResult
|
||||
*/
|
||||
function transformIntoIterableFindImportsOutput(importsAnalyzerResult) {
|
||||
export function transformIntoIterableFindImportsOutput(importsAnalyzerResult) {
|
||||
/** @type {IterableFindImportsAnalyzerEntry[]} */
|
||||
const iterableEntries = [];
|
||||
|
||||
|
|
@ -56,7 +56,3 @@ function transformIntoIterableFindImportsOutput(importsAnalyzerResult) {
|
|||
}
|
||||
return iterableEntries;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
transformIntoIterableFindImportsOutput,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,23 +1,10 @@
|
|||
// A base class for writing Analyzers
|
||||
const { Analyzer } = require('../core/Analyzer.js');
|
||||
export { Analyzer } from '../core/Analyzer.js';
|
||||
|
||||
// Expose analyzers that are requested to be run in external contexts
|
||||
const FindExportsAnalyzer = require('./find-exports.js');
|
||||
const FindImportsAnalyzer = require('./find-imports.js');
|
||||
const MatchImportsAnalyzer = require('./match-paths.js');
|
||||
export { default as FindExportsAnalyzer } from './find-exports.js';
|
||||
export { default as FindImportsAnalyzer } from './find-imports.js';
|
||||
export { default as MatchImportsAnalyzer } from './match-paths.js';
|
||||
|
||||
const {
|
||||
transformIntoIterableFindImportsOutput,
|
||||
} = require('./helpers/transform-into-iterable-find-imports-output.js');
|
||||
const {
|
||||
transformIntoIterableFindExportsOutput,
|
||||
} = require('./helpers/transform-into-iterable-find-exports-output.js');
|
||||
|
||||
module.exports = {
|
||||
Analyzer,
|
||||
FindExportsAnalyzer,
|
||||
FindImportsAnalyzer,
|
||||
MatchImportsAnalyzer,
|
||||
transformIntoIterableFindImportsOutput,
|
||||
transformIntoIterableFindExportsOutput,
|
||||
};
|
||||
export { transformIntoIterableFindImportsOutput } from './helpers/transform-into-iterable-find-imports-output.js';
|
||||
export { transformIntoIterableFindExportsOutput } from './helpers/transform-into-iterable-find-exports-output.js';
|
||||
|
|
|
|||
|
|
@ -1,28 +1,24 @@
|
|||
/* eslint-disable no-continue */
|
||||
const pathLib = require('path');
|
||||
import pathLib from 'path';
|
||||
/* eslint-disable no-shadow, no-param-reassign */
|
||||
const FindImportsAnalyzer = require('./find-imports.js');
|
||||
const FindExportsAnalyzer = require('./find-exports.js');
|
||||
const { Analyzer } = require('../core/Analyzer.js');
|
||||
const { fromImportToExportPerspective } = require('./helpers/from-import-to-export-perspective.js');
|
||||
const {
|
||||
transformIntoIterableFindExportsOutput,
|
||||
} = require('./helpers/transform-into-iterable-find-exports-output.js');
|
||||
const {
|
||||
transformIntoIterableFindImportsOutput,
|
||||
} = require('./helpers/transform-into-iterable-find-imports-output.js');
|
||||
import FindImportsAnalyzer from './find-imports.js';
|
||||
import FindExportsAnalyzer from './find-exports.js';
|
||||
import { Analyzer } from '../core/Analyzer.js';
|
||||
import { fromImportToExportPerspective } from './helpers/from-import-to-export-perspective.js';
|
||||
import { transformIntoIterableFindExportsOutput } from './helpers/transform-into-iterable-find-exports-output.js';
|
||||
import { transformIntoIterableFindImportsOutput } from './helpers/transform-into-iterable-find-imports-output.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../types/analyzers').FindImportsAnalyzerResult} FindImportsAnalyzerResult
|
||||
* @typedef {import('../types/analyzers').FindExportsAnalyzerResult} FindExportsAnalyzerResult
|
||||
* @typedef {import('../types/analyzers').IterableFindExportsAnalyzerEntry} IterableFindExportsAnalyzerEntry
|
||||
* @typedef {import('../types/analyzers').IterableFindImportsAnalyzerEntry} IterableFindImportsAnalyzerEntry
|
||||
* @typedef {import('../types/analyzers').ConciseMatchImportsAnalyzerResult} ConciseMatchImportsAnalyzerResult
|
||||
* @typedef {import('../types/analyzers').MatchImportsConfig} MatchImportsConfig
|
||||
* @typedef {import('../types/analyzers').MatchImportsAnalyzerResult} MatchImportsAnalyzerResult
|
||||
* @typedef {import('../types/core').PathRelativeFromProjectRoot} PathRelativeFromProjectRoot
|
||||
* @typedef {import('../types/core').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../types/core').AnalyzerName} AnalyzerName
|
||||
* @typedef {import('../../../types/index.js').FindImportsAnalyzerResult} FindImportsAnalyzerResult
|
||||
* @typedef {import('../../../types/index.js').FindExportsAnalyzerResult} FindExportsAnalyzerResult
|
||||
* @typedef {import('../../../types/index.js').IterableFindExportsAnalyzerEntry} IterableFindExportsAnalyzerEntry
|
||||
* @typedef {import('../../../types/index.js').IterableFindImportsAnalyzerEntry} IterableFindImportsAnalyzerEntry
|
||||
* @typedef {import('../../../types/index.js').ConciseMatchImportsAnalyzerResult} ConciseMatchImportsAnalyzerResult
|
||||
* @typedef {import('../../../types/index.js').MatchImportsConfig} MatchImportsConfig
|
||||
* @typedef {import('../../../types/index.js').MatchImportsAnalyzerResult} MatchImportsAnalyzerResult
|
||||
* @typedef {import('../../../types/index.js').PathRelativeFromProjectRoot} PathRelativeFromProjectRoot
|
||||
* @typedef {import('../../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../../types/index.js').AnalyzerName} AnalyzerName
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -77,6 +73,7 @@ async function matchImportsPostprocess(exportsAnalyzerResult, importsAnalyzerRes
|
|||
// TODO: What if this info is retrieved from cached importProject/target project?
|
||||
const importProjectPath = cfg.targetProjectPath;
|
||||
|
||||
// TODO: make find-import / export automatically output these, to improve perf...
|
||||
const iterableFindExportsOutput = transformIntoIterableFindExportsOutput(exportsAnalyzerResult);
|
||||
const iterableFindImportsOutput = transformIntoIterableFindImportsOutput(importsAnalyzerResult);
|
||||
|
||||
|
|
@ -107,7 +104,7 @@ async function matchImportsPostprocess(exportsAnalyzerResult, importsAnalyzerRes
|
|||
/**
|
||||
* 2. Are we from the same source?
|
||||
* A.k.a. is source required by target the same as the one found in target.
|
||||
* (we know the specifier name is tha same, now we need to check the file as well.)
|
||||
* (we know the specifier name is the same, now we need to check the file as well.)
|
||||
*
|
||||
* Example:
|
||||
* exportFile './foo.js'
|
||||
|
|
@ -152,20 +149,16 @@ async function matchImportsPostprocess(exportsAnalyzerResult, importsAnalyzerRes
|
|||
}
|
||||
|
||||
const importProject = importsAnalyzerResult.analyzerMeta.targetProject.name;
|
||||
return /** @type {AnalyzerQueryResult} */ createCompatibleMatchImportsResult(
|
||||
conciseResultsArray,
|
||||
importProject,
|
||||
return /** @type {AnalyzerQueryResult} */ (
|
||||
createCompatibleMatchImportsResult(conciseResultsArray, importProject)
|
||||
);
|
||||
}
|
||||
|
||||
class MatchImportsAnalyzer extends Analyzer {
|
||||
static get analyzerName() {
|
||||
return 'match-imports';
|
||||
}
|
||||
export default class MatchImportsAnalyzer extends Analyzer {
|
||||
/** @type {AnalyzerName} */
|
||||
static analyzerName = 'match-imports';
|
||||
|
||||
static get requiresReference() {
|
||||
return true;
|
||||
}
|
||||
static requiresReference = true;
|
||||
|
||||
/**
|
||||
* Based on ExportsAnalyzerResult of reference project(s) (for instance lion-based-ui)
|
||||
|
|
@ -197,10 +190,9 @@ class MatchImportsAnalyzer extends Analyzer {
|
|||
/**
|
||||
* Prepare
|
||||
*/
|
||||
const analyzerResult = this._prepare(cfg);
|
||||
|
||||
if (analyzerResult) {
|
||||
return analyzerResult;
|
||||
const cachedAnalyzerResult = this._prepare(cfg);
|
||||
if (cachedAnalyzerResult) {
|
||||
return cachedAnalyzerResult;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -240,5 +232,3 @@ class MatchImportsAnalyzer extends Analyzer {
|
|||
return this._finalize(queryOutput, cfg);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MatchImportsAnalyzer;
|
||||
|
|
|
|||
|
|
@ -1,15 +1,18 @@
|
|||
/* eslint-disable no-shadow, no-param-reassign */
|
||||
const MatchSubclassesAnalyzer = require('./match-subclasses.js');
|
||||
const FindExportsAnalyzer = require('./find-exports.js');
|
||||
const FindCustomelementsAnalyzer = require('./find-customelements.js');
|
||||
const { Analyzer } = require('../core/Analyzer.js');
|
||||
import MatchSubclassesAnalyzer from './match-subclasses.js';
|
||||
import FindExportsAnalyzer from './find-exports.js';
|
||||
import FindCustomelementsAnalyzer from './find-customelements.js';
|
||||
import { Analyzer } from '../core/Analyzer.js';
|
||||
|
||||
/** @typedef {import('../types/core').FindExportsAnalyzerResult} FindExportsAnalyzerResult */
|
||||
/** @typedef {import('../types/core').FindCustomelementsAnalyzerResult} FindCustomelementsAnalyzerResult */
|
||||
/** @typedef {import('../types/core').MatchSubclassesAnalyzerResult} MatchSubclassesAnalyzerResult */
|
||||
/** @typedef {import('../types/core').FindImportsAnalyzerResult} FindImportsAnalyzerResult */
|
||||
/** @typedef {import('../types/core').MatchedExportSpecifier} MatchedExportSpecifier */
|
||||
/** @typedef {import('../types/core').RootFile} RootFile */
|
||||
/**
|
||||
* @typedef {import('../../../types/index.js').AnalyzerName} AnalyzerName
|
||||
* @typedef {import('../../../types/index.js').FindExportsAnalyzerResult} FindExportsAnalyzerResult
|
||||
* @typedef {import('../../../types/index.js').FindCustomelementsAnalyzerResult} FindCustomelementsAnalyzerResult
|
||||
* @typedef {import('../../../types/index.js').MatchSubclassesAnalyzerResult} MatchSubclassesAnalyzerResult
|
||||
* @typedef {import('../../../types/index.js').FindImportsAnalyzerResult} FindImportsAnalyzerResult
|
||||
* @typedef {import('../../../types/index.js').MatchedExportSpecifier} MatchedExportSpecifier
|
||||
* @typedef {import('../../../types/index.js').RootFile} RootFile
|
||||
*/
|
||||
|
||||
/**
|
||||
* For prefix `{ from: 'lion', to: 'wolf' }`
|
||||
|
|
@ -361,14 +364,11 @@ function matchPathsPostprocess(
|
|||
* ...
|
||||
* ]
|
||||
*/
|
||||
class MatchPathsAnalyzer extends Analyzer {
|
||||
static get analyzerName() {
|
||||
return 'match-paths';
|
||||
}
|
||||
export default class MatchPathsAnalyzer extends Analyzer {
|
||||
/** @type {AnalyzerName} */
|
||||
static analyzerName = 'match-paths';
|
||||
|
||||
static get requiresReference() {
|
||||
return true;
|
||||
}
|
||||
static requiresReference = true;
|
||||
|
||||
/**
|
||||
* @param {MatchClasspathsConfig} customConfig
|
||||
|
|
@ -513,5 +513,3 @@ class MatchPathsAnalyzer extends Analyzer {
|
|||
return this._finalize(queryOutput, cfg);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MatchPathsAnalyzer;
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
/* eslint-disable no-continue */
|
||||
const pathLib = require('path');
|
||||
import pathLib from 'path';
|
||||
/* eslint-disable no-shadow, no-param-reassign */
|
||||
const FindClassesAnalyzer = require('./find-classes.js');
|
||||
const FindExportsAnalyzer = require('./find-exports.js');
|
||||
const { Analyzer } = require('../core/Analyzer.js');
|
||||
const { fromImportToExportPerspective } = require('./helpers/from-import-to-export-perspective.js');
|
||||
import FindClassesAnalyzer from './find-classes.js';
|
||||
import FindExportsAnalyzer from './find-exports.js';
|
||||
import { Analyzer } from '../core/Analyzer.js';
|
||||
import { fromImportToExportPerspective } from './helpers/from-import-to-export-perspective.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../types/analyzers').FindClassesAnalyzerResult} FindClassesAnalyzerResult
|
||||
* @typedef {import('../types/analyzers').FindImportsAnalyzerResult} FindImportsAnalyzerResult
|
||||
* @typedef {import('../types/analyzers').FindExportsAnalyzerResult} FindExportsAnalyzerResult
|
||||
* @typedef {import('../types/analyzers').IterableFindExportsAnalyzerEntry} IterableFindExportsAnalyzerEntry
|
||||
* @typedef {import('../types/analyzers').IterableFindImportsAnalyzerEntry} IterableFindImportsAnalyzerEntry
|
||||
* @typedef {import('../types/analyzers').ConciseMatchImportsAnalyzerResult} ConciseMatchImportsAnalyzerResult
|
||||
* @typedef {import('../types/analyzers').MatchImportsConfig} MatchImportsConfig
|
||||
* @typedef {import('../types/core').PathRelativeFromProjectRoot} PathRelativeFromProjectRoot
|
||||
* @typedef {import('../types/core').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../../types/index.js').FindClassesAnalyzerResult} FindClassesAnalyzerResult
|
||||
* @typedef {import('../../../types/index.js').FindImportsAnalyzerResult} FindImportsAnalyzerResult
|
||||
* @typedef {import('../../../types/index.js').FindExportsAnalyzerResult} FindExportsAnalyzerResult
|
||||
* @typedef {import('../../../types/index.js').IterableFindExportsAnalyzerEntry} IterableFindExportsAnalyzerEntry
|
||||
* @typedef {import('../../../types/index.js').IterableFindImportsAnalyzerEntry} IterableFindImportsAnalyzerEntry
|
||||
* @typedef {import('../../../types/index.js').ConciseMatchImportsAnalyzerResult} ConciseMatchImportsAnalyzerResult
|
||||
* @typedef {import('../../../types/index.js').MatchImportsConfig} MatchImportsConfig
|
||||
* @typedef {import('../../../types/index.js').PathRelativeFromProjectRoot} PathRelativeFromProjectRoot
|
||||
* @typedef {import('../../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
*/
|
||||
|
||||
function getMemberOverrides(
|
||||
|
|
@ -87,7 +87,7 @@ async function matchSubclassesPostprocess(
|
|||
|
||||
/**
|
||||
* Step 1: a 'flat' data structure
|
||||
* @desc Create a key value storage map for exports/class matches
|
||||
* Create a key value storage map for exports/class matches
|
||||
* - key: `${exportSpecifier}::${normalizedSource}::${project}` from reference project
|
||||
* - value: an array of import file matches like `${targetProject}::${normalizedSource}::${className}`
|
||||
* @example
|
||||
|
|
@ -199,7 +199,7 @@ async function matchSubclassesPostprocess(
|
|||
|
||||
/**
|
||||
* Step 2: a rich data structure
|
||||
* @desc Transform resultObj from step 1 into an array of objects
|
||||
* Transform resultObj from step 1 into an array of objects
|
||||
* @example
|
||||
* [{
|
||||
* exportSpecifier: {
|
||||
|
|
@ -275,7 +275,7 @@ async function matchSubclassesPostprocess(
|
|||
// return aResult;
|
||||
// }
|
||||
|
||||
class MatchSubclassesAnalyzer extends Analyzer {
|
||||
export default class MatchSubclassesAnalyzer extends Analyzer {
|
||||
static get analyzerName() {
|
||||
return 'match-subclasses';
|
||||
}
|
||||
|
|
@ -285,7 +285,7 @@ class MatchSubclassesAnalyzer extends Analyzer {
|
|||
}
|
||||
|
||||
/**
|
||||
* @desc Based on ExportsAnalyzerResult of reference project(s) (for instance lion-based-ui)
|
||||
* Based on ExportsAnalyzerResult of reference project(s) (for instance lion-based-ui)
|
||||
* and targetClassesAnalyzerResult of search-targets (for instance my-app-using-lion-based-ui),
|
||||
* an overview is returned of all matching imports and exports.
|
||||
* @param {MatchSubclassesConfig} customConfig
|
||||
|
|
@ -357,5 +357,3 @@ class MatchSubclassesAnalyzer extends Analyzer {
|
|||
return this._finalize(queryOutput, cfg);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MatchSubclassesAnalyzer;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
const pathLib = require('path');
|
||||
const { LogService } = require('../../core/LogService.js');
|
||||
import pathLib from 'path';
|
||||
import { LogService } from '../../core/LogService.js';
|
||||
|
||||
const /** @type {AnalyzerOptions} */ options = {
|
||||
filterSpecifier(results, targetSpecifier, specifiersKey) {
|
||||
|
|
@ -77,7 +77,7 @@ function sortBySpecifier(analyzerResult, customConfig) {
|
|||
return /** @type {AnalyzerQueryResult} */ resultsBySpecifier;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
name: 'sort-by-specifier',
|
||||
execute: sortBySpecifier,
|
||||
compatibleAnalyzers: ['find-imports', 'find-exports'],
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
/* eslint-disable no-param-reassign */
|
||||
const semver = require('semver');
|
||||
const pathLib = require('path');
|
||||
const { LogService } = require('./LogService.js');
|
||||
const { QueryService } = require('./QueryService.js');
|
||||
const { ReportService } = require('./ReportService.js');
|
||||
const { InputDataService } = require('./InputDataService.js');
|
||||
const { toPosixPath } = require('../utils/to-posix-path.js');
|
||||
const { memoize } = require('../utils/memoize.js');
|
||||
const { getFilePathRelativeFromRoot } = require('../utils/get-file-path-relative-from-root.js');
|
||||
import semver from 'semver';
|
||||
import pathLib from 'path';
|
||||
import { LogService } from './LogService.js';
|
||||
import { QueryService } from './QueryService.js';
|
||||
import { ReportService } from './ReportService.js';
|
||||
import { InputDataService } from './InputDataService.js';
|
||||
import { toPosixPath } from '../utils/to-posix-path.js';
|
||||
import { memoize } from '../utils/memoize.js';
|
||||
import { getFilePathRelativeFromRoot } from '../utils/get-file-path-relative-from-root.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../types/core').AnalyzerName} AnalyzerName
|
||||
* @typedef {import('../types/core').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../types/core').QueryOutput} QueryOutput
|
||||
* @typedef {import('../types/core').ProjectInputData} ProjectInputData
|
||||
* @typedef {import('../types/core').ProjectInputDataWithMeta} ProjectInputDataWithMeta
|
||||
* @typedef {import('../types/core').AnalyzerQueryResult} AnalyzerQueryResult
|
||||
* @typedef {import('../types/core').MatchAnalyzerConfig} MatchAnalyzerConfig
|
||||
* @typedef {import('../../../types/index.js').AnalyzerName} AnalyzerName
|
||||
* @typedef {import('../../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../../types/index.js').QueryOutput} QueryOutput
|
||||
* @typedef {import('../../../types/index.js').ProjectInputData} ProjectInputData
|
||||
* @typedef {import('../../../types/index.js').ProjectInputDataWithMeta} ProjectInputDataWithMeta
|
||||
* @typedef {import('../../../types/index.js').AnalyzerQueryResult} AnalyzerQueryResult
|
||||
* @typedef {import('../../../types/index.js').MatchAnalyzerConfig} MatchAnalyzerConfig
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -140,14 +140,14 @@ const checkForMatchCompatibility = memoize(
|
|||
const targetPkg = InputDataService.getPackageJson(targetPath);
|
||||
|
||||
const allTargetDeps = [
|
||||
...Object.entries(targetPkg.devDependencies || {}),
|
||||
...Object.entries(targetPkg.dependencies || {}),
|
||||
...Object.entries(targetPkg?.devDependencies || {}),
|
||||
...Object.entries(targetPkg?.dependencies || {}),
|
||||
];
|
||||
const importEntry = allTargetDeps.find(([name]) => referencePkg.name === name);
|
||||
const importEntry = allTargetDeps.find(([name]) => referencePkg?.name === name);
|
||||
if (!importEntry) {
|
||||
return { compatible: false, reason: 'no-dependency' };
|
||||
}
|
||||
if (!semver.satisfies(referencePkg.version, importEntry[1])) {
|
||||
if (referencePkg?.version && !semver.satisfies(referencePkg.version, importEntry[1])) {
|
||||
return { compatible: false, reason: 'no-matched-version' };
|
||||
}
|
||||
return { compatible: true };
|
||||
|
|
@ -164,14 +164,15 @@ function unwindJsonResult(targetOrReferenceProjectResult) {
|
|||
return { queryOutput, analyzerMeta };
|
||||
}
|
||||
|
||||
class Analyzer {
|
||||
export class Analyzer {
|
||||
static requiresReference = false;
|
||||
|
||||
/** @type {AnalyzerName|''} */
|
||||
/** @type {AnalyzerName} */
|
||||
static analyzerName = '';
|
||||
|
||||
name = /** @type {typeof Analyzer} */ (this.constructor).analyzerName;
|
||||
|
||||
/** @type {'babel'|'swc-to-babel'|'swc-to-babel'} */
|
||||
requiredAst = 'babel';
|
||||
|
||||
/**
|
||||
|
|
@ -196,7 +197,7 @@ class Analyzer {
|
|||
*/
|
||||
_prepare(cfg) {
|
||||
LogService.debug(`Analyzer "${this.name}": started _prepare method`);
|
||||
this.constructor.__unwindProvidedResults(cfg);
|
||||
/** @type {typeof Analyzer} */ (this.constructor).__unwindProvidedResults(cfg);
|
||||
|
||||
if (!cfg.targetProjectResult) {
|
||||
this.targetProjectMeta = InputDataService.getProjectMeta(cfg.targetProjectPath);
|
||||
|
|
@ -330,7 +331,10 @@ class Analyzer {
|
|||
/**
|
||||
* Create ASTs for our inputData
|
||||
*/
|
||||
const astDataProjects = await QueryService.addAstToProjectsData(finalTargetData, 'babel');
|
||||
const astDataProjects = await QueryService.addAstToProjectsData(
|
||||
finalTargetData,
|
||||
this.requiredAst,
|
||||
);
|
||||
return analyzePerAstFile(astDataProjects[0], traverseEntryFn);
|
||||
}
|
||||
|
||||
|
|
@ -384,5 +388,3 @@ class Analyzer {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { Analyzer };
|
||||
|
|
|
|||
|
|
@ -1,15 +1,18 @@
|
|||
const babelParser = require('@babel/parser');
|
||||
const parse5 = require('parse5');
|
||||
const traverseHtml = require('../utils/traverse-html.js');
|
||||
const { LogService } = require('./LogService.js');
|
||||
import babelParser from '@babel/parser';
|
||||
import * as parse5 from 'parse5';
|
||||
import swc from '@swc/core';
|
||||
import { traverseHtml } from '../utils/traverse-html.js';
|
||||
import { LogService } from './LogService.js';
|
||||
import { guardedSwcToBabel } from '../utils/guarded-swc-to-babel.js';
|
||||
|
||||
/**
|
||||
* @typedef {import("@babel/types").File} File
|
||||
* @typedef {import("@swc/core").Module} SwcAstModule
|
||||
* @typedef {import("@babel/parser").ParserOptions} ParserOptions
|
||||
* @typedef {import('../types/core').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
*/
|
||||
|
||||
class AstService {
|
||||
export class AstService {
|
||||
/**
|
||||
* Compiles an array of file paths using Babel.
|
||||
* @param {string} code
|
||||
|
|
@ -31,6 +34,24 @@ class AstService {
|
|||
return ast;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles an array of file paths using Babel.
|
||||
* @param {string} code
|
||||
* @param {ParserOptions} parserOptions
|
||||
* @returns {File}
|
||||
*/
|
||||
static _getSwcToBabelAst(code, parserOptions = {}) {
|
||||
if (this.fallbackToBabel) {
|
||||
return this._getBabelAst(code, parserOptions);
|
||||
}
|
||||
const ast = swc.parseSync(code, {
|
||||
syntax: 'typescript',
|
||||
// importAssertions: true,
|
||||
...parserOptions,
|
||||
});
|
||||
return guardedSwcToBabel(ast, code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines all script tags as if it were one js file.
|
||||
* @param {string} htmlCode
|
||||
|
|
@ -56,7 +77,7 @@ class AstService {
|
|||
/**
|
||||
* Returns the Babel AST
|
||||
* @param { string } code
|
||||
* @param { 'babel' } astType
|
||||
* @param { 'babel'|'swc-to-babel' } astType
|
||||
* @param { {filePath?: PathFromSystemRoot} } options
|
||||
* @returns {File|undefined}
|
||||
*/
|
||||
|
|
@ -64,11 +85,21 @@ class AstService {
|
|||
static getAst(code, astType, { filePath } = {}) {
|
||||
// eslint-disable-next-line default-case
|
||||
try {
|
||||
return this._getBabelAst(code);
|
||||
if (astType === 'babel') {
|
||||
return this._getBabelAst(code);
|
||||
}
|
||||
if (astType === 'swc-to-babel') {
|
||||
return this._getSwcToBabelAst(code);
|
||||
}
|
||||
throw new Error(`astType "${astType}" not supported.`);
|
||||
} catch (e) {
|
||||
LogService.error(`Error when parsing "${filePath}":/n${e}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { AstService };
|
||||
/**
|
||||
* This option can be used as a last resort when an swc AST combined with swc-to-babel, is backwards incompatible
|
||||
* (for instance when @babel/generator expects a different ast structure and fails).
|
||||
* Analyzers should use guarded-swc-to-babel util.
|
||||
*/
|
||||
AstService.fallbackToBabel = false;
|
||||
|
|
|
|||
|
|
@ -1,39 +1,39 @@
|
|||
/* eslint-disable no-param-reassign */
|
||||
const fs = require('fs');
|
||||
const pathLib = require('path');
|
||||
const child_process = require('child_process'); // eslint-disable-line camelcase
|
||||
const glob = require('glob');
|
||||
const anymatch = require('anymatch');
|
||||
import fs from 'fs';
|
||||
import pathLib from 'path';
|
||||
import child_process from 'child_process'; // eslint-disable-line camelcase
|
||||
import glob from 'glob';
|
||||
import anymatch from 'anymatch';
|
||||
// @ts-expect-error
|
||||
const isNegatedGlob = require('is-negated-glob');
|
||||
const { LogService } = require('./LogService.js');
|
||||
const { AstService } = require('./AstService.js');
|
||||
const { getFilePathRelativeFromRoot } = require('../utils/get-file-path-relative-from-root.js');
|
||||
const { toPosixPath } = require('../utils/to-posix-path.js');
|
||||
const { memoize } = require('../utils/memoize.js');
|
||||
import isNegatedGlob from 'is-negated-glob';
|
||||
import { LogService } from './LogService.js';
|
||||
import { AstService } from './AstService.js';
|
||||
import { getFilePathRelativeFromRoot } from '../utils/get-file-path-relative-from-root.js';
|
||||
import { toPosixPath } from '../utils/to-posix-path.js';
|
||||
import { memoize } from '../utils/memoize.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../types/analyzers').FindImportsAnalyzerResult} FindImportsAnalyzerResult
|
||||
* @typedef {import('../types/analyzers').FindImportsAnalyzerEntry} FindImportsAnalyzerEntry
|
||||
* @typedef {import('../types/core').PathRelativeFromProjectRoot} PathRelativeFromProjectRoot
|
||||
* @typedef {import('../types/core').PathRelative} PathRelative
|
||||
* @typedef {import('../types/core').QueryConfig} QueryConfig
|
||||
* @typedef {import('../types/core').QueryResult} QueryResult
|
||||
* @typedef {import('../types/core').FeatureQueryConfig} FeatureQueryConfig
|
||||
* @typedef {import('../types/core').SearchQueryConfig} SearchQueryConfig
|
||||
* @typedef {import('../types/core').AnalyzerQueryConfig} AnalyzerQueryConfig
|
||||
* @typedef {import('../types/core').Feature} Feature
|
||||
* @typedef {import('../types/core').AnalyzerConfig} AnalyzerConfig
|
||||
* @typedef {import('../types/core').Analyzer} Analyzer
|
||||
* @typedef {import('../types/core').AnalyzerName} AnalyzerName
|
||||
* @typedef {import('../types/core').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../types/core').GatherFilesConfig} GatherFilesConfig
|
||||
* @typedef {import('../types/core').AnalyzerQueryResult} AnalyzerQueryResult
|
||||
* @typedef {import('../types/core').ProjectInputData} ProjectInputData
|
||||
* @typedef {import('../types/core').ProjectInputDataWithMeta} ProjectInputDataWithMeta
|
||||
* @typedef {import('../types/core').Project} Project
|
||||
* @typedef {import('../types/core').ProjectName} ProjectName
|
||||
* @typedef {import('../types/core').PackageJson} PackageJson
|
||||
* @typedef {import('../../../types/index.js').FindImportsAnalyzerResult} FindImportsAnalyzerResult
|
||||
* @typedef {import('../../../types/index.js').FindImportsAnalyzerEntry} FindImportsAnalyzerEntry
|
||||
* @typedef {import('../../../types/index.js').PathRelativeFromProjectRoot} PathRelativeFromProjectRoot
|
||||
* @typedef {import('../../../types/index.js').PathRelative} PathRelative
|
||||
* @typedef {import('../../../types/index.js').QueryConfig} QueryConfig
|
||||
* @typedef {import('../../../types/index.js').QueryResult} QueryResult
|
||||
* @typedef {import('../../../types/index.js').FeatureQueryConfig} FeatureQueryConfig
|
||||
* @typedef {import('../../../types/index.js').SearchQueryConfig} SearchQueryConfig
|
||||
* @typedef {import('../../../types/index.js').AnalyzerQueryConfig} AnalyzerQueryConfig
|
||||
* @typedef {import('../../../types/index.js').Feature} Feature
|
||||
* @typedef {import('../../../types/index.js').AnalyzerConfig} AnalyzerConfig
|
||||
* @typedef {import('../../../types/index.js').Analyzer} Analyzer
|
||||
* @typedef {import('../../../types/index.js').AnalyzerName} AnalyzerName
|
||||
* @typedef {import('../../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../../types/index.js').GatherFilesConfig} GatherFilesConfig
|
||||
* @typedef {import('../../../types/index.js').AnalyzerQueryResult} AnalyzerQueryResult
|
||||
* @typedef {import('../../../types/index.js').ProjectInputData} ProjectInputData
|
||||
* @typedef {import('../../../types/index.js').ProjectInputDataWithMeta} ProjectInputDataWithMeta
|
||||
* @typedef {import('../../../types/index.js').Project} Project
|
||||
* @typedef {import('../../../types/index.js').ProjectName} ProjectName
|
||||
* @typedef {import('../../../types/index.js').PackageJson} PackageJson
|
||||
* @typedef {{path:PathFromSystemRoot; name:ProjectName}} ProjectNameAndPath
|
||||
*/
|
||||
|
||||
|
|
@ -219,6 +219,10 @@ function stripDotSlashFromLocalPath(localPathWithDotSlash) {
|
|||
return localPathWithDotSlash.replace(/^\.\//, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} localPathWithoutDotSlash
|
||||
* @returns {string}
|
||||
*/
|
||||
function normalizeLocalPathWithDotSlash(localPathWithoutDotSlash) {
|
||||
if (!localPathWithoutDotSlash.startsWith('.')) {
|
||||
return `./${localPathWithoutDotSlash}`;
|
||||
|
|
@ -227,7 +231,7 @@ function normalizeLocalPathWithDotSlash(localPathWithoutDotSlash) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {{val:object|string;nodeResolveMode:string}} opts
|
||||
* @param {{valObjOrStr:object|string;nodeResolveMode:string}} opts
|
||||
* @returns {string|null}
|
||||
*/
|
||||
function getStringOrObjectValOfExportMapEntry({ valObjOrStr, nodeResolveMode }) {
|
||||
|
|
@ -248,7 +252,7 @@ function getStringOrObjectValOfExportMapEntry({ valObjOrStr, nodeResolveMode })
|
|||
*
|
||||
* Also serves as SSOT in many other contexts wrt data locations and gathering
|
||||
*/
|
||||
class InputDataService {
|
||||
export class InputDataService {
|
||||
/**
|
||||
* Create an array of ProjectData
|
||||
* @param {(PathFromSystemRoot|ProjectInputData)[]} projectPaths
|
||||
|
|
@ -708,5 +712,3 @@ InputDataService.getMonoRepoPackages = memoize(InputDataService.getMonoRepoPacka
|
|||
InputDataService.createDataObject = memoize(InputDataService.createDataObject);
|
||||
|
||||
InputDataService.getPackageJson = getPackageJson;
|
||||
|
||||
module.exports = { InputDataService };
|
||||
|
|
|
|||
|
|
@ -1,9 +1,19 @@
|
|||
const pathLib = require('path');
|
||||
const chalk = require('chalk');
|
||||
const fs = require('fs');
|
||||
import pathLib from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
const { log } = console;
|
||||
|
||||
const colors = {
|
||||
reset: '\x1b[0m',
|
||||
bright: '\x1b[1m',
|
||||
dim: '\x1b[2m',
|
||||
fgRed: '\x1b[31m',
|
||||
fgGreen: '\x1b[32m',
|
||||
fgYellow: '\x1b[33m',
|
||||
fgGray: '\x1b[90m',
|
||||
fgBlue: '\x1b[34m',
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} [title]
|
||||
* @returns {string}
|
||||
|
|
@ -12,7 +22,7 @@ function printTitle(title) {
|
|||
return `${title ? `${title}\n` : ''}`;
|
||||
}
|
||||
|
||||
class LogService {
|
||||
export class LogService {
|
||||
/**
|
||||
* @param {string} text
|
||||
* @param {string} [title]
|
||||
|
|
@ -22,7 +32,7 @@ class LogService {
|
|||
return;
|
||||
}
|
||||
|
||||
log(chalk.bgCyanBright.black.bold(` debug${printTitle(title)}`), text);
|
||||
log(colors.bright, ` debug${printTitle(title)}`, colors.reset, text);
|
||||
// @ts-ignore
|
||||
this._logHistory.push(`- debug -${printTitle(title)} ${text}`);
|
||||
}
|
||||
|
|
@ -36,7 +46,7 @@ class LogService {
|
|||
return;
|
||||
}
|
||||
|
||||
log(chalk.bgYellowBright.black.bold(`warning${printTitle(title)}`), text);
|
||||
log(colors.fgYellow, `warning${printTitle(title)}`, colors.reset, text);
|
||||
// @ts-ignore
|
||||
this._logHistory.push(`- warning -${printTitle(title)} ${text}`);
|
||||
}
|
||||
|
|
@ -57,7 +67,7 @@ class LogService {
|
|||
return;
|
||||
}
|
||||
|
||||
log(chalk.bgRedBright.black.bold(` error${printTitle(title)}`), text);
|
||||
log(colors.fgRed, ` error${printTitle(title)}`, colors.reset, text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -71,7 +81,7 @@ class LogService {
|
|||
return;
|
||||
}
|
||||
|
||||
log(chalk.bgGreen.black.bold(`success${printTitle(title)}`), text);
|
||||
log(colors.fgGreen, `success${printTitle(title)}`, colors.reset, text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -84,7 +94,7 @@ class LogService {
|
|||
if (this.allMuted) {
|
||||
return;
|
||||
}
|
||||
log(chalk.bgBlue.black.bold(` info${printTitle(title)}`), text);
|
||||
log(colors.fgBlue, ` info${printTitle(title)}`, colors.reset, text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -120,5 +130,3 @@ LogService.throwsOnError = false;
|
|||
|
||||
/** @type {string[]} */
|
||||
LogService._logHistory = [];
|
||||
|
||||
module.exports = { LogService };
|
||||
|
|
|
|||
|
|
@ -1,32 +1,33 @@
|
|||
const deepmerge = require('deepmerge');
|
||||
const child_process = require('child_process'); // eslint-disable-line camelcase
|
||||
const { AstService } = require('./AstService.js');
|
||||
const { LogService } = require('./LogService.js');
|
||||
const { getFilePathRelativeFromRoot } = require('../utils/get-file-path-relative-from-root.js');
|
||||
const { memoize } = require('../utils/memoize.js');
|
||||
import child_process from 'child_process'; // eslint-disable-line camelcase
|
||||
import path from 'path';
|
||||
import { AstService } from './AstService.js';
|
||||
import { LogService } from './LogService.js';
|
||||
import { getFilePathRelativeFromRoot } from '../utils/get-file-path-relative-from-root.js';
|
||||
import { memoize } from '../utils/memoize.js';
|
||||
import { getCurrentDir } from '../utils/get-current-dir.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../types/analyzers').FindImportsAnalyzerResult} FindImportsAnalyzerResult
|
||||
* @typedef {import('../types/analyzers').FindImportsAnalyzerEntry} FindImportsAnalyzerEntry
|
||||
* @typedef {import('../types/core').PathRelativeFromProjectRoot} PathRelativeFromProjectRoot
|
||||
* @typedef {import('../types/core').QueryConfig} QueryConfig
|
||||
* @typedef {import('../types/core').QueryResult} QueryResult
|
||||
* @typedef {import('../types/core').FeatureQueryConfig} FeatureQueryConfig
|
||||
* @typedef {import('../types/core').SearchQueryConfig} SearchQueryConfig
|
||||
* @typedef {import('../types/core').AnalyzerQueryConfig} AnalyzerQueryConfig
|
||||
* @typedef {import('../types/core').Feature} Feature
|
||||
* @typedef {import('../types/core').AnalyzerConfig} AnalyzerConfig
|
||||
* @typedef {import('../types/core').Analyzer} Analyzer
|
||||
* @typedef {import('../types/core').AnalyzerName} AnalyzerName
|
||||
* @typedef {import('../types/core').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../types/core').GatherFilesConfig} GatherFilesConfig
|
||||
* @typedef {import('../types/core').AnalyzerQueryResult} AnalyzerQueryResult
|
||||
* @typedef {import('../types/core').ProjectInputData} ProjectInputData
|
||||
* @typedef {import('./Analyzer.js').Analyzer} Analyzer
|
||||
* @typedef {import('../../../types/index.js').FindImportsAnalyzerResult} FindImportsAnalyzerResult
|
||||
* @typedef {import('../../../types/index.js').FindImportsAnalyzerEntry} FindImportsAnalyzerEntry
|
||||
* @typedef {import('../../../types/index.js').PathRelativeFromProjectRoot} PathRelativeFromProjectRoot
|
||||
* @typedef {import('../../../types/index.js').QueryConfig} QueryConfig
|
||||
* @typedef {import('../../../types/index.js').QueryResult} QueryResult
|
||||
* @typedef {import('../../../types/index.js').FeatureQueryConfig} FeatureQueryConfig
|
||||
* @typedef {import('../../../types/index.js').SearchQueryConfig} SearchQueryConfig
|
||||
* @typedef {import('../../../types/index.js').AnalyzerQueryConfig} AnalyzerQueryConfig
|
||||
* @typedef {import('../../../types/index.js').Feature} Feature
|
||||
* @typedef {import('../../../types/index.js').ProjectInputData} ProjectInputData
|
||||
* @typedef {import('../../../types/index.js').AnalyzerConfig} AnalyzerConfig
|
||||
* @typedef {import('../../../types/index.js').AnalyzerName} AnalyzerName
|
||||
* @typedef {import('../../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../../types/index.js').GatherFilesConfig} GatherFilesConfig
|
||||
* @typedef {import('../../../types/index.js').AnalyzerQueryResult} AnalyzerQueryResult
|
||||
*/
|
||||
|
||||
const astProjectsDataCache = new Map();
|
||||
|
||||
class QueryService {
|
||||
export class QueryService {
|
||||
/**
|
||||
* @param {string} regexString string for 'free' regex searches.
|
||||
* @returns {SearchQueryConfig}
|
||||
|
|
@ -104,18 +105,29 @@ class QueryService {
|
|||
|
||||
/**
|
||||
* Retrieves the default export found in ./program/analyzers/find-import.js
|
||||
* @param {string|typeof Analyzer} analyzerObjectOrString
|
||||
* @param {typeof Analyzer} analyzerCtor
|
||||
* @param {AnalyzerConfig} [analyzerConfig]
|
||||
* @returns {AnalyzerQueryConfig}
|
||||
* @returns {Promise<AnalyzerQueryConfig>}
|
||||
*/
|
||||
static getQueryConfigFromAnalyzer(analyzerObjectOrString, analyzerConfig) {
|
||||
static async getQueryConfigFromAnalyzer(analyzerObjectOrString, analyzerConfig) {
|
||||
let analyzer;
|
||||
if (typeof analyzerObjectOrString === 'string') {
|
||||
// Get it from our location(s) of predefined analyzers.
|
||||
// Mainly needed when this method is called via cli
|
||||
try {
|
||||
// eslint-disable-next-line import/no-dynamic-require, global-require
|
||||
analyzer = /** @type {Analyzer} */ (require(`../analyzers/${analyzerObjectOrString}`));
|
||||
const module = /** @type {Analyzer} */ (
|
||||
await import(
|
||||
path.join(
|
||||
'file:///',
|
||||
path.resolve(
|
||||
getCurrentDir(import.meta.url),
|
||||
`../analyzers/${analyzerObjectOrString}.js`,
|
||||
),
|
||||
)
|
||||
)
|
||||
);
|
||||
analyzer = module.default;
|
||||
} catch (e) {
|
||||
LogService.error(e.toString());
|
||||
process.exit(1);
|
||||
|
|
@ -134,19 +146,17 @@ class QueryService {
|
|||
|
||||
/**
|
||||
* Search via unix grep
|
||||
* @param {InputData} inputData
|
||||
* @param {ProjectInputData} inputData
|
||||
* @param {FeatureQueryConfig|SearchQueryConfig} queryConfig
|
||||
* @param {{hasVerboseReporting:boolean;gatherFilesConfig:GatherFilesConfig}} [customConfig]
|
||||
* @returns {Promise<QueryResult>}
|
||||
*/
|
||||
static async grepSearch(inputData, queryConfig, customConfig) {
|
||||
const cfg = deepmerge(
|
||||
{
|
||||
hasVerboseReporting: false,
|
||||
gatherFilesConfig: {},
|
||||
},
|
||||
customConfig,
|
||||
);
|
||||
const cfg = {
|
||||
hasVerboseReporting: false,
|
||||
gatherFilesConfig: {},
|
||||
...customConfig,
|
||||
};
|
||||
|
||||
const results = [];
|
||||
// 1. Analyze the type of query from the QueryConfig (for instance 'feature' or 'search').
|
||||
|
|
@ -229,7 +239,7 @@ class QueryService {
|
|||
|
||||
/**
|
||||
* @param {ProjectInputData[]} projectsData
|
||||
* @param {'babel'|'typescript'|'es-module-lexer'} requiredAst
|
||||
* @param {'babel'|'swc-to-babel'} requiredAst
|
||||
*/
|
||||
static async addAstToProjectsData(projectsData, requiredAst) {
|
||||
return projectsData.map(projectData => {
|
||||
|
|
@ -237,12 +247,13 @@ class QueryService {
|
|||
if (cachedData) {
|
||||
return cachedData;
|
||||
}
|
||||
|
||||
const resultEntries = projectData.entries.map(entry => {
|
||||
const ast = AstService.getAst(entry.context.code, requiredAst, { filePath: entry.file });
|
||||
return { ...entry, ast };
|
||||
});
|
||||
const astData = { ...projectData, entries: resultEntries };
|
||||
this._addToProjectsDataCache(projectData.project.path, astData);
|
||||
this._addToProjectsDataCache(`${projectData.project.path}#${requiredAst}`, astData);
|
||||
return astData;
|
||||
});
|
||||
}
|
||||
|
|
@ -251,12 +262,12 @@ class QueryService {
|
|||
* We need to make sure we don't run into memory issues (ASTs are huge),
|
||||
* so we only store one project in cache now. This will be a performance benefit for
|
||||
* lion-based-ui-cli, that runs providence consecutively for the same project
|
||||
* TODO: instead of storing one result in cache, use sizeof and a memory ;imit
|
||||
* TODO: instead of storing one result in cache, use sizeof and a memory limit
|
||||
* to allow for more projects
|
||||
* @param {string} path
|
||||
* @param {InputData} astData
|
||||
* @param {string} pathAndRequiredAst
|
||||
* @param {ProjectInputData} astData
|
||||
*/
|
||||
static _addToProjectsDataCache(path, astData) {
|
||||
static _addToProjectsDataCache(pathAndRequiredAst, astData) {
|
||||
if (this.cacheDisabled) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -266,7 +277,7 @@ class QueryService {
|
|||
if (astProjectsDataCache.size >= 2) {
|
||||
astProjectsDataCache.delete(astProjectsDataCache.keys()[0]);
|
||||
}
|
||||
astProjectsDataCache.set(path, astData);
|
||||
astProjectsDataCache.set(pathAndRequiredAst, astData);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -318,14 +329,12 @@ class QueryService {
|
|||
* @returns
|
||||
*/
|
||||
static _performGrep(searchPath, regex, customConfig) {
|
||||
const cfg = deepmerge(
|
||||
{
|
||||
count: false,
|
||||
gatherFilesConfig: {},
|
||||
hasDebugEnabled: false,
|
||||
},
|
||||
customConfig,
|
||||
);
|
||||
const cfg = {
|
||||
count: false,
|
||||
gatherFilesConfig: {},
|
||||
hasDebugEnabled: false,
|
||||
...customConfig,
|
||||
};
|
||||
|
||||
const /** @type {string[]} */ ext = cfg.gatherFilesConfig.extensions;
|
||||
const include = ext ? `--include="\\.(${ext.map(e => e.slice(1)).join('|')})" ` : '';
|
||||
|
|
@ -347,7 +356,4 @@ class QueryService {
|
|||
}
|
||||
}
|
||||
QueryService.cacheDisabled = false;
|
||||
|
||||
QueryService.addAstToProjectsData = memoize(QueryService.addAstToProjectsData);
|
||||
|
||||
module.exports = { QueryService };
|
||||
|
|
|
|||
|
|
@ -1,17 +1,16 @@
|
|||
const fs = require('fs');
|
||||
const pathLib = require('path');
|
||||
const getHash = require('../utils/get-hash.js');
|
||||
const { memoize } = require('../utils/memoize.js');
|
||||
// const memoize = fn => fn;
|
||||
import fs from 'fs';
|
||||
import pathLib from 'path';
|
||||
import { getHash } from '../utils/get-hash.js';
|
||||
import { memoize } from '../utils/memoize.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../types/core').Project} Project
|
||||
* @typedef {import('../types/core').ProjectName} ProjectName
|
||||
* @typedef {import('../types/core').AnalyzerQueryResult} AnalyzerQueryResult
|
||||
* @typedef {import('../types/core').AnalyzerConfig} AnalyzerConfig
|
||||
* @typedef {import('../types/core').AnalyzerName} AnalyzerName
|
||||
* @typedef {import('../types/core').QueryResult} QueryResult
|
||||
* @typedef {import('../types/core').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../../types/index.js').Project} Project
|
||||
* @typedef {import('../../../types/index.js').ProjectName} ProjectName
|
||||
* @typedef {import('../../../types/index.js').AnalyzerQueryResult} AnalyzerQueryResult
|
||||
* @typedef {import('../../../types/index.js').AnalyzerConfig} AnalyzerConfig
|
||||
* @typedef {import('../../../types/index.js').AnalyzerName} AnalyzerName
|
||||
* @typedef {import('../../../types/index.js').QueryResult} QueryResult
|
||||
* @typedef {import('../../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -30,7 +29,7 @@ function createResultIdentifier(searchP, cfg, refP) {
|
|||
return `${format(searchP)}${refP ? `_+_${format(refP)}` : ''}__${cfgHash}`;
|
||||
}
|
||||
|
||||
class ReportService {
|
||||
export class ReportService {
|
||||
/**
|
||||
* Prints queryResult report to console
|
||||
* @param {QueryResult} queryResult
|
||||
|
|
@ -130,5 +129,3 @@ class ReportService {
|
|||
}
|
||||
ReportService.createIdentifier = memoize(ReportService.createIdentifier);
|
||||
ReportService.getCachedResult = memoize(ReportService.getCachedResult);
|
||||
|
||||
module.exports = { ReportService };
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
const { performance } = require('perf_hooks');
|
||||
const deepmerge = require('deepmerge');
|
||||
const { ReportService } = require('./core/ReportService.js');
|
||||
const { InputDataService } = require('./core/InputDataService.js');
|
||||
const { LogService } = require('./core/LogService.js');
|
||||
const { QueryService } = require('./core/QueryService.js');
|
||||
import { performance } from 'perf_hooks';
|
||||
import { ReportService } from './core/ReportService.js';
|
||||
import { InputDataService } from './core/InputDataService.js';
|
||||
import { LogService } from './core/LogService.js';
|
||||
import { QueryService } from './core/QueryService.js';
|
||||
import { AstService } from './core/AstService.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('./types/core').ProvidenceConfig} ProvidenceConfig
|
||||
* @typedef {import('./types/core').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('./types/core').QueryResult} QueryResult
|
||||
* @typedef {import('./types/core').AnalyzerQueryResult} AnalyzerQueryResult
|
||||
* @typedef {import('./types/core').QueryConfig} QueryConfig
|
||||
* @typedef {import('./types/core').AnalyzerQueryConfig} AnalyzerQueryConfig
|
||||
* @typedef {import('./types/core').GatherFilesConfig} GatherFilesConfig
|
||||
* @typedef {import('../../types/index.js').ProvidenceConfig} ProvidenceConfig
|
||||
* @typedef {import('../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../types/index.js').QueryResult} QueryResult
|
||||
* @typedef {import('../../types/index.js').AnalyzerQueryResult} AnalyzerQueryResult
|
||||
* @typedef {import('../../types/index.js').QueryConfig} QueryConfig
|
||||
* @typedef {import('../../types/index.js').AnalyzerQueryConfig} AnalyzerQueryConfig
|
||||
* @typedef {import('../../types/index.js').GatherFilesConfig} GatherFilesConfig
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -172,34 +172,32 @@ async function handleRegexSearch(queryConfig, cfg, inputData) {
|
|||
*
|
||||
* @param {QueryConfig} queryConfig a query configuration object containing analyzerOptions.
|
||||
* @param {Partial<ProvidenceConfig>} customConfig
|
||||
* @return {Promise<QueryResult[]>}
|
||||
*/
|
||||
async function providenceMain(queryConfig, customConfig) {
|
||||
export async function providence(queryConfig, customConfig) {
|
||||
const tStart = performance.now();
|
||||
|
||||
const cfg = /** @type {ProvidenceConfig} */ (
|
||||
deepmerge(
|
||||
{
|
||||
queryMethod: 'grep',
|
||||
// This is a merge of all 'main entry projects'
|
||||
// found in search-targets, including their children
|
||||
targetProjectPaths: null,
|
||||
referenceProjectPaths: null,
|
||||
// This will be needed to identify the parent/child relationship to write to
|
||||
// {outputFolder}/entryProjectDependencies.json, which will map
|
||||
// a project#version to [ depA#version, depB#version ]
|
||||
targetProjectRootPaths: null,
|
||||
gatherFilesConfig: {},
|
||||
report: true,
|
||||
debugEnabled: false,
|
||||
writeLogFile: false,
|
||||
skipCheckMatchCompatibility: false,
|
||||
measurePerformance: false,
|
||||
/** Allows to navigate to source file in code editor */
|
||||
addSystemPathsInResult: false,
|
||||
},
|
||||
customConfig,
|
||||
)
|
||||
);
|
||||
const cfg = /** @type {ProvidenceConfig} */ ({
|
||||
queryMethod: 'grep',
|
||||
// This is a merge of all 'main entry projects'
|
||||
// found in search-targets, including their children
|
||||
targetProjectPaths: null,
|
||||
referenceProjectPaths: null,
|
||||
// This will be needed to identify the parent/child relationship to write to
|
||||
// {outputFolder}/entryProjectDependencies.json, which will map
|
||||
// a project#version to [ depA#version, depB#version ]
|
||||
targetProjectRootPaths: null,
|
||||
gatherFilesConfig: {},
|
||||
report: true,
|
||||
debugEnabled: false,
|
||||
writeLogFile: false,
|
||||
skipCheckMatchCompatibility: false,
|
||||
measurePerformance: false,
|
||||
/** Allows to navigate to source file in code editor */
|
||||
addSystemPathsInResult: false,
|
||||
fallbackToBabel: false,
|
||||
...customConfig,
|
||||
});
|
||||
|
||||
if (cfg.debugEnabled) {
|
||||
LogService.debugEnabled = true;
|
||||
|
|
@ -209,6 +207,10 @@ async function providenceMain(queryConfig, customConfig) {
|
|||
InputDataService.referenceProjectPaths = cfg.referenceProjectPaths;
|
||||
}
|
||||
|
||||
if (cfg.fallbackToBabel) {
|
||||
AstService.fallbackToBabel = true;
|
||||
}
|
||||
|
||||
let queryResults;
|
||||
if (queryConfig.type === 'ast-analyzer') {
|
||||
queryResults = await handleAnalyzer(queryConfig, cfg);
|
||||
|
|
@ -240,6 +242,6 @@ async function providenceMain(queryConfig, customConfig) {
|
|||
return queryResults;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
providence: providenceMain,
|
||||
export const _providenceModule = {
|
||||
providence,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
export * from './find-classes';
|
||||
export * from './find-customelements';
|
||||
export * from './find-exports';
|
||||
export * from './find-imports';
|
||||
export * from './match-imports';
|
||||
export * from './match-subclasses';
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
export * from './core';
|
||||
export * from './Analyzer';
|
||||
export * from './QueryService';
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
export * from './core';
|
||||
export * from './analyzers';
|
||||
export * from './utils';
|
||||
|
|
@ -1 +0,0 @@
|
|||
export type MemoizeFunction<T> = (fn: T, storage?: object) => T;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* @typedef {import('../types/core/core').PathRelativeFromProjectRoot} PathRelativeFromProjectRoot
|
||||
* @typedef {import('../types/core/core').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../../types/index.js').PathRelativeFromProjectRoot} PathRelativeFromProjectRoot
|
||||
* @typedef {import('../../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -11,8 +11,6 @@
|
|||
* @param {PathFromSystemRoot} projectRoot
|
||||
* @returns {PathRelativeFromProjectRoot}
|
||||
*/
|
||||
function getFilePathRelativeFromRoot(absolutePath, projectRoot) {
|
||||
export function getFilePathRelativeFromRoot(absolutePath, projectRoot) {
|
||||
return /** @type {PathRelativeFromProjectRoot} */ (absolutePath.replace(projectRoot, '.'));
|
||||
}
|
||||
|
||||
module.exports = { getFilePathRelativeFromRoot };
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
* @param {string|object} inputValue
|
||||
* @returns {number}
|
||||
*/
|
||||
function getHash(inputValue) {
|
||||
export function getHash(inputValue) {
|
||||
if (typeof inputValue === 'object') {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
inputValue = JSON.stringify(inputValue);
|
||||
|
|
@ -14,5 +14,3 @@ function getHash(inputValue) {
|
|||
0,
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = getHash;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,22 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const babelTraversePkg = require('@babel/traverse');
|
||||
const { AstService } = require('../core/AstService.js');
|
||||
const { trackDownIdentifier } = require('../analyzers/helpers/track-down-identifier.js');
|
||||
const { toPosixPath } = require('./to-posix-path.js');
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import babelTraversePkg from '@babel/traverse';
|
||||
import { AstService } from '../core/AstService.js';
|
||||
import { trackDownIdentifier } from '../analyzers/helpers/track-down-identifier.js';
|
||||
import { toPosixPath } from './to-posix-path.js';
|
||||
|
||||
function getFilePathOrExternalSource({ rootPath, localPath }) {
|
||||
/**
|
||||
* @typedef {import('@babel/types').Node} Node
|
||||
* @typedef {import('@babel/traverse').NodePath} NodePath
|
||||
* @typedef {import('../../../types/index.js').PathRelativeFromProjectRoot} PathRelativeFromProjectRoot
|
||||
* @typedef {import('../../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {{rootPath:PathFromSystemRoot; localPath:PathRelativeFromProjectRoot}} opts
|
||||
* @returns
|
||||
*/
|
||||
export function getFilePathOrExternalSource({ rootPath, localPath }) {
|
||||
if (!localPath.startsWith('.')) {
|
||||
// We are not resolving external files like '@lion/input-amount/x.js',
|
||||
// but we give a 100% score if from and to are same here..
|
||||
|
|
@ -27,9 +38,9 @@ function getFilePathOrExternalSource({ rootPath, localPath }) {
|
|||
* - Is it a ref? Call ourselves with referencedIdentifierName ('x' in example above)
|
||||
* - is it a non ref declaration? Return the path of the node
|
||||
* @param {{ referencedIdentifierName:string, globalScopeBindings:BabelBinding; }} opts
|
||||
* @returns {BabelNodePath}
|
||||
* @returns {NodePath}
|
||||
*/
|
||||
function getReferencedDeclaration({ referencedIdentifierName, globalScopeBindings }) {
|
||||
export function getReferencedDeclaration({ referencedIdentifierName, globalScopeBindings }) {
|
||||
const [, refDeclaratorBinding] = Object.entries(globalScopeBindings).find(
|
||||
([key]) => key === referencedIdentifierName,
|
||||
);
|
||||
|
|
@ -52,22 +63,24 @@ function getReferencedDeclaration({ referencedIdentifierName, globalScopeBinding
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {{ filePath: string; exportedIdentifier: string; }} opts
|
||||
* @param {{ filePath: PathFromSystemRoot; exportedIdentifier: string; projectRootPath: PathFromSystemRoot }} opts
|
||||
* @returns {Promise<{ sourceNodePath: string; sourceFragment: string|null; externalImportSource: string; }>}
|
||||
*/
|
||||
async function getSourceCodeFragmentOfDeclaration({
|
||||
export async function getSourceCodeFragmentOfDeclaration({
|
||||
filePath,
|
||||
exportedIdentifier,
|
||||
projectRootPath,
|
||||
}) {
|
||||
const code = fs.readFileSync(filePath, 'utf-8');
|
||||
const ast = AstService.getAst(code, 'babel');
|
||||
const code = fs.readFileSync(filePath, 'utf8');
|
||||
// TODO: fix swc-to-babel lib to make this compatible with 'swc-to-babel' mode of getAst
|
||||
const babelAst = AstService.getAst(code, 'babel', { filePath });
|
||||
|
||||
/** @type {NodePath} */
|
||||
let finalNodePath;
|
||||
|
||||
babelTraversePkg.default(ast, {
|
||||
Program(babelPath) {
|
||||
babelPath.stop();
|
||||
babelTraversePkg.default(babelAst, {
|
||||
Program(astPath) {
|
||||
astPath.stop();
|
||||
|
||||
// Situations
|
||||
// - Identifier is part of default export (in this case 'exportedIdentifier' is '[default]' )
|
||||
|
|
@ -77,13 +90,14 @@ async function getSourceCodeFragmentOfDeclaration({
|
|||
// - declared right away
|
||||
// - referenced (possibly recursively) by other declaration
|
||||
|
||||
const globalScopeBindings = babelPath.get('body')[0].scope.bindings;
|
||||
const globalScopeBindings = astPath.get('body')[0].scope.bindings;
|
||||
|
||||
if (exportedIdentifier === '[default]') {
|
||||
const defaultExportPath = babelPath
|
||||
const defaultExportPath = astPath
|
||||
.get('body')
|
||||
.find(child => child.node.type === 'ExportDefaultDeclaration');
|
||||
const isReferenced = defaultExportPath.node.declaration?.type === 'Identifier';
|
||||
// @ts-expect-error
|
||||
const isReferenced = defaultExportPath?.node.declaration?.type === 'Identifier';
|
||||
|
||||
if (!isReferenced) {
|
||||
finalNodePath = defaultExportPath.get('declaration');
|
||||
|
|
@ -94,7 +108,7 @@ async function getSourceCodeFragmentOfDeclaration({
|
|||
});
|
||||
}
|
||||
} else {
|
||||
const variableDeclaratorPath = babelPath.scope.getBinding(exportedIdentifier).path;
|
||||
const variableDeclaratorPath = astPath.scope.getBinding(exportedIdentifier).path;
|
||||
const varDeclNode = variableDeclaratorPath.node;
|
||||
const isReferenced = varDeclNode.init?.type === 'Identifier';
|
||||
const contentPath = varDeclNode.init
|
||||
|
|
@ -154,13 +168,10 @@ async function getSourceCodeFragmentOfDeclaration({
|
|||
|
||||
return {
|
||||
sourceNodePath: finalNodePath,
|
||||
sourceFragment: code.slice(finalNodePath.node?.start, finalNodePath.node?.end),
|
||||
sourceFragment: code.slice(
|
||||
finalNodePath.node?.loc?.start.index,
|
||||
finalNodePath.node?.loc?.end.index,
|
||||
),
|
||||
externalImportSource: null,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getSourceCodeFragmentOfDeclaration,
|
||||
getFilePathOrExternalSource,
|
||||
getReferencedDeclaration,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
import toBabel from 'swc-to-babel';
|
||||
|
||||
/**
|
||||
* @typedef {import('@babel/types').File} File
|
||||
*/
|
||||
|
||||
/**
|
||||
* Internal wrapper around swc-to-babel...
|
||||
* Allows to easily switch all swc based analyzers to Babel in case
|
||||
* they turn out to be not stable yet (for instance printing a transformed ast with @babel/generator)
|
||||
* Checks first whether it gets a Babel ast provided or not...
|
||||
* @param {*} swcOrBabelAst
|
||||
* @param {string} source
|
||||
* @returns {File}
|
||||
*/
|
||||
export function guardedSwcToBabel(swcOrBabelAst, source) {
|
||||
const isSwcAst = swcOrBabelAst.type === 'Module';
|
||||
if (isSwcAst) {
|
||||
// @ts-ignore
|
||||
return toBabel(swcOrBabelAst, source);
|
||||
}
|
||||
return swcOrBabelAst;
|
||||
}
|
||||
|
|
@ -1,16 +1,8 @@
|
|||
const {
|
||||
export {
|
||||
getSourceCodeFragmentOfDeclaration,
|
||||
getFilePathOrExternalSource,
|
||||
} = require('./get-source-code-fragment-of-declaration.js');
|
||||
const { memoize } = require('./memoize.js');
|
||||
const { toRelativeSourcePath, isRelativeSourcePath } = require('./relative-source-path.js');
|
||||
} from './get-source-code-fragment-of-declaration.js';
|
||||
export { memoize } from './memoize.js';
|
||||
export { toRelativeSourcePath, isRelativeSourcePath } from './relative-source-path.js';
|
||||
|
||||
// TODO: move trackdownIdentifier to utils as well
|
||||
|
||||
module.exports = {
|
||||
memoize,
|
||||
getSourceCodeFragmentOfDeclaration,
|
||||
getFilePathOrExternalSource,
|
||||
toRelativeSourcePath,
|
||||
isRelativeSourcePath,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
* console.log(tags);
|
||||
* }
|
||||
*/
|
||||
class JsdocCommentParser {
|
||||
export default class JsdocCommentParser {
|
||||
/**
|
||||
* parse comment to tags.
|
||||
* @param {ASTNode} commentNode - comment node.
|
||||
|
|
@ -122,5 +122,3 @@ class JsdocCommentParser {
|
|||
}, '*\n');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JsdocCommentParser;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
const memoizeConfig = {
|
||||
export const memoizeConfig = {
|
||||
isCacheDisabled: false,
|
||||
};
|
||||
|
||||
|
|
@ -24,10 +24,10 @@ function createCachableArg(arg) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {function} functionToMemoize
|
||||
* @param {{ storage?:object; serializeObjects?: boolean }} opts
|
||||
* @type {<T>(functionToMemoize:T, opts?:{ storage?:object; serializeObjects?: boolean }) => T}
|
||||
*/
|
||||
function memoize(functionToMemoize, { storage = {}, serializeObjects = false } = {}) {
|
||||
export function memoize(functionToMemoize, { storage = {}, serializeObjects = false } = {}) {
|
||||
// @ts-ignore
|
||||
// eslint-disable-next-line func-names
|
||||
return function () {
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
|
|
@ -47,8 +47,3 @@ function memoize(functionToMemoize, { storage = {}, serializeObjects = false } =
|
|||
return outcome;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
memoize,
|
||||
memoizeConfig,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,7 +3,11 @@ import fs from 'fs';
|
|||
import { pathToFileURL } from 'url';
|
||||
|
||||
/**
|
||||
* @returns {Promise<object|null>}
|
||||
* @typedef {import('../../../types/index.js').ProvidenceCliConf} ProvidenceCliConf
|
||||
*/
|
||||
|
||||
/**
|
||||
* @returns {Promise<{providenceConf:Partial<ProvidenceCliConf>;providenceConfRaw:string}|null>}
|
||||
*/
|
||||
async function getConf() {
|
||||
const confPathWithoutExtension = `${pathLib.join(process.cwd(), 'providence.conf')}`;
|
||||
|
|
@ -24,13 +24,16 @@
|
|||
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
import fs from 'fs';
|
||||
/* istanbul ignore next */
|
||||
const promisify = require('util').promisify || require('util-promisify');
|
||||
const { resolve, basename, dirname, join } = require('path');
|
||||
const rpj = promisify(require('read-package-json'));
|
||||
const readdir = promisify(require('readdir-scoped-modules'));
|
||||
const realpath = require('read-package-tree/realpath.js');
|
||||
import { promisify } from 'util';
|
||||
import { basename, dirname, join } from 'path';
|
||||
import rpjSync from 'read-package-json';
|
||||
import readdirSync from 'readdir-scoped-modules';
|
||||
import realpath from 'read-package-tree/realpath.js';
|
||||
|
||||
const rpj = promisify(rpjSync);
|
||||
const readdir = promisify(readdirSync);
|
||||
|
||||
let ID = 0;
|
||||
class Node {
|
||||
|
|
@ -220,4 +223,5 @@ const rpt = (root, filterWith, cb, mode = 'npm') => {
|
|||
|
||||
rpt.Node = Node;
|
||||
rpt.Link = Link;
|
||||
module.exports = rpt;
|
||||
|
||||
export default rpt;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
const { toPosixPath } = require('./to-posix-path.js');
|
||||
import { toPosixPath } from './to-posix-path.js';
|
||||
|
||||
/**
|
||||
* Determines for a source path of an import- or export specifier, whether
|
||||
|
|
@ -8,7 +8,7 @@ const { toPosixPath } = require('./to-posix-path.js');
|
|||
* @param {string} source source path of an import- or export specifier
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isRelativeSourcePath(source) {
|
||||
export function isRelativeSourcePath(source) {
|
||||
return source.startsWith('.');
|
||||
}
|
||||
|
||||
|
|
@ -19,8 +19,6 @@ function isRelativeSourcePath(source) {
|
|||
* @param {string} fullPath like '/path/to/repo/my/file.js'
|
||||
* @param {string} rootPath like '/path/to/repo'
|
||||
*/
|
||||
function toRelativeSourcePath(fullPath, rootPath) {
|
||||
export function toRelativeSourcePath(fullPath, rootPath) {
|
||||
return toPosixPath(fullPath).replace(toPosixPath(rootPath), '.');
|
||||
}
|
||||
|
||||
module.exports = { isRelativeSourcePath, toRelativeSourcePath };
|
||||
|
|
|
|||
|
|
@ -1,20 +1,20 @@
|
|||
import pathLib from 'path';
|
||||
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
||||
import { LogService } from '../core/LogService.js';
|
||||
import { memoize } from './memoize.js';
|
||||
import { toPosixPath } from './to-posix-path.js';
|
||||
|
||||
/**
|
||||
* Solution inspired by es-dev-server:
|
||||
* https://github.com/open-wc/open-wc/blob/master/packages/es-dev-server/src/utils/resolve-module-imports.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('../types/core/core').PathRelativeFromProjectRoot} PathRelativeFromProjectRoot
|
||||
* @typedef {import('../types/core/core').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../types/core/core').SpecifierSource} SpecifierSource
|
||||
* @typedef {import('../../../types/index.js').PathRelativeFromProjectRoot} PathRelativeFromProjectRoot
|
||||
* @typedef {import('../../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../../types/index.js').SpecifierSource} SpecifierSource
|
||||
*/
|
||||
|
||||
const pathLib = require('path');
|
||||
const { nodeResolve } = require('@rollup/plugin-node-resolve');
|
||||
const { LogService } = require('../core/LogService.js');
|
||||
const { memoize } = require('./memoize.js');
|
||||
const { toPosixPath } = require('./to-posix-path.js');
|
||||
|
||||
const fakePluginContext = {
|
||||
meta: {
|
||||
// rollupVersion needed in plugin context => nodeResolvePackageJson.peerDependencies.rollup
|
||||
|
|
@ -29,7 +29,16 @@ const fakePluginContext = {
|
|||
},
|
||||
};
|
||||
|
||||
async function resolveImportPath(importee, importer, opts) {
|
||||
/**
|
||||
* Based on importee (in a statement "import {x} from '@lion/core'", "@lion/core" is an
|
||||
* importee), which can be a bare module specifier, a filename without extension, or a folder
|
||||
* name without an extension.
|
||||
* @param {SpecifierSource} importee source like '@lion/core' or '../helpers/index.js'
|
||||
* @param {PathFromSystemRoot} importer importing file, like '/my/project/importing-file.js'
|
||||
* @param {{customResolveOptions?: {preserveSymlinks:boolean}}} [opts] nodeResolve options
|
||||
* @returns {Promise<PathFromSystemRoot|null>} the resolved file system path, like '/my/project/node_modules/@lion/core/index.js'
|
||||
*/
|
||||
async function resolveImportPathFn(importee, importer, opts) {
|
||||
const rollupResolve = nodeResolve({
|
||||
rootDir: pathLib.dirname(importer),
|
||||
// allow resolving polyfills for nodejs libs
|
||||
|
|
@ -59,15 +68,4 @@ async function resolveImportPath(importee, importer, opts) {
|
|||
return toPosixPath(result.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on importee (in a statement "import {x} from '@lion/core'", "@lion/core" is an
|
||||
* importee), which can be a bare module specifier, a filename without extension, or a folder
|
||||
* name without an extension.
|
||||
* @param {SpecifierSource} importee source like '@lion/core' or '../helpers/index.js'
|
||||
* @param {PathFromSystemRoot} importer importing file, like '/my/project/importing-file.js'
|
||||
* @param {{customResolveOptions?: {preserveSymlinks:boolean}}} [opts] nodeResolve options
|
||||
* @returns {Promise<PathFromSystemRoot|null>} the resolved file system path, like '/my/project/node_modules/@lion/core/index.js'
|
||||
*/
|
||||
const resolveImportPathMemoized = memoize(resolveImportPath);
|
||||
|
||||
module.exports = { resolveImportPath: resolveImportPathMemoized };
|
||||
export const resolveImportPath = memoize(resolveImportPathFn);
|
||||
|
|
|
|||
|
|
@ -1,16 +1,14 @@
|
|||
/**
|
||||
* @typedef {import('../types/core/core').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {PathFromSystemRoot|string} pathStr C:\Example\path/like/this
|
||||
* @returns {PathFromSystemRoot} /Example/path/like/this
|
||||
*/
|
||||
function toPosixPath(pathStr) {
|
||||
export function toPosixPath(pathStr) {
|
||||
if (process.platform === 'win32') {
|
||||
return /** @type {PathFromSystemRoot} */ (pathStr.replace(/^.:/, '').replace(/\\/g, '/'));
|
||||
}
|
||||
return /** @type {PathFromSystemRoot} */ (pathStr);
|
||||
}
|
||||
|
||||
module.exports = { toPosixPath };
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
/**
|
||||
* @param {ASTNode} curNode Node to start from. Will loop over its children
|
||||
* @param {Node} curNode Node to start from. Will loop over its children
|
||||
* @param {object} processObject Will be executed for every node
|
||||
* @param {ASTNode} [parentNode] parent of curNode
|
||||
*/
|
||||
function traverseHtml(curNode, processObject) {
|
||||
export function traverseHtml(curNode, processObject) {
|
||||
function pathify(node) {
|
||||
return {
|
||||
node,
|
||||
|
|
@ -24,5 +23,3 @@ function traverseHtml(curNode, processObject) {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = traverseHtml;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
// @ts-ignore
|
||||
const mockFs = require('mock-fs');
|
||||
// @ts-ignore
|
||||
const mockRequire = require('mock-require');
|
||||
// @ts-expect-error
|
||||
import mockFs from 'mock-fs';
|
||||
// @ts-expect-error
|
||||
import mockRequire from 'mock-require';
|
||||
|
||||
/**
|
||||
* @param {object} obj
|
||||
*/
|
||||
function mockFsAndRequire(obj) {
|
||||
export function mockFsAndRequire(obj) {
|
||||
mockFs(obj);
|
||||
|
||||
// Object.entries(obj).forEach(([key, value]) => {
|
||||
|
|
@ -23,7 +23,3 @@ mockFsAndRequire.restore = () => {
|
|||
mockFs.restore();
|
||||
mockRequire.stopAll();
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
mockFsAndRequire,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,57 +1,47 @@
|
|||
const { LogService } = require('../src/program/core/LogService.js');
|
||||
import { LogService } from '../src/program/core/LogService.js';
|
||||
|
||||
const originalWarn = LogService.warn;
|
||||
function suppressWarningLogs() {
|
||||
export function suppressWarningLogs() {
|
||||
LogService.warn = () => {};
|
||||
}
|
||||
function restoreSuppressWarningLogs() {
|
||||
export function restoreSuppressWarningLogs() {
|
||||
LogService.warn = originalWarn;
|
||||
}
|
||||
|
||||
const originalInfo = LogService.info;
|
||||
function suppressInfoLogs() {
|
||||
export function suppressInfoLogs() {
|
||||
LogService.info = () => {};
|
||||
}
|
||||
function restoreSuppressInfoLogs() {
|
||||
export function restoreSuppressInfoLogs() {
|
||||
LogService.info = originalInfo;
|
||||
}
|
||||
|
||||
const originalDebug = LogService.debug;
|
||||
function suppressDebugLogs() {
|
||||
export function suppressDebugLogs() {
|
||||
LogService.debug = () => {};
|
||||
}
|
||||
function restoreSuppressDebugLogs() {
|
||||
export function restoreSuppressDebugLogs() {
|
||||
LogService.debug = originalDebug;
|
||||
}
|
||||
|
||||
const originalSuccess = LogService.success;
|
||||
function suppressSuccessLogs() {
|
||||
export function suppressSuccessLogs() {
|
||||
LogService.success = () => {};
|
||||
}
|
||||
function restoreSuppressSuccessLogs() {
|
||||
export function restoreSuppressSuccessLogs() {
|
||||
LogService.success = originalSuccess;
|
||||
}
|
||||
|
||||
function suppressNonCriticalLogs() {
|
||||
export function suppressNonCriticalLogs() {
|
||||
suppressInfoLogs();
|
||||
suppressWarningLogs();
|
||||
suppressDebugLogs();
|
||||
suppressSuccessLogs();
|
||||
}
|
||||
|
||||
function restoreSuppressNonCriticalLogs() {
|
||||
export function restoreSuppressNonCriticalLogs() {
|
||||
restoreSuppressInfoLogs();
|
||||
restoreSuppressWarningLogs();
|
||||
restoreSuppressDebugLogs();
|
||||
restoreSuppressSuccessLogs();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
suppressWarningLogs,
|
||||
restoreSuppressWarningLogs,
|
||||
suppressInfoLogs,
|
||||
restoreSuppressInfoLogs,
|
||||
|
||||
suppressNonCriticalLogs,
|
||||
restoreSuppressNonCriticalLogs,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
const path = require('path');
|
||||
import path from 'path';
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
const { mockFsAndRequire: mock } = require('./mock-fs-and-require.js');
|
||||
|
||||
import { mockFsAndRequire } from './mock-fs-and-require.js';
|
||||
|
||||
export const mock = mockFsAndRequire;
|
||||
|
||||
/**
|
||||
* Makes sure that, whenever the main program (providence) calls
|
||||
|
|
@ -70,21 +70,21 @@ function getMockObjectForProject(files, cfg = {}, existingMock = {}) {
|
|||
* paths match with the indexes of the files
|
||||
* @param {object} existingMock config for mock-fs, so the previous config is not overridden
|
||||
*/
|
||||
function mockProject(files, cfg = {}, existingMock = {}) {
|
||||
export function mockProject(files, cfg = {}, existingMock = {}) {
|
||||
const obj = getMockObjectForProject(files, cfg, existingMock);
|
||||
mock(obj);
|
||||
mockFsAndRequire(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
function restoreMockedProjects() {
|
||||
mock.restore();
|
||||
export function restoreMockedProjects() {
|
||||
mockFsAndRequire.restore();
|
||||
}
|
||||
|
||||
function getEntry(queryResult, index = 0) {
|
||||
export function getEntry(queryResult, index = 0) {
|
||||
return queryResult.queryOutput[index];
|
||||
}
|
||||
|
||||
function getEntries(queryResult) {
|
||||
export function getEntries(queryResult) {
|
||||
return queryResult.queryOutput;
|
||||
}
|
||||
|
||||
|
|
@ -113,7 +113,7 @@ function createPackageJson({ filePaths, codeSnippets, projectName, refProjectNam
|
|||
* When a non imported ref dependency or a wrong version of a dev dependency needs to be
|
||||
* tested, please explicitly provide a ./package.json that does so.
|
||||
*/
|
||||
function mockTargetAndReferenceProject(searchTargetProject, referenceProject) {
|
||||
export function mockTargetAndReferenceProject(searchTargetProject, referenceProject) {
|
||||
const targetProjectName = searchTargetProject.name || 'fictional-target-project';
|
||||
const refProjectName = referenceProject.name || 'fictional-ref-project';
|
||||
|
||||
|
|
@ -156,12 +156,3 @@ function mockTargetAndReferenceProject(searchTargetProject, referenceProject) {
|
|||
targetMock,
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
mock,
|
||||
mockProject,
|
||||
restoreMockedProjects,
|
||||
getEntry,
|
||||
getEntries,
|
||||
mockTargetAndReferenceProject,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
const { ReportService } = require('../src/program/core/ReportService.js');
|
||||
|
||||
/**
|
||||
* @typedef {import('../src/program/types/core').QueryResult} QueryResult
|
||||
*/
|
||||
|
||||
const originalWriteToJson = ReportService.writeToJson;
|
||||
|
||||
/**
|
||||
* @param {QueryResult[]} queryResults
|
||||
*/
|
||||
function mockWriteToJson(queryResults) {
|
||||
ReportService.writeToJson = queryResult => {
|
||||
queryResults.push(queryResult);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {QueryResult[]} [queryResults]
|
||||
*/
|
||||
function restoreWriteToJson(queryResults) {
|
||||
ReportService.writeToJson = originalWriteToJson;
|
||||
while (queryResults?.length) {
|
||||
queryResults.pop();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
mockWriteToJson,
|
||||
restoreWriteToJson,
|
||||
};
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
Has a deprecated (from Node 16) export maps format:
|
||||
|
||||
```
|
||||
"exports": {
|
||||
"./src/": "./src/"
|
||||
})
|
||||
```
|
||||
```
|
||||
|
|
|
|||
|
|
@ -1,21 +1,22 @@
|
|||
const { InputDataService } = require('../src/program/core/InputDataService.js');
|
||||
const { QueryService } = require('../src/program/core/QueryService.js');
|
||||
const { restoreMockedProjects } = require('./mock-project-helpers.js');
|
||||
const { mockWriteToJson, restoreWriteToJson } = require('./mock-report-service-helpers.js');
|
||||
const {
|
||||
import { InputDataService } from '../src/program/core/InputDataService.js';
|
||||
import { QueryService } from '../src/program/core/QueryService.js';
|
||||
import { restoreMockedProjects } from './mock-project-helpers.js';
|
||||
import {
|
||||
suppressNonCriticalLogs,
|
||||
restoreSuppressNonCriticalLogs,
|
||||
} = require('./mock-log-service-helpers.js');
|
||||
const { memoizeConfig } = require('../src/program/utils/memoize.js');
|
||||
} from './mock-log-service-helpers.js';
|
||||
import { memoizeConfig } from '../src/program/utils/memoize.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../src/program/types/core').QueryResult} QueryResult
|
||||
* @returns {QueryResult[]}
|
||||
* @typedef {import('../types/index.js').QueryResult} QueryResult
|
||||
*/
|
||||
|
||||
function setupAnalyzerTest() {
|
||||
/** @type {QueryResult[]} */
|
||||
const queryResults = [];
|
||||
let hasRunBefore = false;
|
||||
|
||||
export function setupAnalyzerTest() {
|
||||
if (hasRunBefore) {
|
||||
return;
|
||||
}
|
||||
|
||||
const originalReferenceProjectPaths = InputDataService.referenceProjectPaths;
|
||||
const cacheDisabledQInitialValue = QueryService.cacheDisabled;
|
||||
|
|
@ -35,16 +36,12 @@ function setupAnalyzerTest() {
|
|||
|
||||
beforeEach(() => {
|
||||
InputDataService.referenceProjectPaths = [];
|
||||
mockWriteToJson(queryResults);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
InputDataService.referenceProjectPaths = originalReferenceProjectPaths;
|
||||
restoreWriteToJson(queryResults);
|
||||
restoreMockedProjects();
|
||||
});
|
||||
|
||||
return queryResults;
|
||||
hasRunBefore = true;
|
||||
}
|
||||
|
||||
module.exports = { setupAnalyzerTest };
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
const { Analyzer } = require('../../src/program/core/Analyzer.js');
|
||||
import { Analyzer } from '../../src/program/core/Analyzer.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('@babel/types').File} File
|
||||
* @typedef {import('../../src/program/types/core').QueryOutputEntry} QueryOutputEntry
|
||||
* @typedef {import('../../types/index.js').AnalyzerName} AnalyzerName
|
||||
* @typedef {import('../../types/index.js').QueryOutputEntry} QueryOutputEntry
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -31,7 +32,8 @@ const options = {
|
|||
* @param {File} ast
|
||||
*/
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function myAnalyzerPerAstEntry(ast) {
|
||||
function getResultPerAstFile(ast) {
|
||||
console.debug('myAnalyzerPerAstEntry');
|
||||
// Visit AST...
|
||||
const transformedEntryResult = [];
|
||||
// Do the traverse: https://babeljs.io/docs/en/babel-traverse
|
||||
|
|
@ -40,10 +42,9 @@ function myAnalyzerPerAstEntry(ast) {
|
|||
return transformedEntryResult;
|
||||
}
|
||||
|
||||
class DummyAnalyzer extends Analyzer {
|
||||
static get analyzerName() {
|
||||
return 'dummy-analyzer';
|
||||
}
|
||||
export class DummyAnalyzer extends Analyzer {
|
||||
/** @type {AnalyzerName} */
|
||||
static analyzerName = 'find-dummy-analyzer';
|
||||
|
||||
/**
|
||||
* @param {AstDataProject[]} astDataProjects
|
||||
|
|
@ -71,7 +72,7 @@ class DummyAnalyzer extends Analyzer {
|
|||
*/
|
||||
const queryOutput = await this._traverse((ast, astContext) => {
|
||||
// Run the traversel per entry
|
||||
let transformedEntryResult = myAnalyzerPerAstEntry(ast);
|
||||
let transformedEntryResult = getResultPerAstFile(ast);
|
||||
const meta = {};
|
||||
|
||||
// (optional): Post processors on TransformedEntry
|
||||
|
|
@ -93,5 +94,3 @@ class DummyAnalyzer extends Analyzer {
|
|||
return this._finalize(queryOutput, cfg);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { DummyAnalyzer };
|
||||
|
|
|
|||
|
|
@ -0,0 +1,415 @@
|
|||
/* eslint-disable no-unused-expressions */
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
import sinon from 'sinon';
|
||||
import pathLib from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { expect } from 'chai';
|
||||
import { it } from 'mocha';
|
||||
import {
|
||||
mockProject,
|
||||
restoreMockedProjects,
|
||||
mockTargetAndReferenceProject,
|
||||
} from '../../test-helpers/mock-project-helpers.js';
|
||||
import { _providenceModule } from '../../src/program/providence.js';
|
||||
import { _cliHelpersModule } from '../../src/cli/cli-helpers.js';
|
||||
import { toPosixPath } from '../../src/program/utils/to-posix-path.js';
|
||||
import { memoizeConfig } from '../../src/program/utils/memoize.js';
|
||||
import { getExtendDocsResults } from '../../src/cli/launch-providence-with-extend-docs.js';
|
||||
import { AstService } from '../../src/index.js';
|
||||
import { setupAnalyzerTest } from '../../test-helpers/setup-analyzer-test.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../../types/index.js').QueryResult} QueryResult
|
||||
*/
|
||||
|
||||
const __dirname = pathLib.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const { pathsArrayFromCs, pathsArrayFromCollectionName, appendProjectDependencyPaths } =
|
||||
_cliHelpersModule;
|
||||
|
||||
const externalCfgMock = {
|
||||
searchTargetCollections: {
|
||||
'lion-collection': [
|
||||
'./providence-input-data/search-targets/example-project-a',
|
||||
'./providence-input-data/search-targets/example-project-b',
|
||||
// ...etc
|
||||
],
|
||||
},
|
||||
referenceCollections: {
|
||||
'lion-based-ui-collection': [
|
||||
'./providence-input-data/references/lion-based-ui',
|
||||
'./providence-input-data/references/lion-based-ui-labs',
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
setupAnalyzerTest();
|
||||
|
||||
describe('CLI helpers', () => {
|
||||
const rootDir = toPosixPath(pathLib.resolve(__dirname, '../../'));
|
||||
|
||||
describe('pathsArrayFromCs', () => {
|
||||
it('allows absolute paths', async () => {
|
||||
expect(pathsArrayFromCs('/mocked/path/example-project', rootDir)).to.eql([
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
});
|
||||
|
||||
it('allows relative paths', async () => {
|
||||
expect(
|
||||
pathsArrayFromCs('./test-helpers/project-mocks/importing-target-project', rootDir),
|
||||
).to.eql([`${rootDir}/test-helpers/project-mocks/importing-target-project`]);
|
||||
expect(
|
||||
pathsArrayFromCs('test-helpers/project-mocks/importing-target-project', rootDir),
|
||||
).to.eql([`${rootDir}/test-helpers/project-mocks/importing-target-project`]);
|
||||
});
|
||||
|
||||
it('allows globs', async () => {
|
||||
expect(pathsArrayFromCs('test-helpers/project-mocks*', rootDir)).to.eql([
|
||||
`${rootDir}/test-helpers/project-mocks`,
|
||||
`${rootDir}/test-helpers/project-mocks-analyzer-outputs`,
|
||||
]);
|
||||
});
|
||||
|
||||
it('allows multiple comma separated paths', async () => {
|
||||
const paths =
|
||||
'test-helpers/project-mocks*, ./test-helpers/project-mocks/importing-target-project,/mocked/path/example-project';
|
||||
expect(pathsArrayFromCs(paths, rootDir)).to.eql([
|
||||
`${rootDir}/test-helpers/project-mocks`,
|
||||
`${rootDir}/test-helpers/project-mocks-analyzer-outputs`,
|
||||
`${rootDir}/test-helpers/project-mocks/importing-target-project`,
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('pathsArrayFromCollectionName', () => {
|
||||
it('gets collections from external target config', async () => {
|
||||
expect(
|
||||
pathsArrayFromCollectionName('lion-collection', 'search-target', externalCfgMock, rootDir),
|
||||
).to.eql(
|
||||
externalCfgMock.searchTargetCollections['lion-collection'].map(p =>
|
||||
toPosixPath(pathLib.join(rootDir, p)),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it('gets collections from external reference config', async () => {
|
||||
expect(
|
||||
pathsArrayFromCollectionName(
|
||||
'lion-based-ui-collection',
|
||||
'reference',
|
||||
externalCfgMock,
|
||||
rootDir,
|
||||
),
|
||||
).to.eql(
|
||||
externalCfgMock.referenceCollections['lion-based-ui-collection'].map(p =>
|
||||
toPosixPath(pathLib.join(rootDir, p)),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('appendProjectDependencyPaths', () => {
|
||||
beforeEach(() => {
|
||||
mockProject(
|
||||
{
|
||||
'./src/OriginalComp.js': `export class OriginalComp {}`,
|
||||
'./src/inbetween.js': `export { OriginalComp as InBetweenComp } from './OriginalComp.js'`,
|
||||
'./index.js': `export { InBetweenComp as MyComp } from './src/inbetween.js'`,
|
||||
'./node_modules/dependency-a/index.js': '',
|
||||
'./bower_components/dependency-b/index.js': '',
|
||||
'./node_modules/my-dependency/index.js': '',
|
||||
},
|
||||
{
|
||||
projectName: 'example-project',
|
||||
projectPath: '/mocked/path/example-project',
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('adds bower and node dependencies', async () => {
|
||||
const result = await appendProjectDependencyPaths(['/mocked/path/example-project']);
|
||||
expect(result).to.eql([
|
||||
'/mocked/path/example-project/node_modules/dependency-a',
|
||||
'/mocked/path/example-project/node_modules/my-dependency',
|
||||
'/mocked/path/example-project/bower_components/dependency-b',
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
});
|
||||
|
||||
it('allows a regex filter', async () => {
|
||||
const result = await appendProjectDependencyPaths(
|
||||
['/mocked/path/example-project'],
|
||||
'/^dependency-/',
|
||||
);
|
||||
expect(result).to.eql([
|
||||
'/mocked/path/example-project/node_modules/dependency-a',
|
||||
// in windows, it should not add '/mocked/path/example-project/node_modules/my-dependency',
|
||||
'/mocked/path/example-project/bower_components/dependency-b',
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
|
||||
const result2 = await appendProjectDependencyPaths(['/mocked/path/example-project'], '/b$/');
|
||||
expect(result2).to.eql([
|
||||
'/mocked/path/example-project/bower_components/dependency-b',
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
});
|
||||
|
||||
it('allows to filter out only npm or bower deps', async () => {
|
||||
const result = await appendProjectDependencyPaths(
|
||||
['/mocked/path/example-project'],
|
||||
undefined,
|
||||
['npm'],
|
||||
);
|
||||
expect(result).to.eql([
|
||||
'/mocked/path/example-project/node_modules/dependency-a',
|
||||
'/mocked/path/example-project/node_modules/my-dependency',
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
|
||||
const result2 = await appendProjectDependencyPaths(
|
||||
['/mocked/path/example-project'],
|
||||
undefined,
|
||||
['bower'],
|
||||
);
|
||||
expect(result2).to.eql([
|
||||
'/mocked/path/example-project/bower_components/dependency-b',
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Extend docs', () => {
|
||||
afterEach(() => {
|
||||
restoreMockedProjects();
|
||||
});
|
||||
|
||||
it('rewrites monorepo package paths when analysis is run from monorepo root', async () => {
|
||||
// This fails after InputDataService.addAstToProjectsData is memoized
|
||||
// (it does pass when run in isolation however, as a quick fix we disable memoization cache here...)
|
||||
memoizeConfig.isCacheDisabled = true;
|
||||
// Since we use the print method here, we need to force Babel, bc swc-to-babel output is not compatible
|
||||
// with @babel/generate
|
||||
const initialAstServiceFallbackToBabel = AstService.fallbackToBabel;
|
||||
AstService.fallbackToBabel = true;
|
||||
|
||||
const theirProjectFiles = {
|
||||
'./package.json': JSON.stringify({
|
||||
name: 'their-components',
|
||||
version: '1.0.0',
|
||||
}),
|
||||
'./src/TheirButton.js': `export class TheirButton extends HTMLElement {}`,
|
||||
'./src/TheirTooltip.js': `export class TheirTooltip extends HTMLElement {}`,
|
||||
'./their-button.js': `
|
||||
import { TheirButton } from './src/TheirButton.js';
|
||||
|
||||
customElements.define('their-button', TheirButton);
|
||||
`,
|
||||
'./demo.js': `
|
||||
import { TheirTooltip } from './src/TheirTooltip.js';
|
||||
import './their-button.js';
|
||||
`,
|
||||
};
|
||||
|
||||
const myProjectFiles = {
|
||||
'./package.json': JSON.stringify({
|
||||
name: '@my/root',
|
||||
workspaces: ['packages/*', 'another-folder/my-tooltip'],
|
||||
dependencies: {
|
||||
'their-components': '1.0.0',
|
||||
},
|
||||
}),
|
||||
// Package 1: @my/button
|
||||
'./packages/button/package.json': JSON.stringify({
|
||||
name: '@my/button',
|
||||
}),
|
||||
'./packages/button/src/MyButton.js': `
|
||||
import { TheirButton } from 'their-components/src/TheirButton.js';
|
||||
|
||||
export class MyButton extends TheirButton {}
|
||||
`,
|
||||
'./packages/button/src/my-button.js': `
|
||||
import { MyButton } from './MyButton.js';
|
||||
|
||||
customElements.define('my-button', MyButton);
|
||||
`,
|
||||
|
||||
// Package 2: @my/tooltip
|
||||
'./packages/tooltip/package.json': JSON.stringify({
|
||||
name: '@my/tooltip',
|
||||
}),
|
||||
'./packages/tooltip/src/MyTooltip.js': `
|
||||
import { TheirTooltip } from 'their-components/src/TheirTooltip.js';
|
||||
|
||||
export class MyTooltip extends TheirTooltip {}
|
||||
`,
|
||||
};
|
||||
|
||||
const theirProject = {
|
||||
path: '/my-components/node_modules/their-components',
|
||||
name: 'their-components',
|
||||
files: Object.entries(theirProjectFiles).map(([file, code]) => ({ file, code })),
|
||||
};
|
||||
|
||||
const myProject = {
|
||||
path: '/my-components',
|
||||
name: 'my-components',
|
||||
files: Object.entries(myProjectFiles).map(([file, code]) => ({ file, code })),
|
||||
};
|
||||
|
||||
mockTargetAndReferenceProject(theirProject, myProject);
|
||||
|
||||
const result = await getExtendDocsResults({
|
||||
referenceProjectPaths: [theirProject.path],
|
||||
prefixCfg: { from: 'their', to: 'my' },
|
||||
extensions: ['.js'],
|
||||
cwd: '/my-components',
|
||||
});
|
||||
|
||||
expect(result).to.eql([
|
||||
{
|
||||
name: 'TheirButton',
|
||||
variable: {
|
||||
from: 'TheirButton',
|
||||
to: 'MyButton',
|
||||
paths: [
|
||||
{
|
||||
from: './src/TheirButton.js',
|
||||
to: '@my/button/src/MyButton.js', // rewritten from './packages/button/src/MyButton.js',
|
||||
},
|
||||
{
|
||||
from: 'their-components/src/TheirButton.js',
|
||||
to: '@my/button/src/MyButton.js', // rewritten from './packages/button/src/MyButton.js',
|
||||
},
|
||||
],
|
||||
},
|
||||
tag: {
|
||||
from: 'their-button',
|
||||
to: 'my-button',
|
||||
paths: [
|
||||
{
|
||||
from: './their-button.js',
|
||||
to: '@my/button/src/my-button.js', // rewritten from './packages/button/src/MyButton.js',
|
||||
},
|
||||
{
|
||||
from: 'their-components/their-button.js',
|
||||
to: '@my/button/src/my-button.js', // rewritten from './packages/button/src/MyButton.js',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'TheirTooltip',
|
||||
variable: {
|
||||
from: 'TheirTooltip',
|
||||
to: 'MyTooltip',
|
||||
paths: [
|
||||
{
|
||||
from: './src/TheirTooltip.js',
|
||||
to: '@my/tooltip/src/MyTooltip.js', // './packages/tooltip/src/MyTooltip.js',
|
||||
},
|
||||
{
|
||||
from: 'their-components/src/TheirTooltip.js',
|
||||
to: '@my/tooltip/src/MyTooltip.js', // './packages/tooltip/src/MyTooltip.js',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
AstService.fallbackToBabel = initialAstServiceFallbackToBabel;
|
||||
});
|
||||
|
||||
it('does not check for match compatibility (target and reference) in monorepo targets', async () => {
|
||||
// ===== REFERENCE AND TARGET PROJECTS =====
|
||||
|
||||
const theirProjectFiles = {
|
||||
'./package.json': JSON.stringify({
|
||||
name: 'their-components',
|
||||
version: '1.0.0',
|
||||
}),
|
||||
'./src/TheirButton.js': `export class TheirButton extends HTMLElement {}`,
|
||||
};
|
||||
|
||||
// This will be detected as being a monorepo
|
||||
const monoProjectFiles = {
|
||||
'./package.json': JSON.stringify({
|
||||
name: '@mono/root',
|
||||
workspaces: ['packages/*'],
|
||||
dependencies: {
|
||||
'their-components': '1.0.0',
|
||||
},
|
||||
}),
|
||||
// Package: @mono/button
|
||||
'./packages/button/package.json': JSON.stringify({
|
||||
name: '@mono/button',
|
||||
}),
|
||||
};
|
||||
|
||||
// This will be detected as NOT being a monorepo
|
||||
const nonMonoProjectFiles = {
|
||||
'./package.json': JSON.stringify({
|
||||
name: 'non-mono',
|
||||
dependencies: {
|
||||
'their-components': '1.0.0',
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
const theirProject = {
|
||||
path: '/their-components',
|
||||
name: 'their-components',
|
||||
files: Object.entries(theirProjectFiles).map(([file, code]) => ({ file, code })),
|
||||
};
|
||||
|
||||
const monoProject = {
|
||||
path: '/mono-components',
|
||||
name: 'mono-components',
|
||||
files: Object.entries(monoProjectFiles).map(([file, code]) => ({ file, code })),
|
||||
};
|
||||
|
||||
const nonMonoProject = {
|
||||
path: '/non-mono-components',
|
||||
name: 'non-mono-components',
|
||||
files: Object.entries(nonMonoProjectFiles).map(([file, code]) => ({ file, code })),
|
||||
};
|
||||
|
||||
// ===== TESTS =====
|
||||
|
||||
const providenceStub = sinon.stub(_providenceModule, 'providence').returns(
|
||||
new Promise(resolve => {
|
||||
resolve([]);
|
||||
}),
|
||||
);
|
||||
|
||||
// ===== mono =====
|
||||
|
||||
mockTargetAndReferenceProject(theirProject, monoProject);
|
||||
await getExtendDocsResults({
|
||||
referenceProjectPaths: ['/their-components'],
|
||||
prefixCfg: { from: 'their', to: 'my' },
|
||||
extensions: ['.js'],
|
||||
cwd: '/mono-components',
|
||||
});
|
||||
|
||||
expect(providenceStub.args[0][1].skipCheckMatchCompatibility).to.equal(true);
|
||||
providenceStub.resetHistory();
|
||||
restoreMockedProjects();
|
||||
|
||||
// ===== non mono =====
|
||||
|
||||
mockTargetAndReferenceProject(theirProject, nonMonoProject);
|
||||
await getExtendDocsResults({
|
||||
referenceProjectPaths: ['/their-components'],
|
||||
prefixCfg: { from: 'their', to: 'my' },
|
||||
extensions: ['.js'],
|
||||
cwd: '/non-mono-components',
|
||||
});
|
||||
expect(providenceStub.args[0][1].skipCheckMatchCompatibility).to.equal(false);
|
||||
|
||||
providenceStub.restore();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
import pathLib from 'path';
|
||||
import { expect } from 'chai';
|
||||
import { it } from 'mocha';
|
||||
import { appendProjectDependencyPaths } from '../../src/cli/cli-helpers.js';
|
||||
import { toPosixPath } from '../../src/program/utils/to-posix-path.js';
|
||||
import { getCurrentDir } from '../../src/program/utils/get-current-dir.mjs';
|
||||
import { getCurrentDir } from '../../src/program/utils/get-current-dir.js';
|
||||
|
||||
/**
|
||||
* These tests are added on top of unit tests. See:
|
||||
436
packages-node/providence-analytics/test-node/cli/cli.test.js
Normal file
436
packages-node/providence-analytics/test-node/cli/cli.test.js
Normal file
|
|
@ -0,0 +1,436 @@
|
|||
/* eslint-disable no-unused-expressions */
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
import sinon from 'sinon';
|
||||
import { expect } from 'chai';
|
||||
import { it } from 'mocha';
|
||||
import commander from 'commander';
|
||||
import { mockProject } from '../../test-helpers/mock-project-helpers.js';
|
||||
import { InputDataService } from '../../src/program/core/InputDataService.js';
|
||||
import { QueryService } from '../../src/program/core/QueryService.js';
|
||||
import { _providenceModule } from '../../src/program/providence.js';
|
||||
import { _cliHelpersModule } from '../../src/cli/cli-helpers.js';
|
||||
import { cli } from '../../src/cli/cli.js';
|
||||
import { _promptAnalyzerMenuModule } from '../../src/cli/prompt-analyzer-menu.js';
|
||||
import { memoizeConfig } from '../../src/program/utils/memoize.js';
|
||||
import { _extendDocsModule } from '../../src/cli/launch-providence-with-extend-docs.js';
|
||||
import { dashboardServer } from '../../dashboard/server.js';
|
||||
import { setupAnalyzerTest } from '../../test-helpers/setup-analyzer-test.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../../types/index.js').QueryResult} QueryResult
|
||||
*/
|
||||
|
||||
const externalCfgMock = {
|
||||
searchTargetCollections: {
|
||||
'lion-collection': [
|
||||
'./providence-input-data/search-targets/example-project-a',
|
||||
'./providence-input-data/search-targets/example-project-b',
|
||||
// ...etc
|
||||
],
|
||||
},
|
||||
referenceCollections: {
|
||||
'lion-based-ui-collection': [
|
||||
'./providence-input-data/references/lion-based-ui',
|
||||
'./providence-input-data/references/lion-based-ui-labs',
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
setupAnalyzerTest();
|
||||
|
||||
/**
|
||||
* @param {string} args
|
||||
* @param {string} cwd
|
||||
*/
|
||||
async function runCli(args, cwd) {
|
||||
const argv = [
|
||||
...process.argv.slice(0, 2),
|
||||
...args.split(' ').map(a => a.replace(/^("|')?(.*)("|')?$/, '$2')),
|
||||
];
|
||||
await cli({ argv, cwd });
|
||||
}
|
||||
|
||||
describe('Providence CLI', () => {
|
||||
const rootDir = '/mocked/path/example-project';
|
||||
|
||||
/** @type {sinon.SinonStub} */
|
||||
let providenceStub;
|
||||
/** @type {sinon.SinonStub} */
|
||||
let promptCfgStub;
|
||||
/** @type {sinon.SinonStub} */
|
||||
let iExtConfStub;
|
||||
/** @type {sinon.SinonStub} */
|
||||
let promptStub;
|
||||
/** @type {sinon.SinonStub} */
|
||||
let qConfStub;
|
||||
|
||||
before(() => {
|
||||
// Prevent MaxListenersExceededWarning
|
||||
commander.setMaxListeners(100);
|
||||
|
||||
/** @type {sinon.SinonStub} */
|
||||
providenceStub = sinon.stub(_providenceModule, 'providence').returns(Promise.resolve());
|
||||
|
||||
/** @type {sinon.SinonStub} */
|
||||
promptCfgStub = sinon
|
||||
.stub(_promptAnalyzerMenuModule, 'promptAnalyzerConfigMenu')
|
||||
.returns(Promise.resolve({ analyzerConfig: { con: 'fig' } }));
|
||||
|
||||
/** @type {sinon.SinonStub} */
|
||||
iExtConfStub = sinon.stub(InputDataService, 'getExternalConfig').returns(externalCfgMock);
|
||||
|
||||
/** @type {sinon.SinonStub} */
|
||||
promptStub = sinon
|
||||
.stub(_promptAnalyzerMenuModule, 'promptAnalyzerMenu')
|
||||
.returns(Promise.resolve({ analyzerName: 'match-analyzer-mock' }));
|
||||
|
||||
/** @type {sinon.SinonStub} */
|
||||
qConfStub = sinon.stub(QueryService, 'getQueryConfigFromAnalyzer').returns(
|
||||
// @ts-expect-error
|
||||
Promise.resolve({
|
||||
analyzer: {
|
||||
name: 'match-analyzer-mock',
|
||||
requiresReference: true,
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
commander.setMaxListeners(10);
|
||||
|
||||
providenceStub.restore();
|
||||
promptCfgStub.restore();
|
||||
iExtConfStub.restore();
|
||||
promptStub.restore();
|
||||
qConfStub.restore();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
mockProject(
|
||||
{
|
||||
'./src/OriginalComp.js': `export class OriginalComp {}`,
|
||||
'./src/inbetween.js': `export { OriginalComp as InBetweenComp } from './OriginalComp.js'`,
|
||||
'./index.js': `export { InBetweenComp as MyComp } from './src/inbetween.js'`,
|
||||
'./node_modules/dependency-a/index.js': '',
|
||||
'./bower_components/dependency-b/index.js': '',
|
||||
},
|
||||
{
|
||||
projectName: 'example-project',
|
||||
projectPath: '/mocked/path/example-project',
|
||||
},
|
||||
);
|
||||
memoizeConfig.isCacheDisabled = true;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
providenceStub.resetHistory();
|
||||
promptCfgStub.resetHistory();
|
||||
iExtConfStub.resetHistory();
|
||||
promptStub.resetHistory();
|
||||
qConfStub.resetHistory();
|
||||
});
|
||||
|
||||
const analyzeCmd = 'analyze match-analyzer-mock';
|
||||
|
||||
it('calls providence', async () => {
|
||||
await runCli(`${analyzeCmd} -t /mocked/path/example-project`, rootDir);
|
||||
expect(providenceStub.called).to.be.true;
|
||||
});
|
||||
|
||||
it('creates a QueryConfig', async () => {
|
||||
await runCli(`${analyzeCmd} -t /mocked/path/example-project`, rootDir);
|
||||
expect(qConfStub.called).to.be.true;
|
||||
expect(qConfStub.args[0][0]).to.equal('match-analyzer-mock');
|
||||
});
|
||||
|
||||
describe('Global options', () => {
|
||||
const anyCmdThatAcceptsGlobalOpts = 'analyze match-analyzer-mock';
|
||||
|
||||
/** @type {sinon.SinonStub} */
|
||||
let pathsArrayFromCollectionStub;
|
||||
/** @type {sinon.SinonStub} */
|
||||
let pathsArrayFromCsStub;
|
||||
/** @type {sinon.SinonStub} */
|
||||
let appendProjectDependencyPathsStub;
|
||||
|
||||
before(() => {
|
||||
pathsArrayFromCsStub = sinon
|
||||
.stub(_cliHelpersModule, 'pathsArrayFromCs')
|
||||
.returns(['/mocked/path/example-project']);
|
||||
pathsArrayFromCollectionStub = sinon
|
||||
.stub(_cliHelpersModule, 'pathsArrayFromCollectionName')
|
||||
.returns(['/mocked/path/example-project']);
|
||||
appendProjectDependencyPathsStub = sinon
|
||||
.stub(_cliHelpersModule, 'appendProjectDependencyPaths')
|
||||
.returns(
|
||||
Promise.resolve([
|
||||
'/mocked/path/example-project',
|
||||
'/mocked/path/example-project/node_modules/mock-dep-a',
|
||||
'/mocked/path/example-project/bower_components/mock-dep-b',
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
pathsArrayFromCsStub.restore();
|
||||
pathsArrayFromCollectionStub.restore();
|
||||
appendProjectDependencyPathsStub.restore();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
pathsArrayFromCsStub.resetHistory();
|
||||
pathsArrayFromCollectionStub.resetHistory();
|
||||
appendProjectDependencyPathsStub.resetHistory();
|
||||
});
|
||||
|
||||
it('"-e --extensions"', async () => {
|
||||
await runCli(`${anyCmdThatAcceptsGlobalOpts} -e bla,blu`, rootDir);
|
||||
expect(providenceStub.args[0][1].gatherFilesConfig.extensions).to.eql(['.bla', '.blu']);
|
||||
|
||||
providenceStub.resetHistory();
|
||||
|
||||
await runCli(`${anyCmdThatAcceptsGlobalOpts} --extensions bla,blu`, rootDir);
|
||||
expect(providenceStub.args[0][1].gatherFilesConfig.extensions).to.eql(['.bla', '.blu']);
|
||||
});
|
||||
|
||||
it('"-t --search-target-paths"', async () => {
|
||||
await runCli(`${anyCmdThatAcceptsGlobalOpts} -t /mocked/path/example-project`, rootDir);
|
||||
expect(pathsArrayFromCsStub.args[0][0]).to.equal('/mocked/path/example-project');
|
||||
expect(providenceStub.args[0][1].targetProjectPaths).to.eql(['/mocked/path/example-project']);
|
||||
|
||||
pathsArrayFromCsStub.resetHistory();
|
||||
providenceStub.resetHistory();
|
||||
|
||||
await runCli(
|
||||
`${anyCmdThatAcceptsGlobalOpts} --search-target-paths /mocked/path/example-project`,
|
||||
rootDir,
|
||||
);
|
||||
expect(pathsArrayFromCsStub.args[0][0]).to.equal('/mocked/path/example-project');
|
||||
expect(providenceStub.args[0][1].targetProjectPaths).to.eql(['/mocked/path/example-project']);
|
||||
});
|
||||
|
||||
it('"-r --reference-paths"', async () => {
|
||||
await runCli(`${anyCmdThatAcceptsGlobalOpts} -r /mocked/path/example-project`, rootDir);
|
||||
expect(pathsArrayFromCsStub.args[0][0]).to.equal('/mocked/path/example-project');
|
||||
expect(providenceStub.args[0][1].referenceProjectPaths).to.eql([
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
|
||||
pathsArrayFromCsStub.resetHistory();
|
||||
providenceStub.resetHistory();
|
||||
|
||||
await runCli(
|
||||
`${anyCmdThatAcceptsGlobalOpts} --reference-paths /mocked/path/example-project`,
|
||||
rootDir,
|
||||
);
|
||||
expect(pathsArrayFromCsStub.args[0][0]).to.equal('/mocked/path/example-project');
|
||||
expect(providenceStub.args[0][1].referenceProjectPaths).to.eql([
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
});
|
||||
|
||||
it('"--search-target-collection"', async () => {
|
||||
await runCli(
|
||||
`${anyCmdThatAcceptsGlobalOpts} --search-target-collection lion-collection`,
|
||||
rootDir,
|
||||
);
|
||||
expect(pathsArrayFromCollectionStub.args[0][0]).to.equal('lion-collection');
|
||||
expect(providenceStub.args[0][1].targetProjectPaths).to.eql(['/mocked/path/example-project']);
|
||||
});
|
||||
|
||||
it('"--reference-collection"', async () => {
|
||||
await runCli(
|
||||
`${anyCmdThatAcceptsGlobalOpts} --reference-collection lion-based-ui-collection`,
|
||||
rootDir,
|
||||
);
|
||||
expect(pathsArrayFromCollectionStub.args[0][0]).to.equal('lion-based-ui-collection');
|
||||
expect(providenceStub.args[0][1].referenceProjectPaths).to.eql([
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
});
|
||||
|
||||
it('"-a --allowlist"', async () => {
|
||||
await runCli(`${anyCmdThatAcceptsGlobalOpts} -a mocked/**/*,rocked/*`, rootDir);
|
||||
expect(providenceStub.args[0][1].gatherFilesConfig.allowlist).to.eql([
|
||||
'mocked/**/*',
|
||||
'rocked/*',
|
||||
]);
|
||||
|
||||
providenceStub.resetHistory();
|
||||
|
||||
await runCli(`${anyCmdThatAcceptsGlobalOpts} --allowlist mocked/**/*,rocked/*`, rootDir);
|
||||
expect(providenceStub.args[0][1].gatherFilesConfig.allowlist).to.eql([
|
||||
'mocked/**/*',
|
||||
'rocked/*',
|
||||
]);
|
||||
});
|
||||
|
||||
it('"--allowlist-reference"', async () => {
|
||||
await runCli(
|
||||
`${anyCmdThatAcceptsGlobalOpts} --allowlist-reference mocked/**/*,rocked/*`,
|
||||
rootDir,
|
||||
);
|
||||
expect(providenceStub.args[0][1].gatherFilesConfigReference.allowlist).to.eql([
|
||||
'mocked/**/*',
|
||||
'rocked/*',
|
||||
]);
|
||||
});
|
||||
|
||||
it('"--allowlist-mode"', async () => {
|
||||
await runCli(`${anyCmdThatAcceptsGlobalOpts} --allowlist-mode git`, rootDir);
|
||||
expect(providenceStub.args[0][1].gatherFilesConfig.allowlistMode).to.equal('git');
|
||||
});
|
||||
|
||||
it('"--allowlist-mode-reference"', async () => {
|
||||
await runCli(`${anyCmdThatAcceptsGlobalOpts} --allowlist-mode-reference npm`, rootDir);
|
||||
expect(providenceStub.args[0][1].gatherFilesConfigReference.allowlistMode).to.equal('npm');
|
||||
});
|
||||
|
||||
it('"-D --debug"', async () => {
|
||||
await runCli(`${anyCmdThatAcceptsGlobalOpts} -D`, rootDir);
|
||||
expect(providenceStub.args[0][1].debugEnabled).to.equal(true);
|
||||
|
||||
providenceStub.resetHistory();
|
||||
|
||||
await runCli(`${anyCmdThatAcceptsGlobalOpts} --debug`, rootDir);
|
||||
expect(providenceStub.args[0][1].debugEnabled).to.equal(true);
|
||||
});
|
||||
|
||||
it('"--write-log-file"', async () => {
|
||||
await runCli(`${anyCmdThatAcceptsGlobalOpts} --write-log-file`, rootDir);
|
||||
expect(providenceStub.args[0][1].writeLogFile).to.equal(true);
|
||||
});
|
||||
|
||||
it('"--target-dependencies"', async () => {
|
||||
await runCli(`${anyCmdThatAcceptsGlobalOpts}`, rootDir);
|
||||
expect(appendProjectDependencyPathsStub.called).to.be.false;
|
||||
|
||||
appendProjectDependencyPathsStub.resetHistory();
|
||||
providenceStub.resetHistory();
|
||||
|
||||
await runCli(`${anyCmdThatAcceptsGlobalOpts} --target-dependencies`, rootDir);
|
||||
expect(appendProjectDependencyPathsStub.called).to.be.true;
|
||||
expect(providenceStub.args[0][1].targetProjectPaths).to.eql([
|
||||
'/mocked/path/example-project',
|
||||
'/mocked/path/example-project/node_modules/mock-dep-a',
|
||||
'/mocked/path/example-project/bower_components/mock-dep-b',
|
||||
]);
|
||||
});
|
||||
|
||||
it('"--target-dependencies /^with-regex/"', async () => {
|
||||
await runCli(`${anyCmdThatAcceptsGlobalOpts} --target-dependencies /^mock-/`, rootDir);
|
||||
expect(appendProjectDependencyPathsStub.args[0][1]).to.equal('/^mock-/');
|
||||
});
|
||||
|
||||
it('"--skip-check-match-compatibility"', async () => {
|
||||
await runCli(`${anyCmdThatAcceptsGlobalOpts} --skip-check-match-compatibility`, rootDir);
|
||||
expect(providenceStub.args[0][1].skipCheckMatchCompatibility).to.equal(true);
|
||||
});
|
||||
|
||||
it('"--fallback-to-babel"', async () => {
|
||||
await runCli(`${anyCmdThatAcceptsGlobalOpts} --fallback-to-babel`, rootDir);
|
||||
expect(providenceStub.args[0][1].fallbackToBabel).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Commands', () => {
|
||||
describe('Analyze', () => {
|
||||
it('calls providence', async () => {
|
||||
await runCli(`${analyzeCmd}`, rootDir);
|
||||
expect(providenceStub.called).to.be.true;
|
||||
});
|
||||
|
||||
describe('Options', () => {
|
||||
it('"-o --prompt-optional-config"', async () => {
|
||||
await runCli(`analyze -o`, rootDir);
|
||||
expect(promptStub.called).to.be.true;
|
||||
|
||||
promptStub.resetHistory();
|
||||
|
||||
await runCli(`analyze --prompt-optional-config`, rootDir);
|
||||
expect(promptStub.called).to.be.true;
|
||||
});
|
||||
|
||||
it('"-c --config"', async () => {
|
||||
await runCli(`analyze match-analyzer-mock -c {"a":"2"}`, rootDir);
|
||||
expect(qConfStub.args[0][0]).to.equal('match-analyzer-mock');
|
||||
expect(qConfStub.args[0][1]).to.eql({ a: '2', metaConfig: {} });
|
||||
|
||||
qConfStub.resetHistory();
|
||||
|
||||
await runCli(`analyze match-analyzer-mock --config {"a":"2"}`, rootDir);
|
||||
expect(qConfStub.args[0][0]).to.equal('match-analyzer-mock');
|
||||
expect(qConfStub.args[0][1]).to.eql({ a: '2', metaConfig: {} });
|
||||
});
|
||||
|
||||
it('calls "promptAnalyzerConfigMenu" without config given', async () => {
|
||||
await runCli(`analyze match-analyzer-mock`, rootDir);
|
||||
expect(promptCfgStub.called).to.be.true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('Query', () => {});
|
||||
describe.skip('Search', () => {});
|
||||
|
||||
describe('Manage', () => {});
|
||||
|
||||
describe('Dashboard', () => {
|
||||
/** @type {sinon.SinonStub} */
|
||||
const startStub = sinon.stub(dashboardServer, 'start');
|
||||
it('spawns a dashboard', async () => {
|
||||
runCli(`dashboard`, rootDir);
|
||||
expect(startStub.called).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
describe('Extend docs', () => {
|
||||
/** @type {sinon.SinonStub} */
|
||||
let extendDocsStub;
|
||||
|
||||
before(() => {
|
||||
extendDocsStub = sinon
|
||||
.stub(_extendDocsModule, 'launchProvidenceWithExtendDocs')
|
||||
.returns(Promise.resolve());
|
||||
});
|
||||
|
||||
after(() => {
|
||||
extendDocsStub.restore();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
extendDocsStub.resetHistory();
|
||||
});
|
||||
|
||||
it('allows configuration', async () => {
|
||||
await runCli(
|
||||
[
|
||||
'extend-docs',
|
||||
'-t /xyz',
|
||||
'-r /xyz/x',
|
||||
'--prefix-from pfrom --prefix-to pto',
|
||||
'--output-folder /outp',
|
||||
'--extensions bla',
|
||||
'--allowlist al --allowlist-reference alr',
|
||||
].join(' '),
|
||||
rootDir,
|
||||
);
|
||||
expect(extendDocsStub.called).to.be.true;
|
||||
expect(extendDocsStub.args[0][0]).to.eql({
|
||||
referenceProjectPaths: ['/xyz/x'],
|
||||
prefixCfg: {
|
||||
from: 'pfrom',
|
||||
to: 'pto',
|
||||
},
|
||||
outputFolder: '/outp',
|
||||
extensions: ['.bla'],
|
||||
allowlist: ['al'],
|
||||
allowlistReference: ['alr'],
|
||||
cwd: '/mocked/path/example-project',
|
||||
skipCheckMatchCompatibility: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,807 +0,0 @@
|
|||
/* eslint-disable no-unused-expressions */
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
import sinon from 'sinon';
|
||||
import pathLib from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { expect } from 'chai';
|
||||
import commander from 'commander';
|
||||
import {
|
||||
mockProject,
|
||||
restoreMockedProjects,
|
||||
mockTargetAndReferenceProject,
|
||||
} from '../../test-helpers/mock-project-helpers.js';
|
||||
import {
|
||||
mockWriteToJson,
|
||||
restoreWriteToJson,
|
||||
} from '../../test-helpers/mock-report-service-helpers.js';
|
||||
import {
|
||||
suppressNonCriticalLogs,
|
||||
restoreSuppressNonCriticalLogs,
|
||||
} from '../../test-helpers/mock-log-service-helpers.js';
|
||||
import { InputDataService } from '../../src/program/core/InputDataService.js';
|
||||
import { QueryService } from '../../src/program/core/QueryService.js';
|
||||
import providenceModule from '../../src/program/providence.js';
|
||||
import cliHelpersModule from '../../src/cli/cli-helpers.js';
|
||||
import { cli } from '../../src/cli/cli.mjs';
|
||||
import promptAnalyzerModule from '../../src/cli/prompt-analyzer-menu.js';
|
||||
import { toPosixPath } from '../../src/program/utils/to-posix-path.js';
|
||||
import { memoizeConfig } from '../../src/program/utils/memoize.js';
|
||||
import extendDocsModule, {
|
||||
getExtendDocsResults,
|
||||
} from '../../src/cli/launch-providence-with-extend-docs.js';
|
||||
import { dashboardServer } from '../../dashboard/server.mjs';
|
||||
|
||||
/**
|
||||
* @typedef {import('../../src/program/types/core').QueryResult} QueryResult
|
||||
*/
|
||||
|
||||
const __dirname = pathLib.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const { pathsArrayFromCs, pathsArrayFromCollectionName, appendProjectDependencyPaths } =
|
||||
cliHelpersModule;
|
||||
|
||||
/** @type {QueryResult[]} */
|
||||
const queryResults = [];
|
||||
|
||||
const externalCfgMock = {
|
||||
searchTargetCollections: {
|
||||
'lion-collection': [
|
||||
'./providence-input-data/search-targets/example-project-a',
|
||||
'./providence-input-data/search-targets/example-project-b',
|
||||
// ...etc
|
||||
],
|
||||
},
|
||||
referenceCollections: {
|
||||
'lion-based-ui-collection': [
|
||||
'./providence-input-data/references/lion-based-ui',
|
||||
'./providence-input-data/references/lion-based-ui-labs',
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} args
|
||||
* @param {string} cwd
|
||||
*/
|
||||
async function runCli(args, cwd) {
|
||||
const argv = [
|
||||
...process.argv.slice(0, 2),
|
||||
...args.split(' ').map(a => a.replace(/^("|')?(.*)("|')?$/, '$2')),
|
||||
];
|
||||
await cli({ argv, cwd });
|
||||
}
|
||||
|
||||
describe('Providence CLI', () => {
|
||||
const rootDir = '/mocked/path/example-project';
|
||||
|
||||
/** @type {sinon.SinonStub} */
|
||||
let providenceStub;
|
||||
/** @type {sinon.SinonStub} */
|
||||
let promptCfgStub;
|
||||
/** @type {sinon.SinonStub} */
|
||||
let iExtConfStub;
|
||||
/** @type {sinon.SinonStub} */
|
||||
let promptStub;
|
||||
/** @type {sinon.SinonStub} */
|
||||
let qConfStub;
|
||||
|
||||
const memoizeCacheDisabledInitial = memoizeConfig.isCacheDisabled;
|
||||
memoizeConfig.isCacheDisabled = true;
|
||||
|
||||
before(() => {
|
||||
// Prevent MaxListenersExceededWarning
|
||||
commander.setMaxListeners(100);
|
||||
|
||||
mockWriteToJson(queryResults);
|
||||
suppressNonCriticalLogs();
|
||||
|
||||
mockProject(
|
||||
{
|
||||
'./src/OriginalComp.js': `export class OriginalComp {}`,
|
||||
'./src/inbetween.js': `export { OriginalComp as InBetweenComp } from './OriginalComp.js'`,
|
||||
'./index.js': `export { InBetweenComp as MyComp } from './src/inbetween.js'`,
|
||||
'./node_modules/dependency-a/index.js': '',
|
||||
'./bower_components/dependency-b/index.js': '',
|
||||
},
|
||||
{
|
||||
projectName: 'example-project',
|
||||
projectPath: '/mocked/path/example-project',
|
||||
},
|
||||
);
|
||||
|
||||
/** @type {sinon.SinonStub} */
|
||||
providenceStub = sinon.stub(providenceModule, 'providence').returns(Promise.resolve());
|
||||
|
||||
/** @type {sinon.SinonStub} */
|
||||
promptCfgStub = sinon
|
||||
.stub(promptAnalyzerModule, 'promptAnalyzerConfigMenu')
|
||||
.returns(Promise.resolve({ analyzerConfig: { con: 'fig' } }));
|
||||
|
||||
/** @type {sinon.SinonStub} */
|
||||
iExtConfStub = sinon.stub(InputDataService, 'getExternalConfig').returns(externalCfgMock);
|
||||
|
||||
/** @type {sinon.SinonStub} */
|
||||
promptStub = sinon
|
||||
.stub(promptAnalyzerModule, 'promptAnalyzerMenu')
|
||||
.returns(Promise.resolve({ analyzerName: 'match-analyzer-mock' }));
|
||||
|
||||
/** @type {sinon.SinonStub} */
|
||||
qConfStub = sinon.stub(QueryService, 'getQueryConfigFromAnalyzer').returns({
|
||||
analyzer: {
|
||||
name: 'match-analyzer-mock',
|
||||
requiresReference: true,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
after(() => {
|
||||
commander.setMaxListeners(10);
|
||||
|
||||
restoreSuppressNonCriticalLogs();
|
||||
restoreMockedProjects();
|
||||
restoreWriteToJson();
|
||||
|
||||
providenceStub.restore();
|
||||
promptCfgStub.restore();
|
||||
iExtConfStub.restore();
|
||||
promptStub.restore();
|
||||
qConfStub.restore();
|
||||
|
||||
memoizeConfig.isCacheDisabled = memoizeCacheDisabledInitial;
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
memoizeConfig.isCacheDisabled = true;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
providenceStub.resetHistory();
|
||||
promptCfgStub.resetHistory();
|
||||
iExtConfStub.resetHistory();
|
||||
promptStub.resetHistory();
|
||||
qConfStub.resetHistory();
|
||||
});
|
||||
|
||||
const analyzeCmd = 'analyze match-analyzer-mock';
|
||||
|
||||
it('calls providence', async () => {
|
||||
await runCli(`${analyzeCmd} -t /mocked/path/example-project`, rootDir);
|
||||
expect(providenceStub.called).to.be.true;
|
||||
});
|
||||
|
||||
it('creates a QueryConfig', async () => {
|
||||
await runCli(`${analyzeCmd} -t /mocked/path/example-project`, rootDir);
|
||||
expect(qConfStub.called).to.be.true;
|
||||
expect(qConfStub.args[0][0]).to.equal('match-analyzer-mock');
|
||||
});
|
||||
|
||||
describe('Global options', () => {
|
||||
/** @type {sinon.SinonStub} */
|
||||
let pathsArrayFromCollectionStub;
|
||||
/** @type {sinon.SinonStub} */
|
||||
let pathsArrayFromCsStub;
|
||||
/** @type {sinon.SinonStub} */
|
||||
let appendProjectDependencyPathsStub;
|
||||
|
||||
before(() => {
|
||||
pathsArrayFromCsStub = sinon
|
||||
.stub(cliHelpersModule, 'pathsArrayFromCs')
|
||||
.returns(['/mocked/path/example-project']);
|
||||
pathsArrayFromCollectionStub = sinon
|
||||
.stub(cliHelpersModule, 'pathsArrayFromCollectionName')
|
||||
.returns(['/mocked/path/example-project']);
|
||||
appendProjectDependencyPathsStub = sinon
|
||||
.stub(cliHelpersModule, 'appendProjectDependencyPaths')
|
||||
.returns(
|
||||
Promise.resolve([
|
||||
'/mocked/path/example-project',
|
||||
'/mocked/path/example-project/node_modules/mock-dep-a',
|
||||
'/mocked/path/example-project/bower_components/mock-dep-b',
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
pathsArrayFromCsStub.restore();
|
||||
pathsArrayFromCollectionStub.restore();
|
||||
appendProjectDependencyPathsStub.restore();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
pathsArrayFromCsStub.resetHistory();
|
||||
pathsArrayFromCollectionStub.resetHistory();
|
||||
appendProjectDependencyPathsStub.resetHistory();
|
||||
});
|
||||
|
||||
it('"-e --extensions"', async () => {
|
||||
await runCli(`${analyzeCmd} -e bla,blu`, rootDir);
|
||||
expect(providenceStub.args[0][1].gatherFilesConfig.extensions).to.eql(['.bla', '.blu']);
|
||||
|
||||
providenceStub.resetHistory();
|
||||
|
||||
await runCli(`${analyzeCmd} --extensions bla,blu`, rootDir);
|
||||
expect(providenceStub.args[0][1].gatherFilesConfig.extensions).to.eql(['.bla', '.blu']);
|
||||
});
|
||||
|
||||
it('"-t --search-target-paths"', async () => {
|
||||
await runCli(`${analyzeCmd} -t /mocked/path/example-project`, rootDir);
|
||||
expect(pathsArrayFromCsStub.args[0][0]).to.equal('/mocked/path/example-project');
|
||||
expect(providenceStub.args[0][1].targetProjectPaths).to.eql(['/mocked/path/example-project']);
|
||||
|
||||
pathsArrayFromCsStub.resetHistory();
|
||||
providenceStub.resetHistory();
|
||||
|
||||
await runCli(`${analyzeCmd} --search-target-paths /mocked/path/example-project`, rootDir);
|
||||
expect(pathsArrayFromCsStub.args[0][0]).to.equal('/mocked/path/example-project');
|
||||
expect(providenceStub.args[0][1].targetProjectPaths).to.eql(['/mocked/path/example-project']);
|
||||
});
|
||||
|
||||
it('"-r --reference-paths"', async () => {
|
||||
await runCli(`${analyzeCmd} -r /mocked/path/example-project`, rootDir);
|
||||
expect(pathsArrayFromCsStub.args[0][0]).to.equal('/mocked/path/example-project');
|
||||
expect(providenceStub.args[0][1].referenceProjectPaths).to.eql([
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
|
||||
pathsArrayFromCsStub.resetHistory();
|
||||
providenceStub.resetHistory();
|
||||
|
||||
await runCli(`${analyzeCmd} --reference-paths /mocked/path/example-project`, rootDir);
|
||||
expect(pathsArrayFromCsStub.args[0][0]).to.equal('/mocked/path/example-project');
|
||||
expect(providenceStub.args[0][1].referenceProjectPaths).to.eql([
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
});
|
||||
|
||||
it('"--search-target-collection"', async () => {
|
||||
await runCli(`${analyzeCmd} --search-target-collection lion-collection`, rootDir);
|
||||
expect(pathsArrayFromCollectionStub.args[0][0]).to.equal('lion-collection');
|
||||
expect(providenceStub.args[0][1].targetProjectPaths).to.eql(['/mocked/path/example-project']);
|
||||
});
|
||||
|
||||
it('"--reference-collection"', async () => {
|
||||
await runCli(`${analyzeCmd} --reference-collection lion-based-ui-collection`, rootDir);
|
||||
expect(pathsArrayFromCollectionStub.args[0][0]).to.equal('lion-based-ui-collection');
|
||||
expect(providenceStub.args[0][1].referenceProjectPaths).to.eql([
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
});
|
||||
|
||||
it('"-a --allowlist"', async () => {
|
||||
await runCli(`${analyzeCmd} -a mocked/**/*,rocked/*`, rootDir);
|
||||
expect(providenceStub.args[0][1].gatherFilesConfig.allowlist).to.eql([
|
||||
'mocked/**/*',
|
||||
'rocked/*',
|
||||
]);
|
||||
|
||||
providenceStub.resetHistory();
|
||||
|
||||
await runCli(`${analyzeCmd} --allowlist mocked/**/*,rocked/*`, rootDir);
|
||||
expect(providenceStub.args[0][1].gatherFilesConfig.allowlist).to.eql([
|
||||
'mocked/**/*',
|
||||
'rocked/*',
|
||||
]);
|
||||
});
|
||||
|
||||
it('"--allowlist-reference"', async () => {
|
||||
await runCli(`${analyzeCmd} --allowlist-reference mocked/**/*,rocked/*`, rootDir);
|
||||
expect(providenceStub.args[0][1].gatherFilesConfigReference.allowlist).to.eql([
|
||||
'mocked/**/*',
|
||||
'rocked/*',
|
||||
]);
|
||||
});
|
||||
|
||||
it('--allowlist-mode', async () => {
|
||||
await runCli(`${analyzeCmd} --allowlist-mode git`, rootDir);
|
||||
expect(providenceStub.args[0][1].gatherFilesConfig.allowlistMode).to.equal('git');
|
||||
});
|
||||
|
||||
it('--allowlist-mode-reference', async () => {
|
||||
await runCli(`${analyzeCmd} --allowlist-mode-reference npm`, rootDir);
|
||||
expect(providenceStub.args[0][1].gatherFilesConfigReference.allowlistMode).to.equal('npm');
|
||||
});
|
||||
|
||||
it('"-D --debug"', async () => {
|
||||
await runCli(`${analyzeCmd} -D`, rootDir);
|
||||
expect(providenceStub.args[0][1].debugEnabled).to.equal(true);
|
||||
|
||||
providenceStub.resetHistory();
|
||||
|
||||
await runCli(`${analyzeCmd} --debug`, rootDir);
|
||||
expect(providenceStub.args[0][1].debugEnabled).to.equal(true);
|
||||
});
|
||||
|
||||
it('--write-log-file"', async () => {
|
||||
await runCli(`${analyzeCmd} --write-log-file`, rootDir);
|
||||
expect(providenceStub.args[0][1].writeLogFile).to.equal(true);
|
||||
});
|
||||
|
||||
it('--target-dependencies"', async () => {
|
||||
await runCli(`${analyzeCmd}`, rootDir);
|
||||
expect(appendProjectDependencyPathsStub.called).to.be.false;
|
||||
|
||||
appendProjectDependencyPathsStub.resetHistory();
|
||||
providenceStub.resetHistory();
|
||||
|
||||
await runCli(`${analyzeCmd} --target-dependencies`, rootDir);
|
||||
expect(appendProjectDependencyPathsStub.called).to.be.true;
|
||||
expect(providenceStub.args[0][1].targetProjectPaths).to.eql([
|
||||
'/mocked/path/example-project',
|
||||
'/mocked/path/example-project/node_modules/mock-dep-a',
|
||||
'/mocked/path/example-project/bower_components/mock-dep-b',
|
||||
]);
|
||||
});
|
||||
|
||||
it('--target-dependencies /^with-regex/"', async () => {
|
||||
await runCli(`${analyzeCmd} --target-dependencies /^mock-/`, rootDir);
|
||||
expect(appendProjectDependencyPathsStub.args[0][1]).to.equal('/^mock-/');
|
||||
});
|
||||
|
||||
it('"--skip-check-match-compatibility"', async () => {
|
||||
await runCli(`${analyzeCmd} --skip-check-match-compatibility`, rootDir);
|
||||
expect(providenceStub.args[0][1].skipCheckMatchCompatibility).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Commands', () => {
|
||||
describe('Analyze', () => {
|
||||
it('calls providence', async () => {
|
||||
await runCli(`${analyzeCmd}`, rootDir);
|
||||
expect(providenceStub.called).to.be.true;
|
||||
});
|
||||
|
||||
describe('Options', () => {
|
||||
it('"-o --prompt-optional-config"', async () => {
|
||||
await runCli(`analyze -o`, rootDir);
|
||||
expect(promptStub.called).to.be.true;
|
||||
|
||||
promptStub.resetHistory();
|
||||
|
||||
await runCli(`analyze --prompt-optional-config`, rootDir);
|
||||
expect(promptStub.called).to.be.true;
|
||||
});
|
||||
|
||||
it('"-c --config"', async () => {
|
||||
await runCli(`analyze match-analyzer-mock -c {"a":"2"}`, rootDir);
|
||||
expect(qConfStub.args[0][0]).to.equal('match-analyzer-mock');
|
||||
expect(qConfStub.args[0][1]).to.eql({ a: '2', metaConfig: {} });
|
||||
|
||||
qConfStub.resetHistory();
|
||||
|
||||
await runCli(`analyze match-analyzer-mock --config {"a":"2"}`, rootDir);
|
||||
expect(qConfStub.args[0][0]).to.equal('match-analyzer-mock');
|
||||
expect(qConfStub.args[0][1]).to.eql({ a: '2', metaConfig: {} });
|
||||
});
|
||||
|
||||
it('calls "promptAnalyzerConfigMenu" without config given', async () => {
|
||||
await runCli(`analyze match-analyzer-mock`, rootDir);
|
||||
expect(promptCfgStub.called).to.be.true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('Query', () => {});
|
||||
describe.skip('Search', () => {});
|
||||
|
||||
describe('Manage', () => {});
|
||||
|
||||
describe('Dashboard', () => {
|
||||
/** @type {sinon.SinonStub} */
|
||||
const startStub = sinon.stub(dashboardServer, 'start');
|
||||
it('spawns a dashboard', async () => {
|
||||
runCli(`dashboard`, rootDir);
|
||||
expect(startStub.called).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
describe('Extend docs', () => {
|
||||
/** @type {sinon.SinonStub} */
|
||||
let extendDocsStub;
|
||||
|
||||
before(() => {
|
||||
extendDocsStub = sinon
|
||||
.stub(extendDocsModule, 'launchProvidenceWithExtendDocs')
|
||||
.returns(Promise.resolve());
|
||||
});
|
||||
|
||||
after(() => {
|
||||
extendDocsStub.restore();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
extendDocsStub.resetHistory();
|
||||
});
|
||||
|
||||
it('allows configuration', async () => {
|
||||
await runCli(
|
||||
[
|
||||
'extend-docs',
|
||||
'-t /xyz',
|
||||
'-r /xyz/x',
|
||||
'--prefix-from pfrom --prefix-to pto',
|
||||
'--output-folder /outp',
|
||||
'--extensions bla',
|
||||
'--allowlist al --allowlist-reference alr',
|
||||
].join(' '),
|
||||
rootDir,
|
||||
);
|
||||
expect(extendDocsStub.called).to.be.true;
|
||||
expect(extendDocsStub.args[0][0]).to.eql({
|
||||
referenceProjectPaths: ['/xyz/x'],
|
||||
prefixCfg: {
|
||||
from: 'pfrom',
|
||||
to: 'pto',
|
||||
},
|
||||
outputFolder: '/outp',
|
||||
extensions: ['.bla'],
|
||||
allowlist: ['al'],
|
||||
allowlistReference: ['alr'],
|
||||
cwd: '/mocked/path/example-project',
|
||||
skipCheckMatchCompatibility: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('CLI helpers', () => {
|
||||
const rootDir = toPosixPath(pathLib.resolve(__dirname, '../../'));
|
||||
|
||||
describe('pathsArrayFromCs', () => {
|
||||
it('allows absolute paths', async () => {
|
||||
expect(pathsArrayFromCs('/mocked/path/example-project', rootDir)).to.eql([
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
});
|
||||
|
||||
it('allows relative paths', async () => {
|
||||
expect(
|
||||
pathsArrayFromCs('./test-helpers/project-mocks/importing-target-project', rootDir),
|
||||
).to.eql([`${rootDir}/test-helpers/project-mocks/importing-target-project`]);
|
||||
expect(
|
||||
pathsArrayFromCs('test-helpers/project-mocks/importing-target-project', rootDir),
|
||||
).to.eql([`${rootDir}/test-helpers/project-mocks/importing-target-project`]);
|
||||
});
|
||||
|
||||
it('allows globs', async () => {
|
||||
expect(pathsArrayFromCs('test-helpers/project-mocks*', rootDir)).to.eql([
|
||||
`${rootDir}/test-helpers/project-mocks`,
|
||||
`${rootDir}/test-helpers/project-mocks-analyzer-outputs`,
|
||||
]);
|
||||
});
|
||||
|
||||
it('allows multiple comma separated paths', async () => {
|
||||
const paths =
|
||||
'test-helpers/project-mocks*, ./test-helpers/project-mocks/importing-target-project,/mocked/path/example-project';
|
||||
expect(pathsArrayFromCs(paths, rootDir)).to.eql([
|
||||
`${rootDir}/test-helpers/project-mocks`,
|
||||
`${rootDir}/test-helpers/project-mocks-analyzer-outputs`,
|
||||
`${rootDir}/test-helpers/project-mocks/importing-target-project`,
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('pathsArrayFromCollectionName', () => {
|
||||
it('gets collections from external target config', async () => {
|
||||
expect(
|
||||
pathsArrayFromCollectionName('lion-collection', 'search-target', externalCfgMock, rootDir),
|
||||
).to.eql(
|
||||
externalCfgMock.searchTargetCollections['lion-collection'].map(p =>
|
||||
toPosixPath(pathLib.join(rootDir, p)),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it('gets collections from external reference config', async () => {
|
||||
expect(
|
||||
pathsArrayFromCollectionName(
|
||||
'lion-based-ui-collection',
|
||||
'reference',
|
||||
externalCfgMock,
|
||||
rootDir,
|
||||
),
|
||||
).to.eql(
|
||||
externalCfgMock.referenceCollections['lion-based-ui-collection'].map(p =>
|
||||
toPosixPath(pathLib.join(rootDir, p)),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('appendProjectDependencyPaths', () => {
|
||||
before(() => {
|
||||
mockWriteToJson(queryResults);
|
||||
suppressNonCriticalLogs();
|
||||
|
||||
mockProject(
|
||||
{
|
||||
'./src/OriginalComp.js': `export class OriginalComp {}`,
|
||||
'./src/inbetween.js': `export { OriginalComp as InBetweenComp } from './OriginalComp.js'`,
|
||||
'./index.js': `export { InBetweenComp as MyComp } from './src/inbetween.js'`,
|
||||
'./node_modules/dependency-a/index.js': '',
|
||||
'./bower_components/dependency-b/index.js': '',
|
||||
'./node_modules/my-dependency/index.js': '',
|
||||
},
|
||||
{
|
||||
projectName: 'example-project',
|
||||
projectPath: '/mocked/path/example-project',
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('adds bower and node dependencies', async () => {
|
||||
const result = await appendProjectDependencyPaths(['/mocked/path/example-project']);
|
||||
expect(result).to.eql([
|
||||
'/mocked/path/example-project/node_modules/dependency-a',
|
||||
'/mocked/path/example-project/node_modules/my-dependency',
|
||||
'/mocked/path/example-project/bower_components/dependency-b',
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
});
|
||||
|
||||
it('allows a regex filter', async () => {
|
||||
const result = await appendProjectDependencyPaths(
|
||||
['/mocked/path/example-project'],
|
||||
'/^dependency-/',
|
||||
);
|
||||
expect(result).to.eql([
|
||||
'/mocked/path/example-project/node_modules/dependency-a',
|
||||
// in windows, it should not add '/mocked/path/example-project/node_modules/my-dependency',
|
||||
'/mocked/path/example-project/bower_components/dependency-b',
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
|
||||
const result2 = await appendProjectDependencyPaths(['/mocked/path/example-project'], '/b$/');
|
||||
expect(result2).to.eql([
|
||||
'/mocked/path/example-project/bower_components/dependency-b',
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
});
|
||||
|
||||
it('allows to filter out only npm or bower deps', async () => {
|
||||
const result = await appendProjectDependencyPaths(['/mocked/path/example-project'], null, [
|
||||
'npm',
|
||||
]);
|
||||
expect(result).to.eql([
|
||||
'/mocked/path/example-project/node_modules/dependency-a',
|
||||
'/mocked/path/example-project/node_modules/my-dependency',
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
|
||||
const result2 = await appendProjectDependencyPaths(['/mocked/path/example-project'], null, [
|
||||
'bower',
|
||||
]);
|
||||
expect(result2).to.eql([
|
||||
'/mocked/path/example-project/bower_components/dependency-b',
|
||||
'/mocked/path/example-project',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Extend docs', () => {
|
||||
afterEach(() => {
|
||||
restoreMockedProjects();
|
||||
});
|
||||
|
||||
it('rewrites monorepo package paths when analysis is run from monorepo root', async () => {
|
||||
// This fails after InputDataService.addAstToProjectsData is memoized
|
||||
// (it does pass when run in isolation however, as a quick fix we disable memoization cache here...)
|
||||
memoizeConfig.isCacheDisabled = true;
|
||||
|
||||
const theirProjectFiles = {
|
||||
'./package.json': JSON.stringify({
|
||||
name: 'their-components',
|
||||
version: '1.0.0',
|
||||
}),
|
||||
'./src/TheirButton.js': `export class TheirButton extends HTMLElement {}`,
|
||||
'./src/TheirTooltip.js': `export class TheirTooltip extends HTMLElement {}`,
|
||||
'./their-button.js': `
|
||||
import { TheirButton } from './src/TheirButton.js';
|
||||
|
||||
customElements.define('their-button', TheirButton);
|
||||
`,
|
||||
'./demo.js': `
|
||||
import { TheirTooltip } from './src/TheirTooltip.js';
|
||||
import './their-button.js';
|
||||
`,
|
||||
};
|
||||
|
||||
const myProjectFiles = {
|
||||
'./package.json': JSON.stringify({
|
||||
name: '@my/root',
|
||||
workspaces: ['packages/*', 'another-folder/my-tooltip'],
|
||||
dependencies: {
|
||||
'their-components': '1.0.0',
|
||||
},
|
||||
}),
|
||||
// Package 1: @my/button
|
||||
'./packages/button/package.json': JSON.stringify({
|
||||
name: '@my/button',
|
||||
}),
|
||||
'./packages/button/src/MyButton.js': `
|
||||
import { TheirButton } from 'their-components/src/TheirButton.js';
|
||||
|
||||
export class MyButton extends TheirButton {}
|
||||
`,
|
||||
'./packages/button/src/my-button.js': `
|
||||
import { MyButton } from './MyButton.js';
|
||||
|
||||
customElements.define('my-button', MyButton);
|
||||
`,
|
||||
|
||||
// Package 2: @my/tooltip
|
||||
'./packages/tooltip/package.json': JSON.stringify({
|
||||
name: '@my/tooltip',
|
||||
}),
|
||||
'./packages/tooltip/src/MyTooltip.js': `
|
||||
import { TheirTooltip } from 'their-components/src/TheirTooltip.js';
|
||||
|
||||
export class MyTooltip extends TheirTooltip {}
|
||||
`,
|
||||
};
|
||||
|
||||
const theirProject = {
|
||||
path: '/my-components/node_modules/their-components',
|
||||
name: 'their-components',
|
||||
files: Object.entries(theirProjectFiles).map(([file, code]) => ({ file, code })),
|
||||
};
|
||||
|
||||
const myProject = {
|
||||
path: '/my-components',
|
||||
name: 'my-components',
|
||||
files: Object.entries(myProjectFiles).map(([file, code]) => ({ file, code })),
|
||||
};
|
||||
|
||||
mockTargetAndReferenceProject(theirProject, myProject);
|
||||
|
||||
const result = await getExtendDocsResults({
|
||||
referenceProjectPaths: [theirProject.path],
|
||||
prefixCfg: { from: 'their', to: 'my' },
|
||||
extensions: ['.js'],
|
||||
cwd: '/my-components',
|
||||
});
|
||||
|
||||
expect(result).to.eql([
|
||||
{
|
||||
name: 'TheirButton',
|
||||
variable: {
|
||||
from: 'TheirButton',
|
||||
to: 'MyButton',
|
||||
paths: [
|
||||
{
|
||||
from: './src/TheirButton.js',
|
||||
to: '@my/button/src/MyButton.js', // rewritten from './packages/button/src/MyButton.js',
|
||||
},
|
||||
{
|
||||
from: 'their-components/src/TheirButton.js',
|
||||
to: '@my/button/src/MyButton.js', // rewritten from './packages/button/src/MyButton.js',
|
||||
},
|
||||
],
|
||||
},
|
||||
tag: {
|
||||
from: 'their-button',
|
||||
to: 'my-button',
|
||||
paths: [
|
||||
{
|
||||
from: './their-button.js',
|
||||
to: '@my/button/src/my-button.js', // rewritten from './packages/button/src/MyButton.js',
|
||||
},
|
||||
{
|
||||
from: 'their-components/their-button.js',
|
||||
to: '@my/button/src/my-button.js', // rewritten from './packages/button/src/MyButton.js',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'TheirTooltip',
|
||||
variable: {
|
||||
from: 'TheirTooltip',
|
||||
to: 'MyTooltip',
|
||||
paths: [
|
||||
{
|
||||
from: './src/TheirTooltip.js',
|
||||
to: '@my/tooltip/src/MyTooltip.js', // './packages/tooltip/src/MyTooltip.js',
|
||||
},
|
||||
{
|
||||
from: 'their-components/src/TheirTooltip.js',
|
||||
to: '@my/tooltip/src/MyTooltip.js', // './packages/tooltip/src/MyTooltip.js',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('does not check for match compatibility (target and reference) in monorepo targets', async () => {
|
||||
// ===== REFERENCE AND TARGET PROJECTS =====
|
||||
|
||||
const theirProjectFiles = {
|
||||
'./package.json': JSON.stringify({
|
||||
name: 'their-components',
|
||||
version: '1.0.0',
|
||||
}),
|
||||
'./src/TheirButton.js': `export class TheirButton extends HTMLElement {}`,
|
||||
};
|
||||
|
||||
// This will be detected as being a monorepo
|
||||
const monoProjectFiles = {
|
||||
'./package.json': JSON.stringify({
|
||||
name: '@mono/root',
|
||||
workspaces: ['packages/*'],
|
||||
dependencies: {
|
||||
'their-components': '1.0.0',
|
||||
},
|
||||
}),
|
||||
// Package: @mono/button
|
||||
'./packages/button/package.json': JSON.stringify({
|
||||
name: '@mono/button',
|
||||
}),
|
||||
};
|
||||
|
||||
// This will be detected as NOT being a monorepo
|
||||
const nonMonoProjectFiles = {
|
||||
'./package.json': JSON.stringify({
|
||||
name: 'non-mono',
|
||||
dependencies: {
|
||||
'their-components': '1.0.0',
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
const theirProject = {
|
||||
path: '/their-components',
|
||||
name: 'their-components',
|
||||
files: Object.entries(theirProjectFiles).map(([file, code]) => ({ file, code })),
|
||||
};
|
||||
|
||||
const monoProject = {
|
||||
path: '/mono-components',
|
||||
name: 'mono-components',
|
||||
files: Object.entries(monoProjectFiles).map(([file, code]) => ({ file, code })),
|
||||
};
|
||||
|
||||
const nonMonoProject = {
|
||||
path: '/non-mono-components',
|
||||
name: 'non-mono-components',
|
||||
files: Object.entries(nonMonoProjectFiles).map(([file, code]) => ({ file, code })),
|
||||
};
|
||||
|
||||
// ===== TESTS =====
|
||||
|
||||
const providenceStub = sinon.stub(providenceModule, 'providence').returns(
|
||||
new Promise(resolve => {
|
||||
resolve([]);
|
||||
}),
|
||||
);
|
||||
|
||||
// ===== mono =====
|
||||
|
||||
mockTargetAndReferenceProject(theirProject, monoProject);
|
||||
await getExtendDocsResults({
|
||||
referenceProjectPaths: ['/their-components'],
|
||||
prefixCfg: { from: 'their', to: 'my' },
|
||||
extensions: ['.js'],
|
||||
cwd: '/mono-components',
|
||||
});
|
||||
|
||||
expect(providenceStub.args[0][1].skipCheckMatchCompatibility).to.equal(true);
|
||||
providenceStub.resetHistory();
|
||||
restoreMockedProjects();
|
||||
|
||||
// ===== non mono =====
|
||||
|
||||
mockTargetAndReferenceProject(theirProject, nonMonoProject);
|
||||
await getExtendDocsResults({
|
||||
referenceProjectPaths: ['/their-components'],
|
||||
prefixCfg: { from: 'their', to: 'my' },
|
||||
extensions: ['.js'],
|
||||
cwd: '/non-mono-components',
|
||||
});
|
||||
expect(providenceStub.args[0][1].skipCheckMatchCompatibility).to.equal(false);
|
||||
|
||||
providenceStub.restore();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -6,9 +6,9 @@ import { fileURLToPath } from 'url';
|
|||
import { expect } from 'chai';
|
||||
import fetch from 'node-fetch';
|
||||
import { createTestServer } from '@web/dev-server-core/test-helpers';
|
||||
import { createDashboardServerConfig } from '../../dashboard/server.mjs';
|
||||
import { createDashboardServerConfig } from '../../dashboard/server.js';
|
||||
import { ReportService } from '../../src/program/core/ReportService.js';
|
||||
import { providenceConfUtil } from '../../src/program/utils/providence-conf-util.mjs';
|
||||
import { providenceConfUtil } from '../../src/program/utils/providence-conf-util.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('@web/dev-server-core').DevServer} DevServer
|
||||
|
|
@ -3,18 +3,31 @@ import pathLib, { dirname } from 'path';
|
|||
import { fileURLToPath } from 'url';
|
||||
import fs from 'fs';
|
||||
import { expect } from 'chai';
|
||||
import { it } from 'mocha';
|
||||
import { providence } from '../../../../src/program/providence.js';
|
||||
import { QueryService } from '../../../../src/program/core/QueryService.js';
|
||||
import { ReportService } from '../../../../src/program/core/ReportService.js';
|
||||
import { memoizeConfig } from '../../../../src/program/utils/memoize.js';
|
||||
|
||||
import { setupAnalyzerTest } from '../../../../test-helpers/setup-analyzer-test.js';
|
||||
import {
|
||||
mockWriteToJson,
|
||||
restoreWriteToJson,
|
||||
} from '../../../../test-helpers/mock-report-service-helpers.js';
|
||||
FindExportsAnalyzer,
|
||||
FindImportsAnalyzer,
|
||||
MatchImportsAnalyzer,
|
||||
} from '../../../../src/program/analyzers/index.js';
|
||||
import MatchSubclassesAnalyzer from '../../../../src/program/analyzers/match-subclasses.js';
|
||||
import MatchPathsAnalyzer from '../../../../src/program/analyzers/match-paths.js';
|
||||
import FindCustomelementsAnalyzer from '../../../../src/program/analyzers/find-customelements.js';
|
||||
import FindClassesAnalyzer from '../../../../src/program/analyzers/find-classes.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../../../../types/index.js').ProvidenceConfig} ProvidenceConfig
|
||||
* @typedef {import('../../../../types/index.js').QueryResult} QueryResult
|
||||
*/
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
setupAnalyzerTest();
|
||||
|
||||
describe('Analyzers file-system integration', () => {
|
||||
/**
|
||||
* Flag to enable mode that generates e2e mocks.
|
||||
|
|
@ -23,7 +36,6 @@ describe('Analyzers file-system integration', () => {
|
|||
*/
|
||||
const generateE2eMode = process.argv.includes('--generate-e2e-mode');
|
||||
|
||||
const queryResults = [];
|
||||
const targetPath = pathLib.resolve(
|
||||
__dirname,
|
||||
'../../../../test-helpers/project-mocks/importing-target-project',
|
||||
|
|
@ -50,73 +62,69 @@ describe('Analyzers file-system integration', () => {
|
|||
__dirname,
|
||||
'../../../../test-helpers/project-mocks-analyzer-outputs',
|
||||
);
|
||||
// @ts-expect-error
|
||||
// eslint-disable-next-line func-names
|
||||
ReportService._getResultFileNameAndPath = function (name) {
|
||||
return pathLib.join(this.outputPath, `${name}.json`);
|
||||
};
|
||||
} else {
|
||||
ReportService.outputPath = __dirname; // prevents cache to fail the test
|
||||
|
||||
beforeEach(() => {
|
||||
mockWriteToJson(queryResults);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
restoreWriteToJson(queryResults);
|
||||
});
|
||||
}
|
||||
const analyzers = [
|
||||
{
|
||||
analyzerName: 'find-customelements',
|
||||
providenceConfig: {
|
||||
targetProjectPaths: [targetPath],
|
||||
},
|
||||
ctor: FindCustomelementsAnalyzer,
|
||||
},
|
||||
{
|
||||
analyzerName: 'find-imports',
|
||||
providenceConfig: {
|
||||
targetProjectPaths: [targetPath],
|
||||
},
|
||||
ctor: FindImportsAnalyzer,
|
||||
},
|
||||
{
|
||||
analyzerName: 'find-exports',
|
||||
providenceConfig: {
|
||||
targetProjectPaths: [referencePath],
|
||||
},
|
||||
ctor: FindExportsAnalyzer,
|
||||
},
|
||||
{
|
||||
analyzerName: 'find-classes',
|
||||
providenceConfig: {
|
||||
targetProjectPaths: [targetPath],
|
||||
},
|
||||
ctor: FindClassesAnalyzer,
|
||||
},
|
||||
{
|
||||
analyzerName: 'match-imports',
|
||||
providenceConfig: {
|
||||
targetProjectPaths: [targetPath],
|
||||
referenceProjectPaths: [referencePath],
|
||||
},
|
||||
ctor: MatchImportsAnalyzer,
|
||||
},
|
||||
{
|
||||
analyzerName: 'match-subclasses',
|
||||
providenceConfig: {
|
||||
targetProjectPaths: [targetPath],
|
||||
referenceProjectPaths: [referencePath],
|
||||
},
|
||||
ctor: MatchSubclassesAnalyzer,
|
||||
},
|
||||
{
|
||||
analyzerName: 'match-paths',
|
||||
providenceConfig: {
|
||||
targetProjectPaths: [targetPath],
|
||||
referenceProjectPaths: [referencePath],
|
||||
},
|
||||
ctor: MatchPathsAnalyzer,
|
||||
},
|
||||
];
|
||||
|
||||
for (const { analyzerName, providenceConfig } of analyzers) {
|
||||
it(`"${analyzerName}" analyzer`, async () => {
|
||||
const findExportsQueryConfig = QueryService.getQueryConfigFromAnalyzer(analyzerName);
|
||||
await providence(findExportsQueryConfig, providenceConfig);
|
||||
for (const { ctor, providenceConfig } of analyzers) {
|
||||
it(`"${ctor.analyzerName}" analyzer`, async () => {
|
||||
const findExportsQueryConfig = await QueryService.getQueryConfigFromAnalyzer(ctor);
|
||||
const queryResults = await providence(
|
||||
findExportsQueryConfig,
|
||||
/** @type {ProvidenceConfig} */ (providenceConfig),
|
||||
);
|
||||
if (generateE2eMode) {
|
||||
console.info(
|
||||
'Successfully created mocks. Do not forget to rerun tests now without "--generate-e2e-mode"',
|
||||
|
|
@ -127,7 +135,7 @@ describe('Analyzers file-system integration', () => {
|
|||
fs.readFileSync(
|
||||
pathLib.resolve(
|
||||
__dirname,
|
||||
`../../../../test-helpers/project-mocks-analyzer-outputs/${analyzerName}.json`,
|
||||
`../../../../test-helpers/project-mocks-analyzer-outputs/${ctor.analyzerName}.json`,
|
||||
),
|
||||
'utf8',
|
||||
),
|
||||
|
|
@ -1,22 +1,30 @@
|
|||
const { expect } = require('chai');
|
||||
const { providence } = require('../../../src/program/providence.js');
|
||||
const { QueryService } = require('../../../src/program/core/QueryService.js');
|
||||
const { setupAnalyzerTest } = require('../../../test-helpers/setup-analyzer-test.js');
|
||||
const { mockProject, getEntry } = require('../../../test-helpers/mock-project-helpers.js');
|
||||
import { expect } from 'chai';
|
||||
import { it } from 'mocha';
|
||||
import { providence } from '../../../src/program/providence.js';
|
||||
import { QueryService } from '../../../src/program/core/QueryService.js';
|
||||
import { mockProject, getEntry } from '../../../test-helpers/mock-project-helpers.js';
|
||||
import { setupAnalyzerTest } from '../../../test-helpers/setup-analyzer-test.js';
|
||||
import FindClassesAnalyzer from '../../../src/program/analyzers/find-classes.js';
|
||||
|
||||
const findClassesQueryConfig = QueryService.getQueryConfigFromAnalyzer('find-classes');
|
||||
/**
|
||||
* @typedef {import('../../../types/index.js').ProvidenceConfig} ProvidenceConfig
|
||||
*/
|
||||
|
||||
describe('Analyzer "find-classes"', () => {
|
||||
const queryResults = setupAnalyzerTest();
|
||||
setupAnalyzerTest();
|
||||
|
||||
describe('Analyzer "find-classes"', async () => {
|
||||
const findClassesQueryConfig = await QueryService.getQueryConfigFromAnalyzer(FindClassesAnalyzer);
|
||||
|
||||
// const queryResults = setupAnalyzerTest();
|
||||
/** @type {Partial<ProvidenceConfig>} */
|
||||
const _providenceCfg = {
|
||||
targetProjectPaths: ['/fictional/project'], // defined in mockProject
|
||||
};
|
||||
|
||||
it(`finds class definitions`, async () => {
|
||||
mockProject([`class EmptyClass {}`]);
|
||||
await providence(findClassesQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findClassesQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result).to.eql([
|
||||
{
|
||||
name: 'EmptyClass',
|
||||
|
|
@ -31,9 +39,8 @@ describe('Analyzer "find-classes"', () => {
|
|||
|
||||
it(`finds mixin definitions`, async () => {
|
||||
mockProject([`const m = superclass => class MyMixin extends superclass {}`]);
|
||||
await providence(findClassesQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findClassesQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result).to.eql([
|
||||
{
|
||||
name: 'MyMixin',
|
||||
|
|
@ -63,9 +70,8 @@ describe('Analyzer "find-classes"', () => {
|
|||
`,
|
||||
'./internal.js': '',
|
||||
});
|
||||
await providence(findClassesQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findClassesQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result[1].superClasses).to.eql([
|
||||
{
|
||||
isMixin: true,
|
||||
|
|
@ -85,9 +91,8 @@ describe('Analyzer "find-classes"', () => {
|
|||
` const m = superclass => class MyMixin extends superclass {}
|
||||
class EmptyClass extends Mixin(OtherClass) {}`,
|
||||
]);
|
||||
await providence(findClassesQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findClassesQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result.length).to.equal(2);
|
||||
});
|
||||
|
||||
|
|
@ -102,9 +107,8 @@ describe('Analyzer "find-classes"', () => {
|
|||
$$privateMethod() {}
|
||||
}`,
|
||||
]);
|
||||
await providence(findClassesQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findClassesQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result[0].members.methods).to.eql([
|
||||
{
|
||||
accessType: 'public',
|
||||
|
|
@ -139,9 +143,8 @@ describe('Analyzer "find-classes"', () => {
|
|||
static set _staticGetterSetter(v) {}
|
||||
}`,
|
||||
]);
|
||||
await providence(findClassesQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findClassesQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result[0].members.props).to.eql([
|
||||
{
|
||||
accessType: 'public',
|
||||
|
|
@ -168,9 +171,8 @@ describe('Analyzer "find-classes"', () => {
|
|||
disconnectedCallback() {}
|
||||
}`,
|
||||
]);
|
||||
await providence(findClassesQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findClassesQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result[0].members.methods.length).to.equal(0);
|
||||
expect(firstEntry.result[0].members.props.length).to.equal(0);
|
||||
});
|
||||
|
|
@ -190,9 +192,8 @@ describe('Analyzer "find-classes"', () => {
|
|||
shouldUpdate() {}
|
||||
}`,
|
||||
]);
|
||||
await providence(findClassesQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findClassesQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result[0].members.methods.length).to.equal(0);
|
||||
expect(firstEntry.result[0].members.props.length).to.equal(0);
|
||||
});
|
||||
|
|
@ -205,9 +206,8 @@ describe('Analyzer "find-classes"', () => {
|
|||
onLocaleUpdated() {}
|
||||
}`,
|
||||
]);
|
||||
await providence(findClassesQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findClassesQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result[0].members.methods.length).to.equal(0);
|
||||
expect(firstEntry.result[0].members.props.length).to.equal(0);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,22 +1,29 @@
|
|||
const { expect } = require('chai');
|
||||
const { providence } = require('../../../src/program/providence.js');
|
||||
const { QueryService } = require('../../../src/program/core/QueryService.js');
|
||||
const { setupAnalyzerTest } = require('../../../test-helpers/setup-analyzer-test.js');
|
||||
import { expect } from 'chai';
|
||||
import { it } from 'mocha';
|
||||
import { providence } from '../../../src/program/providence.js';
|
||||
import { QueryService } from '../../../src/program/core/QueryService.js';
|
||||
import { setupAnalyzerTest } from '../../../test-helpers/setup-analyzer-test.js';
|
||||
import { mockProject, getEntry } from '../../../test-helpers/mock-project-helpers.js';
|
||||
import FindCustomelementsAnalyzer from '../../../src/program/analyzers/find-customelements.js';
|
||||
|
||||
const { mockProject, getEntry } = require('../../../test-helpers/mock-project-helpers.js');
|
||||
/**
|
||||
* @typedef {import('../../../types/index.js').ProvidenceConfig} ProvidenceConfig
|
||||
*/
|
||||
|
||||
const findCustomelementsQueryConfig =
|
||||
QueryService.getQueryConfigFromAnalyzer('find-customelements');
|
||||
const _providenceCfg = {
|
||||
targetProjectPaths: ['/fictional/project'], // defined in mockProject
|
||||
};
|
||||
setupAnalyzerTest();
|
||||
|
||||
describe('Analyzer "find-customelements"', () => {
|
||||
const queryResults = setupAnalyzerTest();
|
||||
describe('Analyzer "find-customelements"', async () => {
|
||||
const findCustomelementsQueryConfig = await QueryService.getQueryConfigFromAnalyzer(
|
||||
FindCustomelementsAnalyzer,
|
||||
);
|
||||
/** @type {Partial<ProvidenceConfig>} */
|
||||
const _providenceCfg = {
|
||||
targetProjectPaths: ['/fictional/project'], // defined in mockProject
|
||||
};
|
||||
|
||||
it(`stores the tagName of a custom element`, async () => {
|
||||
mockProject([`customElements.define('custom-el', class extends HTMLElement {});`]);
|
||||
await providence(findCustomelementsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findCustomelementsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].tagName).to.equal('custom-el');
|
||||
|
|
@ -30,7 +37,7 @@ describe('Analyzer "find-customelements"', () => {
|
|||
window.customElements.define('custom-el3', class extends HTMLElement {});
|
||||
})();`,
|
||||
]);
|
||||
await providence(findCustomelementsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findCustomelementsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const secondEntry = getEntry(queryResult, 1);
|
||||
|
|
@ -48,7 +55,7 @@ describe('Analyzer "find-customelements"', () => {
|
|||
customElements.define('custom-el', CustomEl);
|
||||
`,
|
||||
});
|
||||
await providence(findCustomelementsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findCustomelementsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].rootFile).to.eql({
|
||||
|
|
@ -59,7 +66,7 @@ describe('Analyzer "find-customelements"', () => {
|
|||
|
||||
it(`stores "[inline]" constructors`, async () => {
|
||||
mockProject([`customElements.define('custom-el', class extends HTMLElement {});`]);
|
||||
await providence(findCustomelementsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findCustomelementsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].constructorIdentifier).to.equal('[inline]');
|
||||
|
|
@ -68,7 +75,7 @@ describe('Analyzer "find-customelements"', () => {
|
|||
|
||||
it(`stores "[current]" rootFile`, async () => {
|
||||
mockProject([`customElements.define('custom-el', class extends HTMLElement {});`]);
|
||||
await providence(findCustomelementsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findCustomelementsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].rootFile.file).to.equal('[current]');
|
||||
|
|
@ -82,7 +89,7 @@ describe('Analyzer "find-customelements"', () => {
|
|||
customElements.define('custom-el', CustomEl);
|
||||
`,
|
||||
});
|
||||
await providence(findCustomelementsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findCustomelementsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].constructorIdentifier).to.equal('CustomEl');
|
||||
|
|
@ -99,7 +106,7 @@ describe('Analyzer "find-customelements"', () => {
|
|||
customElements.define('tag-3', class extends HTMLElement {});
|
||||
`,
|
||||
]);
|
||||
await providence(findCustomelementsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findCustomelementsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const secondEntry = getEntry(queryResult, 1);
|
||||
|
|
|
|||
|
|
@ -1,18 +1,21 @@
|
|||
const { expect } = require('chai');
|
||||
const { providence } = require('../../../src/program/providence.js');
|
||||
const { QueryService } = require('../../../src/program/core/QueryService.js');
|
||||
const { setupAnalyzerTest } = require('../../../test-helpers/setup-analyzer-test.js');
|
||||
import { expect } from 'chai';
|
||||
import { it } from 'mocha';
|
||||
import { providence } from '../../../src/program/providence.js';
|
||||
import { QueryService } from '../../../src/program/core/QueryService.js';
|
||||
import { setupAnalyzerTest } from '../../../test-helpers/setup-analyzer-test.js';
|
||||
import { mockProject, getEntry, getEntries } from '../../../test-helpers/mock-project-helpers.js';
|
||||
import FindExportsAnalyzer from '../../../src/program/analyzers/find-exports.js';
|
||||
|
||||
const {
|
||||
mockProject,
|
||||
getEntry,
|
||||
getEntries,
|
||||
} = require('../../../test-helpers/mock-project-helpers.js');
|
||||
/**
|
||||
* @typedef {import('../../../types/index.js').ProvidenceConfig} ProvidenceConfig
|
||||
*/
|
||||
|
||||
const findExportsQueryConfig = QueryService.getQueryConfigFromAnalyzer('find-exports');
|
||||
setupAnalyzerTest();
|
||||
|
||||
describe('Analyzer "find-exports"', () => {
|
||||
const queryResults = setupAnalyzerTest();
|
||||
describe('Analyzer "find-exports"', async () => {
|
||||
const findExportsQueryConfig = await QueryService.getQueryConfigFromAnalyzer(FindExportsAnalyzer);
|
||||
|
||||
/** @type {Partial<ProvidenceConfig>} */
|
||||
const _providenceCfg = {
|
||||
targetProjectPaths: ['/fictional/project'], // defined in mockProject
|
||||
};
|
||||
|
|
@ -20,32 +23,28 @@ describe('Analyzer "find-exports"', () => {
|
|||
describe('Export notations', () => {
|
||||
it(`supports [export const x = 0] (named specifier)`, async () => {
|
||||
mockProject([`export const x = 0`]);
|
||||
await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].exportSpecifiers.length).to.equal(1);
|
||||
expect(firstEntry.result[0].exportSpecifiers[0]).to.equal('x');
|
||||
expect(firstEntry.result[0].source).to.be.undefined;
|
||||
const queryResults = await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const firstResult = getEntry(queryResults[0]).result[0];
|
||||
|
||||
expect(firstResult.exportSpecifiers).to.eql(['x']);
|
||||
expect(firstResult.source).to.be.undefined;
|
||||
});
|
||||
|
||||
it(`supports [export default class X {}] (default export)`, async () => {
|
||||
mockProject([`export default class X {}`]);
|
||||
await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].exportSpecifiers.length).to.equal(1);
|
||||
expect(firstEntry.result[0].exportSpecifiers[0]).to.equal('[default]');
|
||||
expect(firstEntry.result[0].source).to.equal(undefined);
|
||||
const queryResults = await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const firstResult = getEntry(queryResults[0]).result[0];
|
||||
expect(firstResult.exportSpecifiers).to.eql(['[default]']);
|
||||
expect(firstResult.source).to.be.undefined;
|
||||
});
|
||||
|
||||
it(`supports [export default fn(){}] (default export)`, async () => {
|
||||
mockProject([`export default x => x * 3`]);
|
||||
await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].exportSpecifiers.length).to.equal(1);
|
||||
expect(firstEntry.result[0].exportSpecifiers[0]).to.equal('[default]');
|
||||
expect(firstEntry.result[0].source).to.equal(undefined);
|
||||
const queryResults = await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const firstResult = getEntry(queryResults[0]).result[0];
|
||||
|
||||
expect(firstResult.exportSpecifiers).to.eql(['[default]']);
|
||||
expect(firstResult.source).to.equal(undefined);
|
||||
});
|
||||
|
||||
it(`supports [export {default as x} from 'y'] (default re-export)`, async () => {
|
||||
|
|
@ -55,10 +54,9 @@ describe('Analyzer "find-exports"', () => {
|
|||
"export { default as namedExport } from './file-with-default-export.js';",
|
||||
});
|
||||
|
||||
await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0]).to.eql({
|
||||
const queryResults = await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const firstResult = getEntry(queryResults[0]).result[0];
|
||||
expect(firstResult).to.eql({
|
||||
exportSpecifiers: ['[default]'],
|
||||
source: undefined,
|
||||
rootFileMap: [
|
||||
|
|
@ -69,10 +67,7 @@ describe('Analyzer "find-exports"', () => {
|
|||
],
|
||||
});
|
||||
|
||||
const secondEntry = getEntry(queryResult, 1);
|
||||
expect(secondEntry.result[0].exportSpecifiers.length).to.equal(1);
|
||||
expect(secondEntry.result[0].exportSpecifiers[0]).to.equal('namedExport');
|
||||
expect(secondEntry.result[0].source).to.equal('./file-with-default-export.js');
|
||||
const secondEntry = getEntry(queryResults[0], 1);
|
||||
expect(secondEntry.result[0]).to.eql({
|
||||
exportSpecifiers: ['namedExport'],
|
||||
source: './file-with-default-export.js',
|
||||
|
|
@ -89,9 +84,8 @@ describe('Analyzer "find-exports"', () => {
|
|||
|
||||
it(`supports [import {x} from 'y'; export default x] (named re-export as default)`, async () => {
|
||||
mockProject([`import {x} from 'y'; export default x;`]);
|
||||
await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result[0].exportSpecifiers.length).to.equal(1);
|
||||
expect(firstEntry.result[0].exportSpecifiers[0]).to.equal('[default]');
|
||||
expect(firstEntry.result[0].source).to.equal('y');
|
||||
|
|
@ -99,9 +93,8 @@ describe('Analyzer "find-exports"', () => {
|
|||
|
||||
it(`supports [import x from 'y'; export default x] (default re-export as default)`, async () => {
|
||||
mockProject([`import x from 'y'; export default x;`]);
|
||||
await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result[0].exportSpecifiers.length).to.equal(1);
|
||||
expect(firstEntry.result[0].exportSpecifiers[0]).to.equal('[default]');
|
||||
expect(firstEntry.result[0].source).to.equal('y');
|
||||
|
|
@ -109,9 +102,8 @@ describe('Analyzer "find-exports"', () => {
|
|||
|
||||
it(`supports [export { x } from 'my/source'] (re-export named specifier)`, async () => {
|
||||
mockProject([`export { x } from 'my/source'`]);
|
||||
await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result[0].exportSpecifiers.length).to.equal(1);
|
||||
expect(firstEntry.result[0].exportSpecifiers[0]).to.equal('x');
|
||||
expect(firstEntry.result[0].source).to.equal('my/source');
|
||||
|
|
@ -119,9 +111,8 @@ describe('Analyzer "find-exports"', () => {
|
|||
|
||||
it(`supports [export { x as y } from 'my/source'] (re-export renamed specifier)`, async () => {
|
||||
mockProject([`export { x as y } from 'my/source'`]);
|
||||
await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result[0].exportSpecifiers.length).to.equal(1);
|
||||
expect(firstEntry.result[0].exportSpecifiers[0]).to.equal('y');
|
||||
expect(firstEntry.result[0].source).to.equal('my/source');
|
||||
|
|
@ -130,16 +121,15 @@ describe('Analyzer "find-exports"', () => {
|
|||
it(`supports [export styles from './styles.css' assert { type: "css" }] (import assertions)`, async () => {
|
||||
mockProject({
|
||||
'./styles.css': '.block { display:block; };',
|
||||
'./x.js': `export styles from './styles.css' assert { type: "css" };`,
|
||||
'./x.js': `export { styles as default } from './styles.css' assert { type: "css" };`,
|
||||
});
|
||||
await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result[0].exportSpecifiers.length).to.equal(1);
|
||||
expect(firstEntry.result[0].exportSpecifiers[0]).to.equal('styles');
|
||||
expect(firstEntry.result[0].exportSpecifiers[0]).to.equal('[default]');
|
||||
expect(firstEntry.result[0].source).to.equal('./styles.css');
|
||||
expect(firstEntry.result[0].rootFileMap[0]).to.eql({
|
||||
currentFileSpecifier: 'styles',
|
||||
currentFileSpecifier: '[default]',
|
||||
rootFile: {
|
||||
file: './styles.css',
|
||||
specifier: '[default]',
|
||||
|
|
@ -152,9 +142,8 @@ describe('Analyzer "find-exports"', () => {
|
|||
'./styles.css': '.block { display:block; };',
|
||||
'./x.js': `import styles from './styles.css' assert { type: "css" }; export default styles;`,
|
||||
});
|
||||
await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result[0].exportSpecifiers.length).to.equal(1);
|
||||
expect(firstEntry.result[0].exportSpecifiers[0]).to.equal('[default]');
|
||||
expect(firstEntry.result[0].source).to.equal('./styles.css');
|
||||
|
|
@ -169,9 +158,8 @@ describe('Analyzer "find-exports"', () => {
|
|||
|
||||
it(`stores meta info(local name) of renamed specifiers`, async () => {
|
||||
mockProject([`export { x as y } from 'my/source'`]);
|
||||
await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
// This info will be relevant later to identify 'transitive' relations
|
||||
expect(firstEntry.result[0].localMap).to.eql([
|
||||
{
|
||||
|
|
@ -183,9 +171,8 @@ describe('Analyzer "find-exports"', () => {
|
|||
|
||||
it(`supports [export { x, y } from 'my/source'] (multiple re-exported named specifiers)`, async () => {
|
||||
mockProject([`export { x, y } from 'my/source'`]);
|
||||
await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result[0].exportSpecifiers.length).to.equal(2);
|
||||
expect(firstEntry.result[0].exportSpecifiers).to.eql(['x', 'y']);
|
||||
expect(firstEntry.result[0].source).to.equal('my/source');
|
||||
|
|
@ -197,12 +184,10 @@ describe('Analyzer "find-exports"', () => {
|
|||
'./src/inbetween.js': `export { OriginalComp as InBetweenComp } from './OriginalComp.js'`,
|
||||
'./index.js': `export { InBetweenComp as MyComp } from './src/inbetween.js'`,
|
||||
});
|
||||
await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const secondEntry = getEntry(queryResult, 1);
|
||||
const thirdEntry = getEntry(queryResult, 2);
|
||||
const queryResults = await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
const secondEntry = getEntry(queryResults[0], 1);
|
||||
const thirdEntry = getEntry(queryResults[0], 2);
|
||||
|
||||
expect(firstEntry.result[0].rootFileMap).to.eql([
|
||||
{
|
||||
|
|
@ -247,9 +232,8 @@ describe('Analyzer "find-exports"', () => {
|
|||
export default ExtendRefDefault;
|
||||
`,
|
||||
});
|
||||
await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
|
||||
expect(firstEntry.result[0].rootFileMap).to.eql([
|
||||
{
|
||||
|
|
@ -265,9 +249,8 @@ describe('Analyzer "find-exports"', () => {
|
|||
it(`correctly handles empty files`, async () => {
|
||||
// These can be encountered while scanning repos.. They should not break the code...
|
||||
mockProject([`// some comment here...`]);
|
||||
await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result[0].exportSpecifiers).to.eql(['[file]']);
|
||||
expect(firstEntry.result[0].source).to.equal(undefined);
|
||||
});
|
||||
|
|
@ -276,9 +259,8 @@ describe('Analyzer "find-exports"', () => {
|
|||
describe('Export variable types', () => {
|
||||
it(`classes`, async () => {
|
||||
mockProject([`export class X {}`]);
|
||||
await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result[0].exportSpecifiers.length).to.equal(1);
|
||||
expect(firstEntry.result[0].exportSpecifiers[0]).to.equal('X');
|
||||
expect(firstEntry.result[0].source).to.be.undefined;
|
||||
|
|
@ -286,9 +268,8 @@ describe('Analyzer "find-exports"', () => {
|
|||
|
||||
it(`functions`, async () => {
|
||||
mockProject([`export function y() {}`]);
|
||||
await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
const queryResults = await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const firstEntry = getEntry(queryResults[0]);
|
||||
expect(firstEntry.result[0].exportSpecifiers.length).to.equal(1);
|
||||
expect(firstEntry.result[0].exportSpecifiers[0]).to.equal('y');
|
||||
expect(firstEntry.result[0].source).to.be.undefined;
|
||||
|
|
@ -319,22 +300,25 @@ describe('Analyzer "find-exports"', () => {
|
|||
},
|
||||
);
|
||||
|
||||
const findExportsCategoryQueryObj = QueryService.getQueryConfigFromAnalyzer('find-exports', {
|
||||
metaConfig: {
|
||||
categoryConfig: [
|
||||
{
|
||||
project: 'my-project',
|
||||
categories: {
|
||||
fooCategory: localFilePath => localFilePath.startsWith('./foo'),
|
||||
barCategory: localFilePath => localFilePath.startsWith('./packages/bar'),
|
||||
testCategory: localFilePath => localFilePath.includes('/test/'),
|
||||
const findExportsCategoryQueryObj = await QueryService.getQueryConfigFromAnalyzer(
|
||||
'find-exports',
|
||||
{
|
||||
metaConfig: {
|
||||
categoryConfig: [
|
||||
{
|
||||
project: 'my-project',
|
||||
categories: {
|
||||
fooCategory: localFilePath => localFilePath.startsWith('./foo'),
|
||||
barCategory: localFilePath => localFilePath.startsWith('./packages/bar'),
|
||||
testCategory: localFilePath => localFilePath.includes('/test/'),
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
);
|
||||
|
||||
await providence(findExportsCategoryQueryObj, _providenceCfg);
|
||||
const queryResults = await providence(findExportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const [firstEntry, secondEntry, thirdEntry] = getEntries(queryResult);
|
||||
expect(firstEntry.meta.categories).to.eql(['fooCategory']);
|
||||
|
|
|
|||
|
|
@ -1,26 +1,28 @@
|
|||
const { expect } = require('chai');
|
||||
const { providence } = require('../../../src/program/providence.js');
|
||||
const { QueryService } = require('../../../src/program/core/QueryService.js');
|
||||
const { setupAnalyzerTest } = require('../../../test-helpers/setup-analyzer-test.js');
|
||||
const { mockProject, getEntry } = require('../../../test-helpers/mock-project-helpers.js');
|
||||
import { expect } from 'chai';
|
||||
import { it } from 'mocha';
|
||||
import { providence } from '../../../src/program/providence.js';
|
||||
import { QueryService } from '../../../src/program/core/QueryService.js';
|
||||
import { setupAnalyzerTest } from '../../../test-helpers/setup-analyzer-test.js';
|
||||
import { mockProject, getEntry } from '../../../test-helpers/mock-project-helpers.js';
|
||||
import FindImportsAnalyzer from '../../../src/program/analyzers/find-imports.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../../../src/program/types/core').ProvidenceConfig} ProvidenceConfig
|
||||
* @typedef {import('../../../types/index.js').ProvidenceConfig} ProvidenceConfig
|
||||
*/
|
||||
|
||||
const findImportsQueryConfig = QueryService.getQueryConfigFromAnalyzer('find-imports');
|
||||
/** @type {Partial<ProvidenceConfig>} */
|
||||
const _providenceCfg = {
|
||||
targetProjectPaths: ['/fictional/project'], // defined in mockProject
|
||||
};
|
||||
setupAnalyzerTest();
|
||||
|
||||
describe('Analyzer "find-imports"', () => {
|
||||
const queryResults = setupAnalyzerTest();
|
||||
describe('Analyzer "find-imports"', async () => {
|
||||
const findImportsQueryConfig = await QueryService.getQueryConfigFromAnalyzer(FindImportsAnalyzer);
|
||||
/** @type {Partial<ProvidenceConfig>} */
|
||||
const _providenceCfg = {
|
||||
targetProjectPaths: ['/fictional/project'], // defined in mockProject
|
||||
};
|
||||
|
||||
describe('Import notations', () => {
|
||||
it(`supports [import 'imported/source'] (no specifiers)`, async () => {
|
||||
mockProject([`import 'imported/source'`]);
|
||||
await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].importSpecifiers).to.eql(['[file]']);
|
||||
|
|
@ -29,7 +31,7 @@ describe('Analyzer "find-imports"', () => {
|
|||
|
||||
it(`supports [import x from 'imported/source'] (default specifier)`, async () => {
|
||||
mockProject([`import x from 'imported/source'`]);
|
||||
await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].importSpecifiers[0]).to.equal('[default]');
|
||||
|
|
@ -38,7 +40,7 @@ describe('Analyzer "find-imports"', () => {
|
|||
|
||||
it(`supports [import { x } from 'imported/source'] (named specifier)`, async () => {
|
||||
mockProject([`import { x } from 'imported/source'`]);
|
||||
await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].importSpecifiers[0]).to.equal('x');
|
||||
|
|
@ -48,7 +50,7 @@ describe('Analyzer "find-imports"', () => {
|
|||
|
||||
it(`supports [import { x, y } from 'imported/source'] (multiple named specifiers)`, async () => {
|
||||
mockProject([`import { x, y } from 'imported/source'`]);
|
||||
await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].importSpecifiers[0]).to.equal('x');
|
||||
|
|
@ -59,7 +61,7 @@ describe('Analyzer "find-imports"', () => {
|
|||
|
||||
it(`supports [import x, { y, z } from 'imported/source'] (default and named specifiers)`, async () => {
|
||||
mockProject([`import x, { y, z } from 'imported/source'`]);
|
||||
await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].importSpecifiers[0]).to.equal('[default]');
|
||||
|
|
@ -70,7 +72,7 @@ describe('Analyzer "find-imports"', () => {
|
|||
|
||||
it(`supports [import { x as y } from 'imported/source'] (renamed specifiers)`, async () => {
|
||||
mockProject([`import { x as y } from 'imported/source'`]);
|
||||
await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].importSpecifiers[0]).to.equal('x');
|
||||
|
|
@ -78,41 +80,41 @@ describe('Analyzer "find-imports"', () => {
|
|||
|
||||
it(`supports [import * as all from 'imported/source'] (namespace specifiers)`, async () => {
|
||||
mockProject([`import * as all from 'imported/source'`]);
|
||||
await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].importSpecifiers[0]).to.equal('[*]');
|
||||
});
|
||||
|
||||
describe('Reexports', () => {
|
||||
it(`supports [export { x } from 'imported/source'] (reexported named specifiers)`, async () => {
|
||||
it(`supports [export { x } from 'imported/source'] (re-exported named specifiers)`, async () => {
|
||||
mockProject([`export { x } from 'imported/source'`]);
|
||||
await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].importSpecifiers[0]).to.equal('x');
|
||||
});
|
||||
|
||||
it(`supports [export { x as y } from 'imported/source'] (reexported renamed specifiers)`, async () => {
|
||||
it(`supports [export { x as y } from 'imported/source'] (re-exported renamed specifiers)`, async () => {
|
||||
mockProject([`export { x as y } from 'imported/source'`]);
|
||||
await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].importSpecifiers[0]).to.equal('x');
|
||||
});
|
||||
|
||||
// maybe in the future... needs experimental babel flag "exportDefaultFrom"
|
||||
it.skip(`supports [export x from 'imported/source'] (reexported default specifiers)`, async () => {
|
||||
it.skip(`supports [export x from 'imported/source'] (re-exported default specifiers)`, async () => {
|
||||
mockProject([`export x from 'imported/source'`]);
|
||||
await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].importSpecifiers[0]).to.equal('x');
|
||||
});
|
||||
|
||||
it(`supports [export * as x from 'imported/source'] (reexported namespace specifiers)`, async () => {
|
||||
it(`supports [export * as x from 'imported/source'] (re-exported namespace specifiers)`, async () => {
|
||||
mockProject([`export * as x from 'imported/source'`]);
|
||||
await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].importSpecifiers[0]).to.equal('[*]');
|
||||
|
|
@ -122,7 +124,7 @@ describe('Analyzer "find-imports"', () => {
|
|||
// Currently only supported for find-exports. For now not needed...
|
||||
it.skip(`stores meta info(local name) of renamed specifiers`, async () => {
|
||||
mockProject([`import { x as y } from 'imported/source'`]);
|
||||
await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
// This info will be relevant later to identify transitive relations
|
||||
|
|
@ -134,7 +136,7 @@ describe('Analyzer "find-imports"', () => {
|
|||
|
||||
it(`supports [import('my/source')] (dynamic imports)`, async () => {
|
||||
mockProject([`import('my/source')`]);
|
||||
await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].importSpecifiers[0]).to.equal('[default]');
|
||||
|
|
@ -150,7 +152,7 @@ describe('Analyzer "find-imports"', () => {
|
|||
import(pathReference);
|
||||
`,
|
||||
]);
|
||||
await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].importSpecifiers[0]).to.equal('[default]');
|
||||
|
|
@ -161,7 +163,7 @@ describe('Analyzer "find-imports"', () => {
|
|||
// import styles from "./styles.css" assert { type: "css" };
|
||||
it(`supports [import styles from "@css/lib/styles.css" assert { type: "css" }] (import assertions)`, async () => {
|
||||
mockProject([`import styles from "@css/lib/styles.css" assert { type: "css" };`]);
|
||||
await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].importSpecifiers[0]).to.equal('[default]');
|
||||
|
|
@ -170,8 +172,10 @@ describe('Analyzer "find-imports"', () => {
|
|||
});
|
||||
|
||||
it(`supports [export styles from "@css/lib/styles.css" assert { type: "css" }] (import assertions)`, async () => {
|
||||
mockProject([`export styles from "@css/lib/styles.css" assert { type: "css" };`]);
|
||||
await providence(findImportsQueryConfig, _providenceCfg);
|
||||
mockProject([
|
||||
`export { styles as default } from "@css/lib/styles.css" assert { type: "css" };`,
|
||||
]);
|
||||
const queryResults = await providence(findImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].importSpecifiers[0]).to.equal('[default]');
|
||||
|
|
@ -182,7 +186,7 @@ describe('Analyzer "find-imports"', () => {
|
|||
describe('Filter out false positives', () => {
|
||||
it(`doesn't support [object.import('my/source')] (import method members)`, async () => {
|
||||
mockProject([`object.import('my/source')`]);
|
||||
await providence(findImportsQueryConfig, {
|
||||
const queryResults = await providence(findImportsQueryConfig, {
|
||||
targetProjectPaths: ['/fictional/project'], // defined in mockProject
|
||||
});
|
||||
const queryResult = queryResults[0];
|
||||
|
|
@ -209,7 +213,7 @@ describe('Analyzer "find-imports"', () => {
|
|||
import '../../internal/source';
|
||||
`,
|
||||
]);
|
||||
await providence(findImportsQueryConfig, { ..._providenceCfg });
|
||||
const queryResults = await providence(findImportsQueryConfig, { ..._providenceCfg });
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].importSpecifiers.length).to.equal(1);
|
||||
|
|
@ -219,7 +223,7 @@ describe('Analyzer "find-imports"', () => {
|
|||
});
|
||||
|
||||
it('normalizes source paths', async () => {
|
||||
const queryConfig = QueryService.getQueryConfigFromAnalyzer('find-imports', {
|
||||
const queryConfig = await QueryService.getQueryConfigFromAnalyzer(FindImportsAnalyzer, {
|
||||
keepInternalSources: true,
|
||||
});
|
||||
mockProject({
|
||||
|
|
@ -232,7 +236,7 @@ describe('Analyzer "find-imports"', () => {
|
|||
'./internal/source/x.js': '',
|
||||
'./index.js': '',
|
||||
});
|
||||
await providence(queryConfig, _providenceCfg);
|
||||
const queryResults = await providence(queryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const firstEntry = getEntry(queryResult);
|
||||
expect(firstEntry.result[0].importSpecifiers.length).to.equal(1);
|
||||
|
|
@ -250,7 +254,7 @@ describe('Analyzer "find-imports"', () => {
|
|||
|
||||
describe('Options', () => {
|
||||
it('"keepInternalSources"', async () => {
|
||||
const queryConfig = QueryService.getQueryConfigFromAnalyzer('find-imports', {
|
||||
const queryConfig = await QueryService.getQueryConfigFromAnalyzer(FindImportsAnalyzer, {
|
||||
keepInternalSources: true,
|
||||
});
|
||||
mockProject([
|
||||
|
|
@ -262,7 +266,7 @@ describe('Analyzer "find-imports"', () => {
|
|||
import '../../internal/source';
|
||||
`,
|
||||
]);
|
||||
await providence(queryConfig, _providenceCfg);
|
||||
const queryResults = await providence(queryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
|
||||
const firstEntry = getEntry(queryResult);
|
||||
|
|
@ -277,11 +281,11 @@ describe('Analyzer "find-imports"', () => {
|
|||
|
||||
// Post processors for whole result
|
||||
it('"keepOriginalSourceExtensions"', async () => {
|
||||
const queryConfig = QueryService.getQueryConfigFromAnalyzer('find-imports', {
|
||||
const queryConfig = await QueryService.getQueryConfigFromAnalyzer(FindImportsAnalyzer, {
|
||||
keepOriginalSourceExtensions: true,
|
||||
});
|
||||
mockProject([`import '@external/source.js'`, `import '@external/source';`]);
|
||||
await providence(queryConfig, _providenceCfg);
|
||||
const queryResults = await providence(queryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
|
||||
const firstEntry = getEntry(queryResult);
|
||||
|
|
@ -295,7 +299,7 @@ describe('Analyzer "find-imports"', () => {
|
|||
// but only without loss of information and once depending analyzers (match-imports and
|
||||
// match-subclasses) are made compatible.
|
||||
it.skip('"sortBySpecifier"', async () => {
|
||||
const queryConfig = QueryService.getQueryConfigFromAnalyzer('find-imports', {
|
||||
const queryConfig = await QueryService.getQueryConfigFromAnalyzer(FindImportsAnalyzer, {
|
||||
sortBySpecifier: true,
|
||||
});
|
||||
mockProject(
|
||||
|
|
@ -305,7 +309,7 @@ describe('Analyzer "find-imports"', () => {
|
|||
],
|
||||
{ filePaths: ['./file1.js', './file2.js'] },
|
||||
);
|
||||
await providence(queryConfig, _providenceCfg);
|
||||
const queryResults = await providence(queryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,25 +1,24 @@
|
|||
const { expect } = require('chai');
|
||||
const { default: traverse } = require('@babel/traverse');
|
||||
const {
|
||||
import { expect } from 'chai';
|
||||
import { it } from 'mocha';
|
||||
import babelTraverse from '@babel/traverse';
|
||||
import {
|
||||
trackDownIdentifier,
|
||||
trackDownIdentifierFromScope,
|
||||
} = require('../../../../src/program/analyzers/helpers/track-down-identifier.js');
|
||||
const { AstService } = require('../../../../src/program/core/AstService.js');
|
||||
const {
|
||||
} from '../../../../src/program/analyzers/helpers/track-down-identifier.js';
|
||||
import { AstService } from '../../../../src/program/core/AstService.js';
|
||||
import {
|
||||
mockProject,
|
||||
restoreMockedProjects,
|
||||
} = require('../../../../test-helpers/mock-project-helpers.js');
|
||||
const { memoizeConfig } = require('../../../../src/program/utils/memoize.js');
|
||||
} from '../../../../test-helpers/mock-project-helpers.js';
|
||||
import { setupAnalyzerTest } from '../../../../test-helpers/setup-analyzer-test.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('@babel/traverse').NodePath} NodePath
|
||||
*/
|
||||
|
||||
setupAnalyzerTest();
|
||||
|
||||
describe('trackdownIdentifier', () => {
|
||||
beforeEach(() => {
|
||||
memoizeConfig.isCacheDisabled = true;
|
||||
});
|
||||
afterEach(() => {
|
||||
memoizeConfig.isCacheDisabled = false;
|
||||
restoreMockedProjects();
|
||||
});
|
||||
|
||||
it(`tracks down identifier to root file (file that declares identifier)`, async () => {
|
||||
mockProject(
|
||||
{
|
||||
|
|
@ -306,15 +305,17 @@ describe('trackDownIdentifierFromScope', () => {
|
|||
const identifierNameInScope = 'MyClass';
|
||||
const fullCurrentFilePath = '/my/project//src/declarationOfMyClass.js';
|
||||
const projectPath = '/my/project';
|
||||
/** @type {NodePath} */
|
||||
let astPath;
|
||||
|
||||
traverse(ast, {
|
||||
babelTraverse.default(ast, {
|
||||
ClassDeclaration(path) {
|
||||
astPath = path;
|
||||
},
|
||||
});
|
||||
|
||||
const rootFile = await trackDownIdentifierFromScope(
|
||||
// @ts-ignore
|
||||
astPath,
|
||||
identifierNameInScope,
|
||||
fullCurrentFilePath,
|
||||
|
|
@ -349,15 +350,17 @@ describe('trackDownIdentifierFromScope', () => {
|
|||
const identifierNameInScope = 'MyClass';
|
||||
const fullCurrentFilePath = '/my/project/internal.js';
|
||||
const projectPath = '/my/project';
|
||||
/** @type {NodePath} */
|
||||
let astPath;
|
||||
|
||||
traverse(ast, {
|
||||
babelTraverse.default(ast, {
|
||||
ImportDeclaration(path) {
|
||||
astPath = path;
|
||||
},
|
||||
});
|
||||
|
||||
const rootFile = await trackDownIdentifierFromScope(
|
||||
// @ts-ignore
|
||||
astPath,
|
||||
identifierNameInScope,
|
||||
fullCurrentFilePath,
|
||||
|
|
@ -389,15 +392,17 @@ describe('trackDownIdentifierFromScope', () => {
|
|||
const identifierNameInScope = 'El1';
|
||||
const fullCurrentFilePath = '/my/project/internal.js';
|
||||
const projectPath = '/my/project';
|
||||
/** @type {NodePath} */
|
||||
let astPath;
|
||||
|
||||
traverse(ast, {
|
||||
babelTraverse.default(ast, {
|
||||
ClassDeclaration(path) {
|
||||
astPath = path;
|
||||
},
|
||||
});
|
||||
|
||||
const rootFile = await trackDownIdentifierFromScope(
|
||||
// @ts-ignore
|
||||
astPath,
|
||||
identifierNameInScope,
|
||||
fullCurrentFilePath,
|
||||
|
|
|
|||
|
|
@ -1,64 +1,76 @@
|
|||
const { expect } = require('chai');
|
||||
const { providence } = require('../../../src/program/providence.js');
|
||||
const { QueryService } = require('../../../src/program/core/QueryService.js');
|
||||
const FindExportsAnalyzer = require('../../../src/program/analyzers/find-exports.js');
|
||||
const FindImportsAnalyzer = require('../../../src/program/analyzers/find-imports.js');
|
||||
const { setupAnalyzerTest } = require('../../../test-helpers/setup-analyzer-test.js');
|
||||
const { mockTargetAndReferenceProject } = require('../../../test-helpers/mock-project-helpers.js');
|
||||
import { expect } from 'chai';
|
||||
import { it } from 'mocha';
|
||||
import { providence } from '../../../src/program/providence.js';
|
||||
import { QueryService } from '../../../src/program/core/QueryService.js';
|
||||
import FindExportsAnalyzer from '../../../src/program/analyzers/find-exports.js';
|
||||
import FindImportsAnalyzer from '../../../src/program/analyzers/find-imports.js';
|
||||
import { setupAnalyzerTest } from '../../../test-helpers/setup-analyzer-test.js';
|
||||
import { mockTargetAndReferenceProject } from '../../../test-helpers/mock-project-helpers.js';
|
||||
import MatchImportsAnalyzer from '../../../src/program/analyzers/match-imports.js';
|
||||
|
||||
const matchImportsQueryConfig = QueryService.getQueryConfigFromAnalyzer('match-imports');
|
||||
const _providenceCfg = {
|
||||
targetProjectPaths: ['/importing/target/project'],
|
||||
referenceProjectPaths: ['/importing/target/project/node_modules/exporting-ref-project'],
|
||||
};
|
||||
/**
|
||||
* @typedef {import('../../../types/index.js').ProvidenceConfig} ProvidenceConfig
|
||||
*/
|
||||
|
||||
// 1. Reference input data
|
||||
const referenceProject = {
|
||||
path: '/importing/target/project/node_modules/exporting-ref-project',
|
||||
name: 'exporting-ref-project',
|
||||
files: [
|
||||
// This file contains all 'original' exported definitions
|
||||
{
|
||||
file: './ref-src/core.js',
|
||||
code: `
|
||||
setupAnalyzerTest();
|
||||
//
|
||||
describe('Analyzer "match-imports"', async () => {
|
||||
const matchImportsQueryConfig = await QueryService.getQueryConfigFromAnalyzer(
|
||||
MatchImportsAnalyzer,
|
||||
);
|
||||
/** @type {Partial<ProvidenceConfig>} */
|
||||
const _providenceCfg = {
|
||||
targetProjectPaths: ['/importing/target/project'],
|
||||
referenceProjectPaths: ['/importing/target/project/node_modules/exporting-ref-project'],
|
||||
};
|
||||
|
||||
// 1. Reference input data
|
||||
const referenceProject = {
|
||||
path: '/importing/target/project/node_modules/exporting-ref-project',
|
||||
name: 'exporting-ref-project',
|
||||
files: [
|
||||
// This file contains all 'original' exported definitions
|
||||
{
|
||||
file: './ref-src/core.js',
|
||||
code: `
|
||||
// named specifier
|
||||
export class RefClass extends HTMLElement {};
|
||||
|
||||
// default specifier
|
||||
export default class OtherClass {};
|
||||
`,
|
||||
},
|
||||
// This file is used to test file system 'resolvements' -> importing repos using
|
||||
// `import 'exporting-ref-project/ref-src/folder'` should be pointed to this index.js file
|
||||
{
|
||||
file: './ref-src/folder/index.js',
|
||||
code: `
|
||||
},
|
||||
// This file is used to test file system 'resolvements' -> importing repos using
|
||||
// `import 'exporting-ref-project/ref-src/folder'` should be pointed to this index.js file
|
||||
{
|
||||
file: './ref-src/folder/index.js',
|
||||
code: `
|
||||
// this file (and thus this export) should be resolved via
|
||||
// [import 'exporting-ref-project/ref-src/folder']
|
||||
export const resolvePathCorrect = null;
|
||||
`,
|
||||
},
|
||||
{
|
||||
file: './ref-component.js',
|
||||
code: `
|
||||
},
|
||||
{
|
||||
file: './ref-component.js',
|
||||
code: `
|
||||
// global effects
|
||||
import { RefClass } from './ref-src/core.js';
|
||||
customElements.define('ref-component', RefClass);
|
||||
`,
|
||||
},
|
||||
{
|
||||
file: './not-imported.js',
|
||||
code: `
|
||||
},
|
||||
{
|
||||
file: './not-imported.js',
|
||||
code: `
|
||||
// this file will not be included by "importing-target-project" defined below
|
||||
export const notImported = null;
|
||||
`,
|
||||
},
|
||||
// This file re-exports everything from 'ref-src/core.js'
|
||||
{
|
||||
file: './index.js',
|
||||
// Default export, renamed export
|
||||
// export default class X
|
||||
code: `
|
||||
},
|
||||
// This file re-exports everything from 'ref-src/core.js'
|
||||
{
|
||||
file: './index.js',
|
||||
// Default export, renamed export
|
||||
// export default class X
|
||||
code: `
|
||||
// re-exported specifier
|
||||
export { RefClass } from './ref-src/core.js';
|
||||
|
||||
|
|
@ -69,26 +81,26 @@ const referenceProject = {
|
|||
import refConstImported from './ref-src/core.js';
|
||||
export default refConstImported;
|
||||
`,
|
||||
},
|
||||
{
|
||||
file: './export-namespaced.js',
|
||||
code: `
|
||||
},
|
||||
{
|
||||
file: './export-namespaced.js',
|
||||
code: `
|
||||
// This file will test if all its exported specifiers are catched via "import * as"
|
||||
// (namespaced)
|
||||
export const a = 4;
|
||||
export default class B {};
|
||||
`,
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const searchTargetProject = {
|
||||
path: '/importing/target/project',
|
||||
name: 'importing-target-project',
|
||||
files: [
|
||||
{
|
||||
file: './target-src/indirect-imports.js',
|
||||
code: `
|
||||
const searchTargetProject = {
|
||||
path: '/importing/target/project',
|
||||
name: 'importing-target-project',
|
||||
files: [
|
||||
{
|
||||
file: './target-src/indirect-imports.js',
|
||||
code: `
|
||||
// named import (indirect, needs transitivity check)
|
||||
import { RefClass } from 'exporting-ref-project';
|
||||
|
||||
|
|
@ -101,10 +113,10 @@ const searchTargetProject = {
|
|||
// should not be found
|
||||
import { nonMatched } from 'unknown-project';
|
||||
`,
|
||||
},
|
||||
{
|
||||
file: './target-src/direct-imports.js',
|
||||
code: `
|
||||
},
|
||||
{
|
||||
file: './target-src/direct-imports.js',
|
||||
code: `
|
||||
// a direct named import
|
||||
import { RefClass } from 'exporting-ref-project/ref-src/core.js';
|
||||
|
||||
|
|
@ -128,77 +140,74 @@ const searchTargetProject = {
|
|||
// - should resolve "as folder", to 'exporting-ref-project/ref-src/folder/index.js'
|
||||
import { resolvePathCorrect } from 'exporting-ref-project/ref-src/folder';
|
||||
`,
|
||||
},
|
||||
{
|
||||
file: './import-namespaced.js',
|
||||
code: `
|
||||
},
|
||||
{
|
||||
file: './import-namespaced.js',
|
||||
code: `
|
||||
// should return a match for every export in reference source
|
||||
import * as namespace from 'exporting-ref-project/export-namespaced.js';
|
||||
`,
|
||||
},
|
||||
|
||||
/**
|
||||
* Possible other checks (although already tested in unit tests of find-import/find-exports):
|
||||
* - dynamic imports
|
||||
* - default and named specifiers in one declaration
|
||||
* - renamed imports
|
||||
* - ...?
|
||||
*/
|
||||
],
|
||||
};
|
||||
|
||||
// 2. Based on the example reference and target projects, we expect the following
|
||||
// extracted specifiers to be found...
|
||||
const expectedExportIdsIndirect = [
|
||||
'RefClass::./index.js::exporting-ref-project',
|
||||
'RefRenamedClass::./index.js::exporting-ref-project',
|
||||
'[default]::./index.js::exporting-ref-project',
|
||||
];
|
||||
|
||||
const expectedExportIdsDirect = [
|
||||
'RefClass::./ref-src/core.js::exporting-ref-project',
|
||||
'[default]::./ref-src/core.js::exporting-ref-project',
|
||||
'resolvePathCorrect::./ref-src/folder/index.js::exporting-ref-project',
|
||||
];
|
||||
|
||||
const expectedExportIdsNamespaced = [
|
||||
'a::./export-namespaced.js::exporting-ref-project',
|
||||
'[default]::./export-namespaced.js::exporting-ref-project',
|
||||
];
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const expectedExportIds = [
|
||||
...expectedExportIdsIndirect,
|
||||
...expectedExportIdsDirect,
|
||||
...expectedExportIdsNamespaced,
|
||||
];
|
||||
|
||||
// 3. The AnalyzerQueryResult generated by "match-imports"
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const expectedMatchesOutput = [
|
||||
{
|
||||
exportSpecifier: {
|
||||
name: 'RefClass',
|
||||
project: 'exporting-ref-project', // name under which it is registered in npm ("name" attr in package.json)
|
||||
filePath: './ref-src/core.js',
|
||||
id: 'RefClass::./ref-src/core.js::exporting-ref-project',
|
||||
},
|
||||
// All the matched targets (files importing the specifier), ordered per project
|
||||
matchesPerProject: [
|
||||
{
|
||||
project: 'importing-target-project',
|
||||
files: [
|
||||
'./target-src/indirect-imports.js',
|
||||
// ...
|
||||
],
|
||||
},
|
||||
// ...
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
describe('Analyzer "match-imports"', () => {
|
||||
const queryResults = setupAnalyzerTest();
|
||||
/**
|
||||
* Possible other checks (although already tested in unit tests of find-import/find-exports):
|
||||
* - dynamic imports
|
||||
* - default and named specifiers in one declaration
|
||||
* - renamed imports
|
||||
* - ...?
|
||||
*/
|
||||
],
|
||||
};
|
||||
|
||||
// 2. Based on the example reference and target projects, we expect the following
|
||||
// extracted specifiers to be found...
|
||||
const expectedExportIdsIndirect = [
|
||||
'RefClass::./index.js::exporting-ref-project',
|
||||
'RefRenamedClass::./index.js::exporting-ref-project',
|
||||
'[default]::./index.js::exporting-ref-project',
|
||||
];
|
||||
|
||||
const expectedExportIdsDirect = [
|
||||
'RefClass::./ref-src/core.js::exporting-ref-project',
|
||||
'[default]::./ref-src/core.js::exporting-ref-project',
|
||||
'resolvePathCorrect::./ref-src/folder/index.js::exporting-ref-project',
|
||||
];
|
||||
|
||||
const expectedExportIdsNamespaced = [
|
||||
'a::./export-namespaced.js::exporting-ref-project',
|
||||
'[default]::./export-namespaced.js::exporting-ref-project',
|
||||
];
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const expectedExportIds = [
|
||||
...expectedExportIdsIndirect,
|
||||
...expectedExportIdsDirect,
|
||||
...expectedExportIdsNamespaced,
|
||||
];
|
||||
|
||||
// 3. The AnalyzerQueryResult generated by "match-imports"
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const expectedMatchesOutput = [
|
||||
{
|
||||
exportSpecifier: {
|
||||
name: 'RefClass',
|
||||
project: 'exporting-ref-project', // name under which it is registered in npm ("name" attr in package.json)
|
||||
filePath: './ref-src/core.js',
|
||||
id: 'RefClass::./ref-src/core.js::exporting-ref-project',
|
||||
},
|
||||
// All the matched targets (files importing the specifier), ordered per project
|
||||
matchesPerProject: [
|
||||
{
|
||||
project: 'importing-target-project',
|
||||
files: [
|
||||
'./target-src/indirect-imports.js',
|
||||
// ...
|
||||
],
|
||||
},
|
||||
// ...
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
function testMatchedEntry(targetExportedId, queryResult, importedByFiles = []) {
|
||||
const matchedEntry = queryResult.queryOutput.find(
|
||||
|
|
@ -229,7 +238,8 @@ describe('Analyzer "match-imports"', () => {
|
|||
files: [{ file: './index.js', code: `import myFn from 'ref/direct.js';` }],
|
||||
};
|
||||
mockTargetAndReferenceProject(targetProject, refProject);
|
||||
await providence(matchImportsQueryConfig, {
|
||||
|
||||
const queryResults = await providence(matchImportsQueryConfig, {
|
||||
targetProjectPaths: [targetProject.path],
|
||||
referenceProjectPaths: [refProject.path],
|
||||
});
|
||||
|
|
@ -262,7 +272,7 @@ describe('Analyzer "match-imports"', () => {
|
|||
files: [{ file: './index.js', code: `import { x } from 'ref/indirect.js';` }],
|
||||
};
|
||||
mockTargetAndReferenceProject(targetProject, refProject);
|
||||
await providence(matchImportsQueryConfig, {
|
||||
const queryResults = await providence(matchImportsQueryConfig, {
|
||||
targetProjectPaths: [targetProject.path],
|
||||
referenceProjectPaths: [refProject.path],
|
||||
});
|
||||
|
|
@ -294,7 +304,7 @@ describe('Analyzer "match-imports"', () => {
|
|||
files: [{ file: './index.js', code: `import * as xy from 'ref/namespaced.js';` }],
|
||||
};
|
||||
mockTargetAndReferenceProject(targetProject, refProject);
|
||||
await providence(matchImportsQueryConfig, {
|
||||
const queryResults = await providence(matchImportsQueryConfig, {
|
||||
targetProjectPaths: [targetProject.path],
|
||||
referenceProjectPaths: [refProject.path],
|
||||
});
|
||||
|
|
@ -333,7 +343,7 @@ describe('Analyzer "match-imports"', () => {
|
|||
describe('Inside small example project', () => {
|
||||
it(`identifies all direct export specifiers consumed by "importing-target-project"`, async () => {
|
||||
mockTargetAndReferenceProject(searchTargetProject, referenceProject);
|
||||
await providence(matchImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
expectedExportIdsDirect.forEach(directId => {
|
||||
expect(
|
||||
|
|
@ -346,7 +356,7 @@ describe('Analyzer "match-imports"', () => {
|
|||
|
||||
it(`identifies all indirect export specifiers consumed by "importing-target-project"`, async () => {
|
||||
mockTargetAndReferenceProject(searchTargetProject, referenceProject);
|
||||
await providence(matchImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
expectedExportIdsIndirect.forEach(indirectId => {
|
||||
expect(
|
||||
|
|
@ -359,7 +369,7 @@ describe('Analyzer "match-imports"', () => {
|
|||
|
||||
it(`matches namespaced specifiers consumed by "importing-target-project"`, async () => {
|
||||
mockTargetAndReferenceProject(searchTargetProject, referenceProject);
|
||||
await providence(matchImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
expectedExportIdsNamespaced.forEach(exportedSpecifierId => {
|
||||
expect(
|
||||
|
|
@ -394,7 +404,7 @@ describe('Analyzer "match-imports"', () => {
|
|||
files: [{ file: './index.js', code: `import myFn from 'ref/direct.js';` }],
|
||||
};
|
||||
mockTargetAndReferenceProject(targetProject, refProject);
|
||||
await providence(matchImportsQueryConfig, {
|
||||
const queryResults = await providence(matchImportsQueryConfig, {
|
||||
targetProjectPaths: [targetProject.path],
|
||||
referenceProjectPaths: [refProject.path],
|
||||
});
|
||||
|
|
@ -419,7 +429,7 @@ describe('Analyzer "match-imports"', () => {
|
|||
],
|
||||
};
|
||||
mockTargetAndReferenceProject(targetProject, refProject);
|
||||
await providence(matchImportsQueryConfig, {
|
||||
const queryResults = await providence(matchImportsQueryConfig, {
|
||||
targetProjectPaths: [targetProject.path],
|
||||
referenceProjectPaths: [refProject.path],
|
||||
});
|
||||
|
|
@ -460,7 +470,7 @@ describe('Analyzer "match-imports"', () => {
|
|||
],
|
||||
};
|
||||
mockTargetAndReferenceProject(targetProject, refProject);
|
||||
await providence(matchImportsQueryConfig, {
|
||||
const queryResults = await providence(matchImportsQueryConfig, {
|
||||
targetProjectPaths: [targetProject.path],
|
||||
referenceProjectPaths: [refProject.path],
|
||||
});
|
||||
|
|
@ -478,7 +488,7 @@ describe('Analyzer "match-imports"', () => {
|
|||
describe('Inside small example project', () => {
|
||||
it(`produces a list of all matches, sorted by project`, async () => {
|
||||
mockTargetAndReferenceProject(searchTargetProject, referenceProject);
|
||||
await providence(matchImportsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchImportsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
|
||||
expectedExportIdsDirect.forEach(targetId => {
|
||||
|
|
@ -502,11 +512,14 @@ describe('Analyzer "match-imports"', () => {
|
|||
targetProjectPath: referenceProject.path,
|
||||
});
|
||||
|
||||
const matchImportsQueryConfigExt = QueryService.getQueryConfigFromAnalyzer('match-imports', {
|
||||
targetProjectResult: findImportsResult,
|
||||
referenceProjectResult: findExportsResult,
|
||||
});
|
||||
await providence(matchImportsQueryConfigExt, _providenceCfg);
|
||||
const matchImportsQueryConfigExt = await QueryService.getQueryConfigFromAnalyzer(
|
||||
MatchImportsAnalyzer,
|
||||
{
|
||||
targetProjectResult: findImportsResult,
|
||||
referenceProjectResult: findExportsResult,
|
||||
},
|
||||
);
|
||||
const queryResults = await providence(matchImportsQueryConfigExt, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
|
||||
expectedExportIdsDirect.forEach(targetId => {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,18 @@
|
|||
const { expect } = require('chai');
|
||||
const { providence } = require('../../../src/program/providence.js');
|
||||
const { QueryService } = require('../../../src/program/core/QueryService.js');
|
||||
const { setupAnalyzerTest } = require('../../../test-helpers/setup-analyzer-test.js');
|
||||
const { mockTargetAndReferenceProject } = require('../../../test-helpers/mock-project-helpers.js');
|
||||
import { expect } from 'chai';
|
||||
import { it } from 'mocha';
|
||||
import { providence } from '../../../src/program/providence.js';
|
||||
import { QueryService } from '../../../src/program/core/QueryService.js';
|
||||
import { setupAnalyzerTest } from '../../../test-helpers/setup-analyzer-test.js';
|
||||
import { mockTargetAndReferenceProject } from '../../../test-helpers/mock-project-helpers.js';
|
||||
import MatchPathsAnalyzer from '../../../src/program/analyzers/match-paths.js';
|
||||
|
||||
describe('Analyzer "match-paths"', () => {
|
||||
const queryResults = setupAnalyzerTest();
|
||||
/**
|
||||
* @typedef {import('../../../types/index.js').ProvidenceConfig} ProvidenceConfig
|
||||
*/
|
||||
|
||||
setupAnalyzerTest();
|
||||
|
||||
describe('Analyzer "match-paths"', async () => {
|
||||
const referenceProject = {
|
||||
path: '/importing/target/project/node_modules/reference-project',
|
||||
name: 'reference-project',
|
||||
|
|
@ -108,7 +114,8 @@ describe('Analyzer "match-paths"', () => {
|
|||
],
|
||||
};
|
||||
|
||||
const matchPathsQueryConfig = QueryService.getQueryConfigFromAnalyzer('match-paths');
|
||||
const matchPathsQueryConfig = await QueryService.getQueryConfigFromAnalyzer(MatchPathsAnalyzer);
|
||||
/** @type {Partial<ProvidenceConfig>} */
|
||||
const _providenceCfg = {
|
||||
targetProjectPaths: [searchTargetProject.path],
|
||||
referenceProjectPaths: [referenceProject.path],
|
||||
|
|
@ -179,7 +186,7 @@ describe('Analyzer "match-paths"', () => {
|
|||
|
||||
it(`outputs an array result with from/to classes and paths`, async () => {
|
||||
mockTargetAndReferenceProject(searchTargetProject, referenceProject);
|
||||
await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
expect(queryResult.queryOutput).to.eql(expectedMatches);
|
||||
});
|
||||
|
|
@ -222,7 +229,7 @@ describe('Analyzer "match-paths"', () => {
|
|||
|
||||
it(`identifies all "from" and "to" classes`, async () => {
|
||||
mockTargetAndReferenceProject(targetProj, refProj);
|
||||
await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
expect(queryResult.queryOutput[0].variable.from).to.equal('RefClass');
|
||||
expect(queryResult.queryOutput[0].variable.to).to.equal('TargetClass');
|
||||
|
|
@ -230,7 +237,7 @@ describe('Analyzer "match-paths"', () => {
|
|||
|
||||
it(`identifies all "from" and "to" paths`, async () => {
|
||||
mockTargetAndReferenceProject(targetProj, refProj);
|
||||
await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
expect(queryResult.queryOutput[0].variable.paths[0]).to.eql({
|
||||
from: './index.js',
|
||||
|
|
@ -254,7 +261,7 @@ describe('Analyzer "match-paths"', () => {
|
|||
|
||||
it(`gives back "to" path closest to root`, async () => {
|
||||
mockTargetAndReferenceProject(targetProjWithMultipleExports, refProj);
|
||||
await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
expect(queryResult.queryOutput[0].variable.paths[0]).to.eql({
|
||||
from: './index.js',
|
||||
|
|
@ -287,7 +294,7 @@ describe('Analyzer "match-paths"', () => {
|
|||
],
|
||||
};
|
||||
mockTargetAndReferenceProject(targetProjWithMultipleExportsAndMainEntry, refProj);
|
||||
await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
expect(queryResult.queryOutput[0].variable.paths[0]).to.eql({
|
||||
from: './index.js',
|
||||
|
|
@ -298,7 +305,7 @@ describe('Analyzer "match-paths"', () => {
|
|||
|
||||
it(`prefixes project paths`, async () => {
|
||||
mockTargetAndReferenceProject(targetProj, refProj);
|
||||
await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
const unprefixedPaths = queryResult.queryOutput[0].variable.paths[0];
|
||||
expect(unprefixedPaths).to.eql({ from: './index.js', to: './target-src/TargetClass.js' });
|
||||
|
|
@ -327,7 +334,7 @@ describe('Analyzer "match-paths"', () => {
|
|||
],
|
||||
};
|
||||
mockTargetAndReferenceProject(targetProjMultipleTargetExtensions, refProj);
|
||||
await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
expect(queryResult.queryOutput[0].variable.paths[0]).to.eql({
|
||||
from: './index.js',
|
||||
|
|
@ -395,10 +402,13 @@ describe('Analyzer "match-paths"', () => {
|
|||
],
|
||||
};
|
||||
mockTargetAndReferenceProject(targetProjMultipleTargetExtensions, refProj);
|
||||
const matchPathsQueryConfigFilter = QueryService.getQueryConfigFromAnalyzer('match-paths', {
|
||||
prefix: { from: 'ref', to: 'target' },
|
||||
});
|
||||
await providence(matchPathsQueryConfigFilter, _providenceCfg);
|
||||
const matchPathsQueryConfigFilter = await QueryService.getQueryConfigFromAnalyzer(
|
||||
MatchPathsAnalyzer,
|
||||
{
|
||||
prefix: { from: 'ref', to: 'target' },
|
||||
},
|
||||
);
|
||||
const queryResults = await providence(matchPathsQueryConfigFilter, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
expect(queryResult.queryOutput[0].variable.paths[0]).to.eql({
|
||||
from: './index.js',
|
||||
|
|
@ -503,7 +513,7 @@ describe('Analyzer "match-paths"', () => {
|
|||
|
||||
it(`outputs an array result with from/to tag names and paths`, async () => {
|
||||
mockTargetAndReferenceProject(searchTargetProject, referenceProject);
|
||||
await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
expect(queryResult.queryOutput[0].tag).to.eql(expectedMatches[0]);
|
||||
expect(queryResult.queryOutput[1].tag).to.eql(expectedMatches[1]);
|
||||
|
|
@ -563,7 +573,7 @@ describe('Analyzer "match-paths"', () => {
|
|||
referenceProjectPaths: ['/their-components'],
|
||||
};
|
||||
|
||||
await providence(
|
||||
const queryResults = await providence(
|
||||
{ ...matchPathsQueryConfig, prefix: { from: 'their', to: 'my' } },
|
||||
providenceCfg,
|
||||
);
|
||||
|
|
@ -587,7 +597,7 @@ describe('Analyzer "match-paths"', () => {
|
|||
describe('Features', () => {
|
||||
it(`identifies all "from" and "to" tagnames`, async () => {
|
||||
mockTargetAndReferenceProject(searchTargetProject, referenceProject);
|
||||
await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
expect(queryResult.queryOutput[0].tag.from).to.equal('el-1');
|
||||
expect(queryResult.queryOutput[0].tag.to).to.equal('extended-el-1');
|
||||
|
|
@ -595,7 +605,7 @@ describe('Analyzer "match-paths"', () => {
|
|||
|
||||
it(`identifies all "from" and "to" paths`, async () => {
|
||||
mockTargetAndReferenceProject(searchTargetProject, referenceProject);
|
||||
await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
expect(queryResult.queryOutput[0].tag.paths[0]).to.eql({
|
||||
from: './customelementDefinitions.js',
|
||||
|
|
@ -605,7 +615,7 @@ describe('Analyzer "match-paths"', () => {
|
|||
|
||||
it(`prefixes project paths`, async () => {
|
||||
mockTargetAndReferenceProject(searchTargetProject, referenceProject);
|
||||
await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
expect(queryResult.queryOutput[0].tag.paths[1]).to.eql({
|
||||
from: 'reference-project/customelementDefinitions.js',
|
||||
|
|
@ -724,7 +734,7 @@ describe('Analyzer "match-paths"', () => {
|
|||
|
||||
it(`outputs a "name", "variable" and "tag" entry`, async () => {
|
||||
mockTargetAndReferenceProject(searchTargetProjectFull, referenceProjectFull);
|
||||
await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchPathsQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
expect(queryResult.queryOutput).to.eql(expectedMatchesFull);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,30 +1,39 @@
|
|||
const { expect } = require('chai');
|
||||
const { providence } = require('../../../src/program/providence.js');
|
||||
const { QueryService } = require('../../../src/program/core/QueryService.js');
|
||||
const { mockTargetAndReferenceProject } = require('../../../test-helpers/mock-project-helpers.js');
|
||||
const { setupAnalyzerTest } = require('../../../test-helpers/setup-analyzer-test.js');
|
||||
import { expect } from 'chai';
|
||||
import { it } from 'mocha';
|
||||
import { providence } from '../../../src/program/providence.js';
|
||||
import { QueryService } from '../../../src/program/core/QueryService.js';
|
||||
import { mockTargetAndReferenceProject } from '../../../test-helpers/mock-project-helpers.js';
|
||||
import { setupAnalyzerTest } from '../../../test-helpers/setup-analyzer-test.js';
|
||||
import MatchSubclassesAnalyzer from '../../../src/program/analyzers/match-subclasses.js';
|
||||
|
||||
// 1. Reference input data
|
||||
const referenceProject = {
|
||||
path: '/importing/target/project/node_modules/exporting-ref-project',
|
||||
name: 'exporting-ref-project',
|
||||
files: [
|
||||
// This file contains all 'original' exported definitions
|
||||
{
|
||||
file: './ref-src/core.js',
|
||||
code: `
|
||||
/**
|
||||
* @typedef {import('../../../types/index.js').ProvidenceConfig} ProvidenceConfig
|
||||
*/
|
||||
|
||||
setupAnalyzerTest();
|
||||
|
||||
describe('Analyzer "match-subclasses"', async () => {
|
||||
// 1. Reference input data
|
||||
const referenceProject = {
|
||||
path: '/importing/target/project/node_modules/exporting-ref-project',
|
||||
name: 'exporting-ref-project',
|
||||
files: [
|
||||
// This file contains all 'original' exported definitions
|
||||
{
|
||||
file: './ref-src/core.js',
|
||||
code: `
|
||||
// named specifier
|
||||
export class RefClass extends HTMLElement {};
|
||||
|
||||
// default specifier
|
||||
export default class OtherClass {};
|
||||
`,
|
||||
},
|
||||
// This file is used to test file system 'resolvements' -> importing repos using
|
||||
// `import 'exporting-ref-project/ref-src/folder'` should be pointed to this index.js file
|
||||
{
|
||||
file: './index.js',
|
||||
code: `
|
||||
},
|
||||
// This file is used to test file system 'resolvements' -> importing repos using
|
||||
// `import 'exporting-ref-project/ref-src/folder'` should be pointed to this index.js file
|
||||
{
|
||||
file: './index.js',
|
||||
code: `
|
||||
export { RefClass as RefRenamedClass } from './ref-src/core.js';
|
||||
|
||||
// re-exported default specifier
|
||||
|
|
@ -33,28 +42,28 @@ const referenceProject = {
|
|||
|
||||
export const Mixin = superclass => class MyMixin extends superclass {}
|
||||
`,
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const searchTargetProject = {
|
||||
path: '/importing/target/project',
|
||||
name: 'importing-target-project',
|
||||
files: [
|
||||
{
|
||||
file: './target-src/indirect-imports.js',
|
||||
// Indirect (via project root) imports
|
||||
code: `
|
||||
const searchTargetProject = {
|
||||
path: '/importing/target/project',
|
||||
name: 'importing-target-project',
|
||||
files: [
|
||||
{
|
||||
file: './target-src/indirect-imports.js',
|
||||
// Indirect (via project root) imports
|
||||
code: `
|
||||
// renamed import (indirect, needs transitivity check)
|
||||
import { RefRenamedClass } from 'exporting-ref-project';
|
||||
import defaultExport from 'exporting-ref-project';
|
||||
|
||||
class ExtendRefRenamedClass extends RefRenamedClass {}
|
||||
`,
|
||||
},
|
||||
{
|
||||
file: './target-src/direct-imports.js',
|
||||
code: `
|
||||
},
|
||||
{
|
||||
file: './target-src/direct-imports.js',
|
||||
code: `
|
||||
// a direct named import
|
||||
import { RefClass } from 'exporting-ref-project/ref-src/core.js';
|
||||
|
||||
|
|
@ -71,61 +80,59 @@ const searchTargetProject = {
|
|||
class ExtendRefDefault extends RefDefault {}
|
||||
class ExtendRefClassWithMixin extends ForeignMixin(Mixin(RefClass)) {}
|
||||
`,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const matchSubclassesQueryConfig = QueryService.getQueryConfigFromAnalyzer('match-subclasses');
|
||||
const _providenceCfg = {
|
||||
targetProjectPaths: [searchTargetProject.path],
|
||||
referenceProjectPaths: [referenceProject.path],
|
||||
};
|
||||
|
||||
// 2. Extracted specifiers (by find-exports analyzer)
|
||||
const expectedExportIdsIndirect = ['RefRenamedClass::./index.js::exporting-ref-project'];
|
||||
|
||||
const expectedExportIdsDirect = [
|
||||
// ids should be unique across multiple projects
|
||||
// Not in scope: version number of a project.
|
||||
'RefClass::./ref-src/core.js::exporting-ref-project',
|
||||
'[default]::./index.js::exporting-ref-project',
|
||||
'Mixin::./index.js::exporting-ref-project',
|
||||
];
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const expectedExportIds = [...expectedExportIdsIndirect, ...expectedExportIdsDirect];
|
||||
|
||||
// 3. The AnalyzerQueryResult generated by "match-subclasses"
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const expectedMatchesOutput = [
|
||||
{
|
||||
exportSpecifier: {
|
||||
name: 'RefClass',
|
||||
// name under which it is registered in npm ("name" attr in package.json)
|
||||
project: 'exporting-ref-project',
|
||||
filePath: './ref-src/core.js',
|
||||
id: 'RefClass::./ref-src/core.js::exporting-ref-project',
|
||||
|
||||
// TODO: next step => identify transitive relations and add inside
|
||||
// most likely via post processor
|
||||
},
|
||||
// All the matched targets (files importing the specifier), ordered per project
|
||||
matchesPerProject: [
|
||||
{
|
||||
project: 'importing-target-project',
|
||||
files: [
|
||||
{ file: './target-src/indirect-imports.js', identifier: 'ExtendedRefClass' },
|
||||
// ...
|
||||
],
|
||||
},
|
||||
// ...
|
||||
],
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
// eslint-disable-next-line no-shadow
|
||||
const matchSubclassesQueryConfig = await QueryService.getQueryConfigFromAnalyzer(
|
||||
MatchSubclassesAnalyzer,
|
||||
);
|
||||
/** @type {Partial<ProvidenceConfig>} */
|
||||
const _providenceCfg = {
|
||||
targetProjectPaths: [searchTargetProject.path],
|
||||
referenceProjectPaths: [referenceProject.path],
|
||||
};
|
||||
|
||||
describe('Analyzer "match-subclasses"', () => {
|
||||
const queryResults = setupAnalyzerTest();
|
||||
// 2. Extracted specifiers (by find-exports analyzer)
|
||||
const expectedExportIdsIndirect = ['RefRenamedClass::./index.js::exporting-ref-project'];
|
||||
|
||||
const expectedExportIdsDirect = [
|
||||
// ids should be unique across multiple projects
|
||||
// Not in scope: version number of a project.
|
||||
'RefClass::./ref-src/core.js::exporting-ref-project',
|
||||
'[default]::./index.js::exporting-ref-project',
|
||||
'Mixin::./index.js::exporting-ref-project',
|
||||
];
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const expectedExportIds = [...expectedExportIdsIndirect, ...expectedExportIdsDirect];
|
||||
|
||||
// 3. The AnalyzerQueryResult generated by "match-subclasses"
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const expectedMatchesOutput = [
|
||||
{
|
||||
exportSpecifier: {
|
||||
name: 'RefClass',
|
||||
// name under which it is registered in npm ("name" attr in package.json)
|
||||
project: 'exporting-ref-project',
|
||||
filePath: './ref-src/core.js',
|
||||
id: 'RefClass::./ref-src/core.js::exporting-ref-project',
|
||||
|
||||
// TODO: next step => identify transitive relations and add inside
|
||||
// most likely via post processor
|
||||
},
|
||||
// All the matched targets (files importing the specifier), ordered per project
|
||||
matchesPerProject: [
|
||||
{
|
||||
project: 'importing-target-project',
|
||||
files: [
|
||||
{ file: './target-src/indirect-imports.js', identifier: 'ExtendedRefClass' },
|
||||
// ...
|
||||
],
|
||||
},
|
||||
// ...
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
describe('Match Features', () => {
|
||||
it(`identifies all directly imported class extensions`, async () => {
|
||||
|
|
@ -149,7 +156,7 @@ describe('Analyzer "match-subclasses"', () => {
|
|||
],
|
||||
};
|
||||
mockTargetAndReferenceProject(targetProject, refProject);
|
||||
await providence(matchSubclassesQueryConfig, {
|
||||
const queryResults = await providence(matchSubclassesQueryConfig, {
|
||||
targetProjectPaths: [targetProject.path],
|
||||
referenceProjectPaths: [refProject.path],
|
||||
});
|
||||
|
|
@ -201,7 +208,7 @@ describe('Analyzer "match-subclasses"', () => {
|
|||
],
|
||||
};
|
||||
mockTargetAndReferenceProject(targetProject, refProject);
|
||||
await providence(matchSubclassesQueryConfig, {
|
||||
const queryResults = await providence(matchSubclassesQueryConfig, {
|
||||
targetProjectPaths: [targetProject.path],
|
||||
referenceProjectPaths: [refProject.path],
|
||||
});
|
||||
|
|
@ -255,7 +262,7 @@ describe('Analyzer "match-subclasses"', () => {
|
|||
],
|
||||
};
|
||||
mockTargetAndReferenceProject(targetProject, refProject);
|
||||
await providence(matchSubclassesQueryConfig, {
|
||||
const queryResults = await providence(matchSubclassesQueryConfig, {
|
||||
targetProjectPaths: [targetProject.path],
|
||||
referenceProjectPaths: [refProject.path],
|
||||
});
|
||||
|
|
@ -289,7 +296,7 @@ describe('Analyzer "match-subclasses"', () => {
|
|||
describe('Inside small example project', () => {
|
||||
it(`identifies all indirect export specifiers consumed by "importing-target-project"`, async () => {
|
||||
mockTargetAndReferenceProject(searchTargetProject, referenceProject);
|
||||
await providence(matchSubclassesQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchSubclassesQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
expectedExportIdsIndirect.forEach(indirectId => {
|
||||
expect(
|
||||
|
|
@ -302,7 +309,7 @@ describe('Analyzer "match-subclasses"', () => {
|
|||
|
||||
it(`identifies all direct export specifiers consumed by "importing-target-project"`, async () => {
|
||||
mockTargetAndReferenceProject(searchTargetProject, referenceProject);
|
||||
await providence(matchSubclassesQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchSubclassesQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
expectedExportIdsDirect.forEach(directId => {
|
||||
expect(
|
||||
|
|
@ -336,7 +343,7 @@ describe('Analyzer "match-subclasses"', () => {
|
|||
}
|
||||
|
||||
mockTargetAndReferenceProject(searchTargetProject, referenceProject);
|
||||
await providence(matchSubclassesQueryConfig, _providenceCfg);
|
||||
const queryResults = await providence(matchSubclassesQueryConfig, _providenceCfg);
|
||||
const queryResult = queryResults[0];
|
||||
|
||||
expectedExportIdsDirect.forEach(targetId => {
|
||||
|
|
|
|||
|
|
@ -1,20 +1,19 @@
|
|||
const { expect } = require('chai');
|
||||
const {
|
||||
mockProject,
|
||||
restoreMockedProjects,
|
||||
} = require('../../../test-helpers/mock-project-helpers.js');
|
||||
const { setupAnalyzerTest } = require('../../../test-helpers/setup-analyzer-test.js');
|
||||
const { QueryService } = require('../../../src/program/core/QueryService.js');
|
||||
const { providence } = require('../../../src/program/providence.js');
|
||||
const { DummyAnalyzer } = require('../../../test-helpers/templates/DummyAnalyzer.js');
|
||||
import { expect } from 'chai';
|
||||
import { it } from 'mocha';
|
||||
import { mockProject, restoreMockedProjects } from '../../../test-helpers/mock-project-helpers.js';
|
||||
import { setupAnalyzerTest } from '../../../test-helpers/setup-analyzer-test.js';
|
||||
import { QueryService } from '../../../src/program/core/QueryService.js';
|
||||
import { providence } from '../../../src/program/providence.js';
|
||||
import { DummyAnalyzer } from '../../../test-helpers/templates/DummyAnalyzer.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../../../src/program/types/core').ProvidenceConfig} ProvidenceConfig
|
||||
* @typedef {import('../../../types/index.js').ProvidenceConfig} ProvidenceConfig
|
||||
*/
|
||||
|
||||
describe('Analyzer', () => {
|
||||
setupAnalyzerTest();
|
||||
|
||||
describe('Analyzer', async () => {
|
||||
const dummyAnalyzer = new DummyAnalyzer();
|
||||
const queryResults = setupAnalyzerTest();
|
||||
|
||||
describe('Public api', () => {
|
||||
it('has a "name" string', async () => {
|
||||
|
|
@ -41,17 +40,17 @@ describe('Analyzer', () => {
|
|||
restoreMockedProjects();
|
||||
});
|
||||
|
||||
const myQueryConfigObject = QueryService.getQueryConfigFromAnalyzer(DummyAnalyzer);
|
||||
const myQueryConfigObject = await QueryService.getQueryConfigFromAnalyzer(DummyAnalyzer);
|
||||
/** @type {Partial<ProvidenceConfig>} */
|
||||
const _providenceCfg = {
|
||||
targetProjectPaths: ['/fictional/project'],
|
||||
};
|
||||
|
||||
describe('Prepare phase', () => {
|
||||
it('looks for a cached result', async () => {
|
||||
it.skip('looks for a cached result', async () => {
|
||||
// Our configuration object
|
||||
mockProject([`const validJs = true;`, `let invalidJs = false;`]);
|
||||
await providence(myQueryConfigObject, _providenceCfg);
|
||||
// const queryResults = await providence(myQueryConfigObject, _providenceCfg);
|
||||
});
|
||||
|
||||
it('exposes a ".targetMeta" object', async () => {});
|
||||
|
|
@ -76,8 +75,8 @@ describe('Analyzer', () => {
|
|||
});
|
||||
|
||||
describe('Finalize phase', () => {
|
||||
it('returns an AnalyzerQueryResult', async () => {
|
||||
await providence(myQueryConfigObject, _providenceCfg);
|
||||
it.skip('returns an AnalyzerQueryResult', async () => {
|
||||
const queryResults = await providence(myQueryConfigObject, _providenceCfg);
|
||||
|
||||
const queryResult = queryResults[0];
|
||||
const { queryOutput, meta } = queryResult;
|
||||
|
|
|
|||
|
|
@ -1,15 +1,18 @@
|
|||
const { expect } = require('chai');
|
||||
const pathLib = require('path');
|
||||
const { InputDataService } = require('../../../src/program/core/InputDataService.js');
|
||||
const { memoizeConfig } = require('../../../src/program/utils/memoize.js');
|
||||
const {
|
||||
import { expect } from 'chai';
|
||||
import { it } from 'mocha';
|
||||
import pathLib from 'path';
|
||||
import { InputDataService } from '../../../src/program/core/InputDataService.js';
|
||||
import { memoizeConfig } from '../../../src/program/utils/memoize.js';
|
||||
import { getCurrentDir } from '../../../src/program/utils/get-current-dir.js';
|
||||
import {
|
||||
restoreMockedProjects,
|
||||
mockProject,
|
||||
mock,
|
||||
} = require('../../../test-helpers/mock-project-helpers.js');
|
||||
} from '../../../test-helpers/mock-project-helpers.js';
|
||||
// import { setupAnalyzerTest } from '../../../test-helpers/setup-analyzer-test.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../../../src/program/types/core').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
*/
|
||||
|
||||
describe('InputDataService', () => {
|
||||
|
|
@ -52,7 +55,7 @@ describe('InputDataService', () => {
|
|||
it('"createDataObject"', async () => {
|
||||
/** @type {* & PathFromSystemRoot} */
|
||||
const projectPath = pathLib.resolve(
|
||||
__dirname,
|
||||
getCurrentDir(import.meta.url),
|
||||
'../../../test-helpers/project-mocks/importing-target-project',
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
const { expect } = require('chai');
|
||||
const { QueryService } = require('../../../src/program/core/QueryService.js');
|
||||
const { DummyAnalyzer } = require('../../../test-helpers/templates/DummyAnalyzer.js');
|
||||
const FindImportsAnalyzer = require('../../../src/program/analyzers/find-imports.js');
|
||||
import { expect } from 'chai';
|
||||
import { it } from 'mocha';
|
||||
import { QueryService } from '../../../src/program/core/QueryService.js';
|
||||
import { DummyAnalyzer } from '../../../test-helpers/templates/DummyAnalyzer.js';
|
||||
import FindImportsAnalyzer from '../../../src/program/analyzers/find-imports.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('../../../src/program/types/core').Analyzer} Analyzer
|
||||
* @typedef {import('../../../src/program/types/core').PathFromSystemRoot} PathFromSystemRoot
|
||||
* @typedef {import('../../../types/index.js').Analyzer} Analyzer
|
||||
* @typedef {import('../../../types/index.js').PathFromSystemRoot} PathFromSystemRoot
|
||||
*/
|
||||
|
||||
describe('QueryService', () => {
|
||||
|
|
@ -144,6 +145,7 @@ describe('QueryService', () => {
|
|||
|
||||
it('throws when no string provided', async () => {
|
||||
expect(() => {
|
||||
// @ts-ignore
|
||||
QueryService.getQueryConfigFromFeatureString();
|
||||
}).to.throw('[QueryService.getQueryConfigFromFeatureString]: provide a string');
|
||||
});
|
||||
|
|
@ -152,7 +154,10 @@ describe('QueryService', () => {
|
|||
describe('"getQueryConfigFromAnalyzer"', () => {
|
||||
const myAnalyzerCfg = { targetProjectPath: /** @type {PathFromSystemRoot} */ ('/my/path') };
|
||||
it('accepts a constructor as first argument', async () => {
|
||||
const result = QueryService.getQueryConfigFromAnalyzer('find-imports', myAnalyzerCfg);
|
||||
const result = await QueryService.getQueryConfigFromAnalyzer(
|
||||
'find-imports',
|
||||
myAnalyzerCfg,
|
||||
);
|
||||
expect(result).to.eql({
|
||||
type: 'ast-analyzer',
|
||||
analyzerName: 'find-imports',
|
||||
|
|
@ -162,13 +167,13 @@ describe('QueryService', () => {
|
|||
});
|
||||
|
||||
it('accepts a string as first argument', async () => {
|
||||
const result = QueryService.getQueryConfigFromAnalyzer(
|
||||
const result = await QueryService.getQueryConfigFromAnalyzer(
|
||||
/** @type {* & Analyzer} */ (DummyAnalyzer),
|
||||
myAnalyzerCfg,
|
||||
);
|
||||
expect(result).to.eql({
|
||||
type: 'ast-analyzer',
|
||||
analyzerName: 'dummy-analyzer',
|
||||
analyzerName: 'find-dummy-analyzer',
|
||||
analyzerConfig: myAnalyzerCfg,
|
||||
analyzer: DummyAnalyzer,
|
||||
});
|
||||
|
|
@ -176,22 +181,22 @@ describe('QueryService', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('QueryResults', () => {
|
||||
describe.skip('"grepSearch"', () => {
|
||||
it('with FeatureConfig', async () => {
|
||||
const featureCfg = QueryService.getQueryConfigFromFeatureString('tg-icon[size=xs]');
|
||||
const result = QueryService.grepSearch(featureCfg);
|
||||
expect(result).to.eql({
|
||||
type: 'ast-analyzer',
|
||||
analyzerName: 'find-imports',
|
||||
analyzerConfig: { x: 'y' },
|
||||
analyzer: FindImportsAnalyzer,
|
||||
});
|
||||
});
|
||||
});
|
||||
// describe('QueryResults', () => {
|
||||
// describe.skip('"grepSearch"', () => {
|
||||
// it('with FeatureConfig', async () => {
|
||||
// const featureCfg = QueryService.getQueryConfigFromFeatureString('tg-icon[size=xs]');
|
||||
// const result = QueryService.grepSearch(featureCfg);
|
||||
// expect(result).to.eql({
|
||||
// type: 'ast-analyzer',
|
||||
// analyzerName: 'find-imports',
|
||||
// analyzerConfig: { x: 'y' },
|
||||
// analyzer: FindImportsAnalyzer,
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
it('"astSearch"', async () => {});
|
||||
});
|
||||
// it('"astSearch"', async () => {});
|
||||
// });
|
||||
|
||||
describe('Ast retrieval', () => {
|
||||
it('"addAstToProjectsData"', async () => {});
|
||||
|
|
|
|||
|
|
@ -1,8 +1,18 @@
|
|||
const { expect } = require('chai');
|
||||
const { mock } = require('../../../test-helpers/mock-project-helpers.js');
|
||||
const { getSourceCodeFragmentOfDeclaration } = require('../../../src/program/utils/index.js');
|
||||
import { expect } from 'chai';
|
||||
import { it } from 'mocha';
|
||||
import { mock } from '../../../test-helpers/mock-project-helpers.js';
|
||||
import { getSourceCodeFragmentOfDeclaration } from '../../../src/program/utils/index.js';
|
||||
import { memoizeConfig } from '../../../src/program/utils/memoize.js';
|
||||
|
||||
describe('getSourceCodeFragmentOfDeclaration', () => {
|
||||
const initialMemoizeSsCacheDisabled = memoizeConfig.isCacheDisabled;
|
||||
before(() => {
|
||||
memoizeConfig.isCacheDisabled = true;
|
||||
});
|
||||
after(() => {
|
||||
memoizeConfig.isCacheDisabled = initialMemoizeSsCacheDisabled;
|
||||
});
|
||||
|
||||
describe('Named specifiers', () => {
|
||||
it('finds source code for directly declared specifiers', async () => {
|
||||
const fakeFs = {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
const { expect } = require('chai');
|
||||
const { memoize, memoizeConfig } = require('../../../src/program/utils/memoize.js');
|
||||
import { expect } from 'chai';
|
||||
import { it } from 'mocha';
|
||||
import { memoize, memoizeConfig } from '../../../src/program/utils/memoize.js';
|
||||
|
||||
const cacheDisabledInitialValue = memoizeConfig.isCacheDisabled;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
const { expect } = require('chai');
|
||||
const {
|
||||
import { expect } from 'chai';
|
||||
import { it } from 'mocha';
|
||||
import {
|
||||
mockProject,
|
||||
restoreMockedProjects,
|
||||
mockTargetAndReferenceProject,
|
||||
} = require('../../../test-helpers/mock-project-helpers.js');
|
||||
const { resolveImportPath } = require('../../../src/program/utils/resolve-import-path.js');
|
||||
const { memoizeConfig } = require('../../../src/program/utils/memoize.js');
|
||||
} from '../../../test-helpers/mock-project-helpers.js';
|
||||
import { resolveImportPath } from '../../../src/program/utils/resolve-import-path.js';
|
||||
import { memoizeConfig } from '../../../src/program/utils/memoize.js';
|
||||
|
||||
describe('resolveImportPath', () => {
|
||||
beforeEach(() => {
|
||||
|
|
|
|||
9
packages-node/providence-analytics/tsconfig.json
Normal file
9
packages-node/providence-analytics/tsconfig.json
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist-types",
|
||||
"rootDir": "."
|
||||
},
|
||||
"include": ["src", "dashboard", "types"],
|
||||
"exclude": ["dist-types"]
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ import {
|
|||
RootFile,
|
||||
AnalyzerQueryResult,
|
||||
FindAnalyzerOutputFile,
|
||||
} from '../core';
|
||||
} from '../core/index.js';
|
||||
|
||||
export interface FindClassesAnalyzerResult extends AnalyzerQueryResult {
|
||||
queryOutput: FindClassesAnalyzerOutputFile[];
|
||||
|
|
@ -4,7 +4,7 @@ import {
|
|||
RootFile,
|
||||
AnalyzerQueryResult,
|
||||
FindAnalyzerOutputFile,
|
||||
} from '../core';
|
||||
} from '../core/index.js';
|
||||
|
||||
export interface FindCustomelementsAnalyzerResult extends AnalyzerQueryResult {
|
||||
queryOutput: FindCustomelementsAnalyzerOutputFile[];
|
||||
|
|
@ -6,7 +6,7 @@ import {
|
|||
RootFile,
|
||||
AnalyzerQueryResult,
|
||||
FindAnalyzerOutputFile,
|
||||
} from '../core';
|
||||
} from '../core/index.js';
|
||||
|
||||
export interface FindExportsAnalyzerResult extends AnalyzerQueryResult {
|
||||
queryOutput: FindExportsAnalyzerOutputFile[];
|
||||
|
|
@ -4,7 +4,7 @@ import {
|
|||
PathRelativeFromProjectRoot,
|
||||
AnalyzerQueryResult,
|
||||
FindAnalyzerOutputFile,
|
||||
} from '../core';
|
||||
} from '../core/index.js';
|
||||
|
||||
export interface FindImportsAnalyzerResult extends AnalyzerQueryResult {
|
||||
queryOutput: FindImportsAnalyzerOutputFile[];
|
||||
|
|
@ -41,6 +41,8 @@ export interface FindImportsAnalyzerEntry {
|
|||
* - file `import { x } from '../';` gives `"../index.js"`
|
||||
*/
|
||||
normalizedSource: SpecifierSource;
|
||||
|
||||
assertionType: string;
|
||||
}
|
||||
|
||||
/**
|
||||
6
packages-node/providence-analytics/types/analyzers/index.d.ts
vendored
Normal file
6
packages-node/providence-analytics/types/analyzers/index.d.ts
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export * from './find-classes.js';
|
||||
export * from './find-customelements.js';
|
||||
export * from './find-exports.js';
|
||||
export * from './find-imports.js';
|
||||
export * from './match-imports.js';
|
||||
export * from './match-subclasses.js';
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
import { ImportOrExportId, PathRelativeFromProjectRoot, ProjectName } from '../core/core';
|
||||
import { AnalyzerQueryResult, MatchedExportSpecifier, MatchAnalyzerConfig } from '../core/Analyzer';
|
||||
import { ImportOrExportId, PathRelativeFromProjectRoot, ProjectName } from '../core/core.js';
|
||||
import {
|
||||
AnalyzerQueryResult,
|
||||
MatchedExportSpecifier,
|
||||
MatchAnalyzerConfig,
|
||||
} from '../core/Analyzer.js';
|
||||
|
||||
export interface MatchImportsAnalyzerResult extends AnalyzerQueryResult {
|
||||
queryOutput: MatchImportsAnalyzerOutputEntry[];
|
||||
|
|
@ -4,7 +4,7 @@ import {
|
|||
PathRelativeFromProjectRoot,
|
||||
AnalyzerQueryResult,
|
||||
MatchedExportSpecifier,
|
||||
} from '../core';
|
||||
} from '../core/index.js';
|
||||
|
||||
export interface MatchSubclassesAnalyzerResult extends AnalyzerQueryResult {
|
||||
queryOutput: MatchSubclassesAnalyzerOutputEntry[];
|
||||
|
|
@ -9,12 +9,12 @@ import {
|
|||
GatherFilesConfig,
|
||||
SpecifierName,
|
||||
QueryOutput,
|
||||
} from './index';
|
||||
} from './index.js';
|
||||
|
||||
/**
|
||||
* Name of the analyzer, like 'find-imports' or 'match-sublcasses'
|
||||
*/
|
||||
export type AnalyzerName = `${'find' | 'match'}-${string}`;
|
||||
export type AnalyzerName = `${'find' | 'match'}-${string}` | '';
|
||||
|
||||
// TODO: make sure that data structures of JSON output (generated in ReportService)
|
||||
// and data structure generated in Analyzer.prototype._finalize match exactly (move logic from ReportSerivce to _finalize)
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { AnalyzerName, Feature, AnalyzerConfig, PathRelativeFromProjectRoot } from './index';
|
||||
import { Analyzer } from '../../core/Analyzer';
|
||||
export { Analyzer } from '../../core/Analyzer';
|
||||
import { AnalyzerName, Feature, AnalyzerConfig, PathRelativeFromProjectRoot } from './index.js';
|
||||
import { Analyzer } from '../../src/program/core/Analyzer.js';
|
||||
export { Analyzer } from '../../src/program/core/Analyzer.js';
|
||||
|
||||
/**
|
||||
* Type of the query. Currently only "ast-analyzer" supported
|
||||
|
|
@ -173,6 +173,7 @@ export type ProvidenceConfig = {
|
|||
measurePerformance: boolean;
|
||||
writeLogFile: boolean;
|
||||
skipCheckMatchCompatibility: boolean;
|
||||
fallbackToBabel: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
3
packages-node/providence-analytics/types/core/index.d.ts
vendored
Normal file
3
packages-node/providence-analytics/types/core/index.d.ts
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export * from './core.js';
|
||||
export * from './Analyzer.js';
|
||||
export * from './QueryService.js';
|
||||
3
packages-node/providence-analytics/types/index.ts
Normal file
3
packages-node/providence-analytics/types/index.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export * from './core/index.js';
|
||||
export * from './analyzers/index.js';
|
||||
export * from './misc.js';
|
||||
37
packages-node/providence-analytics/types/misc.d.ts
vendored
Normal file
37
packages-node/providence-analytics/types/misc.d.ts
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
export type PkgName = `@${string}/${string}` | string;
|
||||
export type PkgVersion = `${number}.${number}.${number}`;
|
||||
export type TargetDep = `${PkgName}#${PkgVersion}`;
|
||||
export type TargetDepsObj = {
|
||||
[key: TargetDep]: TargetDep[];
|
||||
};
|
||||
export type TargetOrRefCollectionsObj = {
|
||||
[key: PkgName]: PkgName[];
|
||||
};
|
||||
export type ProvidenceCliConf = {
|
||||
metaConfig: {
|
||||
categoryConfig: {
|
||||
/* This is the name found in package.json */
|
||||
project: string;
|
||||
majorVersion: number;
|
||||
/* These conditions will be run on overy filePath */
|
||||
categories: {
|
||||
[category: string]: (localFilePath: string) => string[];
|
||||
};
|
||||
}[];
|
||||
};
|
||||
/*
|
||||
* By predefening groups, we can do a query for programs/collections...
|
||||
* Select via " providence analyze --search-target-collection 'exampleCollection' "
|
||||
*/
|
||||
searchTargetCollections: {
|
||||
[targetCollection: string]: string[];
|
||||
};
|
||||
referenceCollections: {
|
||||
/**
|
||||
* Usually the references are different from the targets.
|
||||
* In this demo file, we test @lion usage amongst itself
|
||||
* Select via " providence analyze --reference-collection 'exampleCollection' "
|
||||
*/
|
||||
[referenceCollection: string]: string[];
|
||||
};
|
||||
};
|
||||
53
patches/swc-to-babel+1.26.0.patch
Normal file
53
patches/swc-to-babel+1.26.0.patch
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
diff --git a/node_modules/swc-to-babel/lib/swc/index.js b/node_modules/swc-to-babel/lib/swc/index.js
|
||||
index ab285b3..a58a61d 100644
|
||||
--- a/node_modules/swc-to-babel/lib/swc/index.js
|
||||
+++ b/node_modules/swc-to-babel/lib/swc/index.js
|
||||
@@ -143,6 +143,15 @@ module.exports.ClassMethod = (path) => {
|
||||
key,
|
||||
});
|
||||
|
||||
+ if (node.kind === 'getter') {
|
||||
+ node.kind = 'get';
|
||||
+ }
|
||||
+ if (node.kind === 'setter') {
|
||||
+ node.kind = 'set';
|
||||
+ }
|
||||
+
|
||||
+ node.static = node.isStatic;
|
||||
+
|
||||
delete path.node.isStatic;
|
||||
delete path.node.accessibility;
|
||||
delete path.node.isAbstract;
|
||||
@@ -301,7 +310,7 @@ module.exports.TSIndexedAccessType = (path) => {
|
||||
module.exports.ImportDeclaration = ({node}) => {
|
||||
const {typeOnly} = node;
|
||||
|
||||
- node.assertions = node.asserts || [];
|
||||
+ node.assertions = node.asserts?.properties || [];
|
||||
node.importKind = typeOnly ? 'type' : 'value';
|
||||
|
||||
delete node.asserts;
|
||||
@@ -340,9 +349,10 @@ module.exports.convertGetterSetter = ({node}) => {
|
||||
};
|
||||
|
||||
module.exports.ExportDefaultDeclaration = ({node}) => {
|
||||
- node.declaration = node.decl;
|
||||
+ // node.declaration may have been already provided by convertExportDefaultExpression
|
||||
+ node.declaration = node.declaration || node.decl;
|
||||
node.exportKind = 'value';
|
||||
- node.assertions = [];
|
||||
+ node.assertions = node.asserts?.properties || [];
|
||||
|
||||
delete node.decl;
|
||||
};
|
||||
@@ -350,8 +360,8 @@ module.exports.ExportDefaultDeclaration = ({node}) => {
|
||||
module.exports.ExportNamedDeclaration = ({node}) => {
|
||||
const {typeOnly} = node;
|
||||
|
||||
- node.assertions = [];
|
||||
- node.source = null;
|
||||
+ node.assertions = node.asserts?.properties || [];
|
||||
+ // node.source = null;
|
||||
node.specifiers = node.specifiers || [];
|
||||
|
||||
node.exportKind = typeOnly ? 'type' : 'value';
|
||||
Loading…
Reference in a new issue