binhend 2.1.24 → 2.1.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "binhend",
3
- "version": "2.1.24",
3
+ "version": "2.1.25",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
@@ -1,11 +1,12 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
- const { isEmptyArray, isArray, isObject } = require('./utils/types');
3
+ const { isEmptyArray, isArray, isObject, mustString } = require('./utils/types');
4
4
 
5
5
  // @ts-ignore
6
- function ConfigLoader(configObject, { module } = {}) {
6
+ function ConfigLoader(configObject, { rootPath } = {}) {
7
7
  const configs = configObject || {};
8
- const rootPath = module?.path || require.main.path;
8
+
9
+ rootPath = mustString(rootPath) || require.main.path;
9
10
 
10
11
  this.getConfigs = () => {
11
12
  return configs;
@@ -22,8 +23,8 @@ function ConfigLoader(configObject, { module } = {}) {
22
23
  var filtered = isArray(filters) ? filter(object, filters) : object;
23
24
  Object.assign(config, filtered);
24
25
  }
25
- catch(e) {
26
- return failed(e, object);
26
+ catch (error) {
27
+ return failed(error, object);
27
28
  }
28
29
 
29
30
  return this;
@@ -46,7 +47,7 @@ function ConfigLoader(configObject, { module } = {}) {
46
47
 
47
48
  function filter(object, filterKeys) {
48
49
  if (!isObject(object) || isEmptyArray(filterKeys)) return {};
49
-
50
+
50
51
  var filtered = {};
51
52
 
52
53
  filterKeys.forEach((field) => {
@@ -62,7 +63,7 @@ function json(path) {
62
63
  try {
63
64
  return require.main.require(path);
64
65
  }
65
- catch(e) {
66
+ catch (e) {
66
67
  return failed(e, path);
67
68
  }
68
69
  }
@@ -82,7 +83,7 @@ function file(path, encoding) {
82
83
 
83
84
  return processKeyValueStrings(lines);
84
85
  }
85
- catch(e) {
86
+ catch (e) {
86
87
  return failed(e, path);
87
88
  }
88
89
  }
@@ -96,7 +97,7 @@ function processKeyValueStrings(strings) {
96
97
 
97
98
  var regex_is_comment = /^#/;
98
99
 
99
- strings.forEach(function(string) {
100
+ strings.forEach(function (string) {
100
101
  if (regex_is_comment.test(string.trim())) return;
101
102
 
102
103
  var parsed = parseKeyValue(string);
@@ -53,7 +53,8 @@ module.exports = (options) => {
53
53
 
54
54
  // Handle preflight OPTIONS request
55
55
  if (req.method === 'OPTIONS' && !preflightContinue) {
56
- return res.sendStatus(mustNumber(optionsSuccessStatus, 204));
56
+ var statusCode = mustNumber(optionsSuccessStatus) || 204; // 204 - No Content
57
+ return res.sendStatus(statusCode);
57
58
  }
58
59
 
59
60
  return next();
@@ -30,16 +30,22 @@ function generate(sourceRootPath, outputRootPath, callbackDone) {
30
30
  writeToFileIfNew(fileOutputPath + '.js', cssModuleCode);
31
31
  // not return here, but wait for next "if" statement to be copied to build folder, then return there.
32
32
  }
33
-
34
- if (fileExtension !== '.js' && fileExtension !== '.mjs') {
33
+
34
+ if (fileExtension !== '.js' && fileExtension !== '.cjs' && fileExtension !== '.mjs') {
35
35
  // any files not JS (.css, .jpg, etc.) will be copied to build folder.
36
- return cloneFileIfNew(fileSourcePath, fileOutputPath);
36
+ cloneFileIfNew(fileSourcePath, fileOutputPath);
37
+ return;
37
38
  }
38
39
 
39
- var content = readFileSync(fileSourcePath, { encoding: 'utf8', flag: 'r' });
40
- var code = PREFIX_CODE + mapConfigValues(content.trim()) + '\r\n\r\n;binh.final(module);';
40
+ var fileContent = readFileSync(fileSourcePath, { encoding: 'utf8', flag: 'r' });
41
+ var formatCode = mapConfigValues(fileContent.trim()); // for .cjs (common js) and .mjs (module js) files, not build code but still bind config values
42
+
43
+ if (fileExtension === '.js') {
44
+ // for .js files, build code and bind config values
45
+ formatCode = PREFIX_CODE + formatCode + '\r\n\r\n;binh.final(module);';
46
+ }
41
47
 
42
- writeToFileIfNew(fileOutputPath, code);
48
+ writeToFileIfNew(fileOutputPath, formatCode);
43
49
  }
44
50
  catch (error) {
45
51
  printError('Failed formatting file:', fileSourcePath, error);