Skip to content

Commit

Permalink
Update build to not include transitives of cjs modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Nov 7, 2024
1 parent 9047d25 commit e466fac
Show file tree
Hide file tree
Showing 5 changed files with 1,220 additions and 1,957 deletions.
43 changes: 26 additions & 17 deletions .config/rollup.base.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ const customResolver = nodeResolve({
preferBuiltins: true
})

function isAncestorsCjs(resolvedId, parentId) {
let currNmIndex = resolvedId.indexOf(SLASH_NODE_MODULES_SLASH)
while (currNmIndex !== -1) {
const nextNmIndex = resolvedId.indexOf(
SLASH_NODE_MODULES_SLASH,
currNmIndex + 1
)
const currPkgName = resolvedId.slice(
currNmIndex + SLASH_NODE_MODULES_SLASH.length,
nextNmIndex === -1 ? resolvedId.length : nextNmIndex
)
if (isEsmId(currPkgName, parentId)) {
return false
}
currNmIndex = nextNmIndex
}
return true
}

export default (extendConfig = {}) => {
const depStats = {
dependencies: { __proto__: null },
Expand Down Expand Up @@ -79,22 +98,7 @@ export default (extendConfig = {}) => {
const parentId = parentId_ ? resolveId(parentId_) : undefined
const resolvedId = resolveId(id, parentId)
if (resolvedId.endsWith('.json')) {
let currNmIndex = resolvedId.indexOf(SLASH_NODE_MODULES_SLASH)
while (currNmIndex !== -1) {
const nextNmIndex = resolvedId.indexOf(
SLASH_NODE_MODULES_SLASH,
currNmIndex + 1
)
const currPkgName = resolvedId.slice(
currNmIndex + SLASH_NODE_MODULES_SLASH.length,
nextNmIndex === -1 ? resolvedId.length : nextNmIndex
)
if (isEsmId(currPkgName, parentId)) {
return false
}
currNmIndex = nextNmIndex
}
return true
return isAncestorsCjs(resolvedId, parentId)
}
if (!isPackageName(id)) {
return false
Expand All @@ -115,8 +119,13 @@ export default (extendConfig = {}) => {
''
return false
}
const parentNodeModulesIndex = parentId.lastIndexOf('/node_modules/')
const parentNodeModulesIndex = parentId.lastIndexOf(
SLASH_NODE_MODULES_SLASH
)
if (parentNodeModulesIndex !== -1) {
if (isAncestorsCjs(resolvedId, parentId)) {
return true
}
const parentNameStart = parentNodeModulesIndex + 14
const parentNameEnd = getPackageNameEnd(parentId, parentNameStart)
const {
Expand Down
46 changes: 8 additions & 38 deletions .dep-stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
"@npmcli/promise-spawn": "^8.0.2",
"@socketregistry/hyrious__bun.lockb": "1.0.4",
"@socketsecurity/config": "^2.1.3",
"@socketsecurity/registry": "^1.0.13",
"@socketsecurity/registry": "^1.0.14",
"@socketsecurity/sdk": "^1.3.0",
"blessed": "^0.1.81",
"blessed-contrib": "^4.11.0",
"browserslist": "4.24.2",
"chalk-table": "^1.0.2",
"hpagent": "^1.2.0",
"ignore": "^6.0.2",
"micromatch": "^4.0.8",
"npm-package-arg": "^12.0.0",
"pacote": "^20.0.0",
"pony-cause": "^2.1.11",
"semver": "^7.6.3",
"synp": "^1.9.13",
"tinyglobby": "^0.2.10",
"which": "^5.0.0",
Expand Down Expand Up @@ -84,61 +86,29 @@
"@npmcli/promise-spawn": "^8.0.2",
"@socketregistry/hyrious__bun.lockb": "1.0.4",
"@socketsecurity/config": "^2.1.3",
"@socketsecurity/registry": "^1.0.13",
"@socketsecurity/registry": "^1.0.14",
"@socketsecurity/sdk": "^1.3.0",
"ansi-align": "^3.0.1",
"blessed": "^0.1.81",
"blessed-contrib": "^4.11.0",
"browserslist": "4.24.2",
"chalk-table": "^1.0.2",
"cli-boxes": "^4.0.1",
"cli-spinners": "^3.2.0",
"cross-spawn": "^7.0.3",
"dot-prop": "^9.0.0",
"eastasianwidth": "^0.3.0",
"emoji-regex": "^10.4.0",
"graceful-fs": "^4.2.11",
"has-flag": "^5.0.1",
"emoji-regex": "^10.3.0",
"hpagent": "^1.2.0",
"ignore": "^6.0.2",
"ini": "5.0.0",
"ini": "4.1.1",
"micromatch": "^4.0.8",
"npm-package-arg": "^12.0.0",
"onetime": "^7.0.0",
"pacote": "^20.0.0",
"pony-cause": "^2.1.11",
"rc": "1.2.8",
"registry-auth-token": "^5.0.2",
"semver": "^7.6.3",
"signal-exit": "^4.1.0",
"supports-color": "^9.4.0",
"supports-hyperlinks": "^3.1.0",
"synp": "^1.9.13",
"tinyglobby": "^0.2.10",
"which": "^5.0.0",
"write-file-atomic": "^6.0.0",
"yaml": "^2.6.0",
"yargs-parser": "^21.1.1"
},
"transitives": {
"ansi-align": "^3.0.1",
"cli-boxes": "^4.0.1",
"cli-spinners": "^3.2.0",
"cross-spawn": "^7.0.3",
"dot-prop": "^9.0.0",
"eastasianwidth": "^0.3.0",
"emoji-regex": "^10.4.0",
"graceful-fs": "^4.2.11",
"has-flag": "^5.0.1",
"ignore": "^6.0.2",
"ini": "5.0.0",
"onetime": "^7.0.0",
"rc": "1.2.8",
"registry-auth-token": "^5.0.2",
"semver": "^7.6.3",
"signal-exit": "^4.1.0",
"supports-color": "^9.4.0",
"supports-hyperlinks": "^3.1.0",
"write-file-atomic": "^6.0.0"
"emoji-regex": "^10.3.0",
"ini": "4.1.1"
}
}
12 changes: 11 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const tsParser = require('@typescript-eslint/parser')
const gitignorePath = path.resolve(__dirname, '.gitignore')
const prettierignorePath = path.resolve(__dirname, '.prettierignore')

const {
engines: { node: nodeRange }
} = require('./package.json')

const sharedPlugins = {
'sort-destructure-keys': sortDestructureKeysPlugin,
unicorn: unicornPlugin
Expand Down Expand Up @@ -104,7 +108,13 @@ module.exports = [
'n/no-unpublished-bin': ['error'],
'n/no-unsupported-features/es-builtins': ['error'],
'n/no-unsupported-features/es-syntax': ['error'],
'n/no-unsupported-features/node-builtins': ['error'],
'n/no-unsupported-features/node-builtins': [
'error',
{
ignores: ['test.describe'],
version: nodeRange
}
],
'n/prefer-node-protocol': ['error'],
'no-unused-vars': [
'error',
Expand Down
Loading

0 comments on commit e466fac

Please sign in to comment.