From c35af7ca26837b27e51c69f73159a3c1721d21cb Mon Sep 17 00:00:00 2001 From: Dave Date: Sat, 9 Nov 2024 10:08:43 +0100 Subject: [PATCH 1/4] Update reify.js Resolution attempt for #6412. Unfortunately, resolution of that issue introduces another error; `Tracker "idealTree" already exists`. --- workspaces/arborist/lib/arborist/reify.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/workspaces/arborist/lib/arborist/reify.js b/workspaces/arborist/lib/arborist/reify.js index be920272d48f0..3c01113b7a6f3 100644 --- a/workspaces/arborist/lib/arborist/reify.js +++ b/workspaces/arborist/lib/arborist/reify.js @@ -12,6 +12,7 @@ const hgi = require('hosted-git-info') const rpj = require('read-package-json-fast') const { dirname, resolve, relative, join } = require('node:path') +const { existsSync } = require("node:fs") const { depth: dfwalk } = require('treeverse') const { lstat, @@ -123,10 +124,12 @@ module.exports = cls => class Reifier extends cls { // we do NOT want to set ownership on this folder, especially // recursively, because it can have other side effects to do that // in a project directory. We just want to make it if it's missing. - await mkdir(resolve(this.path), { recursive: true }) + let resolvedPath = resolve(this.path); + if(!existsSync(resolvedPath)) + await mkdir(resolvedPath, { recursive: true }) // do not allow the top-level node_modules to be a symlink - await this.#validateNodeModules(resolve(this.path, 'node_modules')) + await this.#validateNodeModules(resolve(resolvedPath, 'node_modules')) } await this[_loadTrees](options) From d029b47205bc004567016bd2de8a318327f394b0 Mon Sep 17 00:00:00 2001 From: Dave Date: Wed, 20 Nov 2024 22:35:02 +0100 Subject: [PATCH 2/4] Update reify.js Addressed style and syntax issues as per GitHub Workflows feedback. --- workspaces/arborist/lib/arborist/reify.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/workspaces/arborist/lib/arborist/reify.js b/workspaces/arborist/lib/arborist/reify.js index 3c01113b7a6f3..6f1d8c84ea884 100644 --- a/workspaces/arborist/lib/arborist/reify.js +++ b/workspaces/arborist/lib/arborist/reify.js @@ -12,8 +12,8 @@ const hgi = require('hosted-git-info') const rpj = require('read-package-json-fast') const { dirname, resolve, relative, join } = require('node:path') -const { existsSync } = require("node:fs") const { depth: dfwalk } = require('treeverse') +const { existsSync } = require('node:fs') const { lstat, mkdir, @@ -124,9 +124,11 @@ module.exports = cls => class Reifier extends cls { // we do NOT want to set ownership on this folder, especially // recursively, because it can have other side effects to do that // in a project directory. We just want to make it if it's missing. - let resolvedPath = resolve(this.path); - if(!existsSync(resolvedPath)) + const resolvedPath = resolve(this.path) + if (!existsSync(resolvedPath)) + { await mkdir(resolvedPath, { recursive: true }) + } // do not allow the top-level node_modules to be a symlink await this.#validateNodeModules(resolve(resolvedPath, 'node_modules')) From 2240a5bfcb4f07158e4759b34148bed5073a4096 Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 21 Nov 2024 00:00:09 +0100 Subject: [PATCH 3/4] Update reify.js Now using `access` from `node:fs/promises` instead of `existsSync` from `node:fs`. --- workspaces/arborist/lib/arborist/reify.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/workspaces/arborist/lib/arborist/reify.js b/workspaces/arborist/lib/arborist/reify.js index 6f1d8c84ea884..e50e8ddc0524d 100644 --- a/workspaces/arborist/lib/arborist/reify.js +++ b/workspaces/arborist/lib/arborist/reify.js @@ -13,12 +13,12 @@ const rpj = require('read-package-json-fast') const { dirname, resolve, relative, join } = require('node:path') const { depth: dfwalk } = require('treeverse') -const { existsSync } = require('node:fs') const { lstat, mkdir, rm, symlink, + access, } = require('node:fs/promises') const { moveFile } = require('@npmcli/fs') const PackageJson = require('@npmcli/package-json') @@ -125,9 +125,14 @@ module.exports = cls => class Reifier extends cls { // recursively, because it can have other side effects to do that // in a project directory. We just want to make it if it's missing. const resolvedPath = resolve(this.path) - if (!existsSync(resolvedPath)) - { - await mkdir(resolvedPath, { recursive: true }) + try { + await access(resolvedPath) + } catch (accessError) { + if (accessError.code === "ENOENT") { + await mkdir(resolvedPath, { recursive: true }) + } else { + throw accessError + } } // do not allow the top-level node_modules to be a symlink From 4b6da2cce71cc37039c71282559459169c2f372b Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 21 Nov 2024 18:52:20 +0100 Subject: [PATCH 4/4] Update reify.js Now using single-quotes instead of double-quotes. --- workspaces/arborist/lib/arborist/reify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workspaces/arborist/lib/arborist/reify.js b/workspaces/arborist/lib/arborist/reify.js index e50e8ddc0524d..666342cf444b3 100644 --- a/workspaces/arborist/lib/arborist/reify.js +++ b/workspaces/arborist/lib/arborist/reify.js @@ -128,7 +128,7 @@ module.exports = cls => class Reifier extends cls { try { await access(resolvedPath) } catch (accessError) { - if (accessError.code === "ENOENT") { + if (accessError.code === 'ENOENT') { await mkdir(resolvedPath, { recursive: true }) } else { throw accessError