mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
refactor(jsdoc): remove env.dirname
BREAKING CHANGE: no more `jsdoc/env.dirname`
This commit is contained in:
parent
d48e0151e2
commit
30a3ae25f7
@ -42,10 +42,9 @@ module.exports = (() => {
|
|||||||
cli.setVersionInfo = () => {
|
cli.setVersionInfo = () => {
|
||||||
const env = dependencies.get('env');
|
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
|
// allow this to throw--something is really wrong if we can't read our own package file
|
||||||
const info = JSON.parse(
|
const info = JSON.parse(stripBom(fs.readFileSync(packageJsonPath, 'utf8')));
|
||||||
stripBom(fs.readFileSync(path.join(env.dirname, 'package.json'), 'utf8'))
|
|
||||||
);
|
|
||||||
const revision = new Date(parseInt(info.revision, 10));
|
const revision = new Date(parseInt(info.revision, 10));
|
||||||
|
|
||||||
env.version = {
|
env.version = {
|
||||||
|
|||||||
@ -2,11 +2,9 @@
|
|||||||
|
|
||||||
// initialize the environment for Node.js
|
// initialize the environment for Node.js
|
||||||
(() => {
|
(() => {
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
let env;
|
let env;
|
||||||
let jsdocPath = __dirname;
|
|
||||||
|
|
||||||
// Create a custom require method that adds `lib/jsdoc` and `node_modules` to the module
|
// 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
|
// 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 */
|
/* 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 = require('./lib/jsdoc/env');
|
||||||
env.dirname = jsdocPath;
|
|
||||||
env.args = process.argv.slice(2);
|
env.args = process.argv.slice(2);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|||||||
@ -31,14 +31,6 @@ module.exports = {
|
|||||||
*/
|
*/
|
||||||
conf: {},
|
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.
|
* The user's working directory at the time when JSDoc started running.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -34,9 +34,8 @@ const helpers = {
|
|||||||
},
|
},
|
||||||
getDocSetFromFile: (filename, parser, shouldValidate, augment) => {
|
getDocSetFromFile: (filename, parser, shouldValidate, augment) => {
|
||||||
let doclets;
|
let doclets;
|
||||||
const env = jsdoc.deps.get('env');
|
const packagePath = path.resolve(__dirname, '../..');
|
||||||
|
const sourceCode = fs.readFileSync(path.join(packagePath, filename), 'utf8');
|
||||||
const sourceCode = fs.readFileSync(path.join(env.dirname, filename), 'utf8');
|
|
||||||
const testParser = parser || helpers.createParser();
|
const testParser = parser || helpers.createParser();
|
||||||
|
|
||||||
handlers.attachTo(testParser);
|
handlers.attachTo(testParser);
|
||||||
|
|||||||
@ -13,7 +13,7 @@ describe('module names', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should create a name from the file path when no documented module name exists', () => {
|
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);
|
env.sourceFiles.push(filename);
|
||||||
doclets = srcParser.parse(filename);
|
doclets = srcParser.parse(filename);
|
||||||
@ -44,10 +44,10 @@ describe('module names', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it('should use the documented module name if available', () => {
|
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);
|
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.length).toBeGreaterThan(1);
|
||||||
expect(doclets[0].longname).toBe('module:my/module/name');
|
expect(doclets[0].longname).toBe('module:my/module/name');
|
||||||
|
|||||||
@ -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.', () => {
|
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);
|
env.sourceFiles.push(filename);
|
||||||
doclets = srcParser.parse(filename);
|
doclets = srcParser.parse(filename);
|
||||||
@ -30,10 +30,10 @@ describe('@overview tag', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('The name and longname should be equal', () => {
|
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);
|
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);
|
expect(doclets[0].name).toBe(doclets[0].longname);
|
||||||
});
|
});
|
||||||
@ -47,7 +47,7 @@ describe('@overview tag', () => {
|
|||||||
let doclet;
|
let doclet;
|
||||||
let docletMeta;
|
let docletMeta;
|
||||||
let docletSrc;
|
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
|
// set up the environment to reflect the fake filepath
|
||||||
env.opts._ = [fakePath];
|
env.opts._ = [fakePath];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user