/
global.ts
73 lines (64 loc) · 2.03 KB
/
global.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { promises as fs } from 'fs'
import path from 'path'
import { add } from '@pnpm/plugin-commands-installation'
import prepare from '@pnpm/prepare'
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
import tempy from 'tempy'
import getNodeExecPath from '../lib/nodeExecPath'
const REGISTRY_URL = `http://localhost:${REGISTRY_MOCK_PORT}`
const tmp = tempy.directory()
const DEFAULT_OPTIONS = {
argv: {
original: [],
},
bail: false,
bin: 'node_modules/.bin',
cacheDir: path.join(tmp, 'cache'),
extraEnv: {},
cliOptions: {},
include: {
dependencies: true,
devDependencies: true,
optionalDependencies: true,
},
lock: true,
pnpmfile: '.pnpmfile.cjs',
rawConfig: { registry: REGISTRY_URL },
rawLocalConfig: { registry: REGISTRY_URL },
registries: {
default: REGISTRY_URL,
},
sort: true,
storeDir: path.join(tmp, 'store'),
userConfig: {},
workspaceConcurrency: 1,
}
test('globally installed package is linked with active version of Node.js', async () => {
const nodeExecPath = await getNodeExecPath()
prepare()
await add.handler({
...DEFAULT_OPTIONS,
dir: process.cwd(),
global: true,
linkWorkspacePackages: false,
pnpmHomeDir: path.dirname(nodeExecPath),
}, ['@pnpm.e2e/hello-world-js-bin'])
const manifest = (await import(path.resolve('package.json')))
expect(
manifest.dependenciesMeta['@pnpm.e2e/hello-world-js-bin']?.node
).toBeTruthy()
const shimContent = await fs.readFile('node_modules/.bin/hello-world-js-bin', 'utf-8')
expect(shimContent).toContain(nodeExecPath)
})
test('globally installed package isn not linked with active version of Node.js if the Node.js executable is not under the pnpm home directory', async () => {
prepare()
await add.handler({
...DEFAULT_OPTIONS,
dir: process.cwd(),
global: true,
linkWorkspacePackages: false,
pnpmHomeDir: path.resolve('pnpm-home'),
}, ['@pnpm.e2e/hello-world-js-bin'])
const manifest = (await import(path.resolve('package.json')))
expect(manifest.dependenciesMeta).toBeFalsy()
})