Skip to content

Commit

Permalink
Build: Require 'use strict' for Node.js files and fix violations
Browse files Browse the repository at this point in the history
Thanks to @mgol for raising this at
#1798.
  • Loading branch information
Krinkle committed Sep 4, 2024
1 parent 51d0196 commit 365c04a
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
{
"files": [
"bin/**",
"build/**",
"build/**/*.js",
"src/cli/**",
"Gruntfile.js",
"rollup.config.js"
Expand All @@ -99,6 +99,7 @@
"node": true
},
"rules": {
"strict": "error",
"compat/compat": "off",
"no-console": "off",
"no-process-exit": "off",
Expand Down
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-env node */
'use strict';

const fs = require('fs');
const path = require('path');
Expand Down
2 changes: 2 additions & 0 deletions build/dev.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const fs = require('fs');
const http = require('http');
const path = require('path');
Expand Down
1 change: 1 addition & 0 deletions build/dist-replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// If a date or timestamp is used, then honour SOURCE_DATE_EPOCH
// and update RELEASE.md as needed.
// <https://reproducible-builds.org/docs/source-date-epoch/>.
'use strict';

let distVersion = require('../package.json').version;

Expand Down
43 changes: 14 additions & 29 deletions build/npm-search.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
'use strict';

const NPM_REGISTRY_URL = 'https://registry.npmjs.org/';

/**
* npm-search.js is based on npm-keyword v6.1.0 by @sindresorhus,
* This is based on npm-keyword v6.1.0 by @sindresorhus,
* but simplified to not have 32 needless dependencies.
*
* - <https://github.com/sindresorhus/npm-keyword/tree/v6.1.0>
* - <https://snyk.io/test/npm/npm-keyword/6.1.0?tab=dependencies>
*
* @param {string} keyword
* @return {Object[]} List of package objects
*/
'use strict';
const https = require('https');
const registryUrl = 'https://registry.npmjs.org/';

function fetch (url) {
return new Promise((resolve, reject) => {
const req = https.get(url, (resp) => {
let data = '';
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', () => {
resolve(data);
});
});
req.on('error', reject);
});
async function keyword (keyword) {
const { objects } = await search('keywords:' + keyword, { size: 250 });
return objects.map(element => element.package);
}

async function search (phrase, options) {
Expand All @@ -32,17 +25,9 @@ async function search (phrase, options) {
}

phrase = encodeURIComponent(phrase).replace('%2C', '+');
const url = `${registryUrl}-/v1/search?text=${phrase}&size=${options.size}`;
return JSON.parse(await fetch(url));
}

/**
* @param {string} keyword
* @return {Object[]} List of package objects
*/
async function keyword (keyword) {
const { objects } = await search('keywords:' + keyword, { size: 250 });
return objects.map(element => element.package);
const url = `${NPM_REGISTRY_URL}-/v1/search?text=${phrase}&size=${options.size}`;
const resp = await fetch(url);
return await resp.json();
}

module.exports = { search, keyword };
Expand Down
1 change: 1 addition & 0 deletions build/prep-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// See also RELEASE.md.
//
// Inspired by <https://github.com/jquery/jquery-release>.
'use strict';

const fs = require('fs');
const path = require('path');
Expand Down
2 changes: 2 additions & 0 deletions build/q4000-template.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const fs = require('fs');
const path = require('path');

Expand Down
1 change: 1 addition & 0 deletions build/reproducible-builds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// * Node.js 18+, npm 10+
// * Git 2.11+
// * tar, shasum, gunzip (preinstalled on Linux/macOS)
'use strict';

const cp = require('child_process');
const fs = require('fs');
Expand Down
2 changes: 1 addition & 1 deletion build/review-package.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Helper for reviewing build artefacts against a past release.
//
// See also RELEASE.md.

/* eslint-env node */
'use strict';

const cp = require('child_process');
const fs = require('fs');
Expand Down
2 changes: 2 additions & 0 deletions build/site-set-version.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const fs = require('fs');

const { CommandError, isValidVersion, versionAnywhereRegPattern } = require('./utils.js');
Expand Down
2 changes: 2 additions & 0 deletions build/site-update-plugins.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const fs = require('fs');
const { keyword } = require('./npm-search.js');

Expand Down
2 changes: 2 additions & 0 deletions build/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const cp = require('child_process');
const fs = require('fs');
const https = require('https');
Expand Down
1 change: 1 addition & 0 deletions demos/bundlers/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-env node */
'use strict';
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-qunit');
Expand Down
1 change: 1 addition & 0 deletions demos/grunt-contrib-qunit/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-env node */
'use strict';
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-qunit');

Expand Down
1 change: 1 addition & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-env node */
'use strict';

const { babel } = require('@rollup/plugin-babel');
const { nodeResolve } = require('@rollup/plugin-node-resolve');
Expand Down
2 changes: 2 additions & 0 deletions src/cli/require-from-cwd.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

module.exports = function requireFromCWD (mod) {
const resolvedPath = require.resolve(mod, { paths: [process.cwd()] });
return require(resolvedPath);
Expand Down
8 changes: 6 additions & 2 deletions src/cli/require-qunit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Depending on the exact usage, QUnit could be in one of several places, this
// function handles finding it.
'use strict';

/**
* Depending on the exact usage, QUnit could be in one of several places, this
* function handles finding it.
*/
module.exports = function requireQUnit (resolve = require.resolve) {
try {
// For:
Expand Down

0 comments on commit 365c04a

Please sign in to comment.