Skip to content

Commit

Permalink
[cascading] from release/11.1.0-rc to main (#2047)
Browse files Browse the repository at this point in the history
<!--
{"currentBranch":"release/11.1.0-rc","targetBranch":"main","bypassReviewers":false,"isConflicting":false}
-->

## Cascading from release/11.1.0-rc to main

---

:heavy_exclamation_mark: The pull request is conflicting with the target
branch.
You can fix the issue locally with the following commands:

<details open>
  <summary>Using <b>gh CLI</b></summary>

  ```shell
  gh pr checkout 2047
  git pull --ff origin main
  ```

  and update this Pull Request with

  ```shell
  gh pr push 2047
  ```
</details>

<details>
  <summary>Using <b>git</b> only</summary>

  ```shell
  git fetch origin
  git checkout origin/cascading/11.1.0-rc-main
  git pull --ff origin main
  ```

  and update this Pull Request with

  ```shell
  git push origin HEAD:cascading/11.1.0-rc-main
  ```
</details>

---

<small>This Pull Request has been generated with :heart: by the
[Otter](https://github.com/AmadeusITGroup/otter) cascading tool.</small>
  • Loading branch information
matthieu-crouzet committed Aug 13, 2024
2 parents e33576f + 051fc0a commit 3796b6a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ const initTest = async (

// Add scope to project for registry management
let packageJson = JSON.parse(readFileSync(packageJsonPath, { encoding: 'utf8' }).toString());
const packageName = `@o3r/${packageJson.name}-${packageNameSuffix}`;
const packageName = `@o3r/${o3rEnvironment.testEnvironment.folderName}-${packageNameSuffix}`;
packageJson = {
...packageJson,
name: packageName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { spawnSync, SpawnSyncOptionsWithBufferEncoding, SpawnSyncReturns } from 'node:child_process';
import { spawnSync, SpawnSyncOptionsWithStringEncoding, SpawnSyncReturns } from 'node:child_process';
import { mkdirSync, readFileSync, rmSync } from 'node:fs';
import { randomBytes } from 'node:crypto';
import { tmpdir } from 'node:os';
import { join, posix, sep } from 'node:path';

function runAndThrowOnError(command: string, spawnOptions: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns<Buffer> {
function runAndThrowOnError(command: string, spawnOptions: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns<string> {
const cmdOutput = spawnSync(command, spawnOptions);
if (cmdOutput.error || cmdOutput.status !== 0) {
throw cmdOutput.stderr.toString();
throw cmdOutput.stderr;
}
return cmdOutput;
}
Expand All @@ -16,6 +16,10 @@ function pathToPosix(path: string): string {
return path.split(sep).join(posix.sep);
}

function sanitizeInput(input: string) {
return input.replace(/[^\w/\\:@^~=<> .-]/g, '');
}

/**
* Retrieves the list of given files from an npm package using npm.
* @param packageDescriptor Package descriptor using the npm semver format (i.e. @o3r/demo@^1.2.3)
Expand All @@ -28,13 +32,19 @@ export function getFilesFromRegistry(packageDescriptor: string, paths: string[])
mkdirSync(tempDirPath);

try {
const npmPackCmd = runAndThrowOnError(`npm pack "${packageDescriptor}" --pack-destination ${pathToPosix(tempDirPath)}`, { shell: true });
const tgzFile = npmPackCmd.stdout.toString().trim();
const npmPackCmd = runAndThrowOnError(
`npm pack "${sanitizeInput(packageDescriptor)}" --pack-destination "${pathToPosix(tempDirPath)}"`,
{ shell: true, encoding: 'utf8' }
);
const tgzFile = npmPackCmd.stdout.trim();

extractedFiles = paths.reduce((filesContent, path) => {
// tar expects a posix path
const pathInTgz = posix.join('./package', path);
runAndThrowOnError(`tar -zxvf ${pathToPosix(tgzFile)} -C ${pathToPosix(tempDirPath)} ${pathInTgz}`, { shell: true, cwd: tempDirPath });
runAndThrowOnError(
`tar -zxvf "${pathToPosix(tgzFile)}" -C "${pathToPosix(tempDirPath)}" "${pathInTgz}"`,
{ shell: true, cwd: tempDirPath, encoding: 'utf8' }
);
filesContent[path] = readFileSync(join(tempDirPath, pathInTgz)).toString();
return filesContent;
}, extractedFiles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const initTest = async (

// Add scope to project for registry management
let packageJson = JSON.parse(readFileSync(packageJsonPath, { encoding: 'utf8' }).toString());
const packageName = `@o3r/${packageJson.name}-${packageNameSuffix}`;
const packageName = `@o3r/${o3rEnvironment.testEnvironment.folderName}-${packageNameSuffix}`;
packageJson = {
...packageJson,
name: packageName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const initTest = async (

// Add scope to project for registry management
let packageJson = JSON.parse(readFileSync(packageJsonPath, { encoding: 'utf8' }).toString());
const packageName = `@o3r/${packageJson.name}-${packageNameSuffix}`;
const packageName = `@o3r/${o3rEnvironment.testEnvironment.folderName}-${packageNameSuffix}`;
packageJson = {
...packageJson,
name: packageName,
Expand Down
1 change: 1 addition & 0 deletions packages/@o3r/test-helpers/src/prepare-test-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export async function prepareTestEnv(folderName: string, options?: PrepareTestEn
const untouchedProjectsPaths = [untouchedAppPath, untouchedLibPath];

return {
folderName,
workspacePath,
applicationPath,
appName,
Expand Down

0 comments on commit 3796b6a

Please sign in to comment.