After bumping esbuild-plugin-eslint from v0.3.3 to v0.3.8 in order to use the new release from #11, I encountered the problem of importing ESM in a CJS environment (which appears to have been introduced in v0.3.4). Since this is for use with the Serverless Framework (using serverless-esbuild), I can't just move to ESM, unfortunately.
To work around this, I added https://github.com/nktnet1/import-sync in order to import this plugin. This worked great, as I got back to the error of "no eslint configuration found" from v0.3.3. However, once I bumped eslint to the v9 beta, I got the following error
The above error, but in a code block
```
ā [ERROR] A dynamic import callback was not specified. [plugin eslint]
/home/james/projects/LabelLogicLive_Monorepo/packages/api/node_modules/eslint/lib/eslint/eslint.js:315:19:
315 ā const config = (await import(fileURL)).default;
āµ ^
at new NodeError (node:internal/errors:393:5)
at importModuleDynamicallyCallback (node:internal/process/esm_loader:39:9)
at loadFlatConfigFile (/home/james/projects/LabelLogicLive_Monorepo/packages/api/node_modules/eslint/lib/eslint/eslint.js:315:20)
at async calculateConfigArray (/home/james/projects/LabelLogicLive_Monorepo/packages/api/node_modules/eslint/lib/eslint/eslint.js:394:28)
at async ESLint.lintFiles (/home/james/projects/LabelLogicLive_Monorepo/packages/api/node_modules/eslint/lib/eslint/eslint.js:803:25)
at async /home/james/projects/LabelLogicLive_Monorepo/packages/api/node_modules/esbuild-plugin-eslint/dist/index.js:15:29
at async /home/james/projects/LabelLogicLive_Monorepo/packages/api/node_modules/esbuild/lib/main.js:1481:27
This error came from the "onEnd" callback registered here:
/home/james/projects/LabelLogicLive_Monorepo/packages/api/node_modules/esbuild-plugin-eslint/dist/index.js:14:8:
14 ā onEnd(async () => {
āµ ~~~~~
```
This makes me wonder whether the problem is with the importing of ESM in a CJS environment, since my workaround I had while waiting on your fix for #11 was working perfectly fine without the need for any hacks. I also tried it with v9 of eslint, and it still worked perfectly fine. The problem is somewhere between importing esbuild-plugin-eslint, and the loading of eslint itself.
For reference, this is the plugin workaround code
```js
const eslintPlugin = ({ filter }) => ({
name: "eslint",
setup: ({ onLoad, onEnd }) => {
loadESLint().then(eslintClass => {
/** @type {import("esbuild").OnLoadArgs["path"][]} */
const filesToLint = [];
const eslint = new eslintClass();
onLoad({ filter }, ({ path }) => {
if (!path.includes("node_modules")) filesToLint.push(path);
return null;
});
onEnd(async () => {
const results = await eslint.lintFiles(filesToLint);
const formatter = await eslint.loadFormatter("stylish");
const output = await formatter.format(results);
if (output.length > 0) console.log(output);
const warnings = results.reduce(
(count, result) => count + result.warningCount,
0
);
const errors = results.reduce(
(count, result) => count + result.errorCount,
0
);
const ret = { errors: [] };
if (warnings > 0) {
ret.errors.push({
text: `${warnings} warnings were found by eslint!`
});
}
if (errors > 0) {
ret.errors.push(
{ text: `${errors} errors were found by eslint!` }
);
}
return ret;
});
});
}
});
```
Would it be possible to get a release of esbuild-plugin-eslint with a cjs build alongside the esm build?
After bumping esbuild-plugin-eslint from v0.3.3 to v0.3.8 in order to use the new release from #11, I encountered the problem of importing ESM in a CJS environment (which appears to have been introduced in v0.3.4). Since this is for use with the Serverless Framework (using
serverless-esbuild
), I can't just move to ESM, unfortunately.To work around this, I added https://github.com/nktnet1/import-sync in order to import this plugin. This worked great, as I got back to the error of "no eslint configuration found" from v0.3.3. However, once I bumped eslint to the v9 beta, I got the following error
The above error, but in a code block
``` ā [ERROR] A dynamic import callback was not specified. [plugin eslint] /home/james/projects/LabelLogicLive_Monorepo/packages/api/node_modules/eslint/lib/eslint/eslint.js:315:19: 315 ā const config = (await import(fileURL)).default; āµ ^ at new NodeError (node:internal/errors:393:5) at importModuleDynamicallyCallback (node:internal/process/esm_loader:39:9) at loadFlatConfigFile (/home/james/projects/LabelLogicLive_Monorepo/packages/api/node_modules/eslint/lib/eslint/eslint.js:315:20) at async calculateConfigArray (/home/james/projects/LabelLogicLive_Monorepo/packages/api/node_modules/eslint/lib/eslint/eslint.js:394:28) at async ESLint.lintFiles (/home/james/projects/LabelLogicLive_Monorepo/packages/api/node_modules/eslint/lib/eslint/eslint.js:803:25) at async /home/james/projects/LabelLogicLive_Monorepo/packages/api/node_modules/esbuild-plugin-eslint/dist/index.js:15:29 at async /home/james/projects/LabelLogicLive_Monorepo/packages/api/node_modules/esbuild/lib/main.js:1481:27 This error came from the "onEnd" callback registered here: /home/james/projects/LabelLogicLive_Monorepo/packages/api/node_modules/esbuild-plugin-eslint/dist/index.js:14:8: 14 ā onEnd(async () => { āµ ~~~~~ ```This makes me wonder whether the problem is with the importing of ESM in a CJS environment, since my workaround I had while waiting on your fix for #11 was working perfectly fine without the need for any hacks. I also tried it with v9 of eslint, and it still worked perfectly fine. The problem is somewhere between importing
esbuild-plugin-eslint
, and the loading ofeslint
itself.For reference, this is the plugin workaround code
```js const eslintPlugin = ({ filter }) => ({ name: "eslint", setup: ({ onLoad, onEnd }) => { loadESLint().then(eslintClass => { /** @type {import("esbuild").OnLoadArgs["path"][]} */ const filesToLint = []; const eslint = new eslintClass(); onLoad({ filter }, ({ path }) => { if (!path.includes("node_modules")) filesToLint.push(path); return null; }); onEnd(async () => { const results = await eslint.lintFiles(filesToLint); const formatter = await eslint.loadFormatter("stylish"); const output = await formatter.format(results); if (output.length > 0) console.log(output); const warnings = results.reduce( (count, result) => count + result.warningCount, 0 ); const errors = results.reduce( (count, result) => count + result.errorCount, 0 ); const ret = { errors: [] }; if (warnings > 0) { ret.errors.push({ text: `${warnings} warnings were found by eslint!` }); } if (errors > 0) { ret.errors.push( { text: `${errors} errors were found by eslint!` } ); } return ret; }); }); } }); ```Would it be possible to get a release of esbuild-plugin-eslint with a cjs build alongside the esm build?
For example, the dist folder would look like
and the package.json would include the following