Skip to content

Commit

Permalink
fix(manager/pub): skip dependency flutter_test and path dependencies (
Browse files Browse the repository at this point in the history
  • Loading branch information
zeshuaro committed Aug 18, 2023
1 parent cec6fae commit a24b6e5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
40 changes: 35 additions & 5 deletions lib/modules/manager/pub/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ describe('modules/manager/pub/extract', () => {
});

it('returns valid dependencies', () => {
const dependenciesDepType = 'dependencies';
const devDependenciesDepType = 'dev_dependencies';
const dartDatasource = 'dart';
const skipReason = undefined;
const content = codeBlock`
environment:
sdk: ^3.0.0
Expand All @@ -44,53 +47,80 @@ describe('modules/manager/pub/extract', () => {
baz:
non-sense: true
qux: false
path_dep:
path: path1
dev_dependencies:
test: ^0.1.0
build:
version: 0.0.1
flutter_test:
sdk: flutter
path_dev_dep:
path: path2
`;
const actual = extractPackageFile(content, packageFile);
expect(actual).toEqual({
deps: [
{
currentValue: '1.0.0',
depName: 'foo',
depType: 'dependencies',
depType: dependenciesDepType,
datasource: dartDatasource,
skipReason,
},
{
currentValue: '1.1.0',
depName: 'bar',
depType: 'dependencies',
depType: dependenciesDepType,
datasource: dartDatasource,
skipReason,
},
{
currentValue: '',
depName: 'baz',
depType: 'dependencies',
depType: dependenciesDepType,
datasource: dartDatasource,
skipReason,
},
{
currentValue: '',
depName: 'path_dep',
depType: dependenciesDepType,
datasource: dartDatasource,
skipReason: 'path-dependency',
},
{
currentValue: '^0.1.0',
depName: 'test',
depType: 'dev_dependencies',
depType: devDependenciesDepType,
datasource: dartDatasource,
skipReason,
},
{
currentValue: '0.0.1',
depName: 'build',
depType: 'dev_dependencies',
depType: devDependenciesDepType,
datasource: dartDatasource,
skipReason,
},
{
currentValue: '',
depName: 'path_dev_dep',
depType: devDependenciesDepType,
datasource: dartDatasource,
skipReason: 'path-dependency',
},
{
currentValue: '^3.0.0',
depName: 'dart',
datasource: 'dart-version',
skipReason,
},
{
currentValue: '2.0.0',
depName: 'flutter',
datasource: 'flutter-version',
skipReason,
},
],
});
Expand Down
10 changes: 9 additions & 1 deletion lib/modules/manager/pub/extract.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import is from '@sindresorhus/is';
import type { SkipReason } from '../../../types';
import { DartDatasource } from '../../datasource/dart';
import { DartVersionDatasource } from '../../datasource/dart-version';
import { FlutterVersionDatasource } from '../../datasource/flutter-version';
Expand All @@ -17,15 +18,21 @@ function extractFromSection(

const deps: PackageDependency[] = [];
for (const depName of Object.keys(sectionContent)) {
if (depName === 'meta') {
if (depName === 'meta' || depName === 'flutter_test') {
continue;
}

let currentValue = sectionContent[depName];
let skipReason: SkipReason | undefined;

if (!is.string(currentValue)) {
const version = currentValue.version;
const path = currentValue.path;
if (version) {
currentValue = version;
} else if (path) {
currentValue = '';
skipReason = 'path-dependency';
} else {
currentValue = '';
}
Expand All @@ -36,6 +43,7 @@ function extractFromSection(
depType: sectionKey,
currentValue,
datasource: DartDatasource.id,
skipReason,
});
}

Expand Down
5 changes: 4 additions & 1 deletion lib/modules/manager/pub/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { LooseRecord, Yaml } from '../../../util/schema-utils';

const PubspecDependencySchema = LooseRecord(
z.string(),
z.union([z.string(), z.object({ version: z.string().optional() })])
z.union([
z.string(),
z.object({ version: z.string().optional(), path: z.string().optional() }),
])
);

export const PubspecSchema = z.object({
Expand Down

0 comments on commit a24b6e5

Please sign in to comment.