mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-11 16:26:20 +00:00
Moar prettier
This commit is contained in:
@@ -10,11 +10,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { promises as fs } from 'fs';
|
||||
import { basename } from 'path';
|
||||
import { promises as fs } from "fs";
|
||||
import { basename } from "path";
|
||||
|
||||
const defaultOpts = {
|
||||
prefix: 'asset-url',
|
||||
prefix: "asset-url"
|
||||
};
|
||||
|
||||
export default function assetPlugin(opts) {
|
||||
@@ -23,9 +23,9 @@ export default function assetPlugin(opts) {
|
||||
/** @type {Map<string, Buffer>} */
|
||||
let assetIdToSourceBuffer;
|
||||
|
||||
const prefix = opts.prefix + ':';
|
||||
const prefix = opts.prefix + ":";
|
||||
return {
|
||||
name: 'asset-plugin',
|
||||
name: "asset-plugin",
|
||||
buildStart() {
|
||||
assetIdToSourceBuffer = new Map();
|
||||
},
|
||||
@@ -56,20 +56,20 @@ export default function assetPlugin(opts) {
|
||||
throw Error(`Cannot find ${realId}`);
|
||||
}
|
||||
// Add an additional .js to the end so it ends up with .js at the end in the _virtual folder.
|
||||
return prefix + resolveResult.id + '.js';
|
||||
return prefix + resolveResult.id + ".js";
|
||||
},
|
||||
async load(id) {
|
||||
if (!id.startsWith(prefix)) return;
|
||||
const realId = id.slice(prefix.length, -'.js'.length);
|
||||
const realId = id.slice(prefix.length, -".js".length);
|
||||
const source = await fs.readFile(realId);
|
||||
assetIdToSourceBuffer.set(id, source);
|
||||
this.addWatchFile(realId);
|
||||
|
||||
return `export default import.meta.ROLLUP_FILE_URL_${this.emitFile({
|
||||
type: 'asset',
|
||||
type: "asset",
|
||||
source,
|
||||
name: basename(realId),
|
||||
name: basename(realId)
|
||||
})}`;
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ export default function ejsAssetPlugin() {
|
||||
for (const [key, value] of Object.entries(JSON.parse(source))) {
|
||||
code += `
|
||||
export const ${key} = ${JSON.stringify(value)};
|
||||
`
|
||||
`;
|
||||
}
|
||||
return code;
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ function instantiateEmscriptenWasm(factory, path) {
|
||||
locateFile() {
|
||||
return path;
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
|
||||
@@ -4,4 +4,4 @@ export default class ImageData {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import { program } from "commander";
|
||||
import JSON5 from "json5";
|
||||
import {
|
||||
Worker,
|
||||
isMainThread,
|
||||
parentPort
|
||||
} from "worker_threads";
|
||||
import { Worker, isMainThread, parentPort } from "worker_threads";
|
||||
import { cpus } from "os";
|
||||
import { extname, join, basename } from "path";
|
||||
import { promises as fsp } from "fs";
|
||||
@@ -131,10 +127,7 @@ async function processFiles(files) {
|
||||
value.defaultEncoderOptions,
|
||||
JSON5.parse(program[encName])
|
||||
);
|
||||
const outputFile = join(
|
||||
program.outputDir,
|
||||
`${base}.${value.extension}`
|
||||
);
|
||||
const outputFile = join(program.outputDir, `${base}.${value.extension}`);
|
||||
jobs.push(
|
||||
jobPromise(pool[i], {
|
||||
bitmap,
|
||||
|
||||
Reference in New Issue
Block a user