Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assets integration: Fix React ES6 Exports #1098

Merged
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
31 changes: 29 additions & 2 deletions react/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,31 @@ function resolvePath(sourcePath, currentFile, opts) {
if (check.test(sourcePath)) {
const matches = check.exec(sourcePath);
resolvedPath = `${rootPath}${matches[1]}`;
// ES Modules need to list out the extension on the end of the path,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what this is doing? I looked at index.js in dist/ before and after and don't see anything different with this change:
https://github.com/massgov/mayflower/pull/1098/files#diff-1ed6f9d93c1ab4ea1481408cc9aab6daR71-R95''

// otherwise index.js will be used instead of index.mjs.
if (opts.hasOwnProperty('isES5') && opts.isES5 === false) {
// List of exports that are files and not directories.
const excludes = [
'Input/error',
'Input/context',
'Input/utility',
'Input/validate',
'TabContainer/tab',
'TabContainer/tab-body',
'TabContainer/context',
'utilities/componentPropTypeCheck',
'Breadcrumb/item',
'GenTeaser/utils'
];
// If the current path is a file and not a directory...
if (excludes.some((rule) => sourcePath.includes(rule))) {
// Add the .mjs extension.
resolvedPath = `${resolvedPath}.mjs`;
} else {
// Else, add the path to the index.mjs file the ES module needs.
resolvedPath = `${resolvedPath}/index.mjs`;
}
}
}
});
return resolvedPath || sourcePath;
Expand Down Expand Up @@ -112,7 +137,8 @@ function transpileES5() {
'module-resolver',
{
resolvePath,
alias: aliases
alias: aliases,
isES5: true
}
],
'@babel/plugin-proposal-optional-chaining',
Expand Down Expand Up @@ -170,7 +196,8 @@ function transpileES6() {
'module-resolver',
{
resolvePath,
alias: aliases
alias: aliases,
isES5: false
}
],
'@babel/plugin-proposal-optional-chaining',
Expand Down
5 changes: 3 additions & 2 deletions react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"description": "React versions of Mayflower design system UI components",
"author": "Massachusetts Digital Services (MDS)",
"version": "10.0.0",
"main": "dist/index.js",
"module": "dist/index.mjs",
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",
"sideEffects": [
"**/*.css",
"**/*.scss"
Expand All @@ -13,6 +13,7 @@
"dist"
],
"exports": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"default": "./dist/index.mjs"
},
Expand Down
2 changes: 1 addition & 1 deletion react/src/components/forms/Form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import React from 'react';
import PropTypes from 'prop-types';
import { FormContext } from '../Input/context';
import { FormContext } from 'MayflowerReactForms/Input/context';

/* eslint-disable react/no-unused-state */

Expand Down
2 changes: 1 addition & 1 deletion react/src/components/forms/Input/error.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import ErrorMessage from 'MayflowerReactForms/ErrorMessage';
import { InputContext } from './context';
import { InputContext } from 'MayflowerReactForms/Input/context';

class Error extends React.Component {
displayErrorMessage = (inputContext) => {
Expand Down
2 changes: 1 addition & 1 deletion react/src/components/forms/Input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PropTypes from 'prop-types';
import classNames from 'classnames';

import Label from 'MayflowerReactForms/Label';
import { InputContext, FormContext } from './context';
import { InputContext, FormContext } from 'MayflowerReactForms/Input/context';

/* eslint-disable react/no-unused-state */

Expand Down
2 changes: 1 addition & 1 deletion react/src/components/organisms/GenTeaser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import PhoneNumber from 'MayflowerReactContact/PhoneNumber';
import Address from 'MayflowerReactContact/Address';
import TeaserSearch from 'MayflowerReactGenTeaser/TeaserSearch';
import TeaserOrgs from 'MayflowerReactGenTeaser/TeaserOrgs';
import { buildUrl } from './utils';
import { buildUrl } from 'MayflowerReactOrganisms/GenTeaser/utils';

const GenTeaser = (props) => {
const {
Expand Down