mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
JSDoc has a few requirements that are somewhat unusual for a Node.js app:
1. We need `require('jsdoc/foo')` to work from any module.
2. We need `require('jsdoc/foo')` to work from external code, such as templates and plugins.
Prior to this commit, JSDoc did two separate things to meet these requirements:
1. Use an npm post-install script to create a symlink from `lib/jsdoc` to `node_modules/jsdoc`.
2. When a user runs JSDoc, copy templates and plugins into the JSDoc directory.
These fixes worked, sort of. But they also caused numerous issues with file permissions, especially on Windows.
We now use the Requizzle module, which hacks the Node.js module system to support JSDoc's use cases. There's no longer a post-install script, and there's no need for a symlink in `node_modules`.
30 lines
850 B
JavaScript
30 lines
850 B
JavaScript
/*
|
|
Copyright (c) 2014 Google Inc. All rights reserved.
|
|
|
|
Use of this source code is governed by the MIT License, available in this package's LICENSE file
|
|
or at http://opensource.org/licenses/MIT.
|
|
*/
|
|
'use strict';
|
|
|
|
var _ = require('underscore');
|
|
var Requizzle = require('./lib/requizzle');
|
|
|
|
module.exports = function requizzle(options) {
|
|
var instance;
|
|
|
|
if (!options || typeof options !== 'object') {
|
|
throw new TypeError('Requizzle\'s options parameter must be a non-null object.');
|
|
}
|
|
options = _.clone(options);
|
|
options.parent = module.parent;
|
|
|
|
return function(filepath) {
|
|
instance = instance || new Requizzle(options);
|
|
return instance.requizzle(filepath);
|
|
};
|
|
};
|
|
module.exports.Requizzle = Requizzle;
|
|
|
|
// force Node.js to reload this module each time it's required, so module.parent is always correct
|
|
delete require.cache[__filename];
|