Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide source file path for tasks in gulp --tasks-json output #74

Open
phated opened this issue Apr 5, 2016 · 1 comment
Open

Provide source file path for tasks in gulp --tasks-json output #74

phated opened this issue Apr 5, 2016 · 1 comment

Comments

@phated
Copy link
Member

phated commented Apr 5, 2016

Moved from gulpjs/gulp#1180

@sttk
Copy link
Contributor

sttk commented Feb 11, 2023

Tasks registered with gulp.task are possible by using Error.captureStackTrace as written in the original issue.

And tasks defined as functions are also possible with the following code if those source codes are loaded with require:
And tasks defined as functions in source files loaded with require are also possible with the following code.
(If no source file of a task function is found with the following code, the function is registered with gulp.task/series/parallel in the same source file.)

$ pwd
/path/to/sample
$ cat main.js
const { a, b } = require('./a');
const path = require('node:path');
const configPath = path.resolve('./a.js');
const mod0 = require.cache[configPath];
console.log('a:', findSrcPath(a, mod0));
console.log('b:', findSrcPath(b, mod0));
function findSrcPath(fn, mod) {
  if (Object.values(mod.exports).includes(fn)) {
    for (const child of mod.children) {
      const id = findSrcPath(fn, child);
      if (id) return id;
    }
    return mod.id;
  }
}
$ cat a.js
const { b } = require('./b');                                                                                                          
exports.a = function() {};
exports.b = b;
$ cat b.js
function b() {}                                                                                                                        
module.exports = { b };
$ node main.js
a: /path/to/sample/a.js
b: /path/to/sample/b.js

However, I can't come up with any idea about tasks defined as functions in source files loaded with import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

2 participants