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

[DDW-1103] Add script for copying runtime dependencies #2997

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
52 changes: 52 additions & 0 deletions scripts/copy-runtime-dependencies.js
Original file line number Diff line number Diff line change
@@ -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.');
21 changes: 13 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down