diff --git a/.gitignore b/.gitignore index 53cf8c17e..2e34a630b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,8 @@ package-lock.json yarn.lock +# only the root node_modules folder since some of the test fixtures have them /node_modules -/actions/bundle-size/node_modules -/coverage -/dist -/docs +dist .docs .nyc_output *.log diff --git a/package.json b/package.json index 500645936..dbbda450f 100644 --- a/package.json +++ b/package.json @@ -229,39 +229,39 @@ "@electron/get": "^2.0.0", "@polka/send-type": "^0.5.2", "@semantic-release/changelog": "^6.0.1", - "@semantic-release/commit-analyzer": "^9.0.2", + "@semantic-release/commit-analyzer": "^10.0.1", "@semantic-release/git": "^10.0.1", - "@semantic-release/github": "https://registry.npmjs.org/@achingbrain/semantic-release-github/-/semantic-release-github-0.0.2.tgz", - "@semantic-release/npm": "^9.0.2", - "@semantic-release/release-notes-generator": "^10.0.3", + "@semantic-release/github": "^9.0.3", + "@semantic-release/npm": "^10.0.4", + "@semantic-release/release-notes-generator": "^11.0.4", "@types/chai": "^4.2.16", "@types/chai-as-promised": "^7.1.3", "@types/chai-string": "^1.4.2", "@types/chai-subset": "^1.3.3", "@types/mocha": "^10.0.0", - "@types/node": "^18.11.15", + "@types/node": "^20.4.2", "@typescript-eslint/eslint-plugin": "^5.18.0", "buffer": "^6.0.3", "bytes": "^3.1.0", - "c8": "^7.7.0", + "c8": "^8.0.0", "chai": "^4.3.4", "chai-as-promised": "^7.1.1", "chai-bites": "^0.1.2", "chai-parentheses": "^0.0.2", "chai-string": "^1.5.0", "chai-subset": "^1.6.0", - "conventional-changelog-conventionalcommits": "^5.0.0", + "conventional-changelog-conventionalcommits": "^6.1.0", "cors": "^2.8.5", "depcheck": "^1.4.3", "diff": "^5.1.0", "electron-mocha-main": "^11.0.3", "env-paths": "^3.0.0", - "esbuild": "^0.17.9", + "esbuild": "^0.18.12", "eslint": "^8.31.0", - "eslint-config-ipfs": "^4.0.2", + "eslint-config-ipfs": "^5.0.0", "eslint-plugin-etc": "^2.0.2", "eslint-plugin-import": "^2.18.0", - "eslint-plugin-jsdoc": "^43.1.1", + "eslint-plugin-jsdoc": "^46.4.3", "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^6.1.1", "execa": "^7.0.0", @@ -272,48 +272,48 @@ "kleur": "^4.1.4", "lilconfig": "^2.0.5", "listr": "~0.14.2", - "mdast-util-from-markdown": "^1.2.0", - "mdast-util-gfm": "^2.0.1", - "mdast-util-gfm-footnote": "^1.0.1", - "mdast-util-gfm-strikethrough": "^1.0.1", - "mdast-util-gfm-table": "^1.0.4", - "mdast-util-gfm-task-list-item": "^1.0.1", - "mdast-util-to-markdown": "^1.3.0", - "mdast-util-toc": "^6.1.0", + "mdast-util-from-markdown": "^2.0.0", + "mdast-util-gfm": "^3.0.0", + "mdast-util-gfm-footnote": "^2.0.0", + "mdast-util-gfm-strikethrough": "^2.0.0", + "mdast-util-gfm-table": "^2.0.0", + "mdast-util-gfm-task-list-item": "^2.0.0", + "mdast-util-to-markdown": "^2.0.0", + "mdast-util-toc": "^7.0.0", "merge-options": "^3.0.4", - "micromark-extension-gfm": "^2.0.1", - "micromark-extension-gfm-footnote": "^1.0.4", - "micromark-extension-gfm-strikethrough": "^1.0.4", - "micromark-extension-gfm-table": "^1.0.5", - "micromark-extension-gfm-task-list-item": "^1.0.3", + "micromark-extension-gfm": "^3.0.0", + "micromark-extension-gfm-footnote": "^2.0.0", + "micromark-extension-gfm-strikethrough": "^2.0.0", + "micromark-extension-gfm-table": "^2.0.0", + "micromark-extension-gfm-task-list-item": "^2.0.1", "minimatch": "^9.0.0", "mocha": "^10.0.0", - "npm-package-json-lint": "^6.3.0", + "npm-package-json-lint": "^7.0.0", "nyc": "^15.1.0", "p-map": "^6.0.0", "p-retry": "^5.1.2", "pascalcase": "^2.0.0", "path": "^0.12.7", - "playwright-test": "^8.1.0", + "playwright-test": "^12.1.1", "polka": "^0.5.2", "premove": "^4.0.0", "prompt": "^1.2.2", "proper-lockfile": "^4.1.2", "react-native-test-runner": "^5.0.0", - "read-pkg-up": "^9.1.0", + "read-pkg-up": "^10.0.0", "rimraf": "^5.0.0", - "semantic-release": "^20.1.3", + "semantic-release": "^21.0.7", "semantic-release-monorepo": "^7.0.5", "semver": "^7.3.8", "source-map-support": "^0.5.20", "strip-bom": "^5.0.0", "strip-json-comments": "^5.0.0", "tempy": "^3.0.0", - "typedoc": "^0.23.21", + "typedoc": "^0.24.8", "typedoc-plugin-mdn-links": "^3.0.3", - "typedoc-plugin-missing-exports": "^1.0.0", - "typescript": "^4.6.3", - "typescript-docs-verifier": "2.4.0", + "typedoc-plugin-missing-exports": "^2.0.0", + "typescript": "^5.1.6", + "typescript-docs-verifier": "^2.5.0", "uint8arrays": "^4.0.2", "undici": "^5.0.0", "update-notifier": "^6.0.2", @@ -337,7 +337,7 @@ "@types/semver": "^7.3.4", "@types/update-notifier": "^6.0.1", "@types/yargs": "^17.0.0", - "electron": "^24.1.2" + "electron": "^25.3.0" }, "browser": { "fs": false, diff --git a/src/check-project/check-typedoc-files.js b/src/check-project/check-typedoc-files.js new file mode 100644 index 000000000..892a59afd --- /dev/null +++ b/src/check-project/check-typedoc-files.js @@ -0,0 +1,33 @@ +/* eslint-disable no-console */ + +import path from 'path' +import fs from 'fs-extra' +import { + ensureFileHasContents +} from './utils.js' + +/** + * @param {string} projectDir + * @param {boolean} isTypescriptProject + */ +export async function checkTypedocFiles (projectDir, isTypescriptProject) { + console.info('Check typedoc files') + + const pkg = fs.readJSONSync(path.join(projectDir, 'package.json')) + const entryPoints = Object.values(pkg.exports) + .map(e => { + const path = e.import + + if (isTypescriptProject) { + return path + .replace('dist/src', 'src') + .replace('.js', '.ts') + } + + return path + }) + + await ensureFileHasContents(JSON.stringify({ + entryPoints + }, null, 2), 'typedoc.json') +} diff --git a/src/check-project/index.js b/src/check-project/index.js index 9dfb42240..332e7f7a0 100755 --- a/src/check-project/index.js +++ b/src/check-project/index.js @@ -17,6 +17,7 @@ import { checkLicenseFiles } from './check-licence-files.js' import { checkMonorepoFiles } from './check-monorepo-files.js' import { checkMonorepoReadme } from './check-monorepo-readme.js' import { checkReadme } from './check-readme.js' +import { checkTypedocFiles } from './check-typedoc-files.js' import { monorepoManifest } from './manifests/monorepo.js' import { typedCJSManifest } from './manifests/typed-cjs.js' import { typedESMManifest } from './manifests/typed-esm.js' @@ -424,6 +425,7 @@ async function processModule (projectDir, manifest, branchName, repoUrl, homePag await checkLicenseFiles(projectDir) await checkReadme(projectDir, repoUrl, branchName, ciFile, rootManifest) + await checkTypedocFiles(projectDir, typescript) } export default new Listr([ diff --git a/src/check-project/readme/utils.js b/src/check-project/readme/utils.js index e202438bc..4f11c09b9 100644 --- a/src/check-project/readme/utils.js +++ b/src/check-project/readme/utils.js @@ -18,17 +18,17 @@ export function parseMarkdown (md) { return fromMarkdown(md, { extensions: [ gfm(), - gfmTable, + gfmTable(), gfmFootnote(), gfmStrikethrough(), - gfmTaskListItem + gfmTaskListItem() ], mdastExtensions: [ gfmFromMarkdown(), - gfmTableFromMarkdown, + gfmTableFromMarkdown(), gfmFootnoteFromMarkdown(), - gfmStrikethroughFromMarkdown, - gfmTaskListItemFromMarkdown + gfmStrikethroughFromMarkdown(), + gfmTaskListItemFromMarkdown() ] }) } @@ -43,8 +43,8 @@ export function writeMarkdown (tree) { gfmToMarkdown(), gfmTableToMarkdown(), gfmFootnoteToMarkdown(), - gfmStrikethroughToMarkdown, - gfmTaskListItemToMarkdown + gfmStrikethroughToMarkdown(), + gfmTaskListItemToMarkdown() ], bullet: '-', listItemIndent: 'one' diff --git a/src/config/tsconfig.aegir.json b/src/config/tsconfig.aegir.json index 277005b3e..7b6dc9e06 100644 --- a/src/config/tsconfig.aegir.json +++ b/src/config/tsconfig.aegir.json @@ -27,7 +27,7 @@ "noUnusedLocals": true, "noUnusedParameters": false, // advanced - "importsNotUsedAsValues": "error", + "verbatimModuleSyntax": true, "forceConsistentCasingInFileNames": true, "skipLibCheck": true, "stripInternal": true, diff --git a/src/docs.js b/src/docs.js index c9149a29a..da0a3706b 100644 --- a/src/docs.js +++ b/src/docs.js @@ -49,11 +49,11 @@ const docs = async (ctx, task) => { '--gitRevision', 'master', '--plugin', - fromAegir('src/docs/typedoc-plugin.cjs'), + fromAegir('src/docs/typedoc-plugin.js'), '--plugin', - fromAegir('src/docs/unknown-symbol-resolver-plugin.cjs'), + fromAegir('src/docs/unknown-symbol-resolver-plugin.js'), '--plugin', - fromAegir('src/docs/type-indexer-plugin.cjs'), + fromAegir('src/docs/type-indexer-plugin.js'), '--plugin', 'typedoc-plugin-mdn-links', '--plugin', diff --git a/src/docs/type-indexer-plugin.cjs b/src/docs/type-indexer-plugin.js similarity index 59% rename from src/docs/type-indexer-plugin.cjs rename to src/docs/type-indexer-plugin.js index 630c81c36..81380f7ef 100644 --- a/src/docs/type-indexer-plugin.cjs +++ b/src/docs/type-indexer-plugin.js @@ -1,17 +1,18 @@ -const fs = require('fs') -const { RendererEvent } = require('typedoc') -const path = require('path') +import fs from 'fs' +import path from 'path' +import { RendererEvent, ReflectionKind } from 'typedoc' +import { parseProjects } from '../utils.js' /** * The types of models we want to store documentation URLs for */ const MODELS = [ - 'Interface', - 'Function', - 'Type alias', - 'Variable', - 'Class', - 'Enumeration' + ReflectionKind.Interface, + ReflectionKind.Function, + ReflectionKind.TypeAlias, + ReflectionKind.Variable, + ReflectionKind.Class, + ReflectionKind.Enum ] /** @@ -20,6 +21,8 @@ const MODELS = [ * @property {Record} Documentation.typedocs * @property {string[]} Documentation.exported * @property {string} [Documentation.outputDir] + * + * @typedef {import('../utils.js').Project} Project */ /** @@ -27,15 +30,23 @@ const MODELS = [ * current project that contains URLs that map exported symbol names to published * typedoc pages. * - * See `unknown-symbol-resolver-plugin.cjs` for how it is consumed. + * See `unknown-symbol-resolver-plugin.js` for how it is consumed. * * @param {import("typedoc/dist/lib/application").Application} Application */ -function load (Application) { +export function load (Application) { const manifestPath = `${process.cwd()}/package.json` - const manifest = require(manifestPath) + const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8')) const isMonorepo = Boolean(manifest.workspaces) + // workaround for https://github.com/TypeStrong/typedoc/issues/2338 + /** @type {Record} */ + let projects = {} + + if (isMonorepo) { + projects = parseProjects(process.cwd(), manifest.workspaces) + } + /** @type {string} */ let ghPages @@ -54,6 +65,7 @@ function load (Application) { */ const onRendererBegin = event => { if (!event.urls) { + Application.logger.warn('No urls found in RendererEvent') return } @@ -62,14 +74,45 @@ function load (Application) { for (const urlMapping of event.urls) { if (!urlMapping.model.sources || urlMapping.model.sources.length === 0) { + Application.logger.info(`No sources found in URLMapping for variant "${urlMapping.model.variant}"`) + continue + } + + if (!MODELS.includes(urlMapping.model.kind)) { + Application.logger.info(`Skipping model "${urlMapping.model.variant}" as it is not in the list of model types we are interested in`) continue } - if (!MODELS.includes(urlMapping.model.kindString)) { + if (urlMapping.model.sources == null || urlMapping.model.sources.length === 0) { + Application.logger.info(`Skipping model "${urlMapping.model.variant}" as it has no url mapping sources`) continue } - const context = findContext(urlMapping, isMonorepo) + const source = urlMapping.model.sources[0] + + // workaround for https://github.com/TypeStrong/typedoc/issues/2338 + if (!path.isAbsolute(source.fullFileName)) { + const project = urlMapping.model.parent + const projectDir = projects[project.name]?.dir + + if (!projectDir) { + Application.logger.warn(`Full file name "${source.fullFileName}" was not absolute but could not find containing project - see https://github.com/TypeStrong/typedoc/issues/2338`) + continue + } else { + const fullFileName = `${projectDir}/src/${source.fullFileName}` + + if (fs.existsSync(fullFileName)) { + Application.logger.info(`Full file name of source was not absolute, overriding ${source.fullFileName} -> ${fullFileName} - see https://github.com/TypeStrong/typedoc/issues/2338`) + + source.fullFileName = fullFileName + } else { + Application.logger.warn(`Full file name "${source.fullFileName}" was not absolute, found containing project but could not locate source file in project - see https://github.com/TypeStrong/typedoc/issues/2338`) + continue + } + } + } + + const context = findContext(source, isMonorepo) // set up manifest to contain typedoc urls if (typedocs[context.manifestPath] == null) { @@ -83,11 +126,11 @@ function load (Application) { } // cannot differentiate between types with duplicate names in the same module https://github.com/TypeStrong/typedoc/issues/2125 - if (typedocs[context.manifestPath].typedocs[urlMapping.model.originalName] != null) { - Application.logger.warn(`Duplicate exported type name ${urlMapping.model.originalName} defined in ${urlMapping.model.sources[0].fullFileName}`) + if (typedocs[context.manifestPath].typedocs[urlMapping.model.name] != null) { + Application.logger.warn(`Duplicate exported type name ${urlMapping.model.name} defined in ${urlMapping.model.sources[0].fullFileName}`) } else { // store reference to generate doc url - typedocs[context.manifestPath].typedocs[urlMapping.model.originalName] = `${ghPages}${urlMapping.url}` + typedocs[context.manifestPath].typedocs[urlMapping.model.name] = `${ghPages}${urlMapping.url}` } } @@ -103,16 +146,18 @@ function load (Application) { recursive: true }) fs.writeFileSync(`${context.outputDir}/typedoc-urls.json`, JSON.stringify(context.typedocs, null, 2)) + + Application.logger.info(`Wrote typedoc URLs to ${context.outputDir}/typedoc-urls.json`) }) + + if (Object.keys(typedocs).length === 0) { + Application.logger.warn('No typedoc-urls.json written!') + } } Application.renderer.on(RendererEvent.BEGIN, onRendererBegin) } -module.exports = { - load -} - /** * @typedef {object} ProjectContext * @property {string} [ProjectContext.outputDir] @@ -123,31 +168,25 @@ module.exports = { * For a given UrlMapping, find the nearest package.json file * and work out if a `typedoc-urls.json` should be generated. * - * @param {import("typedoc/dist/lib/output/models/UrlMapping").UrlMapping} mapping + * @param {import("typedoc/dist/lib/models/sources/file").SourceReference} source * @param {boolean} isMonorepo * @returns {ProjectContext} */ -function findContext (mapping, isMonorepo) { - const sources = mapping.model.sources - - if (sources == null || sources.length === 0 || sources[0].fullFileName == null) { - throw new Error('UrlMapping had no sources') - } - - const absolutePathSegments = sources[0].fullFileName.split('/') +function findContext (source, isMonorepo) { + const absolutePathSegments = source.fullFileName.split('/') while (absolutePathSegments.length) { // remove last path segment absolutePathSegments.pop() - let manifestPath = makeAbsolute(path.join(...absolutePathSegments, 'package.json')) + const manifestPath = makeAbsolute(path.join(...absolutePathSegments, 'package.json')) /** @type {string | undefined} */ let outputDir = makeAbsolute(path.join(...(isMonorepo ? absolutePathSegments : process.cwd().split('/')), 'dist')) // this can occur when a symbol from a dependency is exported, if this is // the case do not try to write a `typedoc-urls.json` file - if (sources[0].fullFileName.includes('node_modules')) { + if (source.fullFileName.includes('node_modules')) { outputDir = undefined } diff --git a/src/docs/typedoc-plugin.cjs b/src/docs/typedoc-plugin.js similarity index 83% rename from src/docs/typedoc-plugin.cjs rename to src/docs/typedoc-plugin.js index e784b78af..5d966fd84 100644 --- a/src/docs/typedoc-plugin.cjs +++ b/src/docs/typedoc-plugin.js @@ -1,11 +1,11 @@ -const { Converter } = require('typedoc') -const path = require('path') -const fs = require('fs') +import fs from 'fs' +import path from 'path' +import { Converter } from 'typedoc' /** * @param {import("typedoc/dist/lib/application").Application} Application */ -const plugin = function (Application) { +export function load (Application) { const app = Application.owner const pkg = path.join(process.cwd(), 'package.json') /** @type {any} */ @@ -23,7 +23,6 @@ const plugin = function (Application) { * @param {import("typescript").Node} node */ const cb = (context, reflection, node) => { - if (pkgJson && reflection.name === 'export=') { let name if (node) { @@ -36,7 +35,3 @@ const plugin = function (Application) { app.converter.on(Converter.EVENT_CREATE_DECLARATION, cb) } - -module.exports = { - load: plugin -} diff --git a/src/docs/unknown-symbol-resolver-plugin.cjs b/src/docs/unknown-symbol-resolver-plugin.js similarity index 59% rename from src/docs/unknown-symbol-resolver-plugin.cjs rename to src/docs/unknown-symbol-resolver-plugin.js index a9bed8e6d..d3b21ab75 100644 --- a/src/docs/unknown-symbol-resolver-plugin.cjs +++ b/src/docs/unknown-symbol-resolver-plugin.js @@ -1,5 +1,5 @@ -const fs = require('fs') -const path = require('path') +import fs from 'fs' +import path from 'path' /** @type {Record>} */ const knownSymbols = { @@ -8,10 +8,10 @@ const knownSymbols = { 'Chai.Assertion': 'https://www.chaijs.com/api/assert/' }, '@types/node': { - 'EventEmitter': 'https://nodejs.org/dist/latest-v19.x/docs/api/events.html#class-eventemitter', - 'Server': 'https://nodejs.org/dist/latest-v19.x/docs/api/net.html#class-netserver', - 'IncomingMessage': 'https://nodejs.org/dist/latest-v19.x/docs/api/http.html#class-httpincomingmessage', - 'ServerResponse': 'https://nodejs.org/dist/latest-v19.x/docs/api/http.html#class-httpserverresponse', + EventEmitter: 'https://nodejs.org/dist/latest-v19.x/docs/api/events.html#class-eventemitter', + Server: 'https://nodejs.org/dist/latest-v19.x/docs/api/net.html#class-netserver', + IncomingMessage: 'https://nodejs.org/dist/latest-v19.x/docs/api/http.html#class-httpincomingmessage', + ServerResponse: 'https://nodejs.org/dist/latest-v19.x/docs/api/http.html#class-httpserverresponse', 'global.NodeJS.ReadStream': 'https://nodejs.org/dist/latest-v19.x/docs/api/tty.html#class-ttyreadstream', 'global.NodeJS.WriteStream': 'https://nodejs.org/dist/latest-v19.x/docs/api/tty.html#class-ttywritestream', 'global.NodeJS.ProcessEnv': 'https://nodejs.org/dist/latest-v19.x/docs/api/process.html#processenv', @@ -20,8 +20,8 @@ const knownSymbols = { 'internal.Transform': 'https://nodejs.org/dist/latest-v19.x/docs/api/stream.html#class-streamtransform', 'internal.Writable': 'https://nodejs.org/dist/latest-v19.x/docs/api/stream.html#class-streamwritable' }, - 'esbuild': { - 'BuildOptions': 'https://esbuild.github.io/api/#build-api' + esbuild: { + BuildOptions: 'https://esbuild.github.io/api/#build-api' } } @@ -37,43 +37,39 @@ const ignoreModules = [ * * @param {import("typedoc/dist/lib/application").Application} Application */ -function load(Application) { +export function load (Application) { Application.converter.addUnknownSymbolResolver((ref) => { - const moduleName = ref.moduleSource - const symbolName = calculateName(ref.symbolReference?.path) + const moduleName = ref.moduleSource + const symbolName = calculateName(ref.symbolReference?.path) - if (moduleName == null || symbolName == null) { - // can't resolve symbol - return - } - - if (ignoreModules.includes(moduleName)) { - return - } + if (moduleName == null || symbolName == null) { + // can't resolve symbol + return + } - const moduleDocs = knownSymbols[moduleName] + if (ignoreModules.includes(moduleName)) { + return + } - // do we know about this module - if (moduleDocs != null && moduleDocs[symbolName] != null) { - return moduleDocs[symbolName] - } + const moduleDocs = knownSymbols[moduleName] - // try to load docs from package.json - if the manifest declares a - // `docs` key use that to look up links to typedocs - const typedocs = loadTypedocUrls(moduleName) + // do we know about this module + if (moduleDocs != null && moduleDocs[symbolName] != null) { + return moduleDocs[symbolName] + } - if (typedocs[symbolName] != null) { - return typedocs[symbolName] - } + // try to load docs from package.json - if the manifest declares a + // `docs` key use that to look up links to typedocs + const typedocs = loadTypedocUrls(moduleName) - Application.logger.warn(`Unknown symbol ${symbolName} from module ${moduleName}`) + if (typedocs[symbolName] != null) { + return typedocs[symbolName] + } - return `https://www.npmjs.com/package/${moduleName}` - }) -} + Application.logger.warn(`Unknown symbol ${symbolName} from module ${moduleName}`) -module.exports = { - load + return `https://www.npmjs.com/package/${moduleName}` + }) } /** diff --git a/src/utils.js b/src/utils.js index de37374cf..9e5334474 100644 --- a/src/utils.js +++ b/src/utils.js @@ -362,16 +362,16 @@ export async function everyMonorepoProject (projectDir, fn) { * @param {string} projectDir * @param {string[]} workspaces */ -async function parseProjects (projectDir, workspaces) { +export function parseProjects (projectDir, workspaces) { /** @type {Record} */ const projects = {} for (const workspace of workspaces) { - for await (const subProjectDir of glob('.', workspace, { + for (const subProjectDir of glob('.', workspace, { cwd: projectDir, absolute: true })) { - const stat = await fs.stat(subProjectDir) + const stat = fs.statSync(subProjectDir) if (!stat.isDirectory()) { continue @@ -471,21 +471,21 @@ function checkForCircularDependencies (projects) { * @property {boolean} [absolute] If true produces absolute paths (default: false) * @property {boolean} [nodir] If true yields file paths and skip directories (default: false) * - * Async iterable filename pattern matcher + * Iterable filename pattern matcher * * @param {string} dir * @param {string} pattern * @param {GlobOptions & import('minimatch').MinimatchOptions} [options] - * @returns {AsyncGenerator} + * @returns {Generator} */ -export async function * glob (dir, pattern, options = {}) { +export function * glob (dir, pattern, options = {}) { const absoluteDir = path.resolve(dir) const relativeDir = path.relative(options.cwd ?? process.cwd(), dir) - const stats = await fs.stat(absoluteDir) + const stats = fs.statSync(absoluteDir) if (stats.isDirectory()) { - for await (const entry of _glob(absoluteDir, '', pattern, options)) { + for (const entry of _glob(absoluteDir, '', pattern, options)) { yield entry } @@ -502,10 +502,30 @@ export async function * glob (dir, pattern, options = {}) { * @param {string} dir * @param {string} pattern * @param {GlobOptions & import('minimatch').MinimatchOptions} options - * @returns {AsyncGenerator} + * @returns {Generator} */ -async function * _glob (base, dir, pattern, options) { - for await (const entry of await fs.opendir(path.join(base, dir))) { +function * _glob (base, dir, pattern, options) { + const p = path.join(base, dir) + + if (!fs.existsSync(p)) { + return + } + + const stats = fs.statSync(p) + + if (!stats.isDirectory()) { + return + } + + const d = fs.opendirSync(p) + + while (true) { + const entry = d.readSync() + + if (entry == null) { + break + } + const relativeEntryPath = path.join(dir, entry.name) const absoluteEntryPath = path.join(base, dir, entry.name) diff --git a/test/fixtures/js+ts/tsconfig.json b/test/fixtures/js+ts/tsconfig.json index 94fff3042..ac19351e4 100644 --- a/test/fixtures/js+ts/tsconfig.json +++ b/test/fixtures/js+ts/tsconfig.json @@ -27,7 +27,7 @@ "noUnusedLocals": true, "noUnusedParameters": false, // advanced - "importsNotUsedAsValues": "error", + "verbatimModuleSyntax": true, "forceConsistentCasingInFileNames": true, "skipLibCheck": true, "stripInternal": true, diff --git a/test/fixtures/projects/a-monorepo/packages/a-workspace-project/package.json b/test/fixtures/projects/a-monorepo/packages/a-workspace-project/package.json index 1f998e586..c6f6dbc04 100644 --- a/test/fixtures/projects/a-monorepo/packages/a-workspace-project/package.json +++ b/test/fixtures/projects/a-monorepo/packages/a-workspace-project/package.json @@ -10,8 +10,5 @@ }, "type": "module", "author": "", - "license": "ISC", - "typedoc": { - "entryPoint": "./src/index.js" - } + "license": "ISC" } diff --git a/test/fixtures/projects/a-monorepo/packages/a-workspace-project/src/types.ts b/test/fixtures/projects/a-monorepo/packages/a-workspace-project/src/types.ts index 2b2ea6dc5..a0f8b6be4 100644 --- a/test/fixtures/projects/a-monorepo/packages/a-workspace-project/src/types.ts +++ b/test/fixtures/projects/a-monorepo/packages/a-workspace-project/src/types.ts @@ -1,4 +1,3 @@ - export interface ExportedButNotInExports { aMethod: () => void } diff --git a/test/fixtures/projects/a-monorepo/packages/a-workspace-project/tsconfig.json b/test/fixtures/projects/a-monorepo/packages/a-workspace-project/tsconfig.json index 4c965e69f..6ddff411a 100644 --- a/test/fixtures/projects/a-monorepo/packages/a-workspace-project/tsconfig.json +++ b/test/fixtures/projects/a-monorepo/packages/a-workspace-project/tsconfig.json @@ -27,7 +27,7 @@ "noUnusedLocals": true, "noUnusedParameters": false, // advanced - "importsNotUsedAsValues": "error", + "verbatimModuleSyntax": true, "forceConsistentCasingInFileNames": true, "skipLibCheck": true, "stripInternal": true, diff --git a/test/fixtures/projects/a-monorepo/packages/a-workspace-project/typedoc.json b/test/fixtures/projects/a-monorepo/packages/a-workspace-project/typedoc.json new file mode 100644 index 000000000..c7d830493 --- /dev/null +++ b/test/fixtures/projects/a-monorepo/packages/a-workspace-project/typedoc.json @@ -0,0 +1,3 @@ +{ + "entryPoints": ["./src/index.js"] +} \ No newline at end of file diff --git a/test/fixtures/projects/a-monorepo/packages/another-workspace-project/package.json b/test/fixtures/projects/a-monorepo/packages/another-workspace-project/package.json index 96d160f47..0cd372fcb 100644 --- a/test/fixtures/projects/a-monorepo/packages/another-workspace-project/package.json +++ b/test/fixtures/projects/a-monorepo/packages/another-workspace-project/package.json @@ -10,8 +10,5 @@ }, "type": "module", "author": "", - "license": "ISC", - "typedoc": { - "entryPoint": "./src/index.js" - } + "license": "ISC" } diff --git a/test/fixtures/projects/a-monorepo/packages/another-workspace-project/src/dir/index.js b/test/fixtures/projects/a-monorepo/packages/another-workspace-project/src/dir/index.js new file mode 100644 index 000000000..50c309ccb --- /dev/null +++ b/test/fixtures/projects/a-monorepo/packages/another-workspace-project/src/dir/index.js @@ -0,0 +1,7 @@ +/** + * @param {string} arg + * @returns {boolean} + */ +export function garply (arg) { + return true +} diff --git a/test/fixtures/projects/a-monorepo/packages/another-workspace-project/src/index.js b/test/fixtures/projects/a-monorepo/packages/another-workspace-project/src/index.js index 58dc564eb..7147f8a99 100644 --- a/test/fixtures/projects/a-monorepo/packages/another-workspace-project/src/index.js +++ b/test/fixtures/projects/a-monorepo/packages/another-workspace-project/src/index.js @@ -14,3 +14,5 @@ export const useHerp = () => { export const useDerp = () => { } + +export { garply } from './dir/index.js' diff --git a/test/fixtures/projects/a-monorepo/packages/another-workspace-project/src/types.ts b/test/fixtures/projects/a-monorepo/packages/another-workspace-project/src/types.ts index 2b2ea6dc5..a0f8b6be4 100644 --- a/test/fixtures/projects/a-monorepo/packages/another-workspace-project/src/types.ts +++ b/test/fixtures/projects/a-monorepo/packages/another-workspace-project/src/types.ts @@ -1,4 +1,3 @@ - export interface ExportedButNotInExports { aMethod: () => void } diff --git a/test/fixtures/projects/a-monorepo/packages/another-workspace-project/tsconfig.json b/test/fixtures/projects/a-monorepo/packages/another-workspace-project/tsconfig.json index 4c965e69f..6ddff411a 100644 --- a/test/fixtures/projects/a-monorepo/packages/another-workspace-project/tsconfig.json +++ b/test/fixtures/projects/a-monorepo/packages/another-workspace-project/tsconfig.json @@ -27,7 +27,7 @@ "noUnusedLocals": true, "noUnusedParameters": false, // advanced - "importsNotUsedAsValues": "error", + "verbatimModuleSyntax": true, "forceConsistentCasingInFileNames": true, "skipLibCheck": true, "stripInternal": true, diff --git a/test/fixtures/projects/a-monorepo/packages/another-workspace-project/typedoc.json b/test/fixtures/projects/a-monorepo/packages/another-workspace-project/typedoc.json new file mode 100644 index 000000000..c7d830493 --- /dev/null +++ b/test/fixtures/projects/a-monorepo/packages/another-workspace-project/typedoc.json @@ -0,0 +1,3 @@ +{ + "entryPoints": ["./src/index.js"] +} \ No newline at end of file diff --git a/test/fixtures/projects/a-ts-project/src/a-module.ts b/test/fixtures/projects/a-ts-project/src/a-module.ts index e61412a0c..9213777e3 100644 --- a/test/fixtures/projects/a-ts-project/src/a-module.ts +++ b/test/fixtures/projects/a-ts-project/src/a-module.ts @@ -1,4 +1,3 @@ - export interface ExportedButNotInExports { aMethod: () => void } diff --git a/test/fixtures/projects/a-ts-project/src/dir/index.ts b/test/fixtures/projects/a-ts-project/src/dir/index.ts new file mode 100644 index 000000000..c2b642f2c --- /dev/null +++ b/test/fixtures/projects/a-ts-project/src/dir/index.ts @@ -0,0 +1,3 @@ +export function garply (arg: string): boolean { + return true +} diff --git a/test/fixtures/projects/a-ts-project/src/index.ts b/test/fixtures/projects/a-ts-project/src/index.ts index 029f1c3a9..68870c473 100644 --- a/test/fixtures/projects/a-ts-project/src/index.ts +++ b/test/fixtures/projects/a-ts-project/src/index.ts @@ -3,6 +3,8 @@ import derp from 'an-esm-dep' import type { UsedButNotExported } from './a-module.js' import type { EventEmitter } from 'events' +export { garply } from './dir/index.js' + export const useHerp = (): void => { herp() } diff --git a/test/fixtures/projects/a-ts-project/tsconfig.json b/test/fixtures/projects/a-ts-project/tsconfig.json index 94fff3042..ac19351e4 100644 --- a/test/fixtures/projects/a-ts-project/tsconfig.json +++ b/test/fixtures/projects/a-ts-project/tsconfig.json @@ -27,7 +27,7 @@ "noUnusedLocals": true, "noUnusedParameters": false, // advanced - "importsNotUsedAsValues": "error", + "verbatimModuleSyntax": true, "forceConsistentCasingInFileNames": true, "skipLibCheck": true, "stripInternal": true, diff --git a/test/fixtures/projects/an-esm-project/src/dir/index.js b/test/fixtures/projects/an-esm-project/src/dir/index.js new file mode 100644 index 000000000..50c309ccb --- /dev/null +++ b/test/fixtures/projects/an-esm-project/src/dir/index.js @@ -0,0 +1,7 @@ +/** + * @param {string} arg + * @returns {boolean} + */ +export function garply (arg) { + return true +} diff --git a/test/fixtures/projects/an-esm-project/src/index.js b/test/fixtures/projects/an-esm-project/src/index.js index 87284c643..b25f813e3 100644 --- a/test/fixtures/projects/an-esm-project/src/index.js +++ b/test/fixtures/projects/an-esm-project/src/index.js @@ -1,6 +1,8 @@ import herp from 'a-cjs-dep' import derp from 'an-esm-dep' +export { garply } from './dir/index.js' + /** * @typedef {import('./types').ExportedButNotInExports} ExportedButNotInExports */ diff --git a/test/fixtures/projects/an-esm-project/src/types.ts b/test/fixtures/projects/an-esm-project/src/types.ts index e61412a0c..9213777e3 100644 --- a/test/fixtures/projects/an-esm-project/src/types.ts +++ b/test/fixtures/projects/an-esm-project/src/types.ts @@ -1,4 +1,3 @@ - export interface ExportedButNotInExports { aMethod: () => void } diff --git a/test/fixtures/projects/an-esm-project/tsconfig.json b/test/fixtures/projects/an-esm-project/tsconfig.json index 4c965e69f..6ddff411a 100644 --- a/test/fixtures/projects/an-esm-project/tsconfig.json +++ b/test/fixtures/projects/an-esm-project/tsconfig.json @@ -27,7 +27,7 @@ "noUnusedLocals": true, "noUnusedParameters": false, // advanced - "importsNotUsedAsValues": "error", + "verbatimModuleSyntax": true, "forceConsistentCasingInFileNames": true, "skipLibCheck": true, "stripInternal": true,