diff --git a/src/index.ts b/src/index.ts index 33346d4..3780624 100644 --- a/src/index.ts +++ b/src/index.ts @@ -43,9 +43,11 @@ const deepmerge = createDeepMerge({ } }); -const fileExists = (path: string) => fs.promises.access(path, fs.constants.F_OK) - .then(() => true) - .catch(() => false); +function fileExists(path: string) { + return fs.promises.access(path, fs.constants.F_OK) + .then(() => true) + .catch(() => false); +} function swc(options: PluginOptions = {}): RollupPlugin { const filter = createFilter( @@ -116,9 +118,6 @@ function swc(options: PluginOptions = {}): RollupPlugin { ? {} : getOptions(this, dirname(id), options.tsconfig); - // TODO: SWC is about to add "preserve" jsx - // https://github.com/swc-project/swc/pull/5661 - // Respect "preserve" after swc adds the support const useReact17NewTransform = tsconfigOptions.jsx === 'react-jsx' || tsconfigOptions.jsx === 'react-jsxdev'; const swcOptionsFromTsConfig: SwcOptions = { diff --git a/src/options.ts b/src/options.ts index 0dd5fc7..32444a9 100644 --- a/src/options.ts +++ b/src/options.ts @@ -9,11 +9,11 @@ import { fileURLToPath } from 'node:url'; const cache = new Map(); -export const getOptions = ( +export function getOptions( ctx: TransformPluginContext, cwd: string, tsconfig?: string -) => { +) { const cacheKey = `${cwd}:${tsconfig ?? 'undefined'}`; if (cache.has(cacheKey)) { @@ -57,9 +57,9 @@ export const getOptions = ( cache.set(cacheKey, compilerOptions); return compilerOptions; -}; +} -export const checkIsLegacyTypeScript = () => { +export function checkIsLegacyTypeScript() { try { // @ts-expect-error -- It's required to using 'import.mtea.url' but i don't want to change the tsconfig. const tsPath = resolve('typescript/package.json', import.meta.url); @@ -70,4 +70,4 @@ export const checkIsLegacyTypeScript = () => { } catch { return false; } -}; +} diff --git a/test/index.ts b/test/index.ts index b99c0a1..eaf90d6 100644 --- a/test/index.ts +++ b/test/index.ts @@ -27,7 +27,7 @@ import { async as ezspawn } from '@jsdevtools/ez-spawn'; chai.should(); chai.use(jestSnapshotPlugin()); -const rollupInvriant = (v: RollupOutput['output'][number] | undefined | null) => { +function rollupInvriant(v: RollupOutput['output'][number] | undefined | null) { if (v == null) { throw new Error('Invariant failed'); } @@ -35,10 +35,9 @@ const rollupInvriant = (v: RollupOutput['output'][number] | undefined | null) => throw new Error('Non rollup output module found!'); } return v; -}; +} -const build = async ( - rollupImpl: typeof rollup2 | typeof rollup3 | typeof rollup4, +async function build(rollupImpl: typeof rollup2 | typeof rollup3 | typeof rollup4, options?: PluginOptions, { input = './index.js', @@ -54,8 +53,7 @@ const build = async ( sourcemap?: boolean, dir?: string, external?: ExternalOption - } = {} -) => { + } = {}) { const build = await rollupImpl({ input: (() => { if (typeof input === 'string') { @@ -79,27 +77,25 @@ const build = async ( }); const { output } = await build.generate({ format: 'esm', sourcemap }); return output; -}; +} -const runMinify = async ( - rollupImpl: typeof rollup2 | typeof rollup3 | typeof rollup4, +async function runMinify(rollupImpl: typeof rollup2 | typeof rollup3 | typeof rollup4, options: JsMinifyOptions, { input = './index.js', otherRollupPlugins = [], sourcemap = false, dir = '.' - } -) => { + }) { const build = await rollupImpl({ input: [...(Array.isArray(input) ? input : [input])].map((v) => path.resolve(dir, v)), plugins: [...otherRollupPlugins, minify(options)] as any }); const { output } = await build.generate({ format: 'esm', sourcemap }); return output; -}; +} -const tests = (rollupImpl: typeof rollup2 | typeof rollup3 | typeof rollup4, isolateDir: string) => { +function tests(rollupImpl: typeof rollup2 | typeof rollup3 | typeof rollup4, isolateDir: string) { const fixture = async (fixtureName: string) => { const fixtureDir = path.join(__dirname, 'fixtures', fixtureName); const testDir = path.join(isolateDir, 'rollup-plugin-swc', fixtureName); @@ -392,7 +388,7 @@ const tests = (rollupImpl: typeof rollup2 | typeof rollup3 | typeof rollup4, iso { input: './index.ts', dir } ))[0].code.should.matchSnapshot(); }); -}; +} describe('rollup-plugin-swc3', () => { const ramDiskPath = create.sync('rolluppluginswc3test', 64 * 1024 * 1024, { quiet: false });