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

Support for re-exporting ES6 modules #11

Open
frenzzy opened this issue Jul 31, 2019 · 2 comments
Open

Support for re-exporting ES6 modules #11

frenzzy opened this issue Jul 31, 2019 · 2 comments

Comments

@frenzzy
Copy link

frenzzy commented Jul 31, 2019

IN example:

module.exports = require('./lib/index.js');

OUT actual:

import _libIndexJs from "./lib/index.js";
var module = {
  exports: {}
};
var exports = module.exports;

module.exports = _libIndexJs;
export default module.exports;

OUT expected:

export * from "./lib/index.js";

Source Code: https://unpkg.com/[email protected]/index.js

import { graphql } from 'react-relay'
// Uncaught SyntaxError: The requested module 'node_modules/react-relay/index.js' does not provide an export named 'graphql'
@frenzzy
Copy link
Author

frenzzy commented Jul 31, 2019

Would be cool to support named exports too

Source code: https://unpkg.com/[email protected]/lib/index.js

IN example:

var ReactRelayContext = require("./ReactRelayContext");
var ReactRelayFragmentContainer = require("./ReactRelayFragmentContainer");
var ReactRelayPaginationContainer = require("./ReactRelayPaginationContainer");
var ReactRelayQueryRenderer = require("./ReactRelayQueryRenderer");
var ReactRelayRefetchContainer = require("./ReactRelayRefetchContainer");
var RelayRuntime = require("relay-runtime");

module.exports = {
  QueryRenderer: ReactRelayQueryRenderer,
  MutationTypes: RelayRuntime.MutationTypes,
  RangeOperations: RelayRuntime.RangeOperations,
  ReactRelayContext: ReactRelayContext,
  applyOptimisticMutation: RelayRuntime.applyOptimisticMutation,
  commitLocalUpdate: RelayRuntime.commitLocalUpdate,
  commitMutation: RelayRuntime.commitMutation,
  createFragmentContainer: ReactRelayFragmentContainer.createContainer,
  createPaginationContainer: ReactRelayPaginationContainer.createContainer,
  createRefetchContainer: ReactRelayRefetchContainer.createContainer,
  fetchQuery: RelayRuntime.fetchQuery,
  graphql: RelayRuntime.graphql,
  requestSubscription: RelayRuntime.requestSubscription
};

OUT actual:

import _relayRuntime from "relay-runtime";
import _ReactRelayRefetchContainer from "./ReactRelayRefetchContainer";
import _ReactRelayQueryRenderer from "./ReactRelayQueryRenderer";
import _ReactRelayPaginationContainer from "./ReactRelayPaginationContainer";
import _ReactRelayFragmentContainer from "./ReactRelayFragmentContainer";
import _ReactRelayContext from "./ReactRelayContext";
var module = {
  exports: {}
};
var exports = module.exports;
var ReactRelayContext = _ReactRelayContext;
var ReactRelayFragmentContainer = _ReactRelayFragmentContainer;
var ReactRelayPaginationContainer = _ReactRelayPaginationContainer;
var ReactRelayQueryRenderer = _ReactRelayQueryRenderer;
var ReactRelayRefetchContainer = _ReactRelayRefetchContainer;
var RelayRuntime = _relayRuntime;

module.exports = {
  QueryRenderer: ReactRelayQueryRenderer,
  MutationTypes: RelayRuntime.MutationTypes,
  RangeOperations: RelayRuntime.RangeOperations,
  ReactRelayContext: ReactRelayContext,
  applyOptimisticMutation: RelayRuntime.applyOptimisticMutation,
  commitLocalUpdate: RelayRuntime.commitLocalUpdate,
  commitMutation: RelayRuntime.commitMutation,
  createFragmentContainer: ReactRelayFragmentContainer.createContainer,
  createPaginationContainer: ReactRelayPaginationContainer.createContainer,
  createRefetchContainer: ReactRelayRefetchContainer.createContainer,
  fetchQuery: RelayRuntime.fetchQuery,
  graphql: RelayRuntime.graphql,
  requestSubscription: RelayRuntime.requestSubscription
};
export default module.exports;

OUT expected:

import _relayRuntime from "relay-runtime";
import _ReactRelayRefetchContainer from "./ReactRelayRefetchContainer";
import _ReactRelayQueryRenderer from "./ReactRelayQueryRenderer";
import _ReactRelayPaginationContainer from "./ReactRelayPaginationContainer";
import _ReactRelayFragmentContainer from "./ReactRelayFragmentContainer";
import _ReactRelayContext from "./ReactRelayContext";
var module = {
  exports: {}
};
var exports = module.exports;
var ReactRelayContext = _ReactRelayContext;
var ReactRelayFragmentContainer = _ReactRelayFragmentContainer;
var ReactRelayPaginationContainer = _ReactRelayPaginationContainer;
var ReactRelayQueryRenderer = _ReactRelayQueryRenderer;
var ReactRelayRefetchContainer = _ReactRelayRefetchContainer;
var RelayRuntime = _relayRuntime;

module.exports = {
  QueryRenderer: ReactRelayQueryRenderer,
  MutationTypes: RelayRuntime.MutationTypes,
  RangeOperations: RelayRuntime.RangeOperations,
  ReactRelayContext: ReactRelayContext,
  applyOptimisticMutation: RelayRuntime.applyOptimisticMutation,
  commitLocalUpdate: RelayRuntime.commitLocalUpdate,
  commitMutation: RelayRuntime.commitMutation,
  createFragmentContainer: ReactRelayFragmentContainer.createContainer,
  createPaginationContainer: ReactRelayPaginationContainer.createContainer,
  createRefetchContainer: ReactRelayRefetchContainer.createContainer,
  fetchQuery: RelayRuntime.fetchQuery,
  graphql: RelayRuntime.graphql,
  requestSubscription: RelayRuntime.requestSubscription
};
export const { // <====== NAMED EXPORTS ADDED
  QueryRenderer,
  MutationTypes,
  RangeOperations,
  ReactRelayContext,
  applyOptimisticMutation,
  commitLocalUpdate,
  commitMutation,
  createFragmentContainer,
  createPaginationContainer,
  createRefetchContainer,
  fetchQuery,
  graphql,
  requestSubscription,
} = module.exports;
export default module.exports;

Is it possible/doable?

See also rollup-plugin-commonjs and its namedExports option for inspiration.

@screetBloom
Copy link

Any progress so far?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants