Skip to content

Commit

Permalink
feat!: deploy with local dependencies (#6016)
Browse files Browse the repository at this point in the history
Co-authored-by: Zoltan Kochan <z@kochan.io>

Close #5911
Close #5961
  • Loading branch information
await-ovo committed Feb 19, 2023
1 parent 417c8ac commit 7a0ce1d
Show file tree
Hide file tree
Showing 20 changed files with 47 additions and 8 deletions.
10 changes: 10 additions & 0 deletions .changeset/fuzzy-insects-give.md
@@ -0,0 +1,10 @@
---
"@pnpm/plugin-commands-installation": major
"@pnpm/plugin-commands-deploy": major
"@pnpm/store-connection-manager": major
"@pnpm/client": major
"pnpm": major
---

When there's a `files` field in the `package.json`, only deploy those files that are listed in it.
Use the same logic also when injecting packages. This behavior can be changed by setting the `deploy-all-files` setting to `true` [#5911](https://github.com/pnpm/pnpm/issues/5911).
1 change: 1 addition & 0 deletions config/config/src/Config.ts
Expand Up @@ -89,6 +89,7 @@ export interface Config {
failedToLoadBuiltInConfig: boolean
resolvePeersFromWorkspaceRoot?: boolean
useLockfileV6?: boolean
deployAllFiles?: boolean

// proxy
httpProxy?: string
Expand Down
2 changes: 2 additions & 0 deletions config/config/src/index.ts
Expand Up @@ -39,6 +39,7 @@ export const types = Object.assign({
'merge-git-branch-lockfiles-branch-pattern': Array,
color: ['always', 'auto', 'never'],
'config-dir': String,
'deploy-all-files': Boolean,
dev: [null, true],
dir: String,
'enable-modules-dir': Boolean,
Expand Down Expand Up @@ -183,6 +184,7 @@ export async function getConfig (
'auto-install-peers': true,
bail: true,
color: 'auto',
'deploy-all-files': false,
'enable-modules-dir': true,
'extend-node-path': true,
'fetch-retries': 2,
Expand Down
Expand Up @@ -39,6 +39,7 @@ export interface StrictRebuildOptions {
unsafePerm: boolean
pending: boolean
shamefullyHoist: boolean
deployAllFiles: boolean
}

export type RebuildOptions = Partial<StrictRebuildOptions> &
Expand Down
1 change: 1 addition & 0 deletions exec/plugin-commands-rebuild/test/utils/index.ts
Expand Up @@ -11,6 +11,7 @@ export const DEFAULT_OPTS = {
cacheDir: '../cache',
cert: undefined,
cliOptions: {},
deployAllFiles: false,
fetchRetries: 2,
fetchRetryFactor: 90,
fetchRetryMaxtimeout: 90,
Expand Down
5 changes: 3 additions & 2 deletions pkg-manager/client/src/index.ts
Expand Up @@ -26,6 +26,7 @@ export type ClientOptions = {
userConfig?: Record<string, string>
gitShallowHosts?: string[]
resolveSymlinksInInjectedDirs?: boolean
includeOnlyPackageFiles?: boolean
} & ResolverFactoryOptions & AgentOptions

export interface Client {
Expand Down Expand Up @@ -56,13 +57,13 @@ type Fetchers = {
function createFetchers (
fetchFromRegistry: FetchFromRegistry,
getAuthHeader: GetAuthHeader,
opts: Pick<ClientOptions, 'rawConfig' | 'retry' | 'gitShallowHosts' | 'resolveSymlinksInInjectedDirs' | 'unsafePerm'>,
opts: Pick<ClientOptions, 'rawConfig' | 'retry' | 'gitShallowHosts' | 'resolveSymlinksInInjectedDirs' | 'unsafePerm' | 'includeOnlyPackageFiles'>,
customFetchers?: CustomFetchers
): Fetchers {
const defaultFetchers = {
...createTarballFetcher(fetchFromRegistry, getAuthHeader, opts),
...createGitFetcher(opts),
...createDirectoryFetcher({ resolveSymlinks: opts.resolveSymlinksInInjectedDirs }),
...createDirectoryFetcher({ resolveSymlinks: opts.resolveSymlinksInInjectedDirs, includeOnlyPackageFiles: opts.includeOnlyPackageFiles }),
}

const overwrites = mapValues(
Expand Down
2 changes: 2 additions & 0 deletions pkg-manager/plugin-commands-installation/src/install.ts
Expand Up @@ -245,6 +245,7 @@ export type InstallCommandOptions = Pick<Config,
| 'bail'
| 'bin'
| 'cliOptions'
| 'deployAllFiles'
| 'depth'
| 'dev'
| 'engineStrict'
Expand Down Expand Up @@ -297,6 +298,7 @@ export type InstallCommandOptions = Pick<Config,
dedupe?: boolean
saveLockfile?: boolean
workspace?: boolean
includeOnlyPackageFiles?: boolean
} & Partial<Pick<Config, 'modulesCacheMaxAge' | 'pnpmHomeDir' | 'preferWorkspacePackages'>>

export async function handler (
Expand Down
Expand Up @@ -92,6 +92,7 @@ export type InstallDepsOptions = Pick<Config,
recursive?: boolean
dedupe?: boolean
workspace?: boolean
includeOnlyPackageFiles?: boolean
} & Partial<Pick<Config, 'pnpmHomeDir'>>

export async function installDeps (
Expand Down
1 change: 1 addition & 0 deletions pkg-manager/plugin-commands-installation/test/add.ts
Expand Up @@ -18,6 +18,7 @@ const DEFAULT_OPTIONS = {
cacheDir: path.join(tmp, 'cache'),
extraEnv: {},
cliOptions: {},
deployAllFiles: false,
include: {
dependencies: true,
devDependencies: true,
Expand Down
1 change: 1 addition & 0 deletions pkg-manager/plugin-commands-installation/test/fetch.ts
Expand Up @@ -13,6 +13,7 @@ const DEFAULT_OPTIONS = {
bail: false,
bin: 'node_modules/.bin',
cliOptions: {},
deployAllFiles: false,
extraEnv: {},
include: {
dependencies: true,
Expand Down
1 change: 1 addition & 0 deletions pkg-manager/plugin-commands-installation/test/global.ts
Expand Up @@ -18,6 +18,7 @@ const DEFAULT_OPTIONS = {
cacheDir: path.join(tmp, 'cache'),
extraEnv: {},
cliOptions: {},
deployAllFiles: false,
include: {
dependencies: true,
devDependencies: true,
Expand Down
Expand Up @@ -16,6 +16,7 @@ const DEFAULT_OPTIONS = {
cacheDir: path.join(TMP, 'cache'),
extraEnv: {},
cliOptions: {},
deployAllFiles: false,
include: {
dependencies: true,
devDependencies: true,
Expand Down
1 change: 1 addition & 0 deletions pkg-manager/plugin-commands-installation/test/prune.ts
Expand Up @@ -15,6 +15,7 @@ const DEFAULT_OPTIONS = {
bin: 'node_modules/.bin',
extraEnv: {},
cliOptions: {},
deployAllFiles: false,
include: {
dependencies: true,
devDependencies: true,
Expand Down
Expand Up @@ -27,6 +27,7 @@ const DEFAULT_OPTIONS = {
bin: 'node_modules/.bin',
extraEnv: {},
cliOptions: {},
deployAllFiles: false,
include: {
dependencies: true,
devDependencies: true,
Expand Down
Expand Up @@ -13,6 +13,7 @@ export const DEFAULT_OPTS = {
cert: undefined,
extraEnv: {},
cliOptions: {},
deployAllFiles: false,
fetchRetries: 2,
fetchRetryFactor: 90,
fetchRetryMaxtimeout: 90,
Expand Down
8 changes: 5 additions & 3 deletions releasing/plugin-commands-deploy/src/deploy.ts
Expand Up @@ -74,7 +74,8 @@ export async function handler (
const deployDir = path.isAbsolute(deployDirParam) ? deployDirParam : path.join(opts.dir, deployDirParam)
await rimraf(deployDir)
await fs.promises.mkdir(deployDir, { recursive: true })
await copyProject(deployedDir, deployDir)
const includeOnlyPackageFiles = !opts.deployAllFiles
await copyProject(deployedDir, deployDir, { includeOnlyPackageFiles })
await install.handler({
...opts,
depth: Infinity,
Expand All @@ -95,11 +96,12 @@ export async function handler (
// This is a workaround to prevent frozen install in CI envs.
'frozen-lockfile': false,
},
includeOnlyPackageFiles,
})
}

async function copyProject (src: string, dest: string) {
const { filesIndex } = await fetchFromDir(src, { includeOnlyPackageFiles: true })
async function copyProject (src: string, dest: string, opts: { includeOnlyPackageFiles: boolean }) {
const { filesIndex } = await fetchFromDir(src, opts)
const importPkg = createIndexedPkgImporter('clone-or-copy')
await importPkg(dest, { filesMap: filesIndex, force: true, fromStore: true })
}
12 changes: 10 additions & 2 deletions releasing/plugin-commands-deploy/test/deploy.test.ts
Expand Up @@ -24,6 +24,7 @@ test('deploy', async () => {
{
name: 'project-2',
version: '2.0.0',
files: ['index.js'],
dependencies: {
'project-3': 'workspace:*',
'is-odd': '1.0.0',
Expand All @@ -32,15 +33,18 @@ test('deploy', async () => {
{
name: 'project-3',
version: '2.0.0',
files: ['index.js'],
dependencies: {
'project-3': 'workspace:*',
'is-odd': '1.0.0',
},
},
])

fs.writeFileSync('project-1/test.js', '', 'utf8')
fs.writeFileSync('project-1/index.js', '', 'utf8')
; ['project-1', 'project-2', 'project-3'].forEach(name => {
fs.writeFileSync(`${name}/test.js`, '', 'utf8')
fs.writeFileSync(`${name}/index.js`, '', 'utf8')
})

const { allProjects, selectedProjectsGraph } = await readProjects(process.cwd(), [{ namePattern: 'project-1' }])

Expand All @@ -64,5 +68,9 @@ test('deploy', async () => {
await project.hasNot('is-negative')
expect(fs.existsSync('deploy/index.js')).toBeTruthy()
expect(fs.existsSync('deploy/test.js')).toBeFalsy()
expect(fs.existsSync('deploy/node_modules/.pnpm/file+project-2/node_modules/project-2/index.js')).toBeTruthy()
expect(fs.existsSync('deploy/node_modules/.pnpm/file+project-2/node_modules/project-2/test.js')).toBeFalsy()
expect(fs.existsSync('deploy/node_modules/.pnpm/file+project-3/node_modules/project-3/index.js')).toBeTruthy()
expect(fs.existsSync('deploy/node_modules/.pnpm/file+project-3/node_modules/project-3/test.js')).toBeFalsy()
expect(fs.existsSync('pnpm-lock.yaml')).toBeFalsy() // no changes to the lockfile are written
})
1 change: 1 addition & 0 deletions releasing/plugin-commands-deploy/test/utils/index.ts
Expand Up @@ -13,6 +13,7 @@ export const DEFAULT_OPTS = {
cert: undefined,
extraEnv: {},
cliOptions: {},
deployAllFiles: false,
fetchRetries: 2,
fetchRetryFactor: 90,
fetchRetryMaxtimeout: 90,
Expand Down
1 change: 1 addition & 0 deletions reviewing/plugin-commands-outdated/test/utils/index.ts
Expand Up @@ -13,6 +13,7 @@ export const DEFAULT_OPTS = {
cert: undefined,
extraEnv: {},
cliOptions: {},
deployAllFiles: false,
fetchRetries: 2,
fetchRetryFactor: 90,
fetchRetryMaxtimeout: 90,
Expand Down
Expand Up @@ -43,7 +43,7 @@ export type CreateNewStoreControllerOptions = CreateResolverOptions & Pick<Confi
| 'verifyStoreIntegrity'
> & {
ignoreFile?: (filename: string) => boolean
} & Partial<Pick<Config, 'userConfig'>> & Pick<ClientOptions, 'resolveSymlinksInInjectedDirs'>
} & Partial<Pick<Config, 'userConfig' | 'deployAllFiles'>> & Pick<ClientOptions, 'resolveSymlinksInInjectedDirs'>

export async function createNewStoreController (
opts: CreateNewStoreControllerOptions
Expand Down Expand Up @@ -84,6 +84,7 @@ export async function createNewStoreController (
),
gitShallowHosts: opts.gitShallowHosts,
resolveSymlinksInInjectedDirs: opts.resolveSymlinksInInjectedDirs,
includeOnlyPackageFiles: !opts.deployAllFiles,
})
await fs.mkdir(opts.storeDir, { recursive: true })
return {
Expand Down

0 comments on commit 7a0ce1d

Please sign in to comment.