fix: tsc errors and rest of the tests
Signed-off-by: Hellgren Heikki <heikki.hellgren@op.fi>
This commit is contained in:
@@ -21,7 +21,7 @@ const manypkg = require('@manypkg/get-packages');
|
||||
|
||||
/**
|
||||
* @typedef ExtendedPackage
|
||||
* @type {import('@manypkg/get-packages').Package & { packageJson: { exports?: Record<string, string>, files?: Array<string>, backstage?: { inline?: boolean } }}} packageJson
|
||||
* @type {import('@manypkg/get-packages').Package & { packageJson: { exports?: Record<string, string>, files?: Array<string>, backstage?: { inline?: boolean, role?: string } }}} packageJson
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,17 @@ const visitImports = require('../lib/visitImports');
|
||||
const getPackages = require('../lib/getPackages');
|
||||
const minimatch = require('minimatch');
|
||||
|
||||
/** @typedef {import('../lib/getPackages.js').ExtendedPackage} ExtendedPackage */
|
||||
|
||||
/**
|
||||
* @param {string} pattern
|
||||
* @param {string} filePath
|
||||
* @returns {boolean}
|
||||
*/
|
||||
const matchesPattern = (pattern, filePath) => {
|
||||
return new minimatch.Minimatch(pattern).match(filePath);
|
||||
};
|
||||
|
||||
const roleRules = [
|
||||
{
|
||||
sourceRole: ['frontend-plugin', 'web-library'],
|
||||
@@ -87,23 +98,22 @@ module.exports = {
|
||||
? context.physicalFilename
|
||||
: context.filename;
|
||||
|
||||
/** @type {ExtendedPackage | undefined} */
|
||||
const pkg = packages.byPath(filePath);
|
||||
if (!pkg) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const options = context.options[0] || {};
|
||||
/** @type {string[]} */
|
||||
const ignoreTargetPackages = options.excludedTargetPackages || [];
|
||||
/** @type {string[]} */
|
||||
const ignorePatterns = options.excludedFiles || [
|
||||
'**/*.{test,spec}.[jt]s?(x)',
|
||||
'**/dev/index.[jt]s?(x)',
|
||||
];
|
||||
|
||||
if (
|
||||
ignorePatterns.some(pattern =>
|
||||
new minimatch.Minimatch(pattern).match(context.filename),
|
||||
)
|
||||
) {
|
||||
if (ignorePatterns.some(pattern => matchesPattern(pattern, filePath))) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -112,8 +122,9 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @type {ExtendedPackage | undefined} */
|
||||
const targetPackage = imp.package;
|
||||
const targetName = targetPackage.packageJson.name;
|
||||
const targetName = targetPackage?.packageJson.name;
|
||||
const sourceName = pkg.packageJson.name;
|
||||
if (sourceName === targetName) {
|
||||
return;
|
||||
|
||||
@@ -24,6 +24,7 @@ jest.mock('child_process', () => ({
|
||||
|
||||
const RULE = 'no-undeclared-imports';
|
||||
const FIXTURE = joinPath(__dirname, '__fixtures__/monorepo');
|
||||
//
|
||||
|
||||
const ERR_UNDECLARED = (
|
||||
name: string,
|
||||
@@ -246,26 +247,14 @@ ruleTester.run(RULE, rule, {
|
||||
},
|
||||
{
|
||||
code: `import 'react-dom'`,
|
||||
output: `import 'directive:add-import:dependencies:react-dom'`,
|
||||
output: `import 'directive:add-import:peerDependencies:react-dom'`,
|
||||
filename: joinPath(FIXTURE, 'packages/foo/src/index.ts'),
|
||||
errors: [
|
||||
ERR_UNDECLARED(
|
||||
'react-dom',
|
||||
'dependencies',
|
||||
'peerDependencies',
|
||||
joinPath('packages', 'foo'),
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
code: `import 'react-dom'`,
|
||||
output: `import 'directive:add-import:devDependencies:react-dom'`,
|
||||
filename: joinPath(FIXTURE, 'packages/foo/src/index.test.ts'),
|
||||
errors: [
|
||||
ERR_UNDECLARED(
|
||||
'react-dom',
|
||||
'devDependencies',
|
||||
joinPath('packages', 'foo'),
|
||||
'--dev',
|
||||
'--peer',
|
||||
),
|
||||
],
|
||||
},
|
||||
|
||||
+55
-45
@@ -93,15 +93,17 @@ describe('gitlab:group:ensureExists', () => {
|
||||
full_path: 'group1/group2',
|
||||
});
|
||||
|
||||
const config = new ConfigReader({
|
||||
integrations: {
|
||||
gitlab: [
|
||||
{
|
||||
host: 'gitlab.com',
|
||||
token: 'tokenlols',
|
||||
apiBaseUrl: 'https://api.gitlab.com',
|
||||
},
|
||||
],
|
||||
const config = mockServices.rootConfig({
|
||||
data: {
|
||||
integrations: {
|
||||
gitlab: [
|
||||
{
|
||||
host: 'gitlab.com',
|
||||
token: 'tokenlols',
|
||||
apiBaseUrl: 'https://api.gitlab.com',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
@@ -140,15 +142,17 @@ describe('gitlab:group:ensureExists', () => {
|
||||
full_path: 'group1/group2/group3',
|
||||
});
|
||||
|
||||
const config = new ConfigReader({
|
||||
integrations: {
|
||||
gitlab: [
|
||||
{
|
||||
host: 'gitlab.com',
|
||||
token: 'tokenlols',
|
||||
apiBaseUrl: 'https://api.gitlab.com',
|
||||
},
|
||||
],
|
||||
const config = mockServices.rootConfig({
|
||||
data: {
|
||||
integrations: {
|
||||
gitlab: [
|
||||
{
|
||||
host: 'gitlab.com',
|
||||
token: 'tokenlols',
|
||||
apiBaseUrl: 'https://api.gitlab.com',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
@@ -172,15 +176,17 @@ describe('gitlab:group:ensureExists', () => {
|
||||
});
|
||||
|
||||
it(`Should ${examples[3].description}`, async () => {
|
||||
const config = new ConfigReader({
|
||||
integrations: {
|
||||
gitlab: [
|
||||
{
|
||||
host: 'gitlab.com',
|
||||
token: 'tokenlols',
|
||||
apiBaseUrl: 'https://api.gitlab.com',
|
||||
},
|
||||
],
|
||||
const config = mockServices.rootConfig({
|
||||
data: {
|
||||
integrations: {
|
||||
gitlab: [
|
||||
{
|
||||
host: 'gitlab.com',
|
||||
token: 'tokenlols',
|
||||
apiBaseUrl: 'https://api.gitlab.com',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
@@ -215,15 +221,17 @@ describe('gitlab:group:ensureExists', () => {
|
||||
full_path: 'group1/group2/group3',
|
||||
});
|
||||
|
||||
const config = new ConfigReader({
|
||||
integrations: {
|
||||
gitlab: [
|
||||
{
|
||||
host: 'gitlab.com',
|
||||
token: 'tokenlols',
|
||||
apiBaseUrl: 'https://api.gitlab.com',
|
||||
},
|
||||
],
|
||||
const config = mockServices.rootConfig({
|
||||
data: {
|
||||
integrations: {
|
||||
gitlab: [
|
||||
{
|
||||
host: 'gitlab.com',
|
||||
token: 'tokenlols',
|
||||
apiBaseUrl: 'https://api.gitlab.com',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
@@ -266,15 +274,17 @@ describe('gitlab:group:ensureExists', () => {
|
||||
full_path: 'group1/group2/group3/group4',
|
||||
});
|
||||
|
||||
const config = new ConfigReader({
|
||||
integrations: {
|
||||
gitlab: [
|
||||
{
|
||||
host: 'gitlab.com',
|
||||
token: 'tokenlols',
|
||||
apiBaseUrl: 'https://api.gitlab.com',
|
||||
},
|
||||
],
|
||||
const config = mockServices.rootConfig({
|
||||
data: {
|
||||
integrations: {
|
||||
gitlab: [
|
||||
{
|
||||
host: 'gitlab.com',
|
||||
token: 'tokenlols',
|
||||
apiBaseUrl: 'https://api.gitlab.com',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
|
||||
Reference in New Issue
Block a user