From 8041a42e7aa367d74838ce4746afab0b84456829 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Mon, 13 Sep 2021 13:33:56 -0700 Subject: [PATCH 1/2] Fix transformer export --- rollup.config.cjs | 2 +- src/transformer.js | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/rollup.config.cjs b/rollup.config.cjs index e416926..94971cf 100644 --- a/rollup.config.cjs +++ b/rollup.config.cjs @@ -14,7 +14,7 @@ module.exports = [ output: { file: 'dist/transformer.cjs', format: 'cjs', - exports: 'named' + exports: 'default' }, external, plugins: [ diff --git a/src/transformer.js b/src/transformer.js index 2e33c57..c424cce 100644 --- a/src/transformer.js +++ b/src/transformer.js @@ -10,7 +10,7 @@ const dynamicImport = async (filename) => import(pathToFileURL(filename)) /** * Jest will only call this method when running in ESM mode. */ -export const processAsync = async (source, filename, jestOptions) => { +const processAsync = async (source, filename, jestOptions) => { const options = jestOptions?.transformerConfig ?? {} const { preprocess, rootMode } = options @@ -33,7 +33,7 @@ export const processAsync = async (source, filename, jestOptions) => { * Starts a new process, so is higher overhead than processAsync. * However, Jest calls this method in CJS mode. */ -const processSync = (source, filename, jestOptions) => { +const process = (source, filename, jestOptions) => { const options = jestOptions?.transformerConfig ?? {} const { preprocess, rootMode, maxBuffer, showConsoleLog } = options if (!preprocess) { @@ -80,9 +80,7 @@ const compiler = (format, options = {}, filename, processedCode, processedMap) = } } -export const createTransformer = () => ({ - process: processSync, +export default { + process, processAsync -}) - -export default createTransformer +} From 2f1889d48e1aad018d73050c171615c08fa021ac Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Mon, 13 Sep 2021 14:01:23 -0700 Subject: [PATCH 2/2] update tests --- src/__tests__/transformer.test.cjs | 4 ++-- src/__tests__/transformer.test.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/__tests__/transformer.test.cjs b/src/__tests__/transformer.test.cjs index 096f3cd..ec13fae 100644 --- a/src/__tests__/transformer.test.cjs +++ b/src/__tests__/transformer.test.cjs @@ -1,11 +1,11 @@ const { readFileSync } = require('fs') const { resolve } = require('path') -const { createTransformer } = require('../../dist/transformer.cjs') +const transformer = require('../../dist/transformer.cjs') const runTransformer = (filename, options) => { const path = require.resolve(`./fixtures/${filename}.svelte`) const source = readFileSync(path).toString() - const result = createTransformer().process(source, path, { transformerConfig: options }) + const result = transformer.process(source, path, { transformerConfig: options }) expect(result.code).toBeDefined() expect(result.code).toContain('SvelteComponent') expect(result.map).toBeDefined() diff --git a/src/__tests__/transformer.test.js b/src/__tests__/transformer.test.js index f700393..075ede5 100644 --- a/src/__tests__/transformer.test.js +++ b/src/__tests__/transformer.test.js @@ -3,7 +3,7 @@ import { dirname } from 'path' import { fileURLToPath } from 'url' import { jest } from '@jest/globals' -import { processAsync } from '../../dist/transformer.mjs' +import transformer from '../../dist/transformer.mjs' // Node API __dirname is missing in ESM export const __dirname = dirname(fileURLToPath(import.meta.url)) @@ -11,7 +11,7 @@ export const __dirname = dirname(fileURLToPath(import.meta.url)) const runTransformer = async (filename, options) => { const path = `${__dirname}/fixtures/${filename}.svelte` const source = readFileSync(path).toString() - const result = await processAsync(source, path, { transformerConfig: options }) + const result = await transformer.processAsync(source, path, { transformerConfig: options }) expect(result.code).toBeDefined() expect(result.code).toContain('SvelteComponent') expect(result.map).toBeDefined()