-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
185 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,3 +77,10 @@ test/fixture/functions | |
|
||
.pnpm-store | ||
.wrangler | ||
|
||
# mirror pkg | ||
.mirror | ||
|
||
# Generated types | ||
*.d.ts | ||
!runtime-meta.d.ts |
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 was deleted.
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 was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export const pkgDir: string; | ||
export const runtimeDir: string; | ||
export const subpaths: string[]; | ||
export const runtimeDependencies: string[]; | ||
export declare const pkgDir: string; | ||
export declare const runtimeDir: string; | ||
export declare const subpaths: string[]; | ||
export declare const runtimeDependencies: string[]; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { subpaths } from "../build.config"; | ||
import { fileURLToPath } from "mlly"; | ||
import { PackageJson, readPackageJSON } from "pkg-types"; | ||
import { writeFile, mkdir, rm, cp } from "node:fs/promises"; | ||
import { join } from "pathe"; | ||
import { e } from "crossws/dist/shared/crossws.381454fe"; | ||
|
||
const copyPkgFields = [ | ||
"description", | ||
"keywords", | ||
"repository", | ||
"license", | ||
"type", | ||
"exports", | ||
"main", | ||
"types", | ||
"bin", | ||
"files", | ||
]; | ||
|
||
const copyFiles = ["README.md", "LICENSE"]; | ||
|
||
async function main() { | ||
// Dirs | ||
const mainDir = fileURLToPath(new URL("..", import.meta.url)); | ||
const mirrorDir = fileURLToPath(new URL("../.mirror", import.meta.url)); | ||
await rm(mirrorDir, { recursive: true }).catch(() => {}); | ||
await mkdir(mirrorDir, { recursive: true }); | ||
|
||
// Read main package | ||
const mainPkg = await readPackageJSON(mainDir); | ||
|
||
// Check for nightly | ||
const isNightly = mainPkg.name!.includes("nightly"); | ||
|
||
// Mirror nitro<>nitropack | ||
const mirrrorPkgName = mainPkg.name!.includes("pack") | ||
? mainPkg.name!.replace("pack", "") | ||
: mainPkg.name!.replace("nitro", "nitropack"); | ||
|
||
// Canonical name for main pkg (without -nightly suffix) | ||
const canonicalName = mainPkg.name!.replace("-nightly", ""); | ||
|
||
// Copy package.json fields | ||
const mirrorPkg: PackageJson = { | ||
name: mirrrorPkgName, | ||
version: `${mainPkg.version}-${mainPkg.name}-mirror`, | ||
dependencies: {}, | ||
}; | ||
|
||
// Add dependency | ||
if (isNightly) { | ||
mirrorPkg.dependencies![canonicalName] = | ||
`npm:${mainPkg.name}@${mainPkg.version}`; | ||
} else { | ||
mirrorPkg.dependencies![canonicalName] = `${mainPkg.version}`; | ||
} | ||
|
||
for (const field of copyPkgFields) { | ||
if (mainPkg[field]) { | ||
mirrorPkg[field] = mainPkg[field]; | ||
} | ||
} | ||
await writeFile( | ||
join(mirrorDir, "package.json"), | ||
JSON.stringify(mirrorPkg, null, 2) | ||
); | ||
|
||
// Generate subpath re-exports | ||
for (const subpath of subpaths) { | ||
await mkdir(join(mirrorDir, "dist", subpath), { recursive: true }); | ||
await writeFile( | ||
join(mirrorDir, "dist", subpath, "index.mjs"), | ||
`export * from "${canonicalName}/${subpath}";` | ||
); | ||
await writeFile( | ||
join(mirrorDir, "dist", subpath, "index.d.ts"), | ||
`export * from "${canonicalName}/${subpath}";` | ||
); | ||
await writeFile( | ||
join(mirrorDir, "dist", subpath, "index.d.mts"), | ||
`export * from "${canonicalName}/${subpath}";` | ||
); | ||
await writeFile( | ||
join(mirrorDir, `${subpath}.d.ts`), | ||
`export * from "./dist/${subpath}";` | ||
); | ||
} | ||
|
||
// Runtime Meta | ||
await writeFile( | ||
join(mirrorDir, "runtime-meta.mjs"), | ||
`export * from "${canonicalName}/runtime/meta";` | ||
); | ||
await writeFile( | ||
join(mirrorDir, "runtime-meta.d.ts"), | ||
`export * from "${canonicalName}/runtime/meta";` | ||
); | ||
|
||
// Other files | ||
for (const file of copyFiles) { | ||
await cp(join(mainDir, file), join(mirrorDir, file)); | ||
} | ||
} | ||
|
||
// eslint-disable-next-line unicorn/prefer-top-level-await | ||
main(); |
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
This file was deleted.
Oops, something went wrong.