Skip to content

Commit

Permalink
feat(interfaces): PublishConfig
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Dec 1, 2022
1 parent ec81ecd commit a530f4f
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/interfaces/__tests__/publish-config.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @file Unit Tests - PublishConfig
* @module pkg-types/interfaces/tests/PublishConfig
*/

import type TestSubject from '../publish-config'

describe('unit:interfaces/PublishConfig', () => {
it('should allow empty object', () => {
assertType<TestSubject>({})
})

it('should allow object that only has property "access"', () => {
assertType<TestSubject>({ access: 'public' })
assertType<TestSubject>({ access: 'restricted' })
})

it('should allow object that only has property "bin"', () => {
assertType<TestSubject>({ bin: './cli.mjs' })
assertType<TestSubject>({ bin: { mkbuild: './cli.mjs' } })
})

it('should allow object that only has property "executableFiles"', () => {
assertType<TestSubject>({ executableFiles: ['./dist/shim.js'] })
})

it('should allow object that only has property "main"', () => {
assertType<TestSubject>({ main: './index.cjs' })
})

it('should allow object that only has property "module"', () => {
assertType<TestSubject>({ module: './index.mjs' })
})

it('should allow object that only has property "registry"', () => {
assertType<TestSubject>({ registry: 'http://npm.pkg.github.com' })
})

it('should allow object that only has property "tag"', () => {
assertType<TestSubject>({ tag: 'alpha' })
})

it('should allow object with all properties', () => {
assertType<Required<TestSubject>>({
access: 'public',
bin: './cli.mjs',
executableFiles: ['./dist/shim.js'],
main: './index.cjs',
module: './index.mjs',
registry: 'http://npm.pkg.github.com',
tag: 'alpha'
})
})

it('should allow object with unknown key', () => {
assertType<TestSubject>({ key: 'value' })
})
})
1 change: 1 addition & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export type { default as FundingObject } from './funding-object'
export type { default as InstallConfig } from './install-config'
export type { default as LicenseObject } from './license-object'
export type { default as PeerDependencyMeta } from './peer-dependency-meta'
export type { default as PublishConfig } from './publish-config'
export type { default as WorkspacesConfig } from './workspaces-config'
70 changes: 70 additions & 0 deletions src/interfaces/publish-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* @file Interfaces - PublishConfig
* @module pkg-types/interfaces/PublishConfig
*/

import type { Access, Bin, Registry } from '#src/types'
import type { JSONValue } from '@flex-development/tutils'

/**
* Set of configuration values to use when a package is published.
*
* @see https://docs.npmjs.com/cli/v9/configuring-npm/package-json#publishconfig
* @see https://yarnpkg.com/configuration/manifest#publishConfig
*/
interface PublishConfig {
[key: string]: JSONValue | undefined

/**
* Package access level.
*/
access?: Access

/**
* Replacement for top-level `bin` field.
*
* **Note**: Only modifies the manifest stored in the package tarball, not the
* real `package.json` file.
*/
bin?: Bin

/**
* Additional files that must have the executable flag (`+x`) set even if they
* aren't directly accessible through the `bin` field.
*/
executableFiles?: string[]

/**
* Replacement for top-level `main` field.
*
* **Note**: Only modifies the manifest stored in the package tarball, not the
* real `package.json` file.
*/
main?: string

/**
* Replacement for top-level `module` field.
*
* **Note**: Only modifies the manifest stored in the package tarball, not the
* real `package.json` file.
*/
module?: string

/**
* Package registry URL.
*
* @default 'https://registry.npmjs.org/'
*/
registry?: Registry

/**
* Distribution tag.
*
* @see https://docs.npmjs.com/cli/commands/npm-dist-tag
*
* @default 'latest'
*/
tag?: string
}

export type { PublishConfig as default }

0 comments on commit a530f4f

Please sign in to comment.