Skip to content

Commit

Permalink
Flesh out the registry package
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Oct 10, 2024
1 parent 7594ef3 commit aa20354
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 35 deletions.
7 changes: 5 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions registry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@

[![CI - SocketDev/socket-registry-js](https://github.com/SocketDev/socket-registry-js/actions/workflows/test.yml/badge.svg)](https://github.com/SocketDev/socket-registry-js/actions/workflows/test.yml)
[![Follow @SocketSecurity](https://img.shields.io/twitter/follow/SocketSecurity?style=social)](https://twitter.com/SocketSecurity)

> A support package for
> [`@socketregistry`](https://github.com/SocketDev/socket-registry-js) providing
> helper methods and metadata.
33 changes: 33 additions & 0 deletions registry/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
declare enum Categories {
CLEANUP = 'cleanup',
LEVELUP = 'levelup',
SPEEDUP = 'speedup',
TUNEUP = 'tuneup'
}
declare type CategoryString = `${Categories}`
declare enum PURL_Type {
NPM = 'npm'
}
declare type EcosystemString = `${PURL_Type}`
declare enum Interop {
BROWSERIFY = 'browserify',
CJS = 'cjs',
ESM = 'esm'
}
declare type InteropString = `${Interop}`
declare type ManifestData = {
categories: CategoryString[]
interop: InteropString[]
license: string
package: string
version: string
deprecated?: boolean
engines?: { node: string; npm?: string }
skipTests?: boolean
}
declare module '@socketsecurity/registry' {
export function getManifestData(
eco: EcosystemString,
regPkgName: string
): ManifestData | undefined
}
20 changes: 19 additions & 1 deletion registry/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
'use strict'

module.exports = require('./manifest.json')
const { PackageURL } = require('packageurl-js')

function getManifestData(eco, regPkgName) {
const registryManifest = require('./manifest.json')
let purlObj
const entry = registryManifest[eco].find(({ 0: purlStr }) => {
const purlObj_ = PackageURL.fromString(purlStr)
const found = purlObj_.name === regPkgName
if (found) {
purlObj = purlObj_
}
return found
})
return entry ? { ...entry[1], version: purlObj.version } : undefined
}

module.exports = {
getManifestData
}
15 changes: 11 additions & 4 deletions registry/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@socketsecurity/registry",
"version": "1.0.0",
"version": "1.0.1",
"license": "MIT",
"description": "Socket.dev registry helpers and metadata",
"description": "Socket.dev registry helpers methods and metadata",
"keywords": [
"Socket.dev"
],
Expand All @@ -12,16 +12,23 @@
"directory": "registry"
},
"exports": {
".": "./index.js",
".": {
"types": "./index.d.ts",
"default": "./index.js"
},
"./manifest.json": "./manifest.json",
"./package.json": "./package.json"
},
"sideEffects": false,
"dependencies": {
"packageurl-js": "^2.0.1"
},
"engines": {
"node": ">=18.20.4"
},
"files": [
"*.js",
"*.d.ts",
"*.{c,}js",
"*.json"
]
}
22 changes: 0 additions & 22 deletions scripts/utils/manifest.js

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/utils/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ const {
TEMPLATE_ES_SHIM_STATIC_METHOD,
npmTemplatesPath
} = constants
const { getManifestData } = require('@socketregistry/scripts/utils//manifest')
const { globLicenses } = require('@socketregistry/scripts/utils/globs')
const { isObjectObject } = require('@socketregistry/scripts/utils/objects')
const {
readPackageJson,
resolveOriginalPackageName
} = require('@socketregistry/scripts/utils/packages')
const { prettierFormat } = require('@socketregistry/scripts/utils/strings')
const { getManifestData } = require('@socketsecurity/registry')

const eta = new Eta()

Expand Down
5 changes: 2 additions & 3 deletions test/npm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ import {
// @ts-ignore
} from '@socketregistry/scripts/utils/git'
// @ts-ignore
import { getManifestData } from '@socketregistry/scripts/utils/manifest'
// @ts-ignore
import { runScript } from '@socketregistry/scripts/utils/npm'
import {
resolveOriginalPackageName
// @ts-ignore
} from '@socketregistry/scripts/utils/packages'
// @ts-ignore
import { isNonEmptyString } from '@socketregistry/scripts/utils/strings'
import { getManifestData } from '@socketsecurity/registry'

// Pass args as tap --test-arg:
// npm run test:unit ./test/npm.test.ts -- --test-arg="--force"
Expand Down Expand Up @@ -72,7 +71,7 @@ describe(eco, { skip: !packageNames.length }, () => {
const skip =
!nwPkgJson.scripts?.test ||
(WIN_32 &&
!manifestData.interop.includes('browserify') &&
!manifestData?.interop.includes('browserify') &&
!win32EnsureTestsByEcosystem?.[eco].has(origPkgName)) ||
(isNonEmptyString(nodeRange) &&
!semver.satisfies(NODE_VERSION, nodeRange))
Expand Down
3 changes: 1 addition & 2 deletions test/packages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import {
// @ts-ignore
} from '@socketregistry/scripts/utils/git'
// @ts-ignore
import { getManifestData } from '@socketregistry/scripts/utils/manifest'
// @ts-ignore
import { isObjectObject } from '@socketregistry/scripts/utils/objects'
import {
findTypesForSubpath,
Expand All @@ -46,6 +44,7 @@ import { trimLeadingDotSlash } from '@socketregistry/scripts/utils/path'
import { localeCompare } from '@socketregistry/scripts/utils/sorts'
// @ts-ignore
import { isNonEmptyString } from '@socketregistry/scripts/utils/strings'
import { getManifestData } from '@socketsecurity/registry'

// Pass args as tap --test-arg:
// npm run test:unit ./test/packages.test.ts -- --test-arg="--force"
Expand Down

0 comments on commit aa20354

Please sign in to comment.