Skip to content

Commit 0f2b6b9

Browse files
committed
fix: factorize cache folders
1 parent 47ed2d0 commit 0f2b6b9

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

packages/@ama-sdk/create/src/index.it.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ let sdkFolderPath: string;
2424
let sdkPackagePath: string;
2525
const execAppOptions = getDefaultExecSyncOptions();
2626
const packageManager = getPackageManager();
27+
const describeSkipYarn1 = isYarn1Enforced ? describe.skip : describe;
2728

28-
describe('Create new sdk command', () => {
29+
describeSkipYarn1('Create new sdk command', () => {
2930
beforeEach(() => {
3031
const isYarnTest = o3rEnvironment.testEnvironment.isYarnTest;
3132
sdkFolderPath = o3rEnvironment.testEnvironment.workspacePath;
@@ -40,7 +41,7 @@ describe('Create new sdk command', () => {
4041

4142
// copy yarnrc config to generated SDK
4243
mkdirSync(sdkPackagePath, { recursive: true });
43-
const yarnConfigFile = isYarn1Enforced() ? '.yarnrc' : '.yarnrc.yml';
44+
const yarnConfigFile = '.yarnrc.yml';
4445
cpSync(path.join(sdkFolderPath, yarnConfigFile), path.join(sdkPackagePath, yarnConfigFile));
4546
cpSync(path.join(sdkFolderPath, '.yarn'), path.join(sdkPackagePath, '.yarn'), { recursive: true });
4647
fs.writeFileSync(path.join(sdkPackagePath, 'yarn.lock'), '');
@@ -61,7 +62,7 @@ describe('Create new sdk command', () => {
6162
packageManagerCreate({
6263
script: '@ama-sdk',
6364
args: ['typescript', sdkPackageName, '--package-manager', packageManager, '--spec-path', path.join(sdkFolderPath, 'swagger-spec.yml')]
64-
}, execAppOptions, !isYarn1Enforced() ? 'npm' : undefined)
65+
}, execAppOptions, 'npm')
6566
).not.toThrow();
6667
expect(() => packageManagerRun({script: 'build'}, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow();
6768
expect(existsSync(path.join(sdkPackagePath, 'src', 'models', 'base', 'pet', 'pet.reviver.ts'))).toBeFalsy();
@@ -116,7 +117,7 @@ describe('Create new sdk command', () => {
116117
expect(() => packageManagerCreate({
117118
script: '@ama-sdk',
118119
args: ['typescript', sdkPackageName, '--package-manager', packageManager]
119-
}, execAppOptions, !isYarn1Enforced() ? 'npm' : undefined)).not.toThrow();
120+
}, execAppOptions, 'npm')).not.toThrow();
120121
expect(() => packageManagerRun({ script: 'build' }, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow();
121122
expect(() =>
122123
packageManagerExec({
@@ -133,7 +134,7 @@ describe('Create new sdk command', () => {
133134
packageManagerCreate({
134135
script: '@ama-sdk',
135136
args: ['typescript', sdkPackageName, '--package-manager', packageManager, '--spec-path', './missing-file.yml']
136-
}, execAppOptions, !isYarn1Enforced() ? 'npm' : undefined)
137+
}, execAppOptions, 'npm')
137138
).toThrow();
138139
});
139140

@@ -142,7 +143,7 @@ describe('Create new sdk command', () => {
142143
packageManagerCreate({
143144
script: `@ama-sdk@${o3rEnvironment.testEnvironment.o3rExactVersion}`,
144145
args: ['typescript', sdkPackageName, '--exact-o3r-version', '--package-manager', packageManager, '--spec-path', path.join(sdkFolderPath, 'swagger-spec.yml')]
145-
}, execAppOptions, !isYarn1Enforced() ? 'npm' : undefined)
146+
}, execAppOptions, 'npm')
146147
).not.toThrow();
147148
expect(() => packageManagerRun({script: 'build'}, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow();
148149
const packageJson = JSON.parse(fs.readFileSync(path.join(sdkPackagePath, 'package.json'), 'utf-8'));

packages/@o3r/create/src/index.it.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import * as path from 'node:path';
2121

2222
const defaultExecOptions = getDefaultExecSyncOptions();
2323
const workspaceProjectName = 'my-project';
24-
25-
describe('Create new otter project command', () => {
24+
const describeSkipYarn1 = isYarn1Enforced ? describe.skip : describe;
25+
describeSkipYarn1('Create new otter project command', () => {
2626
test('should generate a project with an application', async () => {
2727
const { workspacePath, packageManagerConfig, o3rVersion } = o3rEnvironment.testEnvironment;
2828
const inProjectPath = path.join(workspacePath, workspaceProjectName);
@@ -34,7 +34,7 @@ describe('Create new otter project command', () => {
3434
await fs.mkdir(inProjectPath, { recursive: true });
3535
setPackagerManagerConfig(packageManagerConfig, execInAppOptions);
3636

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

61-
expect(() => packageManagerCreate({ script: `@o3r@${o3rVersion}`, args: [workspaceProjectName, ...createOptions] }, execWorkspaceOptions, !isYarn1Enforced() ? 'npm' : undefined)).not.toThrow();
61+
expect(() => packageManagerCreate({ script: `@o3r@${o3rVersion}`, args: [workspaceProjectName, ...createOptions] }, execWorkspaceOptions, 'npm')).not.toThrow();
6262
expect(existsSync(path.join(inProjectPath, 'angular.json'))).toBe(true);
6363
expect(existsSync(path.join(inProjectPath, 'package.json'))).toBe(true);
6464
expect(() => packageManagerInstall(execInAppOptions)).not.toThrow();

packages/@o3r/create/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ const prepareWorkspace = (relativeDirectory = '.', projectPackageManager = 'npm'
255255

256256
exitProcessIfErrorInSpawnSync(INSTALL_PROCESS_ERROR_CODE, spawnSync(runner, ['install'], spawnSyncOpts));
257257
};
258-
// const isYarn1 = packageManager === 'yarn' && argv['yarn-version']?.split('.')[0] === '1';
259258
const addOtterFramework = (relativeDirectory = '.', projectPackageManager = 'npm') => {
260259
const cwd = resolve(process.cwd(), relativeDirectory);
261260
const runner = process.platform === 'win32' ? `${projectPackageManager}.cmd` : projectPackageManager;

packages/@o3r/test-helpers/src/prepare-test-env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { execFileSync, ExecSyncOptions } from 'node:child_process';
1+
import { execFileSync, execSync, ExecSyncOptions } from 'node:child_process';
22
import { cpSync, existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs';
33
import * as path from 'node:path';
44
import type { PackageJson } from 'type-fest';

packages/@o3r/test-helpers/src/utilities/package-manager.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,6 @@ export function setPackagerManagerConfig(options: PackageManagerConfig, execAppO
270270
execFileSync('yarn', ['config', 'set', '@o3r:registry', options.registry], execOptions);
271271
execFileSync('yarn', ['config', 'set', 'unsafeHttpWhitelist', '127.0.0.1'], execOptions);
272272
}
273-
const cacheFolder = 'cache-folder';
274-
const globalFolder = 'global-folder';
275273
const ignoreRootCheckConfig = '--add.ignore-workspace-root-check';
276274
const yarnRcPath = join(execOptions.cwd as string, '.yarnrc');
277275

@@ -281,12 +279,11 @@ export function setPackagerManagerConfig(options: PackageManagerConfig, execAppO
281279
appendFileSync(yarnRcPath, `\n${ignoreRootCheckConfig} true`);
282280
}
283281
if (options.globalFolderPath) {
284-
if (!content.includes(cacheFolder)) {
285-
appendFileSync(yarnRcPath, `\n${cacheFolder} "${posix.join(options.globalFolderPath.split(sep).join(posix.sep), 'yarn1-cache', options.packageScope || '')}"`);
286-
}
287-
if (!content.includes(globalFolder)) {
288-
appendFileSync(yarnRcPath, `\n${globalFolder} "${posix.join(options.globalFolderPath.split(sep).join(posix.sep), 'yarn1-global', options.packageScope || '')}"`);
289-
}
282+
['cache-folder', 'global-folder'].forEach(folder => {
283+
if (!content.includes(folder)) {
284+
appendFileSync(yarnRcPath, `\n${folder} "${posix.join(options.globalFolderPath!.split(sep).join(posix.sep), `yarn1-${folder}`, options.packageScope || '')}"`);
285+
}
286+
});
290287
}
291288
} else {
292289
console.warn(`File not found at '${yarnRcPath}'.`);

0 commit comments

Comments
 (0)