-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #243 from relative-ci/stats-options
Stats options
- Loading branch information
Showing
8 changed files
with
527 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean); | ||
|
||
export type ExcludeFilepathOption = ExcludeFilepathParam | Array<ExcludeFilepathParam>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import path from 'path'; | ||
import crypto from 'crypto'; | ||
import type { OutputChunk } from 'rollup'; | ||
|
||
import type { ExcludeFilepathOption } from './types'; | ||
|
||
const HASH_LENGTH = 7; | ||
|
||
/** | ||
* Get content byte size | ||
*/ | ||
export function getByteSize(content: string | Buffer): number { | ||
if (typeof content === 'string') { | ||
return Buffer.from(content).length; | ||
} | ||
|
||
return content?.length || 0; | ||
} | ||
|
||
/** | ||
* Generate a 7 chars hash from a filepath | ||
*/ | ||
export function getHash(filepath: string): string { | ||
const digest = crypto.createHash('sha256'); | ||
return digest.update(Buffer.from(filepath)).digest('hex').substr(0, HASH_LENGTH); | ||
} | ||
|
||
export function getChunkId(chunk: OutputChunk): string { | ||
let value = chunk.name; | ||
|
||
// Use entry module relative path | ||
if (chunk.moduleIds?.length > 0) { | ||
const absoluteModulePath = chunk.moduleIds[chunk.moduleIds.length - 1]; | ||
value = path.relative(process.cwd(), absoluteModulePath); | ||
} | ||
|
||
return getHash([chunk, value].join('-')); | ||
} | ||
|
||
/** | ||
* Check if filepath should be excluded based on a config | ||
*/ | ||
export function checkExcludeFilepath( | ||
filepath: string, | ||
option?: ExcludeFilepathOption, | ||
): boolean { | ||
if (!option) { | ||
return false; | ||
} | ||
|
||
if (Array.isArray(option)) { | ||
let res = false; | ||
|
||
for (let i = 0; i <= option.length - 1 && res === false; i++) { | ||
res = checkExcludeFilepath(filepath, option[i]); | ||
} | ||
|
||
return res; | ||
} | ||
|
||
if (typeof option === 'function') { | ||
return option(filepath); | ||
} | ||
|
||
if (typeof option === 'string') { | ||
return Boolean(filepath.match(option)); | ||
} | ||
|
||
if ('test' in option) { | ||
return option.test(filepath); | ||
} | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
import path from 'path'; | ||
import type { OutputBundle } from 'rollup'; | ||
|
||
const ROOT_DIR = path.join(__dirname, '../../../'); | ||
|
||
export default { | ||
'assets/logo-abcd1234.svg': { | ||
name: undefined, | ||
fileName: 'assets/logo-abcd1234.svg', | ||
type: 'asset', | ||
source: '<svg></svg>', | ||
needsCodeReference: true, | ||
}, | ||
'assets/main-abcd1234.js': { | ||
name: 'main', | ||
fileName: 'assets/main-abcd1234.js', | ||
preliminaryFileName: 'assets/main-abcd1234.js', | ||
sourcemapFileName: 'assets/main-abcd1234.js.map', | ||
type: 'chunk', | ||
code: 'export default function () {}', | ||
isEntry: true, | ||
isDynamicEntry: false, | ||
facadeModuleId: null, | ||
map: null, | ||
isImplicitEntry: false, | ||
implicitlyLoadedBefore: [], | ||
importedBindings: {}, | ||
referencedFiles: [], | ||
moduleIds: [ | ||
path.join(ROOT_DIR, 'src/component-a.js'), | ||
path.join(ROOT_DIR, 'src/index.js'), | ||
], | ||
modules: { | ||
[path.join(ROOT_DIR, 'src/component-a.js')]: { | ||
code: 'export default A = 1;', | ||
originalLength: 10, | ||
renderedLength: 8, | ||
removedExports: [], | ||
renderedExports: [], | ||
}, | ||
[path.join(ROOT_DIR, 'src/index.js')]: { | ||
code: '', | ||
originalLength: 100, | ||
renderedLength: 80, | ||
removedExports: [], | ||
renderedExports: [], | ||
}, | ||
}, | ||
imports: [], | ||
exports: [], | ||
dynamicImports: [], | ||
}, | ||
'assets/vendors-abcd1234.js': { | ||
name: 'vendors', | ||
fileName: 'assets/vendors-abcd1234.js', | ||
preliminaryFileName: 'assets/vendors-abcd1234.js', | ||
sourcemapFileName: 'assets/vendors-abcd1234.js.map', | ||
type: 'chunk', | ||
code: 'export default function () {}', | ||
isEntry: true, | ||
isDynamicEntry: false, | ||
facadeModuleId: null, | ||
map: null, | ||
isImplicitEntry: false, | ||
implicitlyLoadedBefore: [], | ||
importedBindings: {}, | ||
referencedFiles: [], | ||
moduleIds: [ | ||
path.join(ROOT_DIR, 'node_modules', 'package-a', 'index.js'), | ||
path.join(ROOT_DIR, 'node_modules', 'package-b', 'index.js'), | ||
], | ||
modules: { | ||
[path.join( | ||
ROOT_DIR, | ||
'node_modules', | ||
'package-a', | ||
'index.js' | ||
)]: { | ||
code: '', | ||
originalLength: 10, | ||
renderedLength: 8, | ||
removedExports: [], | ||
renderedExports: [], | ||
}, | ||
[path.join( | ||
ROOT_DIR, | ||
'node_modules', | ||
'package-b', | ||
'index.js' | ||
)]: { | ||
code: '', | ||
originalLength: 100, | ||
renderedLength: 80, | ||
removedExports: [], | ||
renderedExports: [], | ||
}, | ||
}, | ||
imports: [], | ||
exports: [], | ||
dynamicImports: [], | ||
}, | ||
'assets/index-abcd1234.js': { | ||
name: 'index', | ||
fileName: 'assets/index-abcd1234.js', | ||
preliminaryFileName: 'assets/index-abcd1234.js', | ||
sourcemapFileName: 'assets/index-abcd1234.js.map', | ||
type: 'chunk', | ||
code: 'export default function () {}', | ||
isEntry: false, | ||
isDynamicEntry: true, | ||
facadeModuleId: null, | ||
map: null, | ||
isImplicitEntry: false, | ||
implicitlyLoadedBefore: [], | ||
importedBindings: {}, | ||
referencedFiles: [], | ||
moduleIds: [ | ||
path.join(ROOT_DIR, 'src', 'components/component-b/index.js'), | ||
], | ||
modules: { | ||
[path.join( | ||
ROOT_DIR, | ||
'src', | ||
'components', | ||
'component-b', | ||
'index.js', | ||
)]: { | ||
code: '', | ||
originalLength: 10, | ||
renderedLength: 8, | ||
removedExports: [], | ||
renderedExports: [], | ||
}, | ||
}, | ||
imports: [], | ||
exports: [], | ||
dynamicImports: [], | ||
}, | ||
'assets/index-efab5678.js': { | ||
name: 'index', | ||
fileName: 'assets/index-efab5678.js', | ||
preliminaryFileName: 'assets/index-efab5678.js', | ||
sourcemapFileName: 'assets/index-efab5678.js.map', | ||
type: 'chunk', | ||
code: 'export default function () {}', | ||
isEntry: false, | ||
isDynamicEntry: true, | ||
facadeModuleId: null, | ||
map: null, | ||
isImplicitEntry: false, | ||
implicitlyLoadedBefore: [], | ||
importedBindings: {}, | ||
referencedFiles: [], | ||
moduleIds: [ | ||
path.join(ROOT_DIR, 'src', 'components/component-c/index.js'), | ||
], | ||
modules: { | ||
[path.join( | ||
ROOT_DIR, | ||
'src', | ||
'components', | ||
'component-c', | ||
'index.js', | ||
)]: { | ||
code: '', | ||
originalLength: 10, | ||
renderedLength: 8, | ||
removedExports: [], | ||
renderedExports: [], | ||
}, | ||
}, | ||
imports: [], | ||
exports: [], | ||
dynamicImports: [], | ||
}, | ||
} satisfies OutputBundle; |
Oops, something went wrong.