diff --git a/src/manifest/fixtures/empty-platforms-with-prefix/package.json b/src/manifest/fixtures/empty-platforms-with-prefix/package.json new file mode 100644 index 00000000..f422084a --- /dev/null +++ b/src/manifest/fixtures/empty-platforms-with-prefix/package.json @@ -0,0 +1,55 @@ +{ + "name": "empty-platforms-with-prefix", + "private": false, + "version": "0.1.17", + "description": "A simple Neon library with a prefix and no platforms.", + "type": "module", + "exports": { + ".": { + "import": { + "types": "./types/index.d.mts", + "default": "./lib/index.mjs" + }, + "require": { + "types": "./types/index.d.cts", + "default": "./lib/index.cjs" + } + } + }, + "types": "./types/index.d.cts", + "main": "./lib/index.cjs", + "files": [ + "lib/index.cjs", + "lib/load.cjs", + "lib/index.mjs", + "types/index.d.cts", + "types/index.d.mts" + ], + "scripts": { + "test": "cargo test", + "cargo-build": "cargo build --message-format=json > cargo.log", + "cross-build": "cross build --message-format=json > cross.log", + "postcargo-build": "neon dist -v < cargo.log", + "postcross-build": "neon dist -v -m /target < cross.log", + "debug": "npm run cargo-build --", + "build": "npm run cargo-build -- --release", + "cross": "npm run cross-build -- --release", + "prepack": "neon update-platforms -v 2>update-platforms.log", + "version": "neon bump -v --binaries platforms" + }, + "author": "David Herman ", + "license": "MIT", + "devDependencies": { + "@neon-rs/cli": "^0.0.186" + }, + "dependencies": { + "@neon-rs/load": "^0.0.186" + }, + "neon": { + "type": "library", + "org": "@dherman", + "prefix": "empty-platforms-with-prefix-", + "platforms": {}, + "load": "./lib/load.cjs" + } +} diff --git a/src/manifest/package.json b/src/manifest/package.json index eb511daa..30f0344c 100644 --- a/src/manifest/package.json +++ b/src/manifest/package.json @@ -1,7 +1,7 @@ { "name": "@neon-rs/manifest", "private": false, - "version": "0.1.3", + "version": "0.2.0", "description": "Library for working with Neon package configuration.", "exports": { ".": { diff --git a/src/manifest/src/cache/npm/npm.cts b/src/manifest/src/cache/npm/npm.cts index 8806bb4b..42fba5c6 100644 --- a/src/manifest/src/cache/npm/npm.cts +++ b/src/manifest/src/cache/npm/npm.cts @@ -111,7 +111,7 @@ export class NPMCacheCfg implements CacheCfg { [], js.callExpression( js.identifier('require'), - [js.literal(`${cfg.org}/${platform}`)] + [js.literal(`${cfg.org}/${cfg.prefix ?? ''}${platform}`)] ) ) ); @@ -123,7 +123,7 @@ export class NPMCacheCfg implements CacheCfg { packageNames(): string[] { const cfg = this.manifest.cfg(); - return Object.keys(this.manifest.allPlatforms()).map(key => `${cfg.org}/${key}`); + return Object.keys(this.manifest.allPlatforms()).map(key => `${cfg.org}/${cfg.prefix ?? ''}${key}`); } updatePlatforms(lib: LibraryManifest): boolean { diff --git a/src/manifest/src/library/library.cts b/src/manifest/src/library/library.cts index 7625f42c..e2e8d40c 100644 --- a/src/manifest/src/library/library.cts +++ b/src/manifest/src/library/library.cts @@ -8,6 +8,7 @@ import { NPMCacheCfg } from "../cache/npm/npm.cjs"; export interface LibraryCfg { type: "library"; org: string; + prefix?: string; platforms: PlatformFamily; load?: string; } @@ -26,6 +27,11 @@ function assertIsLibraryCfg(json: unknown): asserts json is LibraryCfg { throw new TypeError(`expected "neon.load" to be a string, found ${json.load}`); } } + if ('prefix' in json) { + if (typeof json.prefix !== 'string' && typeof json.prefix !== 'undefined') { + throw new TypeError(`expected "neon.prefix" to be a string, found ${json.prefix}`); + } + } } function isEmptyFamily(family: PlatformFamily): boolean { diff --git a/src/manifest/src/test/manifest.cts b/src/manifest/src/test/manifest.cts index 721eea5b..b10c2f13 100644 --- a/src/manifest/src/test/manifest.cts +++ b/src/manifest/src/test/manifest.cts @@ -34,6 +34,12 @@ describe("simple manifest", () => { assert.strictEqual(lib.version, '0.1.17'); }); + async function testPrefixPlatforms(lib: LibraryManifest, name: string, prefix: string, version: string) { + const contents = await fs.readFile(path.join(lib.dir, 'lib', 'load.cjs'), 'utf8'); + assert.include(contents, `'darwin-arm64': () => require('@${name}/${prefix}darwin-arm64')`); + assert.include(contents, `'darwin-x64': () => require('@${name}/${prefix}darwin-x64')`); + } + async function testEmptyPlatforms(lib: LibraryManifest, name: string, version: string) { await lib.addNodePlatform('darwin-arm64'); assert.isTrue(lib.hasUnsavedChanges()); @@ -92,4 +98,14 @@ describe("simple manifest", () => { const json: any = lib.toJSON(); assert.strictEqual(json.optionalDependencies['@empty-object-platforms/darwin-arm64'], lib.version); }); + + it("handles prefixes", async () => { + const lib = await library('empty-platforms-with-prefix'); + await lib.addPlatformPreset('macos'); + await lib.saveChanges(() => {}); + const reloaded = await LibraryManifest.load(lib.dir); + assert.strictEqual(reloaded.cfg().platforms, 'macos'); + assert.strictEqual(reloaded.cfg().prefix, 'empty-platforms-with-prefix-'); + assert.strictEqual(reloaded.cfg().org, '@dherman'); + }); }); diff --git a/src/package.json b/src/package.json index 68f64b50..ba09244a 100644 --- a/src/package.json +++ b/src/package.json @@ -5,14 +5,16 @@ "version": "0.1.81", "workspaces": [ "cli", - "install" + "install", + "manifest" ], "author": "Dave Herman ", "license": "MIT", "scripts": { - "dist": "npm run dist:cli && npm run dist:install", + "dist": "npm run dist:cli && npm run dist:install && npm run dist:manifest", "dist:cli": "cd cli && npm run dist", "dist:install": "cd install && npm run dist", + "dist:manifest": "cd manifest && npm run dist", "version": "node ../dist/cli bump -v --workspaces" }, "dependencies": {