Skip to content

Commit

Permalink
chore: make eslint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Oct 10, 2024
1 parent 0e39007 commit 44f9a25
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
11 changes: 5 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 = {
Expand Down
10 changes: 5 additions & 5 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { fileURLToPath } from 'node:url';

const cache = new Map<string, TsConfigJson.CompilerOptions>();

export const getOptions = (
export function getOptions(
ctx: TransformPluginContext,
cwd: string,
tsconfig?: string
) => {
) {
const cacheKey = `${cwd}:${tsconfig ?? 'undefined'}`;

if (cache.has(cacheKey)) {
Expand Down Expand Up @@ -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);
Expand All @@ -70,4 +70,4 @@ export const checkIsLegacyTypeScript = () => {
} catch {
return false;
}
};
}
24 changes: 10 additions & 14 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@ 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');
}
if (!('code' in v)) {
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',
Expand All @@ -54,8 +53,7 @@ const build = async (
sourcemap?: boolean,
dir?: string,
external?: ExternalOption
} = {}
) => {
} = {}) {
const build = await rollupImpl({
input: (() => {
if (typeof input === 'string') {
Expand All @@ -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);
Expand Down Expand Up @@ -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 });
Expand Down

0 comments on commit 44f9a25

Please sign in to comment.