add a script to find ready to migrate to ts project refs plugins (#82305) (#82402)

This commit is contained in:
Mikhail Shustov 2020-11-03 13:27:25 +03:00 committed by GitHub
parent b3ff73ea6d
commit 30bcdf68b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 110 additions and 0 deletions

View file

@ -0,0 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
require('../src/setup_node_env');
require('../src/dev/run_find_plugins_ready_migrate_to_ts_refs');

View file

@ -0,0 +1,89 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import Path from 'path';
import Fs from 'fs';
import { get } from 'lodash';
import { run, KibanaPlatformPlugin } from '@kbn/dev-utils';
import { getPluginDeps, findPlugins } from './plugin_discovery';
interface AllOptions {
id?: string;
examples?: boolean;
extraPluginScanDirs?: string[];
}
run(
async ({ flags, log }) => {
const { examples = false, extraPluginScanDirs = [] } = flags as AllOptions;
const pluginMap = findPlugins({
oss: false,
examples,
extraPluginScanDirs,
});
const readyToMigrate = new Set<KibanaPlatformPlugin>();
for (const pluginId of pluginMap.keys()) {
const { deps, errors } = getPluginDeps({
pluginMap,
id: pluginId,
});
if (deps.size === 0 && errors.size === 0) {
readyToMigrate.add(pluginMap.get(pluginId)!);
}
}
const notMigratedPlugins = [...readyToMigrate].filter(
(plugin) => !isMigratedToTsProjectRefs(plugin.directory)
);
if (notMigratedPlugins.length > 0) {
log.info(
`Dependencies ready to migrate to TS project refs:\n${notMigratedPlugins
.map((p) => p.manifest.id)
.join('\n')}`
);
}
},
{
flags: {
boolean: ['examples'],
string: ['id'],
default: {
examples: false,
},
allowUnexpected: false,
help: `
--examples Include examples folder
--extraPluginScanDirs Include extra scan folder
`,
},
}
);
function isMigratedToTsProjectRefs(dir: string): boolean {
try {
const path = Path.join(dir, 'tsconfig.json');
const content = Fs.readFileSync(path, { encoding: 'utf8' });
return get(JSON.parse(content), 'compilerOptions.composite', false);
} catch (e) {
return false;
}
}