Turn Manifest['name'] into an object
MODIFY
packages/@romejs/codec-js-manifest/convert.ts
packages/@romejs/codec-js-manifest/convert.ts
@@ -16,13 +16,14 @@ import {
import {stringifySemver} from '@romejs/codec-semver';
import {Dict} from '@romejs/typescript-helpers';
import {stringifyPathPattern} from '@romejs/path-match';
+import {manifestNameToString} from './name';
export function convertManifestToJSON(manifest: Manifest): JSONManifest {
return {
// Include unknown properties from the initial package.json
...manifest.raw,
- name: manifest.name,
+ name: manifestNameToString(manifest.name),
description: manifest.description,
private: manifest.private,
type: manifest.type,
@@ -136,8 +137,11 @@ function dependencyMapToObject(
}
const obj: Dict<string> = {};
- for (const [key, pattern] of map) {
+ for (const [name, pattern] of map) {
+ const key = manifestNameToString(name);
+ if (key !== undefined) {
obj[key] = stringifyDependencyPattern(pattern);
}
+ }
return obj;
}

MODIFY
packages/@romejs/codec-js-manifest/dependencies.ts
packages/@romejs/codec-js-manifest/dependencies.ts
@@ -16,6 +16,7 @@ import {createUnknownFilePath, UnknownFilePath} from '@romejs/path';
import {normalizeName} from './name';
import {ob1Add} from '@romejs/ob1';
import {descriptions} from '@romejs/diagnostics';
+import {ManifestName} from './types';
export type DependencyPattern =
| HostedGitPattern
@@ -27,7 +28,7 @@ export type DependencyPattern =
| NpmPattern
| LinkPattern;
-export type ManifestDependencies = Map<string, DependencyPattern>;
+export type ManifestDependencies = Map<ManifestName, DependencyPattern>;
type UrlWithHash = {
url: string;
@@ -284,7 +285,7 @@ const NPM_PREFIX = 'npm:';
type NpmPattern = {
type: 'npm';
- name: string;
+ name: ManifestName;
range: undefined | SemverRangeNode;
};
@@ -301,7 +302,10 @@ function parseNpm(
consumer.unexpected(descriptions.MANIFEST.EMPTY_NPM_PATTERN);
return {
type: 'npm',
- name: 'unknown',
+ name: {
+ org: undefined,
+ packageName: undefined,
+ },
range: undefined,
};
}
@@ -343,7 +347,7 @@ function parseNpm(
});
// Increase offset passed name
- offset += name.length;
+ offset += nameRaw.length;
offset++;
let range: undefined | SemverRangeNode;
@@ -450,9 +454,9 @@ export function normalizeDependencies(
return map;
}
- for (const [name, value] of consumer.asMap()) {
- normalizeName({
- name,
+ for (const [rawName, value] of consumer.asMap()) {
+ const name = normalizeName({
+ name: rawName,
loose,
unexpected: ({description, at}) => {
value.unexpected(description, {

MODIFY
packages/@romejs/codec-js-manifest/index.ts
packages/@romejs/codec-js-manifest/index.ts
@@ -18,6 +18,7 @@ import {
ManifestRepository,
ManifestExports,
ManifestExportConditions,
+ ManifestName,
} from './types';
import {tryParseWithOptionalOffsetPosition} from '@romejs/parser-core';
import {normalizeName} from './name';
@@ -34,6 +35,8 @@ export * from './types';
export * from './convert';
+export {manifestNameToString} from './name';
+
const TYPO_KEYS: Map<string, string> = new Map([
['autohr', 'author'],
['autor', 'author'],
@@ -526,9 +529,12 @@ function normalizeBugs(
}
}
-function normalizeRootName(consumer: Consumer, loose: boolean): MString {
+function normalizeRootName(consumer: Consumer, loose: boolean): ManifestName {
if (!consumer.has('name')) {
- return;
+ return {
+ packageName: undefined,
+ org: undefined,
+ };
}
const prop = consumer.get('name');
@@ -625,7 +631,7 @@ export async function normalizeManifest(
license: normalizeLicense(consumer, loose),
type: consumer.get('type').asStringSetOrVoid(['module', 'commonjs']),
- bin: normalizeBin(consumer, name, loose),
+ bin: normalizeBin(consumer, name.packageName, loose),
scripts: normalizeStringMap(consumer, 'scripts', loose),
homepage: normalizeString(consumer, 'homepage'),
repository: normalizeRepo(consumer.get('repository'), loose),

MODIFY
packages/@romejs/codec-js-manifest/name.ts
packages/@romejs/codec-js-manifest/name.ts
@@ -10,6 +10,7 @@ import {
DiagnosticDescriptionOptionalCategory,
descriptions,
} from '@romejs/diagnostics';
+import {ManifestName} from './types';
type NormalizeNameUnexpected = (opts: {
description: DiagnosticDescriptionOptionalCategory;
@@ -80,10 +81,23 @@ function validateNamePart(
return normalizedName;
}
-export function normalizeName(opts: NormalizeNameOptions): string {
+export function manifestNameToString(name: ManifestName): undefined | string {
+ const {packageName, org} = name;
+
+ if (org === undefined) {
+ return packageName;
+ }
+
+ return `@${org}/${packageName}`;
+}
+
+export function normalizeName(opts: NormalizeNameOptions): ManifestName {
const {unexpected} = opts;
let {name} = opts;
+ let org: undefined | string;
+ let packageName: undefined | string;
+
if (name.length > 214) {
unexpected({
at: 'prefix',
@@ -103,7 +117,7 @@ export function normalizeName(opts: NormalizeNameOptions): string {
if (name[0] === '@') {
// Validate org and package name separately
- const [org, packageName, ...other] = name.slice(1).split('/');
+ const [rawOrg, rawPackageName, ...other] = name.slice(1).split('/');
// Leading @
let offset: Number0 = ob1Coerce0(1);
@@ -112,19 +126,18 @@ export function normalizeName(opts: NormalizeNameOptions): string {
const sanitizedOrg = validateNamePart(opts, {
isOrg: true,
isOrgPart: true,
- name: org,
+ name: rawOrg,
offset,
});
- offset = ob1Add(offset, org.length);
+ offset = ob1Add(offset, rawOrg.length);
+ org = sanitizedOrg;
- if (packageName === undefined) {
+ if (rawPackageName === undefined) {
unexpected({
at: 'prefix',
description: descriptions.MANIFEST.ORG_WITH_NO_PACKAGE_NAME,
start: offset,
});
-
- name = `@${sanitizedOrg}/unknown`;
} else {
// Forward slashSeparator
offset = ob1Inc(offset);
@@ -133,10 +146,10 @@ export function normalizeName(opts: NormalizeNameOptions): string {
const sanitizedPackageName = validateNamePart(opts, {
isOrg: false,
isOrgPart: true,
- name: packageName,
+ name: rawPackageName,
offset,
});
- offset = ob1Add(offset, packageName.length);
+ offset = ob1Add(offset, rawPackageName.length);
// Complain on excess separators
if (other.length > 0) {
@@ -147,10 +160,10 @@ export function normalizeName(opts: NormalizeNameOptions): string {
});
}
- name = `@${sanitizedOrg}/${sanitizedPackageName}`;
+ packageName = sanitizedPackageName;
}
} else {
- name = validateNamePart(opts, {
+ packageName = validateNamePart(opts, {
name,
offset: ob1Number0,
isOrg: false,
@@ -158,5 +171,5 @@ export function normalizeName(opts: NormalizeNameOptions): string {
});
}
- return name;
+ return {org, packageName};
}

MODIFY
packages/@romejs/codec-js-manifest/types.ts
packages/@romejs/codec-js-manifest/types.ts
@@ -56,8 +56,13 @@ export type ManifestExportConditions = Map<string, {
relative: RelativeFilePath;
}>;
+export type ManifestName = {
+ org?: string;
+ packageName?: string;
+};
+
export type Manifest = {
- name: MString;
+ name: ManifestName;
description: MString;
version: undefined | SemverVersionNode;
license: undefined | SPDXExpressionNode;
@@ -88,7 +93,7 @@ export type Manifest = {
// Serialized version of a Manifest
export type JSONManifest = {
- name: Manifest['name'];
+ name: MString;
description: Manifest['description'];
version: MString;
license: MString;

MODIFY
packages/@romejs/core/master/fs/MemoryFileSystem.ts
packages/@romejs/core/master/fs/MemoryFileSystem.ts
@@ -10,6 +10,7 @@ import {
Manifest,
ManifestDefinition,
normalizeManifest,
+ manifestNameToString,
} from '@romejs/codec-js-manifest';
import {
PathPatterns,
@@ -895,7 +896,7 @@ export default class MemoryFileSystem {
// Set haste name and haste location to the directory itself
if (manifest.name !== undefined) {
- hasteName = manifest.name;
+ hasteName = manifestNameToString(manifest.name);
}
// If we aren't in node_modules then this is a project package

MODIFY
packages/@romejs/core/master/project/ProjectManager.ts
packages/@romejs/core/master/project/ProjectManager.ts
@@ -32,7 +32,10 @@ import {
descriptions,
} from '@romejs/diagnostics';
import {matchPathPatterns} from '@romejs/path-match';
-import {ManifestDefinition} from '@romejs/codec-js-manifest';
+import {
+ ManifestDefinition,
+ manifestNameToString,
+} from '@romejs/codec-js-manifest';
import {
AbsoluteFilePath,
UnknownFilePath,
@@ -304,7 +307,7 @@ export default class ProjectManager {
if (pkg === undefined || pkg.folder.equal(project.folder)) {
break;
} else {
- const name = pkg.manifest.name;
+ const name = manifestNameToString(pkg.manifest.name);
if (name !== undefined) {
parts.unshift(name);
@@ -654,7 +657,7 @@ export default class ProjectManager {
def: ManifestDefinition,
diagnostics: DiagnosticsProcessor,
) {
- const {name} = def.manifest;
+ const name = manifestNameToString(def.manifest.name);
// Declare this package in all projects
const projects = this.getHierarchyFromProject(project);

Turn Manifest['name'] into an object