Skip to content

Commit

Permalink
Use alias to get rid of .. paths
Browse files Browse the repository at this point in the history
Lots of ../../.. in the source and in the docs made things pretty cumbersome. Now, there's an alias `@` which points to the root directory. I went with `@` instead of a name like `root` just to avoid any confusion thinking there's a real npm module with that name.

Also, this could have been done with a single babel plugin, but there seems to be some concern that jest or webpack caching may break, so instead I went with tool-specific plugins/settings for webpack/jest/rollup.

tleunen/babel-plugin-module-resolver#346
  • Loading branch information
jdeal committed Feb 23, 2019
1 parent ff5471a commit 9d312da
Show file tree
Hide file tree
Showing 114 changed files with 276 additions and 256 deletions.
2 changes: 1 addition & 1 deletion __tests__/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-dom/test-utils';

import Formatic from '../src/formatic';
import Formatic from '@/src/formatic';

describe('actions', function() {
const mounted = function(element) {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/field-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import React from 'react';
import { mount } from 'enzyme';

import Formatic from '../../src/formatic';
import FieldContainer from '../../src/components/field-container';
import Formatic from '@/src/formatic';
import FieldContainer from '@/src/components/field-container';

describe('FieldContainer', () => {
it('should pass in onChangeValue', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/fields/array.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/

import { renderFieldsToHtml } from '../../../FormaticTestUtils';
import arrayExample from '../../../demo/examples/array';
import { renderFieldsToHtml } from '@/src/FormaticTestUtils';
import arrayExample from '@/demo/examples/array';

describe('array field', () => {
it('should render correctly', () => {
Expand Down
6 changes: 3 additions & 3 deletions __tests__/components/fields/assoc-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import React from 'react';
import TestUtils from 'react-dom/test-utils';

import Formatic from '../../../src/formatic';
import { renderFieldsToHtml } from '../../../FormaticTestUtils';
import assocListExample from '../../../demo/examples/assoc-list';
import Formatic from '@/src/formatic';
import { renderFieldsToHtml } from '@/src/FormaticTestUtils';
import assocListExample from '@/demo/examples/assoc-list';

const renderedKeys = doc => {
const inputs = TestUtils.scryRenderedDOMComponentsWithTag(doc, 'input');
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/fields/boolean.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/

import { renderFieldsToHtml } from '../../../FormaticTestUtils';
import booleanExample from '../../../demo/examples/boolean';
import { renderFieldsToHtml } from '@/src/FormaticTestUtils';
import booleanExample from '@/demo/examples/boolean';

describe('boolean field', () => {
it('should render correctly', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/fields/checkbox-array.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/

import { renderFieldsToHtml } from '../../../FormaticTestUtils';
import checkboxArrayExample from '../../../demo/examples/checkbox-array';
import { renderFieldsToHtml } from '@/src/FormaticTestUtils';
import checkboxArrayExample from '@/demo/examples/checkbox-array';

describe('checkbox-array field', () => {
it('should render correctly', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/fields/checkbox-boolean.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/

import { renderFieldsToHtml } from '../../../FormaticTestUtils';
import checkboxBooleanExample from '../../../demo/examples/checkbox-boolean';
import { renderFieldsToHtml } from '@/src/FormaticTestUtils';
import checkboxBooleanExample from '@/demo/examples/checkbox-boolean';

describe('checkbox-boolean field', () => {
it('should render correctly', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/fields/code.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/

import { renderFieldsToHtml } from '../../../FormaticTestUtils';
import codeExample from '../../../demo/examples/code';
import { renderFieldsToHtml } from '@/src/FormaticTestUtils';
import codeExample from '@/demo/examples/code';

describe('code field', () => {
it('should render correctly', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/fields/copy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/

import { renderFieldsToHtml } from '../../../FormaticTestUtils';
import copyExample from '../../../demo/examples/copy';
import { renderFieldsToHtml } from '@/src/FormaticTestUtils';
import copyExample from '@/demo/examples/copy';

describe('copy field', () => {
it('should render correctly', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/fields/fields.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/

import { renderFieldsToHtml } from '../../../FormaticTestUtils';
import fieldsExample from '../../../demo/examples/fields';
import { renderFieldsToHtml } from '@/src/FormaticTestUtils';
import fieldsExample from '@/demo/examples/fields';

describe('fields field', () => {
it('should render correctly', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/fields/grouped-fields.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/

import { renderFieldsToHtml } from '../../../FormaticTestUtils';
import groupedFieldsExample from '../../../demo/examples/grouped-fields';
import { renderFieldsToHtml } from '@/src/FormaticTestUtils';
import groupedFieldsExample from '@/demo/examples/grouped-fields';

describe('grouped-fields field', () => {
it('should render correctly', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/fields/json.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/

import { renderFieldsToHtml } from '../../../FormaticTestUtils';
import jsonExample from '../../../demo/examples/json';
import { renderFieldsToHtml } from '@/src/FormaticTestUtils';
import jsonExample from '@/demo/examples/json';

describe('json field', () => {
it('should render correctly', () => {
Expand Down
8 changes: 4 additions & 4 deletions __tests__/components/fields/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import React from 'react';
import TestUtils from 'react-dom/test-utils';
import ReactDOM from 'react-dom';
import Formatic from '../../../src/formatic';
import ObjectClass from '../../../src/components/fields/object';
import { renderFieldsToHtml } from '../../../FormaticTestUtils';
import objectExample from '../../../demo/examples/object';
import Formatic from '@/src/formatic';
import ObjectClass from '@/src/components/fields/object';
import { renderFieldsToHtml } from '@/src/FormaticTestUtils';
import objectExample from '@/demo/examples/object';

const renderedKeys = doc => {
const inputs = TestUtils.scryRenderedDOMComponentsWithTag(doc, 'input');
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/fields/password.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/

import { renderFieldsToHtml } from '../../../FormaticTestUtils';
import passwordExample from '../../../demo/examples/password';
import { renderFieldsToHtml } from '@/src/FormaticTestUtils';
import passwordExample from '@/demo/examples/password';

describe('password field', () => {
it('should render correctly', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/fields/pretty-boolean.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/

import { renderFieldsToHtml } from '../../../FormaticTestUtils';
import prettyBooleanExample from '../../../demo/examples/pretty-boolean';
import { renderFieldsToHtml } from '@/src/FormaticTestUtils';
import prettyBooleanExample from '@/demo/examples/pretty-boolean';

describe('pretty-boolean field', () => {
it('should render correctly', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/fields/pretty-select.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/

import { renderFieldsToHtml } from '../../../FormaticTestUtils';
import prettySelectExample from '../../../demo/examples/pretty-select';
import { renderFieldsToHtml } from '@/src/FormaticTestUtils';
import prettySelectExample from '@/demo/examples/pretty-select';

describe('pretty-select field', () => {
it('should render correctly', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/fields/pretty-text.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/

import { renderFieldsToHtml } from '../../../FormaticTestUtils';
import prettyBooleanExample from '../../../demo/examples/pretty-boolean';
import { renderFieldsToHtml } from '@/src/FormaticTestUtils';
import prettyBooleanExample from '@/demo/examples/pretty-boolean';

describe('pretty-boolean field', () => {
it('should render correctly', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/fields/select.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/

import { renderFieldsToHtml } from '../../../FormaticTestUtils';
import selectExample from '../../../demo/examples/select';
import { renderFieldsToHtml } from '@/src/FormaticTestUtils';
import selectExample from '@/demo/examples/select';

describe('select field', () => {
it('should render correctly', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/fields/single-line-string.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/

import { renderFieldsToHtml } from '../../../FormaticTestUtils';
import singleLineStringExample from '../../../demo/examples/single-line-string';
import { renderFieldsToHtml } from '@/src/FormaticTestUtils';
import singleLineStringExample from '@/demo/examples/single-line-string';

describe('single-line-string field', () => {
it('should render correctly', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/fields/string.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/

import { renderFieldsToHtml } from '../../../FormaticTestUtils';
import stringExample from '../../../demo/examples/string';
import { renderFieldsToHtml } from '@/src/FormaticTestUtils';
import stringExample from '@/demo/examples/string';

describe('string field', () => {
it('should render correctly', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/helpers/tag-translator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

/* global describe it expect */

import TagTranslator from '../../../src/components/helpers/tag-translator';
import TagTranslator from '@/src/components/helpers/tag-translator';

import Formatic from '../../../src/formatic';
import Formatic from '@/src/formatic';

describe('editor-util', function() {
const replaceChoices = [
Expand Down
4 changes: 2 additions & 2 deletions __tests__/components/mixins/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import React from 'react';
import createReactClass from 'create-react-class';
import { mount } from 'enzyme';

import FieldMixin from '../../../src/mixins/field';
import HelperMixin from '../../../src/mixins/helper';
import FieldMixin from '@/src/mixins/field';
import HelperMixin from '@/src/mixins/helper';

const MyHelper = createReactClass({
displayName: 'MyHelper',
Expand Down
2 changes: 1 addition & 1 deletion __tests__/plugins.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/
'use strict';

import Formatic from '../src/formatic';
import Formatic from '@/src/formatic';

describe('plugins', function() {
it('can create a new default configuration', function() {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-dom/test-utils';
import _ from 'lodash';
import Formatic from '../src/formatic';
import Formatic from '@/src/formatic';

const printTree = function(node, indent) {
indent = indent || '';
Expand Down
2 changes: 1 addition & 1 deletion __tests__/undash.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/
'use strict';

import _ from '../src/undash';
import _ from '@/src/undash';

describe('utils', () => {
it('should flatten', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/
'use strict';

import utils, { argumentsToArray } from '../src/utils';
import utils, { argumentsToArray } from '@/src/utils';

describe('utils', function() {
it('should deep copy primitives', function() {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/validation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*global describe, it, expect*/
'use strict';

import Formatic from '../src/formatic';
import Formatic from '@/src/formatic';

describe('types and value changes', function() {
const config = Formatic.createConfig();
Expand Down
12 changes: 11 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
module.exports = {
presets: [['@babel/preset-env'], ['@babel/preset-react']],
plugins: [['@babel/proposal-class-properties']],
plugins: [
['@babel/proposal-class-properties'],
// [
// 'module-resolver',
// {
// alias: {
// root: '.',
// },
// },
// ],
],
};
8 changes: 8 additions & 0 deletions babel.config.next.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ module.exports = {
sourceMap: true,
},
],
// [
// 'module-resolver',
// {
// alias: {
// root: '.',
// },
// },
// ],
],
env: {
test: {
Expand Down
2 changes: 1 addition & 1 deletion docs/components/Button.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @jsx jsx */
import { jsx, css } from '@emotion/core';

import Colors from '../styles/Colors';
import Colors from '@/docs/styles/Colors';

const getTag = props => {
if (props.isDisabled) {
Expand Down
2 changes: 1 addition & 1 deletion docs/components/Container.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @jsx jsx */
import { jsx, css } from '@emotion/core';

import { getMediaQueriesForWidths } from '../styles/Media';
import { getMediaQueriesForWidths } from '@/docs/styles/Media';

const styles = {
container: css({
Expand Down
2 changes: 1 addition & 1 deletion docs/components/Example.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @jsx jsx */
import { jsx, css } from '@emotion/core';

import Colors from '../styles/Colors';
import Colors from '@/docs/styles/Colors';

const styles = {
example: css({
Expand Down
2 changes: 1 addition & 1 deletion docs/components/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { jsx, css } from '@emotion/core';

import Container from './Container';
import Colors from '../styles/Colors';
import Colors from '@/docs/styles/Colors';

const styles = {
footer: css({
Expand Down
6 changes: 3 additions & 3 deletions docs/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import { jsx, css } from '@emotion/core';

import Container from './Container';
import Colors from '../styles/Colors';
import Typography from '../styles/Typography';
import { getMediaQueriesForWidths } from '../styles/Media';
import Colors from '@/docs/styles/Colors';
import Typography from '@/docs/styles/Typography';
import { getMediaQueriesForWidths } from '@/docs/styles/Media';

const styles = {
header: css({
Expand Down
4 changes: 2 additions & 2 deletions docs/components/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { jsx, css } from '@emotion/core';
import NextLink from 'next/link';

import Colors from '../styles/Colors';
import { prefixHref } from '../utils';
import Colors from '@/docs/styles/Colors';
import { prefixHref } from '@/docs/utils';

const styles = {
link: css({
Expand Down
8 changes: 4 additions & 4 deletions docs/components/NavMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { Toggle } from 'react-powerplug';
import { RawLink, NavLink } from './Link';
import Container from './Container';
import Icon from './Icon';
import Colors from '../styles/Colors';
import { getMediaQueriesForWidths } from '../styles/Media';
import Colors from '@/docs/styles/Colors';
import { getMediaQueriesForWidths } from '@/docs/styles/Media';

import MenuIcon from '../../static/icons/menu.svg';
import DeleteIcon from '../../static/icons/delete.svg';
import MenuIcon from '@/static/icons/menu.svg';
import DeleteIcon from '@/static/icons/delete.svg';

const styles = {
navWrapper: css({
Expand Down
6 changes: 3 additions & 3 deletions docs/components/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import { jsx, css } from '@emotion/core';
import Layout from './Layout';

import Typography from '../styles/Typography';
import Typography from '@/docs/styles/Typography';

import 'sanitize.css';
import 'codemirror/lib/codemirror.css';
import '../../static/css/app.css';
import '../../static/css/formatic.css';
import '@/static/css/app.css';
import '@/static/css/formatic.css';

const pages = {
start: {
Expand Down
Loading

0 comments on commit 9d312da

Please sign in to comment.