Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: public-hoist-pattern #2631

Merged
merged 18 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/eight-poets-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@pnpm/read-projects-context": major
---

`hoistedDependencies` is returned instead of `hoistedAliases`.

`currentPublicHoistPattern` is returned instead of `shamefullyHoist`.
5 changes: 5 additions & 0 deletions .changeset/few-moose-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pnpm/types": minor
---

Added a new type: HoistedDependencies.
5 changes: 5 additions & 0 deletions .changeset/fluffy-wasps-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pnpm/matcher": patch
---

When no patterns are passed in, create a matcher that always returns `false`.
5 changes: 5 additions & 0 deletions .changeset/fresh-rules-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pnpm/hoist": major
---

Breaking changes in the API.
7 changes: 7 additions & 0 deletions .changeset/nervous-turtles-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@pnpm/modules-cleaner": major
---

Replaced `hoistedAliases` with `hoistedDependencies`.

Added `publicHoistedModulesDir` option.
6 changes: 6 additions & 0 deletions .changeset/red-seas-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pnpm/config": minor
"@pnpm/plugin-commands-installation": minor
---

Added a new setting: `public-hoist-pattern`. This setting can be overwritten by `--[no-]shamefully-hoist`. The default value of `public-hoist-pattern` is `types/*`.
5 changes: 5 additions & 0 deletions .changeset/shy-doors-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"supi": minor
---

`shamefullyHoist` replaced by `publicHoistPattern` and `forcePublicHoistPattern`.
7 changes: 7 additions & 0 deletions .changeset/swift-forks-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@pnpm/headless": major
---

`hoistedAliases` replaced with `hoistedDependencies`.

`shamefullyHoist` replaced with `publicHoistPattern`.
9 changes: 9 additions & 0 deletions .changeset/two-houses-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@pnpm/get-context": major
---

`hoistedAliases` replaced with `hoistedDependencies`.

`shamefullyHoist` replaced with `publicHoistPattern`.

`forceShamefullyHoist` replaced with `forcePublicHoistPattern`.
9 changes: 9 additions & 0 deletions .changeset/warm-plums-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@pnpm/headless": major
"@pnpm/modules-yaml": major
"supi": minor
---

Breaking changes to the `node_modules/.modules.yaml` file:
* `hoistedAliases` replaced with `hoistedDependencies`.
* `shamefullyHoist` replaced with `publicHoistPattern`.
1 change: 1 addition & 0 deletions packages/config/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export interface Config {
pnpmfile: string,
packageImportMethod?: 'auto' | 'hardlink' | 'copy' | 'clone',
hoistPattern?: string[],
publicHoistPattern?: string[],
useStoreServer?: boolean,
useRunningStoreServer?: boolean,
workspaceConcurrency: number,
Expand Down
11 changes: 10 additions & 1 deletion packages/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const types = Object.assign({
'prefer-frozen-shrinkwrap': Boolean,
'prefer-offline': Boolean,
'production': [null, true],
'public-hoist-pattern': Array,
'publish-branch': String,
'reporter': String,
'save-peer': Boolean,
Expand Down Expand Up @@ -146,10 +147,10 @@ export default async (
'link-workspace-packages': true,
'package-lock': npmDefaults['package-lock'],
'pending': false,
'public-hoist-pattern': ['@types/*'],
'registry': npmDefaults.registry,
'save-peer': false,
'save-workspace-protocol': true,
'shamefully-hoist': false,
'shared-workspace-lockfile': true,
'shared-workspace-shrinkwrap': true,
'shrinkwrap': npmDefaults.shrinkwrap,
Expand Down Expand Up @@ -311,6 +312,14 @@ export default async (
if (pnpmConfig['hoist'] === false) {
delete pnpmConfig.hoistPattern
}
switch (pnpmConfig.shamefullyHoist) {
case false:
delete pnpmConfig.publicHoistPattern
break
case true:
pnpmConfig.publicHoistPattern = ['*']
break
}
if (typeof pnpmConfig['color'] === 'boolean') {
switch (pnpmConfig['color']) {
case true:
Expand Down
92 changes: 39 additions & 53 deletions packages/get-context/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import readProjectsContext from '@pnpm/read-projects-context'
import {
DEPENDENCIES_FIELDS,
HoistedDependencies,
ProjectManifest,
ReadPackageHook,
Registries,
Expand All @@ -27,7 +28,7 @@ export interface PnpmContext<T> {
existsCurrentLockfile: boolean,
existsWantedLockfile: boolean,
extraBinPaths: string[],
hoistedAliases: {[depPath: string]: string[]}
hoistedDependencies: HoistedDependencies,
include: IncludedDependencies,
modulesFile: Modules | null,
pendingBuilds: string[],
Expand All @@ -38,9 +39,9 @@ export interface PnpmContext<T> {
rootModulesDir: string,
hoistPattern: string[] | undefined,
hoistedModulesDir: string,
publicHoistPattern: string[] | undefined,
lockfileDir: string,
virtualStoreDir: string,
shamefullyHoist: boolean,
skipped: Set<string>,
storeDir: string,
wantedLockfile: Lockfile,
Expand Down Expand Up @@ -75,8 +76,8 @@ export default async function getContext<T> (
hoistPattern?: string[] | undefined,
forceHoistPattern?: boolean,

shamefullyHoist?: boolean,
forceShamefullyHoist?: boolean,
publicHoistPattern?: string[] | undefined,
forcePublicHoistPattern?: boolean,
}
): Promise<PnpmContext<T>> {
const modulesDir = opts.modulesDir ?? 'node_modules'
Expand All @@ -86,6 +87,7 @@ export default async function getContext<T> (
if (importersContext.modules) {
const { purged } = await validateModules(importersContext.modules, importersContext.projects, {
currentHoistPattern: importersContext.currentHoistPattern,
currentPublicHoistPattern: importersContext.currentPublicHoistPattern,
forceNewModules: opts.forceNewModules === true,
include: opts.include,
lockfileDir: opts.lockfileDir,
Expand All @@ -97,8 +99,8 @@ export default async function getContext<T> (
forceHoistPattern: opts.forceHoistPattern,
hoistPattern: opts.hoistPattern,

forceShamefullyHoist: opts.forceShamefullyHoist,
shamefullyHoist: opts.shamefullyHoist,
forcePublicHoistPattern: opts.forcePublicHoistPattern,
publicHoistPattern: opts.publicHoistPattern,
})
if (purged) {
importersContext = await readProjectsContext(projects, {
Expand Down Expand Up @@ -126,28 +128,26 @@ export default async function getContext<T> (
const extraBinPaths = [
...opts.extraBinPaths || [],
]
const shamefullyHoist = Boolean(typeof importersContext.shamefullyHoist === 'undefined' ? opts.shamefullyHoist : importersContext.shamefullyHoist)
if (opts.hoistPattern && !shamefullyHoist) {
extraBinPaths.unshift(path.join(virtualStoreDir, 'node_modules/.bin'))
const hoistedModulesDir = path.join(virtualStoreDir, 'node_modules')
if (opts.hoistPattern?.length) {
extraBinPaths.unshift(path.join(hoistedModulesDir, '.bin'))
}
const hoistedModulesDir = shamefullyHoist
? importersContext.rootModulesDir : path.join(virtualStoreDir, 'node_modules')
const ctx: PnpmContext<T> = {
extraBinPaths,
hoistedAliases: importersContext.hoistedAliases,
hoistedDependencies: importersContext.hoistedDependencies,
hoistedModulesDir,
hoistPattern: opts.hoistPattern,
hoistPattern: importersContext.currentHoistPattern,
include: opts.include || importersContext.include,
lockfileDir: opts.lockfileDir,
modulesFile: importersContext.modules,
pendingBuilds: importersContext.pendingBuilds,
projects: importersContext.projects,
publicHoistPattern: importersContext.currentPublicHoistPattern,
registries: {
...opts.registries,
...importersContext.registries,
},
rootModulesDir: importersContext.rootModulesDir,
shamefullyHoist,
skipped: importersContext.skipped,
storeDir: opts.storeDir,
virtualStoreDir,
Expand All @@ -174,6 +174,7 @@ async function validateModules (
}>,
opts: {
currentHoistPattern?: string[],
currentPublicHoistPattern?: string[],
forceNewModules: boolean,
include?: IncludedDependencies,
lockfileDir: string,
Expand All @@ -185,44 +186,30 @@ async function validateModules (
hoistPattern?: string[] | undefined,
forceHoistPattern?: boolean,

shamefullyHoist?: boolean | undefined,
forceShamefullyHoist?: boolean,
publicHoistPattern?: string[] | undefined,
forcePublicHoistPattern?: boolean,
}
): Promise<{ purged: boolean }> {
const rootProject = projects.find(({ id }) => id === '.')
if (opts.forceShamefullyHoist && modules.shamefullyHoist !== opts.shamefullyHoist) {
if (opts.forcePublicHoistPattern && !R.equals(modules.publicHoistPattern, opts.publicHoistPattern)) {
if (opts.forceNewModules && rootProject) {
await purgeModulesDirsOfImporter(rootProject)
return { purged: true }
}
if (modules.shamefullyHoist) {
throw new PnpmError(
'SHAMEFULLY_HOIST_WANTED',
'This modules directory was created using the --shamefully-hoist option.'
+ ' You must add that option, or else run "pnpm install" to recreate the modules directory.'
)
}
throw new PnpmError(
'SHAMEFULLY_HOIST_NOT_WANTED',
'This modules directory was created without the --shamefully-hoist option.'
+ ' You must remove that option, or else "pnpm install" to recreate the modules directory.'
'PUBLIC_HOIST_PATTERN_DIFF',
'This modules directory was created using a different public-hoist-pattern value.'
+ ' Run "pnpm install" to recreate the modules directory.'
)
}
let purged = false
if (opts.forceHoistPattern && rootProject) {
try {
if (!R.equals(opts.currentHoistPattern, (opts.hoistPattern || undefined))) {
if (opts.currentHoistPattern) {
throw new PnpmError(
'HOISTING_WANTED',
'This modules directory was created using the --hoist-pattern option.'
+ ' You must add this option, or else add the --force option to recreate the modules directory.'
)
}
throw new PnpmError(
'HOISTING_NOT_WANTED',
'This modules directory was created without the --hoist-pattern option.'
+ ' You must remove that option, or else run "pnpm install" to recreate the modules directory.'
'HOIST_PATTERN_DIFF',
'This modules directory was created using a different hoist-pattern value.'
+ ' Run "pnpm install" to recreate the modules directory.'
)
}
} catch (err) {
Expand Down Expand Up @@ -297,7 +284,7 @@ export interface PnpmSingleContext {
existsCurrentLockfile: boolean,
existsWantedLockfile: boolean,
extraBinPaths: string[],
hoistedAliases: {[depPath: string]: string[]},
hoistedDependencies: HoistedDependencies,
hoistedModulesDir: string,
hoistPattern: string[] | undefined,
manifest: ProjectManifest,
Expand All @@ -307,11 +294,11 @@ export interface PnpmSingleContext {
include: IncludedDependencies,
modulesFile: Modules | null,
pendingBuilds: string[],
publicHoistPattern: string[] | undefined,
registries: Registries,
rootModulesDir: string,
lockfileDir: string,
virtualStoreDir: string,
shamefullyHoist: boolean,
skipped: Set<string>,
storeDir: string,
wantedLockfile: Lockfile,
Expand Down Expand Up @@ -339,20 +326,20 @@ export async function getContextForSingleImporter (
hoistPattern?: string[] | undefined,
forceHoistPattern?: boolean,

shamefullyHoist?: boolean,
forceShamefullyHoist?: boolean,
publicHoistPattern?: string[] | undefined,
forcePublicHoistPattern?: boolean,
},
alreadyPurged: boolean = false
): Promise<PnpmSingleContext> {
const {
currentHoistPattern,
hoistedAliases,
currentPublicHoistPattern,
hoistedDependencies,
projects,
include,
modules,
pendingBuilds,
registries,
shamefullyHoist,
skipped,
rootModulesDir,
} = await readProjectsContext(
Expand All @@ -377,6 +364,7 @@ export async function getContextForSingleImporter (
if (modules && !alreadyPurged) {
const { purged } = await validateModules(modules, projects, {
currentHoistPattern,
currentPublicHoistPattern,
forceNewModules: opts.forceNewModules === true,
include: opts.include,
lockfileDir: opts.lockfileDir,
Expand All @@ -388,8 +376,8 @@ export async function getContextForSingleImporter (
forceHoistPattern: opts.forceHoistPattern,
hoistPattern: opts.hoistPattern,

forceShamefullyHoist: opts.forceShamefullyHoist,
shamefullyHoist: opts.shamefullyHoist,
forcePublicHoistPattern: opts.forcePublicHoistPattern,
publicHoistPattern: opts.publicHoistPattern,
})
if (purged) {
return getContextForSingleImporter(manifest, opts, true)
Expand All @@ -400,17 +388,15 @@ export async function getContextForSingleImporter (
const extraBinPaths = [
...opts.extraBinPaths || [],
]
const sHoist = Boolean(typeof shamefullyHoist === 'undefined' ? opts.shamefullyHoist : shamefullyHoist)
if (opts.hoistPattern && !sHoist) {
extraBinPaths.unshift(path.join(virtualStoreDir, 'node_modules/.bin'))
const hoistedModulesDir = path.join(virtualStoreDir, 'node_modules')
if (opts.hoistPattern?.length) {
extraBinPaths.unshift(path.join(hoistedModulesDir, '.bin'))
}
const hoistedModulesDir = sHoist
? rootModulesDir : path.join(virtualStoreDir, 'node_modules')
const ctx: PnpmSingleContext = {
extraBinPaths,
hoistedAliases,
hoistedDependencies,
hoistedModulesDir,
hoistPattern: opts.hoistPattern,
hoistPattern: currentHoistPattern,
importerId,
include: opts.include || include,
lockfileDir: opts.lockfileDir,
Expand All @@ -419,12 +405,12 @@ export async function getContextForSingleImporter (
modulesFile: modules,
pendingBuilds,
prefix: opts.dir,
publicHoistPattern: currentPublicHoistPattern,
registries: {
...opts.registries,
...registries,
},
rootModulesDir,
shamefullyHoist: sHoist,
skipped,
storeDir,
virtualStoreDir,
Expand Down