Skip to content

Commit 428e138

Browse files
committed
Fix issue where fs-extra was not found
1 parent b91ce7d commit 428e138

File tree

13 files changed

+145
-53
lines changed

13 files changed

+145
-53
lines changed
Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,53 @@
1-
const fs = require('fs-extra')
1+
/* eslint-disable */
2+
const fs = require('fs').promises
23
const path = require('path')
34

4-
function copyDirectory() {
5+
async function copyDirectory() {
56
const sourceDir = path.resolve(__dirname, './extensions')
67
const destinationDir = path.resolve(__dirname, './dist/extensions')
7-
// Check if the source directory exists
8-
if (!fs.existsSync(sourceDir)) {
9-
console.error(`Source directory '${sourceDir}' not found.`)
10-
return
8+
9+
try {
10+
try {
11+
await fs.access(sourceDir)
12+
} catch (error) {
13+
console.error(`Source directory '${sourceDir}' not found.`)
14+
return
15+
}
16+
17+
// Create the destination directory if it doesn't exist
18+
try {
19+
await fs.mkdir(destinationDir, {recursive: true})
20+
} catch (err) {
21+
// Ignore the error if the directory already exists
22+
if (err.code !== 'EEXIST') throw err
23+
}
24+
25+
// Copy the contents of the source directory to the destination directory
26+
await copyRecursive(sourceDir, destinationDir)
27+
28+
console.log(`Copied '${sourceDir}' to '${destinationDir}'.`)
29+
} catch (err) {
30+
console.error('An error occurred:', err)
1131
}
32+
}
1233

13-
// Create the destination directory if it doesn't exist
14-
fs.ensureDirSync(destinationDir)
34+
async function copyRecursive(src, dest) {
35+
const entries = await fs.readdir(src, {withFileTypes: true})
36+
await fs.mkdir(dest, {recursive: true}).catch((err) => {
37+
// Handle errors other than "directory already exists"
38+
if (err.code !== 'EEXIST') throw err
39+
})
1540

16-
// Copy the contents of the source directory to the destination directory
17-
fs.copySync(sourceDir, destinationDir, {overwrite: true})
41+
for (const entry of entries) {
42+
const srcPath = path.join(src, entry.name)
43+
const destPath = path.join(dest, entry.name)
1844

19-
console.log(`Copied '${sourceDir}' to '${destinationDir}'.`)
45+
if (entry.isDirectory()) {
46+
await copyRecursive(srcPath, destPath)
47+
} else {
48+
await fs.copyFile(srcPath, destPath)
49+
}
50+
}
2051
}
2152

22-
copyDirectory()
53+
copyDirectory().catch(console.error)

packages/run-chrome-extension/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"node": ">=18"
99
},
1010
"name": "webpack-run-chrome-extension",
11-
"version": "1.0.4",
11+
"version": "1.0.5",
1212
"description": "Run your extension on Google Chrome with auto-reload support",
1313
"main": "./dist/module.js",
1414
"types": "./dist/module.d.ts",
@@ -49,7 +49,6 @@
4949
"browser-extension-manifest-fields": "*",
5050
"chrome-location": "^1.2.1",
5151
"content-security-policy-parser": "^0.4.1",
52-
"fs-extra": "^11.2.0",
5352
"loader-utils": "^3.2.1",
5453
"prefers-yarn": "^1.0.1",
5554
"progress": "^2.0.3",
@@ -58,7 +57,6 @@
5857
"ws": "^8.16.0"
5958
},
6059
"devDependencies": {
61-
"@types/fs-extra": "^11.0.4",
6260
"@types/loader-utils": "^2.0.6",
6361
"copy-webpack-plugin": "^12.0.2",
6462
"css-loader": "^6.9.1",

packages/run-chrome-extension/steps/RunChromePlugin/chrome/createUserDataDir.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Released under MIT license.
44

55
import path from 'path'
6-
import fs from 'fs-extra'
6+
import fs from 'fs'
77
import addProgressBar from '../../../helpers/addProgressBar'
88
import masterPreferences from './masterPreferences'
99

@@ -24,7 +24,9 @@ export default function createUserDataDir(
2424
addProgressBar('👤 Creating user data directory...', () => {
2525
const outputPath = path.resolve(__dirname, 'run-chrome-data-dir')
2626
const preferences = path.join(outputPath, 'Default')
27-
fs.ensureDirSync(preferences)
27+
28+
// Ensure directory exists
29+
fs.mkdirSync(preferences, {recursive: true})
2830

2931
const preferencesPath = path.join(preferences, 'Preferences')
3032

packages/run-chrome-extension/steps/RunChromePlugin/chrome/isFirstRun.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'path'
2-
import fs from 'fs-extra'
2+
import fs from 'fs'
33

44
export default function isFirstRun() {
55
return !fs.existsSync(path.resolve(__dirname, 'run-chrome-data-dir'))
Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,53 @@
1-
const fs = require('fs-extra')
1+
/* eslint-disable */
2+
const fs = require('fs').promises
23
const path = require('path')
34

4-
function copyDirectory() {
5+
async function copyDirectory() {
56
const sourceDir = path.resolve(__dirname, './extensions')
67
const destinationDir = path.resolve(__dirname, './dist/extensions')
7-
// Check if the source directory exists
8-
if (!fs.existsSync(sourceDir)) {
9-
console.error(`Source directory '${sourceDir}' not found.`)
10-
return
8+
9+
try {
10+
try {
11+
await fs.access(sourceDir)
12+
} catch (error) {
13+
console.error(`Source directory '${sourceDir}' not found.`)
14+
return
15+
}
16+
17+
// Create the destination directory if it doesn't exist
18+
try {
19+
await fs.mkdir(destinationDir, {recursive: true})
20+
} catch (err) {
21+
// Ignore the error if the directory already exists
22+
if (err.code !== 'EEXIST') throw err
23+
}
24+
25+
// Copy the contents of the source directory to the destination directory
26+
await copyRecursive(sourceDir, destinationDir)
27+
28+
console.log(`Copied '${sourceDir}' to '${destinationDir}'.`)
29+
} catch (err) {
30+
console.error('An error occurred:', err)
1131
}
32+
}
1233

13-
// Create the destination directory if it doesn't exist
14-
fs.ensureDirSync(destinationDir)
34+
async function copyRecursive(src, dest) {
35+
const entries = await fs.readdir(src, {withFileTypes: true})
36+
await fs.mkdir(dest, {recursive: true}).catch((err) => {
37+
// Handle errors other than "directory already exists"
38+
if (err.code !== 'EEXIST') throw err
39+
})
1540

16-
// Copy the contents of the source directory to the destination directory
17-
fs.copySync(sourceDir, destinationDir, {overwrite: true})
41+
for (const entry of entries) {
42+
const srcPath = path.join(src, entry.name)
43+
const destPath = path.join(dest, entry.name)
1844

19-
console.log(`Copied '${sourceDir}' to '${destinationDir}'.`)
45+
if (entry.isDirectory()) {
46+
await copyRecursive(srcPath, destPath)
47+
} else {
48+
await fs.copyFile(srcPath, destPath)
49+
}
50+
}
2051
}
2152

2253
copyDirectory()

packages/run-edge-extension/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"node": ">=18"
99
},
1010
"name": "webpack-run-edge-extension",
11-
"version": "1.0.3",
11+
"version": "1.0.4",
1212
"description": "Run your extension on Microsoft Edge with auto-reload support",
1313
"main": "./dist/module.js",
1414
"types": "./dist/module.d.ts",
@@ -49,7 +49,6 @@
4949
"browser-extension-manifest-fields": "*",
5050
"content-security-policy-parser": "^0.4.1",
5151
"edge-location": "^1.0.0",
52-
"fs-extra": "^11.2.0",
5352
"loader-utils": "^3.2.1",
5453
"prefers-yarn": "^1.0.1",
5554
"progress": "^2.0.3",
@@ -58,7 +57,6 @@
5857
"ws": "^8.16.0"
5958
},
6059
"devDependencies": {
61-
"@types/fs-extra": "^11.0.4",
6260
"@types/loader-utils": "^2.0.6",
6361
"copy-webpack-plugin": "^12.0.2",
6462
"css-loader": "^6.9.1",

packages/run-edge-extension/steps/RunEdgePlugin/edge/createUserDataDir.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Released under MIT license.
44

55
import path from 'path'
6-
import fs from 'fs-extra'
6+
import fs from 'fs'
77
import addProgressBar from '../../../helpers/addProgressBar'
88
import masterPreferences from './masterPreferences'
99

@@ -24,7 +24,9 @@ export default function createUserDataDir(
2424
addProgressBar('👤 Creating user data directory...', () => {
2525
const outputPath = path.resolve(__dirname, 'run-edge-data-dir')
2626
const preferences = path.join(outputPath, 'Default')
27-
fs.ensureDirSync(preferences)
27+
28+
// Ensure directory exists
29+
fs.mkdirSync(preferences, {recursive: true})
2830

2931
const preferencesPath = path.join(preferences, 'Preferences')
3032

packages/run-edge-extension/steps/RunEdgePlugin/edge/isFirstRun.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'path'
2-
import fs from 'fs-extra'
2+
import fs from 'fs'
33

44
export default function isFirstRun() {
55
return !fs.existsSync(path.resolve(__dirname, 'run-edge-data-dir'))

programs/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"node": ">=18"
99
},
1010
"name": "extension-create",
11-
"version": "1.0.6",
11+
"version": "1.0.7",
1212
"description": "Create cross-browser extensions with no build configuration.",
1313
"main": "./dist/cli.js",
1414
"types": "./dist/cli.d.ts",

programs/create/copyTemplates.js

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,53 @@
1-
const fs = require('fs-extra')
1+
/* eslint-disable */
2+
const fs = require('fs').promises
23
const path = require('path')
34

4-
function copyDirectory() {
5+
async function copyDirectory() {
56
const sourceDir = path.resolve(__dirname, './templates')
67
const destinationDir = path.resolve(__dirname, './dist/templates')
7-
// Check if the source directory exists
8-
if (!fs.existsSync(sourceDir)) {
9-
console.error(`Source directory '${sourceDir}' not found.`)
10-
return
8+
9+
try {
10+
try {
11+
await fs.access(sourceDir)
12+
} catch (error) {
13+
console.error(`Source directory '${sourceDir}' not found.`)
14+
return
15+
}
16+
17+
// Create the destination directory if it doesn't exist
18+
try {
19+
await fs.mkdir(destinationDir, {recursive: true})
20+
} catch (err) {
21+
// Ignore the error if the directory already exists
22+
if (err.code !== 'EEXIST') throw err
23+
}
24+
25+
// Copy the contents of the source directory to the destination directory
26+
await copyRecursive(sourceDir, destinationDir)
27+
28+
console.log(`Copied '${sourceDir}' to '${destinationDir}'.`)
29+
} catch (err) {
30+
console.error('An error occurred:', err)
1131
}
32+
}
1233

13-
// Create the destination directory if it doesn't exist
14-
fs.ensureDirSync(destinationDir)
34+
async function copyRecursive(src, dest) {
35+
const entries = await fs.readdir(src, {withFileTypes: true})
36+
await fs.mkdir(dest, {recursive: true}).catch((error) => {
37+
// Ignore the error if the directory already exists
38+
if (error.code !== 'EEXIST') throw error
39+
})
1540

16-
// Copy the contents of the source directory to the destination directory
17-
fs.copySync(sourceDir, destinationDir, {overwrite: true})
41+
for (const entry of entries) {
42+
const srcPath = path.join(src, entry.name)
43+
const destPath = path.join(dest, entry.name)
1844

19-
console.log(`Copied '${sourceDir}' to '${destinationDir}'.`)
45+
if (entry.isDirectory()) {
46+
await copyRecursive(srcPath, destPath)
47+
} else {
48+
await fs.copyFile(srcPath, destPath)
49+
}
50+
}
2051
}
2152

2253
copyDirectory()

0 commit comments

Comments
 (0)