Skip to content

Commit

Permalink
refactor: TS -> JS. (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
avocadowastaken authored May 6, 2021
1 parent 8f871dc commit 6ed7c48
Show file tree
Hide file tree
Showing 34 changed files with 858 additions and 638 deletions.
22 changes: 2 additions & 20 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,8 @@
},

{
"parserOptions": {
"project": "./tsconfig.json"
},
"files": "*.ts",
"extends": ["plugin:@superdispatch/ts-node"]
},

{
"files": ["**/__tests__/**/*.ts", "**/__testutils__/**/*.ts"],
"extends": "plugin:@superdispatch/ts-jest"
},

{
"parserOptions": {
"sourceType": "module"
},
"files": "**/__tests__/packages/**/*.js",
"rules": {
"strict": "off"
}
"files": ["*.spec.js", "integration/**/*.js"],
"extends": "plugin:@superdispatch/jest"
}
]
}
29 changes: 0 additions & 29 deletions .github/workflows/build.yml

This file was deleted.

18 changes: 18 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Main

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: umidbekk/actions/npm/install@v1
- run: yarn test
- uses: codecov/codecov-action@v1
7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
# Editors
.idea
.vscode

# Dependencies
node_modules/

# Distributive
/dist

# Testing
/coverage

Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## babel-plugin-direct-import

[![Build](https://github.com/umidbekk/babel-plugin-direct-import/workflows/Build/badge.svg?branch=master)](https://github.com/umidbekk/babel-plugin-direct-import/actions)
[![Main](https://github.com/umidbekk/babel-plugin-direct-import/workflows/Main/badge.svg?branch=master)](https://github.com/umidbekk/babel-plugin-direct-import/actions)
[![npm version](https://img.shields.io/npm/v/babel-plugin-direct-import.svg)](https://www.npmjs.com/package/babel-plugin-direct-import)
[![npm downloads](https://img.shields.io/npm/dm/babel-plugin-direct-import.svg)](https://www.npmjs.com/package/babel-plugin-direct-import)
[![Codecov](https://img.shields.io/codecov/c/gh/umidbekk/babel-plugin-direct-import.svg)](https://codecov.io/gh/umidbekk/babel-plugin-direct-import)
Expand Down Expand Up @@ -49,9 +49,7 @@ import ChevronRight from '@material-ui/icons/esm/ChevronRight.js';
"plugins": [
[
"babel-plugin-direct-import",
{
"modules": ["luxon", "@material-ui/core", "@material-ui/icons"]
}
{ "modules": ["luxon", "@material-ui/core", "@material-ui/icons"] }
]
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getConfigExports } from '../../../utils/getConfigExports';
'use strict';

const getModuleExports = require('../../../lib/internal/getModuleExports');

it('resolves exports for `@material-ui/core`', () => {
expect(getConfigExports({ name: '@material-ui/core' }))
.toMatchInlineSnapshot(`
expect(getModuleExports('@material-ui/core')).toMatchInlineSnapshot(`
Map {
"colors" => Object {
"external": "colors",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { runPlugin } from '../../../__testutils__/runPlugin';
'use strict';

const runPlugin = require('../../runPlugin');

describe('@material-ui/core', () => {
it('transforms imports', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { runPlugin } from '../../../__testutils__/runPlugin';
'use strict';

const runPlugin = require('../../runPlugin');

describe('@material-ui/icons', () => {
it('transforms imports', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { getConfigExports } from '../../../utils/getConfigExports';
'use strict';

const getModuleExports = require('../../../lib/internal/getModuleExports');

test('exports', () => {
expect(getConfigExports({ name: '@material-ui/lab' })).toMatchInlineSnapshot(`
expect(getModuleExports('@material-ui/lab')).toMatchInlineSnapshot(`
Map {
"Alert" => Object {
"external": "Alert",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { runPlugin } from '../../../__testutils__/runPlugin';
'use strict';

const runPlugin = require('../../runPlugin');

test('transforms', () => {
expect(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getConfigExports } from '../../../utils/getConfigExports';
'use strict';

const getModuleExports = require('../../../lib/internal/getModuleExports');

it('resolves exports for `@material-ui/styles`', () => {
expect(getConfigExports({ name: '@material-ui/styles' }))
.toMatchInlineSnapshot(`
expect(getModuleExports('@material-ui/styles')).toMatchInlineSnapshot(`
Map {
"createGenerateClassName" => Object {
"external": "createGenerateClassName",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { runPlugin } from '../../../__testutils__/runPlugin';
'use strict';

const runPlugin = require('../../runPlugin');

describe('@material-ui/styles', () => {
it('transforms imports', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { getConfigExports } from '../../utils/getConfigExports';
'use strict';

const getModuleExports = require('../../lib/internal/getModuleExports');

it('resolves exports for `luxon`', () => {
expect(getConfigExports({ name: 'luxon' })).toMatchInlineSnapshot(`
expect(getModuleExports('luxon')).toMatchInlineSnapshot(`
Map {
"DateTime" => Object {
"external": "DateTime",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { runPlugin } from '../../__testutils__/runPlugin';
'use strict';

const runPlugin = require('../runPlugin');

describe('luxon', () => {
it('transforms imports', () => {
Expand Down
30 changes: 30 additions & 0 deletions integration/runPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

const babel = require('@babel/core');
const plugin = require('../lib/plugin');

/** @type {Set<string>} */
const transformed = new Set();

expect.addSnapshotSerializer({
test(value) {
return transformed.has(value);
},
serialize(value) {
return value.trim();
},
});

/**
* @param {string} input
* @param {unknown[]} modules
* @returns {string}
*/
module.exports = function runPlugin(input, modules) {
const result = babel.transformSync(input, {
plugins: [[plugin, { modules }]],
});
if (!result?.code) return '';
transformed.add(result.code);
return result.code;
};
Loading

0 comments on commit 6ed7c48

Please sign in to comment.