diff --git a/package.json b/package.json index 7ee30d0528..538a96d8c1 100644 --- a/package.json +++ b/package.json @@ -168,6 +168,7 @@ "react-intl-translations-manager": "5.0.3", "react-syntax-highlighter": "13.5.3", "regenerator-runtime": "0.13.7", + "resolve-tree": "^0.1.14", "sass": "1.32.13", "sass-loader": "10.1.1", "seedrandom": "3.0.5", diff --git a/scripts/copy-runtime-dependencies.js b/scripts/copy-runtime-dependencies.js new file mode 100755 index 0000000000..176dbf233f --- /dev/null +++ b/scripts/copy-runtime-dependencies.js @@ -0,0 +1,52 @@ +#!/usr/bin/env node + +const cp = require('child_process'); +const path = require('path'); +const resolve = require('resolve-tree'); +const mainWebpackConfig = require('../source/main/webpack.config'); + +const uniq = list => Array.from(new Set(list)); +const exec = command => { + try { + cp.execSync(command).toString(); + } catch (e) { + console.error(e.stderr.toString()); + process.exit(1); + } +}; + +let destinationDir = process.argv[2]; +if (!destinationDir) { + console.error('Destination path argument is required'); + process.exit(1); +} + +destinationDir = path.resolve(process.cwd(), destinationDir); +const runtimePackagesNames = uniq(Object.keys(mainWebpackConfig.externals)); + +console.info(`\ +Going to copy following packages along with their dependencies: +${runtimePackagesNames.map(p => ` - ${p}`).join('\n')}`); + +const packagesAbsolutePaths = uniq( + resolve.flatten(resolve.packagesSync(runtimePackagesNames)).map(j => j.root), +); + +console.info(`Collected ${packagesAbsolutePaths.length} packages in total.`); + +const rootNodeModulesPath = `${ + packagesAbsolutePaths[0].split('/node_modules/')[0] +}/node_modules/`; +const relativePackagesPaths = packagesAbsolutePaths.map(p => + p.replace(rootNodeModulesPath, ''), +); +const patternForAllPackagesNames = + relativePackagesPaths.length > 1 + ? `{${relativePackagesPaths.join(',')}}` + : relativePackagesPaths[0]; +const fullGlobPattern = `${rootNodeModulesPath}./${patternForAllPackagesNames}`; + +console.info('Copying..'); +exec(`rsync -aR ${fullGlobPattern} ${destinationDir}`); + +console.info('Done.'); diff --git a/yarn.lock b/yarn.lock index 0bbcf832f9..6d56b4f674 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9016,6 +9016,10 @@ fuse.js@^3.4.6: version "3.6.1" resolved "https://registry.yarnpkg.com/fuse.js/-/fuse.js-3.6.1.tgz#7de85fdd6e1b3377c23ce010892656385fd9b10c" +fw@^0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/fw/-/fw-0.1.2.tgz#3524f6793d16e83bc0124e945082c13093bd799a" + galactus@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/galactus/-/galactus-0.2.1.tgz#cbed2d20a40c1f5679a35908e2b9415733e78db9" @@ -15294,6 +15298,14 @@ resolve-pathname@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/resolve-pathname/-/resolve-pathname-3.0.0.tgz#99d02224d3cf263689becbb393bc560313025dcd" +resolve-tree@^0.1.14: + version "0.1.14" + resolved "https://registry.yarnpkg.com/resolve-tree/-/resolve-tree-0.1.14.tgz#34e9be1ffbb980fc12d8417505ac5f259ee0e471" + dependencies: + fw "^0.1.2" + object-assign "^4.0.1" + resolve "^1.1.6" + resolve-url@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a" @@ -16002,14 +16014,7 @@ socks-proxy-agent@^6.0.0: debug "^4.3.3" socks "^2.6.2" -socks@^2.6.1: - version "2.6.2" - resolved "https://registry.yarnpkg.com/socks/-/socks-2.6.2.tgz#ec042d7960073d40d94268ff3bb727dc685f111a" - dependencies: - ip "^1.1.5" - smart-buffer "^4.2.0" - -socks@^2.6.2: +socks@^2.6.1, socks@^2.6.2: version "2.6.2" resolved "https://registry.yarnpkg.com/socks/-/socks-2.6.2.tgz#ec042d7960073d40d94268ff3bb727dc685f111a" dependencies: