-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
require user to specify the Neon project type:
- either by passing --app or --lib - or by interactive dialog via stdin
- Loading branch information
Showing
9 changed files
with
394 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import { Cache } from "../cache.js"; | ||
|
||
export class NPM implements Cache { | ||
readonly org: string | null; | ||
readonly org: string; | ||
|
||
readonly type: string = "npm"; | ||
|
||
constructor(org: string | null) { | ||
this.org = org; | ||
constructor(pkg: string, org?: string) { | ||
this.org = org || NPM.inferOrg(pkg); | ||
} | ||
|
||
static inferOrg(pkg: string): string { | ||
const m = pkg.match(/^@([^/]+)\/([^/]+)/); | ||
return "@" + (m ? m[1] : pkg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as fs from 'node:fs/promises'; | ||
import * as path from 'node:path'; | ||
import { existsSync, rmSync } from 'node:fs'; | ||
|
||
export async function assertCanMkdir(dir: string) { | ||
// pretty lightweight way to check both that folder doesn't exist and | ||
// that the user has write permissions. | ||
await fs.mkdir(dir); | ||
await fs.rmdir(dir); | ||
} | ||
|
||
export async function mktemp(): Promise<string> { | ||
const tmpFolderName = await fs.mkdtemp("neon-"); | ||
const tmpFolderAbsPath = path.join(process.cwd(), tmpFolderName); | ||
function cleanupTmp() { | ||
try { | ||
if (existsSync(tmpFolderAbsPath)) { | ||
rmSync(tmpFolderAbsPath, { recursive: true }); | ||
} | ||
} catch (e) { | ||
console.error(`warning: could not delete ${tmpFolderName}: ${e}`); | ||
} | ||
} | ||
process.on('exit', cleanupTmp); | ||
process.on('SIGINT', cleanupTmp); | ||
process.on('uncaughtException', cleanupTmp); | ||
return tmpFolderName; | ||
} |
Oops, something went wrong.