Skip to content

Commit

Permalink
Shave another 10 bytes off each gzip file (#5)
Browse files Browse the repository at this point in the history
Shave another 10 bytes off each gzip file
  • Loading branch information
surma committed Sep 13, 2019
2 parents 3ae1f0d + 7c4a54d commit 3d4bb99
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# WebAssembly Feature Detection

A small library (~560B gzip’d) to detect which features of WebAssembly are supported in your current browser.
A small library (~550B gzip’d) to detect which features of WebAssembly are supported in your current browser.

## Installation

Expand Down
22 changes: 10 additions & 12 deletions rollup-plugins/index-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default function({ indexPath, pluginFolder }) {
}

const plugins = await fsp.readdir(rootPluginPath);
const base64s = [];
const sources = await Promise.all(
plugins.map(async plugin => {
const source = await fsp.readFile(
Expand All @@ -41,27 +40,26 @@ export default function({ indexPath, pluginFolder }) {
"",
""
])[1].split(" ");
const module = await compileWat(
`./src/${pluginFolder}/${plugin}/module.wat`,
flags
);
const hexModule = module.toString("hex");
const module = JSON.stringify([
...(await compileWat(
`./src/${pluginFolder}/${plugin}/module.wat`,
flags
))
]);
if (await fileExists(`./src/${pluginFolder}/${plugin}/index.js`)) {
return `
import { default as ${camelCaseify(
plugin
)}_internal } from "./${pluginFolder}/${plugin}/index.js";
export async function ${camelCaseify(plugin)}() {
return (await Promise.all([validate(${JSON.stringify(
hexModule
)}), ${camelCaseify(plugin)}_internal()])).every(x => x);
return (await Promise.all([validate(${module}), ${camelCaseify(
plugin
)}_internal()])).every(x => x);
}
`;
}
return `
export const ${camelCaseify(
plugin
)} = validate.bind(null, ${JSON.stringify(hexModule)});
export const ${camelCaseify(plugin)} = validate.bind(null, ${module});
`;
})
);
Expand Down
6 changes: 2 additions & 4 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
// This function only exists because `WebAssembly.validate` will
// be called quite often and by having our own function terser can give it
// a one-letter name.
export async function validate(hexModule) {
return WebAssembly.validate(
new Uint8Array(hexModule.match(/(.{1,2})/g).map(v => parseInt(v, 16)))
);
export async function validate(module) {
return WebAssembly.validate(new Uint8Array(module));
}

0 comments on commit 3d4bb99

Please sign in to comment.