-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support ESM module loaders in Flight fixture (#20229)
This lets the Flight fixture run as "type": "module" or "commonjs". Experimental loaders can be used similar to require.extensions to do the transpilation and replacement of .client.js references.
- Loading branch information
1 parent
760d9ab
commit e41fd1f
Showing
13 changed files
with
108 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "commonjs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "commonjs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {pipeToNodeWritable} from 'react-transport-dom-webpack/server.js'; | ||
import * as React from 'react'; | ||
import App from '../src/App.server.js'; | ||
|
||
import {URL} from 'url'; | ||
|
||
const rootPath = import.meta.url; | ||
function resolve(relative) { | ||
return new URL(relative, rootPath).href; | ||
} | ||
|
||
export default function(req, res) { | ||
res.setHeader('Access-Control-Allow-Origin', '*'); | ||
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', | ||
}, | ||
[resolve('../src/ShowMore.client.js')]: { | ||
id: './src/ShowMore.client.js', | ||
chunks: ['2'], | ||
name: 'default', | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import babel from '@babel/core'; | ||
|
||
const options = { | ||
babelrc: false, | ||
ignore: [/\/(build|node_modules)\//], | ||
plugins: [ | ||
'@babel/plugin-syntax-import-meta', | ||
'@babel/plugin-transform-react-jsx', | ||
], | ||
}; | ||
|
||
const optionsCommonJS = { | ||
ignore: [/\/(build|node_modules)\//], | ||
presets: ['react-app'], | ||
plugins: ['@babel/transform-modules-commonjs'], | ||
}; | ||
|
||
export async function transformSource(source, context, defaultTransformSource) { | ||
const {format} = context; | ||
if (format === 'module' || format === 'commonjs') { | ||
const opt = Object.assign( | ||
{filename: context.url}, | ||
format === 'commonjs' ? optionsCommonJS : options | ||
); | ||
const {code} = await babel.transformAsync(source, opt); | ||
return {source: code}; | ||
} | ||
return defaultTransformSource(source, context); | ||
} | ||
|
||
export async function getSource(url, context, defaultGetSource) { | ||
if (url.endsWith('.client.js')) { | ||
const name = url; | ||
return { | ||
source: | ||
"export default { $$typeof: Symbol.for('react.module.reference'), name: " + | ||
JSON.stringify(name) + | ||
'}', | ||
}; | ||
} | ||
return defaultGetSource(url, context, defaultGetSource); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "commonjs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e41fd1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good