@knighted/duel 1.0.5 → 1.0.6

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/cjs/duel.cjs CHANGED
@@ -26,17 +26,25 @@ const runBuild = (project, outDir) => {
26
26
  build.on('error', err => {
27
27
  reject(new Error(`Failed to compile: ${err.message}`));
28
28
  });
29
- build.on('close', code => {
30
- if (code === null) {
31
- return reject(new Error('Failed to compile.'));
32
- }
29
+ build.on('exit', code => {
33
30
  if (code > 0) {
34
- return reject(new Error('Compilation errors found.'));
31
+ return reject(new Error(code));
35
32
  }
36
33
  resolve(code);
37
34
  });
38
35
  });
39
36
  };
37
+ const handleErrorAndExit = message => {
38
+ const exitCode = Number(message);
39
+ if (isNaN(exitCode)) {
40
+ (0, util_js_1.logError)(message);
41
+ process.exit(1);
42
+ }
43
+ else {
44
+ (0, util_js_1.logError)('Compilation errors found.');
45
+ process.exit(exitCode);
46
+ }
47
+ };
40
48
  const duel = async (args) => {
41
49
  const ctx = await (0, init_js_1.init)(args);
42
50
  if (ctx) {
@@ -141,7 +149,7 @@ const duel = async (args) => {
141
149
  success = true;
142
150
  }
143
151
  catch ({ message }) {
144
- (0, util_js_1.logError)(message);
152
+ handleErrorAndExit(message);
145
153
  }
146
154
  if (success) {
147
155
  const filenames = await (0, glob_1.glob)(`${absoluteDualOutDir}/**/*{.js,.d.ts}`, {
@@ -165,13 +173,14 @@ const duel = async (args) => {
165
173
  success = true;
166
174
  }
167
175
  catch ({ message }) {
168
- (0, util_js_1.logError)(message);
176
+ handleErrorAndExit(message);
169
177
  }
170
178
  if (success) {
171
179
  const dualConfigPath = (0, node_path_1.join)(projectDir, `tsconfig.${hex}.json`);
172
180
  const absoluteDualOutDir = (0, node_path_1.join)(projectDir, isCjsBuild ? (0, node_path_1.join)(outDir, 'cjs') : (0, node_path_1.join)(outDir, 'esm'));
173
181
  const tsconfigDual = getOverrideTsConfig();
174
182
  const pkgRename = 'package.json.bak';
183
+ let errorMsg = '';
175
184
  /**
176
185
  * Create a new package.json with updated `type` field.
177
186
  * Create a new tsconfig.json.
@@ -191,12 +200,17 @@ const duel = async (args) => {
191
200
  }
192
201
  catch ({ message }) {
193
202
  success = false;
194
- (0, util_js_1.logError)(message);
203
+ errorMsg = message;
204
+ }
205
+ finally {
206
+ // Cleanup and restore
207
+ await (0, promises_1.rm)(dualConfigPath, { force: true });
208
+ await (0, promises_1.rm)(pkg.path, { force: true });
209
+ await (0, promises_1.rename)((0, node_path_1.join)(pkgDir, pkgRename), pkg.path);
210
+ if (errorMsg) {
211
+ handleErrorAndExit(errorMsg);
212
+ }
195
213
  }
196
- // Cleanup and restore
197
- await (0, promises_1.rm)(dualConfigPath, { force: true });
198
- await (0, promises_1.rm)(pkg.path, { force: true });
199
- await (0, promises_1.rename)((0, node_path_1.join)(pkgDir, pkgRename), pkg.path);
200
214
  if (success) {
201
215
  const filenames = await (0, glob_1.glob)(`${absoluteDualOutDir}/**/*{.js,.d.ts}`, {
202
216
  ignore: 'node_modules/**',
package/dist/esm/duel.js CHANGED
@@ -23,17 +23,25 @@ const runBuild = (project, outDir) => {
23
23
  build.on('error', err => {
24
24
  reject(new Error(`Failed to compile: ${err.message}`));
25
25
  });
26
- build.on('close', code => {
27
- if (code === null) {
28
- return reject(new Error('Failed to compile.'));
29
- }
26
+ build.on('exit', code => {
30
27
  if (code > 0) {
31
- return reject(new Error('Compilation errors found.'));
28
+ return reject(new Error(code));
32
29
  }
33
30
  resolve(code);
34
31
  });
35
32
  });
36
33
  };
34
+ const handleErrorAndExit = message => {
35
+ const exitCode = Number(message);
36
+ if (isNaN(exitCode)) {
37
+ logError(message);
38
+ process.exit(1);
39
+ }
40
+ else {
41
+ logError('Compilation errors found.');
42
+ process.exit(exitCode);
43
+ }
44
+ };
37
45
  const duel = async (args) => {
38
46
  const ctx = await init(args);
39
47
  if (ctx) {
@@ -138,7 +146,7 @@ const duel = async (args) => {
138
146
  success = true;
139
147
  }
140
148
  catch ({ message }) {
141
- logError(message);
149
+ handleErrorAndExit(message);
142
150
  }
143
151
  if (success) {
144
152
  const filenames = await glob(`${absoluteDualOutDir}/**/*{.js,.d.ts}`, {
@@ -162,13 +170,14 @@ const duel = async (args) => {
162
170
  success = true;
163
171
  }
164
172
  catch ({ message }) {
165
- logError(message);
173
+ handleErrorAndExit(message);
166
174
  }
167
175
  if (success) {
168
176
  const dualConfigPath = join(projectDir, `tsconfig.${hex}.json`);
169
177
  const absoluteDualOutDir = join(projectDir, isCjsBuild ? join(outDir, 'cjs') : join(outDir, 'esm'));
170
178
  const tsconfigDual = getOverrideTsConfig();
171
179
  const pkgRename = 'package.json.bak';
180
+ let errorMsg = '';
172
181
  /**
173
182
  * Create a new package.json with updated `type` field.
174
183
  * Create a new tsconfig.json.
@@ -188,12 +197,17 @@ const duel = async (args) => {
188
197
  }
189
198
  catch ({ message }) {
190
199
  success = false;
191
- logError(message);
200
+ errorMsg = message;
201
+ }
202
+ finally {
203
+ // Cleanup and restore
204
+ await rm(dualConfigPath, { force: true });
205
+ await rm(pkg.path, { force: true });
206
+ await rename(join(pkgDir, pkgRename), pkg.path);
207
+ if (errorMsg) {
208
+ handleErrorAndExit(errorMsg);
209
+ }
192
210
  }
193
- // Cleanup and restore
194
- await rm(dualConfigPath, { force: true });
195
- await rm(pkg.path, { force: true });
196
- await rename(join(pkgDir, pkgRename), pkg.path);
197
211
  if (success) {
198
212
  const filenames = await glob(`${absoluteDualOutDir}/**/*{.js,.d.ts}`, {
199
213
  ignore: 'node_modules/**',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knighted/duel",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "TypeScript dual packages.",
5
5
  "type": "module",
6
6
  "main": "dist",