Skip to content

Commit a623bf4

Browse files
gkalpakatscott
authored andcommitted
build(docs-infra): enable linting for ng-packages-installer scripts (angular#41429)
This commit enables linting for the scripts in `aio/tools/ng-packages-installer/`. It also makes the necessary changes to the files to make linting pass. PR Close angular#41429
1 parent d42019d commit a623bf4

4 files changed

Lines changed: 51 additions & 20 deletions

File tree

aio/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"docs-test": "node tools/transforms/test.js",
6262
"redirects-test": "node tests/deployment/unit/test",
6363
"firebase-utils-test": "node tools/firebase-test-utils/test",
64-
"tools-lint": "tslint --config \"tools/tslint.json\" --project \"tools/firebase-test-utils\"",
64+
"tools-lint": "tslint --config \"tools/tslint.json\" --project \"tools/firebase-test-utils\" && eslint tools/ng-packages-installer",
6565
"tools-test": "yarn docs-test && yarn boilerplate:test && jasmine tools/ng-packages-installer/index.spec.js && jasmine scripts/deploy-to-firebase.spec.js && yarn firebase-utils-test",
6666
"preserve-and-sync": "yarn docs",
6767
"serve-and-sync": "run-p \"docs-watch --watch-only\" \"start {@}\" --",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
extends: [
3+
'eslint:recommended',
4+
'plugin:jasmine/recommended',
5+
],
6+
env: {
7+
es2020: true,
8+
jasmine: true,
9+
node: true,
10+
},
11+
plugins: [
12+
'jasmine',
13+
],
14+
rules: {
15+
'indent': ['error', 2],
16+
'linebreak-style': ['error', 'unix'],
17+
'max-len': ['error', 120],
18+
'quotes': ['error', 'single'],
19+
'semi': ['error', 'always'],
20+
'jasmine/new-line-before-expect': ['off'],
21+
},
22+
};

aio/tools/ng-packages-installer/index.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ class NgPackagesInstaller {
162162
this._log(`Overriding dependency with peerDependency: ${key}: ${peerDepRange}`);
163163
dependencies[key] = peerDepRange;
164164
} else {
165-
this._log(`${devDependencies[key] ? 'Overriding' : 'Assigning'} devDependency with peerDependency: ${key}: ${peerDepRange}`);
165+
this._log(
166+
`${devDependencies[key] ? 'Overriding' : 'Assigning'} devDependency with peerDependency: ` +
167+
`${key}: ${peerDepRange}`);
166168
devDependencies[key] = peerDepRange;
167169
}
168170
});
@@ -183,10 +185,11 @@ class NgPackagesInstaller {
183185
shelljs.exec(DIST_PACKAGES_BUILD_CMD);
184186
} else {
185187
this._warn([
186-
'Automatically building the local Angular/Zone.js packages is currently not supported on Windows.',
187-
`Please, ensure '${ANGULAR_DIST_PACKAGES_DIR}', ${ZONEJS_DIST_PACKAGES_DIR} and '${ANGULAR_MISC_DIST_PACKAGES}' exist and are up-to-date ` +
188-
`(e.g. by running '${DIST_PACKAGES_BUILD_SCRIPT}' in Git Bash for Windows, Windows Subsystem for Linux or ` +
189-
'a Linux docker container or VM).',
188+
'Automatically building the local Angular/angular-in-memory-web-api/zone.js packages is currently not ' +
189+
'supported on Windows.',
190+
`Please, ensure '${ANGULAR_DIST_PACKAGES_DIR}', '${ZONEJS_DIST_PACKAGES_DIR}' and ` +
191+
`'${ANGULAR_MISC_DIST_PACKAGES}' exist and are up-to-date (e.g. by running '${DIST_PACKAGES_BUILD_SCRIPT}' ` +
192+
'in Git Bash for Windows, Windows Subsystem for Linux or a Linux docker container or VM).',
190193
'',
191194
'Proceeding anyway...',
192195
].join('\n'));
@@ -265,7 +268,7 @@ class NgPackagesInstaller {
265268
...collectPackages(ANGULAR_MISC_DIST_PACKAGES),
266269
};
267270

268-
this._log('Found the following Angular distributables:', Object.keys(packageConfigs).map(key => `\n - ${key}`));
271+
this._log('Found the following Angular distributables:', ...Object.keys(packageConfigs).map(key => `\n - ${key}`));
269272
return packageConfigs;
270273
}
271274

@@ -277,7 +280,7 @@ class NgPackagesInstaller {
277280

278281
/**
279282
* Log a message if the `debug` property is set to true.
280-
* @param {...string[]} messages - The messages to be logged.
283+
* @param {string[]} messages - The messages to be logged.
281284
*/
282285
_log(...messages) {
283286
if (this.debug) {
@@ -339,7 +342,8 @@ class NgPackagesInstaller {
339342
const parsed = lockfile.parse(lockfileContent);
340343

341344
if (parsed.type !== 'success') {
342-
throw new Error(`[${NgPackagesInstaller.name}]: Error parsing lockfile '${lockfilePath}' (result type: ${parsed.type}).`);
345+
throw new Error(
346+
`[${NgPackagesInstaller.name}]: Error parsing lockfile '${lockfilePath}' (result type: ${parsed.type}).`);
343347
}
344348

345349
return parsed.object;
@@ -362,7 +366,7 @@ class NgPackagesInstaller {
362366

363367
/**
364368
* Log a warning message do draw user's attention.
365-
* @param {...string[]} messages - The messages to be logged.
369+
* @param {string[]} messages - The messages to be logged.
366370
*/
367371
_warn(...messages) {
368372
const lines = messages.join(' ').split('\n');
@@ -400,6 +404,7 @@ function main() {
400404
return new NgPackagesInstaller(projectDir, options);
401405
};
402406

407+
/* eslint-disable max-len */
403408
yargs
404409
.usage('$0 <cmd> [args]')
405410

@@ -421,6 +426,7 @@ function main() {
421426
.strict()
422427
.wrap(yargs.terminalWidth())
423428
.argv;
429+
/* eslint-enable max-len */
424430
}
425431

426432
module.exports = NgPackagesInstaller;

aio/tools/ng-packages-installer/index.spec.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('NgPackagesInstaller', () => {
4646
fs.existsSync.and.returnValue(true);
4747
installer.checkDependencies();
4848
expect(fs.existsSync).toHaveBeenCalledWith(path.resolve(projectDir, 'node_modules/_local_.json'));
49-
expect(installer._printWarning).toHaveBeenCalled();
49+
expect(installer._printWarning).toHaveBeenCalledWith();
5050
});
5151
});
5252

@@ -163,15 +163,15 @@ describe('NgPackagesInstaller', () => {
163163

164164
it('should not continue processing', () => {
165165
installer.installLocalDependencies();
166-
expect(installer._checkLocalMarker).toHaveBeenCalled();
166+
expect(installer._checkLocalMarker).toHaveBeenCalledWith();
167167
expect(installer._getDistPackages).not.toHaveBeenCalled();
168168
});
169169

170170
it('should continue processing (without checking for local marker) if `force` is true', () => {
171171
installer.force = true;
172172
installer.installLocalDependencies();
173173
expect(installer._checkLocalMarker).not.toHaveBeenCalled();
174-
expect(installer._getDistPackages).toHaveBeenCalled();
174+
expect(installer._getDistPackages).toHaveBeenCalledWith();
175175
});
176176
});
177177

@@ -180,16 +180,17 @@ describe('NgPackagesInstaller', () => {
180180

181181
beforeEach(() => {
182182
log = [];
183-
fs.writeFileSync.and.callFake((filePath, contents) => filePath === packageJsonPath && log.push(`writeFile: ${contents}`));
183+
fs.writeFileSync.and.callFake((filePath, contents) =>
184+
filePath === packageJsonPath && log.push(`writeFile: ${contents}`));
184185
installer._installDeps.and.callFake((...args) => log.push(`installDeps: ${args.join(' ')}`));
185186
installer._checkLocalMarker.and.returnValue(false);
186187
installer.installLocalDependencies();
187188
});
188189

189190
it('should parse the lockfile and get the dist packages', () => {
190-
expect(installer._checkLocalMarker).toHaveBeenCalled();
191+
expect(installer._checkLocalMarker).toHaveBeenCalledWith();
191192
expect(installer._parseLockfile).toHaveBeenCalledWith(yarnLockPath);
192-
expect(installer._getDistPackages).toHaveBeenCalled();
193+
expect(installer._getDistPackages).toHaveBeenCalledWith();
193194
});
194195

195196
it('should temporarily overwrite the package.json files of local Angular packages', () => {
@@ -260,7 +261,7 @@ describe('NgPackagesInstaller', () => {
260261
it('should overwrite package.json, then install deps, then restore original package.json', () => {
261262
expect(log).toEqual([
262263
`writeFile: ${expectedModifiedPackageJson}`,
263-
`installDeps: --pure-lockfile --check-files`,
264+
'installDeps: --pure-lockfile --check-files',
264265
`writeFile: ${dummyPackageJson}`
265266
]);
266267
});
@@ -316,7 +317,8 @@ describe('NgPackagesInstaller', () => {
316317

317318
expect(shelljs.exec).not.toHaveBeenCalled();
318319
expect(warning).toContain(
319-
'Automatically building the local Angular/Zone.js packages is currently not supported on Windows.');
320+
'Automatically building the local Angular/angular-in-memory-web-api/zone.js packages is currently not ' +
321+
'supported on Windows.');
320322
expect(warning).toContain('Git Bash for Windows');
321323
expect(warning).toContain('Windows Subsystem for Linux');
322324
expect(warning).toContain('Linux docker container or VM');
@@ -340,7 +342,8 @@ describe('NgPackagesInstaller', () => {
340342
expect(installer._buildDistPackages).toHaveBeenCalledTimes(1);
341343
});
342344

343-
it('should not build the local packages by default', () => {
345+
it('should not build the local packages, if `buildPackages` is false', () => {
346+
installer = new NgPackagesInstaller(projectDir, {buildPackages: false});
344347
installer._getDistPackages();
345348
expect(installer._buildDistPackages).not.toHaveBeenCalled();
346349
});
@@ -506,7 +509,7 @@ describe('NgPackagesInstaller', () => {
506509
it('should throw if parsing the lockfile fails', () => {
507510
lockfile.parse.and.returnValue({type: 'not success'});
508511
expect(() => installer._parseLockfile('/foo/bar/yarn.lock')).toThrowError(
509-
'[NgPackagesInstaller]: Error parsing lockfile \'/foo/bar/yarn.lock\' (result type: not success).');
512+
'[NgPackagesInstaller]: Error parsing lockfile \'/foo/bar/yarn.lock\' (result type: not success).');
510513
});
511514

512515
it('should return the parsed lockfile content as an object', () => {

0 commit comments

Comments
 (0)