Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/address-book/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"directory": "packages/address-book"
},
"exports": {
"./horizon/addresses.json": "./src/horizon/addresses.json",
"./issuance/addresses.json": "./src/issuance/addresses.json",
"./subgraph-service/addresses.json": "./src/subgraph-service/addresses.json"
"./*/addresses.json": "./src/*/addresses.json"
},
"files": [
"src/**/*.json",
Expand Down
69 changes: 27 additions & 42 deletions packages/address-book/scripts/copy-addresses-for-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,52 @@
/**
* Copy Addresses for Publishing
*
* This script copies the actual addresses.json files from horizon and subgraph-service
* packages to replace the symlinks before npm publish.
*
* Why we need this:
* - Development uses symlinks (committed to git) for convenience
* - npm publish doesn't include symlinks in the published package
* - We need actual files in the published package for consumers
*
* The postpublish script will restore the symlinks after publishing.
* Replaces the dev-time symlinks under src/<name>/addresses.json with real
* file copies before npm publish — npm does not include symlinks in the
* published tarball. restore-symlinks.js puts the symlinks back afterwards.
*/

const fs = require('fs')
const path = require('path')
const SOURCES = require('./sources')

const FILES_TO_COPY = [
{
source: '../../../horizon/addresses.json',
target: 'src/horizon/addresses.json',
},
{
source: '../../../issuance/addresses.json',
target: 'src/issuance/addresses.json',
},
{
source: '../../../subgraph-service/addresses.json',
target: 'src/subgraph-service/addresses.json',
},
]
const ROOT = path.resolve(__dirname, '..')
const SRC = path.join(ROOT, 'src')

function copyFileForPublish(source, target) {
const targetPath = path.resolve(__dirname, '..', target)
const sourcePath = path.resolve(path.dirname(targetPath), source)
function copyOne(name) {
const sourcePath = path.resolve(ROOT, '..', name, 'addresses.json')
const targetDir = path.join(SRC, name)
const targetPath = path.join(targetDir, 'addresses.json')

// Ensure source exists
if (!fs.existsSync(sourcePath)) {
console.error(`❌ Source file ${sourcePath} does not exist`)
process.exit(1)
}

// Remove existing symlink
if (fs.existsSync(targetPath)) {
fs.unlinkSync(targetPath)
}
fs.mkdirSync(targetDir, { recursive: true })
fs.rmSync(targetPath, { force: true })
fs.copyFileSync(sourcePath, targetPath)
console.log(`✅ Copied for publish: src/${name}/addresses.json`)
}

// Copy actual file
try {
fs.copyFileSync(sourcePath, targetPath)
console.log(`✅ Copied for publish: ${target} <- ${source}`)
} catch (error) {
console.error(`❌ Failed to copy ${source} to ${target}:`, error.message)
function checkDrift() {
const dirs = fs
.readdirSync(SRC)
.filter((d) => fs.statSync(path.join(SRC, d)).isDirectory())
.sort()
const expected = [...SOURCES].sort()
if (JSON.stringify(dirs) !== JSON.stringify(expected)) {
console.error(`❌ Drift between SOURCES and src/`)
console.error(` SOURCES: [${expected.join(', ')}]`)
console.error(` src/ : [${dirs.join(', ')}]`)
process.exit(1)
}
}

function main() {
console.log('📦 Copying address files for npm publish...')

for (const { source, target } of FILES_TO_COPY) {
copyFileForPublish(source, target)
}

for (const name of SOURCES) copyOne(name)
checkDrift()
console.log('✅ Address files copied for publish!')
}

Expand Down
52 changes: 15 additions & 37 deletions packages/address-book/scripts/restore-symlinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,32 @@
/**
* Restore Symlinks After Publishing
*
* This script restores the symlinks after npm publish completes.
* The prepublishOnly script replaces symlinks with actual files for publishing,
* and this script puts the symlinks back for development.
* Restores the dev-time symlinks under src/<name>/addresses.json after
* npm publish. copy-addresses-for-publish.js replaces them with real files
* for the publish step; this puts them back.
*/

const fs = require('fs')
const path = require('path')
const SOURCES = require('./sources')

const SYMLINKS_TO_RESTORE = [
{
target: '../../../horizon/addresses.json',
link: 'src/horizon/addresses.json',
},
{
target: '../../../issuance/addresses.json',
link: 'src/issuance/addresses.json',
},
{
target: '../../../subgraph-service/addresses.json',
link: 'src/subgraph-service/addresses.json',
},
]
const ROOT = path.resolve(__dirname, '..')
const SRC = path.join(ROOT, 'src')

function restoreSymlink(target, link) {
const linkPath = path.resolve(__dirname, '..', link)
function restoreOne(name) {
const linkTarget = `../../../${name}/addresses.json`
const linkDir = path.join(SRC, name)
const linkPath = path.join(linkDir, 'addresses.json')

// Remove the copied file
if (fs.existsSync(linkPath)) {
fs.unlinkSync(linkPath)
}

// Restore symlink
try {
fs.symlinkSync(target, linkPath)
console.log(`✅ Restored symlink: ${link} -> ${target}`)
} catch (error) {
console.error(`❌ Failed to restore symlink ${link}:`, error.message)
process.exit(1)
}
fs.mkdirSync(linkDir, { recursive: true })
fs.rmSync(linkPath, { force: true })
fs.symlinkSync(linkTarget, linkPath)
console.log(`✅ Restored symlink: src/${name}/addresses.json -> ${linkTarget}`)
}

function main() {
console.log('🔗 Restoring symlinks after publish...')

for (const { target, link } of SYMLINKS_TO_RESTORE) {
restoreSymlink(target, link)
}

for (const name of SOURCES) restoreOne(name)
console.log('✅ Symlinks restored!')
}

Expand Down
4 changes: 4 additions & 0 deletions packages/address-book/scripts/sources.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Source packages exported from @graphprotocol/address-book.
// Each name corresponds to packages/<name>/addresses.json (source of truth)
// and packages/address-book/src/<name>/addresses.json (publish symlink).
Comment thread
RembrandtK marked this conversation as resolved.
module.exports = ['horizon', 'issuance', 'subgraph-service']