From a9eed8b6fae2ef5677a3fc6fc6057e12acea6d5b Mon Sep 17 00:00:00 2001 From: macbre Date: Tue, 14 Jun 2022 14:21:12 +0100 Subject: [PATCH 1/2] analyzeCss.js: lazy load analyze-css module via await import() Prepare for analyze-css to be a pure EMS package - https://github.com/macbre/analyze-css/issues/616 --- modules/analyzeCss/analyzeCss.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/analyzeCss/analyzeCss.js b/modules/analyzeCss/analyzeCss.js index 3a4102c8d..71aa03827 100644 --- a/modules/analyzeCss/analyzeCss.js +++ b/modules/analyzeCss/analyzeCss.js @@ -49,11 +49,6 @@ module.exports = function (phantomas) { return; } - // load analyze-css module - // https://www.npmjs.com/package/analyze-css - const analyzer = require("analyze-css"); - phantomas.log("Using version %s", analyzer.version); - phantomas.setMetric("cssParsingErrors"); // @desc number of CSS files (or embeded CSS) that failed to be parse by analyze-css @optional phantomas.setMetric("cssInlineStyles"); // @desc number of inline styles @optional @@ -92,6 +87,11 @@ module.exports = function (phantomas) { } **/ + // load analyze-css module + // https://www.npmjs.com/package/analyze-css + const analyzer = (await import("analyze-css")).default; + phantomas.log("Using version %s", analyzer.version); + // https://www.npmjs.com/package/analyze-css#commonjs-module var options = {}; let results; From d8174d035e3984a73e2277d01db52c41c5d6afce Mon Sep 17 00:00:00 2001 From: macbre Date: Tue, 14 Jun 2022 14:26:25 +0100 Subject: [PATCH 2/2] eslint: allow dynamicImport syntax Solves: phantomas/modules/analyzeCss/analyzeCss.js 92:29 error 'import()' expressions are not supported yet node/no-unsupported-features/es-syntax --- .eslintrc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 95226d33b..ac50b132a 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -17,4 +17,4 @@ rules: - allowEmptyCatch: true no-prototype-builtins: 'off' "node/no-extraneous-require": 'off' - "node/no-unsupported-features/es-syntax": 'error' + "node/no-unsupported-features/es-syntax": ['error', {'ignores': ['dynamicImport']}]