Skip to content

Commit

Permalink
fix: factorize cache folders
Browse files Browse the repository at this point in the history
  • Loading branch information
vscaiceanu-1a committed Jun 12, 2024
1 parent 47ed2d0 commit 0f2b6b9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
13 changes: 7 additions & 6 deletions packages/@ama-sdk/create/src/index.it.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ let sdkFolderPath: string;
let sdkPackagePath: string;
const execAppOptions = getDefaultExecSyncOptions();
const packageManager = getPackageManager();
const describeSkipYarn1 = isYarn1Enforced ? describe.skip : describe;

describe('Create new sdk command', () => {
describeSkipYarn1('Create new sdk command', () => {
beforeEach(() => {
const isYarnTest = o3rEnvironment.testEnvironment.isYarnTest;
sdkFolderPath = o3rEnvironment.testEnvironment.workspacePath;
Expand All @@ -40,7 +41,7 @@ describe('Create new sdk command', () => {

// copy yarnrc config to generated SDK
mkdirSync(sdkPackagePath, { recursive: true });
const yarnConfigFile = isYarn1Enforced() ? '.yarnrc' : '.yarnrc.yml';
const yarnConfigFile = '.yarnrc.yml';
cpSync(path.join(sdkFolderPath, yarnConfigFile), path.join(sdkPackagePath, yarnConfigFile));
cpSync(path.join(sdkFolderPath, '.yarn'), path.join(sdkPackagePath, '.yarn'), { recursive: true });
fs.writeFileSync(path.join(sdkPackagePath, 'yarn.lock'), '');
Expand All @@ -61,7 +62,7 @@ describe('Create new sdk command', () => {
packageManagerCreate({
script: '@ama-sdk',
args: ['typescript', sdkPackageName, '--package-manager', packageManager, '--spec-path', path.join(sdkFolderPath, 'swagger-spec.yml')]
}, execAppOptions, !isYarn1Enforced() ? 'npm' : undefined)
}, execAppOptions, 'npm')
).not.toThrow();
expect(() => packageManagerRun({script: 'build'}, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow();
expect(existsSync(path.join(sdkPackagePath, 'src', 'models', 'base', 'pet', 'pet.reviver.ts'))).toBeFalsy();
Expand Down Expand Up @@ -116,7 +117,7 @@ describe('Create new sdk command', () => {
expect(() => packageManagerCreate({
script: '@ama-sdk',
args: ['typescript', sdkPackageName, '--package-manager', packageManager]
}, execAppOptions, !isYarn1Enforced() ? 'npm' : undefined)).not.toThrow();
}, execAppOptions, 'npm')).not.toThrow();
expect(() => packageManagerRun({ script: 'build' }, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow();
expect(() =>
packageManagerExec({
Expand All @@ -133,7 +134,7 @@ describe('Create new sdk command', () => {
packageManagerCreate({
script: '@ama-sdk',
args: ['typescript', sdkPackageName, '--package-manager', packageManager, '--spec-path', './missing-file.yml']
}, execAppOptions, !isYarn1Enforced() ? 'npm' : undefined)
}, execAppOptions, 'npm')
).toThrow();
});

Expand All @@ -142,7 +143,7 @@ describe('Create new sdk command', () => {
packageManagerCreate({
script: `@ama-sdk@${o3rEnvironment.testEnvironment.o3rExactVersion}`,
args: ['typescript', sdkPackageName, '--exact-o3r-version', '--package-manager', packageManager, '--spec-path', path.join(sdkFolderPath, 'swagger-spec.yml')]
}, execAppOptions, !isYarn1Enforced() ? 'npm' : undefined)
}, execAppOptions, 'npm')
).not.toThrow();
expect(() => packageManagerRun({script: 'build'}, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow();
const packageJson = JSON.parse(fs.readFileSync(path.join(sdkPackagePath, 'package.json'), 'utf-8'));
Expand Down
8 changes: 4 additions & 4 deletions packages/@o3r/create/src/index.it.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import * as path from 'node:path';

const defaultExecOptions = getDefaultExecSyncOptions();
const workspaceProjectName = 'my-project';

describe('Create new otter project command', () => {
const describeSkipYarn1 = isYarn1Enforced ? describe.skip : describe;
describeSkipYarn1('Create new otter project command', () => {
test('should generate a project with an application', async () => {
const { workspacePath, packageManagerConfig, o3rVersion } = o3rEnvironment.testEnvironment;
const inProjectPath = path.join(workspacePath, workspaceProjectName);
Expand All @@ -34,7 +34,7 @@ describe('Create new otter project command', () => {
await fs.mkdir(inProjectPath, { recursive: true });
setPackagerManagerConfig(packageManagerConfig, execInAppOptions);

expect(() => packageManagerCreate({ script: `@o3r${o3rVersion}`, args: [workspaceProjectName, ...createOptions] }, execWorkspaceOptions, !isYarn1Enforced() ? 'npm' : undefined)).not.toThrow();
expect(() => packageManagerCreate({ script: `@o3r@${o3rVersion}`, args: [workspaceProjectName, ...createOptions] }, execWorkspaceOptions, 'npm')).not.toThrow();
expect(existsSync(path.join(inProjectPath, 'angular.json'))).toBe(true);
expect(existsSync(path.join(inProjectPath, 'package.json'))).toBe(true);
expect(() => packageManagerInstall(execInAppOptions)).not.toThrow();
Expand All @@ -58,7 +58,7 @@ describe('Create new otter project command', () => {
await fs.mkdir(inProjectPath, { recursive: true });
setPackagerManagerConfig(packageManagerConfig, execInAppOptions);

expect(() => packageManagerCreate({ script: `@o3r@${o3rVersion}`, args: [workspaceProjectName, ...createOptions] }, execWorkspaceOptions, !isYarn1Enforced() ? 'npm' : undefined)).not.toThrow();
expect(() => packageManagerCreate({ script: `@o3r@${o3rVersion}`, args: [workspaceProjectName, ...createOptions] }, execWorkspaceOptions, 'npm')).not.toThrow();
expect(existsSync(path.join(inProjectPath, 'angular.json'))).toBe(true);
expect(existsSync(path.join(inProjectPath, 'package.json'))).toBe(true);
expect(() => packageManagerInstall(execInAppOptions)).not.toThrow();
Expand Down
1 change: 0 additions & 1 deletion packages/@o3r/create/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ const prepareWorkspace = (relativeDirectory = '.', projectPackageManager = 'npm'

exitProcessIfErrorInSpawnSync(INSTALL_PROCESS_ERROR_CODE, spawnSync(runner, ['install'], spawnSyncOpts));
};
// const isYarn1 = packageManager === 'yarn' && argv['yarn-version']?.split('.')[0] === '1';
const addOtterFramework = (relativeDirectory = '.', projectPackageManager = 'npm') => {
const cwd = resolve(process.cwd(), relativeDirectory);
const runner = process.platform === 'win32' ? `${projectPackageManager}.cmd` : projectPackageManager;
Expand Down
2 changes: 1 addition & 1 deletion packages/@o3r/test-helpers/src/prepare-test-env.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { execFileSync, ExecSyncOptions } from 'node:child_process';
import { execFileSync, execSync, ExecSyncOptions } from 'node:child_process';
import { cpSync, existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs';
import * as path from 'node:path';
import type { PackageJson } from 'type-fest';
Expand Down
13 changes: 5 additions & 8 deletions packages/@o3r/test-helpers/src/utilities/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,6 @@ export function setPackagerManagerConfig(options: PackageManagerConfig, execAppO
execFileSync('yarn', ['config', 'set', '@o3r:registry', options.registry], execOptions);
execFileSync('yarn', ['config', 'set', 'unsafeHttpWhitelist', '127.0.0.1'], execOptions);
}
const cacheFolder = 'cache-folder';
const globalFolder = 'global-folder';
const ignoreRootCheckConfig = '--add.ignore-workspace-root-check';
const yarnRcPath = join(execOptions.cwd as string, '.yarnrc');

Expand All @@ -281,12 +279,11 @@ export function setPackagerManagerConfig(options: PackageManagerConfig, execAppO
appendFileSync(yarnRcPath, `\n${ignoreRootCheckConfig} true`);
}
if (options.globalFolderPath) {
if (!content.includes(cacheFolder)) {
appendFileSync(yarnRcPath, `\n${cacheFolder} "${posix.join(options.globalFolderPath.split(sep).join(posix.sep), 'yarn1-cache', options.packageScope || '')}"`);
}
if (!content.includes(globalFolder)) {
appendFileSync(yarnRcPath, `\n${globalFolder} "${posix.join(options.globalFolderPath.split(sep).join(posix.sep), 'yarn1-global', options.packageScope || '')}"`);
}
['cache-folder', 'global-folder'].forEach(folder => {
if (!content.includes(folder)) {
appendFileSync(yarnRcPath, `\n${folder} "${posix.join(options.globalFolderPath!.split(sep).join(posix.sep), `yarn1-${folder}`, options.packageScope || '')}"`);
}
});
}
} else {
console.warn(`File not found at '${yarnRcPath}'.`);
Expand Down

0 comments on commit 0f2b6b9

Please sign in to comment.