@commercetools-frontend/create-mc-app 24.0.0 → 24.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/commercetools-frontend-create-mc-app.cjs.dev.js +40 -6
- package/dist/commercetools-frontend-create-mc-app.cjs.prod.js +40 -6
- package/dist/commercetools-frontend-create-mc-app.esm.js +39 -6
- package/dist/declarations/src/utils.d.ts +3 -1
- package/package.json +2 -2
- package/src/tasks/install-dependencies.ts +12 -1
- package/src/utils.ts +30 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @commercetools-frontend/create-mc-app
|
|
2
2
|
|
|
3
|
+
## 24.2.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies []:
|
|
8
|
+
- @commercetools-frontend/application-config@24.2.0
|
|
9
|
+
|
|
10
|
+
## 24.1.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- [#3771](https://github.com/commercetools/merchant-center-application-kit/pull/3771) [`23e0e7d`](https://github.com/commercetools/merchant-center-application-kit/commit/23e0e7d3d89aef129203b9c8539ff3b1d06e6f7c) Thanks [@mustafaasif2](https://github.com/mustafaasif2)! - Fix compatibility issues with Yarn 3 and Yarn 4 in starter templates by configuring nodeLinker to use node-modules.
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies []:
|
|
19
|
+
- @commercetools-frontend/application-config@24.1.0
|
|
20
|
+
|
|
3
21
|
## 24.0.0
|
|
4
22
|
|
|
5
23
|
### Major Changes
|
|
@@ -13,6 +13,7 @@ var crypto = require('node:crypto');
|
|
|
13
13
|
var path = require('node:path');
|
|
14
14
|
var readline = require('node:readline');
|
|
15
15
|
var applicationConfig = require('@commercetools-frontend/application-config');
|
|
16
|
+
var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
|
|
16
17
|
var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
|
|
17
18
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
18
19
|
var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
|
|
@@ -47,6 +48,7 @@ var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsW
|
|
|
47
48
|
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
48
49
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
49
50
|
var readline__default = /*#__PURE__*/_interopDefault(readline);
|
|
51
|
+
var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty);
|
|
50
52
|
var _sliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_sliceInstanceProperty);
|
|
51
53
|
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
52
54
|
var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
|
|
@@ -70,7 +72,7 @@ var prettier__default = /*#__PURE__*/_interopDefault(prettier);
|
|
|
70
72
|
|
|
71
73
|
var pkgJson = {
|
|
72
74
|
name: "@commercetools-frontend/create-mc-app",
|
|
73
|
-
version: "24.
|
|
75
|
+
version: "24.2.0",
|
|
74
76
|
description: "Create Merchant Center applications to quickly get up and running",
|
|
75
77
|
bugs: "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
76
78
|
repository: {
|
|
@@ -96,7 +98,7 @@ var pkgJson = {
|
|
|
96
98
|
"@babel/core": "^7.22.17",
|
|
97
99
|
"@babel/runtime": "^7.22.15",
|
|
98
100
|
"@babel/runtime-corejs3": "^7.22.15",
|
|
99
|
-
"@commercetools-frontend/application-config": "^24.
|
|
101
|
+
"@commercetools-frontend/application-config": "^24.2.0",
|
|
100
102
|
"@types/babel__core": "^7.20.1",
|
|
101
103
|
"@types/semver": "^7.5.1",
|
|
102
104
|
commander: "^13.1.0",
|
|
@@ -161,6 +163,32 @@ const shouldUseYarn = () => {
|
|
|
161
163
|
return false;
|
|
162
164
|
}
|
|
163
165
|
};
|
|
166
|
+
const getYarnVersion = () => {
|
|
167
|
+
try {
|
|
168
|
+
var _context;
|
|
169
|
+
const result = execa__default["default"].commandSync('yarn --version', {
|
|
170
|
+
encoding: 'utf-8'
|
|
171
|
+
});
|
|
172
|
+
return _trimInstanceProperty__default["default"](_context = result.stdout).call(_context);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
const configureYarn = projectDirectoryPath => {
|
|
178
|
+
const yarnVersion = getYarnVersion();
|
|
179
|
+
if (!yarnVersion) return;
|
|
180
|
+
|
|
181
|
+
// Check if Yarn version is 2 or higher. Plug'n'Play was introduced in Yarn v2
|
|
182
|
+
if (semver__default["default"].gte(yarnVersion, '2.0.0')) {
|
|
183
|
+
// Sanitize and resolve the path
|
|
184
|
+
const normalizedProjectPath = path__default["default"].resolve(projectDirectoryPath);
|
|
185
|
+
|
|
186
|
+
// Create .yarnrc.yml to use node_modules
|
|
187
|
+
const yarnrcPath = path__default["default"].join(normalizedProjectPath, '.yarnrc.yml');
|
|
188
|
+
const yarnrcContent = 'nodeLinker: "node-modules"';
|
|
189
|
+
fs__default["default"].writeFileSync(yarnrcPath, yarnrcContent);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
164
192
|
const getPreferredPackageManager = options => {
|
|
165
193
|
if (options.packageManager) {
|
|
166
194
|
return options.packageManager;
|
|
@@ -184,12 +212,12 @@ const getInstallCommand = options => {
|
|
|
184
212
|
const slugify = name => name.toLowerCase().replace(/_/gi, '-');
|
|
185
213
|
const upperFirst = value => value.charAt(0).toUpperCase() + _sliceInstanceProperty__default["default"](value).call(value, 1);
|
|
186
214
|
const wordify = slug => {
|
|
187
|
-
var
|
|
188
|
-
return _mapInstanceProperty__default["default"](
|
|
215
|
+
var _context2;
|
|
216
|
+
return _mapInstanceProperty__default["default"](_context2 = slug.split('-')).call(_context2, word => upperFirst(word)).join(' ');
|
|
189
217
|
};
|
|
190
218
|
const resolveFilePathByExtension = requestedModule => {
|
|
191
|
-
var
|
|
192
|
-
const fileExtension = _findInstanceProperty__default["default"](
|
|
219
|
+
var _context3;
|
|
220
|
+
const fileExtension = _findInstanceProperty__default["default"](_context3 = ['.js', '.ts', '.mjs', '.cjs']).call(_context3, ext => {
|
|
193
221
|
const filePath = `${requestedModule}${ext}`;
|
|
194
222
|
return doesFileExist(filePath);
|
|
195
223
|
});
|
|
@@ -392,6 +420,12 @@ function installDependencies(options) {
|
|
|
392
420
|
return {
|
|
393
421
|
title: 'Installing dependencies (this might take a while)',
|
|
394
422
|
task: () => {
|
|
423
|
+
const packageManager = getPreferredPackageManager(options);
|
|
424
|
+
|
|
425
|
+
// Only configure Yarn if it's the selected package manager
|
|
426
|
+
if (packageManager === 'yarn') {
|
|
427
|
+
configureYarn(options.projectDirectoryPath);
|
|
428
|
+
}
|
|
395
429
|
const installCommand = getInstallCommand(options);
|
|
396
430
|
|
|
397
431
|
// TODO: we could check for min yarn/npm versions
|
|
@@ -13,6 +13,7 @@ var crypto = require('node:crypto');
|
|
|
13
13
|
var path = require('node:path');
|
|
14
14
|
var readline = require('node:readline');
|
|
15
15
|
var applicationConfig = require('@commercetools-frontend/application-config');
|
|
16
|
+
var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
|
|
16
17
|
var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
|
|
17
18
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
18
19
|
var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
|
|
@@ -47,6 +48,7 @@ var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsW
|
|
|
47
48
|
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
48
49
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
49
50
|
var readline__default = /*#__PURE__*/_interopDefault(readline);
|
|
51
|
+
var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty);
|
|
50
52
|
var _sliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_sliceInstanceProperty);
|
|
51
53
|
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
52
54
|
var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
|
|
@@ -70,7 +72,7 @@ var prettier__default = /*#__PURE__*/_interopDefault(prettier);
|
|
|
70
72
|
|
|
71
73
|
var pkgJson = {
|
|
72
74
|
name: "@commercetools-frontend/create-mc-app",
|
|
73
|
-
version: "24.
|
|
75
|
+
version: "24.2.0",
|
|
74
76
|
description: "Create Merchant Center applications to quickly get up and running",
|
|
75
77
|
bugs: "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
76
78
|
repository: {
|
|
@@ -96,7 +98,7 @@ var pkgJson = {
|
|
|
96
98
|
"@babel/core": "^7.22.17",
|
|
97
99
|
"@babel/runtime": "^7.22.15",
|
|
98
100
|
"@babel/runtime-corejs3": "^7.22.15",
|
|
99
|
-
"@commercetools-frontend/application-config": "^24.
|
|
101
|
+
"@commercetools-frontend/application-config": "^24.2.0",
|
|
100
102
|
"@types/babel__core": "^7.20.1",
|
|
101
103
|
"@types/semver": "^7.5.1",
|
|
102
104
|
commander: "^13.1.0",
|
|
@@ -161,6 +163,32 @@ const shouldUseYarn = () => {
|
|
|
161
163
|
return false;
|
|
162
164
|
}
|
|
163
165
|
};
|
|
166
|
+
const getYarnVersion = () => {
|
|
167
|
+
try {
|
|
168
|
+
var _context;
|
|
169
|
+
const result = execa__default["default"].commandSync('yarn --version', {
|
|
170
|
+
encoding: 'utf-8'
|
|
171
|
+
});
|
|
172
|
+
return _trimInstanceProperty__default["default"](_context = result.stdout).call(_context);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
const configureYarn = projectDirectoryPath => {
|
|
178
|
+
const yarnVersion = getYarnVersion();
|
|
179
|
+
if (!yarnVersion) return;
|
|
180
|
+
|
|
181
|
+
// Check if Yarn version is 2 or higher. Plug'n'Play was introduced in Yarn v2
|
|
182
|
+
if (semver__default["default"].gte(yarnVersion, '2.0.0')) {
|
|
183
|
+
// Sanitize and resolve the path
|
|
184
|
+
const normalizedProjectPath = path__default["default"].resolve(projectDirectoryPath);
|
|
185
|
+
|
|
186
|
+
// Create .yarnrc.yml to use node_modules
|
|
187
|
+
const yarnrcPath = path__default["default"].join(normalizedProjectPath, '.yarnrc.yml');
|
|
188
|
+
const yarnrcContent = 'nodeLinker: "node-modules"';
|
|
189
|
+
fs__default["default"].writeFileSync(yarnrcPath, yarnrcContent);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
164
192
|
const getPreferredPackageManager = options => {
|
|
165
193
|
if (options.packageManager) {
|
|
166
194
|
return options.packageManager;
|
|
@@ -184,12 +212,12 @@ const getInstallCommand = options => {
|
|
|
184
212
|
const slugify = name => name.toLowerCase().replace(/_/gi, '-');
|
|
185
213
|
const upperFirst = value => value.charAt(0).toUpperCase() + _sliceInstanceProperty__default["default"](value).call(value, 1);
|
|
186
214
|
const wordify = slug => {
|
|
187
|
-
var
|
|
188
|
-
return _mapInstanceProperty__default["default"](
|
|
215
|
+
var _context2;
|
|
216
|
+
return _mapInstanceProperty__default["default"](_context2 = slug.split('-')).call(_context2, word => upperFirst(word)).join(' ');
|
|
189
217
|
};
|
|
190
218
|
const resolveFilePathByExtension = requestedModule => {
|
|
191
|
-
var
|
|
192
|
-
const fileExtension = _findInstanceProperty__default["default"](
|
|
219
|
+
var _context3;
|
|
220
|
+
const fileExtension = _findInstanceProperty__default["default"](_context3 = ['.js', '.ts', '.mjs', '.cjs']).call(_context3, ext => {
|
|
193
221
|
const filePath = `${requestedModule}${ext}`;
|
|
194
222
|
return doesFileExist(filePath);
|
|
195
223
|
});
|
|
@@ -392,6 +420,12 @@ function installDependencies(options) {
|
|
|
392
420
|
return {
|
|
393
421
|
title: 'Installing dependencies (this might take a while)',
|
|
394
422
|
task: () => {
|
|
423
|
+
const packageManager = getPreferredPackageManager(options);
|
|
424
|
+
|
|
425
|
+
// Only configure Yarn if it's the selected package manager
|
|
426
|
+
if (packageManager === 'yarn') {
|
|
427
|
+
configureYarn(options.projectDirectoryPath);
|
|
428
|
+
}
|
|
395
429
|
const installCommand = getInstallCommand(options);
|
|
396
430
|
|
|
397
431
|
// TODO: we could check for min yarn/npm versions
|
|
@@ -9,6 +9,7 @@ import crypto from 'node:crypto';
|
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
import readline from 'node:readline';
|
|
11
11
|
import { CLOUD_IDENTIFIERS } from '@commercetools-frontend/application-config';
|
|
12
|
+
import _trimInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/trim';
|
|
12
13
|
import _sliceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/slice';
|
|
13
14
|
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
|
14
15
|
import _findInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find';
|
|
@@ -35,7 +36,7 @@ import prettier from 'prettier';
|
|
|
35
36
|
|
|
36
37
|
var pkgJson = {
|
|
37
38
|
name: "@commercetools-frontend/create-mc-app",
|
|
38
|
-
version: "24.
|
|
39
|
+
version: "24.2.0",
|
|
39
40
|
description: "Create Merchant Center applications to quickly get up and running",
|
|
40
41
|
bugs: "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
41
42
|
repository: {
|
|
@@ -61,7 +62,7 @@ var pkgJson = {
|
|
|
61
62
|
"@babel/core": "^7.22.17",
|
|
62
63
|
"@babel/runtime": "^7.22.15",
|
|
63
64
|
"@babel/runtime-corejs3": "^7.22.15",
|
|
64
|
-
"@commercetools-frontend/application-config": "^24.
|
|
65
|
+
"@commercetools-frontend/application-config": "^24.2.0",
|
|
65
66
|
"@types/babel__core": "^7.20.1",
|
|
66
67
|
"@types/semver": "^7.5.1",
|
|
67
68
|
commander: "^13.1.0",
|
|
@@ -126,6 +127,32 @@ const shouldUseYarn = () => {
|
|
|
126
127
|
return false;
|
|
127
128
|
}
|
|
128
129
|
};
|
|
130
|
+
const getYarnVersion = () => {
|
|
131
|
+
try {
|
|
132
|
+
var _context;
|
|
133
|
+
const result = execa.commandSync('yarn --version', {
|
|
134
|
+
encoding: 'utf-8'
|
|
135
|
+
});
|
|
136
|
+
return _trimInstanceProperty(_context = result.stdout).call(_context);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const configureYarn = projectDirectoryPath => {
|
|
142
|
+
const yarnVersion = getYarnVersion();
|
|
143
|
+
if (!yarnVersion) return;
|
|
144
|
+
|
|
145
|
+
// Check if Yarn version is 2 or higher. Plug'n'Play was introduced in Yarn v2
|
|
146
|
+
if (semver.gte(yarnVersion, '2.0.0')) {
|
|
147
|
+
// Sanitize and resolve the path
|
|
148
|
+
const normalizedProjectPath = path.resolve(projectDirectoryPath);
|
|
149
|
+
|
|
150
|
+
// Create .yarnrc.yml to use node_modules
|
|
151
|
+
const yarnrcPath = path.join(normalizedProjectPath, '.yarnrc.yml');
|
|
152
|
+
const yarnrcContent = 'nodeLinker: "node-modules"';
|
|
153
|
+
fs.writeFileSync(yarnrcPath, yarnrcContent);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
129
156
|
const getPreferredPackageManager = options => {
|
|
130
157
|
if (options.packageManager) {
|
|
131
158
|
return options.packageManager;
|
|
@@ -149,12 +176,12 @@ const getInstallCommand = options => {
|
|
|
149
176
|
const slugify = name => name.toLowerCase().replace(/_/gi, '-');
|
|
150
177
|
const upperFirst = value => value.charAt(0).toUpperCase() + _sliceInstanceProperty(value).call(value, 1);
|
|
151
178
|
const wordify = slug => {
|
|
152
|
-
var
|
|
153
|
-
return _mapInstanceProperty(
|
|
179
|
+
var _context2;
|
|
180
|
+
return _mapInstanceProperty(_context2 = slug.split('-')).call(_context2, word => upperFirst(word)).join(' ');
|
|
154
181
|
};
|
|
155
182
|
const resolveFilePathByExtension = requestedModule => {
|
|
156
|
-
var
|
|
157
|
-
const fileExtension = _findInstanceProperty(
|
|
183
|
+
var _context3;
|
|
184
|
+
const fileExtension = _findInstanceProperty(_context3 = ['.js', '.ts', '.mjs', '.cjs']).call(_context3, ext => {
|
|
158
185
|
const filePath = `${requestedModule}${ext}`;
|
|
159
186
|
return doesFileExist(filePath);
|
|
160
187
|
});
|
|
@@ -357,6 +384,12 @@ function installDependencies(options) {
|
|
|
357
384
|
return {
|
|
358
385
|
title: 'Installing dependencies (this might take a while)',
|
|
359
386
|
task: () => {
|
|
387
|
+
const packageManager = getPreferredPackageManager(options);
|
|
388
|
+
|
|
389
|
+
// Only configure Yarn if it's the selected package manager
|
|
390
|
+
if (packageManager === 'yarn') {
|
|
391
|
+
configureYarn(options.projectDirectoryPath);
|
|
392
|
+
}
|
|
360
393
|
const installCommand = getInstallCommand(options);
|
|
361
394
|
|
|
362
395
|
// TODO: we could check for min yarn/npm versions
|
|
@@ -2,6 +2,8 @@ import type { TApplicationType, TCliTaskOptions, TPackageManager } from './types
|
|
|
2
2
|
declare const isSemVer: (version: string) => boolean;
|
|
3
3
|
declare const doesFileExist: (path: string) => boolean;
|
|
4
4
|
declare const shouldUseYarn: () => boolean;
|
|
5
|
+
declare const getYarnVersion: () => string | null;
|
|
6
|
+
declare const configureYarn: (projectDirectoryPath: string) => void;
|
|
5
7
|
declare const getPreferredPackageManager: (options: TCliTaskOptions) => TPackageManager;
|
|
6
8
|
declare const getInstallCommand: (options: TCliTaskOptions) => string;
|
|
7
9
|
declare const slugify: (name: string) => string;
|
|
@@ -9,4 +11,4 @@ declare const upperFirst: (value: string) => string;
|
|
|
9
11
|
declare const wordify: (slug: string) => string;
|
|
10
12
|
declare const resolveFilePathByExtension: (requestedModule: string) => string;
|
|
11
13
|
declare const isCustomView: (applicationType: TApplicationType) => boolean;
|
|
12
|
-
export { isSemVer, shouldUseYarn, slugify, wordify, upperFirst, resolveFilePathByExtension, getPreferredPackageManager, getInstallCommand, isCustomView, doesFileExist, };
|
|
14
|
+
export { isSemVer, shouldUseYarn, getYarnVersion, configureYarn, slugify, wordify, upperFirst, resolveFilePathByExtension, getPreferredPackageManager, getInstallCommand, isCustomView, doesFileExist, };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/create-mc-app",
|
|
3
|
-
"version": "24.
|
|
3
|
+
"version": "24.2.0",
|
|
4
4
|
"description": "Create Merchant Center applications to quickly get up and running",
|
|
5
5
|
"bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
6
6
|
"repository": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@babel/core": "^7.22.17",
|
|
27
27
|
"@babel/runtime": "^7.22.15",
|
|
28
28
|
"@babel/runtime-corejs3": "^7.22.15",
|
|
29
|
-
"@commercetools-frontend/application-config": "^24.
|
|
29
|
+
"@commercetools-frontend/application-config": "^24.2.0",
|
|
30
30
|
"@types/babel__core": "^7.20.1",
|
|
31
31
|
"@types/semver": "^7.5.1",
|
|
32
32
|
"commander": "^13.1.0",
|
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import execa from 'execa';
|
|
2
2
|
import type { ListrTask } from 'listr2';
|
|
3
3
|
import type { TCliTaskOptions } from '../types';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
getInstallCommand,
|
|
6
|
+
configureYarn,
|
|
7
|
+
getPreferredPackageManager,
|
|
8
|
+
} from '../utils';
|
|
5
9
|
|
|
6
10
|
function installDependencies(options: TCliTaskOptions): ListrTask {
|
|
7
11
|
return {
|
|
8
12
|
title: 'Installing dependencies (this might take a while)',
|
|
9
13
|
task: () => {
|
|
14
|
+
const packageManager = getPreferredPackageManager(options);
|
|
15
|
+
|
|
16
|
+
// Only configure Yarn if it's the selected package manager
|
|
17
|
+
if (packageManager === 'yarn') {
|
|
18
|
+
configureYarn(options.projectDirectoryPath);
|
|
19
|
+
}
|
|
20
|
+
|
|
10
21
|
const installCommand = getInstallCommand(options);
|
|
11
22
|
|
|
12
23
|
// TODO: we could check for min yarn/npm versions
|
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
2
3
|
import execa from 'execa';
|
|
4
|
+
import semver from 'semver';
|
|
3
5
|
import type {
|
|
4
6
|
TApplicationType,
|
|
5
7
|
TCliTaskOptions,
|
|
@@ -26,6 +28,32 @@ const shouldUseYarn = () => {
|
|
|
26
28
|
}
|
|
27
29
|
};
|
|
28
30
|
|
|
31
|
+
const getYarnVersion = () => {
|
|
32
|
+
try {
|
|
33
|
+
const result = execa.commandSync('yarn --version', { encoding: 'utf-8' });
|
|
34
|
+
return result.stdout.trim();
|
|
35
|
+
} catch (error) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const configureYarn = (projectDirectoryPath: string) => {
|
|
41
|
+
const yarnVersion = getYarnVersion();
|
|
42
|
+
if (!yarnVersion) return;
|
|
43
|
+
|
|
44
|
+
// Check if Yarn version is 2 or higher. Plug'n'Play was introduced in Yarn v2
|
|
45
|
+
if (semver.gte(yarnVersion, '2.0.0')) {
|
|
46
|
+
// Sanitize and resolve the path
|
|
47
|
+
const normalizedProjectPath = path.resolve(projectDirectoryPath);
|
|
48
|
+
|
|
49
|
+
// Create .yarnrc.yml to use node_modules
|
|
50
|
+
const yarnrcPath = path.join(normalizedProjectPath, '.yarnrc.yml');
|
|
51
|
+
const yarnrcContent = 'nodeLinker: "node-modules"';
|
|
52
|
+
|
|
53
|
+
fs.writeFileSync(yarnrcPath, yarnrcContent);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
29
57
|
const getPreferredPackageManager = (
|
|
30
58
|
options: TCliTaskOptions
|
|
31
59
|
): TPackageManager => {
|
|
@@ -76,6 +104,8 @@ const isCustomView = (applicationType: TApplicationType) =>
|
|
|
76
104
|
export {
|
|
77
105
|
isSemVer,
|
|
78
106
|
shouldUseYarn,
|
|
107
|
+
getYarnVersion,
|
|
108
|
+
configureYarn,
|
|
79
109
|
slugify,
|
|
80
110
|
wordify,
|
|
81
111
|
upperFirst,
|