Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"test": "npx jest",
"test:cov": "npx jest --coverage --coverageProvider v8",
"lint": "npx eslint src/*.ts --cache",
"lint:fix": "yarn lint:eslint --fix",
"prepublishOnly": "yarn build"
"lint:fix": "npx yarn lint:eslint --fix",
"prepare": "npx yarn build"
},
"ultra": {
"concurrent": [
Expand Down
43 changes: 41 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
import { posix } from "path"
import { existsSync } from "fs"

const PROCESS_CWD = process.cwd()
const filePathPrefix = "file:"

function resolveAbsPath(path: string) {
return posix.resolve(PROCESS_CWD, path.replace(filePathPrefix, ""))
}

function findLocalDependencyPaths(
cwd: string,
resolvedPaths: Set<string>
): string[] {
const absPath = resolveAbsPath(cwd)
const absPackageJsonPath = posix.resolve(absPath, "package.json")

if (!existsSync(absPackageJsonPath)) return []
resolvedPaths.add(absPath)
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { dependencies = {} } = require(absPackageJsonPath)

return Object.entries(dependencies as { [key: string]: string })
.map(([, path]) => [path, resolveAbsPath(path)])
.filter(
([path, resolvedAbsPath]) =>
path.startsWith(filePathPrefix) && !resolvedPaths.has(resolvedAbsPath)
)
.flatMap(([, resolvedAbsPath]) => {
resolvedPaths.add(resolvedAbsPath)
return findLocalDependencyPaths(resolvedAbsPath, resolvedPaths)
})
}

Object.keys(require.cache)
.filter(m =>
Expand All @@ -12,11 +44,18 @@ Object.keys(require.cache)
) => {
if (Array.isArray(config._)) config._.push(options.cwd)
else if (config._) config._ = [config._, options.cwd]
else config._ = options.cwd
else config._ = [options.cwd]

const resolvedPaths = new Set<string>()
config._.flatMap(path =>
findLocalDependencyPaths(resolveAbsPath(path), resolvedPaths)
)
config._ = [...config._, ...resolvedPaths]

return parse(config, options)
}
})

export const tagFormat = `${
require(posix.resolve(process.cwd(), "package.json")).name
require(posix.resolve(PROCESS_CWD, "package.json")).name
}-v\${version}`
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"module": "CommonJS", // Should be CommonJS for NodeJS apps
"strict": true,
"target": "ES2016", // any node version after 2016 is supported
"lib": ["ES2020"],
"moduleResolution": "node", // should be node
"resolveJsonModule": true,
"esModuleInterop": true,
Expand Down