MCPcopy Create free account
hub / github.com/formkit/formkit / prepForDistribution

Function prepForDistribution

scripts/deploy.mjs:178–203  ·  view source on GitHub ↗

* Prepare the file for ESM distribution. * @param {string} file - The file source code to replace * @param {string} version - The version we are publishing * @returns

(file, version, min = true)

Source from the content-addressed store, hash-verified

176 * @returns
177 */
178async function prepForDistribution(file, version, min = true) {
179 let src = file.replace(
180 /(from|import)\s+['"]@formkit\/([a-z0-9]+)['"]/g,
181 `$1 '/$2@${version}'`
182 )
183 // const vueImportRegex = /^import\s+(.*)\s+from\s+'vue';?/gm
184 // const vueMatch = src.match(vueImportRegex)
185 // if (vueMatch) {
186 // src = src.replace(vueImportRegex, '')
187 // const vueImportStatement = `const $1 = await import(\`./vue.js?src=\${(new URL(import.meta.url).searchParams.get('vue') || 'https://cdn.jsdelivr.net/npm/vue@next/%2Besm')}\`);`
188 // src = src.replace(
189 // /(^import\s+.*;)(?!\s(import|export))/gm,
190 // '$1\n' + vueMatch[0]
191 // )
192 // src = src.replace(vueImportRegex, vueImportStatement)
193 // }
194 if (!min) return src
195
196 try {
197 const result = await minify(src, { module: true })
198 return result.code
199 } catch (err) {
200 console.error(err)
201 throw err
202 }
203}
204
205/**
206 * Deploy the project to a file store used for iife distribution. This is a

Callers 1

sendFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected