Skip to content
Open
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
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ jobs:
- run: pnpm i --frozen-lockfile
- run: pnpm test

test-babel-8:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 22.x
cache: pnpm
- run: pnpm i
- run: pnpm i @babel/core@^8.0.0-0 @babel/plugin-syntax-decorators@^8.0.0-0 @babel/plugin-transform-typescript@^8.0.0-0 --save
- run: pnpm test

floating:
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */

const runNatively = !!process.features.typescript;

module.exports = {
runner: runNatively ? 'jest-light-runner' : undefined,
preset: 'ts-jest/presets/default-esm',
testEnvironment: 'node',
moduleDirectories: ['node_modules', 'src'],
Expand All @@ -9,6 +13,7 @@ module.exports = {
diagnostics: {
ignoreCodes: [151001],
},
useESM: runNatively,
},
},
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.4.7",
"jest-light-runner": "^0.7.10",
"release-plan": "^0.9.0",
"rimraf": "^3.0.2",
"ts-jest": "^27.1.3",
Expand Down
1,199 changes: 1,187 additions & 12 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { transformAsync, createConfigItem } from '@babel/core';
// @ts-expect-error Type definitions don't know about createConfigItemSync
import { transformAsync, createConfigItemSync } from '@babel/core';
import type { VisitNodeObject, Node } from '@babel/traverse';
import { format, Options as PrettierOptions } from 'prettier';
import { format, type Options as PrettierOptions } from 'prettier';

// @ts-expect-error We're only importing so we can create a config item, so we don't care about types
import bts from '@babel/plugin-transform-typescript';
const babelTsTransform = createConfigItem([
const babelTsTransform = createConfigItemSync([
bts,
{ allowDeclareFields: true, onlyRemoveTypeImports: true },
]);

// @ts-expect-error We're only importing so we can create a config item, so we don't care about types
import bsd from '@babel/plugin-syntax-decorators';
const babelDecoratorSyntax = createConfigItem([bsd, { legacy: true }]);
const babelDecoratorSyntax = createConfigItemSync([bsd, { version: 'legacy' }]);

export async function removeTypes(code: string, prettierConfig: PrettierOptions | boolean = true) {
// Babel collapses newlines all over the place, which messes with the formatting of almost any
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { removeTypes } from '../src';
import { removeTypes } from '../src/index.ts';

describe('removeTypes', () => {
it(`preserves default exports`, async () => {
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"target": "es2020",
"module": "es2020",
"removeComments": true,
"allowImportingTsExtensions": true,

"strict": true,
"noUnusedLocals": true,
Expand Down