Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Aug 30, 2023
1 parent 44e8fec commit 43831d0
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 26 deletions.
2 changes: 1 addition & 1 deletion mock-registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"json-stringify-safe": "^5.0.1",
"nock": "^13.3.3",
"npm-package-arg": "^11.0.0",
"pacote": "^17.0.2",
"pacote": "^17.0.3",
"tap": "^16.3.8"
}
}
4 changes: 3 additions & 1 deletion node_modules/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@
!/npm-install-checks
!/npm-normalize-package-bin
!/npm-package-arg
!/npm-packlist
!/npm-pick-manifest
!/npm-profile
!/npm-registry-fetch
Expand All @@ -211,6 +210,9 @@
!/once
!/p-map
!/pacote
!/pacote/node_modules/
/pacote/node_modules/*
!/pacote/node_modules/npm-packlist
!/parse-conflict-json
!/path-is-absolute
!/path-key
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,22 @@ const defaults = [
]

const strictDefaults = [
// these are forcibly included at all levels
// these are forcibly excluded
'/.git',
]

const allLevels = [
// these are included by default but can be excluded by package.json files array
'!/readme{,.*[^~$]}',
'!/copying{,.*[^~$]}',
'!/license{,.*[^~$]}',
'!/licence{,.*[^~$]}',
// these are forcibly excluded
'/.git',
]

const rootOnly = [
/^!.*readme/i,
/^!.*copying/i,
/^!.*licen[sc]e/i,
]

const normalizePath = (path) => path.split('\\').join('/')
Expand Down Expand Up @@ -132,6 +141,7 @@ class PackWalker extends IgnoreWalker {
// known required files for this directory
this.injectRules(strictRules, [
...strictDefaults,
...allLevels,
...this.requiredFiles.map((file) => `!${file}`),
])
}
Expand Down Expand Up @@ -284,6 +294,7 @@ class PackWalker extends IgnoreWalker {
const ignores = []
const strict = [
...strictDefaults,
...allLevels,
'!/package.json',
'/.git',
'/node_modules',
Expand All @@ -304,6 +315,9 @@ class PackWalker extends IgnoreWalker {
file = file.slice(0, -2)
}
const inverse = `!${file}`

this.excludeNonRoot(file)

try {
// if an entry in the files array is a specific file, then we need to include it as a
// strict requirement for this package. if it's a directory or a pattern, it's a default
Expand Down Expand Up @@ -352,6 +366,20 @@ class PackWalker extends IgnoreWalker {
this.injectRules(strictRules, strict, callback)
}

// excludes non root files by checking if elements from the files array in
// package.json contain an ! and readme/license/licence/copying, and then
// removing readme/license/licence/copying accordingly from strict defaults
excludeNonRoot (file) {
// Find the pattern
const matchingPattern = rootOnly.find(regex => regex.test(file))

if (matchingPattern) {
// Find which index matches the pattern and remove it from allLevels
const indexToRemove = allLevels.findIndex(element => matchingPattern.test(element))
allLevels.splice(indexToRemove, 1)
}
}

// custom method: after we've finished gathering the files for the root package, we call this
// before emitting the 'done' event in order to gather all of the files for bundled deps
async gatherBundles () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "npm-packlist",
"version": "7.0.4",
"version": "8.0.0",
"description": "Get a list of the files to add from a folder into an npm package",
"directories": {
"test": "test"
Expand All @@ -18,7 +18,7 @@
"devDependencies": {
"@npmcli/arborist": "^6.0.0 || ^6.0.0-pre.0",
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "4.10.0",
"@npmcli/template-oss": "4.18.0",
"mutate-fs": "^2.1.1",
"tap": "^16.0.1"
},
Expand Down Expand Up @@ -55,6 +55,7 @@
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.10.0"
"version": "4.18.0",
"publish": true
}
}
4 changes: 2 additions & 2 deletions node_modules/pacote/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pacote",
"version": "17.0.2",
"version": "17.0.3",
"description": "JavaScript package downloader",
"author": "GitHub Inc.",
"bin": {
Expand Down Expand Up @@ -52,7 +52,7 @@
"fs-minipass": "^3.0.0",
"minipass": "^7.0.2",
"npm-package-arg": "^11.0.0",
"npm-packlist": "^7.0.0",
"npm-packlist": "^8.0.0",
"npm-pick-manifest": "^9.0.0",
"npm-registry-fetch": "^16.0.0",
"proc-log": "^3.0.0",
Expand Down
34 changes: 23 additions & 11 deletions package-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"npm-user-validate": "^2.0.0",
"npmlog": "^7.0.1",
"p-map": "^4.0.0",
"pacote": "^17.0.2",
"pacote": "^17.0.3",
"parse-conflict-json": "^3.0.1",
"proc-log": "^3.0.0",
"qrcode-terminal": "^0.12.0",
Expand Down Expand Up @@ -230,7 +230,7 @@
"json-stringify-safe": "^5.0.1",
"nock": "^13.3.3",
"npm-package-arg": "^11.0.0",
"pacote": "^17.0.2",
"pacote": "^17.0.3",
"tap": "^16.3.8"
},
"engines": {
Expand Down Expand Up @@ -9791,7 +9791,7 @@
"version": "7.0.4",
"resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-7.0.4.tgz",
"integrity": "sha512-d6RGEuRrNS5/N84iglPivjaJPxhDbZmlbTwTDX2IbcRHG5bZCdtysYMhwiPvcF4GisXHGn7xsxv+GQ7T/02M5Q==",
"inBundle": true,
"dev": true,
"dependencies": {
"ignore-walk": "^6.0.0"
},
Expand Down Expand Up @@ -10379,9 +10379,9 @@
}
},
"node_modules/pacote": {
"version": "17.0.2",
"resolved": "https://registry.npmjs.org/pacote/-/pacote-17.0.2.tgz",
"integrity": "sha512-Us2QUwVHu4wwUhGZVOHlFIG9LhQ0Aq8zsv1ZvJ37rQwfxSIe/PaPfskz905hHycEXRfmlGKJ5xoEtrF+y66T6w==",
"version": "17.0.3",
"resolved": "https://registry.npmjs.org/pacote/-/pacote-17.0.3.tgz",
"integrity": "sha512-nT66y5NK2u/d7qV9lP6ye+powAufDl6OHT+aOZ4Cmtq89GSqgB05Ar6aQ7DM+0+bIE5NCdYUcqFlkK4m/0LVHA==",
"inBundle": true,
"dependencies": {
"@npmcli/git": "^5.0.0",
Expand All @@ -10392,7 +10392,7 @@
"fs-minipass": "^3.0.0",
"minipass": "^7.0.2",
"npm-package-arg": "^11.0.0",
"npm-packlist": "^7.0.0",
"npm-packlist": "^8.0.0",
"npm-pick-manifest": "^9.0.0",
"npm-registry-fetch": "^16.0.0",
"proc-log": "^3.0.0",
Expand All @@ -10410,6 +10410,18 @@
"node": "^16.14.0 || >=18.0.0"
}
},
"node_modules/pacote/node_modules/npm-packlist": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-8.0.0.tgz",
"integrity": "sha512-ErAGFB5kJUciPy1mmx/C2YFbvxoJ0QJ9uwkCZOeR6CqLLISPZBOiFModAbSXnjjlwW5lOhuhXva+fURsSGJqyw==",
"inBundle": true,
"dependencies": {
"ignore-walk": "^6.0.0"
},
"engines": {
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
}
},
"node_modules/parent-module": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz",
Expand Down Expand Up @@ -15852,7 +15864,7 @@
"npm-pick-manifest": "^9.0.0",
"npm-registry-fetch": "^16.0.0",
"npmlog": "^7.0.1",
"pacote": "^17.0.2",
"pacote": "^17.0.3",
"parse-conflict-json": "^3.0.0",
"proc-log": "^3.0.0",
"promise-all-reject-late": "^1.0.0",
Expand Down Expand Up @@ -15933,7 +15945,7 @@
"diff": "^5.1.0",
"minimatch": "^9.0.0",
"npm-package-arg": "^11.0.0",
"pacote": "^17.0.2",
"pacote": "^17.0.3",
"tar": "^6.1.13"
},
"devDependencies": {
Expand All @@ -15954,7 +15966,7 @@
"ci-info": "^3.7.1",
"npm-package-arg": "^11.0.0",
"npmlog": "^7.0.1",
"pacote": "^17.0.2",
"pacote": "^17.0.3",
"proc-log": "^3.0.0",
"read": "^2.0.0",
"read-package-json-fast": "^3.0.2",
Expand Down Expand Up @@ -16032,7 +16044,7 @@
"@npmcli/arborist": "^6.3.0",
"@npmcli/run-script": "^6.0.0",
"npm-package-arg": "^11.0.0",
"pacote": "^17.0.2"
"pacote": "^17.0.3"
},
"devDependencies": {
"@npmcli/eslint-config": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"npm-user-validate": "^2.0.0",
"npmlog": "^7.0.1",
"p-map": "^4.0.0",
"pacote": "^17.0.2",
"pacote": "^17.0.3",
"parse-conflict-json": "^3.0.1",
"proc-log": "^3.0.0",
"qrcode-terminal": "^0.12.0",
Expand Down
2 changes: 1 addition & 1 deletion workspaces/arborist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"npm-pick-manifest": "^9.0.0",
"npm-registry-fetch": "^16.0.0",
"npmlog": "^7.0.1",
"pacote": "^17.0.2",
"pacote": "^17.0.3",
"parse-conflict-json": "^3.0.0",
"proc-log": "^3.0.0",
"promise-all-reject-late": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion workspaces/libnpmdiff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"diff": "^5.1.0",
"minimatch": "^9.0.0",
"npm-package-arg": "^11.0.0",
"pacote": "^17.0.2",
"pacote": "^17.0.3",
"tar": "^6.1.13"
},
"templateOSS": {
Expand Down
2 changes: 1 addition & 1 deletion workspaces/libnpmexec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"ci-info": "^3.7.1",
"npm-package-arg": "^11.0.0",
"npmlog": "^7.0.1",
"pacote": "^17.0.2",
"pacote": "^17.0.3",
"proc-log": "^3.0.0",
"read": "^2.0.0",
"read-package-json-fast": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion workspaces/libnpmpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@npmcli/arborist": "^6.3.0",
"@npmcli/run-script": "^6.0.0",
"npm-package-arg": "^11.0.0",
"pacote": "^17.0.2"
"pacote": "^17.0.3"
},
"engines": {
"node": "^16.14.0 || >=18.0.0"
Expand Down

0 comments on commit 43831d0

Please sign in to comment.