Skip to content

Commit

Permalink
moving node_modules dir
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Sep 27, 2022
1 parent de7f843 commit d825081
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions test/lib/next-modes/base.ts
Expand Up @@ -169,17 +169,17 @@ export class NextInstance {
// Move files[node_modules] to a temporary folder node_modules_back,
// then copy the modules back to node_modules after installation.
const tempNodeModulesPath = path.join(this.testDir, tempNodeModulesFolder)
const nodeModulesPath = path.join(this.files.fsPath, 'node_modules')
const nodeModulesDir = path.join(this.testDir, 'node_modules')
const nodeModulesStats = await fs.stat(this.files.fsPath)
const hasNodeModulesDir = nodeModulesStats.isDirectory()
if (hasNodeModulesDir) {
// Move node_modules to temp folder
await fs.copy(nodeModulesPath, tempNodeModulesPath)
await fs.move(nodeModulesDir, tempNodeModulesPath)
}
await fs.copy(this.files.fsPath, this.testDir)
if (hasNodeModulesDir) {
// Move node_modules from temp back to origin
await fs.copy(tempNodeModulesPath, nodeModulesPath)
await fs.copy(tempNodeModulesPath, nodeModulesDir)
await fs.remove(tempNodeModulesPath)
}
} else {
Expand All @@ -188,7 +188,10 @@ export class NextInstance {
const item = this.files[filename]
let outputFilename = path.join(this.testDir, filename)
if (filename === 'node_modules') {
nodeModulesFolder = typeof item === 'string' ? item : item.fsPath
nodeModulesFolder = path.join(
this.testDir,
typeof item === 'string' ? item : item.fsPath
)
outputFilename = path.join(this.testDir, tempNodeModulesFolder)
}

Expand All @@ -202,10 +205,10 @@ export class NextInstance {

if (nodeModulesFolder) {
await fs.copy(
path.join(this.testDir, tempNodeModulesFolder),
nodeModulesFolder,
path.join(this.testDir, 'node_modules')
)
await fs.remove(path.join(this.testDir, tempNodeModulesFolder))
await fs.remove(nodeModulesFolder)
}
}

Expand Down

0 comments on commit d825081

Please sign in to comment.