build(docs-infra): enable linting for `ng-packages-installer` scripts (#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 #41429
This commit is contained in:
parent
d42019d412
commit
a623bf4e70
|
@ -61,7 +61,7 @@
|
|||
"docs-test": "node tools/transforms/test.js",
|
||||
"redirects-test": "node tests/deployment/unit/test",
|
||||
"firebase-utils-test": "node tools/firebase-test-utils/test",
|
||||
"tools-lint": "tslint --config \"tools/tslint.json\" --project \"tools/firebase-test-utils\"",
|
||||
"tools-lint": "tslint --config \"tools/tslint.json\" --project \"tools/firebase-test-utils\" && eslint tools/ng-packages-installer",
|
||||
"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",
|
||||
"preserve-and-sync": "yarn docs",
|
||||
"serve-and-sync": "run-p \"docs-watch --watch-only\" \"start {@}\" --",
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
module.exports = {
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:jasmine/recommended',
|
||||
],
|
||||
env: {
|
||||
es2020: true,
|
||||
jasmine: true,
|
||||
node: true,
|
||||
},
|
||||
plugins: [
|
||||
'jasmine',
|
||||
],
|
||||
rules: {
|
||||
'indent': ['error', 2],
|
||||
'linebreak-style': ['error', 'unix'],
|
||||
'max-len': ['error', 120],
|
||||
'quotes': ['error', 'single'],
|
||||
'semi': ['error', 'always'],
|
||||
'jasmine/new-line-before-expect': ['off'],
|
||||
},
|
||||
};
|
|
@ -162,7 +162,9 @@ class NgPackagesInstaller {
|
|||
this._log(`Overriding dependency with peerDependency: ${key}: ${peerDepRange}`);
|
||||
dependencies[key] = peerDepRange;
|
||||
} else {
|
||||
this._log(`${devDependencies[key] ? 'Overriding' : 'Assigning'} devDependency with peerDependency: ${key}: ${peerDepRange}`);
|
||||
this._log(
|
||||
`${devDependencies[key] ? 'Overriding' : 'Assigning'} devDependency with peerDependency: ` +
|
||||
`${key}: ${peerDepRange}`);
|
||||
devDependencies[key] = peerDepRange;
|
||||
}
|
||||
});
|
||||
|
@ -183,10 +185,11 @@ class NgPackagesInstaller {
|
|||
shelljs.exec(DIST_PACKAGES_BUILD_CMD);
|
||||
} else {
|
||||
this._warn([
|
||||
'Automatically building the local Angular/Zone.js packages is currently not supported on Windows.',
|
||||
`Please, ensure '${ANGULAR_DIST_PACKAGES_DIR}', ${ZONEJS_DIST_PACKAGES_DIR} and '${ANGULAR_MISC_DIST_PACKAGES}' exist and are up-to-date ` +
|
||||
`(e.g. by running '${DIST_PACKAGES_BUILD_SCRIPT}' in Git Bash for Windows, Windows Subsystem for Linux or ` +
|
||||
'a Linux docker container or VM).',
|
||||
'Automatically building the local Angular/angular-in-memory-web-api/zone.js packages is currently not ' +
|
||||
'supported on Windows.',
|
||||
`Please, ensure '${ANGULAR_DIST_PACKAGES_DIR}', '${ZONEJS_DIST_PACKAGES_DIR}' and ` +
|
||||
`'${ANGULAR_MISC_DIST_PACKAGES}' exist and are up-to-date (e.g. by running '${DIST_PACKAGES_BUILD_SCRIPT}' ` +
|
||||
'in Git Bash for Windows, Windows Subsystem for Linux or a Linux docker container or VM).',
|
||||
'',
|
||||
'Proceeding anyway...',
|
||||
].join('\n'));
|
||||
|
@ -265,7 +268,7 @@ class NgPackagesInstaller {
|
|||
...collectPackages(ANGULAR_MISC_DIST_PACKAGES),
|
||||
};
|
||||
|
||||
this._log('Found the following Angular distributables:', Object.keys(packageConfigs).map(key => `\n - ${key}`));
|
||||
this._log('Found the following Angular distributables:', ...Object.keys(packageConfigs).map(key => `\n - ${key}`));
|
||||
return packageConfigs;
|
||||
}
|
||||
|
||||
|
@ -277,7 +280,7 @@ class NgPackagesInstaller {
|
|||
|
||||
/**
|
||||
* Log a message if the `debug` property is set to true.
|
||||
* @param {...string[]} messages - The messages to be logged.
|
||||
* @param {string[]} messages - The messages to be logged.
|
||||
*/
|
||||
_log(...messages) {
|
||||
if (this.debug) {
|
||||
|
@ -339,7 +342,8 @@ class NgPackagesInstaller {
|
|||
const parsed = lockfile.parse(lockfileContent);
|
||||
|
||||
if (parsed.type !== 'success') {
|
||||
throw new Error(`[${NgPackagesInstaller.name}]: Error parsing lockfile '${lockfilePath}' (result type: ${parsed.type}).`);
|
||||
throw new Error(
|
||||
`[${NgPackagesInstaller.name}]: Error parsing lockfile '${lockfilePath}' (result type: ${parsed.type}).`);
|
||||
}
|
||||
|
||||
return parsed.object;
|
||||
|
@ -362,7 +366,7 @@ class NgPackagesInstaller {
|
|||
|
||||
/**
|
||||
* Log a warning message do draw user's attention.
|
||||
* @param {...string[]} messages - The messages to be logged.
|
||||
* @param {string[]} messages - The messages to be logged.
|
||||
*/
|
||||
_warn(...messages) {
|
||||
const lines = messages.join(' ').split('\n');
|
||||
|
@ -400,6 +404,7 @@ function main() {
|
|||
return new NgPackagesInstaller(projectDir, options);
|
||||
};
|
||||
|
||||
/* eslint-disable max-len */
|
||||
yargs
|
||||
.usage('$0 <cmd> [args]')
|
||||
|
||||
|
@ -421,6 +426,7 @@ function main() {
|
|||
.strict()
|
||||
.wrap(yargs.terminalWidth())
|
||||
.argv;
|
||||
/* eslint-enable max-len */
|
||||
}
|
||||
|
||||
module.exports = NgPackagesInstaller;
|
||||
|
|
|
@ -46,7 +46,7 @@ describe('NgPackagesInstaller', () => {
|
|||
fs.existsSync.and.returnValue(true);
|
||||
installer.checkDependencies();
|
||||
expect(fs.existsSync).toHaveBeenCalledWith(path.resolve(projectDir, 'node_modules/_local_.json'));
|
||||
expect(installer._printWarning).toHaveBeenCalled();
|
||||
expect(installer._printWarning).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -163,7 +163,7 @@ describe('NgPackagesInstaller', () => {
|
|||
|
||||
it('should not continue processing', () => {
|
||||
installer.installLocalDependencies();
|
||||
expect(installer._checkLocalMarker).toHaveBeenCalled();
|
||||
expect(installer._checkLocalMarker).toHaveBeenCalledWith();
|
||||
expect(installer._getDistPackages).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
@ -171,7 +171,7 @@ describe('NgPackagesInstaller', () => {
|
|||
installer.force = true;
|
||||
installer.installLocalDependencies();
|
||||
expect(installer._checkLocalMarker).not.toHaveBeenCalled();
|
||||
expect(installer._getDistPackages).toHaveBeenCalled();
|
||||
expect(installer._getDistPackages).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -180,16 +180,17 @@ describe('NgPackagesInstaller', () => {
|
|||
|
||||
beforeEach(() => {
|
||||
log = [];
|
||||
fs.writeFileSync.and.callFake((filePath, contents) => filePath === packageJsonPath && log.push(`writeFile: ${contents}`));
|
||||
fs.writeFileSync.and.callFake((filePath, contents) =>
|
||||
filePath === packageJsonPath && log.push(`writeFile: ${contents}`));
|
||||
installer._installDeps.and.callFake((...args) => log.push(`installDeps: ${args.join(' ')}`));
|
||||
installer._checkLocalMarker.and.returnValue(false);
|
||||
installer.installLocalDependencies();
|
||||
});
|
||||
|
||||
it('should parse the lockfile and get the dist packages', () => {
|
||||
expect(installer._checkLocalMarker).toHaveBeenCalled();
|
||||
expect(installer._checkLocalMarker).toHaveBeenCalledWith();
|
||||
expect(installer._parseLockfile).toHaveBeenCalledWith(yarnLockPath);
|
||||
expect(installer._getDistPackages).toHaveBeenCalled();
|
||||
expect(installer._getDistPackages).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it('should temporarily overwrite the package.json files of local Angular packages', () => {
|
||||
|
@ -260,7 +261,7 @@ describe('NgPackagesInstaller', () => {
|
|||
it('should overwrite package.json, then install deps, then restore original package.json', () => {
|
||||
expect(log).toEqual([
|
||||
`writeFile: ${expectedModifiedPackageJson}`,
|
||||
`installDeps: --pure-lockfile --check-files`,
|
||||
'installDeps: --pure-lockfile --check-files',
|
||||
`writeFile: ${dummyPackageJson}`
|
||||
]);
|
||||
});
|
||||
|
@ -316,7 +317,8 @@ describe('NgPackagesInstaller', () => {
|
|||
|
||||
expect(shelljs.exec).not.toHaveBeenCalled();
|
||||
expect(warning).toContain(
|
||||
'Automatically building the local Angular/Zone.js packages is currently not supported on Windows.');
|
||||
'Automatically building the local Angular/angular-in-memory-web-api/zone.js packages is currently not ' +
|
||||
'supported on Windows.');
|
||||
expect(warning).toContain('Git Bash for Windows');
|
||||
expect(warning).toContain('Windows Subsystem for Linux');
|
||||
expect(warning).toContain('Linux docker container or VM');
|
||||
|
@ -340,7 +342,8 @@ describe('NgPackagesInstaller', () => {
|
|||
expect(installer._buildDistPackages).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should not build the local packages by default', () => {
|
||||
it('should not build the local packages, if `buildPackages` is false', () => {
|
||||
installer = new NgPackagesInstaller(projectDir, {buildPackages: false});
|
||||
installer._getDistPackages();
|
||||
expect(installer._buildDistPackages).not.toHaveBeenCalled();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue