From 38b03bcb0ed476dea6cebe17df94e87656d37cc6 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 17 Feb 2022 06:19:44 +0100 Subject: [PATCH] Print ids for unfinished moduleParsed and shouldTransformCachedModule hooks --- .eslintrc.js | 3 +- src/utils/hookActions.ts | 6 ++ .../unfulfilled-hook-actions/_config.js | 7 +- .../unfulfilled-hook-actions/buggy-plugin.js | 33 ---------- .../cli/samples/unfulfilled-hook-actions/e.js | 1 + .../samples/unfulfilled-hook-actions/main.js | 1 + .../unfulfilled-hook-actions/rollup.config.js | 65 +++++++++++++++++++ 7 files changed, 79 insertions(+), 37 deletions(-) delete mode 100644 test/cli/samples/unfulfilled-hook-actions/buggy-plugin.js create mode 100644 test/cli/samples/unfulfilled-hook-actions/e.js create mode 100644 test/cli/samples/unfulfilled-hook-actions/rollup.config.js diff --git a/.eslintrc.js b/.eslintrc.js index 4a501ad0045..2517dd75e0e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,7 +19,8 @@ module.exports = { '!/test/*.js', '!/test/*/*.js', '/test/node_modules/*.*', - '!/test/*/samples/**/_config.js' + '!/test/*/samples/**/_config.js', + '!/test/*/samples/**/rollup.config.js' ], overrides: [ { diff --git a/src/utils/hookActions.ts b/src/utils/hookActions.ts index 06282ae2822..06c99ec6373 100644 --- a/src/utils/hookActions.ts +++ b/src/utils/hookActions.ts @@ -23,6 +23,12 @@ function formatAction([pluginName, hookName, args]: [string, string, Parameters< case 'transform': action += ` ${s(args[1])}`; break; + case 'shouldTransformCachedModule': + action += ` ${s((args[0] as { id: string }).id)}`; + break; + case 'moduleParsed': + action += ` ${s((args[0] as { id: string }).id)}`; + break; } return action; } diff --git a/test/cli/samples/unfulfilled-hook-actions/_config.js b/test/cli/samples/unfulfilled-hook-actions/_config.js index 7336c290a29..7aa6f14577b 100644 --- a/test/cli/samples/unfulfilled-hook-actions/_config.js +++ b/test/cli/samples/unfulfilled-hook-actions/_config.js @@ -3,12 +3,12 @@ const { assertIncludes } = require('../../../utils.js'); module.exports = { description: 'show errors with non-zero exit code for unfulfilled async plugin actions on exit', - command: 'rollup main.js -p ./buggy-plugin.js --silent', + command: 'rollup -c --silent', after(err) { // exit code check has to be here as error(err) is only called upon failure assert.strictEqual(err && err.code, 1); }, - error(err) { + error() { // do not abort test upon error return true; }, @@ -19,6 +19,7 @@ module.exports = { assertIncludes(stderr, '(buggy-plugin) resolveId "./c.js" "main.js"'); assertIncludes(stderr, '(buggy-plugin) load "./b.js"'); assertIncludes(stderr, '(buggy-plugin) transform "./a.js"'); - assertIncludes(stderr, '(buggy-plugin) moduleParsed'); + assertIncludes(stderr, '(buggy-plugin) moduleParsed "./d.js"'); + assertIncludes(stderr, '(buggy-plugin) shouldTransformCachedModule "./e.js"'); } }; diff --git a/test/cli/samples/unfulfilled-hook-actions/buggy-plugin.js b/test/cli/samples/unfulfilled-hook-actions/buggy-plugin.js deleted file mode 100644 index 4666e3d1e6e..00000000000 --- a/test/cli/samples/unfulfilled-hook-actions/buggy-plugin.js +++ /dev/null @@ -1,33 +0,0 @@ -var path = require('path'); - -function relative(id) { - if (id[0] != '/') return id; - if (id[0] != '\\') return id; - return './' + path.relative(process.cwd(), id); -} - -module.exports = function() { - return { - name: 'buggy-plugin', - resolveId(id) { - if (id.includes('\0')) return; - - // this action will never resolve or reject - if (id.endsWith('c.js')) return new Promise(() => {}); - - return relative(id); - }, - load(id) { - // this action will never resolve or reject - if (id.endsWith('b.js')) return new Promise(() => {}); - }, - transform(code, id) { - // this action will never resolve or reject - if (id.endsWith('a.js')) return new Promise(() => {}); - }, - moduleParsed(mod) { - // this action will never resolve or reject - if (mod.id.endsWith('d.js')) return new Promise(() => {}); - } - }; -} diff --git a/test/cli/samples/unfulfilled-hook-actions/e.js b/test/cli/samples/unfulfilled-hook-actions/e.js new file mode 100644 index 00000000000..fe97ae732c1 --- /dev/null +++ b/test/cli/samples/unfulfilled-hook-actions/e.js @@ -0,0 +1 @@ +console.log('e'); diff --git a/test/cli/samples/unfulfilled-hook-actions/main.js b/test/cli/samples/unfulfilled-hook-actions/main.js index f0d40cba75c..4240ab41f0c 100644 --- a/test/cli/samples/unfulfilled-hook-actions/main.js +++ b/test/cli/samples/unfulfilled-hook-actions/main.js @@ -2,4 +2,5 @@ import './a.js'; import './b.js'; import './c.js'; import './d.js'; +import './e.js'; console.log('main'); diff --git a/test/cli/samples/unfulfilled-hook-actions/rollup.config.js b/test/cli/samples/unfulfilled-hook-actions/rollup.config.js new file mode 100644 index 00000000000..4ef13e37ca8 --- /dev/null +++ b/test/cli/samples/unfulfilled-hook-actions/rollup.config.js @@ -0,0 +1,65 @@ +const path = require('path'); +const acorn = require('acorn'); + +function relative(id) { + if (id[0] !== '/') return id; + if (id[0] !== '\\') return id; + return './' + path.relative(process.cwd(), id); +} + +const moduleECode = "console.log('e');\n"; + +module.exports = { + input: 'main.js', + cache: { + modules: [ + { + id: './e.js', + ast: acorn.parse(moduleECode, { + ecmaVersion: 6, + sourceType: 'module' + }), + code: moduleECode, + dependencies: [], + customTransformCache: false, + originalCode: moduleECode, + originalSourcemap: null, + resolvedIds: {}, + sourcemapChain: [], + transformDependencies: [] + } + ] + }, + plugins: [ + { + name: 'buggy-plugin', + resolveId(id) { + if (id.includes('\0')) return; + + // this action will never resolve or reject + if (id.endsWith('c.js')) return new Promise(() => {}); + + return relative(id); + }, + load(id) { + // this action will never resolve or reject + if (id.endsWith('b.js')) return new Promise(() => {}); + }, + transform(code, id) { + // this action will never resolve or reject + if (id.endsWith('a.js')) return new Promise(() => {}); + }, + moduleParsed({ id }) { + // this action will never resolve or reject + if (id.endsWith('d.js')) return new Promise(() => {}); + }, + shouldTransformCachedModule({ id }) { + // this action will never resolve or reject + if (id.endsWith('e.js')) return new Promise(() => {}); + } + } + ], + output: { + format: 'es' + } +};