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
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
]
},
"scripts": {
"postinstall": "husky install && preconstruct dev",
"postinstall": "node scripts/postinstall.js",
"build": "preconstruct build",
"watch": "preconstruct watch",
"dev": "preconstruct dev",
Expand Down Expand Up @@ -94,7 +94,6 @@
"eslint-plugin-react-hooks": "^4.3.0",
"husky": "^7.0.4",
"patch-package": "^6.4.7",
"postinstall-postinstall": "^2.1.0",
"prettier": "^2.5.1",
"pretty-quick": "^3.1.3",
"react": "^18.0.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/leva/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
"main": "dist/leva.cjs.js",
"module": "dist/leva.esm.js",
"types": "dist/leva.cjs.d.ts",
"files": [
"dist",
"src",
"plugin"
],
"scripts": {
"prepare": "node ../../scripts/prepare-package.js"
},
"license": "MIT",
"repository": {
"type": "git",
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-bezier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"main": "dist/leva-ui-plugin-bezier.cjs.js",
"module": "dist/leva-ui-plugin-bezier.esm.js",
"types": "dist/leva-ui-plugin-bezier.cjs.d.ts",
"files": [
"dist",
"src"
],
"scripts": {
"prepare": "node ../../scripts/prepare-package.js"
},
"license": "MIT",
"repository": {
"type": "git",
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-dates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"main": "dist/leva-ui-plugin-dates.cjs.js",
"module": "dist/leva-ui-plugin-dates.esm.js",
"types": "dist/leva-ui-plugin-dates.cjs.d.ts",
"files": [
"dist",
"src"
],
"scripts": {
"prepare": "node ../../scripts/prepare-package.js"
},
"license": "MIT",
"repository": {
"type": "git",
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-plot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"main": "dist/leva-ui-plugin-plot.cjs.js",
"module": "dist/leva-ui-plugin-plot.esm.js",
"types": "dist/leva-ui-plugin-plot.cjs.d.ts",
"files": [
"dist",
"src"
],
"scripts": {
"prepare": "node ../../scripts/prepare-package.js"
},
"license": "MIT",
"repository": {
"type": "git",
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-spring/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"main": "dist/leva-ui-plugin-spring.cjs.js",
"module": "dist/leva-ui-plugin-spring.esm.js",
"types": "dist/leva-ui-plugin-spring.cjs.d.ts",
"files": [
"dist",
"src"
],
"scripts": {
"prepare": "node ../../scripts/prepare-package.js"
},
"license": "MIT",
"repository": {
"type": "git",
Expand Down
51 changes: 51 additions & 0 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const { execSync } = require('child_process')
const { existsSync } = require('fs')

// Skip if explicitly disabled
if (process.env.SKIP_BUILD === '1' || process.env.SKIP_POSTINSTALL === '1') {
process.exit(0)
}

// Detect if this is a git install via pnpm's synthetic script names
// pnpm creates 'npm-install', 'yarn-install', or 'pnpm-install' scripts
// ONLY when preparing git dependencies
const lifecycleEvent = process.env.npm_lifecycle_event

// Detect git install via pnpm's store tmp directory pattern
// pnpm prepares git dependencies in /pnpm/store/v{version}/tmp/
const cwd = process.cwd()
const isPnpmStoreTmp = /[/\\]pnpm[/\\]store[/\\]v\d+[/\\]tmp[/\\]/.test(cwd)

const isGitInstall =
lifecycleEvent === 'npm-install' ||
lifecycleEvent === 'yarn-install' ||
lifecycleEvent === 'pnpm-install' ||
isPnpmStoreTmp

// Skip if installed as sub-dependency in local development
// (Don't skip for git installs - the ../../package.json would be the consuming project)
if (!isGitInstall) {
const isSubDependency = existsSync('../../package.json')
if (isSubDependency) {
process.exit(0)
}
}

if (isGitInstall) {
// Git install: build production files
console.log('Building Leva for GitHub installation...')
try {
execSync('npx preconstruct build', { stdio: 'inherit' })
} catch (e) {
console.error('Build failed:', e.message)
process.exit(1)
}
} else {
// Local development: use dev mode for fast linking
try {
execSync('npx preconstruct dev', { stdio: 'inherit' })
} catch (e) {
console.error('Failed to run preconstruct dev:', e.message)
process.exit(1)
}
}
35 changes: 35 additions & 0 deletions scripts/prepare-package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { execSync } = require('child_process')
const { existsSync } = require('fs')
const path = require('path')

// Skip if explicitly disabled
if (process.env.SKIP_BUILD === '1') {
process.exit(0)
}

const lifecycleEvent = process.env.npm_lifecycle_event

// Git install: synthetic events from pnpm/npm/yarn
const isGitInstall =
lifecycleEvent === 'npm-install' || lifecycleEvent === 'yarn-install' || lifecycleEvent === 'pnpm-install'

// Publishing: prepare runs before pack/publish
// When running from a package, go up to workspace root
// process.cwd() is the package directory (e.g., packages/leva)
const workspaceRoot = path.resolve(process.cwd(), '../..')
const isInWorkspace = existsSync(path.join(workspaceRoot, 'package.json'))

// Only build if:
// 1. Git install (for consumers), OR
// 2. Publishing (not in workspace = preparing for publish)
if (isGitInstall || !isInWorkspace) {
try {
execSync('preconstruct build', {
stdio: 'inherit',
cwd: workspaceRoot,
})
} catch (e) {
console.error('Build failed:', e.message)
process.exit(1)
}
}
8 changes: 0 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2454,7 +2454,6 @@ __metadata:
eslint-plugin-react-hooks: ^4.3.0
husky: ^7.0.4
patch-package: ^6.4.7
postinstall-postinstall: ^2.1.0
prettier: ^2.5.1
pretty-quick: ^3.1.3
react: ^18.0.0
Expand Down Expand Up @@ -15863,13 +15862,6 @@ __metadata:
languageName: node
linkType: hard

"postinstall-postinstall@npm:^2.1.0":
version: 2.1.0
resolution: "postinstall-postinstall@npm:2.1.0"
checksum: e1d34252cf8d2c5641c7d2db7426ec96e3d7a975f01c174c68f09ef5b8327bc8d5a9aa2001a45e693db2cdbf69577094d3fe6597b564ad2d2202b65fba76134b
languageName: node
linkType: hard

"potpack@npm:^1.0.1":
version: 1.0.2
resolution: "potpack@npm:1.0.2"
Expand Down