User:Thundercraft5/sw.js/module-bundler.js

const { pages, mediaWikiPages } = await Promise.all([	new mw.Api.get({ "action": "query", "format": "json", "assert": "user", "meta": "userinfo", "uiprop": "latestcontrib|editcount|changeablegroups|rights|implicitgroups|groups|groupmemberships" }),	new mw.Api.get({ "action": "query", "format": "json", "assert": "user", "prop": "revisions", "generator": "allpages", "rvprop": "ids|content", "rvslots": "*", "gapnamespace": "8", "gaplimit": "max", }).then(({ query: { pages }}) => Object.values(pages).filter(p => p.title.endsWith('.js'))), ]).then(async ([{ query: { userinfo }}, mediaWikiPages]) => {	const pages = await new mw.Api.get({ "action": "query", "format": "json", "assert": "user", "prop": "revisions", "generator": "allpages", "rvprop": "ids|content", "rvslots": "*", "gapprefix": userinfo.name + "/", "gapnamespace": "2", "gaplimit": "max", }).then(({ query: { pages }}) => Object.values(pages).filter(p => p.title.endsWith('.js')));

return { pages, mediaWikiPages }; });

let moduleById = {}; for (const module of pages) { moduleById[module.title] = module.revisions[0].slots.main["*"]; }

const absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|\/])/; const relativePath = /^\.?\.\//;

function isAbsolute(path) { return absolutePath.test(path); }

function isRelative(path) { return relativePath.test(path); }

function basename(path) { return path.split(/(\/|\\)/).pop; }

function dirname(path) { const match = /(\/|\\)[^\/\\]*$/.exec(path); if (!match) return '.';

const dir = path.slice(0, -match[0].length);

// If `dir` is the empty string, we're at root. return dir ? dir : '/'; }

function extname(path) { const match = /\.[^\.]+$/.exec(basename(path)); if (!match) return ''; return match[0]; } function relative(from, to) { const fromParts = from.split(/[\/\\]/).filter(Boolean); const toParts = to.split(/[\/\\]/).filter(Boolean);

while (fromParts[0] && toParts[0] && fromParts[0] === toParts[0]) { fromParts.shift; toParts.shift; }

while (toParts[0] === '.' || toParts[0] === '..') { const toPart = toParts.shift; if (toPart === '..') { fromParts.pop; }	}

while (fromParts.pop) { toParts.unshift('..'); }

return toParts.join('/'); }

function resolve(...paths) { let resolvedParts = paths.shift.split(/[\/\\]/);

paths.forEach(path => {		if (isAbsolute(path)) {			resolvedParts = path.split(/[\/\\]/);		} else {			const parts = path.split(/[\/\\]/);

while (parts[0] === '.' || parts[0] === '..') { const part = parts.shift; if (part === '..') { resolvedParts.pop; }			}

resolvedParts.push.apply(resolvedParts, parts); }	});

return resolvedParts.join('/'); }

const inputOptions = { plugins: [ {			resolveId(importee, importer) { if (!importer) return importee; if (importee[0] !== '.') return false;

let resolved = resolve(dirname(importer), importee).replace(/^\.\//, ''); if (resolved in moduleById) return resolved;

resolved += '.js'; if (resolved in moduleById) return resolved;

throw new Error(`Could not resolve '${importee}' from '${importer}'.`); },			load(id) { console.log(moduleById); return moduleById[id]; }		}	],	onwarn(warning) { console.warn(warning); }, }; inputOptions.input = ["User:Thundercraft5/sw.js/module.js"]; (await (await rollup.rollup(inputOptions)).generate({ format: "es" })).output[0].code;