Skip to content

Commit

Permalink
fix(lerna-config): fix generate tsconfig issues for applications
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Sep 7, 2023
1 parent a032a89 commit dc776dc
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions @ornikar/lerna-config/bin/generate-tsconfig-files.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,24 @@ import { getGraphPackages } from '../index.mjs';
)
: {};

const hasReferences = tsPackages.some((lernaPkg) => {
if (lernaPkg.name === pkg.name) return false;
return (
(lernaPkg.dependencies && lernaPkg.dependencies[pkg.name]) ||
(lernaPkg.devDependencies && lernaPkg.devDependencies[pkg.name]) ||
(lernaPkg.peerDependencies && lernaPkg.peerDependencies[pkg.name])
);
});

const filteredCurrentCompilerOptions = tsconfigCurrentContent.compilerOptions || {};
const isLegacyRootDirDot = !existsSync(path.join(packagePath, 'src'));
const isApp = !tsconfigBuildPath;
const isApp = !!pkg.private && !hasReferences;
const isRootDirSrc = !(isLegacyRootDirDot || filteredCurrentCompilerOptions.rootDirs);
const isBaseUrlSrc = isApp && !isLegacyRootDirDot;

const compilerOptions = {
rootDir: isLegacyRootDirDot ? '.' : 'src',
baseUrl: isApp ? undefined : isLegacyRootDirDot ? '.' : './src',
rootDir: isRootDirSrc ? 'src' : '.',
baseUrl: isApp ? (isLegacyRootDirDot ? '.' : './src') : undefined,
composite: true,
incremental: true,
isolatedModules: true,
Expand All @@ -75,15 +87,6 @@ import { getGraphPackages } from '../index.mjs';
tsBuildInfoFile: `../../node_modules/.cache/tsc/${pkg.name}/tsbuildinfo`,
};

const hasReferences = tsPackages.some((lernaPkg) => {
if (lernaPkg.name === pkg.name) return false;
return (
(lernaPkg.dependencies && lernaPkg.dependencies[pkg.name]) ||
(lernaPkg.devDependencies && lernaPkg.devDependencies[pkg.name]) ||
(lernaPkg.peerDependencies && lernaPkg.peerDependencies[pkg.name])
);
});

if (!hasReferences) {
compilerOptions.noEmit = true;
delete compilerOptions.emitDeclarationOnly;
Expand All @@ -108,7 +111,7 @@ import { getGraphPackages } from '../index.mjs';
...compilerOptions,
...filteredCurrentCompilerOptions,
},
include: tsconfigCurrentContent.include || [isLegacyRootDirDot ? '.' : 'src', '../../typings'],
include: tsconfigCurrentContent.include || [isRootDirSrc ? 'src' : '.', '../../typings'],
};

if (isLegacyRootDirDot) {
Expand Down Expand Up @@ -181,7 +184,7 @@ import { getGraphPackages } from '../index.mjs';
if (tsDependencies.length > 0) {
tsDependencies.forEach((pkgDep) => {
const pkgRelativePath = path.relative(pkgDep.rootPath, pkgDep.location);
const depPath = `../../${pkgRelativePath}/src`;
const depPath = `../../${isBaseUrlSrc ? '../' : ''}${pkgRelativePath}/src`;
if (!tsconfigContent.compilerOptions.paths) {
tsconfigContent.compilerOptions.paths = {};
}
Expand Down

0 comments on commit dc776dc

Please sign in to comment.