Skip to content

Commit fe7caad

Browse files
committed
feat: add manifest.json standardization and auto-fix scripts
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: passed - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: failed --- status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 8427c6a commit fe7caad

File tree

15 files changed

+1228
-0
lines changed

15 files changed

+1228
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* @license Apache-2.0
5+
*
6+
* Copyright (c) 2026 The Stdlib Authors.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
'use strict';
22+
23+
/*
24+
* Remove duplicate entries from the `dependencies` arrays in all `manifest.json` files.
25+
*
26+
* To enable verbose logging, set the `DEBUG` environment variable.
27+
*
28+
* ``` bash
29+
* $ DEBUG=* remove_duplicate_dependencies
30+
* ```
31+
*/
32+
33+
// MODULES //
34+
35+
var resolve = require( 'path' ).resolve;
36+
var logger = require( 'debug' );
37+
var glob = require( 'glob' ).sync;
38+
var readJSON = require( '@stdlib/fs/read-json' ).sync;
39+
var writeFile = require( '@stdlib/fs/write-file' ).sync;
40+
var rootDir = require( '@stdlib/_tools/utils/root-dir' );
41+
42+
43+
// VARIABLES //
44+
45+
var debug = logger( 'manifest-json:remove-duplicate-dependencies' );
46+
var ROOT = resolve( rootDir(), 'lib', 'node_modules' );
47+
48+
49+
// FUNCTIONS //
50+
51+
/**
52+
* Returns an array with duplicate values removed.
53+
*
54+
* @private
55+
* @param {StringArray} arr - input array
56+
* @returns {StringArray} deduplicated array
57+
*/
58+
function unique( arr ) {
59+
var seen = {};
60+
var out = [];
61+
var i;
62+
for ( i = 0; i < arr.length; i++ ) {
63+
if ( !seen[ arr[ i ] ] ) {
64+
seen[ arr[ i ] ] = true;
65+
out.push( arr[ i ] );
66+
}
67+
}
68+
return out;
69+
}
70+
71+
/**
72+
* Removes duplicate entries from the `dependencies` arrays in all `manifest.json` files.
73+
*
74+
* @private
75+
*/
76+
function main() {
77+
var changed;
78+
var files;
79+
var opts;
80+
var deps;
81+
var conf;
82+
var out;
83+
var i;
84+
var j;
85+
86+
debug( 'Searching for manifest.json files in %s.', ROOT );
87+
opts = {
88+
'cwd': ROOT,
89+
'ignore': [
90+
'node_modules/**',
91+
'**/build/**',
92+
'**/snippets/**'
93+
],
94+
'realpath': true
95+
};
96+
files = glob( '**/@stdlib/**/manifest.json', opts );
97+
debug( 'Found %d files.', files.length );
98+
99+
for ( i = 0; i < files.length; i++ ) {
100+
debug( 'Processing file: %s (%d of %d).', files[ i ], i+1, files.length );
101+
102+
out = readJSON( files[ i ] );
103+
if ( out instanceof Error ) {
104+
debug( 'Error reading file: %s. Skipping.', out.message );
105+
continue;
106+
}
107+
changed = false;
108+
for ( j = 0; j < out.confs.length; j++ ) {
109+
conf = out.confs[ j ];
110+
if ( conf.dependencies && conf.dependencies.length > 1 ) {
111+
deps = unique( conf.dependencies );
112+
if ( deps.length !== conf.dependencies.length ) {
113+
debug( 'Found %d duplicate(s) in conf %d.', conf.dependencies.length - deps.length, j );
114+
conf.dependencies = deps;
115+
changed = true;
116+
}
117+
}
118+
}
119+
if ( changed ) {
120+
debug( 'Duplicates removed. Writing file.' );
121+
writeFile( files[ i ], JSON.stringify( out, null, 2 )+'\n', {
122+
'encoding': 'utf8'
123+
});
124+
} else {
125+
debug( 'No duplicates found. Skipping.' );
126+
}
127+
}
128+
debug( 'Finished removing duplicate dependencies in all manifest.json files.' );
129+
}
130+
131+
132+
// MAIN //
133+
134+
main();
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* @license Apache-2.0
5+
*
6+
* Copyright (c) 2026 The Stdlib Authors.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
'use strict';
22+
23+
/*
24+
* Sort the `dependencies` arrays in all `manifest.json` files alphabetically.
25+
*
26+
* To enable verbose logging, set the `DEBUG` environment variable.
27+
*
28+
* ``` bash
29+
* $ DEBUG=* sort_dependencies
30+
* ```
31+
*/
32+
33+
// MODULES //
34+
35+
var resolve = require( 'path' ).resolve;
36+
var logger = require( 'debug' );
37+
var glob = require( 'glob' ).sync;
38+
var readJSON = require( '@stdlib/fs/read-json' ).sync;
39+
var writeFile = require( '@stdlib/fs/write-file' ).sync;
40+
var rootDir = require( '@stdlib/_tools/utils/root-dir' );
41+
42+
43+
// VARIABLES //
44+
45+
var debug = logger( 'manifest-json:sort-dependencies' );
46+
var ROOT = resolve( rootDir(), 'lib', 'node_modules' );
47+
48+
49+
// FUNCTIONS //
50+
51+
/**
52+
* Sorts the `dependencies` arrays in all `manifest.json` files alphabetically.
53+
*
54+
* @private
55+
*/
56+
function main() {
57+
var changed;
58+
var files;
59+
var opts;
60+
var deps;
61+
var conf;
62+
var out;
63+
var i;
64+
var j;
65+
66+
debug( 'Searching for manifest.json files in %s.', ROOT );
67+
opts = {
68+
'cwd': ROOT,
69+
'ignore': [
70+
'node_modules/**',
71+
'**/build/**',
72+
'**/snippets/**'
73+
],
74+
'realpath': true
75+
};
76+
files = glob( '**/@stdlib/**/manifest.json', opts );
77+
debug( 'Found %d files.', files.length );
78+
79+
for ( i = 0; i < files.length; i++ ) {
80+
debug( 'Processing file: %s (%d of %d).', files[ i ], i+1, files.length );
81+
82+
out = readJSON( files[ i ] );
83+
if ( out instanceof Error ) {
84+
debug( 'Error reading file: %s. Skipping.', out.message );
85+
continue;
86+
}
87+
changed = false;
88+
for ( j = 0; j < out.confs.length; j++ ) {
89+
conf = out.confs[ j ];
90+
if ( conf.dependencies && conf.dependencies.length > 1 ) {
91+
deps = conf.dependencies.slice().sort();
92+
if ( JSON.stringify( deps ) !== JSON.stringify( conf.dependencies ) ) {
93+
conf.dependencies = deps;
94+
changed = true;
95+
}
96+
}
97+
}
98+
if ( changed ) {
99+
debug( 'Dependencies reordered. Writing file.' );
100+
writeFile( files[ i ], JSON.stringify( out, null, 2 )+'\n', {
101+
'encoding': 'utf8'
102+
});
103+
} else {
104+
debug( 'Dependencies already sorted. Skipping.' );
105+
}
106+
}
107+
debug( 'Finished sorting dependencies in all manifest.json files.' );
108+
}
109+
110+
111+
// MAIN //
112+
113+
main();
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* @license Apache-2.0
5+
*
6+
* Copyright (c) 2026 The Stdlib Authors.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
'use strict';
22+
23+
/*
24+
* Standardize all `manifest.json` files by enforcing consistent key ordering.
25+
*
26+
* To enable verbose logging, set the `DEBUG` environment variable.
27+
*
28+
* ``` bash
29+
* $ DEBUG=* standardize_all
30+
* ```
31+
*/
32+
33+
// MODULES //
34+
35+
var join = require( 'path' ).join;
36+
var resolve = require( 'path' ).resolve;
37+
var logger = require( 'debug' );
38+
var glob = require( 'glob' ).sync;
39+
var readJSON = require( '@stdlib/fs/read-json' ).sync;
40+
var writeFile = require( '@stdlib/fs/write-file' ).sync;
41+
var rootDir = require( '@stdlib/_tools/utils/root-dir' );
42+
var standardize = require( './../standardize' );
43+
44+
45+
// VARIABLES //
46+
47+
var debug = logger( 'manifest-json:standardize-all' );
48+
var ROOT = resolve( rootDir(), 'lib', 'node_modules' );
49+
50+
51+
// FUNCTIONS //
52+
53+
/**
54+
* Standardizes all `manifest.json` files by enforcing consistent key ordering.
55+
*
56+
* @private
57+
*/
58+
function main() {
59+
var files;
60+
var opts;
61+
var out;
62+
var i;
63+
64+
debug( 'Searching for manifest.json files in %s.', ROOT );
65+
opts = {
66+
'cwd': ROOT,
67+
'ignore': [
68+
'node_modules/**',
69+
'**/build/**',
70+
'**/snippets/**'
71+
],
72+
'realpath': true
73+
};
74+
files = glob( '**/@stdlib/**/manifest.json', opts );
75+
debug( 'Found %d files.', files.length );
76+
77+
for ( i = 0; i < files.length; i++ ) {
78+
debug( 'Processing file: %s (%d of %d).', files[ i ], i+1, files.length );
79+
80+
out = readJSON( files[ i ] );
81+
if ( out instanceof Error ) {
82+
debug( 'Error reading file: %s. Skipping.', out.message );
83+
continue;
84+
}
85+
out = standardize( out );
86+
87+
debug( 'Serializing manifest data.' );
88+
out = JSON.stringify( out, null, 2 ); // 2-space indentation
89+
90+
debug( 'Writing manifest data to file.' );
91+
writeFile( files[ i ], out+'\n', {
92+
'encoding': 'utf8'
93+
});
94+
}
95+
debug( 'Finished standardizing all manifest.json files.' );
96+
}
97+
98+
99+
// MAIN //
100+
101+
main();

0 commit comments

Comments
 (0)