Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/server/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@ export const template = ({ body }: Params = {}) =>
const CODE_STYLE = 'font-size: 14px; font-family: monospace;'

async function init(dirtyVersion) {
const version = dirtyVersion && dirtyVersion.replace(/^v/, '') || '2.29.3'
const url = 'https://unpkg.com/date-fns' + (version ? '@' + version : '') + '/esm/index.js'
const version = dirtyVersion && dirtyVersion.replace(/^v/, '') || '4.1.0'
const url = 'https://unpkg.com/date-fns' + (version ? '@' + version : '')
const packageUrl = url + '/package.json'
try {
const dateFns = await import(url)
const response = await fetch(packageUrl)
const packageJson = await response.json()
const indexUrl = url + '/' + packageJson.module
const dateFns = await import(indexUrl)
window._ = dateFns
window.dateFns = dateFns

Expand All @@ -98,7 +102,7 @@ export const template = ({ body }: Params = {}) =>

console.log(
'%c( ⩗) date-fns console\\n' +
'%cRun %cinit()%c or %cinit("v2.16.1" /* version */)\\n' +
'%cRun %cinit()%c or %cinit("v4.1.0" /* version */)\\n' +
'%cto make date-fns functions available in console.',
HEADER_STYLE, MESSAGE_STYLE, CODE_STYLE, MESSAGE_STYLE, CODE_STYLE, MESSAGE_STYLE,
)
Expand Down