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

[pull] master from facebook:master #120

Merged
merged 2 commits into from
Dec 1, 2020
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
14 changes: 12 additions & 2 deletions fixtures/flight/loader/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {resolve, getSource} from 'react-transport-dom-webpack/node-loader';
import {
resolve,
getSource,
transformSource as reactTransformSource,
} from 'react-transport-dom-webpack/node-loader';

export {resolve, getSource};

Expand All @@ -13,7 +17,7 @@ const babelOptions = {
],
};

export async function transformSource(source, context, defaultTransformSource) {
async function babelTransformSource(source, context, defaultTransformSource) {
const {format} = context;
if (format === 'module') {
const opt = Object.assign({filename: context.url}, babelOptions);
Expand All @@ -22,3 +26,9 @@ export async function transformSource(source, context, defaultTransformSource) {
}
return defaultTransformSource(source, context, defaultTransformSource);
}

export async function transformSource(source, context, defaultTransformSource) {
return reactTransformSource(source, context, (s, c) => {
return babelTransformSource(s, c, defaultTransformSource);
});
}
File renamed without changes.
33 changes: 27 additions & 6 deletions fixtures/flight/server/handler.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,35 @@ module.exports = async function(req, res) {
pipeToNodeWritable(<App />, res, {
// TODO: Read from a map on the disk.
[resolve('../src/Counter.client.js')]: {
id: './src/Counter.client.js',
chunks: ['1'],
name: 'default',
Counter: {
id: './src/Counter.client.js',
chunks: ['2'],
name: 'Counter',
},
},
[resolve('../src/Counter2.client.js')]: {
Counter: {
id: './src/Counter2.client.js',
chunks: ['1'],
name: 'Counter',
},
},
[resolve('../src/ShowMore.client.js')]: {
id: './src/ShowMore.client.js',
chunks: ['2'],
name: 'default',
default: {
id: './src/ShowMore.client.js',
chunks: ['3'],
name: 'default',
},
'': {
id: './src/ShowMore.client.js',
chunks: ['3'],
name: '',
},
'*': {
id: './src/ShowMore.client.js',
chunks: ['3'],
name: '*',
},
},
});
};
3 changes: 2 additions & 1 deletion fixtures/flight/server/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"type": "commonjs"
"type": "commonjs",
"main": "./cli.server.js"
}
4 changes: 3 additions & 1 deletion fixtures/flight/src/App.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import * as React from 'react';

import Container from './Container.js';

import Counter from './Counter.client.js';
import {Counter} from './Counter.client.js';
import {Counter as Counter2} from './Counter2.client.js';

import ShowMore from './ShowMore.client.js';

Expand All @@ -11,6 +12,7 @@ export default function App() {
<Container>
<h1>Hello, world</h1>
<Counter />
<Counter2 />
<ShowMore>
<p>Lorem ipsum</p>
</ShowMore>
Expand Down
2 changes: 1 addition & 1 deletion fixtures/flight/src/Counter.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';

import Container from './Container.js';

export default function Counter() {
export function Counter() {
const [count, setCount] = React.useState(0);
return (
<Container>
Expand Down
1 change: 1 addition & 0 deletions fixtures/flight/src/Counter2.client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Counter.client.js';
1 change: 1 addition & 0 deletions packages/react-transport-dom-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"webpack": "^4.43.0"
},
"dependencies": {
"acorn": "^6.2.1",
"loose-envify": "^1.1.0",
"object-assign": "^4.1.1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,16 @@ export function requireModule<T>(moduleData: ModuleReference<T>): T {
throw entry;
}
}
return __webpack_require__(moduleData.id)[moduleData.name];
const moduleExports = __webpack_require__(moduleData.id);
if (moduleData.name === '*') {
// This is a placeholder value that represents that the caller imported this
// as a CommonJS module as is.
return moduleExports;
}
if (moduleData.name === '') {
// This is a placeholder value that represents that the caller accessed the
// default property of this if it was an ESM interop module.
return moduleExports.__esModule ? moduleExports.default : moduleExports;
}
return moduleExports[moduleData.name];
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
*/

type WebpackMap = {
[filename: string]: ModuleMetaData,
[filepath: string]: {
[name: string]: ModuleMetaData,
},
};

export type BundlerConfig = WebpackMap;

// eslint-disable-next-line no-unused-vars
export type ModuleReference<T> = {
$$typeof: Symbol,
filepath: string,
name: string,
};

Expand All @@ -30,7 +33,7 @@ export type ModuleKey = string;
const MODULE_TAG = Symbol.for('react.module.reference');

export function getModuleKey(reference: ModuleReference<any>): ModuleKey {
return reference.name;
return reference.filepath + '#' + reference.name;
}

export function isModuleReference(reference: Object): boolean {
Expand All @@ -41,5 +44,5 @@ export function resolveModuleMetaData<T>(
config: BundlerConfig,
moduleReference: ModuleReference<T>,
): ModuleMetaData {
return config[moduleReference.name];
return config[moduleReference.filepath][moduleReference.name];
}
Loading