diff --git a/src/plugins/output-state-plugin.ts b/src/plugins/output-state-plugin.ts index 154b2021..0c405758 100644 --- a/src/plugins/output-state-plugin.ts +++ b/src/plugins/output-state-plugin.ts @@ -9,7 +9,7 @@ import { getSpecialExportTypeFromComposedExportPath, normalizeExportPath, } from '../entries' -import { isBinExportPath, isTypeFile } from '../utils' +import { isBinExportPath, isPrivateExportPath, isTypeFile } from '../utils' // [filename, sourceFileName, size] type FileState = [string, string, number] @@ -156,22 +156,43 @@ function logOutputState(stats: SizeStats) { const [filename, , size] = item const normalizedExportName = normalizeExportName(exportName) - const prefix = + const exportNameWithPadding = index === 0 - ? normalizedExportName + ? // Each exports, only show the export path in the first item. + // For other formats, just show the padding spaces. + normalizedExportName : ' '.repeat(normalizedExportName.length) const filenamePadding = ' '.repeat( Math.max(maxLengthOfExportName, 'Exports'.length) - normalizedExportName.length, ) const isType = isTypeFile(filename) + + const prettiedSize = prettyBytes(size) const sizePadding = ' '.repeat( Math.max(maxFilenameLength, 'File'.length) - filename.length, ) - const prettiedSize = prettyBytes(size) + + // Logging shared in debug mode + if (isPrivateExportPath(exportName)) { + if (index === 0 && process.env.DEBUG) { + const sizePadding = ' '.repeat( + Math.max(maxFilenameLength, 'File'.length) - + 'private shared'.length, + ) + console.log( + pc.dim(normalizeExportName(exportName)), + filenamePadding, + pc.dim('private shared'), + sizePadding, + pc.dim(prettiedSize), + ) + } + return + } console.log( - prefix, + exportNameWithPadding, filenamePadding, `${pc[isType ? 'dim' : 'bold'](filename)}`, sizePadding, diff --git a/src/utils.ts b/src/utils.ts index 69dba835..37cf5a41 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -247,3 +247,12 @@ export function sourceFilenameToExportFullPath(filename: string) { return relativify(exportPath) } + +// If the file is matching the private module convention file export path. +// './lib/_foo' -> true +// './_util/index' -> true +// './lib/_foo/bar' -> true +// './foo' -> false +export function isPrivateExportPath(exportPath: string) { + return /\/_/.test(exportPath) +} diff --git a/test/integration/shared-module/index.test.ts b/test/integration/shared-module/index.test.ts index 3f3d046c..5be97948 100644 --- a/test/integration/shared-module/index.test.ts +++ b/test/integration/shared-module/index.test.ts @@ -10,7 +10,7 @@ describe('integration shared-module', () => { { directory: __dirname, }, - async ({ distDir }) => { + async ({ distDir, stdout }) => { const jsFiles = await getFileNamesFromDirectory(distDir) expect(jsFiles).toEqual([ '_internal/index.cjs', @@ -35,6 +35,9 @@ describe('integration shared-module', () => { 'index.react-server.js': `'./_internal/index.react-server.js'`, './_internal/index.react-server.js': 'internal:react-server', }) + + // Hide private shared module + expect(stdout).not.toContain('./lib/_util') }, ) })