mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-26 02:51:59 -04:00
* feat(config): add support for token helper Use the new interface in `pnpm/credentials-by-uri` for supporting token helpers. A token helper is an executable, set in the user's `.npmrc` which outputs an auth token. This can be used in situations where the `authToken` is not a constant value, but is something that refreshes regularly, where a script or other tool can use an existing refresh token to obtain a new access token. The configuration for the path to the helper must be an absolute path, with no arguments. In order to be secure, it is _only_ permitted to set this value in the user `.npmrc`, otherwise a project could place a value in a project local `.npmrc` and run arbitrary executables. A similar feature is available in many similar tools. The implementation in `credentials-by-uri` is modelled after the `vault` (vaultproject.io) implementation - https://github.com/hashicorp/vault/blob/main/command/token/helper_external.go * test: fix * docs: add changesets Co-authored-by: Zoltan Kochan <z@kochan.io>
84 lines
2.2 KiB
TypeScript
84 lines
2.2 KiB
TypeScript
import fs from 'fs'
|
|
import path from 'path'
|
|
import assertStore from '@pnpm/assert-store'
|
|
import { store } from '@pnpm/plugin-commands-store'
|
|
import { tempDir } from '@pnpm/prepare'
|
|
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
|
|
|
|
const STORE_VERSION = 'v3'
|
|
|
|
test('pnpm store add express@4.16.3', async () => {
|
|
tempDir()
|
|
|
|
const cacheDir = path.resolve('cache')
|
|
const storeDir = path.resolve('store')
|
|
|
|
await store.handler({
|
|
cacheDir,
|
|
dir: process.cwd(),
|
|
rawConfig: {
|
|
registry: `http://localhost:${REGISTRY_MOCK_PORT}/`,
|
|
},
|
|
registries: { default: `http://localhost:${REGISTRY_MOCK_PORT}/` },
|
|
storeDir,
|
|
userConfig: {},
|
|
}, ['add', 'express@4.16.3'])
|
|
|
|
const { cafsHas } = assertStore(path.join(storeDir, STORE_VERSION))
|
|
await cafsHas('sha1-avilAjUNsyRuzEvs9rWjTSL37VM=')
|
|
})
|
|
|
|
test('pnpm store add scoped package that uses not the standard registry', async () => {
|
|
tempDir()
|
|
|
|
const cacheDir = path.resolve('cache')
|
|
const storeDir = path.resolve('store')
|
|
|
|
await store.handler({
|
|
cacheDir,
|
|
dir: process.cwd(),
|
|
rawConfig: {
|
|
registry: 'https://registry.npmjs.org/',
|
|
},
|
|
registries: {
|
|
'@foo': `http://localhost:${REGISTRY_MOCK_PORT}/`,
|
|
default: 'https://registry.npmjs.org/',
|
|
},
|
|
storeDir,
|
|
userConfig: {},
|
|
}, ['add', '@foo/no-deps@1.0.0'])
|
|
|
|
const { cafsHas } = assertStore(path.join(storeDir, STORE_VERSION))
|
|
await cafsHas('@foo/no-deps', '1.0.0')
|
|
})
|
|
|
|
test('should fail if some packages can not be added', async () => {
|
|
tempDir()
|
|
fs.mkdirSync('_')
|
|
process.chdir('_')
|
|
const cacheDir = path.resolve('cache')
|
|
const storeDir = path.resolve('pnpm-store')
|
|
|
|
let thrown = false
|
|
try {
|
|
await store.handler({
|
|
cacheDir,
|
|
dir: process.cwd(),
|
|
rawConfig: {
|
|
registry: 'https://registry.npmjs.org/',
|
|
},
|
|
registries: {
|
|
'@foo': `http://localhost:${REGISTRY_MOCK_PORT}/`,
|
|
default: 'https://registry.npmjs.org/',
|
|
},
|
|
storeDir,
|
|
userConfig: {},
|
|
}, ['add', '@pnpm/this-does-not-exist'])
|
|
} catch (e: any) { // eslint-disable-line
|
|
thrown = true
|
|
expect(e.code).toBe('ERR_PNPM_STORE_ADD_FAILURE')
|
|
expect(e.message).toBe('Some packages have not been added correctly')
|
|
}
|
|
expect(thrown).toBeTruthy()
|
|
})
|