Skip to content

Commit 7bd1a0e

Browse files
authored
Merge pull request #654 from seznam/fix-cia-test
test: fix create-ima-app test
2 parents 16c2f8c + 3897ed4 commit 7bd1a0e

2 files changed

Lines changed: 59 additions & 13 deletions

File tree

utils/tests/setDependency.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const [, , ...args] = process.argv;
6+
const [pkgJsonPath, pkg, version] = args;
7+
8+
if (!pkg || !version || !pkgJsonPath) {
9+
console.error(
10+
'Usage: node utils/tests/setDependency.js <path-to-pkg.json> <pkg-name> <version>'
11+
);
12+
process.exit(1);
13+
}
14+
15+
const pkgJsonFullPath = path.resolve(pkgJsonPath);
16+
17+
if (!fs.existsSync(pkgJsonFullPath)) {
18+
console.error(`File not found: ${pkgJsonFullPath}`);
19+
process.exit(1);
20+
}
21+
22+
const pkgJsonContent = fs.readFileSync(pkgJsonFullPath, 'utf-8');
23+
const pkgJson = JSON.parse(pkgJsonContent);
24+
25+
setDependency();
26+
27+
fs.writeFileSync(
28+
pkgJsonFullPath,
29+
JSON.stringify(pkgJson, null, 2) + '\n',
30+
'utf-8'
31+
);
32+
// eslint-disable-next-line no-console
33+
console.log(`Updated ${pkg} to version ${version} in ${pkgJsonFullPath}`);
34+
35+
/**
36+
* Updates the dependency version in dependencies, devDependencies, or adds it to overrides.
37+
*/
38+
function setDependency() {
39+
if (pkgJson.dependencies && pkgJson.dependencies[pkg]) {
40+
pkgJson.dependencies[pkg] = version;
41+
return;
42+
}
43+
44+
if (pkgJson.devDependencies && pkgJson.devDependencies[pkg]) {
45+
pkgJson.devDependencies[pkg] = version;
46+
return;
47+
}
48+
49+
if (!pkgJson.overrides) {
50+
pkgJson.overrides = {};
51+
}
52+
53+
pkgJson.overrides[pkg] = version;
54+
}

utils/tests/testRunner.sh

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,14 @@ cd "$ROOT_DIR_IMA"
1212

1313
CREATE_IMA_APP_DIR="$ROOT_DIR_IMA/packages/create-ima-app"
1414
PACKAGES="@ima/cli @ima/core @ima/dev-utils @ima/error-overlay @ima/helpers @ima/hmr-client @ima/server @ima/react-page-renderer @ima/testing-library"
15+
CREATE_IMA_APP_PACKAGE_JSON="$CREATE_IMA_APP_DIR/template/common/package.json"
1516

1617
# Pack ima packages from local filesystem and link
1718
for PACKAGE in $PACKAGES ; do
1819
echo "Working on $PACKAGE"
1920

20-
# Convert package name to directory name (e.g., @ima/cli -> cli)
21-
PACKAGE_DIR=$(echo "$PACKAGE" | sed 's#@ima/##g')
22-
23-
# cd into the package directory
24-
cd "$ROOT_DIR_IMA/packages/$PACKAGE_DIR"
25-
26-
# Pack from local filesystem and specify destination
27-
npm pack --pack-destination="$ROOT_DIR_IMA"
21+
# Pack from local filesystem
22+
npm pack -w $PACKAGE
2823

2924
# Get the generated tarball path in the root directory
3025
SANITIZED_PACKAGE_NAME=$(echo "$PACKAGE" | sed 's#@ima/#ima-#g')
@@ -35,11 +30,8 @@ for PACKAGE in $PACKAGES ; do
3530
exit 1
3631
fi
3732

38-
# Update the template package.json to use local tarball
39-
sed -i "s#\"$PACKAGE\":\s\".*\"#\"$PACKAGE\": \"$PACKAGE_PATH\"#" $CREATE_IMA_APP_DIR/template/common/package.json
40-
41-
# Return to the original directory
42-
cd "$ROOT_DIR_IMA"
33+
# Update the template package.json to use local tarball or add it as an override
34+
node "$ROOT_DIR_IMA/utils/tests/setDependency.js" "$CREATE_IMA_APP_PACKAGE_JSON" "$PACKAGE" "$PACKAGE_PATH"
4335
done
4436

4537
cd "$ROOT_DIR_IMA"

0 commit comments

Comments
 (0)