refactor: NodeModules options renamed to Modules

This commit is contained in:
Zoltan Kochan
2020-05-09 02:33:54 +00:00
parent b3b201b2aa
commit e3990787a1
20 changed files with 68 additions and 61 deletions

View File

@@ -0,0 +1,7 @@
---
"@pnpm/build-modules": major
"@pnpm/get-context": major
"@pnpm/lifecycle": major
---
Rename NodeModules to Modules in option names.

View File

@@ -25,7 +25,7 @@ export default async (
userAgent: string,
sideEffectsCacheWrite: boolean,
storeController: StoreController,
rootNodeModulesDir: string,
rootModulesDir: string,
},
) => {
const warn = (message: string) => logger.warn({ message, prefix: opts.lockfileDir })
@@ -66,7 +66,7 @@ async function buildDependency (
lockfileDir: string,
optional: boolean,
rawConfig: object,
rootNodeModulesDir: string,
rootModulesDir: string,
sideEffectsCacheWrite: boolean,
storeController: StoreController,
unsafePerm: boolean,
@@ -83,7 +83,7 @@ async function buildDependency (
pkgRoot: depNode.peripheralLocation,
prepare: depNode.prepare,
rawConfig: opts.rawConfig,
rootNodeModulesDir: opts.rootNodeModulesDir,
rootModulesDir: opts.rootModulesDir,
unsafePerm: opts.unsafePerm || false,
})
if (hasSideEffects && opts.sideEffectsCacheWrite) {

View File

@@ -58,7 +58,7 @@ export default async function getContext<T> (
projects: (ProjectOptions & T)[],
opts: {
force: boolean,
forceNewNodeModules?: boolean,
forceNewModules?: boolean,
forceSharedLockfile: boolean,
extraBinPaths: string[],
lockfileDir: string,
@@ -87,9 +87,9 @@ export default async function getContext<T> (
const virtualStoreDir = pathAbsolute(opts.virtualStoreDir ?? path.join(modulesDir, '.pnpm'), opts.lockfileDir)
if (importersContext.modules) {
const { purged } = await validateNodeModules(importersContext.modules, importersContext.projects, {
const { purged } = await validateModules(importersContext.modules, importersContext.projects, {
currentHoistPattern: importersContext.currentHoistPattern,
forceNewNodeModules: opts.forceNewNodeModules === true,
forceNewModules: opts.forceNewModules === true,
include: opts.include,
lockfileDir: opts.lockfileDir,
modulesDir,
@@ -172,7 +172,7 @@ export default async function getContext<T> (
return ctx
}
async function validateNodeModules (
async function validateModules (
modules: Modules,
projects: Array<{
modulesDir: string,
@@ -181,7 +181,7 @@ async function validateNodeModules (
}>,
opts: {
currentHoistPattern?: string[],
forceNewNodeModules: boolean,
forceNewModules: boolean,
include?: IncludedDependencies,
lockfileDir: string,
modulesDir: string,
@@ -201,7 +201,7 @@ async function validateNodeModules (
): Promise<{ purged: boolean }> {
const rootProject = projects.find(({ id }) => id === '.')
if (opts.forceShamefullyHoist && modules.shamefullyHoist !== opts.shamefullyHoist) {
if (opts.forceNewNodeModules && rootProject) {
if (opts.forceNewModules && rootProject) {
await purgeModulesDirsOfImporter(rootProject)
return { purged: true }
}
@@ -219,7 +219,7 @@ async function validateNodeModules (
)
}
if (opts.forceIndependentLeaves && Boolean(modules.independentLeaves) !== opts.independentLeaves) {
if (opts.forceNewNodeModules) {
if (opts.forceNewModules) {
await Promise.all(projects.map(purgeModulesDirsOfImporter))
if (!rootProject) {
await purgeModulesDirsOfImporter({
@@ -260,7 +260,7 @@ async function validateNodeModules (
)
}
} catch (err) {
if (!opts.forceNewNodeModules) throw err
if (!opts.forceNewModules) throw err
await purgeModulesDirsOfImporter(rootProject)
purged = true
}
@@ -283,13 +283,13 @@ async function validateNodeModules (
}
}
} catch (err) {
if (!opts.forceNewNodeModules) throw err
if (!opts.forceNewModules) throw err
await purgeModulesDirsOfImporter(project)
purged = true
}
}))
if (modules.registries && !R.equals(opts.registries, modules.registries)) {
if (opts.forceNewNodeModules) {
if (opts.forceNewModules) {
await Promise.all(projects.map(purgeModulesDirsOfImporter))
return { purged: true }
}
@@ -355,7 +355,7 @@ export async function getContextForSingleImporter (
manifest: ProjectManifest,
opts: {
force: boolean,
forceNewNodeModules?: boolean,
forceNewModules?: boolean,
forceSharedLockfile: boolean,
extraBinPaths: string[],
lockfileDir: string,
@@ -413,9 +413,9 @@ export async function getContextForSingleImporter (
const virtualStoreDir = pathAbsolute(opts.virtualStoreDir ?? 'node_modules/.pnpm', opts.lockfileDir)
if (modules && !alreadyPurged) {
const { purged } = await validateNodeModules(modules, projects, {
const { purged } = await validateModules(modules, projects, {
currentHoistPattern,
forceNewNodeModules: opts.forceNewNodeModules === true,
forceNewModules: opts.forceNewModules === true,
include: opts.include,
lockfileDir: opts.lockfileDir,
modulesDir: opts.modulesDir ?? 'node_modules',

View File

@@ -61,7 +61,7 @@ import pathAbsolute = require('path-absolute')
import R = require('ramda')
import realpathMissing = require('realpath-missing')
const brokenNodeModulesLogger = logger('_broken_node_modules')
const brokenModulesLogger = logger('_broken_node_modules')
export type ReporterFunction = (logObj: LogBase) => void
@@ -319,7 +319,7 @@ export default async (opts: HeadlessOptions) => {
lockfileDir,
optional: opts.include.optionalDependencies,
rawConfig: opts.rawConfig,
rootNodeModulesDir: virtualStoreDir,
rootModulesDir: virtualStoreDir,
sideEffectsCacheWrite: opts.sideEffectsCacheWrite,
storeController: opts.storeController,
unsafePerm: opts.unsafePerm,
@@ -512,7 +512,7 @@ async function lockfileToDepGraph (
return
}
brokenNodeModulesLogger.debug({
brokenModulesLogger.debug({
missing: peripheralLocation,
})
}

View File

@@ -817,8 +817,8 @@ test('installing in a workspace', async (t) => {
projects: [projects[0]],
}))
const rootNodeModules = assertProject(t, workspaceFixture)
const lockfile = await rootNodeModules.readCurrentLockfile()
const rootModules = assertProject(t, workspaceFixture)
const lockfile = await rootModules.readCurrentLockfile()
t.deepEqual(Object.keys(lockfile.packages), [
'/is-negative/1.0.0',
'/is-positive/1.0.0',

View File

@@ -6,11 +6,11 @@ const fixtures = path.join(__dirname, 'fixtures')
const workspaceFixture = path.join(__dirname, 'workspace-fixture')
const workspaceFixture2 = path.join(__dirname, 'workspace-fixture2')
removeNodeModules()
removeModules()
.then(() => console.log('Done'))
.catch(err => console.error(err))
async function removeNodeModules () {
async function removeModules () {
const dirsToRemove = [
...(await fs.readdir(fixtures)).map((dir) => path.join(fixtures, dir)),
...(await fs.readdir(workspaceFixture)).map((dir) => path.join(workspaceFixture, dir)),

View File

@@ -25,7 +25,7 @@ await runLifecycleHook('preinstall', pkg, {
pkgId: 'target-pkg/1.0.0',
pkgRoot: targetPkgRoot,
rawConfig: {},
rootNodeModulesDir: path.resolve('node_modules'),
rootModulesDir: path.resolve('node_modules'),
unsafePerm: true,
})
@@ -34,7 +34,7 @@ await runPostinstallHooks({
pkgId: 'target-pkg/1.0.0',
pkgRoot: targetPkgRoot,
rawConfig: {},
rootNodeModulesDir: path.resolve('node_modules'),
rootModulesDir: path.resolve('node_modules'),
unsafePerm: true,
})
```

View File

@@ -15,7 +15,7 @@ export async function runPostinstallHooks (
pkgRoot: string,
prepare?: boolean,
rawConfig: object,
rootNodeModulesDir: string,
rootModulesDir: string,
unsafePerm: boolean,
},
): Promise<boolean> {

View File

@@ -11,7 +11,7 @@ export type RunLifecycleHookOptions = {
optional?: boolean,
pkgRoot: string,
rawConfig: object,
rootNodeModulesDir: string,
rootModulesDir: string,
stdio?: string,
unsafePerm: boolean,
}
@@ -46,7 +46,7 @@ export default async function runLifecycleHook (
}
return lifecycle(m, stage, opts.pkgRoot, {
config: opts.rawConfig,
dir: opts.rootNodeModulesDir,
dir: opts.rootModulesDir,
extraBinPaths: opts.extraBinPaths || [],
log: {
clearProgress: noop,

View File

@@ -31,7 +31,7 @@ export default async function runLifecycleHooksConcurrently (
extraBinPaths: opts.extraBinPaths,
pkgRoot: rootDir,
rawConfig: opts.rawConfig,
rootNodeModulesDir: modulesDir,
rootModulesDir: modulesDir,
stdio: opts.stdio,
unsafePerm: opts.unsafePerm,
}

View File

@@ -6,7 +6,7 @@ import rimraf = require('rimraf')
import test = require('tape')
const fixtures = path.join(__dirname, 'fixtures')
const rootNodeModulesDir = path.join(__dirname, '..', 'node_modules')
const rootModulesDir = path.join(__dirname, '..', 'node_modules')
test('runLifecycleHook()', async (t) => {
const pkgRoot = path.join(fixtures, 'simple')
@@ -16,7 +16,7 @@ test('runLifecycleHook()', async (t) => {
optional: false,
pkgRoot,
rawConfig: {},
rootNodeModulesDir,
rootModulesDir,
unsafePerm: true,
})
@@ -34,7 +34,7 @@ test('runPostinstallHooks()', async (t) => {
optional: false,
pkgRoot,
rawConfig: {},
rootNodeModulesDir,
rootModulesDir,
unsafePerm: true,
})
@@ -53,7 +53,7 @@ test('runPostinstallHooks() with prepare = true', async (t) => {
pkgRoot,
prepare: true,
rawConfig: {},
rootNodeModulesDir,
rootModulesDir,
unsafePerm: true,
})

View File

@@ -133,7 +133,7 @@ export async function handler (
extraBinPaths: opts.extraBinPaths,
pkgRoot: dir,
rawConfig: opts.rawConfig,
rootNodeModulesDir: await realpathMissing(path.join(dir, 'node_modules')),
rootModulesDir: await realpathMissing(path.join(dir, 'node_modules')),
stdio: 'inherit',
unsafePerm: true, // when running scripts explicitly, assume that they're trusted.
})

View File

@@ -293,7 +293,7 @@ async function _rebuild (
pkgRoot,
prepare: pkgSnapshot.prepare,
rawConfig: opts.rawConfig,
rootNodeModulesDir: ctx.rootModulesDir,
rootModulesDir: ctx.rootModulesDir,
unsafePerm: opts.unsafePerm || false,
})
pkgsThatWereRebuilt.add(relDepPath)

View File

@@ -116,7 +116,7 @@ export async function handler (
extraBinPaths: opts.extraBinPaths,
pkgRoot: dir,
rawConfig: opts.rawConfig,
rootNodeModulesDir: await realpathMissing(path.join(dir, 'node_modules')),
rootModulesDir: await realpathMissing(path.join(dir, 'node_modules')),
stdio: 'inherit',
unsafePerm: true, // when running scripts explicitly, assume that they're trusted.
}

View File

@@ -56,7 +56,7 @@ export default async (
extraBinPaths: opts.extraBinPaths,
pkgRoot: prefix,
rawConfig: opts.rawConfig,
rootNodeModulesDir: await realpathMissing(path.join(prefix, 'node_modules')),
rootModulesDir: await realpathMissing(path.join(prefix, 'node_modules')),
stdio,
unsafePerm: true, // when running scripts explicitly, assume that they're trusted.
}

View File

@@ -26,14 +26,14 @@ It also depends on `@pnpm/logger` version `1`, so install it as well via:
TODO
### `supi.link(linkFromPkgs, linkToNodeModules, [options])`
### `supi.link(linkFromPkgs, linkToModules, [options])`
Create symbolic links from the linked packages to the target package's `node_modules` (and its `node_modules/.bin`).
**Arguments:**
* `linkFromPkgs` - *String[]* - paths to the packages that should be linked.
* `linkToNodeModules` - *String* - path to the dependent package's `node_modules` directory.
* `linkToModules` - *String* - path to the dependent package's `node_modules` directory.
* `options.reporter` - *Function* - A function that listens for logs.
### `supi.linkToGlobal(linkFrom, options)`

View File

@@ -143,7 +143,7 @@ export async function mutateModules (
}
const installsOnly = projects.every((project) => project.mutation === 'install')
opts['forceNewNodeModules'] = installsOnly
opts['forceNewModules'] = installsOnly
const ctx = await getContext(projects, opts)
for (const { manifest, rootDir } of ctx.projects) {
@@ -771,7 +771,7 @@ async function installInContext (
lockfileDir: ctx.lockfileDir,
optional: opts.include.optionalDependencies,
rawConfig: opts.rawConfig,
rootNodeModulesDir: ctx.virtualStoreDir,
rootModulesDir: ctx.virtualStoreDir,
sideEffectsCacheWrite: opts.sideEffectsCacheWrite,
storeController: opts.storeController,
unsafePerm: opts.unsafePerm,

View File

@@ -33,7 +33,7 @@ import resolvePeers, {
} from './resolvePeers'
import updateLockfile from './updateLockfile'
const brokenNodeModulesLogger = logger('_broken_node_modules')
const brokenModulesLogger = logger('_broken_node_modules')
export {
DependenciesGraph,
@@ -454,7 +454,7 @@ async function selectNewFromWantedDeps (
if (await fs.exists(depNode.peripheralLocation)) {
return
}
brokenNodeModulesLogger.debug({
brokenModulesLogger.debug({
missing: depNode.peripheralLocation,
})
}

View File

@@ -430,9 +430,9 @@ test('hoist when updating in one of the workspace projects', async (t) => {
]
await mutateModules(mutatedProjects, await testDefaults({ hoistPattern: '*' }))
const rootNodeModules = assertProject(t, process.cwd())
const rootModules = assertProject(t, process.cwd())
{
const modulesManifest = await rootNodeModules.readModulesManifest()
const modulesManifest = await rootModules.readModulesManifest()
t.deepEqual(modulesManifest?.hoistedAliases, {
[`localhost+${REGISTRY_MOCK_PORT}/dep-of-pkg-with-1-dep/100.0.0`]: ['dep-of-pkg-with-1-dep'],
[`localhost+${REGISTRY_MOCK_PORT}/foo/100.0.0`]: ['foo'],
@@ -447,7 +447,7 @@ test('hoist when updating in one of the workspace projects', async (t) => {
},
], await testDefaults({ hoistPattern: '*', pruneLockfileImporters: false }))
const lockfile = await rootNodeModules.readCurrentLockfile()
const lockfile = await rootModules.readCurrentLockfile()
t.deepEqual(
Object.keys(lockfile.packages),
@@ -460,7 +460,7 @@ test('hoist when updating in one of the workspace projects', async (t) => {
)
{
const modulesManifest = await rootNodeModules.readModulesManifest()
const modulesManifest = await rootModules.readModulesManifest()
t.deepEqual(modulesManifest?.hoistedAliases, {
[`localhost+${REGISTRY_MOCK_PORT}/dep-of-pkg-with-1-dep/100.0.0`]: ['dep-of-pkg-with-1-dep'],
})

View File

@@ -65,9 +65,9 @@ test('install only the dependencies of the specified importer', async (t) => {
await projects['project-1'].has('is-positive')
await projects['project-2'].hasNot('is-negative')
const rootNodeModules = assertProject(t, process.cwd())
await rootNodeModules.has(`.pnpm/localhost+${REGISTRY_MOCK_PORT}/is-positive@1.0.0`)
await rootNodeModules.hasNot(`.pnpm/localhost+${REGISTRY_MOCK_PORT}/is-negative@1.0.0`)
const rootModules = assertProject(t, process.cwd())
await rootModules.has(`.pnpm/localhost+${REGISTRY_MOCK_PORT}/is-positive@1.0.0`)
await rootModules.hasNot(`.pnpm/localhost+${REGISTRY_MOCK_PORT}/is-negative@1.0.0`)
})
test('install only the dependencies of the specified importer. The current lockfile has importers that do not exist anymore', async (t) => {
@@ -138,8 +138,8 @@ test('install only the dependencies of the specified importer. The current lockf
},
], await testDefaults({ hoistPattern: '*' }))
const rootNodeModules = assertProject(t, process.cwd())
const currentLockfile = await rootNodeModules.readCurrentLockfile()
const rootModules = assertProject(t, process.cwd())
const currentLockfile = await rootModules.readCurrentLockfile()
t.ok(currentLockfile.importers['project-3'])
t.ok(currentLockfile.packages['/foobar/100.0.0'])
})
@@ -193,12 +193,12 @@ test('dependencies of other importers are not pruned when installing for a subse
await projects['project-1'].has('is-positive')
await projects['project-2'].has('is-negative')
const rootNodeModules = assertProject(t, process.cwd())
await rootNodeModules.has(`.pnpm/localhost+${REGISTRY_MOCK_PORT}/is-positive@2.0.0`)
await rootNodeModules.hasNot(`.pnpm/localhost+${REGISTRY_MOCK_PORT}/is-positive@1.0.0`)
await rootNodeModules.has(`.pnpm/localhost+${REGISTRY_MOCK_PORT}/is-negative@1.0.0`)
const rootModules = assertProject(t, process.cwd())
await rootModules.has(`.pnpm/localhost+${REGISTRY_MOCK_PORT}/is-positive@2.0.0`)
await rootModules.hasNot(`.pnpm/localhost+${REGISTRY_MOCK_PORT}/is-positive@1.0.0`)
await rootModules.has(`.pnpm/localhost+${REGISTRY_MOCK_PORT}/is-negative@1.0.0`)
const lockfile = await rootNodeModules.readCurrentLockfile()
const lockfile = await rootModules.readCurrentLockfile()
t.deepEqual(Object.keys(lockfile.importers), ['project-1', 'project-2'])
t.deepEqual(Object.keys(lockfile.packages), [
'/is-negative/1.0.0',
@@ -258,10 +258,10 @@ test('dependencies of other importers are not pruned when (headless) installing
await projects['project-1'].has('is-positive')
await projects['project-2'].has('is-negative')
const rootNodeModules = assertProject(t, process.cwd())
await rootNodeModules.has(`.pnpm/localhost+${REGISTRY_MOCK_PORT}/is-positive@2.0.0`)
await rootNodeModules.hasNot(`.pnpm/localhost+${REGISTRY_MOCK_PORT}/is-positive@1.0.0`)
await rootNodeModules.has(`.pnpm/localhost+${REGISTRY_MOCK_PORT}/is-negative@1.0.0`)
const rootModules = assertProject(t, process.cwd())
await rootModules.has(`.pnpm/localhost+${REGISTRY_MOCK_PORT}/is-positive@2.0.0`)
await rootModules.hasNot(`.pnpm/localhost+${REGISTRY_MOCK_PORT}/is-positive@1.0.0`)
await rootModules.has(`.pnpm/localhost+${REGISTRY_MOCK_PORT}/is-negative@1.0.0`)
})
test('adding a new dev dependency to project that uses a shared lockfile', async (t) => {