-
Notifications
You must be signed in to change notification settings - Fork 20
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
30 changed files
with
189 additions
and
159 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"porto": patch | ||
--- | ||
|
||
Modified `porto/wagmi` entrypoint to export `Actions`, `Hooks`, and `Query` modules. |
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 |
---|---|---|
|
@@ -41,7 +41,3 @@ out | |
# vercel | ||
.vercel | ||
|
||
# proxy packages | ||
src/Chains | ||
src/Porto | ||
src/wagmi |
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,67 +1,55 @@ | ||
import { mkdir, readFile, readdir, rm, symlink } from 'node:fs/promises' | ||
import { basename, dirname, join, resolve } from 'node:path' | ||
|
||
// Symlinks package sources to dist for local development | ||
import * as fs from 'node:fs' | ||
import { basename, dirname, resolve } from 'node:path' | ||
import { getExports } from './utils/exports.js' | ||
|
||
// biome-ignore lint/suspicious/noConsoleLog: | ||
console.log('Setting up packages for development.') | ||
|
||
const packagePath = resolve(import.meta.dirname, '../src/package.json') | ||
type Package = { | ||
bin?: Record<string, string> | undefined | ||
exports: Record<string, { types: string; default: string } | string> | ||
name?: string | undefined | ||
private?: boolean | undefined | ||
} | ||
const packageJson = JSON.parse(await readFile(packagePath, 'utf8')) as Package | ||
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf-8')) | ||
|
||
// biome-ignore lint/suspicious/noConsoleLog: | ||
console.log(`${packageJson.name} — ${dirname(packagePath)}`) | ||
|
||
const dir = resolve(dirname(packagePath)) | ||
|
||
// Empty dist directories | ||
const distDirName = '_dist' | ||
const dist = resolve(dir, distDirName) | ||
let files: string[] = [] | ||
try { | ||
files = await readdir(dist) | ||
} catch { | ||
await mkdir(dist) | ||
} | ||
fs.rmSync(resolve(dir, '_dist'), { recursive: true, force: true }) | ||
|
||
const promises = [] | ||
for (const file of files) { | ||
promises.push(rm(join(dist, file), { recursive: true, force: true })) | ||
} | ||
await Promise.all(promises) | ||
const exports = getExports() | ||
|
||
// Link exports to dist locations | ||
for (const [key, exports] of Object.entries(packageJson.exports)) { | ||
for (const [key, distExports] of Object.entries(exports.dist ?? {})) { | ||
// Skip `package.json` exports | ||
if (/package\.json$/.test(key)) continue | ||
if (typeof exports === 'string') continue | ||
|
||
let entries: any | ||
if (typeof distExports === 'string') | ||
entries = [ | ||
['default', distExports], | ||
['types', distExports.replace('.js', '.d.ts')], | ||
] | ||
else entries = Object.entries(distExports as {}) | ||
|
||
// Link exports to dist locations | ||
for (const [_, value] of Object.entries(exports) as [ | ||
for (const [, value] of entries as [ | ||
type: 'types' | 'default', | ||
value: string, | ||
][]) { | ||
const srcDir = resolve(dir, dirname(value).replace(distDirName, '')) | ||
let srcFileName: string | ||
if (key === '.') srcFileName = 'index.ts' | ||
else { | ||
srcFileName = basename(`${key}.ts`) | ||
} | ||
const srcFilePath = resolve(srcDir, srcFileName) | ||
const srcFilePath = resolve(dir, exports.src[key]!) | ||
|
||
const distDir = resolve(dir, dirname(value)) | ||
const distFileName = basename(value) | ||
const distFilePath = resolve(distDir, distFileName) | ||
|
||
await mkdir(distDir, { recursive: true }) | ||
fs.mkdirSync(distDir, { recursive: true }) | ||
|
||
// Symlink src to dist file | ||
await symlink(srcFilePath, distFilePath, 'file') | ||
try { | ||
fs.symlinkSync(srcFilePath, distFilePath, 'file') | ||
} catch {} | ||
} | ||
} | ||
|
||
console.log('Done. Set up packages.') | ||
// biome-ignore lint/suspicious/noConsoleLog: | ||
console.log('Done.') |
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,38 +1,41 @@ | ||
import { mkdir, readFile, writeFile } from 'node:fs/promises' | ||
import { dirname, relative, resolve } from 'node:path' | ||
|
||
// Generates proxy packages for package.json#exports. | ||
|
||
console.log('Generating proxy packages.') | ||
|
||
const packagePath = resolve(import.meta.dirname, '../src/package.json') | ||
type Package = Record<string, unknown> & { | ||
name?: string | undefined | ||
private?: boolean | undefined | ||
exports: Record<string, { types: string; default: string } | string> | ||
} | ||
const packageJson = JSON.parse(await readFile(packagePath, 'utf8')) as Package | ||
|
||
console.log(`${packageJson.name} — ${dirname(packagePath)}`) | ||
|
||
const dir = resolve(dirname(packagePath)) | ||
|
||
for (const [key, exports] of Object.entries(packageJson.exports)) { | ||
// Skip `package.json` export | ||
if (/package\.json$/.test(key)) continue | ||
if (key === '.') continue | ||
if (typeof exports === 'string') continue | ||
if (!exports.default) continue | ||
|
||
const proxyDir = resolve(dir, key) | ||
await mkdir(proxyDir, { recursive: true }) | ||
|
||
const types = relative(key, exports.types) | ||
const main = relative(key, exports.default) | ||
await writeFile( | ||
`${proxyDir}/package.json`, | ||
`${JSON.stringify({ type: 'module', types, main }, undefined, 2)}\n`, | ||
) | ||
} | ||
|
||
console.log('Done. Generated proxy packages.') | ||
import * as fs from 'node:fs' | ||
import { join, relative, resolve } from 'node:path' | ||
import { getExports } from './utils/exports.js' | ||
|
||
const packageJsonPath = join(import.meta.dirname, '../src/package.json') | ||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')) | ||
|
||
const exports = getExports({ | ||
onEntry: ({ entryName, name, parentEntryName }) => { | ||
const modulePath = (dist?: string) => { | ||
let path = './' | ||
if (dist) path += `${dist}/` | ||
if (dist || (parentEntryName && parentEntryName !== 'core')) | ||
path += `${parentEntryName}/` | ||
if (dist || name !== 'index') path += name | ||
return path | ||
} | ||
|
||
try { | ||
fs.mkdirSync(resolve(import.meta.dirname, '../src', entryName)) | ||
} catch {} | ||
fs.writeFileSync( | ||
resolve(import.meta.dirname, '../src', entryName, 'package.json'), | ||
JSON.stringify( | ||
{ | ||
type: 'module', | ||
types: relative(modulePath(), modulePath('_dist')) + '.d.ts', | ||
main: relative(modulePath(), modulePath('_dist')) + '.js', | ||
}, | ||
null, | ||
2, | ||
), | ||
) | ||
}, | ||
}) | ||
|
||
packageJson.exports = exports.dist | ||
|
||
delete packageJson.type | ||
|
||
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)) |
Oops, something went wrong.