Skip to content

Commit

Permalink
fix(pack-plugin): dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelfimov committed Jul 4, 2024
1 parent e4af7f4 commit 976b9a7
Show file tree
Hide file tree
Showing 8 changed files with 1,825 additions and 107 deletions.
1,770 changes: 1,770 additions & 0 deletions .yarn/releases/yarn.cjs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@ plugins:
pnpEnableEsmLoader: true

yarnPath: yarn/cli/src/cli.dev.mjs
#yarnPath: .yarn/releases/yarn.cjs
11 changes: 4 additions & 7 deletions yarn/pack-utils/src/copy.utils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import type { Workspace } from '@yarnpkg/core'
import type { Cache } from '@yarnpkg/core'
import type { Project } from '@yarnpkg/core'
import type { Report } from '@yarnpkg/core'
import type { Descriptor } from '@yarnpkg/core'
import type { Locator } from '@yarnpkg/core'
import type { PortablePath } from '@yarnpkg/fslib'

import { Workspace } from '@yarnpkg/core'
import { Manifest } from '@yarnpkg/core'
import { structUtils } from '@yarnpkg/core'
import { xfs } from '@yarnpkg/fslib'
import { ppath } from '@yarnpkg/fslib'
import { toFilename } from '@yarnpkg/fslib'

export const copyCacheMarkedFiles = async (
project: Project,
Expand Down Expand Up @@ -52,7 +51,7 @@ export const copyPlugins = async (
destination: PortablePath,
report: Report
): Promise<void> => {
const pluginDir = ppath.join(toFilename('.yarn'), toFilename('plugins'))
const pluginDir = ppath.join('.yarn', 'plugins')

if (await xfs.existsPromise(ppath.join(project.cwd, pluginDir))) {
report.reportInfo(null, pluginDir)
Expand Down Expand Up @@ -136,14 +135,12 @@ export const copyYarnRelease = async (
report: Report
): Promise<void> => {
const src = project.configuration.get('yarnPath')
// @ts-expect-error any
const path = ppath.relative(project.cwd, src)
const path = ppath.relative(project.cwd, src!)
const dest = ppath.join(destination, path)

report.reportInfo(null, path)

// @ts-expect-error any
await xfs.copyPromise(dest, src, {
await xfs.copyPromise(dest, src!, {
overwrite: true,
})
}
1 change: 0 additions & 1 deletion yarn/pack-utils/src/export/ProtocolResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export class ProtocolResolver implements Resolver {
}

supportsLocator(locator: Locator, opts: MinimalResolveOptions) {
// eslint-disable-next-line
if (semver.valid(locator.reference)) return true

if (TAG_REGEXP.test(locator.reference)) return true
Expand Down
3 changes: 2 additions & 1 deletion yarn/pack-utils/src/export/exportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

// @ts-nocheck

import { createGzip } from 'node:zlib'

import { Project } from '@yarnpkg/core'
import { VirtualFetcher } from '@yarnpkg/core'
import { Workspace } from '@yarnpkg/core'
Expand All @@ -16,7 +18,6 @@ import { tgzUtils } from '@yarnpkg/core'
import { ppath } from '@yarnpkg/fslib'
import { xfs } from '@yarnpkg/fslib'
import { packUtils } from '@yarnpkg/plugin-pack'
import { createGzip } from 'zlib'
import tar from 'tar-stream'

import { MultiResolver } from './MultiResolver.js'
Expand Down
2 changes: 1 addition & 1 deletion yarn/pack-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as workspacesUtils from './workspaces.utils.js'
import * as copyUtils from './copy.utils.js'
import * as packUtils from './pack.utils.js'
import * as workspacesUtils from './workspaces.utils.js'

export { workspacesUtils, copyUtils, packUtils }
127 changes: 38 additions & 89 deletions yarn/pack-utils/src/pack.utils.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,27 @@
import { Configuration } from '@yarnpkg/core'
import type { Workspace } from '@yarnpkg/core'
import { Project } from '@yarnpkg/core'
import { Report } from '@yarnpkg/core'
import type { Locator } from '@yarnpkg/core'
import type { PortablePath } from '@yarnpkg/fslib'
import type { Filename } from '@yarnpkg/fslib'

import { Cache } from '@yarnpkg/core'
import { CwdFS } from '@yarnpkg/fslib'
import { structUtils } from '@yarnpkg/core'
import { tgzUtils } from '@yarnpkg/core'
import { toFilename } from '@yarnpkg/fslib'
import { xfs } from '@yarnpkg/fslib'
import { ppath } from '@yarnpkg/fslib'
import { npath } from '@yarnpkg/fslib'
import { packUtils } from '@yarnpkg/plugin-pack'

import { ExportCache } from './export/ExportCache.js'
import { copyRcFile } from './copy.utils.js'
import { copyPlugins } from './copy.utils.js'
import { copyYarnRelease } from './copy.utils.js'
import { genPackTgz } from './export/exportUtils.js'
import { makeFetcher } from './export/exportUtils.js'
import { makeResolver } from './export/exportUtils.js'

export const generateLockfile = async (
project: Project,
destination: PortablePath,
report: Report
): Promise<void> => {
// @ts-expect-error
const filename = toFilename(project.configuration.get('lockfileFilename'))
const dest = ppath.join(destination, filename)

report.reportInfo(null, filename)

await xfs.mkdirpPromise(ppath.dirname(dest))
await xfs.writeFilePromise(dest, project.generateLockfile())
}

export function parseSpec(
spec: string
): { parentLocator: Locator | null; path: PortablePath } | undefined {
const { params, selector } = structUtils.parseRange(spec)

const path = npath.toPortablePath(selector)

const parentLocator =
params && typeof params.locator === 'string' ? structUtils.parseLocator(params.locator) : null

return { parentLocator, path }
}
import type { Workspace } from '@yarnpkg/core'
import type { Report } from '@yarnpkg/core'
import type { PortablePath } from '@yarnpkg/fslib'

import { Configuration } from '@yarnpkg/core'
import { Project } from '@yarnpkg/core'
import { Cache } from '@yarnpkg/core'
import { CwdFS } from '@yarnpkg/fslib'
import { tgzUtils } from '@yarnpkg/core'
import { ppath } from '@yarnpkg/fslib'
import { packUtils } from '@yarnpkg/plugin-pack'

import { ExportCache } from './export/ExportCache.js'
import { genPackTgz } from './export/exportUtils.js'
import { makeFetcher } from './export/exportUtils.js'
import { makeResolver } from './export/exportUtils.js'

export const pack = async (
configuration: Configuration,
project: Project,
workspace: Workspace,
report: Report,
destination: PortablePath
) => {
): Promise<void> => {
const cache = await Cache.find(configuration, { immutable: true })

await project.restoreInstallState()
Expand All @@ -70,63 +33,49 @@ export const pack = async (

const tgz = await genPackTgz(workspace)

// @ts-expect-error any
await tgzUtils.extractArchiveTo(tgz, baseFs, { stripComponents: 1 })

const tmpConfiguration = Configuration.create(destination, destination, configuration.plugins)

tmpConfiguration.values.set('compressionLevel', project.configuration.get('compressionLevel'))
tmpConfiguration.values.set('enableGlobalCache', false)
tmpConfiguration.values.set('enableMirror', false)
tmpConfiguration.values.set('globalFolder', configuration.get('globalFolder'))
tmpConfiguration.values.set('packageExtensions', configuration.get('packageExtensions'))
tmpConfiguration.values.set('pnpEnableEsmLoader', configuration.get('pnpEnableEsmLoader'))
tmpConfiguration.values.set(
`bstatePath`,
ppath.join(destination, `build-state.yml` as Filename)
`cacheFolder`,
ppath.join(destination, `.yarn/packages` as PortablePath)
)
tmpConfiguration.values.set('preferAggregateCacheInfo', true)

await Configuration.updateConfiguration(destination, {
cacheFolder: `.yarn/packages` as PortablePath,
compressionLevel: tmpConfiguration.get(`compressionLevel`),
enableGlobalCache: tmpConfiguration.get(`enableGlobalCache`),
enableNetwork: tmpConfiguration.get(`enableNetwork`),
enableMirror: tmpConfiguration.get(`enableMirror`),
packageExtensions: tmpConfiguration.get(`packageExtensions`),
nodeLinker: project.configuration.get('nodeLinker'),
})

// tmpConfiguration.values.set(`enableNetwork`, false);
// tmpConfiguration.values.set(`enableMirror`, false);

tmpConfiguration.values.set(`compressionLevel`, configuration.get(`compressionLevel`))
tmpConfiguration.values.set(`globalFolder`, configuration.get(`globalFolder`))
tmpConfiguration.values.set(`packageExtensions`, configuration.get(`packageExtensions`))

// @ts-expect-error any
await tmpConfiguration.refreshPackageExtensions()
await tmpConfiguration.getPackageExtensions()

const { project: tmpProject, workspace: tmpWorkspace } = await Project.find(
tmpConfiguration,
destination
)

tmpWorkspace!.manifest.dependencies = workspace.manifest.dependencies
tmpWorkspace!.manifest.peerDependencies = workspace.manifest.peerDependencies
tmpWorkspace!.manifest.resolutions = project.topLevelWorkspace.manifest.resolutions
tmpWorkspace!.manifest.dependenciesMeta = project.topLevelWorkspace.manifest.dependenciesMeta
tmpWorkspace!.manifest.devDependencies.clear()

await tmpProject.install({
// @ts-expect-error any
cache: await ExportCache.find(tmpConfiguration, cache),
fetcher: makeFetcher(project),
resolver: makeResolver(project),
persistProject: true,
report,
persistProject: false,
})

await report.startTimerPromise('Copy RC files', async () => {
await copyRcFile(project, destination, report)
})

await report.startTimerPromise('Copy plugins', async () => {
await copyPlugins(project, destination, report)
})

await report.startTimerPromise('Copy Yarn releases', async () => {
await copyYarnRelease(project, destination, report)
})

await generateLockfile(tmpProject, destination, report)

await xfs.writeJsonPromise(ppath.join(destination, 'package.json' as PortablePath), {
...tmpWorkspace!.manifest.exportTo({}),
devDependencies: {},
})
})
}
17 changes: 9 additions & 8 deletions yarn/pack-utils/src/workspaces.utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Workspace } from '@yarnpkg/core'
import { Project } from '@yarnpkg/core'
import { Manifest } from '@yarnpkg/core'
import { Report } from '@yarnpkg/core'
import { PortablePath } from '@yarnpkg/fslib'
import { ppath } from '@yarnpkg/fslib'
import { xfs } from '@yarnpkg/fslib'
import { packUtils } from '@yarnpkg/plugin-pack'
import type { Workspace } from '@yarnpkg/core'
import type { Project } from '@yarnpkg/core'
import type { PortablePath } from '@yarnpkg/fslib'

import { Manifest } from '@yarnpkg/core'
import { Report } from '@yarnpkg/core'
import { ppath } from '@yarnpkg/fslib'
import { xfs } from '@yarnpkg/fslib'
import { packUtils } from '@yarnpkg/plugin-pack'

export const clearUnusedWorkspaces = (
project: Project,
Expand Down

0 comments on commit 976b9a7

Please sign in to comment.