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

add gql file extension #4691

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 6 additions & 1 deletion packages/babel-plugin-named-asset-import/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ function namedAssetImportPlugin({ types: t }) {

return {
visitor: {
ImportDeclaration(path, { opts: { loaderMap } }) {
ImportDeclaration(
path,
{
opts: { loaderMap },
}
) {
const sourcePath = path.node.source.value;
const ext = extname(sourcePath).substr(1);

Expand Down
2 changes: 1 addition & 1 deletion packages/react-dev-utils/FileSizeReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function printFileSizesAfterBuild(
name: path.basename(asset.name),
size: size,
sizeLabel:
filesize(size) + (difference ? ' (' + difference + ')' : '')
filesize(size) + (difference ? ' (' + difference + ')' : ''),
};
})
)
Expand Down
3 changes: 2 additions & 1 deletion packages/react-dev-utils/ModuleScopePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class ModuleScopePlugin {
} else {
callback();
}
});
}
);
}
}

Expand Down
4 changes: 3 additions & 1 deletion packages/react-dev-utils/clearConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
'use strict';

function clearConsole() {
process.stdout.write(process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H');
process.stdout.write(
process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H'
);
}

module.exports = clearConsole;
4 changes: 3 additions & 1 deletion packages/react-dev-utils/getProcessForPort.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ function getProcessCommand(processId, processDirectory) {

function getDirectoryOfProcessById(processId) {
return execSync(
'lsof -p ' + processId + ' | awk \'$4=="cwd" {for (i=9; i<=NF; i++) printf "%s ", $i}\'',
'lsof -p ' +
processId +
' | awk \'$4=="cwd" {for (i=9; i<=NF; i++) printf "%s ", $i}\'',
execOptions
).trim();
}
Expand Down
6 changes: 3 additions & 3 deletions packages/react-scripts/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ module.exports = {
{
loader: require.resolve('thread-loader'),
options: {
poolTimeout: Infinity // keep workers alive for more effective watch mode
poolTimeout: Infinity, // keep workers alive for more effective watch mode
},
},
{
Expand Down Expand Up @@ -266,7 +266,7 @@ module.exports = {
{
loader: require.resolve('thread-loader'),
options: {
poolTimeout: Infinity // keep workers alive for more effective watch mode
poolTimeout: Infinity, // keep workers alive for more effective watch mode
},
},
{
Expand Down Expand Up @@ -331,7 +331,7 @@ module.exports = {
},
// The GraphQL loader preprocesses GraphQL queries in .graphql files.
{
test: /\.(graphql)$/,
test: /\.(graphql|gql)$/,
loader: 'graphql-tag/loader',
},
// "file" loader makes sure those assets get served by WebpackDevServer.
Expand Down
2 changes: 1 addition & 1 deletion packages/react-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ module.exports = {
},
// The GraphQL loader preprocesses GraphQL queries in .graphql files.
{
test: /\.(graphql)$/,
test: /\.(graphql|gql)$/,
loader: 'graphql-tag/loader',
},
// "file" loader makes sure assets end up in the `build` folder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,43 @@ import url from 'url';

const matchCSS = (doc, regexes) => {
if (process.env.E2E_FILE) {
const elements = doc.getElementsByTagName('link');
let href = "";
for (const elem of elements) {
if (elem.rel === 'stylesheet') {
href = elem.href;
}
const elements = doc.getElementsByTagName('link');
let href = '';
for (const elem of elements) {
if (elem.rel === 'stylesheet') {
href = elem.href;
}
resourceLoader(
{ url: url.parse(href) },
(_, textContent) => {
for (const regex of regexes) {
expect(textContent).to.match(regex);
}
}
);

}
resourceLoader({ url: url.parse(href) }, (_, textContent) => {
for (const regex of regexes) {
expect(textContent).to.match(regex);
}
});
} else {
for (let i = 0; i < regexes.length; ++i) {
expect(doc.getElementsByTagName('style')[i].textContent.replace(/\s/g, '')).to.match(regexes[i]);
expect(
doc.getElementsByTagName('style')[i].textContent.replace(/\s/g, '')
).to.match(regexes[i]);
}
}
}
};

describe('Integration', () => {
describe('Webpack plugins', () => {
it('css inclusion', async () => {
const doc = await initDOM('css-inclusion');
matchCSS(doc, [/html\{/, /#feature-css-inclusion\{background:.+;color:.+}/]);
matchCSS(doc, [
/html\{/,
/#feature-css-inclusion\{background:.+;color:.+}/,
]);
});

it('css modules inclusion', async () => {
const doc = await initDOM('css-modules-inclusion');
matchCSS(doc, [/.+style_cssModulesInclusion__.+\{background:.+;color:.+}/,
/.+assets_cssModulesIndexInclusion__.+\{background:.+;color:.+}/]);
matchCSS(doc, [
/.+style_cssModulesInclusion__.+\{background:.+;color:.+}/,
/.+assets_cssModulesIndexInclusion__.+\{background:.+;color:.+}/,
]);
});

it('scss inclusion', async () => {
Expand All @@ -54,9 +57,10 @@ describe('Integration', () => {

it('scss modules inclusion', async () => {
const doc = await initDOM('scss-modules-inclusion');
matchCSS(doc, [/.+scss-styles_scssModulesInclusion.+\{background:.+;color:.+}/,
/.+assets_scssModulesIndexInclusion.+\{background:.+;color:.+}/]);

matchCSS(doc, [
/.+scss-styles_scssModulesInclusion.+\{background:.+;color:.+}/,
/.+assets_scssModulesIndexInclusion.+\{background:.+;color:.+}/,
]);
});

it('sass inclusion', async () => {
Expand All @@ -66,8 +70,10 @@ describe('Integration', () => {

it('sass modules inclusion', async () => {
const doc = await initDOM('sass-modules-inclusion');
matchCSS(doc, [/.+sass-styles_sassModulesInclusion.+\{background:.+;color:.+}/,
/.+assets_sassModulesIndexInclusion.+\{background:.+;color:.+}/]);
matchCSS(doc, [
/.+sass-styles_sassModulesInclusion.+\{background:.+;color:.+}/,
/.+assets_sassModulesIndexInclusion.+\{background:.+;color:.+}/,
]);
});

it('graphql files inclusion', async () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/react-scripts/fixtures/kitchensink/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ class BuiltEmitter extends Component {
}

render() {
const { props: { feature }, handleReady } = this;
const {
props: { feature },
handleReady,
} = this;
return (
<div>
{createElement(feature, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@

import React from 'react';
import A from './assets/graphql.graphql';
import B from './assets/graphql.gql';

export default () => (
export const GraphLQLExtension = () => (
<p id="graphql-inclusion">
<span>{JSON.stringify(A)}</span>
</p>
);

export const GQLExtension = () => (
<p id="graphql-inclusion">
<span>{JSON.stringify(B)}</span>
</p>
);
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@

import React from 'react';
import ReactDOM from 'react-dom';
import GraphQLInclusion from './GraphQLInclusion';
import { GraphLExtension, GQLExtension } from './GraphQLInclusion';

describe('graphql files inclusion', () => {
it('renders without crashing', () => {
it('renders without crashing with GraphLExtension', () => {
const div = document.createElement('div');
ReactDOM.render(<GraphQLInclusion />, div);
});
it('renders without crashing with GQLExtension', () => {
const div = document.createElement('div');
ReactDOM.render(<GQLExtension />, div);
});
});
4 changes: 2 additions & 2 deletions packages/react-scripts/scripts/utils/createJestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ module.exports = (resolve, rootDir, srcRoots) => {
transform: {
'^.+\\.(js|jsx|mjs)$': resolve('config/jest/babelTransform.js'),
'^.+\\.css$': resolve('config/jest/cssTransform.js'),
'^.+\\.(graphql)$': resolve('config/jest/graphqlTransform.js'),
'^(?!.*\\.(js|jsx|mjs|css|json|graphql)$)': resolve(
'^.+\\.(gql|graphql)$': resolve('config/jest/graphqlTransform.js'),
'^(?!.*\\.(js|jsx|mjs|css|json|graphql|gql)$)': resolve(
'config/jest/fileTransform.js'
),
},
Expand Down