From a097e2f2997cc6e8b86a10a60efce7f752c629e4 Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Wed, 5 Jul 2017 22:56:29 -0700 Subject: [PATCH] get rid of jsdoc/util/runtime (#1383); delint --- jsdoc.js | 51 +++++++++++-------- lib/jsdoc/util/runtime.js | 87 -------------------------------- package.json | 2 +- test/spec-collection.js | 43 ++++++++-------- test/specs/jsdoc/util/runtime.js | 29 ----------- 5 files changed, 50 insertions(+), 162 deletions(-) delete mode 100644 lib/jsdoc/util/runtime.js delete mode 100644 test/specs/jsdoc/util/runtime.js diff --git a/jsdoc.js b/jsdoc.js index ff6e7740..4eb3c9b9 100755 --- a/jsdoc.js +++ b/jsdoc.js @@ -1,38 +1,45 @@ #!/usr/bin/env node -/* global arguments, require: true */ -/* eslint strict: [2, "function"] */ +/* global require: true */ +/* eslint strict: ["error", "function"] */ /** * @project jsdoc * @author Michael Mathews * @license See LICENSE.md file included in this distribution. */ -// initialize the environment for the current JavaScript VM -(function(args) { +// initialize the environment for Node.js +(function() { 'use strict'; - var path; + var fs = require('fs'); + var path = require('path'); - if (args[0] && typeof args[0] === 'object') { - // we should be on Node.js - args = [__dirname, process.cwd()]; - path = require('path'); + var env; + var jsdocPath = __dirname; + var pwd = process.cwd(); - // 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 - // plugins, and within JSDoc itself. It also allows external templates and plugins to - // require JSDoc's module dependencies without installing them locally. - require = require('requizzle')({ - requirePaths: { - before: [path.join(__dirname, 'lib')], - after: [path.join(__dirname, 'node_modules')] - }, - infect: true - }); + // 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 + // plugins, and within JSDoc itself. It also allows external templates and plugins to + // require JSDoc's module dependencies without installing them locally. + require = require('requizzle')({ + requirePaths: { + before: [path.join(__dirname, 'lib')], + after: [path.join(__dirname, 'node_modules')] + }, + infect: true + }); + + // resolve the path if it's a symlink + if ( fs.statSync(jsdocPath).isSymbolicLink() ) { + jsdocPath = path.resolve( path.dirname(jsdocPath), fs.readlinkSync(jsdocPath) ); } - require('./lib/jsdoc/util/runtime').initialize(args); -})( Array.prototype.slice.call(arguments, 0) ); + env = require('./lib/jsdoc/env'); + env.dirname = jsdocPath; + env.pwd = pwd; + env.args = process.argv.slice(2); +})(); /** * Data about the environment in which JSDoc is running, including the configuration settings that diff --git a/lib/jsdoc/util/runtime.js b/lib/jsdoc/util/runtime.js deleted file mode 100644 index c078d08f..00000000 --- a/lib/jsdoc/util/runtime.js +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Helper functions to enable JSDoc to run on multiple JavaScript runtimes. - * - * @module jsdoc/util/runtime - * @private - */ -'use strict'; - -var env = require('jsdoc/env'); - -// This string represents a directory name; do not modify it! -/** @private */ -var NODE = exports.NODE = 'node'; - -/** - * The JavaScript runtime that is executing JSDoc: - * - * + `module:jsdoc/util/runtime~NODE`: Node.js. - * - * @private - */ -var runtime = (function() { - if (require && require.main && module) { - return NODE; - } else { - // unknown runtime - throw new Error('Unable to identify the current JavaScript runtime.'); - } -})(); - -/** - * Check whether Node.js is running JSDoc. - * @return {boolean} Set to `true` if the current runtime is Node.js. - */ -exports.isNode = function() { - return runtime === NODE; -}; - -function initializeNode(args) { - var fs = require('fs'); - var path = require('path'); - - var jsdocPath = args[0]; - var pwd = args[1]; - - // resolve the path if it's a symlink - if ( fs.statSync(jsdocPath).isSymbolicLink() ) { - jsdocPath = path.resolve( path.dirname(jsdocPath), fs.readlinkSync(jsdocPath) ); - } - - env.dirname = jsdocPath; - env.pwd = pwd; - env.args = process.argv.slice(2); -} - -exports.initialize = function(args) { - switch (runtime) { - case NODE: - initializeNode(args); - break; - default: - throw new Error('Cannot initialize the unknown JavaScript runtime "' + runtime + '"!'); - } -}; - -/** - * Retrieve the identifier for the current JavaScript runtime. - * - * @private - * @return {string} The runtime identifier. - */ -exports.getRuntime = function() { - return runtime; -}; - -/** - * Get the require path for the runtime-specific implementation of a module. - * - * @param {string} partialPath - The partial path to the module. Use the same format as when calling - * `require()`. - * @return {object} The require path for the runtime-specific implementation of the module. - */ -exports.getModulePath = function(partialPath) { - var path = require('path'); - - return path.join(env.dirname, runtime, partialPath); -}; diff --git a/package.json b/package.json index ec3cfebf..c227bc42 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jsdoc", "version": "3.5.0-dev", - "revision": "1499313126253", + "revision": "1499320604033", "description": "An API documentation generator for JavaScript.", "keywords": [ "documentation", diff --git a/test/spec-collection.js b/test/spec-collection.js index 8b549a60..1b940714 100644 --- a/test/spec-collection.js +++ b/test/spec-collection.js @@ -2,7 +2,6 @@ var fs = require('jsdoc/fs'); var path = require('jsdoc/path'); -var runtime = require('jsdoc/util/runtime'); var klaw = require('klaw'); var specs = []; @@ -10,7 +9,7 @@ var finalSpecs = []; var createSpecObj = function(_path, root) { function relativePath() { - return _path.replace(root, '').replace(/^[\/\\]/, '').replace(/\\/g, '/'); + return _path.replace(root, '').replace(/^[/\\]/, '').replace(/\\/g, '/'); } return { @@ -19,13 +18,13 @@ var createSpecObj = function(_path, root) { }, relativePath: relativePath, directory: function() { - return _path.replace(/[\/\\][\s\w\.\-]*$/, '').replace(/\\/g, '/'); + return _path.replace(/[/\\][\s\w.-]*$/, '').replace(/\\/g, '/'); }, relativeDirectory: function() { - return relativePath().replace(/[\/\\][\s\w\.\-]*$/, '').replace(/\\/g, '/'); + return relativePath().replace(/[/\\][\s\w.-]*$/, '').replace(/\\/g, '/'); }, filename: function() { - return _path.replace(/^.*[\\\/]/, ''); + return _path.replace(/^.*[\\/]/, ''); } }; }; @@ -43,16 +42,12 @@ function addSpec(file, target) { function isValidSpec(file, matcher) { var result; - var skipPath = runtime.NODE; - // valid specs must... try { // ...be a file result = fs.statSync(file).isFile() && // ...match the matcher - matcher.test( path.basename(file) ) && - // ...be relevant to the current runtime - file.indexOf('/' + skipPath + '/') === -1; + matcher.test( path.basename(file) ); } catch (e) { result = false; @@ -76,24 +71,26 @@ function shouldLoad(file, matcher) { } exports.load = function(loadpath, matcher, clear, callback) { + var wannaBeSpecs = []; + if (clear === true) { clearSpecs(); } - var wannaBeSpecs = []; klaw(loadpath) - .on('data', function(spec) { - wannaBeSpecs.push(spec.path); - }) - .on('end', function() { - for (var i = 0; i < wannaBeSpecs.length; i++) { - var file = wannaBeSpecs[i]; - if ( shouldLoad(file, matcher) ) { - addSpec(file); - } - } - callback(); - }); + .on('data', function(spec) { + wannaBeSpecs.push(spec.path); + }) + .on('end', function() { + for (var i = 0; i < wannaBeSpecs.length; i++) { + var file = wannaBeSpecs[i]; + + if ( shouldLoad(file, matcher) ) { + addSpec(file); + } + } + callback(); + }); }; exports.getSpecs = function() { diff --git a/test/specs/jsdoc/util/runtime.js b/test/specs/jsdoc/util/runtime.js deleted file mode 100644 index c69a53a8..00000000 --- a/test/specs/jsdoc/util/runtime.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict'; - -describe('jsdoc/util/runtime', function() { - var runtime = require('jsdoc/util/runtime'); - var isNode; - - it('should exist', function() { - expect(runtime).toBeDefined(); - expect(typeof runtime).toEqual('object'); - }); - - it("should export a 'NODE' constant", function() { - expect(runtime.NODE).toBeDefined(); - expect(typeof runtime.NODE).toEqual('string'); - }); - - it("should export an 'isNode' function", function() { - expect(runtime.isNode).toBeDefined(); - expect(typeof runtime.isNode).toEqual('function'); - }); - - describe('isNode', function() { - isNode = runtime.isNode(); - - it('should return a boolean', function() { - expect(typeof isNode).toEqual('boolean'); - }); - }); -});