Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix transformer export #75

Merged
merged 2 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}