diff --git a/.changeset/twenty-snakes-deny.md b/.changeset/twenty-snakes-deny.md new file mode 100644 index 00000000000..5c6b7d170f4 --- /dev/null +++ b/.changeset/twenty-snakes-deny.md @@ -0,0 +1,6 @@ +--- +"@pnpm/modules-yaml": minor +"pnpm": patch +--- + +Do not create a `node_modules` folder with a `.modules.yaml` file if there are now dependencies inside `node_modules`. diff --git a/__utils__/prepare/package.json b/__utils__/prepare/package.json index d4b4adebc2a..f91c45a966d 100644 --- a/__utils__/prepare/package.json +++ b/__utils__/prepare/package.json @@ -9,7 +9,7 @@ "unique-string": "^2.0.0", "write-json5-file": "^3.1.0", "write-pkg": "4.0.0", - "write-yaml-file": "^4.2.0" + "write-yaml-file": "^5.0.0" }, "devDependencies": { "@pnpm/prepare": "workspace:*", diff --git a/exec/plugin-commands-rebuild/package.json b/exec/plugin-commands-rebuild/package.json index 1154c37b0ea..2f5952b1e0e 100644 --- a/exec/plugin-commands-rebuild/package.json +++ b/exec/plugin-commands-rebuild/package.json @@ -46,7 +46,7 @@ "execa": "npm:safe-execa@0.1.2", "path-exists": "^4.0.0", "sinon": "^15.0.4", - "write-yaml-file": "^4.2.0" + "write-yaml-file": "^5.0.0" }, "dependencies": { "@pnpm/cli-utils": "workspace:*", diff --git a/exec/plugin-commands-script-runners/package.json b/exec/plugin-commands-script-runners/package.json index 0ab4d06d161..1f2980983a0 100644 --- a/exec/plugin-commands-script-runners/package.json +++ b/exec/plugin-commands-script-runners/package.json @@ -41,7 +41,7 @@ "@types/is-windows": "^1.0.0", "@types/ramda": "0.28.20", "is-windows": "^1.0.2", - "write-yaml-file": "^4.2.0" + "write-yaml-file": "^5.0.0" }, "dependencies": { "@pnpm/cli-utils": "workspace:*", diff --git a/lockfile/filter-lockfile/package.json b/lockfile/filter-lockfile/package.json index b371c20faf5..05e4413509e 100644 --- a/lockfile/filter-lockfile/package.json +++ b/lockfile/filter-lockfile/package.json @@ -38,7 +38,7 @@ "@types/ramda": "0.28.20", "detect-libc": "^2.0.1", "tempy": "^1.0.1", - "write-yaml-file": "^4.2.0", + "write-yaml-file": "^5.0.0", "yaml-tag": "1.1.0" }, "dependencies": { diff --git a/lockfile/lockfile-file/package.json b/lockfile/lockfile-file/package.json index 254888c16f6..2d491068c10 100644 --- a/lockfile/lockfile-file/package.json +++ b/lockfile/lockfile-file/package.json @@ -42,7 +42,7 @@ "@types/semver": "7.3.13", "@types/write-file-atomic": "^4.0.0", "tempy": "^1.0.1", - "write-yaml-file": "^4.2.0", + "write-yaml-file": "^5.0.0", "yaml-tag": "1.1.0" }, "dependencies": { diff --git a/lockfile/lockfile-utils/package.json b/lockfile/lockfile-utils/package.json index 390f22653a1..1e7a8f59471 100644 --- a/lockfile/lockfile-utils/package.json +++ b/lockfile/lockfile-utils/package.json @@ -35,7 +35,7 @@ "@types/js-yaml": "^4.0.5", "@types/ramda": "0.28.20", "tempy": "^1.0.1", - "write-yaml-file": "^4.2.0", + "write-yaml-file": "^5.0.0", "yaml-tag": "1.1.0" }, "dependencies": { diff --git a/patching/plugin-commands-patching/package.json b/patching/plugin-commands-patching/package.json index 780dac090a6..7cb53ca4a7f 100644 --- a/patching/plugin-commands-patching/package.json +++ b/patching/plugin-commands-patching/package.json @@ -41,7 +41,7 @@ "@types/normalize-path": "^3.0.0", "@types/ramda": "0.28.20", "@types/semver": "7.3.13", - "write-yaml-file": "^4.2.0" + "write-yaml-file": "^5.0.0" }, "dependencies": { "@pnpm/cli-utils": "workspace:*", diff --git a/pkg-manager/core/package.json b/pkg-manager/core/package.json index 478ec8c4cb6..dc8110f8f62 100644 --- a/pkg-manager/core/package.json +++ b/pkg-manager/core/package.json @@ -101,7 +101,7 @@ "sinon": "^15.0.4", "symlink-dir": "^5.1.1", "write-json-file": "^4.3.0", - "write-yaml-file": "^4.2.0" + "write-yaml-file": "^5.0.0" }, "directories": { "test": "test" diff --git a/pkg-manager/core/src/install/index.ts b/pkg-manager/core/src/install/index.ts index 8fec00f2eca..5507d39b1a9 100644 --- a/pkg-manager/core/src/install/index.ts +++ b/pkg-manager/core/src/install/index.ts @@ -1195,6 +1195,8 @@ const _installInContext: InstallFunction = async (projects, ctx, opts) => { skipped: Array.from(ctx.skipped), storeDir: ctx.storeDir, virtualStoreDir: ctx.virtualStoreDir, + }, { + makeModulesDir: Object.keys(result.currentLockfile.packages ?? {}).length > 0, }) })(), ]) diff --git a/pkg-manager/headless/src/index.ts b/pkg-manager/headless/src/index.ts index 90b959f579d..0d2f61c2e9e 100644 --- a/pkg-manager/headless/src/index.ts +++ b/pkg-manager/headless/src/index.ts @@ -566,6 +566,8 @@ export async function headlessInstall (opts: HeadlessOptions) { skipped: Array.from(skipped), storeDir: opts.storeDir, virtualStoreDir, + }, { + makeModulesDir: Object.keys(filteredLockfile.packages ?? {}).length > 0, }) if (opts.useLockfile) { // We need to write the wanted lockfile as well. diff --git a/pkg-manager/modules-yaml/package.json b/pkg-manager/modules-yaml/package.json index 7351fa6be1a..c3cbb100654 100644 --- a/pkg-manager/modules-yaml/package.json +++ b/pkg-manager/modules-yaml/package.json @@ -35,7 +35,7 @@ "is-windows": "^1.0.2", "ramda": "npm:@pnpm/ramda@0.28.1", "read-yaml-file": "^2.1.0", - "write-yaml-file": "^4.2.0" + "write-yaml-file": "^5.0.0" }, "devDependencies": { "@pnpm/modules-yaml": "workspace:*", diff --git a/pkg-manager/modules-yaml/src/index.ts b/pkg-manager/modules-yaml/src/index.ts index ef778546a8b..bdeeaf686de 100644 --- a/pkg-manager/modules-yaml/src/index.ts +++ b/pkg-manager/modules-yaml/src/index.ts @@ -91,7 +91,10 @@ const YAML_OPTS = { export async function writeModulesManifest ( modulesDir: string, - modules: Modules & { registries: Registries } + modules: Modules & { registries: Registries }, + opts?: { + makeModulesDir?: boolean + } ) { const modulesYamlPath = path.join(modulesDir, MODULES_FILENAME) const saveModules = { ...modules } @@ -114,5 +117,12 @@ export async function writeModulesManifest ( if (!isWindows()) { saveModules.virtualStoreDir = path.relative(modulesDir, saveModules.virtualStoreDir) } - return writeYamlFile(modulesYamlPath, saveModules, YAML_OPTS) + try { + await writeYamlFile(modulesYamlPath, saveModules, { + ...YAML_OPTS, + makeDir: opts?.makeModulesDir ?? false, + }) + } catch (err: any) { // eslint-disable-line + if ((err as NodeJS.ErrnoException).code !== 'ENOENT') throw err + } } diff --git a/pkg-manager/modules-yaml/test/index.ts b/pkg-manager/modules-yaml/test/index.ts index 3dee1d34b37..e9c4a190f0d 100644 --- a/pkg-manager/modules-yaml/test/index.ts +++ b/pkg-manager/modules-yaml/test/index.ts @@ -1,4 +1,5 @@ /// +import fs from 'fs' import path from 'path' import { readModulesManifest, writeModulesManifest } from '@pnpm/modules-yaml' import readYamlFile from 'read-yaml-file' @@ -60,3 +61,55 @@ test('backward compatible read of .modules.yaml created with shamefully-hoist=fa '/body-parser/1.19.0': { 'body-parser': 'private' }, }) }) + +test('readModulesManifest() should not create a node_modules directory if it does not exist', async () => { + const modulesDir = path.join(tempy.directory(), 'node_modules') + const modulesYaml = { + hoistedDependencies: {}, + included: { + dependencies: true, + devDependencies: true, + optionalDependencies: true, + }, + layoutVersion: 1, + packageManager: 'pnpm@2', + pendingBuilds: [], + publicHoistPattern: [], + prunedAt: new Date().toUTCString(), + registries: { + default: 'https://registry.npmjs.org/', + }, + shamefullyHoist: false, + skipped: [], + storeDir: '/.pnpm-store', + virtualStoreDir: path.join(modulesDir, '.pnpm'), + } + await writeModulesManifest(modulesDir, modulesYaml) + expect(fs.existsSync(modulesDir)).toBeFalsy() +}) + +test('readModulesManifest() should create a node_modules directory if makeModuleDir is set to true', async () => { + const modulesDir = path.join(tempy.directory(), 'node_modules') + const modulesYaml = { + hoistedDependencies: {}, + included: { + dependencies: true, + devDependencies: true, + optionalDependencies: true, + }, + layoutVersion: 1, + packageManager: 'pnpm@2', + pendingBuilds: [], + publicHoistPattern: [], + prunedAt: new Date().toUTCString(), + registries: { + default: 'https://registry.npmjs.org/', + }, + shamefullyHoist: false, + skipped: [], + storeDir: '/.pnpm-store', + virtualStoreDir: path.join(modulesDir, '.pnpm'), + } + await writeModulesManifest(modulesDir, modulesYaml, { makeModulesDir: true }) + expect(await readModulesManifest(modulesDir)).toEqual(modulesYaml) +}) diff --git a/pkg-manager/plugin-commands-installation/package.json b/pkg-manager/plugin-commands-installation/package.json index 20aa4277b1d..8191b205e91 100644 --- a/pkg-manager/plugin-commands-installation/package.json +++ b/pkg-manager/plugin-commands-installation/package.json @@ -55,7 +55,7 @@ "tempy": "^1.0.1", "write-json-file": "^4.3.0", "write-pkg": "4.0.0", - "write-yaml-file": "^4.2.0" + "write-yaml-file": "^5.0.0" }, "dependencies": { "@pnpm/cli-utils": "workspace:*", diff --git a/pkg-manifest/exportable-manifest/package.json b/pkg-manifest/exportable-manifest/package.json index e6911e30bfe..04adb8bbaa0 100644 --- a/pkg-manifest/exportable-manifest/package.json +++ b/pkg-manifest/exportable-manifest/package.json @@ -34,7 +34,7 @@ "@types/cross-spawn": "^6.0.2", "@types/ramda": "0.28.20", "cross-spawn": "^7.0.3", - "write-yaml-file": "^4.2.0" + "write-yaml-file": "^5.0.0" }, "dependencies": { "@pnpm/error": "workspace:*", diff --git a/pkg-manifest/write-project-manifest/package.json b/pkg-manifest/write-project-manifest/package.json index 0e63a99a4b6..0c1b632e0c5 100644 --- a/pkg-manifest/write-project-manifest/package.json +++ b/pkg-manifest/write-project-manifest/package.json @@ -33,7 +33,7 @@ "@pnpm/types": "workspace:*", "json5": "^2.2.3", "write-file-atomic": "^5.0.0", - "write-yaml-file": "^4.2.0" + "write-yaml-file": "^5.0.0" }, "devDependencies": { "@pnpm/write-project-manifest": "workspace:*", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c4b5222beef..807109f6e18 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -313,8 +313,8 @@ importers: specifier: 4.0.0 version: 4.0.0 write-yaml-file: - specifier: ^4.2.0 - version: 4.2.0 + specifier: ^5.0.0 + version: 5.0.0 devDependencies: '@pnpm/prepare': specifier: workspace:* @@ -1193,8 +1193,8 @@ importers: specifier: ^15.0.4 version: 15.0.4 write-yaml-file: - specifier: ^4.2.0 - version: 4.2.0 + specifier: ^5.0.0 + version: 5.0.0 exec/plugin-commands-script-runners: dependencies: @@ -1290,8 +1290,8 @@ importers: specifier: ^1.0.2 version: 1.0.2 write-yaml-file: - specifier: ^4.2.0 - version: 4.2.0 + specifier: ^5.0.0 + version: 5.0.0 exec/prepare-package: dependencies: @@ -1844,8 +1844,8 @@ importers: specifier: ^1.0.1 version: 1.0.1 write-yaml-file: - specifier: ^4.2.0 - version: 4.2.0 + specifier: ^5.0.0 + version: 5.0.0 yaml-tag: specifier: 1.1.0 version: 1.1.0 @@ -1929,8 +1929,8 @@ importers: specifier: ^1.0.1 version: 1.0.1 write-yaml-file: - specifier: ^4.2.0 - version: 4.2.0 + specifier: ^5.0.0 + version: 5.0.0 yaml-tag: specifier: 1.1.0 version: 1.1.0 @@ -2019,8 +2019,8 @@ importers: specifier: ^1.0.1 version: 1.0.1 write-yaml-file: - specifier: ^4.2.0 - version: 4.2.0 + specifier: ^5.0.0 + version: 5.0.0 yaml-tag: specifier: 1.1.0 version: 1.1.0 @@ -2664,8 +2664,8 @@ importers: specifier: 7.3.13 version: 7.3.13 write-yaml-file: - specifier: ^4.2.0 - version: 4.2.0 + specifier: ^5.0.0 + version: 5.0.0 pkg-manager/client: dependencies: @@ -2966,8 +2966,8 @@ importers: specifier: ^4.3.0 version: 4.3.0 write-yaml-file: - specifier: ^4.2.0 - version: 4.2.0 + specifier: ^5.0.0 + version: 5.0.0 pkg-manager/direct-dep-linker: dependencies: @@ -3401,8 +3401,8 @@ importers: specifier: ^2.1.0 version: 2.1.0 write-yaml-file: - specifier: ^4.2.0 - version: 4.2.0 + specifier: ^5.0.0 + version: 5.0.0 devDependencies: '@pnpm/modules-yaml': specifier: workspace:* @@ -3768,8 +3768,8 @@ importers: specifier: 4.0.0 version: 4.0.0 write-yaml-file: - specifier: ^4.2.0 - version: 4.2.0 + specifier: ^5.0.0 + version: 5.0.0 pkg-manager/read-projects-context: dependencies: @@ -4001,8 +4001,8 @@ importers: specifier: ^7.0.3 version: 7.0.3 write-yaml-file: - specifier: ^4.2.0 - version: 4.2.0 + specifier: ^5.0.0 + version: 5.0.0 pkg-manifest/manifest-utils: dependencies: @@ -4112,8 +4112,8 @@ importers: specifier: ^5.0.0 version: 5.0.0 write-yaml-file: - specifier: ^4.2.0 - version: 4.2.0 + specifier: ^5.0.0 + version: 5.0.0 devDependencies: '@pnpm/write-project-manifest': specifier: workspace:* @@ -4399,8 +4399,8 @@ importers: specifier: 4.0.0 version: 4.0.0 write-yaml-file: - specifier: ^4.2.0 - version: 4.2.0 + specifier: ^5.0.0 + version: 5.0.0 pnpm/artifacts/exe: optionalDependencies: @@ -4651,8 +4651,8 @@ importers: specifier: ^6.1.13 version: 6.1.13 write-yaml-file: - specifier: ^4.2.0 - version: 4.2.0 + specifier: ^5.0.0 + version: 5.0.0 resolving/default-resolver: dependencies: @@ -5230,8 +5230,8 @@ importers: specifier: ^6.0.1 version: 6.0.1 write-yaml-file: - specifier: ^4.2.0 - version: 4.2.0 + specifier: ^5.0.0 + version: 5.0.0 reviewing/plugin-commands-outdated: dependencies: @@ -8871,7 +8871,7 @@ packages: /@types/byline@4.2.33: resolution: {integrity: sha512-LJYez7wrWcJQQDknqZtrZuExMGP0IXmPl1rOOGDqLbu+H7UNNRfKNuSxCBcQMLH1EfjeWidLedC/hCc5dDfBog==} dependencies: - '@types/node': 18.16.0 + '@types/node': 18.16.2 dev: true /@types/cacheable-request@6.0.3: @@ -9029,6 +9029,10 @@ packages: /@types/node@18.16.0: resolution: {integrity: sha512-BsAaKhB+7X+H4GnSjGhJG9Qi8Tw+inU9nJDwmD5CgOmBLEI6ArdhikpLX7DjbjDRDTbqZzU2LSQNZg8WGPiSZQ==} + /@types/node@18.16.2: + resolution: {integrity: sha512-GQW/JL/5Fz/0I8RpeBG9lKp0+aNcXEaVL71c0D2Q0QHDTFvlYKT7an0onCUXj85anv7b4/WesqdfchLc0jtsCg==} + dev: true + /@types/normalize-package-data@2.4.1: resolution: {integrity: sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==} dev: true @@ -16057,6 +16061,10 @@ packages: /signal-exit@3.0.7: resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} + /signal-exit@4.0.1: + resolution: {integrity: sha512-uUWsN4aOxJAS8KOuf3QMyFtgm1pkb6I+KRZbRF/ghdf5T7sM+B1lLLzPDxswUjkmHyxQAVzEgG35E3NzDM9GVw==} + engines: {node: '>=14'} + /signed-varint@2.0.1: resolution: {integrity: sha512-abgDPg1106vuZZOvw7cFwdCABddfJRz5akcCcchzTbhyhYnsG31y4AlZEgp315T7W3nQq5P4xeOm186ZiPVFzw==} dependencies: @@ -17485,6 +17493,13 @@ packages: imurmurhash: 0.1.4 signal-exit: 3.0.7 + /write-file-atomic@5.0.1: + resolution: {integrity: sha512-+QU2zd6OTD8XWIJCbffaiQeH9U73qIqafo1x6V1snCWYGJf6cVE0cDR4D8xRzcEnfI21IFrUPzPGtcPf8AC+Rw==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} + dependencies: + imurmurhash: 0.1.4 + signal-exit: 4.0.1 + /write-ini-file@4.0.1: resolution: {integrity: sha512-8XPBFS/EqPls2V4vYSc8kPVXjLg2b0GgVVC52w2WEH4sVDXew9rgch60ckXLiTfiYQKmkxezRaRctbGQr7oj5Q==} engines: {node: '>=14.6'} @@ -17550,6 +17565,13 @@ packages: js-yaml: /@zkochan/js-yaml@0.0.6 write-file-atomic: 3.0.3 + /write-yaml-file@5.0.0: + resolution: {integrity: sha512-FdNA4RyH1L43TlvGG8qOMIfcEczwA5ij+zLXUy3Z83CjxhLvcV7/Q/8pk22wnCgYw7PJhtK+7lhO+qqyT4NdvQ==} + engines: {node: '>=16.14'} + dependencies: + js-yaml: /@zkochan/js-yaml@0.0.6 + write-file-atomic: 5.0.1 + /xtend@4.0.2: resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==} engines: {node: '>=0.4'} @@ -17951,5 +17973,5 @@ time: /write-json-file@4.3.0: '2020-02-07T08:54:49.528Z' /write-json5-file@3.1.0: '2021-02-11T22:54:24.439Z' /write-pkg@4.0.0: '2019-04-29T10:37:09.855Z' - /write-yaml-file@4.2.0: '2021-02-11T22:54:29.120Z' + /write-yaml-file@5.0.0: '2023-04-27T22:24:56.969Z' /yaml-tag@1.1.0: '2017-06-06T16:19:00.523Z' diff --git a/pnpm/package.json b/pnpm/package.json index fa742bc26fb..c938f2d78f0 100644 --- a/pnpm/package.json +++ b/pnpm/package.json @@ -108,7 +108,7 @@ "which": "^3.0.0", "write-json-file": "^4.3.0", "write-pkg": "4.0.0", - "write-yaml-file": "^4.2.0" + "write-yaml-file": "^5.0.0" }, "directories": { "test": "test" diff --git a/releasing/plugin-commands-publishing/package.json b/releasing/plugin-commands-publishing/package.json index 61eb0b56bc9..8af863770ab 100644 --- a/releasing/plugin-commands-publishing/package.json +++ b/releasing/plugin-commands-publishing/package.json @@ -53,7 +53,7 @@ "load-json-file": "^6.2.0", "path-exists": "^4.0.0", "tar": "^6.1.13", - "write-yaml-file": "^4.2.0" + "write-yaml-file": "^5.0.0" }, "dependencies": { "@pnpm/cli-utils": "workspace:*", diff --git a/reviewing/plugin-commands-listing/package.json b/reviewing/plugin-commands-listing/package.json index 6c79e06dca4..00c75a28a97 100644 --- a/reviewing/plugin-commands-listing/package.json +++ b/reviewing/plugin-commands-listing/package.json @@ -41,7 +41,7 @@ "@types/ramda": "0.28.20", "execa": "npm:safe-execa@0.1.2", "strip-ansi": "^6.0.1", - "write-yaml-file": "^4.2.0" + "write-yaml-file": "^5.0.0" }, "dependencies": { "@pnpm/cli-utils": "workspace:*",