Skip to content

Commit 19b3362

Browse files
committed
refactor: create spdx-pack bundle to eliminate duplication
Consolidates spdx-correct and spdx-expression-parse into a single spdx-pack bundle to eliminate duplicate code. Individual spdx modules now re-export from spdx-pack as thin wrappers (~160 bytes each). Changes: - Add src/external/spdx-pack.js and .d.ts with spdx-correct and spdx-expression-parse - Convert spdx-correct.js and spdx-expression-parse.js to wrappers - Update build-externals config to bundle spdx-pack and copy wrappers Bundle size impact: - Before: 61KB total (36KB + 25KB) - After: 44KB spdx-pack + 2 × ~160B wrappers = ~44.3KB total - Savings: ~17KB (28% reduction)
1 parent d382b78 commit 19b3362

5 files changed

Lines changed: 32 additions & 4 deletions

File tree

scripts/build-externals/config.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ export const externalPackages = [
3131
// inquirer-pack: Bundle all @inquirer packages together.
3232
{ name: 'inquirer-pack', bundle: true },
3333
{ name: 'picomatch', bundle: false },
34-
{ name: 'spdx-correct', bundle: true },
35-
{ name: 'spdx-expression-parse', bundle: true },
34+
// spdx-pack: Bundle spdx-correct, spdx-expression-parse, and dependencies together.
35+
{ name: 'spdx-pack', bundle: true },
36+
{ name: 'spdx-correct', bundle: false },
37+
{ name: 'spdx-expression-parse', bundle: false },
3638
{ name: 'streaming-iterables', bundle: true },
3739
{ name: 'validate-npm-package-name', bundle: true },
3840
{ name: 'which', bundle: true },

src/external/spdx-correct.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
'use strict'
22

3-
module.exports = require('spdx-correct')
3+
// Re-export from spdx-pack bundle for better deduplication.
4+
const { spdxCorrect } = require('./spdx-pack')
5+
module.exports = spdxCorrect
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
'use strict'
22

3-
module.exports = require('spdx-expression-parse')
3+
// Re-export from spdx-pack bundle for better deduplication.
4+
const { spdxExpressionParse } = require('./spdx-pack')
5+
module.exports = spdxExpressionParse

src/external/spdx-pack.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type spdxCorrect from 'spdx-correct'
2+
import type spdxExpressionParse from 'spdx-expression-parse'
3+
4+
export interface SpdxPack {
5+
spdxCorrect: typeof spdxCorrect
6+
spdxExpressionParse: typeof spdxExpressionParse
7+
}
8+
9+
declare const spdxPack: SpdxPack
10+
export default spdxPack

src/external/spdx-pack.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict'
2+
3+
// spdx-pack: Bundle spdx-correct and spdx-expression-parse together.
4+
// These packages share dependencies and are commonly used together for SPDX license validation.
5+
6+
const spdxCorrect = require('spdx-correct')
7+
const spdxExpressionParse = require('spdx-expression-parse')
8+
9+
module.exports = {
10+
spdxCorrect,
11+
spdxExpressionParse,
12+
}

0 commit comments

Comments
 (0)