diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 1ed453a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,10 +0,0 @@ -root = true - -[*] -end_of_line = lf -insert_final_newline = true - -[*.{js,json,yml}] -charset = utf-8 -indent_style = space -indent_size = 2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba76a72..80ed214 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,7 @@ jobs: node-version-file: .nvmrc cache: "yarn" - run: yarn install --immutable + - run: yarn format:check - run: yarn lint - run: yarn build - run: yarn typecheck diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..a532862 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,13 @@ +.yarn/* + +.pnp.cjs +.pnp.loader.mjs + +node_modules +coverage +dist +esm +.junit +out +*.d.ts +*.tgz \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..c58e5ae --- /dev/null +++ b/.prettierrc @@ -0,0 +1,13 @@ +{ + "arrowParens": "avoid", + "bracketSameLine": false, + "bracketSpacing": true, + "endOfLine": "lf", + "jsxSingleQuote": false, + "printWidth": 120, + "proseWrap": "preserve", + "quoteProps": "as-needed", + "semi": true, + "tabWidth": 2, + "trailingComma": "es5" +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 8e8adf9..da487ff 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,6 +1,3 @@ { - "recommendations": [ - "arcanis.vscode-zipfs", - "dbaeumer.vscode-eslint" - ] + "recommendations": ["arcanis.vscode-zipfs", "dbaeumer.vscode-eslint", "esbenp.prettier-vscode"] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 4082042..1dd64dc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,5 +5,14 @@ }, "typescript.tsdk": ".yarn/sdks/typescript/lib", "typescript.enablePromptUseWorkspaceTsdk": true, - "eslint.nodePath": ".yarn/sdks" + "eslint.nodePath": ".yarn/sdks", + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true, + "prettier.prettierPath": ".yarn/sdks/prettier/index.cjs", + "[typescript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[typescriptreact]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + } } diff --git a/.yarn/sdks/eslint/bin/eslint.js b/.yarn/sdks/eslint/bin/eslint.js index e6604ff..9d83e3a 100755 --- a/.yarn/sdks/eslint/bin/eslint.js +++ b/.yarn/sdks/eslint/bin/eslint.js @@ -1,11 +1,11 @@ #!/usr/bin/env node -const {existsSync} = require(`fs`); -const {createRequire, register} = require(`module`); -const {resolve} = require(`path`); -const {pathToFileURL} = require(`url`); +const { existsSync } = require(`fs`); +const { createRequire, register } = require(`module`); +const { resolve } = require(`path`); +const { pathToFileURL } = require(`url`); -const relPnpApiPath = "../../../../.pnp.cjs"; +const relPnpApiPath = '../../../../.pnp.cjs'; const absPnpApiPath = resolve(__dirname, relPnpApiPath); const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); diff --git a/.yarn/sdks/eslint/lib/api.js b/.yarn/sdks/eslint/lib/api.js index 8addf97..2d2de8f 100644 --- a/.yarn/sdks/eslint/lib/api.js +++ b/.yarn/sdks/eslint/lib/api.js @@ -1,11 +1,11 @@ #!/usr/bin/env node -const {existsSync} = require(`fs`); -const {createRequire, register} = require(`module`); -const {resolve} = require(`path`); -const {pathToFileURL} = require(`url`); +const { existsSync } = require(`fs`); +const { createRequire, register } = require(`module`); +const { resolve } = require(`path`); +const { pathToFileURL } = require(`url`); -const relPnpApiPath = "../../../../.pnp.cjs"; +const relPnpApiPath = '../../../../.pnp.cjs'; const absPnpApiPath = resolve(__dirname, relPnpApiPath); const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); diff --git a/.yarn/sdks/eslint/lib/config-api.js b/.yarn/sdks/eslint/lib/config-api.js new file mode 100644 index 0000000..cf1d214 --- /dev/null +++ b/.yarn/sdks/eslint/lib/config-api.js @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +const { existsSync } = require(`fs`); +const { createRequire, register } = require(`module`); +const { resolve } = require(`path`); +const { pathToFileURL } = require(`url`); + +const relPnpApiPath = '../../../../.pnp.cjs'; + +const absPnpApiPath = resolve(__dirname, relPnpApiPath); +const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); +const absRequire = createRequire(absPnpApiPath); + +const absPnpLoaderPath = resolve(absPnpApiPath, `../.pnp.loader.mjs`); +const isPnpLoaderEnabled = existsSync(absPnpLoaderPath); + +if (existsSync(absPnpApiPath)) { + if (!process.versions.pnp) { + // Setup the environment to be able to require eslint/config + require(absPnpApiPath).setup(); + if (isPnpLoaderEnabled && register) { + register(pathToFileURL(absPnpLoaderPath)); + } + } +} + +const wrapWithUserWrapper = existsSync(absUserWrapperPath) + ? exports => absRequire(absUserWrapperPath)(exports) + : exports => exports; + +// Defer to the real eslint/config your application uses +module.exports = wrapWithUserWrapper(absRequire(`eslint/config`)); diff --git a/.yarn/sdks/eslint/lib/types/config-api.d.ts b/.yarn/sdks/eslint/lib/types/config-api.d.ts new file mode 100644 index 0000000..c1f24ef --- /dev/null +++ b/.yarn/sdks/eslint/lib/types/config-api.d.ts @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +const { existsSync } = require(`fs`); +const { createRequire, register } = require(`module`); +const { resolve } = require(`path`); +const { pathToFileURL } = require(`url`); + +const relPnpApiPath = '../../../../../.pnp.cjs'; + +const absPnpApiPath = resolve(__dirname, relPnpApiPath); +const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); +const absRequire = createRequire(absPnpApiPath); + +const absPnpLoaderPath = resolve(absPnpApiPath, `../.pnp.loader.mjs`); +const isPnpLoaderEnabled = existsSync(absPnpLoaderPath); + +if (existsSync(absPnpApiPath)) { + if (!process.versions.pnp) { + // Setup the environment to be able to require eslint/config + require(absPnpApiPath).setup(); + if (isPnpLoaderEnabled && register) { + register(pathToFileURL(absPnpLoaderPath)); + } + } +} + +const wrapWithUserWrapper = existsSync(absUserWrapperPath) + ? exports => absRequire(absUserWrapperPath)(exports) + : exports => exports; + +// Defer to the real eslint/config your application uses +module.exports = wrapWithUserWrapper(absRequire(`eslint/config`)); diff --git a/.yarn/sdks/eslint/lib/types/index.d.ts b/.yarn/sdks/eslint/lib/types/index.d.ts new file mode 100644 index 0000000..7cfc9bc --- /dev/null +++ b/.yarn/sdks/eslint/lib/types/index.d.ts @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +const { existsSync } = require(`fs`); +const { createRequire, register } = require(`module`); +const { resolve } = require(`path`); +const { pathToFileURL } = require(`url`); + +const relPnpApiPath = '../../../../../.pnp.cjs'; + +const absPnpApiPath = resolve(__dirname, relPnpApiPath); +const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); +const absRequire = createRequire(absPnpApiPath); + +const absPnpLoaderPath = resolve(absPnpApiPath, `../.pnp.loader.mjs`); +const isPnpLoaderEnabled = existsSync(absPnpLoaderPath); + +if (existsSync(absPnpApiPath)) { + if (!process.versions.pnp) { + // Setup the environment to be able to require eslint + require(absPnpApiPath).setup(); + if (isPnpLoaderEnabled && register) { + register(pathToFileURL(absPnpLoaderPath)); + } + } +} + +const wrapWithUserWrapper = existsSync(absUserWrapperPath) + ? exports => absRequire(absUserWrapperPath)(exports) + : exports => exports; + +// Defer to the real eslint your application uses +module.exports = wrapWithUserWrapper(absRequire(`eslint`)); diff --git a/.yarn/sdks/eslint/lib/types/rules.d.ts b/.yarn/sdks/eslint/lib/types/rules.d.ts new file mode 100644 index 0000000..b5933ea --- /dev/null +++ b/.yarn/sdks/eslint/lib/types/rules.d.ts @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +const { existsSync } = require(`fs`); +const { createRequire, register } = require(`module`); +const { resolve } = require(`path`); +const { pathToFileURL } = require(`url`); + +const relPnpApiPath = '../../../../../.pnp.cjs'; + +const absPnpApiPath = resolve(__dirname, relPnpApiPath); +const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); +const absRequire = createRequire(absPnpApiPath); + +const absPnpLoaderPath = resolve(absPnpApiPath, `../.pnp.loader.mjs`); +const isPnpLoaderEnabled = existsSync(absPnpLoaderPath); + +if (existsSync(absPnpApiPath)) { + if (!process.versions.pnp) { + // Setup the environment to be able to require eslint/rules + require(absPnpApiPath).setup(); + if (isPnpLoaderEnabled && register) { + register(pathToFileURL(absPnpLoaderPath)); + } + } +} + +const wrapWithUserWrapper = existsSync(absUserWrapperPath) + ? exports => absRequire(absUserWrapperPath)(exports) + : exports => exports; + +// Defer to the real eslint/rules your application uses +module.exports = wrapWithUserWrapper(absRequire(`eslint/rules`)); diff --git a/.yarn/sdks/eslint/lib/types/universal.d.ts b/.yarn/sdks/eslint/lib/types/universal.d.ts new file mode 100644 index 0000000..a5e4717 --- /dev/null +++ b/.yarn/sdks/eslint/lib/types/universal.d.ts @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +const { existsSync } = require(`fs`); +const { createRequire, register } = require(`module`); +const { resolve } = require(`path`); +const { pathToFileURL } = require(`url`); + +const relPnpApiPath = '../../../../../.pnp.cjs'; + +const absPnpApiPath = resolve(__dirname, relPnpApiPath); +const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); +const absRequire = createRequire(absPnpApiPath); + +const absPnpLoaderPath = resolve(absPnpApiPath, `../.pnp.loader.mjs`); +const isPnpLoaderEnabled = existsSync(absPnpLoaderPath); + +if (existsSync(absPnpApiPath)) { + if (!process.versions.pnp) { + // Setup the environment to be able to require eslint/universal + require(absPnpApiPath).setup(); + if (isPnpLoaderEnabled && register) { + register(pathToFileURL(absPnpLoaderPath)); + } + } +} + +const wrapWithUserWrapper = existsSync(absUserWrapperPath) + ? exports => absRequire(absUserWrapperPath)(exports) + : exports => exports; + +// Defer to the real eslint/universal your application uses +module.exports = wrapWithUserWrapper(absRequire(`eslint/universal`)); diff --git a/.yarn/sdks/eslint/lib/types/use-at-your-own-risk.d.ts b/.yarn/sdks/eslint/lib/types/use-at-your-own-risk.d.ts new file mode 100644 index 0000000..b238a39 --- /dev/null +++ b/.yarn/sdks/eslint/lib/types/use-at-your-own-risk.d.ts @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +const { existsSync } = require(`fs`); +const { createRequire, register } = require(`module`); +const { resolve } = require(`path`); +const { pathToFileURL } = require(`url`); + +const relPnpApiPath = '../../../../../.pnp.cjs'; + +const absPnpApiPath = resolve(__dirname, relPnpApiPath); +const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); +const absRequire = createRequire(absPnpApiPath); + +const absPnpLoaderPath = resolve(absPnpApiPath, `../.pnp.loader.mjs`); +const isPnpLoaderEnabled = existsSync(absPnpLoaderPath); + +if (existsSync(absPnpApiPath)) { + if (!process.versions.pnp) { + // Setup the environment to be able to require eslint/use-at-your-own-risk + require(absPnpApiPath).setup(); + if (isPnpLoaderEnabled && register) { + register(pathToFileURL(absPnpLoaderPath)); + } + } +} + +const wrapWithUserWrapper = existsSync(absUserWrapperPath) + ? exports => absRequire(absUserWrapperPath)(exports) + : exports => exports; + +// Defer to the real eslint/use-at-your-own-risk your application uses +module.exports = wrapWithUserWrapper(absRequire(`eslint/use-at-your-own-risk`)); diff --git a/.yarn/sdks/eslint/lib/universal.js b/.yarn/sdks/eslint/lib/universal.js new file mode 100644 index 0000000..66096f7 --- /dev/null +++ b/.yarn/sdks/eslint/lib/universal.js @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +const { existsSync } = require(`fs`); +const { createRequire, register } = require(`module`); +const { resolve } = require(`path`); +const { pathToFileURL } = require(`url`); + +const relPnpApiPath = '../../../../.pnp.cjs'; + +const absPnpApiPath = resolve(__dirname, relPnpApiPath); +const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); +const absRequire = createRequire(absPnpApiPath); + +const absPnpLoaderPath = resolve(absPnpApiPath, `../.pnp.loader.mjs`); +const isPnpLoaderEnabled = existsSync(absPnpLoaderPath); + +if (existsSync(absPnpApiPath)) { + if (!process.versions.pnp) { + // Setup the environment to be able to require eslint/universal + require(absPnpApiPath).setup(); + if (isPnpLoaderEnabled && register) { + register(pathToFileURL(absPnpLoaderPath)); + } + } +} + +const wrapWithUserWrapper = existsSync(absUserWrapperPath) + ? exports => absRequire(absUserWrapperPath)(exports) + : exports => exports; + +// Defer to the real eslint/universal your application uses +module.exports = wrapWithUserWrapper(absRequire(`eslint/universal`)); diff --git a/.yarn/sdks/eslint/lib/unsupported-api.js b/.yarn/sdks/eslint/lib/unsupported-api.js index c2b464c..688b652 100644 --- a/.yarn/sdks/eslint/lib/unsupported-api.js +++ b/.yarn/sdks/eslint/lib/unsupported-api.js @@ -1,11 +1,11 @@ #!/usr/bin/env node -const {existsSync} = require(`fs`); -const {createRequire, register} = require(`module`); -const {resolve} = require(`path`); -const {pathToFileURL} = require(`url`); +const { existsSync } = require(`fs`); +const { createRequire, register } = require(`module`); +const { resolve } = require(`path`); +const { pathToFileURL } = require(`url`); -const relPnpApiPath = "../../../../.pnp.cjs"; +const relPnpApiPath = '../../../../.pnp.cjs'; const absPnpApiPath = resolve(__dirname, relPnpApiPath); const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); diff --git a/.yarn/sdks/eslint/package.json b/.yarn/sdks/eslint/package.json index e597c7c..4c600eb 100644 --- a/.yarn/sdks/eslint/package.json +++ b/.yarn/sdks/eslint/package.json @@ -1,14 +1,31 @@ { "name": "eslint", - "version": "9.9.1-sdk", + "version": "9.31.0-sdk", "main": "./lib/api.js", "type": "commonjs", "bin": { "eslint": "./bin/eslint.js" }, "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "default": "./lib/api.js" + }, + "./config": { + "types": "./lib/types/config-api.d.ts", + "default": "./lib/config-api.js" + }, "./package.json": "./package.json", - ".": "./lib/api.js", - "./use-at-your-own-risk": "./lib/unsupported-api.js" + "./use-at-your-own-risk": { + "types": "./lib/types/use-at-your-own-risk.d.ts", + "default": "./lib/unsupported-api.js" + }, + "./rules": { + "types": "./lib/types/rules.d.ts" + }, + "./universal": { + "types": "./lib/types/universal.d.ts", + "default": "./lib/universal.js" + } } } diff --git a/.yarn/sdks/prettier/bin/prettier.cjs b/.yarn/sdks/prettier/bin/prettier.cjs new file mode 100755 index 0000000..c313aed --- /dev/null +++ b/.yarn/sdks/prettier/bin/prettier.cjs @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +const { existsSync } = require(`fs`); +const { createRequire, register } = require(`module`); +const { resolve } = require(`path`); +const { pathToFileURL } = require(`url`); + +const relPnpApiPath = '../../../../.pnp.cjs'; + +const absPnpApiPath = resolve(__dirname, relPnpApiPath); +const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); +const absRequire = createRequire(absPnpApiPath); + +const absPnpLoaderPath = resolve(absPnpApiPath, `../.pnp.loader.mjs`); +const isPnpLoaderEnabled = existsSync(absPnpLoaderPath); + +if (existsSync(absPnpApiPath)) { + if (!process.versions.pnp) { + // Setup the environment to be able to require prettier/bin/prettier.cjs + require(absPnpApiPath).setup(); + if (isPnpLoaderEnabled && register) { + register(pathToFileURL(absPnpLoaderPath)); + } + } +} + +const wrapWithUserWrapper = existsSync(absUserWrapperPath) + ? exports => absRequire(absUserWrapperPath)(exports) + : exports => exports; + +// Defer to the real prettier/bin/prettier.cjs your application uses +module.exports = wrapWithUserWrapper(absRequire(`prettier/bin/prettier.cjs`)); diff --git a/.yarn/sdks/prettier/index.cjs b/.yarn/sdks/prettier/index.cjs new file mode 100644 index 0000000..1f696d7 --- /dev/null +++ b/.yarn/sdks/prettier/index.cjs @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +const { existsSync } = require(`fs`); +const { createRequire, register } = require(`module`); +const { resolve } = require(`path`); +const { pathToFileURL } = require(`url`); + +const relPnpApiPath = '../../../.pnp.cjs'; + +const absPnpApiPath = resolve(__dirname, relPnpApiPath); +const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); +const absRequire = createRequire(absPnpApiPath); + +const absPnpLoaderPath = resolve(absPnpApiPath, `../.pnp.loader.mjs`); +const isPnpLoaderEnabled = existsSync(absPnpLoaderPath); + +if (existsSync(absPnpApiPath)) { + if (!process.versions.pnp) { + // Setup the environment to be able to require prettier + require(absPnpApiPath).setup(); + if (isPnpLoaderEnabled && register) { + register(pathToFileURL(absPnpLoaderPath)); + } + } +} + +const wrapWithUserWrapper = existsSync(absUserWrapperPath) + ? exports => absRequire(absUserWrapperPath)(exports) + : exports => exports; + +// Defer to the real prettier your application uses +module.exports = wrapWithUserWrapper(absRequire(`prettier`)); diff --git a/.yarn/sdks/prettier/package.json b/.yarn/sdks/prettier/package.json new file mode 100644 index 0000000..ba0b314 --- /dev/null +++ b/.yarn/sdks/prettier/package.json @@ -0,0 +1,7 @@ +{ + "name": "prettier", + "version": "3.8.1-sdk", + "main": "./index.cjs", + "type": "commonjs", + "bin": "./bin/prettier.cjs" +} diff --git a/.yarn/sdks/typescript/bin/tsc b/.yarn/sdks/typescript/bin/tsc index 867a7bd..a54a860 100755 --- a/.yarn/sdks/typescript/bin/tsc +++ b/.yarn/sdks/typescript/bin/tsc @@ -1,11 +1,11 @@ #!/usr/bin/env node -const {existsSync} = require(`fs`); -const {createRequire, register} = require(`module`); -const {resolve} = require(`path`); -const {pathToFileURL} = require(`url`); +const { existsSync } = require(`fs`); +const { createRequire, register } = require(`module`); +const { resolve } = require(`path`); +const { pathToFileURL } = require(`url`); -const relPnpApiPath = "../../../../.pnp.cjs"; +const relPnpApiPath = '../../../../.pnp.cjs'; const absPnpApiPath = resolve(__dirname, relPnpApiPath); const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); diff --git a/.yarn/sdks/typescript/bin/tsserver b/.yarn/sdks/typescript/bin/tsserver index 3fc5aa3..a3b4ef5 100755 --- a/.yarn/sdks/typescript/bin/tsserver +++ b/.yarn/sdks/typescript/bin/tsserver @@ -1,11 +1,11 @@ #!/usr/bin/env node -const {existsSync} = require(`fs`); -const {createRequire, register} = require(`module`); -const {resolve} = require(`path`); -const {pathToFileURL} = require(`url`); +const { existsSync } = require(`fs`); +const { createRequire, register } = require(`module`); +const { resolve } = require(`path`); +const { pathToFileURL } = require(`url`); -const relPnpApiPath = "../../../../.pnp.cjs"; +const relPnpApiPath = '../../../../.pnp.cjs'; const absPnpApiPath = resolve(__dirname, relPnpApiPath); const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); diff --git a/.yarn/sdks/typescript/lib/tsc.js b/.yarn/sdks/typescript/lib/tsc.js index da411bd..a162180 100644 --- a/.yarn/sdks/typescript/lib/tsc.js +++ b/.yarn/sdks/typescript/lib/tsc.js @@ -1,11 +1,11 @@ #!/usr/bin/env node -const {existsSync} = require(`fs`); -const {createRequire, register} = require(`module`); -const {resolve} = require(`path`); -const {pathToFileURL} = require(`url`); +const { existsSync } = require(`fs`); +const { createRequire, register } = require(`module`); +const { resolve } = require(`path`); +const { pathToFileURL } = require(`url`); -const relPnpApiPath = "../../../../.pnp.cjs"; +const relPnpApiPath = '../../../../.pnp.cjs'; const absPnpApiPath = resolve(__dirname, relPnpApiPath); const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); diff --git a/.yarn/sdks/typescript/lib/tsserver.js b/.yarn/sdks/typescript/lib/tsserver.js index 6249c46..b988748 100644 --- a/.yarn/sdks/typescript/lib/tsserver.js +++ b/.yarn/sdks/typescript/lib/tsserver.js @@ -1,11 +1,11 @@ #!/usr/bin/env node -const {existsSync} = require(`fs`); -const {createRequire, register} = require(`module`); -const {resolve} = require(`path`); -const {pathToFileURL} = require(`url`); +const { existsSync } = require(`fs`); +const { createRequire, register } = require(`module`); +const { resolve } = require(`path`); +const { pathToFileURL } = require(`url`); -const relPnpApiPath = "../../../../.pnp.cjs"; +const relPnpApiPath = '../../../../.pnp.cjs'; const absPnpApiPath = resolve(__dirname, relPnpApiPath); const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); @@ -37,16 +37,18 @@ const moduleWrapperFn = tsserver => { return tsserver; } - const {isAbsolute} = require(`path`); + const { isAbsolute } = require(`path`); const pnpApi = require(`pnpapi`); const isVirtual = str => str.match(/\/(\$\$virtual|__virtual__)\//); - const isPortal = str => str.startsWith("portal:/"); + const isPortal = str => str.startsWith('portal:/'); const normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`); - const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => { - return `${locator.name}@${locator.reference}`; - })); + const dependencyTreeRoots = new Set( + pnpApi.getDependencyTreeRoots().map(locator => { + return `${locator.name}@${locator.reference}`; + }) + ); // VSCode sends the zip paths to TS using the "zip://" prefix, that TS // doesn't understand. This layer makes sure to remove the protocol @@ -68,7 +70,10 @@ const moduleWrapperFn = tsserver => { const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str; if (resolved) { const locator = pnpApi.findPackageLocator(resolved); - if (locator && (dependencyTreeRoots.has(`${locator.name}@${locator.reference}`) || isPortal(locator.reference))) { + if ( + locator && + (dependencyTreeRoots.has(`${locator.name}@${locator.reference}`) || isPortal(locator.reference)) + ) { str = resolved; } } @@ -96,41 +101,55 @@ const moduleWrapperFn = tsserver => { // Before | ^/zip/c:/foo/bar.zip/package.json // After | ^/zip//c:/foo/bar.zip/package.json // - case `vscode <1.61`: { - str = `^zip:${str}`; - } break; + case `vscode <1.61`: + { + str = `^zip:${str}`; + } + break; - case `vscode <1.66`: { - str = `^/zip/${str}`; - } break; + case `vscode <1.66`: + { + str = `^/zip/${str}`; + } + break; - case `vscode <1.68`: { - str = `^/zip${str}`; - } break; + case `vscode <1.68`: + { + str = `^/zip${str}`; + } + break; - case `vscode`: { - str = `^/zip/${str}`; - } break; + case `vscode`: + { + str = `^/zip/${str}`; + } + break; // To make "go to definition" work, // We have to resolve the actual file system path from virtual path // and convert scheme to supported by [vim-rzip](https://github.com/lbrayner/vim-rzip) - case `coc-nvim`: { - str = normalize(resolved).replace(/\.zip\//, `.zip::`); - str = resolve(`zipfile:${str}`); - } break; + case `coc-nvim`: + { + str = normalize(resolved).replace(/\.zip\//, `.zip::`); + str = resolve(`zipfile:${str}`); + } + break; // Support neovim native LSP and [typescript-language-server](https://github.com/theia-ide/typescript-language-server) // We have to resolve the actual file system path from virtual path, // everything else is up to neovim - case `neovim`: { - str = normalize(resolved).replace(/\.zip\//, `.zip::`); - str = `zipfile://${str}`; - } break; - - default: { - str = `zip:${str}`; - } break; + case `neovim`: + { + str = normalize(resolved).replace(/\.zip\//, `.zip::`); + str = `zipfile://${str}`; + } + break; + + default: + { + str = `zip:${str}`; + } + break; } } else { str = str.replace(/^\/?/, process.platform === `win32` ? `` : `/`); @@ -142,26 +161,30 @@ const moduleWrapperFn = tsserver => { function fromEditorPath(str) { switch (hostInfo) { - case `coc-nvim`: { - str = str.replace(/\.zip::/, `.zip/`); - // The path for coc-nvim is in format of //zipfile://.yarn/... - // So in order to convert it back, we use .* to match all the thing - // before `zipfile:` - return process.platform === `win32` - ? str.replace(/^.*zipfile:\//, ``) - : str.replace(/^.*zipfile:/, ``); - } break; - - case `neovim`: { - str = str.replace(/\.zip::/, `.zip/`); - // The path for neovim is in format of zipfile:////.yarn/... - return str.replace(/^zipfile:\/\//, ``); - } break; + case `coc-nvim`: + { + str = str.replace(/\.zip::/, `.zip/`); + // The path for coc-nvim is in format of //zipfile://.yarn/... + // So in order to convert it back, we use .* to match all the thing + // before `zipfile:` + return process.platform === `win32` ? str.replace(/^.*zipfile:\//, ``) : str.replace(/^.*zipfile:/, ``); + } + break; + + case `neovim`: + { + str = str.replace(/\.zip::/, `.zip/`); + // The path for neovim is in format of zipfile:////.yarn/... + return str.replace(/^zipfile:\/\//, ``); + } + break; case `vscode`: - default: { - return str.replace(/^\^?(zip:|\/zip(\/ts-nul-authority)?)\/+/, process.platform === `win32` ? `` : `/`) - } break; + default: + { + return str.replace(/^\^?(zip:|\/zip(\/ts-nul-authority)?)\/+/, process.platform === `win32` ? `` : `/`); + } + break; } } @@ -173,8 +196,8 @@ const moduleWrapperFn = tsserver => { // TypeScript already does local loads and if this code is running the user trusts the workspace // https://github.com/microsoft/vscode/issues/45856 const ConfiguredProject = tsserver.server.ConfiguredProject; - const {enablePluginsWithOptions: originalEnablePluginsWithOptions} = ConfiguredProject.prototype; - ConfiguredProject.prototype.enablePluginsWithOptions = function() { + const { enablePluginsWithOptions: originalEnablePluginsWithOptions } = ConfiguredProject.prototype; + ConfiguredProject.prototype.enablePluginsWithOptions = function () { this.projectService.allowLocalPluginLoads = true; return originalEnablePluginsWithOptions.apply(this, arguments); }; @@ -184,7 +207,7 @@ const moduleWrapperFn = tsserver => { // like an absolute path of ours and normalize it. const Session = tsserver.server.Session; - const {onMessage: originalOnMessage, send: originalSend} = Session.prototype; + const { onMessage: originalOnMessage, send: originalSend } = Session.prototype; let hostInfo = `unknown`; Object.assign(Session.prototype, { @@ -200,10 +223,12 @@ const moduleWrapperFn = tsserver => { ) { hostInfo = parsedMessage.arguments.hostInfo; if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK) { - const [, major, minor] = (process.env.VSCODE_IPC_HOOK.match( - // The RegExp from https://semver.org/ but without the caret at the start - /(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ - ) ?? []).map(Number) + const [, major, minor] = ( + process.env.VSCODE_IPC_HOOK.match( + // The RegExp from https://semver.org/ but without the caret at the start + /(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ + ) ?? [] + ).map(Number); if (major === 1) { if (minor < 61) { @@ -221,23 +246,27 @@ const moduleWrapperFn = tsserver => { return typeof value === 'string' ? fromEditorPath(value) : value; }); - return originalOnMessage.call( - this, - isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON) - ); + return originalOnMessage.call(this, isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON)); }, send(/** @type {any} */ msg) { - return originalSend.call(this, JSON.parse(JSON.stringify(msg, (key, value) => { - return typeof value === `string` ? toEditorPath(value) : value; - }))); - } + return originalSend.call( + this, + JSON.parse( + JSON.stringify(msg, (key, value) => { + return typeof value === `string` ? toEditorPath(value) : value; + }) + ) + ); + }, }); return tsserver; }; -const [major, minor] = absRequire(`typescript/package.json`).version.split(`.`, 2).map(value => parseInt(value, 10)); +const [major, minor] = absRequire(`typescript/package.json`) + .version.split(`.`, 2) + .map(value => parseInt(value, 10)); // In TypeScript@>=5.5 the tsserver uses the public TypeScript API so that needs to be patched as well. // Ref https://github.com/microsoft/TypeScript/pull/55326 if (major > 5 || (major === 5 && minor >= 5)) { diff --git a/.yarn/sdks/typescript/lib/tsserverlibrary.js b/.yarn/sdks/typescript/lib/tsserverlibrary.js index 0e50e0a..b2b4b7b 100644 --- a/.yarn/sdks/typescript/lib/tsserverlibrary.js +++ b/.yarn/sdks/typescript/lib/tsserverlibrary.js @@ -1,11 +1,11 @@ #!/usr/bin/env node -const {existsSync} = require(`fs`); -const {createRequire, register} = require(`module`); -const {resolve} = require(`path`); -const {pathToFileURL} = require(`url`); +const { existsSync } = require(`fs`); +const { createRequire, register } = require(`module`); +const { resolve } = require(`path`); +const { pathToFileURL } = require(`url`); -const relPnpApiPath = "../../../../.pnp.cjs"; +const relPnpApiPath = '../../../../.pnp.cjs'; const absPnpApiPath = resolve(__dirname, relPnpApiPath); const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); @@ -37,16 +37,18 @@ const moduleWrapperFn = tsserver => { return tsserver; } - const {isAbsolute} = require(`path`); + const { isAbsolute } = require(`path`); const pnpApi = require(`pnpapi`); const isVirtual = str => str.match(/\/(\$\$virtual|__virtual__)\//); - const isPortal = str => str.startsWith("portal:/"); + const isPortal = str => str.startsWith('portal:/'); const normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`); - const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => { - return `${locator.name}@${locator.reference}`; - })); + const dependencyTreeRoots = new Set( + pnpApi.getDependencyTreeRoots().map(locator => { + return `${locator.name}@${locator.reference}`; + }) + ); // VSCode sends the zip paths to TS using the "zip://" prefix, that TS // doesn't understand. This layer makes sure to remove the protocol @@ -68,7 +70,10 @@ const moduleWrapperFn = tsserver => { const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str; if (resolved) { const locator = pnpApi.findPackageLocator(resolved); - if (locator && (dependencyTreeRoots.has(`${locator.name}@${locator.reference}`) || isPortal(locator.reference))) { + if ( + locator && + (dependencyTreeRoots.has(`${locator.name}@${locator.reference}`) || isPortal(locator.reference)) + ) { str = resolved; } } @@ -96,41 +101,55 @@ const moduleWrapperFn = tsserver => { // Before | ^/zip/c:/foo/bar.zip/package.json // After | ^/zip//c:/foo/bar.zip/package.json // - case `vscode <1.61`: { - str = `^zip:${str}`; - } break; + case `vscode <1.61`: + { + str = `^zip:${str}`; + } + break; - case `vscode <1.66`: { - str = `^/zip/${str}`; - } break; + case `vscode <1.66`: + { + str = `^/zip/${str}`; + } + break; - case `vscode <1.68`: { - str = `^/zip${str}`; - } break; + case `vscode <1.68`: + { + str = `^/zip${str}`; + } + break; - case `vscode`: { - str = `^/zip/${str}`; - } break; + case `vscode`: + { + str = `^/zip/${str}`; + } + break; // To make "go to definition" work, // We have to resolve the actual file system path from virtual path // and convert scheme to supported by [vim-rzip](https://github.com/lbrayner/vim-rzip) - case `coc-nvim`: { - str = normalize(resolved).replace(/\.zip\//, `.zip::`); - str = resolve(`zipfile:${str}`); - } break; + case `coc-nvim`: + { + str = normalize(resolved).replace(/\.zip\//, `.zip::`); + str = resolve(`zipfile:${str}`); + } + break; // Support neovim native LSP and [typescript-language-server](https://github.com/theia-ide/typescript-language-server) // We have to resolve the actual file system path from virtual path, // everything else is up to neovim - case `neovim`: { - str = normalize(resolved).replace(/\.zip\//, `.zip::`); - str = `zipfile://${str}`; - } break; - - default: { - str = `zip:${str}`; - } break; + case `neovim`: + { + str = normalize(resolved).replace(/\.zip\//, `.zip::`); + str = `zipfile://${str}`; + } + break; + + default: + { + str = `zip:${str}`; + } + break; } } else { str = str.replace(/^\/?/, process.platform === `win32` ? `` : `/`); @@ -142,26 +161,30 @@ const moduleWrapperFn = tsserver => { function fromEditorPath(str) { switch (hostInfo) { - case `coc-nvim`: { - str = str.replace(/\.zip::/, `.zip/`); - // The path for coc-nvim is in format of //zipfile://.yarn/... - // So in order to convert it back, we use .* to match all the thing - // before `zipfile:` - return process.platform === `win32` - ? str.replace(/^.*zipfile:\//, ``) - : str.replace(/^.*zipfile:/, ``); - } break; - - case `neovim`: { - str = str.replace(/\.zip::/, `.zip/`); - // The path for neovim is in format of zipfile:////.yarn/... - return str.replace(/^zipfile:\/\//, ``); - } break; + case `coc-nvim`: + { + str = str.replace(/\.zip::/, `.zip/`); + // The path for coc-nvim is in format of //zipfile://.yarn/... + // So in order to convert it back, we use .* to match all the thing + // before `zipfile:` + return process.platform === `win32` ? str.replace(/^.*zipfile:\//, ``) : str.replace(/^.*zipfile:/, ``); + } + break; + + case `neovim`: + { + str = str.replace(/\.zip::/, `.zip/`); + // The path for neovim is in format of zipfile:////.yarn/... + return str.replace(/^zipfile:\/\//, ``); + } + break; case `vscode`: - default: { - return str.replace(/^\^?(zip:|\/zip(\/ts-nul-authority)?)\/+/, process.platform === `win32` ? `` : `/`) - } break; + default: + { + return str.replace(/^\^?(zip:|\/zip(\/ts-nul-authority)?)\/+/, process.platform === `win32` ? `` : `/`); + } + break; } } @@ -173,8 +196,8 @@ const moduleWrapperFn = tsserver => { // TypeScript already does local loads and if this code is running the user trusts the workspace // https://github.com/microsoft/vscode/issues/45856 const ConfiguredProject = tsserver.server.ConfiguredProject; - const {enablePluginsWithOptions: originalEnablePluginsWithOptions} = ConfiguredProject.prototype; - ConfiguredProject.prototype.enablePluginsWithOptions = function() { + const { enablePluginsWithOptions: originalEnablePluginsWithOptions } = ConfiguredProject.prototype; + ConfiguredProject.prototype.enablePluginsWithOptions = function () { this.projectService.allowLocalPluginLoads = true; return originalEnablePluginsWithOptions.apply(this, arguments); }; @@ -184,7 +207,7 @@ const moduleWrapperFn = tsserver => { // like an absolute path of ours and normalize it. const Session = tsserver.server.Session; - const {onMessage: originalOnMessage, send: originalSend} = Session.prototype; + const { onMessage: originalOnMessage, send: originalSend } = Session.prototype; let hostInfo = `unknown`; Object.assign(Session.prototype, { @@ -200,10 +223,12 @@ const moduleWrapperFn = tsserver => { ) { hostInfo = parsedMessage.arguments.hostInfo; if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK) { - const [, major, minor] = (process.env.VSCODE_IPC_HOOK.match( - // The RegExp from https://semver.org/ but without the caret at the start - /(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ - ) ?? []).map(Number) + const [, major, minor] = ( + process.env.VSCODE_IPC_HOOK.match( + // The RegExp from https://semver.org/ but without the caret at the start + /(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ + ) ?? [] + ).map(Number); if (major === 1) { if (minor < 61) { @@ -221,23 +246,27 @@ const moduleWrapperFn = tsserver => { return typeof value === 'string' ? fromEditorPath(value) : value; }); - return originalOnMessage.call( - this, - isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON) - ); + return originalOnMessage.call(this, isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON)); }, send(/** @type {any} */ msg) { - return originalSend.call(this, JSON.parse(JSON.stringify(msg, (key, value) => { - return typeof value === `string` ? toEditorPath(value) : value; - }))); - } + return originalSend.call( + this, + JSON.parse( + JSON.stringify(msg, (key, value) => { + return typeof value === `string` ? toEditorPath(value) : value; + }) + ) + ); + }, }); return tsserver; }; -const [major, minor] = absRequire(`typescript/package.json`).version.split(`.`, 2).map(value => parseInt(value, 10)); +const [major, minor] = absRequire(`typescript/package.json`) + .version.split(`.`, 2) + .map(value => parseInt(value, 10)); // In TypeScript@>=5.5 the tsserver uses the public TypeScript API so that needs to be patched as well. // Ref https://github.com/microsoft/TypeScript/pull/55326 if (major > 5 || (major === 5 && minor >= 5)) { diff --git a/.yarn/sdks/typescript/lib/typescript.js b/.yarn/sdks/typescript/lib/typescript.js index 7b6cc22..ebcbccc 100644 --- a/.yarn/sdks/typescript/lib/typescript.js +++ b/.yarn/sdks/typescript/lib/typescript.js @@ -1,11 +1,11 @@ #!/usr/bin/env node -const {existsSync} = require(`fs`); -const {createRequire, register} = require(`module`); -const {resolve} = require(`path`); -const {pathToFileURL} = require(`url`); +const { existsSync } = require(`fs`); +const { createRequire, register } = require(`module`); +const { resolve } = require(`path`); +const { pathToFileURL } = require(`url`); -const relPnpApiPath = "../../../../.pnp.cjs"; +const relPnpApiPath = '../../../../.pnp.cjs'; const absPnpApiPath = resolve(__dirname, relPnpApiPath); const absUserWrapperPath = resolve(__dirname, `./sdk.user.cjs`); diff --git a/.yarn/sdks/typescript/package.json b/.yarn/sdks/typescript/package.json index 1399ec4..b4cde73 100644 --- a/.yarn/sdks/typescript/package.json +++ b/.yarn/sdks/typescript/package.json @@ -1,6 +1,6 @@ { "name": "typescript", - "version": "5.5.4-sdk", + "version": "5.8.3-sdk", "main": "./lib/typescript.js", "type": "commonjs", "bin": { diff --git a/docs/en/reference/manifest.json b/docs/en/reference/manifest.json index e32aa04..cc2091a 100644 --- a/docs/en/reference/manifest.json +++ b/docs/en/reference/manifest.json @@ -119,4 +119,4 @@ } ] } -] \ No newline at end of file +] diff --git a/package.json b/package.json index db8578c..5894358 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,8 @@ "typecheck": "yarn workspaces foreach -ptR --from 'packages/*' run typecheck", "build": "yarn workspaces foreach -ptR --from 'packages/*' run build", "test": "yarn workspaces foreach -ptR --from 'packages/*' run test", + "format": "prettier --write 'packages/**/*' 'docs/**/*.{ts,tsx,js,jsx,json}'", + "format:check": "prettier --check 'packages/**/*' 'docs/**/*.{ts,tsx,js,jsx,json}'", "changeset:version": "changeset version", "changeset:publish": "changeset publish" }, @@ -27,6 +29,7 @@ "eslint": "^9.9.1", "hygen": "^6.2.11", "knip": "^5.61.3", + "prettier": "^3.8.1", "tsx": "^4.20.3", "typescript": "^5.8.3", "typescript-eslint": "^8.4.0", diff --git a/packages/cli/src/commands/build/build.schema.ts b/packages/cli/src/commands/build/build.schema.ts index c5063d9..a3e9fc4 100644 --- a/packages/cli/src/commands/build/build.schema.ts +++ b/packages/cli/src/commands/build/build.schema.ts @@ -2,34 +2,23 @@ import z from "zod"; export const buildConfigSchema = z.object({ manifest: z.object({ - prefix: z - .string() - .describe("Default prefix for documentation links") - .default("docs/references"), - enabled: z - .boolean() - .describe("Whether to generate manifest.json file") - .default(true), + prefix: z.string().describe("Default prefix for documentation links").default("docs/references"), + enabled: z.boolean().describe("Whether to generate manifest.json file").default(true), path: z .string() .describe( - "Path to save manifest file (relative to project root or absolute path). If not specified, uses outputDir/manifest.json", + "Path to save manifest file (relative to project root or absolute path). If not specified, uses outputDir/manifest.json" ) .optional(), }), - outputDir: z - .string() - .describe("Directory where build output will be saved") - .default("docs/references"), + outputDir: z.string().describe("Directory where build output will be saved").default("docs/references"), generator: z.object({ name: z.string().describe("Generator name (vitepress or plugin name)"), signatureLanguage: z .string() .optional() .default("typescript") - .describe( - "Language for code signature highlighting (e.g., typescript, tsx, javascript)", - ), + .describe("Language for code signature highlighting (e.g., typescript, tsx, javascript)"), labels: z .object({ parameters: z.string().default("Parameters"), diff --git a/packages/cli/src/commands/build/index.ts b/packages/cli/src/commands/build/index.ts index d362b3b..3800e7a 100644 --- a/packages/cli/src/commands/build/index.ts +++ b/packages/cli/src/commands/build/index.ts @@ -22,23 +22,11 @@ export class BuildCommand extends Command { static paths = [[`build`]]; async execute(): Promise { - const { - projectConfig, - projectRoot, - buildConfig, - targetPackages, - parser, - generator, - manifestManager, - outputDir, - } = await loadContext(); + const { projectConfig, projectRoot, buildConfig, targetPackages, parser, generator, manifestManager, outputDir } = + await loadContext(); if (targetPackages.length === 0) { - printNoPackagesFound( - projectConfig.workspace.include, - projectConfig.root, - projectConfig.packageManager - ); + printNoPackagesFound(projectConfig.workspace.include, projectConfig.root, projectConfig.packageManager); return 1; } @@ -53,23 +41,15 @@ export class BuildCommand extends Command { const projectSourceFiles = project.getSourceFiles(); const exportSourceFiles = projectSourceFiles.filter(isExportSourceFile); - const exportDeclarationsBySourceFiles = exportSourceFiles.flatMap( - getExportedDeclarationsBySourceFile - ); - const excludeBarrelReExport = excludeBarrelReExports( - exportDeclarationsBySourceFiles - ); - const targets = excludeBarrelReExport.filter((target) => { + const exportDeclarationsBySourceFiles = exportSourceFiles.flatMap(getExportedDeclarationsBySourceFile); + const excludeBarrelReExport = excludeBarrelReExports(exportDeclarationsBySourceFiles); + const targets = excludeBarrelReExport.filter(target => { return target.jsDoc && hasJSDocTag(target.declaration, "public"); }); - const targetsWithJSDoc = targets.map((target) => - parseJSDoc(target, parser) - ); + const targetsWithJSDoc = targets.map(target => parseJSDoc(target, parser)); - const docs = targetsWithJSDoc.map((target) => - generator.generateDocs(target, pkg.location) - ); + const docs = targetsWithJSDoc.map(target => generator.generateDocs(target, pkg.location)); console.log(`Generated ${docs.length} documentation files:`); for (const doc of docs) { @@ -92,12 +72,7 @@ export class BuildCommand extends Command { await fs.mkdir(path.dirname(manifestPath), { recursive: true }); await fs.writeFile(manifestPath, manifestManager.toString()); - console.log( - `📋 Generated manifest: ${path.relative( - projectConfig.root, - manifestPath - )}` - ); + console.log(`📋 Generated manifest: ${path.relative(projectConfig.root, manifestPath)}`); } return 0; @@ -110,10 +85,7 @@ async function loadContext() { const projectRoot = path.resolve(root, config.project.root); const buildConfig = config.commands.build; const projectConfig = config.project; - const packageManager = createPackageManager( - projectConfig.packageManager, - projectRoot - ); + const packageManager = createPackageManager(projectConfig.packageManager, projectRoot); const packages = packageManager.getPackages(); const parser = new JSDocParser(); @@ -122,7 +94,7 @@ async function loadContext() { config, }); - const targetPackages = packages.filter((pkg) => + const targetPackages = packages.filter(pkg => isTargetPackage(pkg, { include: projectConfig.workspace.include, exclude: projectConfig.workspace.exclude, @@ -132,16 +104,9 @@ async function loadContext() { try { const plugins = await loadPlugins(config); pluginManager.registerAll(plugins); - console.log( - `📦 Loaded ${plugins.length} plugin(s): ${plugins - .map((p) => p.name) - .join(", ")}` - ); + console.log(`📦 Loaded ${plugins.length} plugin(s): ${plugins.map(p => p.name).join(", ")}`); } catch (error) { - console.error( - `❌ Failed to load plugins: ${error instanceof Error ? error.message : String(error) - }` - ); + console.error(`❌ Failed to load plugins: ${error instanceof Error ? error.message : String(error)}`); } const generator = pluginManager.getGenerator(config); @@ -164,11 +129,7 @@ async function loadContext() { }; } -function printNoPackagesFound( - include: string[], - root: string, - packageManager: string -) { +function printNoPackagesFound(include: string[], root: string, packageManager: string) { console.error("❌ not found packages"); console.error("check your config:"); console.error(` - workspace.include: ${JSON.stringify(include)}`); diff --git a/packages/cli/src/commands/build/manifest/manifest.ts b/packages/cli/src/commands/build/manifest/manifest.ts index a8ddf71..0abe18d 100644 --- a/packages/cli/src/commands/build/manifest/manifest.ts +++ b/packages/cli/src/commands/build/manifest/manifest.ts @@ -12,7 +12,7 @@ interface ManifestOptions { * @name SidebarItem * @description * Represents a sidebar navigation item for the documentation site. Can be a link or a folder containing other items. - * + * * @param {string} text Display text for the sidebar item * @param {string} [link] Optional link URL for the item * @param {SidebarItem[]} [items] Optional array of sub-items for folder-type items @@ -59,9 +59,7 @@ export class Manifest { let current = result; for (const folderName of parts) { - let folder = current.find( - (item) => item.text === folderName && !item.link, - ); + let folder = current.find(item => item.text === folderName && !item.link); if (!folder) { folder = { diff --git a/packages/cli/src/commands/check/index.ts b/packages/cli/src/commands/check/index.ts index f39981f..b7feb6e 100644 --- a/packages/cli/src/commands/check/index.ts +++ b/packages/cli/src/commands/check/index.ts @@ -19,11 +19,7 @@ export class CheckCommand extends Command { const { checkConfig, projectConfig, projectRoot, targetPackages } = await loadContext(); if (targetPackages.length === 0) { - printNoPackagesFound( - projectConfig.workspace.include, - projectConfig.root, - projectConfig.packageManager - ); + printNoPackagesFound(projectConfig.workspace.include, projectConfig.root, projectConfig.packageManager); return 1; } @@ -35,33 +31,25 @@ export class CheckCommand extends Command { const tsConfigPath = getTsConfigPath(projectRoot, pkg.location); const project = getTsProject(tsConfigPath); - const entryPoints = - checkConfig.entryPoints ?? getPackageEntryPoints(packagePath); + const entryPoints = checkConfig.entryPoints ?? getPackageEntryPoints(packagePath); const sourceFiles = project.getSourceFiles(); - const entryPointFiles = sourceFiles.filter((file) => { + const entryPointFiles = sourceFiles.filter(file => { const filePath = file.getFilePath(); - return entryPoints.some((entryPoint) => filePath.includes(entryPoint)); + return entryPoints.some(entryPoint => filePath.includes(entryPoint)); }); const exportSourceFiles = entryPointFiles.filter(isExportSourceFile); - const exportDeclarationsBySourceFiles = exportSourceFiles.flatMap( - getExportedDeclarationsBySourceFile - ); - const excludeBarrelReExport = excludeBarrelReExports( - exportDeclarationsBySourceFiles - ); - const missingJSDocExports = excludeBarrelReExport.filter((target) => { + const exportDeclarationsBySourceFiles = exportSourceFiles.flatMap(getExportedDeclarationsBySourceFile); + const excludeBarrelReExport = excludeBarrelReExports(exportDeclarationsBySourceFiles); + const missingJSDocExports = excludeBarrelReExport.filter(target => { return !hasJSDocTag(target.declaration, "public"); }); if (missingJSDocExports.length > 0) { console.log(`❌ ${pkg.name} has missing JSDoc:`); - missingJSDocExports.forEach((exportInfo) => { - const relativePath = path.relative( - projectConfig.root, - exportInfo.filePath - ); + missingJSDocExports.forEach(exportInfo => { + const relativePath = path.relative(projectConfig.root, exportInfo.filePath); console.log(` - ${relativePath}:${exportInfo.symbolName}`); }); } else { @@ -82,13 +70,10 @@ async function loadContext() { const projectRoot = path.resolve(root, config.project.root); const projectConfig = config.project; const checkConfig = config.commands.check; - const packageManager = createPackageManager( - projectConfig.packageManager, - projectRoot - ); + const packageManager = createPackageManager(projectConfig.packageManager, projectRoot); const packages = packageManager.getPackages(); - const targetPackages = packages.filter((pkg) => + const targetPackages = packages.filter(pkg => isTargetPackage(pkg, { include: projectConfig.workspace.include, exclude: projectConfig.workspace.exclude, @@ -103,11 +88,7 @@ async function loadContext() { }; } -function printNoPackagesFound( - include: string[], - root: string, - packageManager: string -) { +function printNoPackagesFound(include: string[], root: string, packageManager: string) { console.error("❌ not found packages"); console.error("check your config:"); console.error(` - workspace.include: ${JSON.stringify(include)}`); diff --git a/packages/cli/src/commands/generate/generate.schema.ts b/packages/cli/src/commands/generate/generate.schema.ts index aafd182..0025cb4 100644 --- a/packages/cli/src/commands/generate/generate.schema.ts +++ b/packages/cli/src/commands/generate/generate.schema.ts @@ -10,7 +10,7 @@ export const generateConfigSchema = z z.object({ signature: z.string(), prompt: z.string(), - }), + }) ) .returns(z.promise(z.string())) .describe("Function to fetch JSDoc from AI service"), diff --git a/packages/cli/src/commands/generate/index.ts b/packages/cli/src/commands/generate/index.ts index 32cb84c..538759c 100644 --- a/packages/cli/src/commands/generate/index.ts +++ b/packages/cli/src/commands/generate/index.ts @@ -20,23 +20,18 @@ export class GenerateCommand extends Command { static paths = [[`generate`]]; async execute(): Promise { - const { projectConfig, projectRoot, generateConfig, targetPackages } = - await loadContext(); + const { projectConfig, projectRoot, generateConfig, targetPackages } = await loadContext(); if (!generateConfig) { console.error("❌ not found generate config"); return 1; } if (targetPackages.length === 0) { - printNoPackagesFound( - projectConfig.workspace.include, - projectConfig.root, - projectConfig.packageManager - ); + printNoPackagesFound(projectConfig.workspace.include, projectConfig.root, projectConfig.packageManager); return 1; } - const allGenerateTargets = targetPackages.flatMap((pkg) => { + const allGenerateTargets = targetPackages.flatMap(pkg => { console.log(`📝 ${pkg.name} processing...`); try { @@ -44,20 +39,16 @@ export class GenerateCommand extends Command { const project = getTsProject(tsConfigPath); const projectSourceFiles = project.getSourceFiles(); - const exportDeclarationsBySourceFiles = projectSourceFiles.flatMap( - getExportedDeclarationsBySourceFile - ); + const exportDeclarationsBySourceFiles = projectSourceFiles.flatMap(getExportedDeclarationsBySourceFile); - const excludeBarrelReExport = excludeBarrelReExports( - exportDeclarationsBySourceFiles - ); + const excludeBarrelReExport = excludeBarrelReExports(exportDeclarationsBySourceFiles); - const generateTargets = excludeBarrelReExport.filter((target) => { + const generateTargets = excludeBarrelReExport.filter(target => { return target.jsDoc && hasJSDocTag(target.declaration, "generate"); }); return generateTargets - .map((target) => { + .map(target => { const signature = extractSignature(target.declaration); if (signature == null) { return null; @@ -91,13 +82,10 @@ export class GenerateCommand extends Command { const fetcher = generateConfig.jsdoc.fetcher; const promptTemplate = generateConfig.jsdoc.prompt; - const templateFunction = (signature: string) => - `${promptTemplate}\n\nSignature: ${signature}`; + const templateFunction = (signature: string) => `${promptTemplate}\n\nSignature: ${signature}`; for (const selectTarget of selectedTargets) { - const sourceFile = selectTarget.project.getSourceFile( - selectTarget.filePath - ); + const sourceFile = selectTarget.project.getSourceFile(selectTarget.filePath); if (!sourceFile) continue; const declaration = selectTarget.declaration; @@ -113,9 +101,7 @@ export class GenerateCommand extends Command { updateJSDoc(declaration, newJSDoc); await sourceFile.save(); - console.log( - `✅ ${selectTarget.filePath} ${selectTarget.symbolName} updated` - ); + console.log(`✅ ${selectTarget.filePath} ${selectTarget.symbolName} updated`); } console.log("✅ generate done"); @@ -130,19 +116,16 @@ async function loadContext() { const projectRoot = path.resolve(root, config.project.root); const generateConfig = config.commands?.generate; const projectConfig = config.project; - const packageManager = createPackageManager( - projectConfig.packageManager, - projectRoot - ); + const packageManager = createPackageManager(projectConfig.packageManager, projectRoot); const packages = packageManager.getPackages(); if (packages.length > 0) { - packages.forEach((pkg) => { + packages.forEach(pkg => { console.log(` - ${pkg.name} (${pkg.location})`); }); } - const targetPackages = packages.filter((pkg) => + const targetPackages = packages.filter(pkg => isTargetPackage(pkg, { include: projectConfig.workspace.include, exclude: projectConfig.workspace.exclude, @@ -158,11 +141,7 @@ async function loadContext() { }; } -function printNoPackagesFound( - include: string[], - root: string, - packageManager: string -) { +function printNoPackagesFound(include: string[], root: string, packageManager: string) { console.error("❌ not found packages"); console.error("check your config:"); console.error(` - workspace.include: ${JSON.stringify(include)}`); @@ -175,9 +154,7 @@ interface GenerateTarget extends ExportDeclaration { project: Project; } -async function promptTargetSelection( - targetContexts: GenerateTarget[] -): Promise { +async function promptTargetSelection(targetContexts: GenerateTarget[]): Promise { const choices = [ { name: "All targets", @@ -200,8 +177,7 @@ async function promptTargetSelection( return targetContexts; } - const selectedIndex = - choices.findIndex((choice) => choice.name === response.selection) - 1; + const selectedIndex = choices.findIndex(choice => choice.name === response.selection) - 1; if (selectedIndex === -1) { return []; } diff --git a/packages/cli/src/config/config.schema.ts b/packages/cli/src/config/config.schema.ts index a2427ab..34ea6b4 100644 --- a/packages/cli/src/config/config.schema.ts +++ b/packages/cli/src/config/config.schema.ts @@ -8,12 +8,8 @@ export const configSchema = z.object({ root: z.string().describe("Project root directory"), packageManager: z.enum(["yarn", "pnpm", "npm"]).describe("Package manager"), workspace: z.object({ - include: z - .array(z.string()) - .describe("Package patterns to include in build"), - exclude: z - .array(z.string()) - .describe("Package patterns to exclude from build"), + include: z.array(z.string()).describe("Package patterns to include in build"), + exclude: z.array(z.string()).describe("Package patterns to exclude from build"), }), }), commands: z.object({ @@ -25,11 +21,9 @@ export const configSchema = z.object({ .array( z.object({ name: z.string().describe("Plugin name"), - plugin: z - .function() - .describe("Plugin factory function that returns plugin instance"), + plugin: z.function().describe("Plugin factory function that returns plugin instance"), options: z.record(z.any()).optional().describe("Plugin options"), - }), + }) ) .optional() .default([]), @@ -42,7 +36,7 @@ export const configSchema = z.object({ * @name Config * @description * Type for Docflow configuration files. Includes project settings, command settings, and plugin settings. - * + * * @param {object} project Project configuration information * @param {string} project.root Project root directory * @param {"yarn" | "pnpm" | "npm"} project.packageManager Package manager to use diff --git a/packages/cli/src/config/load-config.ts b/packages/cli/src/config/load-config.ts index 230bd21..ffb73a4 100644 --- a/packages/cli/src/config/load-config.ts +++ b/packages/cli/src/config/load-config.ts @@ -36,9 +36,7 @@ export async function loadConfig(rootPath: string) { const result = configSchema.safeParse(config); if (!result.success) { - throw new Error( - `Invalid config file: ${JSON.stringify(result.error.format(), null, 2)}` - ); + throw new Error(`Invalid config file: ${JSON.stringify(result.error.format(), null, 2)}`); } return result.data; diff --git a/packages/cli/src/core/entry-point.ts b/packages/cli/src/core/entry-point.ts index 850d665..a5259ae 100644 --- a/packages/cli/src/core/entry-point.ts +++ b/packages/cli/src/core/entry-point.ts @@ -40,7 +40,7 @@ function extractExportsEntries(exportsField: unknown): string[] { const entries: string[] = []; const exportsObj = exportsField as Record; - Object.values(exportsObj).forEach((value) => { + Object.values(exportsObj).forEach(value => { // { // "exports": { // ".": "./dist/index.js", @@ -60,7 +60,7 @@ function extractExportsEntries(exportsField: unknown): string[] { // } else if (typeof value === "object" && value !== null) { const conditionalExports = value as Record; - ["import", "require", "default"].forEach((condition) => { + ["import", "require", "default"].forEach(condition => { const conditionValue = conditionalExports[condition]; if (typeof conditionValue === "string") { entries.push(normalizeEntryPath(conditionValue)); diff --git a/packages/cli/src/core/generator/vitepress/vitepress-generator.ts b/packages/cli/src/core/generator/vitepress/vitepress-generator.ts index f2ebb3f..f2515a4 100644 --- a/packages/cli/src/core/generator/vitepress/vitepress-generator.ts +++ b/packages/cli/src/core/generator/vitepress/vitepress-generator.ts @@ -10,16 +10,9 @@ import { } from "../../types/parser.types.js"; import { MarkdownSection } from "../../types/generator.types.js"; import { TargetWithJSDoc } from "../../types/parser.types.js"; -import { - GeneratorConfig, - defaultVitePressLabels, -} from "../../types/generator.types.js"; +import { GeneratorConfig, defaultVitePressLabels } from "../../types/generator.types.js"; import path from "path"; -import { - GeneratedDoc, - MarkdownDocument, - MarkdownGenerator, -} from "../../types/generator.types.js"; +import { GeneratedDoc, MarkdownDocument, MarkdownGenerator } from "../../types/generator.types.js"; export class VitePressGenerator implements MarkdownGenerator { private labels: typeof defaultVitePressLabels; @@ -91,10 +84,7 @@ export class VitePressGenerator implements MarkdownGenerator { serialize(markdownDoc: MarkdownDocument): string { const parts: string[] = []; - if ( - markdownDoc.frontmatter && - Object.keys(markdownDoc.frontmatter).length > 0 - ) { + if (markdownDoc.frontmatter && Object.keys(markdownDoc.frontmatter).length > 0) { parts.push("---"); for (const [key, value] of Object.entries(markdownDoc.frontmatter)) { parts.push(`${key}: ${JSON.stringify(value)}`); @@ -124,10 +114,7 @@ export class VitePressGenerator implements MarkdownGenerator { }; } - private generateRelativePath( - target: TargetWithJSDoc, - packagePath: string, - ): string { + private generateRelativePath(target: TargetWithJSDoc, packagePath: string): string { const { parsedJSDoc: jsDocData, symbolName, kind } = target; const category = jsDocData.category || kind || "misc"; const name = jsDocData.name || symbolName; @@ -209,12 +196,8 @@ export class VitePressGenerator implements MarkdownGenerator { for (const prop of typedef.properties) { const requiredText = prop.required ? "" : " (optional)"; - const defaultText = prop.defaultValue - ? `, default = ${prop.defaultValue}` - : ""; - content.push( - `- \`${prop.name}\`${requiredText}${defaultText} ${prop.description}`, - ); + const defaultText = prop.defaultValue ? `, default = ${prop.defaultValue}` : ""; + content.push(`- \`${prop.name}\`${requiredText}${defaultText} ${prop.description}`); } content.push(""); @@ -226,9 +209,7 @@ export class VitePressGenerator implements MarkdownGenerator { }; } - private createParametersSection( - parameters: ParameterData[], - ): MarkdownSection { + private createParametersSection(parameters: ParameterData[]): MarkdownSection { const content = [`### ${this.labels.parameters}`, ""]; content.push('
    '); @@ -249,34 +230,23 @@ export class VitePressGenerator implements MarkdownGenerator { private renderParameter(param: ParameterData, isRoot = false): string { const cssClass = isRoot ? "post-parameters-li-root" : ""; - const requiredText = param.required - ? 'Required' - : ""; + const requiredText = param.required ? 'Required' : ""; const defaultText = param.defaultValue - ? `${this.escapeHtml( - param.defaultValue, - )}` + ? `${this.escapeHtml(param.defaultValue)}` : ""; - const typeText = `${this.escapeHtml( - param.type, - )}`; + const typeText = `${this.escapeHtml(param.type)}`; const cleanedDescription = param.description.replace(/^-\s*/, "").trim(); - const afterNameParts = [typeText, defaultText].filter( - (part) => part.length > 0, - ); - const afterNameText = - afterNameParts.length > 0 ? " · " + afterNameParts.join(" · ") : ""; + const afterNameParts = [typeText, defaultText].filter(part => part.length > 0); + const afterNameText = afterNameParts.length > 0 ? " · " + afterNameParts.join(" · ") : ""; const lines = [ `
  • `, ` ${param.name}${requiredText}${afterNameText}`, `
    `, - `

    ${this.toHTMLCode( - cleanedDescription, - )}

    `, + `

    ${this.toHTMLCode(cleanedDescription)}

    `, ]; if (param.nested && param.nested.length > 0) { @@ -299,9 +269,7 @@ export class VitePressGenerator implements MarkdownGenerator { "", '
      ', '
    • ', - ` ${this.escapeHtml( - returns.type, - )}`, + ` ${this.escapeHtml(returns.type)}`, "
      ", `

      ${nameText}${returns.description}

      `, "
    • ", @@ -312,12 +280,8 @@ export class VitePressGenerator implements MarkdownGenerator { content.push(""); for (const prop of returns.properties) { const requiredText = prop.required ? "" : " (optional)"; - const defaultText = prop.defaultValue - ? `, default: ${prop.defaultValue}` - : ""; - content.push( - `- \`${prop.name}\`: ${prop.description}${requiredText}${defaultText}`, - ); + const defaultText = prop.defaultValue ? `, default: ${prop.defaultValue}` : ""; + content.push(`- \`${prop.name}\`: ${prop.description}${requiredText}${defaultText}`); } } @@ -334,15 +298,9 @@ export class VitePressGenerator implements MarkdownGenerator { for (const throwItem of throws) { const nameText = throwItem.name ? `${throwItem.name} ` : ""; content.push('
    • '); - content.push( - ` ${this.escapeHtml( - throwItem.type, - )}`, - ); + content.push(` ${this.escapeHtml(throwItem.type)}`); content.push("
      "); - content.push( - `

      ${nameText}${throwItem.description}

      `, - ); + content.push(`

      ${nameText}${throwItem.description}

      `); content.push("
    • "); } @@ -383,16 +341,11 @@ export class VitePressGenerator implements MarkdownGenerator { } private createVersionSection(versions: VersionData[]): MarkdownSection { - const content = [ - `### ${this.labels.version}`, - "", - "|Version|Changes|", - "|-|-|", - ]; + const content = [`### ${this.labels.version}`, "", "|Version|Changes|", "|-|-|"]; for (const version of versions) { const versionText = version.platforms - ? version.platforms.map((p) => `**\`${p}\`**`).join(" ") + ? version.platforms.map(p => `**\`${p}\`**`).join(" ") : `**\`${version.version}\`**`; content.push(`| ${versionText} |${version.description}|`); @@ -416,9 +369,6 @@ export class VitePressGenerator implements MarkdownGenerator { private toHTMLCode(text: string): string { return text .replace(/`([^`]+)`/g, "$1") - .replace( - /\[([^\]]+)\]\(([^)]+)\)/g, - '$1', - ); + .replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1'); } } diff --git a/packages/cli/src/core/parser/jsdoc/jsdoc-parser.ts b/packages/cli/src/core/parser/jsdoc/jsdoc-parser.ts index 92127e7..53b0dd5 100644 --- a/packages/cli/src/core/parser/jsdoc/jsdoc-parser.ts +++ b/packages/cli/src/core/parser/jsdoc/jsdoc-parser.ts @@ -62,7 +62,7 @@ export class JSDocParser { } private extractDescription(block: commentParser.Block): string | undefined { - const descriptionTag = block.tags.find((tag) => tag.tag === "description"); + const descriptionTag = block.tags.find(tag => tag.tag === "description"); if (!descriptionTag) return undefined; const name = descriptionTag.name; @@ -84,7 +84,7 @@ export class JSDocParser { } private extractDeprecated(block: commentParser.Block): string | undefined { - const tag = block.tags.find((t) => t.tag === "deprecated"); + const tag = block.tags.find(t => t.tag === "deprecated"); if (!tag) return undefined; const nameMessage = tag.name; @@ -95,7 +95,7 @@ export class JSDocParser { } private extractSignature(block: commentParser.Block): string | undefined { - const signatureTag = block.tags.find((tag) => tag.tag === "signature"); + const signatureTag = block.tags.find(tag => tag.tag === "signature"); if (!signatureTag) return undefined; const signatureText = signatureTag.description.trim(); @@ -103,7 +103,7 @@ export class JSDocParser { } private extractParameters(block: commentParser.Block): ParameterData[] { - const paramTags = block.tags.filter((tag) => tag.tag === "param"); + const paramTags = block.tags.filter(tag => tag.tag === "param"); const parameters: ParameterData[] = []; const paramMap = new Map(); @@ -138,7 +138,7 @@ export class JSDocParser { private handleNestedParameter( param: ParameterData, paramMap: Map, - parameters: ParameterData[], + parameters: ParameterData[] ): void { const parts = param.name.split("."); const parentName = parts[0]; @@ -165,11 +165,11 @@ export class JSDocParser { } private extractReturns(block: commentParser.Block): ReturnData | undefined { - const returnTag = block.tags.find((tag) => tag.tag === "returns"); + const returnTag = block.tags.find(tag => tag.tag === "returns"); if (!returnTag) return undefined; - const propertyTags = block.tags.filter((tag) => tag.tag === "property"); - const properties = propertyTags.map((tag) => ({ + const propertyTags = block.tags.filter(tag => tag.tag === "property"); + const properties = propertyTags.map(tag => ({ name: tag.name, description: tag.description, required: !tag.optional, @@ -185,9 +185,9 @@ export class JSDocParser { } private extractThrows(block: commentParser.Block): ThrowsData[] { - const throwsTags = block.tags.filter((tag) => tag.tag === "throws"); + const throwsTags = block.tags.filter(tag => tag.tag === "throws"); - return throwsTags.map((tag) => ({ + return throwsTags.map(tag => ({ type: tag.type, name: tag.name, description: tag.description, @@ -195,15 +195,15 @@ export class JSDocParser { } private extractTypedefs(block: commentParser.Block): TypedefData[] { - const typedefTags = block.tags.filter((tag) => tag.tag === "typedef"); - const propertyTags = block.tags.filter((tag) => tag.tag === "property"); + const typedefTags = block.tags.filter(tag => tag.tag === "typedef"); + const propertyTags = block.tags.filter(tag => tag.tag === "property"); - return typedefTags.map((tag) => { + return typedefTags.map(tag => { const name = tag.name; const type = tag.type; const description = tag.description; - const properties = propertyTags.map((tag) => ({ + const properties = propertyTags.map(tag => ({ name: tag.name, type: tag.type, description: tag.description, @@ -221,9 +221,9 @@ export class JSDocParser { } private extractExamples(block: commentParser.Block): ExampleData[] { - const exampleTags = block.tags.filter((tag) => tag.tag === "example"); + const exampleTags = block.tags.filter(tag => tag.tag === "example"); - return exampleTags.map((tag) => { + return exampleTags.map(tag => { const content = tag.description; return { @@ -234,9 +234,9 @@ export class JSDocParser { } private extractSee(block: commentParser.Block): SeeData[] { - const seeTags = block.tags.filter((tag) => tag.tag === "see"); + const seeTags = block.tags.filter(tag => tag.tag === "see"); - return seeTags.map((tag) => { + return seeTags.map(tag => { const reference = tag.name || tag.type; const description = tag.description; @@ -248,15 +248,13 @@ export class JSDocParser { } private extractVersions(block: commentParser.Block): VersionData[] { - const versionTags = block.tags.filter((tag) => tag.tag === "version"); + const versionTags = block.tags.filter(tag => tag.tag === "version"); - return versionTags.map((tag) => { + return versionTags.map(tag => { const versionName = tag.name; const description = tag.description; - const platforms = versionName.includes("/") - ? versionName.split("/") - : undefined; + const platforms = versionName.includes("/") ? versionName.split("/") : undefined; return { version: versionName, @@ -266,11 +264,8 @@ export class JSDocParser { }); } - private findTagValue( - block: commentParser.Block, - tagName: string, - ): string | undefined { - const tag = block.tags.find((t) => t.tag === tagName); + private findTagValue(block: commentParser.Block, tagName: string): string | undefined { + const tag = block.tags.find(t => t.tag === tagName); if (!tag) return undefined; const name = tag.name; diff --git a/packages/cli/src/core/parser/jsdoc/jsdoc-utils.ts b/packages/cli/src/core/parser/jsdoc/jsdoc-utils.ts index b9e0e88..ad11bf6 100644 --- a/packages/cli/src/core/parser/jsdoc/jsdoc-utils.ts +++ b/packages/cli/src/core/parser/jsdoc/jsdoc-utils.ts @@ -4,11 +4,7 @@ export function hasJSDocTag(node: Node, tagName: string): boolean { const jsDocableNode = getJSDocableNode(node); if (!jsDocableNode) return false; - return jsDocableNode - .getJsDocs() - .some((jsDoc) => - jsDoc.getTags().some((tag) => tag.getTagName() === tagName), - ); + return jsDocableNode.getJsDocs().some(jsDoc => jsDoc.getTags().some(tag => tag.getTagName() === tagName)); } export function getJSDoc(node: Node): JSDoc | undefined { diff --git a/packages/cli/src/core/parser/jsdoc/parse-jsdoc.ts b/packages/cli/src/core/parser/jsdoc/parse-jsdoc.ts index c9f2c56..ee1d8c3 100644 --- a/packages/cli/src/core/parser/jsdoc/parse-jsdoc.ts +++ b/packages/cli/src/core/parser/jsdoc/parse-jsdoc.ts @@ -1,13 +1,7 @@ import { JSDocParser } from "./jsdoc-parser.js"; -import { - ExportDeclaration, - TargetWithJSDoc, -} from "../../types/parser.types.js"; +import { ExportDeclaration, TargetWithJSDoc } from "../../types/parser.types.js"; -export function parseJSDoc( - exportDeclaration: ExportDeclaration, - parser: JSDocParser, -): TargetWithJSDoc { +export function parseJSDoc(exportDeclaration: ExportDeclaration, parser: JSDocParser): TargetWithJSDoc { const jsDocData = parser.parse(exportDeclaration.jsDoc); if (exportDeclaration.signature && !jsDocData.signature) { jsDocData.signature = exportDeclaration.signature; diff --git a/packages/cli/src/core/parser/jsdoc/update-jsdoc.ts b/packages/cli/src/core/parser/jsdoc/update-jsdoc.ts index 4a1d0df..2f8a082 100644 --- a/packages/cli/src/core/parser/jsdoc/update-jsdoc.ts +++ b/packages/cli/src/core/parser/jsdoc/update-jsdoc.ts @@ -5,7 +5,7 @@ export function updateJSDoc(declaration: Node, newJSDoc: string): void { if (Node.isJSDocable(declaration)) { const jsDocs = declaration.getJsDocs(); - jsDocs.forEach((jsDoc) => { + jsDocs.forEach(jsDoc => { jsDoc.remove(); }); } diff --git a/packages/cli/src/core/parser/source/exclude-barrel-re-exports.ts b/packages/cli/src/core/parser/source/exclude-barrel-re-exports.ts index 5f42772..111a2b1 100644 --- a/packages/cli/src/core/parser/source/exclude-barrel-re-exports.ts +++ b/packages/cli/src/core/parser/source/exclude-barrel-re-exports.ts @@ -1,22 +1,16 @@ import { groupBy } from "es-toolkit"; import { ExportDeclaration } from "../../types/parser.types.js"; -export function excludeBarrelReExports( - exportDeclarations: ExportDeclaration[], -): ExportDeclaration[] { - return Object.values(groupBy(exportDeclarations, (exp) => exp.symbolName)) - .map((declarations) => { +export function excludeBarrelReExports(exportDeclarations: ExportDeclaration[]): ExportDeclaration[] { + return Object.values(groupBy(exportDeclarations, exp => exp.symbolName)) + .map(declarations => { if (declarations.length === 1) { return declarations[0]; } - const nonBarrelExports = declarations.filter( - (decl) => !decl.filePath.endsWith("index.ts"), - ); + const nonBarrelExports = declarations.filter(decl => !decl.filePath.endsWith("index.ts")); - return nonBarrelExports.length > 0 - ? nonBarrelExports[0] - : declarations[0]; + return nonBarrelExports.length > 0 ? nonBarrelExports[0] : declarations[0]; }) .filter((decl): decl is ExportDeclaration => decl !== undefined); } diff --git a/packages/cli/src/core/parser/source/extract-signature.ts b/packages/cli/src/core/parser/source/extract-signature.ts index e9a032c..9e877c6 100644 --- a/packages/cli/src/core/parser/source/extract-signature.ts +++ b/packages/cli/src/core/parser/source/extract-signature.ts @@ -45,17 +45,15 @@ function formatFunctionSignature(node: FunctionDeclaration): string { const name = node.getName() ?? "anonymous"; const typeParams = node .getTypeParameters() - .map((tp) => tp.getText()) + .map(tp => tp.getText()) .join(", "); const params = node .getParameters() - .map((p) => p.getText()) + .map(p => p.getText()) .join(", "); const returnType = node.getReturnType().getText(); - return `function ${name}${ - typeParams ? `<${typeParams}>` : "" - }(${params}): ${returnType};`; + return `function ${name}${typeParams ? `<${typeParams}>` : ""}(${params}): ${returnType};`; } // {let|const|var} {name}: <{generics}>({parameters}) => {returnType}; @@ -71,17 +69,15 @@ function formatArrowFunctionSignature(node: VariableDeclaration): string { const typeParams = initializer .getTypeParameters() - .map((tp) => tp.getText()) + .map(tp => tp.getText()) .join(", "); const params = initializer .getParameters() - .map((p) => p.getText()) + .map(p => p.getText()) .join(", "); const returnType = initializer.getReturnType().getText(); - return `${declarationKind} ${name}: ${ - typeParams ? `<${typeParams}>` : "" - }(${params}) => ${returnType};`; + return `${declarationKind} ${name}: ${typeParams ? `<${typeParams}>` : ""}(${params}) => ${returnType};`; } // {let|const|var} {name}: {type}; @@ -100,7 +96,7 @@ function formatClassSignature(node: ClassDeclaration): string { const isAbstract = node.isAbstract() ? "abstract " : ""; const typeParams = node .getTypeParameters() - .map((tp) => tp.getText()) + .map(tp => tp.getText()) .join(", "); const extendsExpr = node.getExtends(); @@ -108,13 +104,9 @@ function formatClassSignature(node: ClassDeclaration): string { const implementsExprs = node.getImplements(); const implementsText = - implementsExprs.length > 0 - ? ` implements ${implementsExprs.map((i) => i.getText()).join(", ")}` - : ""; + implementsExprs.length > 0 ? ` implements ${implementsExprs.map(i => i.getText()).join(", ")}` : ""; - return `${isAbstract}class ${name}${ - typeParams ? `<${typeParams}>` : "" - }${extendsText}${implementsText};`; + return `${isAbstract}class ${name}${typeParams ? `<${typeParams}>` : ""}${extendsText}${implementsText};`; } // interface {name}<{generics}> {extends ...}? { {members} } @@ -122,26 +114,21 @@ function formatInterfaceSignature(node: InterfaceDeclaration): string { const name = node.getName(); const typeParams = node .getTypeParameters() - .map((tp) => tp.getText()) + .map(tp => tp.getText()) .join(", "); const extendsExprs = node.getExtends(); - const extendsText = - extendsExprs.length > 0 - ? ` extends ${extendsExprs.map((e) => e.getText()).join(", ")}` - : ""; + const extendsText = extendsExprs.length > 0 ? ` extends ${extendsExprs.map(e => e.getText()).join(", ")}` : ""; const members = node .getMembers() - .map((member) => { + .map(member => { const text = member.getText().trim(); return text.endsWith(";") ? text.slice(0, -1) : text; }) .join("; "); - return `interface ${name}${ - typeParams ? `<${typeParams}>` : "" - }${extendsText} { ${members} }`; + return `interface ${name}${typeParams ? `<${typeParams}>` : ""}${extendsText} { ${members} }`; } // type {name}<{generics}> = {definition}; @@ -149,7 +136,7 @@ function formatTypeAliasSignature(node: TypeAliasDeclaration): string { const name = node.getName(); const typeParams = node .getTypeParameters() - .map((tp) => tp.getText()) + .map(tp => tp.getText()) .join(", "); const type = node.getTypeNode()?.getText() ?? "unknown"; @@ -163,13 +150,11 @@ function formatEnumSignature(node: EnumDeclaration): string { const members = node .getMembers() - .map((member) => { + .map(member => { const memberName = member.getName(); const value = member.getValue(); if (value !== undefined) { - return `${memberName} = ${ - typeof value === "string" ? `"${value}"` : value - }`; + return `${memberName} = ${typeof value === "string" ? `"${value}"` : value}`; } return memberName; }) diff --git a/packages/cli/src/core/parser/source/get-declaration-kind.ts b/packages/cli/src/core/parser/source/get-declaration-kind.ts index 2e9beca..951852d 100644 --- a/packages/cli/src/core/parser/source/get-declaration-kind.ts +++ b/packages/cli/src/core/parser/source/get-declaration-kind.ts @@ -1,9 +1,7 @@ import { Node, ExportedDeclarations } from "ts-morph"; import { DeclarationKind } from "../../types/parser.types.js"; -export function getDeclarationKind( - declaration: ExportedDeclarations, -): DeclarationKind | undefined { +export function getDeclarationKind(declaration: ExportedDeclarations): DeclarationKind | undefined { if (Node.isFunctionDeclaration(declaration)) { return "function"; } @@ -26,11 +24,7 @@ export function getDeclarationKind( if (Node.isVariableDeclaration(declaration)) { const initializer = declaration.getInitializer(); - if ( - initializer && - (Node.isArrowFunction(initializer) || - Node.isFunctionExpression(initializer)) - ) { + if (initializer && (Node.isArrowFunction(initializer) || Node.isFunctionExpression(initializer))) { return "function"; } return "variable"; diff --git a/packages/cli/src/core/parser/source/get-exported-declarations-by-sourcefile.ts b/packages/cli/src/core/parser/source/get-exported-declarations-by-sourcefile.ts index 229d163..38c70c7 100644 --- a/packages/cli/src/core/parser/source/get-exported-declarations-by-sourcefile.ts +++ b/packages/cli/src/core/parser/source/get-exported-declarations-by-sourcefile.ts @@ -4,15 +4,13 @@ import { getDeclarationKind } from "./get-declaration-kind.js"; import { getJSDoc } from "../jsdoc/jsdoc-utils.js"; import { extractSignature } from "./extract-signature.js"; -export function getExportedDeclarationsBySourceFile( - sourceFile: SourceFile, -): ExportDeclaration[] { +export function getExportedDeclarationsBySourceFile(sourceFile: SourceFile): ExportDeclaration[] { const filePath = sourceFile.getFilePath(); const exportedDeclarations = sourceFile.getExportedDeclarations(); return Array.from(exportedDeclarations) .flatMap(([symbolName, declarations]) => - declarations.map((declaration) => { + declarations.map(declaration => { const kind = getDeclarationKind(declaration); const jsDoc = getJSDoc(declaration); const signature = extractSignature(declaration); @@ -29,7 +27,7 @@ export function getExportedDeclarationsBySourceFile( jsDoc, signature, }; - }), + }) ) .filter((item): item is ExportDeclaration => item !== null); } diff --git a/packages/cli/src/core/types/generator.types.ts b/packages/cli/src/core/types/generator.types.ts index 6d7a639..7e2c6ef 100644 --- a/packages/cli/src/core/types/generator.types.ts +++ b/packages/cli/src/core/types/generator.types.ts @@ -1,8 +1,4 @@ -import { - TargetWithJSDoc, - ParsedJSDoc, - StandardizedFilePath, -} from "./parser.types.js"; +import { TargetWithJSDoc, ParsedJSDoc, StandardizedFilePath } from "./parser.types.js"; /** * @public @@ -11,7 +7,7 @@ import { * @name GeneratorConfig * @description * Configuration for the markdown generator. Defines generator name, project root, labels, and signature language. - * + * * @param {string} name Name of the generator (e.g., 'vitepress', 'nextra') * @param {string} projectRoot Absolute path to the project root directory * @param {object} [labels] Custom labels for documentation sections @@ -62,7 +58,7 @@ export const defaultVitePressLabels = { * @name MarkdownSection * @description * Interface representing a section of a markdown document. - * + * * @param {string} type Type of the markdown section (title, description, signature, etc.) * @param {string} content Section content in markdown format */ @@ -91,7 +87,7 @@ type MarkdownSectionType = * @name MarkdownDocument * @description * Structure representing a complete markdown document with optional frontmatter and sections. - * + * * @param {object} [frontmatter] Optional frontmatter data for the document * @param {MarkdownSection[]} sections Array of sections that make up the document content */ @@ -107,7 +103,7 @@ export interface MarkdownDocument { * @name GeneratedDoc * @description * Document generation result containing file path, content, and relative path information. - * + * * @param {StandardizedFilePath} filePath Absolute file path where the document will be saved * @param {string} content Generated markdown content * @param {string} relativePath Relative path from the output directory @@ -125,7 +121,7 @@ export interface GeneratedDoc { * @name MarkdownGenerator * @description * Interface for markdown generators that convert JSDoc data to markdown documents. - * + * * @param {function} generate Function to convert JSDoc data to markdown document structure * @param {function} serialize Function to convert markdown document to string * @param {function} generateDocs Function to generate document files from targets @@ -133,8 +129,5 @@ export interface GeneratedDoc { export interface MarkdownGenerator { generate(jsDocData: ParsedJSDoc, sourcePath?: string): MarkdownDocument; serialize(markdownDoc: MarkdownDocument): string; - generateDocs( - targetsWithJSDoc: TargetWithJSDoc, - packagePath: string, - ): GeneratedDoc; + generateDocs(targetsWithJSDoc: TargetWithJSDoc, packagePath: string): GeneratedDoc; } diff --git a/packages/cli/src/core/types/parser.types.ts b/packages/cli/src/core/types/parser.types.ts index 3a3ce1f..cd9cc70 100644 --- a/packages/cli/src/core/types/parser.types.ts +++ b/packages/cli/src/core/types/parser.types.ts @@ -7,7 +7,7 @@ import { ExportedDeclarations, JSDoc } from "ts-morph"; * @name ParsedJSDoc * @description * Represents the parsed result of JSDoc templates used in Docflow. - * + * * @param {string} [name] Name of the documented element * @param {string} [description] Description of the element * @param {string} [category] Category classification of the element @@ -45,7 +45,7 @@ export interface ParsedJSDoc { * @name PropertyData * @description * Represents property information of an object type. Used to describe object properties in ReturnData and TypedefData. - * + * * @param {string} name Name of the property * @param {string} description Description of the property * @param {boolean} required Whether the property is required @@ -65,7 +65,7 @@ interface PropertyData { * @name ExampleData * @description * Represents the parsed result of @example tags in JSDoc. - * + * * @param {string} [title] Optional title of the example * @param {string} code Example code content * @param {string} [language] Programming language for syntax highlighting @@ -83,7 +83,7 @@ export interface ExampleData { * @name ParameterData * @description * Represents the parsed result of @param tags in JSDoc. - * + * * @param {string} name Parameter name * @param {string} type Parameter type * @param {string} description Parameter description @@ -107,7 +107,7 @@ export interface ParameterData { * @name ReturnData * @description * Represents the parsed result of @returns tags in JSDoc. Used to describe return value information of functions. - * + * * @param {string} type Type of the return value * @param {string} [name] Optional name of the return value * @param {string} description Description of the return value @@ -127,7 +127,7 @@ export interface ReturnData { * @name ThrowsData * @description * Represents the parsed result of @throws tags in JSDoc. Used to describe exception information that can occur in functions. - * + * * @param {string} type Type of the exception * @param {string} [name] Optional name of the exception * @param {string} description Exception occurrence conditions and description @@ -145,7 +145,7 @@ export interface ThrowsData { * @name TypedefData * @description * Represents the parsed result of @typedef tags in JSDoc. Used to define custom types or complex object structures. - * + * * @param {string} name Name of the type * @param {string} type Base type of the type (e.g., Object, Array, etc.) * @param {string} description Description of the type @@ -165,7 +165,7 @@ export interface TypedefData { * @name SeeData * @description * Represents the parsed result of @see tags in JSDoc. Used to provide references to external documents or related content. - * + * * @param {string} reference URL or link to the external document to reference * @param {string} [description] Optional description for the reference */ @@ -181,7 +181,7 @@ export interface SeeData { * @name VersionData * @description * Represents the parsed result of @version tags in JSDoc. Used to display version information in table format. - * + * * @param {string} version Version number * @param {string} description Description of changes in the version * @param {string[]} [platforms] List of supported platforms (optional) @@ -199,7 +199,7 @@ export interface VersionData { * @name TargetWithJSDoc * @description * Parsed JSDoc data for document generation, extending the [ExportDeclaration](/en/reference/cli/parser/ExportDeclaration) interface. - * + * * @param {ParsedJSDoc} parsedJSDoc Parsed result of JSDoc templates used in Docflow */ export interface TargetWithJSDoc extends ExportDeclaration { @@ -214,13 +214,7 @@ export interface TargetWithJSDoc extends ExportDeclaration { * @description * Represents the types of TypeScript declarations that can be documented. */ -export type DeclarationKind = - | "function" - | "class" - | "interface" - | "type" - | "enum" - | "variable"; +export type DeclarationKind = "function" | "class" | "interface" | "type" | "enum" | "variable"; /** * @public @@ -241,7 +235,7 @@ export type StandardizedFilePath = string & { * @name ExportDeclaration * @description * Represents an exported declaration with metadata including file path, symbol name, and JSDoc information. - * + * * @param {StandardizedFilePath} filePath Standardized file path of the exported declaration * @param {string} symbolName Symbol name of the exported declaration * @param {ExportedDeclarations} declaration TypeScript declaration object diff --git a/packages/cli/src/package-manager/create-package-manager.ts b/packages/cli/src/package-manager/create-package-manager.ts index 9af562b..c4de861 100644 --- a/packages/cli/src/package-manager/create-package-manager.ts +++ b/packages/cli/src/package-manager/create-package-manager.ts @@ -3,10 +3,7 @@ import { YarnPackageManager } from "./package-managers/yarn-package-manager.js"; import { PnpmPackageManager } from "./package-managers/pnpm-package-manager.js"; import { NpmPackageManager } from "./package-managers/npm-package-manager.js"; -export function createPackageManager( - type: "yarn" | "pnpm" | "npm", - cwd: string, -): PackageManager { +export function createPackageManager(type: "yarn" | "pnpm" | "npm", cwd: string): PackageManager { switch (type) { case "yarn": return new YarnPackageManager(cwd); diff --git a/packages/cli/src/package-manager/package-managers/npm-package-manager.ts b/packages/cli/src/package-manager/package-managers/npm-package-manager.ts index 4aa72ca..bd2de8f 100644 --- a/packages/cli/src/package-manager/package-managers/npm-package-manager.ts +++ b/packages/cli/src/package-manager/package-managers/npm-package-manager.ts @@ -9,7 +9,7 @@ const npmSchema = z.object({ }); export class NpmPackageManager implements PackageManager { - constructor(private cwd: string) { } + constructor(private cwd: string) {} getPackages(): Package[] { try { @@ -18,7 +18,7 @@ export class NpmPackageManager implements PackageManager { if (!Array.isArray(parsed)) return []; return parsed - .map((ws) => npmSchema.parse(ws)) + .map(ws => npmSchema.parse(ws)) .map(({ name, path: pkgPath }) => ({ name, location: path.relative(this.cwd, pkgPath), diff --git a/packages/cli/src/package-manager/package-managers/pnpm-package-manager.ts b/packages/cli/src/package-manager/package-managers/pnpm-package-manager.ts index 6fd453d..aa9227a 100644 --- a/packages/cli/src/package-manager/package-managers/pnpm-package-manager.ts +++ b/packages/cli/src/package-manager/package-managers/pnpm-package-manager.ts @@ -9,7 +9,7 @@ const pnpmSchema = z.object({ }); export class PnpmPackageManager implements PackageManager { - constructor(private cwd: string) { } + constructor(private cwd: string) {} getPackages(): Package[] { try { @@ -17,8 +17,8 @@ export class PnpmPackageManager implements PackageManager { const parsed = JSON.parse(raw) as Array; return parsed - .map((pkg) => pnpmSchema.parse(pkg)) - .filter((pkg) => pkg.name !== undefined) + .map(pkg => pnpmSchema.parse(pkg)) + .filter(pkg => pkg.name !== undefined) .map(({ name, path: pkgPath }) => ({ name: name as string, location: path.relative(this.cwd, pkgPath), diff --git a/packages/cli/src/package-manager/package-managers/yarn-package-manager.ts b/packages/cli/src/package-manager/package-managers/yarn-package-manager.ts index 1ae4184..86f7a3c 100644 --- a/packages/cli/src/package-manager/package-managers/yarn-package-manager.ts +++ b/packages/cli/src/package-manager/package-managers/yarn-package-manager.ts @@ -10,7 +10,7 @@ const workspaceIdentitySchema = z.object({ }); export class YarnPackageManager implements PackageManager { - constructor(private cwd: string) { } + constructor(private cwd: string) {} getPackages(): Package[] { try { @@ -20,14 +20,14 @@ export class YarnPackageManager implements PackageManager { return output .split("\n") .filter(Boolean) - .map((line) => workspaceIdentitySchema.parse(JSON.parse(line))) - .filter((ws) => ws.name !== null) - .map((ws) => { + .map(line => workspaceIdentitySchema.parse(JSON.parse(line))) + .filter(ws => ws.name !== null) + .map(ws => { const locationAbsolutePath = path.join(repoRootPath, ws.location); return { name: ws.name as string, - location: path.relative(this.cwd, locationAbsolutePath) + location: path.relative(this.cwd, locationAbsolutePath), }; }); } catch { diff --git a/packages/cli/src/package-manager/utils/is-target-package.ts b/packages/cli/src/package-manager/utils/is-target-package.ts index 1b6a7f8..4a265f0 100644 --- a/packages/cli/src/package-manager/utils/is-target-package.ts +++ b/packages/cli/src/package-manager/utils/is-target-package.ts @@ -6,16 +6,11 @@ type TargetPackageConfig = { exclude: string[]; }; -export function isTargetPackage( - pkg: Package, - { include, exclude }: TargetPackageConfig, -): boolean { +export function isTargetPackage(pkg: Package, { include, exclude }: TargetPackageConfig): boolean { const { location } = pkg; - const isIncluded = - include.length === 0 || - include.some((pattern) => minimatch(location, pattern)); - const isExcluded = exclude.some((pattern) => minimatch(location, pattern)); + const isIncluded = include.length === 0 || include.some(pattern => minimatch(location, pattern)); + const isExcluded = exclude.some(pattern => minimatch(location, pattern)); return isIncluded && !isExcluded; } diff --git a/packages/cli/src/plugins/load-plugins.ts b/packages/cli/src/plugins/load-plugins.ts index b5c3a99..6e130b4 100644 --- a/packages/cli/src/plugins/load-plugins.ts +++ b/packages/cli/src/plugins/load-plugins.ts @@ -6,31 +6,23 @@ export async function loadPlugins(config: Config): Promise { for (const pluginConfig of config.plugins) { try { - const pluginInstance = await pluginConfig.plugin( - pluginConfig.options || {}, - ); + const pluginInstance = await pluginConfig.plugin(pluginConfig.options || {}); if (!pluginInstance || typeof pluginInstance !== "object") { - throw new Error( - `Plugin factory for '${pluginConfig.name}' did not return a valid plugin object`, - ); + throw new Error(`Plugin factory for '${pluginConfig.name}' did not return a valid plugin object`); } const plugin = pluginInstance as Plugin; if (!plugin.hooks) { - throw new Error( - `Plugin '${pluginConfig.name}' must have hooks defined`, - ); + throw new Error(`Plugin '${pluginConfig.name}' must have hooks defined`); } plugin.name = pluginConfig.name; plugins.push(plugin); } catch (error) { throw new Error( - `Failed to load plugin '${pluginConfig.name}': ${ - error instanceof Error ? error.message : String(error) - }`, + `Failed to load plugin '${pluginConfig.name}': ${error instanceof Error ? error.message : String(error)}` ); } } diff --git a/packages/cli/src/plugins/plugin-manager.ts b/packages/cli/src/plugins/plugin-manager.ts index cb669fe..befc5e2 100644 --- a/packages/cli/src/plugins/plugin-manager.ts +++ b/packages/cli/src/plugins/plugin-manager.ts @@ -26,9 +26,7 @@ export class PluginManager { return this.plugins.reduce((current, plugin) => { const { transformManifest } = plugin.hooks; - return transformManifest - ? transformManifest(current, this.context) - : current; + return transformManifest ? transformManifest(current, this.context) : current; }, manifest); } @@ -46,22 +44,13 @@ export class PluginManager { } } - const plugin = this.plugins.find((p) => p.name === generatorConfig.name); + const plugin = this.plugins.find(p => p.name === generatorConfig.name); if (plugin?.hooks.provideGenerator) { return plugin.hooks.provideGenerator(); } - const availableGenerators = [ - "vitepress", - ...this.plugins - .filter((p) => p.hooks.provideGenerator) - .map((p) => p.name), - ]; - throw new Error( - `Generator '${ - generatorConfig.name - }' not found. Available: ${availableGenerators.join(", ")}`, - ); + const availableGenerators = ["vitepress", ...this.plugins.filter(p => p.hooks.provideGenerator).map(p => p.name)]; + throw new Error(`Generator '${generatorConfig.name}' not found. Available: ${availableGenerators.join(", ")}`); } getPlugins(): Plugin[] { diff --git a/packages/cli/src/plugins/types/plugin.types.ts b/packages/cli/src/plugins/types/plugin.types.ts index c3a633e..e9ca232 100644 --- a/packages/cli/src/plugins/types/plugin.types.ts +++ b/packages/cli/src/plugins/types/plugin.types.ts @@ -9,7 +9,7 @@ import { MarkdownGenerator } from "../../core/types/generator.types.js"; * @name PluginContext * @description * Context information passed during plugin execution. Includes workspace path and configuration data. - * + * * @param {string} [workspacePath] Absolute path to the workspace root directory * @param {Config} [config] Complete configuration object including project, command, and plugin settings */ @@ -25,7 +25,7 @@ export interface PluginContext { * @name Plugin * @description * Interface defining the basic structure of a Docflow plugin. Includes plugin name and hook functions. - * + * * @param {string} name Unique identifier for the plugin * @param {object} hooks Object containing hook functions that the plugin can implement * @param {function} [hooks.transformManifest] Hook to transform generated manifest data @@ -34,10 +34,7 @@ export interface PluginContext { export interface Plugin { name: string; hooks: { - transformManifest?: ( - manifest: SidebarItem[], - context: PluginContext, - ) => SidebarItem[]; + transformManifest?: (manifest: SidebarItem[], context: PluginContext) => SidebarItem[]; provideGenerator?: () => MarkdownGenerator; }; } diff --git a/packages/cli/src/tests/commands/build/manifest/manifest.spec.ts b/packages/cli/src/tests/commands/build/manifest/manifest.spec.ts index d8780b0..d258714 100644 --- a/packages/cli/src/tests/commands/build/manifest/manifest.spec.ts +++ b/packages/cli/src/tests/commands/build/manifest/manifest.spec.ts @@ -94,7 +94,7 @@ describe("Manifest", () => { manifest.add("beta/file.md"); const output = JSON.parse(manifest.toString()); - const topLevelTexts = output.map((item) => item.text); + const topLevelTexts = output.map(item => item.text); expect(topLevelTexts).toEqual(["alpha", "beta", "zebra"]); }); diff --git a/packages/cli/src/tests/config/config.schema.spec.ts b/packages/cli/src/tests/config/config.schema.spec.ts index df2aba2..977579a 100644 --- a/packages/cli/src/tests/config/config.schema.spec.ts +++ b/packages/cli/src/tests/config/config.schema.spec.ts @@ -54,8 +54,7 @@ describe("configSchema", () => { ...validConfig, project: { ...validConfig.project, - packageManager: - "invalid" as unknown as Config["project"]["packageManager"], + packageManager: "invalid" as unknown as Config["project"]["packageManager"], }, }; @@ -70,8 +69,7 @@ describe("configSchema", () => { ...validConfig.project, workspace: { ...validConfig.project.workspace, - include: - "not-array" as unknown as Config["project"]["workspace"]["include"], + include: "not-array" as unknown as Config["project"]["workspace"]["include"], }, }, }; diff --git a/packages/cli/src/tests/config/load-config.spec.ts b/packages/cli/src/tests/config/load-config.spec.ts index a862467..d5cd94e 100644 --- a/packages/cli/src/tests/config/load-config.spec.ts +++ b/packages/cli/src/tests/config/load-config.spec.ts @@ -1,9 +1,6 @@ import { describe, it, expect, beforeEach, afterEach } from "vitest"; import { loadConfig } from "../../config/load-config.js"; -import { - createE2EWorkspace, - E2EWorkspace, -} from "../utils/create-e2e-workspace.js"; +import { createE2EWorkspace, E2EWorkspace } from "../utils/create-e2e-workspace.js"; describe("loadConfig", () => { let workspace: E2EWorkspace; @@ -26,8 +23,6 @@ describe("loadConfig", () => { it("should throw error when config file is invalid", async () => { await workspace.write("docflow.config.js", "export default {}"); - await expect(loadConfig(workspace.root)).rejects.toThrow( - /Invalid config file/ - ); + await expect(loadConfig(workspace.root)).rejects.toThrow(/Invalid config file/); }); }); diff --git a/packages/cli/src/tests/core/generator/vitepress/vitepress-generator.spec.ts b/packages/cli/src/tests/core/generator/vitepress/vitepress-generator.spec.ts index 160ee62..ac051ca 100644 --- a/packages/cli/src/tests/core/generator/vitepress/vitepress-generator.spec.ts +++ b/packages/cli/src/tests/core/generator/vitepress/vitepress-generator.spec.ts @@ -125,10 +125,7 @@ export function testNoExamples(input: string): boolean { ` ); - const targetWithJSDoc = await tsHelper.getExportWithJSDoc( - "testNoExamples", - "test-no-examples.ts" - ); + const targetWithJSDoc = await tsHelper.getExportWithJSDoc("testNoExamples", "test-no-examples.ts"); const result = generator.generateDocs(targetWithJSDoc, "@test/core"); expect(result.content).not.toContain("## Examples"); diff --git a/packages/cli/src/tests/core/get-ts-config-path.spec.ts b/packages/cli/src/tests/core/get-ts-config-path.spec.ts index 59a8ced..d040568 100644 --- a/packages/cli/src/tests/core/get-ts-config-path.spec.ts +++ b/packages/cli/src/tests/core/get-ts-config-path.spec.ts @@ -19,11 +19,7 @@ describe("getTsConfigPath", () => { const packageLocation = "packages/core"; const tsConfigPath = getTsConfigPath(projectRoot, packageLocation); - const expectedPath = path.join( - projectRoot, - packageLocation, - "tsconfig.json" - ); + const expectedPath = path.join(projectRoot, packageLocation, "tsconfig.json"); expect(tsConfigPath).toBe(expectedPath); }); @@ -40,11 +36,7 @@ describe("getTsConfigPath", () => { const packageLocation = "packages/core"; const tsConfigPath = getTsConfigPath(projectRoot, packageLocation); - const expectedPath = path.join( - projectRoot, - packageLocation, - "tsconfig.json" - ); + const expectedPath = path.join(projectRoot, packageLocation, "tsconfig.json"); expect(tsConfigPath).toBe(expectedPath); }); diff --git a/packages/cli/src/tests/core/get-ts-project.spec.ts b/packages/cli/src/tests/core/get-ts-project.spec.ts index 3b0fa76..db8cbd1 100644 --- a/packages/cli/src/tests/core/get-ts-project.spec.ts +++ b/packages/cli/src/tests/core/get-ts-project.spec.ts @@ -27,10 +27,10 @@ describe("getTsProject", () => { const project = getTsProject(tsConfigPath); const sourceFiles = project.getSourceFiles(); - const filePaths = sourceFiles.map((sf) => sf.getFilePath()); + const filePaths = sourceFiles.map(sf => sf.getFilePath()); - expect(filePaths.some((path) => path.includes("math.ts"))).toBe(true); - expect(filePaths.some((path) => path.includes("string.ts"))).toBe(true); + expect(filePaths.some(path => path.includes("math.ts"))).toBe(true); + expect(filePaths.some(path => path.includes("string.ts"))).toBe(true); }); it("should handle different packages correctly", async () => { @@ -38,9 +38,9 @@ describe("getTsProject", () => { const utilsProject = getTsProject(utilsConfigPath); const sourceFiles = utilsProject.getSourceFiles(); - const filePaths = sourceFiles.map((sf) => sf.getFilePath()); + const filePaths = sourceFiles.map(sf => sf.getFilePath()); - expect(filePaths.some((path) => path.includes("helpers.ts"))).toBe(true); - expect(filePaths.some((path) => path.includes("validators.ts"))).toBe(true); + expect(filePaths.some(path => path.includes("helpers.ts"))).toBe(true); + expect(filePaths.some(path => path.includes("validators.ts"))).toBe(true); }); }); diff --git a/packages/cli/src/tests/core/parser/jsdoc/jsdoc-parser.spec.ts b/packages/cli/src/tests/core/parser/jsdoc/jsdoc-parser.spec.ts index 28629a7..83fb89a 100644 --- a/packages/cli/src/tests/core/parser/jsdoc/jsdoc-parser.spec.ts +++ b/packages/cli/src/tests/core/parser/jsdoc/jsdoc-parser.spec.ts @@ -32,9 +32,7 @@ export function add(a: number, b: number): number { const jsDoc = func.getJsDocs()[0]!; const result = parser.parse(jsDoc); - expect(result.description).toContain( - "A simple function that adds two numbers" - ); + expect(result.description).toContain("A simple function that adds two numbers"); expect(result.parameters).toHaveLength(2); expect(result.parameters?.[0].name).toBe("a"); expect(result.parameters?.[0].type).toBe("number"); @@ -299,9 +297,7 @@ export function parseUserAgent(userAgent: string): { browser?: string; version?: expect(result.returns?.properties).toBeDefined(); expect(result.returns?.properties).toHaveLength(3); expect(result.returns?.properties?.[0].name).toBe("appVersion"); - expect(result.returns?.properties?.[0].description).toBe( - "App version info" - ); + expect(result.returns?.properties?.[0].description).toBe("App version info"); }); }); }); diff --git a/packages/cli/src/tests/core/parser/jsdoc/jsdoc-utils.spec.ts b/packages/cli/src/tests/core/parser/jsdoc/jsdoc-utils.spec.ts index 20bab87..8eb48cd 100644 --- a/packages/cli/src/tests/core/parser/jsdoc/jsdoc-utils.spec.ts +++ b/packages/cli/src/tests/core/parser/jsdoc/jsdoc-utils.spec.ts @@ -1,14 +1,8 @@ import { describe, it, expect, beforeEach, afterEach } from "vitest"; -import { - hasJSDocTag, - getJSDoc, -} from "../../../../core/parser/jsdoc/jsdoc-utils.js"; +import { hasJSDocTag, getJSDoc } from "../../../../core/parser/jsdoc/jsdoc-utils.js"; import { getTsProject } from "../../../../core/get-ts-project.js"; import { getTsConfigPath } from "../../../../core/get-ts-config-path.js"; -import { - createE2EWorkspace, - E2EWorkspace, -} from "../../../utils/create-e2e-workspace.js"; +import { createE2EWorkspace, E2EWorkspace } from "../../../utils/create-e2e-workspace.js"; describe("jsdoc-utils", () => { let workspace: E2EWorkspace; @@ -26,9 +20,7 @@ describe("jsdoc-utils", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const addFunction = mathFile?.getFunction("add"); expect(addFunction).toBeDefined(); @@ -41,9 +33,7 @@ describe("jsdoc-utils", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const subtractFunction = mathFile?.getFunction("subtract"); expect(subtractFunction).toBeDefined(); @@ -56,9 +46,7 @@ describe("jsdoc-utils", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const subtractFunction = mathFile?.getFunction("subtract"); expect(subtractFunction).toBeDefined(); @@ -85,9 +73,7 @@ export function testFunction() { ); const updatedProject = getTsProject(tsConfigPath); - const testFile = updatedProject - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("test-tags.ts")); + const testFile = updatedProject.getSourceFiles().find(sf => sf.getFilePath().includes("test-tags.ts")); const testFunction = testFile?.getFunction("testFunction"); expect(testFunction).toBeDefined(); @@ -105,9 +91,7 @@ export function testFunction() { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const addFunction = mathFile?.getFunction("add"); expect(addFunction).toBeDefined(); @@ -122,9 +106,7 @@ export function testFunction() { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const subtractFunction = mathFile?.getFunction("subtract"); expect(subtractFunction).toBeDefined(); @@ -138,9 +120,7 @@ export function testFunction() { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const piVariable = mathFile?.getVariableDeclaration("PI"); expect(piVariable).toBeDefined(); @@ -154,9 +134,7 @@ export function testFunction() { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const classFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("classes.ts")); + const classFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("classes.ts")); const userClass = classFile?.getClass("User"); expect(userClass).toBeDefined(); diff --git a/packages/cli/src/tests/core/parser/jsdoc/parse-jsdoc.spec.ts b/packages/cli/src/tests/core/parser/jsdoc/parse-jsdoc.spec.ts index 47724e4..2c948de 100644 --- a/packages/cli/src/tests/core/parser/jsdoc/parse-jsdoc.spec.ts +++ b/packages/cli/src/tests/core/parser/jsdoc/parse-jsdoc.spec.ts @@ -4,10 +4,7 @@ import { getTsProject } from "../../../../core/get-ts-project.js"; import { JSDocParser } from "../../../../core/parser/jsdoc/jsdoc-parser.js"; import { parseJSDoc } from "../../../../core/parser/jsdoc/parse-jsdoc.js"; import { getExportedDeclarationsBySourceFile } from "../../../../core/parser/source/get-exported-declarations-by-sourcefile.js"; -import { - createE2EWorkspace, - E2EWorkspace, -} from "../../../utils/create-e2e-workspace.js"; +import { createE2EWorkspace, E2EWorkspace } from "../../../utils/create-e2e-workspace.js"; describe("parseJSDoc", () => { let workspace: E2EWorkspace; @@ -25,14 +22,10 @@ describe("parseJSDoc", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const exportDeclarations = getExportedDeclarationsBySourceFile(mathFile!); - const addExport = exportDeclarations.find( - (exp) => exp.symbolName === "add" - ); + const addExport = exportDeclarations.find(exp => exp.symbolName === "add"); expect(addExport).toBeDefined(); @@ -62,14 +55,10 @@ export function minimalJSDoc(x: number): number { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const testFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("test-minimal-jsdoc.ts")); + const testFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("test-minimal-jsdoc.ts")); const exportDeclarations = getExportedDeclarationsBySourceFile(testFile!); - const minimalExport = exportDeclarations.find( - (exp) => exp.symbolName === "minimalJSDoc" - ); + const minimalExport = exportDeclarations.find(exp => exp.symbolName === "minimalJSDoc"); expect(minimalExport).toBeDefined(); @@ -86,14 +75,10 @@ export function minimalJSDoc(x: number): number { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const exportDeclarations = getExportedDeclarationsBySourceFile(mathFile!); - const addExport = exportDeclarations.find( - (exp) => exp.symbolName === "add" - ); + const addExport = exportDeclarations.find(exp => exp.symbolName === "add"); expect(addExport).toBeDefined(); @@ -113,14 +98,10 @@ export function minimalJSDoc(x: number): number { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const exportDeclarations = getExportedDeclarationsBySourceFile(mathFile!); - const addExport = exportDeclarations.find( - (exp) => exp.symbolName === "add" - ); + const addExport = exportDeclarations.find(exp => exp.symbolName === "add"); expect(addExport).toBeDefined(); @@ -135,14 +116,10 @@ export function minimalJSDoc(x: number): number { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const exportDeclarations = getExportedDeclarationsBySourceFile(mathFile!); - const addExport = exportDeclarations.find( - (exp) => exp.symbolName === "add" - ); + const addExport = exportDeclarations.find(exp => exp.symbolName === "add"); expect(addExport).toBeDefined(); @@ -158,14 +135,10 @@ export function minimalJSDoc(x: number): number { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const exportDeclarations = getExportedDeclarationsBySourceFile(mathFile!); - const addExport = exportDeclarations.find( - (exp) => exp.symbolName === "add" - ); + const addExport = exportDeclarations.find(exp => exp.symbolName === "add"); expect(addExport).toBeDefined(); @@ -182,14 +155,10 @@ export function minimalJSDoc(x: number): number { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const exportDeclarations = getExportedDeclarationsBySourceFile(mathFile!); - const multiplyExport = exportDeclarations.find( - (exp) => exp.symbolName === "multiply" - ); + const multiplyExport = exportDeclarations.find(exp => exp.symbolName === "multiply"); expect(multiplyExport).toBeDefined(); expect(multiplyExport!.kind).toBe("function"); diff --git a/packages/cli/src/tests/core/parser/jsdoc/update-jsdoc.spec.ts b/packages/cli/src/tests/core/parser/jsdoc/update-jsdoc.spec.ts index 957c2e6..8265ae8 100644 --- a/packages/cli/src/tests/core/parser/jsdoc/update-jsdoc.spec.ts +++ b/packages/cli/src/tests/core/parser/jsdoc/update-jsdoc.spec.ts @@ -22,15 +22,13 @@ describe("updateJSDoc", () => { export function testFunction(param: string): boolean { return param.length > 0; } - `, + ` ); const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const testFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("test-update.ts")); + const testFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("test-update.ts")); const testFunction = testFile?.getFunction("testFunction"); expect(testFunction).toBeDefined(); @@ -60,15 +58,13 @@ export function testFunction(param: string): boolean { export function testFunction(param: string): boolean { return param.length > 0; } - `, + ` ); const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const testFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("test-replace.ts")); + const testFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("test-replace.ts")); const testFunction = testFile?.getFunction("testFunction"); expect(testFunction).toBeDefined(); @@ -93,15 +89,13 @@ export function testFunction(param: string): boolean { "packages/core/src/test-variable.ts", ` export const testVariable = "test value"; - `, + ` ); const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const testFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("test-variable.ts")); + const testFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("test-variable.ts")); const testVariable = testFile?.getVariableDeclaration("testVariable"); expect(testVariable).toBeDefined(); @@ -125,15 +119,13 @@ export const testVariable = "test value"; export class TestClass { constructor(public name: string) {} } - `, + ` ); const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const testFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("test-class.ts")); + const testFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("test-class.ts")); const testClass = testFile?.getClass("TestClass"); expect(testClass).toBeDefined(); @@ -158,15 +150,13 @@ export interface TestInterface { name: string; age: number; } - `, + ` ); const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const testFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("test-interface.ts")); + const testFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("test-interface.ts")); const testInterface = testFile?.getInterface("TestInterface"); expect(testInterface).toBeDefined(); @@ -194,15 +184,13 @@ export function firstFunction(): void { export function secondFunction(): void { console.log("second"); } - `, + ` ); const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const testFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("test-preserve.ts")); + const testFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("test-preserve.ts")); const firstFunction = testFile?.getFunction("firstFunction"); expect(firstFunction).toBeDefined(); @@ -226,15 +214,13 @@ export function secondFunction(): void { export function complexFunction(a: number, b: string, c?: boolean): string { return \`\${a}-\${b}-\${c}\`; } - `, + ` ); const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const testFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("test-multiline.ts")); + const testFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("test-multiline.ts")); const complexFunction = testFile?.getFunction("complexFunction"); expect(complexFunction).toBeDefined(); @@ -252,9 +238,7 @@ export function complexFunction(a: number, b: string, c?: boolean): string { updateJSDoc(complexFunction!, newJSDoc); const updatedContent = testFile?.getFullText(); - expect(updatedContent).toContain( - "A complex function with multiple parameters", - ); + expect(updatedContent).toContain("A complex function with multiple parameters"); expect(updatedContent).toContain("@param a - The numeric parameter"); expect(updatedContent).toContain("@param b - The string parameter"); expect(updatedContent).toContain("@param c - Optional boolean parameter"); diff --git a/packages/cli/src/tests/core/parser/source/exclude-barrel-re-exports.spec.ts b/packages/cli/src/tests/core/parser/source/exclude-barrel-re-exports.spec.ts index 43b03c8..d581028 100644 --- a/packages/cli/src/tests/core/parser/source/exclude-barrel-re-exports.spec.ts +++ b/packages/cli/src/tests/core/parser/source/exclude-barrel-re-exports.spec.ts @@ -21,17 +21,13 @@ describe("excludeBarrelReExports", () => { const project = getTsProject(tsConfigPath); const sourceFiles = project.getSourceFiles(); - const allExportDeclarations = sourceFiles.flatMap((sf) => - getExportedDeclarationsBySourceFile(sf), - ); + const allExportDeclarations = sourceFiles.flatMap(sf => getExportedDeclarationsBySourceFile(sf)); const uniqueExports = excludeBarrelReExports(allExportDeclarations); - expect(uniqueExports.length).toBeLessThanOrEqual( - allExportDeclarations.length, - ); + expect(uniqueExports.length).toBeLessThanOrEqual(allExportDeclarations.length); - const symbolNames = uniqueExports.map((exp) => exp.symbolName); + const symbolNames = uniqueExports.map(exp => exp.symbolName); const uniqueSymbolNames = [...new Set(symbolNames)]; expect(symbolNames.length).toBe(uniqueSymbolNames.length); }); @@ -41,13 +37,11 @@ describe("excludeBarrelReExports", () => { const project = getTsProject(tsConfigPath); const sourceFiles = project.getSourceFiles(); - const allExportDeclarations = sourceFiles.flatMap((sf) => - getExportedDeclarationsBySourceFile(sf), - ); + const allExportDeclarations = sourceFiles.flatMap(sf => getExportedDeclarationsBySourceFile(sf)); const uniqueExports = excludeBarrelReExports(allExportDeclarations); - const addExport = uniqueExports.find((exp) => exp.symbolName === "add"); + const addExport = uniqueExports.find(exp => exp.symbolName === "add"); expect(addExport).toBeDefined(); expect(addExport!.filePath).toContain("math.ts"); @@ -64,9 +58,7 @@ describe("excludeBarrelReExports", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const exportDeclarations = getExportedDeclarationsBySourceFile(mathFile!); const singleExport = exportDeclarations.slice(0, 1); @@ -81,12 +73,8 @@ describe("excludeBarrelReExports", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); - const stringFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("string.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); + const stringFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("string.ts")); const mathExports = getExportedDeclarationsBySourceFile(mathFile!); const stringExports = getExportedDeclarationsBySourceFile(stringFile!); @@ -94,9 +82,9 @@ describe("excludeBarrelReExports", () => { const allExports = [...mathExports, ...stringExports]; const uniqueExports = excludeBarrelReExports(allExports); - const filePaths = [...new Set(uniqueExports.map((exp) => exp.filePath))]; + const filePaths = [...new Set(uniqueExports.map(exp => exp.filePath))]; expect(filePaths.length).toBeGreaterThan(1); - expect(filePaths.some((path) => path.includes("math.ts"))).toBe(true); - expect(filePaths.some((path) => path.includes("string.ts"))).toBe(true); + expect(filePaths.some(path => path.includes("math.ts"))).toBe(true); + expect(filePaths.some(path => path.includes("string.ts"))).toBe(true); }); }); diff --git a/packages/cli/src/tests/core/parser/source/extract-signature.spec.ts b/packages/cli/src/tests/core/parser/source/extract-signature.spec.ts index af20d2d..088abda 100644 --- a/packages/cli/src/tests/core/parser/source/extract-signature.spec.ts +++ b/packages/cli/src/tests/core/parser/source/extract-signature.spec.ts @@ -19,9 +19,7 @@ describe("extractSignature", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const addFunction = mathFile?.getFunction("add"); expect(addFunction).toBeDefined(); @@ -36,9 +34,7 @@ describe("extractSignature", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const multiplyVariable = mathFile?.getVariableDeclaration("multiply"); expect(multiplyVariable).toBeDefined(); @@ -52,9 +48,7 @@ describe("extractSignature", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const classFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("classes.ts")); + const classFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("classes.ts")); const userClass = classFile?.getClass("User"); expect(userClass).toBeDefined(); @@ -68,9 +62,7 @@ describe("extractSignature", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/types"); const project = getTsProject(tsConfigPath); - const configFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("index.ts")); + const configFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("index.ts")); const userConfigInterface = configFile?.getInterface("UserConfig"); expect(userConfigInterface).toBeDefined(); @@ -84,9 +76,7 @@ describe("extractSignature", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const statusEnum = mathFile?.getEnum("Status"); expect(statusEnum).toBeDefined(); @@ -102,9 +92,7 @@ describe("extractSignature", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const classesFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("classes.ts")); + const classesFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("classes.ts")); const importStatement = classesFile?.getImportDeclarations()[0]; expect(importStatement).toBeDefined(); diff --git a/packages/cli/src/tests/core/parser/source/get-declaration-kind.spec.ts b/packages/cli/src/tests/core/parser/source/get-declaration-kind.spec.ts index ab0bfc3..99e3a76 100644 --- a/packages/cli/src/tests/core/parser/source/get-declaration-kind.spec.ts +++ b/packages/cli/src/tests/core/parser/source/get-declaration-kind.spec.ts @@ -19,9 +19,7 @@ describe("getDeclarationKind", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const addFunction = mathFile?.getFunction("add"); expect(addFunction).toBeDefined(); @@ -34,9 +32,7 @@ describe("getDeclarationKind", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const piVariable = mathFile?.getVariableDeclaration("PI"); expect(piVariable).toBeDefined(); @@ -49,9 +45,7 @@ describe("getDeclarationKind", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const classFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("classes.ts")); + const classFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("classes.ts")); const userClass = classFile?.getClass("User"); expect(userClass).toBeDefined(); @@ -65,9 +59,7 @@ describe("getDeclarationKind", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/types"); const project = getTsProject(tsConfigPath); - const configFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("index.ts")); + const configFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("index.ts")); const userConfigInterface = configFile?.getInterface("UserConfig"); expect(userConfigInterface).toBeDefined(); @@ -81,9 +73,7 @@ describe("getDeclarationKind", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/types"); const project = getTsProject(tsConfigPath); - const configFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("index.ts")); + const configFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("index.ts")); const idTypeAlias = configFile?.getTypeAlias("ID"); expect(idTypeAlias).toBeDefined(); @@ -97,9 +87,7 @@ describe("getDeclarationKind", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const statusEnum = mathFile?.getEnum("Status"); expect(statusEnum).toBeDefined(); @@ -113,9 +101,7 @@ describe("getDeclarationKind", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const classesFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("classes.ts")); + const classesFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("classes.ts")); const importStatement = classesFile?.getImportDeclarations()[0]; expect(importStatement).toBeDefined(); diff --git a/packages/cli/src/tests/core/parser/source/get-exported-declarations-by-sourcefile.spec.ts b/packages/cli/src/tests/core/parser/source/get-exported-declarations-by-sourcefile.spec.ts index d4bd341..0e10fdd 100644 --- a/packages/cli/src/tests/core/parser/source/get-exported-declarations-by-sourcefile.spec.ts +++ b/packages/cli/src/tests/core/parser/source/get-exported-declarations-by-sourcefile.spec.ts @@ -2,10 +2,7 @@ import { describe, it, expect, beforeEach, afterEach } from "vitest"; import { getExportedDeclarationsBySourceFile } from "../../../../core/parser/source/get-exported-declarations-by-sourcefile.js"; import { getTsProject } from "../../../../core/get-ts-project.js"; import { getTsConfigPath } from "../../../../core/get-ts-config-path.js"; -import { - createE2EWorkspace, - E2EWorkspace, -} from "../../../utils/create-e2e-workspace.js"; +import { createE2EWorkspace, E2EWorkspace } from "../../../utils/create-e2e-workspace.js"; describe("getExportedDeclarationsBySourceFile", () => { let workspace: E2EWorkspace; @@ -22,9 +19,7 @@ describe("getExportedDeclarationsBySourceFile", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); expect(mathFile).toBeDefined(); @@ -32,7 +27,7 @@ describe("getExportedDeclarationsBySourceFile", () => { expect(exportDeclarations.length).toBeGreaterThan(0); - const symbolNames = exportDeclarations.map((decl) => decl.symbolName); + const symbolNames = exportDeclarations.map(decl => decl.symbolName); expect(symbolNames).toContain("add"); expect(symbolNames).toContain("multiply"); expect(symbolNames).toContain("PI"); @@ -43,15 +38,11 @@ describe("getExportedDeclarationsBySourceFile", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const exportDeclarations = getExportedDeclarationsBySourceFile(mathFile!); - const addDeclaration = exportDeclarations.find( - (decl) => decl.symbolName === "add" - ); + const addDeclaration = exportDeclarations.find(decl => decl.symbolName === "add"); expect(addDeclaration).toBeDefined(); expect(addDeclaration!.kind).toBe("function"); expect(addDeclaration!.signature).toContain("function add"); @@ -75,15 +66,11 @@ const internalVariable = "test"; ); const updatedProject = getTsProject(tsConfigPath); - const noExportsFile = updatedProject - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("no-exports.ts")); + const noExportsFile = updatedProject.getSourceFiles().find(sf => sf.getFilePath().includes("no-exports.ts")); expect(noExportsFile).toBeDefined(); - const exportDeclarations = getExportedDeclarationsBySourceFile( - noExportsFile! - ); + const exportDeclarations = getExportedDeclarationsBySourceFile(noExportsFile!); expect(exportDeclarations).toHaveLength(0); }); @@ -92,16 +79,14 @@ const internalVariable = "test"; const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const indexFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("index.ts")); + const indexFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("index.ts")); expect(indexFile).toBeDefined(); const exportDeclarations = getExportedDeclarationsBySourceFile(indexFile!); expect(exportDeclarations.length).toBeGreaterThan(0); - const symbolNames = exportDeclarations.map((decl) => decl.symbolName); + const symbolNames = exportDeclarations.map(decl => decl.symbolName); expect(symbolNames).toContain("add"); expect(symbolNames).toContain("multiply"); expect(symbolNames).toContain("toUpper"); @@ -112,23 +97,17 @@ const internalVariable = "test"; const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); const exportDeclarations = getExportedDeclarationsBySourceFile(mathFile!); - const withJSDoc = exportDeclarations.filter( - (decl) => decl.jsDoc !== undefined - ); - const withoutJSDoc = exportDeclarations.filter( - (decl) => decl.jsDoc === undefined - ); + const withJSDoc = exportDeclarations.filter(decl => decl.jsDoc !== undefined); + const withoutJSDoc = exportDeclarations.filter(decl => decl.jsDoc === undefined); expect(withJSDoc.length).toBeGreaterThan(0); expect(withoutJSDoc.length).toBeGreaterThan(0); - exportDeclarations.forEach((decl) => { + exportDeclarations.forEach(decl => { expect(decl.kind).toBeDefined(); expect(decl.signature).toBeDefined(); expect(decl.filePath).toBeDefined(); diff --git a/packages/cli/src/tests/core/parser/source/is-export-source-file.spec.ts b/packages/cli/src/tests/core/parser/source/is-export-source-file.spec.ts index 71968b9..7209e8c 100644 --- a/packages/cli/src/tests/core/parser/source/is-export-source-file.spec.ts +++ b/packages/cli/src/tests/core/parser/source/is-export-source-file.spec.ts @@ -2,10 +2,7 @@ import { describe, it, expect, beforeEach, afterEach } from "vitest"; import { isExportSourceFile } from "../../../../core/parser/source/is-export-source-file.js"; import { getTsProject } from "../../../../core/get-ts-project.js"; import { getTsConfigPath } from "../../../../core/get-ts-config-path.js"; -import { - createE2EWorkspace, - E2EWorkspace, -} from "../../../utils/create-e2e-workspace.js"; +import { createE2EWorkspace, E2EWorkspace } from "../../../utils/create-e2e-workspace.js"; describe("isExportSourceFile", () => { let workspace: E2EWorkspace; @@ -22,9 +19,7 @@ describe("isExportSourceFile", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const mathFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("math.ts")); + const mathFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("math.ts")); expect(mathFile).toBeDefined(); expect(isExportSourceFile(mathFile!)).toBe(true); @@ -34,9 +29,7 @@ describe("isExportSourceFile", () => { const tsConfigPath = getTsConfigPath(workspace.root, "packages/core"); const project = getTsProject(tsConfigPath); - const indexFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("index.ts")); + const indexFile = project.getSourceFiles().find(sf => sf.getFilePath().includes("index.ts")); expect(indexFile).toBeDefined(); expect(isExportSourceFile(indexFile!)).toBe(true); @@ -57,9 +50,7 @@ const internalVariable = "test"; ); const updatedProject = getTsProject(tsConfigPath); - const noExportsFile = updatedProject - .getSourceFiles() - .find((sf) => sf.getFilePath().includes("no-exports.ts")); + const noExportsFile = updatedProject.getSourceFiles().find(sf => sf.getFilePath().includes("no-exports.ts")); expect(noExportsFile).toBeDefined(); expect(isExportSourceFile(noExportsFile!)).toBe(false); diff --git a/packages/cli/src/tests/e2e/workflow.e2e.spec.ts b/packages/cli/src/tests/e2e/workflow.e2e.spec.ts index a387210..c007b9e 100644 --- a/packages/cli/src/tests/e2e/workflow.e2e.spec.ts +++ b/packages/cli/src/tests/e2e/workflow.e2e.spec.ts @@ -1,8 +1,5 @@ import { describe, it, expect, beforeEach, afterEach } from "vitest"; -import { - createE2EWorkspace, - E2EWorkspace, -} from "../utils/create-e2e-workspace.js"; +import { createE2EWorkspace, E2EWorkspace } from "../utils/create-e2e-workspace.js"; import { execSync } from "child_process"; import type { SidebarItem } from "../../commands/build/manifest/manifest.js"; @@ -67,9 +64,7 @@ describe("workflow", () => { stdio: "inherit", }); - const manifestContent = await workspace.read( - "docs/references/manifest.json" - ); + const manifestContent = await workspace.read("docs/references/manifest.json"); expect(manifestContent).toBeDefined(); const manifest: unknown = JSON.parse(manifestContent); @@ -83,23 +78,19 @@ describe("workflow", () => { expect(manifest.length).toBeGreaterThanOrEqual(2); - const coreSection = manifest.find((section) => section.text === "core"); - const mathSection = manifest.find((section) => section.text === "math"); + const coreSection = manifest.find(section => section.text === "core"); + const mathSection = manifest.find(section => section.text === "math"); expect(coreSection).toBeDefined(); expect(mathSection).toBeDefined(); expect(coreSection?.items?.length).toBeGreaterThanOrEqual(1); expect(mathSection?.items?.length).toBeGreaterThanOrEqual(1); - const fetchDataMd = await workspace.read( - "docs/references/core/index/fetchData.md" - ); + const fetchDataMd = await workspace.read("docs/references/core/index/fetchData.md"); expect(fetchDataMd).toContain("# fetchData"); expect(fetchDataMd).toContain("data from the given URL"); expect(fetchDataMd).toContain("@libs/core"); - const calculateAreaMd = await workspace.read( - "docs/references/math/index/calculateArea.md" - ); + const calculateAreaMd = await workspace.read("docs/references/math/index/calculateArea.md"); expect(calculateAreaMd).toContain("# calculateArea"); expect(calculateAreaMd).toContain("the area of a circle"); expect(calculateAreaMd).toContain("@libs/math"); diff --git a/packages/cli/src/tests/package-manager/package-manager.spec.ts b/packages/cli/src/tests/package-manager/package-manager.spec.ts index fe57789..b4efbac 100644 --- a/packages/cli/src/tests/package-manager/package-manager.spec.ts +++ b/packages/cli/src/tests/package-manager/package-manager.spec.ts @@ -74,10 +74,7 @@ describe("PackageManager integration", () => { it("PnpmPackageManager should parse workspaces correctly", async () => { const workspace = await createE2EWorkspace({ packageManager: "pnpm" }); try { - await workspace.write( - "pnpm-workspace.yaml", - "packages:\n - 'packages/*'\n" - ); + await workspace.write("pnpm-workspace.yaml", "packages:\n - 'packages/*'\n"); const pnpm = new PnpmPackageManager(workspace.root); const result = pnpm.getPackages(); @@ -118,7 +115,7 @@ describe("isTargetPackage", () => { ]; it("should return all packages when include is empty", () => { - const result = mockPackages.filter((pkg) => + const result = mockPackages.filter(pkg => isTargetPackage(pkg, { include: [], exclude: [], @@ -129,7 +126,7 @@ describe("isTargetPackage", () => { }); it("should filter packages by include patterns", () => { - const result = mockPackages.filter((pkg) => + const result = mockPackages.filter(pkg => isTargetPackage(pkg, { include: ["packages/*"], exclude: [], @@ -143,7 +140,7 @@ describe("isTargetPackage", () => { }); it("should exclude packages by exclude patterns", () => { - const result = mockPackages.filter((pkg) => + const result = mockPackages.filter(pkg => isTargetPackage(pkg, { include: [], exclude: ["apps/*"], @@ -158,7 +155,7 @@ describe("isTargetPackage", () => { }); it("should combine include and exclude patterns", () => { - const result = mockPackages.filter((pkg) => + const result = mockPackages.filter(pkg => isTargetPackage(pkg, { include: ["packages/*", "apps/*"], exclude: ["apps/docs"], @@ -173,7 +170,7 @@ describe("isTargetPackage", () => { }); it("should handle multiple include patterns", () => { - const result = mockPackages.filter((pkg) => + const result = mockPackages.filter(pkg => isTargetPackage(pkg, { include: ["packages/*", "libs/*"], exclude: [], @@ -188,7 +185,7 @@ describe("isTargetPackage", () => { }); it("should handle multiple exclude patterns", () => { - const result = mockPackages.filter((pkg) => + const result = mockPackages.filter(pkg => isTargetPackage(pkg, { include: [], exclude: ["apps/*", "libs/*"], @@ -202,7 +199,7 @@ describe("isTargetPackage", () => { }); it("should return empty array when all packages are excluded", () => { - const result = mockPackages.filter((pkg) => + const result = mockPackages.filter(pkg => isTargetPackage(pkg, { include: ["packages/*"], exclude: ["packages/*"], diff --git a/packages/cli/src/tests/plugin/plugin-loader.spec.ts b/packages/cli/src/tests/plugin/plugin-loader.spec.ts index d409b4c..98fecb0 100644 --- a/packages/cli/src/tests/plugin/plugin-loader.spec.ts +++ b/packages/cli/src/tests/plugin/plugin-loader.spec.ts @@ -40,8 +40,7 @@ export default { plugins: [ { name: "my-plugin", - plugin: async () => - (await import(`${workspace.root}/my-plugin.js`)).default, + plugin: async () => (await import(`${workspace.root}/my-plugin.js`)).default, }, ], }; @@ -79,8 +78,7 @@ export const myNamedPlugin = { plugins: [ { name: "myNamedPlugin", - plugin: async () => - (await import(`${workspace.root}/named-plugin.js`)).myNamedPlugin, + plugin: async () => (await import(`${workspace.root}/named-plugin.js`)).myNamedPlugin, }, ], }; @@ -107,7 +105,7 @@ export const myNamedPlugin = { name: "inline-plugin", hooks: { transformManifest: (manifest: SidebarItem[]) => { - return manifest.map((item) => ({ ...item, inline: true })); + return manifest.map(item => ({ ...item, inline: true })); }, }, }), @@ -149,15 +147,12 @@ export const myNamedPlugin = { plugins: [ { name: "missing-plugin", - plugin: async () => - (await import(`${workspace.root}/nonexistent.js`)).default, + plugin: async () => (await import(`${workspace.root}/nonexistent.js`)).default, }, ], }; - await expect(loadPlugins(config)).rejects.toThrow( - "Failed to load plugin 'missing-plugin'" - ); + await expect(loadPlugins(config)).rejects.toThrow("Failed to load plugin 'missing-plugin'"); }); it("should throw error for plugin without path or hooks", async () => { @@ -176,9 +171,7 @@ export const myNamedPlugin = { ], }; - await expect(loadPlugins(config)).rejects.toThrow( - "pluginConfig.plugin is not a function" - ); + await expect(loadPlugins(config)).rejects.toThrow("pluginConfig.plugin is not a function"); }); it("should throw error for invalid plugin export", async () => { @@ -199,14 +192,11 @@ export default "not a plugin object"; plugins: [ { name: "invalid-plugin", - plugin: async () => - (await import(`${workspace.root}/invalid-plugin.js`)).default, + plugin: async () => (await import(`${workspace.root}/invalid-plugin.js`)).default, }, ], }; - await expect(loadPlugins(config)).rejects.toThrow( - "did not return a valid plugin object" - ); + await expect(loadPlugins(config)).rejects.toThrow("did not return a valid plugin object"); }); }); diff --git a/packages/cli/src/tests/plugin/plugin-manager.spec.ts b/packages/cli/src/tests/plugin/plugin-manager.spec.ts index bda1f5e..c5320ae 100644 --- a/packages/cli/src/tests/plugin/plugin-manager.spec.ts +++ b/packages/cli/src/tests/plugin/plugin-manager.spec.ts @@ -1,21 +1,11 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest"; import { SidebarItem } from "../../commands/build/manifest/manifest.js"; import { loadConfig } from "../../config/load-config.js"; -import { - GeneratedDoc, - MarkdownDocument, - MarkdownGenerator, -} from "../../core/types/generator.types.js"; -import { - ParsedJSDoc, - StandardizedFilePath, -} from "../../core/types/parser.types.js"; +import { GeneratedDoc, MarkdownDocument, MarkdownGenerator } from "../../core/types/generator.types.js"; +import { ParsedJSDoc, StandardizedFilePath } from "../../core/types/parser.types.js"; import { PluginManager } from "../../plugins/plugin-manager.js"; import { Plugin } from "../../plugins/types/plugin.types.js"; -import { - createE2EWorkspace, - E2EWorkspace, -} from "../utils/create-e2e-workspace.js"; +import { createE2EWorkspace, E2EWorkspace } from "../utils/create-e2e-workspace.js"; import { MockPlugins } from "../utils/plugin-mocks.js"; describe("PluginManager", () => { @@ -31,10 +21,7 @@ describe("PluginManager", () => { it("should register multiple plugins", () => { const manager = new PluginManager(); - const plugins = [ - MockPlugins.empty("plugin-1"), - MockPlugins.empty("plugin-2"), - ]; + const plugins = [MockPlugins.empty("plugin-1"), MockPlugins.empty("plugin-2")]; manager.registerAll(plugins); @@ -113,7 +100,7 @@ describe("PluginManager", () => { ], }), serialize: (doc: MarkdownDocument): string => { - return doc.sections.map((s) => s.content).join("\n"); + return doc.sections.map(s => s.content).join("\n"); }, }; @@ -184,9 +171,7 @@ describe("PluginManager", () => { expect(() => { manager.getGenerator(config); - }).toThrow( - "Generator 'unknown' not found. Available: vitepress, custom-1, custom-2" - ); + }).toThrow("Generator 'unknown' not found. Available: vitepress, custom-1, custom-2"); }); it("should work with plugin that doesn't provide generator", async () => { @@ -196,7 +181,7 @@ describe("PluginManager", () => { const plugin: Plugin = { name: "manifest-only-plugin", hooks: { - transformManifest: (manifest) => manifest, + transformManifest: manifest => manifest, }, }; @@ -241,7 +226,7 @@ describe("PluginManager", () => { } result += "---\n\n"; } - result += doc.sections.map((s) => s.content).join("\n\n"); + result += doc.sections.map(s => s.content).join("\n\n"); return result; }, }; diff --git a/packages/cli/src/tests/utils/create-e2e-workspace.ts b/packages/cli/src/tests/utils/create-e2e-workspace.ts index b6203f2..fb43801 100644 --- a/packages/cli/src/tests/utils/create-e2e-workspace.ts +++ b/packages/cli/src/tests/utils/create-e2e-workspace.ts @@ -1,12 +1,7 @@ import path from "path"; import { TestWorkspace, createTestWorkspace } from "./create-test-workspace.js"; import { execSync } from "child_process"; -import { - createCorePackage, - createMathPackage, - createUtilsPackage, - createTypesPackage, -} from "./package-creators.js"; +import { createCorePackage, createMathPackage, createUtilsPackage, createTypesPackage } from "./package-creators.js"; import { createDocflowConfig } from "./docflow-config.js"; import { getWorkingDirectory } from "../../utils/get-working-directory.js"; diff --git a/packages/cli/src/tests/utils/create-test-workspace.ts b/packages/cli/src/tests/utils/create-test-workspace.ts index 8d0aeac..88e0621 100644 --- a/packages/cli/src/tests/utils/create-test-workspace.ts +++ b/packages/cli/src/tests/utils/create-test-workspace.ts @@ -20,9 +20,7 @@ export async function createTestWorkspace(): Promise { const formatContent = (content: unknown, isJsonFile: boolean) => { if (!isJsonFile) return String(content); - return typeof content === "string" - ? content - : JSON.stringify(content, null, 2); + return typeof content === "string" ? content : JSON.stringify(content, null, 2); }; const isRcFile = /\.?\w*rc$/i.test(filePath); diff --git a/packages/cli/src/tests/utils/generator-config.ts b/packages/cli/src/tests/utils/generator-config.ts index 5702fb1..44f8cb3 100644 --- a/packages/cli/src/tests/utils/generator-config.ts +++ b/packages/cli/src/tests/utils/generator-config.ts @@ -18,4 +18,4 @@ export const DEFAULT_GENERATOR_CONFIG: GeneratorConfig = { export function createGeneratorConfig(overrides: Partial = {}): GeneratorConfig { return { ...DEFAULT_GENERATOR_CONFIG, ...overrides }; -} \ No newline at end of file +} diff --git a/packages/cli/src/tests/utils/package-creators.ts b/packages/cli/src/tests/utils/package-creators.ts index d0181e8..996f535 100644 --- a/packages/cli/src/tests/utils/package-creators.ts +++ b/packages/cli/src/tests/utils/package-creators.ts @@ -1,8 +1,6 @@ import { TestWorkspace } from "./create-test-workspace.js"; -export async function createCorePackage( - workspace: TestWorkspace -): Promise { +export async function createCorePackage(workspace: TestWorkspace): Promise { await workspace.write("packages/core/package.json", { name: "@libs/core", version: "1.0.0", @@ -217,9 +215,7 @@ export class SimpleClass { ); } -export async function createMathPackage( - workspace: TestWorkspace -): Promise { +export async function createMathPackage(workspace: TestWorkspace): Promise { await workspace.write("packages/math/package.json", { name: "@libs/math", version: "1.0.0", @@ -260,9 +256,7 @@ export function calculateVolume(radius: number, height: number): number { ); } -export async function createUtilsPackage( - workspace: TestWorkspace -): Promise { +export async function createUtilsPackage(workspace: TestWorkspace): Promise { await workspace.write("packages/utils/package.json", { name: "@libs/utils", version: "1.0.0", @@ -369,9 +363,7 @@ export function isString(value: unknown): value is string { ); } -export async function createTypesPackage( - workspace: TestWorkspace -): Promise { +export async function createTypesPackage(workspace: TestWorkspace): Promise { await workspace.write("packages/types/package.json", { name: "@libs/types", version: "1.0.0", diff --git a/packages/cli/src/tests/utils/plugin-mocks.ts b/packages/cli/src/tests/utils/plugin-mocks.ts index 5d93e74..5ac0d64 100644 --- a/packages/cli/src/tests/utils/plugin-mocks.ts +++ b/packages/cli/src/tests/utils/plugin-mocks.ts @@ -27,15 +27,14 @@ export const MockPlugins = { manifestAppender: (name: string, itemToAdd: SidebarItem): Plugin => ({ name, hooks: { - transformManifest: (manifest) => [...manifest, itemToAdd], + transformManifest: manifest => [...manifest, itemToAdd], }, }), manifestMarker: (name: string, marker: Record): Plugin => ({ name, hooks: { - transformManifest: (manifest) => - manifest.map((item) => ({ ...item, ...marker })), + transformManifest: manifest => manifest.map(item => ({ ...item, ...marker })), }, }), }; @@ -52,10 +51,7 @@ export function createManifestTransformPlugin( }; } -export function createGeneratorPlugin( - name: string, - generator: MarkdownGenerator -): Plugin { +export function createGeneratorPlugin(name: string, generator: MarkdownGenerator): Plugin { return { name, hooks: { diff --git a/packages/cli/src/tests/utils/setup-package.ts b/packages/cli/src/tests/utils/setup-package.ts index 7986c68..6ea75c4 100644 --- a/packages/cli/src/tests/utils/setup-package.ts +++ b/packages/cli/src/tests/utils/setup-package.ts @@ -8,7 +8,7 @@ export async function setupPackage( tsconfig?: Record; tsconfigBuild?: Record; files?: Record; - } = {}, + } = {} ): Promise { const packagePath = path.join(workspace.root, "packages", packageName); diff --git a/packages/cli/src/tests/utils/ts-project-helpers.ts b/packages/cli/src/tests/utils/ts-project-helpers.ts index e0dd4f7..59d3ecc 100644 --- a/packages/cli/src/tests/utils/ts-project-helpers.ts +++ b/packages/cli/src/tests/utils/ts-project-helpers.ts @@ -11,18 +11,13 @@ export class TSProjectTestHelper { constructor(private workspace: E2EWorkspace) {} async getProject(packageName: string = "core") { - const tsConfigPath = getTsConfigPath( - this.workspace.root, - `packages/${packageName}` - ); + const tsConfigPath = getTsConfigPath(this.workspace.root, `packages/${packageName}`); return getTsProject(tsConfigPath); } async getFileExports(fileName: string, packageName: string = "core") { const project = await this.getProject(packageName); - const sourceFile = project - .getSourceFiles() - .find((sf) => sf.getFilePath().includes(fileName)); + const sourceFile = project.getSourceFiles().find(sf => sf.getFilePath().includes(fileName)); if (!sourceFile) { throw new Error(`File ${fileName} not found in package ${packageName}`); @@ -31,13 +26,9 @@ export class TSProjectTestHelper { return getExportedDeclarationsBySourceFile(sourceFile); } - async getExportByName( - exportName: string, - fileName: string, - packageName: string = "core" - ) { + async getExportByName(exportName: string, fileName: string, packageName: string = "core") { const exports = await this.getFileExports(fileName, packageName); - const targetExport = exports.find((exp) => exp.symbolName === exportName); + const targetExport = exports.find(exp => exp.symbolName === exportName); if (!targetExport) { throw new Error(`Export ${exportName} not found in ${fileName}`); @@ -46,16 +37,8 @@ export class TSProjectTestHelper { return targetExport; } - async getExportWithJSDoc( - exportName: string, - fileName: string, - packageName: string = "core" - ) { - const exportDeclaration = await this.getExportByName( - exportName, - fileName, - packageName - ); + async getExportWithJSDoc(exportName: string, fileName: string, packageName: string = "core") { + const exportDeclaration = await this.getExportByName(exportName, fileName, packageName); return parseJSDoc(exportDeclaration, this.parser); } diff --git a/packages/cli/src/utils/get-working-directory.ts b/packages/cli/src/utils/get-working-directory.ts index cf6388d..50dc4f1 100644 --- a/packages/cli/src/utils/get-working-directory.ts +++ b/packages/cli/src/utils/get-working-directory.ts @@ -1,8 +1,8 @@ export function getWorkingDirectory(): string { - // This is more reliable than process.cwd() when running via npm, pnpm - if (process.env.INIT_CWD != null) { - return process.env.INIT_CWD; - } + // This is more reliable than process.cwd() when running via npm, pnpm + if (process.env.INIT_CWD != null) { + return process.env.INIT_CWD; + } - return process.cwd(); + return process.cwd(); } diff --git a/yarn.lock b/yarn.lock index df19997..d827b54 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3659,6 +3659,7 @@ __metadata: eslint: "npm:^9.9.1" hygen: "npm:^6.2.11" knip: "npm:^5.61.3" + prettier: "npm:^3.8.1" tsx: "npm:^4.20.3" typescript: "npm:^5.8.3" typescript-eslint: "npm:^8.4.0" @@ -6517,6 +6518,15 @@ __metadata: languageName: node linkType: hard +"prettier@npm:^3.8.1": + version: 3.8.1 + resolution: "prettier@npm:3.8.1::__archiveUrl=https%3A%2F%2Fregistry.npmjs.org%2Fprettier%2F-%2Fprettier-3.8.1.tgz" + bin: + prettier: bin/prettier.cjs + checksum: 10c0/33169b594009e48f570471271be7eac7cdcf88a209eed39ac3b8d6d78984039bfa9132f82b7e6ba3b06711f3bfe0222a62a1bfb87c43f50c25a83df1b78a2c42 + languageName: node + linkType: hard + "pretty-ms@npm:7.0.1": version: 7.0.1 resolution: "pretty-ms@npm:7.0.1"