Skip to content

Commit

Permalink
Print ids for unfinished moduleParsed and shouldTransformCachedModule…
Browse files Browse the repository at this point in the history
… hooks
  • Loading branch information
lukastaegert committed Feb 17, 2022
1 parent 5bd96df commit 0675bd3
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 36 deletions.
6 changes: 6 additions & 0 deletions src/utils/hookActions.ts
Expand Up @@ -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;
}
Expand Down
7 changes: 4 additions & 3 deletions test/cli/samples/unfulfilled-hook-actions/_config.js
Expand Up @@ -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;
},
Expand All @@ -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"');
}
};
33 changes: 0 additions & 33 deletions test/cli/samples/unfulfilled-hook-actions/buggy-plugin.js

This file was deleted.

1 change: 1 addition & 0 deletions test/cli/samples/unfulfilled-hook-actions/e.js
@@ -0,0 +1 @@
console.log('e');
1 change: 1 addition & 0 deletions test/cli/samples/unfulfilled-hook-actions/main.js
Expand Up @@ -2,4 +2,5 @@ import './a.js';
import './b.js';
import './c.js';
import './d.js';
import './e.js';
console.log('main');
105 changes: 105 additions & 0 deletions test/cli/samples/unfulfilled-hook-actions/rollup.config.js
@@ -0,0 +1,105 @@
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 = {
input: 'main.js',
cache: {
modules: [
{
id: './e.js',
ast: {
type: 'Program',
start: 0,
end: 18,
body: [
{
type: 'ExpressionStatement',
start: 0,
end: 17,
expression: {
type: 'CallExpression',
start: 0,
end: 16,
callee: {
type: 'MemberExpression',
start: 0,
end: 11,
object: {
type: 'Identifier',
start: 0,
end: 7,
name: 'console'
},
property: {
type: 'Identifier',
start: 8,
end: 11,
name: 'log'
},
computed: false,
optional: false
},
arguments: [
{
type: 'Literal',
start: 12,
end: 15,
value: 'e',
raw: "'e'"
}
],
optional: false
}
}
],
sourceType: 'module'
},
code: "console.log('e');\n",
dependencies: [],
customTransformCache: false,
originalCode: "console.log('e');\n",
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'
}
};

0 comments on commit 0675bd3

Please sign in to comment.