Skip to content

Commit 1bd1bc1

Browse files
authored
Merge pull request #2 from syJSdev/develop
node 10 support
2 parents db1e456 + 30a7120 commit 1bd1bc1

File tree

6 files changed

+34
-40
lines changed

6 files changed

+34
-40
lines changed

.eslintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"object-curly-newline": ["error", { "multiline": true, "consistent": true }],
77
"semi": ["error", "never"],
88
"object-shorthand": ["off"],
9+
"no-console": ["off"],
10+
"no-await-in-loop": ["off"],
911
"prettier/prettier": ["error"]
1012
},
1113
"env": {

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: node_js
22
node_js:
33
- 12
4+
- 10
45
script:
56
- jest --ci --coverage && codecov

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "rollup-plugin-copy-merge",
33
"description": "Copy & Merge files and folders using Rollup",
4-
"version": "0.1.0",
4+
"version": "0.2.0",
55
"author": "syJSdev <whitedragon226@gmail.com>",
66
"repository": "syJSdev/rollup-plugin-copy-merge",
77
"main": "dist/index.commonjs.js",
@@ -19,7 +19,6 @@
1919
"@types/fs-extra": "^8.0.1",
2020
"colorette": "^1.1.0",
2121
"fs-extra": "^8.1.0",
22-
"fs-jetpack": "^4.1.0",
2322
"globby": "10.0.1",
2423
"is-plain-object": "^3.0.0"
2524
},
@@ -63,8 +62,7 @@
6362
]
6463
},
6564
"engines": {
66-
"npm": ">=6.0.0",
67-
"node": ">=12.0.0"
65+
"node": ">=10.12"
6866
},
6967
"keywords": [
7068
"rollup",

src/index.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
/* eslint-disable no-await-in-loop, no-console, no-restricted-syntax */
21
import path from 'path'
3-
import fsJet from 'fs-jetpack'
2+
import fs from 'fs-extra'
43
import isObject from 'is-plain-object'
54
import globby from 'globby'
65
import { bold, green, yellow } from 'colorette'
76

87
import { ensureTrailingNewLine, stringify } from './utils'
98

109
async function isFile(filePath) {
11-
const fileStats = await fsJet.inspectAsync(filePath)
10+
const fileStats = await fs.stat(filePath)
1211

13-
return fileStats.type === 'file'
12+
return fileStats.isFile()
1413
}
1514

1615
function renameTarget(target, rename) {
@@ -42,7 +41,7 @@ async function generateCopyTarget(src, dest, file, { flatten, rename, transform
4241
}
4342
let contents
4443
if (file || transform) {
45-
contents = await fsJet.readAsync(src)
44+
contents = await fs.readFile(src, 'utf-8')
4645
if (transform) {
4746
contents = await transform(contents)
4847
}
@@ -112,7 +111,8 @@ export default function copy(options = {}) {
112111
const copyTargets = []
113112

114113
if (Array.isArray(targets) && targets.length) {
115-
for (const target of targets) {
114+
for (let index = 0; index < targets.length; index += 1) {
115+
const target = targets[index]
116116
if (!isObject(target)) {
117117
throw new Error(`${stringify(target)} target must be an object`)
118118
}
@@ -147,15 +147,16 @@ export default function copy(options = {}) {
147147
})
148148
)
149149
)
150-
copyTargets.push(...targetsList.flat(1))
150+
targetsList.forEach((ts) => {
151+
copyTargets.push(...ts)
152+
})
151153
} else {
152-
copyTargets.push(
153-
...(await generateCopyTargets(matchedPaths, dest, file, {
154-
flatten,
155-
rename,
156-
transform
157-
}))
158-
)
154+
const ts = await generateCopyTargets(matchedPaths, dest, file, {
155+
flatten,
156+
rename,
157+
transform
158+
})
159+
copyTargets.push(...ts)
159160
}
160161
}
161162
}
@@ -166,15 +167,16 @@ export default function copy(options = {}) {
166167
console.log(green('copied:'))
167168
}
168169

169-
for (const copyTarget of copyTargets) {
170+
for (let index = 0; index < copyTargets.length; index += 1) {
171+
const copyTarget = copyTargets[index]
170172
const { src, contents, transformed, merge, merged, dest } = copyTarget
171173

172-
if (transformed || merged) {
173-
if (merge || transformed) {
174-
await fsJet.writeAsync(dest, contents, restPluginOptions)
175-
}
174+
if (transformed) {
175+
await fs.outputFile(dest, contents)
176+
} else if (merged) {
177+
if (merge) await fs.outputFile(dest, contents)
176178
} else {
177-
await fsJet.copyAsync(src, dest, { overwrite: true, ...restPluginOptions })
179+
await fs.copy(src, dest, restPluginOptions)
178180
}
179181

180182
if (verbose) {

tests/index.test.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,9 @@ describe('Concat', () => {
285285
})
286286

287287
expect(await fs.pathExists('dist/asset-all.js')).toBe(true)
288-
const contents = await fs.readFile('dist/asset-all.js', 'utf8')
289-
const contents1 = await fs.readFile('src/assets/asset-1.js', 'utf8')
290-
const contents2 = await fs.readFile('src/assets/asset-2.js', 'utf8')
288+
const contents = await readFile('dist/asset-all.js')
289+
const contents1 = await readFile('src/assets/asset-1.js')
290+
const contents2 = await readFile('src/assets/asset-2.js')
291291
expect(contents === ensureTrailingNewLine(contents1).concat(contents2)).toBe(true)
292292
})
293293

@@ -297,9 +297,9 @@ describe('Concat', () => {
297297
})
298298

299299
expect(await fs.pathExists('dist/css-all.css')).toBe(true)
300-
const contents = await fs.readFile('dist/css-all.css', 'utf8')
301-
const contents1 = await fs.readFile('src/assets/css/css-1.css', 'utf8')
302-
const contents2 = await fs.readFile('src/assets/css/css-2.css', 'utf8')
300+
const contents = await readFile('dist/css-all.css')
301+
const contents1 = await readFile('src/assets/css/css-1.css')
302+
const contents2 = await readFile('src/assets/css/css-2.css')
303303
expect(contents === ensureTrailingNewLine(contents1).concat(contents2)).toBe(true)
304304
})
305305

@@ -313,7 +313,6 @@ describe('Concat', () => {
313313
})
314314

315315
describe('Options', () => {
316-
/* eslint-disable no-console */
317316
test('Verbose, copy files', async () => {
318317
console.log = jest.fn()
319318

yarn.lock

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,14 +2470,6 @@ fs-extra@^8.1.0:
24702470
jsonfile "^4.0.0"
24712471
universalify "^0.1.0"
24722472

2473-
fs-jetpack@^4.1.0:
2474-
version "4.1.0"
2475-
resolved "https://registry.yarnpkg.com/fs-jetpack/-/fs-jetpack-4.1.0.tgz#d693fcffd3cedbd8829226967866b9e89f290f0f"
2476-
integrity sha512-h4nHLIcCaxnXfUWhwP+mLnar03R2DBlqicNvKJG44TJob8RV6GB8EKNwJgSaBeDAfqWhqq01y+Ao96vRwpXlPw==
2477-
dependencies:
2478-
minimatch "^3.0.2"
2479-
rimraf "^2.6.3"
2480-
24812473
fs.realpath@^1.0.0:
24822474
version "1.0.0"
24832475
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@@ -3823,7 +3815,7 @@ mimic-fn@^2.1.0:
38233815
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b"
38243816
integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==
38253817

3826-
minimatch@^3.0.2, minimatch@^3.0.4:
3818+
minimatch@^3.0.4:
38273819
version "3.0.4"
38283820
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
38293821
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==

0 commit comments

Comments
 (0)