diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/cmd/build.js | 106 | ||||
-rw-r--r-- | scripts/cmd/copy.js | 124 | ||||
-rwxr-xr-x | scripts/index.js | 28 | ||||
-rwxr-xr-x | scripts/notify/index.js | 106 | ||||
-rw-r--r-- | scripts/smoke/index.js | 36 | ||||
-rw-r--r-- | scripts/stats/index.js | 124 | ||||
-rw-r--r-- | scripts/utils/svelte-plugin.js | 90 |
7 files changed, 307 insertions, 307 deletions
diff --git a/scripts/cmd/build.js b/scripts/cmd/build.js index 469f5d0c3..b5eb91195 100644 --- a/scripts/cmd/build.js +++ b/scripts/cmd/build.js @@ -7,70 +7,70 @@ import glob from 'tiny-glob'; /** @type {import('esbuild').BuildOptions} */ const defaultConfig = { - minify: false, - format: 'esm', - platform: 'node', - target: 'node14', - sourcemap: 'inline', - sourcesContent: false, + minify: false, + format: 'esm', + platform: 'node', + target: 'node14', + sourcemap: 'inline', + sourcesContent: false, }; const dt = new Intl.DateTimeFormat('en-us', { - hour: '2-digit', - minute: '2-digit', + hour: '2-digit', + minute: '2-digit', }); export default async function build(...args) { - const config = Object.assign({}, defaultConfig); - const isDev = args.slice(-1)[0] === 'IS_DEV'; - const patterns = args - .filter((f) => !!f) // remove empty args - .map((f) => f.replace(/^'/, '').replace(/'$/, '')); // Needed for Windows: glob strings contain surrounding string chars??? remove these - let entryPoints = [].concat(...(await Promise.all(patterns.map((pattern) => glob(pattern, { filesOnly: true, absolute: true }))))); + const config = Object.assign({}, defaultConfig); + const isDev = args.slice(-1)[0] === 'IS_DEV'; + const patterns = args + .filter((f) => !!f) // remove empty args + .map((f) => f.replace(/^'/, '').replace(/'$/, '')); // Needed for Windows: glob strings contain surrounding string chars??? remove these + let entryPoints = [].concat(...(await Promise.all(patterns.map((pattern) => glob(pattern, { filesOnly: true, absolute: true }))))); - const { type = 'module', dependencies = {} } = await fs.readFile('./package.json').then((res) => JSON.parse(res.toString())); - const format = type === 'module' ? 'esm' : 'cjs'; - const outdir = 'dist'; - await clean(outdir); + const { type = 'module', dependencies = {} } = await fs.readFile('./package.json').then((res) => JSON.parse(res.toString())); + const format = type === 'module' ? 'esm' : 'cjs'; + const outdir = 'dist'; + await clean(outdir); - if (!isDev) { - await esbuild.build({ - ...config, - bundle: entryPoints.length === 1, // Note: only use `bundle` with a single entrypoint! - entryPoints, - outdir, - format, - plugins: [svelte({ isDev })], - }); - return; - } + if (!isDev) { + await esbuild.build({ + ...config, + bundle: entryPoints.length === 1, // Note: only use `bundle` with a single entrypoint! + entryPoints, + outdir, + format, + plugins: [svelte({ isDev })], + }); + return; + } - const builder = await esbuild.build({ - ...config, - watch: { - onRebuild(error, result) { - const date = dt.format(new Date()); - if (error || (result && result.errors.length)) { - console.error(dim(`[${date}] `) + red(error || result.errors.join('\n'))); - } else { - if (result.warnings.length) { - console.log(dim(`[${date}] `) + yellow('β updated with warnings:\n' + result.warnings.join('\n'))); - } - console.log(dim(`[${date}] `) + green('β updated')); - } - }, - }, - entryPoints, - outdir, - format, - plugins: [svelte({ isDev })], - }); + const builder = await esbuild.build({ + ...config, + watch: { + onRebuild(error, result) { + const date = dt.format(new Date()); + if (error || (result && result.errors.length)) { + console.error(dim(`[${date}] `) + red(error || result.errors.join('\n'))); + } else { + if (result.warnings.length) { + console.log(dim(`[${date}] `) + yellow('β updated with warnings:\n' + result.warnings.join('\n'))); + } + console.log(dim(`[${date}] `) + green('β updated')); + } + }, + }, + entryPoints, + outdir, + format, + plugins: [svelte({ isDev })], + }); - process.on('beforeExit', () => { - builder.stop && builder.stop(); - }); + process.on('beforeExit', () => { + builder.stop && builder.stop(); + }); } async function clean(outdir) { - return del([`${outdir}/**`, `!${outdir}/**/*.d.ts`]); + return del([`${outdir}/**`, `!${outdir}/**/*.d.ts`]); } diff --git a/scripts/cmd/copy.js b/scripts/cmd/copy.js index f31fb3739..925990fe4 100644 --- a/scripts/cmd/copy.js +++ b/scripts/cmd/copy.js @@ -8,76 +8,76 @@ const { resolve, dirname, sep, join } = posix; /** @type {import('arg').Spec} */ const spec = { - '--tgz': Boolean, + '--tgz': Boolean, }; export default async function copy() { - let { _: patterns, ['--tgz']: isCompress } = arg(spec); - patterns = patterns.slice(1); + let { _: patterns, ['--tgz']: isCompress } = arg(spec); + patterns = patterns.slice(1); - if (isCompress) { - const files = await glob(patterns, { gitignore: true }); - const rootDir = resolveRootDir(files); - const destDir = rootDir.replace(/^[^/]+/, 'dist'); + if (isCompress) { + const files = await glob(patterns, { gitignore: true }); + const rootDir = resolveRootDir(files); + const destDir = rootDir.replace(/^[^/]+/, 'dist'); - const templates = files.reduce((acc, curr) => { - const name = curr.replace(rootDir, '').slice(1).split(sep)[0]; - if (acc[name]) { - acc[name].push(resolve(curr)); - } else { - acc[name] = [resolve(curr)]; - } - return acc; - }, {}); + const templates = files.reduce((acc, curr) => { + const name = curr.replace(rootDir, '').slice(1).split(sep)[0]; + if (acc[name]) { + acc[name].push(resolve(curr)); + } else { + acc[name] = [resolve(curr)]; + } + return acc; + }, {}); - let meta = {}; - return Promise.all( - Object.entries(templates).map(([template, files]) => { - const cwd = resolve(join(rootDir, template)); - const dest = join(destDir, `${template}.tgz`); - const metafile = files.find((f) => f.endsWith('meta.json')); - if (metafile) { - files = files.filter((f) => f !== metafile); - meta[template] = JSON.parse(readFileSync(metafile).toString()); - } - return fs.mkdir(dirname(dest), { recursive: true }).then(() => - tar.create( - { - gzip: true, - portable: true, - file: dest, - cwd, - }, - files.map((f) => f.replace(cwd, '').slice(1)) - ) - ); - }) - ).then(() => { - if (Object.keys(meta).length > 0) { - return fs.writeFile(resolve(destDir, 'meta.json'), JSON.stringify(meta, null, 2)); - } - }); - } + let meta = {}; + return Promise.all( + Object.entries(templates).map(([template, files]) => { + const cwd = resolve(join(rootDir, template)); + const dest = join(destDir, `${template}.tgz`); + const metafile = files.find((f) => f.endsWith('meta.json')); + if (metafile) { + files = files.filter((f) => f !== metafile); + meta[template] = JSON.parse(readFileSync(metafile).toString()); + } + return fs.mkdir(dirname(dest), { recursive: true }).then(() => + tar.create( + { + gzip: true, + portable: true, + file: dest, + cwd, + }, + files.map((f) => f.replace(cwd, '').slice(1)) + ) + ); + }) + ).then(() => { + if (Object.keys(meta).length > 0) { + return fs.writeFile(resolve(destDir, 'meta.json'), JSON.stringify(meta, null, 2)); + } + }); + } - const files = await glob(patterns); - await Promise.all( - files.map((file) => { - const dest = resolve(file.replace(/^[^/]+/, 'dist')); - return fs.mkdir(dirname(dest), { recursive: true }).then(() => fs.copyFile(resolve(file), dest)); - }) - ); + const files = await glob(patterns); + await Promise.all( + files.map((file) => { + const dest = resolve(file.replace(/^[^/]+/, 'dist')); + return fs.mkdir(dirname(dest), { recursive: true }).then(() => fs.copyFile(resolve(file), dest)); + }) + ); } function resolveRootDir(files) { - return files - .reduce((acc, curr) => { - const currParts = curr.split(sep); - if (acc.length === 0) return currParts; - const result = []; - currParts.forEach((part, i) => { - if (acc[i] === part) result.push(part); - }); - return result; - }, []) - .join(sep); + return files + .reduce((acc, curr) => { + const currParts = curr.split(sep); + if (acc.length === 0) return currParts; + const result = []; + currParts.forEach((part, i) => { + if (acc[i] === part) result.push(part); + }); + return result; + }, []) + .join(sep); } diff --git a/scripts/index.js b/scripts/index.js index 7908b112c..dd789f032 100755 --- a/scripts/index.js +++ b/scripts/index.js @@ -1,19 +1,19 @@ #!/usr/bin/env node export default async function run() { - const [cmd, ...args] = process.argv.slice(2); - switch (cmd) { - case 'dev': - case 'build': { - const { default: build } = await import('./cmd/build.js'); - await build(...args, cmd === 'dev' ? 'IS_DEV' : undefined); - break; - } - case 'copy': { - const { default: copy } = await import('./cmd/copy.js'); - await copy(...args); - break; - } - } + const [cmd, ...args] = process.argv.slice(2); + switch (cmd) { + case 'dev': + case 'build': { + const { default: build } = await import('./cmd/build.js'); + await build(...args, cmd === 'dev' ? 'IS_DEV' : undefined); + break; + } + case 'copy': { + const { default: copy } = await import('./cmd/copy.js'); + await copy(...args); + break; + } + } } run(); diff --git a/scripts/notify/index.js b/scripts/notify/index.js index 6427e91aa..950fef1de 100755 --- a/scripts/notify/index.js +++ b/scripts/notify/index.js @@ -6,76 +6,76 @@ const baseUrl = new URL('https://github.com/withastro/astro/blob/main/'); const emojis = ['π', 'π₯³', 'π', 'π§βπ', 'π', 'π', 'β
', 'π€©', 'π€', 'π']; const descriptors = ['new releases', 'hot and fresh updates', 'shiny updates', 'exciting changes', 'package updates', 'awesome updates', 'bug fixes and features', 'updates']; const verbs = [ - 'just went out!', - 'just launched!', - 'now available!', - 'in the wild!', - 'now live!', - 'hit the registry!', - 'to share!', - 'for you!', - 'for yβall! π€ ', - 'cominβ your way!', - 'cominβ atcha!', - 'cominβ in hot!', - 'freshly minted on the blockchain! (jk)', - '[is] out (now with 100% more reticulated splines!)', - '(as seen on TV!)', - 'just dropped!', - 'β artisanally hand-crafted just for you.', - 'β oh happy day!', - 'β enjoy!', - 'now out. Be the first on your block to download!', - 'made with love π', - '[is] out! Our best [version] yet!', - '[is] here. DOWNLOAD! DOWNLOAD! DOWNLOAD!', - '... HUZZAH!', - '[has] landed!', - 'landed! The internet just got a little more fun.', - 'β from our family to yours.', - 'β go forth and build!', + 'just went out!', + 'just launched!', + 'now available!', + 'in the wild!', + 'now live!', + 'hit the registry!', + 'to share!', + 'for you!', + 'for yβall! π€ ', + 'cominβ your way!', + 'cominβ atcha!', + 'cominβ in hot!', + 'freshly minted on the blockchain! (jk)', + '[is] out (now with 100% more reticulated splines!)', + '(as seen on TV!)', + 'just dropped!', + 'β artisanally hand-crafted just for you.', + 'β oh happy day!', + 'β enjoy!', + 'now out. Be the first on your block to download!', + 'made with love π', + '[is] out! Our best [version] yet!', + '[is] here. DOWNLOAD! DOWNLOAD! DOWNLOAD!', + '... HUZZAH!', + '[has] landed!', + 'landed! The internet just got a little more fun.', + 'β from our family to yours.', + 'β go forth and build!', ]; function item(items) { - return items[Math.floor(Math.random() * items.length)]; + return items[Math.floor(Math.random() * items.length)]; } const plurals = new Map([ - ['is', 'are'], - ['has', 'have'], + ['is', 'are'], + ['has', 'have'], ]); function pluralize(text) { - return text.replace(/(\[([^\]]+)\])/gm, (_, _full, match) => (plurals.has(match) ? plurals.get(match) : `${match}s`)); + return text.replace(/(\[([^\]]+)\])/gm, (_, _full, match) => (plurals.has(match) ? plurals.get(match) : `${match}s`)); } function singularlize(text) { - return text.replace(/(\[([^\]]+)\])/gm, (_, _full, match) => `${match}`); + return text.replace(/(\[([^\]]+)\])/gm, (_, _full, match) => `${match}`); } async function run() { - const releases = process.argv.slice(2)[0]; - const data = JSON.parse(releases); - const packages = await Promise.all( - data.map(({ name, version }) => { - const p = path.relative('./', path.dirname(require.resolve(name))).replace(path.sep, '/'); - return { name, version, url: new URL(`${p}/CHANGELOG.md#${version.replace(/\./g, '')}`, baseUrl).toString() }; - }) - ); + const releases = process.argv.slice(2)[0]; + const data = JSON.parse(releases); + const packages = await Promise.all( + data.map(({ name, version }) => { + const p = path.relative('./', path.dirname(require.resolve(name))).replace(path.sep, '/'); + return { name, version, url: new URL(`${p}/CHANGELOG.md#${version.replace(/\./g, '')}`, baseUrl).toString() }; + }) + ); - const emoji = item(emojis); - const descriptor = item(descriptors); - const verb = item(verbs); + const emoji = item(emojis); + const descriptor = item(descriptors); + const verb = item(verbs); - if (packages.length === 1) { - const { name, version, url } = packages[0]; - console.log(`${emoji} \`${name}@${version}\` ${singularlize(verb)}\nRead the [release notes β](<${url}>)`); - } else { - console.log(`${emoji} Some ${descriptor} ${pluralize(verb)}\n`); - for (const { name, version, url } of packages) { - console.log(`β’ \`${name}@${version}\` Read the [release notes β](<${url}>)`); - } - } + if (packages.length === 1) { + const { name, version, url } = packages[0]; + console.log(`${emoji} \`${name}@${version}\` ${singularlize(verb)}\nRead the [release notes β](<${url}>)`); + } else { + console.log(`${emoji} Some ${descriptor} ${pluralize(verb)}\n`); + for (const { name, version, url } of packages) { + console.log(`β’ \`${name}@${version}\` Read the [release notes β](<${url}>)`); + } + } } run(); diff --git a/scripts/smoke/index.js b/scripts/smoke/index.js index e1e296a61..d5412adc0 100644 --- a/scripts/smoke/index.js +++ b/scripts/smoke/index.js @@ -7,25 +7,25 @@ import { fileURLToPath } from 'url'; // and update our CI to run through Turbo. export default async function run() { - const examplesUrl = new URL('../../examples/', import.meta.url); - const examplesToTest = fs - .readdirSync(examplesUrl) - .map((filename) => new URL(filename, examplesUrl)) - .filter((fileUrl) => fs.statSync(fileUrl).isDirectory()); - const allProjectsToTest = [...examplesToTest, new URL('../../www', import.meta.url), new URL('../../docs', import.meta.url)]; + const examplesUrl = new URL('../../examples/', import.meta.url); + const examplesToTest = fs + .readdirSync(examplesUrl) + .map((filename) => new URL(filename, examplesUrl)) + .filter((fileUrl) => fs.statSync(fileUrl).isDirectory()); + const allProjectsToTest = [...examplesToTest, new URL('../../www', import.meta.url), new URL('../../docs', import.meta.url)]; - console.log(''); - for (const projectToTest of allProjectsToTest) { - const filePath = fileURLToPath(projectToTest); - console.log(' π€ Testing', filePath, '\n'); - try { - await execa('yarn', ['build'], { cwd: fileURLToPath(projectToTest), stdout: 'inherit', stderr: 'inherit' }); - } catch (err) { - console.log(err); - process.exit(1); - } - console.log('\n π€ Test complete.'); - } + console.log(''); + for (const projectToTest of allProjectsToTest) { + const filePath = fileURLToPath(projectToTest); + console.log(' π€ Testing', filePath, '\n'); + try { + await execa('yarn', ['build'], { cwd: fileURLToPath(projectToTest), stdout: 'inherit', stderr: 'inherit' }); + } catch (err) { + console.log(err); + process.exit(1); + } + console.log('\n π€ Test complete.'); + } } run(); diff --git a/scripts/stats/index.js b/scripts/stats/index.js index 646896966..435bb5c56 100644 --- a/scripts/stats/index.js +++ b/scripts/stats/index.js @@ -45,77 +45,77 @@ const COLUMN_ID_BUGS_PRIORITIZED = 14946516; // const pulls = JSON.parse(readFileSync('pulls.json').toString()); async function countCards(column_id) { - return octokit.paginate('GET /projects/columns/{column_id}/cards', { - column_id, - mediaType: { - previews: ['inertia'], - }, - }); + return octokit.paginate('GET /projects/columns/{column_id}/cards', { + column_id, + mediaType: { + previews: ['inertia'], + }, + }); } async function countCommits(since) { - return octokit.paginate('GET /repos/{owner}/{repo}/commits', { - owner, - repo, - since: since.toISOString(), - }); + return octokit.paginate('GET /repos/{owner}/{repo}/commits', { + owner, + repo, + since: since.toISOString(), + }); } export async function run() { - const twentyFourHoursAgo = new Date(); - twentyFourHoursAgo.setDate(twentyFourHoursAgo.getDate() - 1); + const twentyFourHoursAgo = new Date(); + twentyFourHoursAgo.setDate(twentyFourHoursAgo.getDate() - 1); - const allOpenIssues = await octokit.paginate('GET /repos/{owner}/{repo}/issues', { - owner, - repo, - }); - const openIssues = allOpenIssues.filter((iss) => !iss.pull_request); - const openPulls = allOpenIssues.filter((iss) => iss.pull_request); + const allOpenIssues = await octokit.paginate('GET /repos/{owner}/{repo}/issues', { + owner, + repo, + }); + const openIssues = allOpenIssues.filter((iss) => !iss.pull_request); + const openPulls = allOpenIssues.filter((iss) => iss.pull_request); - const allIssuesLastTwentyFourHours = await octokit.paginate('GET /repos/{owner}/{repo}/issues', { - owner, - repo, - state: 'all', - per_page: 100, - since: twentyFourHoursAgo.toISOString(), - }); - const issuesLastTwentyFourHours = allIssuesLastTwentyFourHours.filter((iss) => new Date(iss.created_at) > twentyFourHoursAgo && !iss.pull_request); - const pullsLastTwentyFourHours = allIssuesLastTwentyFourHours.filter((iss) => new Date(iss.created_at) > twentyFourHoursAgo && iss.pull_request); + const allIssuesLastTwentyFourHours = await octokit.paginate('GET /repos/{owner}/{repo}/issues', { + owner, + repo, + state: 'all', + per_page: 100, + since: twentyFourHoursAgo.toISOString(), + }); + const issuesLastTwentyFourHours = allIssuesLastTwentyFourHours.filter((iss) => new Date(iss.created_at) > twentyFourHoursAgo && !iss.pull_request); + const pullsLastTwentyFourHours = allIssuesLastTwentyFourHours.filter((iss) => new Date(iss.created_at) > twentyFourHoursAgo && iss.pull_request); - const entry = [ - // Date (Human Readable) - `"${new Date().toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })}"`, - // Commits in last 24 hours - (await countCommits(twentyFourHoursAgo)).length, - // New Issues(All) in last 24 hours - issuesLastTwentyFourHours.length, - // New Issues(Bugs) in last 24 hours - issuesLastTwentyFourHours.filter((iss) => iss.title.startsWith('π BUG:')).length, - // New Issues(RFC) in last 24 hours - issuesLastTwentyFourHours.filter((iss) => iss.title.startsWith('π‘ RFC:')).length, - // New Issues(Docs) in last 24 hours - issuesLastTwentyFourHours.filter((iss) => iss.title.startsWith('π DOC:')).length, - // New Pull Requests in last 24 hours - pullsLastTwentyFourHours.length, - // Pull requests - openPulls.length, - // Open Issues - openIssues.length, - // Bugs: Needs Triage - (await countCards(COLUMN_ID_BUGS_NEEDS_TRIAGE)).length, - // Bugs: Accepted - (await countCards(COLUMN_ID_BUGS_ACCEPTED)).length + (await countCards(COLUMN_ID_BUGS_PRIORITIZED)).length, - // RFC: In Progress - 0, // (await countCards(COLUMN_ID_RFCS_IN_PROGRESS)).length, - // RFC: Accepted - 0, // (await countCards(COLUMN_ID_RFCS_ACCEPTED)).length + (await countCards(COLUMN_ID_RFCS_PRIORITIZED)).length, - // Date (ISO) - `"${new Date().toISOString()}"`, - ].join(','); + const entry = [ + // Date (Human Readable) + `"${new Date().toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })}"`, + // Commits in last 24 hours + (await countCommits(twentyFourHoursAgo)).length, + // New Issues(All) in last 24 hours + issuesLastTwentyFourHours.length, + // New Issues(Bugs) in last 24 hours + issuesLastTwentyFourHours.filter((iss) => iss.title.startsWith('π BUG:')).length, + // New Issues(RFC) in last 24 hours + issuesLastTwentyFourHours.filter((iss) => iss.title.startsWith('π‘ RFC:')).length, + // New Issues(Docs) in last 24 hours + issuesLastTwentyFourHours.filter((iss) => iss.title.startsWith('π DOC:')).length, + // New Pull Requests in last 24 hours + pullsLastTwentyFourHours.length, + // Pull requests + openPulls.length, + // Open Issues + openIssues.length, + // Bugs: Needs Triage + (await countCards(COLUMN_ID_BUGS_NEEDS_TRIAGE)).length, + // Bugs: Accepted + (await countCards(COLUMN_ID_BUGS_ACCEPTED)).length + (await countCards(COLUMN_ID_BUGS_PRIORITIZED)).length, + // RFC: In Progress + 0, // (await countCards(COLUMN_ID_RFCS_IN_PROGRESS)).length, + // RFC: Accepted + 0, // (await countCards(COLUMN_ID_RFCS_ACCEPTED)).length + (await countCards(COLUMN_ID_RFCS_PRIORITIZED)).length, + // Date (ISO) + `"${new Date().toISOString()}"`, + ].join(','); - const statCsv = readFileSync('scripts/stats/stats.csv', { encoding: 'utf-8' }); - const [statHeader, ...statItems] = statCsv.split('\n'); - const updatedStatCsv = [statHeader, entry, ...statItems].join('\n'); - writeFileSync('scripts/stats/stats.csv', updatedStatCsv); + const statCsv = readFileSync('scripts/stats/stats.csv', { encoding: 'utf-8' }); + const [statHeader, ...statItems] = statCsv.split('\n'); + const updatedStatCsv = [statHeader, entry, ...statItems].join('\n'); + writeFileSync('scripts/stats/stats.csv', updatedStatCsv); } run(); diff --git a/scripts/utils/svelte-plugin.js b/scripts/utils/svelte-plugin.js index f8a30ff33..29e60c2d5 100644 --- a/scripts/utils/svelte-plugin.js +++ b/scripts/utils/svelte-plugin.js @@ -4,58 +4,58 @@ import { relative, isAbsolute, join, dirname } from 'path'; import { promises as fs } from 'fs'; const convertMessage = ({ message, start, end, filename, frame }) => ({ - text: message, - location: start && - end && { - file: filename, - line: start.line, - column: start.column, - length: start.line === end.line ? end.column - start.column : 0, - lineText: frame, - }, + text: message, + location: start && + end && { + file: filename, + line: start.line, + column: start.column, + length: start.line === end.line ? end.column - start.column : 0, + lineText: frame, + }, }); const handleLoad = async (args, generate, { isDev }) => { - const { path } = args; - const source = await fs.readFile(path, 'utf8'); - const filename = relative(process.cwd(), path); + const { path } = args; + const source = await fs.readFile(path, 'utf8'); + const filename = relative(process.cwd(), path); - try { - let compileOptions = { dev: isDev, css: false, generate, hydratable: true }; + try { + let compileOptions = { dev: isDev, css: false, generate, hydratable: true }; - let { js, warnings } = compile(source, { ...compileOptions, filename }); - let contents = js.code + `\n//# sourceMappingURL=` + js.map.toUrl(); + let { js, warnings } = compile(source, { ...compileOptions, filename }); + let contents = js.code + `\n//# sourceMappingURL=` + js.map.toUrl(); - return { loader: 'js', contents, resolveDir: dirname(path), warnings: warnings.map((w) => convertMessage(w)) }; - } catch (e) { - return { errors: [convertMessage(e)] }; - } + return { loader: 'js', contents, resolveDir: dirname(path), warnings: warnings.map((w) => convertMessage(w)) }; + } catch (e) { + return { errors: [convertMessage(e)] }; + } }; export default function sveltePlugin({ isDev = false }) { - return { - name: 'svelte-esbuild', - setup(build) { - build.onResolve({ filter: /\.svelte$/ }, (args) => { - let path = args.path.replace(/\.(?:client|server)/, ''); - path = isAbsolute(path) ? path : join(args.resolveDir, path); - - if (/\.client\.svelte$/.test(args.path)) { - return { - path, - namespace: 'svelte:client', - }; - } - - if (/\.server\.svelte$/.test(args.path)) { - return { - path, - namespace: 'svelte:server', - }; - } - }); - build.onLoad({ filter: /.*/, namespace: 'svelte:client' }, (args) => handleLoad(args, 'dom', { isDev })); - build.onLoad({ filter: /.*/, namespace: 'svelte:server' }, (args) => handleLoad(args, 'ssr', { isDev })); - }, - }; + return { + name: 'svelte-esbuild', + setup(build) { + build.onResolve({ filter: /\.svelte$/ }, (args) => { + let path = args.path.replace(/\.(?:client|server)/, ''); + path = isAbsolute(path) ? path : join(args.resolveDir, path); + + if (/\.client\.svelte$/.test(args.path)) { + return { + path, + namespace: 'svelte:client', + }; + } + + if (/\.server\.svelte$/.test(args.path)) { + return { + path, + namespace: 'svelte:server', + }; + } + }); + build.onLoad({ filter: /.*/, namespace: 'svelte:client' }, (args) => handleLoad(args, 'dom', { isDev })); + build.onLoad({ filter: /.*/, namespace: 'svelte:server' }, (args) => handleLoad(args, 'ssr', { isDev })); + }, + }; } |