mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-27 19:41:44 -04:00
## Summary Rename all internal packages so their npm names follow the `@pnpm/<domain>.<leaf>` convention, matching their directory structure. Also rename directories to remove redundancy and improve clarity. ### Bulk rename (94 packages) All `@pnpm/` packages now derive their name from their directory path using dot-separated segments. Exceptions: `packages/`, `__utils__/`, and `pnpm/artifacts/` keep leaf names only. ### Directory renames (removing redundant prefixes) - `cli/cli-meta` → `cli/meta`, `cli/cli-utils` → `cli/utils` - `config/config` → `config/reader`, `config/config-writer` → `config/writer` - `fetching/fetching-types` → `fetching/types` - `lockfile/lockfile-to-pnp` → `lockfile/to-pnp` - `store/store-connection-manager` → `store/connection-manager` - `store/store-controller-types` → `store/controller-types` - `store/store-path` → `store/path` ### Targeted renames (clarity improvements) - `deps/dependency-path` → `deps/path` (`@pnpm/deps.path`) - `deps/calc-dep-state` → `deps/graph-hasher` (`@pnpm/deps.graph-hasher`) - `deps/inspection/dependencies-hierarchy` → `deps/inspection/tree-builder` (`@pnpm/deps.inspection.tree-builder`) - `bins/link-bins` → `bins/linker`, `bins/remove-bins` → `bins/remover`, `bins/package-bins` → `bins/resolver` - `installing/get-context` → `installing/context` - `store/package-store` → `store/controller` - `pkg-manifest/manifest-utils` → `pkg-manifest/utils` ### Manifest reader/writer renames - `workspace/read-project-manifest` → `workspace/project-manifest-reader` (`@pnpm/workspace.project-manifest-reader`) - `workspace/write-project-manifest` → `workspace/project-manifest-writer` (`@pnpm/workspace.project-manifest-writer`) - `workspace/read-manifest` → `workspace/workspace-manifest-reader` (`@pnpm/workspace.workspace-manifest-reader`) - `workspace/manifest-writer` → `workspace/workspace-manifest-writer` (`@pnpm/workspace.workspace-manifest-writer`) ### Workspace package renames - `workspace/find-packages` → `workspace/projects-reader` - `workspace/find-workspace-dir` → `workspace/root-finder` - `workspace/resolve-workspace-range` → `workspace/range-resolver` - `workspace/filter-packages-from-dir` merged into `workspace/filter-workspace-packages` → `workspace/projects-filter` ### Domain moves - `pkg-manifest/read-project-manifest` → `workspace/project-manifest-reader` - `pkg-manifest/write-project-manifest` → `workspace/project-manifest-writer` - `pkg-manifest/exportable-manifest` → `releasing/exportable-manifest` ### Scope - 1206 files changed - Updated: package.json names/deps, TypeScript imports, tsconfig references, changeset files, renovate.json, test fixtures, import ordering
117 lines
3.7 KiB
TypeScript
117 lines
3.7 KiB
TypeScript
import path from 'node:path'
|
|
import { Readable } from 'node:stream'
|
|
|
|
import { jest } from '@jest/globals'
|
|
import type { FetchNodeOptionsToDir as FetchNodeOptions } from '@pnpm/engine.runtime.node.fetcher'
|
|
import { tempDir } from '@pnpm/prepare'
|
|
import { StoreIndex } from '@pnpm/store.index'
|
|
import AdmZip from 'adm-zip'
|
|
import { Response } from 'node-fetch'
|
|
|
|
jest.unstable_mockModule('detect-libc', () => ({
|
|
isNonGlibcLinux: jest.fn(),
|
|
}))
|
|
|
|
const { fetchNode } = await import('@pnpm/engine.runtime.node.fetcher')
|
|
const { isNonGlibcLinux } = await import('detect-libc')
|
|
|
|
// A stable fake hex digest used as placeholder sha256 in mock SHASUMS256.txt files.
|
|
// Any non-zero value works; the tarball content won't match, so integrity will
|
|
// fail — but all URL assertions run before that happens.
|
|
const FAKE_SHA256 = '5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef'
|
|
|
|
const fetchMock = jest.fn(async (url: string) => {
|
|
if (url.endsWith('SHASUMS256.txt')) {
|
|
// Return a minimal SHASUMS file covering the artifacts used in tests.
|
|
return new Response(
|
|
`${FAKE_SHA256} node-v22.0.0-linux-x64-musl.tar.gz\n`
|
|
)
|
|
}
|
|
if (url.endsWith('.zip')) {
|
|
// The Windows code path for pnpm's node bootstrapping expects a subdir
|
|
// within the .zip file.
|
|
const pkgName = path.basename(url, '.zip')
|
|
const zip = new AdmZip()
|
|
zip.addFile(`${pkgName}/dummy-file`, Buffer.from('test'))
|
|
|
|
return new Response(Readable.from(zip.toBuffer()))
|
|
}
|
|
|
|
return new Response(Readable.from(Buffer.alloc(0)))
|
|
})
|
|
|
|
const storeIndexes: StoreIndex[] = []
|
|
afterAll(() => {
|
|
for (const si of storeIndexes) si.close()
|
|
})
|
|
|
|
beforeEach(() => {
|
|
jest.mocked(isNonGlibcLinux).mockReturnValue(Promise.resolve(false))
|
|
fetchMock.mockClear()
|
|
})
|
|
|
|
test.skip('install Node using a custom node mirror', async () => {
|
|
tempDir()
|
|
|
|
const nodeMirrorBaseUrl = 'https://pnpm-node-mirror-test.localhost/download/release/'
|
|
const storeDir = path.resolve('store')
|
|
const storeIndex = new StoreIndex(storeDir)
|
|
storeIndexes.push(storeIndex)
|
|
const opts: FetchNodeOptions = {
|
|
nodeMirrorBaseUrl,
|
|
storeDir,
|
|
storeIndex,
|
|
}
|
|
|
|
await fetchNode(fetchMock, '16.4.0', path.resolve('node'), opts)
|
|
|
|
for (const call of fetchMock.mock.calls) {
|
|
expect(call[0]).toMatch(nodeMirrorBaseUrl)
|
|
}
|
|
})
|
|
|
|
test.skip('install Node using the default node mirror', async () => {
|
|
tempDir()
|
|
|
|
const storeDir = path.resolve('store')
|
|
const storeIndex = new StoreIndex(storeDir)
|
|
storeIndexes.push(storeIndex)
|
|
const opts: FetchNodeOptions = {
|
|
storeDir,
|
|
storeIndex,
|
|
}
|
|
|
|
await fetchNode(fetchMock, '16.4.0', path.resolve('node'), opts)
|
|
|
|
for (const call of fetchMock.mock.calls) {
|
|
expect(call[0]).toMatch('https://nodejs.org/download/release/')
|
|
}
|
|
})
|
|
|
|
|
|
test('auto-detects musl on non-glibc Linux and uses unofficial-builds mirror', async () => {
|
|
jest.mocked(isNonGlibcLinux).mockReturnValue(Promise.resolve(true))
|
|
tempDir()
|
|
|
|
// The function will throw because the downloaded tarball content won't match
|
|
// the fake sha256 we put in the SHASUMS256.txt mock, but all fetch calls are
|
|
// recorded before the integrity check, so we can assert the correct URLs.
|
|
const storeIndex = new StoreIndex(path.resolve('store'))
|
|
storeIndexes.push(storeIndex)
|
|
await expect(
|
|
fetchNode(fetchMock, '22.0.0', path.resolve('node'), {
|
|
storeDir: path.resolve('store'),
|
|
storeIndex,
|
|
platform: 'linux',
|
|
arch: 'x64',
|
|
retry: { retries: 0 },
|
|
})
|
|
).rejects.toThrow()
|
|
|
|
const shasumsUrl = fetchMock.mock.calls[0][0] as string
|
|
expect(shasumsUrl).toContain('unofficial-builds.nodejs.org')
|
|
|
|
const tarballUrl = fetchMock.mock.calls[1][0] as string
|
|
expect(tarballUrl).toContain('unofficial-builds.nodejs.org')
|
|
expect(tarballUrl).toContain('node-v22.0.0-linux-x64-musl.tar.gz')
|
|
}) |