Skip to content

Commit

Permalink
fix: invalid transformer export (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Sep 14, 2021
1 parent 1d6057c commit 4729f0b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion rollup.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = [
output: {
file: 'dist/transformer.cjs',
format: 'cjs',
exports: 'named'
exports: 'default'
},
external,
plugins: [
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/transformer.test.cjs
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/transformer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ 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))

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()
Expand Down
12 changes: 5 additions & 7 deletions src/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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) {
Expand Down Expand Up @@ -80,9 +80,7 @@ const compiler = (format, options = {}, filename, processedCode, processedMap) =
}
}

export const createTransformer = () => ({
process: processSync,
export default {
process,
processAsync
})

export default createTransformer
}

0 comments on commit 4729f0b

Please sign in to comment.