From fcba5e9996d40410ce48ec647db60e9d345df26b Mon Sep 17 00:00:00 2001 From: LFades Date: Tue, 8 Feb 2022 17:39:37 -0500 Subject: [PATCH] Updated swc plugin --- packages/local/taskfile-swc.cjs | 24 +++++++++--------------- packages/local/taskfile.js | 2 +- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/packages/local/taskfile-swc.cjs b/packages/local/taskfile-swc.cjs index a63678309..fb50e97c0 100644 --- a/packages/local/taskfile-swc.cjs +++ b/packages/local/taskfile-swc.cjs @@ -2,21 +2,19 @@ // https://github.com/lukeed/taskr/pull/305 const path = require('path') - -// eslint-disable-next-line import/no-extraneous-dependencies const transform = require('@swc/core').transform module.exports = function (task) { - // eslint-disable-next-line require-yield task.plugin( 'swc', {}, - function* (file, serverOrClient, { stripExtension, dev, outDir = 'dist', baseUrl = '' } = {}) { + function* ( + file, + { server = true, stripExtension, dev, outDir = 'dist', baseUrl = '' } = {} + ) { // Don't compile .d.ts if (file.base.endsWith('.d.ts')) return - const isClient = serverOrClient === 'client' - const swcClientOptions = { module: { type: 'es6', @@ -24,7 +22,6 @@ module.exports = function (task) { }, jsc: { loose: true, - target: 'es2016', parser: { syntax: 'typescript', @@ -42,7 +39,6 @@ module.exports = function (task) { }, }, } - const swcServerOptions = { module: { type: 'es6', @@ -50,12 +46,11 @@ module.exports = function (task) { }, env: { targets: { - node: '12.0.0', + node: '14.0.0', }, }, jsc: { loose: true, - parser: { syntax: 'typescript', dynamicImport: true, @@ -73,7 +68,7 @@ module.exports = function (task) { }, } - const swcOptions = isClient ? swcClientOptions : swcServerOptions + const swcOptions = server ? swcServerOptions : swcClientOptions // Using `outDir` and `baseUrl` build a relative path from `outDir` to // the `baseUrl` path for source maps @@ -81,16 +76,15 @@ module.exports = function (task) { const basePath = path.join(__dirname, baseUrl) const relativeFilePath = path.relative(basePath, filePath) const fullFilePath = path.join(__dirname, filePath) - const distFilePath = path.dirname(path.join(__dirname, outDir, relativeFilePath)) - + const distFilePath = path.dirname( + path.join(__dirname, outDir, relativeFilePath) + ) const options = { filename: filePath, sourceMaps: true, sourceFileName: path.relative(distFilePath, fullFilePath), - ...swcOptions, } - const output = yield transform(file.data.toString('utf-8'), options) const ext = path.extname(file.base) diff --git a/packages/local/taskfile.js b/packages/local/taskfile.js index 2bc725e93..5ba4d8a2d 100644 --- a/packages/local/taskfile.js +++ b/packages/local/taskfile.js @@ -1,7 +1,7 @@ export async function build(task, opts) { await task .source('src/**/*.+(ts|tsx|js)') - .swc('server', { dev: opts.dev, outDir: 'dist', baseUrl: 'src' }) + .swc({ dev: opts.dev, outDir: 'dist', baseUrl: 'src' }) .target('dist') .source('src/**/*.+(json|cjs)') .target('dist')