From e6cb7b312df0180577f9a4859fede9e24cd35d5d Mon Sep 17 00:00:00 2001 From: Eric King Date: Sat, 10 Feb 2024 14:00:53 -0600 Subject: [PATCH] chore(deps): removed `mkdirp` --- package.json | 6 +- pnpm-lock.yaml | 41 +- test/WebpackAssetsManifest-test.js | 1197 ++++++++++++---------------- 3 files changed, 544 insertions(+), 700 deletions(-) diff --git a/package.json b/package.json index fd3208f..7c6b8d9 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "packageManager": "pnpm@8.15.1+sha256.245fe901f8e7fa8782d7f17d32b6a83995e2ae03984cb5b62b8949bfdc27c7b5", "scripts": { "lint": "eslint --fix src test", + "format": "prettier --write .", "typecheck": "tsc --noEmit", "spellcheck": "cspell --no-progress './{.github,src,test}/**/*.{js,json}' './*.{md,js}' './package.json'", "test": "NODE_OPTIONS='--openssl-legacy-provider' nyc mocha --colors", @@ -50,6 +51,7 @@ "name": "Eric King", "url": "http://webdeveric.com/" }, + "prettier": "@webdeveric/prettier-config", "dependencies": { "chalk": "^4.0", "deepmerge": "^4.0", @@ -69,6 +71,7 @@ "@types/tapable": "^2.2.2", "@types/webpack-sources": "^3.2.0", "@webdeveric/eslint-config": "^0.4.0", + "@webdeveric/prettier-config": "^0.2.0", "chai": "^4.3.0", "chai-spies": "^1.0.0", "compression-webpack-plugin": "^7.1.2", @@ -76,15 +79,16 @@ "cspell": "^8.3.2", "css-loader": "^5.2.4", "eslint": "^8.56.0", + "eslint-config-prettier": "^9.1.0", "file-loader": "^6.2.0", "fs-extra": "^9.1.0", "husky": "^9.0.10", "lint-staged": "^15.2.2", "memory-fs": "^0.5.0", "mini-css-extract-plugin": "^1.6.0", - "mkdirp": "^1.0.4", "mocha": "^10.3.0", "nyc": "^15.1.0", + "prettier": "^3.2.5", "rimraf": "^3.0.2", "superagent": "^8.1.0", "typescript": "^5.3.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f1d4cd4..f5c909b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -46,6 +46,9 @@ devDependencies: '@webdeveric/eslint-config': specifier: ^0.4.0 version: 0.4.0(eslint@8.56.0) + '@webdeveric/prettier-config': + specifier: ^0.2.0 + version: 0.2.0(prettier@3.2.5) chai: specifier: ^4.3.0 version: 4.4.1 @@ -67,6 +70,9 @@ devDependencies: eslint: specifier: ^8.56.0 version: 8.56.0 + eslint-config-prettier: + specifier: ^9.1.0 + version: 9.1.0(eslint@8.56.0) file-loader: specifier: ^6.2.0 version: 6.2.0(webpack@5.90.1) @@ -85,15 +91,15 @@ devDependencies: mini-css-extract-plugin: specifier: ^1.6.0 version: 1.6.2(webpack@5.90.1) - mkdirp: - specifier: ^1.0.4 - version: 1.0.4 mocha: specifier: ^10.3.0 version: 10.3.0 nyc: specifier: ^15.1.0 version: 15.1.0 + prettier: + specifier: ^3.2.5 + version: 3.2.5 rimraf: specifier: ^3.0.2 version: 3.0.2 @@ -950,6 +956,14 @@ packages: eslint: 8.56.0 dev: true + /@webdeveric/prettier-config@0.2.0(prettier@3.2.5): + resolution: {integrity: sha512-bcVZEXBts3cn73WWO17xiYpkpvw0+o3CbUViTirv7Pyp9Cju4tkmWBFmAP8K9aygdf0owlXVKH7aaVvErIHSZA==} + peerDependencies: + prettier: '>=2.4.0' + dependencies: + prettier: 3.2.5 + dev: true + /@xtuc/ieee754@1.2.0: resolution: {integrity: sha512-DX8nKgqcGwsc0eJSqYt5lwP4DH5FlHnmuWWBRy7X0NcaGR0ZtuyeESgMwTYVEtxmsNGY+qit4QYT/MIYTOTPeA==} dev: true @@ -2248,6 +2262,15 @@ packages: engines: {node: '>=10'} dev: true + /eslint-config-prettier@9.1.0(eslint@8.56.0): + resolution: {integrity: sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==} + hasBin: true + peerDependencies: + eslint: '>=7.0.0' + dependencies: + eslint: 8.56.0 + dev: true + /eslint-scope@5.1.1: resolution: {integrity: sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==} engines: {node: '>=8.0.0'} @@ -3971,12 +3994,6 @@ packages: minimist: 1.2.8 dev: true - /mkdirp@1.0.4: - resolution: {integrity: sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==} - engines: {node: '>=10'} - hasBin: true - dev: true - /mocha@10.3.0: resolution: {integrity: sha512-uF2XJs+7xSLsrmIvn37i/wnc91nw7XjOQB8ccyx5aEgdnohr7n+rEiZP23WkCYHjilR6+EboEnbq/ZQDz4LSbg==} engines: {node: '>= 14.0.0'} @@ -4545,6 +4562,12 @@ packages: engines: {node: '>= 0.8.0'} dev: true + /prettier@3.2.5: + resolution: {integrity: sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==} + engines: {node: '>=14'} + hasBin: true + dev: true + /process-nextick-args@2.0.1: resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==} dev: true diff --git a/test/WebpackAssetsManifest-test.js b/test/WebpackAssetsManifest-test.js index 1954f93..be5785c 100644 --- a/test/WebpackAssetsManifest-test.js +++ b/test/WebpackAssetsManifest-test.js @@ -3,7 +3,7 @@ const fs = require('fs-extra'); const path = require('path'); const chalk = require('chalk'); -const mkdirp = require('mkdirp'); +const { mkdir } = require('node:fs/promises'); const chai = require('chai'); const spies = require('chai-spies'); const rimraf = require('rimraf'); @@ -21,39 +21,42 @@ chai.use(spies); const _444 = 0o444; const _777 = 0o777; -console.log( chalk`Webpack version: {blueBright.bold %s}`, require('webpack/package.json').version ); -console.log( chalk`Webpack dev server version: {blueBright.bold %s}`, require('webpack-dev-server/package.json').version ); +console.log(chalk`Webpack version: {blueBright.bold %s}`, require('webpack/package.json').version); +console.log( + chalk`Webpack dev server version: {blueBright.bold %s}`, + require('webpack-dev-server/package.json').version, +); -function create( config, pluginOptions, comp = makeCompiler ) -{ +function create(config, pluginOptions, comp = makeCompiler) { let manifest; - if ( Array.isArray( pluginOptions ) ) { - const [ options, callback ] = pluginOptions; + if (Array.isArray(pluginOptions)) { + const [options, callback] = pluginOptions; - manifest = new WebpackAssetsManifest( options ); + manifest = new WebpackAssetsManifest(options); - callback( manifest ); + callback(manifest); } else { - manifest = new WebpackAssetsManifest( pluginOptions ); + manifest = new WebpackAssetsManifest(pluginOptions); } - config.plugins.push( manifest ); + config.plugins.push(manifest); - const compiler = comp( config ); + const compiler = comp(config); - const run = () => new Promise( (resolve, reject) => { - compiler.run( error => { - error ? reject( error ) : resolve(); + const run = () => + new Promise((resolve, reject) => { + compiler.run(error => { + error ? reject(error) : resolve(); - compiler.close( () => {} ); + compiler.close(() => {}); + }); }); - }); return { compiler, manifest, run }; } -describe('WebpackAssetsManifest', function() { +describe('WebpackAssetsManifest', function () { beforeEach(() => { chai.spy.on(console, 'info', () => {}); chai.spy.on(console, 'warn', () => {}); @@ -64,11 +67,11 @@ describe('WebpackAssetsManifest', function() { }); before('set up', async () => { - await mkdirp(configs.getWorkspace(), _777); + await mkdir(configs.getWorkspace(), { recursive: true, mode: _777 }); }); after('clean up', done => { - rimraf(configs.getWorkspace(), function(err) { + rimraf(configs.getWorkspace(), function (err) { if (err) { throw err; } @@ -77,48 +80,48 @@ describe('WebpackAssetsManifest', function() { }); }); - describe('Methods', function() { - describe('getExtension()', function() { + describe('Methods', function () { + describe('getExtension()', function () { const manifest = new WebpackAssetsManifest(); - it('should return the file extension', function() { + it('should return the file extension', function () { assert.equal('.css', manifest.getExtension('main.css')); }); - it('should return two extensions for known formats', function() { + it('should return two extensions for known formats', function () { assert.equal('.js.map', manifest.getExtension('main.js.map')); assert.equal('.css.map', manifest.getExtension('main.css.map')); assert.equal('.tar.gz', manifest.getExtension('archive.tar.gz')); assert.equal('.ext', manifest.getExtension('some.unknown.ext')); }); - it('should return empty string when filename is undefined or empty', function() { + it('should return empty string when filename is undefined or empty', function () { assert.equal('', manifest.getExtension()); assert.equal('', manifest.getExtension('')); }); - it('should return empty string when filename does not have an extension', function() { + it('should return empty string when filename does not have an extension', function () { assert.equal('', manifest.getExtension('no-extension')); }); - it('should ignore query string and fragment', function() { + it('should ignore query string and fragment', function () { assert.equal('.js', manifest.getExtension('main.js?a=1')); assert.equal('.js', manifest.getExtension('main.js#b')); assert.equal('.js', manifest.getExtension('main.js?a=1#b')); }); }); - describe('toJSON()', function() { + describe('toJSON()', function () { const manifest = new WebpackAssetsManifest(); - it('should return an object', function() { + it('should return an object', function () { assert.deepEqual({}, manifest.toJSON()); assert.equal('{}', JSON.stringify(manifest)); }); }); - describe('toString()', function() { - it('should return a JSON string', function() { + describe('toString()', function () { + it('should return a JSON string', function () { const manifest = new WebpackAssetsManifest(); manifest.hooks.afterOptions.call(manifest.options, manifest); @@ -127,7 +130,7 @@ describe('WebpackAssetsManifest', function() { assert.equal('{}', manifest + ''); }); - it('can use tabs', function() { + it('can use tabs', function () { const manifest = new WebpackAssetsManifest({ space: '\t', }); @@ -140,64 +143,52 @@ describe('WebpackAssetsManifest', function() { }); }); - describe('getOutputPath()', function() { - it('should work with an absolute output path', function() { - const { manifest } = create( - configs.hello(), - { - output: '/manifest.json', - }, - ); + describe('getOutputPath()', function () { + it('should work with an absolute output path', function () { + const { manifest } = create(configs.hello(), { + output: '/manifest.json', + }); assert.equal('/manifest.json', manifest.getOutputPath()); }); - it('should work with a relative output path', function() { - const { compiler, manifest } = create( - configs.hello(), - { - output: '../manifest.json', - }, - ); + it('should work with a relative output path', function () { + const { compiler, manifest } = create(configs.hello(), { + output: '../manifest.json', + }); - assert.equal( - path.resolve(compiler.options.output.path, '../manifest.json'), - manifest.getOutputPath(), - ); + assert.equal(path.resolve(compiler.options.output.path, '../manifest.json'), manifest.getOutputPath()); }); - it('should output manifest in compiler output.path by default', function() { - const { compiler, manifest } = create( configs.hello() ); + it('should output manifest in compiler output.path by default', function () { + const { compiler, manifest } = create(configs.hello()); - assert.equal( - compiler.options.output.path, - path.dirname(manifest.getOutputPath()), - ); + assert.equal(compiler.options.output.path, path.dirname(manifest.getOutputPath())); }); - it('should return an empty string if manifest has not been applied yet', function() { + it('should return an empty string if manifest has not been applied yet', function () { const manifest = new WebpackAssetsManifest(); assert.equal('', manifest.getOutputPath()); }); }); - describe('fixKey()', function() { - it('should replace \\ with /', function() { + describe('fixKey()', function () { + it('should replace \\ with /', function () { const manifest = new WebpackAssetsManifest(); assert.equal('images/Ginger.jpg', manifest.fixKey('images\\Ginger.jpg')); }); - it('should return the key if not a string', function() { + it('should return the key if not a string', function () { const manifest = new WebpackAssetsManifest(); assert.equal(1, manifest.fixKey(1)); }); }); - describe('set()', function() { - it('should add to manifest.assets', function() { + describe('set()', function () { + it('should add to manifest.assets', function () { const manifest = new WebpackAssetsManifest(); assert.deepEqual({}, manifest.assets); @@ -214,7 +205,7 @@ describe('WebpackAssetsManifest', function() { ); }); - it('should transform backslashes to slashes', function() { + it('should transform backslashes to slashes', function () { const manifest = new WebpackAssetsManifest(); assert.deepEqual({}, manifest.assets); @@ -230,19 +221,19 @@ describe('WebpackAssetsManifest', function() { }); }); - describe('setRaw()', function() { - it('Uses keys without fixing them', function() { + describe('setRaw()', function () { + it('Uses keys without fixing them', function () { const manifest = new WebpackAssetsManifest(); manifest.setRaw('\\\\', 'image.jpg'); - assert.isTrue( manifest.has('\\\\') ); - assert.equal( manifest.get('\\\\'), 'image.jpg' ); + assert.isTrue(manifest.has('\\\\')); + assert.equal(manifest.get('\\\\'), 'image.jpg'); }); }); - describe('has()', function() { - it('should return a boolean', function() { + describe('has()', function () { + it('should return a boolean', function () { const manifest = new WebpackAssetsManifest({ assets: Object.assign({}, require('./fixtures/json/images.json')), }); @@ -252,47 +243,47 @@ describe('WebpackAssetsManifest', function() { }); }); - describe('get()', function() { + describe('get()', function () { const manifest = new WebpackAssetsManifest({ assets: Object.assign({}, require('./fixtures/json/images.json')), }); - it('gets a value from the manifest', function() { + it('gets a value from the manifest', function () { assert.equal('images/Ginger.jpg', manifest.get('Ginger.jpg')); }); - it('returns a default value', function() { + it('returns a default value', function () { const defaultValue = 'some/default.gif'; assert.equal(defaultValue, manifest.get('dog.gif', defaultValue)); }); - it('returns undefined when no default value is provided', function() { + it('returns undefined when no default value is provided', function () { assert.equal(undefined, manifest.get('dog.gif')); }); }); - describe('delete()', function() { - it('removes an asset from the manifest', function() { + describe('delete()', function () { + it('removes an asset from the manifest', function () { const manifest = new WebpackAssetsManifest(); - [ 'some/image.jpg', 'some\\image.jpg' ].forEach( key => { - [ 'set', 'setRaw' ].forEach( method => { - manifest[ method ](key, 'image.jpg'); + ['some/image.jpg', 'some\\image.jpg'].forEach(key => { + ['set', 'setRaw'].forEach(method => { + manifest[method](key, 'image.jpg'); - assert.isTrue( manifest.has(key) ); + assert.isTrue(manifest.has(key)); manifest.delete(key); - assert.isFalse( manifest.has(key) ); + assert.isFalse(manifest.has(key)); }); }); - assert.isFalse( manifest.delete('404.js') ); + assert.isFalse(manifest.delete('404.js')); }); }); - describe('inDevServer()', function() { + describe('inDevServer()', function () { let originalArgv; beforeEach(() => { @@ -303,24 +294,17 @@ describe('WebpackAssetsManifest', function() { process.argv = originalArgv; }); - it('Identifies `webpack serve` from argv', function() { + it('Identifies `webpack serve` from argv', function () { const manifest = new WebpackAssetsManifest(); assert.isFalse(manifest.inDevServer()); - process.argv = [ - originalArgv[ 0 ], - path.join( - path.dirname( originalArgv[ 1 ] ), - 'webpack', - ), - 'serve', - ]; + process.argv = [originalArgv[0], path.join(path.dirname(originalArgv[1]), 'webpack'), 'serve']; assert.isTrue(manifest.inDevServer()); }); - it('Identifies webpack-dev-server from argv', function() { + it('Identifies webpack-dev-server from argv', function () { const manifest = new WebpackAssetsManifest(); assert.isFalse(manifest.inDevServer()); @@ -330,7 +314,7 @@ describe('WebpackAssetsManifest', function() { assert.isTrue(manifest.inDevServer()); }); - it('Identifies webpack-dev-server from outputFileSystem', function() { + it('Identifies webpack-dev-server from outputFileSystem', function () { const config = configs.hello(); config.output.path = '/'; @@ -343,7 +327,7 @@ describe('WebpackAssetsManifest', function() { assert.isTrue(manifest.inDevServer()); }); - it('Works correct with null prototypes outputFileSystem', function() { + it('Works correct with null prototypes outputFileSystem', function () { const config = configs.hello(); config.output.path = '/'; @@ -360,63 +344,60 @@ describe('WebpackAssetsManifest', function() { }); }); - describe('getProxy()', function() { - it('Returns a Proxy', function() { + describe('getProxy()', function () { + it('Returns a Proxy', function () { const manifest = new WebpackAssetsManifest(); - [ undefined, false, true ].forEach( raw => { - const proxy = manifest.getProxy( raw ); + [undefined, false, true].forEach(raw => { + const proxy = manifest.getProxy(raw); assert.instanceOf(proxy, WebpackAssetsManifest); - proxy[ 'test' ] = 'test'; + proxy['test'] = 'test'; - assert.isTrue( 'test' in proxy ); + assert.isTrue('test' in proxy); - assert.equal( 'test', proxy[ 'test' ] ); + assert.equal('test', proxy['test']); - delete proxy[ 'test' ]; + delete proxy['test']; - assert.isUndefined( proxy[ 'test' ] ); - assert.isFalse( 'test' in proxy ); + assert.isUndefined(proxy['test']); + assert.isFalse('test' in proxy); }); }); }); - describe('clear()', function() { + describe('clear()', function () { it('clears data', async () => { - const { manifest, run } = create( configs.hello() ); + const { manifest, run } = create(configs.hello()); - expect( manifest.assets ).to.be.empty; + expect(manifest.assets).to.be.empty; await run(); - expect( manifest.assets ).to.not.be.empty; + expect(manifest.assets).to.not.be.empty; manifest.clear(); - expect( manifest.assets ).to.be.empty; + expect(manifest.assets).to.be.empty; }); }); }); - describe('Options', function() { - describe('enabled', function() { + describe('Options', function () { + describe('enabled', function () { it('does nothing if not enabled', async () => { - const { manifest, run } = create( - configs.hello(), - { - enabled: false, - }, - ); + const { manifest, run } = create(configs.hello(), { + enabled: false, + }); await run(); - expect( manifest.assets ).to.be.empty; + expect(manifest.assets).to.be.empty; }); }); - describe('sortManifest', function() { + describe('sortManifest', function () { const assets = { 'd.js': 'd.js', 'c.js': 'c.js', @@ -424,20 +405,17 @@ describe('WebpackAssetsManifest', function() { 'a.js': 'a.js', }; - it('should turn on sorting', function() { + it('should turn on sorting', function () { const manifest = new WebpackAssetsManifest({ assets, sortManifest: true, space: 0, }); - assert.equal( - '{"a.js":"a.js","b.js":"b.js","c.js":"c.js","d.js":"d.js"}', - manifest.toString(), - ); + assert.equal('{"a.js":"a.js","b.js":"b.js","c.js":"c.js","d.js":"d.js"}', manifest.toString()); }); - it('should turn off sorting', function() { + it('should turn off sorting', function () { const manifest = new WebpackAssetsManifest({ assets, sortManifest: false, @@ -446,16 +424,13 @@ describe('WebpackAssetsManifest', function() { manifest.processAssetsByChunkName(assets); - assert.equal( - '{"d.js":"d.js","c.js":"c.js","b.js":"b.js","a.js":"a.js"}', - manifest.toString(), - ); + assert.equal('{"d.js":"d.js","c.js":"c.js","b.js":"b.js","a.js":"a.js"}', manifest.toString()); }); - it('should use custom comparison function', function() { + it('should use custom comparison function', function () { const manifest = new WebpackAssetsManifest({ assets, - sortManifest: function(left, right) { + sortManifest: function (left, right) { return left.localeCompare(right); }, space: 0, @@ -463,15 +438,12 @@ describe('WebpackAssetsManifest', function() { manifest.processAssetsByChunkName(assets); - assert.equal( - '{"a.js":"a.js","b.js":"b.js","c.js":"c.js","d.js":"d.js"}', - manifest.toString(), - ); + assert.equal('{"a.js":"a.js","b.js":"b.js","c.js":"c.js","d.js":"d.js"}', manifest.toString()); }); }); - describe('fileExtRegex', function() { - it('should use custom RegExp', function() { + describe('fileExtRegex', function () { + it('should use custom RegExp', function () { const manifest = new WebpackAssetsManifest({ fileExtRegex: /\.[a-z0-9]+$/i, }); @@ -480,7 +452,7 @@ describe('WebpackAssetsManifest', function() { assert.equal(manifest.getExtension('test.js.map'), '.map'); }); - it('should fallback to path.extname', function() { + it('should fallback to path.extname', function () { const manifest = new WebpackAssetsManifest({ fileExtRegex: false, }); @@ -489,12 +461,12 @@ describe('WebpackAssetsManifest', function() { }); }); - describe('replacer', function() { + describe('replacer', function () { const assets = { 'logo.svg': 'images/logo.svg', }; - it('should remove all entries', function() { + it('should remove all entries', function () { const manifest = new WebpackAssetsManifest({ assets, replacer: () => undefined, @@ -503,12 +475,12 @@ describe('WebpackAssetsManifest', function() { assert.equal('{}', manifest.toString()); }); - it('should update values', function() { + it('should update values', function () { const manifest = new WebpackAssetsManifest({ assets, space: 0, - replacer: function(key, value) { - if ( typeof value === 'string' ) { + replacer: function (key, value) { + if (typeof value === 'string') { return value.toUpperCase(); } @@ -520,43 +492,34 @@ describe('WebpackAssetsManifest', function() { }); }); - describe('assets', function() { + describe('assets', function () { const assets = { 'logo.svg': 'images/logo.svg', }; - it('should set the initial assets data', function() { + it('should set the initial assets data', function () { const manifest = new WebpackAssetsManifest({ assets: Object.assign({}, require('./fixtures/json/images.json')), space: 0, }); - Object.keys( assets ).forEach( key => { - manifest.set(key, assets[ key ]); + Object.keys(assets).forEach(key => { + manifest.set(key, assets[key]); }); - assert.equal( - '{"Ginger.jpg":"images/Ginger.jpg","logo.svg":"images/logo.svg"}', - manifest.toString(), - ); + assert.equal('{"Ginger.jpg":"images/Ginger.jpg","logo.svg":"images/logo.svg"}', manifest.toString()); }); - it('should be sharable', function() { + it('should be sharable', function () { const sharedAssets = Object.create(null); - const { manifest: manifest1 } = create( - configs.hello(), - { - assets: sharedAssets, - }, - ); + const { manifest: manifest1 } = create(configs.hello(), { + assets: sharedAssets, + }); - const { manifest: manifest2 } = create( - configs.client(), - { - assets: sharedAssets, - }, - ); + const { manifest: manifest2 } = create(configs.client(), { + assets: sharedAssets, + }); manifest1.set('main.js', 'main.js'); manifest2.set('subpage.js', 'subpage.js'); @@ -565,10 +528,9 @@ describe('WebpackAssetsManifest', function() { }); }); - describe('merge', function() { - async function setupManifest(manifest) - { - await mkdirp( path.dirname( manifest.getOutputPath() ) ); + describe('merge', function () { + async function setupManifest(manifest) { + await mkdir(path.dirname(manifest.getOutputPath())); await fs.promises.copyFile( path.resolve(__dirname, 'fixtures/json/sample-manifest.json'), @@ -579,14 +541,11 @@ describe('WebpackAssetsManifest', function() { } it('should merge data if output file exists', async () => { - const { manifest, run } = create( - configs.hello(), - { - entrypoints: true, - merge: true, - space: 0, - }, - ); + const { manifest, run } = create(configs.hello(), { + entrypoints: true, + merge: true, + space: 0, + }); await setupManifest(manifest); await run(); @@ -599,61 +558,55 @@ describe('WebpackAssetsManifest', function() { it('can customize during merge', async () => { const mergingResults = []; - const { manifest, run } = create( - configs.hello(), - { - merge: 'customize', - space: 0, - customize(entry, original, manifest) { - assert.isBoolean(manifest.isMerging); - mergingResults.push(manifest.isMerging); - }, + const { manifest, run } = create(configs.hello(), { + merge: 'customize', + space: 0, + customize(entry, original, manifest) { + assert.isBoolean(manifest.isMerging); + mergingResults.push(manifest.isMerging); }, - ); + }); await setupManifest(manifest); await run(); - assert.isTrue( mergingResults.some( result => result === true ) ); - assert.isTrue( mergingResults.some( result => result === false ) ); + assert.isTrue(mergingResults.some(result => result === true)); + assert.isTrue(mergingResults.some(result => result === false)); }); it('merge skips customize()', async () => { const mock = chai.spy(); - const { manifest, run } = create( - configs.hello(), - { - merge: true, - customize(entry, original, manifest) { - if ( manifest.isMerging ) { - mock(); - } - }, + const { manifest, run } = create(configs.hello(), { + merge: true, + customize(entry, original, manifest) { + if (manifest.isMerging) { + mock(); + } }, - ); + }); await setupManifest(manifest); await run(); - expect( mock ).to.not.have.been.called(); + expect(mock).to.not.have.been.called(); }); }); - describe('publicPath', function() { + describe('publicPath', function () { const img = 'images/photo.jpg'; const cdn = { default: 'https://cdn.example.com/', images: 'https://img-cdn.example.com/', }; - it('can be a string', function() { + it('can be a string', function () { const manifest = new WebpackAssetsManifest({ publicPath: 'assets/', }); manifest.set('hello', 'world'); - assert.equal( manifest.get('hello'), 'assets/world' ); + assert.equal(manifest.get('hello'), 'assets/world'); }); it('can be true', async () => { @@ -661,16 +614,13 @@ describe('WebpackAssetsManifest', function() { config.output.publicPath = cdn.default; - const { manifest, run } = create( - config, - { - publicPath: true, - }, - ); + const { manifest, run } = create(config, { + publicPath: true, + }); await run(); - assert.equal( cdn.default + 'main.js', manifest.get('main.js') ); + assert.equal(cdn.default + 'main.js', manifest.get('main.js')); }); it('has no effect if false', async () => { @@ -678,32 +628,29 @@ describe('WebpackAssetsManifest', function() { config.output.publicPath = cdn.default; - const { manifest, run } = create( - config, - { - publicPath: false, - }, - ); + const { manifest, run } = create(config, { + publicPath: false, + }); await run(); - assert.equal('main.js', manifest.get('main.js') ); + assert.equal('main.js', manifest.get('main.js')); }); - it('only prefixes strings', function() { + it('only prefixes strings', function () { const manifest = new WebpackAssetsManifest({ publicPath: cdn.default, }); - manifest.set('obj', {} ); + manifest.set('obj', {}); assert.deepEqual({}, manifest.get('obj')); }); - it('can be a custom function', function() { + it('can be a custom function', function () { const manifest = new WebpackAssetsManifest({ - publicPath: function( val, manifest ) { - if ( manifest.getExtension( val ).substr(1).toLowerCase() ) { + publicPath: function (val, manifest) { + if (manifest.getExtension(val).substr(1).toLowerCase()) { return cdn.images + val; } @@ -711,126 +658,105 @@ describe('WebpackAssetsManifest', function() { }, }); - assert.isFunction( manifest.options.publicPath ); + assert.isFunction(manifest.options.publicPath); - manifest.set( img, img ); + manifest.set(img, img); - assert.equal( cdn.images + img, manifest.get( img ) ); + assert.equal(cdn.images + img, manifest.get(img)); }); }); - describe('customize', function() { - it('customizes the key and value', function() { - const { manifest } = create( - configs.hello(), - { - customize(entry) { - return { - key: entry.key.toUpperCase(), - value: entry.value.toUpperCase(), - }; - }, + describe('customize', function () { + it('customizes the key and value', function () { + const { manifest } = create(configs.hello(), { + customize(entry) { + return { + key: entry.key.toUpperCase(), + value: entry.value.toUpperCase(), + }; }, - ); + }); manifest.set('hello', 'world'); - assert.isTrue( manifest.has('HELLO') ); - assert.isFalse( manifest.has('hello') ); + assert.isTrue(manifest.has('HELLO')); + assert.isFalse(manifest.has('hello')); }); - it('customizes the key', function() { - const { manifest } = create( - configs.hello(), - { - customize(entry) { - return { - key: entry.key.toUpperCase(), - }; - }, + it('customizes the key', function () { + const { manifest } = create(configs.hello(), { + customize(entry) { + return { + key: entry.key.toUpperCase(), + }; }, - ); + }); manifest.set('hello', 'world'); - assert.isTrue( manifest.has('HELLO') ); - assert.isFalse( manifest.has('hello') ); - assert.equal( manifest.get('HELLO'), 'world' ); + assert.isTrue(manifest.has('HELLO')); + assert.isFalse(manifest.has('hello')); + assert.equal(manifest.get('HELLO'), 'world'); }); - it('customizes the value', function() { - const { manifest } = create( - configs.hello(), - { - customize(entry) { - return { - value: entry.value.toUpperCase(), - }; - }, + it('customizes the value', function () { + const { manifest } = create(configs.hello(), { + customize(entry) { + return { + value: entry.value.toUpperCase(), + }; }, - ); + }); manifest.set('hello', 'world'); - assert.isFalse( manifest.has('HELLO') ); - assert.isTrue( manifest.has('hello') ); - assert.equal( manifest.get('hello'), 'WORLD' ); + assert.isFalse(manifest.has('HELLO')); + assert.isTrue(manifest.has('hello')); + assert.equal(manifest.get('hello'), 'WORLD'); }); - it('has no effect unless an object or false is returned', function() { - const { manifest } = create( - configs.hello(), - { - customize() { - return 3.14; - }, + it('has no effect unless an object or false is returned', function () { + const { manifest } = create(configs.hello(), { + customize() { + return 3.14; }, - ); + }); manifest.set('hello', 'world'); - assert.isTrue( manifest.has('hello') ); - assert.equal( manifest.get('hello'), 'world' ); + assert.isTrue(manifest.has('hello')); + assert.equal(manifest.get('hello'), 'world'); }); - it('skips adding asset if false is returned', function() { - const { manifest } = create( - configs.hello(), - { - customize() { - return false; - }, + it('skips adding asset if false is returned', function () { + const { manifest } = create(configs.hello(), { + customize() { + return false; }, - ); + }); manifest.set('hello', 'world'); - assert.isFalse( manifest.has('hello') ); - assert.deepEqual( {}, manifest.assets ); + assert.isFalse(manifest.has('hello')); + assert.deepEqual({}, manifest.assets); }); }); - describe('integrityHashes', function() { - it('invalid crypto hashes are filtered out', function() { - const { manifest } = create( - configs.hello(), - { - integrityHashes: [ 'sha256', 'invalid-algorithm' ], - }, - ); + describe('integrityHashes', function () { + it('invalid crypto hashes are filtered out', function () { + const { manifest } = create(configs.hello(), { + integrityHashes: ['sha256', 'invalid-algorithm'], + }); assert.notInclude(manifest.options.integrityHashes, 'invalid-algorithm'); }); }); - describe('integrity', function() { + describe('integrity', function () { it('manifest entry contains an integrity property', async () => { - const { manifest, run } = create( - configs.hello(), - { - integrity: true, - }, - ); + const { manifest, run } = create(configs.hello(), { + integrity: true, + }); await run(); @@ -838,65 +764,53 @@ describe('WebpackAssetsManifest', function() { assert.typeOf(asset, 'object'); assert.property(asset, 'integrity'); - assert.isNotEmpty( asset.integrity ); + assert.isNotEmpty(asset.integrity); }); }); - describe('integrityPropertyName', function() { + describe('integrityPropertyName', function () { it('Assigns SRI hashes to currentAsset.info[ integrityPropertyName ]', async () => { const integrityPropertyName = 'sri'; - const { run } = create( - configs.hello(), - { - integrity: true, - integrityHashes: [ 'md5' ], - integrityPropertyName, - customize(entry, original, manifest, asset) { - assert.containsAllKeys( - asset.info, - [ integrityPropertyName ], - `asset.info is missing ${integrityPropertyName} property`, - ); - }, + const { run } = create(configs.hello(), { + integrity: true, + integrityHashes: ['md5'], + integrityPropertyName, + customize(entry, original, manifest, asset) { + assert.containsAllKeys( + asset.info, + [integrityPropertyName], + `asset.info is missing ${integrityPropertyName} property`, + ); }, - ); + }); await run(); }); it('Does not overwrite existing currentAsset.info[ integrityPropertyName ]', async () => { - const { manifest, run } = create( - configs.hello(), - { - integrity: true, - integrityHashes: [ 'md5' ], - apply(manifest) { - manifest.compiler.hooks.compilation.tap( - 'test', - compilation => { - chai.spy.on(compilation.assetsInfo, 'get', () => ({ - [ manifest.options.integrityPropertyName ]: 'test', - })); - }, - ); - }, + const { manifest, run } = create(configs.hello(), { + integrity: true, + integrityHashes: ['md5'], + apply(manifest) { + manifest.compiler.hooks.compilation.tap('test', compilation => { + chai.spy.on(compilation.assetsInfo, 'get', () => ({ + [manifest.options.integrityPropertyName]: 'test', + })); + }); }, - ); + }); await run(); - expect( manifest.get('main.js')[ manifest.options.integrityPropertyName ] ).to.equal('test'); + expect(manifest.get('main.js')[manifest.options.integrityPropertyName]).to.equal('test'); }); }); - describe('entrypoints', function() { + describe('entrypoints', function () { it('entrypoints are included in manifest', async () => { - const { manifest, run } = create( - configs.hello(), - { - entrypoints: true, - }, - ); + const { manifest, run } = create(configs.hello(), { + entrypoints: true, + }); await run(); @@ -906,57 +820,48 @@ describe('WebpackAssetsManifest', function() { }); it('entrypoints can use default values instead of values from this.assets', async () => { - const { manifest, run } = create( - configs.hello(), - { - entrypoints: true, - entrypointsUseAssets: false, - integrity: true, - }, - ); + const { manifest, run } = create(configs.hello(), { + entrypoints: true, + entrypointsUseAssets: false, + integrity: true, + }); await run(); - expect( manifest.get('entrypoints') ).to.deep.equal({ + expect(manifest.get('entrypoints')).to.deep.equal({ main: { assets: { - js: [ 'main.js' ], + js: ['main.js'], }, }, }); }); it('entrypoints are prefixed with publicPath when entrypointsUseAssets is false', async () => { - const { manifest, run } = create( - configs.hello(), - { - entrypoints: true, - entrypointsUseAssets: false, - publicPath: 'https://example.com/', - }, - ); + const { manifest, run } = create(configs.hello(), { + entrypoints: true, + entrypointsUseAssets: false, + publicPath: 'https://example.com/', + }); await run(); - expect( manifest.get('entrypoints') ).to.deep.equal({ + expect(manifest.get('entrypoints')).to.deep.equal({ main: { assets: { - js: [ 'https://example.com/main.js' ], + js: ['https://example.com/main.js'], }, }, }); }); }); - describe('entrypointsKey', function() { + describe('entrypointsKey', function () { it('customize the key used for entrypoints', async () => { - const { manifest, run } = create( - configs.hello(), - { - entrypoints: true, - entrypointsKey: 'myEntrypoints', - }, - ); + const { manifest, run } = create(configs.hello(), { + entrypoints: true, + entrypointsKey: 'myEntrypoints', + }); await run(); @@ -966,13 +871,10 @@ describe('WebpackAssetsManifest', function() { }); it('can be false', async () => { - const { manifest, run } = create( - configs.hello(), - { - entrypoints: true, - entrypointsKey: false, - }, - ); + const { manifest, run } = create(configs.hello(), { + entrypoints: true, + entrypointsKey: false, + }); await run(); @@ -989,68 +891,63 @@ describe('WebpackAssetsManifest', function() { entrypoints: true, }; - const { manifest, run: run1 } = create( configs.hello(), options ); + const { manifest, run: run1 } = create(configs.hello(), options); - const { run: run2 } = create( configs.client(), options ); + const { run: run2 } = create(configs.client(), options); - await Promise.all([ run1(), run2() ]); + await Promise.all([run1(), run2()]); - const entrypointsKeys = Object.keys( manifest.get('entrypoints') ); + const entrypointsKeys = Object.keys(manifest.get('entrypoints')); - expect( entrypointsKeys ).to.contain('main'); - expect( entrypointsKeys ).to.contain('client'); + expect(entrypointsKeys).to.contain('main'); + expect(entrypointsKeys).to.contain('client'); }); }); - describe('done', function() { + describe('done', function () { it('is called when compilation is done', async () => { - const mock1 = chai.spy( async () => true ); - const mock2 = chai.spy( async () => true ); + const mock1 = chai.spy(async () => true); + const mock2 = chai.spy(async () => true); const mock3 = chai.spy(); - const { manifest, run } = create( - configs.hello(), - { - async done() { - await mock1(); - }, + const { manifest, run } = create(configs.hello(), { + async done() { + await mock1(); }, - ); + }); - manifest.hooks.done.tapPromise('test', async () => { await mock2(); }); - manifest.hooks.done.tap('test', () => { mock3(); }); + manifest.hooks.done.tapPromise('test', async () => { + await mock2(); + }); + manifest.hooks.done.tap('test', () => { + mock3(); + }); await run(); - expect( mock1 ).to.have.been.called; - expect( mock2 ).to.have.been.called; - expect( mock3 ).to.have.been.called; + expect(mock1).to.have.been.called; + expect(mock2).to.have.been.called; + expect(mock3).to.have.been.called; }); }); - describe('contextRelativeKeys', function() { + describe('contextRelativeKeys', function () { it('keys are filepaths relative to the compiler context', async () => { - const { manifest, run } = create( - configs.client(), - { - contextRelativeKeys: true, - }, - ); + const { manifest, run } = create(configs.client(), { + contextRelativeKeys: true, + }); await run(); - expect( manifest.get('client.js') ).to.equal('client.js'); - expect( manifest.get('test/fixtures/images/Ginger.asset.jpg') ).to.equal('images/Ginger.asset.jpg'); + expect(manifest.get('client.js')).to.equal('client.js'); + expect(manifest.get('test/fixtures/images/Ginger.asset.jpg')).to.equal('images/Ginger.asset.jpg'); }); }); - describe('writeToDisk', function() { + describe('writeToDisk', function () { it('Uses webpack config options.devServer.writeToDisk when available', async () => { - const { manifest } = create( - configs.devServer(), - { - writeToDisk: 'auto', - }, - ); + const { manifest } = create(configs.devServer(), { + writeToDisk: 'auto', + }); const mockCompilation = { options: { @@ -1061,16 +958,13 @@ describe('WebpackAssetsManifest', function() { }; // The plugin shouldn't write to disk if the dev server is configured to do it. - expect( manifest.shouldWriteToDisk( mockCompilation ) ).to.be.false; + expect(manifest.shouldWriteToDisk(mockCompilation)).to.be.false; }); it('Calls options.devServer.writeToDisk() with manifest path', async () => { - const { manifest } = create( - configs.devServer( __dirname ), - { - writeToDisk: 'auto', - }, - ); + const { manifest } = create(configs.devServer(__dirname), { + writeToDisk: 'auto', + }); const mockCompilation = { getPath: filename => filename, @@ -1084,198 +978,161 @@ describe('WebpackAssetsManifest', function() { }; // The plugin shouldn't write to disk if the dev server is configured to do it. - expect( manifest.shouldWriteToDisk( mockCompilation ) ).to.be.false; + expect(manifest.shouldWriteToDisk(mockCompilation)).to.be.false; }); }); - describe('extra', function() { + describe('extra', function () { it('Holds arbitrary data', async () => { - const { manifest } = create( - configs.hello(), - { - extra: { - test: true, - }, + const { manifest } = create(configs.hello(), { + extra: { + test: true, }, - ); + }); expect(manifest.options.extra.test).to.be.true; }); }); - describe('Default options', function() { - it('Defaults are used', function() { - const { manifest } = create( configs.hello() ); + describe('Default options', function () { + it('Defaults are used', function () { + const { manifest } = create(configs.hello()); - expect( manifest.options ).to.deep.equal( manifest.defaultOptions ); + expect(manifest.options).to.deep.equal(manifest.defaultOptions); }); }); - describe('Schema validation', function() { - it('Error is thrown if options schema validation fails', function() { + describe('Schema validation', function () { + it('Error is thrown if options schema validation fails', function () { expect(() => { - create( - configs.hello(), - { - space: false, - }, - ); + create(configs.hello(), { + space: false, + }); }).to.throw(); }); - it('Error is thrown when options has unknown property', function() { + it('Error is thrown when options has unknown property', function () { expect(() => { - create( - configs.hello(), - { - someUnknownProperty: 'will fail', - }, - ); + create(configs.hello(), { + someUnknownProperty: 'will fail', + }); }).to.throw(); }); }); }); - describe('Hooks', function() { - it('Callbacks passed in options are tapped', function() { - const { manifest } = create( - configs.hello(), - { - apply: () => {}, - customize: () => {}, - transform: () => {}, - done: () => {}, - }, - ); + describe('Hooks', function () { + it('Callbacks passed in options are tapped', function () { + const { manifest } = create(configs.hello(), { + apply: () => {}, + customize: () => {}, + transform: () => {}, + done: () => {}, + }); - expect( manifest.hooks.apply.taps.length ).to.be.at.least(1); - expect( manifest.hooks.customize.taps.length ).to.be.at.least(1); - expect( manifest.hooks.transform.taps.length ).to.be.at.least(1); - expect( manifest.hooks.done.taps.length ).to.be.at.least(1); + expect(manifest.hooks.apply.taps.length).to.be.at.least(1); + expect(manifest.hooks.customize.taps.length).to.be.at.least(1); + expect(manifest.hooks.transform.taps.length).to.be.at.least(1); + expect(manifest.hooks.done.taps.length).to.be.at.least(1); }); - describe('Apply', function() { - it('Is called after the manifest is set up', function() { + describe('Apply', function () { + it('Is called after the manifest is set up', function () { const mock = chai.spy(); - create( - configs.hello(), - { - apply() { - mock(); - }, + create(configs.hello(), { + apply() { + mock(); }, - ); + }); - expect( mock ).to.have.been.called(); + expect(mock).to.have.been.called(); }); }); - describe('Customize', function() { - it('Can customize an entry', function() { - const { manifest } = create( - configs.hello(), - { - customize(entry) { - entry.value = 'customized'; - }, + describe('Customize', function () { + it('Can customize an entry', function () { + const { manifest } = create(configs.hello(), { + customize(entry) { + entry.value = 'customized'; }, - ); + }); manifest.set('key', 'not customized'); - expect( manifest.get('key') ).to.equal('customized'); + expect(manifest.get('key')).to.equal('customized'); }); }); - describe('Options', function() { - it('Options can be altered with a hook', function() { - const mock = chai.spy( options => { + describe('Options', function () { + it('Options can be altered with a hook', function () { + const mock = chai.spy(options => { options.space = 0; return options; }); - const { manifest } = create( - configs.hello(), - [ - undefined, - manifest => manifest.hooks.options.tap('test', mock ), - ], - ); + const { manifest } = create(configs.hello(), [undefined, manifest => manifest.hooks.options.tap('test', mock)]); - expect( mock ).to.have.been.called(); + expect(mock).to.have.been.called(); - expect( manifest.options.space ).to.equal(0); + expect(manifest.options.space).to.equal(0); }); }); - describe('Transform', function() { - it('Transforms the data', function() { - const { manifest } = create( - configs.hello(), - { - space: 0, - transform(assets) { - return { assets }; - }, + describe('Transform', function () { + it('Transforms the data', function () { + const { manifest } = create(configs.hello(), { + space: 0, + transform(assets) { + return { assets }; }, - ); + }); expect(`${manifest}`).to.equal('{"assets":{}}'); }); }); - describe('Done', function() { + describe('Done', function () { it('Is called when the compilation is done', async () => { const mock = chai.spy(); - const { run } = create( - configs.hello(), - [ - { - done() { - mock(); - }, - }, - () => { - expect( mock ).to.not.have.been.called(); + const { run } = create(configs.hello(), [ + { + done() { + mock(); }, - ], - ); + }, + () => { + expect(mock).to.not.have.been.called(); + }, + ]); await run(); - expect( mock ).to.have.been.called(); + expect(mock).to.have.been.called(); }); }); }); - describe('Usage with webpack', function() { + describe('Usage with webpack', function () { it('writes to disk', async () => { - const { manifest, run } = create( - configs.hello(), - { - writeToDisk: true, - }, - ); + const { manifest, run } = create(configs.hello(), { + writeToDisk: true, + }); await run(); - const content = await fs.promises.readFile( manifest.getOutputPath() ); + const content = await fs.promises.readFile(manifest.getOutputPath()); - assert.equal( manifest.toString(), content.toString() ); + assert.equal(manifest.toString(), content.toString()); }); it('compiler has error if unable to create directory', async () => { fs.chmodSync(configs.getWorkspace(), _444); - const { run } = create( - configs.hello(), - undefined, - webpack, - ); + const { run } = create(configs.hello(), undefined, webpack); - const error = await run().catch( error => error ); + const error = await run().catch(error => error); assert.isNotNull(error, 'Permissions error not found'); assert.equal('EACCES', error.code); @@ -1284,16 +1141,16 @@ describe('WebpackAssetsManifest', function() { }); it('finds module assets', async () => { - const { manifest, run } = create( configs.client( true ) ); + const { manifest, run } = create(configs.client(true)); await run(); - assert.isTrue( manifest.has('images/Ginger.asset.jpg') ); + assert.isTrue(manifest.has('images/Ginger.asset.jpg')); }); it('should support multi compiler mode', done => { const assets = Object.create(null); - const multiConfig = configs.multi().map( config => { + const multiConfig = configs.multi().map(config => { config.plugins = [ new WebpackAssetsManifest({ assets, @@ -1303,27 +1160,21 @@ describe('WebpackAssetsManifest', function() { return config; }); - webpack(multiConfig, function( err ) { + webpack(multiConfig, function (err) { assert.isNull(err, 'Error found in compiler.run'); - const manifestPath = multiConfig[ 0 ].plugins[ 0 ].getOutputPath(); + const manifestPath = multiConfig[0].plugins[0].getOutputPath(); - assert.strictEqual( - multiConfig[ 0 ].plugins[ 0 ].assets, - multiConfig[ 1 ].plugins[ 0 ].assets, - ); + assert.strictEqual(multiConfig[0].plugins[0].assets, multiConfig[1].plugins[0].assets); - fs.readFile( - manifestPath, - function(err, content) { - assert.isNull(err, 'Error reading assets manifest'); - assert.include(content.toString(), 'client.js'); - assert.include(content.toString(), 'server.js'); - assert.include(content.toString(), 'images/Ginger.asset.jpg'); + fs.readFile(manifestPath, function (err, content) { + assert.isNull(err, 'Error reading assets manifest'); + assert.include(content.toString(), 'client.js'); + assert.include(content.toString(), 'server.js'); + assert.include(content.toString(), 'images/Ginger.asset.jpg'); - done(); - }, - ); + done(); + }); }); }); @@ -1336,13 +1187,13 @@ describe('WebpackAssetsManifest', function() { { output: './reports/assets-manifest.json', integrity: true, - integrityHashes: [ 'md5' ], + integrityHashes: ['md5'], entrypoints: true, entrypointsUseAssets: true, publicPath: true, contextRelativeKeys: false, customize(entry, original, manifest, asset) { - if ( entry.key.toLowerCase().startsWith('main') ) { + if (entry.key.toLowerCase().startsWith('main')) { return false; } @@ -1350,7 +1201,7 @@ describe('WebpackAssetsManifest', function() { value: { publicPath: entry.value, value: original.value, - integrity: asset.info[ manifest.options.integrityPropertyName ], + integrity: asset.info[manifest.options.integrityPropertyName], }, }; }, @@ -1374,29 +1225,29 @@ describe('WebpackAssetsManifest', function() { it('main assets were excluded in customize()', () => { const { assets } = manifest.toJSON(); - expect( assets ).to.not.have.keys([ 'main.js', 'main.css' ]); + expect(assets).to.not.have.keys(['main.js', 'main.css']); }); it('asset names point to the same file due to module.rules config', () => { const { assets } = manifest.toJSON(); - expect( assets[ 'images/Ginger.asset.jpg' ], 'assets: images/Ginger.asset.jpg is undefined' ).to.not.be.undefined; - expect( assets[ 'images/Ginger.loader.jpg' ], 'assets: images/Ginger.loader.jpg is undefined' ).to.not.be.undefined; - expect( assets[ 'images/Ginger.asset.jpg' ] ).to.deep.equal( assets[ 'images/Ginger.loader.jpg' ] ); + expect(assets['images/Ginger.asset.jpg'], 'assets: images/Ginger.asset.jpg is undefined').to.not.be.undefined; + expect(assets['images/Ginger.loader.jpg'], 'assets: images/Ginger.loader.jpg is undefined').to.not.be.undefined; + expect(assets['images/Ginger.asset.jpg']).to.deep.equal(assets['images/Ginger.loader.jpg']); }); it('entrypoints use values from assets (could be a customized value)', () => { const { assets, entrypoints } = manifest.toJSON(); - expect( entrypoints.complex.assets.js[ 0 ] ).to.deep.equal( assets[ 'complex.js' ] ); + expect(entrypoints.complex.assets.js[0]).to.deep.equal(assets['complex.js']); }); it('entrypoints use default values when corresponding asset is not found (excluded during customize)', () => { const { entrypoints } = manifest.toJSON(); - expect( entrypoints.main.assets ).to.deep.equal({ - css: [ 'https://assets.example.com/main-HASH.css' ], - js: [ 'https://assets.example.com/main-HASH.js' ], + expect(entrypoints.main.assets).to.deep.equal({ + css: ['https://assets.example.com/main-HASH.css'], + js: ['https://assets.example.com/main-HASH.js'], }); }); }); @@ -1411,14 +1262,14 @@ describe('WebpackAssetsManifest', function() { integrity: true, }); - config.plugins.push( manifest, integrityManifest ); + config.plugins.push(manifest, integrityManifest); - const compiler = makeCompiler( config ); + const compiler = makeCompiler(config); - compiler.run( err => { - expect( err ).to.be.null; - expect( manifest.has( integrityManifest.options.output ) ).to.be.false; - expect( integrityManifest.has( manifest.options.output ) ).to.be.false; + compiler.run(err => { + expect(err).to.be.null; + expect(manifest.has(integrityManifest.options.output)).to.be.false; + expect(integrityManifest.has(manifest.options.output)).to.be.false; done(); }); @@ -1427,50 +1278,40 @@ describe('WebpackAssetsManifest', function() { describe('Uses asset.info.sourceFilename when assetNames does not have a matching asset', () => { it('contextRelativeKeys is on', async () => { - const { manifest, run } = create( - configs.client(), - { - contextRelativeKeys: true, - }, - ); + const { manifest, run } = create(configs.client(), { + contextRelativeKeys: true, + }); // Pretend like assetNames is empty. - chai.spy.on( manifest.assetNames, 'entries', () => new Map().entries() ); + chai.spy.on(manifest.assetNames, 'entries', () => new Map().entries()); await run(); - assert.isTrue( manifest.has('test/fixtures/images/Ginger.asset.jpg') ); + assert.isTrue(manifest.has('test/fixtures/images/Ginger.asset.jpg')); }); it('contextRelativeKeys is off', async () => { - const { manifest, run } = create( - configs.client(), - { - contextRelativeKeys: false, - }, - ); + const { manifest, run } = create(configs.client(), { + contextRelativeKeys: false, + }); // Pretend like assetNames is empty. - chai.spy.on( manifest.assetNames, 'entries', () => new Map().entries() ); + chai.spy.on(manifest.assetNames, 'entries', () => new Map().entries()); await run(); - assert.isTrue( manifest.has('Ginger.asset.jpg') ); + assert.isTrue(manifest.has('Ginger.asset.jpg')); }); }); }); - describe('Errors writing file to disk', function() { + describe('Errors writing file to disk', function () { it('has error creating directory', async () => { fs.chmodSync(configs.getWorkspace(), _444); - const { run } = create( - configs.hello(), - undefined, - webpack, - ); + const { run } = create(configs.hello(), undefined, webpack); - const error = await run().catch( error => error ); + const error = await run().catch(error => error); assert.isNotNull(error, 'Permissions error not found'); assert.equal('EACCES', error.code); @@ -1478,7 +1319,7 @@ describe('WebpackAssetsManifest', function() { fs.chmodSync(configs.getWorkspace(), _777); }); - it('has error writing file', function(done) { + it('has error writing file', function (done) { const { compiler, manifest, run } = create( configs.hello(), { @@ -1487,28 +1328,24 @@ describe('WebpackAssetsManifest', function() { webpack, ); - webpack_mkdirp( - compiler.outputFileSystem, - path.dirname(manifest.getOutputPath()), - async err => { - assert.isUndefined(err, 'Error found when creating directory'); + webpack_mkdirp(compiler.outputFileSystem, path.dirname(manifest.getOutputPath()), async err => { + assert.isUndefined(err, 'Error found when creating directory'); - fs.writeFileSync(manifest.getOutputPath(), '', { mode: _444 }); + fs.writeFileSync(manifest.getOutputPath(), '', { mode: _444 }); - const error = await run().catch( error => error ); + const error = await run().catch(error => error); - assert.isNotNull(error, 'Permissions error not found'); - assert.equal('EACCES', error.code); + assert.isNotNull(error, 'Permissions error not found'); + assert.equal('EACCES', error.code); - fs.chmodSync(manifest.getOutputPath(), _777); + fs.chmodSync(manifest.getOutputPath(), _777); - done(); - }, - ); + done(); + }); }); }); - describe('Usage with webpack-dev-server', function() { + describe('Usage with webpack-dev-server', function () { let originalEnv; let WebpackDevServer; @@ -1529,15 +1366,11 @@ describe('WebpackAssetsManifest', function() { }); it('inDevServer() should return true', done => { - const { compiler, manifest } = create( - configs.devServer(), - undefined, - webpack, - ); + const { compiler, manifest } = create(configs.devServer(), undefined, webpack); const server = new WebpackDevServer(compiler, getOptions()); - server.listen(8888, 'localhost', function() { + server.listen(8888, 'localhost', function () { server.close(); assert.isTrue(manifest.inDevServer()); @@ -1547,37 +1380,31 @@ describe('WebpackAssetsManifest', function() { }); it('Should serve the assets manifest JSON file', done => { - const { compiler } = create( - configs.devServer( configs.tmpDirPath() ), - undefined, - webpack, - ); + const { compiler } = create(configs.devServer(configs.tmpDirPath()), undefined, webpack); const server = new WebpackDevServer(compiler, getOptions()); - server.listen(8888, 'localhost', function() { - superagent - .get('http://localhost:8888/assets/assets-manifest.json') - .end(function(err, res) { - server.close(); + server.listen(8888, 'localhost', function () { + superagent.get('http://localhost:8888/assets/assets-manifest.json').end(function (err, res) { + server.close(); - assert.isNull( err ); + assert.isNull(err); - assert.equal( res.status, 200 ); + assert.equal(res.status, 200); - assert.isAbove( res.text.length, 0, 'res.text.length is zero' ); + assert.isAbove(res.text.length, 0, 'res.text.length is zero'); - done(); - }); + done(); + }); }); }); it('Should write to disk using absolute output path', done => { - const config = configs.devServer( configs.tmpDirPath() ); + const config = configs.devServer(configs.tmpDirPath()); const { compiler, manifest } = create( config, { - output: path.join( config.output.path, 'manifest.json' ), + output: path.join(config.output.path, 'manifest.json'), writeToDisk: true, }, webpack, @@ -1585,20 +1412,18 @@ describe('WebpackAssetsManifest', function() { const server = new WebpackDevServer(compiler, getOptions()); - server.listen(8888, 'localhost', function() { - superagent - .get('http://localhost:8888/assets/manifest.json') - .end(function(err) { - if ( err ) { - throw err; - } + server.listen(8888, 'localhost', function () { + superagent.get('http://localhost:8888/assets/manifest.json').end(function (err) { + if (err) { + throw err; + } - server.close(); + server.close(); - assert.isTrue(fs.statSync(manifest.getOutputPath()).isFile()); + assert.isTrue(fs.statSync(manifest.getOutputPath()).isFile()); - done(); - }); + done(); + }); }); }); @@ -1613,41 +1438,39 @@ describe('WebpackAssetsManifest', function() { const server = new WebpackDevServer(compiler, getOptions()); - server.listen(8888, 'localhost', function() { - superagent - .get('http://localhost:8888/assets/assets-manifest.json') - .end(function(err) { - if ( err ) { - throw err; - } + server.listen(8888, 'localhost', function () { + superagent.get('http://localhost:8888/assets/assets-manifest.json').end(function (err) { + if (err) { + throw err; + } - server.close(); + server.close(); - assert.isTrue(fs.statSync(manifest.getOutputPath()).isFile()); + assert.isTrue(fs.statSync(manifest.getOutputPath()).isFile()); - fs.unlinkSync(manifest.getOutputPath()); + fs.unlinkSync(manifest.getOutputPath()); - done(); - }); + done(); + }); }); }); }); - describe('Hot module replacement', function() { - it('Should ignore HMR files', function() { + describe('Hot module replacement', function () { + it('Should ignore HMR files', function () { const config = configs.hello(); - const { manifest } = create( config ); + const { manifest } = create(config); manifest.processAssetsByChunkName( { - main: [ 'main.123456.js', '0.123456.hot-update.js' ], + main: ['main.123456.js', '0.123456.hot-update.js'], }, - new Set([ '0.123456.hot-update.js' ]), + new Set(['0.123456.hot-update.js']), ); - assert.equal( manifest.assetNames.get('main.js'), 'main.123456.js' ); - assert.isFalse( [ ...manifest.assetNames.values() ].includes('0.123456.hot-update.js') ); + assert.equal(manifest.assetNames.get('main.js'), 'main.123456.js'); + assert.isFalse([...manifest.assetNames.values()].includes('0.123456.hot-update.js')); }); it('getCompilationAssets() returns assets and HMR Set', () => { @@ -1674,74 +1497,68 @@ describe('WebpackAssetsManifest', function() { }, }); - const { assets, hmrFiles } = manifest.getCompilationAssets( mockCompilation ); + const { assets, hmrFiles } = manifest.getCompilationAssets(mockCompilation); - expect( mockCompilation.getAssets ).to.have.been.called; - expect( assets ).to.be.an('array').that.does.include( mainAsset ).and.to.have.lengthOf(1); - expect( hmrFiles.has( hmrFilename ) ).to.be.true; + expect(mockCompilation.getAssets).to.have.been.called; + expect(assets).to.be.an('array').that.does.include(mainAsset).and.to.have.lengthOf(1); + expect(hmrFiles.has(hmrFilename)).to.be.true; }); }); - describe('Works with css files', function() { + describe('Works with css files', function () { it('Correct filenames are used', async () => { - const { manifest, run } = create( configs.styles() ); + const { manifest, run } = create(configs.styles()); await run(); - expect( manifest.toString() ).to.contain('styles.css'); + expect(manifest.toString()).to.contain('styles.css'); }); }); describe('Works with copy-webpack-plugin', () => { it('Correct filenames are used', async () => { - const { manifest, run } = create( configs.copy() ); + const { manifest, run } = create(configs.copy()); await run(); - expect( manifest.get('readme.md') ).to.equal('readme-copied.md'); + expect(manifest.get('readme.md')).to.equal('readme-copied.md'); }); }); describe('Works with compression-webpack-plugin', () => { it('adds gz filenames to the manifest', async () => { - const { manifest, run } = create( configs.compression() ); + const { manifest, run } = create(configs.compression()); await run(); - expect( manifest.get('main.js.gz') ).to.equal('main.js.gz'); + expect(manifest.get('main.js.gz')).to.equal('main.js.gz'); }); }); describe('Works with webpack-subresource-integrity', () => { it('Uses integrity value from webpack-subresource-integrity plugin', async () => { - const { manifest, run } = create( - configs.sri(), - { - integrity: true, - // When using `webpack-subresource-integrity`, this is ignored unless you - // also specify `integrityPropertyName` as something other than `integrity`. - integrityHashes: [ 'md5' ], - }, - ); + const { manifest, run } = create(configs.sri(), { + integrity: true, + // When using `webpack-subresource-integrity`, this is ignored unless you + // also specify `integrityPropertyName` as something other than `integrity`. + integrityHashes: ['md5'], + }); await run(); - expect( manifest.get('main.js').integrity.startsWith('sha256-') ).to.be.true; + expect(manifest.get('main.js').integrity.startsWith('sha256-')).to.be.true; }); it('Uses integrity value from this plugin', async () => { - const { manifest, run } = create( - configs.sri(), - { - integrity: true, - integrityPropertyName: 'md5', - integrityHashes: [ 'md5' ], - }, - ); + const { manifest, run } = create(configs.sri(), { + integrity: true, + integrityPropertyName: 'md5', + integrityHashes: ['md5'], + }); await run(); - expect( manifest.get('main.js').integrity.startsWith('md5-') ).to.be.true; + expect(manifest.get('main.js').integrity.startsWith('md5-')).to.be.true; }); }); });