From 0cdad8b71e9fb8a4f47e46dc9f87c6176028325c Mon Sep 17 00:00:00 2001 From: demensky Date: Thu, 14 Sep 2023 00:22:54 +0300 Subject: [PATCH 1/3] refactor: replace lodash with native alternatives where possible Replace `_.forEach` and `_.each` with `for...of`. --- .../processors/extractDecoratedClasses.js | 25 +++++----- .../processors/checkUnbalancedBackTicks.js | 17 +++---- .../processors/createOverviewDump.js | 15 +++--- spec/Observable-spec.ts | 7 ++- spec/support/mocha.sauce.runner.js | 47 +++++++++---------- 5 files changed, 49 insertions(+), 62 deletions(-) diff --git a/docs_app/tools/transforms/angular-api-package/processors/extractDecoratedClasses.js b/docs_app/tools/transforms/angular-api-package/processors/extractDecoratedClasses.js index de643aa5a5..40161aa281 100644 --- a/docs_app/tools/transforms/angular-api-package/processors/extractDecoratedClasses.js +++ b/docs_app/tools/transforms/angular-api-package/processors/extractDecoratedClasses.js @@ -1,7 +1,4 @@ -var _ = require('lodash'); - module.exports = function extractDecoratedClassesProcessor(EXPORT_DOC_TYPES) { - // Add the "directive" docType into those that can be exported from a module EXPORT_DOC_TYPES.push('directive', 'pipe'); @@ -9,21 +6,21 @@ module.exports = function extractDecoratedClassesProcessor(EXPORT_DOC_TYPES) { $runAfter: ['processing-docs'], $runBefore: ['docs-processed'], decoratorTypes: ['Directive', 'Component', 'Pipe'], - $process: function(docs) { + $process(docs) { var decoratorTypes = this.decoratorTypes; - _.forEach(docs, function(doc) { - - _.forEach(doc.decorators, function(decorator) { - - if (decoratorTypes.indexOf(decorator.name) !== -1) { - doc.docType = decorator.name.toLowerCase(); - doc[doc.docType + 'Options'] = decorator.argumentInfo[0]; + for (const doc of docs) { + if (doc.decorators) { + for (const decorator of doc.decorators) { + if (decoratorTypes.indexOf(decorator.name) !== -1) { + doc.docType = decorator.name.toLowerCase(); + doc[doc.docType + 'Options'] = decorator.argumentInfo[0]; + } } - }); - }); + } + } return docs; - } + }, }; }; diff --git a/docs_app/tools/transforms/angular-base-package/processors/checkUnbalancedBackTicks.js b/docs_app/tools/transforms/angular-base-package/processors/checkUnbalancedBackTicks.js index 6037c37577..97a9ca6ef2 100644 --- a/docs_app/tools/transforms/angular-base-package/processors/checkUnbalancedBackTicks.js +++ b/docs_app/tools/transforms/angular-base-package/processors/checkUnbalancedBackTicks.js @@ -1,5 +1,3 @@ -var _ = require('lodash'); - /** * @dgProcessor checkUnbalancedBackTicks * @description @@ -8,26 +6,23 @@ var _ = require('lodash'); * source content. */ module.exports = function checkUnbalancedBackTicks(log, createDocMessage) { - var BACKTICK_REGEX = /^ *```/gm; return { // $runAfter: ['checkAnchorLinksProcessor'], $runAfter: ['inlineTagProcessor'], $runBefore: ['writeFilesProcessor'], - $process: function(docs) { - _.forEach(docs, function(doc) { + $process(docs) { + for (const doc of docs) { if (doc.renderedContent) { var matches = doc.renderedContent.match(BACKTICK_REGEX); if (matches && matches.length % 2 !== 0) { doc.unbalancedBackTicks = true; - log.warn(createDocMessage( - 'checkUnbalancedBackTicks processor: unbalanced backticks found in rendered content', - doc)); + log.warn(createDocMessage('checkUnbalancedBackTicks processor: unbalanced backticks found in rendered content', doc)); log.warn(doc.renderedContent); } } - }); - } + } + }, }; -}; \ No newline at end of file +}; diff --git a/docs_app/tools/transforms/angular.io-package/processors/createOverviewDump.js b/docs_app/tools/transforms/angular.io-package/processors/createOverviewDump.js index 6032e94f64..684274c0da 100644 --- a/docs_app/tools/transforms/angular.io-package/processors/createOverviewDump.js +++ b/docs_app/tools/transforms/angular.io-package/processors/createOverviewDump.js @@ -1,24 +1,21 @@ -var _ = require('lodash'); - module.exports = function createOverviewDump() { - return { $runAfter: ['processing-docs'], $runBefore: ['docs-processed'], - $process: function(docs) { + $process(docs) { var overviewDoc = { id: 'overview-dump', aliases: ['overview-dump'], path: 'overview-dump', outputPath: 'overview-dump.html', - modules: [] + modules: [], }; - _.forEach(docs, function(doc) { + for (const doc of docs) { if (doc.docType === 'module') { overviewDoc.modules.push(doc); } - }); + } docs.push(overviewDoc); - } + }, }; -}; \ No newline at end of file +}; diff --git a/spec/Observable-spec.ts b/spec/Observable-spec.ts index 54a53a706c..46d29c5e04 100644 --- a/spec/Observable-spec.ts +++ b/spec/Observable-spec.ts @@ -5,7 +5,6 @@ import { Observable, config, Subscription, Subscriber, Operator, NEVER, Subject, import { map, filter, count, tap, combineLatestWith, concatWith, mergeWith, raceWith, zipWith, catchError, share} from 'rxjs/operators'; import { TestScheduler } from 'rxjs/testing'; import { observableMatcher } from './helpers/observableMatcher'; -import { result } from 'lodash'; function expectFullObserver(val: any) { expect(val).to.be.a('object'); @@ -643,7 +642,7 @@ describe('Observable', () => { it('should allow any kind of piped function', () => { const source = of('test'); const result = source.pipe( - source => source instanceof Observable, + source => source instanceof Observable, isObservable => isObservable ? 'Well hello, there.' : 'Huh?' ); expect(result).to.equal('Well hello, there.'); @@ -727,7 +726,7 @@ describe('Observable', () => { subscriber.next(1); subscriber.next(2); - + // NOTE that we are NOT calling `subscriber.complete()` here. // therefore the teardown below would never be called naturally // by the observable unless it was unsubscribed. @@ -948,4 +947,4 @@ describe('Observable', () => { expect(state).to.equal('unsubscribed'); }); }); -}); \ No newline at end of file +}); diff --git a/spec/support/mocha.sauce.runner.js b/spec/support/mocha.sauce.runner.js index e17ff9f497..96d559426b 100644 --- a/spec/support/mocha.sauce.runner.js +++ b/spec/support/mocha.sauce.runner.js @@ -1,16 +1,15 @@ -var _ = require('lodash'); var mochaSauce = require('mocha-in-sauce'); var customLaunchers = { sl_chrome: { base: 'SauceLabs', browserName: 'chrome', - version: '46' + version: '46', }, sl_chrome_beta: { base: 'SauceLabs', browserName: 'chrome', - version: 'beta' + version: 'beta', }, /* sl_chrome_dev: { @@ -21,7 +20,7 @@ var customLaunchers = { sl_firefox: { base: 'SauceLabs', browserName: 'firefox', - version: '44' + version: '44', }, /*sl_firefox_beta: { base: 'SauceLabs', @@ -37,92 +36,92 @@ var customLaunchers = { base: 'SauceLabs', browserName: 'safari', platform: 'OS X 10.9', - version: '7' + version: '7', }, sl_safari8: { base: 'SauceLabs', browserName: 'safari', platform: 'OS X 10.10', - version: '8' + version: '8', }, sl_safari9: { base: 'SauceLabs', browserName: 'safari', platform: 'OS X 10.11', - version: '9.0' + version: '9.0', }, sl_ios8: { base: 'SauceLabs', browserName: 'iphone', platform: 'OS X 10.11', - version: '8.4' + version: '8.4', }, sl_ios9: { base: 'SauceLabs', browserName: 'iphone', platform: 'OS X 10.11', - version: '9.1' + version: '9.1', }, sl_ie9: { base: 'SauceLabs', browserName: 'internet explorer', platform: 'Windows 2008', - version: '9' + version: '9', }, sl_ie10: { base: 'SauceLabs', browserName: 'internet explorer', platform: 'Windows 2012', - version: '10' + version: '10', }, sl_ie11: { base: 'SauceLabs', browserName: 'internet explorer', platform: 'Windows 8.1', - version: '11' + version: '11', }, sl_edge: { base: 'SauceLabs', browserName: 'MicrosoftEdge', platform: 'Windows 10', - version: '14.14393' + version: '14.14393', }, sl_edge_13: { base: 'SauceLabs', browserName: 'MicrosoftEdge', platform: 'Windows 10', - version: '13.10586' + version: '13.10586', }, sl_android_4_1: { base: 'SauceLabs', browserName: 'android', platform: 'Linux', - version: '4.1' + version: '4.1', }, sl_android_4_2: { base: 'SauceLabs', browserName: 'android', platform: 'Linux', - version: '4.2' + version: '4.2', }, sl_android_4_3: { base: 'SauceLabs', browserName: 'android', platform: 'Linux', - version: '4.3' + version: '4.3', }, sl_android_4_4: { base: 'SauceLabs', browserName: 'android', platform: 'Linux', - version: '4.4' + version: '4.4', }, sl_android5: { base: 'SauceLabs', browserName: 'android', platform: 'Linux', - version: '5.1' - } + version: '5.1', + }, }; var sauce = new mochaSauce({ @@ -134,15 +133,15 @@ var sauce = new mochaSauce({ port: 4445, runSauceConnect: true, // run sauceConnect automatically - url: 'http://localhost:9876/spec/support/mocha-browser-runner.html' + url: 'http://localhost:9876/spec/support/mocha-browser-runner.html', }); sauce.record(true, true); sauce.concurrency(1); -_.each(customLaunchers, function (browser) { +for (const browser of customLaunchers) { sauce.browser(browser); -}); +} sauce.on('start', function (browser) { console.log(' started %s %s %s ...', browser.browserName, browser.version, browser.platform || ''); @@ -154,4 +153,4 @@ sauce.on('end', function (browser, res) { sauce.start(function (err, res) { console.log('-------------- done --------------'); -}); \ No newline at end of file +}); From d0bb20387ec9d1c55e5673398a3f11949e41cf6d Mon Sep 17 00:00:00 2001 From: demensky Date: Thu, 14 Sep 2023 00:28:15 +0300 Subject: [PATCH 2/3] ci: update `@types/lodash` to be compatible with latest TS version Refs: DefinitelyTyped/DefinitelyTyped#66122 --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 895e235786..8c52fcf1eb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "@swc/core": "^1.2.128", "@swc/helpers": "^0.3.2", "@types/chai": "^4.2.11", - "@types/lodash": "4.14.102", + "@types/lodash": "^4.14.198", "@types/mocha": "^10.0.1", "@types/node": "^14.14.6", "@types/shelljs": "^0.8.8", @@ -690,9 +690,9 @@ "dev": true }, "node_modules/@types/lodash": { - "version": "4.14.102", - "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.102.tgz", - "integrity": "sha512-k/SxycYmVc6sYo6kzm8cABHcbMs9MXn6jYsja1hLvZ/x9e31VHRRn+1UzWdpv6doVchphvKaOsZ0VTqbF7zvNg==", + "version": "4.14.198", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.198.tgz", + "integrity": "sha512-trNJ/vtMZYMLhfN45uLq4ShQSw0/S7xCTLLVM+WM1rmFpba/VS42jVUgaO3w/NOLiWR/09lnYk0yMaA/atdIsg==", "dev": true }, "node_modules/@types/minimatch": { @@ -10062,9 +10062,9 @@ "dev": true }, "@types/lodash": { - "version": "4.14.102", - "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.102.tgz", - "integrity": "sha512-k/SxycYmVc6sYo6kzm8cABHcbMs9MXn6jYsja1hLvZ/x9e31VHRRn+1UzWdpv6doVchphvKaOsZ0VTqbF7zvNg==", + "version": "4.14.198", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.198.tgz", + "integrity": "sha512-trNJ/vtMZYMLhfN45uLq4ShQSw0/S7xCTLLVM+WM1rmFpba/VS42jVUgaO3w/NOLiWR/09lnYk0yMaA/atdIsg==", "dev": true }, "@types/minimatch": { diff --git a/package.json b/package.json index 4e35a7299f..76956c6018 100644 --- a/package.json +++ b/package.json @@ -141,7 +141,7 @@ "@swc/core": "^1.2.128", "@swc/helpers": "^0.3.2", "@types/chai": "^4.2.11", - "@types/lodash": "4.14.102", + "@types/lodash": "^4.14.198", "@types/mocha": "^10.0.1", "@types/node": "^14.14.6", "@types/shelljs": "^0.8.8", From 86960f3b97a2673a50f2e36cec27f3da04191160 Mon Sep 17 00:00:00 2001 From: demensky Date: Thu, 14 Sep 2023 00:32:51 +0300 Subject: [PATCH 3/3] ci: remove Node.js v16 support for compatibility with latest npm Node.js v16 is planned to be End-of-Life on 2023-09-11. --- .github/workflows/ci_main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_main.yml b/.github/workflows/ci_main.yml index 60782e681d..9e39a03769 100644 --- a/.github/workflows/ci_main.yml +++ b/.github/workflows/ci_main.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: ['16', '18'] + node: ['18'] name: Node ${{ matrix.node }} build