Skip to content

Commit 7083d03

Browse files
committed
replace the default sorting behaviour which was removed in node-glob v9 (used by file-set)
1 parent abe80fc commit 7083d03

File tree

6 files changed

+42
-24
lines changed

6 files changed

+42
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Finally, use the `render()` method to invocate jsdoc directly, generating your d
9494
```js
9595
import jsdoc from 'jsdoc-api'
9696

97-
await jsdoc.render({ files: ['index.js', 'lib/*.js'], destination: 'jsdoc-output' })
97+
await jsdoc.render({ files: ['index.js', 'lib/something.js'], destination: 'jsdoc-output' })
9898
```
9999

100100
See the [API documentation](https://github.com/jsdoc2md/jsdoc-api/blob/master/docs/api.md) for further details. See the [example folder](https://github.com/jsdoc2md/jsdoc-api/tree/master/example) for code examples.

dist/index.cjs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ var fs$1 = require('fs');
55
var os = require('os');
66
var crypto = require('crypto');
77
var node_url = require('node:url');
8-
var node_path = require('node:path');
8+
var path$2 = require('node:path');
99
var actualFS = require('node:fs');
1010
var promises = require('node:fs/promises');
1111
var node_events = require('node:events');
1212
var Stream = require('node:stream');
1313
var node_string_decoder = require('node:string_decoder');
14+
var os$1 = require('node:os');
1415
var assert = require('assert');
1516
var url = require('url');
1617
var cp = require('child_process');
1718
var util = require('node:util');
18-
var os$1 = require('node:os');
1919

2020
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
2121
function _interopNamespaceDefault(e) {
@@ -5992,7 +5992,7 @@ class PathWin32 extends PathBase {
59925992
* @internal
59935993
*/
59945994
getRootString(path) {
5995-
return node_path.win32.parse(path).root;
5995+
return path$2.win32.parse(path).root;
59965996
}
59975997
/**
59985998
* @internal
@@ -6700,7 +6700,7 @@ class PathScurryWin32 extends PathScurryBase {
67006700
sep = '\\';
67016701
constructor(cwd = process.cwd(), opts = {}) {
67026702
const { nocase = true } = opts;
6703-
super(cwd, node_path.win32, '\\', { ...opts, nocase });
6703+
super(cwd, path$2.win32, '\\', { ...opts, nocase });
67046704
this.nocase = nocase;
67056705
for (let p = this.cwd; p; p = p.parent) {
67066706
p.nocase = this.nocase;
@@ -6713,7 +6713,7 @@ class PathScurryWin32 extends PathScurryBase {
67136713
// if the path starts with a single separator, it's not a UNC, and we'll
67146714
// just get separator as the root, and driveFromUNC will return \
67156715
// In that case, mount \ on the root from the cwd.
6716-
return node_path.win32.parse(dir).root.toUpperCase();
6716+
return path$2.win32.parse(dir).root.toUpperCase();
67176717
}
67186718
/**
67196719
* @internal
@@ -6742,7 +6742,7 @@ class PathScurryPosix extends PathScurryBase {
67426742
sep = '/';
67436743
constructor(cwd = process.cwd(), opts = {}) {
67446744
const { nocase = false } = opts;
6745-
super(cwd, node_path.posix, '/', { ...opts, nocase });
6745+
super(cwd, path$2.posix, '/', { ...opts, nocase });
67466746
this.nocase = nocase;
67476747
}
67486748
/**
@@ -8135,15 +8135,18 @@ class FileSet {
81358135
if (stat.isFile() && !this.files.includes(file)) {
81368136
this.files.push(file);
81378137
} else if (stat.isDirectory() && !this.dirs.includes(file)) {
8138-
this.dirs.push(file.endsWith('/') ? file : `${file}/`);
8138+
this.dirs.push(file.endsWith(path$2.sep) ? file : `${file}${path$2.sep}`);
81398139
}
81408140
} catch (err) {
81418141
if (err.code === 'ENOENT') {
8142-
if (glob.hasMagic(file)) {
8143-
const found = await glob(file, { mark: true });
8142+
const posixPath = os$1.platform() === 'win32'
8143+
? file.replaceAll(path$2.sep, path$2.posix.sep)
8144+
: file;
8145+
if (glob.hasMagic(posixPath)) {
8146+
const found = await glob(posixPath, { mark: true });
81448147
if (found.length) {
81458148
for (const match of found) {
8146-
if (match.endsWith('/')) {
8149+
if (match.endsWith(path$2.sep)) {
81478150
if (!this.dirs.includes(match)) this.dirs.push(match);
81488151
} else {
81498152
if (!this.files.includes(match)) this.files.push(match);
@@ -8262,6 +8265,9 @@ class JsdocCommand {
82628265
async execute () {
82638266
this.inputFileSet = new FileSet();
82648267
await this.inputFileSet.add(this.options.files);
8268+
/* node-glob v9+ (used by file-set) no longer sorts the output by default. We will continue to sort the file list, for now, as it's what the user expected by default. The user's system locale is used. */
8269+
const collator = new Intl.Collator();
8270+
this.inputFileSet.files.sort(collator.compare);
82658271

82668272
if (this.options.source.length) {
82678273
this.tempFiles = this.options.source.map(source => new TempFile(source));
@@ -8351,7 +8357,6 @@ class Explain extends JsdocCommand {
83518357
}
83528358

83538359
async _runJsdoc () {
8354-
// console.log('SKDJKLAHS', this.options, this.tempFileSet?.files, this.inputFileSet.files)
83558360
const cmd = this.options.source.length
83568361
? `node ${this.jsdocPath} ${toSpawnArgs$1(this.jsdocOptions).join(' ')} -X ${this.tempFileSet.files.join(' ')}`
83578362
: `node ${this.jsdocPath} ${toSpawnArgs$1(this.jsdocOptions).join(' ')} -X ${this.inputFileSet.files.join(' ')}`;
@@ -8453,8 +8458,7 @@ const jsdoc = {
84538458
* @typicalname options
84548459
*/
84558460
class JsdocOptions {
8456-
constructor (options) {
8457-
options = options || {};
8461+
constructor (options = {}) {
84588462

84598463
/**
84608464
* One or more filenames to process. Either `files`, `source` or `configure` must be supplied.
@@ -8535,6 +8539,12 @@ class JsdocOptions {
85358539
*/
85368540
this.readme = options.readme;
85378541

8542+
/* Warning to avoid a common mistake where dmd templates are passed in.. a jsdoc template must be a filename. */
8543+
if (options.template !== undefined && options.template?.split(/\r?\n/)?.length !== 1) {
8544+
console.warn('Suspicious `options.template` value - the jsdoc `template` option must be a file path.');
8545+
console.warn(options.template);
8546+
}
8547+
85388548
/**
85398549
* The path to the template to use. Default: path/to/jsdoc/templates/default.
85408550
* @type {string}

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ const jsdoc = {
5959
* @typicalname options
6060
*/
6161
class JsdocOptions {
62-
constructor (options) {
63-
options = options || {}
62+
constructor (options = {}) {
6463

6564
/**
6665
* One or more filenames to process. Either `files`, `source` or `configure` must be supplied.
@@ -141,6 +140,12 @@ class JsdocOptions {
141140
*/
142141
this.readme = options.readme
143142

143+
/* Warning to avoid a common mistake where dmd templates are passed in.. a jsdoc template must be a filename. */
144+
if (options.template !== undefined && options.template?.split(/\r?\n/)?.length !== 1) {
145+
console.warn('Suspicious `options.template` value - the jsdoc `template` option must be a file path.')
146+
console.warn(options.template)
147+
}
148+
144149
/**
145150
* The path to the template to use. Default: path/to/jsdoc/templates/default.
146151
* @type {string}

lib/jsdoc-command.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class JsdocCommand {
4343
async execute () {
4444
this.inputFileSet = new FileSet()
4545
await this.inputFileSet.add(this.options.files)
46+
/* node-glob v9+ (used by file-set) no longer sorts the output by default. We will continue to sort the file list, for now, as it's what the user expected by default. The user's system locale is used. */
47+
const collator = new Intl.Collator()
48+
this.inputFileSet.files.sort(collator.compare)
4649

4750
if (this.options.source.length) {
4851
this.tempFiles = this.options.source.map(source => new TempFile(source))

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"array-back": "^6.2.2",
3535
"cache-point": "^3.0.0",
3636
"current-module-paths": "^1.1.2",
37-
"file-set": "^6.0.0",
37+
"file-set": "^6.0.1",
3838
"jsdoc": "^4.0.3",
3939
"object-to-spawn-args": "^2.0.1",
4040
"walk-back": "^5.1.1"

0 commit comments

Comments
 (0)