libdragon 10.7.0 → 10.7.1

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
@@ -1,5 +1,16 @@
1
1
  # Change Log
2
2
 
3
+ ## [10.7.1] - 2022-04-20
4
+
5
+ ### Fixed
6
+
7
+ - Migrating from and old version was incorrectly erroring out to do an additional
8
+ `init`, which is not necessarily required.
9
+
10
+ ### Changed
11
+
12
+ - Do not print usage information when a command fails.
13
+
3
14
  ## [10.7.0] - 2022-04-17
4
15
 
5
16
  ### Fixed
@@ -8,22 +19,6 @@
8
19
  means the id output of the `start` action is now written to stdout while we can
9
20
  also display other information on the terminal. This allowed enabling the docker
10
21
  logs for a more responsive experience. The output of `help` still goes to stdout.
11
- - Skip reading the project information for `version` and `help` commands. This
12
- was breaking things when these were run with a stopped docker service.
13
- - Resolved a potential failure case where the host mount path is not reported
14
- as a native path. That would prevent proper container discovery. This was not
15
- being an issue previously but I realized it was not working for Windows now.
16
- - Do not throw if the output stream is not finalized. This was previously causing
17
- issues when the long output of a command is piped to another process like `less`.
18
- Fixes #46
19
- - Produce a correct error if an invalid flag with a singe `-` is provided.
20
- - Sekeleton project's Makefile `clean` recipe now works properly. Fixes #56.
21
- - A case where it is impossible to recover the container is fixed. This was
22
- happening when the host does not have git and the cached container file is
23
- missing. In that case the cli was attempting to run git without the containerId.
24
- - `destroy` can now cleanup any remaining container even if the project init was
25
- failed. This is also useful to clean up old folders that were once libdragon
26
- projects.
27
22
 
28
23
  ### Added
29
24
 
package/index.js CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  const chalk = require('chalk').stderr;
4
4
 
5
- const { fn: printUsage } = require('./modules/actions/help');
6
5
  const {
7
6
  STATUS_OK,
8
7
  STATUS_BAD_PARAM,
@@ -25,11 +24,6 @@ parseParameters(process.argv)
25
24
  .catch((e) => {
26
25
  if (e instanceof ParameterError) {
27
26
  log(chalk.red(e.message));
28
- printUsage({
29
- options: {
30
- EXTRA_PARAMS: [e.actionName],
31
- },
32
- });
33
27
  process.exit(STATUS_BAD_PARAM);
34
28
  }
35
29
  if (e instanceof ValidationError) {
@@ -2,7 +2,6 @@ const chalk = require('chalk').stderr;
2
2
 
3
3
  const { log } = require('./helpers');
4
4
  const actions = require('./actions');
5
- const { fn: printUsage } = require('./actions/help');
6
5
  const { STATUS_BAD_PARAM } = require('./constants');
7
6
  const { globals } = require('./globals');
8
7
 
@@ -56,13 +55,11 @@ const parseParameters = async (argv) => {
56
55
 
57
56
  if (val.indexOf('-') == 0) {
58
57
  log(chalk.red(`Invalid flag \`${val}\``));
59
- printUsage();
60
58
  process.exit(STATUS_BAD_PARAM);
61
59
  }
62
60
 
63
61
  if (options.CURRENT_ACTION) {
64
62
  log(chalk.red(`Expected only a single action, found: \`${val}\``));
65
- printUsage();
66
63
  process.exit(STATUS_BAD_PARAM);
67
64
  }
68
65
 
@@ -70,7 +67,6 @@ const parseParameters = async (argv) => {
70
67
 
71
68
  if (!options.CURRENT_ACTION) {
72
69
  log(chalk.red(`Invalid action \`${val}\``));
73
- printUsage();
74
70
  process.exit(STATUS_BAD_PARAM);
75
71
  }
76
72
 
@@ -82,7 +78,6 @@ const parseParameters = async (argv) => {
82
78
 
83
79
  if (!options.CURRENT_ACTION) {
84
80
  log(chalk.red('No action provided'));
85
- printUsage();
86
81
  process.exit(STATUS_BAD_PARAM);
87
82
  }
88
83
 
@@ -91,7 +86,6 @@ const parseParameters = async (argv) => {
91
86
  options.EXTRA_PARAMS.length === 0
92
87
  ) {
93
88
  log(chalk.red('You should provide a command to exec'));
94
- printUsage(undefined, [options.CURRENT_ACTION.name]);
95
89
  process.exit(STATUS_BAD_PARAM);
96
90
  }
97
91
 
@@ -102,7 +96,6 @@ const parseParameters = async (argv) => {
102
96
  options.DOCKER_IMAGE
103
97
  ) {
104
98
  log(chalk.red('Invalid flag: image'));
105
- printUsage(undefined, [options.CURRENT_ACTION.name]);
106
99
  process.exit(STATUS_BAD_PARAM);
107
100
  }
108
101
 
@@ -111,13 +104,11 @@ const parseParameters = async (argv) => {
111
104
  !['submodule', 'subtree', 'manual'].includes(options.VENDOR_STRAT)
112
105
  ) {
113
106
  log(chalk.red(`Invalid strategy \`${options.VENDOR_STRAT}\``));
114
- printUsage();
115
107
  process.exit(STATUS_BAD_PARAM);
116
108
  }
117
109
 
118
110
  if (![actions.disasm].includes(options.CURRENT_ACTION) && options.FILE) {
119
111
  log(chalk.red('Invalid flag: file'));
120
- printUsage(undefined, [options.CURRENT_ACTION.name]);
121
112
  process.exit(STATUS_BAD_PARAM);
122
113
  }
123
114
 
@@ -77,17 +77,21 @@ async function findContainerId(libdragonInfo) {
77
77
  }
78
78
  }
79
79
 
80
- async function findLibdragonRoot(start = '.') {
81
- const manifest = path.join(start, LIBDRAGON_PROJECT_MANIFEST, CONFIG_FILE);
82
- if (await fileExists(manifest)) {
80
+ async function findLibdragonRoot(
81
+ start = '.',
82
+ relativeFile = path.join(LIBDRAGON_PROJECT_MANIFEST, CONFIG_FILE)
83
+ ) {
84
+ const fileToCheck = path.join(start, relativeFile);
85
+ log(`Checking if file exists: ${path.resolve(fileToCheck)}`, true);
86
+ if (await fileExists(fileToCheck)) {
83
87
  return path.resolve(start);
88
+ }
89
+
90
+ const parent = path.resolve(start, '..');
91
+ if (parent !== path.resolve(start)) {
92
+ return findLibdragonRoot(parent, relativeFile);
84
93
  } else {
85
- const parent = path.resolve(start, '..');
86
- if (parent !== path.resolve(start)) {
87
- return findLibdragonRoot(parent);
88
- } else {
89
- return;
90
- }
94
+ return;
91
95
  }
92
96
  }
93
97
 
@@ -114,7 +118,15 @@ async function readProjectInfo(info) {
114
118
  return info;
115
119
  }
116
120
 
117
- const projectRoot = await findLibdragonRoot();
121
+ const migratedRoot = await findLibdragonRoot();
122
+
123
+ // Look for old one for backwards compatibility
124
+ const projectRoot =
125
+ migratedRoot ??
126
+ (await findLibdragonRoot(
127
+ '.',
128
+ path.join(LIBDRAGON_PROJECT_MANIFEST, IMAGE_FILE)
129
+ ));
118
130
 
119
131
  if (!projectRoot && !forceReadProjectInfo) {
120
132
  throw new ParameterError(
@@ -146,16 +158,15 @@ async function readProjectInfo(info) {
146
158
 
147
159
  log(`Project root: ${info.root}`, true);
148
160
 
149
- const configFile = path.join(
150
- info.root,
151
- LIBDRAGON_PROJECT_MANIFEST,
152
- CONFIG_FILE
153
- );
154
-
155
- if (await fileExists(configFile)) {
161
+ if (migratedRoot) {
156
162
  info = {
157
163
  ...info,
158
- ...JSON.parse(await fs.readFile(configFile, { encoding: 'utf8' })),
164
+ ...JSON.parse(
165
+ await fs.readFile(
166
+ path.join(info.root, LIBDRAGON_PROJECT_MANIFEST, CONFIG_FILE),
167
+ { encoding: 'utf8' }
168
+ )
169
+ ),
159
170
  };
160
171
  } else {
161
172
  // Cleanup old files and migrate to the new config file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libdragon",
3
- "version": "10.7.0",
3
+ "version": "10.7.1",
4
4
  "description": "This is a docker wrapper for libdragon",
5
5
  "main": "index.js",
6
6
  "engines": {