@modern-js/packages-generator 3.0.4 → 3.0.5

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/dist/index.js CHANGED
@@ -35750,7 +35750,7 @@ var require_nodeEnv = __commonJS({
35750
35750
  });
35751
35751
  }
35752
35752
  exports.canUseNpm = canUseNpm;
35753
- function canUseYarn() {
35753
+ function canUseYarn2() {
35754
35754
  return __async(this, null, function* () {
35755
35755
  try {
35756
35756
  yield (0, compiled_1.execa)("yarn", ["--version"], { env: process.env });
@@ -35760,7 +35760,7 @@ var require_nodeEnv = __commonJS({
35760
35760
  }
35761
35761
  });
35762
35762
  }
35763
- exports.canUseYarn = canUseYarn;
35763
+ exports.canUseYarn = canUseYarn2;
35764
35764
  function canUsePnpm() {
35765
35765
  return __async(this, null, function* () {
35766
35766
  try {
@@ -44398,7 +44398,7 @@ var require_env = __commonJS({
44398
44398
  exports.canUseNpm = canUseNpm;
44399
44399
  exports.canUseNvm = canUseNvm;
44400
44400
  exports.canUsePnpm = canUsePnpm;
44401
- exports.canUseYarn = canUseYarn;
44401
+ exports.canUseYarn = canUseYarn2;
44402
44402
  var _utils = require_dist();
44403
44403
  function canUseNvm() {
44404
44404
  return __async(this, null, function* () {
@@ -44425,7 +44425,7 @@ var require_env = __commonJS({
44425
44425
  }
44426
44426
  });
44427
44427
  }
44428
- function canUseYarn() {
44428
+ function canUseYarn2() {
44429
44429
  return __async(this, null, function* () {
44430
44430
  try {
44431
44431
  yield (0, _utils.execa)("yarn", ["--version"], {
@@ -45461,14 +45461,14 @@ var require_packageManager = __commonJS({
45461
45461
  value: true
45462
45462
  });
45463
45463
  exports.canUsePnpm = canUsePnpm;
45464
- exports.canUseYarn = canUseYarn;
45464
+ exports.canUseYarn = canUseYarn2;
45465
45465
  exports.runInstall = runInstall;
45466
45466
  var _path = _interopRequireDefault(require("path"));
45467
45467
  var _utils = require_dist();
45468
45468
  function _interopRequireDefault(obj) {
45469
45469
  return obj && obj.__esModule ? obj : { default: obj };
45470
45470
  }
45471
- function canUseYarn() {
45471
+ function canUseYarn2() {
45472
45472
  return __async(this, null, function* () {
45473
45473
  try {
45474
45474
  yield (0, _utils.execa)("yarn", ["--version"], {
@@ -45515,7 +45515,7 @@ var require_packageManager = __commonJS({
45515
45515
  params.push(`--registry=${registryUrl}`);
45516
45516
  }
45517
45517
  yield (0, _utils.execa)("pnpm", params, options);
45518
- } else if (yield canUseYarn()) {
45518
+ } else if (yield canUseYarn2()) {
45519
45519
  const params = ["install", "--production", "--silent", "--ignore-scripts"];
45520
45520
  if (registryUrl) {
45521
45521
  params.push(`--registry=${registryUrl}`);
@@ -136245,6 +136245,26 @@ var require_compiled2 = __commonJS({
136245
136245
  }
136246
136246
  });
136247
136247
 
136248
+ // ../../../toolkit/utils/dist/commands.js
136249
+ var require_commands = __commonJS({
136250
+ "../../../toolkit/utils/dist/commands.js"(exports) {
136251
+ "use strict";
136252
+ Object.defineProperty(exports, "__esModule", { value: true });
136253
+ exports.isDevCommand = exports.getCommand = void 0;
136254
+ var getCommand = () => {
136255
+ const args = process.argv.slice(2);
136256
+ const command = args[0];
136257
+ return command;
136258
+ };
136259
+ exports.getCommand = getCommand;
136260
+ var isDevCommand = () => {
136261
+ const command = (0, exports.getCommand)();
136262
+ return command === "dev" || command === "start";
136263
+ };
136264
+ exports.isDevCommand = isDevCommand;
136265
+ }
136266
+ });
136267
+
136248
136268
  // ../../../toolkit/utils/dist/format.js
136249
136269
  var require_format2 = __commonJS({
136250
136270
  "../../../toolkit/utils/dist/format.js"(exports) {
@@ -136819,7 +136839,7 @@ var require_constants6 = __commonJS({
136819
136839
  exports.SERVER_DIR = "server";
136820
136840
  exports.SHARED_DIR = "shared";
136821
136841
  exports.CONFIG_CACHE_DIR = "./node_modules/.cache/node-bundle-require";
136822
- exports.CONFIG_FILE_EXTENSIONS = [".js", ".ts", ".ejs", ".mjs"];
136842
+ exports.CONFIG_FILE_EXTENSIONS = [".js", ".ts", ".mjs"];
136823
136843
  exports.OUTPUT_CONFIG_FILE = "modern.config.json";
136824
136844
  exports.DEFAULT_SERVER_CONFIG = "modern.server-runtime.config";
136825
136845
  exports.ROUTE_MINIFEST_FILE = "routes-manifest.json";
@@ -137310,7 +137330,7 @@ var require_nodeEnv2 = __commonJS({
137310
137330
  });
137311
137331
  }
137312
137332
  exports.canUseNpm = canUseNpm;
137313
- function canUseYarn() {
137333
+ function canUseYarn2() {
137314
137334
  return __async(this, null, function* () {
137315
137335
  try {
137316
137336
  yield (0, compiled_1.execa)("yarn", ["--version"], { env: process.env });
@@ -137320,7 +137340,7 @@ var require_nodeEnv2 = __commonJS({
137320
137340
  }
137321
137341
  });
137322
137342
  }
137323
- exports.canUseYarn = canUseYarn;
137343
+ exports.canUseYarn = canUseYarn2;
137324
137344
  function canUsePnpm() {
137325
137345
  return __async(this, null, function* () {
137326
137346
  try {
@@ -138399,6 +138419,7 @@ var require_dist3 = __commonJS({
138399
138419
  };
138400
138420
  Object.defineProperty(exports, "__esModule", { value: true });
138401
138421
  __exportStar(require_compiled2(), exports);
138422
+ __exportStar(require_commands(), exports);
138402
138423
  __exportStar(require_format2(), exports);
138403
138424
  __exportStar(require_FileSizeReporter2(), exports);
138404
138425
  __exportStar(require_printBuildError2(), exports);
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "3.0.4",
14
+ "version": "3.0.5",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "main": "./dist/index.js",
17
17
  "files": [
@@ -27,10 +27,10 @@
27
27
  "@types/node": "^14",
28
28
  "jest": "^27",
29
29
  "typescript": "^4",
30
- "@modern-js/generator-common": "3.0.4",
31
- "@modern-js/generator-utils": "3.0.4",
32
- "@scripts/jest-config": "2.2.0",
33
- "@scripts/build": "2.2.0"
30
+ "@modern-js/generator-common": "3.0.5",
31
+ "@scripts/jest-config": "2.3.0",
32
+ "@modern-js/generator-utils": "3.0.5",
33
+ "@scripts/build": "2.3.0"
34
34
  },
35
35
  "sideEffects": false,
36
36
  "publishConfig": {
package/src/index.ts ADDED
@@ -0,0 +1,68 @@
1
+ import path from 'path';
2
+ import { GeneratorContext, GeneratorCore } from '@modern-js/codesmith';
3
+ import { AppAPI } from '@modern-js/codesmith-api-app';
4
+ import { JsonAPI } from '@modern-js/codesmith-api-json';
5
+ import { PackageManager } from '@modern-js/generator-common';
6
+ import { fs } from '@modern-js/generator-utils';
7
+
8
+ const handleTemplateFile = async (
9
+ context: GeneratorContext,
10
+ generator: GeneratorCore,
11
+ ) => {
12
+ const { packageManager, packagesInfo } = context.config;
13
+ const jsonAPI = new JsonAPI(generator);
14
+ if (packageManager === PackageManager.Pnpm) {
15
+ const update: Record<string, string> = {};
16
+ Object.entries(packagesInfo || {}).forEach(([name, version]) => {
17
+ update[`pnpm.overrides.${name}`] = version as string;
18
+ });
19
+ await jsonAPI.update(context.materials.default.get('package.json'), {
20
+ query: {},
21
+ update: {
22
+ $set: update,
23
+ },
24
+ });
25
+ } else {
26
+ const pkgInfo = fs.readJSONSync(
27
+ path.join(context.materials.default.basePath, 'package.json'),
28
+ 'utf-8',
29
+ );
30
+ const { dependencies = {}, devDependencies = {} } = pkgInfo;
31
+
32
+ const update: Record<string, string> = {};
33
+ Object.entries(packagesInfo || {}).forEach(([name, version]) => {
34
+ update[`resolutions.${name}`] = version as string;
35
+ if (dependencies[name]) {
36
+ update[`dependencies.${name}`] = version as string;
37
+ }
38
+ if (devDependencies[name]) {
39
+ update[`devDependencies.${name}`] = version as string;
40
+ }
41
+ });
42
+ await jsonAPI.update(context.materials.default.get('package.json'), {
43
+ query: {},
44
+ update: {
45
+ $set: update,
46
+ },
47
+ });
48
+ }
49
+ };
50
+
51
+ export default async (context: GeneratorContext, generator: GeneratorCore) => {
52
+ const appApi = new AppAPI(context, generator);
53
+ const { locale } = context.config;
54
+ appApi.i18n.changeLanguage({ locale });
55
+
56
+ if (!(await appApi.checkEnvironment())) {
57
+ // eslint-disable-next-line no-process-exit
58
+ process.exit(1);
59
+ }
60
+
61
+ generator.logger.debug(`start run @modern-js/packages-generator`);
62
+ generator.logger.debug(`context=${JSON.stringify(context)}`);
63
+ generator.logger.debug(`context.data=${JSON.stringify(context.data)}`);
64
+
65
+ await handleTemplateFile(context, generator);
66
+
67
+ generator.logger.debug(`forge @modern-js/packages-generator succeed `);
68
+ };