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

relay-example: Get transpile workspaces programatically #1462

Merged
merged 2 commits into from
Dec 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 6 additions & 14 deletions src/example-relay/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@ const path = require('path');
const withTranspileModules = require('next-transpile-modules');
const withCustomBabelConfigFile = require('next-plugin-custom-babel-config');

const getTranspileWorkspaces = require('./scripts/getTranspileWorkspaces'); // @x-shipit-disable

const transpileWorkspaces = getTranspileWorkspaces(); // @x-shipit-disable
// @x-shipit-enable: const transpileWorkspaces = [];

module.exports = (withCustomBabelConfigFile(
withTranspileModules([
'@adeira/css-colors',
'@adeira/fetch',
'@adeira/graphql-bc-checker',
'@adeira/graphql-global-id',
'@adeira/graphql-relay',
'@adeira/js',
'@adeira/monorepo-utils',
'@adeira/murmur-hash',
'@adeira/relay',
'@adeira/relay-runtime',
'@adeira/relay-utils',
'@adeira/sx',
])({
withTranspileModules(transpileWorkspaces)({
images: {
domains: ['images.kiwi.com'],
},
Expand Down
28 changes: 28 additions & 0 deletions src/example-relay/scripts/getTranspileWorkspaces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// @flow

const { spawnSync } = require('child_process');

/**
* This should probably have been a part of @adeira/monorepo-utils,
* but it is difficult to make it run in next.config.js because of our setup.
* Maybe when we have migrated to bazel, we can move this to monorepo-utils
*/
function getTranspileWorkspaces() /* : $ReadOnlyArray<string> */ {
const workspaces = JSON.parse(
JSON.parse(spawnSync('yarn', ['workspaces', '--json', 'info']).stdout.toString()).data,
);

const transpileWorkspaces = new Set();

const getWorkspaces = (workspace = '@adeira/example-relay') => {
for (const dependency of workspaces[workspace].workspaceDependencies) {
transpileWorkspaces.add(dependency);
getWorkspaces(dependency);
}
};

getWorkspaces();
return Array.from(transpileWorkspaces);
}

module.exports = getTranspileWorkspaces;
1 change: 1 addition & 0 deletions src/monorepo-shipit/config/__tests__/example-relay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ testExportedPaths(path.join(__dirname, '..', 'example-relay.js'), [
['src/example-relay/WORKSPACE.bazel', undefined], // correctly deleted
['src/example-relay/WORKSPACE', undefined], // correctly deleted
['package.json', undefined], // correctly deleted
['src/example-relay/scripts/getTranspileWorkspaces.js', undefined], // correctly deleted
]);
2 changes: 1 addition & 1 deletion src/monorepo-shipit/config/example-relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ module.exports = ({
]);
},
getStrippedFiles() {
return new Set([/__github__/, /^\.babelrc\.js$/]);
return new Set([/__github__/, /^\.babelrc\.js$/, /scripts\/getTranspileWorkspaces.js/]);
},
}: ConfigType);