Skip to content

Commit d6be967

Browse files
committed
Update cleanup() of script and test.
1 parent 6bf076b commit d6be967

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

script/clean.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const trash = require("./trash.js")
99
const rootPath = path.resolve(__dirname, "..")
1010
const nodeModulesPath = path.resolve(rootPath, "node_modules")
1111

12-
const trashPaths = ignorePaths
13-
.filter((thePath) => thePath !== nodeModulesPath)
12+
const keptPaths = [nodeModulesPath]
13+
const trashPaths = ignorePaths.filter(isKept)
1414

1515
function cleanEmptyDirs() {
1616
return Promise
@@ -38,6 +38,10 @@ function isEmpty(dirPath) {
3838
return ! fs.readdirSync(dirPath).length
3939
}
4040

41+
function isKept(thePath) {
42+
return keptPaths.every((dirname) => ! thePath.startsWith(dirname))
43+
}
44+
4145
cleanRepo()
4246
.then(cleanEmptyDirs)
4347
.then(cleanNodeModules)

script/test.js

+20-19
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,11 @@ const isWin = process.platform === "win32"
1616

1717
const rootPath = path.resolve(__dirname, "..")
1818
const testPath = path.resolve(rootPath, "test")
19-
const buildPath = path.resolve(rootPath, "build")
2019
const envPath = path.resolve(testPath, "env")
2120
const esmPath = path.resolve(rootPath, "esm.js")
2221
const indexPath = path.resolve(rootPath, "index.js")
23-
const loaderDirPath = path.resolve(rootPath, "esm")
2422
const mochaPath = path.resolve(rootPath, "node_modules/mocha/bin/_mocha")
2523
const nodePath = path.resolve(envPath, "prefix", isWin ? "node.exe" : "bin/node")
26-
const nodeModulesPath = path.resolve(rootPath, "node_modules")
27-
const vendorPath = path.resolve(rootPath, "src/vendor")
28-
29-
const uglifyOptions = fs.readJSONSync(path.resolve(rootPath, ".uglifyrc"))
30-
31-
const jsPaths = [
32-
esmPath,
33-
indexPath
34-
]
35-
36-
const trashPaths = ignorePaths
37-
.filter((thePath) =>
38-
thePath !== loaderDirPath &&
39-
thePath !== nodeModulesPath &&
40-
! thePath.startsWith(buildPath) &&
41-
! thePath.startsWith(vendorPath)
42-
)
4324

4425
const NODE_ENV = argv.prod ? "production" : "development"
4526
const ESM_ENV = NODE_ENV + "-test"
@@ -50,6 +31,19 @@ const NODE_PATH = [
5031
path.resolve(envPath, "node_path/relative")
5132
].join(path.delimiter)
5233

34+
const jsPaths = [
35+
esmPath,
36+
indexPath
37+
]
38+
39+
const keptPaths = [
40+
path.resolve(rootPath, "build"),
41+
path.resolve(rootPath, "esm"),
42+
path.resolve(rootPath, "node_modules"),
43+
path.resolve(rootPath, "src/vendor"),
44+
path.resolve(rootPath, "test/vendor")
45+
]
46+
5347
const nodeArgs = []
5448

5549
if (process.env.HARMONY) {
@@ -63,6 +57,9 @@ nodeArgs.push(
6357
"tests.js"
6458
)
6559

60+
const trashPaths = ignorePaths.filter(isKept)
61+
const uglifyOptions = fs.readJSONSync(path.resolve(rootPath, ".uglifyrc"))
62+
6663
function cleanJS() {
6764
jsPaths.forEach((filename) => {
6865
const content = fs.readFileSync(filename, "utf8")
@@ -77,6 +74,10 @@ function cleanRepo() {
7774
return Promise.all(trashPaths.map(trash))
7875
}
7976

77+
function isKept(thePath) {
78+
return keptPaths.every((dirname) => ! thePath.startsWith(dirname))
79+
}
80+
8081
function minifyJS(content) {
8182
return uglify(content, uglifyOptions).code
8283
}

0 commit comments

Comments
 (0)