@cbnventures/nova 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/bin/nova.mjs +3 -3
- package/build/package.json +14 -10
- package/build/src/cli/generate/github/funding.js +2 -2
- package/build/src/cli/generate/github/funding.js.map +1 -1
- package/build/src/cli/generate/github/issue-template.d.ts.map +1 -1
- package/build/src/cli/generate/github/issue-template.js +6 -95
- package/build/src/cli/generate/github/issue-template.js.map +1 -1
- package/build/src/cli/generate/github/workflows-blueprint-validate.d.ts +12 -0
- package/build/src/cli/generate/github/workflows-blueprint-validate.d.ts.map +1 -0
- package/build/src/cli/generate/github/workflows-blueprint-validate.js +535 -0
- package/build/src/cli/generate/github/workflows-blueprint-validate.js.map +1 -0
- package/build/src/cli/generate/github/workflows-blueprint-variables.d.ts +9 -0
- package/build/src/cli/generate/github/workflows-blueprint-variables.d.ts.map +1 -0
- package/build/src/cli/generate/github/workflows-blueprint-variables.js +117 -0
- package/build/src/cli/generate/github/workflows-blueprint-variables.js.map +1 -0
- package/build/src/cli/generate/github/workflows-blueprint.d.ts +60 -0
- package/build/src/cli/generate/github/workflows-blueprint.d.ts.map +1 -0
- package/build/src/cli/generate/github/workflows-blueprint.js +2251 -0
- package/build/src/cli/generate/github/workflows-blueprint.js.map +1 -0
- package/build/src/cli/generate/must-haves/agent-conventions.d.ts.map +1 -1
- package/build/src/cli/generate/must-haves/agent-conventions.js +14 -5
- package/build/src/cli/generate/must-haves/agent-conventions.js.map +1 -1
- package/build/src/cli/generate/must-haves/dotenv.d.ts +5 -7
- package/build/src/cli/generate/must-haves/dotenv.d.ts.map +1 -1
- package/build/src/cli/generate/must-haves/dotenv.js +146 -417
- package/build/src/cli/generate/must-haves/dotenv.js.map +1 -1
- package/build/src/cli/generate/must-haves/editorconfig.js +2 -2
- package/build/src/cli/generate/must-haves/editorconfig.js.map +1 -1
- package/build/src/cli/generate/must-haves/gitignore.d.ts +0 -8
- package/build/src/cli/generate/must-haves/gitignore.d.ts.map +1 -1
- package/build/src/cli/generate/must-haves/gitignore.js +9 -397
- package/build/src/cli/generate/must-haves/gitignore.js.map +1 -1
- package/build/src/cli/generate/must-haves/license.d.ts.map +1 -1
- package/build/src/cli/generate/must-haves/license.js +4 -4
- package/build/src/cli/generate/must-haves/license.js.map +1 -1
- package/build/src/cli/generate/must-haves/read-me.d.ts +6 -2
- package/build/src/cli/generate/must-haves/read-me.d.ts.map +1 -1
- package/build/src/cli/generate/must-haves/read-me.js +103 -63
- package/build/src/cli/generate/must-haves/read-me.js.map +1 -1
- package/build/src/cli/index.js +108 -2
- package/build/src/cli/index.js.map +1 -1
- package/build/src/cli/recipe/github/sync-features.d.ts.map +1 -1
- package/build/src/cli/recipe/github/sync-features.js +5 -3
- package/build/src/cli/recipe/github/sync-features.js.map +1 -1
- package/build/src/cli/recipe/github/sync-identity.d.ts.map +1 -1
- package/build/src/cli/recipe/github/sync-identity.js +6 -4
- package/build/src/cli/recipe/github/sync-identity.js.map +1 -1
- package/build/src/cli/recipe/github/sync-policies.d.ts.map +1 -1
- package/build/src/cli/recipe/github/sync-policies.js +13 -4
- package/build/src/cli/recipe/github/sync-policies.js.map +1 -1
- package/build/src/cli/recipe/index.d.ts.map +1 -1
- package/build/src/cli/recipe/index.js +32 -0
- package/build/src/cli/recipe/index.js.map +1 -1
- package/build/src/cli/recipe/license/update-copyright.d.ts +7 -0
- package/build/src/cli/recipe/license/update-copyright.d.ts.map +1 -0
- package/build/src/cli/recipe/license/update-copyright.js +191 -0
- package/build/src/cli/recipe/license/update-copyright.js.map +1 -0
- package/build/src/cli/recipe/package-json/cleanup.d.ts.map +1 -1
- package/build/src/cli/recipe/package-json/cleanup.js +14 -13
- package/build/src/cli/recipe/package-json/cleanup.js.map +1 -1
- package/build/src/cli/recipe/package-json/normalize-artifacts.d.ts.map +1 -1
- package/build/src/cli/recipe/package-json/normalize-artifacts.js +11 -6
- package/build/src/cli/recipe/package-json/normalize-artifacts.js.map +1 -1
- package/build/src/cli/recipe/package-json/normalize-bundler.d.ts.map +1 -1
- package/build/src/cli/recipe/package-json/normalize-bundler.js +11 -6
- package/build/src/cli/recipe/package-json/normalize-bundler.js.map +1 -1
- package/build/src/cli/recipe/package-json/normalize-dependencies.d.ts.map +1 -1
- package/build/src/cli/recipe/package-json/normalize-dependencies.js +18 -10
- package/build/src/cli/recipe/package-json/normalize-dependencies.js.map +1 -1
- package/build/src/cli/recipe/package-json/normalize-modules.d.ts.map +1 -1
- package/build/src/cli/recipe/package-json/normalize-modules.js +11 -6
- package/build/src/cli/recipe/package-json/normalize-modules.js.map +1 -1
- package/build/src/cli/recipe/package-json/normalize-tooling.d.ts.map +1 -1
- package/build/src/cli/recipe/package-json/normalize-tooling.js +12 -7
- package/build/src/cli/recipe/package-json/normalize-tooling.js.map +1 -1
- package/build/src/cli/recipe/package-json/sync-environment.d.ts.map +1 -1
- package/build/src/cli/recipe/package-json/sync-environment.js +46 -14
- package/build/src/cli/recipe/package-json/sync-environment.js.map +1 -1
- package/build/src/cli/recipe/package-json/sync-identity.d.ts.map +1 -1
- package/build/src/cli/recipe/package-json/sync-identity.js +29 -16
- package/build/src/cli/recipe/package-json/sync-identity.js.map +1 -1
- package/build/src/cli/recipe/package-json/sync-ownership.d.ts.map +1 -1
- package/build/src/cli/recipe/package-json/sync-ownership.js +18 -11
- package/build/src/cli/recipe/package-json/sync-ownership.js.map +1 -1
- package/build/src/cli/recipe/read-me/update-badges.d.ts +6 -0
- package/build/src/cli/recipe/read-me/update-badges.d.ts.map +1 -0
- package/build/src/cli/recipe/read-me/update-badges.js +115 -0
- package/build/src/cli/recipe/read-me/update-badges.js.map +1 -0
- package/build/src/cli/recipe/read-me/update-credits.d.ts +6 -0
- package/build/src/cli/recipe/read-me/update-credits.d.ts.map +1 -0
- package/build/src/cli/recipe/read-me/update-credits.js +115 -0
- package/build/src/cli/recipe/read-me/update-credits.js.map +1 -0
- package/build/src/cli/recipe/read-me/update-documentation.d.ts +6 -0
- package/build/src/cli/recipe/read-me/update-documentation.d.ts.map +1 -0
- package/build/src/cli/recipe/read-me/update-documentation.js +115 -0
- package/build/src/cli/recipe/read-me/update-documentation.js.map +1 -0
- package/build/src/cli/recipe/read-me/update-header.d.ts +6 -0
- package/build/src/cli/recipe/read-me/update-header.d.ts.map +1 -0
- package/build/src/cli/recipe/read-me/update-header.js +115 -0
- package/build/src/cli/recipe/read-me/update-header.js.map +1 -0
- package/build/src/cli/recipe/read-me/update-introduction.d.ts +6 -0
- package/build/src/cli/recipe/read-me/update-introduction.d.ts.map +1 -0
- package/build/src/cli/recipe/read-me/update-introduction.js +115 -0
- package/build/src/cli/recipe/read-me/update-introduction.js.map +1 -0
- package/build/src/cli/scaffold/starter/base.js +1 -1
- package/build/src/cli/scaffold/starter/base.js.map +1 -1
- package/build/src/cli/utility/changelog.d.ts +2 -0
- package/build/src/cli/utility/changelog.d.ts.map +1 -1
- package/build/src/cli/utility/changelog.js +159 -3
- package/build/src/cli/utility/changelog.js.map +1 -1
- package/build/src/cli/utility/initialize.d.ts +9 -0
- package/build/src/cli/utility/initialize.d.ts.map +1 -1
- package/build/src/cli/utility/initialize.js +978 -111
- package/build/src/cli/utility/initialize.js.map +1 -1
- package/build/src/cli/utility/run-scripts.d.ts.map +1 -1
- package/build/src/cli/utility/run-scripts.js +4 -4
- package/build/src/cli/utility/run-scripts.js.map +1 -1
- package/build/src/cli/utility/transpile.js +1 -1
- package/build/src/cli/utility/transpile.js.map +1 -1
- package/build/src/cli/utility/type-check.js +1 -1
- package/build/src/cli/utility/type-check.js.map +1 -1
- package/build/src/cli/utility/version.js +1 -1
- package/build/src/cli/utility/version.js.map +1 -1
- package/build/src/lib/dotenv.d.ts +3 -0
- package/build/src/lib/dotenv.d.ts.map +1 -0
- package/build/src/lib/dotenv.js +66 -0
- package/build/src/lib/dotenv.js.map +1 -0
- package/build/src/lib/env-github.d.ts +4 -0
- package/build/src/lib/env-github.d.ts.map +1 -0
- package/build/src/lib/env-github.js +57 -0
- package/build/src/lib/env-github.js.map +1 -0
- package/build/src/lib/env-managed-set.d.ts +3 -0
- package/build/src/lib/env-managed-set.d.ts.map +1 -0
- package/build/src/lib/env-managed-set.js +102 -0
- package/build/src/lib/env-managed-set.js.map +1 -0
- package/build/src/lib/env-namespace.d.ts +3 -0
- package/build/src/lib/env-namespace.d.ts.map +1 -0
- package/build/src/lib/env-namespace.js +11 -0
- package/build/src/lib/env-namespace.js.map +1 -0
- package/build/src/lib/env-reconcile.d.ts +3 -0
- package/build/src/lib/env-reconcile.d.ts.map +1 -0
- package/build/src/lib/env-reconcile.js +109 -0
- package/build/src/lib/env-reconcile.js.map +1 -0
- package/build/src/lib/env-status.d.ts +3 -0
- package/build/src/lib/env-status.d.ts.map +1 -0
- package/build/src/lib/env-status.js +113 -0
- package/build/src/lib/env-status.js.map +1 -0
- package/build/src/lib/file-discovery.d.ts +3 -0
- package/build/src/lib/file-discovery.d.ts.map +1 -0
- package/build/src/lib/file-discovery.js +32 -0
- package/build/src/lib/file-discovery.js.map +1 -0
- package/build/src/lib/item.d.ts +4 -1
- package/build/src/lib/item.d.ts.map +1 -1
- package/build/src/lib/item.js +35 -0
- package/build/src/lib/item.js.map +1 -1
- package/build/src/lib/markdown-slug.d.ts +4 -0
- package/build/src/lib/markdown-slug.d.ts.map +1 -0
- package/build/src/lib/markdown-slug.js +25 -0
- package/build/src/lib/markdown-slug.js.map +1 -0
- package/build/src/lib/nova-config.d.ts +14 -2
- package/build/src/lib/nova-config.d.ts.map +1 -1
- package/build/src/lib/nova-config.js +507 -78
- package/build/src/lib/nova-config.js.map +1 -1
- package/build/src/lib/read-me-regions.d.ts +4 -0
- package/build/src/lib/read-me-regions.d.ts.map +1 -0
- package/build/src/lib/read-me-regions.js +33 -0
- package/build/src/lib/read-me-regions.js.map +1 -0
- package/build/src/lib/regex.d.ts +73 -0
- package/build/src/lib/regex.d.ts.map +1 -1
- package/build/src/lib/regex.js +75 -2
- package/build/src/lib/regex.js.map +1 -1
- package/build/src/lib/scaffold.d.ts.map +1 -1
- package/build/src/lib/scaffold.js +33 -14
- package/build/src/lib/scaffold.js.map +1 -1
- package/build/src/lib/type-declaration-engine.d.ts +32 -0
- package/build/src/lib/type-declaration-engine.d.ts.map +1 -0
- package/build/src/lib/type-declaration-engine.js +796 -0
- package/build/src/lib/type-declaration-engine.js.map +1 -0
- package/build/src/lib/utility.d.ts +2 -1
- package/build/src/lib/utility.d.ts.map +1 -1
- package/build/src/lib/utility.js +47 -15
- package/build/src/lib/utility.js.map +1 -1
- package/build/src/lib/workflow-templates.d.ts.map +1 -1
- package/build/src/lib/workflow-templates.js +86 -60
- package/build/src/lib/workflow-templates.js.map +1 -1
- package/build/src/presets/eslint/dx-code-style.d.ts.map +1 -1
- package/build/src/presets/eslint/dx-code-style.js +6 -0
- package/build/src/presets/eslint/dx-code-style.js.map +1 -1
- package/build/src/presets/eslint/fw-astro.d.ts +4 -0
- package/build/src/presets/eslint/fw-astro.d.ts.map +1 -0
- package/build/src/presets/eslint/fw-astro.js +13 -0
- package/build/src/presets/eslint/fw-astro.js.map +1 -0
- package/build/src/presets/eslint/index.d.ts +1 -0
- package/build/src/presets/eslint/index.d.ts.map +1 -1
- package/build/src/presets/eslint/index.js +1 -0
- package/build/src/presets/eslint/index.js.map +1 -1
- package/build/src/presets/tsconfig/fw-astro.json +15 -0
- package/build/src/rules/eslint/conventions/no-implicit-boolean.d.ts.map +1 -1
- package/build/src/rules/eslint/conventions/no-implicit-boolean.js +3 -2
- package/build/src/rules/eslint/conventions/no-implicit-boolean.js.map +1 -1
- package/build/src/rules/eslint/conventions/require-hash-private.js +1 -1
- package/build/src/rules/eslint/conventions/require-hash-private.js.map +1 -1
- package/build/src/rules/eslint/conventions/require-kebab-case-filename.d.ts.map +1 -1
- package/build/src/rules/eslint/conventions/require-kebab-case-filename.js +4 -1
- package/build/src/rules/eslint/conventions/require-kebab-case-filename.js.map +1 -1
- package/build/src/rules/eslint/conventions/require-node-protocol.d.ts +11 -0
- package/build/src/rules/eslint/conventions/require-node-protocol.d.ts.map +1 -0
- package/build/src/rules/eslint/conventions/require-node-protocol.js +76 -0
- package/build/src/rules/eslint/conventions/require-node-protocol.js.map +1 -0
- package/build/src/rules/eslint/formatting/no-raw-text-in-code.d.ts.map +1 -1
- package/build/src/rules/eslint/formatting/no-raw-text-in-code.js +2 -1
- package/build/src/rules/eslint/formatting/no-raw-text-in-code.js.map +1 -1
- package/build/src/rules/eslint/formatting/require-padding-lines.d.ts.map +1 -1
- package/build/src/rules/eslint/formatting/require-padding-lines.js +7 -3
- package/build/src/rules/eslint/formatting/require-padding-lines.js.map +1 -1
- package/build/src/rules/eslint/formatting/require-ternary-parens.d.ts.map +1 -1
- package/build/src/rules/eslint/formatting/require-ternary-parens.js +7 -17
- package/build/src/rules/eslint/formatting/require-ternary-parens.js.map +1 -1
- package/build/src/rules/eslint/index.d.ts +4 -0
- package/build/src/rules/eslint/index.d.ts.map +1 -1
- package/build/src/rules/eslint/index.js +4 -0
- package/build/src/rules/eslint/index.js.map +1 -1
- package/build/src/rules/eslint/jsdoc/require-jsdoc-body.d.ts +3 -2
- package/build/src/rules/eslint/jsdoc/require-jsdoc-body.d.ts.map +1 -1
- package/build/src/rules/eslint/jsdoc/require-jsdoc-body.js +22 -0
- package/build/src/rules/eslint/jsdoc/require-jsdoc-body.js.map +1 -1
- package/build/src/rules/eslint/jsdoc/require-jsdoc-hierarchy.d.ts +2 -1
- package/build/src/rules/eslint/jsdoc/require-jsdoc-hierarchy.d.ts.map +1 -1
- package/build/src/rules/eslint/jsdoc/require-jsdoc-hierarchy.js +19 -4
- package/build/src/rules/eslint/jsdoc/require-jsdoc-hierarchy.js.map +1 -1
- package/build/src/rules/eslint/jsdoc/require-jsdoc-param-alignment.d.ts.map +1 -1
- package/build/src/rules/eslint/jsdoc/require-jsdoc-param-alignment.js +3 -2
- package/build/src/rules/eslint/jsdoc/require-jsdoc-param-alignment.js.map +1 -1
- package/build/src/rules/eslint/jsdoc/require-jsdoc-param-name.d.ts.map +1 -1
- package/build/src/rules/eslint/jsdoc/require-jsdoc-param-name.js +10 -6
- package/build/src/rules/eslint/jsdoc/require-jsdoc-param-name.js.map +1 -1
- package/build/src/rules/eslint/jsdoc/require-jsdoc-presence.d.ts +12 -0
- package/build/src/rules/eslint/jsdoc/require-jsdoc-presence.d.ts.map +1 -0
- package/build/src/rules/eslint/jsdoc/require-jsdoc-presence.js +169 -0
- package/build/src/rules/eslint/jsdoc/require-jsdoc-presence.js.map +1 -0
- package/build/src/rules/eslint/jsdoc/require-jsdoc-returns.d.ts +11 -0
- package/build/src/rules/eslint/jsdoc/require-jsdoc-returns.d.ts.map +1 -0
- package/build/src/rules/eslint/jsdoc/require-jsdoc-returns.js +80 -0
- package/build/src/rules/eslint/jsdoc/require-jsdoc-returns.js.map +1 -0
- package/build/src/rules/eslint/jsdoc/require-jsdoc-since.d.ts +1 -1
- package/build/src/rules/eslint/jsdoc/require-jsdoc-since.d.ts.map +1 -1
- package/build/src/rules/eslint/jsdoc/require-jsdoc-since.js +102 -6
- package/build/src/rules/eslint/jsdoc/require-jsdoc-since.js.map +1 -1
- package/build/src/rules/eslint/jsdoc/require-jsdoc-tag-order.d.ts +15 -0
- package/build/src/rules/eslint/jsdoc/require-jsdoc-tag-order.d.ts.map +1 -0
- package/build/src/rules/eslint/jsdoc/require-jsdoc-tag-order.js +290 -0
- package/build/src/rules/eslint/jsdoc/require-jsdoc-tag-order.js.map +1 -0
- package/build/src/rules/eslint/patterns/no-await-in-loop.js +1 -1
- package/build/src/rules/eslint/patterns/no-await-in-loop.js.map +1 -1
- package/build/src/rules/eslint/patterns/no-bracket-method-call.d.ts.map +1 -1
- package/build/src/rules/eslint/patterns/no-bracket-method-call.js +4 -0
- package/build/src/rules/eslint/patterns/no-bracket-method-call.js.map +1 -1
- package/build/src/rules/eslint/regex/no-regex-literals.d.ts +1 -0
- package/build/src/rules/eslint/regex/no-regex-literals.d.ts.map +1 -1
- package/build/src/rules/eslint/regex/no-regex-literals.js +39 -1
- package/build/src/rules/eslint/regex/no-regex-literals.js.map +1 -1
- package/build/src/rules/eslint/typescript/no-inline-type-annotation.d.ts.map +1 -1
- package/build/src/rules/eslint/typescript/no-inline-type-annotation.js +4 -1
- package/build/src/rules/eslint/typescript/no-inline-type-annotation.js.map +1 -1
- package/build/src/rules/eslint/typescript/require-bracket-property-access.d.ts.map +1 -1
- package/build/src/rules/eslint/typescript/require-bracket-property-access.js +8 -1
- package/build/src/rules/eslint/typescript/require-bracket-property-access.js.map +1 -1
- package/build/src/rules/eslint/typescript/require-type-naming.js +2 -2
- package/build/src/rules/eslint/typescript/require-type-naming.js.map +1 -1
- package/build/src/rules/vitest/active-vitest.d.ts +5 -0
- package/build/src/rules/vitest/active-vitest.d.ts.map +1 -0
- package/build/src/rules/vitest/active-vitest.js +19 -0
- package/build/src/rules/vitest/active-vitest.js.map +1 -0
- package/build/src/rules/vitest/dotenv/register.d.ts +3 -0
- package/build/src/rules/vitest/dotenv/register.d.ts.map +1 -0
- package/build/src/rules/vitest/dotenv/register.js +22 -0
- package/build/src/rules/vitest/dotenv/register.js.map +1 -0
- package/build/src/rules/vitest/dotenv/rules.d.ts +3 -0
- package/build/src/rules/vitest/dotenv/rules.d.ts.map +1 -0
- package/build/src/rules/vitest/dotenv/rules.js +32 -0
- package/build/src/rules/vitest/dotenv/rules.js.map +1 -0
- package/build/src/rules/vitest/enable.d.ts +3 -0
- package/build/src/rules/vitest/enable.d.ts.map +1 -0
- package/build/src/rules/vitest/enable.js +7 -0
- package/build/src/rules/vitest/enable.js.map +1 -0
- package/build/src/rules/vitest/frontmatter/register.d.ts +3 -0
- package/build/src/rules/vitest/frontmatter/register.d.ts.map +1 -0
- package/build/src/rules/vitest/frontmatter/register.js +52 -0
- package/build/src/rules/vitest/frontmatter/register.js.map +1 -0
- package/build/src/rules/vitest/frontmatter/rules.d.ts +15 -0
- package/build/src/rules/vitest/frontmatter/rules.d.ts.map +1 -0
- package/build/src/rules/vitest/frontmatter/rules.js +498 -0
- package/build/src/rules/vitest/frontmatter/rules.js.map +1 -0
- package/build/src/rules/vitest/index.d.ts +8 -0
- package/build/src/rules/vitest/index.d.ts.map +1 -0
- package/build/src/rules/vitest/index.js +7 -0
- package/build/src/rules/vitest/index.js.map +1 -0
- package/build/src/rules/vitest/link/register.d.ts +3 -0
- package/build/src/rules/vitest/link/register.d.ts.map +1 -0
- package/build/src/rules/vitest/link/register.js +44 -0
- package/build/src/rules/vitest/link/register.js.map +1 -0
- package/build/src/rules/vitest/link/rules.d.ts +12 -0
- package/build/src/rules/vitest/link/rules.d.ts.map +1 -0
- package/build/src/rules/vitest/link/rules.js +313 -0
- package/build/src/rules/vitest/link/rules.js.map +1 -0
- package/build/src/rules/vitest/markdown-table/register.d.ts +3 -0
- package/build/src/rules/vitest/markdown-table/register.d.ts.map +1 -0
- package/build/src/rules/vitest/markdown-table/register.js +26 -0
- package/build/src/rules/vitest/markdown-table/register.js.map +1 -0
- package/build/src/rules/vitest/markdown-table/rules.d.ts +3 -0
- package/build/src/rules/vitest/markdown-table/rules.d.ts.map +1 -0
- package/build/src/rules/vitest/markdown-table/rules.js +99 -0
- package/build/src/rules/vitest/markdown-table/rules.js.map +1 -0
- package/build/src/rules/vitest/terminology/register.d.ts +3 -0
- package/build/src/rules/vitest/terminology/register.d.ts.map +1 -0
- package/build/src/rules/vitest/terminology/register.js +39 -0
- package/build/src/rules/vitest/terminology/register.js.map +1 -0
- package/build/src/rules/vitest/terminology/rules.d.ts +10 -0
- package/build/src/rules/vitest/terminology/rules.d.ts.map +1 -0
- package/build/src/rules/vitest/terminology/rules.js +202 -0
- package/build/src/rules/vitest/terminology/rules.js.map +1 -0
- package/build/src/rules/vitest/type-declarations/register.d.ts +3 -0
- package/build/src/rules/vitest/type-declarations/register.d.ts.map +1 -0
- package/build/src/rules/vitest/type-declarations/register.js +33 -0
- package/build/src/rules/vitest/type-declarations/register.js.map +1 -0
- package/build/src/rules/vitest/type-declarations/rules.d.ts +13 -0
- package/build/src/rules/vitest/type-declarations/rules.d.ts.map +1 -0
- package/build/src/rules/vitest/type-declarations/rules.js +736 -0
- package/build/src/rules/vitest/type-declarations/rules.js.map +1 -0
- package/build/src/toolkit/index.d.ts +1 -0
- package/build/src/toolkit/index.d.ts.map +1 -1
- package/build/src/toolkit/index.js +1 -0
- package/build/src/toolkit/index.js.map +1 -1
- package/build/src/toolkit/logger.d.ts.map +1 -1
- package/build/src/toolkit/logger.js +3 -1
- package/build/src/toolkit/logger.js.map +1 -1
- package/build/src/toolkit/markdown-table.js +1 -1
- package/build/src/toolkit/markdown-table.js.map +1 -1
- package/build/src/toolkit/nova-identity.d.ts +19 -0
- package/build/src/toolkit/nova-identity.d.ts.map +1 -0
- package/build/src/toolkit/nova-identity.js +141 -0
- package/build/src/toolkit/nova-identity.js.map +1 -0
- package/build/src/types/cli/generate/github/funding.d.ts +4 -4
- package/build/src/types/cli/generate/github/issue-template.d.ts +15 -35
- package/build/src/types/cli/generate/github/workflows-blueprint-validate.d.ts +351 -0
- package/build/src/types/cli/generate/github/workflows-blueprint-variables.d.ts +131 -0
- package/build/src/types/cli/generate/github/workflows-blueprint.d.ts +1180 -0
- package/build/src/types/cli/generate/must-haves/agent-conventions.d.ts +9 -2
- package/build/src/types/cli/generate/must-haves/dotenv.d.ts +101 -314
- package/build/src/types/cli/generate/must-haves/editorconfig.d.ts +2 -2
- package/build/src/types/cli/generate/must-haves/gitignore.d.ts +13 -343
- package/build/src/types/cli/generate/must-haves/license.d.ts +5 -5
- package/build/src/types/cli/generate/must-haves/read-me.d.ts +136 -88
- package/build/src/types/cli/index.d.ts +14 -0
- package/build/src/types/cli/recipe/github/handle-gh-failure.d.ts +2 -2
- package/build/src/types/cli/recipe/github/sync-features.d.ts +20 -13
- package/build/src/types/cli/recipe/github/sync-identity.d.ts +20 -13
- package/build/src/types/cli/recipe/github/sync-policies.d.ts +24 -15
- package/build/src/types/cli/recipe/index.d.ts +7 -3
- package/build/src/types/cli/recipe/license/update-copyright.d.ts +142 -0
- package/build/src/types/cli/recipe/package-json/cleanup.d.ts +26 -22
- package/build/src/types/cli/recipe/package-json/normalize-artifacts.d.ts +22 -16
- package/build/src/types/cli/recipe/package-json/normalize-bundler.d.ts +20 -14
- package/build/src/types/cli/recipe/package-json/normalize-dependencies.d.ts +31 -19
- package/build/src/types/cli/recipe/package-json/normalize-modules.d.ts +20 -14
- package/build/src/types/cli/recipe/package-json/normalize-tooling.d.ts +20 -14
- package/build/src/types/cli/recipe/package-json/sync-environment.d.ts +46 -22
- package/build/src/types/cli/recipe/package-json/sync-identity.d.ts +36 -19
- package/build/src/types/cli/recipe/package-json/sync-ownership.d.ts +33 -23
- package/build/src/types/cli/recipe/read-me/update-badges.d.ts +77 -0
- package/build/src/types/cli/recipe/read-me/update-credits.d.ts +77 -0
- package/build/src/types/cli/recipe/read-me/update-documentation.d.ts +77 -0
- package/build/src/types/cli/recipe/read-me/update-header.d.ts +77 -0
- package/build/src/types/cli/recipe/read-me/update-introduction.d.ts +77 -0
- package/build/src/types/cli/scaffold/starter/base.d.ts +2 -2
- package/build/src/types/cli/utility/changelog.d.ts +165 -73
- package/build/src/types/cli/utility/initialize.d.ts +1007 -350
- package/build/src/types/cli/utility/run-scripts.d.ts +1 -1
- package/build/src/types/cli/utility/transpile.d.ts +8 -3
- package/build/src/types/cli/utility/type-check.d.ts +9 -3
- package/build/src/types/cli/utility/version.d.ts +32 -32
- package/build/src/types/lib/constants.d.ts +1 -1
- package/build/src/types/lib/dotenv.d.ts +67 -0
- package/build/src/types/lib/env-github.d.ts +67 -0
- package/build/src/types/lib/env-managed-set.d.ts +90 -0
- package/build/src/types/lib/env-namespace.d.ts +22 -0
- package/build/src/types/lib/env-reconcile.d.ts +71 -0
- package/build/src/types/lib/env-status.d.ts +102 -0
- package/build/src/types/lib/file-discovery.d.ts +40 -0
- package/build/src/types/lib/item.d.ts +42 -0
- package/build/src/types/lib/markdown-slug.d.ts +25 -0
- package/build/src/types/lib/nova-config.d.ts +455 -68
- package/build/src/types/lib/read-me-regions.d.ts +51 -0
- package/build/src/types/lib/regex.d.ts +193 -18
- package/build/src/types/lib/scaffold.d.ts +43 -23
- package/build/src/types/lib/type-declaration-engine.d.ts +1052 -0
- package/build/src/types/lib/utility.d.ts +40 -6
- package/build/src/types/lib/workflow-templates.d.ts +11 -75
- package/build/src/types/presets/eslint/fw-astro.d.ts +8 -0
- package/build/src/types/rules/eslint/conventions/no-implicit-boolean.d.ts +7 -0
- package/build/src/types/rules/eslint/conventions/require-naming-convention.d.ts +8 -4
- package/build/src/types/rules/eslint/conventions/require-node-protocol.d.ts +56 -0
- package/build/src/types/rules/eslint/formatting/require-padding-lines.d.ts +2 -0
- package/build/src/types/rules/eslint/formatting/require-ternary-parens.d.ts +8 -3
- package/build/src/types/rules/eslint/jsdoc/require-jsdoc-body.d.ts +16 -0
- package/build/src/types/rules/eslint/jsdoc/require-jsdoc-hierarchy.d.ts +19 -15
- package/build/src/types/rules/eslint/jsdoc/require-jsdoc-param-name.d.ts +3 -1
- package/build/src/types/rules/eslint/jsdoc/require-jsdoc-presence.d.ts +125 -0
- package/build/src/types/rules/eslint/jsdoc/require-jsdoc-returns.d.ts +48 -0
- package/build/src/types/rules/eslint/jsdoc/require-jsdoc-since.d.ts +71 -1
- package/build/src/types/rules/eslint/jsdoc/require-jsdoc-tag-order.d.ts +204 -0
- package/build/src/types/rules/eslint/patterns/no-await-in-loop.d.ts +1 -1
- package/build/src/types/rules/eslint/patterns/no-bracket-method-call.d.ts +1 -1
- package/build/src/types/rules/eslint/regex/no-regex-literals.d.ts +44 -0
- package/build/src/types/rules/eslint/typescript/require-bracket-property-access.d.ts +19 -7
- package/build/src/types/rules/eslint/typescript/require-type-naming.d.ts +3 -3
- package/build/src/types/rules/vitest/active-vitest.d.ts +31 -0
- package/build/src/types/rules/vitest/dotenv/register.d.ts +31 -0
- package/build/src/types/rules/vitest/dotenv/rules.d.ts +29 -0
- package/build/src/types/rules/vitest/enable.d.ts +12 -0
- package/build/src/types/rules/vitest/frontmatter/register.d.ts +63 -0
- package/build/src/types/rules/vitest/frontmatter/rules.d.ts +430 -0
- package/build/src/types/rules/vitest/index.d.ts +419 -0
- package/build/src/types/rules/vitest/link/register.d.ts +79 -0
- package/build/src/types/rules/vitest/link/rules.d.ts +368 -0
- package/build/src/types/rules/vitest/markdown-table/register.d.ts +33 -0
- package/build/src/types/rules/vitest/markdown-table/rules.d.ts +55 -0
- package/build/src/types/rules/vitest/terminology/register.d.ts +48 -0
- package/build/src/types/rules/vitest/terminology/rules.d.ts +190 -0
- package/build/src/types/rules/vitest/type-declarations/register.d.ts +46 -0
- package/build/src/types/rules/vitest/type-declarations/rules.d.ts +894 -0
- package/build/src/types/shared.d.ts +727 -26
- package/build/src/types/tests/cli/generate/github/funding.test.d.ts +14 -10
- package/build/src/types/tests/cli/generate/github/issue-template.test.d.ts +38 -17
- package/build/src/types/tests/cli/generate/github/workflows-blueprint-generate.test.d.ts +199 -0
- package/build/src/types/tests/cli/generate/github/workflows-blueprint-parity.test.d.ts +75 -0
- package/build/src/types/tests/cli/generate/github/workflows-blueprint-publish-parity.test.d.ts +295 -0
- package/build/src/types/tests/cli/generate/github/workflows-blueprint-validate.test.d.ts +901 -0
- package/build/src/types/tests/cli/generate/github/workflows-blueprint-variables.test.d.ts +144 -0
- package/build/src/types/tests/cli/generate/github/workflows-blueprint.test.d.ts +332 -0
- package/build/src/types/tests/cli/generate/must-haves/agent-conventions.test.d.ts +83 -11
- package/build/src/types/tests/cli/generate/must-haves/dotenv.test.d.ts +142 -12
- package/build/src/types/tests/cli/generate/must-haves/editorconfig.test.d.ts +12 -8
- package/build/src/types/tests/cli/generate/must-haves/gitignore.test.d.ts +14 -19
- package/build/src/types/tests/cli/generate/must-haves/read-me.test.d.ts +33 -10
- package/build/src/types/tests/cli/recipe/github/handle-gh-failure.test.d.ts +28 -24
- package/build/src/types/tests/cli/recipe/github/sync-features.test.d.ts +115 -111
- package/build/src/types/tests/cli/recipe/github/sync-identity.test.d.ts +192 -142
- package/build/src/types/tests/cli/recipe/github/sync-policies.test.d.ts +199 -126
- package/build/src/types/tests/cli/recipe/license/update-copyright.test.d.ts +617 -0
- package/build/src/types/tests/cli/recipe/package-json/normalize-dependencies.test.d.ts +27 -0
- package/build/src/types/tests/cli/recipe/package-json/sync-environment.test.d.ts +21 -0
- package/build/src/types/tests/cli/recipe/package-json/sync-identity.test.d.ts +52 -0
- package/build/src/types/tests/cli/recipe/read-me/update-badges.test.d.ts +258 -0
- package/build/src/types/tests/cli/recipe/read-me/update-credits.test.d.ts +258 -0
- package/build/src/types/tests/cli/recipe/read-me/update-documentation.test.d.ts +258 -0
- package/build/src/types/tests/cli/recipe/read-me/update-header.test.d.ts +258 -0
- package/build/src/types/tests/cli/recipe/read-me/update-introduction.test.d.ts +258 -0
- package/build/src/types/tests/cli/scaffold/docs/docusaurus.test.d.ts +4 -0
- package/build/src/types/tests/cli/utility/changelog.test.d.ts +293 -0
- package/build/src/types/tests/cli/utility/initialize.test.d.ts +148 -1
- package/build/src/types/tests/lib/dotenv.test.d.ts +95 -0
- package/build/src/types/tests/lib/file-discovery.test.d.ts +37 -0
- package/build/src/types/tests/lib/item.test.d.ts +21 -0
- package/build/src/types/tests/lib/markdown-slug.test.d.ts +24 -0
- package/build/src/types/tests/lib/nova-config.test.d.ts +503 -83
- package/build/src/types/tests/lib/read-me-regions.test.d.ts +43 -0
- package/build/src/types/tests/lib/regex.test.d.ts +252 -0
- package/build/src/types/tests/lib/utility.test.d.ts +35 -0
- package/build/src/types/tests/lib/workflow-templates.test.d.ts +18 -2
- package/build/src/types/tests/rules/eslint/conventions/require-node-protocol.test.d.ts +8 -0
- package/build/src/types/tests/rules/eslint/jsdoc/require-jsdoc-presence.test.d.ts +8 -0
- package/build/src/types/tests/rules/eslint/jsdoc/require-jsdoc-returns.test.d.ts +8 -0
- package/build/src/types/tests/rules/eslint/jsdoc/require-jsdoc-since.test.d.ts +18 -0
- package/build/src/types/tests/rules/eslint/jsdoc/require-jsdoc-tag-order.test.d.ts +8 -0
- package/build/src/types/tests/rules/vitest/active-vitest.test.d.ts +56 -0
- package/build/src/types/tests/rules/vitest/dotenv.test.d.ts +19 -0
- package/build/src/types/tests/rules/vitest/enable.test.d.ts +27 -0
- package/build/src/types/tests/rules/vitest/frontmatter.test.d.ts +22 -0
- package/build/src/types/tests/rules/vitest/link.test.d.ts +74 -0
- package/build/src/types/tests/rules/vitest/markdown-table.test.d.ts +28 -0
- package/build/src/types/tests/rules/vitest/terminology.test.d.ts +43 -0
- package/build/src/types/tests/rules/vitest/type-declarations.test.d.ts +10 -0
- package/build/src/types/tests/scaffold-version-drift.test.d.ts +42 -0
- package/build/src/types/tests/since-version.test.d.ts +137 -0
- package/build/src/types/tests/toolkit/logger.test.d.ts +70 -5
- package/build/src/types/tests/toolkit/nova-identity.test.d.ts +118 -0
- package/build/src/types/tests/type-declarations.test.d.ts +40 -1813
- package/build/src/types/toolkit/logger.d.ts +4 -0
- package/build/src/types/toolkit/nova-identity.d.ts +313 -0
- package/build/templates/generators/github/workflows/check-sponsor-gated-issues/base.yml +1 -1
- package/build/templates/generators/github/workflows/publish/base.yml +3 -1
- package/build/templates/generators/github/workflows/publish/targets/cloudflare-pages-docusaurus.yml +1 -1
- package/build/templates/generators/github/workflows/publish/targets/cloudflare-workers.yml +36 -0
- package/build/templates/generators/github/workflows/publish/targets/docker-hub.yml +1 -1
- package/build/templates/generators/github/workflows/publish/targets/ghcr.yml +1 -1
- package/build/templates/generators/github/workflows/publish/targets/github-action.yml +1 -1
- package/build/templates/generators/github/workflows/publish/targets/github-packages.yml +1 -1
- package/build/templates/generators/github/workflows/publish/targets/github-pages-docusaurus.yml +4 -4
- package/build/templates/generators/github/workflows/publish/targets/npm.yml +1 -1
- package/build/templates/generators/github/workflows/publish/targets/vercel-nextjs.yml +1 -1
- package/build/templates/generators/must-haves/agent-conventions/AGENTS.md +1 -2
- package/build/templates/generators/must-haves/agent-conventions/CLAUDE.md +1 -2
- package/build/templates/generators/must-haves/agent-conventions/conventions/java.md +5 -5
- package/build/templates/generators/must-haves/agent-conventions/conventions/kotlin.md +4 -4
- package/build/templates/generators/must-haves/agent-conventions/conventions/php.md +2 -2
- package/build/templates/generators/must-haves/agent-conventions/conventions/typescript.md +6 -6
- package/build/templates/generators/must-haves/agent-conventions/conventions/universal.md +2 -0
- package/build/templates/generators/must-haves/dotenv/env +5 -2
- package/build/templates/generators/must-haves/dotenv/env.sample +6 -3
- package/build/templates/generators/must-haves/gitignore/gitignore +6 -0
- package/build/templates/scaffold/app/express/package.json +5 -5
- package/build/templates/scaffold/app/nextjs/package.json +7 -7
- package/build/templates/scaffold/app/vite/package.json +3 -3
- package/build/templates/scaffold/app/workers/package.json +3 -3
- package/build/templates/scaffold/docs/docusaurus/docs/intro.md +6 -0
- package/build/templates/scaffold/docs/docusaurus/docusaurus.config.ts +9 -3
- package/build/templates/scaffold/docs/docusaurus/package.json +14 -7
- package/build/templates/scaffold/docs/docusaurus/src/tests/frontmatter.test.ts +25 -0
- package/build/templates/scaffold/docs/docusaurus/src/tests/link.test.ts +16 -0
- package/build/templates/scaffold/docs/docusaurus/src/tests/markdown-table.test.ts +16 -0
- package/build/templates/scaffold/docs/docusaurus/src/tests/terminology.test.ts +16 -0
- package/build/templates/scaffold/docs/docusaurus/src/tests/type-declarations.test.ts +17 -0
- package/build/templates/scaffold/docs/docusaurus/vitest.config.ts +22 -0
- package/build/templates/scaffold/docs/docusaurus/vitest.setup.ts +26 -0
- package/package.json +14 -10
- package/build/src/cli/generate/github/workflows.d.ts +0 -17
- package/build/src/cli/generate/github/workflows.d.ts.map +0 -1
- package/build/src/cli/generate/github/workflows.js +0 -856
- package/build/src/cli/generate/github/workflows.js.map +0 -1
- package/build/src/types/cli/generate/github/workflows.d.ts +0 -596
- package/build/src/types/tests/cli/generate/github/workflows-helpers.test.d.ts +0 -239
- package/build/src/types/tests/cli/generate/github/workflows.test.d.ts +0 -587
- package/build/templates/generators/github/workflows/publish/targets/aws-amplify-nextjs.yml +0 -32
- package/build/templates/generators/must-haves/agent-conventions/cursorrules +0 -55
|
@@ -0,0 +1,796 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { relative, sep, } from 'node:path';
|
|
3
|
+
import { glob } from 'glob';
|
|
4
|
+
import { createSourceFile, forEachChild, isArrowFunction, isCallExpression, isClassDeclaration, isClassExpression, isConstructorDeclaration, isFunctionDeclaration, isFunctionExpression, isGetAccessorDeclaration, isIdentifier, isMethodDeclaration, isPrivateIdentifier, isSetAccessorDeclaration, isStringLiteral, isTypePredicateNode, isTypeReferenceNode, isVariableStatement, ScriptTarget, } from 'typescript';
|
|
5
|
+
import { LIB_REGEX_PATTERN_ANGLE_BRACKET_GENERIC, LIB_REGEX_PATTERN_CAMEL_CASE_WORDS, LIB_REGEX_PATTERN_COMPLEX_TYPE_RHS_CHARS, LIB_REGEX_PATTERN_DTS_ARRAY_ALIAS, LIB_REGEX_PATTERN_DTS_PROPERTY_LINE, LIB_REGEX_PATTERN_EMPTY_ARRAY_BRACKETS, LIB_REGEX_PATTERN_EXPORT_TYPE_NAME, LIB_REGEX_PATTERN_EXT_D_TS_SUFFIX, LIB_REGEX_PATTERN_IMPORT_TYPE_BLOCK, LIB_REGEX_PATTERN_NON_ALPHANUMERIC_RUN, LIB_REGEX_PATTERN_REGEX_SPECIAL_CHARS, LIB_REGEX_PATTERN_SINGLE_PASCAL_TYPE, LIB_REGEX_PATTERN_TYPED_BODY_DECLARATION, } from './regex.js';
|
|
6
|
+
export const testConfig = {
|
|
7
|
+
standaloneTypeFiles: [
|
|
8
|
+
'/fetch-response.d.ts',
|
|
9
|
+
'/shared.d.ts',
|
|
10
|
+
],
|
|
11
|
+
typeRoots: [
|
|
12
|
+
'src',
|
|
13
|
+
'utils',
|
|
14
|
+
],
|
|
15
|
+
};
|
|
16
|
+
export async function discoverSourceFiles(config = {}) {
|
|
17
|
+
const packageRoot = config['packageRoot'] ?? process.cwd();
|
|
18
|
+
const typeRoots = config['typeRoots'] ?? ['src'];
|
|
19
|
+
const patterns = typeRoots.map((typeRoot) => `${typeRoot}/**/*.ts`);
|
|
20
|
+
const ignorePatterns = typeRoots.map((typeRoot) => `${typeRoot}/**/*.d.ts`);
|
|
21
|
+
const matched = await glob(patterns, {
|
|
22
|
+
cwd: packageRoot,
|
|
23
|
+
absolute: true,
|
|
24
|
+
ignore: ignorePatterns,
|
|
25
|
+
});
|
|
26
|
+
return matched.sort();
|
|
27
|
+
}
|
|
28
|
+
export async function discoverTypeFiles(config = {}) {
|
|
29
|
+
const packageRoot = config['packageRoot'] ?? process.cwd();
|
|
30
|
+
const typeRoots = config['typeRoots'] ?? ['src'];
|
|
31
|
+
const patterns = typeRoots.map((typeRoot) => `${typeRoot}/types/**/*.d.ts`);
|
|
32
|
+
const matched = await glob(patterns, {
|
|
33
|
+
cwd: packageRoot,
|
|
34
|
+
absolute: true,
|
|
35
|
+
});
|
|
36
|
+
return matched.sort();
|
|
37
|
+
}
|
|
38
|
+
export function deriveClassPrefix(filePath, config = {}) {
|
|
39
|
+
const packageRoot = config['packageRoot'] ?? process.cwd();
|
|
40
|
+
const typeRoots = config['typeRoots'] ?? ['src'];
|
|
41
|
+
const currentDirectory = packageRoot;
|
|
42
|
+
const relativePath = relative(currentDirectory, filePath);
|
|
43
|
+
let relativeCleaned = relativePath;
|
|
44
|
+
for (const typeRoot of typeRoots) {
|
|
45
|
+
relativeCleaned = relativeCleaned.replace(`${typeRoot}/types/`, '');
|
|
46
|
+
relativeCleaned = relativeCleaned.replace(`${typeRoot}/`, '');
|
|
47
|
+
}
|
|
48
|
+
const segments = relativeCleaned
|
|
49
|
+
.replace('.d.ts', '')
|
|
50
|
+
.replace('.ts', '')
|
|
51
|
+
.replace('.test', '')
|
|
52
|
+
.split(sep)
|
|
53
|
+
.join('/')
|
|
54
|
+
.split('/');
|
|
55
|
+
const camelCaseWordsPattern = new RegExp(LIB_REGEX_PATTERN_CAMEL_CASE_WORDS.source, 'g');
|
|
56
|
+
return segments.map((segment) => {
|
|
57
|
+
if (segment.includes('-') === false
|
|
58
|
+
&& segment.charAt(0) === segment.charAt(0).toUpperCase()
|
|
59
|
+
&& segment.length > 0) {
|
|
60
|
+
const words = segment.match(camelCaseWordsPattern);
|
|
61
|
+
if (words !== null) {
|
|
62
|
+
return words.map((word) => {
|
|
63
|
+
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
64
|
+
}).join('');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return segment.split('-').map((part) => {
|
|
68
|
+
return part.charAt(0).toUpperCase() + part.slice(1);
|
|
69
|
+
}).join('');
|
|
70
|
+
}).join('_');
|
|
71
|
+
}
|
|
72
|
+
export function extractImportedNames(lines) {
|
|
73
|
+
const importedNames = new Set();
|
|
74
|
+
let inImportBlock = false;
|
|
75
|
+
for (const line of lines) {
|
|
76
|
+
if (line.startsWith('import type') === true) {
|
|
77
|
+
inImportBlock = true;
|
|
78
|
+
const inlineMatch = line.match(LIB_REGEX_PATTERN_IMPORT_TYPE_BLOCK);
|
|
79
|
+
if (inlineMatch !== null && inlineMatch[1] !== undefined) {
|
|
80
|
+
const inlineMatchCapture = inlineMatch[1];
|
|
81
|
+
const specifiers = inlineMatchCapture.split(',').map((specifier) => specifier.trim());
|
|
82
|
+
for (const specifier of specifiers) {
|
|
83
|
+
importedNames.add(specifier);
|
|
84
|
+
}
|
|
85
|
+
inImportBlock = false;
|
|
86
|
+
}
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (inImportBlock === true) {
|
|
90
|
+
const trimmed = line.trim().replace(',', '');
|
|
91
|
+
if (trimmed.startsWith('}') === true) {
|
|
92
|
+
inImportBlock = false;
|
|
93
|
+
}
|
|
94
|
+
else if (trimmed !== '' && trimmed.startsWith('//') === false) {
|
|
95
|
+
importedNames.add(trimmed);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return importedNames;
|
|
100
|
+
}
|
|
101
|
+
export function buildDtsSections(dtsLines, sourceSections, classPrefix) {
|
|
102
|
+
const sortedSections = [...sourceSections].sort((sectionA, sectionB) => sectionB.length - sectionA.length);
|
|
103
|
+
const sectionMap = new Map();
|
|
104
|
+
const sectionOrder = [];
|
|
105
|
+
for (const line of dtsLines) {
|
|
106
|
+
if (line.startsWith('export type ') === false) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const match = line.match(LIB_REGEX_PATTERN_EXPORT_TYPE_NAME);
|
|
110
|
+
if (match === null || match[1] === undefined) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const typeName = match[1];
|
|
114
|
+
let owningSection = '';
|
|
115
|
+
for (const candidate of sortedSections) {
|
|
116
|
+
if (typeName.startsWith(`${candidate}_`) === true) {
|
|
117
|
+
owningSection = candidate;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (owningSection === '' && typeName.startsWith(`${classPrefix}_`) === true) {
|
|
122
|
+
owningSection = classPrefix;
|
|
123
|
+
}
|
|
124
|
+
if (owningSection === '') {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (sectionMap.has(owningSection) === false) {
|
|
128
|
+
sectionMap.set(owningSection, {
|
|
129
|
+
prefix: owningSection,
|
|
130
|
+
typeLines: [],
|
|
131
|
+
});
|
|
132
|
+
sectionOrder.push(owningSection);
|
|
133
|
+
}
|
|
134
|
+
const section = sectionMap.get(owningSection);
|
|
135
|
+
section['typeLines'].push(line);
|
|
136
|
+
}
|
|
137
|
+
return sectionOrder.map((prefix) => sectionMap.get(prefix));
|
|
138
|
+
}
|
|
139
|
+
export function extractReferencedTypes(line, classPrefix) {
|
|
140
|
+
const match = line.match(LIB_REGEX_PATTERN_EXPORT_TYPE_NAME);
|
|
141
|
+
if (match === null || match[1] === undefined) {
|
|
142
|
+
return [];
|
|
143
|
+
}
|
|
144
|
+
const typeName = match[1];
|
|
145
|
+
const rightSide = line.slice(line.indexOf('=') + 1);
|
|
146
|
+
const referencedTypes = [];
|
|
147
|
+
const typePattern = new RegExp(`${classPrefix}_\\w+`, 'g');
|
|
148
|
+
let typeMatch = typePattern.exec(rightSide);
|
|
149
|
+
while (typeMatch !== null) {
|
|
150
|
+
const referencedType = typeMatch[0];
|
|
151
|
+
if (referencedType !== typeName) {
|
|
152
|
+
referencedTypes.push(referencedType);
|
|
153
|
+
}
|
|
154
|
+
typeMatch = typePattern.exec(rightSide);
|
|
155
|
+
}
|
|
156
|
+
return referencedTypes;
|
|
157
|
+
}
|
|
158
|
+
export function deriveDtsMapping(typeRoots) {
|
|
159
|
+
return {
|
|
160
|
+
sourceToDts: (file) => {
|
|
161
|
+
let mapped = file;
|
|
162
|
+
for (const typeRoot of typeRoots) {
|
|
163
|
+
if (file.includes(`/${typeRoot}/`) === true) {
|
|
164
|
+
mapped = file.replace(`/${typeRoot}/`, `/${typeRoot}/types/`);
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return mapped.replace('.ts', '.d.ts');
|
|
169
|
+
},
|
|
170
|
+
dtsToSource: (file) => {
|
|
171
|
+
return file.replace('/types/', '/').replace('.d.ts', '.ts');
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
export function deriveSourcePath(dtsPath) {
|
|
176
|
+
return dtsPath.replace('/types/', '/').replace('.d.ts', '.ts');
|
|
177
|
+
}
|
|
178
|
+
export async function fileExists(filePath) {
|
|
179
|
+
try {
|
|
180
|
+
await readFile(filePath, 'utf-8');
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
export function extractTypeNames(typeLines) {
|
|
188
|
+
const typeNames = [];
|
|
189
|
+
for (const line of typeLines) {
|
|
190
|
+
const match = line.match(LIB_REGEX_PATTERN_EXPORT_TYPE_NAME);
|
|
191
|
+
if (match !== null && match[1] !== undefined) {
|
|
192
|
+
typeNames.push(match[1]);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return typeNames;
|
|
196
|
+
}
|
|
197
|
+
export function findFirstOccurrence(sourceLines, typeName) {
|
|
198
|
+
let inImportBlock = false;
|
|
199
|
+
for (let i = 0; i < sourceLines.length; i += 1) {
|
|
200
|
+
const line = sourceLines[i];
|
|
201
|
+
if (line === undefined) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (line.startsWith('import ') === true || line.startsWith('import type') === true) {
|
|
205
|
+
inImportBlock = true;
|
|
206
|
+
}
|
|
207
|
+
if (inImportBlock === true) {
|
|
208
|
+
if (line.includes(' from ') === true) {
|
|
209
|
+
inImportBlock = false;
|
|
210
|
+
}
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
const typeNamePattern = new RegExp(`\\b${typeName}\\b`);
|
|
214
|
+
if (typeNamePattern.test(line) === true) {
|
|
215
|
+
return i;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return -1;
|
|
219
|
+
}
|
|
220
|
+
export function extractObjectTypes(lines, classPrefix) {
|
|
221
|
+
const objectTypes = [];
|
|
222
|
+
const typeLineMap = new Map();
|
|
223
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
224
|
+
const line = lines[i];
|
|
225
|
+
if (line === undefined) {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const typeDefMatch = line.match(new RegExp(`^export type (${classPrefix}\\w+)`));
|
|
229
|
+
if (typeDefMatch !== null && typeDefMatch[1] !== undefined) {
|
|
230
|
+
typeLineMap.set(typeDefMatch[1], i);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
234
|
+
const line2 = lines[i];
|
|
235
|
+
if (line2 === undefined) {
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
const objectMatch = line2.match(new RegExp(`^export type (${classPrefix}\\w+) = (?:Readonly<)?\\{$`));
|
|
239
|
+
if (objectMatch === null || objectMatch[1] === undefined) {
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
const properties = [];
|
|
243
|
+
for (let j = i + 1; j < lines.length; j += 1) {
|
|
244
|
+
const propertyLine = lines[j];
|
|
245
|
+
if (propertyLine === undefined) {
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
const trimmedProperty = propertyLine.trim();
|
|
249
|
+
if (trimmedProperty.startsWith('}') === true) {
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
const propertyMatch = trimmedProperty.match(LIB_REGEX_PATTERN_DTS_PROPERTY_LINE);
|
|
253
|
+
if (propertyMatch !== null
|
|
254
|
+
&& propertyMatch[1] !== undefined
|
|
255
|
+
&& propertyMatch[2] !== undefined) {
|
|
256
|
+
const propertyKey = propertyMatch[1];
|
|
257
|
+
const propertyValueType = propertyMatch[2];
|
|
258
|
+
const typeLineIndex = typeLineMap.get(propertyValueType) ?? -1;
|
|
259
|
+
properties.push({
|
|
260
|
+
key: propertyKey,
|
|
261
|
+
valueType: propertyValueType,
|
|
262
|
+
typeLineIndex,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const objectName = objectMatch[1];
|
|
267
|
+
objectTypes.push({
|
|
268
|
+
name: objectName,
|
|
269
|
+
lineIndex: i,
|
|
270
|
+
properties,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
return objectTypes;
|
|
274
|
+
}
|
|
275
|
+
const sourceFileCache = new Map();
|
|
276
|
+
export function parseSourceFile(filePath, content) {
|
|
277
|
+
const cached = sourceFileCache.get(filePath);
|
|
278
|
+
if (cached !== undefined && cached['content'] === content) {
|
|
279
|
+
return cached['sourceFile'];
|
|
280
|
+
}
|
|
281
|
+
const sourceFile = createSourceFile(filePath, content, ScriptTarget.Latest, true);
|
|
282
|
+
sourceFileCache.set(filePath, {
|
|
283
|
+
content,
|
|
284
|
+
sourceFile,
|
|
285
|
+
});
|
|
286
|
+
return sourceFile;
|
|
287
|
+
}
|
|
288
|
+
export function extractFunctionParams(filePath, content) {
|
|
289
|
+
const sourceFile = parseSourceFile(filePath, content);
|
|
290
|
+
const params = [];
|
|
291
|
+
function visit(node) {
|
|
292
|
+
let parameterList = undefined;
|
|
293
|
+
if (isFunctionDeclaration(node) === true
|
|
294
|
+
|| isMethodDeclaration(node) === true
|
|
295
|
+
|| isConstructorDeclaration(node) === true) {
|
|
296
|
+
parameterList = node['parameters'];
|
|
297
|
+
}
|
|
298
|
+
else if (isVariableStatement(node) === true) {
|
|
299
|
+
for (const decl of node.declarationList.declarations) {
|
|
300
|
+
if (decl.initializer !== undefined
|
|
301
|
+
&& (isArrowFunction(decl.initializer) === true
|
|
302
|
+
|| isFunctionExpression(decl.initializer) === true)) {
|
|
303
|
+
parameterList = decl.initializer.parameters;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (parameterList !== undefined) {
|
|
308
|
+
for (const param of parameterList) {
|
|
309
|
+
const paramNode = param;
|
|
310
|
+
if (paramNode['name'] !== undefined
|
|
311
|
+
&& isIdentifier(paramNode['name']) === true
|
|
312
|
+
&& paramNode['type'] !== undefined
|
|
313
|
+
&& isTypeReferenceNode(paramNode['type']) === true
|
|
314
|
+
&& isIdentifier(paramNode['type']['typeName']) === true) {
|
|
315
|
+
const lineNumber = sourceFile.getLineAndCharacterOfPosition((param).getStart()).line + 1;
|
|
316
|
+
const paramRecord = {
|
|
317
|
+
paramName: paramNode['name']['text'],
|
|
318
|
+
typeName: paramNode['type']['typeName']['text'],
|
|
319
|
+
lineNumber,
|
|
320
|
+
};
|
|
321
|
+
params.push(paramRecord);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
forEachChild(node, visit);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
forEachChild(sourceFile, visit);
|
|
329
|
+
return params;
|
|
330
|
+
}
|
|
331
|
+
export function extractBodyDeclarations(lines) {
|
|
332
|
+
const declarations = [];
|
|
333
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
334
|
+
const line = lines[i];
|
|
335
|
+
if (line === undefined) {
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
const match = line.match(LIB_REGEX_PATTERN_TYPED_BODY_DECLARATION);
|
|
339
|
+
if (match !== null
|
|
340
|
+
&& match[1] !== undefined
|
|
341
|
+
&& match[2] !== undefined
|
|
342
|
+
&& match[3] !== undefined) {
|
|
343
|
+
const declaration = {
|
|
344
|
+
keyword: match[1],
|
|
345
|
+
varName: match[2],
|
|
346
|
+
typeName: match[3],
|
|
347
|
+
lineNumber: i + 1,
|
|
348
|
+
};
|
|
349
|
+
declarations.push(declaration);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return declarations;
|
|
353
|
+
}
|
|
354
|
+
export function extractTopLevelIdentifiers(filePath, content) {
|
|
355
|
+
const sourceFile = parseSourceFile(filePath, content);
|
|
356
|
+
const identifiers = [];
|
|
357
|
+
function getLine(node) {
|
|
358
|
+
return sourceFile.getLineAndCharacterOfPosition(node.getStart()).line + 1;
|
|
359
|
+
}
|
|
360
|
+
forEachChild(sourceFile, (node) => {
|
|
361
|
+
if (isClassDeclaration(node) === true && node.name !== undefined) {
|
|
362
|
+
const identifier = {
|
|
363
|
+
name: node.name.text,
|
|
364
|
+
kind: 'class',
|
|
365
|
+
lineNumber: getLine(node),
|
|
366
|
+
};
|
|
367
|
+
identifiers.push(identifier);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
if (isFunctionDeclaration(node) === true && node.name !== undefined) {
|
|
371
|
+
const identifier2 = {
|
|
372
|
+
name: node.name.text,
|
|
373
|
+
kind: 'function',
|
|
374
|
+
lineNumber: getLine(node),
|
|
375
|
+
};
|
|
376
|
+
identifiers.push(identifier2);
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
if (isVariableStatement(node) === true) {
|
|
380
|
+
for (const decl of node.declarationList.declarations) {
|
|
381
|
+
if (decl.name !== undefined
|
|
382
|
+
&& isIdentifier(decl.name) === true
|
|
383
|
+
&& decl.initializer !== undefined
|
|
384
|
+
&& (isArrowFunction(decl.initializer) === true
|
|
385
|
+
|| isFunctionExpression(decl.initializer) === true
|
|
386
|
+
|| isClassExpression(decl.initializer) === true)) {
|
|
387
|
+
const identifier3 = {
|
|
388
|
+
name: decl.name.text,
|
|
389
|
+
kind: 'const',
|
|
390
|
+
lineNumber: getLine(decl),
|
|
391
|
+
};
|
|
392
|
+
identifiers.push(identifier3);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return;
|
|
397
|
+
});
|
|
398
|
+
return identifiers;
|
|
399
|
+
}
|
|
400
|
+
export function buildSourceSectionMap(filePath, content, classPrefix) {
|
|
401
|
+
const sourceFile = parseSourceFile(filePath, content);
|
|
402
|
+
const sectionMap = new Map();
|
|
403
|
+
const maxDepth = 5000;
|
|
404
|
+
function getLine(node) {
|
|
405
|
+
return sourceFile.getLineAndCharacterOfPosition(node.getStart()).line + 1;
|
|
406
|
+
}
|
|
407
|
+
function pascalCase(name) {
|
|
408
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
409
|
+
}
|
|
410
|
+
let currentDepth = 0;
|
|
411
|
+
function tagAllChildren(node, section) {
|
|
412
|
+
if (currentDepth >= maxDepth) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
currentDepth += 1;
|
|
416
|
+
forEachChild(node, (child) => visit(child, section));
|
|
417
|
+
currentDepth -= 1;
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
function visit(node, section) {
|
|
421
|
+
if (isClassDeclaration(node) === true && node.name !== undefined) {
|
|
422
|
+
const newSection = `${section}_${pascalCase(node.name.text)}`;
|
|
423
|
+
sectionMap.set(getLine(node), newSection);
|
|
424
|
+
tagAllChildren(node, newSection);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
const accessor = node;
|
|
428
|
+
if ((isMethodDeclaration(node) === true
|
|
429
|
+
|| isGetAccessorDeclaration(node) === true
|
|
430
|
+
|| isSetAccessorDeclaration(node) === true)
|
|
431
|
+
&& accessor.name !== undefined
|
|
432
|
+
&& (isIdentifier(accessor.name) === true
|
|
433
|
+
|| isPrivateIdentifier(accessor.name) === true)) {
|
|
434
|
+
const rawMethodName = accessor.name.text;
|
|
435
|
+
const cleanMethodName = (rawMethodName.startsWith('#') === true) ? rawMethodName.slice(1) : rawMethodName;
|
|
436
|
+
const newSection2 = `${section}_${pascalCase(cleanMethodName)}`;
|
|
437
|
+
sectionMap.set(getLine(node), newSection2);
|
|
438
|
+
tagAllChildren(node, newSection2);
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
if (isConstructorDeclaration(node) === true) {
|
|
442
|
+
const newSection3 = `${section}_Constructor`;
|
|
443
|
+
sectionMap.set(getLine(node), newSection3);
|
|
444
|
+
tagAllChildren(node, newSection3);
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
if (isFunctionDeclaration(node) === true && node.name !== undefined) {
|
|
448
|
+
const newSection4 = `${section}_${pascalCase(node.name.text)}`;
|
|
449
|
+
sectionMap.set(getLine(node), newSection4);
|
|
450
|
+
tagAllChildren(node, newSection4);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
if (isVariableStatement(node) === true) {
|
|
454
|
+
let hasInitializer = false;
|
|
455
|
+
let subSection = section;
|
|
456
|
+
for (const decl of node.declarationList.declarations) {
|
|
457
|
+
if (decl.name !== undefined
|
|
458
|
+
&& isIdentifier(decl.name) === true
|
|
459
|
+
&& decl.initializer !== undefined
|
|
460
|
+
&& (isArrowFunction(decl.initializer) === true
|
|
461
|
+
|| isFunctionExpression(decl.initializer) === true
|
|
462
|
+
|| isClassExpression(decl.initializer) === true)) {
|
|
463
|
+
hasInitializer = true;
|
|
464
|
+
subSection = `${section}_${pascalCase(decl.name.text)}`;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
sectionMap.set(getLine(node), section);
|
|
468
|
+
if (hasInitializer === true) {
|
|
469
|
+
for (const decl of node.declarationList.declarations) {
|
|
470
|
+
if (decl.initializer === undefined) {
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
if (isArrowFunction(decl.initializer) === true || isFunctionExpression(decl.initializer) === true) {
|
|
474
|
+
if (decl.initializer.body !== undefined) {
|
|
475
|
+
tagAllChildren(decl.initializer.body, subSection);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
else if (isClassExpression(decl.initializer) === true) {
|
|
479
|
+
tagAllChildren(decl.initializer, subSection);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
tagAllChildren(node, section);
|
|
485
|
+
}
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
if (isCallExpression(node) === true
|
|
489
|
+
&& node.arguments.length >= 2
|
|
490
|
+
&& node.arguments[0] !== undefined
|
|
491
|
+
&& isStringLiteral(node.arguments[0]) === true) {
|
|
492
|
+
let callbackArg = undefined;
|
|
493
|
+
for (let argIndex = 1; argIndex < node.arguments.length; argIndex += 1) {
|
|
494
|
+
const arg = node.arguments[argIndex];
|
|
495
|
+
if (arg !== undefined
|
|
496
|
+
&& (isArrowFunction(arg) === true
|
|
497
|
+
|| isFunctionExpression(arg) === true)) {
|
|
498
|
+
callbackArg = arg;
|
|
499
|
+
break;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
if (callbackArg !== undefined) {
|
|
503
|
+
const stringArg = node.arguments[0];
|
|
504
|
+
const chunk = parseDescribeString(stringArg.text);
|
|
505
|
+
if (chunk !== '') {
|
|
506
|
+
const newSection5 = `${section}_${chunk}`;
|
|
507
|
+
sectionMap.set(getLine(node), section);
|
|
508
|
+
tagAllChildren(callbackArg, newSection5);
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
sectionMap.set(getLine(node), section);
|
|
514
|
+
tagAllChildren(node, section);
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
forEachChild(sourceFile, (child) => visit(child, classPrefix));
|
|
518
|
+
return sectionMap;
|
|
519
|
+
}
|
|
520
|
+
export function parseDescribeString(input) {
|
|
521
|
+
const pieces = input
|
|
522
|
+
.split(LIB_REGEX_PATTERN_NON_ALPHANUMERIC_RUN)
|
|
523
|
+
.filter((piece) => piece.length > 0)
|
|
524
|
+
.map((piece) => piece.charAt(0).toUpperCase() + piece.slice(1));
|
|
525
|
+
return pieces.join('');
|
|
526
|
+
}
|
|
527
|
+
export function stripUnderscorePrefix(input) {
|
|
528
|
+
if (input.startsWith('_') === true) {
|
|
529
|
+
return input.slice(1);
|
|
530
|
+
}
|
|
531
|
+
return input;
|
|
532
|
+
}
|
|
533
|
+
export function checkTypeNameUniqueness(declarations) {
|
|
534
|
+
const violations = [];
|
|
535
|
+
const seen = new Map();
|
|
536
|
+
for (const declaration of declarations) {
|
|
537
|
+
const existing = seen.get(declaration['typeName']);
|
|
538
|
+
if (existing !== undefined) {
|
|
539
|
+
const violation = `Two declarations would produce the same type name '${declaration['typeName']}'. First: line ${existing['lineNumber']} ('${existing['name']}'); duplicate: line ${declaration['lineNumber']} ('${declaration['name']}'). Rename one of the declarations so the type names differ.`;
|
|
540
|
+
violations.push(violation);
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
seen.set(declaration['typeName'], {
|
|
544
|
+
name: declaration['name'],
|
|
545
|
+
lineNumber: declaration['lineNumber'],
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return violations;
|
|
550
|
+
}
|
|
551
|
+
export function detectInlineTypedCallbacks(filePath, content) {
|
|
552
|
+
const sourceFile = parseSourceFile(filePath, content);
|
|
553
|
+
const callbacks = [];
|
|
554
|
+
function visit(node) {
|
|
555
|
+
if ((isArrowFunction(node) === true
|
|
556
|
+
|| isFunctionExpression(node) === true)
|
|
557
|
+
&& node.parent !== undefined) {
|
|
558
|
+
let isFunctionTypedConst = false;
|
|
559
|
+
let walker = node.parent;
|
|
560
|
+
while (walker !== undefined) {
|
|
561
|
+
if (isVariableStatement(walker) === true) {
|
|
562
|
+
isFunctionTypedConst = true;
|
|
563
|
+
break;
|
|
564
|
+
}
|
|
565
|
+
if (walker['kind'] !== undefined
|
|
566
|
+
&& (isCallExpression(walker) === true
|
|
567
|
+
|| isArrowFunction(walker) === true
|
|
568
|
+
|| isFunctionExpression(walker) === true)) {
|
|
569
|
+
break;
|
|
570
|
+
}
|
|
571
|
+
walker = walker['parent'];
|
|
572
|
+
}
|
|
573
|
+
if (isFunctionTypedConst === false) {
|
|
574
|
+
for (const param of node.parameters) {
|
|
575
|
+
const paramNode = param;
|
|
576
|
+
if (paramNode['name'] !== undefined
|
|
577
|
+
&& isIdentifier(paramNode['name']) === true
|
|
578
|
+
&& paramNode['type'] !== undefined
|
|
579
|
+
&& isTypeReferenceNode(paramNode['type']) === true
|
|
580
|
+
&& isIdentifier(paramNode['type']['typeName']) === true) {
|
|
581
|
+
const lineNumber = sourceFile.getLineAndCharacterOfPosition(param.getStart()).line + 1;
|
|
582
|
+
const callback = {
|
|
583
|
+
paramName: paramNode['name']['text'],
|
|
584
|
+
typeName: paramNode['type']['typeName']['text'],
|
|
585
|
+
lineNumber,
|
|
586
|
+
};
|
|
587
|
+
callbacks.push(callback);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
forEachChild(node, visit);
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
forEachChild(sourceFile, visit);
|
|
596
|
+
return callbacks;
|
|
597
|
+
}
|
|
598
|
+
export function extractArrayTypes(lines) {
|
|
599
|
+
const arrayTypes = [];
|
|
600
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
601
|
+
const line = lines[i];
|
|
602
|
+
if (line === undefined) {
|
|
603
|
+
continue;
|
|
604
|
+
}
|
|
605
|
+
const match = line.match(LIB_REGEX_PATTERN_DTS_ARRAY_ALIAS);
|
|
606
|
+
if (match !== null
|
|
607
|
+
&& match[1] !== undefined
|
|
608
|
+
&& match[2] !== undefined) {
|
|
609
|
+
const arrayType = {
|
|
610
|
+
arrayTypeName: match[1],
|
|
611
|
+
elementTypeName: match[2],
|
|
612
|
+
lineIndex: i,
|
|
613
|
+
};
|
|
614
|
+
arrayTypes.push(arrayType);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
return arrayTypes;
|
|
618
|
+
}
|
|
619
|
+
export function extractFunctionReturns(filePath, content) {
|
|
620
|
+
const sourceFile = parseSourceFile(filePath, content);
|
|
621
|
+
const returnRecords = [];
|
|
622
|
+
function visit(node) {
|
|
623
|
+
if (isFunctionDeclaration(node) === true
|
|
624
|
+
|| isMethodDeclaration(node) === true
|
|
625
|
+
|| isConstructorDeclaration(node) === true) {
|
|
626
|
+
const fnNode = node;
|
|
627
|
+
const typeNode = fnNode['type'];
|
|
628
|
+
if (typeNode !== undefined) {
|
|
629
|
+
let returnType = '';
|
|
630
|
+
let typeGuardFlag = false;
|
|
631
|
+
if (isTypePredicateNode(typeNode) === true) {
|
|
632
|
+
typeGuardFlag = true;
|
|
633
|
+
const predicateNode = typeNode;
|
|
634
|
+
if (predicateNode['type'] !== undefined
|
|
635
|
+
&& isTypeReferenceNode(predicateNode['type']) === true
|
|
636
|
+
&& isIdentifier(predicateNode['type']['typeName']) === true) {
|
|
637
|
+
returnType = predicateNode['type']['typeName']['text'];
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
else if (isTypeReferenceNode(typeNode) === true && isIdentifier(typeNode['typeName']) === true) {
|
|
641
|
+
returnType = typeNode['typeName']['text'];
|
|
642
|
+
}
|
|
643
|
+
if (returnType !== '') {
|
|
644
|
+
const lineNumber = sourceFile.getLineAndCharacterOfPosition(node.getStart()).line + 1;
|
|
645
|
+
const returnRecord = {
|
|
646
|
+
returnType,
|
|
647
|
+
isTypeGuard: typeGuardFlag,
|
|
648
|
+
lineNumber,
|
|
649
|
+
};
|
|
650
|
+
returnRecords.push(returnRecord);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
forEachChild(node, visit);
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
forEachChild(sourceFile, visit);
|
|
658
|
+
return returnRecords;
|
|
659
|
+
}
|
|
660
|
+
export function isAliasToForeignType(typeName, dtsContent, classPrefix, standaloneTypeFiles = []) {
|
|
661
|
+
const escapedTypeName = typeName.replace(new RegExp(LIB_REGEX_PATTERN_REGEX_SPECIAL_CHARS.source, 'g'), '\\$&');
|
|
662
|
+
const pattern = new RegExp(`^export type ${escapedTypeName}\\s*=\\s*([^;]+);`, 'm');
|
|
663
|
+
const match = dtsContent.match(pattern);
|
|
664
|
+
if (match === null || match[1] === undefined) {
|
|
665
|
+
return false;
|
|
666
|
+
}
|
|
667
|
+
let rhs = match[1].trim();
|
|
668
|
+
rhs = rhs.replace(new RegExp(LIB_REGEX_PATTERN_ANGLE_BRACKET_GENERIC.source, 'g'), '');
|
|
669
|
+
rhs = rhs.replace(new RegExp(LIB_REGEX_PATTERN_EMPTY_ARRAY_BRACKETS.source, 'g'), '');
|
|
670
|
+
if (LIB_REGEX_PATTERN_COMPLEX_TYPE_RHS_CHARS.test(rhs) === true) {
|
|
671
|
+
return false;
|
|
672
|
+
}
|
|
673
|
+
const typeMatch = rhs.trim().match(LIB_REGEX_PATTERN_SINGLE_PASCAL_TYPE);
|
|
674
|
+
if (typeMatch === null || typeMatch[1] === undefined) {
|
|
675
|
+
return false;
|
|
676
|
+
}
|
|
677
|
+
const leftmostType = typeMatch[1];
|
|
678
|
+
if (leftmostType.startsWith(`${classPrefix}_`) === true) {
|
|
679
|
+
return false;
|
|
680
|
+
}
|
|
681
|
+
let importStart = dtsContent.indexOf('import ');
|
|
682
|
+
let importSource = null;
|
|
683
|
+
while (importStart !== -1) {
|
|
684
|
+
const braceOpen = dtsContent.indexOf('{', importStart);
|
|
685
|
+
const braceClose = dtsContent.indexOf('}', braceOpen);
|
|
686
|
+
const quoteStart = dtsContent.indexOf('\'', braceClose);
|
|
687
|
+
const quoteEnd = dtsContent.indexOf('\'', quoteStart + 1);
|
|
688
|
+
if (braceOpen === -1
|
|
689
|
+
|| braceClose === -1
|
|
690
|
+
|| quoteStart === -1
|
|
691
|
+
|| quoteEnd === -1) {
|
|
692
|
+
break;
|
|
693
|
+
}
|
|
694
|
+
const specifiers = dtsContent.slice(braceOpen + 1, braceClose).split(',').map((specifier) => specifier.trim());
|
|
695
|
+
if (specifiers.includes(leftmostType) === true) {
|
|
696
|
+
importSource = dtsContent.slice(quoteStart + 1, quoteEnd);
|
|
697
|
+
break;
|
|
698
|
+
}
|
|
699
|
+
importStart = dtsContent.indexOf('import ', quoteEnd + 1);
|
|
700
|
+
}
|
|
701
|
+
if (importSource === null) {
|
|
702
|
+
return false;
|
|
703
|
+
}
|
|
704
|
+
for (const standalonePattern of standaloneTypeFiles) {
|
|
705
|
+
if (importSource.endsWith(standalonePattern) === true) {
|
|
706
|
+
return false;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
return LIB_REGEX_PATTERN_EXT_D_TS_SUFFIX.test(importSource);
|
|
710
|
+
}
|
|
711
|
+
export function isLocallyDefined(typeName, dtsContent) {
|
|
712
|
+
const escapedTypeName = typeName.replace(new RegExp(LIB_REGEX_PATTERN_REGEX_SPECIAL_CHARS.source, 'g'), '\\$&');
|
|
713
|
+
const pattern = new RegExp(`^export type ${escapedTypeName}\\b`, 'm');
|
|
714
|
+
return pattern.test(dtsContent);
|
|
715
|
+
}
|
|
716
|
+
export function isReservedSuffix(typeName) {
|
|
717
|
+
return (typeName.endsWith('_Returns') === true
|
|
718
|
+
|| typeName.endsWith('_TypeGuard') === true
|
|
719
|
+
|| typeName.endsWith('_Return') === true
|
|
720
|
+
|| typeName.endsWith('Returns') === true
|
|
721
|
+
|| typeName.endsWith('TypeGuard') === true
|
|
722
|
+
|| typeName.endsWith('Return') === true);
|
|
723
|
+
}
|
|
724
|
+
export function validateLeaf(varName, typeName, sourceSection, classPrefix) {
|
|
725
|
+
const stripped = stripUnderscorePrefix(varName);
|
|
726
|
+
const titleVar = stripped.charAt(0).toUpperCase() + stripped.slice(1);
|
|
727
|
+
const expectedSection = `${sourceSection}_${titleVar}`;
|
|
728
|
+
const expectedClass = `${classPrefix}_${titleVar}`;
|
|
729
|
+
if (typeName === expectedSection || typeName === expectedClass) {
|
|
730
|
+
return null;
|
|
731
|
+
}
|
|
732
|
+
let actualLeaf = typeName;
|
|
733
|
+
if (typeName.startsWith(`${sourceSection}_`) === true) {
|
|
734
|
+
actualLeaf = typeName.slice(sourceSection.length + 1);
|
|
735
|
+
}
|
|
736
|
+
else if (typeName.startsWith(`${classPrefix}_`) === true) {
|
|
737
|
+
actualLeaf = typeName.slice(classPrefix.length + 1);
|
|
738
|
+
}
|
|
739
|
+
return {
|
|
740
|
+
actualLeaf,
|
|
741
|
+
expectedLeaf: titleVar,
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
export function validateReturnType(returnType, typeGuardFlag) {
|
|
745
|
+
if (returnType.endsWith('_Return') === true || returnType.endsWith('Return') === true) {
|
|
746
|
+
return `Return type '${returnType}' uses banned singular 'Return' suffix; rename to use 'Returns' (plural).`;
|
|
747
|
+
}
|
|
748
|
+
if (typeGuardFlag === true) {
|
|
749
|
+
if (returnType.endsWith('_TypeGuard') === false && returnType.endsWith('TypeGuard') === false) {
|
|
750
|
+
return `Type-guard return type '${returnType}' must end in 'TypeGuard'.`;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
else if (returnType.endsWith('_Returns') === false && returnType.endsWith('Returns') === false) {
|
|
754
|
+
if (returnType.endsWith('_TypeGuard') === true || returnType.endsWith('TypeGuard') === true) {
|
|
755
|
+
return `Return type '${returnType}' ends in 'TypeGuard' but the function does not use 'value is T' form; either rename to '_Returns' or rewrite as a type guard.`;
|
|
756
|
+
}
|
|
757
|
+
return `Function return type '${returnType}' must end in 'Returns' (plural).`;
|
|
758
|
+
}
|
|
759
|
+
return null;
|
|
760
|
+
}
|
|
761
|
+
export function runRulePipeline(filePath, sourceContent, dtsContent, classPrefix) {
|
|
762
|
+
const sectionMap = buildSourceSectionMap(filePath, sourceContent, classPrefix);
|
|
763
|
+
const lines = sourceContent.split('\n');
|
|
764
|
+
const declarations = extractBodyDeclarations(lines);
|
|
765
|
+
const callbacks = detectInlineTypedCallbacks(filePath, sourceContent);
|
|
766
|
+
const fnReturnRecords = extractFunctionReturns(filePath, sourceContent);
|
|
767
|
+
const violations = [];
|
|
768
|
+
for (const callback of callbacks) {
|
|
769
|
+
violations.push(`7.4: ${callback['paramName']}: ${callback['typeName']}`);
|
|
770
|
+
}
|
|
771
|
+
for (const declaration of declarations) {
|
|
772
|
+
const sourceSection = sectionMap.get(declaration['lineNumber']) ?? classPrefix;
|
|
773
|
+
if (isReservedSuffix(declaration['typeName']) === true) {
|
|
774
|
+
violations.push(`7.3: ${declaration['varName']}: ${declaration['typeName']}`);
|
|
775
|
+
continue;
|
|
776
|
+
}
|
|
777
|
+
const leafResult = validateLeaf(declaration['varName'], declaration['typeName'], sourceSection, classPrefix);
|
|
778
|
+
if (leafResult !== null) {
|
|
779
|
+
violations.push(`7.1: ${declaration['varName']}: ${declaration['typeName']}`);
|
|
780
|
+
}
|
|
781
|
+
if (isLocallyDefined(declaration['typeName'], dtsContent) === false) {
|
|
782
|
+
violations.push(`7.2-not-defined: ${declaration['typeName']}`);
|
|
783
|
+
}
|
|
784
|
+
else if (isAliasToForeignType(declaration['typeName'], dtsContent, classPrefix) === true) {
|
|
785
|
+
violations.push(`7.2-alias: ${declaration['typeName']}`);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
for (const fnReturn of fnReturnRecords) {
|
|
789
|
+
const reason = validateReturnType(fnReturn['returnType'], fnReturn['isTypeGuard']);
|
|
790
|
+
if (reason !== null) {
|
|
791
|
+
violations.push(`7.5/6/7: ${fnReturn['returnType']}`);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
return violations;
|
|
795
|
+
}
|
|
796
|
+
//# sourceMappingURL=type-declaration-engine.js.map
|