diff --git a/.changeset/fuzzy-insects-give.md b/.changeset/fuzzy-insects-give.md new file mode 100644 index 00000000000..db04a9cf348 --- /dev/null +++ b/.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). diff --git a/config/config/src/Config.ts b/config/config/src/Config.ts index aa4e7a07468..f92e3aafef8 100644 --- a/config/config/src/Config.ts +++ b/config/config/src/Config.ts @@ -89,6 +89,7 @@ export interface Config { failedToLoadBuiltInConfig: boolean resolvePeersFromWorkspaceRoot?: boolean useLockfileV6?: boolean + deployAllFiles?: boolean // proxy httpProxy?: string diff --git a/config/config/src/index.ts b/config/config/src/index.ts index 1e7def6f975..8c377865770 100644 --- a/config/config/src/index.ts +++ b/config/config/src/index.ts @@ -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, @@ -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, diff --git a/exec/plugin-commands-rebuild/src/implementation/extendRebuildOptions.ts b/exec/plugin-commands-rebuild/src/implementation/extendRebuildOptions.ts index 8781b385d0f..88d872c231d 100644 --- a/exec/plugin-commands-rebuild/src/implementation/extendRebuildOptions.ts +++ b/exec/plugin-commands-rebuild/src/implementation/extendRebuildOptions.ts @@ -39,6 +39,7 @@ export interface StrictRebuildOptions { unsafePerm: boolean pending: boolean shamefullyHoist: boolean + deployAllFiles: boolean } export type RebuildOptions = Partial & diff --git a/exec/plugin-commands-rebuild/test/utils/index.ts b/exec/plugin-commands-rebuild/test/utils/index.ts index e8200e19f43..d05e3817b5e 100644 --- a/exec/plugin-commands-rebuild/test/utils/index.ts +++ b/exec/plugin-commands-rebuild/test/utils/index.ts @@ -11,6 +11,7 @@ export const DEFAULT_OPTS = { cacheDir: '../cache', cert: undefined, cliOptions: {}, + deployAllFiles: false, fetchRetries: 2, fetchRetryFactor: 90, fetchRetryMaxtimeout: 90, diff --git a/pkg-manager/client/src/index.ts b/pkg-manager/client/src/index.ts index 48f79d4dadf..e6d2bb6a465 100644 --- a/pkg-manager/client/src/index.ts +++ b/pkg-manager/client/src/index.ts @@ -26,6 +26,7 @@ export type ClientOptions = { userConfig?: Record gitShallowHosts?: string[] resolveSymlinksInInjectedDirs?: boolean + includeOnlyPackageFiles?: boolean } & ResolverFactoryOptions & AgentOptions export interface Client { @@ -56,13 +57,13 @@ type Fetchers = { function createFetchers ( fetchFromRegistry: FetchFromRegistry, getAuthHeader: GetAuthHeader, - opts: Pick, + opts: Pick, 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( diff --git a/pkg-manager/plugin-commands-installation/src/install.ts b/pkg-manager/plugin-commands-installation/src/install.ts index f91403668c7..c41c088f980 100644 --- a/pkg-manager/plugin-commands-installation/src/install.ts +++ b/pkg-manager/plugin-commands-installation/src/install.ts @@ -245,6 +245,7 @@ export type InstallCommandOptions = Pick> export async function handler ( diff --git a/pkg-manager/plugin-commands-installation/src/installDeps.ts b/pkg-manager/plugin-commands-installation/src/installDeps.ts index 8af909ec9bb..581d6c987c6 100644 --- a/pkg-manager/plugin-commands-installation/src/installDeps.ts +++ b/pkg-manager/plugin-commands-installation/src/installDeps.ts @@ -92,6 +92,7 @@ export type InstallDepsOptions = Pick> export async function installDeps ( diff --git a/pkg-manager/plugin-commands-installation/test/add.ts b/pkg-manager/plugin-commands-installation/test/add.ts index d66fe50c8fe..3444bb12b82 100644 --- a/pkg-manager/plugin-commands-installation/test/add.ts +++ b/pkg-manager/plugin-commands-installation/test/add.ts @@ -18,6 +18,7 @@ const DEFAULT_OPTIONS = { cacheDir: path.join(tmp, 'cache'), extraEnv: {}, cliOptions: {}, + deployAllFiles: false, include: { dependencies: true, devDependencies: true, diff --git a/pkg-manager/plugin-commands-installation/test/fetch.ts b/pkg-manager/plugin-commands-installation/test/fetch.ts index 4e7698b0495..f423d9824c1 100644 --- a/pkg-manager/plugin-commands-installation/test/fetch.ts +++ b/pkg-manager/plugin-commands-installation/test/fetch.ts @@ -13,6 +13,7 @@ const DEFAULT_OPTIONS = { bail: false, bin: 'node_modules/.bin', cliOptions: {}, + deployAllFiles: false, extraEnv: {}, include: { dependencies: true, diff --git a/pkg-manager/plugin-commands-installation/test/global.ts b/pkg-manager/plugin-commands-installation/test/global.ts index 50d182cb488..10308e3dce4 100644 --- a/pkg-manager/plugin-commands-installation/test/global.ts +++ b/pkg-manager/plugin-commands-installation/test/global.ts @@ -18,6 +18,7 @@ const DEFAULT_OPTIONS = { cacheDir: path.join(tmp, 'cache'), extraEnv: {}, cliOptions: {}, + deployAllFiles: false, include: { dependencies: true, devDependencies: true, diff --git a/pkg-manager/plugin-commands-installation/test/peerDependencies.ts b/pkg-manager/plugin-commands-installation/test/peerDependencies.ts index bd46c176015..194bcd4000a 100644 --- a/pkg-manager/plugin-commands-installation/test/peerDependencies.ts +++ b/pkg-manager/plugin-commands-installation/test/peerDependencies.ts @@ -16,6 +16,7 @@ const DEFAULT_OPTIONS = { cacheDir: path.join(TMP, 'cache'), extraEnv: {}, cliOptions: {}, + deployAllFiles: false, include: { dependencies: true, devDependencies: true, diff --git a/pkg-manager/plugin-commands-installation/test/prune.ts b/pkg-manager/plugin-commands-installation/test/prune.ts index 0c09e1614fc..e16fd5e705e 100644 --- a/pkg-manager/plugin-commands-installation/test/prune.ts +++ b/pkg-manager/plugin-commands-installation/test/prune.ts @@ -15,6 +15,7 @@ const DEFAULT_OPTIONS = { bin: 'node_modules/.bin', extraEnv: {}, cliOptions: {}, + deployAllFiles: false, include: { dependencies: true, devDependencies: true, diff --git a/pkg-manager/plugin-commands-installation/test/update/interactive.ts b/pkg-manager/plugin-commands-installation/test/update/interactive.ts index b2ae0b64e4d..f71146968cd 100644 --- a/pkg-manager/plugin-commands-installation/test/update/interactive.ts +++ b/pkg-manager/plugin-commands-installation/test/update/interactive.ts @@ -27,6 +27,7 @@ const DEFAULT_OPTIONS = { bin: 'node_modules/.bin', extraEnv: {}, cliOptions: {}, + deployAllFiles: false, include: { dependencies: true, devDependencies: true, diff --git a/pkg-manager/plugin-commands-installation/test/utils/index.ts b/pkg-manager/plugin-commands-installation/test/utils/index.ts index b409fb15de1..2ffa712ea49 100644 --- a/pkg-manager/plugin-commands-installation/test/utils/index.ts +++ b/pkg-manager/plugin-commands-installation/test/utils/index.ts @@ -13,6 +13,7 @@ export const DEFAULT_OPTS = { cert: undefined, extraEnv: {}, cliOptions: {}, + deployAllFiles: false, fetchRetries: 2, fetchRetryFactor: 90, fetchRetryMaxtimeout: 90, diff --git a/releasing/plugin-commands-deploy/src/deploy.ts b/releasing/plugin-commands-deploy/src/deploy.ts index 2e85892b88b..1e0755a3eb6 100644 --- a/releasing/plugin-commands-deploy/src/deploy.ts +++ b/releasing/plugin-commands-deploy/src/deploy.ts @@ -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, @@ -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 }) } diff --git a/releasing/plugin-commands-deploy/test/deploy.test.ts b/releasing/plugin-commands-deploy/test/deploy.test.ts index f5593ab2a80..61bb6b5f5d9 100644 --- a/releasing/plugin-commands-deploy/test/deploy.test.ts +++ b/releasing/plugin-commands-deploy/test/deploy.test.ts @@ -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', @@ -32,6 +33,7 @@ test('deploy', async () => { { name: 'project-3', version: '2.0.0', + files: ['index.js'], dependencies: { 'project-3': 'workspace:*', 'is-odd': '1.0.0', @@ -39,8 +41,10 @@ test('deploy', async () => { }, ]) - 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' }]) @@ -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 }) diff --git a/releasing/plugin-commands-deploy/test/utils/index.ts b/releasing/plugin-commands-deploy/test/utils/index.ts index b409fb15de1..2ffa712ea49 100644 --- a/releasing/plugin-commands-deploy/test/utils/index.ts +++ b/releasing/plugin-commands-deploy/test/utils/index.ts @@ -13,6 +13,7 @@ export const DEFAULT_OPTS = { cert: undefined, extraEnv: {}, cliOptions: {}, + deployAllFiles: false, fetchRetries: 2, fetchRetryFactor: 90, fetchRetryMaxtimeout: 90, diff --git a/reviewing/plugin-commands-outdated/test/utils/index.ts b/reviewing/plugin-commands-outdated/test/utils/index.ts index d2bc5519c36..c5096b0c2b2 100644 --- a/reviewing/plugin-commands-outdated/test/utils/index.ts +++ b/reviewing/plugin-commands-outdated/test/utils/index.ts @@ -13,6 +13,7 @@ export const DEFAULT_OPTS = { cert: undefined, extraEnv: {}, cliOptions: {}, + deployAllFiles: false, fetchRetries: 2, fetchRetryFactor: 90, fetchRetryMaxtimeout: 90, diff --git a/store/store-connection-manager/src/createNewStoreController.ts b/store/store-connection-manager/src/createNewStoreController.ts index 54735a2bb67..11d4c233af9 100644 --- a/store/store-connection-manager/src/createNewStoreController.ts +++ b/store/store-connection-manager/src/createNewStoreController.ts @@ -43,7 +43,7 @@ export type CreateNewStoreControllerOptions = CreateResolverOptions & Pick & { ignoreFile?: (filename: string) => boolean -} & Partial> & Pick +} & Partial> & Pick export async function createNewStoreController ( opts: CreateNewStoreControllerOptions @@ -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 {