Skip to content

Commit 4dff419

Browse files
committed
squashing bugs: more clearly distinguish between when we're asking for the org, when we're asking for the base name of the package, and when we're asking for the fully qualified package name
also, bump the manifest version in create-neon so it recognizes prefixes
1 parent 8fef4fd commit 4dff419

File tree

7 files changed

+32
-28
lines changed

7 files changed

+32
-28
lines changed

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkgs/create-neon/data/templates/manifest/base/default.json.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
{
3-
"name": "{{options.name}}",
3+
"name": "{{options.fullName}}",
44
"version": "{{options.version}}",
55
"main": "index.node",
66
"scripts": {},

pkgs/create-neon/data/templates/manifest/base/library.json.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
{
3-
"name": "{{options.name}}",
3+
"name": "{{options.fullName}}",
44
"version": "{{options.version}}",
55
{{#eq options.library.module compare="esm"}}
66
"exports": {

pkgs/create-neon/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"typescript": "^5.3.2"
4949
},
5050
"dependencies": {
51-
"@neon-rs/manifest": "^0.1.0",
51+
"@neon-rs/manifest": "^0.2.1",
5252
"chalk": "^5.3.0",
5353
"command-line-args": "^5.2.1",
5454
"command-line-usage": "^7.0.1",

pkgs/create-neon/src/bin/create-neon.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ try {
4040
}
4141

4242
const [pkg] = opts._unknown;
43-
const { org, name } = /^(@(?<org>[^/]+)\/)?(?<name>.*)/.exec(pkg)?.groups as {
43+
const { org, basename } = /^((?<org>@[^/]+)\/)?(?<basename>.*)/.exec(pkg)?.groups as {
4444
org: string;
45-
name: string;
45+
basename: string;
4646
};
47+
const fullName = org ? `${org}/${basename}` : basename;
4748
const platforms = parsePlatforms(opts.platform);
48-
const cache = parseCache(opts.lib, opts.bins, name, org);
49+
const cache = parseCache(opts.lib, opts.bins, basename, org);
4950
const ci = parseCI(opts.ci);
5051

5152
if (opts.yes) {
@@ -54,7 +55,8 @@ try {
5455

5556
createNeon({
5657
org,
57-
name,
58+
basename,
59+
fullName,
5860
version: "0.1.0",
5961
library: opts.lib
6062
? {
@@ -120,7 +122,7 @@ function parseCache(
120122
pkg: string,
121123
org: string | undefined
122124
): Cache | undefined {
123-
let prefix = org ? `${pkg}-` : "";
125+
const defaultPrefix = org ? `${pkg}-` : "";
124126
org ??= `@${pkg}`;
125127
126128
// CASE: npm create neon -- --app logos-r-us
@@ -140,7 +142,7 @@ function parseCache(
140142
// - lib: `@acme/logo-generator`
141143
// - bin: `@acme/logo-generator-darwin-arm64`
142144
if (bins === "none" || bins === "npm") {
143-
return new NPM(org, prefix);
145+
return new NPM(org, defaultPrefix);
144146
}
145147
146148
// CASE: npm create neon -- --lib --bins=npm:acme logo-generator
@@ -156,8 +158,9 @@ function parseCache(
156158
// bin: @acme-libs/logo-generator-darwin-arm64
157159
if (bins.startsWith("npm:")) {
158160
const split = bins.substring(4).split("/", 2);
159-
160-
return new NPM(split[0], split.length > 1 ? split[1] : prefix);
161+
const org = split[0].replace(/^@?/, '@'); // don't care if they include the @ or not
162+
const prefix = split.length > 1 ? split[1] : defaultPrefix;
163+
return new NPM(org, prefix);
161164
}
162165
163166
throw new Error(

pkgs/create-neon/src/create/creator.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export type LibraryOptions = {
3030

3131
export type ProjectOptions = {
3232
org?: string | undefined;
33-
name: string;
33+
basename: string;
34+
fullName: string;
3435
version: string;
3536
library: LibraryOptions | null;
3637
app: boolean | null;
@@ -65,12 +66,12 @@ export abstract class Creator {
6566
async create(cx: Context): Promise<void> {
6667
try {
6768
this._temp = await mktemp();
68-
this._tempPkg = path.join(this._temp, this._options.name);
69+
this._tempPkg = path.join(this._temp, this._options.basename);
6970

7071
await fs.mkdir(this._tempPkg);
7172
} catch (err: any) {
7273
await die(
73-
`Could not create \`${this._options.name}\`: ${err.message}`,
74+
`Could not create \`${this._options.basename}\`: ${err.message}`,
7475
this._temp
7576
);
7677
}
@@ -123,11 +124,11 @@ export abstract class Creator {
123124
await this.createNeonBoilerplate(cx);
124125

125126
try {
126-
await fs.rename(this._tempPkg, this._options.name);
127+
await fs.rename(this._tempPkg, this._options.basename);
127128
await fs.rmdir(this._temp);
128129
} catch (err: any) {
129130
await die(
130-
`Could not create \`${this._options.name}\`: ${err.message}`,
131+
`Could not create \`${this._options.basename}\`: ${err.message}`,
131132
this._tempPkg
132133
);
133134
}

pkgs/create-neon/src/index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,21 @@ async function askProjectType(options: ProjectOptions) {
5858

5959
const org =
6060
cache === "npm"
61-
? await dialog.ask({
61+
? (await dialog.ask({
6262
prompt: "cache org",
6363
parse: (v: string): string => v,
64-
default: `@${options.org ?? options.name}`,
65-
})
64+
default: `@${options.org ?? options.basename}`,
65+
})).replace(/^@?/, "@") // don't care if they include the @ or not
6666
: null;
6767

6868
const prefix =
69-
cache === "npm" && org === `@${options.name}`
69+
cache === "npm" && org === `@${options.basename}`
7070
? ""
7171
: cache === "npm"
7272
? await dialog.ask({
7373
prompt: "cache prefix",
7474
parse: (v: string): string => v,
75-
default: `${options.name}-`,
75+
default: `${options.basename}-`,
7676
})
7777
: null;
7878

@@ -99,9 +99,9 @@ async function askProjectType(options: ProjectOptions) {
9999

100100
export async function createNeon(options: ProjectOptions): Promise<void> {
101101
try {
102-
await assertCanMkdir(options.name);
102+
await assertCanMkdir(options.basename);
103103
} catch (err: any) {
104-
await die(`Could not create \`${options.name}\`: ${err.message}`);
104+
await die(`Could not create \`${options.basename}\`: ${err.message}`);
105105
}
106106

107107
const cx = new Context(options);
@@ -124,6 +124,6 @@ export async function createNeon(options: ProjectOptions): Promise<void> {
124124
await creator.create(cx);
125125

126126
console.log(
127-
`✨ Created Neon project \`${options.name}\`. Happy 🦀 hacking! ✨`
127+
`✨ Created Neon project \`${options.fullName}\`. Happy 🦀 hacking! ✨`
128128
);
129129
}

0 commit comments

Comments
 (0)