feat(project): avoid validate manifest
MODIFY
internal/codec-js-manifest/index.test.ts
internal/codec-js-manifest/index.test.ts
@@ -25,7 +25,9 @@ test(
DIAGNOSTIC_CATEGORIES.parse,
"manifest",
);
- t.snapshot(await normalizeManifest(PATH, manifest, []));
+ t.snapshot(
+ await normalizeManifest({path: PATH, consumer: manifest, projects: []}),
+ );
},
);
@@ -44,7 +46,9 @@ test(
DIAGNOSTIC_CATEGORIES.parse,
"manifest",
);
- t.snapshot(await normalizeManifest(PATH, manifest, []));
+ t.snapshot(
+ await normalizeManifest({path: PATH, consumer: manifest, projects: []}),
+ );
},
);
@@ -63,6 +67,8 @@ test(
DIAGNOSTIC_CATEGORIES.parse,
"manifest",
);
- t.snapshot(await normalizeManifest(PATH, manifest, []));
+ t.snapshot(
+ await normalizeManifest({path: PATH, consumer: manifest, projects: []}),
+ );
},
);

MODIFY
internal/codec-js-manifest/normalize/fields.ts
internal/codec-js-manifest/normalize/fields.ts
@@ -176,6 +176,7 @@ export function normalizeRepoField(
}
}
+// TODO: review this logic
export function normalizeExportsField(
consumer: Consumer,
): boolean | ManifestExportsField {

MODIFY
internal/codec-js-manifest/normalize/index.ts
internal/codec-js-manifest/normalize/index.ts
@@ -238,7 +238,6 @@ const INCORRECT_DEPENDENCIES_SUFFIXES = [
"dependancies",
"dependecies",
];
-
function checkDependencyKeyTypo(key: string, prop: Consumer) {
for (const depPrefixKey of DEPENDENCIES_KEYS) {
// Ignore if the key is a valid dependency key
@@ -274,7 +273,7 @@ function normalizeManifestMetadata(
metadata: ManifestMetadata;
parsedLicense: undefined | SPDXLicenseParseResult;
} {
- const {consumer, loose} = context;
+ const {consumer, loose, checkDependenciesAndLicense} = context;
const name = normalizeNameField(consumer, loose);
const version = normalizeVersion(context);
@@ -283,12 +282,14 @@ function normalizeManifestMetadata(
}
const strName = name === undefined ? undefined : manifestNameToString(name);
-
- const parsedLicense = normalizeLicense(
+ let parsedLicense: undefined | SPDXLicenseParseResult = undefined;
+ if (checkDependenciesAndLicense) {
+ parsedLicense = normalizeLicense(
consumer,
{name: strName, version},
context,
);
+ }
return {
parsedLicense,
@@ -385,12 +386,18 @@ type NormalizeContext = {
loose: boolean;
consumer: Consumer;
projects: CompilerProject[];
+ checkDependenciesAndLicense?: boolean;
};
+interface NormalizeManifest {
+ path: AbsoluteFilePath;
+ consumer: Consumer;
+ projects: CompilerProject[];
+ checkDependenciesAndLicense?: boolean;
+}
+
export async function normalizeManifest(
- path: AbsoluteFilePath,
- consumer: Consumer,
- projects: CompilerProject[],
+ {path, consumer, projects, checkDependenciesAndLicense}: NormalizeManifest,
): Promise<Manifest> {
const loose = path.hasSegment("node_modules");
@@ -399,7 +406,6 @@ export async function normalizeManifest(
for (const [key, prop] of consumer.asMap()) {
// Check for typos for dependencies
checkDependencyKeyTypo(key, prop);
-
// Check for other typos
const correctKey = TYPO_KEYS.get(key);
if (correctKey !== undefined) {
@@ -413,6 +419,7 @@ export async function normalizeManifest(
loose,
consumer,
projects,
+ checkDependenciesAndLicense,
};
const {metadata, parsedLicense} = normalizeManifestMetadata(context);

MODIFY
internal/codec-spdx-license/parse.ts
internal/codec-spdx-license/parse.ts
@@ -175,6 +175,10 @@ function isLicenseValid(
const {exceptions} = parser.options;
if (exceptions !== undefined) {
for (const project of exceptions.projects) {
+ // if the check on dependencies is not enabled, do not do any kind of check
+ if (!project.config.dependencies.enabled) {
+ continue;
+ }
const {invalidLicenses} = project.config.dependencies.exceptions;
const licenses = invalidLicenses.get(id);
if (licenses === undefined) {

MODIFY
internal/core/common/IntegrationLoader.ts
internal/core/common/IntegrationLoader.ts
@@ -139,7 +139,11 @@ export default class IntegrationLoader<
);
const versionProp = jsonConsumer.get("version");
- const manifest = await normalizeManifest(manifestPath, jsonConsumer, []);
+ const manifest = await normalizeManifest({
+ path: manifestPath,
+ consumer: jsonConsumer,
+ projects: [],
+ });
if (manifest.version === undefined) {
throw versionProp.unexpected(() =>

MODIFY
internal/core/server/commands/init.ts
internal/core/server/commands/init.ts
@@ -197,11 +197,11 @@ export default createServerCommand<Flags>({
path: manifestPath,
input: await manifestPath.readFileText(),
});
- const manifestDefinition = await normalizeManifest(
- manifestPath,
+ const manifestDefinition = await normalizeManifest({
+ path: manifestPath,
consumer,
- [],
- );
+ projects: [],
+ });
if (!manifestDefinition) {
reporter.error(markup`Couldn't find any manifest at path ${cwd}`);
return;

MODIFY
internal/core/server/fs/MemoryFileSystem.ts
internal/core/server/fs/MemoryFileSystem.ts
@@ -703,8 +703,18 @@ export default class MemoryFileSystem {
const projects = await this.server.projectManager.getProjectHierarchyFromPath(
path,
);
+ let checkDependenciesAndLicense = false;
+ const mainProject = await this.server.projectManager.findLoadedProject(path);
+ if (mainProject) {
+ checkDependenciesAndLicense = mainProject.config.dependencies.enabled;
+ }
const {consumer: normalizeConsumer, diagnostics: rawDiagnostics} = consumer.capture();
- const manifest = await normalizeManifest(path, normalizeConsumer, projects);
+ const manifest = await normalizeManifest({
+ path,
+ consumer: normalizeConsumer,
+ projects,
+ checkDependenciesAndLicense,
+ });
// If manifest is undefined then we failed to validate and have diagnostics
if (rawDiagnostics.length > 0) {

MODIFY
internal/core/server/fs/Resolver.ts
internal/core/server/fs/Resolver.ts
@@ -294,7 +294,6 @@ function getPreferredMainKey(
if (alias !== undefined) {
return alias;
}
-
if (manifest.main !== undefined) {
return {
key: consumer.get("main"),

MODIFY
internal/core/server/project/ProjectManager.ts
internal/core/server/project/ProjectManager.ts
@@ -606,7 +606,6 @@ export default class ProjectManager {
diagnostics: DiagnosticsProcessor,
) {
const name = manifestNameToString(def.manifest.name);
-
const type = isProjectPackage ? "project package manifest" : "manifest";
this.logger.info(
markup`Declaring ${type} <emphasis>${name}</emphasis> in project <emphasis>#${project.id}</emphasis> in <emphasis>${def.directory}</emphasis>`,

MODIFY
internal/core/server/utils/getManifest.ts
internal/core/server/utils/getManifest.ts
@@ -12,12 +12,18 @@ export default async function getManifest(
const projects = await server.projectManager.getProjectHierarchyFromPath(
manifestPath,
);
+ let checkDependenciesAndLicense = false;
+ const mainProject = await server.projectManager.findLoadedProject(cwd);
+ if (mainProject) {
+ checkDependenciesAndLicense = mainProject.config.dependencies.enabled;
+ }
if (await manifestPath.exists()) {
- manifest = await normalizeManifest(
- manifestPath,
- json.consumeValue(await manifestPath.readFileTextMeta()),
+ manifest = await normalizeManifest({
+ path: manifestPath,
+ consumer: json.consumeValue(await manifestPath.readFileTextMeta()),
projects,
- );
+ checkDependenciesAndLicense,
+ });
}
return manifest;
}

MODIFY
internal/project/load.ts
internal/project/load.ts
@@ -334,7 +334,6 @@ export async function normalizeProjectConfig(
if (dependencies.has("enabled")) {
config.dependencies.enabled = dependencies.get("enabled").asBoolean();
}
-
if (dependencies.has("exceptions")) {
const exceptions = dependencies.get("exceptions").asMap();

feat(project): avoid validate manifest (#1615)