diff --git a/package-lock.json b/package-lock.json index 1c33476fea8..d0e97dca0ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1991,6 +1991,34 @@ "fs-extra": "^8.1.0", "matcher-collection": "^2.0.1", "walk-sync": "^2.0.2" + }, + "dependencies": { + "fs-extra": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", + "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "dev": true, + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, + "jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.6" + } + }, + "universalify": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", + "dev": true + } } }, "flat": { @@ -2032,14 +2060,14 @@ "dev": true }, "fs-extra": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", - "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.0.tgz", + "integrity": "sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==", "dev": true, "requires": { "graceful-fs": "^4.2.0", - "jsonfile": "^4.0.0", - "universalify": "^0.1.0" + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" } }, "fs.realpath": { @@ -2740,12 +2768,13 @@ } }, "jsonfile": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", - "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", "dev": true, "requires": { - "graceful-fs": "^4.1.6" + "graceful-fs": "^4.1.6", + "universalify": "^2.0.0" } }, "levn": { @@ -4634,9 +4663,9 @@ "dev": true }, "universalify": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", - "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", "dev": true }, "uri-js": { diff --git a/package.json b/package.json index 857e8ee89c2..240d4a6cdf5 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,7 @@ "eslint-plugin-prettier": "^4.0.0", "execa": "^5.1.1", "fixturify": "^2.1.1", + "fs-extra": "^10.0.0", "hash.js": "^1.1.7", "husky": "^7.0.4", "is-reference": "^3.0.0", diff --git a/test/cli/index.js b/test/cli/index.js index 5401bf699a0..f0c1de862d4 100644 --- a/test/cli/index.js +++ b/test/cli/index.js @@ -1,6 +1,7 @@ const assert = require('assert'); const { exec } = require('child_process'); const path = require('path'); +const { readFileSync } = require('fs-extra'); const sander = require('sander'); const { normaliseOutput, @@ -109,7 +110,7 @@ runTestSuiteWithSamples( done(err); } } else { - const expected = sander.readFileSync('_expected.js').toString(); + const expected = readFileSync('_expected.js', 'utf8'); try { assert.equal(normaliseOutput(code), normaliseOutput(expected)); done(); diff --git a/test/form/index.js b/test/form/index.js index 928a9cdd641..1054aed4655 100644 --- a/test/form/index.js +++ b/test/form/index.js @@ -1,5 +1,6 @@ const assert = require('assert'); const path = require('path'); +const { readFileSync } = require('fs-extra'); const sander = require('sander'); const rollup = require('../../dist/rollup'); const { normaliseOutput, runTestSuiteWithSamples } = require('../utils.js'); @@ -79,19 +80,19 @@ runTestSuiteWithSamples('form', path.resolve(__dirname, 'samples'), (dir, config async function generateAndTestBundle(bundle, outputOptions, expectedFile, { show }) { await bundle.write(outputOptions); - const actualCode = normaliseOutput(sander.readFileSync(outputOptions.file)); + const actualCode = normaliseOutput(readFileSync(outputOptions.file, 'utf8')); let expectedCode; let actualMap; let expectedMap; try { - expectedCode = normaliseOutput(sander.readFileSync(expectedFile)); + expectedCode = normaliseOutput(readFileSync(expectedFile, 'utf8')); } catch (err) { expectedCode = 'missing file'; } try { - actualMap = JSON.parse(sander.readFileSync(outputOptions.file + '.map').toString()); + actualMap = JSON.parse(readFileSync(outputOptions.file + '.map', 'utf8')); actualMap.sourcesContent = actualMap.sourcesContent ? actualMap.sourcesContent.map(normaliseOutput) : null; @@ -100,7 +101,7 @@ async function generateAndTestBundle(bundle, outputOptions, expectedFile, { show } try { - expectedMap = JSON.parse(sander.readFileSync(expectedFile + '.map').toString()); + expectedMap = JSON.parse(readFileSync(expectedFile + '.map', 'utf8')); expectedMap.sourcesContent = actualMap.sourcesContent ? expectedMap.sourcesContent.map(normaliseOutput) : null; diff --git a/test/watch/index.js b/test/watch/index.js index f7d9124fb52..081be97f222 100644 --- a/test/watch/index.js +++ b/test/watch/index.js @@ -1,5 +1,6 @@ const assert = require('assert'); const path = require('path'); +const { readFileSync } = require('fs-extra'); const sander = require('sander'); const rollup = require('../../dist/rollup'); @@ -1083,9 +1084,7 @@ describe('rollup.watch', () => { 'BUNDLE_END', 'END', () => { - const generated = sander.readFileSync('test/_tmp/output/bundle.js', { - encoding: 'utf-8' - }); + const generated = readFileSync('test/_tmp/output/bundle.js', 'utf8'); assert.ok(/jQuery/.test(generated)); } ]); @@ -1505,7 +1504,7 @@ describe('rollup.watch', () => { plugins: { load() { this.addWatchFile(WATCHED_ID); - return `export default "${sander.readFileSync(WATCHED_ID).toString().trim()}"`; + return `export default "${readFileSync(WATCHED_ID, 'utf8').trim()}"`; } } }); @@ -1562,10 +1561,7 @@ describe('rollup.watch', () => { if (addWatchFile) { this.addWatchFile(WATCHED_ID); } - return `export const value = "${sander - .readFileSync(WATCHED_ID) - .toString() - .trim()}"`; + return `export const value = "${readFileSync(WATCHED_ID, 'utf8').trim()}"`; } } } @@ -1613,7 +1609,7 @@ describe('rollup.watch', () => { transform(code, id) { if (id.endsWith('dep1.js')) { this.addWatchFile(path.resolve('test/_tmp/input/dep2.js')); - const text = sander.readFileSync('test/_tmp/input/dep2.js').toString().trim(); + const text = readFileSync('test/_tmp/input/dep2.js', 'utf8').trim(); return `export default ${JSON.stringify(text)}`; } } @@ -1800,7 +1796,7 @@ describe('rollup.watch', () => { transform() { transformRuns++; this.addWatchFile(WATCHED_ID); - return `export default "${sander.readFileSync(WATCHED_ID).toString().trim()}"`; + return `export default "${readFileSync(WATCHED_ID, 'utf8').trim()}"`; } } });