-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1041 from neon-bindings/create-neon-requires-proj…
…ect-type fix(create-neon): Explicit project type
- Loading branch information
Showing
11 changed files
with
438 additions
and
125 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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?.[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.