Skip to content

Commit 43ad4ce

Browse files
committed
Increase test coverage
1 parent de8a4ab commit 43ad4ce

File tree

5 files changed

+212
-142
lines changed

5 files changed

+212
-142
lines changed

index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
SOFTWARE.
2121
*/
2222

23+
/* c8 ignore start - Re-export only file, no logic to test. */
2324
export {
2425
PackageURL,
2526
PurlComponent,
2627
PurlQualifierNames,
2728
PurlType,
2829
} from './src/package-url.js'
30+
/* c8 ignore stop */

scripts/update-data-npm.mjs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import Module from 'node:module'
22
import path from 'node:path'
33
import { fileURLToPath } from 'node:url'
44

5+
import allThePackageNamesData from 'all-the-package-names/names' with {
6+
type: 'json',
7+
}
8+
import allThePackageNamesV1Data from 'all-the-package-names-v1.3905.0/names' with {
9+
type: 'json',
10+
}
511
import pacote from 'pacote'
612
import semver from 'semver'
713
import validateNpmPackageName from 'validate-npm-package-name'
@@ -61,13 +67,6 @@ void (async () => {
6167
spinner.stop()
6268
return
6369
}
64-
const allThePackageNamesData = await import('all-the-package-names/names.json', {
65-
with: { type: 'json' }
66-
})
67-
const allThePackageNamesV1Data = await import('all-the-package-names-v1.3905.0/names.json', {
68-
with: { type: 'json' }
69-
})
70-
7170
const allThePackageNames = [
7271
...new Set([
7372
// Load the 43.1MB names.json file of '[email protected]'

src/purl-type.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ const getNpmBuiltinNames = (() => {
1919
let builtinNames: any
2020
return () => {
2121
if (builtinNames === undefined) {
22+
/* c8 ignore start - Error handling for module access. */
2223
try {
23-
// Try to use Node.js builtinModules first
24+
// Try to use Node.js builtinModules first.
2425
builtinNames = (module.constructor as any)?.builtinModules
25-
} catch {}
26+
} catch {
27+
}
28+
/* c8 ignore stop */
2629
if (!builtinNames) {
2730
// Fallback to hardcoded list
2831
builtinNames = [
@@ -80,11 +83,12 @@ const getNpmLegacyNames = (() => {
8083

8184
return (): string[] => {
8285
if (fullLegacyNames === undefined) {
86+
/* c8 ignore start - Fallback path only used if JSON file fails to load. */
8387
try {
84-
// Try to load the full list from JSON file
88+
// Try to load the full list from JSON file.
8589
fullLegacyNames = require('../data/npm/legacy-names.json')
8690
} catch {
87-
// Fallback to hardcoded builtin names for simplicity
91+
// Fallback to hardcoded builtin names for simplicity.
8892
fullLegacyNames = [
8993
'assert',
9094
'buffer',
@@ -98,6 +102,7 @@ const getNpmLegacyNames = (() => {
98102
'util',
99103
]
100104
}
105+
/* c8 ignore stop */
101106
}
102107
return fullLegacyNames!
103108
}

0 commit comments

Comments
 (0)