Skip to content

Commit

Permalink
Merge pull request #153 from reactioncommerce/fix-152-mikemurray-fix-…
Browse files Browse the repository at this point in the history
…root-exports

fix: Package root level exports
  • Loading branch information
mikemurray authored Feb 26, 2020
2 parents 131456e + 69fe363 commit 07079f8
Show file tree
Hide file tree
Showing 87 changed files with 31 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .reaction/scripts/templates/Component.test.js.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { render } from "../../tests/index.js";
import { render } from "../tests/index.js";
import COMPONENT from "./COMPONENT";

test("basic snapshot - only default props", () => {
Expand Down
2 changes: 1 addition & 1 deletion docs/component-development-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ This will merge components from a components context provider into the `componen
(3) Use mockComponents in your tests

```js
import mockComponents from "../../../tests/mockComponents";
import mockComponents from "../../tests/mockComponents";
```

Everywhere you render your component in a Jest test function:
Expand Down
2 changes: 1 addition & 1 deletion package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"private": false,
"sideEffects": false,
"scripts": {
"prebuild": "rimraf dist/**/* && rimraf dist-modules-temp && node ./scripts/prebuild.js",
"prebuild": "rimraf dist/**/* && rimraf dist-modules-temp",
"build": "npm run build:common && npm run build:modules",
"build:common": "BABEL_ENV=production babel --root-mode upward src --out-dir dist",
"build:modules": "BABEL_ENV=production BABEL_MODULES=1 babel --root-mode upward src --out-dir dist-modules-temp",
Expand Down
40 changes: 0 additions & 40 deletions package/scripts/postbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

const path = require("path");
const fse = require("fs-extra");
const replaceInFiles = require("replace-in-files");

const DIST_FOLDER = path.join(process.cwd(), "dist");
const DIST_MODULES_FOLDER = path.join(process.cwd(), "dist-modules-temp");
const COMPONENTS_FOLDER = path.join(DIST_FOLDER, "components");

/**
* @summary Recursively changes all files with one extension to another
Expand Down Expand Up @@ -64,26 +62,6 @@ async function createPackageFile() {
return newPackageData;
}

/**
* @summary After a component has been moved to `dist` and flattened,
* change all "../../../utils" to "../../utils"
* @param {String} componentFolderPath The full path to the components folder
* @returns {Promise<undefined>} Nothing
*/
async function replaceUtilsPathForComponent(componentFolderPath) {
await replaceInFiles({
files: `${componentFolderPath}/**/*.js`,
from: /\.\.\/\.\.\/utils/g,
to: "../utils"
});

await replaceInFiles({
files: `${componentFolderPath}/**/*.mjs`,
from: /\.\.\/\.\.\/utils/g,
to: "../utils"
});
}

/**
* @summary The main post-build script.
* 1. Rename all `.js` files in `dist-modules-temp` to `.mjs` extension
Expand All @@ -105,24 +83,6 @@ async function run() {
// Delete `dist-modules-temp`
await fse.remove(DIST_MODULES_FOLDER);

// We now have a `dist` folder but we want to remove the extra `components`
// folder inside it in order to have flatter import paths. We"ll traverse the `dist/components/*`
// folders here and move them up a level.
const directoryContents = await fse.readdir(COMPONENTS_FOLDER);
const promises = directoryContents.map(async (componentName) => {
if (componentName.indexOf(".") !== -1) return Promise.resolve();
const componentFolder = path.join(COMPONENTS_FOLDER, componentName);
const distComponentFolder = path.join(DIST_FOLDER, componentName);
await fse.copy(componentFolder, distComponentFolder);

// The relative path to global `utils` folder has changed, so do a multi-file search/replace
return replaceUtilsPathForComponent(distComponentFolder);
});
await Promise.all(promises);

// Then delete `dist/components`
await fse.remove(COMPONENTS_FOLDER);

// Then copy the package.json file into the `dist` folder so that we can do `npm publish dist`
// and thereby remove the `dist` from the import paths, flattening them more.
await createPackageFile();
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { fireEvent, render, waitForElement } from "../../tests/index.js";
import { fireEvent, render, waitForElement } from "../tests/index.js";
import ActionMenu from "./ActionMenu";

const options = [{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { render } from "../../tests/index.js";
import { render } from "../tests/index.js";
import Button from "./Button";

test("basic snapshot - only default props", () => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { render } from "../../tests/index.js";
import { render } from "../tests/index.js";
import Chip from "./Chip";

test("basic snapshot - only default props", () => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { render, fireEvent } from "../../tests/";
import { render, fireEvent } from "../tests/";
import Button from "../Button";
import ConfirmDialog from "./ConfirmDialog";
import useConfirmDialog from "./helpers/useConfirmDialog";
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable require-jsdoc */
/* eslint-disable react/no-multi-comp */
import React, { useMemo, useCallback, useState } from "react";
import { fireEvent, render, waitForElement } from "../../tests/index.js";
import { fireEvent, render, waitForElement } from "../tests/index.js";
import { getPaginatedData, data } from "./mocks/sampleData";
import DataTable, { useDataTable } from "./";

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { render } from "../../tests/index.js";
import { render } from "../tests/index.js";
import DataTableFilter from "./DataTableFilter";

const options = [{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { render } from "../../tests/index.js";
import { render } from "../tests/index.js";
import DialogTitle from "./DialogTitle";

test("basic snapshot - only default props", () => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { render } from "../../tests";
import { render } from "../tests";
import Select from "./Select";

const options = [
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { fireEvent, render, waitForElement } from "../../tests/index.js";
import { fireEvent, render, waitForElement } from "../tests/index.js";
import SplitButton from "./SplitButton";

const options = [{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { MenuItem } from "@material-ui/core";
import { render } from "../../tests/index.js";
import { render } from "../tests/index.js";
import TextField from "./TextField";

test("snapshot - singleline", () => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { render } from "../../tests/index.js";
import { render } from "../tests/index.js";
import Toast from "./Toast";

test("basic snapshot - only default props", () => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 11 additions & 11 deletions package/src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export { default as ActionMenu } from "./components/ActionMenu";
export { default as Button } from "./components/Button";
export { default as Chip } from "./components/Chip";
export { default as ConfirmDialog, ConfirmDialogBase, useConfirmDialog } from "./components/ConfirmDialog";
export { default as DataTable, useDataTable } from "./components/DataTable";
export { default as DataTableFilter } from "./components/DataTableFilter";
export { default as DialogTitle } from "./components/DialogTitle";
export { default as Select } from "./components/Select";
export { default as SplitButton } from "./components/SplitButton";
export { default as TextField } from "./components/TextField";
export { default as Toast } from "./components/Toast";
export { default as ActionMenu } from "./ActionMenu";
export { default as Button } from "./Button";
export { default as Chip } from "./Chip";
export { default as ConfirmDialog, ConfirmDialogBase, useConfirmDialog } from "./ConfirmDialog";
export { default as DataTable, useDataTable } from "./DataTable";
export { default as DataTableFilter } from "./DataTableFilter";
export { default as DialogTitle } from "./DialogTitle";
export { default as Select } from "./Select";
export { default as SplitButton } from "./SplitButton";
export { default as TextField } from "./TextField";
export { default as Toast } from "./Toast";
export { default as defaultTheme } from "./theme/defaultTheme";
2 changes: 1 addition & 1 deletion package/src/tests/realComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* available, in order to test event handling and such.
*/

import Button from "../components/Button";
import Button from "../Button";

export default {
Button
Expand Down
4 changes: 2 additions & 2 deletions styleguide.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const path = require("path");
const fs = require("fs");

const componentsDir = path.join(__dirname, "package/src/components");
const componentsDir = path.join(__dirname, "package/src");
const componentTree = {};

// Build componentTree from project files
if (fs.statSync(componentsDir).isDirectory()) {
const componentItems = fs.readdirSync(componentsDir);
componentItems.forEach((componentName) => {
componentTree[componentName] = path.join("./package/src/components", componentName, `${componentName}.js`);
componentTree[componentName] = path.join("./package/src", componentName, `${componentName}.js`);
});
}

Expand Down
2 changes: 1 addition & 1 deletion styleguide/src/appComponents.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Button from "../../package/src/components/Button";
import Button from "../../package/src/Button";

export default {
Button
Expand Down
2 changes: 1 addition & 1 deletion styleguide/src/sections/Card.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Card, CardHeader, CardContent, Typography } from "@material-ui/core";

```jsx
import { Card, CardHeader, CardContent, Typography } from "@material-ui/core";
import ActionMenu from "../../../package/src/components/ActionMenu";
import ActionMenu from "../../../package/src/ActionMenu";

const options = [{
label: "Open"
Expand Down
2 changes: 1 addition & 1 deletion styleguide/src/sections/QuickEditCard.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
```jsx
import { Card, CardHeader, CardContent, Grid, IconButton, Typography, Grow, FormControlLabel, Switch } from "@material-ui/core";
import CloseIcon from "mdi-material-ui/Close";
import Button from "../../../package/src/components/Button";
import Button from "../../../package/src/Button";

function GrowCard() {
const [checked, setChecked] = React.useState(false);
Expand Down

0 comments on commit 07079f8

Please sign in to comment.