@ui5/cli 3.0.0-alpha.13 → 3.0.0-alpha.15

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 CHANGED
@@ -2,7 +2,28 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
4
4
 
5
- A list of unreleased changes can be found [here](https://github.com/SAP/ui5-cli/compare/v3.0.0-alpha.13...HEAD).
5
+ A list of unreleased changes can be found [here](https://github.com/SAP/ui5-cli/compare/v3.0.0-alpha.15...HEAD).
6
+
7
+ <a name="v3.0.0-alpha.15"></a>
8
+ ## [v3.0.0-alpha.15] - 2022-10-25
9
+ ### Breaking Changes
10
+ - Transform to native ESM ([#529](https://github.com/SAP/ui5-cli/issues/529)) [`8e15daf`](https://github.com/SAP/ui5-cli/commit/8e15daf0e949becbd49d60fc1532642aae7f733e)
11
+
12
+ ### BREAKING CHANGE
13
+
14
+ This package has been transformed to native ESM. Therefore it no longer provides a CommonJS export.
15
+ If your project uses CommonJS, it needs to be converted to ESM or use a dynamic import.
16
+
17
+ For more information see also:
18
+ - https://sap.github.io/ui5-tooling/updates/migrate-v3/
19
+ - https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
20
+
21
+
22
+ <a name="v3.0.0-alpha.14"></a>
23
+ ## [v3.0.0-alpha.14] - 2022-10-20
24
+ ### Dependency Updates
25
+ - Bump [@ui5](https://github.com/ui5)/builder from 3.0.0-alpha.10 to 3.0.0-alpha.11 [`b73f97f`](https://github.com/SAP/ui5-cli/commit/b73f97f7bc7e54747062640dd6db751e125ea9c9)
26
+
6
27
 
7
28
  <a name="v3.0.0-alpha.13"></a>
8
29
  ## [v3.0.0-alpha.13] - 2022-08-10
@@ -819,6 +840,8 @@ Only Node.js v10 or higher is supported.
819
840
  <a name="v0.0.1"></a>
820
841
  ## v0.0.1 - 2018-06-06
821
842
 
843
+ [v3.0.0-alpha.15]: https://github.com/SAP/ui5-cli/compare/v3.0.0-alpha.14...v3.0.0-alpha.15
844
+ [v3.0.0-alpha.14]: https://github.com/SAP/ui5-cli/compare/v3.0.0-alpha.13...v3.0.0-alpha.14
822
845
  [v3.0.0-alpha.13]: https://github.com/SAP/ui5-cli/compare/v3.0.0-alpha.12...v3.0.0-alpha.13
823
846
  [v3.0.0-alpha.12]: https://github.com/SAP/ui5-cli/compare/v3.0.0-alpha.11...v3.0.0-alpha.12
824
847
  [v3.0.0-alpha.11]: https://github.com/SAP/ui5-cli/compare/v3.0.0-alpha.10...v3.0.0-alpha.11
package/bin/ui5.js CHANGED
@@ -1,22 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // The following block should be compatible to as many Node.js versions as possible
4
- /* eslint-disable no-var */
5
- var pkg = require("../package.json");
6
- var semver;
7
- try {
8
- semver = require("semver");
9
- } catch (err) {
10
- // SyntaxError indicates an outdated Node.js version
11
- if (err.name !== "SyntaxError") {
12
- throw err;
13
- }
14
- }
15
- var nodeVersion = process.version;
4
+ // so that the message for unsupported Node.js versions can be displayed
5
+ import semver from "semver";
6
+ import {readFileSync} from "fs";
7
+
8
+ const pkgJsonPath = new URL("../package.json", import.meta.url);
9
+ const pkg = JSON.parse(readFileSync(pkgJsonPath));
10
+
11
+ const nodeVersion = process.version;
16
12
  /* eslint-enable no-var */
17
13
  if (
18
14
  pkg.engines && pkg.engines.node &&
19
- (!semver || !semver.satisfies(nodeVersion, pkg.engines.node, {includePrerelease: true}))
15
+ !semver.satisfies(nodeVersion, pkg.engines.node, {includePrerelease: true})
20
16
  ) {
21
17
  console.log("==================== UNSUPPORTED NODE.JS VERSION ====================");
22
18
  console.log("You are using an unsupported version of Node.js");
@@ -26,7 +22,7 @@ if (
26
22
  console.log("=====================================================================");
27
23
  process.exit(1);
28
24
  } else {
29
- if (semver && semver.prerelease(nodeVersion)) {
25
+ if (semver.prerelease(nodeVersion)) {
30
26
  console.log("====================== UNSTABLE NODE.JS VERSION =====================");
31
27
  console.log("You are using an unstable version of Node.js");
32
28
  console.log("Detected Node.js version " + nodeVersion);
@@ -38,12 +34,12 @@ if (
38
34
  console.log("=====================================================================");
39
35
  }
40
36
  // Timeout is required to log info when importing from local installation
41
- setTimeout(() => {
37
+ setTimeout(async () => {
42
38
  if (!process.env.UI5_CLI_NO_LOCAL) {
43
- const importLocal = require("import-local");
39
+ const {default: importLocal} = await import("import-local");
44
40
  // Prefer a local installation of @ui5/cli.
45
41
  // This will invoke the local CLI, so no further action required
46
- if (importLocal(__filename)) {
42
+ if (importLocal(import.meta.url)) {
47
43
  if (process.argv.includes("--verbose")) {
48
44
  console.info(`INFO: This project contains an individual ${pkg.name} installation which ` +
49
45
  "will be used over the global one.");
@@ -56,43 +52,11 @@ if (
56
52
  return;
57
53
  }
58
54
  }
59
-
60
- const updateNotifier = require("update-notifier");
61
- updateNotifier({
62
- pkg,
63
- updateCheckInterval: 1000 * 60 * 60 * 24, // 1 day
64
- shouldNotifyInNpmScript: true
65
- }).notify();
66
- // Remove --no-update-notifier from argv as it's not known to yargs, but we still want to support using it
67
- const NO_UPDATE_NOTIFIER = "--no-update-notifier";
68
- if (process.argv.includes(NO_UPDATE_NOTIFIER)) {
69
- process.argv = process.argv.filter((v) => v !== NO_UPDATE_NOTIFIER);
70
- }
71
-
72
- const cli = require("yargs");
73
-
74
- cli.parserConfiguration({
75
- "parse-numbers": false
55
+ const {default: cli} = await import("../lib/cli/cli.js");
56
+ await cli(pkg).catch((err) => {
57
+ console.log("Fatal Error: Unable to initialize UI5 CLI");
58
+ console.log(err);
59
+ process.exit(1);
76
60
  });
77
-
78
- // Explicitly set CLI version as the yargs default might
79
- // be wrong in case a local CLI installation is used
80
- // Also add CLI location
81
- const version = `${pkg.version} (from ${__filename})`;
82
- require("../lib/cli/version").set(version);
83
- cli.version(version);
84
-
85
- // Explicitly set script name to prevent windows from displaying "ui5.js"
86
- cli.scriptName("ui5");
87
-
88
- // CLI modules
89
- cli.commandDir("../lib/cli/commands");
90
-
91
- // Format terminal output to full available width
92
- cli.wrap(cli.terminalWidth());
93
-
94
- // yargs registers a get method on the argv property.
95
- // The property needs to be accessed to initialize everything.
96
- cli.argv;
97
61
  }, 0);
98
62
  }
package/jsdoc.json CHANGED
@@ -3,11 +3,13 @@
3
3
  "allowUnknownTags": false
4
4
  },
5
5
  "source": {
6
- "include": ["README.md", "index.js"],
6
+ "include": ["README.md"],
7
7
  "includePattern": ".+\\.js$",
8
8
  "excludePattern": "(node_modules(\\\\|/))"
9
9
  },
10
- "plugins": [],
10
+ "plugins": [
11
+ "jsdoc-plugin.cjs"
12
+ ],
11
13
  "opts": {
12
14
  "template": "node_modules/docdash/",
13
15
  "encoding": "utf8",
@@ -0,0 +1,78 @@
1
+ import chalk from "chalk";
2
+ import logger from "@ui5/logger";
3
+
4
+ export default function(cli) {
5
+ cli.usage("Usage: ui5 <command> [options]")
6
+ .demandCommand(1, "Command required! Please have a look at the help documentation above.")
7
+ .option("config", {
8
+ describe: "Path to project configuration file in YAML format",
9
+ type: "string"
10
+ })
11
+ .option("dependency-definition", {
12
+ describe: "Path to a YAML file containing the project's dependency tree. " +
13
+ "This option will disable resolution of node package dependencies.",
14
+ type: "string"
15
+ })
16
+ .option("verbose", {
17
+ describe: "Enable verbose logging.",
18
+ type: "boolean"
19
+ })
20
+ .option("loglevel", {
21
+ alias: "log-level",
22
+ describe: "Set the logging level (error|warn|info|verbose|silly).",
23
+ default: "info",
24
+ type: "string"
25
+ })
26
+ .option("x-perf", {
27
+ describe: "Outputs performance measurements",
28
+ default: false,
29
+ type: "boolean"
30
+ })
31
+ .showHelpOnFail(true)
32
+ .strict(true)
33
+ .alias("help", "h")
34
+ .alias("version", "v")
35
+ .example("ui5 <command> --translator static:/path/to/projectDependencies.yaml",
36
+ "Execute command using a \"static\" translator with translator parameters")
37
+ .example("ui5 <command> --config /path/to/ui5.yaml",
38
+ "Execute command using a project configuration from custom path")
39
+ .fail(function(msg, err, yargs) {
40
+ if (err) {
41
+ // Exception
42
+ if (logger.isLevelEnabled("error")) {
43
+ console.log("");
44
+ console.log(chalk.bold.red("⚠️ Process Failed With Error"));
45
+
46
+ console.log("");
47
+ console.log(chalk.underline("Error Message:"));
48
+ console.log(err.message);
49
+
50
+ // Unexpected errors should always be logged with stack trace
51
+ const unexpectedErrors = ["SyntaxError", "ReferenceError", "TypeError"];
52
+ if (unexpectedErrors.includes(err.name) || logger.isLevelEnabled("verbose")) {
53
+ console.log("");
54
+ console.log(chalk.underline("Stack Trace:"));
55
+ console.log(err.stack);
56
+ console.log("");
57
+ console.log(
58
+ chalk.dim(
59
+ `If you think this is an issue of the UI5 Tooling, you might report it using the ` +
60
+ `following URL: `) +
61
+ chalk.dim.bold.underline(`https://github.com/SAP/ui5-tooling/issues/new/choose`));
62
+ } else {
63
+ console.log("");
64
+ console.log(chalk.dim(
65
+ `For details, execute the same command again with an additional '--verbose' parameter`));
66
+ }
67
+ }
68
+ } else {
69
+ // Yargs error
70
+ console.log(chalk.bold.yellow("Command Failed:"));
71
+ console.log(`${msg}`);
72
+ console.log("");
73
+ console.log(chalk.dim(`See 'ui5 --help' or 'ui5 build --help' for help`));
74
+ }
75
+ process.exit(1);
76
+ });
77
+ }
78
+
package/lib/cli/cli.js ADDED
@@ -0,0 +1,64 @@
1
+ import updateNotifier from "update-notifier";
2
+ import yargs from "yargs";
3
+ import {hideBin} from "yargs/helpers";
4
+ import {setVersion} from "./version.js";
5
+ import base from "./base.js";
6
+ import {fileURLToPath} from "node:url";
7
+ import {readdir} from "node:fs/promises";
8
+
9
+ async function getCommands() {
10
+ return (await readdir(new URL("./commands", import.meta.url), {withFileTypes: true}))
11
+ .filter((e) => !e.isDirectory() && e.name.endsWith(".js"))
12
+ .map((e) => new URL(`./commands/${e.name}`, import.meta.url));
13
+ }
14
+
15
+ export default async (pkg) => {
16
+ updateNotifier({
17
+ pkg,
18
+ updateCheckInterval: 86400000, // 1 day
19
+ shouldNotifyInNpmScript: true
20
+ }).notify();
21
+
22
+ // Remove --no-update-notifier from argv as it's not known to yargs, but we still want to support using it
23
+ const NO_UPDATE_NOTIFIER = "--no-update-notifier";
24
+ if (process.argv.includes(NO_UPDATE_NOTIFIER)) {
25
+ process.argv = process.argv.filter((v) => v !== NO_UPDATE_NOTIFIER);
26
+ }
27
+
28
+ const cli = yargs(hideBin(process.argv));
29
+ cli.parserConfiguration({
30
+ "parse-numbers": false
31
+ });
32
+
33
+ // Explicitly set CLI version as the yargs default might
34
+ // be wrong in case a local CLI installation is used
35
+ // Also add CLI location
36
+ const ui5JsPath = fileURLToPath(new URL("../../bin/ui5.js", import.meta.url));
37
+ const pkgVersion = `${pkg.version} (from ${ui5JsPath})`;
38
+
39
+ setVersion(pkgVersion);
40
+ cli.version(pkgVersion);
41
+
42
+ // Explicitly set script name to prevent windows from displaying "ui5.js"
43
+ cli.scriptName("ui5");
44
+
45
+ // Setup general options and error handling
46
+ base(cli);
47
+
48
+ // CLI modules
49
+ // YError: loading a directory of commands is not supported yet for ESM
50
+ // cli.commandDir("../lib/cli/commands");
51
+ // See https://github.com/yargs/yargs/issues/2152
52
+ const commandModules = await getCommands();
53
+ for (const modulePath of commandModules) {
54
+ const {default: command} = await import(modulePath);
55
+ cli.command(command);
56
+ }
57
+
58
+ // Format terminal output to full available width
59
+ cli.wrap(cli.terminalWidth());
60
+
61
+ // yargs registers a get method on the argv property.
62
+ // The property needs to be accessed to initialize everything.
63
+ cli.argv;
64
+ };
@@ -1,8 +1,9 @@
1
1
  // Add
2
+ import base from "../middlewares/base.js";
2
3
  const addCommand = {
3
4
  command: "add [--development] [--optional] <framework-libraries..>",
4
5
  describe: "Add SAPUI5/OpenUI5 framework libraries to the project configuration.",
5
- middlewares: [require("../middlewares/base.js")]
6
+ middlewares: [base]
6
7
  };
7
8
 
8
9
  addCommand.builder = function(cli) {
@@ -56,7 +57,8 @@ addCommand.handler = async function(argv) {
56
57
  return library;
57
58
  });
58
59
 
59
- const {yamlUpdated} = await require("../../framework/add")({
60
+ const {default: add} = await import("../../framework/add.js");
61
+ const {yamlUpdated} = await add({
60
62
  projectGraphOptions,
61
63
  libraries
62
64
  });
@@ -85,4 +87,4 @@ addCommand.handler = async function(argv) {
85
87
  }
86
88
  };
87
89
 
88
- module.exports = addCommand;
90
+ export default addCommand;
@@ -1,6 +1,4 @@
1
- // Build
2
-
3
- const baseMiddleware = require("../middlewares/base.js");
1
+ import baseMiddleware from "../middlewares/base.js";
4
2
 
5
3
  const build = {
6
4
  command: "build",
@@ -121,21 +119,21 @@ build.builder = function(cli) {
121
119
  };
122
120
 
123
121
  async function handleBuild(argv) {
124
- const logger = require("@ui5/logger");
125
- const {generateProjectGraph} = require("@ui5/project");
122
+ const {default: logger} = await import("@ui5/logger");
123
+ const {graphFromStaticFile, graphFromPackageDependencies} = await import("@ui5/project/graph");
126
124
 
127
125
  const command = argv._[argv._.length - 1];
128
126
  logger.setShowProgress(true);
129
127
 
130
128
  let graph;
131
129
  if (argv.dependencyDefinition) {
132
- graph = await generateProjectGraph.usingStaticFile({
130
+ graph = await graphFromStaticFile({
133
131
  filePath: argv.dependencyDefinition,
134
132
  rootConfigPath: argv.config,
135
133
  versionOverride: argv.frameworkVersion
136
134
  });
137
135
  } else {
138
- graph = await generateProjectGraph.usingNodePackageDependencies({
136
+ graph = await graphFromPackageDependencies({
139
137
  rootConfigPath: argv.config,
140
138
  versionOverride: argv.frameworkVersion
141
139
  });
@@ -168,4 +166,4 @@ async function handleBuild(argv) {
168
166
 
169
167
  function noop() {}
170
168
 
171
- module.exports = build;
169
+ export default build;
@@ -1,25 +1,25 @@
1
1
  // Init
2
+ import baseMiddleware from "../middlewares/base.js";
3
+
2
4
  const initCommand = {
3
5
  command: "init",
4
6
  describe: "Initialize the UI5 Tooling configuration for an application or library project.",
5
- middlewares: [require("../middlewares/base.js")]
7
+ middlewares: [baseMiddleware]
6
8
  };
7
9
 
8
10
  initCommand.handler = async function() {
9
- const fsHelper = require("../../utils/fsHelper");
10
- const init = require("../../init/init");
11
- const promisify = require("util").promisify;
12
- const path = require("path");
13
- const fs = require("fs");
14
- const jsYaml = require("js-yaml");
15
- const writeFile = promisify(fs.writeFile);
11
+ const {exists} = await import("../../utils/fsHelper.js");
12
+ const {default: init} = await import("../../init/init.js");
13
+ const {default: path} = await import("node:path");
14
+ const {writeFile} = await import("node:fs/promises");
15
+ const {default: jsYaml} = await import("js-yaml");
16
16
 
17
17
  const yamlPath = path.resolve("./ui5.yaml");
18
- if (await fsHelper.exists(yamlPath)) {
18
+ if (await exists(yamlPath)) {
19
19
  throw new Error("Initialization not possible: ui5.yaml already exists");
20
20
  }
21
21
 
22
- const projectConfig = await init.init();
22
+ const projectConfig = await init();
23
23
  const yaml = jsYaml.dump(projectConfig);
24
24
 
25
25
  await writeFile(yamlPath, yaml);
@@ -27,4 +27,4 @@ initCommand.handler = async function() {
27
27
  console.log(yaml);
28
28
  };
29
29
 
30
- module.exports = initCommand;
30
+ export default initCommand;
@@ -1,8 +1,10 @@
1
1
  // Remove
2
+ import baseMiddleware from "../middlewares/base.js";
3
+
2
4
  const removeCommand = {
3
5
  command: "remove <framework-libraries..>",
4
6
  describe: "Remove SAPUI5/OpenUI5 framework libraries from the project configuration.",
5
- middlewares: [require("../middlewares/base.js")]
7
+ middlewares: [baseMiddleware]
6
8
  };
7
9
 
8
10
  removeCommand.builder = function(cli) {
@@ -37,7 +39,9 @@ removeCommand.handler = async function(argv) {
37
39
  return library;
38
40
  });
39
41
 
40
- const {yamlUpdated} = await require("../../framework/remove")({
42
+ const {default: remove} = await import("../../framework/remove.js");
43
+
44
+ const {yamlUpdated} = await remove({
41
45
  projectGraphOptions,
42
46
  libraries
43
47
  });
@@ -62,4 +66,4 @@ removeCommand.handler = async function(argv) {
62
66
  }
63
67
  };
64
68
 
65
- module.exports = removeCommand;
69
+ export default removeCommand;
@@ -1,11 +1,13 @@
1
- const path = require("path");
2
- const os = require("os");
1
+ import path from "node:path";
2
+ import os from "node:os";
3
+ import chalk from "chalk";
4
+ import baseMiddleware from "../middlewares/base.js";
3
5
 
4
6
  // Serve
5
7
  const serve = {
6
8
  command: "serve",
7
9
  describe: "Start a web server for the current project",
8
- middlewares: [require("../middlewares/base.js")]
10
+ middlewares: [baseMiddleware]
9
11
  };
10
12
 
11
13
  serve.builder = function(cli) {
@@ -73,18 +75,18 @@ serve.builder = function(cli) {
73
75
  };
74
76
 
75
77
  serve.handler = async function(argv) {
76
- const {generateProjectGraph} = require("@ui5/project");
77
- const ui5Server = require("@ui5/server");
78
- const server = ui5Server.server;
78
+ const {graphFromStaticFile, graphFromPackageDependencies} = await import("@ui5/project/graph");
79
+ const {serve: serverServe} = await import("@ui5/server");
80
+ const {getSslCertificate} = await import("@ui5/server/internal/sslUtil");
79
81
 
80
82
  let graph;
81
83
  if (argv.dependencyDefinition) {
82
- graph = await generateProjectGraph.usingStaticFile({
84
+ graph = await graphFromStaticFile({
83
85
  filePath: argv.dependencyDefinition,
84
86
  versionOverride: argv.frameworkVersion
85
87
  });
86
88
  } else {
87
- graph = await generateProjectGraph.usingNodePackageDependencies({
89
+ graph = await graphFromPackageDependencies({
88
90
  rootConfigPath: argv.config,
89
91
  versionOverride: argv.frameworkVersion
90
92
  });
@@ -124,17 +126,16 @@ serve.handler = async function(argv) {
124
126
  };
125
127
 
126
128
  if (serverConfig.h2) {
127
- const {key, cert} = await ui5Server.sslUtil.getSslCertificate(serverConfig.key, serverConfig.cert);
129
+ const {key, cert} = await getSslCertificate(serverConfig.key, serverConfig.cert);
128
130
  serverConfig.key = key;
129
131
  serverConfig.cert = cert;
130
132
  }
131
133
 
132
- const {h2, port: actualPort} = await server.serve(graph, serverConfig);
134
+ const {h2, port: actualPort} = await serverServe(graph, serverConfig);
133
135
 
134
136
  const protocol = h2 ? "https" : "http";
135
137
  let browserUrl = protocol + "://localhost:" + actualPort;
136
138
  if (argv.acceptRemoteConnections) {
137
- const chalk = require("chalk");
138
139
  console.log("");
139
140
  console.log(chalk.bold("⚠️ This server is accepting connections from all hosts on your network"));
140
141
  console.log(chalk.dim.underline("Please Note:"));
@@ -158,9 +159,9 @@ serve.handler = async function(argv) {
158
159
  }
159
160
  browserUrl += relPath;
160
161
  }
161
- const open = require("open");
162
+ const {default: open} = await import("open");
162
163
  open(browserUrl, {url: true});
163
164
  }
164
165
  };
165
166
 
166
- module.exports = serve;
167
+ export default serve;
@@ -1,10 +1,13 @@
1
1
  // Tree
2
+ import baseMiddleware from "../middlewares/base.js";
3
+ import chalk from "chalk";
4
+
2
5
  const tree = {
3
6
  command: "tree",
4
7
  describe:
5
8
  "Outputs the dependency tree of the current project to stdout. " +
6
9
  "It takes all relevant parameters of ui5 build into account.",
7
- middlewares: [require("../middlewares/base.js")]
10
+ middlewares: [baseMiddleware]
8
11
  };
9
12
 
10
13
  tree.builder = function(cli) {
@@ -17,29 +20,27 @@ tree.builder = function(cli) {
17
20
  };
18
21
 
19
22
  tree.handler = async function(argv) {
20
- const chalk = require("chalk");
21
-
22
23
  let startTime;
23
24
  let elapsedTime;
24
25
  if (argv.xPerf) {
25
26
  startTime = process.hrtime();
26
27
  }
27
- const {generateProjectGraph} = require("@ui5/project");
28
+ const {graphFromStaticFile, graphFromPackageDependencies} = await import("@ui5/project/graph");
28
29
  let graph;
29
30
  if (argv.dependencyDefinition) {
30
- graph = await generateProjectGraph.usingStaticFile({
31
+ graph = await graphFromStaticFile({
31
32
  filePath: argv.dependencyDefinition,
32
33
  versionOverride: argv.frameworkVersion
33
34
  });
34
35
  } else {
35
- graph = await generateProjectGraph.usingNodePackageDependencies({
36
+ graph = await graphFromPackageDependencies({
36
37
  rootConfigPath: argv.config,
37
38
  versionOverride: argv.frameworkVersion
38
39
  });
39
40
  }
40
41
 
41
42
  if (argv.xPerf) {
42
- elapsedTime = getElapsedTime(startTime);
43
+ elapsedTime = await getElapsedTime(startTime);
43
44
  }
44
45
 
45
46
  const projects = {};
@@ -98,9 +99,9 @@ tree.handler = async function(argv) {
98
99
  }
99
100
  };
100
101
 
101
- function getElapsedTime(startTime) {
102
+ async function getElapsedTime(startTime) {
102
103
  const timeDiff = process.hrtime(startTime);
103
- const prettyHrtime = require("pretty-hrtime");
104
+ const {default: prettyHrtime} = await import("pretty-hrtime");
104
105
  return prettyHrtime(timeDiff);
105
106
  }
106
- module.exports = tree;
107
+ export default tree;
@@ -1,8 +1,10 @@
1
1
  // Use
2
+ import baseMiddleware from "../middlewares/base.js";
3
+
2
4
  const useCommand = {
3
5
  command: "use <framework-info>",
4
6
  describe: "Initialize or update the project's framework configuration.",
5
- middlewares: [require("../middlewares/base.js")]
7
+ middlewares: [baseMiddleware]
6
8
  };
7
9
 
8
10
  useCommand.builder = function(cli) {
@@ -60,7 +62,8 @@ useCommand.handler = async function(argv) {
60
62
  config: argv.config
61
63
  };
62
64
 
63
- const {usedFramework, usedVersion, yamlUpdated} = await require("../../framework/use")({
65
+ const {default: use} = await import("../../framework/use.js");
66
+ const {usedFramework, usedVersion, yamlUpdated} = await use({
64
67
  projectGraphOptions,
65
68
  frameworkOptions
66
69
  });
@@ -79,4 +82,4 @@ useCommand.handler = async function(argv) {
79
82
  }
80
83
  };
81
84
 
82
- module.exports = useCommand;
85
+ export default useCommand;
@@ -1,5 +1,8 @@
1
- // Versions
2
- const baseMiddleware = require("../middlewares/base.js");
1
+ import baseMiddleware from "../middlewares/base.js";
2
+ import {createRequire} from "node:module";
3
+
4
+ // Using CommonsJS require as importing json files causes an ExperimentalWarning
5
+ const require = createRequire(import.meta.url);
3
6
 
4
7
  const versions = {
5
8
  command: "versions",
@@ -18,20 +21,20 @@ versions.getVersion = (pkg) => {
18
21
  };
19
22
 
20
23
  versions.handler = async function() {
21
- const cliVersion = versions.getVersion("../../..");
22
- const builderVersion = versions.getVersion("@ui5/builder");
23
- const serverVersion = versions.getVersion("@ui5/server");
24
- const fsVersion = versions.getVersion("@ui5/fs");
25
- const projectVersion = versions.getVersion("@ui5/project");
26
- const loggerVersion = versions.getVersion("@ui5/logger");
27
- console.log(`
28
- @ui5/cli: ${cliVersion}
29
- @ui5/builder: ${builderVersion}
30
- @ui5/server: ${serverVersion}
31
- @ui5/fs: ${fsVersion}
32
- @ui5/project: ${projectVersion}
33
- @ui5/logger: ${loggerVersion}
34
- `);
24
+ const output = (await Promise.all(
25
+ [
26
+ "@ui5/cli",
27
+ "@ui5/builder",
28
+ "@ui5/server",
29
+ "@ui5/fs",
30
+ "@ui5/project",
31
+ "@ui5/logger",
32
+ ].map(async (id) => {
33
+ return (id + ":").padEnd(15) + versions.getVersion(id);
34
+ })
35
+ )).join("\n");
36
+
37
+ console.log(`\n${output}\n`);
35
38
  };
36
39
 
37
- module.exports = versions;
40
+ export default versions;
@@ -1,4 +1,4 @@
1
- const logger = require("./logger");
1
+ import {initLogger} from "./logger.js";
2
2
  /**
3
3
  * Base middleware for CLI commands.
4
4
  *
@@ -7,7 +7,7 @@ const logger = require("./logger");
7
7
  * @param {object} argv The CLI arguments
8
8
  * @returns {object}
9
9
  */
10
- module.exports = function(argv) {
11
- logger.init(argv);
10
+ export default async function(argv) {
11
+ await initLogger(argv);
12
12
  return {};
13
- };
13
+ }