@sveltejs/kit
Advanced tools
Comparing version
@@ -21,3 +21,3 @@ import { router, renderer } from '../internal/singletons.js'; | ||
* noscroll?: boolean; | ||
* resplaceState?: boolean; | ||
* replaceState?: boolean; | ||
* }} [opts] | ||
@@ -37,11 +37,7 @@ */ | ||
const matching = pathnames | ||
? router.routes.filter((route) => pathnames.some((pathname) => route.pattern.test(pathname))) | ||
? router.routes.filter((route) => pathnames.some((pathname) => route[0].test(pathname))) | ||
: router.routes; | ||
console.log(matching); | ||
const promises = matching.map((r) => r.length !== 1 && Promise.all(r[1].map((load) => load()))); | ||
const promises = matching.map( | ||
(r) => r.type === 'page' && Promise.all(r.parts.map((load) => load())) | ||
); | ||
await Promise.all(promises); | ||
@@ -48,0 +44,0 @@ } |
@@ -8,7 +8,2 @@ import Root from '../../generated/root.svelte'; | ||
/** @param {MouseEvent} event */ | ||
function which(event) { | ||
return event.which === null ? event.button : event.which; | ||
} | ||
function scroll_state() { | ||
@@ -82,3 +77,3 @@ return { | ||
// MIT license https://github.com/visionmedia/page.js#license | ||
if (which(event) !== 1) return; | ||
if (event.button || event.which !== 1) return; | ||
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; | ||
@@ -154,3 +149,3 @@ if (event.defaultPrevented) return; | ||
const routes = this.routes.filter((route) => route.pattern.test(path)); | ||
const routes = this.routes.filter(([pattern]) => pattern.test(path)); | ||
@@ -508,4 +503,5 @@ if (routes.length > 0) { | ||
const route = info.routes[i]; | ||
const [pattern, parts, params] = route; | ||
if (route.type === 'endpoint') { | ||
if (route.length === 1) { | ||
return { reload: true }; | ||
@@ -519,4 +515,4 @@ } | ||
const next = info.routes[j]; | ||
if (next.pattern.toString() === route.pattern.toString()) { | ||
if (next.type === 'page') next.parts.forEach((loader) => loader()); | ||
if (next[0].toString() === pattern.toString()) { | ||
if (next.length !== 1) next[1].forEach((loader) => loader()); | ||
j += 1; | ||
@@ -528,7 +524,7 @@ } else { | ||
const nodes = route.parts.map((loader) => loader()); | ||
const nodes = parts.map((loader) => loader()); | ||
const page = { | ||
host: this.host, | ||
path: info.path, | ||
params: route.params(route.pattern.exec(info.path)), | ||
params: params ? params(route[0].exec(info.path)) : {}, | ||
query: info.query | ||
@@ -535,0 +531,0 @@ }; |
# @sveltejs/kit | ||
## 1.0.0-next.56 | ||
### Patch Changes | ||
- 82cbe2b: Shrink client manifest | ||
- 8024178: remove @sveltejs/app-utils | ||
## 1.0.0-next.55 | ||
@@ -4,0 +11,0 @@ |
@@ -1,246 +0,570 @@ | ||
function read_only_form_data() { | ||
/** @type {Map<string, string[]>} */ | ||
const map = new Map(); | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { M as Mime_1, s as standard } from './standard.js'; | ||
import { mkdirp } from '../filesystem.js'; | ||
return { | ||
/** | ||
* @param {string} key | ||
* @param {string} value | ||
*/ | ||
append(key, value) { | ||
if (map.has(key)) { | ||
map.get(key).push(value); | ||
var other = {"application/prs.cww":["cww"],"application/vnd.1000minds.decision-model+xml":["1km"],"application/vnd.3gpp.pic-bw-large":["plb"],"application/vnd.3gpp.pic-bw-small":["psb"],"application/vnd.3gpp.pic-bw-var":["pvb"],"application/vnd.3gpp2.tcap":["tcap"],"application/vnd.3m.post-it-notes":["pwn"],"application/vnd.accpac.simply.aso":["aso"],"application/vnd.accpac.simply.imp":["imp"],"application/vnd.acucobol":["acu"],"application/vnd.acucorp":["atc","acutc"],"application/vnd.adobe.air-application-installer-package+zip":["air"],"application/vnd.adobe.formscentral.fcdt":["fcdt"],"application/vnd.adobe.fxp":["fxp","fxpl"],"application/vnd.adobe.xdp+xml":["xdp"],"application/vnd.adobe.xfdf":["xfdf"],"application/vnd.ahead.space":["ahead"],"application/vnd.airzip.filesecure.azf":["azf"],"application/vnd.airzip.filesecure.azs":["azs"],"application/vnd.amazon.ebook":["azw"],"application/vnd.americandynamics.acc":["acc"],"application/vnd.amiga.ami":["ami"],"application/vnd.android.package-archive":["apk"],"application/vnd.anser-web-certificate-issue-initiation":["cii"],"application/vnd.anser-web-funds-transfer-initiation":["fti"],"application/vnd.antix.game-component":["atx"],"application/vnd.apple.installer+xml":["mpkg"],"application/vnd.apple.keynote":["key"],"application/vnd.apple.mpegurl":["m3u8"],"application/vnd.apple.numbers":["numbers"],"application/vnd.apple.pages":["pages"],"application/vnd.apple.pkpass":["pkpass"],"application/vnd.aristanetworks.swi":["swi"],"application/vnd.astraea-software.iota":["iota"],"application/vnd.audiograph":["aep"],"application/vnd.balsamiq.bmml+xml":["bmml"],"application/vnd.blueice.multipass":["mpm"],"application/vnd.bmi":["bmi"],"application/vnd.businessobjects":["rep"],"application/vnd.chemdraw+xml":["cdxml"],"application/vnd.chipnuts.karaoke-mmd":["mmd"],"application/vnd.cinderella":["cdy"],"application/vnd.citationstyles.style+xml":["csl"],"application/vnd.claymore":["cla"],"application/vnd.cloanto.rp9":["rp9"],"application/vnd.clonk.c4group":["c4g","c4d","c4f","c4p","c4u"],"application/vnd.cluetrust.cartomobile-config":["c11amc"],"application/vnd.cluetrust.cartomobile-config-pkg":["c11amz"],"application/vnd.commonspace":["csp"],"application/vnd.contact.cmsg":["cdbcmsg"],"application/vnd.cosmocaller":["cmc"],"application/vnd.crick.clicker":["clkx"],"application/vnd.crick.clicker.keyboard":["clkk"],"application/vnd.crick.clicker.palette":["clkp"],"application/vnd.crick.clicker.template":["clkt"],"application/vnd.crick.clicker.wordbank":["clkw"],"application/vnd.criticaltools.wbs+xml":["wbs"],"application/vnd.ctc-posml":["pml"],"application/vnd.cups-ppd":["ppd"],"application/vnd.curl.car":["car"],"application/vnd.curl.pcurl":["pcurl"],"application/vnd.dart":["dart"],"application/vnd.data-vision.rdz":["rdz"],"application/vnd.dbf":["dbf"],"application/vnd.dece.data":["uvf","uvvf","uvd","uvvd"],"application/vnd.dece.ttml+xml":["uvt","uvvt"],"application/vnd.dece.unspecified":["uvx","uvvx"],"application/vnd.dece.zip":["uvz","uvvz"],"application/vnd.denovo.fcselayout-link":["fe_launch"],"application/vnd.dna":["dna"],"application/vnd.dolby.mlp":["mlp"],"application/vnd.dpgraph":["dpg"],"application/vnd.dreamfactory":["dfac"],"application/vnd.ds-keypoint":["kpxx"],"application/vnd.dvb.ait":["ait"],"application/vnd.dvb.service":["svc"],"application/vnd.dynageo":["geo"],"application/vnd.ecowin.chart":["mag"],"application/vnd.enliven":["nml"],"application/vnd.epson.esf":["esf"],"application/vnd.epson.msf":["msf"],"application/vnd.epson.quickanime":["qam"],"application/vnd.epson.salt":["slt"],"application/vnd.epson.ssf":["ssf"],"application/vnd.eszigno3+xml":["es3","et3"],"application/vnd.ezpix-album":["ez2"],"application/vnd.ezpix-package":["ez3"],"application/vnd.fdf":["fdf"],"application/vnd.fdsn.mseed":["mseed"],"application/vnd.fdsn.seed":["seed","dataless"],"application/vnd.flographit":["gph"],"application/vnd.fluxtime.clip":["ftc"],"application/vnd.framemaker":["fm","frame","maker","book"],"application/vnd.frogans.fnc":["fnc"],"application/vnd.frogans.ltf":["ltf"],"application/vnd.fsc.weblaunch":["fsc"],"application/vnd.fujitsu.oasys":["oas"],"application/vnd.fujitsu.oasys2":["oa2"],"application/vnd.fujitsu.oasys3":["oa3"],"application/vnd.fujitsu.oasysgp":["fg5"],"application/vnd.fujitsu.oasysprs":["bh2"],"application/vnd.fujixerox.ddd":["ddd"],"application/vnd.fujixerox.docuworks":["xdw"],"application/vnd.fujixerox.docuworks.binder":["xbd"],"application/vnd.fuzzysheet":["fzs"],"application/vnd.genomatix.tuxedo":["txd"],"application/vnd.geogebra.file":["ggb"],"application/vnd.geogebra.tool":["ggt"],"application/vnd.geometry-explorer":["gex","gre"],"application/vnd.geonext":["gxt"],"application/vnd.geoplan":["g2w"],"application/vnd.geospace":["g3w"],"application/vnd.gmx":["gmx"],"application/vnd.google-apps.document":["gdoc"],"application/vnd.google-apps.presentation":["gslides"],"application/vnd.google-apps.spreadsheet":["gsheet"],"application/vnd.google-earth.kml+xml":["kml"],"application/vnd.google-earth.kmz":["kmz"],"application/vnd.grafeq":["gqf","gqs"],"application/vnd.groove-account":["gac"],"application/vnd.groove-help":["ghf"],"application/vnd.groove-identity-message":["gim"],"application/vnd.groove-injector":["grv"],"application/vnd.groove-tool-message":["gtm"],"application/vnd.groove-tool-template":["tpl"],"application/vnd.groove-vcard":["vcg"],"application/vnd.hal+xml":["hal"],"application/vnd.handheld-entertainment+xml":["zmm"],"application/vnd.hbci":["hbci"],"application/vnd.hhe.lesson-player":["les"],"application/vnd.hp-hpgl":["hpgl"],"application/vnd.hp-hpid":["hpid"],"application/vnd.hp-hps":["hps"],"application/vnd.hp-jlyt":["jlt"],"application/vnd.hp-pcl":["pcl"],"application/vnd.hp-pclxl":["pclxl"],"application/vnd.hydrostatix.sof-data":["sfd-hdstx"],"application/vnd.ibm.minipay":["mpy"],"application/vnd.ibm.modcap":["afp","listafp","list3820"],"application/vnd.ibm.rights-management":["irm"],"application/vnd.ibm.secure-container":["sc"],"application/vnd.iccprofile":["icc","icm"],"application/vnd.igloader":["igl"],"application/vnd.immervision-ivp":["ivp"],"application/vnd.immervision-ivu":["ivu"],"application/vnd.insors.igm":["igm"],"application/vnd.intercon.formnet":["xpw","xpx"],"application/vnd.intergeo":["i2g"],"application/vnd.intu.qbo":["qbo"],"application/vnd.intu.qfx":["qfx"],"application/vnd.ipunplugged.rcprofile":["rcprofile"],"application/vnd.irepository.package+xml":["irp"],"application/vnd.is-xpr":["xpr"],"application/vnd.isac.fcs":["fcs"],"application/vnd.jam":["jam"],"application/vnd.jcp.javame.midlet-rms":["rms"],"application/vnd.jisp":["jisp"],"application/vnd.joost.joda-archive":["joda"],"application/vnd.kahootz":["ktz","ktr"],"application/vnd.kde.karbon":["karbon"],"application/vnd.kde.kchart":["chrt"],"application/vnd.kde.kformula":["kfo"],"application/vnd.kde.kivio":["flw"],"application/vnd.kde.kontour":["kon"],"application/vnd.kde.kpresenter":["kpr","kpt"],"application/vnd.kde.kspread":["ksp"],"application/vnd.kde.kword":["kwd","kwt"],"application/vnd.kenameaapp":["htke"],"application/vnd.kidspiration":["kia"],"application/vnd.kinar":["kne","knp"],"application/vnd.koan":["skp","skd","skt","skm"],"application/vnd.kodak-descriptor":["sse"],"application/vnd.las.las+xml":["lasxml"],"application/vnd.llamagraphics.life-balance.desktop":["lbd"],"application/vnd.llamagraphics.life-balance.exchange+xml":["lbe"],"application/vnd.lotus-1-2-3":["123"],"application/vnd.lotus-approach":["apr"],"application/vnd.lotus-freelance":["pre"],"application/vnd.lotus-notes":["nsf"],"application/vnd.lotus-organizer":["org"],"application/vnd.lotus-screencam":["scm"],"application/vnd.lotus-wordpro":["lwp"],"application/vnd.macports.portpkg":["portpkg"],"application/vnd.mcd":["mcd"],"application/vnd.medcalcdata":["mc1"],"application/vnd.mediastation.cdkey":["cdkey"],"application/vnd.mfer":["mwf"],"application/vnd.mfmp":["mfm"],"application/vnd.micrografx.flo":["flo"],"application/vnd.micrografx.igx":["igx"],"application/vnd.mif":["mif"],"application/vnd.mobius.daf":["daf"],"application/vnd.mobius.dis":["dis"],"application/vnd.mobius.mbk":["mbk"],"application/vnd.mobius.mqy":["mqy"],"application/vnd.mobius.msl":["msl"],"application/vnd.mobius.plc":["plc"],"application/vnd.mobius.txf":["txf"],"application/vnd.mophun.application":["mpn"],"application/vnd.mophun.certificate":["mpc"],"application/vnd.mozilla.xul+xml":["xul"],"application/vnd.ms-artgalry":["cil"],"application/vnd.ms-cab-compressed":["cab"],"application/vnd.ms-excel":["xls","xlm","xla","xlc","xlt","xlw"],"application/vnd.ms-excel.addin.macroenabled.12":["xlam"],"application/vnd.ms-excel.sheet.binary.macroenabled.12":["xlsb"],"application/vnd.ms-excel.sheet.macroenabled.12":["xlsm"],"application/vnd.ms-excel.template.macroenabled.12":["xltm"],"application/vnd.ms-fontobject":["eot"],"application/vnd.ms-htmlhelp":["chm"],"application/vnd.ms-ims":["ims"],"application/vnd.ms-lrm":["lrm"],"application/vnd.ms-officetheme":["thmx"],"application/vnd.ms-outlook":["msg"],"application/vnd.ms-pki.seccat":["cat"],"application/vnd.ms-pki.stl":["*stl"],"application/vnd.ms-powerpoint":["ppt","pps","pot"],"application/vnd.ms-powerpoint.addin.macroenabled.12":["ppam"],"application/vnd.ms-powerpoint.presentation.macroenabled.12":["pptm"],"application/vnd.ms-powerpoint.slide.macroenabled.12":["sldm"],"application/vnd.ms-powerpoint.slideshow.macroenabled.12":["ppsm"],"application/vnd.ms-powerpoint.template.macroenabled.12":["potm"],"application/vnd.ms-project":["mpp","mpt"],"application/vnd.ms-word.document.macroenabled.12":["docm"],"application/vnd.ms-word.template.macroenabled.12":["dotm"],"application/vnd.ms-works":["wps","wks","wcm","wdb"],"application/vnd.ms-wpl":["wpl"],"application/vnd.ms-xpsdocument":["xps"],"application/vnd.mseq":["mseq"],"application/vnd.musician":["mus"],"application/vnd.muvee.style":["msty"],"application/vnd.mynfc":["taglet"],"application/vnd.neurolanguage.nlu":["nlu"],"application/vnd.nitf":["ntf","nitf"],"application/vnd.noblenet-directory":["nnd"],"application/vnd.noblenet-sealer":["nns"],"application/vnd.noblenet-web":["nnw"],"application/vnd.nokia.n-gage.ac+xml":["*ac"],"application/vnd.nokia.n-gage.data":["ngdat"],"application/vnd.nokia.n-gage.symbian.install":["n-gage"],"application/vnd.nokia.radio-preset":["rpst"],"application/vnd.nokia.radio-presets":["rpss"],"application/vnd.novadigm.edm":["edm"],"application/vnd.novadigm.edx":["edx"],"application/vnd.novadigm.ext":["ext"],"application/vnd.oasis.opendocument.chart":["odc"],"application/vnd.oasis.opendocument.chart-template":["otc"],"application/vnd.oasis.opendocument.database":["odb"],"application/vnd.oasis.opendocument.formula":["odf"],"application/vnd.oasis.opendocument.formula-template":["odft"],"application/vnd.oasis.opendocument.graphics":["odg"],"application/vnd.oasis.opendocument.graphics-template":["otg"],"application/vnd.oasis.opendocument.image":["odi"],"application/vnd.oasis.opendocument.image-template":["oti"],"application/vnd.oasis.opendocument.presentation":["odp"],"application/vnd.oasis.opendocument.presentation-template":["otp"],"application/vnd.oasis.opendocument.spreadsheet":["ods"],"application/vnd.oasis.opendocument.spreadsheet-template":["ots"],"application/vnd.oasis.opendocument.text":["odt"],"application/vnd.oasis.opendocument.text-master":["odm"],"application/vnd.oasis.opendocument.text-template":["ott"],"application/vnd.oasis.opendocument.text-web":["oth"],"application/vnd.olpc-sugar":["xo"],"application/vnd.oma.dd2+xml":["dd2"],"application/vnd.openblox.game+xml":["obgx"],"application/vnd.openofficeorg.extension":["oxt"],"application/vnd.openstreetmap.data+xml":["osm"],"application/vnd.openxmlformats-officedocument.presentationml.presentation":["pptx"],"application/vnd.openxmlformats-officedocument.presentationml.slide":["sldx"],"application/vnd.openxmlformats-officedocument.presentationml.slideshow":["ppsx"],"application/vnd.openxmlformats-officedocument.presentationml.template":["potx"],"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":["xlsx"],"application/vnd.openxmlformats-officedocument.spreadsheetml.template":["xltx"],"application/vnd.openxmlformats-officedocument.wordprocessingml.document":["docx"],"application/vnd.openxmlformats-officedocument.wordprocessingml.template":["dotx"],"application/vnd.osgeo.mapguide.package":["mgp"],"application/vnd.osgi.dp":["dp"],"application/vnd.osgi.subsystem":["esa"],"application/vnd.palm":["pdb","pqa","oprc"],"application/vnd.pawaafile":["paw"],"application/vnd.pg.format":["str"],"application/vnd.pg.osasli":["ei6"],"application/vnd.picsel":["efif"],"application/vnd.pmi.widget":["wg"],"application/vnd.pocketlearn":["plf"],"application/vnd.powerbuilder6":["pbd"],"application/vnd.previewsystems.box":["box"],"application/vnd.proteus.magazine":["mgz"],"application/vnd.publishare-delta-tree":["qps"],"application/vnd.pvi.ptid1":["ptid"],"application/vnd.quark.quarkxpress":["qxd","qxt","qwd","qwt","qxl","qxb"],"application/vnd.rar":["rar"],"application/vnd.realvnc.bed":["bed"],"application/vnd.recordare.musicxml":["mxl"],"application/vnd.recordare.musicxml+xml":["musicxml"],"application/vnd.rig.cryptonote":["cryptonote"],"application/vnd.rim.cod":["cod"],"application/vnd.rn-realmedia":["rm"],"application/vnd.rn-realmedia-vbr":["rmvb"],"application/vnd.route66.link66+xml":["link66"],"application/vnd.sailingtracker.track":["st"],"application/vnd.seemail":["see"],"application/vnd.sema":["sema"],"application/vnd.semd":["semd"],"application/vnd.semf":["semf"],"application/vnd.shana.informed.formdata":["ifm"],"application/vnd.shana.informed.formtemplate":["itp"],"application/vnd.shana.informed.interchange":["iif"],"application/vnd.shana.informed.package":["ipk"],"application/vnd.simtech-mindmapper":["twd","twds"],"application/vnd.smaf":["mmf"],"application/vnd.smart.teacher":["teacher"],"application/vnd.software602.filler.form+xml":["fo"],"application/vnd.solent.sdkm+xml":["sdkm","sdkd"],"application/vnd.spotfire.dxp":["dxp"],"application/vnd.spotfire.sfs":["sfs"],"application/vnd.stardivision.calc":["sdc"],"application/vnd.stardivision.draw":["sda"],"application/vnd.stardivision.impress":["sdd"],"application/vnd.stardivision.math":["smf"],"application/vnd.stardivision.writer":["sdw","vor"],"application/vnd.stardivision.writer-global":["sgl"],"application/vnd.stepmania.package":["smzip"],"application/vnd.stepmania.stepchart":["sm"],"application/vnd.sun.wadl+xml":["wadl"],"application/vnd.sun.xml.calc":["sxc"],"application/vnd.sun.xml.calc.template":["stc"],"application/vnd.sun.xml.draw":["sxd"],"application/vnd.sun.xml.draw.template":["std"],"application/vnd.sun.xml.impress":["sxi"],"application/vnd.sun.xml.impress.template":["sti"],"application/vnd.sun.xml.math":["sxm"],"application/vnd.sun.xml.writer":["sxw"],"application/vnd.sun.xml.writer.global":["sxg"],"application/vnd.sun.xml.writer.template":["stw"],"application/vnd.sus-calendar":["sus","susp"],"application/vnd.svd":["svd"],"application/vnd.symbian.install":["sis","sisx"],"application/vnd.syncml+xml":["xsm"],"application/vnd.syncml.dm+wbxml":["bdm"],"application/vnd.syncml.dm+xml":["xdm"],"application/vnd.syncml.dmddf+xml":["ddf"],"application/vnd.tao.intent-module-archive":["tao"],"application/vnd.tcpdump.pcap":["pcap","cap","dmp"],"application/vnd.tmobile-livetv":["tmo"],"application/vnd.trid.tpt":["tpt"],"application/vnd.triscape.mxs":["mxs"],"application/vnd.trueapp":["tra"],"application/vnd.ufdl":["ufd","ufdl"],"application/vnd.uiq.theme":["utz"],"application/vnd.umajin":["umj"],"application/vnd.unity":["unityweb"],"application/vnd.uoml+xml":["uoml"],"application/vnd.vcx":["vcx"],"application/vnd.visio":["vsd","vst","vss","vsw"],"application/vnd.visionary":["vis"],"application/vnd.vsf":["vsf"],"application/vnd.wap.wbxml":["wbxml"],"application/vnd.wap.wmlc":["wmlc"],"application/vnd.wap.wmlscriptc":["wmlsc"],"application/vnd.webturbo":["wtb"],"application/vnd.wolfram.player":["nbp"],"application/vnd.wordperfect":["wpd"],"application/vnd.wqd":["wqd"],"application/vnd.wt.stf":["stf"],"application/vnd.xara":["xar"],"application/vnd.xfdl":["xfdl"],"application/vnd.yamaha.hv-dic":["hvd"],"application/vnd.yamaha.hv-script":["hvs"],"application/vnd.yamaha.hv-voice":["hvp"],"application/vnd.yamaha.openscoreformat":["osf"],"application/vnd.yamaha.openscoreformat.osfpvg+xml":["osfpvg"],"application/vnd.yamaha.smaf-audio":["saf"],"application/vnd.yamaha.smaf-phrase":["spf"],"application/vnd.yellowriver-custom-menu":["cmp"],"application/vnd.zul":["zir","zirz"],"application/vnd.zzazz.deck+xml":["zaz"],"application/x-7z-compressed":["7z"],"application/x-abiword":["abw"],"application/x-ace-compressed":["ace"],"application/x-apple-diskimage":["*dmg"],"application/x-arj":["arj"],"application/x-authorware-bin":["aab","x32","u32","vox"],"application/x-authorware-map":["aam"],"application/x-authorware-seg":["aas"],"application/x-bcpio":["bcpio"],"application/x-bdoc":["*bdoc"],"application/x-bittorrent":["torrent"],"application/x-blorb":["blb","blorb"],"application/x-bzip":["bz"],"application/x-bzip2":["bz2","boz"],"application/x-cbr":["cbr","cba","cbt","cbz","cb7"],"application/x-cdlink":["vcd"],"application/x-cfs-compressed":["cfs"],"application/x-chat":["chat"],"application/x-chess-pgn":["pgn"],"application/x-chrome-extension":["crx"],"application/x-cocoa":["cco"],"application/x-conference":["nsc"],"application/x-cpio":["cpio"],"application/x-csh":["csh"],"application/x-debian-package":["*deb","udeb"],"application/x-dgc-compressed":["dgc"],"application/x-director":["dir","dcr","dxr","cst","cct","cxt","w3d","fgd","swa"],"application/x-doom":["wad"],"application/x-dtbncx+xml":["ncx"],"application/x-dtbook+xml":["dtb"],"application/x-dtbresource+xml":["res"],"application/x-dvi":["dvi"],"application/x-envoy":["evy"],"application/x-eva":["eva"],"application/x-font-bdf":["bdf"],"application/x-font-ghostscript":["gsf"],"application/x-font-linux-psf":["psf"],"application/x-font-pcf":["pcf"],"application/x-font-snf":["snf"],"application/x-font-type1":["pfa","pfb","pfm","afm"],"application/x-freearc":["arc"],"application/x-futuresplash":["spl"],"application/x-gca-compressed":["gca"],"application/x-glulx":["ulx"],"application/x-gnumeric":["gnumeric"],"application/x-gramps-xml":["gramps"],"application/x-gtar":["gtar"],"application/x-hdf":["hdf"],"application/x-httpd-php":["php"],"application/x-install-instructions":["install"],"application/x-iso9660-image":["*iso"],"application/x-java-archive-diff":["jardiff"],"application/x-java-jnlp-file":["jnlp"],"application/x-keepass2":["kdbx"],"application/x-latex":["latex"],"application/x-lua-bytecode":["luac"],"application/x-lzh-compressed":["lzh","lha"],"application/x-makeself":["run"],"application/x-mie":["mie"],"application/x-mobipocket-ebook":["prc","mobi"],"application/x-ms-application":["application"],"application/x-ms-shortcut":["lnk"],"application/x-ms-wmd":["wmd"],"application/x-ms-wmz":["wmz"],"application/x-ms-xbap":["xbap"],"application/x-msaccess":["mdb"],"application/x-msbinder":["obd"],"application/x-mscardfile":["crd"],"application/x-msclip":["clp"],"application/x-msdos-program":["*exe"],"application/x-msdownload":["*exe","*dll","com","bat","*msi"],"application/x-msmediaview":["mvb","m13","m14"],"application/x-msmetafile":["*wmf","*wmz","*emf","emz"],"application/x-msmoney":["mny"],"application/x-mspublisher":["pub"],"application/x-msschedule":["scd"],"application/x-msterminal":["trm"],"application/x-mswrite":["wri"],"application/x-netcdf":["nc","cdf"],"application/x-ns-proxy-autoconfig":["pac"],"application/x-nzb":["nzb"],"application/x-perl":["pl","pm"],"application/x-pilot":["*prc","*pdb"],"application/x-pkcs12":["p12","pfx"],"application/x-pkcs7-certificates":["p7b","spc"],"application/x-pkcs7-certreqresp":["p7r"],"application/x-rar-compressed":["*rar"],"application/x-redhat-package-manager":["rpm"],"application/x-research-info-systems":["ris"],"application/x-sea":["sea"],"application/x-sh":["sh"],"application/x-shar":["shar"],"application/x-shockwave-flash":["swf"],"application/x-silverlight-app":["xap"],"application/x-sql":["sql"],"application/x-stuffit":["sit"],"application/x-stuffitx":["sitx"],"application/x-subrip":["srt"],"application/x-sv4cpio":["sv4cpio"],"application/x-sv4crc":["sv4crc"],"application/x-t3vm-image":["t3"],"application/x-tads":["gam"],"application/x-tar":["tar"],"application/x-tcl":["tcl","tk"],"application/x-tex":["tex"],"application/x-tex-tfm":["tfm"],"application/x-texinfo":["texinfo","texi"],"application/x-tgif":["*obj"],"application/x-ustar":["ustar"],"application/x-virtualbox-hdd":["hdd"],"application/x-virtualbox-ova":["ova"],"application/x-virtualbox-ovf":["ovf"],"application/x-virtualbox-vbox":["vbox"],"application/x-virtualbox-vbox-extpack":["vbox-extpack"],"application/x-virtualbox-vdi":["vdi"],"application/x-virtualbox-vhd":["vhd"],"application/x-virtualbox-vmdk":["vmdk"],"application/x-wais-source":["src"],"application/x-web-app-manifest+json":["webapp"],"application/x-x509-ca-cert":["der","crt","pem"],"application/x-xfig":["fig"],"application/x-xliff+xml":["*xlf"],"application/x-xpinstall":["xpi"],"application/x-xz":["xz"],"application/x-zmachine":["z1","z2","z3","z4","z5","z6","z7","z8"],"audio/vnd.dece.audio":["uva","uvva"],"audio/vnd.digital-winds":["eol"],"audio/vnd.dra":["dra"],"audio/vnd.dts":["dts"],"audio/vnd.dts.hd":["dtshd"],"audio/vnd.lucent.voice":["lvp"],"audio/vnd.ms-playready.media.pya":["pya"],"audio/vnd.nuera.ecelp4800":["ecelp4800"],"audio/vnd.nuera.ecelp7470":["ecelp7470"],"audio/vnd.nuera.ecelp9600":["ecelp9600"],"audio/vnd.rip":["rip"],"audio/x-aac":["aac"],"audio/x-aiff":["aif","aiff","aifc"],"audio/x-caf":["caf"],"audio/x-flac":["flac"],"audio/x-m4a":["*m4a"],"audio/x-matroska":["mka"],"audio/x-mpegurl":["m3u"],"audio/x-ms-wax":["wax"],"audio/x-ms-wma":["wma"],"audio/x-pn-realaudio":["ram","ra"],"audio/x-pn-realaudio-plugin":["rmp"],"audio/x-realaudio":["*ra"],"audio/x-wav":["*wav"],"chemical/x-cdx":["cdx"],"chemical/x-cif":["cif"],"chemical/x-cmdf":["cmdf"],"chemical/x-cml":["cml"],"chemical/x-csml":["csml"],"chemical/x-xyz":["xyz"],"image/prs.btif":["btif"],"image/prs.pti":["pti"],"image/vnd.adobe.photoshop":["psd"],"image/vnd.airzip.accelerator.azv":["azv"],"image/vnd.dece.graphic":["uvi","uvvi","uvg","uvvg"],"image/vnd.djvu":["djvu","djv"],"image/vnd.dvb.subtitle":["*sub"],"image/vnd.dwg":["dwg"],"image/vnd.dxf":["dxf"],"image/vnd.fastbidsheet":["fbs"],"image/vnd.fpx":["fpx"],"image/vnd.fst":["fst"],"image/vnd.fujixerox.edmics-mmr":["mmr"],"image/vnd.fujixerox.edmics-rlc":["rlc"],"image/vnd.microsoft.icon":["ico"],"image/vnd.ms-dds":["dds"],"image/vnd.ms-modi":["mdi"],"image/vnd.ms-photo":["wdp"],"image/vnd.net-fpx":["npx"],"image/vnd.pco.b16":["b16"],"image/vnd.tencent.tap":["tap"],"image/vnd.valve.source.texture":["vtf"],"image/vnd.wap.wbmp":["wbmp"],"image/vnd.xiff":["xif"],"image/vnd.zbrush.pcx":["pcx"],"image/x-3ds":["3ds"],"image/x-cmu-raster":["ras"],"image/x-cmx":["cmx"],"image/x-freehand":["fh","fhc","fh4","fh5","fh7"],"image/x-icon":["*ico"],"image/x-jng":["jng"],"image/x-mrsid-image":["sid"],"image/x-ms-bmp":["*bmp"],"image/x-pcx":["*pcx"],"image/x-pict":["pic","pct"],"image/x-portable-anymap":["pnm"],"image/x-portable-bitmap":["pbm"],"image/x-portable-graymap":["pgm"],"image/x-portable-pixmap":["ppm"],"image/x-rgb":["rgb"],"image/x-tga":["tga"],"image/x-xbitmap":["xbm"],"image/x-xpixmap":["xpm"],"image/x-xwindowdump":["xwd"],"message/vnd.wfa.wsc":["wsc"],"model/vnd.collada+xml":["dae"],"model/vnd.dwf":["dwf"],"model/vnd.gdl":["gdl"],"model/vnd.gtw":["gtw"],"model/vnd.mts":["mts"],"model/vnd.opengex":["ogex"],"model/vnd.parasolid.transmit.binary":["x_b"],"model/vnd.parasolid.transmit.text":["x_t"],"model/vnd.usdz+zip":["usdz"],"model/vnd.valve.source.compiled-map":["bsp"],"model/vnd.vtu":["vtu"],"text/prs.lines.tag":["dsc"],"text/vnd.curl":["curl"],"text/vnd.curl.dcurl":["dcurl"],"text/vnd.curl.mcurl":["mcurl"],"text/vnd.curl.scurl":["scurl"],"text/vnd.dvb.subtitle":["sub"],"text/vnd.fly":["fly"],"text/vnd.fmi.flexstor":["flx"],"text/vnd.graphviz":["gv"],"text/vnd.in3d.3dml":["3dml"],"text/vnd.in3d.spot":["spot"],"text/vnd.sun.j2me.app-descriptor":["jad"],"text/vnd.wap.wml":["wml"],"text/vnd.wap.wmlscript":["wmls"],"text/x-asm":["s","asm"],"text/x-c":["c","cc","cxx","cpp","h","hh","dic"],"text/x-component":["htc"],"text/x-fortran":["f","for","f77","f90"],"text/x-handlebars-template":["hbs"],"text/x-java-source":["java"],"text/x-lua":["lua"],"text/x-markdown":["mkd"],"text/x-nfo":["nfo"],"text/x-opml":["opml"],"text/x-org":["*org"],"text/x-pascal":["p","pas"],"text/x-processing":["pde"],"text/x-sass":["sass"],"text/x-scss":["scss"],"text/x-setext":["etx"],"text/x-sfv":["sfv"],"text/x-suse-ymp":["ymp"],"text/x-uuencode":["uu"],"text/x-vcalendar":["vcs"],"text/x-vcard":["vcf"],"video/vnd.dece.hd":["uvh","uvvh"],"video/vnd.dece.mobile":["uvm","uvvm"],"video/vnd.dece.pd":["uvp","uvvp"],"video/vnd.dece.sd":["uvs","uvvs"],"video/vnd.dece.video":["uvv","uvvv"],"video/vnd.dvb.file":["dvb"],"video/vnd.fvt":["fvt"],"video/vnd.mpegurl":["mxu","m4u"],"video/vnd.ms-playready.media.pyv":["pyv"],"video/vnd.uvvu.mp4":["uvu","uvvu"],"video/vnd.vivo":["viv"],"video/x-f4v":["f4v"],"video/x-fli":["fli"],"video/x-flv":["flv"],"video/x-m4v":["m4v"],"video/x-matroska":["mkv","mk3d","mks"],"video/x-mng":["mng"],"video/x-ms-asf":["asf","asx"],"video/x-ms-vob":["vob"],"video/x-ms-wm":["wm"],"video/x-ms-wmv":["wmv"],"video/x-ms-wmx":["wmx"],"video/x-ms-wvx":["wvx"],"video/x-msvideo":["avi"],"video/x-sgi-movie":["movie"],"video/x-smv":["smv"],"x-conference/x-cooltalk":["ice"]}; | ||
var mime = new Mime_1(standard, other); | ||
/** @typedef {{ | ||
* content: string; | ||
* dynamic: boolean; | ||
* spread: boolean; | ||
* }} Part */ | ||
/** @typedef {{ | ||
* basename: string; | ||
* ext: string; | ||
* parts: Part[], | ||
* file: string; | ||
* is_dir: boolean; | ||
* is_index: boolean; | ||
* is_page: boolean; | ||
* route_suffix: string | ||
* }} Item */ | ||
/** | ||
* @param {{ | ||
* config: import('types.internal').ValidatedConfig; | ||
* output: string; | ||
* cwd?: string; | ||
* }} opts | ||
* @returns {import('types.internal').ManifestData} | ||
*/ | ||
function create_manifest_data({ config, output, cwd = process.cwd() }) { | ||
/** | ||
* @param {string} file_name | ||
* @param {string} dir | ||
*/ | ||
function find_layout(file_name, dir) { | ||
const files = config.extensions.map((ext) => posixify(path.join(dir, `${file_name}${ext}`))); | ||
return files.find((file) => fs.existsSync(path.resolve(cwd, file))); | ||
} | ||
/** @type {string[]} */ | ||
const components = []; | ||
/** @type {import('types.internal').RouteData[]} */ | ||
const routes = []; | ||
const default_layout = path.relative(cwd, `${output}/components/layout.svelte`); | ||
const default_error = path.relative(cwd, `${output}/components/error.svelte`); | ||
/** | ||
* @param {string} dir | ||
* @param {Part[][]} parent_segments | ||
* @param {string[]} parent_params | ||
* @param {string[]} stack | ||
*/ | ||
function walk(dir, parent_segments, parent_params, stack) { | ||
/** @type {Item[]} */ | ||
const items = fs | ||
.readdirSync(dir) | ||
.map((basename) => { | ||
const resolved = path.join(dir, basename); | ||
const file = posixify(path.relative(cwd, resolved)); | ||
const is_dir = fs.statSync(resolved).isDirectory(); | ||
const ext = | ||
config.extensions.find((ext) => basename.endsWith(ext)) || path.extname(basename); | ||
if (basename[0] === '$') return null; // $layout, $error | ||
if (basename[0] === '_') return null; // private files | ||
if (basename[0] === '.' && basename !== '.well-known') return null; | ||
if (!is_dir && !/^(\.[a-z0-9]+)+$/i.test(ext)) return null; // filter out tmp files etc | ||
const segment = is_dir ? basename : basename.slice(0, -ext.length); | ||
if (/\]\[/.test(segment)) { | ||
throw new Error(`Invalid route ${file} — parameters must be separated`); | ||
} | ||
if (count_occurrences('[', segment) !== count_occurrences(']', segment)) { | ||
throw new Error(`Invalid route ${file} — brackets are unbalanced`); | ||
} | ||
const parts = get_parts(segment, file); | ||
const is_index = is_dir ? false : basename.startsWith('index.'); | ||
const is_page = config.extensions.indexOf(ext) !== -1; | ||
const route_suffix = basename.slice(basename.indexOf('.'), -ext.length); | ||
return { | ||
basename, | ||
ext, | ||
parts, | ||
file: posixify(file), | ||
is_dir, | ||
is_index, | ||
is_page, | ||
route_suffix | ||
}; | ||
}) | ||
.filter(Boolean) | ||
.sort(comparator); | ||
items.forEach((item) => { | ||
const segments = parent_segments.slice(); | ||
if (item.is_index) { | ||
if (item.route_suffix) { | ||
if (segments.length > 0) { | ||
const last_segment = segments[segments.length - 1].slice(); | ||
const last_part = last_segment[last_segment.length - 1]; | ||
if (last_part.dynamic) { | ||
last_segment.push({ | ||
dynamic: false, | ||
spread: false, | ||
content: item.route_suffix | ||
}); | ||
} else { | ||
last_segment[last_segment.length - 1] = { | ||
dynamic: false, | ||
spread: false, | ||
content: `${last_part.content}${item.route_suffix}` | ||
}; | ||
} | ||
segments[segments.length - 1] = last_segment; | ||
} else { | ||
segments.push(item.parts); | ||
} | ||
} | ||
} else { | ||
map.set(key, [value]); | ||
segments.push(item.parts); | ||
} | ||
}, | ||
data: new ReadOnlyFormData(map) | ||
}; | ||
} | ||
const params = parent_params.slice(); | ||
params.push(...item.parts.filter((p) => p.dynamic).map((p) => p.content)); | ||
class ReadOnlyFormData { | ||
/** @type {Map<string, string[]>} */ | ||
#map; | ||
if (item.is_dir) { | ||
const component = find_layout('$layout', item.file); | ||
/** @param {Map<string, string[]>} map */ | ||
constructor(map) { | ||
this.#map = map; | ||
} | ||
if (component) components.push(component); | ||
/** @param {string} key */ | ||
get(key) { | ||
const value = this.#map.get(key); | ||
return value && value[0]; | ||
walk( | ||
path.join(dir, item.basename), | ||
segments, | ||
params, | ||
component ? stack.concat(component) : stack | ||
); | ||
} else if (item.is_page) { | ||
components.push(item.file); | ||
const parts = | ||
item.is_index && stack[stack.length - 1] === null | ||
? stack.slice(0, -1).concat(item.file) | ||
: stack.concat(item.file); | ||
const pattern = get_pattern(segments, true); | ||
routes.push({ | ||
type: 'page', | ||
pattern, | ||
params, | ||
parts | ||
}); | ||
} else { | ||
const pattern = get_pattern(segments, !item.route_suffix); | ||
routes.push({ | ||
type: 'endpoint', | ||
pattern, | ||
file: item.file, | ||
params | ||
}); | ||
} | ||
}); | ||
} | ||
/** @param {string} key */ | ||
getAll(key) { | ||
return this.#map.get(key); | ||
const base = path.relative(cwd, config.kit.files.routes); | ||
const layout = find_layout('$layout', base) || default_layout; | ||
const error = find_layout('$error', base) || default_error; | ||
walk(config.kit.files.routes, [], [], []); | ||
const assets_dir = config.kit.files.assets; | ||
return { | ||
assets: fs.existsSync(assets_dir) ? list_files(assets_dir, '') : [], | ||
layout, | ||
error, | ||
components, | ||
routes | ||
}; | ||
} | ||
/** | ||
* @param {string} needle | ||
* @param {string} haystack | ||
*/ | ||
function count_occurrences(needle, haystack) { | ||
let count = 0; | ||
for (let i = 0; i < haystack.length; i += 1) { | ||
if (haystack[i] === needle) count += 1; | ||
} | ||
return count; | ||
} | ||
/** @param {string} key */ | ||
has(key) { | ||
return this.#map.has(key); | ||
/** @param {string} str */ | ||
function posixify(str) { | ||
return str.replace(/\\/g, '/'); | ||
} | ||
/** @param {string} path */ | ||
function is_spread(path) { | ||
const spread_pattern = /\[\.{3}/g; | ||
return spread_pattern.test(path); | ||
} | ||
/** | ||
* @param {Item} a | ||
* @param {Item} b | ||
*/ | ||
function comparator(a, b) { | ||
if (a.is_index !== b.is_index) { | ||
if (a.is_index) return is_spread(a.file) ? 1 : -1; | ||
return is_spread(b.file) ? -1 : 1; | ||
} | ||
*[Symbol.iterator]() { | ||
for (const [key, value] of this.#map) { | ||
for (let i = 0; i < value.length; i += 1) { | ||
yield [key, value[i]]; | ||
} | ||
const max = Math.max(a.parts.length, b.parts.length); | ||
for (let i = 0; i < max; i += 1) { | ||
const a_sub_part = a.parts[i]; | ||
const b_sub_part = b.parts[i]; | ||
if (!a_sub_part) return 1; // b is more specific, so goes first | ||
if (!b_sub_part) return -1; | ||
// if spread && index, order later | ||
if (a_sub_part.spread && b_sub_part.spread) { | ||
return a.is_index ? 1 : -1; | ||
} | ||
} | ||
*entries() { | ||
for (const [key, value] of this.#map) { | ||
for (let i = 0; i < value.length; i += 1) { | ||
yield [key, value[i]]; | ||
} | ||
// If one is ...spread order it later | ||
if (a_sub_part.spread !== b_sub_part.spread) return a_sub_part.spread ? 1 : -1; | ||
if (a_sub_part.dynamic !== b_sub_part.dynamic) { | ||
return a_sub_part.dynamic ? 1 : -1; | ||
} | ||
} | ||
*keys() { | ||
for (const [key, value] of this.#map) { | ||
for (let i = 0; i < value.length; i += 1) { | ||
yield key; | ||
} | ||
if (!a_sub_part.dynamic && a_sub_part.content !== b_sub_part.content) { | ||
return ( | ||
b_sub_part.content.length - a_sub_part.content.length || | ||
(a_sub_part.content < b_sub_part.content ? -1 : 1) | ||
); | ||
} | ||
} | ||
*values() { | ||
for (const [, value] of this.#map) { | ||
for (let i = 0; i < value.length; i += 1) { | ||
yield value; | ||
} | ||
} | ||
if (a.is_page !== b.is_page) { | ||
return a.is_page ? 1 : -1; | ||
} | ||
// otherwise sort alphabetically | ||
return a.file < b.file ? -1 : 1; | ||
} | ||
/** @param {import('http').IncomingMessage} req */ | ||
function get_body(req) { | ||
const headers = req.headers; | ||
const has_body = | ||
headers['content-type'] !== undefined && | ||
// https://github.com/jshttp/type-is/blob/c1f4388c71c8a01f79934e68f630ca4a15fffcd6/index.js#L81-L95 | ||
(headers['transfer-encoding'] !== undefined || !isNaN(Number(headers['content-length']))); | ||
/** | ||
* @param {string} part | ||
* @param {string} file | ||
*/ | ||
function get_parts(part, file) { | ||
return part | ||
.split(/\[(.+?\(.+?\)|.+?)\]/) | ||
.map((str, i) => { | ||
if (!str) return null; | ||
const dynamic = i % 2 === 1; | ||
if (!has_body) return Promise.resolve(undefined); | ||
const [, content] = dynamic ? /([^(]+)$/.exec(str) : [null, str]; | ||
const [type, ...directives] = headers['content-type'].split(/;\s*/); | ||
if (dynamic && !/^(\.\.\.)?[a-zA-Z0-9_$]+$/.test(content)) { | ||
throw new Error(`Invalid route ${file} — parameter name must match /^[a-zA-Z0-9_$]+$/`); | ||
} | ||
switch (type) { | ||
case 'application/octet-stream': | ||
return get_buffer(req); | ||
return { | ||
content, | ||
dynamic, | ||
spread: dynamic && /^\.{3}.+$/.test(content) | ||
}; | ||
}) | ||
.filter(Boolean); | ||
} | ||
case 'text/plain': | ||
return get_text(req); | ||
/** | ||
* @param {Part[][]} segments | ||
* @param {boolean} add_trailing_slash | ||
*/ | ||
function get_pattern(segments, add_trailing_slash) { | ||
const path = segments | ||
.map((segment) => { | ||
return segment | ||
.map((part) => { | ||
return part.dynamic | ||
? part.spread | ||
? '(.+)' | ||
: '([^/]+?)' | ||
: encodeURI(part.content.normalize()) | ||
.replace(/\?/g, '%3F') | ||
.replace(/#/g, '%23') | ||
.replace(/%5B/g, '[') | ||
.replace(/%5D/g, ']') | ||
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | ||
}) | ||
.join(''); | ||
}) | ||
.join('\\/'); | ||
case 'application/json': | ||
return get_json(req); | ||
const trailing = add_trailing_slash && segments.length ? '\\/?$' : '$'; | ||
case 'application/x-www-form-urlencoded': | ||
return get_urlencoded(req); | ||
return new RegExp(`^\\/${path}${trailing}`); | ||
} | ||
case 'multipart/form-data': { | ||
const boundary = directives.find((directive) => directive.startsWith('boundary=')); | ||
if (!boundary) throw new Error('Missing boundary'); | ||
return get_multipart(req, boundary.slice('boundary='.length)); | ||
/** | ||
* @param {string} dir | ||
* @param {string} path | ||
* @param {import('types.internal').Asset[]} files | ||
*/ | ||
function list_files(dir, path, files = []) { | ||
fs.readdirSync(dir).forEach((file) => { | ||
const full = `${dir}/${file}`; | ||
const stats = fs.statSync(full); | ||
const joined = path ? `${path}/${file}` : file; | ||
if (stats.isDirectory()) { | ||
list_files(full, joined, files); | ||
} else { | ||
if (file === '.DS_Store') return; | ||
files.push({ | ||
file: joined, | ||
size: stats.size, | ||
type: mime.getType(joined) | ||
}); | ||
} | ||
default: | ||
throw new Error(`Invalid Content-Type ${type}`); | ||
} | ||
}); | ||
return files; | ||
} | ||
/** @param {import('http').IncomingMessage} req */ | ||
async function get_json(req) { | ||
return JSON.parse(await get_text(req)); | ||
/** @type {Map<string, string>} */ | ||
const previous_contents = new Map(); | ||
/** | ||
* @param {string} file | ||
* @param {string} code | ||
*/ | ||
function write_if_changed(file, code) { | ||
if (code !== previous_contents.get(file)) { | ||
previous_contents.set(file, code); | ||
mkdirp(path.dirname(file)); | ||
fs.writeFileSync(file, code); | ||
} | ||
} | ||
/** @param {import('http').IncomingMessage} req */ | ||
async function get_urlencoded(req) { | ||
const text = await get_text(req); | ||
const s = JSON.stringify; | ||
const { data, append } = read_only_form_data(); | ||
/** @typedef {import('../../../types.internal').ManifestData} ManifestData */ | ||
text | ||
.replace(/\+/g, ' ') | ||
.split('&') | ||
.forEach((str) => { | ||
const [key, value] = str.split('='); | ||
append(decodeURIComponent(key), decodeURIComponent(value)); | ||
}); | ||
/** | ||
* @param {{ | ||
* manifest_data: ManifestData; | ||
* output: string; | ||
* cwd: string; | ||
* }} options | ||
*/ | ||
function create_app({ manifest_data, output, cwd = process.cwd() }) { | ||
const dir = `${output}/generated`; | ||
const base = path.relative(cwd, dir); | ||
return data; | ||
write_if_changed(`${dir}/manifest.js`, generate_client_manifest(manifest_data, base)); | ||
write_if_changed(`${dir}/root.svelte`, generate_app(manifest_data, base)); | ||
} | ||
/** | ||
* @param {import('http').IncomingMessage} req | ||
* @param {string} boundary | ||
* @param {string} str | ||
*/ | ||
async function get_multipart(req, boundary) { | ||
const text = await get_text(req); | ||
const parts = text.split(`--${boundary}`); | ||
function trim(str) { | ||
return str.replace(/^\t\t/gm, '').trim(); | ||
} | ||
const nope = () => { | ||
throw new Error('Malformed form data'); | ||
}; | ||
/** | ||
* @param {ManifestData} manifest_data | ||
* @param {string} base | ||
*/ | ||
function generate_client_manifest(manifest_data, base) { | ||
/** @type {Record<string, number>} */ | ||
const component_indexes = {}; | ||
if (parts[0] !== '' || parts[parts.length - 1].trim() !== '--') { | ||
nope(); | ||
} | ||
/** @param {string} c */ | ||
const get_path = (c) => path.relative(base, c); | ||
const { data, append } = read_only_form_data(); | ||
const components = `[ | ||
${manifest_data.components | ||
.map((component, i) => { | ||
component_indexes[component] = i; | ||
parts.slice(1, -1).forEach((part) => { | ||
const match = /\s*([\s\S]+?)\r\n\r\n([\s\S]*)\s*/.exec(part); | ||
const raw_headers = match[1]; | ||
const body = match[2].trim(); | ||
return `() => import(${s(get_path(component))})`; | ||
}) | ||
.join(',\n\t\t\t\t')} | ||
]`.replace(/^\t/gm, ''); | ||
let key; | ||
raw_headers.split('\r\n').forEach((str) => { | ||
const [raw_header, ...raw_directives] = str.split('; '); | ||
let [name, value] = raw_header.split(': '); | ||
const routes = `[ | ||
${manifest_data.routes | ||
.map((route) => { | ||
if (route.type === 'page') { | ||
const params = | ||
route.params.length > 0 && | ||
'(m) => ({ ' + | ||
route.params | ||
.map((param, i) => { | ||
return param.startsWith('...') | ||
? `${param.slice(3)}: d(m[${i + 1}])` | ||
: `${param}: d(m[${i + 1}])`; | ||
}) | ||
.join(', ') + | ||
'})'; | ||
name = name.toLowerCase(); | ||
const tuple = [ | ||
route.pattern, | ||
`[${route.parts.map((part) => `components[${component_indexes[part]}]`).join(', ')}]`, | ||
params | ||
] | ||
.filter(Boolean) | ||
.join(', '); | ||
/** @type {Record<string, string>} */ | ||
const directives = {}; | ||
raw_directives.forEach((raw_directive) => { | ||
const [name, value] = raw_directive.split('='); | ||
directives[name] = JSON.parse(value); // TODO is this right? | ||
}); | ||
return `// ${route.parts[route.parts.length - 1]}\n\t[${tuple}]`; | ||
} else { | ||
return `// ${route.file}\n\t[${route.pattern}]`; | ||
} | ||
}) | ||
.join(',\n\n\t')} | ||
]`.replace(/^\t/gm, ''); | ||
if (name === 'content-disposition') { | ||
if (value !== 'form-data') nope(); | ||
return trim(` | ||
import * as layout from ${s(get_path(manifest_data.layout))}; | ||
if (directives.filename) { | ||
// TODO we probably don't want to do this automatically | ||
throw new Error('File upload is not yet implemented'); | ||
} | ||
const components = ${components}; | ||
if (directives.name) { | ||
key = directives.name; | ||
} | ||
} | ||
}); | ||
const d = decodeURIComponent; | ||
const empty = () => ({}); | ||
if (!key) nope(); | ||
export const routes = ${routes}; | ||
append(key, body); | ||
}); | ||
return data; | ||
export { layout }; | ||
`); | ||
} | ||
/** | ||
* @param {import('http').IncomingMessage} req | ||
* @returns {Promise<string>} | ||
* @param {ManifestData} manifest_data | ||
* @param {string} base | ||
*/ | ||
function get_text(req) { | ||
return new Promise((fulfil, reject) => { | ||
let data = ''; | ||
function generate_app(manifest_data, base) { | ||
// TODO remove default layout altogether | ||
req.on('error', reject); | ||
const max_depth = Math.max( | ||
...manifest_data.routes.map((route) => | ||
route.type === 'page' ? route.parts.filter(Boolean).length : 0 | ||
) | ||
); | ||
req.on('data', (chunk) => { | ||
data += chunk; | ||
}); | ||
const levels = []; | ||
for (let i = 0; i <= max_depth; i += 1) { | ||
levels.push(i); | ||
} | ||
req.on('end', () => { | ||
fulfil(data); | ||
}); | ||
}); | ||
} | ||
let l = max_depth; | ||
/** | ||
* @param {import('http').IncomingMessage} req | ||
* @returns {Promise<ArrayBuffer>} | ||
*/ | ||
function get_buffer(req) { | ||
return new Promise((fulfil, reject) => { | ||
let data = new Uint8Array(0); | ||
let pyramid = `<svelte:component this={components[${l}]} {...(props_${l} || {})}/>`; | ||
req.on('error', reject); | ||
while (l-- > 1) { | ||
pyramid = ` | ||
<svelte:component this={components[${l}]} {...(props_${l} || {})}> | ||
{#if components[${l + 1}]} | ||
${pyramid.replace(/\n/g, '\n\t\t\t\t\t')} | ||
{/if} | ||
</svelte:component> | ||
` | ||
.replace(/^\t\t\t/gm, '') | ||
.trim(); | ||
} | ||
req.on('data', (chunk) => { | ||
const new_data = new Uint8Array(data.length + chunk.length); | ||
const error_file = path.relative(base, manifest_data.error); | ||
for (let i = 0; i < data.length; i += 1) { | ||
new_data[i] = data[i]; | ||
} | ||
return trim(` | ||
<!-- This file is generated by @sveltejs/kit — do not edit it! --> | ||
<script> | ||
import { setContext, afterUpdate, onMount } from 'svelte'; | ||
import ErrorComponent from ${s(error_file)}; | ||
for (let i = 0; i < chunk.length; i += 1) { | ||
new_data[i + data.length] = chunk[i]; | ||
} | ||
// error handling | ||
export let status = undefined; | ||
export let error = undefined; | ||
data = new_data; | ||
}); | ||
// stores | ||
export let stores; | ||
export let page; | ||
req.on('end', () => { | ||
fulfil(data.buffer); | ||
}); | ||
}); | ||
export let components; | ||
${levels.map((l) => `export let props_${l} = null;`).join('\n\t\t\t')} | ||
const Layout = components[0]; | ||
setContext('__svelte__', stores); | ||
$: stores.page.set(page); | ||
afterUpdate(stores.page.notify); | ||
let mounted = false; | ||
let navigated = false; | ||
let title = null; | ||
onMount(() => { | ||
const unsubscribe = stores.page.subscribe(() => { | ||
if (mounted) { | ||
navigated = true; | ||
title = document.title; | ||
} | ||
}); | ||
mounted = true; | ||
return unsubscribe; | ||
}); | ||
</script> | ||
<Layout {...(props_0 || {})}> | ||
{#if error} | ||
<ErrorComponent {status} {error}/> | ||
{:else} | ||
${pyramid.replace(/\n/g, '\n\t\t\t\t')} | ||
{/if} | ||
</Layout> | ||
{#if mounted} | ||
<div id="svelte-announcer" aria-live="assertive" aria-atomic="true"> | ||
{#if navigated} | ||
Navigated to {title} | ||
{/if} | ||
</div> | ||
{/if} | ||
<style> | ||
#svelte-announcer { | ||
position: absolute; | ||
left: 0; | ||
top: 0; | ||
clip: rect(0 0 0 0); | ||
clip-path: inset(50%); | ||
overflow: hidden; | ||
white-space: nowrap; | ||
width: 1px; | ||
height: 1px; | ||
} | ||
</style> | ||
`); | ||
} | ||
export { get_body as g }; | ||
export { create_app as a, create_manifest_data as c }; |
import fs from 'fs'; | ||
import path from 'path'; | ||
import { r as rimraf, c as copy_assets } from './utils.js'; | ||
import { c as create_manifest_data, a as create_app } from './index2.js'; | ||
import { rimraf } from '../filesystem.js'; | ||
import { c as create_manifest_data, a as create_app } from './index3.js'; | ||
import { c as copy_assets } from './utils.js'; | ||
import vite from 'vite'; | ||
import svelte from '@sveltejs/vite-plugin-svelte'; | ||
import './standard.js'; | ||
import '../cli.js'; | ||
import 'sade'; | ||
import 'url'; | ||
import './standard.js'; | ||
@@ -311,21 +312,21 @@ /** @param {any} value */ | ||
${manifest.routes | ||
.map((route) => { | ||
if (route.type === 'page') { | ||
const params = get_params(route.params); | ||
const parts = route.parts.map(id => `{ id: ${s(id)}, load: components[${component_indexes.get(id)}] }`); | ||
.map((route) => { | ||
if (route.type === 'page') { | ||
const params = get_params(route.params); | ||
const parts = route.parts.map(id => `{ id: ${s(id)}, load: components[${component_indexes.get(id)}] }`); | ||
const js_deps = new Set(common_js_deps); | ||
const css_deps = new Set(common_css_deps); | ||
const js_deps = new Set(common_js_deps); | ||
const css_deps = new Set(common_css_deps); | ||
for (const file of route.parts) { | ||
js_deps_by_file.get(file).forEach(asset => { | ||
js_deps.add(asset); | ||
}); | ||
for (const file of route.parts) { | ||
js_deps_by_file.get(file).forEach(asset => { | ||
js_deps.add(asset); | ||
}); | ||
css_deps_by_file.get(file).forEach(asset => { | ||
css_deps.add(asset); | ||
}); | ||
} | ||
css_deps_by_file.get(file).forEach(asset => { | ||
css_deps.add(asset); | ||
}); | ||
} | ||
return `{ | ||
return `{ | ||
type: 'page', | ||
@@ -338,7 +339,7 @@ pattern: ${route.pattern}, | ||
}`; | ||
} else { | ||
const params = get_params(route.params); | ||
const load = `() => import(${s(app_relative(route.file))})`; | ||
} else { | ||
const params = get_params(route.params); | ||
const load = `() => import(${s(app_relative(route.file))})`; | ||
return `{ | ||
return `{ | ||
type: 'endpoint', | ||
@@ -349,5 +350,5 @@ pattern: ${route.pattern}, | ||
}`; | ||
} | ||
}) | ||
.join(',\n\t\t\t\t\t')} | ||
} | ||
}) | ||
.join(',\n\t\t\t\t\t')} | ||
] | ||
@@ -354,0 +355,0 @@ }; |
import { $ } from '../cli.js'; | ||
import { m as mkdirp, a as copy, l as logger } from './utils.js'; | ||
import { l as logger } from './utils.js'; | ||
import { mkdirp, copy, rimraf } from '../filesystem.js'; | ||
import fs, { readFileSync, writeFileSync, existsSync } from 'fs'; | ||
@@ -721,2 +722,12 @@ import path, { resolve as resolve$1, sep, join as join$1, dirname } from 'path'; | ||
/** @param {string} path */ | ||
rimraf(path) { | ||
rimraf(path); | ||
} | ||
/** @param {string} dir */ | ||
mkdirp(dir) { | ||
mkdirp(dir); | ||
} | ||
/** @param {{ force: boolean, dest: string }} opts */ | ||
@@ -723,0 +734,0 @@ async prerender({ force = false, dest }) { |
@@ -6,3 +6,3 @@ import fs, { readdirSync, statSync, existsSync, createReadStream } from 'fs'; | ||
import { M as Mime_1, s as standard } from './standard.js'; | ||
import { g as get_body } from './index3.js'; | ||
import { g as get_body } from './index.js'; | ||
@@ -9,0 +9,0 @@ function list(dir, callback, pre='') { |
@@ -1,46 +0,7 @@ | ||
import path, { dirname, resolve } from 'path'; | ||
import { dirname, resolve } from 'path'; | ||
import { $ } from '../cli.js'; | ||
import fs, { existsSync } from 'fs'; | ||
import { copy } from '../filesystem.js'; | ||
import { fileURLToPath } from 'url'; | ||
import { existsSync } from 'fs'; | ||
/** @param {string} dir */ | ||
function mkdirp(dir) { | ||
try { | ||
fs.mkdirSync(dir, { recursive: true }); | ||
} catch (e) { | ||
if (e.code === 'EEXIST') return; | ||
throw e; | ||
} | ||
} | ||
/** @param {string} path */ | ||
function rimraf(path) { | ||
(fs.rmSync || fs.rmdirSync)(path, { recursive: true, force: true }); | ||
} | ||
/** | ||
* @param {string} from | ||
* @param {string} to | ||
* @param {(basename: string) => boolean} filter | ||
*/ | ||
function copy(from, to, filter = () => true) { | ||
if (!fs.existsSync(from)) return []; | ||
if (!filter(path.basename(from))) return []; | ||
const files = []; | ||
const stats = fs.statSync(from); | ||
if (stats.isDirectory()) { | ||
fs.readdirSync(from).forEach((file) => { | ||
files.push(...copy(path.join(from, file), path.join(to, file))); | ||
}); | ||
} else { | ||
mkdirp(path.dirname(to)); | ||
fs.copyFileSync(from, to); | ||
files.push(to); | ||
} | ||
return files; | ||
} | ||
const __filename = fileURLToPath(import.meta.url); | ||
@@ -83,2 +44,2 @@ const __dirname = dirname(__filename); | ||
export { copy as a, copy_assets as c, logger as l, mkdirp as m, rimraf as r }; | ||
export { copy_assets as c, logger as l }; |
@@ -465,3 +465,3 @@ import { existsSync } from 'fs'; | ||
const prog = sade('svelte-kit').version('1.0.0-next.55'); | ||
const prog = sade('svelte-kit').version('1.0.0-next.56'); | ||
@@ -477,3 +477,3 @@ prog | ||
const { dev } = await import('./chunks/index.js'); | ||
const { dev } = await import('./chunks/index2.js'); | ||
@@ -480,0 +480,0 @@ try { |
{ | ||
"name": "@sveltejs/kit", | ||
"version": "1.0.0-next.55", | ||
"version": "1.0.0-next.56", | ||
"type": "module", | ||
@@ -12,3 +12,2 @@ "dependencies": { | ||
"@rollup/plugin-replace": "^2.4.1", | ||
"@sveltejs/app-utils": "1.0.0-next.3", | ||
"@types/amphtml-validator": "^1.0.1", | ||
@@ -66,2 +65,9 @@ "@types/mime": "^2.0.3", | ||
}, | ||
"./http": { | ||
"import": "./dist/http.js" | ||
}, | ||
"./filesystem": { | ||
"import": "./dist/filesystem.js", | ||
"require": "./dist/filesystem.cjs" | ||
}, | ||
"./types.d.ts": "./types.d.ts" | ||
@@ -68,0 +74,0 @@ }, |
@@ -58,2 +58,8 @@ import { Headers, LoadInput, LoadOutput, Logger } from './types.internal'; | ||
export interface RequestHandlerResponse { | ||
status?: number; | ||
headers?: Record<string, string>; | ||
body?: any; | ||
} | ||
export type RequestHandler = ( | ||
@@ -69,8 +75,4 @@ request?: { | ||
context?: any | ||
) => { | ||
status?: number; | ||
headers?: Record<string, string>; | ||
body?: any; | ||
}; | ||
) => RequestHandlerResponse | Promise<RequestHandlerResponse>; | ||
export type Load = (input: LoadInput) => LoadOutput | Promise<LoadOutput>; |
@@ -134,6 +134,8 @@ import { Adapter, Load } from './types'; | ||
export type GetParams = (match: RegExpExecArray) => Record<string, string>; | ||
export type SSRPage = { | ||
type: 'page'; | ||
pattern: RegExp; | ||
params: (match: RegExpExecArray) => Record<string, string>; | ||
params: GetParams; | ||
parts: SSRPagePart[]; | ||
@@ -148,3 +150,3 @@ style: string; | ||
pattern: RegExp; | ||
params: (match: RegExpExecArray) => Record<string, string>; | ||
params: GetParams; | ||
load: () => Promise<any>; // TODO | ||
@@ -155,13 +157,5 @@ }; | ||
export type CSRPage = { | ||
type: 'page'; | ||
pattern: RegExp; | ||
params: (match: RegExpExecArray) => Record<string, string>; | ||
parts: CSRComponentLoader[]; | ||
}; | ||
export type CSRPage = [RegExp, CSRComponentLoader[], GetParams?]; | ||
export type CSREndpoint = { | ||
type: 'endpoint'; | ||
pattern: RegExp; | ||
}; | ||
export type CSREndpoint = [RegExp]; | ||
@@ -168,0 +162,0 @@ export type CSRRoute = CSREndpoint | CSRPage; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
325714
0.56%20
-4.76%30
11.11%9408
0.48%20
11.11%