-
Notifications
You must be signed in to change notification settings - Fork 741
Resolve analyzer API, offline support, Pascal support, and licensing #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| vendor/** linguist-vendored whitespace=-trailing-space,-space-before-tab | ||
| vendor/**/*.wasm binary | ||
| vendor/**/*.woff2 binary |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| name: CodeFlow CodeQL configuration | ||
|
|
||
| paths-ignore: | ||
| - vendor/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| name: Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
|
|
||
| - name: Run test suite | ||
| run: node --test tests/*.test.mjs tests/*.smoke.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2026 Braedon Saunders | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| 'use strict'; | ||
|
|
||
| const path = require('path'); | ||
|
|
||
| const { analyze } = require('./lib/analysis.js'); | ||
|
|
||
| function usage() { | ||
| return [ | ||
| 'Usage: node card/analyze.js [--path <directory>] [--exclude <glob> ...]', | ||
| '', | ||
| 'Writes a versioned CodeFlow analysis envelope to stdout as JSON.', | ||
| 'Repeat --exclude to omit multiple files or directory patterns.', | ||
| ].join('\n'); | ||
| } | ||
|
|
||
| function readValue(argv, index, flag) { | ||
| if (index + 1 >= argv.length) throw new Error(flag + ' requires a value'); | ||
| return argv[index + 1]; | ||
| } | ||
|
|
||
| function parseArgs(argv) { | ||
| const parsed = { repoRoot: process.cwd(), exclude: [], help: false }; | ||
| for (let index = 0; index < argv.length; index++) { | ||
| const arg = argv[index]; | ||
| if (arg === '--help' || arg === '-h') { | ||
| parsed.help = true; | ||
| } else if (arg === '--path') { | ||
| parsed.repoRoot = readValue(argv, index, '--path'); | ||
| index++; | ||
| } else if (arg.startsWith('--path=')) { | ||
| parsed.repoRoot = arg.slice('--path='.length); | ||
| } else if (arg === '--exclude') { | ||
| parsed.exclude.push(readValue(argv, index, '--exclude')); | ||
| index++; | ||
| } else if (arg.startsWith('--exclude=')) { | ||
| parsed.exclude.push(arg.slice('--exclude='.length)); | ||
| } else { | ||
| throw new Error('Unknown argument: ' + arg); | ||
| } | ||
| } | ||
| parsed.repoRoot = path.resolve(parsed.repoRoot); | ||
| return parsed; | ||
| } | ||
|
|
||
| async function main(argv) { | ||
| const parsed = parseArgs(argv || process.argv.slice(2)); | ||
| if (parsed.help) { | ||
| process.stdout.write(usage() + '\n'); | ||
| return; | ||
| } | ||
| const result = await analyze({ repoRoot: parsed.repoRoot, exclude: parsed.exclude }); | ||
| process.stdout.write(JSON.stringify(result, null, 2) + '\n'); | ||
| } | ||
|
|
||
| if (require.main === module) { | ||
| main().catch((error) => { | ||
| process.stderr.write('[codeflow-analyze] error: ' + (error.stack || error.message || error) + '\n'); | ||
| process.exitCode = 1; | ||
| }); | ||
| } | ||
|
|
||
| module.exports = { analyze, main, parseArgs, usage }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Shared side-effect-free analysis pipeline used by the Action and headless CLI. | ||
|
|
||
| 'use strict'; | ||
|
|
||
| const path = require('path'); | ||
|
|
||
| const { loadAnalyzer, locateIndexHtml } = require('./analyzer.js'); | ||
| const { buildAnalyzed } = require('./collect.js'); | ||
| const { compileExcludePatterns } = require('./exclude.js'); | ||
| const { snapshotFromAnalysis } = require('./state.js'); | ||
|
|
||
| const HEADLESS_SCHEMA_VERSION = 1; | ||
|
|
||
| function normalizeExcludeInput(exclude) { | ||
| if (Array.isArray(exclude)) return exclude.join(','); | ||
| return exclude == null ? '' : String(exclude); | ||
| } | ||
|
|
||
| async function analyze(options) { | ||
| const opts = options || {}; | ||
| const repoRoot = path.resolve(opts.repoRoot || process.cwd()); | ||
| const actionDir = path.resolve(opts.actionDir || path.join(__dirname, '..')); | ||
| const progress = typeof opts.progress === 'function' ? opts.progress : () => {}; | ||
| const indexHtmlPath = opts.indexHtmlPath || locateIndexHtml(actionDir, repoRoot); | ||
|
|
||
| progress('analyzer source: ' + indexHtmlPath); | ||
| const { Parser, buildAnalysisData, calcBlast, calcHealth } = loadAnalyzer(indexHtmlPath); | ||
| const excludePatterns = compileExcludePatterns(normalizeExcludeInput(opts.exclude)); | ||
| if (excludePatterns.length > 0) { | ||
| progress('exclude patterns: ' + excludePatterns.map((pattern) => pattern.raw).join(', ')); | ||
| } | ||
|
|
||
| const { analyzed, allFns } = await buildAnalyzed(repoRoot, Parser, excludePatterns); | ||
| progress('collected ' + analyzed.length + ' files (' + allFns.length + ' functions)'); | ||
|
|
||
| const data = await buildAnalysisData({ | ||
| analyzed, | ||
| allFns, | ||
| excludePatterns: excludePatterns.map((pattern) => pattern.raw), | ||
| progress: (message) => progress(message), | ||
| yieldFn: async () => {}, | ||
| }); | ||
| progress( | ||
| 'analysis: files=' + data.stats.files + | ||
| ' fns=' + data.stats.functions + | ||
| ' loc=' + data.stats.loc | ||
| ); | ||
|
|
||
| const snapshot = snapshotFromAnalysis( | ||
| data, | ||
| { calcBlast, calcHealth }, | ||
| opts.context || {} | ||
| ); | ||
| progress( | ||
| 'grade=' + (snapshot.grade || '?') + | ||
| ' score=' + (snapshot.score == null ? '?' : snapshot.score) | ||
| ); | ||
|
|
||
| return { schemaVersion: HEADLESS_SCHEMA_VERSION, data, snapshot }; | ||
| } | ||
|
|
||
| module.exports = { analyze, HEADLESS_SCHEMA_VERSION, normalizeExcludeInput }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.