From 38f534ff7a396d205e2843dff1d9874b92cbfc07 Mon Sep 17 00:00:00 2001 From: Franklin Tse Date: Tue, 28 Aug 2018 13:20:09 +0800 Subject: [PATCH] Bug fix; Add test cases --- types/webpack-assets-manifest/index.d.ts | 2 +- types/webpack-assets-manifest/tsconfig.json | 1 + types/webpack-assets-manifest/tslint.json | 9 +- .../webpack-assets-manifest-tests.ts | 103 ++++++++++++++++++ 4 files changed, 113 insertions(+), 2 deletions(-) diff --git a/types/webpack-assets-manifest/index.d.ts b/types/webpack-assets-manifest/index.d.ts index 488de0050f..c428d36294 100644 --- a/types/webpack-assets-manifest/index.d.ts +++ b/types/webpack-assets-manifest/index.d.ts @@ -98,7 +98,7 @@ declare namespace WebpackAssetsManifest { fileExtRegex?: RegExp | null | false; /** https://github.com/webdeveric/webpack-assets-manifest#sortmanifest */ - sortManifest?: boolean | ((a: any, b: any) => number); + sortManifest?: boolean | ((this: WebpackAssetsManifest, a: string, b: string) => number); /** https://github.com/webdeveric/webpack-assets-manifest#merge */ merge?: boolean | "customize"; diff --git a/types/webpack-assets-manifest/tsconfig.json b/types/webpack-assets-manifest/tsconfig.json index cbd18f692e..624eb9f943 100644 --- a/types/webpack-assets-manifest/tsconfig.json +++ b/types/webpack-assets-manifest/tsconfig.json @@ -8,6 +8,7 @@ "noImplicitThis": true, "strictNullChecks": true, "strictFunctionTypes": true, + "esModuleInterop": true, "baseUrl": "../", "typeRoots": [ "../" diff --git a/types/webpack-assets-manifest/tslint.json b/types/webpack-assets-manifest/tslint.json index b4b47a0378..369725d5a4 100644 --- a/types/webpack-assets-manifest/tslint.json +++ b/types/webpack-assets-manifest/tslint.json @@ -1,3 +1,10 @@ { - "extends": "dtslint/dt.json" + "extends": "dtslint/dt.json", + "rules": { + "indent": [ + true, + "tabs", + 4 + ] + } } diff --git a/types/webpack-assets-manifest/webpack-assets-manifest-tests.ts b/types/webpack-assets-manifest/webpack-assets-manifest-tests.ts index e69de29bb2..70436291a7 100644 --- a/types/webpack-assets-manifest/webpack-assets-manifest-tests.ts +++ b/types/webpack-assets-manifest/webpack-assets-manifest-tests.ts @@ -0,0 +1,103 @@ +import WebpackAssetsManifest from "webpack-assets-manifest"; + +/** https://github.com/webdeveric/webpack-assets-manifest/blob/master/examples/asset-integrity.js */ +new WebpackAssetsManifest({ + output: 'asset-integrity-manifest.json', + integrity: true, + publicPath: true, + customize(entry, original, manifest, asset) { + return { + key: entry.value, + value: asset && asset.integrity, + }; + }, +}); + +/** https://github.com/webdeveric/webpack-assets-manifest/blob/master/examples/aws-s3-data-integrity.js */ +new WebpackAssetsManifest({ + output: 'aws-s3-data-integrity-manifest.json', + integrity: true, + integrityHashes: ['md5'], + integrityPropertyName: 'md5', + publicPath: 's3://some-bucket/some-folder/', + customize(entry, original, manifest, asset) { + return { + key: entry.value, + value: asset && asset.md5.substr(4), + }; + }, +}); + +/** https://github.com/webdeveric/webpack-assets-manifest/blob/master/examples/custom-cdn.js */ +new WebpackAssetsManifest({ + output: 'custom-cdn-manifest.json', + publicPath(filename, manifest) { + switch (manifest.getExtension(filename).substr(1).toLowerCase()) { + case 'jpg': case 'jpeg': case 'gif': case 'png': case 'svg': + return `https://img.cdn.example.com/${filename}`; + case 'css': + return `https://css.cdn.example.com/${filename}`; + case 'js': + return `https://js.cdn.example.com/${filename}`; + default: + return `https://cdn.example.com/${filename}`; + } + }, +}); + +/** https://github.com/webdeveric/webpack-assets-manifest/blob/master/examples/customized.js https://github.com/webdeveric/webpack-assets-manifest/blob/master/examples/merged.js */ +new WebpackAssetsManifest({ + output: 'customized-manifest.json', + merge: true, + customize(entry, original, manifest, asset) { + if (manifest.isMerging) {} + + if (entry.key.toLowerCase().endsWith('.map')) { + return false; + } + + return { + key: `src/${entry.key}`, + value: `dist/${entry.value}`, + }; + }, +}); + +/** https://github.com/webdeveric/webpack-assets-manifest/blob/master/examples/sorted.js */ +new WebpackAssetsManifest({ + output: 'sorted-manifest.json', + sortManifest(a, b) { + const extA = this.getExtension(a); + const extB = this.getExtension(b); + + if (extA > extB) { + return 1; + } + + if (extA < extB) { + return -1; + } + + return a.localeCompare(b); + }, +}); + +/** https://github.com/webdeveric/webpack-assets-manifest/blob/master/examples/transformed.js */ +new WebpackAssetsManifest({ + output: 'transformed-manifest.json', + transform(assets, manifest) { + const { name, version } = require('./package.json'); + + assets.package = { + name, + version, + }; + + const { key, value } = manifest.hooks.customize.call({ + key: 'YourKey', + value: 'YourValue', + }); + + assets[key] = value; + }, +});