Skip to content

Commit

Permalink
relay-example: Get transpile workspaces programatically
Browse files Browse the repository at this point in the history
  • Loading branch information
tbergquist-godaddy authored and kodiakhq[bot] committed Dec 5, 2020
1 parent a74bc86 commit e565bb0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
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);

0 comments on commit e565bb0

Please sign in to comment.