resume-cli 3.6.0 → 3.6.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.
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _chalk = _interopRequireDefault(require("chalk"));
8
+ var _getResume = _interopRequireDefault(require("./get-resume"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ // Load the resume from the given path, turning the low-level failures
11
+ // (missing file, unreadable stream, malformed JSON/YAML) into a single
12
+ // friendly, stack-trace-free message. Returns null on failure after printing
13
+ // the message and flagging a non-zero exit code, so callers can bail early
14
+ // instead of leaking an unhandled rejection / Node-internal stack trace.
15
+ const loadResumeOrReport = async resumePath => {
16
+ try {
17
+ return await (0, _getResume.default)({
18
+ path: resumePath
19
+ });
20
+ } catch (err) {
21
+ const label = resumePath === '-' ? 'stdin' : resumePath;
22
+ console.error(_chalk.default.red(`Could not read resume: ${label}`));
23
+ console.error(err && err.message ? err.message : String(err));
24
+ process.exitCode = 1;
25
+ return null;
26
+ }
27
+ };
28
+ var _default = exports.default = loadResumeOrReport;
package/build/main.js CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  require("dotenv/config");
5
5
  var _init = _interopRequireDefault(require("./init"));
6
- var _getResume = _interopRequireDefault(require("./get-resume"));
6
+ var _loadResume = _interopRequireDefault(require("./load-resume"));
7
7
  var _getSchema = _interopRequireDefault(require("./get-schema"));
8
8
  var _validate = _interopRequireDefault(require("./validate"));
9
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -55,12 +55,21 @@ const normalizeTheme = (value, defaultValue) => {
55
55
  });
56
56
  });
57
57
  program.command('validate').description("Validate your resume's schema").action(async () => {
58
- const resume = await (0, _getResume.default)({
59
- path: program.resume
60
- });
61
- const schema = await (0, _getSchema.default)({
62
- path: program.schema
63
- });
58
+ const resume = await (0, _loadResume.default)(program.resume);
59
+ if (resume === null) {
60
+ return;
61
+ }
62
+ let schema;
63
+ try {
64
+ schema = await (0, _getSchema.default)({
65
+ path: program.schema
66
+ });
67
+ } catch (e) {
68
+ console.error(chalk.red('Could not load schema.'));
69
+ console.error(e.message || String(e));
70
+ process.exitCode = 1;
71
+ return;
72
+ }
64
73
  try {
65
74
  await (0, _validate.default)({
66
75
  resume,
@@ -73,9 +82,10 @@ const normalizeTheme = (value, defaultValue) => {
73
82
  }
74
83
  });
75
84
  program.command('export [fileName]').description('Export locally to .html, .pdf, .md (markdown) or .txt (text). Supply a --format <file format> flag and argument to specify export format. .md and .txt need no theme; pick a theme for .html/.pdf with --theme (https://jsonresume.org/themes/).').action(async fileName => {
76
- const resume = await (0, _getResume.default)({
77
- path: program.resume
78
- });
85
+ const resume = await (0, _loadResume.default)(program.resume);
86
+ if (resume === null) {
87
+ return;
88
+ }
79
89
  exportResume({
80
90
  ...program,
81
91
  resume,
@@ -142,6 +142,33 @@ describe('cli configuration', () => {
142
142
  "
143
143
  `);
144
144
  });
145
+ it('should print a friendly error and exit non-zero when the resume file is missing', async () => {
146
+ const {
147
+ code,
148
+ stderr
149
+ } = await run(['validate', '--resume', '/test-resumes/does-not-exist.json'], {
150
+ waitForVolumeExport: false,
151
+ captureStderr: true
152
+ });
153
+ expect(code).toEqual(1);
154
+ expect(stderr).toContain('Could not read resume: /test-resumes/does-not-exist.json');
155
+ // No raw Node unhandled-rejection stack trace must leak.
156
+ expect(stderr).not.toContain('triggerUncaughtException');
157
+ expect(stderr).not.toContain('node:internal');
158
+ });
159
+ it('should print a friendly error and exit non-zero when the resume JSON is malformed', async () => {
160
+ const {
161
+ code,
162
+ stderr
163
+ } = await run(['validate', '--resume', '/test-resumes/malformed-resume.json'], {
164
+ waitForVolumeExport: false,
165
+ captureStderr: true
166
+ });
167
+ expect(code).toEqual(1);
168
+ expect(stderr).toContain('Could not read resume: /test-resumes/malformed-resume.json');
169
+ expect(stderr).not.toContain('triggerUncaughtException');
170
+ expect(stderr).not.toContain('node:internal');
171
+ });
145
172
  });
146
173
  describe('themes', () => {
147
174
  it('lists installed themes by slug and links the gallery', async () => {
@@ -249,5 +276,19 @@ describe('cli configuration', () => {
249
276
  // The raw stack trace must not leak to the user.
250
277
  expect(stderr).not.toContain('at _default');
251
278
  });
279
+ it('should print a friendly error and exit non-zero when the resume file is missing', async () => {
280
+ const {
281
+ code,
282
+ stderr
283
+ } = await run(['export', '/test-resumes/exported-resume.html', '--resume', '/test-resumes/does-not-exist.json', '--theme', 'even'], {
284
+ waitForVolumeExport: false,
285
+ captureStderr: true
286
+ });
287
+ expect(code).toEqual(1);
288
+ expect(stderr).toContain('Could not read resume: /test-resumes/does-not-exist.json');
289
+ // No raw Node unhandled-rejection stack trace must leak.
290
+ expect(stderr).not.toContain('triggerUncaughtException');
291
+ expect(stderr).not.toContain('node:internal');
292
+ });
252
293
  });
253
294
  });
@@ -19,6 +19,8 @@ module.exports = ({
19
19
  name: 123
20
20
  }
21
21
  }),
22
+ // Syntactically broken JSON — exercises the parse-error path.
23
+ 'malformed-resume.json': '{ "basics": { "name": "x" ',
22
24
  'resume.json': JSON.stringify({
23
25
  basics: {
24
26
  name: 'thomas',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resume-cli",
3
- "version": "3.6.0",
3
+ "version": "3.6.1",
4
4
  "description": "The JSON Resume command line interface",
5
5
  "main": "build/main.js",
6
6
  "engines": {