Skip to content

Commit

Permalink
Simplify fixture a bit to easier show usage with or without esm
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Nov 17, 2020
1 parent 07cf810 commit 543f520
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
resolve,
getSource,
} from 'react-transport-dom-webpack/node-loader';
import {resolve, getSource} from 'react-transport-dom-webpack/node-loader';

export {resolve, getSource};

Expand All @@ -19,10 +16,7 @@ const babelOptions = {
export async function transformSource(source, context, defaultTransformSource) {
const {format} = context;
if (format === 'module') {
const opt = Object.assign(
{filename: context.url},
babelOptions
);
const opt = Object.assign({filename: context.url}, babelOptions);
const {code} = await babel.transformAsync(source, opt);
return {source: code};
}
Expand Down
3 changes: 3 additions & 0 deletions fixtures/flight/loader/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
2 changes: 1 addition & 1 deletion fixtures/flight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"prebuild": "cp -r ../../build/node_modules/* ./node_modules/",
"start": "concurrently \"npm run start:server\" \"npm run start:client\"",
"start:client": "node scripts/start.js",
"start:server": "NODE_ENV=development node --experimental-loader ./server/loader.mjs server",
"start:server": "NODE_ENV=development node --experimental-loader ./loader/index.js server",
"start:prod": "node scripts/build.js && NODE_ENV=production node server",
"build": "node scripts/build.js",
"test": "node scripts/test.js --env=jsdom"
Expand Down
16 changes: 12 additions & 4 deletions fixtures/flight/server/handler.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@

import {pipeToNodeWritable} from 'react-transport-dom-webpack/server';
import * as React from 'react';
import App from '../src/App.server';

module.exports = function(req, res) {
import url from 'url';

function resolve(path) {
return url.pathToFileURL(require.resolve(path)).href;
}

module.exports = async function(req, res) {
res.setHeader('Access-Control-Allow-Origin', '*');
const m = await import('../src/App.server.js');
// const m = require('../src/App.server.js');
const App = m.default.default || m.default;
pipeToNodeWritable(<App />, res, {
// TODO: Read from a map on the disk.
[require.resolve('../src/Counter.client.js')]: {
[resolve('../src/Counter.client.js')]: {
id: './src/Counter.client.js',
chunks: ['1'],
name: 'default',
},
[require.resolve('../src/ShowMore.client.js')]: {
[resolve('../src/ShowMore.client.js')]: {
id: './src/ShowMore.client.js',
chunks: ['2'],
name: 'default',
Expand Down
29 changes: 0 additions & 29 deletions fixtures/flight/server/handler.server.mjs

This file was deleted.

3 changes: 1 addition & 2 deletions fixtures/flight/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ app.get('/', function(req, res) {
delete require.cache[key];
}
}
import('./handler.server.mjs').then(m => m.default(req, res));
// require('./handler.server.js')(req, res);
require('./handler.server.js')(req, res);
});

app.listen(3001, () => {
Expand Down

0 comments on commit 543f520

Please sign in to comment.