@aravinthan_p/appnest-engine 1.0.20 → 1.0.22

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.
@@ -2,53 +2,46 @@
2
2
 
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
+ const js = require('@eslint/js');
6
+ const globals = require('globals');
5
7
 
6
8
  const SKIP_FOLDERS = ['node_modules', 'dist'];
7
9
  const BACKEND_EXTENSIONS = ['.js'];
8
10
  const FRONTEND_EXTENSIONS = ['.js', '.jsx', '.css'];
9
11
 
10
- const NODE_GLOBALS = {
11
- require: 'readonly',
12
- module: 'readonly',
13
- exports: 'readonly',
14
- __dirname: 'readonly',
15
- __filename: 'readonly',
16
- process: 'readonly',
17
- console: 'readonly',
18
- };
19
-
20
- const BROWSER_GLOBALS = {
21
- ...NODE_GLOBALS,
22
- window: 'readonly',
23
- document: 'readonly',
24
- navigator: 'readonly',
25
- location: 'readonly',
26
- localStorage: 'readonly',
27
- sessionStorage: 'readonly',
28
- fetch: 'readonly',
29
- setTimeout: 'readonly',
30
- setInterval: 'readonly',
31
- clearTimeout: 'readonly',
32
- clearInterval: 'readonly',
33
- requestAnimationFrame: 'readonly',
34
- cancelAnimationFrame: 'readonly',
35
- HTMLElement: 'readonly',
36
- Element: 'readonly',
37
- Event: 'readonly',
38
- CustomEvent: 'readonly',
39
- URL: 'readonly',
40
- URLSearchParams: 'readonly',
41
- FormData: 'readonly',
42
- Blob: 'readonly',
43
- Image: 'readonly',
44
- history: 'readonly',
45
- screen: 'readonly',
46
- alert: 'readonly',
47
- confirm: 'readonly',
48
- prompt: 'readonly',
49
- atob: 'readonly',
50
- btoa: 'readonly',
51
- };
12
+ /**
13
+ * app-backend policy: CommonJS only (`require`, `module.exports`, `exports.*`).
14
+ * Not flagged (and expected): `module.exports.foo = fn` — that is CommonJS, not ESM.
15
+ * Blocked: `import` / `export` / `import()` AST nodes via `no-restricted-syntax`.
16
+ * Also blocked at parse time (`sourceType: 'script'`): top-level `import`/`export`, `import.meta`.
17
+ */
18
+ const BACKEND_COMMONJS_ONLY_FORBID_ESM = [
19
+ {
20
+ selector: 'ImportDeclaration',
21
+ message:
22
+ 'app-backend is CommonJS-only — use require(), not import.',
23
+ },
24
+ {
25
+ selector: 'ExportNamedDeclaration',
26
+ message:
27
+ 'app-backend is CommonJS-only — use module.exports / exports, not export { }.',
28
+ },
29
+ {
30
+ selector: 'ExportDefaultDeclaration',
31
+ message:
32
+ 'app-backend is CommonJS-only — use module.exports, not export default.',
33
+ },
34
+ {
35
+ selector: 'ExportAllDeclaration',
36
+ message:
37
+ 'app-backend is CommonJS-only — use CommonJS re-exports, not export *.',
38
+ },
39
+ {
40
+ selector: 'ImportExpression',
41
+ message:
42
+ 'app-backend is CommonJS-only — use require(), not dynamic import().',
43
+ },
44
+ ];
52
45
 
53
46
  /**
54
47
  * Recursively find files with allowed extensions under dir, skipping certain folders.
@@ -83,44 +76,62 @@ function constructLintMessage(filename, lint) {
83
76
  }
84
77
 
85
78
  /**
86
- * @param {string} filename
87
- * @param {string|null} frontendPath
88
- * @param {string|null} backendPath
79
+ * Flat ESLint config for app-backend: CommonJS only for backend `.js` sources.
80
+ * - Allowed: require(), module.exports, exports, normal JS (async/await, const, etc.).
81
+ * - Rejected: ESM import / export / import() (see BACKEND_COMMONJS_ONLY_FORBID_ESM).
82
+ * @returns {import('eslint').Linter.Config[]}
83
+ */
84
+ const getEslintBackendConfig = () => [
85
+ js.configs.recommended,
86
+ {
87
+ files: ['**/*.js'],
88
+ languageOptions: {
89
+ ecmaVersion: 2022,
90
+ sourceType: 'script',
91
+ parserOptions: { ecmaVersion: 2022 },
92
+ globals: globals.node,
93
+ },
94
+ rules: {
95
+ 'no-restricted-syntax': ['error', ...BACKEND_COMMONJS_ONLY_FORBID_ESM],
96
+ },
97
+ },
98
+ ];
99
+
100
+ /**
101
+ * Flat ESLint config for app-frontend / app-install-frontend (.js, .jsx).
102
+ * @param {string} filename - Used to enable JSX parsing for `.jsx` files.
103
+ * @returns {import('eslint').Linter.Config[]}
89
104
  */
90
- function getEslintConfigForFile(filename, frontendPath, backendPath) {
91
- const resolved = path.resolve(filename);
92
- const isFrontend = frontendPath && resolved.startsWith(path.resolve(frontendPath));
93
- const globals = isFrontend ? BROWSER_GLOBALS : NODE_GLOBALS;
105
+ const getEslintFrontendConfig = (filename) => {
94
106
  const isJsx = path.extname(filename).toLowerCase() === '.jsx';
95
107
  return [
96
108
  {
97
109
  // Explicit files so .jsx is matched (ESLint default only matches **/*.js, **/*.mjs)
98
110
  files: ['**/*.js', '**/*.jsx'],
111
+ ...js.configs.recommended,
99
112
  languageOptions: {
100
113
  ecmaVersion: 2022,
101
114
  sourceType: 'module',
102
115
  parserOptions: {
103
116
  ecmaVersion: 2022,
104
- ecmaFeatures: { jsx: isFrontend && isJsx },
117
+ ecmaFeatures: { jsx: isJsx },
105
118
  },
106
- globals,
119
+ globals: globals.browser,
107
120
  },
108
121
  rules: {
109
122
  'no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
110
- 'no-undef': 'error',
111
123
  'no-implicit-globals': 'error',
112
124
  },
113
125
  },
114
126
  ];
115
- }
127
+ };
116
128
 
117
129
  module.exports = {
118
130
  SKIP_FOLDERS,
119
131
  BACKEND_EXTENSIONS,
120
132
  FRONTEND_EXTENSIONS,
121
- NODE_GLOBALS,
122
- BROWSER_GLOBALS,
123
133
  spider,
124
134
  constructLintMessage,
125
- getEslintConfigForFile,
135
+ getEslintBackendConfig,
136
+ getEslintFrontendConfig,
126
137
  };
@@ -16,7 +16,7 @@ const validate = async ({ projects = {}, fix = false } = {}) => {
16
16
  const userDir = process.cwd();
17
17
  const appBackendPath = path.resolve(userDir, projects['app-backend'] || 'app-backend');
18
18
  const appFrontendPath = path.resolve(userDir, projects['app-frontend'] || 'app-frontend');
19
- const appInstallationFrontendPath = path.resolve(userDir, projects['app-installation-frontend'] || 'app-installation-frontend');
19
+ const appInstallationFrontendPath = path.resolve(userDir, projects['app-install-frontend'] || 'app-install-frontend');
20
20
 
21
21
  console.log('📂 User Directory:', userDir);
22
22
  console.log('📂 App Backend Path:', appBackendPath);
@@ -37,7 +37,7 @@ const validate = async ({ projects = {}, fix = false } = {}) => {
37
37
  }
38
38
  if (fs.existsSync(appInstallationFrontendPath)) {
39
39
  const installationFrontendLints = await lintFrontend(appInstallationFrontendPath, fix);
40
- reportLints({ lints: installationFrontendLints, projectName: 'app-installation-frontend', projectPath: appInstallationFrontendPath });
40
+ reportLints({ lints: installationFrontendLints, projectName: 'app-install-frontend', projectPath: appInstallationFrontendPath });
41
41
  lints.push(...installationFrontendLints);
42
42
  }
43
43
  return lints;
@@ -49,13 +49,13 @@ const validate = async ({ projects = {}, fix = false } = {}) => {
49
49
 
50
50
  const reportLints = ({ lints, projectName, projectPath }) => {
51
51
  if (lints.length === 0 && !fs.existsSync(projectPath)) {
52
- console.log(`📋 No ${projectName} project folder found to lint.`);
52
+ console.log(`📦 ${projectName} project folder not found to lint.`);
53
53
  return [];
54
54
  }
55
55
 
56
56
  const errors = lints.filter((l) => l.severity === 2);
57
57
  const warnings = lints.filter((l) => l.severity === 1);
58
- console.log(`👉 ${projectName} project folder lint report begins.`);
58
+ console.log(`🏁 Lint report begins for ${projectName} project folder.`);
59
59
  if (errors.length) {
60
60
  console.log(`\n❌ Lint errors (${errors.length}):`);
61
61
  errors.forEach((l) => console.log(' ', l.value));
@@ -67,7 +67,7 @@ const reportLints = ({ lints, projectName, projectPath }) => {
67
67
  if (errors.length === 0 && warnings.length === 0) {
68
68
  console.log(lints.length > 0 ? '✅ Lint passed with no issues.' : '📋 No lintable files found.');
69
69
  }
70
- console.log(`👉 ${projectName} project folder lint report ends. 👍`);
70
+ console.log(`🏁 Lint report ends for ${projectName} project folder.`);
71
71
  }
72
72
 
73
73
  module.exports = {