refactor(jsdoc): remove env.dirname

BREAKING CHANGE: no more `jsdoc/env.dirname`
This commit is contained in:
Jeff Williams 2021-09-27 16:45:46 -07:00
parent d48e0151e2
commit 30a3ae25f7
6 changed files with 11 additions and 29 deletions

View File

@ -42,10 +42,9 @@ module.exports = (() => {
cli.setVersionInfo = () => {
const env = dependencies.get('env');
const packageJsonPath = path.join(require.main.path, 'package.json');
// allow this to throw--something is really wrong if we can't read our own package file
const info = JSON.parse(
stripBom(fs.readFileSync(path.join(env.dirname, 'package.json'), 'utf8'))
);
const info = JSON.parse(stripBom(fs.readFileSync(packageJsonPath, 'utf8')));
const revision = new Date(parseInt(info.revision, 10));
env.version = {

View File

@ -2,11 +2,9 @@
// initialize the environment for Node.js
(() => {
const fs = require('fs');
const path = require('path');
let env;
let jsdocPath = __dirname;
// Create a custom require method that adds `lib/jsdoc` and `node_modules` to the module
// lookup path. This makes it possible to `require('jsdoc/foo')` from external templates and
@ -22,13 +20,7 @@
});
/* eslint-enable no-global-assign, no-redeclare */
// resolve the path if it's a symlink
if (fs.statSync(jsdocPath).isSymbolicLink()) {
jsdocPath = path.resolve(path.dirname(jsdocPath), fs.readlinkSync(jsdocPath));
}
env = require('./lib/jsdoc/env');
env.dirname = jsdocPath;
env.args = process.argv.slice(2);
})();

View File

@ -31,14 +31,6 @@ module.exports = {
*/
conf: {},
/**
* The absolute path to the base directory in which JSDoc is located. Set at startup.
*
* @private
* @type {string}
*/
dirname: null,
/**
* The user's working directory at the time when JSDoc started running.
*

View File

@ -34,9 +34,8 @@ const helpers = {
},
getDocSetFromFile: (filename, parser, shouldValidate, augment) => {
let doclets;
const env = jsdoc.deps.get('env');
const sourceCode = fs.readFileSync(path.join(env.dirname, filename), 'utf8');
const packagePath = path.resolve(__dirname, '../..');
const sourceCode = fs.readFileSync(path.join(packagePath, filename), 'utf8');
const testParser = parser || helpers.createParser();
handlers.attachTo(testParser);

View File

@ -13,7 +13,7 @@ describe('module names', () => {
});
it('should create a name from the file path when no documented module name exists', () => {
const filename = path.resolve(env.dirname, 'test/fixtures/modules/data/mod-1.js');
const filename = path.resolve(__dirname, '../../fixtures/modules/data/mod-1.js');
env.sourceFiles.push(filename);
doclets = srcParser.parse(filename);
@ -44,10 +44,10 @@ describe('module names', () => {
}
it('should use the documented module name if available', () => {
const filename = 'test/fixtures/modules/data/mod-2.js';
const filename = path.resolve(__dirname, '../../fixtures/modules/data/mod-2.js');
env.sourceFiles.push(filename);
doclets = srcParser.parse(path.normalize(path.join(env.dirname, filename)));
doclets = srcParser.parse(filename);
expect(doclets.length).toBeGreaterThan(1);
expect(doclets[0].longname).toBe('module:my/module/name');

View File

@ -21,7 +21,7 @@ describe('@overview tag', () => {
});
it('When a file overview tag appears in a doclet, the name of the doclet should contain the path to the file.', () => {
const filename = path.resolve(env.dirname, 'test/fixtures/file.js');
const filename = path.resolve(__dirname, '../../fixtures/file.js');
env.sourceFiles.push(filename);
doclets = srcParser.parse(filename);
@ -30,10 +30,10 @@ describe('@overview tag', () => {
});
it('The name and longname should be equal', () => {
const filename = 'test/fixtures/file.js';
const filename = path.resolve(__dirname, '../../fixtures/file.js');
env.sourceFiles.push(filename);
doclets = srcParser.parse(path.normalize(path.join(env.dirname, filename)));
doclets = srcParser.parse(filename);
expect(doclets[0].name).toBe(doclets[0].longname);
});
@ -47,7 +47,7 @@ describe('@overview tag', () => {
let doclet;
let docletMeta;
let docletSrc;
let fakePath = path.resolve(path.join(env.dirname, '..', 'somefile.js'));
let fakePath = path.resolve(__dirname, 'somefile.js');
// set up the environment to reflect the fake filepath
env.opts._ = [fakePath];